-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: add TSDoc comments interface-internal module #2949
base: main
Are you sure you want to change the base?
Changes from 5 commits
c27cd2a
dbeb193
cf9e48a
747e585
16c80a2
9d52880
9da0139
20fcb88
aa2aab8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,9 @@ import type { PeerMap } from '@libp2p/peer-collections' | |||||||||||||||||||||||||||
import type { Multiaddr } from '@multiformats/multiaddr' | ||||||||||||||||||||||||||||
import type { ProgressOptions } from 'progress-events' | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Options for opening a connection to a remote peer. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<OpenConnectionProgressEvents> { | ||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Connection requests with a higher priority will be executed before those | ||||||||||||||||||||||||||||
|
@@ -34,49 +37,53 @@ export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<Ope | |||||||||||||||||||||||||||
initiator?: boolean | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
maschad marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
* The `ConnectionManager` module 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. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Manages the dialing, opening, and closing of connections. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must be a single comment, not two:
Suggested change
|
||||||||||||||||||||||||||||
export interface ConnectionManager { | ||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Return connections, optionally filtering by a PeerId | ||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||
* @example | ||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||
* ```TypeScript | ||||||||||||||||||||||||||||
* const connections = libp2p.connectionManager.get(peerId) | ||||||||||||||||||||||||||||
* // [] | ||||||||||||||||||||||||||||
* ``` | ||||||||||||||||||||||||||||
* @param peerId - The PeerId to filter connections (optional). | ||||||||||||||||||||||||||||
* @returns An array of active `Connection` objects. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
getConnections(peerId?: PeerId): Connection[] | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Return a map of all connections with their associated PeerIds | ||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||
* @example | ||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||
* ```TypeScript | ||||||||||||||||||||||||||||
* const connectionsMap = libp2p.connectionManager.getConnectionsMap() | ||||||||||||||||||||||||||||
* ``` | ||||||||||||||||||||||||||||
* @returns A `PeerMap` containing `Connection[]` objects. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
getConnectionsMap(): PeerMap<Connection[]> | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Returns the configured maximum number of connections this connection | ||||||||||||||||||||||||||||
* manager will accept | ||||||||||||||||||||||||||||
* @returns The maximum connection limit. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
getMaxConnections(): number | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Open a connection to a remote peer | ||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||
* @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. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
closeConnections(peer: PeerId, options?: AbortOptions): Promise<void> | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -85,6 +92,9 @@ export interface ConnectionManager { | |||||||||||||||||||||||||||
* exchanged, this lets the ConnectionManager check we have sufficient | ||||||||||||||||||||||||||||
* resources to accept the connection in which case it will return true, | ||||||||||||||||||||||||||||
* 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. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
acceptIncomingConnection(maConn: MultiaddrConnection): Promise<boolean> | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -96,11 +106,7 @@ export interface ConnectionManager { | |||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Return the list of in-progress or queued dials | ||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||
* @example | ||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||
* ```TypeScript | ||||||||||||||||||||||||||||
* const dials = libp2p.connectionManager.getDialQueue() | ||||||||||||||||||||||||||||
* ``` | ||||||||||||||||||||||||||||
* @returns An array of `PendingDial` objects. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
getDialQueue(): PendingDial[] | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -112,6 +118,9 @@ export interface ConnectionManager { | |||||||||||||||||||||||||||
* would not block the dial attempt. | ||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||
* 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> | ||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,13 +1,25 @@ | ||||||||||||||||||||||||||
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` module facilitates peer discovery by randomly finding and dialing peers | ||||||||||||||||||||||||||
* on the libp2p network. It is useful in conjunction with a registered `Topology` to | ||||||||||||||||||||||||||
* discover common network services. | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||
* The `RandomWalk` interface provides a mechanism for discovering and connecting to | ||||||||||||||||||||||||||
* random peers on the libp2p network. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must be a single comment, not two. Also, the docs were wrong here - RandomWalk only discovers peers, it doesn't dial them.
Suggested change
|
||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
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> | ||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,10 @@ | ||||||||||||||||||||||||||||||||||||||||||||
import type { StreamHandler, StreamHandlerOptions, StreamHandlerRecord, Topology, IncomingStreamData } from '@libp2p/interface' | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this comment is necessary - these are named exports so will get their own documentation blocks. Please can you check the output of |
||||||||||||||||||||||||||||||||||||||||||||
* Deprecated types that should be imported from `@libp2p/interface` directly. | ||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||
* These exports ensure backward compatibility but should be avoided in new code. | ||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||
export type { | ||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||
* @deprecated This type should be imported from @libp2p/interface directly | ||||||||||||||||||||||||||||||||||||||||||||
|
@@ -21,46 +26,75 @@ export type { | |||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||
StreamHandlerRecord | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||
* The `Registrar` module provides an interface for managing protocol handlers | ||||||||||||||||||||||||||||||||||||||||||||
* and topologies in a libp2p network. It enables registering and managing | ||||||||||||||||||||||||||||||||||||||||||||
* protocol-specific handlers, ensuring efficient peer-to-peer communication. | ||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||
* The `Registrar` interface allows modules to register, manage, and remove | ||||||||||||||||||||||||||||||||||||||||||||
* protocol handlers and topology discovery mechanisms in libp2p. | ||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must be a single comment, not two. Also we can be a bit more specific in the comment:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||
getHandler(protocol: string): StreamHandlerRecord | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||
* Register a topology handler for a protocol - the topology will be | ||||||||||||||||||||||||||||||||||||||||||||
* invoked when peers are discovered on the network that support the | ||||||||||||||||||||||||||||||||||||||||||||
* passed protocol. | ||||||||||||||||||||||||||||||||||||||||||||
* Register a topology handler for a specific protocol. | ||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||
* An id will be returned that can later be used to unregister the | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part about the id being used to unregister the topology later is important, please do not delete it. |
||||||||||||||||||||||||||||||||||||||||||||
* topology. | ||||||||||||||||||||||||||||||||||||||||||||
* The topology will be notified when peers supporting the protocol | ||||||||||||||||||||||||||||||||||||||||||||
* are discovered on the network. | ||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||
* @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. | ||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||
getTopologies(protocol: string): Topology[] | ||||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be one comment, not two, otherwise only the second will appear in the generated docs.
You can check this by running
npm run docs
in the root of the repo and looking at the HTML that appears in the.docs
folder.