Documentation ¶
Index ¶
- Variables
- func BlockPacketWithCache(msg *RequestMessage, provider types.Provider, batchCache gcache.Cache, ...) ([]byte, error)
- func FillBytes(r io.Reader, bs []byte) (int64, error)
- func MessageToPacket(m interface{}) []byte
- func PacketMessageType(bs []byte) uint16
- func PacketToMessage(bs []byte) (interface{}, error)
- func ReadBool(r io.Reader) (bool, int64, error)
- func ReadBytes(r io.Reader) ([]byte, int64, error)
- func ReadString(r io.Reader) (string, int64, error)
- func ReadUint16(r io.Reader) (uint16, int64, error)
- func ReadUint32(r io.Reader) (uint32, int64, error)
- func ReadUint64(r io.Reader) (uint64, int64, error)
- func ReadUint8(r io.Reader) (uint8, int64, error)
- type BlockMessage
- type Handler
- type Node
- func (nd *Node) AddTx(tx types.Transaction, sigs []common.Signature) error
- func (nd *Node) Close()
- func (nd *Node) GetTxFromTXPool(TxHash hash.Hash256) *txpool.PoolItem
- func (nd *Node) Init() error
- func (nd *Node) OnConnected(p peer.Peer)
- func (nd *Node) OnDisconnected(p peer.Peer)
- func (nd *Node) OnItemExpired(Interval time.Duration, Key string, Item interface{}, IsLast bool)
- func (nd *Node) OnRecv(p peer.Peer, bs []byte) error
- func (nd *Node) OnTimerExpired(height uint32, value string)
- func (nd *Node) PushTx(tx types.Transaction, sigs []common.Signature) error
- func (nd *Node) Run(BindAddress string)
- func (nd *Node) TxPoolList() []*txpool.PoolItem
- type NodeMesh
- func (ms *NodeMesh) AddBadPoint(ID string, Point int)
- func (ms *NodeMesh) AddPeerList(ips []string, hashs []string)
- func (ms *NodeMesh) BroadcastPacket(bs []byte)
- func (ms *NodeMesh) ExceptCast(ID string, bs []byte)
- func (ms *NodeMesh) GetPeer(ID string) peer.Peer
- func (ms *NodeMesh) HasPeer() bool
- func (ms *NodeMesh) Peers() []peer.Peer
- func (ms *NodeMesh) RemovePeer(ID string)
- func (ms *NodeMesh) RequestConnect(Address string, TargetPubHash common.PublicHash)
- func (ms *NodeMesh) RequestPeerList(targetHash string)
- func (ms *NodeMesh) Run(BindAddress string)
- func (ms *NodeMesh) SendPeerList(targetHash string)
- func (ms *NodeMesh) SendTo(pubhash common.PublicHash, bs []byte)
- type PeerListMessage
- type RecvMessageItem
- type RequestExpireHandler
- type RequestMessage
- type RequestPeerListMessage
- type RequestTimer
- type SendMessageItem
- type Status
- type StatusMessage
- type TCPAsyncPeer
- type TCPPeer
- type TransactionMessage
- type TxMsgItem
- type WebsocketPeer
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidHandshake = errors.New("invalid handshake") ErrInvalidLength = errors.New("invalid length") ErrUnknownMessage = errors.New("unknown message") ErrNotExistPeer = errors.New("not exist peer") ErrSelfConnection = errors.New("self connection") ErrInvalidUTXO = errors.New("invalid UTXO") ErrTooManyTrasactionInMessage = errors.New("too many transaction in message") )
errors
var ( StatusMessageType = types.DefineHashedType("p2p.StatusMessage") RequestMessageType = types.DefineHashedType("p2p.RequestMessage") BlockMessageType = types.DefineHashedType("p2p.BlockMessage") TransactionMessageType = types.DefineHashedType("p2p.TransactionMessage") PeerListMessageType = types.DefineHashedType("p2p.PeerListMessage") RequestPeerListMessageType = types.DefineHashedType("p2p.RequestPeerListMessage") )
message types
Functions ¶
func BlockPacketWithCache ¶
func MessageToPacket ¶
func MessageToPacket(m interface{}) []byte
MessageToPacket returns packet of the message
func PacketMessageType ¶
func PacketToMessage ¶
func ReadString ¶
ReadString reads a string array from the reader
func ReadUint16 ¶
ReadUint16 reads a uint16 number from the reader
func ReadUint32 ¶
ReadUint32 reads a uint32 number from the reader
func ReadUint64 ¶
ReadUint64 reads a uint64 number from the reader
Types ¶
type BlockMessage ¶
BlockMessage used to send a chain block to a peer
type Handler ¶
type Handler interface { OnConnected(p peer.Peer) OnDisconnected(p peer.Peer) OnRecv(p peer.Peer, bs []byte) error }
Handler is a interface for connection events
type Node ¶
Node receives a block by the consensus
func NewNode ¶
func NewNode(key key.Key, SeedNodeMap map[common.PublicHash]string, cn *chain.Chain, peerStorePath string) *Node
NewNode returns a Node
func (*Node) GetTxFromTXPool ¶
GetTxFromTXPool returned tx from txpool
func (*Node) OnConnected ¶
OnConnected called when peer connected
func (*Node) OnDisconnected ¶
OnDisconnected called when peer disconnected
func (*Node) OnItemExpired ¶
OnItemExpired is called when the item is expired
func (*Node) OnTimerExpired ¶
OnTimerExpired called when rquest expired
func (*Node) TxPoolList ¶
TxPoolList returned tx list from txpool
type NodeMesh ¶
NodeMesh is a mesh for networking between nodes
func NewNodeMesh ¶
func NewNodeMesh(ChainID uint8, key key.Key, SeedNodeMap map[common.PublicHash]string, handler Handler, peerStorePath string) *NodeMesh
NewNodeMesh returns a NodeMesh
func (*NodeMesh) AddBadPoint ¶
AddBadPoint adds bad points to to the peer
func (*NodeMesh) AddPeerList ¶
func (*NodeMesh) BroadcastPacket ¶
BroadcastPacket sends a packet to all peers
func (*NodeMesh) ExceptCast ¶
ExceptCast sends a message except the peer
func (*NodeMesh) RemovePeer ¶
RemovePeer removes peers from the mesh
func (*NodeMesh) RequestConnect ¶
func (ms *NodeMesh) RequestConnect(Address string, TargetPubHash common.PublicHash)
func (*NodeMesh) RequestPeerList ¶
func (*NodeMesh) SendPeerList ¶
type PeerListMessage ¶
PeerListMessage is a message for a peer list
type RecvMessageItem ¶
RecvMessageItem used to store recv message
type RequestExpireHandler ¶
RequestExpireHandler handles a request expire event
type RequestMessage ¶
RequestMessage used to request a chain data to a peer
type RequestPeerListMessage ¶
type RequestPeerListMessage struct { }
RequestPeerListMessage is a request message for a peer list
type RequestTimer ¶
RequestTimer triggers a event when a request is expired
func NewRequestTimer ¶
func NewRequestTimer(handler RequestExpireHandler) *RequestTimer
NewRequestTimer returns a RequestTimer
func (*RequestTimer) Add ¶
func (rm *RequestTimer) Add(height uint32, t time.Duration, value string)
Add adds the timer of the request
func (*RequestTimer) Exist ¶
func (rm *RequestTimer) Exist(height uint32) bool
Exist returns the target height request exists or not
func (*RequestTimer) RemovesByValue ¶
func (rm *RequestTimer) RemovesByValue(value string)
RemovesByValue removes requests by the value
type SendMessageItem ¶
type SendMessageItem struct { Target common.PublicHash Address common.Address Except bool Packet []byte }
SendMessageItem used to store send message
type StatusMessage ¶
StatusMessage used to provide the chain information to a peer
type TCPAsyncPeer ¶
type TCPAsyncPeer struct {
// contains filtered or unexported fields
}
TCPAsyncPeer manages send and recv of the connection
func NewTCPAsyncPeer ¶
NewTCPAsyncPeer returns a TCPAsyncPeer
func (*TCPAsyncPeer) ConnectedTime ¶
func (p *TCPAsyncPeer) ConnectedTime() int64
ConnectedTime returns peer connected time
func (*TCPAsyncPeer) IsClosed ¶
func (p *TCPAsyncPeer) IsClosed() bool
IsClosed returns it is closed or not
func (*TCPAsyncPeer) ReadPacket ¶
func (p *TCPAsyncPeer) ReadPacket() ([]byte, error)
ReadPacket returns a packet data
func (*TCPAsyncPeer) SendPacket ¶
func (p *TCPAsyncPeer) SendPacket(bs []byte)
SendPacket sends packet to the WebsocketPeer
type TCPPeer ¶
TCPPeer manages send and recv of the connection
func NewTCPPeer ¶
NewTCPPeer returns a TCPPeer
func (*TCPPeer) ConnectedTime ¶
ConnectedTime returns peer connected time
func (*TCPPeer) ReadPacket ¶
ReadPacket returns a packet data
func (*TCPPeer) SendPacket ¶
SendPacket sends packet to the WebsocketPeer
type TransactionMessage ¶
type TransactionMessage struct { Types []uint16 //MAXLEN : 65535 Txs []types.Transaction //MAXLEN : 65535 Signatures [][]common.Signature //MAXLEN : 65535 }
TransactionMessage is a message for a transaction
type TxMsgItem ¶
type TxMsgItem struct { TxHash hash.Hash256 Type uint16 Tx types.Transaction Sigs []common.Signature PeerID string ErrCh *chan error }
TxMsgItem used to store transaction message
type WebsocketPeer ¶
WebsocketPeer manages send and recv of the connection
func NewWebsocketPeer ¶
func NewWebsocketPeer(conn *websocket.Conn, ID string, Name string, connectedTime int64) *WebsocketPeer
NewWebsocketPeer returns a WebsocketPeer
func (*WebsocketPeer) ConnectedTime ¶
func (p *WebsocketPeer) ConnectedTime() int64
ConnectedTime returns peer connected time
func (*WebsocketPeer) IsClosed ¶
func (p *WebsocketPeer) IsClosed() bool
IsClosed returns it is closed or not
func (*WebsocketPeer) Name ¶
func (p *WebsocketPeer) Name() string
Name returns the name of the peer
func (*WebsocketPeer) ReadPacket ¶
func (p *WebsocketPeer) ReadPacket() ([]byte, error)
ReadPacket returns a packet data
func (*WebsocketPeer) SendPacket ¶
func (p *WebsocketPeer) SendPacket(bs []byte)
SendPacket sends packet to the WebsocketPeer