code wiki / (root) / nx_pex.nx

nx_pex.nx

buildroot/runtime/nx_pex.nx

9327 B183 linesdepth 3pulls 4 transitivereach 7 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_pex.nx -- BEP-11 Peer Exchange (ut_pex): parse/build the compact peer lists that connected peers gossip to each other over the BEP-10 extension channel. This is the high-value amplifier for TRACKERLESS magnets + stuck (99.x%) swarms -- once we hold ONE peer, PEX hands us MORE peers (often seeders the tracker/DHT never returned), directly attacking the operator's "no seeder / can't finish" pain. Reuses the universal compact-6B/peer idiom (b0<<24|b1<<16|b2<<8|b3, port b4<<8|b5) shared with nx_dht's value parse + the nx_bencode DECODE layer. Pure (no network): "import strips main", so THIS file is BOTH the lib AND a baked-KAT self-gate (deterministic, sovereign). The live BEP-10 round-trip is proven by nx_pex_gate. license_tier: ORIGINAL module: nishi-core.torrent.pex depends: nishi-core.torrent.bencode

dependencies 2 imports · 2 importers

nx_bencode.nx nx_itoa_lib.nx nx_pex.nx nx_pex_gate.nx nx_torrent_get.nx

imports: nx_bencode.nxnx_itoa_lib.nx

imported by: nx_pex_gate.nxnx_torrent_get.nx

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

main pex_build_added px_puts px_putdec pex_parse_added pex_parse_key nx_bc_dict_get sys_mmap nx_bc_str _bc_is_digit _bc_bytes_eq nx_bc_skip _bc_is_digit ↻ nx_bc_str ↻ px_puts ↻ pex_peer_id nx_bc_dict_get ↻ nx_bc_int _bc_is_digit ↻ px_w px_wn nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write sys_munmap

structs

none

consts

14const PEX_MAGIC_6881: i64 = 6881
15const PEX_MAGIC_51413: i64 = 51413
16const PEX_MAGIC_4096: i64 = 4096
17const PEX_MAGIC_6882: i64 = 6882
21const PEX_OUR_ID: i64 = 3

functions

25func px_puts(out: *u8, off: i64, s: *u8) -> i64
called by 2: pex_build_addedmain
32func px_putdec(out: *u8, off: i64, v: i64) -> i64
called by 1: pex_build_added
46func pex_build_added(ips: *i64, ports: *i64, cnt: i64, out: *u8) -> i64
called by 2: mainmain calls 2: px_putspx_putdec
70func pex_parse_key(buf: *u8, start: i64, n: i64, key: *u8, keylen: i64, ips: *i64, ports: *i64, max: i64) -> i64
96func pex_parse_added(buf: *u8, start: i64, n: i64, ips: *i64, ports: *i64, max: i64) -> i64
called by 3: mainmaintg_from_peer calls 1: pex_parse_key
102func pex_peer_id(mb: *u8, start: i64, n: i64) -> i64
called by 2: mainmain calls 2: nx_bc_dict_getnx_bc_int
113func px_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
118func px_wn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
120func main() -> i64