IF Commons GitHub

logical/rpc

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0006-anyfs-serve-nfs FR-002

ONC RPC version 2 (RFC 5531) over TCP, as far as a server of NFS needs it: the record marking that frames messages on a stream (a record is one or more fragments, the last marked), a call read from a record with its credential (AUTH_NONE or AUTH_SYS with the uid and gid), and the replies a server gives: accepted with a result, accepted with the failure it names (PROG_UNAVAIL, PROG_MISMATCH, PROC_UNAVAIL, GARBAGE_ARGS, SYSTEM_ERR) and denied (RPC_MISMATCH, an authentication error). Pure: bytes in, bytes out.

import { frame, RecordReader } from "./rpc.ts";
const reader = new RecordReader(1024);
const records = reader.push(frame(new Uint8Array([1, 2, 3, 4])));
records.kind === "ok" && records.value.length; // 1

Source: commons/anyfs-serve/src/logical/rpc.ts

5 of 14 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

AUTHconstno test imports it
const AUTH: { readonly NONE: 0; readonly SYS: 1; }

The authentication flavors the server reads.

Credtypeno test imports it
type Cred = { readonly flavor: number; readonly uid?: number; readonly gid?: number; readonly machine?: string };

Who a call says it is: nothing, or a uid and a gid of the caller's computer.

RpcCalltypeno test imports it
type RpcCall = {
  readonly xid: number;
  readonly prog: number;
  readonly vers: number;
  readonly proc: number;
  readonly cred: Cred;
  /** The bytes of the arguments of the procedure. */
  readonly args: Uint8Array;
};

A call, read from a record.

Parsedtypeno test imports it
type Parsed = { readonly kind: "call"; readonly call: RpcCall } | { readonly kind: "reply"; readonly reply: Uint8Array } | { readonly kind: "drop" };

What a record was: a call, or what to answer (or nothing) where it was not one the server can serve.

ACCEPTconstno test imports it
const ACCEPT: { readonly SUCCESS: 0; readonly PROG_UNAVAIL: 1; readonly PROG_MISMATCH: 2; readonly PROC_UNAVAIL: 3; readonly GARBAGE_ARGS: 4; readonly SYSTEM_ERR: 5; }

The accept statuses of a reply.

AUTH_STATconstno test imports it
const AUTH_STAT: { readonly BADCRED: 1; readonly REJECTEDCRED: 2; readonly BADVERF: 3; readonly REJECTEDVERF: 4; readonly TOOWEAK: 5; }

The reasons of an authentication error.

acceptedfunction
function accepted(xid: number, result?: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

An accepted reply with a result: result is the XDR of what the procedure returns.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

failedfunctionno test imports it
function failed(xid: number, stat: 1 | 3 | 4 | 5): Uint8Array<ArrayBufferLike>

An accepted reply that says why there is no result.

progMismatchfunction
function progMismatch(xid: number, low: number, high: number): Uint8Array<ArrayBufferLike>

The reply to a call for a version the server does not have: the versions it has.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

rpcMismatchfunctionno test imports it
function rpcMismatch(xid: number): Uint8Array<ArrayBufferLike>

The denial of a call of another version of RPC than 2.

authErrorfunctionno test imports it
function authError(xid: number, stat: 1 | 2 | 3 | 4 | 5): Uint8Array<ArrayBufferLike>

The denial of a call whose authentication is refused.

parseCallfunction
function parseCall(record: Uint8Array<ArrayBufferLike>): Parsed

Reads a record as a call, or says what to do with it.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

framefunction
function frame(record: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

A record of one fragment, for sending.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

RecordReaderclass
class RecordReader

Joins what arrives on a stream into records: fragments are joined, a record longer than the limit is refused.

MemberTypeWhat it is
push(chunk: Uint8Array<ArrayBufferLike>) => Result<readonly Uint8Array<ArrayBufferLike>[], string>Takes bytes; gives the records they complete, or the reason the stream is not one a server can read.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.