p2p

package
v0.0.0-...-f23cd05 Latest Latest
Warning

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

Go to latest
Published: May 2, 2019 License: Apache-2.0 Imports: 15 Imported by: 15

Documentation

Index

Constants

View Source
const (
	//MIN_MINERS is a lower bound of connections. If there are less, the system actively requests miner peers
	//from neighbors and establishes connections to them
	MIN_MINERS = 5
	//MAX_MINERS is an upper bound of connections. Miner handshakes are rejected if the amount of connections
	//grows above this number. Client connections are always accepted
	MAX_MINERS = 20
	//In order to get a reasonable system time, there needs to be a minimal amount of times available from other peers
	MIN_PEERS_FOR_TIME = 5
	//Interval to check system health in seconds
	HEALTH_CHECK_INTERVAL = 30
	//Broadcast local time to the network in seconds
	TIME_BRDCST_INTERVAL = 60
	//Calculate system time every UPDATE_SYS_TIME seconds
	UPDATE_SYS_TIME = 90

	//Protocol constants
	IPV4ADDR_SIZE = 4
	PORT_SIZE     = 2
)

Package-wide constants and configuration parameters

View Source
const (
	PEERTYPE_MINER  = 1
	PEERTYPE_CLIENT = 2
)
View Source
const (
	FUNDSTX_BRDCST      = 1
	ACCTX_BRDCST        = 2
	CONFIGTX_BRDCST     = 3
	STAKETX_BRDCST      = 4
	VERIFIEDTX_BRDCST   = 5
	BLOCK_BRDCST        = 6
	BLOCK_HEADER_BRDCST = 7
	TX_BRDCST_ACK       = 8

	FUNDSTX_REQ            = 10
	ACCTX_REQ              = 11
	CONFIGTX_REQ           = 12
	STAKETX_REQ            = 13
	BLOCK_REQ              = 14
	BLOCK_HEADER_REQ       = 15
	ACC_REQ                = 16
	ROOTACC_REQ            = 17
	INTERMEDIATE_NODES_REQ = 18

	FUNDSTX_RES            = 20
	ACCTX_RES              = 21
	CONFIGTX_RES           = 22
	STAKETX_RES            = 23
	BLOCK_RES              = 24
	BlOCK_HEADER_RES       = 25
	ACC_RES                = 26
	ROOTACC_RES            = 27
	INTERMEDIATE_NODES_RES = 28

	NEIGHBOR_REQ = 30
	NEIGHBOR_RES = 40

	TIME_BRDCST = 50

	MINER_PING  = 100
	MINER_PONG  = 101
	CLIENT_PING = 102
	CLIENT_PONG = 103

	//Used to signal error
	NOT_FOUND = 110
)

Mapping constants, used to parse incoming messages

View Source
const HEADER_LEN = 5

Variables

View Source
var (
	//Block from the network, to the miner
	BlockIn chan []byte = make(chan []byte)
	//Block from the miner, to the network
	BlockOut chan []byte = make(chan []byte)
	//BlockHeader from the miner, to the clients
	BlockHeaderOut chan []byte = make(chan []byte)

	VerifiedTxsOut chan []byte = make(chan []byte)

	//Data requested by miner, to allow parallelism, we have a chan for every tx type.
	FundsTxChan  = make(chan *protocol.FundsTx)
	AccTxChan    = make(chan *protocol.AccTx)
	ConfigTxChan = make(chan *protocol.ConfigTx)
	StakeTxChan  = make(chan *protocol.StakeTx)

	BlockReqChan = make(chan []byte)
)
View Source
var (
	//List of ip addresses. A connection to a subset of the list will be established as soon as the network health
	//monitor triggers.
	Ipport string
)
View Source
var (
	LogMapping map[uint8]string
)

Functions

func BlockReq

func BlockReq(hash [32]byte) error

Both block and tx requests are handled asymmetricaly, using channels as inter-communication All the request in this file are specifically initiated by the miner package

func BuildPacket

func BuildPacket(typeID uint8, payload []byte) (packet []byte)

func Connect

func Connect(connectionString string) *net.TCPConn

func Init

func Init(ipport string)

Entry point for p2p package

func InitLogging

func InitLogging()

func IsBootstrap

func IsBootstrap() bool

func LastBlockReq

func LastBlockReq() error

func PrepareHandshake

func PrepareHandshake(pingType uint8, localPort int) ([]byte, error)

func ReadSystemTime

func ReadSystemTime() int64

func TxReq

func TxReq(hash [32]byte, reqType uint8) error

Request specific transaction

Types

type Header struct {
	Len    uint32
	TypeID uint8
}

func RcvData

func RcvData(p *peer) (header *Header, payload []byte, err error)

func RcvData_

func RcvData_(c net.Conn) (header *Header, payload []byte, err error)

func ReadHeader

func ReadHeader(reader *bufio.Reader) (*Header, error)

func (Header) String

func (header Header) String() string

Jump to

Keyboard shortcuts

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