Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Libp2pBinding

Defines a peer-to-peer based communication binding for transmitting Coaty communication events via a libp2p pubsub messaging protocol. A detailed explanation can be found here.

With this binding, TCP connections between Coaty agent peers are secured by default, i.e. messages are encryped and signed using public key cryptography.

As this binding is based on peer-to-peer communication, the emitted communication state is Online as long as the binding is in Joined state and the libp2p peer node is not isolated, i.e. has at least one active libp2p connection to remote libp2p peers. However, note that an isolated offline peer can communicate with itself.

This binding supports Raw events with plain topic strings that contain no wildcard tokens. Topic strings must be non-empty and may include arbitrary Unicode characters.

This binding does not support the shouldEnableCrossNamespacing option. Coaty communication events published by agents in a different namespace cannot be observed.

This binding poses the following restrictions on its namespace option: namespace must not include consecutive dots or end with a dot, and namespace must not contain more than 236 characters.

remarks

In case you are running multiple isolated Coaty applications on the same local network, you should specify different namespaces for each of them. This ensures that peer connections are only set up between Coaty agents sharing the same namespace.

remarks

This binding supports two peer discovery methods: Multicast DNS (mDNS) to discover peers in a local network, and Bootstrap Peers to discover peers across networks. mDNS discovery cannot be used across multiple IP subnets. It should be used in networks having a small number of nodes as mDNS queries and responses are transmitted in multicast mode and consecutively generate large volume of traffic. Bootstrap peer discovery uses a list of preconfigured bootstrap nodes. Depending on the application use case, both methods can be combined or used exclusively.

remarks

To enable debug mode of the underlying libp2p libraries, set global variable DEBUG to a comma-separated list of libp2p packages to be debugged before loading this binding. To debug the base libp2p system, use libp2p, to debug a specific module use libp2p:<module>, to debug all modules use libp2p,libp2p:*. For example, to restrict debug mode to the used libp2p pubsub module, set global variable DEBUG to libp2p:floodsub. Valid module names include floodsub, mdns, mplex, dialer, connection-manager, transports, bootstrap, peer-store, etc.

remarks

This binding requires Node.js 12 or higher. Support for browsers is work in progress.

Hierarchy

Implements

  • CommunicationBindingProtocol

Index

Constructors

constructor

  • internal

    For internal use in framework only.

    Create an instance of this binding type with the given options.

    Parameters

    Returns Libp2pBinding

Properties

Static Protected Readonly DEFAULT_NAMESPACE

DEFAULT_NAMESPACE: "-" = "-"

Accessors

apiName

  • get apiName(): string

apiVersion

  • get apiVersion(): number

options

  • Gets the binding options (read-only).

    remarks

    For the optional base binding options defined in CommunicationBindingOptions, (default) values are always set by the base binding class. Thus, a concrete binding class need not check whether a value is defined for these properties.

    Returns Readonly<Libp2pBindingOptions>

state

  • get state(): CommunicationBindingState
  • Returns CommunicationBindingState

Methods

addListener

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

createIoRoute

  • createIoRoute(ioSourceId: string): string
  • Parameters

    • ioSourceId: string

    Returns string

emit

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

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

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number

join

  • join(joinOptions: CommunicationBindingJoinOptions): void
  • Parameters

    • joinOptions: CommunicationBindingJoinOptions

    Returns void

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

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

    • event: string | symbol

    Returns Function[]

Protected log

  • log(logLevel: CommunicationBindingLogLevel, arg1: string, arg2?: any, arg3?: any, arg4?: any): void
  • Parameters

    • logLevel: CommunicationBindingLogLevel
    • arg1: string
    • Optional arg2: any
    • Optional arg3: any
    • Optional arg4: any

    Returns void

off

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

on

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

Protected onInit

  • onInit(): void

Protected onJoin

  • onJoin(joinOptions: CommunicationBindingJoinOptions): void
  • Parameters

    • joinOptions: CommunicationBindingJoinOptions

    Returns void

Protected onPublish

  • onPublish(eventLike: CommunicationEventLike): void
  • Parameters

    • eventLike: CommunicationEventLike

    Returns void

Protected onSubscribe

  • onSubscribe(eventLike: CommunicationEventLike): void
  • Parameters

    • eventLike: CommunicationEventLike

    Returns void

Protected onUnjoin

  • onUnjoin(): Promise<void>

Protected onUnsubscribe

  • onUnsubscribe(eventLike: CommunicationEventLike): void
  • Parameters

    • eventLike: CommunicationEventLike

    Returns void

once

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

publish

  • publish(eventLike: CommunicationEventLike): void
  • Parameters

    • eventLike: CommunicationEventLike

    Returns void

rawListeners

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

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this

subscribe

  • subscribe(eventLike: CommunicationEventLike): void
  • Parameters

    • eventLike: CommunicationEventLike

    Returns void

unjoin

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

unsubscribe

  • unsubscribe(eventLike: CommunicationEventLike): void
  • Parameters

    • eventLike: CommunicationEventLike

    Returns void

Static withOptions

  • Provides the libp2p binding with application-specific options as value of the CommunicationOptions.binding property in the agent container configuration.

    To be used as follows:

    import { Libp2pBinding } from "@coaty/binding.libp2p";
    
    const configuration: Configuration = {
      ...
      communication: {
          binding: Libp2pBinding.withOptions({
              ...
          }),
          ...
      },
      ...
    };

    Parameters

    Returns CommunicationBindingWithOptions<Libp2pBinding, Libp2pBindingOptions>

Generated using TypeDoc