The Registrar provides an interface for registering protocol handlers - these are invoked when remote peers open streams on the local node with the corresponding protocol name.

It also allows configuring network topologies for a given protocol(s). The topology callbacks are invoked when a peer that supports those protocols connects or disconnects.

The Identify protocol must be configured on the current node for topologies to function.

interface Registrar {
    getHandler(protocol): StreamHandlerRecord;
    getProtocols(): string[];
    getTopologies(protocol): Topology[];
    handle(protocol, handler, options?): Promise<void>;
    register(protocol, topology): Promise<string>;
    unhandle(protocol): Promise<void>;
    unregister(id): void;
}

Methods

  • Register a topology handler for a protocol - the topology will be invoked when peers are discovered on the network that support the passed protocol.

    An id will be returned that can later be used to unregister the topology.

    Parameters

    • protocol: string

      The protocol to register.

    • topology: Topology

      The topology handler to register.

    Returns Promise<string>

    A promise resolving to a unique ID for the registered topology.