p2p

package
v1.10.3-0...-b3aebb6 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: LGPL-3.0 Imports: 37 Imported by: 1

Documentation

Overview

package p2p

Index

Constants

View Source
const (
	// SetAsideForConsensus set the number of active validation goroutines for the consensus topic
	SetAsideForConsensus = 1 << 13
	// SetAsideOtherwise set the number of active validation goroutines for other topic
	SetAsideOtherwise = 1 << 11
	// MaxMessageHandlers ..
	MaxMessageHandlers = SetAsideForConsensus + SetAsideOtherwise
	// MaxMessageSize is 2Mb
	MaxMessageSize = 1 << 21
)

Variables

This section is empty.

Functions

func ConstructMessage added in v1.3.8

func ConstructMessage(content []byte) []byte

ConstructMessage constructs the p2p message as [messageType, contentSize, content]

func NewGater

func NewGater(disablePrivateIPScan bool) connmgr.ConnectionGater

Types

type ConnectCallback

type ConnectCallback func(net libp2p_network.Network, conn libp2p_network.Conn) error

type ConnectCallbacks

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

func (*ConnectCallbacks) Add

func (a *ConnectCallbacks) Add(cb ConnectCallback)

func (*ConnectCallbacks) GetAll

func (a *ConnectCallbacks) GetAll() []ConnectCallback

type Counter

type Counter struct {
	*metrics.BandwidthCounter
}

Counter is a wrapper around a metrics.BandwidthCounter that meters both the inbound and outbound network traffic.

func (*Counter) LogRecvMessage

func (c *Counter) LogRecvMessage(size int64)

func (*Counter) LogSentMessage

func (c *Counter) LogSentMessage(size int64)

type DisconnectCallback

type DisconnectCallback func(conn libp2p_network.Conn) error

type DisconnectCallbacks

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

func (*DisconnectCallbacks) Add

func (*DisconnectCallbacks) GetAll

type Gater

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

func (Gater) InterceptAccept

func (gater Gater) InterceptAccept(network.ConnMultiaddrs) (allow bool)

func (Gater) InterceptAddrDial

func (gater Gater) InterceptAddrDial(p peer.ID, m ma.Multiaddr) (allow bool)

Blocking connections at this stage is typical for address filtering.

func (Gater) InterceptPeerDial

func (gater Gater) InterceptPeerDial(p peer.ID) (allow bool)

func (Gater) InterceptSecured

func (gater Gater) InterceptSecured(network.Direction, peer.ID, network.ConnMultiaddrs) (allow bool)

func (Gater) InterceptUpgraded

func (gater Gater) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)

NOTE: the go-libp2p implementation currently IGNORES the disconnect reason.

type Host

type Host interface {
	Start() error
	Close() error
	GetSelfPeer() Peer
	AddPeer(*Peer) error
	GetID() libp2p_peer.ID
	GetP2PHost() libp2p_host.Host
	GetDiscovery() discovery.Discovery
	GetPeerCount() int
	ConnectHostPeer(Peer) error
	// AddStreamProtocol add the given protocol
	AddStreamProtocol(protocols ...sttypes.Protocol)
	// SendMessageToGroups sends a message to one or more multicast groups.
	SendMessageToGroups(groups []nodeconfig.GroupID, msg []byte) error
	PubSub() *libp2p_pubsub.PubSub
	PeerConnectivity() (int, int, int)
	GetOrJoin(topic string) (*libp2p_pubsub.Topic, error)
	ListPeer(topic string) []libp2p_peer.ID
	ListTopic() []string
	ListBlockedPeer() []libp2p_peer.ID
}

Host is the client + server in p2p network.

func NewHost added in v1.3.8

func NewHost(cfg HostConfig) (Host, error)

NewHost ..

type HostConfig

type HostConfig struct {
	Self                     *Peer
	BLSKey                   libp2p_crypto.PrivKey
	BootNodes                []string
	DataStoreFile            *string
	DiscConcurrency          int
	MaxConnPerIP             int
	DisablePrivateIPScan     bool
	MaxPeers                 int64
	ConnManagerLowWatermark  int
	ConnManagerHighWatermark int
	WaitForEachPeerToConnect bool
	ForceReachabilityPublic  bool
}

HostConfig is the config structure to create a new host

type HostV2 added in v1.3.8

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

HostV2 is the version 2 p2p host

func (*HostV2) AddPeer added in v1.3.8

func (host *HostV2) AddPeer(p *Peer) error

AddPeer add p2p.Peer into Peerstore

func (*HostV2) AddStreamProtocol

func (host *HostV2) AddStreamProtocol(protocols ...sttypes.Protocol)

AddStreamProtocol adds the stream protocols to the host to be started and closed when the host starts or close

func (*HostV2) Close

func (host *HostV2) Close() error

Close closes the HostV2.

func (*HostV2) ClosedStream

func (host *HostV2) ClosedStream(net libp2p_network.Network, stream libp2p_network.Stream)

called when a stream closed

func (*HostV2) ConnectHostPeer added in v1.3.8

func (host *HostV2) ConnectHostPeer(peer Peer) error

ConnectHostPeer connects to peer host

func (*HostV2) Connected

func (host *HostV2) Connected(net libp2p_network.Network, conn libp2p_network.Conn)

called when a connection opened

func (*HostV2) Disconnected

func (host *HostV2) Disconnected(net libp2p_network.Network, conn libp2p_network.Conn)

called when a connection closed

func (*HostV2) GetDiscovery

func (host *HostV2) GetDiscovery() discovery.Discovery

GetDiscovery returns the underlying discovery

func (*HostV2) GetID added in v1.3.8

func (host *HostV2) GetID() libp2p_peer.ID

GetID returns ID.Pretty

func (*HostV2) GetOrJoin added in v1.10.0

func (host *HostV2) GetOrJoin(topic string) (*libp2p_pubsub.Topic, error)

GetOrJoin ..

func (*HostV2) GetP2PHost added in v1.3.8

func (host *HostV2) GetP2PHost() libp2p_host.Host

GetP2PHost returns the p2p.Host

func (*HostV2) GetPeerCount added in v1.3.8

func (host *HostV2) GetPeerCount() int

GetPeerCount ...

func (*HostV2) GetSelfPeer added in v1.3.8

func (host *HostV2) GetSelfPeer() Peer

GetSelfPeer gets self peer

func (*HostV2) ListBlockedPeer added in v1.10.0

func (host *HostV2) ListBlockedPeer() []libp2p_peer.ID

ListBlockedPeer returns list of blocked peer

func (*HostV2) ListPeer added in v1.10.0

func (host *HostV2) ListPeer(topic string) []libp2p_peer.ID

ListPeer returns list of peers in a topic

func (*HostV2) ListTopic added in v1.10.0

func (host *HostV2) ListTopic() []string

ListTopic returns the list of topic the node subscribed

func (*HostV2) Listen

func (host *HostV2) Listen(net libp2p_network.Network, addr ma.Multiaddr)

called when network starts listening on an addr

func (*HostV2) ListenClose

func (host *HostV2) ListenClose(net libp2p_network.Network, addr ma.Multiaddr)

called when network stops listening on an addr

func (*HostV2) OpenedStream

func (host *HostV2) OpenedStream(net libp2p_network.Network, stream libp2p_network.Stream)

called when a stream opened

func (*HostV2) PeerConnectivity

func (host *HostV2) PeerConnectivity() (int, int, int)

PeerConnectivity returns total number of known, connected and not connected peers.

func (*HostV2) Peerstore added in v1.3.8

func (host *HostV2) Peerstore() libp2p_peerstore.Peerstore

Peerstore returns the peer store

func (*HostV2) PubSub added in v1.10.0

func (host *HostV2) PubSub() *libp2p_pubsub.PubSub

PubSub ..

func (*HostV2) SendMessageToGroups added in v1.3.8

func (host *HostV2) SendMessageToGroups(groups []nodeconfig.GroupID, msg []byte) (err error)

SendMessageToGroups sends a message to one or more multicast groups. It returns a nil error if and only if it has succeeded to schedule the given message for sending.

func (*HostV2) SetConnectCallback

func (host *HostV2) SetConnectCallback(callback ConnectCallback)

func (*HostV2) SetDisconnectCallback

func (host *HostV2) SetDisconnectCallback(callback DisconnectCallback)

func (*HostV2) Start

func (host *HostV2) Start() error

Start start the HostV2 discovery process TODO: move PubSub start handling logic here

type NamedTopic added in v1.10.0

type NamedTopic struct {
	Name  string
	Topic *libp2p_pubsub.Topic
}

NamedTopic represents pubsub topic Name is the human readable topic, groupID

type Peer

type Peer struct {
	IP              string         // IP address of the peer
	Port            string         // Port number of the peer
	ConsensusPubKey *bls.PublicKey // Public key of the peer, used for consensus signing
	Addrs           []ma.Multiaddr // MultiAddress of the peer
	PeerID          libp2p_peer.ID // PeerID, the pubkey for communication
}

Peer is the object for a p2p peer (node)

Jump to

Keyboard shortcuts

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