Documentation
    Preparing search index...

    Interface ITransport

    Interface that defines the methods a peerkit transport needs to implement

    interface ITransport {
        connect(nodeAddress: string): Promise<void>;
        createStream(nodeId: string, protocol: string): Promise<IStream>;
        disconnect(nodeId: string): Promise<void>;
        getConnectedPeers(): string[];
        getListenAddresses(): string[];
        getNodeId(): string;
        isConnected(nodeId: string): boolean;
        isDirectConnection(nodeId: string): boolean;
        registerStreamHandler(
            protocol: string,
            handler: CustomStreamCreatedCallback,
        ): void;
        send(nodeId: string, message: Uint8Array): Promise<void>;
        sendAgents(nodeId: string, agents: Uint8Array): Promise<void>;
        shutDown(): Promise<void>;
    }

    Implemented by

    Index

    Methods

    • Establish a connection to a known peer by its full address.

      If the connection is routed through a relay, the address must include the relay address.

      Parameters

      • nodeAddress: string

        The dialable address of the node to connect to

      Returns Promise<void>

    • Create a new bi-directional byte stream on an open connection.

      Allows for reusing an open connection for exchaning any kind of data, e.g. audio or video data.

      Parameters

      • nodeId: string

        The node ID of the connection to create a stream for

      • protocol: string

        The name and version of the stream protocol

      Returns Promise<IStream>

    • Disconnect from the peer.

      Parameters

      • nodeId: string

        The node ID to disconnect from

      Returns Promise<void>

    • Return the node IDs of all currently connected peers.

      Returns string[]

    • Return the transport's actual dial addresses after startup.

      Each string is a fully-qualified address that peers can use to connect, including the node's identity suffix where the transport requires it.

      Use this to obtain the relay's dial address rather than constructing it from config.

      Returns string[]

    • Get the transport-level identifier of this node.

      Returns string

    • Is there an active connection to the provided node?

      Parameters

      • nodeId: string

        The node ID to check

      Returns boolean

    • Is the connection to the provided node a direct connection?

      false means the connection is relayed.

      Parameters

      • nodeId: string

        The node ID of the connection to check

      Returns boolean

    • Register a handler for incoming streams on the given protocol.

      The handler is called once per incoming stream, after the access check has passed. Can be called after transport construction.

      Parameters

      • protocol: string

        The protocol identifier to handle

      • handler: CustomStreamCreatedCallback

        Called with the initiating peer's NodeId and the stream

      Returns void

    • Send an opaque application message to a peer. The peer must be connected and have been granted access.

      Parameters

      • nodeId: string

        The ID of the target node

      • message: Uint8Array

        The message to send to the node

      Returns Promise<void>

    • Send opaque agent-info bytes to a peer. The peer must be connected and have been granted access.

      Parameters

      • nodeId: string

        The ID of the target node

      • agents: Uint8Array

        The list of agents to send to the node

      Returns Promise<void>

    • Shut down the transport and all underlying connections.

      Returns Promise<void>