network

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2022 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package network implements a concrete consensus engines.

Index

Constants

View Source
const (

	// CbftProtocolName is protocol name of CBFT.
	CbftProtocolName = "cbft"

	// CbftProtocolVersion is protocol version of CBFT.
	CbftProtocolVersion = 1

	// CbftProtocolLength are the number of implemented message corresponding to cbft protocol versions.
	CbftProtocolLength = 40

	// QCBnMonitorInterval is Qc block synchronization detection interval.
	QCBnMonitorInterval = 1

	// SyncViewChangeInterval is ViewChange synchronization detection interval.
	SyncViewChangeInterval = 1

	// SyncPrepareVoteInterval is PrepareVote synchronization detection interval.
	SyncPrepareVoteInterval = 1

	// TypeForQCBn is the type for QC sync.
	TypeForQCBn = 1

	// TypeForLockedBn is the type for Locked sync.
	TypeForLockedBn = 2

	// TypeForCommitBn is the type for Commit sync.
	TypeForCommitBn = 3
)
View Source
const DefaultFanOut = 5

DefaultFanOut - The fanout value of the gossip protocol, used to indicate the number of nodes selected per broadcast.

Variables

This section is empty.

Functions

func EnhanceEngineManager

func EnhanceEngineManager(ids []discover.NodeID, handlers []*EngineManager)

EnhanceEngineManager is used to register a batch of handlers to simulate the test environment.

The number of simulated network nodes is fixed at four.

func FillEngineManager

func FillEngineManager(ids []discover.NodeID, handler *EngineManager)

FillEngineManager populates the peer for the specified Handle.

func FormatNodes

func FormatNodes(ids []discover.NodeID) string

FormatNodes is used to print the information about peerID.

func RandomID

func RandomID() []discover.NodeID

RandomID returns a list of NodeID by random.

func SetSendQueueHook

func SetSendQueueHook(engine *EngineManager, hook func(msg *types.MsgPackage))

SetSendQueueHook sets the hook for engine.

Types

type Cbft

type Cbft interface {

	// Returns the ID value of the current node.
	NodeID() discover.NodeID

	// Return a list of all consensus nodes.
	ConsensusNodes() ([]discover.NodeID, error)

	// Return configuration information of CBFT consensus.
	Config() *types.Config

	// Entrance: The messages related to the consensus are entered from here.
	// The message sent from the peer node is sent to the CBFT message queue and
	// there is a loop that will distribute the incoming message.
	ReceiveMessage(msg *types.MsgInfo) error

	// ReceiveSyncMsg is used to receive messages that are synchronized from other nodes.
	ReceiveSyncMsg(msg *types.MsgInfo) error

	// Return the highest QC block number of the current node.
	HighestQCBlockBn() (uint64, common.Hash)

	// Return the highest locked block number of the current node.
	HighestLockBlockBn() (uint64, common.Hash)

	// Return the highest commit block number of the current node.
	HighestCommitBlockBn() (uint64, common.Hash)

	// Returns the node ID of the missing vote.
	MissingViewChangeNodes() (*protocols.GetViewChange, error)

	// Returns the missing vote.
	MissingPrepareVote() (*protocols.GetPrepareVote, error)

	// Returns latest status.
	LatestStatus() *protocols.GetLatestStatus

	// OnPong records net delay time.
	OnPong(nodeID string, netLatency int64) error

	// BlockExists determines if a block exists.
	BlockExists(blockNumber uint64, blockHash common.Hash) error
}

Cbft defines the network layer to use the relevant interface to the consensus layer.

type EngineManager

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

EngineManager responsibles for processing the messages in the network.

func NewEngineManger

func NewEngineManger(engine Cbft) *EngineManager

NewEngineManger returns a new handler and do some initialization.

func (*EngineManager) AliveConsensusNodeIDs

func (h *EngineManager) AliveConsensusNodeIDs() ([]string, error)

AliveConsensusNodeIDs returns all NodeID to alive peer.

func (*EngineManager) Broadcast

func (h *EngineManager) Broadcast(msg types.Message)

Broadcast imports messages into the send queue and send it according to broadcast.

Note: The broadcast of this method defaults to FULL mode.

func (*EngineManager) Close

func (h *EngineManager) Close()

Close turns off the handler for sending messages.

func (*EngineManager) ConsensusNodes

func (h *EngineManager) ConsensusNodes() ([]discover.NodeID, error)

ConsensusNodes returns a list of all consensus nodes.

func (*EngineManager) ContainsBlacklist

func (h *EngineManager) ContainsBlacklist(peerID string) bool

ContainsBlacklist returns whether the specified node is blacklisted.

func (*EngineManager) ContainsHistoryMessageHash

func (h *EngineManager) ContainsHistoryMessageHash(hash common.Hash) bool

ContainsMessageHash returns whether the specified hash exists.

func (*EngineManager) Forwarding

func (h *EngineManager) Forwarding(nodeID string, msg types.Message) error

Forwarding is used to forward the messages and determine whether forwarding is required according to the message type.

Note:

  1. message type that need to be forwarded: PrepareBlockMsg/PrepareVoteMsg/ViewChangeMsg/BlockQuorumCertMsg
  2. message type that need not to be forwarded: (Except for the above types, the rest are not forwarded).

func (*EngineManager) MarkBlacklist

func (h *EngineManager) MarkBlacklist(peerID string)

MarkBlacklist marks the specified node as a blacklist. If the number of recorded blacklists reaches the threshold, the node that was first set to blacklist will be removed from the blacklist.

func (*EngineManager) MarkHistoryMessageHash

func (h *EngineManager) MarkHistoryMessageHash(hash common.Hash)

MarkHistoryMessageHash is used to record the hash value of each message from the peer node. If the queue is full, remove the bottom element and add a new one.

func (*EngineManager) NodeInfo

func (h *EngineManager) NodeInfo() *NodeInfo

NodeInfo returns the information of Node.

func (*EngineManager) PartBroadcast

func (h *EngineManager) PartBroadcast(msg types.Message)

PartBroadcast imports messages into the send queue.

Note: The broadcast of this method defaults to PartMode.

func (*EngineManager) PeerSetting

func (h *EngineManager) PeerSetting(peerID string, bType uint64, blockNumber uint64) error

PeerSetting sets the block height of the node related type.

func (*EngineManager) Protocols

func (h *EngineManager) Protocols() []p2p.Protocol

Protocols implemented the Protocols method and returned basic information about the CBFT protocol.

func (*EngineManager) RemoveMessageHash

func (h *EngineManager) RemoveMessageHash(id string, msgHash common.Hash)

RemoveMessageHash removes the specified hash from the peer.

func (*EngineManager) RemovePeer

func (h *EngineManager) RemovePeer(id string)

RemovePeer removes and disconnects a node from a neighbor node.

func (*EngineManager) Send

func (h *EngineManager) Send(peerID string, msg types.Message)

Send imports messages into the send queue and send it according to the specified ID.

func (*EngineManager) SetSendQueueHook

func (h *EngineManager) SetSendQueueHook(f func(*ctpyes.MsgPackage))

SetSendQueueHook

func (*EngineManager) Start

func (h *EngineManager) Start()

Start the loop to send message.

func (*EngineManager) Testing

func (h *EngineManager) Testing()

Testing is only used for unit testing.

func (*EngineManager) Unregister

func (h *EngineManager) Unregister(id string) error

Unregister removes the peer with the specified ID.

type NodeInfo

type NodeInfo struct {
	Config types.Config `json:"config"`
}

NodeInfo representatives node configuration information.

type PeerInfo

type PeerInfo struct {
	ProtocolVersion int    `json:"protocolVersion"`
	HighestQCBn     uint64 `json:"highestQCBn"`
	LockedBn        uint64 `json:"lockedBn"`
	CommitBn        uint64 `json:"commitBn"`
}

PeerInfo represents the node information of the CBFT protocol.

type PeerSet

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

PeerSet represents the collection of active peers currently participating in the Cbft protocol.

func NewPeerSet

func NewPeerSet() *PeerSet

NewPeerSet creates a new PeerSet to track the active participants.

func (*PeerSet) Close

func (ps *PeerSet) Close()

Close disconnects all peers. No new peers can be registered after Close has returned.

func (*PeerSet) Len

func (ps *PeerSet) Len() int

Len returns if the current number of peers in the set.

func (*PeerSet) Register

func (ps *PeerSet) Register(p *peer) error

Register injects a new peer into the working set, or returns an error if the peer is already known. If a new peer it registered, its broadcast loop is also started.

func (*PeerSet) Unregister

func (ps *PeerSet) Unregister(id string) error

Unregister removes a remote peer from the active set, disabling any further actions to/from that particular entity.

Jump to

Keyboard shortcuts

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