Documentation ¶
Index ¶
- Constants
- func NewProtocolError(code int, msg string) error
- type HandshakeMsg
- type ManagerBase
- func (mgr *ManagerBase) AddPeer(node *discover.Node) error
- func (mgr *ManagerBase) Db() db.PeerSetDb
- func (mgr *ManagerBase) DecrPeer()
- func (mgr *ManagerBase) Handshake(status *HandshakeMsg, peer *Node) error
- func (mgr *ManagerBase) PeerCount() int
- func (mgr *ManagerBase) SetDb(db db.PeerSetDb)
- func (mgr *ManagerBase) UnregisterPeer(node *Node)
- type Node
- func (node *Node) AddBlock(block interface{})
- func (node *Node) AddTx(tx interface{})
- func (node *Node) Conn() p2p.MsgReadWriter
- func (node *Node) HasBlock(block interface{}) bool
- func (node *Node) HasTx(tx interface{}) bool
- func (node *Node) ID() string
- func (node *Node) Id() string
- func (node *Node) Peer() *p2p.Peer
- func (node *Node) ReadMsg() (p2p.Msg, error)
- func (node *Node) Send(msgcode uint64, data interface{}) error
- func (node *Node) SetStatus(status *HandshakeMsg)
- func (node *Node) Status() *HandshakeMsg
- type ProtocolError
- type ProtocolManager
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 ¶
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) 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) Conn ¶
func (node *Node) Conn() p2p.MsgReadWriter
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() }
Click to show internal directories.
Click to hide internal directories.