Documentation ¶
Index ¶
- func SetGlobCommInst(c *Communicator)
- type Communicator
- func (c *Communicator) BroadcastBlock(blk *block.Block)
- func (c *Communicator) PeerCount() int
- func (c *Communicator) PeersStats() []*PeerStats
- func (c *Communicator) Protocols() []*p2psrv.Protocol
- func (c *Communicator) Start()
- func (c *Communicator) Stop()
- func (c *Communicator) SubscribeBlock(ch chan *NewBlockEvent) event.Subscription
- func (c *Communicator) Sync(handler HandleBlockStream, qcHandler HandleQC)
- func (c *Communicator) Synced() <-chan struct{}
- func (c *Communicator) TriggerSync()
- type DirectionCount
- type HandleBlockStream
- type HandleQC
- type NewBlockEvent
- type Peer
- func (p *Peer) Duration() mclock.AbsTime
- func (p *Peer) Head() (id meter.Bytes32, totalScore uint64)
- func (p *Peer) IsBlockKnown(id meter.Bytes32) bool
- func (p *Peer) IsPowBlockKnown(id meter.Bytes32) bool
- func (p *Peer) IsTransactionKnown(id meter.Bytes32) bool
- func (p *Peer) MarkBlock(id meter.Bytes32)
- func (p *Peer) MarkPowBlock(id meter.Bytes32)
- func (p *Peer) MarkTransaction(id meter.Bytes32)
- func (p *Peer) String() string
- func (p *Peer) UpdateHead(id meter.Bytes32, totalScore uint64)
- type PeerSet
- type PeerStats
- type Peers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetGlobCommInst ¶
func SetGlobCommInst(c *Communicator)
Types ¶
type Communicator ¶
type Communicator struct {
// contains filtered or unexported fields
}
Communicator communicates with remote p2p peers to exchange blocks and txs, etc.
var (
GlobCommInst *Communicator
)
func GetGlobCommInst ¶
func GetGlobCommInst() *Communicator
func New ¶
func New(chain *chain.Chain, txPool *txpool.TxPool, powPool *powpool.PowPool, configTopic string, magic [4]byte) *Communicator
New create a new Communicator instance.
func (*Communicator) BroadcastBlock ¶
func (c *Communicator) BroadcastBlock(blk *block.Block)
BroadcastBlock broadcast a block to remote peers.
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) Protocols ¶
func (c *Communicator) Protocols() []*p2psrv.Protocol
Protocols returns all supported protocols.
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, qcHandler HandleQC)
Sync start synchronization process.
func (*Communicator) Synced ¶
func (c *Communicator) Synced() <-chan struct{}
Synced returns a channel indicates if synchronization process passed.
type DirectionCount ¶
type HandleBlockStream ¶
HandleBlockStream to handle the stream of downloaded blocks in sync process.
type NewBlockEvent ¶
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) MarkPowBlock ¶
func (*Peer) MarkTransaction ¶
MarkTransaction marks a transaction to known.
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 meter.Bytes32 TotalScore uint64 PeerID string NetAddr string Inbound bool Duration uint64 // in seconds }
PeerStats records stats of a peer.