Documentation ¶
Index ¶
- Constants
- type ComparablePeerID
- type ConfigManager
- func (pm *ConfigManager) AddPeer(multiAddress multiaddr.Multiaddr, alias string) error
- func (pm *ConfigManager) Peer(peerID peer.ID) *PeerConfigItem
- func (pm *ConfigManager) Peers() []*PeerConfigItem
- func (pm *ConfigManager) RemovePeer(peerID peer.ID) error
- func (pm *ConfigManager) Store() error
- func (pm *ConfigManager) StoreOnChange(enabled bool)
- type Manager
- func (m *Manager) AddManualPeer(multiAddr multiaddr.Multiaddr) (*network.Peer, error)
- func (m *Manager) AutopeeringNeighbors() []network.Neighbor
- func (m *Manager) DialPeer(ctx context.Context, peer *network.Peer) error
- func (m *Manager) DisconnectNeighbor(id peer.ID) error
- func (m *Manager) LocalPeerID() peer.ID
- func (m *Manager) ManualPeer(id peer.ID) (*network.Peer, error)
- func (m *Manager) ManualPeers(onlyConnected ...bool) []*network.Peer
- func (m *Manager) Neighbor(id peer.ID) (network.Neighbor, error)
- func (m *Manager) NeighborExists(id peer.ID) bool
- func (m *Manager) Neighbors() []network.Neighbor
- func (m *Manager) OnNeighborAdded(handler func(network.Neighbor)) *event.Hook[func(network.Neighbor)]
- func (m *Manager) OnNeighborRemoved(handler func(network.Neighbor)) *event.Hook[func(network.Neighbor)]
- func (m *Manager) P2PHost() host.Host
- func (m *Manager) RegisterProtocol(factory func() proto.Message, handler func(peer.ID, proto.Message) error)
- func (m *Manager) RemovePeer(id peer.ID) error
- func (m *Manager) Send(packet proto.Message, to ...peer.ID)
- func (m *Manager) Shutdown()
- func (m *Manager) Start(ctx context.Context, networkID string, bootstrapPeers []peer.AddrInfo) error
- func (m *Manager) UnregisterProtocol()
- type Metrics
- type NeighborConnectedFunc
- type NeighborDisconnectedFunc
- type PacketReceivedFunc
- type PacketsStream
- type PeerConfig
- type PeerConfigItem
- type ProtocolHandler
Constants ¶
const ( NeighborsSendQueueSize = 20_000 DroppedPacketDisconnectThreshold = 100 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ComparablePeerID ¶
type ComparablePeerID struct {
// contains filtered or unexported fields
}
ComparablePeerID implements the constraints.ComparableStringer interface for the onChangeMap.
func NewComparablePeerID ¶
func NewComparablePeerID(peerID peer.ID) *ComparablePeerID
func (*ComparablePeerID) Key ¶
func (c *ComparablePeerID) Key() string
func (*ComparablePeerID) String ¶
func (c *ComparablePeerID) String() string
type ConfigManager ¶
type ConfigManager struct {
// contains filtered or unexported fields
}
ConfigManager handles the list of peers that are stored in the peering config. It calls a function if the list changed.
func NewConfigManager ¶
func NewConfigManager(storeCallback func([]*PeerConfigItem) error) *ConfigManager
NewConfigManager creates a new config manager.
func (*ConfigManager) AddPeer ¶
func (pm *ConfigManager) AddPeer(multiAddress multiaddr.Multiaddr, alias string) error
AddPeer adds a peer to the config manager.
func (*ConfigManager) Peer ¶
func (pm *ConfigManager) Peer(peerID peer.ID) *PeerConfigItem
Peer returns a peer by its ID.
func (*ConfigManager) Peers ¶
func (pm *ConfigManager) Peers() []*PeerConfigItem
Peers returns all known peers.
func (*ConfigManager) RemovePeer ¶
func (pm *ConfigManager) RemovePeer(peerID peer.ID) error
RemovePeer removes a peer from the config manager.
func (*ConfigManager) Store ¶
func (pm *ConfigManager) Store() error
Store calls the storeCallback if storeOnChange is active.
func (*ConfigManager) StoreOnChange ¶
func (pm *ConfigManager) StoreOnChange(enabled bool)
StoreOnChange sets whether storing changes to the config is active or not.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
The Manager handles the connected neighbors.
func NewManager ¶
func NewManager(logger log.Logger, libp2pHost host.Host, maxAutopeeringPeers int, allowLocalAutopeering bool, onBlockSentCallback func()) *Manager
NewManager creates a new Manager.
func (*Manager) AddManualPeer ¶
func (*Manager) AutopeeringNeighbors ¶
AutopeeringNeighbors returns all the neighbors that are currently connected via autopeering.
func (*Manager) DisconnectNeighbor ¶
DisconnectNeighbor disconnects the neighbor with the given ID.
func (*Manager) LocalPeerID ¶
LocalPeerID returns the local peer ID.
func (*Manager) OnNeighborAdded ¶
func (*Manager) OnNeighborRemoved ¶
func (*Manager) RegisterProtocol ¶
func (m *Manager) RegisterProtocol(factory func() proto.Message, handler func(peer.ID, proto.Message) error)
RegisterProtocol registers the handler for the protocol within the manager.
func (*Manager) RemovePeer ¶
RemovePeer disconnects the neighbor with the given ID and removes it from manual peering in case it was added manually.
func (*Manager) Shutdown ¶
func (m *Manager) Shutdown()
Shutdown stops the manager and closes all established connections.
func (*Manager) Start ¶
func (m *Manager) Start(ctx context.Context, networkID string, bootstrapPeers []peer.AddrInfo) error
Start starts the manager and initiates manual- and autopeering.
func (*Manager) UnregisterProtocol ¶
func (m *Manager) UnregisterProtocol()
UnregisterProtocol unregisters the handler for the protocol.
type Metrics ¶
type Metrics struct { // The number of total received blocks. IncomingBlocks atomic.Uint32 // The number of received blocks which are new. IncomingNewBlocks atomic.Uint32 // The number of sent blocks. OutgoingBlocks atomic.Uint32 }
Metrics defines P2P metrics over the entire runtime of the node.
type NeighborConnectedFunc ¶
type NeighborConnectedFunc func(neighbor *neighbor)
type NeighborDisconnectedFunc ¶
type NeighborDisconnectedFunc func(neighbor *neighbor)
type PacketReceivedFunc ¶
type PacketsStream ¶
type PacketsStream struct { p2pnetwork.Stream // contains filtered or unexported fields }
PacketsStream represents a stream of packets.
func NewPacketsStream ¶
func NewPacketsStream(stream p2pnetwork.Stream, packetFactory func() proto.Message) *PacketsStream
NewPacketsStream creates a new PacketsStream.
func (*PacketsStream) ReadPacket ¶
func (ps *PacketsStream) ReadPacket(message proto.Message) error
ReadPacket reads a packet from the stream.
func (*PacketsStream) WritePacket ¶
func (ps *PacketsStream) WritePacket(message proto.Message) error
WritePacket writes a packet to the stream.
type PeerConfig ¶
type PeerConfig struct { MultiAddress string `json:"multiAddress" koanf:"multiAddress"` Alias string `json:"alias" koanf:"alias"` }
PeerConfig holds the initial information about peers.
type PeerConfigItem ¶
type PeerConfigItem struct { *PeerConfig // contains filtered or unexported fields }
PeerConfigItem implements the Item interface for the onChangeMap.
func NewPeerConfigItem ¶
func NewPeerConfigItem(peerConfig *PeerConfig) (*PeerConfigItem, error)
func (*PeerConfigItem) Clone ¶
func (p *PeerConfigItem) Clone() onchangemap.Item[string, *ComparablePeerID]
func (*PeerConfigItem) ID ¶
func (p *PeerConfigItem) ID() *ComparablePeerID