Documentation ¶
Index ¶
- type Communicator
- func (c *Communicator) BroadcastBlock(blk *block.EscortedBlock)
- func (c *Communicator) GetPeers() []*p2p.Peer
- func (c *Communicator) PeerCount() int
- func (c *Communicator) PeersStats() []*PeerStats
- func (c *Communicator) Start()
- func (c *Communicator) Stop()
- func (c *Communicator) SubscribeBlock(ch chan *NewBlockEvent) event.Subscription
- func (c *Communicator) Sync(handler HandleBlockStream)
- func (c *Communicator) SyncedCh() <-chan struct{}
- type DirectionCount
- type HandleBlockStream
- type HandleQC
- type NewBlockEvent
- type Peer
- func (p *Peer) Debug(msg string, ctx ...interface{})
- func (p *Peer) Duration() mclock.AbsTime
- func (p *Peer) Error(msg string, ctx ...interface{})
- func (p *Peer) Head() (id types.Bytes32, number uint32)
- func (p *Peer) Info(msg string, ctx ...interface{})
- func (p *Peer) IsBlockKnown(id types.Bytes32) bool
- func (p *Peer) IsTransactionKnown(id []byte) bool
- func (p *Peer) MarkBlock(id types.Bytes32)
- func (p *Peer) MarkTransaction(id []byte)
- func (p *Peer) String() string
- func (p *Peer) UpdateHead(id types.Bytes32, number uint32)
- func (p *Peer) Warn(msg string, ctx ...interface{})
- type PeerSet
- type PeerStats
- type Peers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Communicator ¶
type Communicator struct { Synced bool // contains filtered or unexported fields }
Communicator communicates with remote p2p peers to exchange blocks and txs, etc.
func NewCommunicator ¶
func NewCommunicator(ctx context.Context, chain *chain.Chain, txPool *txpool.TxPool, magic [4]byte, p2pConfig p2p.Config, rootDir string) *Communicator
New create a new Communicator instance.
func (*Communicator) BroadcastBlock ¶
func (c *Communicator) BroadcastBlock(blk *block.EscortedBlock)
BroadcastBlock broadcast a block to remote peers.
func (*Communicator) GetPeers ¶
func (c *Communicator) GetPeers() []*p2p.Peer
func (*Communicator) PeerCount ¶
func (c *Communicator) PeerCount() int
PeerCount returns count of peers.
func (*Communicator) PeersStats ¶
func (c *Communicator) PeersStats() []*PeerStats
PeersStats returns all peers' stats
func (*Communicator) SubscribeBlock ¶
func (c *Communicator) SubscribeBlock(ch chan *NewBlockEvent) event.Subscription
SubscribeBlock subscribe the event that new block received.
func (*Communicator) Sync ¶
func (c *Communicator) Sync(handler HandleBlockStream)
Sync start synchronization process.
func (*Communicator) SyncedCh ¶
func (c *Communicator) SyncedCh() <-chan struct{}
Synced returns a channel indicates if synchronization process passed.
type DirectionCount ¶
type HandleBlockStream ¶
type HandleBlockStream func(ctx context.Context, stream <-chan *block.EscortedBlock) error
HandleBlockStream to handle the stream of downloaded blocks in sync process.
type NewBlockEvent ¶
type NewBlockEvent struct {
*block.EscortedBlock
}
NewBlockEvent event emitted when received block announcement.
type Peer ¶
Peer extends p2p.Peer with RPC integrated.
func (*Peer) IsBlockKnown ¶
IsBlockKnown returns if the block is known.
func (*Peer) IsTransactionKnown ¶
IsTransactionKnown returns if the transaction is known.
func (*Peer) MarkTransaction ¶
MarkTransaction marks a transaction to known.
func (*Peer) UpdateHead ¶
UpdateHead update ID and total score of head block.
type PeerSet ¶
type PeerSet struct {
// contains filtered or unexported fields
}
PeerSet manages a set of peers, which mapped by NodeID.
func (*PeerSet) DirectionCount ¶
func (ps *PeerSet) DirectionCount() DirectionCount
type PeerStats ¶
type PeerStats struct { Name string BestBlockID types.Bytes32 BestBlockNum uint32 PeerID string NetAddr string Inbound bool Duration uint64 // in seconds }
PeerStats records stats of a peer.