Class Libp2p

property

{boolean} persistence

property

{boolean} enabled

property

{import('./circuit').RelayAdvertiseOptions} advertise

property

{import('./circuit').HopOptions} hop

property

{import('./circuit').AutoRelayOptions} autoRelay

property

{Object} [dht] dht module options

property

{Object} [peerDiscovery]

property

{Pubsub} [pubsub] pubsub module options

property

{RelayOptions} [relay]

property

{Record<string, Object>} [transport] transport options indexed by transport key

property

{TransportFactory[]} transport

property

{MuxerFactory[]} streamMuxer

property

{Crypto[]} connEncryption

property

{Libp2pModules} modules libp2p modules to use

property

{import('./address-manager').AddressManagerOptions} [addresses]

property

{import('./connection-manager').ConnectionManagerOptions} [connectionManager]

property

{import('./dialer').DialerOptions} [dialer]

property

{import('./metrics').MetricsOptions} [metrics]

property

{Object} [keychain]

property

{import('./transport-manager').TransportManagerOptions} [transportManager]

property

{PeerStoreOptions & import('./peer-store/persistent').PersistentPeerStoreOptions} [peerStore]

property

{Libp2pConfig} [config]

property

{PeerId} peerId

property

{PeerId} [peerId]

fires

Libp2p#error Emitted when an error occurs

fires

Libp2p#peer:discovery Emitted when a peer is discovered

Hierarchy

Index

References

Connection

Re-exports Connection

CreateOptions

Re-exports CreateOptions

Crypto

Re-exports Crypto

Events

Re-exports Events

Libp2pConfig

Re-exports Libp2pConfig

Libp2pModules

Re-exports Libp2pModules

Libp2pOptions

Re-exports Libp2pOptions

Multiaddr

Re-exports Multiaddr

MuxedStream

Re-exports MuxedStream

MuxerFactory

Re-exports MuxerFactory

PeerStoreOptions

Re-exports PeerStoreOptions

Pubsub

Re-exports Pubsub

RelayOptions

Re-exports RelayOptions

TransportFactory

Re-exports TransportFactory

constructorOptions

Re-exports constructorOptions

Constructors

constructor

Properties

_config

_config: any

_dht

_dht: any

_discovery

_discovery: Map<any, any>

_isStarted

_isStarted: boolean | undefined

Private _maybeConnect

_maybeConnect: any

Will dial to the given peerId if the current number of connected peers is less than the configured ConnectionManager minConnections.

param

_modules

_modules: any

Private _onDidStart

_onDidStart: any

Called when libp2p has started and before it returns

Private _onDiscoveryPeer

_onDiscoveryPeer: any

Called whenever peer discovery services emit peer events. Known peers may be emitted.

param

_options

_options: any

Private _setupPeerDiscovery

_setupPeerDiscovery: any

Initializes and starts peer discovery services

async

_transport

_transport: any[]

addressManager

addressManager: AddressManager

addresses

addresses: any

connectionManager

connectionManager: ConnectionManager

contentRouting

contentRouting: ContentRouting

datastore

datastore: any

dialer

dialer: Dialer

identifyService

identifyService: IdentifyService | undefined

keychain

keychain: Keychain | undefined

metrics

metrics: Metrics | undefined

natManager

natManager: NatManager

peerId

peerId: PeerId

peerRouting

peerRouting: PeerRouting

peerStore

peerStore: PeerStore

pubsub

pubsub: PubsubBaseProtocol

registrar

registrar: Registrar

relay

relay: Relay | undefined

transportManager

transportManager: TransportManager

upgrader

upgrader: Upgrader

Accessors

connections

  • Gets a Map of the current connections. The keys are the stringified PeerId of the peer. The value is an array of Connections to that peer.

    Returns Map<string, Connection[]>

multiaddrs

  • Get a deduplicated list of peer advertising multiaddrs by concatenating the listen addresses used by transports with any configured announce addresses as well as observed addresses reported by peers.

    If Announce addrs are specified, configured listen addresses will be ignored though observed addresses will still be included.

    Returns Multiaddr[]

Methods

_onStarting

  • _onStarting(): Promise<void>
  • Returns Promise<void>

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): any
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns any

dial

  • Dials to the provided peer. If successful, the known metadata of the peer will be added to the nodes peerStore

    Parameters

    • peer: PeerId | Multiaddr | string

      The peer to dial

    • Optional options: { signal?: AbortSignal | undefined } | undefined

    Returns Promise<Connection>

dialProtocol

  • dialProtocol(peer: PeerId | Multiaddr | string, protocols: string[] | string, options?: { signal?: AbortSignal | undefined } | undefined): Promise<Connection | any>
  • Dials to the provided peer and handshakes with the given protocol. If successful, the known metadata of the peer will be added to the nodes peerStore, and the Connection will be returned

    async

    Parameters

    • peer: PeerId | Multiaddr | string

      The peer to dial

    • protocols: string[] | string
    • Optional options: { signal?: AbortSignal | undefined } | undefined

    Returns Promise<Connection | any>

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

getMaxListeners

  • getMaxListeners(): number

handle

  • handle(protocols: string[] | string, handler: (__namedParameters: { Connection: any; MuxedStream: any; string: any }) => void): void
  • Registers the handler for each protocol

    Parameters

    • protocols: string[] | string
    • handler: (__namedParameters: { Connection: any; MuxedStream: any; string: any }) => void
        • (__namedParameters: { Connection: any; MuxedStream: any; string: any }): void
        • Parameters

          • __namedParameters: { Connection: any; MuxedStream: any; string: any }
            • Connection: any
            • MuxedStream: any
            • string: any

          Returns void

    Returns void

hangUp

  • Disconnects all connections to the given peer

    Parameters

    Returns Promise<void>

isStarted

  • isStarted(): boolean | undefined
  • Returns boolean | undefined

listenerCount

  • listenerCount(event: string | symbol): number

listeners

  • listeners(event: string | symbol): Function[]

loadKeychain

  • loadKeychain(): Promise<void>
  • Load keychain keys from the datastore. Imports the private key as 'self', if needed.

    async

    Returns Promise<void>

off

  • off(event: string | symbol, listener: (...args: any[]) => void): any
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns any

on

  • on(event: string | symbol, listener: (...args: any[]) => void): any
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns any

once

  • once(event: string | symbol, listener: (...args: any[]) => void): any
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns any

ping

  • Pings the given peer in order to obtain the operation latency.

    Parameters

    Returns Promise<number>

rawListeners

  • rawListeners(event: string | symbol): Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): any

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): any
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns any

setMaxListeners

  • setMaxListeners(n: number): any

start

  • start(): Promise<void>
  • Starts the libp2p node and all its subsystems

    Returns Promise<void>

stop

  • stop(): Promise<void>
  • Stop the libp2p node by closing its listeners and open connections

    async

    Returns Promise<void>

unhandle

  • unhandle(protocols: string[] | string): void
  • Removes the handler for each protocol. The protocol will no longer be supported on streams.

    Parameters

    • protocols: string[] | string

    Returns void

Static create

  • Like new Libp2p(options) except it will create a PeerId instance if one is not provided in options.

    Parameters

    Returns Promise<Libp2p>