Skip to content

@fkn/lib/wire

type TcpSocketOption =
| {
type: typeof TCP_OPTION_NODELAY;
value: boolean;
}
| {
type: typeof TCP_OPTION_TTL;
value: number;
}
| {
enabled: boolean;
initialDelaySeconds: number;
type: typeof TCP_OPTION_KEEPALIVE;
}
| {
type: typeof TCP_OPTION_SEND_BUFFER_SIZE;
value: number;
}
| {
type: typeof TCP_OPTION_RECV_BUFFER_SIZE;
value: number;
};

type UdpPortAckMessage = object;
consumedBytes: number;
type: typeof UDP_PORT_ACK_TYPE;

type UdpSocketOption =
| {
type: typeof UDP_OPTION_BROADCAST;
value: boolean;
}
| {
type: typeof UDP_OPTION_TTL;
value: number;
}
| {
type: typeof UDP_OPTION_MULTICAST_TTL_V4;
value: number;
}
| {
type: typeof UDP_OPTION_MULTICAST_LOOP_V4;
value: boolean;
}
| {
type: typeof UDP_OPTION_MULTICAST_LOOP_V6;
value: boolean;
}
| {
group: Uint8Array;
interface: Uint8Array;
type: typeof UDP_OPTION_ADD_MEMBERSHIP_V4;
}
| {
group: Uint8Array;
interface: Uint8Array;
type: typeof UDP_OPTION_DROP_MEMBERSHIP_V4;
}
| {
group: Uint8Array;
ifIndex: number;
type: typeof UDP_OPTION_ADD_MEMBERSHIP_V6;
}
| {
group: Uint8Array;
ifIndex: number;
type: typeof UDP_OPTION_DROP_MEMBERSHIP_V6;
}
| {
type: typeof UDP_OPTION_SEND_BUFFER_SIZE;
value: number;
}
| {
type: typeof UDP_OPTION_RECV_BUFFER_SIZE;
value: number;
};
const TCP_OPTION_KEEPALIVE: 2;

const TCP_OPTION_NODELAY: 0;

Socket option codes as they appear on the WebVPN wire, and the option shapes built from them. Also the ack a UDP data-port consumer posts back to the broker that produces the port’s batches.

Owned by the library so both sides share one source: the packet codecs in src/api/webvpn/packets/ import from this file, and the library needs nothing from the app.

The VALUES are protocol: the u8 discriminant of a tagged union inside a TcpSetOption or UdpSetOption client packet (metadata-stream tag 8). A relay built against these numbers deploys independently of any browser holding this file, so renumbering one is a wire break. Booleans go on the wire as u8, 0 for false and anything else true.


const TCP_OPTION_RECV_BUFFER_SIZE: 4;

const TCP_OPTION_SEND_BUFFER_SIZE: 3;

const TCP_OPTION_TTL: 1;

const UDP_OPTION_ADD_MEMBERSHIP_V4: 5;

const UDP_OPTION_ADD_MEMBERSHIP_V6: 7;

const UDP_OPTION_BROADCAST: 0;

const UDP_OPTION_DROP_MEMBERSHIP_V4: 6;

const UDP_OPTION_DROP_MEMBERSHIP_V6: 8;

const UDP_OPTION_MULTICAST_LOOP_V4: 3;

const UDP_OPTION_MULTICAST_LOOP_V6: 4;

const UDP_OPTION_MULTICAST_TTL_V4: 2;

const UDP_OPTION_RECV_BUFFER_SIZE: 10;

const UDP_OPTION_SEND_BUFFER_SIZE: 9;

const UDP_OPTION_TTL: 1;

const UDP_PORT_ACK_INTERVAL_BYTES: number;

const UDP_PORT_ACK_TYPE: "webvpn-udp-port-ack" = 'webvpn-udp-port-ack';