comm

package
v1.2.0-fork7 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: LGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

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

func (c *Communicator) 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, qcHandler HandleQC)

Sync start synchronization process.

func (*Communicator) Synced

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

Synced returns a channel indicates if synchronization process passed.

func (*Communicator) TriggerSync

func (c *Communicator) TriggerSync()

trigger a manual sync

type DirectionCount

type DirectionCount struct {
	Inbound  int
	Outbound int
}

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 HandleQC

type HandleQC func(ctx context.Context, qc *block.QuorumCert) (bool, error)

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 meter.Bytes32, totalScore uint64)

Head returns head block ID and total score.

func (*Peer) IsBlockKnown

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

IsBlockKnown returns if the block is known.

func (*Peer) IsPowBlockKnown

func (p *Peer) IsPowBlockKnown(id meter.Bytes32) bool

func (*Peer) IsTransactionKnown

func (p *Peer) IsTransactionKnown(id meter.Bytes32) bool

IsTransactionKnown returns if the transaction is known.

func (*Peer) MarkBlock

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

MarkBlock marks a block to known.

func (*Peer) MarkPowBlock

func (p *Peer) MarkPowBlock(id meter.Bytes32)

func (*Peer) MarkTransaction

func (p *Peer) MarkTransaction(id meter.Bytes32)

MarkTransaction marks a transaction to known.

func (*Peer) String

func (p *Peer) String() string

func (*Peer) UpdateHead

func (p *Peer) UpdateHead(id meter.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, dir string)

Add add a new peer.

func (*PeerSet) DirectionCount

func (ps *PeerSet) DirectionCount() DirectionCount

func (*PeerSet) Find

func (ps *PeerSet) Find(nodeID enode.ID) *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 enode.ID) *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 meter.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