p2p

package
v1.0.0-alpha.24 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NeighborsSendQueueSize = 20_000
)

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 (m *Manager) AddManualPeer(multiAddr multiaddr.Multiaddr) (*network.Peer, error)

func (*Manager) AutopeeringNeighbors

func (m *Manager) AutopeeringNeighbors() []network.Neighbor

AutopeeringNeighbors returns all the neighbors that are currently connected via autopeering.

func (*Manager) DialPeer

func (m *Manager) DialPeer(ctx context.Context, peer *network.Peer) error

DialPeer connects to a peer.

func (*Manager) DisconnectNeighbor

func (m *Manager) DisconnectNeighbor(id peer.ID) error

DisconnectNeighbor disconnects the neighbor with the given ID.

func (*Manager) LocalPeerID

func (m *Manager) LocalPeerID() peer.ID

LocalPeerID returns the local peer ID.

func (*Manager) ManualPeer

func (m *Manager) ManualPeer(id peer.ID) (*network.Peer, error)

func (*Manager) ManualPeers

func (m *Manager) ManualPeers(onlyConnected ...bool) []*network.Peer

func (*Manager) Neighbor

func (m *Manager) Neighbor(id peer.ID) (network.Neighbor, error)

Neighbor returns the neighbor with the given ID.

func (*Manager) NeighborExists

func (m *Manager) NeighborExists(id peer.ID) bool

func (*Manager) Neighbors

func (m *Manager) Neighbors() []network.Neighbor

Neighbors returns all the neighbors that are currently connected.

func (*Manager) OnNeighborAdded

func (m *Manager) OnNeighborAdded(handler func(network.Neighbor)) *event.Hook[func(network.Neighbor)]

func (*Manager) OnNeighborRemoved

func (m *Manager) OnNeighborRemoved(handler func(network.Neighbor)) *event.Hook[func(network.Neighbor)]

func (*Manager) P2PHost

func (m *Manager) P2PHost() host.Host

P2PHost returns the lib-p2p host.

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

func (m *Manager) RemovePeer(id peer.ID) error

RemovePeer disconnects the neighbor with the given ID and removes it from manual peering in case it was added manually.

func (*Manager) Send

func (m *Manager) Send(packet proto.Message, to ...peer.ID)

Send sends a message with the specific protocol to a set of neighbors.

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 PacketReceivedFunc func(neighbor *neighbor, packet proto.Message)

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 (*PeerConfigItem) ID

type ProtocolHandler

type ProtocolHandler struct {
	PacketFactory func() proto.Message
	PacketHandler func(peer.ID, proto.Message) error
}

ProtocolHandler holds callbacks to handle a protocol.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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