@libp2p/interface-internal
Advanced tools
Comparing version 2.3.0-4ab04faf0 to 2.3.0-68ad3663e
@@ -51,5 +51,12 @@ import type { Multiaddr } from '@multiformats/multiaddr'; | ||
} | ||
/** | ||
* The `AddressManager` provides an interface for managing peer addresses | ||
* in libp2p. It supports handling multiple types of addresses, verifying their validity, | ||
* and storing mappings between internal and external addresses. | ||
*/ | ||
export interface AddressManager { | ||
/** | ||
* Get peer listen multiaddrs | ||
* | ||
* @returns An array of `Multiaddr` objects representing listen addresses. | ||
*/ | ||
@@ -59,2 +66,4 @@ getListenAddrs(): Multiaddr[]; | ||
* Get peer announcing multiaddrs | ||
* | ||
* @returns An array of `Multiaddr` objects representing announce addresses. | ||
*/ | ||
@@ -65,2 +74,4 @@ getAnnounceAddrs(): Multiaddr[]; | ||
* publicly dialable yet | ||
* | ||
* @returns An array of `Multiaddr` objects representing observed addresses. | ||
*/ | ||
@@ -71,2 +82,5 @@ getObservedAddrs(): Multiaddr[]; | ||
* this will make it appear in the output of getAddresses() | ||
* | ||
* @param addr - The observed address. | ||
* @param options - Additional options for confirmation. | ||
*/ | ||
@@ -77,2 +91,4 @@ confirmObservedAddr(addr: Multiaddr, options?: ConfirmAddressOptions): void; | ||
* this will remove it from the output of getObservedAddrs() | ||
* | ||
* @param addr - The observed address to remove. | ||
*/ | ||
@@ -84,2 +100,4 @@ removeObservedAddr(addr: Multiaddr): void; | ||
* confirmObservedAddr. | ||
* | ||
* @param addr - The observed address to add. | ||
*/ | ||
@@ -89,2 +107,4 @@ addObservedAddr(addr: Multiaddr): void; | ||
* Get the current node's addresses | ||
* | ||
* @returns An array of `Multiaddr` objects representing node addresses. | ||
*/ | ||
@@ -94,2 +114,4 @@ getAddresses(): Multiaddr[]; | ||
* Return all known addresses with metadata | ||
* | ||
* @returns An array of `NodeAddress` objects. | ||
*/ | ||
@@ -102,2 +124,5 @@ getAddressesWithMetadata(): NodeAddress[]; | ||
* tuples replaced with `dns4` and `dns6 ones respectively. | ||
* | ||
* @param domain - The domain name to map. | ||
* @param ipAddresses - The associated IP addresses. | ||
*/ | ||
@@ -107,2 +132,4 @@ addDNSMapping(domain: string, ipAddresses: string[]): void; | ||
* Remove a mapping previously added with `addDNSMapping`. | ||
* | ||
* @param domain - The domain name mapping to remove. | ||
*/ | ||
@@ -119,2 +146,8 @@ removeDNSMapping(domain: string): void; | ||
* port forwarding configured, but it does IPv6 -> IPv4 NAT. | ||
* | ||
* @param internalIp - The internal IP address. | ||
* @param internalPort - The internal port number. | ||
* @param externalIp - The external IP address. | ||
* @param externalPort - The external port number (optional). | ||
* @param protocol - The transport protocol (`tcp` or `udp`). | ||
*/ | ||
@@ -124,2 +157,8 @@ addPublicAddressMapping(internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void; | ||
* Remove a publicly routable address that this node is no longer reachable on | ||
* | ||
* @param internalIp - The internal IP address. | ||
* @param internalPort - The internal port number. | ||
* @param externalIp - The external IP address. | ||
* @param externalPort - The external port number (optional). | ||
* @param protocol - The transport protocol (`tcp` or `udp`). | ||
*/ | ||
@@ -126,0 +165,0 @@ removePublicAddressMapping(internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void; |
@@ -5,2 +5,5 @@ import type { AbortOptions, PendingDial, Connection, MultiaddrConnection, PeerId, IsDialableOptions, OpenConnectionProgressEvents } from '@libp2p/interface'; | ||
import type { ProgressOptions } from 'progress-events'; | ||
/** | ||
* Options for opening a connection to a remote peer. | ||
*/ | ||
export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<OpenConnectionProgressEvents> { | ||
@@ -34,2 +37,7 @@ /** | ||
} | ||
/** | ||
* The `ConnectionManager` handles managing connections between peers in a libp2p network. | ||
* It provides methods for opening, closing, and querying connections.This also provides methods | ||
* for accessing the dial queue. | ||
*/ | ||
export interface ConnectionManager { | ||
@@ -39,8 +47,4 @@ /** | ||
* | ||
* @example | ||
* | ||
* ```TypeScript | ||
* const connections = libp2p.connectionManager.get(peerId) | ||
* // [] | ||
* ``` | ||
* @param peerId - The PeerId to filter connections (optional). | ||
* @returns An array of active `Connection` objects. | ||
*/ | ||
@@ -51,7 +55,3 @@ getConnections(peerId?: PeerId): Connection[]; | ||
* | ||
* @example | ||
* | ||
* ```TypeScript | ||
* const connectionsMap = libp2p.connectionManager.getConnectionsMap() | ||
* ``` | ||
* @returns A `PeerMap` containing `Connection[]` objects. | ||
*/ | ||
@@ -62,2 +62,4 @@ getConnectionsMap(): PeerMap<Connection[]>; | ||
* manager will accept | ||
* | ||
* @returns The maximum connection limit. | ||
*/ | ||
@@ -68,7 +70,5 @@ getMaxConnections(): number; | ||
* | ||
* @example | ||
* | ||
* ```TypeScript | ||
* const connection = await libp2p.connectionManager.openConnection(peerId) | ||
* ``` | ||
* @param peer - The target `PeerId`, `Multiaddr`, or an array of `Multiaddr`s. | ||
* @param options - Optional parameters for connection handling. | ||
* @returns A promise that resolves to a `Connection` object. | ||
*/ | ||
@@ -78,2 +78,6 @@ openConnection(peer: PeerId | Multiaddr | Multiaddr[], options?: OpenConnectionOptions): Promise<Connection>; | ||
* Close our connections to a peer | ||
* | ||
* @param peer - The `PeerId` whose connections should be closed. | ||
* @param options - Optional abort options. | ||
* @returns A promise that resolves once the connections are closed. | ||
*/ | ||
@@ -86,2 +90,5 @@ closeConnections(peer: PeerId, options?: AbortOptions): Promise<void>; | ||
* otherwise it will return false. | ||
* | ||
* @param maConn - The multiaddr connection to evaluate. | ||
* @returns A promise that resolves to `true` if the connection can be accepted, `false` otherwise. | ||
*/ | ||
@@ -96,7 +103,3 @@ acceptIncomingConnection(maConn: MultiaddrConnection): Promise<boolean>; | ||
* | ||
* @example | ||
* | ||
* ```TypeScript | ||
* const dials = libp2p.connectionManager.getDialQueue() | ||
* ``` | ||
* @returns An array of `PendingDial` objects. | ||
*/ | ||
@@ -112,2 +115,6 @@ getDialQueue(): PendingDial[]; | ||
* This may involve resolving DNS addresses so you should pass an AbortSignal. | ||
* | ||
* @param multiaddr - The target multiaddr or an array of multiaddrs. | ||
* @param options - Optional parameters for dialability check. | ||
* @returns A promise that resolves to `true` if the multiaddr is dialable, `false` otherwise. | ||
*/ | ||
@@ -114,0 +121,0 @@ isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise<boolean>; |
@@ -0,1 +1,10 @@ | ||
/** | ||
* @packageDocumentation | ||
* | ||
* This module serves as the entry point for `@libp2p/interface-internal`, | ||
* re-exporting key components such as `AddressManager`, `ConnectionManager`, | ||
* `RandomWalk`, `Registrar`, and `TransportManager`. | ||
* | ||
* These interfaces and classes define the core internal behaviors of libp2p. | ||
*/ | ||
export * from './address-manager.js'; | ||
@@ -2,0 +11,0 @@ export * from './connection-manager.js'; |
@@ -0,1 +1,10 @@ | ||
/** | ||
* @packageDocumentation | ||
* | ||
* This module serves as the entry point for `@libp2p/interface-internal`, | ||
* re-exporting key components such as `AddressManager`, `ConnectionManager`, | ||
* `RandomWalk`, `Registrar`, and `TransportManager`. | ||
* | ||
* These interfaces and classes define the core internal behaviors of libp2p. | ||
*/ | ||
export * from './address-manager.js'; | ||
@@ -2,0 +11,0 @@ export * from './connection-manager.js'; |
import type { AbortOptions, PeerInfo } from '@libp2p/interface'; | ||
/** | ||
* RandomWalk finds random peers on the network and dials them. Use this after | ||
* registering a Topology if you need to discover common network services. | ||
* The `RandomWalk` component uses the libp2p peer routing to find arbitrary | ||
* network peers. Consumers may then dial these peers, causing the Identify | ||
* protocol to run and any registered topologies to be notified of their | ||
* supported protocols. | ||
*/ | ||
export interface RandomWalk { | ||
/** | ||
* Begin or join an existing walk. Abort the passed signal if you wish to | ||
* abort the walk early. | ||
* Initiates a random walk for peer discovery. | ||
* | ||
* This method either begins a new random walk or joins an existing one. The process | ||
* continues to find and return random peers until it is aborted. | ||
* | ||
* @param options - Optional `AbortOptions` to allow early termination of the walk. | ||
* @returns An `AsyncGenerator` that yields discovered `PeerInfo` objects. | ||
*/ | ||
@@ -11,0 +18,0 @@ walk(options?: AbortOptions): AsyncGenerator<PeerInfo>; |
@@ -19,17 +19,42 @@ import type { StreamHandler, StreamHandlerOptions, StreamHandlerRecord, Topology, IncomingStreamData } from '@libp2p/interface'; | ||
StreamHandlerRecord }; | ||
/** | ||
* The `Registrar` provides an interface for registering protocol handlers - | ||
* these are invoked when remote peers open streams on the local node with the | ||
* corresponding protocol name. | ||
* | ||
* It also allows configuring network topologies for a given protocol(s). The | ||
* topology callbacks are invoked when a peer that supports those protocols | ||
* connects or disconnects. | ||
* | ||
* The Identify protocol must be configured on the current node for topologies | ||
* to function. | ||
*/ | ||
export interface Registrar { | ||
/** | ||
* Return the list of protocols with registered handlers | ||
* Retrieve the list of registered protocol handlers. | ||
* | ||
* @returns An array of protocol strings. | ||
*/ | ||
getProtocols(): string[]; | ||
/** | ||
* Add a protocol handler | ||
* Register a handler for a specific protocol. | ||
* | ||
* @param protocol - The protocol string (e.g., `/my-protocol/1.0.0`). | ||
* @param handler - The function that handles incoming streams. | ||
* @param options - Optional configuration options for the handler. | ||
* @returns A promise that resolves once the handler is registered. | ||
*/ | ||
handle(protocol: string, handler: StreamHandler, options?: StreamHandlerOptions): Promise<void>; | ||
/** | ||
* Remove a protocol handler | ||
* Remove a registered protocol handler. | ||
* | ||
* @param protocol - The protocol to unhandle. | ||
* @returns A promise that resolves once the handler is removed. | ||
*/ | ||
unhandle(protocol: string): Promise<void>; | ||
/** | ||
* Return the handler for the passed protocol | ||
* Retrieve the registered handler for a given protocol. | ||
* | ||
* @param protocol - The protocol to query. | ||
* @returns A `StreamHandlerRecord` containing the handler and options. | ||
*/ | ||
@@ -44,11 +69,20 @@ getHandler(protocol: string): StreamHandlerRecord; | ||
* topology. | ||
* | ||
* @param protocol - The protocol to register. | ||
* @param topology - The topology handler to register. | ||
* @returns A promise resolving to a unique ID for the registered topology. | ||
*/ | ||
register(protocol: string, topology: Topology): Promise<string>; | ||
/** | ||
* Remove the topology handler with the passed id. | ||
* Unregister a topology handler using its unique ID. | ||
* | ||
* @param id - The ID of the topology to unregister. | ||
*/ | ||
unregister(id: string): void; | ||
/** | ||
* Return all topology handlers that wish to be informed about peers | ||
* that support the passed protocol. | ||
* Retrieve all topology handlers that are interested in peers | ||
* supporting a given protocol. | ||
* | ||
* @param protocol - The protocol to query. | ||
* @returns An array of registered `Topology` handlers. | ||
*/ | ||
@@ -55,0 +89,0 @@ getTopologies(protocol: string): Topology[]; |
import type { AbortOptions, Connection, Listener, Transport, TransportManagerDialProgressEvents } from '@libp2p/interface'; | ||
import type { Multiaddr } from '@multiformats/multiaddr'; | ||
import type { ProgressOptions } from 'progress-events'; | ||
/** | ||
* Options for dialing a connection using the `TransportManager`. | ||
*/ | ||
export interface TransportManagerDialOptions extends AbortOptions, ProgressOptions<TransportManagerDialProgressEvents> { | ||
} | ||
/** | ||
* The `TransportManager` handles the management of network transports, allowing | ||
* opening connections or listening using specific transports, etc. | ||
* | ||
* This is a low-level component - any connections opened will not be managed by | ||
* the `ConnectionManager` or included in any configured connection limits, etc. | ||
* | ||
* Most consumers will call `openConnection` on the `ConnectionManager` instead. | ||
*/ | ||
export interface TransportManager { | ||
/** | ||
* Add a transport to the transport manager | ||
* Add a transport to the transport manager. | ||
* | ||
* @param transport - The transport instance to be added. | ||
*/ | ||
@@ -16,2 +30,6 @@ add(transport: Transport): void; | ||
* instead. | ||
* | ||
* @param ma - The multiaddr to dial. | ||
* @param options - Optional dial options. | ||
* @returns A promise that resolves to a `Connection` object. | ||
*/ | ||
@@ -21,2 +39,4 @@ dial(ma: Multiaddr, options?: TransportManagerDialOptions): Promise<Connection>; | ||
* Return all addresses currently being listened on | ||
* | ||
* @returns An array of `Multiaddr` objects. | ||
*/ | ||
@@ -26,2 +46,4 @@ getAddrs(): Multiaddr[]; | ||
* Return all registered transports | ||
* | ||
* @returns An array of `Transport` instances. | ||
*/ | ||
@@ -31,2 +53,4 @@ getTransports(): Transport[]; | ||
* Return all listeners | ||
* | ||
* @returns An array of `Listener` instances. | ||
*/ | ||
@@ -36,2 +60,5 @@ getListeners(): Listener[]; | ||
* Get the transport to dial a given multiaddr, if one has been configured | ||
* | ||
* @param ma - The target multiaddr. | ||
* @returns A `Transport` instance if available, otherwise `undefined`. | ||
*/ | ||
@@ -42,2 +69,5 @@ dialTransportForMultiaddr(ma: Multiaddr): Transport | undefined; | ||
* configured | ||
* | ||
* @param ma - The target multiaddr. | ||
* @returns A `Transport` instance if available, otherwise `undefined`. | ||
*/ | ||
@@ -47,2 +77,5 @@ listenTransportForMultiaddr(ma: Multiaddr): Transport | undefined; | ||
* Listen on the passed multiaddrs | ||
* | ||
* @param addrs - An array of multiaddrs to listen on. | ||
* @returns A promise that resolves once the transport is actively listening. | ||
*/ | ||
@@ -52,2 +85,5 @@ listen(addrs: Multiaddr[]): Promise<void>; | ||
* Remove a previously configured transport | ||
* | ||
* @param key - The transport key or identifier. | ||
* @returns A promise that resolves once the transport is removed. | ||
*/ | ||
@@ -57,2 +93,4 @@ remove(key: string): Promise<void>; | ||
* Remove all transports | ||
* | ||
* @returns A promise that resolves once all transports are removed. | ||
*/ | ||
@@ -59,0 +97,0 @@ removeAll(): Promise<void>; |
{ | ||
"name": "@libp2p/interface-internal", | ||
"version": "2.3.0-4ab04faf0", | ||
"version": "2.3.0-68ad3663e", | ||
"description": "Interfaces implemented by internal libp2p components", | ||
@@ -51,4 +51,4 @@ "license": "Apache-2.0 OR MIT", | ||
"dependencies": { | ||
"@libp2p/interface": "2.5.0-4ab04faf0", | ||
"@libp2p/peer-collections": "6.0.17-4ab04faf0", | ||
"@libp2p/interface": "2.5.0-68ad3663e", | ||
"@libp2p/peer-collections": "6.0.17-68ad3663e", | ||
"@multiformats/multiaddr": "^12.3.3", | ||
@@ -55,0 +55,0 @@ "progress-events": "^1.0.1" |
@@ -60,5 +60,12 @@ import type { Multiaddr } from '@multiformats/multiaddr' | ||
/** | ||
* The `AddressManager` provides an interface for managing peer addresses | ||
* in libp2p. It supports handling multiple types of addresses, verifying their validity, | ||
* and storing mappings between internal and external addresses. | ||
*/ | ||
export interface AddressManager { | ||
/** | ||
* Get peer listen multiaddrs | ||
* | ||
* @returns An array of `Multiaddr` objects representing listen addresses. | ||
*/ | ||
@@ -69,2 +76,4 @@ getListenAddrs(): Multiaddr[] | ||
* Get peer announcing multiaddrs | ||
* | ||
* @returns An array of `Multiaddr` objects representing announce addresses. | ||
*/ | ||
@@ -76,2 +85,4 @@ getAnnounceAddrs(): Multiaddr[] | ||
* publicly dialable yet | ||
* | ||
* @returns An array of `Multiaddr` objects representing observed addresses. | ||
*/ | ||
@@ -83,2 +94,5 @@ getObservedAddrs(): Multiaddr[] | ||
* this will make it appear in the output of getAddresses() | ||
* | ||
* @param addr - The observed address. | ||
* @param options - Additional options for confirmation. | ||
*/ | ||
@@ -90,2 +104,4 @@ confirmObservedAddr(addr: Multiaddr, options?: ConfirmAddressOptions): void | ||
* this will remove it from the output of getObservedAddrs() | ||
* | ||
* @param addr - The observed address to remove. | ||
*/ | ||
@@ -98,2 +114,4 @@ removeObservedAddr(addr: Multiaddr): void | ||
* confirmObservedAddr. | ||
* | ||
* @param addr - The observed address to add. | ||
*/ | ||
@@ -104,2 +122,4 @@ addObservedAddr(addr: Multiaddr): void | ||
* Get the current node's addresses | ||
* | ||
* @returns An array of `Multiaddr` objects representing node addresses. | ||
*/ | ||
@@ -110,2 +130,4 @@ getAddresses(): Multiaddr[] | ||
* Return all known addresses with metadata | ||
* | ||
* @returns An array of `NodeAddress` objects. | ||
*/ | ||
@@ -119,2 +141,5 @@ getAddressesWithMetadata(): NodeAddress[] | ||
* tuples replaced with `dns4` and `dns6 ones respectively. | ||
* | ||
* @param domain - The domain name to map. | ||
* @param ipAddresses - The associated IP addresses. | ||
*/ | ||
@@ -125,2 +150,4 @@ addDNSMapping(domain: string, ipAddresses: string[]): void | ||
* Remove a mapping previously added with `addDNSMapping`. | ||
* | ||
* @param domain - The domain name mapping to remove. | ||
*/ | ||
@@ -138,2 +165,8 @@ removeDNSMapping(domain: string): void | ||
* port forwarding configured, but it does IPv6 -> IPv4 NAT. | ||
* | ||
* @param internalIp - The internal IP address. | ||
* @param internalPort - The internal port number. | ||
* @param externalIp - The external IP address. | ||
* @param externalPort - The external port number (optional). | ||
* @param protocol - The transport protocol (`tcp` or `udp`). | ||
*/ | ||
@@ -144,4 +177,10 @@ addPublicAddressMapping (internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void | ||
* Remove a publicly routable address that this node is no longer reachable on | ||
* | ||
* @param internalIp - The internal IP address. | ||
* @param internalPort - The internal port number. | ||
* @param externalIp - The external IP address. | ||
* @param externalPort - The external port number (optional). | ||
* @param protocol - The transport protocol (`tcp` or `udp`). | ||
*/ | ||
removePublicAddressMapping (internalIp: string, internalPort: number, externalIp: string, externalPort?: number, protocol?: 'tcp' | 'udp'): void | ||
} |
@@ -6,2 +6,5 @@ import type { AbortOptions, PendingDial, Connection, MultiaddrConnection, PeerId, IsDialableOptions, OpenConnectionProgressEvents } from '@libp2p/interface' | ||
/** | ||
* Options for opening a connection to a remote peer. | ||
*/ | ||
export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<OpenConnectionProgressEvents> { | ||
@@ -38,2 +41,7 @@ /** | ||
/** | ||
* The `ConnectionManager` handles managing connections between peers in a libp2p network. | ||
* It provides methods for opening, closing, and querying connections.This also provides methods | ||
* for accessing the dial queue. | ||
*/ | ||
export interface ConnectionManager { | ||
@@ -43,8 +51,4 @@ /** | ||
* | ||
* @example | ||
* | ||
* ```TypeScript | ||
* const connections = libp2p.connectionManager.get(peerId) | ||
* // [] | ||
* ``` | ||
* @param peerId - The PeerId to filter connections (optional). | ||
* @returns An array of active `Connection` objects. | ||
*/ | ||
@@ -56,7 +60,3 @@ getConnections(peerId?: PeerId): Connection[] | ||
* | ||
* @example | ||
* | ||
* ```TypeScript | ||
* const connectionsMap = libp2p.connectionManager.getConnectionsMap() | ||
* ``` | ||
* @returns A `PeerMap` containing `Connection[]` objects. | ||
*/ | ||
@@ -68,2 +68,4 @@ getConnectionsMap(): PeerMap<Connection[]> | ||
* manager will accept | ||
* | ||
* @returns The maximum connection limit. | ||
*/ | ||
@@ -75,7 +77,5 @@ getMaxConnections(): number | ||
* | ||
* @example | ||
* | ||
* ```TypeScript | ||
* const connection = await libp2p.connectionManager.openConnection(peerId) | ||
* ``` | ||
* @param peer - The target `PeerId`, `Multiaddr`, or an array of `Multiaddr`s. | ||
* @param options - Optional parameters for connection handling. | ||
* @returns A promise that resolves to a `Connection` object. | ||
*/ | ||
@@ -86,2 +86,6 @@ openConnection(peer: PeerId | Multiaddr | Multiaddr[], options?: OpenConnectionOptions): Promise<Connection> | ||
* Close our connections to a peer | ||
* | ||
* @param peer - The `PeerId` whose connections should be closed. | ||
* @param options - Optional abort options. | ||
* @returns A promise that resolves once the connections are closed. | ||
*/ | ||
@@ -95,2 +99,5 @@ closeConnections(peer: PeerId, options?: AbortOptions): Promise<void> | ||
* otherwise it will return false. | ||
* | ||
* @param maConn - The multiaddr connection to evaluate. | ||
* @returns A promise that resolves to `true` if the connection can be accepted, `false` otherwise. | ||
*/ | ||
@@ -107,7 +114,3 @@ acceptIncomingConnection(maConn: MultiaddrConnection): Promise<boolean> | ||
* | ||
* @example | ||
* | ||
* ```TypeScript | ||
* const dials = libp2p.connectionManager.getDialQueue() | ||
* ``` | ||
* @returns An array of `PendingDial` objects. | ||
*/ | ||
@@ -124,4 +127,8 @@ getDialQueue(): PendingDial[] | ||
* This may involve resolving DNS addresses so you should pass an AbortSignal. | ||
* | ||
* @param multiaddr - The target multiaddr or an array of multiaddrs. | ||
* @param options - Optional parameters for dialability check. | ||
* @returns A promise that resolves to `true` if the multiaddr is dialable, `false` otherwise. | ||
*/ | ||
isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise<boolean> | ||
} |
@@ -0,1 +1,11 @@ | ||
/** | ||
* @packageDocumentation | ||
* | ||
* This module serves as the entry point for `@libp2p/interface-internal`, | ||
* re-exporting key components such as `AddressManager`, `ConnectionManager`, | ||
* `RandomWalk`, `Registrar`, and `TransportManager`. | ||
* | ||
* These interfaces and classes define the core internal behaviors of libp2p. | ||
*/ | ||
export * from './address-manager.js' | ||
@@ -2,0 +12,0 @@ export * from './connection-manager.js' |
import type { AbortOptions, PeerInfo } from '@libp2p/interface' | ||
/** | ||
* RandomWalk finds random peers on the network and dials them. Use this after | ||
* registering a Topology if you need to discover common network services. | ||
* The `RandomWalk` component uses the libp2p peer routing to find arbitrary | ||
* network peers. Consumers may then dial these peers, causing the Identify | ||
* protocol to run and any registered topologies to be notified of their | ||
* supported protocols. | ||
*/ | ||
export interface RandomWalk { | ||
/** | ||
* Begin or join an existing walk. Abort the passed signal if you wish to | ||
* abort the walk early. | ||
* Initiates a random walk for peer discovery. | ||
* | ||
* This method either begins a new random walk or joins an existing one. The process | ||
* continues to find and return random peers until it is aborted. | ||
* | ||
* @param options - Optional `AbortOptions` to allow early termination of the walk. | ||
* @returns An `AsyncGenerator` that yields discovered `PeerInfo` objects. | ||
*/ | ||
walk(options?: AbortOptions): AsyncGenerator<PeerInfo> | ||
} |
@@ -25,5 +25,19 @@ import type { StreamHandler, StreamHandlerOptions, StreamHandlerRecord, Topology, IncomingStreamData } from '@libp2p/interface' | ||
/** | ||
* The `Registrar` provides an interface for registering protocol handlers - | ||
* these are invoked when remote peers open streams on the local node with the | ||
* corresponding protocol name. | ||
* | ||
* It also allows configuring network topologies for a given protocol(s). The | ||
* topology callbacks are invoked when a peer that supports those protocols | ||
* connects or disconnects. | ||
* | ||
* The Identify protocol must be configured on the current node for topologies | ||
* to function. | ||
*/ | ||
export interface Registrar { | ||
/** | ||
* Return the list of protocols with registered handlers | ||
* Retrieve the list of registered protocol handlers. | ||
* | ||
* @returns An array of protocol strings. | ||
*/ | ||
@@ -33,3 +47,8 @@ getProtocols(): string[] | ||
/** | ||
* Add a protocol handler | ||
* Register a handler for a specific protocol. | ||
* | ||
* @param protocol - The protocol string (e.g., `/my-protocol/1.0.0`). | ||
* @param handler - The function that handles incoming streams. | ||
* @param options - Optional configuration options for the handler. | ||
* @returns A promise that resolves once the handler is registered. | ||
*/ | ||
@@ -39,3 +58,6 @@ handle(protocol: string, handler: StreamHandler, options?: StreamHandlerOptions): Promise<void> | ||
/** | ||
* Remove a protocol handler | ||
* Remove a registered protocol handler. | ||
* | ||
* @param protocol - The protocol to unhandle. | ||
* @returns A promise that resolves once the handler is removed. | ||
*/ | ||
@@ -45,3 +67,6 @@ unhandle(protocol: string): Promise<void> | ||
/** | ||
* Return the handler for the passed protocol | ||
* Retrieve the registered handler for a given protocol. | ||
* | ||
* @param protocol - The protocol to query. | ||
* @returns A `StreamHandlerRecord` containing the handler and options. | ||
*/ | ||
@@ -57,2 +82,6 @@ getHandler(protocol: string): StreamHandlerRecord | ||
* topology. | ||
* | ||
* @param protocol - The protocol to register. | ||
* @param topology - The topology handler to register. | ||
* @returns A promise resolving to a unique ID for the registered topology. | ||
*/ | ||
@@ -62,3 +91,5 @@ register(protocol: string, topology: Topology): Promise<string> | ||
/** | ||
* Remove the topology handler with the passed id. | ||
* Unregister a topology handler using its unique ID. | ||
* | ||
* @param id - The ID of the topology to unregister. | ||
*/ | ||
@@ -68,6 +99,9 @@ unregister(id: string): void | ||
/** | ||
* Return all topology handlers that wish to be informed about peers | ||
* that support the passed protocol. | ||
* Retrieve all topology handlers that are interested in peers | ||
* supporting a given protocol. | ||
* | ||
* @param protocol - The protocol to query. | ||
* @returns An array of registered `Topology` handlers. | ||
*/ | ||
getTopologies(protocol: string): Topology[] | ||
} |
@@ -5,2 +5,5 @@ import type { AbortOptions, Connection, Listener, Transport, TransportManagerDialProgressEvents } from '@libp2p/interface' | ||
/** | ||
* Options for dialing a connection using the `TransportManager`. | ||
*/ | ||
export interface TransportManagerDialOptions extends AbortOptions, ProgressOptions<TransportManagerDialProgressEvents> { | ||
@@ -10,5 +13,16 @@ | ||
/** | ||
* The `TransportManager` handles the management of network transports, allowing | ||
* opening connections or listening using specific transports, etc. | ||
* | ||
* This is a low-level component - any connections opened will not be managed by | ||
* the `ConnectionManager` or included in any configured connection limits, etc. | ||
* | ||
* Most consumers will call `openConnection` on the `ConnectionManager` instead. | ||
*/ | ||
export interface TransportManager { | ||
/** | ||
* Add a transport to the transport manager | ||
* Add a transport to the transport manager. | ||
* | ||
* @param transport - The transport instance to be added. | ||
*/ | ||
@@ -22,2 +36,6 @@ add(transport: Transport): void | ||
* instead. | ||
* | ||
* @param ma - The multiaddr to dial. | ||
* @param options - Optional dial options. | ||
* @returns A promise that resolves to a `Connection` object. | ||
*/ | ||
@@ -28,2 +46,4 @@ dial(ma: Multiaddr, options?: TransportManagerDialOptions): Promise<Connection> | ||
* Return all addresses currently being listened on | ||
* | ||
* @returns An array of `Multiaddr` objects. | ||
*/ | ||
@@ -34,2 +54,4 @@ getAddrs(): Multiaddr[] | ||
* Return all registered transports | ||
* | ||
* @returns An array of `Transport` instances. | ||
*/ | ||
@@ -40,2 +62,4 @@ getTransports(): Transport[] | ||
* Return all listeners | ||
* | ||
* @returns An array of `Listener` instances. | ||
*/ | ||
@@ -46,2 +70,5 @@ getListeners(): Listener[] | ||
* Get the transport to dial a given multiaddr, if one has been configured | ||
* | ||
* @param ma - The target multiaddr. | ||
* @returns A `Transport` instance if available, otherwise `undefined`. | ||
*/ | ||
@@ -53,2 +80,5 @@ dialTransportForMultiaddr(ma: Multiaddr): Transport | undefined | ||
* configured | ||
* | ||
* @param ma - The target multiaddr. | ||
* @returns A `Transport` instance if available, otherwise `undefined`. | ||
*/ | ||
@@ -59,2 +89,5 @@ listenTransportForMultiaddr(ma: Multiaddr): Transport | undefined | ||
* Listen on the passed multiaddrs | ||
* | ||
* @param addrs - An array of multiaddrs to listen on. | ||
* @returns A promise that resolves once the transport is actively listening. | ||
*/ | ||
@@ -65,2 +98,5 @@ listen(addrs: Multiaddr[]): Promise<void> | ||
* Remove a previously configured transport | ||
* | ||
* @param key - The transport key or identifier. | ||
* @returns A promise that resolves once the transport is removed. | ||
*/ | ||
@@ -71,4 +107,6 @@ remove(key: string): Promise<void> | ||
* Remove all transports | ||
* | ||
* @returns A promise that resolves once all transports are removed. | ||
*/ | ||
removeAll(): Promise<void> | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
46787
976
0
+ Added@libp2p/crypto@5.0.11-68ad3663e(transitive)
+ Added@libp2p/interface@2.5.0-68ad3663e(transitive)
+ Added@libp2p/logger@5.1.8-68ad3663e(transitive)
+ Added@libp2p/peer-collections@6.0.17-68ad3663e(transitive)
+ Added@libp2p/peer-id@5.0.12-68ad3663e(transitive)
+ Added@libp2p/utils@6.5.1-68ad3663e(transitive)
+ Added@types/node@22.13.5(transitive)
+ Addedrace-signal@1.1.3(transitive)
- Removed@libp2p/crypto@5.0.11-4ab04faf0(transitive)
- Removed@libp2p/interface@2.5.0-4ab04faf0(transitive)
- Removed@libp2p/logger@5.1.8-4ab04faf0(transitive)
- Removed@libp2p/peer-collections@6.0.17-4ab04faf0(transitive)
- Removed@libp2p/peer-id@5.0.12-4ab04faf0(transitive)
- Removed@libp2p/utils@6.5.1-4ab04faf0(transitive)
- Removed@types/node@22.13.4(transitive)
- Removedrace-signal@1.1.0(transitive)