IF Commons GitHub

logical/tftp

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-netboot-logical FR-004

The packets of TFTP (RFC 1350) with the options of RFC 2347 to 2349 (blksize, tsize, timeout), as bytes: a read request is parsed, and the data, acknowledgement, option acknowledgement and error packets are made. Block numbers are 16 bits and roll over past 65535 (Ubuntu's initrd is about 100 MB). Pure.

import { dataPacket, parseRequest } from "./tftp.ts";
dataPacket(1, new Uint8Array([1, 2]))[1]; // 3

Source: commons/netboot/src/logical/tftp.ts

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

logical.OPconstno test imports it
const OP: { readonly RRQ: 1; readonly WRQ: 2; readonly DATA: 3; readonly ACK: 4; readonly ERROR: 5; readonly OACK: 6; }

The opcodes.

logical.ERRconstno test imports it
const ERR: { readonly NOT_FOUND: 1; readonly ACCESS: 2; readonly ILLEGAL: 4; readonly OPTION: 8; }

The error codes this server gives.

logical.ReadRequesttypeno test imports it
type ReadRequest = { readonly file: string; readonly mode: string; readonly options: Readonly<Record<string, string>> };

A read request, or why the packet is not one.

logical.parseRequestfunctionno test imports it
function parseRequest(p: Uint8Array<ArrayBufferLike>): { readonly op: number; readonly request?: ReadRequest | undefined; }

Parses a request packet: the opcode and the NUL-separated strings.

logical.dataPacketfunctionno test imports it
function dataPacket(block: number, data: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

A data packet: the block number (taken modulo 65536) and its bytes.

logical.ackPacketfunctionno test imports it
function ackPacket(block: number): Uint8Array<ArrayBufferLike>

An acknowledgement packet.

logical.errorPacketfunctionno test imports it
function errorPacket(code: number, message: string): Uint8Array<ArrayBufferLike>

An error packet.

logical.oackPacketfunctionno test imports it
function oackPacket(options: Readonly<Record<string, string>>): Uint8Array<ArrayBufferLike>

An option acknowledgement.

logical.agreedOptionsfunctionno test imports it
function agreedOptions(asked: Readonly<Record<string, string>>, size: number, maxBlock?: number): { readonly blksize: number; readonly timeoutMs: number; readonly oack: Readonly<Record<string, string>>; }

The options this server agrees to, from those asked for: a block size from 8 to 65464 (and at most maxBlock), the size of the file where it is asked, and a timeout from 1 to 255 seconds.

logical.servedPathfunctionno test imports it
function servedPath(file: string): string | undefined

The path a request names, as a path of the served tree: leading slashes dropped, and refused (undefined) where it climbs out of it or holds a NUL.

physical.ackPacketfunctionno test imports it
function ackPacket(block: number): Uint8Array<ArrayBufferLike>

An acknowledgement packet.

OPconstno test imports it
const OP: { readonly RRQ: 1; readonly WRQ: 2; readonly DATA: 3; readonly ACK: 4; readonly ERROR: 5; readonly OACK: 6; }

The opcodes.

ERRconstno test imports it
const ERR: { readonly NOT_FOUND: 1; readonly ACCESS: 2; readonly ILLEGAL: 4; readonly OPTION: 8; }

The error codes this server gives.

ReadRequesttypeno test imports it
type ReadRequest = { readonly file: string; readonly mode: string; readonly options: Readonly<Record<string, string>> };

A read request, or why the packet is not one.

parseRequestfunction
function parseRequest(p: Uint8Array<ArrayBufferLike>): { readonly op: number; readonly request?: ReadRequest | undefined; }

Parses a request packet: the opcode and the NUL-separated strings.

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

dataPacketfunctionno test imports it
function dataPacket(block: number, data: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>

A data packet: the block number (taken modulo 65536) and its bytes.

ackPacketfunctionno test imports it
function ackPacket(block: number): Uint8Array<ArrayBufferLike>

An acknowledgement packet.

errorPacketfunctionno test imports it
function errorPacket(code: number, message: string): Uint8Array<ArrayBufferLike>

An error packet.

oackPacketfunctionno test imports it
function oackPacket(options: Readonly<Record<string, string>>): Uint8Array<ArrayBufferLike>

An option acknowledgement.

agreedOptionsfunction
function agreedOptions(asked: Readonly<Record<string, string>>, size: number, maxBlock?: number): { readonly blksize: number; readonly timeoutMs: number; readonly oack: Readonly<Record<string, string>>; }

The options this server agrees to, from those asked for: a block size from 8 to 65464 (and at most maxBlock), the size of the file where it is asked, and a timeout from 1 to 255 seconds.

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

servedPathfunction
function servedPath(file: string): string | undefined

The path a request names, as a path of the served tree: leading slashes dropped, and refused (undefined) where it climbs out of it or holds a NUL.

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

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