network

package
v0.0.0-...-2caa6c1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KnownNodes = []string{"localhost:3000"}
)

Functions

func BytesToCmd

func BytesToCmd(bytes []byte) string

BytesToCmd will work like a deserialize function transforming the given bytes to a string

func CloseDB

func CloseDB(chain *blockchain.BlockChain)

CloseDB will grafully shutdown the system if the process is interrupt or recive a syscall

func CmdToBytes

func CmdToBytes(cmd string) []byte

CmdToBytes will work like a serialize function for the commands recibed by the command line package

func DeserializePayload

func DeserializePayload(request []byte, payload interface{}) error

Deserialze payload will deserialize the request into a struuct

func ExtractCmd

func ExtractCmd(request []byte) []byte

func GobEncode

func GobEncode(data interface{}) []byte

GobEncode will allow us to serialize data in a generic way

func HandeBlock

func HandeBlock(request []byte, chain *blockchain.BlockChain)

handle block will handle the address get block request

func HandleAddr

func HandleAddr(request []byte)

handle address will handle the address get address request

func HandleConnection

func HandleConnection(conn net.Conn, chain *blockchain.BlockChain)

HandleConnection will handle connections of the current node

func HandleGetBlocks

func HandleGetBlocks(request []byte, chain *blockchain.BlockChain)

handle get block will handle the get blocks request

func HandleGetData

func HandleGetData(request []byte, chain *blockchain.BlockChain)

Handle GetData will handle the get data request

func HandleInv

func HandleInv(request []byte, chain *blockchain.BlockChain)

handle inventory will handle the get Inv request

func HandleTx

func HandleTx(request []byte, chain *blockchain.BlockChain)

Handle transaction will handle the get transaction request

func HandleVersion

func HandleVersion(request []byte, chain *blockchain.BlockChain)

handle version will handle the get version request

func MineTx

func MineTx(chain *blockchain.BlockChain)

mineTx will will nine the transaction

func NodeIsKnown

func NodeIsKnown(addr string) bool

Node is known will check if the given node is in the list of known nodes

func RequestBlocks

func RequestBlocks()

Request block will call send get block for each node in the list

func SendAddr

func SendAddr(address string)

send address will create the request of the address to be send

func SendBlock

func SendBlock(addr string, b *blockchain.Block)

Send block will create the request of the block to be send

func SendGetBlock

func SendGetBlock(addr string)

SendGetBLock will the create request of the Getblock to be send

func SendGetData

func SendGetData(addr, kind string, id []byte)

SendGetData will the create request of the GetData to be send

func SendInv

func SendInv(addr, kind string, items [][]byte)

SendInv will the create request of the inventory to be send

func SendTx

func SendTx(addr string, txn *blockchain.Transaction)

SendTx will the create request of the transaction to be send

func SendVersion

func SendVersion(addr string, chain *blockchain.BlockChain)

SendVersion will the create request of the Version to be send

func StartServer

func StartServer(nodeID, mineAddress string)

StartServer will start the server with the given node id

Types

type Addr

type Addr struct {
	AddrList []string // represents the list of addresses of each of the nodes
}

type Block

type Block struct {
	AddrFrom string // represents the address that the block is build from
	Block    []byte // represents the block it self
}

type GetBlocks

type GetBlocks struct {
	AddrFrom string // represents the address where the block are being fetching
}

type GetData

type GetData struct {
	AddrFrom string // represents the address where the block are being fetching
	Type     string // represents the type of the data that is being fetching
	ID       []byte // represents the id of the data
}

type Inv

type Inv struct {
	AddrFrom string   // represents the address of the current node
	Type     string   // represents the type of data in the inventory
	Items    [][]byte // represents the items in the inventory
}

type Tx

type Tx struct {
	AddrFrom    string // represents the address of the transaction
	Transaction []byte // represents the transaction
}

type Version

type Version struct {
	Version    int    // represents the version of the current blockchain node
	BestHeigth int    // represents the length of the blockchain
	AddrFrom   string // reprensents the address of the current node
}

Jump to

Keyboard shortcuts

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