comm

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2019 License: LGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Communicator

type Communicator struct {
	// contains filtered or unexported fields
}

Communicator communicates with remote p2p peers to exchange blocks and txs, etc.

func New

func New(chain *chain.Chain, txPool *txpool.TxPool) *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) Start

func (c *Communicator) Start()

Start start the communicator.

func (*Communicator) Stop

func (c *Communicator) Stop()

Stop stop the communicator.

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) Synced

func (c *Communicator) Synced() <-chan struct{}

Synced returns a channel indicates if synchronization process passed.

type HandleBlockStream

type HandleBlockStream func(ctx context.Context, stream <-chan *block.Block) error

HandleBlockStream to handle the stream of downloaded blocks in sync process.

type NewBlockEvent

type NewBlockEvent struct {
	*block.Block
}

NewBlockEvent event emitted when received block announcement.

type Peer

type Peer struct {
	*p2p.Peer
	*rpc.RPC
	// contains filtered or unexported fields
}

Peer extends p2p.Peer with RPC integrated.

func (*Peer) Duration

func (p *Peer) Duration() mclock.AbsTime

Duration returns duration of connection.

func (*Peer) Head

func (p *Peer) Head() (id thor.Bytes32, totalScore uint64)

Head returns head block ID and total score.

func (*Peer) IsBlockKnown

func (p *Peer) IsBlockKnown(id thor.Bytes32) bool

IsBlockKnown returns if the block is known.

func (*Peer) IsTransactionKnown

func (p *Peer) IsTransactionKnown(hash thor.Bytes32) bool

IsTransactionKnown returns if the transaction is known.

func (*Peer) MarkBlock

func (p *Peer) MarkBlock(id thor.Bytes32)

MarkBlock marks a block to known.

func (*Peer) MarkTransaction

func (p *Peer) MarkTransaction(hash thor.Bytes32)

MarkTransaction marks a transaction to known.

func (*Peer) UpdateHead

func (p *Peer) UpdateHead(id thor.Bytes32, totalScore uint64)

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) Add

func (ps *PeerSet) Add(peer *Peer)

Add add a new peer.

func (*PeerSet) Find

func (ps *PeerSet) Find(nodeID discover.NodeID) *Peer

Find find peer for given nodeID.

func (*PeerSet) Len

func (ps *PeerSet) Len() int

Len returns length of set.

func (*PeerSet) Remove

func (ps *PeerSet) Remove(nodeID discover.NodeID) *Peer

Remove removes peer for given nodeID.

func (*PeerSet) Slice

func (ps *PeerSet) Slice() Peers

Slice dumps all peers into a slice. The dumped slice is a random permutation.

type PeerStats

type PeerStats struct {
	Name        string
	BestBlockID thor.Bytes32
	TotalScore  uint64
	PeerID      string
	NetAddr     string
	Inbound     bool
	Duration    uint64 // in seconds
}

PeerStats records stats of a peer.

type Peers

type Peers []*Peer

Peers slice of peers

func (Peers) Filter

func (ps Peers) Filter(cond func(*Peer) bool) Peers

Filter filter out sub set of peers that satisfies the given condition.

func (Peers) Find

func (ps Peers) Find(cond func(*Peer) bool) *Peer

Find find one peer that satisfies the given condition.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL