code wiki / (root) / nx_torrent_seed_gate.nx

nx_torrent_seed_gate.nx

buildroot/runtime/nx_torrent_seed_gate.nx

9319 B166 linesdepth 8pulls 18 transitivereach 0 importersview sourcekind gate/prooftopic torrent
docsdependenciesstructsconstsfunctions

about

nx_torrent_seed_gate.nx -- SOVEREIGN LOOPBACK GATE for the BitTorrent SEEDER (nx_torrent_seed). Proves the missing UPLOAD half end-to-end: a real leecher connects to OUR seeder and pulls VERIFIED pieces off it. This is the exact inverse of nx_peer_download (which proved we can leech): here WE are the source. bind-before-fork (no race); child = the seed core `ts_serve_peer` over a real temp file; parent = a mock leecher that handshakes, reads our BITFIELD (all-present) + UNCHOKE, REQUESTs a piece in 16-byte blocks, assembles it, and asserts (a) the bytes == the file's bytes, (b) sha1(piece) == sha1(file slice) [the BitTorrent integrity guarantee], and (c) a request past EOF on the last, partial piece is CLAMPED to the real length. Deterministic; no external net; no-hang (socket timeouts). Run: ./_offc/nx_sov_build_run.elf nx_torrent_seed_gate (WOMB builds + runs; main() = the gate) license_tier: ORIGINAL module: nishi-core.torrent.seed_gate depends: nishi-core.torrent.seed, nishi-core.torrent.peerwire, nishi-core.crypto.sha1

dependencies 5 imports · 0 importers

nx_torrent_seed.nx nx_connect.nx nx_peerwire.nx nx_sha1.nx nx_gate_verdict.nx nx_torrent_seed_gate.nx

imports: nx_torrent_seed.nxnx_connect.nxnx_peerwire.nxnx_sha1.nxnx_gate_verdict.nx

imported by: nobody (leaf or entry point)

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

main sys_openat_wr g_w ts_sockaddr sys_socket sys_setsockopt sys_set_socket_timeout sys_mmap sys_setsockopt ↻ sys_munmap sys_bind sys_listen sys_fork sys_accept ts_serve_peer sys_set_socket_timeout ↻ ts_read_n sys_read mse_classify_first_byte nx_pw_parse_handshake ts_memeq mse_ctx_plain ts_serve_after_hs nx_pw_build_handshake mse_write rc4_crypt rc4_prga_byte mw_write_n ts_load_have sys_read ↻ ts_build_bitfield_have ts_build_full_bitfield nx_pw_build_msg _pw_put_u32 ts_read_msg_ctx mse_read mw_read_n sys_read ↻ rc4_crypt ↻ _pw_get_u32

structs

none

consts

20const G_PLEN: i64 = 64
21const G_NPC: i64 = 3
22const G_TOTAL: i64 = 160 // 64 + 64 + 32 (last piece is PARTIAL -> exercises EOF clamp)
23const G_BLK: i64 = 16
24const G_PATH: *u8 = "/tmp/_nx_seed_test.bin" as *u8

functions

26func g_w(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
27func g_wn(v: i64) -> i64
called by 1: main
33func main() -> i64