code wiki / (root) / nx_peer_handshake.nx

nx_peer_handshake.nx

buildroot/runtime/nx_peer_handshake.nx

6201 B122 linesdepth 5pulls 7 transitivereach 0 importersview sourcekind tooltopic peer
docsdependenciesstructsconstsfunctions

about

nx_peer_handshake.nx -- BEP-3 peer-wire HANDSHAKE over a real TCP connection (X-TORRENT-LIVE-001 R4-a): the gateway to BOTH metadata (BEP-9/10) and pieces (BEP-3 request/piece). Wires nx_peerwire's KAT'd build/parse (nx_pw_build_handshake / nx_pw_parse_handshake / nx_pw_build_msg / nx_pw_msg_id) to a TCP socket on the nx_syscalls layer (sys_socket SOCK_STREAM + connect/listen/ accept; the UDP analog was nx_udp_tracker_announce). Import nx_peerwire ONLY (pulls nx_syscalls + _pw_*/nx_pw_* transitively; no double-import). GATE = SOVEREIGN LOOPBACK: a mock peer (TCP listen+accept on 127.0.0.1, listen-before-fork = no connect race) replies with its handshake (same info_hash) + a bitfield; the client must parse the handshake (info_hash matches) + receive the bitfield message. No external net; deterministic; no-hang (socket timeouts). license_tier: ORIGINAL module: nishi-core.torrent.peer_handshake depends: nishi-core.torrent.peerwire

dependencies 3 imports · 0 importers

nx_peerwire.nx nx_itoa_lib.nx nx_connect.nx nx_peer_handshake.nx

imports: nx_peerwire.nxnx_itoa_lib.nxnx_connect.nx

imported by: nobody (leaf or entry point)

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

main ph_sockaddr sys_socket sys_setsockopt sys_set_socket_timeout sys_mmap sys_setsockopt ↻ sys_munmap sys_bind sys_listen ph_w sys_fork sys_accept ph_read_n sys_read nx_pw_build_handshake ph_write_n nx_pw_build_msg _pw_put_u32 nx_connect_bounded nx_fcntl sys_connect sys_mmap ↻ sys_poll nx_pw_parse_handshake nx_pw_msg_len _pw_get_u32 nx_pw_msg_id sys_wait4 ph_wn nxi_fd sys_mmap ↻ ccz_cat_num sys_write sys_munmap ↻

structs

none

consts

16const K_MAGIC_53301: i64 = 53301

functions

18func ph_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
called by 1: main
23func ph_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: main calls 1: nxi_fd
24func ph_sockaddr(sa: *u8, port: i64, i0: i64, i1: i64, i2: i64, i3: i64) -> i64
called by 1: main
32func ph_read_n(fd: i64, buf: *u8, n: i64) -> i64
called by 1: main calls 1: sys_read
37func ph_write_n(fd: i64, buf: *u8, n: i64) -> i64
called by 1: main
43func main() -> i64