Intro
Installable via npm install --save libp2p
, it can also be used directly in the browser.
Libp2p
Parameters
_options: any
:
instance
Libp2p.prototype.emit
emit(eventName: string, args: ...any): void
Overrides EventEmitter.emit to conditionally emit errors + + +
+ Libp2p +
+ + + + src/index.js + + ++ Extends + + EventEmitter + +
+ + + + + + + + + + +(any)
+
+ Overrides EventEmitter.emit to conditionally emit errors if there is a handler. If not, errors will be logged.
-Parameters
eventName: string
:args: ...any
:
Returns
void
-Libp2p.prototype.start
start(callback: function (Error)): void
Starts the libp2p node and all sub services
-Parameters
callback: function (Error) (=()=>{})
:
Returns
void
-Libp2p.prototype.stop
stop(callback: function (Error)): void
Stop the libp2p node by closing its listeners and open connections
-Parameters
callback: function (Error) (=()=>{})
:
Returns
void
-Libp2p.prototype.dial
dial(peer: (PeerInfo | PeerId | Multiaddr | string), callback: function (Error)): void
+ Starts the libp2p node and all sub services
+ +(function (Error)
+ = ()=>{}
)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Stop the libp2p node by closing its listeners and open connections
+ +(function (Error)
+ = ()=>{}
)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Dials to the provided peer. If successful, the PeerInfo
of the
peer will be added to the nodes PeerBook
Parameters
Returns
void
-Libp2p.prototype.dialProtocol
dialProtocol(peer: (PeerInfo | PeerId | Multiaddr | string), protocol: string, callback: function (Error, Connection)): void
Dials to the provided peer and handshakes with the given protocol. + +
+ + + + + + + + + + + +((PeerInfo | PeerId | Multiaddr | string))
+ The peer to dial
+
+ (function (Error))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Dials to the provided peer and handshakes with the given protocol.
If successful, the PeerInfo
of the peer will be added to the nodes PeerBook
,
and the Connection
will be sent in the callback
Parameters
Returns
void
-Libp2p.prototype.dialFSM
dialFSM(peer: (PeerInfo | PeerId | Multiaddr | string), protocol: string, callback: function (Error, ConnectionFSM)): void
Similar to dial
and dialProtocol
, but the callback will contain a
+
+
((PeerInfo | PeerId | Multiaddr | string))
+ The peer to dial
+
+ (string)
+
+ (function (Error, Connection))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Similar to dial
and dialProtocol
, but the callback will contain a
Connection State Machine.
Parameters
Returns
void
-createLibp2p
Like new Libp2p(options)
except it will create a PeerInfo
+
+
((PeerInfo | PeerId | Multiaddr | string))
+ The peer to dial
+
+ (string)
+
+ (function (Error, ConnectionFSM))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Disconnects from the given peer
+ + + + + + + + + + + + + +((PeerInfo | PeerId | Multiaddr | string))
+ The peer to ping
+
+ (function (Error))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Pings the provided peer
+ + + + + + + + + + + + + +((PeerInfo | PeerId | Multiaddr | string))
+ The peer to ping
+
+ (function (Error, Ping))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ createLibp2p +
+ + + + src/index.js + + +Like new Libp2p(options)
except it will create a PeerInfo
instance if one is not provided in options.
Returns
void
-findPeer
Iterates over all peer routers in series to find the given peer.
-Parameters
id: String
:The id of the peer to find -
Returns
void
-findProviders
Iterates over all content routers in series to find providers of the given key. + +
(object)
+ Libp2p configuration options
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + Switch +
+ + + + src/switch/index.js + + ++ Extends + + EventEmitter + +
+ + + + + + + + + + +(any)
+
+ (any)
+
+ (any)
+
+ Returns a list of the transports peerInfo has addresses for
+ +(PeerInfo)
+
+ Array<Transport>
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Adds the handlerFunc
and matchFunc
to the Switch's protocol
+handler list for the given protocol
. If the matchFunc
returns
+true for a protocol check, the handlerFunc
will be called.
(string)
+
+ (function (string, Connection))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Removes the given protocol from the Switch's protocol list
+ +(string)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+If a muxed Connection exists for the given peer, it will be closed +and its reference on the Switch will be removed.
+ +((PeerInfo | Multiaddr | PeerId))
+
+ (function ())
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns whether or not the switch has any transports
+ +boolean
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Issues a start on the Switch state.
+ +(function
+ = ()=>{}
)
+ deprecated: Listening for the
+error
+ and
+start
+ events are recommended
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Issues a stop on the Switch state.
+ +(function
+ = ()=>{}
)
+ deprecated: Listening for the
+error
+ and
+stop
+ events are recommended
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ constructor +
+ + + + src/circuit/circuit.js + + +Creates an instance of Dialer.
+ +(Swarm)
+ the swarm
+
+ (any)
+ config options
+
+ + _dialSwarmRelays +
+ + + + src/circuit/circuit.js + + +Dial the relays in the Addresses.Swarm config
+ +(Array)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ dial +
+ + + + src/circuit/circuit.js + + +Dial a peer over a relay
+ + + + + + + + + + + + + +(multiaddr)
+ the multiaddr of the peer to dial
+
+ (Object)
+ dial options
+
+ (Function)
+ a callback called once dialed
+
+ Connection
:
+ the connection
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ createListener +
+ + + + src/circuit/circuit.js + + +Create a listener
+ +(any)
+
+ (Function)
+
+ listener
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ filter +
+ + + + src/circuit/circuit.js + + +Filter check for all multiaddresses +that this transport can dial on
+ +(any)
+
+ Array<multiaddr>
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ constructor +
+ + + + src/circuit/circuit/dialer.js + + +Creates an instance of Dialer.
+ +(Swarm)
+ the swarm
+
+ (any)
+ config options
+
+ + _dialRelayHelper +
+ + + + src/circuit/circuit/dialer.js + + +Helper that returns a relay connection
+ +(any)
+
+ (any)
+
+ Function
:
+ callback
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ dial +
+ + + + src/circuit/circuit/dialer.js + + +Dial a peer over a relay
+ +(multiaddr)
+ the multiaddr of the peer to dial
+
+ (Function)
+ a callback called once dialed
+
+ Connection
:
+ the connection
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ canHop +
+ + + + src/circuit/circuit/dialer.js + + +Does the peer support the HOP protocol
+ +(PeerInfo)
+
+ (Function)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ constructor +
+ + + + src/circuit/circuit/stream-handler.js + + +Create a stream handler for connection
+ + + + + + + + + + + + + ++ read +
+ + + + src/circuit/circuit/stream-handler.js + + +Read and decode message
+ + + + + + + + + + + + + +(Function)
+
+ (void | Function)
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ write +
+ + + + src/circuit/circuit/stream-handler.js + + +Encode and write array of buffers
+ + + + + + + + + + + + + +Function
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ getRawConn +
+ + + + src/circuit/circuit/stream-handler.js + + +Get the raw Connection
+ +(null | Connection | any)
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ rest +
+ + + + src/circuit/circuit/stream-handler.js + + +Return the handshake rest stream and invalidate handler
+ +(any | {source, sink})
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ close +
+ + + + src/circuit/circuit/stream-handler.js + + +Close the stream
+ +undefined
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ getB58String +
+ + + + src/circuit/circuit/utils.js + + +Get b58 string from multiaddr or peerinfo
+ +((Multiaddr | PeerInfo))
+
+ any
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ isPeerConnected +
+ + + + src/circuit/circuit/utils.js + + +Checks if peer has an existing connection
+ + + + + + + + + + + + + +(String)
+
+ (Swarm)
+
+ Boolean
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ writeResponse +
+ + + + src/circuit/circuit/utils.js + + +Write a response
+ +(StreamHandler)
+
+ (CircuitRelay.Status)
+
+ (Function)
+
+ any
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ validateAddrs +
+ + + + src/circuit/circuit/utils.js + + +Validate incomming HOP/STOP message
+ +(CircuitRelay)
+
+ (StreamHandler)
+
+ (CircuitRelay.Type)
+
+ (Function)
+
+ any
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ listen +
+ + + + src/circuit/listener.js + + +Add swarm handler and listen for incoming connections
+ +(Multiaddr)
+
+ (Function)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ close +
+ + + + src/circuit/listener.js + + +Remove swarm listener
+ +(Function)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ getAddrs +
+ + + + src/circuit/listener.js + + +Get fixed up multiaddrs
+NOTE: This method will grab the peers multiaddrs and expand them such that:
+a) If it's an existing /p2p-circuit address for a specific relay i.e.
+/ip4/0.0.0.0/tcp/0/ipfs/QmRelay/p2p-circuit
this method will expand the
+address to /ip4/0.0.0.0/tcp/0/ipfs/QmRelay/p2p-circuit/ipfs/QmPeer
where
+QmPeer
is this peers id
+b) If it's not a /p2p-circuit address, it will encapsulate the address as a /p2p-circuit
+addr, such when dialing over a relay with this address, it will create the circuit using
+the encapsulated transport address. This is useful when for example, a peer should only
+be dialed over TCP rather than any other transport
(Function)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ handle +
+ + + + src/circuit/circuit/stop.js + + +Handle the incoming STOP message
+ + + + + + + + + + + + + +({})
+ the parsed protobuf message
+
+ (StreamHandler)
+ the stream handler wrapped connection
+
+ (Function)
+ callback
+
+ undefined
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ constructor +
+ + + + src/circuit/circuit/hop.js + + +Construct a Circuit object
+This class will handle incoming circuit connections and +either start a relay or hand the relayed connection to +the swarm
+ +(Swarm)
+
+ (Object)
+
+ + handle +
+ + + + src/circuit/circuit/hop.js + + +Handle the relay message
+ +(CircuitRelay)
+
+ (StreamHandler)
+
+ any
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ _connectToStop +
+ + + + src/circuit/circuit/hop.js + + +Connect to STOP
+ +(PeerInfo)
+
+ (StreamHandler)
+
+ (function)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ _negotiateStop +
+ + + + src/circuit/circuit/hop.js + + +Negotiate STOP
+ +(StreamHandler)
+
+ (StreamHandler)
+
+ (CircuitRelay)
+
+ (function)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ TransportManager +
+ + + + src/switch/transport.js + + +Manages the transports for the switch. This simplifies dialing and listening across +multiple transports.
+ +(any)
+
+ For a given transport, return its multiaddrs that match the given multiaddrs
+ + + + + + + + + + + + + +(Transport)
+
+ (Array<Multiaddr>)
+
+ (PeerInfo)
+ Optional - a peer whose addresses should not be returned
+
+ Array<Multiaddr>
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Adds a Transport
to the list of transports on the switch, and assigns it to the given key
(String)
+
+ (Transport)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Closes connections for the given transport key +and removes it from the switch.
+ + + + + + + + + + + + + +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Calls remove
on each transport the switch has
(function (Error))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+For a given transport key
, dial to all that transport multiaddrs
(PeerInfo)
+
+ (function (Error, Connection))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+For a given Transport key
, listen on all multiaddrs in the switch's _peerInfo
.
+If a handler
is not provided, the Switch's protocolMuxer
will be used.
(String)
+
+ (any)
+ Currently ignored
+
+ (function (Connection))
+
+ (function (Error))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Closes the transport with the given key, by closing all of its listeners
+ + + + + + + + + + + + + +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ ourAddresses +
+ + + + src/switch/transport.js + + +Expand addresses in peer info into array of addresses with and without peer +ID suffix.
+ + + + + + + + + + + + + +(PeerInfo)
+ Our peer info object
+
+ Array<String>
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ getDestination +
+ + + + src/switch/transport.js + + +Get the destination address of a (possibly relay) multiaddr as a string
+ +(Multiaddr)
+
+ String
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ LimitDialer +
+ + + + src/switch/limit-dialer/index.js + + +Track dials per peer and limited them.
+ + + + + + + + + + + + + +Dial a list of multiaddrs on the given transport.
+ +(PeerId)
+
+ (SwarmTransport)
+
+ (Array<Multiaddr>)
+
+ (function (Error, Connection))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Dial a single multiaddr on the given transport.
+ +(PeerId)
+
+ (SwarmTransport)
+
+ (Multiaddr)
+
+ (CancelToken)
+
+ (function (Error, Connection))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ DialQueue +
+ + + + src/switch/limit-dialer/queue.js + + +Queue up the amount of dials to a given peer.
+ + + + + + + + + + + + + +Add new work to the queue.
+ +(SwarmTransport)
+
+ (Multiaddr)
+
+ (CancelToken)
+
+ (function (Error, Connection))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ msHandle +
+ + + + src/switch/utils.js + + +For a given multistream, registers to handle the given connection
+ +(MultistreamDialer)
+
+ (Connection)
+
+ Promise
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ msSelect +
+ + + + src/switch/utils.js + + +For a given multistream, selects the given protocol
+ + + + + + + + + + + + + +(MultistreamDialer)
+
+ (string)
+
+ Promise
:
+ Resolves the selected Connection
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ identifyDialer +
+ + + + src/switch/utils.js + + +Runs identify for the given connection and verifies it against the +PeerInfo provided
+ +(Connection)
+
+ (PeerInfo)
+ The PeerInfo determined during crypto exchange
+
+ Promise
:
+ Resolves {peerInfo, observedAddrs}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ uniqueBy +
+ + + + src/switch/utils.js + + +Get unique values from arr
using getValue
to determine
+what is used for uniqueness
(Array)
+ The array to get unique values for
+
+ (function (value))
+ The function to determine what is compared
+
+ Array
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ ConnectionManager +
+ + + + src/switch/connection/manager.js + + +Contains methods for binding handlers to the Switch +in order to better manage its connections.
+ +(any)
+
+ Adds a listener for the given muxer
and creates a handler for it
+leveraging the Switch.protocolMuxer handler factory
(Muxer)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Adds the encrypt
handler for the given tag
and also sets the
+Switch's crypto to passed encrypt
function
(String)
+
+ (function (PeerID, Connection, PeerId, Callback))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+If config.enabled is true, a Circuit relay will be added to the +available Switch transports.
+ +(any)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Sets identify to true on the Switch and performs handshakes +for libp2p-identify leveraging the Switch's muxer.
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ ConnectionOptions +
+ + + + src/switch/connection/index.js + + ++ Type: + Object +
+ + + + + + + + + + + + + +(Switch)
+ : Our switch instance
+
+
+ (PeerInfo)
+ : The PeerInfo of the peer to dial
+
+
+ (Muxer)
+ : Optional - A muxed connection
+
+
+ (Connection)
+ : Optional - The base connection
+
+
+ (string)
+ : Optional - identify the connection as incoming or outgoing. Defaults to out.
+
+
+ + ConnectionFSM +
+ + + + src/switch/connection/index.js + + +ConnectionFSM handles the complex logic of managing a connection +between peers. ConnectionFSM is internally composed of a state machine +to help improve the usability and debuggability of connections. The +state machine also helps to improve the ability to handle dial backoff, +coalescing dials and dial locks.
+ ++ Extends + + BaseConnection + +
+ + + + + + + + + + +(ConnectionOptions)
+
+ Name | +Description | +
---|---|
connectionOptions._switch any
+ |
+ + |
connectionOptions.peerInfo any
+ |
+ + |
connectionOptions.muxer any
+ |
+ + |
connectionOptions.conn any
+ |
+ + |
connectionOptions.type any
+
+ (default 'out' )
+ |
+ + |
Puts the state into dialing mode
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Initiates a handshake for the given protocol
+ + + + + + + + + + + + + +(string)
+ The protocol to negotiate
+
+ (function (Error, Connection))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Puts the state into muxing mode
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Once a connection has been successfully dialed, the connection +will be privatized or encrypted depending on the presence of the +Switch.protector.
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Event handler for disconnecting. Handles any needed cleanup
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Analyses the given error, if it exists, to determine where the state machine +needs to go.
+ +(Error)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Event handler for state transition errors
+ +(Error)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ _dial +
+ + + + src/switch/dialer/index.js + + +(DialRequest)
+
+ Name | +Description | +
---|---|
dialRequest.peerInfo any
+ |
+ + |
dialRequest.protocol any
+ |
+ + |
dialRequest.options any
+ |
+ + |
dialRequest.callback any
+ |
+ + |
void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ start +
+ + + + src/switch/dialer/index.js + + +Starts the DialQueueManager
(function)
+
+ + stop +
+ + + + src/switch/dialer/index.js + + +Aborts all dials that are queued. This should +only be used when the Switch is being stopped
+ +(function)
+
+ + clearDenylist +
+ + + + src/switch/dialer/index.js + + +Clears the denylist for a given peer
+ +(PeerInfo)
+
+ + connect +
+ + + + src/switch/dialer/index.js + + +Attempts to establish a connection to the given peerInfo
at
+a lower priority than a standard dial.
(PeerInfo)
+
+ (object)
+
+ Name | +Description | +
---|---|
options.useFSM boolean
+ |
+ Whether or not to return a
+ConnectionFSM
+. Defaults to false.
+ |
+
options.priority number
+ |
+ Lowest priority goes first. Defaults to 20. + | +
(function (Error, Connection))
+
+ + dial +
+ + + + src/switch/dialer/index.js + + +Adds the dial request to the queue for the given peerInfo
+The request will be added with a high priority (10).
+ dialFSM +
+ + + + src/switch/dialer/index.js + + +Behaves like dial, except it calls back with a ConnectionFSM
+ + + + + + + + + + + + + +(PeerInfo)
+
+ (string)
+
+ (function (Error, ConnectionFSM))
+
+ + constructor +
+ + + + src/switch/dialer/queueManager.js + + +(Switch)
+
+ + start +
+ + + + src/switch/dialer/queueManager.js + + +Allows the DialQueueManager
to execute dials
+ stop +
+ + + + src/switch/dialer/queueManager.js + + +Iterates over all items in the DialerQueue +and executes there callback with an error.
+This causes the entire DialerQueue to be drained
+ ++ add +
+ + + + src/switch/dialer/queueManager.js + + +Adds the dialRequest
to the queue and ensures queue is running
(DialRequest)
+
+ Name | +Description | +
---|---|
dialRequest.peerInfo any
+ |
+ + |
dialRequest.protocol any
+ |
+ + |
dialRequest.options any
+ |
+ + |
dialRequest.callback any
+ |
+ + |
void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ run +
+ + + + src/switch/dialer/queueManager.js + + +Will execute up to MAX_PARALLEL_DIALS
dials
+ clearDenylist +
+ + + + src/switch/dialer/queueManager.js + + +Will remove the peerInfo
from the dial denylist
(PeerInfo)
+
+ + getQueue +
+ + + + src/switch/dialer/queueManager.js + + +Returns the Queue
for the given peerInfo
(PeerInfo)
+
+ Queue
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ DialRequest +
+ + + + src/switch/dialer/queue.js + + +Components required to execute a dial
+ ++ Type: + Object +
+ + + + + + + + + + + + + +(PeerInfo)
+ : The peer to dial to
+
+
+ (string?)
+ : The protocol to create a stream for
+
+
+ + NewConnection +
+ + + + src/switch/dialer/queue.js + + ++ Type: + Object +
+ + + + + + + + + + + + + +(ConnectionFSM)
+
+
+ (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.
(object)
+
+ Name | +Description | +
---|---|
options.protocol string
+ |
+ + |
options.connection ConnectionFSM
+ |
+ + |
options.callback function (Error, Connection)
+ |
+ + |
void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ Queue +
+ + + + src/switch/dialer/queue.js + + +A convenience array wrapper for controlling +a per peer queue
+ + + + + + + + + + + + + +(string)
+
+ (Switch)
+
+ (function (string))
+ Called when the queue stops
+
+ Queue
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Adds the dial request to the queue. The queue is not automatically started
+ + + + + + + + + + + + + +(string)
+
+ (boolean)
+ If callback should use a ConnectionFSM instead
+
+ (function (Error, Connection))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Determines whether or not dialing is currently allowed
+ +boolean
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Starts the queue. If the queue was started true
will be returned.
+If the queue was already running false
is returned.
boolean
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Stops the queue
+ +Stops the queue and errors the callback for each dial request
+ +Marks the queue as denylisted. The queue will be immediately aborted.
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ transportKey +
+ + + + src/switch/connection/handler.js + + +Takes a transport key and returns a connection handler function
+ +(string)
+ The key of the transport to handle connections for
+
+ (function)
+ A custom handler to use
+
+ function (Connection)
:
+ A connection handler function
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ conn +
+ + + + src/switch/connection/handler.js + + +Takes a base connection and manages listening behavior
+ +(Connection)
+ The connection to manage
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ close +
+ + + + src/switch/connection/base.js + + +Puts the state into its disconnecting flow
+ +(Error)
+ Will be emitted if provided
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ getState +
+ + + + src/switch/connection/base.js + + +Gets the current state of the connection
+ +string
:
+ The current state of the connection
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ encrypt +
+ + + + src/switch/connection/base.js + + +Puts the state into encrypting mode
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ protect +
+ + + + src/switch/connection/base.js + + +Puts the state into privatizing mode
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ upgrade +
+ + + + src/switch/connection/base.js + + +Puts the state into muxing mode
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ _onDisconnected +
+ + + + src/switch/connection/base.js + + +Event handler for disconnected.
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ _onPrivatized +
+ + + + src/switch/connection/base.js + + +Event handler for privatized
+ +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.
+ +(Transport)
+
+ (string)
+
+ (Connection)
+
+ (Observer)
+
+ Connection
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ plaintext +
+ + + + src/switch/plaintext.js + + +An encryption stub in the instance that the default crypto +has not been overriden for the Switch
+ ++ 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.
(Switch)
+
+ EventEmitter
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ +
+ + + + src/switch/stats/index.js + + +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.
(Observer)
+
+ (any)
+
+ Stats
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ Stats +
+ + + + src/switch/stats/stat.js + + +A queue based manager for stat processing
+ + + + ++ Extends + + EventEmitter + +
+ + + + + + + + + + +Initializes the internal timer if there are items in the queue. This
+should only need to be called if Stats.stop
was previously called, as
+Stats.push
will also start the processing.
void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Stops processing and computing of stats by clearing the internal +timer.
+ +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns a clone of the current stats.
+ +Map<string, Stat>
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns a clone of the internal movingAverages
+ +Array<MovingAverage>
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Pushes the given operation data to the queue, along with the +current Timestamp, then resets the update timer.
+ + + + + + + + + + + + + +void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ old-peers +
+ + + + src/switch/stats/old-peers.js + + +Creates and returns a Least Recently Used Cache
+ +(Number)
+
+ LRUCache
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ findPeer +
+ + + + src/peer-routing.js + + +Iterates over all peer routers in series to find the given peer.
+ +(String)
+ The id of the peer to find
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ findProviders +
+ + + + src/content-routing.js + + +Iterates over all content routers in series to find providers of the given key. Once a content router succeeds, iteration will stop.
-Parameters
Returns
void
-provide
Iterates over all content routers in parallel to notify it is + +
(CID)
+ The CID key of the content to find
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + provide +
+ + + + src/content-routing.js + + +Iterates over all content routers in parallel to notify it is a provider of the given key.
-Parameters
key: CID
:The CID key of the content to find -callback: function (Error)
:
Returns
void
-