code wiki / (root) / nx_peerwire.nx

nx_peerwire.nx

buildroot/runtime/nx_peerwire.nx

3658 B100 linesdepth 2pulls 2 transitivereach 29 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_peerwire.nx -- BitTorrent peer wire protocol (BEP-3), bits-up. module: nishi-core.torrent.peerwire depends: nx_syscalls.nx capability: CORE_COMPUTE wired_status: FULLY_WIRED The block-exchange core: the 68-byte handshake (<19>"BitTorrent protocol" <8 reserved><info_hash 20><peer_id 20>) and length-prefixed messages (<4 BE len><id><payload>): choke/unchoke/interested/not_interested, have, bitfield, request, piece, cancel. Pure build/parse here (KAT'd, deterministic -- part of the determinism exceed thesis); the socket round-trip reuses the net stack, and piece verification reuses sha1/sha256. Big-endian on the wire.

dependencies 1 imports · 13 importers

nx_syscalls.nx nx_peerwire.nx nx_avail_map.nx nx_peer_connect_live.nx nx_peer_download.nx nx_peer_ext_handshake.nx nx_peer_handshake.nx nx_peer_metadata.nx nx_peer_piece.nx nx_peerwire_test.nx nx_pex_gate.nx nx_torrent_leech_probe.nx

diagram shows first 10 each side; +0 more imports, +3 more importers in the complete lists below.

imports: nx_syscalls.nx

imported by: nx_avail_map.nxnx_peer_connect_live.nxnx_peer_download.nxnx_peer_ext_handshake.nxnx_peer_handshake.nxnx_peer_metadata.nxnx_peer_piece.nxnx_peerwire_test.nxnx_pex_gate.nxnx_torrent_leech_probe.nxnx_torrent_peer_dl.nxnx_torrent_seed.nxnx_torrent_seed_gate.nx

structs

none

consts

17const NX_PW_CHOKE: i64 = 0
18const NX_PW_UNCHOKE: i64 = 1
19const NX_PW_INTERESTED: i64 = 2
20const NX_PW_NOT_INTERESTED: i64 = 3
21const NX_PW_HAVE: i64 = 4
22const NX_PW_BITFIELD: i64 = 5
23const NX_PW_REQUEST: i64 = 6
24const NX_PW_PIECE: i64 = 7
25const NX_PW_CANCEL: i64 = 8

functions

27func _pw_put_u32(out: *u8, off: i64, v: i64) -> i64
34func _pw_get_u32(buf: *u8, off: i64) -> i64
39func nx_pw_build_handshake(info_hash: *u8, peer_id: *u8, out: *u8) -> i64
54func nx_pw_parse_handshake(buf: *u8, n: i64, out_ih: *u8, out_pid: *u8) -> i64
68func nx_pw_build_msg(id: i64, payload: *u8, plen: i64, out: *u8) -> i64
76func nx_pw_msg_len(buf: *u8) -> i64 { return _pw_get_u32(buf, 0) } // payload+id len; 0 = keep-alive
called by 2: mainmain calls 1: _pw_get_u32
77func nx_pw_msg_id(buf: *u8) -> i64 { return buf[4] as i64 } // valid when msg_len > 0
79func nx_pw_build_have(piece_index: i64, out: *u8) -> i64
85func nx_pw_build_request(index: i64, begin: i64, length: i64, out: *u8) -> i64
94func nx_pw_bitfield_has(bitfield: *u8, byte_len: i64, piece_index: i64) -> i64