p2p/host/host library

Host implementations for libp2p.

This package provides implementations of the Host interface.

Classes

AddrSub
A subscription to address updates.
AddrSubManager
A manager for address subscriptions.
BasicBus
BasicBus is a type-based event delivery system
BasicHost
BasicHost is the basic implementation of the Host interface. This particular host implementation:
ExpiringAddr
An address with an expiration time.
MemoryAddrBook
A memory-based implementation of the AddrBook interface.
MemoryKeyBook
A memory-based implementation of the KeyBook interface.
MemoryMetrics
A memory-based implementation of the Metrics interface.
MemoryPeerMetadata
A memory-based implementation of the PeerMetadata interface.
MemoryPeerstore
A memory-based implementation of the Peerstore interface.
MemoryProtoBook
A memory-based implementation of the ProtoBook interface.
MetricsTracer
Metrics for the EventBus implementation.
NATManager
NATManager is a production-ready interface to manage NAT devices and mappings. It leverages advanced NAT discovery, behavior tracking, and mapping logic.
NoopMetricsTracer
A no-op implementation of MetricsTracer that does nothing
OutboundCapabilityInfo
Information about local outbound connectivity capabilities
PeerAddrs
A collection of peer addresses.
PeerRecordState
PeerstoreManager
PeerstoreManager manages the peerstore by removing peers that have disconnected and haven't reconnected within a grace period.
ProtoSegment
A segment of the protocol book, used for sharding.
SimpleMetricsTracer
A simple implementation of MetricsTracer that logs metrics to the console

Enums

OutboundCapability
Outbound network capability types

Constants

defaultMaxSignedPeerRecords → const int
defaultMaxUnconnectedAddrs → const int
defaultNegotiationTimeout → const Duration
Default negotiation timeout
latencyEWMASmoothing → const double
The smoothing factor for the exponentially weighted moving average.

Functions

bufSize(int size) → SubscriptionOpt
Option to set the buffer size for a subscription
createMetricsTracer({bool simple = false}) → MetricsTracer
Creates a new MetricsTracer
defaultAddrsFactory(List<MultiAddr> addrs) → List<MultiAddr>
Default addresses factory function. Filters out loopback and unspecified addresses from the provided list.
name(String name) → SubscriptionOpt
Option to set the name for a subscription
newAddrBook({int maxUnconnectedAddrs = 1000000}) → MemoryAddrBook
Creates a new memory-based address book implementation.
newKeyBook() → MemoryKeyBook
Creates a new memory-based key book implementation.
newMetrics() → MemoryMetrics
Creates a new memory-based metrics implementation.
newNATManager(Network net, {StunClientPool? stunClientPool, Duration? behaviorCheckInterval}) → NATManager
Creates a new NAT manager.
newPeerMetadata() → MemoryPeerMetadata
Creates a new memory-based peer metadata implementation.
newPeerstore({MemoryMetrics? metrics, MemoryKeyBook? keyBook, MemoryAddrBook? addrBook, MemoryProtoBook? protoBook, MemoryPeerMetadata? peerMetadata}) → MemoryPeerstore
Creates a new memory-based peerstore implementation.
newProtoBook({int maxProtos = 128}) → MemoryProtoBook
Creates a new memory-based protocol book implementation.
stateful() → EmitterOpt
Option to make an emitter stateful
ttlIsConnected(Duration ttl) → bool
Returns true if the TTL is at least as long as the connected TTL.
withCleanupInterval(Duration interval) → Option
WithCleanupInterval set the clean up interval. During a clean up run peers that disconnected before the grace period are removed. If unset, the interval is set to half the grace period.
withGracePeriod(Duration period) → Option
WithGracePeriod sets the grace period. If a peer doesn't reconnect during the grace period, its data is removed. Default: 1 minute.
withMetricsTracer(MetricsTracer metricsTracer) → BusOption
Option to set the metrics tracer for a bus

Typedefs

Option = dynamic Function(PeerstoreManager)
A function that configures a PeerstoreManager.

Exceptions / Errors

ErrTooManyProtocols
Error thrown when too many protocols are added for a peer.