reticulum-js
    Preparing search index...

    Class Resource

    A Reticulum Resource — a fragmented transfer riding on top of an ACTIVE Link.

    Construct with data for the sender side (then await resource.advertise()); or via Resource.accept on the receiver side. Both sides emit progress / complete / failed events, and expose whenComplete() for promise-based consumers.

    Hierarchy

    • EventTarget
      • Resource
    Index
    • Parameters

      • options: {
            autoCompress?: boolean;
            bz2?: Bzip2;
            data?: Uint8Array<ArrayBufferLike>;
            isRequest?: boolean;
            isResponse?: boolean;
            link?: Link;
            originalHash?: Uint8Array<ArrayBufferLike>;
            requestId?: Uint8Array<ArrayBufferLike>;
        } = {}
        • OptionalautoCompress?: boolean
        • Optionalbz2?: Bzip2

          Injected bz2 module; never imported by the library.

        • Optionaldata?: Uint8Array<ArrayBufferLike>

          Sender-side payload.

        • OptionalisRequest?: boolean

          This Resource is a REQUEST body.

        • OptionalisResponse?: boolean

          This Resource is a RESPONSE body.

        • Optionallink?: Link
        • OptionaloriginalHash?: Uint8Array<ArrayBufferLike>
        • OptionalrequestId?: Uint8Array<ArrayBufferLike>

          Associated REQUEST id (§11).

      Returns Resource

    _prepared: boolean

    Whether sender preparation is done.

    autoCompress: boolean
    bz2: Bzip2 | undefined
    compressed: boolean
    data: Uint8Array<ArrayBufferLike> | undefined
    encrypted: boolean
    expectedProof: Uint8Array<ArrayBufferLike> | undefined
    hash: Uint8Array<ArrayBufferLike> | undefined
    hashmap: Uint8Array<ArrayBufferLike>[]
    hasMetadata: boolean
    isRequest: boolean
    isResponse: boolean
    link: Link
    originalHash: Uint8Array<ArrayBufferLike> | undefined
    outstanding: number

    Outstanding part requests in the current window (receiver).

    parts: (Uint8Array<ArrayBufferLike> | null)[]
    randomHash: Uint8Array<ArrayBufferLike> | undefined
    receivedCount: number
    requestId: Uint8Array<ArrayBufferLike> | undefined
    segmentIndex: number
    size: number
    split: boolean
    status: number
    totalParts: number
    totalSegments: number
    totalSize: number
    uncompressedSize: number
    window: number = Resource.WINDOW

    Receiver request window during a transfer.

    DEFAULT_MAX_SIZE: number = ...

    Cap on advertised transfer/logical size at accept time (§10.4 bomb defense).

    HASHMAP_FIXED_OVERHEAD: number = 134

    Constants in the advertisement-size formula HASHMAP_MAX_LEN = (MDU-134)/4.

    HEADER_MAXSIZE: number = 35

    RNS.Packet.HEADER_MAXSIZE — worst-case header after relay HEADER_1→HEADER_2 conversion: flags(1) + hops(1) + transport_id(16) + dest_hash(16) + context(1).

    IFAC_MIN_SIZE: number = 1

    RNS.Reticulum.IFAC_MIN_SIZE — reserved IFAC bytes when computing SDU.

    RANDOM_HASH_SIZE: number = 4

    Size of the throwaway random prefix prepended to the wire body (§10.2 step 3). Distinct from the advertisement r field.

    WINDOW: number = 4

    Initial receiver request window (§10.10).

    WINDOW_MAX_SLOW: number = 10

    Default window cap used for the collision-guard span (§10.10 WINDOW_MAX_SLOW).

    • get collisionGuardSize(): number

      Collision-guard span (§10.2 step 7): map_hashes must be unique within this many parts of any position.

      Returns number

    • get hashmapMaxLen(): number

      Number of 4-byte map_hashes that fit in one advertisement's m field (§10.4): floor((link.mdu - 134) / 4). At the default MDU 431 this is 74.

      Returns number

    • get sdu(): number

      Maximum part body size. Parts are raw slices of the already-encrypted whole, sent as context=RESOURCE packets which are NOT token-encrypted (§10.6 gotcha), so the full SDU is available for part data.

      Returns number

    • 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

    • Builds and sends the RESOURCE_ADV (§10.4). The link registers this resource as an outgoing transfer keyed by hash.

      Returns Promise<void>

    • Receiver: assembles all parts, link-decrypts, strips the prefix, optional decompress, recomputes the integrity hash, and emits the RESOURCE_PRF (§10.8).

      Returns Promise<void>

    • Cancels the resource. Sender emits RESOURCE_ICL; receiver cancels locally (an ordinary receiver cancel does NOT emit RESOURCE_RCL per §10.9).

      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

    • Current transfer progress as a float in [0.0, 1.0].

      Returns number

    • Receiver: peer (initiator) cancelled via RESOURCE_ICL.

      Returns Promise<void>

    • Sender: peer (receiver) rejected via RESOURCE_RCL.

      Returns Promise<void>

    • Sender: fulfils an inbound RESOURCE_REQ (§10.5/§10.7) — emits the requested RESOURCE part packets, and a RESOURCE_HMU continuation when the receiver signalled hashmap exhaustion.

      Parameters

      • body: Uint8Array<ArrayBufferLike>

      Returns Promise<void>

    • Receiver: applies a RESOURCE_HMU hashmap continuation (§10.7).

      Parameters

      • body: Uint8Array<ArrayBufferLike>

      Returns Promise<void>

    • Receiver: places an incoming RESOURCE part by matching its 4-byte map_hash against the hashmap (§10.6). Returns true if the part was placed.

      Parameters

      • chunk: Uint8Array<ArrayBufferLike>

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

    • Receiver: builds and sends the next RESOURCE_REQ for missing parts (§10.5). Windowed stop-and-wait for Phase 2 — requests up to window outstanding missing parts, then waits for them before requesting more.

      Returns Promise<void>

    • Sender: validates a RESOURCE_PRF (§10.8). Body is resource_hash(32) || full_proof(32); full_proof must equal the pre-computed expected_proof.

      Parameters

      • body: Uint8Array<ArrayBufferLike>

      Returns Promise<void>

    • Resolves when the transfer reaches a terminal state (COMPLETE/FAILED/etc). Rejects if the resource fails rather than completing.

      Returns Promise<Resource>

    • Accepts an inbound RESOURCE_ADV and prepares to receive parts (§10.4/§10.5).

      Parameters

      • link: Link
      • advertisementPacket: Packet
      • Optionaloptions: { bz2?: Bzip2; maxSize?: number } = {}
        • Optionalbz2?: Bzip2
        • OptionalmaxSize?: number

          Reject advertisements whose t or d exceeds this (§10.4 bomb defense). Defaults to 32 MiB.

      Returns Promise<Resource | null>

      null if the advertisement was rejected.