code wiki / (root) / nx_dht_announce.nx

nx_dht_announce.nx

buildroot/runtime/nx_dht_announce.nx

9803 B139 linesdepth 4pulls 6 transitivereach 1 importersview sourcekind tooltopic dht
docsdependenciesstructsconstsfunctions

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

nx_dht.nx nx_dns_a.nx nx_dht_announce.nx nx_seed_announce_all.nx

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

main da_hex2bin da_hexval da_p da_n dan_announce nx_dns_a_resolve sys_socket sys_set_socket_timeout sys_mmap sys_setsockopt sys_munmap sys_mmap ↻ da_sockaddr da_build_query da_qname sys_sendto sys_close sys_recvfrom da_parse da_u16 da_skip_name sys_socket ↻ sys_set_socket_timeout ↻ da_sock4 dht_build_get_peers dht_put dht_putraw sys_sendto ↻ sys_recvfrom ↻ dht_parse_nodes nx_bc_dict_get sys_mmap ↻ nx_bc_str _bc_is_digit _bc_bytes_eq nx_bc_skip _bc_is_digit ↻ nx_bc_str ↻ da_p ↻

structs

none

consts

16const K_MAGIC_6881: i64 = 6881
17const K_MAGIC_25401: i64 = 25401
18const K_MAGIC_8192: i64 = 8192
19const K_MAGIC_4096: i64 = 4096

functions

21func 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 }
29func 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 }
31func da_sock4(out: *u8, port: i64, a: i64, b: i64, c: i64, d: i64) -> i64
called by 1: dan_announce
37func 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
38func 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 }
called by 2: mainmain calls 1: da_hexval
43func dan_announce(ih: *u8, nid: *u8, our_port: i64) -> i64
118func main(argc: i64, argv: *i64) -> i64