code wiki / (root) / nx_websocket.nx

nx_websocket.nx

buildroot/runtime/nx_websocket.nx

11469 B303 linesdepth 4pulls 4 transitivereach 0 importersview sourcekind orphan librarytopic websocket
docsdependenciesstructsconstsfunctions

about

nx_websocket.nx -- RFC 6455 server-side WebSocket primitive. Pure NishiLang. No external library. Composes nx_sha1 and nx_base64 (both already shipped) for the handshake; implements the binary framing (opcodes, masking, payload-length variants) from the RFC text. Server-side flow: 1. Client sends: GET /ws HTTP/1.1 Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: <base64 16-byte nonce> Sec-WebSocket-Version: 13 We compute Sec-WebSocket-Accept = base64(sha1(key + GUID)) where GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" (RFC 6455 section 1.3). 2. Reply: HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: <accept> 3. Subsequent traffic is binary frames. Frame layout (most-common case; mask MUST be present for client->server): [byte 0] FIN (1) | RSV (3) | OPCODE (4) [byte 1] MASK (1) | LEN7 (7) LEN7 in 0..125: payload length is LEN7 LEN7 == 126: next 2 bytes (big-endian) are payload length LEN7 == 127: next 8 bytes (big-endian) are payload length [4 bytes] masking-key (when MASK=1) [N bytes] payload (XORed with masking-key when MASK=1) Common opcodes: 0x0 continuation 0x1 text 0x2 binary 0x8 close 0x9 ping 0xA pong

dependencies 2 imports · 0 importers

nx_syscalls_x86_64.nx nx_ws_crypto.nx nx_websocket.nx

imports: nx_syscalls_x86_64.nxnx_ws_crypto.nx

imported by: nobody (leaf or entry point)

structs

none

consts

56const NX_WS_VERDICT_UNKNOWN: i64 = 0
57const NX_WS_VERDICT_OK: i64 = 1
58const NX_WS_VERDICT_BAD_HANDSHAKE: i64 = 2
59const NX_WS_VERDICT_BUF_TOO_SMALL: i64 = 3
60const NX_WS_VERDICT_TRUNCATED: i64 = 4
61const NX_WS_VERDICT_UNSUPPORTED_FRAME: i64 = 5
62const NX_WS_VERDICT_BAD_PARAMS: i64 = 6
63const NX_WS_VERDICT_N: i64 = 7
65const NX_WS_OPCODE_CONT: i64 = 0
66const NX_WS_OPCODE_TEXT: i64 = 1
67const NX_WS_OPCODE_BINARY: i64 = 2
68const NX_WS_OPCODE_CLOSE: i64 = 8
69const NX_WS_OPCODE_PING: i64 = 9
70const NX_WS_OPCODE_PONG: i64 = 10
72const NX_WS_FIN_BIT: i64 = 128
73const NX_WS_MASK_BIT: i64 = 128

functions

76func _ws_guid(buf: *u8) -> i64
96func _ws_write_guid_at(combined: *u8, k: i64) -> i64
called by 1: nx_ws_accept_key
115func _ws_copy(dst: *u8, src: *u8, n: i64) -> i64
called by 1: nx_ws_accept_key
127func nx_ws_accept_key(client_key: *u8, key_len: i64,
147func nx_ws_build_handshake_response(out_buf: *u8, out_cap: i64,
203func nx_ws_build_frame(out_buf: *u8, out_cap: i64,
248func nx_ws_parse_frame_inplace(
299func nx_ws_verdict_is_valid(v: i64) -> i64