code wiki / (root) / nx_stun_server.nx

nx_stun_server.nx

buildroot/runtime/nx_stun_server.nx

4053 B79 linesdepth 5pulls 5 transitivereach 1 importersview sourcekind servicetopic stun
docsdependenciesstructsconstsfunctions

about

nx_stun_server.nx -- SOVEREIGN STUN server (reflexive-address responder), NishiLang, composing nx_stun. Rung 3 of the Nishi P2P interop stack (rung1 STUN codec, rung2 ICE). A Nishi endpoint behind a NAT sends a STUN Binding Request to this server; the server replies with a Binding Response whose XOR-MAPPED-ADDRESS is the sender's PUBLIC reflexive IP:port exactly as the server observed it on the wire. That is how an endpoint learns its server-reflexive (srflx) candidate -- the address a peer must use to reach it through the NAT -- WITHOUT any third-party STUN server (no stun.l.google.com). Every byte is ours. ss_handle is PURE (given a datagram + its source sockaddr -> a response), so it is gate-testable without sockets; main() is the UDP daemon that binds and services requests forever. No third-party code. license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/ietf/rfc_5389

dependencies 2 imports · 1 importers

nx_syscalls.nx nx_stun.nx nx_stun_server.nx nx_stun_server_gate.nx

imports: nx_syscalls.nxnx_stun.nx

imported by: nx_stun_server_gate.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap ss_sockaddr sys_socket ssp sys_write sys_bind sys_recvfrom ss_handle st_type st_get16 st_magic st_get32 ss_build_response st_write_header st_put16 st_put32 st_put16 ↻ st_xma_encode st_put16 ↻ st_put32 ↻ st_fingerprint nx_crc32 st_put32 ↻ ss_src_port ss_src_addr sys_sendto

structs

none

consts

14const SS_MAGIC_3478: i64 = 3478
15const SS_MAGIC_2048: i64 = 2048
17const SS_PORT: i64 = 3478 // the IANA-assigned STUN port

functions

20func ss_src_port(sa: *u8) -> i64 { return ((((sa[2] as i64)&0xff)<<8) | ((sa[3] as i64)&0xff)) }
called by 1: ss_handle
21func ss_src_addr(sa: *u8) -> i64
called by 1: ss_handle
26func ss_build_response(buf: *u8, txid: *u8, port: i64, addr: i64) -> i64
41func ss_handle(req: *u8, reqlen: i64, src: *u8, out: *u8) -> i64
49func ssp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
50func ss_sockaddr(sa: *u8, port: i64, i0: i64, i1: i64, i2: i64, i3: i64) -> i64
called by 2: mainmain
58func main() -> i64