nx_dht_announce.nx
buildroot/runtime/nx_dht_announce.nx
about
nx_dht_announce.nx -- SOVEREIGN DHT announce_peer (BEP-5): make OUR seeder DISCOVERABLE for an info_hash.
The seeder (nx_torrent_seed) serves pieces, but a stranger can only reach it if the DHT knows we hold the
info_hash. This organ does the announce half: walk get_peers toward the info_hash (Kademlia BFS) capturing
each responding node's (ip, port, token) -- the token proves we queried that node -- then blast announce_peer
(ih, our_port, token) to those nodes. Each node that ACKs has STORED "peer <us> holds <ih>", so a later
get_peers(ih) reaching it returns us in its values list. Composes nx_dht (KRPC) + nx_dns_a + raw UDP.
v1 = BFS toward the hash (no strict XOR-closest sort yet; announce to reached responders) -- honest label.
nx_dht_announce <ih_hex40> <our_port> -> announce we hold ih at our_port; prints #nodes acked
nx_dht_announce -> LIVE gate: announce the demo info_hash, acks>0 = GREEN
license_tier: ORIGINAL layer: peer-discovery (announce) module: nishi-core.torrent.dht_announce
depends: nishi-core.torrent.dht, nishi-core.dns_a
dependencies 2 imports · 1 importers
imports: nx_dht.nxnx_dns_a.nx
imported by: nx_seed_announce_all.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 16 | const K_MAGIC_6881: i64 = 6881 |
| 17 | const K_MAGIC_25401: i64 = 25401 |
| 18 | const K_MAGIC_8192: i64 = 8192 |
| 19 | const K_MAGIC_4096: i64 = 4096 |
functions
| 21 | func da_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 29 | func da_n(v: i64) -> i64 { if DAN_NT == 0 { DAN_NT = sys_mmap(64) as i64; DAN_NO = sys_mmap(64) as i64 } let t: *u8=DAN_NT as *u8; let o: *u8=DAN_NO as *u8; var m: i64=v; var k: i64=0; if m==0 {t[0]=48 as u8;k=1} while m>0 {t[k]=(48+(m%10)) as u8; m=m/10; k=k+1} var i: i64=0; while i<k {o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 } |
| 31 | func da_sock4(out: *u8, port: i64, a: i64, b: i64, c: i64, d: i64) -> i64 called by 1: dan_announce |
| 37 | func da_hexval(c: i64) -> i64 { if c>=48 { if c<=57 { return c-48 } } if c>=97 { if c<=102 { return c-87 } } if c>=65 { if c<=70 { return c-55 } } return 0 } called by 1: da_hex2bin |
| 38 | func da_hex2bin(hex: *u8, out: *u8) -> i64 { var i: i64=0; while i<20 { let h: i64=hex[i*2] as i64; let l: i64=hex[i*2+1] as i64; if h==0 { return 0 } if l==0 { return 0 } out[i]=((da_hexval(h)*16)+da_hexval(l)) as u8; i=i+1 } return 1 } |
| 43 | func dan_announce(ih: *u8, nid: *u8, our_port: i64) -> i64 called by 2: mainmain calls 13: nx_dns_a_resolvesys_socketsys_set_socket_timeoutda_sock4dht_build_get_peerssys_sendto+7 |
| 118 | func main(argc: i64, argv: *i64) -> i64 |