From 1397b6124e550007c010f2ffea4c66a01a3fefc1 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Thu, 12 Dec 2019 10:43:33 +0100 Subject: [PATCH] chore: update documentation --- index.html | 15776 ++++++++++++++++++++++++--------------------------- 1 file changed, 7557 insertions(+), 8219 deletions(-) diff --git a/index.html b/index.html index 6335b511..34130b6b 100644 --- a/index.html +++ b/index.html @@ -1,8 +1,8 @@ - + - libp2p 0.26.2 | Documentation + libp2p 0.27.0-pre.0 | Documentation @@ -15,7 +15,7 @@

libp2p

-
0.26.2
+
0.27.0-pre.0
-
  • - #dialFSM -
  • -
  • @@ -96,80 +90,18 @@ #ping
  • - - - - -
    - - - - -
  • - createLibp2p - - - -
  • - - -
  • - Switch - - - -
  • +
  • + index + + + + + +
  • + + +
  • + findPeer + + + +
  • + + +
  • + findProviders + + + +
  • + + +
  • + provide + + + +
  • + + +
  • + put + + + +
  • + + +
  • + get + + + +
  • + + +
  • + getMany + + + +
  • + + +
  • + subscribe + + + +
  • + + +
  • + unsubscribe + + + +
  • + + +
  • + publish + + + +
  • + + +
  • + getTopics + + + +
  • + + +
  • + getSubscribers + + + +
  • + + +
  • + getPeerInfo + + + +
  • + + +
  • + getPeerInfoRemote + + + +
  • + +
  • @@ -190,9 +286,59 @@
  • - _dialSwarmRelays + start + + + +
  • + + +
  • + stop + + + +
  • + + +
  • + setPeerValue + + + +
  • + + +
  • + onConnect + + + +
  • + + +
  • + onDisconnect + + + +
  • + + +
  • + constructor @@ -230,9 +376,49 @@
  • + listener + + + + + +
  • + + +
  • - constructor + hop @@ -240,9 +426,9 @@
  • - _dialRelayHelper + writeResponse @@ -250,19 +436,9 @@
  • - dial - - - -
  • - - -
  • - canHop + validateAddrs @@ -299,16 +475,6 @@
  • -
  • - getRawConn - - - -
  • - -
  • @@ -329,86 +495,6 @@
  • -
  • - getB58String - - - -
  • - - -
  • - isPeerConnected - - - -
  • - - -
  • - writeResponse - - - -
  • - - -
  • - validateAddrs - - - -
  • - - -
  • - listen - - - -
  • - - -
  • - close - - - -
  • - - -
  • - getAddrs - - - -
  • - - -
  • - handle - - - -
  • - -
  • @@ -420,9 +506,9 @@
  • - handle + destroy @@ -430,9 +516,9 @@
  • - _connectToStop + connectToMultiaddr @@ -440,390 +526,9 @@
  • - _negotiateStop - - - -
  • - - -
  • - TransportManager - - - - - -
  • - - -
  • - ourAddresses - - - -
  • - - -
  • - getDestination - - - -
  • - - -
  • - LimitDialer - - - - - -
  • - - -
  • - DialQueue - - - - - -
  • - - -
  • - msHandle - - - -
  • - - -
  • - msSelect - - - -
  • - - -
  • - identifyDialer - - - -
  • - - -
  • - uniqueBy - - - -
  • - - -
  • - ConnectionManager - - - - - -
  • - - -
  • - ConnectionOptions - - - -
  • - - -
  • - ConnectionFSM - - - - - -
  • - - -
  • - _dial - - - -
  • - - -
  • - start - - - -
  • - - -
  • - stop - - - -
  • - - -
  • - clearDenylist - - - -
  • - - -
  • - connect - - - -
  • - - -
  • - dial - - - -
  • - - -
  • - dialFSM + connectToPeer @@ -840,36 +545,6 @@
  • -
  • - start - - - -
  • - - -
  • - stop - - - -
  • - - -
  • - add - - - -
  • - -
  • @@ -881,9 +556,9 @@
  • - clearDenylist + constructor @@ -891,9 +566,9 @@
  • - getQueue + start @@ -901,9 +576,9 @@
  • - DialRequest + stop @@ -911,9 +586,9 @@
  • - NewConnection + global @@ -921,9 +596,9 @@
  • - createConnectionWithProtocol + peers @@ -931,67 +606,9 @@
  • - Queue - - - - - -
  • - - -
  • - transportKey + forPeer @@ -999,9 +616,9 @@
  • - conn + protocols @@ -1009,9 +626,9 @@
  • - close + forProtocol @@ -1019,9 +636,9 @@
  • - getState + onPeerDisconnected @@ -1029,9 +646,9 @@
  • - encrypt + updatePlaceholder @@ -1039,9 +656,9 @@
  • - protect + trackStream @@ -1049,9 +666,9 @@
  • - upgrade + mergeStats @@ -1059,59 +676,9 @@
  • - _onDisconnected - - - -
  • - - -
  • - _onPrivatized - - - -
  • - - -
  • - observe-connection - - - -
  • - - -
  • - plaintext - - - -
  • - - -
  • - observer - - - -
  • - - -
  • - + old-peers @@ -1155,6 +722,12 @@ #movingAverages
  • +
  • + #toJSON +
  • +
  • @@ -1171,9 +744,9 @@
  • - old-peers + constructor @@ -1181,9 +754,9 @@
  • - findPeer + add @@ -1191,9 +764,9 @@
  • - findProviders + close @@ -1201,9 +774,9 @@
  • - provide + dial @@ -1211,9 +784,9 @@
  • - subscribe + getAddrs @@ -1221,9 +794,9 @@
  • - unsubscribe + getTransports @@ -1231,9 +804,9 @@
  • - getPeerInfo + transportForMultiaddr @@ -1241,9 +814,373 @@
  • - getPeerInfoRemote + listen + + + +
  • + + +
  • + remove + + + +
  • + + +
  • + removeAll + + + +
  • + + +
  • + Upgrader + + + + + +
  • + + +
  • + Upgrader + + + + + +
  • + + +
  • + PeerStore + + + + + +
  • + + +
  • + Registrar + + + + + +
  • + + +
  • + ping + + + +
  • + + +
  • + mount + + + +
  • + + +
  • + unmount + + + +
  • + + +
  • + constructor + + + +
  • + + +
  • + registrar + + + +
  • + + +
  • + peerInfo + + + +
  • + + +
  • + push + + + +
  • + + +
  • + pushToPeerStore + + + +
  • + + +
  • + identify + + + +
  • + + +
  • + handleMessage + + + +
  • + + +
  • + updatePeerAddresses + + + +
  • + + +
  • + updatePeerProtocols + + + +
  • + + +
  • + getCleanMultiaddr @@ -1297,7 +1234,7 @@ - + src/index.js @@ -1366,7 +1303,7 @@
    - + src/index.js @@ -1442,7 +1379,7 @@ if there is a handler. If not, errors will be logged.

    - start(callback) + start()
    @@ -8385,14 +3598,15 @@ The request will be added with a high priority (10).

    - - src/switch/dialer/queueManager.js + + src/connection-manager/index.js
    -

    Allows the DialQueueManager to execute dials

    +

    Starts the Connection Manager. If Metrics are not enabled on libp2p +only event loop and connection limits will be monitored.

    start()
    @@ -8437,16 +3651,14 @@ The request will be added with a high priority (10).

    - - src/switch/dialer/queueManager.js + + src/connection-manager/index.js
  • -

    Iterates over all items in the DialerQueue -and executes there callback with an error.

    -

    This causes the entire DialerQueue to be drained

    +

    Stops the Connection Manager

    stop()
    @@ -8486,21 +3698,22 @@ and executes there callback with an error.

    -

    Adds the dialRequest to the queue and ensures queue is running

    +

    Sets the value of the given peer. Peers with lower values +will be disconnected first.

    -
    add(dialRequest: DialRequest): void
    +
    setPeerValue(peerId: PeerId, value: number)
    @@ -8517,57 +3730,18 @@ and executes there callback with an error.

    - dialRequest (DialRequest) + peerId (PeerId)
    - - - - - - - - - - - - - - - - - + + +
    +
    + value (number) + A number between 0 and 1 - - -
    - - - - - - - - - - - - - - - - - - - - - -
    NameDescription
    dialRequest.peerInfo any -
    dialRequest.protocol any -
    dialRequest.options any -
    dialRequest.callback any -
    +
    @@ -8577,14 +3751,6 @@ and executes there callback with an error.

    - -
    Returns
    - void: - - - - - @@ -8607,73 +3773,21 @@ and executes there callback with an error.

    -

    Will execute up to MAX_PARALLEL_DIALS dials

    +

    Tracks the incoming connection and check the connection limit

    -
    run()
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - -
    - -

    - clearDenylist -

    - - - - src/switch/dialer/queueManager.js - - -
    - - -

    Will remove the peerInfo from the dial denylist

    - -
    clearDenylist(peerInfo: PeerInfo)
    +
    onConnect(connection: Connection)
    @@ -8690,7 +3804,7 @@ and executes there callback with an error.

    - peerInfo (PeerInfo) + connection (Connection)
    @@ -8724,21 +3838,21 @@ and executes there callback with an error.

    -

    Returns the Queue for the given peerInfo

    +

    Removes the connection from tracking

    -
    getQueue(peerInfo: PeerInfo): Queue
    +
    onDisconnect(connection: Connection)
    @@ -8755,7 +3869,7 @@ and executes there callback with an error.

    - peerInfo (PeerInfo) + connection (Connection)
    @@ -8767,14 +3881,6 @@ and executes there callback with an error.

    - -
    Returns
    - Queue: - - - - - @@ -8797,193 +3903,21 @@ and executes there callback with an error.

    -

    Components required to execute a dial

    +

    Creates an instance of Circuit.

    -
    DialRequest
    - -

    - Type: - Object -

    - - - - - - - - - - - - - -
    Properties
    -
    - -
    - peerInfo (PeerInfo) - : The peer to dial to - - -
    - -
    - protocol (string?) - : The protocol to create a stream for - - -
    - -
    - options (object) - - -
      - -
    • options.useFSM boolean - -

      If callback should return a ConnectionFSM

      -
    • - -
    • options.priority number - -

      The priority of the dial

      -
    • - -
    - -
    - -
    - - - - - - - - - - - - - - - -
    - - - - -
    - - -
    - -

    - NewConnection -

    - - - - src/switch/dialer/queue.js - - -
    - - - -
    NewConnection
    - -

    - Type: - Object -

    - - - - - - - - - - - - - -
    Properties
    -
    - -
    - connectionFSM (ConnectionFSM) - - -
    - -
    - didCreate (boolean) - - -
    - -
    - - - - - - - - - - - - - - - -
    - - - - -
    - - -
    - -

    - createConnectionWithProtocol -

    - - - - src/switch/dialer/queue.js - - -
    - - -

    Attempts to create a new connection or stream (when muxed), -via negotiation of the given protocol. If no protocol is -provided, no action will be taken and callback will be called -immediately with no error or values.

    - -
    createConnectionWithProtocol(options: object): void
    +
    new constructor(options: object)
    @@ -9018,7 +3952,7 @@ immediately with no error or values.

    - options.protocol string + options.libp2p Libp2p @@ -9026,15 +3960,7 @@ immediately with no error or values.

    - options.connection ConnectionFSM - - - - - - - - options.callback function (Error, Connection) + options.upgrader Upgrader @@ -9052,9 +3978,190 @@ immediately with no error or values.

    + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + dial +

    + + + + src/circuit/index.js + + +
    + + +

    Dial a peer over a relay

    + +
    dial(ma: multiaddr, options: Object): Connection
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + ma (multiaddr) + the multiaddr of the peer to dial + +
    + +
    + +
    +
    + options (Object) + dial options + +
    + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.signal AbortSignal? + An optional abort signal +
    + +
    + +
    + + + + +
    Returns
    - void: + Connection: + the connection + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + createListener +

    + + + + src/circuit/index.js + + +
    + + +

    Create a listener

    + +
    createListener(options: any, handler: Function): listener
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + options (any) + +
    + +
    + +
    +
    + handler (Function) + +
    + +
    + +
    + + + + + + +
    Returns
    + listener: @@ -9082,22 +4189,21 @@ immediately with no error or values.

    -

    A convenience array wrapper for controlling -a per peer queue

    +

    Filter check for all Multiaddrs that this transport can dial on

    -
    new Queue(peerId: string, _switch: Switch, onStopped: function (string)): Queue
    +
    filter(multiaddrs: Array<Multiaddr>): Array<Multiaddr>
    @@ -9114,29 +4220,12 @@ a per peer queue

    - peerId (string) + multiaddrs (Array<Multiaddr>)
    -
    -
    - _switch (Switch) - -
    - -
    - -
    -
    - onStopped (function (string)) - Called when the queue stops - -
    - -
    - @@ -9145,7 +4234,7 @@ a per peer queue

    Returns
    - Queue: + Array<Multiaddr>: @@ -9159,14 +4248,84 @@ a per peer queue

    -
    Instance Members
    + + + + +
    + + + + +
    + + +
    + +

    + listener +

    + + + + src/circuit/listener.js + + +
    + + + +
    listener(circuit: any): Listener
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + circuit (any) + +
    + +
    + +
    + + + + + + +
    Returns
    + Listener: + a transport listener + + + + + + + + + + +
    Static Members
    -
    +
    - add(protocol, useFSM, callback) + listen(addr)
    -
    +
    - isDialAllowed() + close()
    - - - - -
    -
    -
    - - start() -
    -
    - -
    - -
    -
    -
    - - stop() -
    -
    - -
    - -
    -
    -
    - - abort() -
    -
    - -
    - -
    -
    -
    - - denylist() -
    -
    - +
    + +
    +
    +
    + + getAddrs() +
    +
    + @@ -9568,6 +4542,8 @@ If the queue was already running false is returned.

    + + @@ -9578,21 +4554,22 @@ If the queue was already running false is returned.

    -

    Takes a transport key and returns a connection handler function

    +

    Performs a HOP request to a relay peer, to request a connection to another +peer. A new, virtual, connection will be created between the two via the relay.

    -
    transportKey
    +
    hop(options: object): Promise<Connection>
    @@ -9609,19 +4586,50 @@ If the queue was already running false is returned.

    - transportKey (string) - The key of the transport to handle connections for - + options (object) +
    -
    - -
    -
    - handler (function) - A custom handler to use + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + +
    NameDescription
    options.connection Connection + Connection to the relay +
    options.request any +
    options.circuit Circuit +
    @@ -9633,8 +4641,8 @@ If the queue was already running false is returned.

    Returns
    - function (Connection): - A connection handler function + Promise<Connection>: + @@ -9661,21 +4669,21 @@ If the queue was already running false is returned.

    -

    Takes a base connection and manages listening behavior

    +

    Write a response

    -
    conn
    +
    writeResponse(streamHandler: StreamHandler, status: CircuitRelay.Status)
    @@ -9692,9 +4700,16 @@ If the queue was already running false is returned.

    - conn (Connection) - The connection to manage - + streamHandler (StreamHandler) + +
    + +
    + +
    +
    + status (CircuitRelay.Status) +
    @@ -9705,6 +4720,233 @@ If the queue was already running false is returned.

    + + + + + + + + + + + + + + + + + +
    + + +
    + +

    + validateAddrs +

    + + + + src/circuit/circuit/utils.js + + +
    + + +

    Validate incomming HOP/STOP message

    + +
    validateAddrs(msg: any, streamHandler: StreamHandler)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + msg (any) + A CircuitRelay unencoded protobuf message + +
    + +
    + +
    +
    + streamHandler (StreamHandler) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + constructor +

    + + + + src/circuit/circuit/stream-handler.js + + +
    + + +

    Create a stream handler for connection

    + +
    constructor(options: object)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + options (object) + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.stream any + A duplex iterable +
    options.maxLength Number + + (default 4096) + max bytes length of message +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + + + + +

    Read and decode message

    + +
    read(): void
    + + + + + + + + + + + + + + +
    Returns
    void: @@ -9725,6 +4967,132 @@ If the queue was already running false is returned.

    +
    + + + + +
    + + + + + +

    Encode and write array of buffers

    + +
    write(msg: any)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + msg (any) + An unencoded CircuitRelay protobuf message + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + + + + +

    Return the handshake rest stream and invalidate handler

    + +
    rest(): any
    + + + + + + + + + + + + + + + + +
    Returns
    + any: + A duplex iterable + + + + + + + + + + + + + + + +
    @@ -9740,16 +5108,75 @@ If the queue was already running false is returned.

    - - src/switch/connection/base.js + + src/circuit/circuit/stream-handler.js
    -

    Puts the state into its disconnecting flow

    +

    Close the stream

    -
    close(err: Error): void
    +
    close(): void
    + + + + + + + + + + + + + + + + +
    Returns
    + void: + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +

    + constructor +

    + + + + src/dialer/index.js + + +
    + + + +
    new constructor($0: Object, options: object, peerStore: Peerstore)
    @@ -9766,11 +5193,284 @@ If the queue was already running false is returned.

    - err (Error) - Will be emitted if provided - + $0 (Object) +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    $0.transportManager any +
    $0.peerStore any +
    $0.concurrency any + + (default MAX_PARALLEL_DIALS) +
    $0.timeout any + + (default DIAL_TIMEOUT) +
    $0.perPeerLimit any + + (default MAX_PER_PEER_DIALS) +
    + +
    + +
    +
    + options (object) + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.transportManager TransportManager +
    options.concurrency number + Number of max concurrent dials. Defaults to +MAX_PARALLEL_DIALS +
    options.timeout number + How long a dial attempt is allowed to take. Defaults to +DIAL_TIMEOUT +
    + +
    + +
    +
    + peerStore (Peerstore) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +

    + destroy +

    + + + + src/dialer/index.js + + +
    + + +

    Clears any pending dials

    + +
    destroy()
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + connectToMultiaddr +

    + + + + src/dialer/index.js + + +
    + + +

    Connects to the first success of a given list of Multiaddr. addrs should +include the id of the peer being dialed, it will be used for encryption verification.

    + +
    connectToMultiaddr(addrs: (Array<Multiaddr> | Multiaddr), options: object?): Promise<Connection>
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + addrs ((Array<Multiaddr> | Multiaddr)) + +
    + +
    + +
    +
    + options (object? + = {}) + +
    + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.signal AbortSignal? + An AbortController signal +
    +
    @@ -9781,7 +5481,7 @@ If the queue was already running false is returned.

    Returns
    - void: + Promise<Connection>: @@ -9809,384 +5509,23 @@ If the queue was already running false is returned.

    -

    Gets the current state of the connection

    +

    Connects to a given PeerInfo or PeerId by dialing all of its known addresses. +The dial to the first address that is successfully able to upgrade a connection +will be used.

    -
    getState(): string
    - - - - - - - - - - - - - - - - -
    Returns
    - string: - The current state of the connection - - - - - - - - - - - - - - - - -
    - - - - -
    - - -
    - -

    - encrypt -

    - - - - src/switch/connection/base.js - - -
    - - -

    Puts the state into encrypting mode

    - -
    encrypt(): void
    - - - - - - - - - - - - - - - - -
    Returns
    - void: - - - - - - - - - - - - - - - - - -
    - - - - -
    - - -
    - -

    - protect -

    - - - - src/switch/connection/base.js - - -
    - - -

    Puts the state into privatizing mode

    - -
    protect(): void
    - - - - - - - - - - - - - - - - -
    Returns
    - void: - - - - - - - - - - - - - - - - - -
    - - - - -
    - - -
    - -

    - upgrade -

    - - - - src/switch/connection/base.js - - -
    - - -

    Puts the state into muxing mode

    - -
    upgrade(): void
    - - - - - - - - - - - - - - - - -
    Returns
    - void: - - - - - - - - - - - - - - - - - -
    - - - - -
    - - -
    - -

    - _onDisconnected -

    - - - - src/switch/connection/base.js - - -
    - - -

    Event handler for disconnected.

    - -
    _onDisconnected(): void
    - - - - - - - - - - - - - - - - -
    Returns
    - void: - - - - - - - - - - - - - - - - - -
    - - - - -
    - - -
    - -

    - _onPrivatized -

    - - - - src/switch/connection/base.js - - -
    - - -

    Event handler for privatized

    - -
    _onPrivatized(): void
    - - - - - - - - - - - - - - - - -
    Returns
    - void: - - - - - - - - - - - - - - - - - -
    - - - - -
    - - -
    - -

    - observe-connection -

    - - - - src/switch/observe-connection.js - - -
    - - -

    Creates a pull stream to run the given Connection stream through -the given Observer. This provides a way to more easily monitor connections -and their metadata. A new Connection will be returned that contains -has the attached Observer.

    - -
    observe-connection(transport: Transport, protocol: string, connection: Connection, observer: Observer): Connection
    +
    connectToPeer(peerId: PeerId, options: object?): Promise<Connection>
    @@ -10203,34 +5542,251 @@ has the attached Observer.

    - transport (Transport) - + peerId (PeerId) + The remote peer id to dial +
    - protocol (string) + options (object? + = {})
    -
    - -
    -
    - connection (Connection) - -
    + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.signal AbortSignal? + An AbortController signal +
    + + + + + + + +
    Returns
    + Promise<Connection>: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + constructor +

    + + + + src/dialer/dial-request.js + + +
    + + +

    Manages running the dialAction on multiple provided addrs in parallel +up to a maximum determined by the number of tokens returned +from dialer.getTokens. Once a DialRequest is created, it can be +started using DialRequest.run(options). Once a single dial has succeeded, +all other dials in the request will be cancelled.

    + +
    constructor(options: object)
    + + + + + + + + + + + +
    Parameters
    +
    +
    - observer (Observer) + options (object)
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.addrs Array<Multiaddr> +
    options.dialAction function (Multiaddr): Promise<Connection> +
    options.dialer Dialer +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + run +

    + + + + src/dialer/dial-request.js + + +
    + + + +
    run(options: object): Connection
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + options (object) + +
    + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.signal AbortSignal + An AbortController signal +
    +
    @@ -10269,77 +5825,20 @@ has the attached Observer.

    -

    An encryption stub in the instance that the default crypto -has not been overriden for the Switch

    - -
    plaintext
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - -
    - - -
    - -

    - observer -

    - - - - src/switch/observer.js - - -
    - - -

    Takes a Switch and returns an Observer that can be used in conjunction with -observe-connection.js. The returned Observer comes with incoming and -outgoing properties that can be used in pull streams to emit all metadata -for messages that pass through a Connection.

    - -
    observer(swtch: Switch): EventEmitter
    +
    constructor(options: object)
    @@ -10356,10 +5855,58 @@ for messages that pass through a Connection.

    - swtch (Switch) + options (object)
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.computeThrottleMaxQueueSize number +
    options.computeThrottleTimeout number +
    options.movingAverageIntervals Array<number> +
    options.maxOldPeersRetention number +
    +
    @@ -10368,9 +5915,167 @@ for messages that pass through a Connection.

    + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + start +

    + + + + src/metrics/index.js + + +
    + + +

    Must be called for stats to saved. Any data pushed for tracking +will be ignored.

    + +
    start()
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + stop +

    + + + + src/metrics/index.js + + +
    + + +

    Stops all averages timers and prevents new data from being tracked. +Once stop is called, start must be called to resume stats tracking.

    + +
    stop()
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + global +

    + + + + src/metrics/index.js + + +
    + + +

    Gets the global Stats object

    + +
    global
    + + + + + + + + + + + + + + +
    Returns
    - EventEmitter: + Stats: @@ -10398,23 +6103,82 @@ for messages that pass through a Connection.

    -

    Binds to message events on the given observer to generate stats -based on the Peer, Protocol and Transport used for the message. Stat -events will be emitted via the update event.

    +

    Returns a list of PeerId strings currently being tracked

    -
    +
    peers
    + + + + + + + + + + + + + + + + +
    Returns
    + Array<string>: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + forPeer +

    + + + + src/metrics/index.js + + +
    + + +

    Returns the Stats object for the given PeerId whether it +is a live peer, or in the disconnected peer LRU cache.

    + +
    forPeer(peerId: PeerId): Stats
    @@ -10431,15 +6195,7 @@ events will be emitted via the update event.

    - observer (Observer) - -
    - -
    - -
    -
    - _options (any) + peerId (PeerId)
    @@ -10471,6 +6227,565 @@ events will be emitted via the update event.

    +
    + + + + +
    + + +
    + +

    + protocols +

    + + + + src/metrics/index.js + + +
    + + +

    Returns a list of all protocol strings currently being tracked.

    + +
    protocols
    + + + + + + + + + + + + + + + + +
    Returns
    + Array<string>: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + forProtocol +

    + + + + src/metrics/index.js + + +
    + + +

    Returns the Stats object for the given protocol.

    + +
    forProtocol(protocol: string): Stats
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + protocol (string) + +
    + +
    + +
    + + + + + + +
    Returns
    + Stats: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + onPeerDisconnected +

    + + + + src/metrics/index.js + + +
    + + +

    Should be called when all connections to a given peer +have closed. The Stats collection for the peer will +be stopped and moved to an LRU for temporary retention.

    + +
    onPeerDisconnected(peerId: PeerId)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + peerId (PeerId) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + updatePlaceholder +

    + + + + src/metrics/index.js + + +
    + + +

    Replaces the PeerId string with the given peerId. +If stats are already being tracked for the given peerId, the +placeholder stats will be merged with the existing stats.

    + +
    updatePlaceholder(placeholder: string, peerId: PeerId)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + placeholder (string) + A peerId string + +
    + +
    + +
    +
    + peerId (PeerId) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + trackStream +

    + + + + src/metrics/index.js + + +
    + + +

    Tracks data running through a given Duplex Iterable stream. If +the peerId is not provided, a placeholder string will be created and +returned. This allows lazy tracking of a peer when the peer is not yet known. +When the PeerId is known, Metrics.updatePlaceholder should be called +with the placeholder string returned from here, and the known PeerId.

    + +
    trackStream(options: Object): string
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + options (Object) + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.stream {sink: function (any), source: function ()} + A duplex iterable stream +
    options.protocol string? + The protocol the stream is running +
    options.peerId PeerId? + The id of the remote peer that's connected +
    options.remotePeer any +
    + +
    + +
    + + + + + + +
    Returns
    + string: + The peerId string or placeholder string + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + mergeStats +

    + + + + src/metrics/index.js + + +
    + + +

    Merges other into target. target will be modified +and returned.

    + +
    mergeStats(target: Stats, other: Stats): Stats
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + target (Stats) + +
    + +
    + +
    +
    + other (Stats) + +
    + +
    + +
    + + + + + + +
    Returns
    + Stats: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + old-peers +

    + + + + src/metrics/old-peers.js + + +
    + + +

    Creates and returns a Least Recently Used Cache

    + +
    old-peers(maxSize: Number): LRUCache
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + maxSize (Number) + +
    + +
    + +
    + + + + + + +
    Returns
    + LRUCache: + + + + + + + + + + + + + + + + +
    @@ -10486,8 +6801,8 @@ events will be emitted via the update event.

    - - src/switch/stats/stat.js + + src/metrics/stats.js @@ -10564,8 +6879,8 @@ events will be emitted via the update event.

    @@ -10630,8 +6945,8 @@ should only need to be called if Stats.stop was previously called, @@ -10695,8 +7010,8 @@ timer.

    @@ -10759,8 +7074,8 @@ timer.

    @@ -10804,6 +7119,70 @@ timer.

    + + + + + +
    +
    +
    + + toJSON() +
    +
    + @@ -10823,8 +7202,8 @@ timer.

    @@ -10912,21 +7291,20 @@ current Timestamp, then resets the update timer.

    -

    Creates and returns a Least Recently Used Cache

    - -
    old-peers(maxSize: Number): LRUCache
    + +
    new constructor(options: object)
    @@ -10941,88 +7319,6 @@ current Timestamp, then resets the update timer.

    Parameters
    -
    -
    - maxSize (Number) - -
    - -
    - -
    - - - - - - -
    Returns
    - LRUCache: - - - - - - - - - - - - - - - - - - - - - - -
    - - -
    - -

    - findPeer -

    - - - - src/peer-routing.js - - -
    - - -

    Iterates over all peer routers in series to find the given peer.

    - -
    findPeer
    - - - - - - - - - - - -
    Parameters
    -
    - -
    -
    - id (String) - The id of the peer to find - -
    - -
    -
    options (object) @@ -11043,9 +7339,18 @@ current Timestamp, then resets the update timer.

    - options.maxTimeout number + options.libp2p Libp2p - How long the query should run + The Libp2p instance. It will be passed to the transports. + + + + + + + options.upgrader Upgrader + + The upgrader to provide to the transports @@ -11056,9 +7361,74 @@ current Timestamp, then resets the update timer.

    +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + add +

    + + + + src/transport-manager.js + + +
    + + +

    Adds a Transport to the manager

    + +
    add(key: String, Transport: Transport): void
    + + + + + + + + + + + +
    Parameters
    +
    +
    - callback (function (Error, Result<Array>)) + key (String) + +
    + +
    + +
    +
    + Transport (Transport)
    @@ -11100,22 +7470,73 @@ current Timestamp, then resets the update timer.

    -

    Iterates over all content routers in series to find providers of the given key. -Once a content router succeeds, iteration will stop.

    +

    Stops all listeners

    -
    findProviders
    +
    close()
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + dial +

    + + + + src/transport-manager.js + + +
    + + +

    Dials the given Multiaddr over it's supported transport

    + +
    dial(ma: Multiaddr, options: any): Promise<Connection>
    @@ -11132,16 +7553,464 @@ Once a content router succeeds, iteration will stop.

    - key (CID) - The CID key of the content to find - + ma (Multiaddr) +
    - options (object) + options (any) + +
    + +
    + +
    + + + + + + +
    Returns
    + Promise<Connection>: + + + + + + + + + + + + + + + + + + + + + + +
    + + +
    + +

    + getAddrs +

    + + + + src/transport-manager.js + + +
    + + +

    Returns all Multiaddr's the listeners are using

    + +
    getAddrs(): Array<Multiaddr>
    + + + + + + + + + + + + + + + + +
    Returns
    + Array<Multiaddr>: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + getTransports +

    + + + + src/transport-manager.js + + +
    + + +

    Returns all the transports instances.

    + +
    getTransports(): Iterator<Transport>
    + + + + + + + + + + + + + + + + +
    Returns
    + Iterator<Transport>: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + transportForMultiaddr +

    + + + + src/transport-manager.js + + +
    + + +

    Finds a transport that matches the given Multiaddr

    + +
    transportForMultiaddr(ma: Multiaddr): (Transport | null)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + ma (Multiaddr) + +
    + +
    + +
    + + + + + + +
    Returns
    + (Transport | null): + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + listen +

    + + + + src/transport-manager.js + + +
    + + +

    Starts listeners for each given Multiaddr.

    + +
    listen(addrs: Array<Multiaddr>)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + addrs (Array<Multiaddr>) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + remove +

    + + + + src/transport-manager.js + + +
    + + +

    Removes the given transport from the manager. +If a transport has any running listeners, they will be closed.

    + +
    remove(key: string)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + key (string) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + removeAll +

    + + + + src/transport-manager.js + + +
    + + +

    Removes all transports from the manager. +If any listeners are running, they will be closed.

    + +
    removeAll()
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + Upgrader +

    + + + + src/upgrader.js + + +
    + + + +
    new Upgrader($0: Object)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + $0 (Object)
    @@ -11159,19 +8028,374 @@ Once a content router succeeds, iteration will stop.

    - options.maxTimeout number + $0.localPeer any - How long the query should run - + - options.maxNumProviders number + $0.metrics any - maximum number of providers to find - + + + + + + + $0.cryptos any + + + + + + + + $0.muxers any + + + + + + + + $0.onConnectionEnd any + + (default ()=>{}) + + + + + + + + $0.onConnection any + + (default ()=>{}) + + + + + + + + + +
    + +
    + + + +
    Properties
    +
    + +
    + sink (function) + + +
    + +
    + source (AsyncIterator) + + +
    + +
    + conn (any) + + +
    + +
    + remoteAddr (Multiaddr) + + +
    + +
    + + + + + + + + + + + +
    Instance Members
    +
    + +
    +
    +
    + + upgradeInbound(maConn) +
    +
    + +
    + +
    +
    +
    + + upgradeOutbound(maConn) +
    +
    + +
    + +
    + + + + + + +
    + + + + +
    + + +
    + +

    + Upgrader +

    + + + + src/upgrader.js + + +
    + + + +
    new Upgrader($0: Object, options: object)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + $0 (Object) + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -11183,7 +8407,94 @@ Once a content router succeeds, iteration will stop.

    - callback (function (Error, Result<Array>)) + options (object) + +
    + +
    + + + + + +
    Properties
    +
    + +
    + conn (any) + : A duplex iterable + + +
    + +
    + remotePeer (PeerId) + + +
    + +
    + protocol (string) + + +
    + +
    + + + + + + + + + + + +
    Instance Members
    +
    + +
    +
    +
    + + upgradeInbound(maConn) +
    +
    + +
    + +
    +
    +
    + + upgradeOutbound(maConn) +
    +
    + - - - - - -
    Returns
    - (Promise | void): - A promise is returned if no callback is provided - - - - - - - - -
    Example
    - -

    Subscribe a handler to a topic

    -

    -
    // `null` must be passed for options until subscribe is no longer using promisify
    -const handler = (message) => { }
    -await libp2p.subscribe(topic, handler, null)
    - -

    Use a callback instead of the Promise api

    -

    -
    // `options` may be passed or omitted when supplying a callback
    -const handler = (message) => { }
    -libp2p.subscribe(topic, handler, callback)
    - - - - +
    @@ -11422,94 +8625,101 @@ libp2p.subscribe(topic, handler, callback)
    -

    - unsubscribe +

    + PeerStore

    - - src/pubsub.js + + src/peer-store/index.js
    -

    Unsubscribes from a pubsub topic

    +

    Responsible for managing known peers, as well as their addresses and metadata

    -
    unsubscribe(topic: string, handler: (function | null), callback: function?): (Promise | void)
    +
    new PeerStore()
    - - - - - - - - - -
    Parameters
    -
    +

    + Extends -

    -
    - topic (string) - -
    - + EventEmitter + +

    + + + + + + + + + + + + + + + + + + + + + + +
    Instance Members
    +
    + +
    +
    +
    + + peers
    - -
    -
    - handler ((function | null)) - The handler to unsubscribe from +
    + - -
    - -
    -
    - callback (function?) - An optional callback + + + -
    - -
    - -
    +

    Map of peers

    + +
    peers
    + +

    + Type: + Map<string, PeerInfo> +

    + + + + + + + + - -
    Returns
    - (Promise | void): - A promise is returned if no callback is provided - - - - -
    Example
    - -

    Unsubscribe a topic for all handlers

    -

    -
    // `null` must be passed until unsubscribe is no longer using promisify
    -await libp2p.unsubscribe(topic, null)
    - -

    Unsubscribe a topic for 1 handler

    -

    -
    await libp2p.unsubscribe(topic, handler)
    - -

    Use a callback instead of the Promise api

    -

    -
    libp2p.unsubscribe(topic, handler, callback)
    - + @@ -11521,31 +8731,34 @@ libp2p.subscribe(topic, handler, callback) - - - -
    +
    +
    + +
    +
    +
    + + put(peerInfo) +
    +
    + +
    + +
    +
    +
    + + add(peerInfo) +
    +
    + +
    + +
    +
    +
    + + update(peerInfo) +
    +
    + +
    + +
    +
    +
    + + get(peerId) +
    +
    + +
    + +
    +
    +
    + + has(peerId) +
    +
    + +
    + +
    +
    +
    + + remove(peerId) +
    +
    + +
    + +
    +
    +
    + + replace(peerInfo) +
    +
    + +
    + +
    +
    +
    + + multiaddrsForPeer(peerId) +
    +
    + +
    + +
    + + + + + + + + + + + +
    + + +
    + +

    + Registrar +

    + + + + src/registrar.js + + +
    + + +

    Responsible for notifying registered protocols of events in the network.

    + +
    new Registrar($0: Object, props: Object)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + $0 (Object) + +
    + +
    NameDescription
    $0.localPeer any +
    $0.metrics any +
    $0.cryptos any +
    $0.muxers any +
    $0.onConnectionEnd any + + (default ()=>{}) +
    $0.onConnection any + + (default ()=>{}) +
    + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    $0.peerStore any +
    + +
    + +
    +
    + props (Object) + +
    + +
    + +
    + + + + + + + + + + + + + +
    Instance Members
    +
    + +
    +
    +
    + + connections +
    +
    + +
    + +
    +
    +
    + + topologies +
    +
    + +
    + +
    +
    +
    + + close() +
    +
    + +
    + +
    +
    +
    + + onConnect(peerInfo, conn) +
    +
    + +
    + +
    +
    +
    + + onDisconnect(peerInfo, connection, error?) +
    +
    + +
    + +
    +
    +
    + + getConnection(peerInfo) +
    +
    + +
    + +
    +
    +
    + + register(topology) +
    +
    + +
    + +
    +
    +
    + + unregister(id) +
    +
    + +
    + +
    + + + + + + +
    + + + + +
    + + +
    + +

    + ping +

    + + + + src/ping/index.js + + +
    + + +

    Ping a given peer and wait for its response, getting the operation latency.

    + +
    ping(node: Libp2p, peer: PeerInfo): Promise<Number>
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + node (Libp2p) + +
    + +
    + +
    +
    + peer (PeerInfo) + +
    + +
    + +
    + + + + + + +
    Returns
    + Promise<Number>: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + mount +

    + + + + src/ping/index.js + + +
    + + +

    Subscribe ping protocol handler.

    + +
    mount(node: Libp2p)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + node (Libp2p) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + unmount +

    + + + + src/ping/index.js + + +
    + + +

    Unsubscribe ping protocol handler.

    + +
    unmount(node: Libp2p)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + node (Libp2p) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + constructor +

    + + + + src/identify/index.js + + +
    + + + +
    new constructor(options: object)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + options (object) + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.registrar Registrar +
    options.protocols Map<string, handler> + A reference to the protocols we support +
    options.peerInfo PeerInfo + The peer running the identify service +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + registrar +

    + + + + src/identify/index.js + + +
    + + + +
    registrar
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + peerInfo +

    + + + + src/identify/index.js + + +
    + + + +
    peerInfo
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + push +

    + + + + src/identify/index.js + + +
    + + +

    Send an Identify Push update to the list of connections

    + +
    push(connections: Array<Connection>): Promise<void>
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + connections (Array<Connection>) + +
    + +
    + +
    + + + + + + +
    Returns
    + Promise<void>: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + pushToPeerStore +

    + + + + src/identify/index.js + + +
    + + +

    Calls push for all peers in the peerStore that are connected

    + +
    pushToPeerStore(peerStore: PeerStore)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + peerStore (PeerStore) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + identify +

    + + + + src/identify/index.js + + +
    + + +

    Requests the Identify message from peer associated with the given connection. +If the identified peer does not match the PeerId associated with the connection, +an error will be thrown.

    + +
    identify(connection: Connection): Promise<void>
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + connection (Connection) + +
    + +
    + +
    + + + + + + +
    Returns
    + Promise<void>: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + handleMessage +

    + + + + src/identify/index.js + + +
    + + +

    A handler to register with Libp2p to process identify messages.

    + +
    handleMessage(options: object): Promise<void>
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + options (object) + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameDescription
    options.connection Connection +
    options.stream any +
    options.protocol String +
    + +
    + +
    + + + + + + +
    Returns
    + Promise<void>: + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + updatePeerAddresses +

    + + + + src/identify/index.js + + +
    + + +

    Replaces the multiaddrs on the given peerInfo, +with the provided multiaddrs

    + +
    updatePeerAddresses(peerInfo: PeerInfo, multiaddrs: (Array<Multiaddr> | Array<Buffer>))
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + peerInfo (PeerInfo) + +
    + +
    + +
    +
    + multiaddrs ((Array<Multiaddr> | Array<Buffer>)) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + updatePeerProtocols +

    + + + + src/identify/index.js + + +
    + + +

    Replaces the protocols on the given peerInfo, +with the provided protocols

    + +
    updatePeerProtocols(peerInfo: PeerInfo, protocols: Array<string>)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + peerInfo (PeerInfo) + +
    + +
    + +
    +
    + protocols (Array<string>) + +
    + +
    + +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + + +
    + +

    + getCleanMultiaddr +

    + + + + src/identify/index.js + + +
    + + +

    Takes the addr and converts it to a Multiaddr if possible

    + +
    getCleanMultiaddr(addr: (Buffer | String)): (Multiaddr | null)
    + + + + + + + + + + + +
    Parameters
    +
    + +
    +
    + addr ((Buffer | String)) + +
    + +
    + +
    + + + + + + +
    Returns
    + (Multiaddr | null):