p3

package
v0.0.0-...-8b53a4d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ALLOWED_IDS = map[int32]bool{
	6688: true,
	6678: true,
}

Only these IDs are allowed to write. This gives the semblance of a permissioned blockchain

View Source
var CREATED = false
View Source
var FIRST_NODE = "http://localhost:6688"
View Source
var FIRST_NODE_ADDRESS = "localhost:6688"

First node will have the canonical block chain on it. It will first create the blockchain, and the other nodes will listen for it.

View Source
var FIRST_NODE_BALLOT = FIRST_NODE + "/show-ballot"
View Source
var FIRST_NODE_PORT int32 = 6688
View Source
var FIRST_NODE_SERVER = FIRST_NODE + "/upload"
View Source
var FOUNDREMOTE = false

Need to introduce a private key so we can properly do signatures

This is the canonical blockchain

View Source
var SELF_ADDR string

Functions

func AskForBlock

func AskForBlock(height int32, hash string)

Function recursively asks for all the missing predecessor blocks instead of only the parent block.

func Canonical

func Canonical(w http.ResponseWriter, r *http.Request)
If there are multiple blocks at max height n, they are considered as forks, and each fork can form a chain.

The canonical chain would be decided once one of the forks grows and that chain becomes the longest chain.

func CountVotes

func CountVotes(value string) int

func Create

func Create(w http.ResponseWriter, r *http.Request)

Create the initial canonical Blockchain and add write it to the server

func Download

func Download()

Download blockchain from First Node

So launch node on SELF_ADDR and then download from the TA_SERVER
SELF_ADDR needs to make a request to FIRST_NODE

func DownloadBallot

func DownloadBallot()
Download the uploaded ballot from other Nodes.

We should save this data to a Ballot Class, like we did with Blockchain.

func ForwardHeartBeat

func ForwardHeartBeat(heartBeatData data.HeartBeatData)

Send to all the peers. Will probably want to send a post request to their ReceiveHeartBeat

func GenerateVotingMpt

func GenerateVotingMpt() p1.MerklePatriciaTrie

Changed so there's User Input Required Now

This contains the data that we need to insert into the block, before we send it to the blockchain. Requires user input before the MPT is generated.

func HeartBeatReceive

func HeartBeatReceive(w http.ResponseWriter, r *http.Request)

func Logger

func Logger(inner http.Handler, name string) http.Handler

func NewRouter

func NewRouter() *mux.Router

func RandSeed

func RandSeed()

func ReadDataFromBallot

func ReadDataFromBallot() voting.Ballot

func SendBlock

func SendBlock(trie p1.MerklePatriciaTrie)

func Show

func Show(w http.ResponseWriter, r *http.Request)

Display peerList and sbc

func ShowBallot

func ShowBallot(w http.ResponseWriter, r *http.Request)

Show the contents of the ballot

func ShowMPT

func ShowMPT(w http.ResponseWriter, r *http.Request)

func Start

func Start(w http.ResponseWriter, r *http.Request)

Register ID, download BlockChain, start HeartBeat

func StartHeartBeat

func StartHeartBeat()

func StartVotingProcess

func StartVotingProcess()

This function starts a new thread that tries different nonces to generate new blocks. Nonce is a string of 16 hexes such as "1f7b169c846f218a". Initialize the rand when you start a new node with something unique about each node, such as the current time or the port number.

func Upload

func Upload(w http.ResponseWriter, r *http.Request)

Called By Download (POST Request from local node's Download Function)

func UploadBlock

func UploadBlock(w http.ResponseWriter, r *http.Request)

If you have the block, return the JSON string of the specific block; if you don't have the block, return HTTP 204: StatusNoContent; if there's an error, return HTTP 500: InternalServerError.

Types

type CanonicalChain

type CanonicalChain struct {
	// contains filtered or unexported fields
}

type CanonicalChainBlock

type CanonicalChainBlock struct {
	// contains filtered or unexported fields
}

type ECDSASignature

type ECDSASignature struct {
	R, S *big.Int
}

Need to make a ECDSASignature struct to verify

type JsonString

type JsonString struct {
	JsonBody string
}

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

type Routes

type Routes []Route

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL