logical.OPconstno test imports itconst OP: { readonly RRQ: 1; readonly WRQ: 2; readonly DATA: 3; readonly ACK: 4; readonly ERROR: 5; readonly OACK: 6; }The opcodes.
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]; // 3logical.OPconstno test imports itconst 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 itconst ERR: { readonly NOT_FOUND: 1; readonly ACCESS: 2; readonly ILLEGAL: 4; readonly OPTION: 8; }The error codes this server gives.
logical.ReadRequesttypeno test imports ittype 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 itfunction 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 itfunction dataPacket(block: number, data: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>A data packet: the block number (taken modulo 65536) and its bytes.
logical.ackPacketfunctionno test imports itfunction ackPacket(block: number): Uint8Array<ArrayBufferLike>An acknowledgement packet.
logical.errorPacketfunctionno test imports itfunction errorPacket(code: number, message: string): Uint8Array<ArrayBufferLike>An error packet.
logical.oackPacketfunctionno test imports itfunction oackPacket(options: Readonly<Record<string, string>>): Uint8Array<ArrayBufferLike>An option acknowledgement.
logical.agreedOptionsfunctionno test imports itfunction 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 itfunction servedPath(file: string): string | undefinedThe 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 itfunction ackPacket(block: number): Uint8Array<ArrayBufferLike>An acknowledgement packet.
OPconstno test imports itconst OP: { readonly RRQ: 1; readonly WRQ: 2; readonly DATA: 3; readonly ACK: 4; readonly ERROR: 5; readonly OACK: 6; }The opcodes.
ERRconstno test imports itconst ERR: { readonly NOT_FOUND: 1; readonly ACCESS: 2; readonly ILLEGAL: 4; readonly OPTION: 8; }The error codes this server gives.
ReadRequesttypeno test imports ittype ReadRequest = { readonly file: string; readonly mode: string; readonly options: Readonly<Record<string, string>> };A read request, or why the packet is not one.
parseRequestfunctionfunction parseRequest(p: Uint8Array<ArrayBufferLike>): { readonly op: number; readonly request?: ReadRequest | undefined; }Parses a request packet: the opcode and the NUL-separated strings.
dataPacketfunctionno test imports itfunction dataPacket(block: number, data: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>A data packet: the block number (taken modulo 65536) and its bytes.
ackPacketfunctionno test imports itfunction ackPacket(block: number): Uint8Array<ArrayBufferLike>An acknowledgement packet.
errorPacketfunctionno test imports itfunction errorPacket(code: number, message: string): Uint8Array<ArrayBufferLike>An error packet.
oackPacketfunctionno test imports itfunction oackPacket(options: Readonly<Record<string, string>>): Uint8Array<ArrayBufferLike>An option acknowledgement.
agreedOptionsfunctionfunction 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.
servedPathfunctionfunction servedPath(file: string): string | undefinedThe 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.