All files / json-pack/src/nfs/v4/server/operations ClientRecord.ts

11.11% Statements 1/9
0% Branches 0/2
0% Functions 0/1
11.11% Lines 1/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68        26x                                                                                                                              
import type * as msg from '../../messages';
import type * as struct from '../../structs';
 
/** Client state record for NFS v4 client registration. */
export class ClientRecord {
  constructor(
    /**
     * Principal associated with this client (from RPC credentials).
     */
    public readonly principal: string,
 
    /**
     * Client verifier - used to detect client reboots.
     * If client sends SETCLIENTID with same clientIdString but different verifier,
     * it indicates the client rebooted and old state should be discarded.
     * Size 8 bytes (NFS4_VERIFIER_SIZE) buffer.
     */
    public readonly verifier: Uint8Array,
 
    /**
     * Client identifier string - globally unique client identity.
     * Typically contains hostname or other unique data.
     * Used to find existing client records across SETCLIENTID calls.
     */
    public readonly clientIdString: Uint8Array,
 
    /**
     * Callback information - RPC program number and network address.
     * Used by server to initiate callbacks to client (e.g., for delegation recalls).
     * Server opens new TCP connection to client using this address when needed.
     */
    public readonly callback: struct.Nfsv4CbClient,
 
    /**
     * Callback identifier - client-provided value.
     * Sent by server in callback RPCs to help client distinguish which
     * server is calling back (useful if client talks to multiple servers).
     */
    public readonly callbackIdent: number,
 
    /**
     * SETCLIENTID confirmation verifier - random 8-byte token.
     * Generated by server, returned to client, must be echoed back in
     * SETCLIENTID_CONFIRM to prove client received the SETCLIENTID response.
     * Prevents race conditions and stale client ID reuse.
     *
     *     const NFS4_VERIFIER_SIZE        = 8;
     *     typedef opaque  verifier4[NFS4_VERIFIER_SIZE];
     */
    public readonly setclientidConfirm: Uint8Array,
 
    /**
     * Cached SETCLIENTID response for duplicate request handling.
     * If a client repeats a SETCLIENTID request (same clientIdString and verifier),
     * server can return this cached response instead of creating a new record.
     * This helps handle network retries and duplicate requests gracefully.
     */
    public cache: msg.Nfsv4SetclientidResponse | undefined = undefined,
 
    /**
     * Last time this client renewed its lease (in milliseconds since epoch).
     * Per RFC 7530 ยง9.5, any stateful operation from the client renews the lease.
     * The server must track this to detect expired leases and revoke client state.
     */
    public lastRenew: number = Date.now(),
  ) {}
}