dart_libp2p library

Classes

AddrBook
AddrBook holds the multiaddrs of peers.
AddrDelay
AddrDelay provides an address along with the delay after which the address should be dialed
AddressTTL
TTL values for addresses
AddrInfo
Represents a peer with its addresses
Advertiser
Interface for advertising services
AutoNATV1Client
Interface for the AutoNAT v1 client.
AutoNATv2
Interface for the AutoNAT v2 service
AutoNATv2Client
Interface for the AutoNAT v2 client
AutoNATv2Protocols
Protocol names for AutoNAT v2
AutoNATv2Server
Interface for the AutoNAT v2 server
CertifiedAddrBook
Envelope contains a signed payload produced by a peer. This is a placeholder for the actual Envelope class that would be defined in the record module. When the record module is implemented, this should be replaced with the actual Envelope class.
Conn
Conn is a connection to a remote peer. It multiplexes streams. Usually there is no need to use a Conn directly, but it may be useful to get information about the peer on the other side:
ConnGater
ConnGater can be implemented by a type that supports active inbound or outbound Conn gating.
ConnManagementScope
ConnManagementScope is the low level interface for connection resource scopes.
ConnManager
ConnManager tracks connections to peers, and allows consumers to associate metadata with each peer.
ConnScope
ConnScope is the user view of a connection scope.
ConnState
ConnectionState holds information about the connection.
ConnStats
ConnStats stores metadata pertaining to a given Conn.
ContentDiscovery
ContentDiscovery is able to retrieve providers for a given CID using the Routing system.
ContentProviding
ContentProviding is able to announce where to find content on the Routing system.
ContentRouting
ContentRouting is a value provider layer of indirection. It is used to find information about who has what content.
Context
Context class for network operations
Decayer
Decayer is implemented by connection managers supporting decaying tags.
DecayingTag
Represents a decaying tag. The tag is a long-lived general object, used to operate on tag values for peers.
DecayingValue
A decaying tag is one whose value automatically decays over time.
Dialer
Dialer represents a service that can dial out to peers
DisconnectReason
Represents a reason for disconnecting from a peer. This is used to communicate the intention behind a Conn closure.
Discoverer
Interface for peer discovery
Discovery
Interface that combines service advertisement and peer discovery
DiscoveryOptions
Options for discovery operations
EcdsaPrivateKey
Implementation of ECDSA private key
EcdsaPublicKey
Implementation of ECDSA public key
Ed25519PrivateKey
Implementation of Ed25519 private key
Ed25519PublicKey
Implementation of Ed25519 public key
Emitter
Emitter represents an actor that emits events onto the eventbus.
Envelope
Envelope contains an arbitrary Uint8List payload, signed by a libp2p peer.
EventBus
Bus is an interface for a type-based event delivery system.
EventDialRequestCompleted
Event for dial request completion
EvtLocalAddressesUpdated
EvtLocalAddressesUpdated should be emitted when the set of listen addresses for the local host changes. This may happen for a number of reasons. For example, we may have opened a new relay connection, established a new NAT mapping via UPnP, or been informed of our observed address by another peer.
EvtLocalProtocolsUpdated
EvtLocalProtocolsUpdated should be emitted when stream handlers are attached or detached from the local host. For handlers attached with a matcher predicate (host.setStreamHandlerMatch()), only the protocol ID will be included in this event.
EvtLocalReachabilityChanged
Reachability-related events for libp2p.
EvtNATDeviceTypeChanged
EvtNATDeviceTypeChanged is an event struct to be emitted when the type of the NAT device changes for a Transport Protocol.
EvtPeerConnectednessChanged
EvtPeerIdentificationCompleted
EvtPeerIdentificationCompleted is emitted when the initial identification round for a peer is completed.
EvtPeerIdentificationFailed
EvtPeerIdentificationFailed is emitted when the initial identification round for a peer failed.
EvtPeerProtocolsUpdated
EvtPeerProtocolsUpdated should be emitted when a peer we're connected to adds or removes protocols from their stack.
GenericDHTEvent
GenericDHTEvent is a type that encapsulates an actual DHT event by carrying its raw JSON.
GetConnLimiter
Provides access to a component's total connection limit.
Host
Host is an object participating in a p2p network, which implements protocols or provides services. It handles requests like a Server, and issues requests like a Client. It is called Host because it is both Server and Client (and Peer may be confusing).
Key
Represents a cryptographic key
KeyBook
KeyBook tracks the keys of Peers.
KeyPair
Represents a key pair (public + private key)
Metrics
Metrics tracks metrics across a set of peers.
MetricsTracer
Interface for metrics tracing
MultiAddr
Represents a multiaddress
MultiaddrDNSResolver
MultiaddrDNSResolver resolves DNS multiaddrs
Multiplexer
Multiplexer wraps a connection with a stream multiplexing implementation and returns a MuxedConn that supports opening multiple streams over the underlying connection
MuxedConn
MuxedConn represents a connection to a remote peer that has been extended to support stream multiplexing.
MuxedStream
MuxedStream is a bidirectional io pipe within a connection.
Negotiator
Negotiator is a component capable of reaching agreement over what protocols to use for inbound streams of communication.
Network
Network is the interface used to connect to the outside world. It dials and listens for connections. it uses a Swarm to pool connections. Connections are encrypted with a TLS-like protocol.
NoopConnGater
A no-op implementation of ConnGater that allows all Conns.
NoopNotifiee
NoopNotifiee is a no-op implementation of Notifiee
Notifiee
Notifiee is an interface for an object wishing to receive notifications from a Network.
NotifyBundle
NotifyBundle implements Notifiee by calling any of the functions set on it, and nop'ing if they are unset. This is the easy way to register for notifications.
NullResourceManager
NullResourceManager is a stub for tests and initialization of default values
NullScope
NullScope is a stub for tests and initialization of default values
P2PStream<T>
Represents a bidirectional channel between two agents in a libp2p network. "agent" is as granular as desired, potentially being a "request -> reply" pair, or whole protocols.
PeerId
Implementation of PeerId that follows the libp2p specification
PeerInfo
Metadata about a peer
PeerMetadata
PeerMetadata can handle values of any type. Serializing values is up to the implementation. Dynamic type introspection may not be supported, in which case explicitly enlisting types in the serializer may be required.
PeerRecord
PeerRecord contains information that is broadly useful to share with other peers, either through a direct exchange (as in the libp2p identify protocol), or through a Peer Routing provider, such as a DHT.
PeerRouting
PeerRouting is a way to find address information about certain peers. This can be implemented by a simple lookup table, a tracking server, or even a DHT.
PeerScope
PeerScope is the interface for peer resource scopes.
Peerstore
Peerstore provides a thread-safe store of Peer related information.
PeerStoreConfig
Configuration for the peer store
PrivateKey
Represents a private key
ProtoBook
ProtoBook tracks the protocols supported by peers.
ProtocolIDUtil
Utility functions for protocol IDs
ProtocolScope
ProtocolScope is the interface for protocol resource scopes.
ProtocolSwitch
Switch is the component responsible for "dispatching" incoming stream requests to their corresponding stream handlers. It is both a Negotiator and a Router.
PubKeyFetcher
PubKeyFetcher is an interface that should be implemented by value stores that can optimize retrieval of public keys.
PublicKey
Represents a public key
QueryEvent
QueryEvent is emitted for every notable event that happens during a DHT query.
QueryEventManager
A class to manage query event subscriptions.
QueryEventRegistry
A registry for query event managers.
RecordBase
RecordRegistry
Type-safe registry for record types
Request
Request to verify reachability of a single address
ReservationPriority
Reservation priorities
ReservedProtocolIDs
These are reserved protocol IDs.
ResourceManager
ResourceManager is the interface for managing resources in libp2p.
ResourceScope
ResourceScope is the interface for all scopes.
ResourceScopeSpan
ResourceScopeSpan is a ResourceScope with a delimited span.
ResourceScopeViewer
ResourceScopeViewer is a mixin interface providing view methods for accessing top level scopes.
Result
Result of the CheckReachability call
Router
Router is an interface that allows users to add and remove protocol handlers, which will be invoked when incoming stream requests for registered protocols are accepted.
Routing
Routing is the combination of different routing types supported by libp2p. It can be satisfied by a single item (such as a DHT) or multiple different pieces that are more optimized to each task.
RoutingOptions
Options for routing operations.
RsaPrivateKey
Implementation of RSA private key
RsaPublicKey
Implementation of RSA public key
ScopeStat
ScopeStat is a struct containing resource accounting information.
ServiceScope
ServiceScope is the interface for service resource scopes
Stats
Stats stores metadata pertaining to a given Stream / Conn.
StreamManagementScope
StreamManagementScope is the interface for stream resource scopes.
StreamScope
StreamScope is the user view of a StreamScope.
StreamStats
Stores metadata pertaining to a given Stream
Subscription<T>
Subscription represents a subscription to one or multiple event types.
TagInfo
Package connmgr provides connection tracking and management interfaces for libp2p.
TransportConn
TransportConn extends the Conn interface with methods for reading and writing raw data. This is used by transport implementations that need to send and receive data directly.
UpdatedAddress
UpdatedAddress is used in the EvtLocalAddressesUpdated event to convey address change information.
ValueStore
ValueStore is a basic Put/Get interface.

Enums

AddrAction
AddrAction represents an action taken on one of a Host's listen addresses. It is used to add context to address change events in EvtLocalAddressesUpdated.
AddressType
Address type classification for connection prioritization
Connectedness
Connectedness signals the capacity for a connection with a given node. It is used to signal to services and other peers whether a node is reachable.
Direction
Common types used by both conn.dart and rcmgr.dart to avoid circular dependencies Direction specifies whether this is an inbound or an outbound connection.
NATDeviceType
NATDeviceType indicates the type of the NAT device.
NATTransportProtocol
NATTransportProtocol is the transport protocol for which the NAT Device Type has been determined.
QueryEventType
QueryEventType indicates the query event's type.
Reachability
Reachability indicates how reachable a node is.

Extensions

MultiAddrClassification on MultiAddr
Extension for address classification and analysis

Constants

autoNATV1Proto → const String
Protocol ID for AutoNAT v1.0.0
maxRsaKeyBits → const int
Maximum RSA key size in bits
messageSizeMax → const int
MessageSizeMax is a soft (recommended) maximum for network messages. One can write more, as the interface is a stream. But it is useful to bunch it up into multiple read/writes when the whole message is a single, large serialized object.
minRsaKeyBits → const int
Minimum RSA key size in bits
PeerRecordEnvelopeDomain → const String
queryEventBufferSize → const int
Number of events to buffer.

Properties

ECDSACurve → ECDomainParameters
The default ECDSA curve used (P-256)
final
expired Option
An option that tells the routing system to return expired records when no newer records are known.
getter/setter pair
globalNoopNotifiee NoopNotifiee
Global noop notifiee. Do not change.
final
offline Option
An option that tells the routing system to operate offline (i.e., rely on cached/local data only).
getter/setter pair
PeerRecordEnvelopePayloadType Uint8List
final
PubKeyUnmarshallers Map<KeyType, PublicKey Function(Uint8List)>
getter/setter pair
WildcardSubscription → _WildcardSubscriptionType
WildcardSubscription is the type to subscribe to receive all events emitted in the eventbus.
final

Functions

bumpOverwrite() BumpFn
Replaces the current value of the tag with the incoming one.
bumpSumBounded(int min, int max) BumpFn
Keeps summing the incoming score, keeping it within a min, max range.
bumpSumUnbounded() BumpFn
Common bump functions Adds the incoming value to the peer's score.
decayExpireWhenInactive(Duration after) DecayFn
Expires a tag after a certain period of no bumps.
decayFixed(int minuend) DecayFn
Subtracts from by the provided minuend, and deletes the tag when first reaching 0 or negative.
decayLinear(double coef) DecayFn
Applies a fractional coefficient to the value of the current tag, rounding down. It erases the tag when the result is zero.
decayNone() DecayFn
Common decay functions Applies no decay.
generateEcdsaKeyPair() Future<KeyPair>
Generate a new ECDSA key pair
generateEd25519KeyPair() Future<KeyPair>
Generate a new Ed25519 key pair
generateEd25519KeyPairFromSeed(Uint8List privateKeySeed) Future<KeyPair>
generateRsaKeyPair({int bits = 2048}) Future<KeyPair>
Generate a new RSA key pair with the specified number of bits
getCertifiedAddrBook(dynamic ab) → (bool, CertifiedAddrBook?)
GetCertifiedAddrBook is a helper to "upcast" an AddrBook to a CertifiedAddrBook by using type assertion. If the given AddrBook is also a CertifiedAddrBook, it will be returned, and the ok return value will be true. Returns (null, false) if the AddrBook is not a CertifiedAddrBook.
getPublicKey(ValueStore store, PeerId id) Future
Retrieves the public key associated with the given peer ID from the value store.
infoFromHost(Host h) AddrInfo
InfoFromHost returns an AddrInfo struct with the Host's ID and all of its Addrs.
isTimeoutException(Object exception) bool
Helper function to determine if an exception is a timeout-related error.
keyForPublicKey(PeerId id) String
Returns the key used to retrieve public keys from a value store.
limit(int limit) DiscoveryOption
Creates an option that sets the limit
publicKeyFromProto(PublicKey pmes) PublicKey
ttl(Duration duration) DiscoveryOption
Creates an option that sets the TTL
unmarshalEnvelopeFromProto(Uint8List data) Envelope
Unmarshals a serialized Envelope protobuf message, without validating its contents.
unmarshalRsaPublicKey(Uint8List bytes) PublicKey
Creates an RsaPublicKey from its protobuf bytes
wrapIdentifyException({required PeerId peerId, required Object exception, Duration? timeout}) IdentifyException
Helper function to wrap a generic exception into an appropriate IdentifyException subtype.

Typedefs

AddrsFactory = List<MultiAddr> Function(List<MultiAddr> addrs)
AddrsFactory functions can be passed to a Host to override addresses returned by Addrs.
BumpFn = int Function(DecayingValue value, int delta)
BumpFn applies a delta onto an existing score, and returns the new score.
CancelFunc = dynamic Function()
A function that closes a subscriber.
DecayFn = (int, bool) Function(DecayingValue value)
DecayFn applies a decay to the peer's score. The implementation must call DecayFn at the interval supplied when registering the tag.
DialRanker = List<AddrDelay> Function(List<MultiAddr> addrs)
DialRanker provides a schedule of dialing the provided addresses
DiscoveryOption = DiscoveryOptions Function(DiscoveryOptions options)
A function that modifies DiscoveryOptions
EmitterOpt = dynamic Function(Object)
A function that represents an emitter option. Use the options exposed by the implementation of choice.
HandlerFunc = void Function(ProtocolID protocol, P2PStream stream)
HandlerFunc is a user-provided function used by the Router to handle a protocol/stream.
Option = dynamic Function(RoutingOptions options)
Options for routing operations.
ProtocolID = String
ProtocolID is a string identifier for a protocol.
RawJSON = String
DHT-related events for libp2p.
StreamHandler = Future<void> Function(P2PStream stream, PeerId remotePeer)
StreamHandler is the type of function used to listen for streams opened by the remote side.
SubscriptionOpt = dynamic Function(Object)
A function that represents a subscription option. Use the options exposed by the implementation of choice.

Exceptions / Errors

ConnectionFailedException
Thrown when connection establishment fails
ECDSAKeyException
Exception thrown when an ECDSA key is invalid
ErrNotFound
Error thrown when an item is not found in the peerstore.
IdentifyException
Base class for all identify-related exceptions.
IdentifyProtocolException
Exception thrown when identify protocol returns invalid/malformed data.
IdentifyStreamException
Exception thrown when identify stream negotiation fails.
IdentifyTimeoutException
Exception thrown when identify protocol negotiation times out.
Libp2pException
Base class for libp2p-related exceptions
LimitedConnException
Exception thrown when attempting to open a stream to a peer with only a limited connection, without specifying the AllowLimitedConn option.
NoConnException
Exception thrown when attempting to open a stream to a peer with the NoDial option and no usable connection is available.
NoRemoteAddrsException
Exception thrown when there are no addresses associated with a peer during a dial.
NotFoundError
Error thrown when a routing operation fails to find the requested record
NotSupportedError
Error thrown when a routing operation is not supported
ProtocolNegotiationException
Thrown when protocol negotiation fails
ResetException
Error thrown when reading or writing on a reset stream.
ResourceLimitExceededException
Exception thrown when attempting to perform an operation that would exceed system resource limits.
ResourceScopeClosedException
Exception thrown when attempting to reserve resources in a closed resource scope.
RsaKeyTooBigException
Exception thrown when an RSA key is too big
RsaKeyTooSmallException
Exception thrown when an RSA key is too small
TemporaryException
Exception thrown when a temporary error occurs
TransientConnException
Exception thrown when attempting to open a stream to a peer with only a transient connection, without specifying the UseTransient option.