protocol

package
v0.0.0-...-602a947 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorHandshakeFailed    = 0x01
	ErrorMaxPeersReached    = 0x02
	ErrorUnknownMessageType = 0x03
	ErrorNotImplemented     = 0x04
	ErrorSyncFailed         = 0x05
	ErrorInvalidRequest     = 0x06
	ErrorInvalidResponse    = 0x07
	ErrorNotFound           = 0x08
	ErrorBadBlock           = 0x09
)

protocol errors

View Source
const (
	// default value will be used for error, since closed channel sends default message
	CHAN_ERROR = uint8(0)
	CHAN_NEXT  = uint8(1)
	CHAN_ABORT = uint8(2)
	CHAN_RETRY = uint8(3)
	CHAN_DONE  = uint8(4)
)
View Source
const (
	ERR_WORLD_STATE_UPDATE_FAILURE = 0x01
)
View Source
const (
	// first message between peers
	Handshake = 0x00
)

protocol messages

Variables

This section is empty.

Functions

func NewProtocolError

func NewProtocolError(code int, msg string) error

Types

type HandshakeMsg

type HandshakeMsg struct {
	NetworkId   core.Byte16 `json:"network_id"       gencodec:"required"`
	ShardId     core.Byte16 `json:"shard_id"       	gencodec:"required"`
	TotalWeight core.Byte8  `json:"total_weight"  	gencodec:"required"`
	Genesis     core.Byte64 `json:"genesis"  		gencodec:"required"`
	TipNumeric  core.Byte8  `json:"tip_numeric"  	gencodec:"required"`
}

the very first message exchanged between two byoi peers upon connection establishment

type ManagerBase

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

base protocol manager implementation for shared data and code, will be extended by actual protocol manager implementations

func (*ManagerBase) AddPeer

func (mgr *ManagerBase) AddPeer(node *discover.Node) error

func (*ManagerBase) Db

func (mgr *ManagerBase) Db() db.PeerSetDb

func (*ManagerBase) DecrPeer

func (mgr *ManagerBase) DecrPeer()

func (*ManagerBase) Handshake

func (mgr *ManagerBase) Handshake(status *HandshakeMsg, peer *Node) error

perform sub protocol handshake

func (*ManagerBase) PeerCount

func (mgr *ManagerBase) PeerCount() int

func (*ManagerBase) SetDb

func (mgr *ManagerBase) SetDb(db db.PeerSetDb)

func (*ManagerBase) UnregisterPeer

func (mgr *ManagerBase) UnregisterPeer(node *Node)

type Node

type Node struct {

	// channel for GetBlockHashesRequest
	GetBlockHashesChan chan uint8
	// channel for GetBlocksRequest
	GetBlocksChan chan uint8
	// last hash from the node
	LastHash *core.Byte64
	// contains filtered or unexported fields
}

func NewNode

func NewNode(peer *p2p.Peer, conn p2p.MsgReadWriter) *Node

create a new instance of a node based on new peer connection

func (*Node) AddBlock

func (node *Node) AddBlock(block interface{})

func (*Node) AddTx

func (node *Node) AddTx(tx interface{})

func (*Node) Conn

func (node *Node) Conn() p2p.MsgReadWriter

func (*Node) HasBlock

func (node *Node) HasBlock(block interface{}) bool

func (*Node) HasTx

func (node *Node) HasTx(tx interface{}) bool

func (*Node) ID

func (node *Node) ID() string

func (*Node) Id

func (node *Node) Id() string

func (*Node) Peer

func (node *Node) Peer() *p2p.Peer

func (*Node) ReadMsg

func (node *Node) ReadMsg() (p2p.Msg, error)

func (*Node) Send

func (node *Node) Send(msgcode uint64, data interface{}) error

func (*Node) SetStatus

func (node *Node) SetStatus(status *HandshakeMsg)

func (*Node) Status

func (node *Node) Status() *HandshakeMsg

type ProtocolError

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

func (*ProtocolError) Error

func (err *ProtocolError) Error() string

type ProtocolManager

type ProtocolManager interface {
	// provide an instance of p2p protocol implementation
	Protocol() p2p.Protocol

	// initiate connection and handshake with a node
	AddPeer(node *discover.Node) error

	// perform protocol specific handshake with newly connected peer
	Handshake(peer *p2p.Peer, status *HandshakeMsg, ws p2p.MsgReadWriter) error

	// get reference to protocol manager's DB
	Db() db.PeerSetDb

	// Shutdown and cleanup
	Shutdown()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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