Documentation ¶
Index ¶
- Constants
- func WriteConnRequest(conn net.Conn, r Request) error
- type MessageHandle
- type Node
- type Packet
- type Peer
- func (p *Peer) BroadcastMessage(msg protocol.Message)
- func (p *Peer) GetListenAddr() string
- func (p *Peer) GetSeedAddr() string
- func (p *Peer) PushAddrMsg(msg *protocol.MsgAddr) error
- func (p *Peer) PushBlock(msg *protocol.MsgBlock) error
- func (p *Peer) PushGetBlocks(msg *protocol.MsgGetBlocks) error
- func (p *Peer) PushTx(msg *protocol.MsgTx) error
- func (p *Peer) PushVersion(msg *protocol.MsgVersion) error
- func (p *Peer) ReciveMessage()
- func (p *Peer) SendRouteMessage(msg protocol.Message)
- func (p *Peer) SendSingleMessage(msg protocol.Message)
- func (p *Peer) StartListen() error
- type Request
- type RequestInfo
- type Seed
Constants ¶
View Source
const ( SendRequest = 1 ServerPing = 2 // ping to the seed ServerPong = 3 // pong to the ping SyncBackupSeeds = 4 // query for the backup seeds BackupSeeds = 5 // return the backup seeds RequestReceived = 6 // ack )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MessageHandle ¶
type MessageHandle interface { // OnGetAddr is invoked when a peer receives a getaddr message. OnGetAddr(msg *protocol.MsgGetAddr) // OnAddr is invoked when a peer receives an addr message. OnAddr(msg *protocol.MsgAddr) // OnInv is invoked when a peer receives an inv message. OnInv(msg *protocol.MsgInv) // OnVersion is invoked when a peer receives an ver message OnVersion(msg *protocol.MsgVersion) // OnGetBlocks is invoked when a peer receives an getblocks message OnGetBlocks(msg *protocol.MsgGetBlocks) // OnGetData is invoked when a peer receives an getdata message OnGetData(msg *protocol.MsgGetData) // OnBlock is invoked when a peer receives an block message OnBlock(msg *protocol.MsgBlock) // OnTx is invoked when a peer receives an tx message OnTx(msg *protocol.MsgTx) }
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is the local server
func NewNode ¶
func NewNode(laddr, saddr string, boardcast chan *RequestInfo, recv chan *Request, single chan *RequestInfo) *Node
NewNode return new &node with laddr, saddr, send, recv
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer extends the node to maintain state shared by the server
func NewPeer ¶
func NewPeer(listenAddr, seedAddr string, msgHandler MessageHandle) *Peer
func (*Peer) BroadcastMessage ¶
BroadcastMessage send message to all downstream nodes and seed node
func (*Peer) GetListenAddr ¶
GetListenAddr get peer listen addr
func (*Peer) GetSeedAddr ¶
func (*Peer) PushGetBlocks ¶
func (p *Peer) PushGetBlocks(msg *protocol.MsgGetBlocks) error
func (*Peer) PushVersion ¶
func (p *Peer) PushVersion(msg *protocol.MsgVersion) error
func (*Peer) ReciveMessage ¶
func (p *Peer) ReciveMessage()
ReciveMessage recive message from net node
func (*Peer) SendRouteMessage ¶
RouteMessage send message to all downstream nodes and seed node without source node
func (*Peer) SendSingleMessage ¶
BroadcastMessage send message to all downstream nodes and seed node
func (*Peer) StartListen ¶
type RequestInfo ¶
type RequestInfo struct { Data interface{} FromAddr string }
Click to show internal directories.
Click to hide internal directories.