reticulum-js
    Preparing search index...

    Class TCPServerInterface

    Reticulum interface that listens for inbound TCP connections.

    Each accepted connection is exposed as a spawned TCPClientInterface via the connection event.

    Hierarchy

    • Interface
      • TCPServerInterface
    Index
    _closed: boolean = false

    Whether a terminal closed event has already been dispatched for the current connection episode (dedupe guard).

    _packetWriter: WritableStreamDefaultWriter<any> | null = null
    _reconnectAbort: AbortController | null = null

    AbortController for the current reconnect wait, so disconnect() can cancel an in-flight backoff immediately.

    _reconnectAttempts: number = 0

    Reconnect attempt counter for the current drop episode. Reset to 0 at the start of each Interface._runReconnectLoop run.

    _reconnecting: boolean = false

    Single-flight guard: only one reconnect loop runs at a time.

    autoReconnect: boolean = RECONNECT_DEFAULTS.autoReconnect

    Whether automatic reconnection is enabled for this initiator interface.

    bitrate: number = 62500

    Nominal physical bitrate of this interface in bits per second (self.bitrate on RNS.Interfaces.Interface in the Python reference, default 62500). Each interface overrides this with its medium's rate.

    Used by TransportCore.prioritizeInterfaces() to order the interface set highest-bitrate-first (mirrors the Python reference's Transport.prioritize_interfaces); the per-bitrate link-timeout and announce-rate-limit behaviours that also build on it are tracked as Phase 2 of work doc #20. Configured bitrates below Reticulum.MINIMUM_BITRATE are ignored (matching Python).

    connectTimeout: number = RECONNECT_DEFAULTS.connectTimeout

    Per-dial connect timeout in seconds.

    detached: boolean = false

    Permanent stop signal read by the reconnect loop. Set by disconnect().

    framing: "kiss" | "hdlc"
    ifacSize: number
    initiator: boolean = false

    Whether this interface is the initiator (the outbound dialer). Only initiators reconnect; adopted/server-spawned sockets never do (matching the Python reference initiator flag).

    maxReconnectTries: number = RECONNECT_DEFAULTS.maxReconnectTries

    Maximum reconnection attempts per drop. Infinity retries forever.

    name: string
    online: boolean
    port: number
    reconnectWait: number = RECONNECT_DEFAULTS.reconnectWait

    Seconds to wait between reconnection attempts.

    server: any
    socket: Socket | null = null

    The underlying socket, when this interface is backed by a Node.js stream.

    spawnedInterfaces: Set<TCPClientInterface>
    • Protected

      Signals the reconnect loop to stop and cancels any in-flight backoff. Client subclasses call this at the top of their disconnect().

      Returns void

    • Protected

      Dispatches a terminal closed event exactly once per connection episode.

      Returns void

    • Protected

      Dials the peer and sets up the RNS streams, resolving once connected and dispatching connected. Implemented by reconnect-capable client subclasses; used both for the initial connection and each reconnect attempt by the shared Interface._runReconnectLoop.

      Returns Promise<void>

    • Protected

      Called when the underlying connection drops (the inbound stream ends or errors). For an initiator with auto-reconnect enabled and not deliberately detached, dispatches disconnected and kicks off the reconnect loop; otherwise dispatches a terminal closed event.

      Matches the Python reference read_loop, which reconnects the initiator on any termination and tears down (non-reconnecting) everyone else.

      Returns void

    • Protected

      Initializes shared reconnect state from constructor options. Called by client interface subclasses (TCP, WebSocket) that support reconnection.

      Subclasses must also set Interface.initiator: true for an outbound dialer, false for an adopted/server-spawned socket.

      Parameters

      • options: ReconnectOptions

      Returns void

    • Protected

      Runs the single-flight reconnect loop. Repeatedly waits reconnectWait seconds then attempts to re-establish the connection via the subclass _establishConnection() hook, until it succeeds, the interface is detached, or maxReconnectTries is exceeded (terminal closed).

      Each attempt fires a reconnecting event with the upcoming attempt number, the wait, and the cap, for observability. A successful reconnect fires connected (via _establishConnection).

      Returns Promise<void>

    • Protected

      Resolves after ms, or immediately if signal aborts. Used so disconnect() can cancel an in-flight reconnect backoff at once.

      Parameters

      • ms: number
      • signal: AbortSignal

      Returns Promise<void>

    • 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

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • Optional hook invoked by import("../transport/transport.js").TransportCore#addInterface with the transport that owns this interface, right after the interface is attached.

      The base implementation is a no-op. Interfaces that spawn sub-interfaces dynamically — notably AutoInterface, which discovers peers and spawns one per peer — override it to remember the transport so the spawned peers can be auto-registered without a separate Reticulum global (the Python reference uses the global RNS.Transport.add_interface for this).

      Overriders should also register any peers spawned before the transport was attached, so the addInterface/connect call order doesn't matter.

      Parameters

      • _transport: TransportCore

      Returns void

    • Closes the listening server and disconnects all spawned client interfaces.

      Returns Promise<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

      • event: Event

      Returns boolean

    • 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
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | EventListenerOptions

      Returns void