code wiki / (root) / nx_dht_get_peers.nx

nx_dht_get_peers.nx

buildroot/runtime/nx_dht_get_peers.nx

8361 B117 linesdepth 4pulls 6 transitivereach 6 importersview sourcekind tooltopic dht
docsdependenciesstructsconstsfunctions

about

nx_dht_get_peers.nx -- SOVEREIGN DHT get_peers lookup (X-TORRENT-LIVE-002 R4c): find peers for a TRACKERLESS info_hash by walking the DHT. Seeds from bootstrap nodes, get_peers each, collects "values" (peers) and "nodes" (closer nodes to query next), a few BFS rounds. This is what makes the operator's trackerless magnets (magnet:?xt=urn:btih:..&dn=.. , no tr=) find peers. Composes nx_dht (KRPC) + nx_dns_a + raw UDP. v1 = BFS (no XOR routing yet); enough for popular swarms. license_tier: ORIGINAL layer: peer-discovery (trackerless) module: nishi-core.torrent.dht_get_peers depends: nishi-core.torrent.dht, nishi-core.dns_a

dependencies 2 imports · 1 importers

nx_dht.nx nx_dns_a.nx nx_dht_get_peers.nx nx_torrent_get.nx

imports: nx_dht.nxnx_dns_a.nx

imported by: nx_torrent_get.nx

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

main dgp_p2 dgp_strlen dgp_find 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 ↻ dgp_sockaddr dht_build_get_peers dht_put dht_putraw sys_sendto ↻ sys_recvfrom ↻ dht_parse_values nx_bc_dict_get sys_mmap ↻ nx_bc_str _bc_is_digit _bc_bytes_eq nx_bc_skip _bc_is_digit ↻ nx_bc_str ↻ nx_bc_skip ↻ dht_parse_nodes nx_bc_dict_get ↻

structs

none

consts

11const K_MAGIC_8192: i64 = 8192
12const K_MAGIC_6881: i64 = 6881
13const K_MAGIC_25401: i64 = 25401

functions

15func dgp_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: dgp_p2
16func dgp_p2(s: *u8) -> i64 { sys_write(1, s, dgp_strlen(s)); return 0 }
called by 2: dgp_findmain calls 1: dgp_strlen
17func dgp_pn2(v: i64) -> i64 { let t: *u8 = sys_mmap(28); 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 } let o: *u8 = sys_mmap(28); var i: i64=0; while i<k { o[i]=t[k-1-i]; i=i+1 } sys_write(1,o,k); return 0 }
called by 2: dgp_findmain
19func dgp_sockaddr(out: *u8, port: i64, a: i64, b: i64, c: i64, d: i64) -> i64
called by 2: dgp_querydgp_find
27func dgp_query(ipv: i64, port: i64, nid: *u8, ih: *u8, pips: *i64, pports: *i64, pmax: i64, nips: *i64, nports: *i64, nmax: i64, out_nn: *i64) -> i64
48func dgp_find(ih: *u8, nid: *u8, pips: *i64, pports: *i64, pmax: i64) -> i64
103func main() -> i64