libp2p
    Preparing search index...

    Interface Connection

    A Connection is a high-level representation of a connection to a remote peer that may have been secured by encryption and multiplexed, depending on the configuration of the nodes between which the connection is made.

    interface Connection {
        direct: boolean;
        direction: MessageStreamDirection;
        encryption?: string;
        id: string;
        limits?: ConnectionLimits;
        log: Logger;
        multiplexer?: string;
        remoteAddr: Multiaddr;
        remotePeer: PeerId;
        rtt?: number;
        status: MessageStreamStatus;
        streams: Stream[];
        timeline: MultiaddrConnectionTimeline;
        abort(err: Error): void;
        addEventListener<K extends "close" | "remoteCloseWrite" | "idle">(
            type: K,
            listener:
                | EventHandler<Omit<MessageStreamEvents, "drain" | "message">[K]>
                | null,
            options?: boolean | AddEventListenerOptions,
        ): void;
        close(options?: AbortOptions): Promise<void>;
        dispatchEvent(event: Event): boolean;
        dispatchEvent(event: Event): boolean;
        listenerCount(type: string): number;
        newStream(
            protocols: string | string[],
            options?: NewStreamOptions,
        ): Promise<Stream>;
        removeEventListener<K extends "close" | "remoteCloseWrite" | "idle">(
            type: K,
            listener?:
                | EventHandler<Omit<MessageStreamEvents, "drain" | "message">[K]>
                | null,
            options?: boolean | EventListenerOptions,
        ): void;
        removeEventListener(
            type: string,
            listener?: EventHandler<Event>,
            options?: boolean | EventListenerOptions,
        ): void;
        safeDispatchEvent<Detail>(
            type: "close" | "remoteCloseWrite" | "idle",
            detail?: CustomEventInit<Detail>,
        ): boolean;
    }

    Hierarchy (View Summary)

    Index

    Properties

    direct: boolean

    Whether this connection is direct or, for example, is via a relay

    Outbound connections are opened by the local node, inbound streams are opened by the remote

    encryption?: string

    The encryption protocol negotiated for this connection

    id: string

    The unique identifier for this connection

    If present, this connection has limits applied to it, perhaps by an intermediate relay. Once the limits have been reached the connection will be closed by the relay.

    log: Logger

    The connection logger, used to log connection-specific information

    multiplexer?: string

    The multiplexer negotiated for this connection

    remoteAddr: Multiaddr

    The address of the remote end of the connection

    remotePeer: PeerId

    The id of the peer at the remote end of the connection

    rtt?: number

    The time in milliseconds it takes to make a round trip to the remote peer.

    This is updated periodically by the connection monitor.

    The current status of the connection

    streams: Stream[]

    A list of open streams on this connection

    When stream life cycle events occurred

    Methods

    • The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

      MDN Reference

      Type Parameters

      • K extends "close" | "remoteCloseWrite" | "idle"

      Parameters

      Returns void

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      Returns boolean

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      Returns boolean

    • Parameters

      • type: string

      Returns number

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Type Parameters

      • K extends "close" | "remoteCloseWrite" | "idle"

      Parameters

      Returns void

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Parameters

      • type: string
      • Optionallistener: EventHandler<Event>
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Type Parameters

      • Detail

      Parameters

      • type: "close" | "remoteCloseWrite" | "idle"
      • Optionaldetail: CustomEventInit<Detail>

      Returns boolean