code wiki / (root) / nx_dht.nx

nx_dht.nx

buildroot/runtime/nx_dht.nx

11635 B185 linesdepth 3pulls 3 transitivereach 10 importersview sourcekind tooltopic dht
docsdependenciesstructsconstsfunctions

about

nx_dht.nx -- SOVEREIGN DHT (BEP-5 / Kademlia) KRPC primitives (X-TORRENT-LIVE-002 R4 foundation). WHY: the operator's magnets are TRACKERLESS (magnet:?xt=urn:btih:..&dn=.. with no tr=). The ONLY way to find peers for a trackerless magnet is the DHT -- a global Kademlia network queried with KRPC (bencode over UDP). This rung = the message layer: build ping/get_peers queries + parse the responses (values=peers, nodes=closer-nodes, token). The team's own organ speaks the protocol; nothing external decides. Composes nx_bencode. UDP transport + iterative lookup = next rungs. KRPC (BEP-5), keys bencode-sorted: ping q: d1:ad2:id20:<nid>e1:q4:ping1:t2:<tx>1:y1:qe get_peers q: d1:ad2:id20:<nid>9:info_hash20:<ih>e1:q9:get_peers1:t2:<tx>1:y1:qe response: d1:rd2:id20:<id>[5:token..][6:valuesl6:<peer>..e | 5:nodes<26B*k>]e1:t2:<tx>1:y1:re license_tier: ORIGINAL layer: peer-discovery (trackerless) module: nishi-core.torrent.dht depends: nishi-core.bencode

dependencies 1 imports · 3 importers

nx_bencode.nx nx_dht.nx nx_dht_announce.nx nx_dht_get_peers.nx nx_dht_ping.nx

imports: nx_bencode.nx

imported by: nx_dht_announce.nxnx_dht_get_peers.nxnx_dht_ping.nx

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

main dht_build_ping dht_put dht_putraw nx_bc_dict_get sys_mmap nx_bc_str _bc_is_digit _bc_bytes_eq nx_bc_skip _bc_is_digit ↻ dht_report dht_p2 dht_strlen dht_build_get_peers dht_put ↻ dht_putraw ↻ dht_put ↻ dht_putraw ↻ dht_parse_values nx_bc_dict_get ↻ nx_bc_str ↻ nx_bc_skip ↻ dht_build_announce_peer dht_put ↻ dht_putraw ↻ dht_putn nx_bc_int _bc_is_digit ↻ dht_parse_token nx_bc_dict_get ↻ nx_bc_str ↻ dht_p2 ↻ dht_pn2

structs

none

consts

16const K_MAGIC_6881: i64 = 6881
17const K_MAGIC_16909060: i64 = 16909060

functions

19func dht_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: dht_p2
20func dht_put(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i }
21func dht_putraw(dst: *u8, off: i64, raw: *u8, len: i64) -> i64 { var i: i64 = 0; while i < len { dst[off+i] = raw[i]; i = i + 1 } return off + len }
22func dht_putn(dst: *u8, off: i64, v: i64) -> i64 { if v==0 { dst[off]=48 as u8; return off+1 } let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; while m>0 {t[k]=(48+(m%10)) as u8; m=m/10; k=k+1} var o: i64=off; var i: i64=k-1; while i>=0 {dst[o]=t[i];o=o+1;i=i-1} return o }
23func dht_p2(s: *u8) -> i64 { sys_write(1, s, dht_strlen(s)); return 0 }
called by 2: dht_reportmain calls 1: dht_strlen
24func dht_pn2(v: i64) -> i64 { let b: *u8 = sys_mmap(28); var m: i64 = v; var k: i64 = 0; if m == 0 { b[0] = 48 as u8; k = 1 } let t: *u8 = sys_mmap(28); while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; let o: *u8 = sys_mmap(28); while i < k { o[i] = t[k-1-i]; i = i + 1 } sys_write(1, o, k); return 0 }
called by 1: main
25func dht_report(label: *u8, ok: i64) -> i64 { if ok == 1 { dht_p2(" [PASS] " as *u8) } else { dht_p2(" [FAIL] " as *u8) } dht_p2(label); dht_p2("\n" as *u8); return 0 }
called by 1: main calls 1: dht_p2
28func dht_build_ping(nid: *u8, tx: *u8, out: *u8) -> i64
called by 2: maindp_try calls 2: dht_putdht_putraw
36func dht_build_get_peers(nid: *u8, ih: *u8, tx: *u8, out: *u8) -> i64
48func dht_build_announce_peer(nid: *u8, ih: *u8, port: i64, token: *u8, tlen: i64, tx: *u8, out: *u8) -> i64
59func dht_parse_token(buf: *u8, n: i64, out: *u8, max: i64) -> i64
71func dht_is_response(buf: *u8, n: i64) -> i64 { if nx_bc_dict_get(buf, 0, n, "r" as *u8, 1) >= 0 { return 1 } return 0 }
called by 1: dan_announce calls 1: nx_bc_dict_get
75func dht_parse_values(buf: *u8, n: i64, ips: *i64, ports: *i64, max: i64) -> i64
102func dht_parse_nodes(buf: *u8, n: i64, ips: *i64, ports: *i64, max: i64) -> i64
125func main() -> i64