nx_peerwire.nx
buildroot/runtime/nx_peerwire.nx
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
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
| 17 | const NX_PW_CHOKE: i64 = 0 |
| 18 | const NX_PW_UNCHOKE: i64 = 1 |
| 19 | const NX_PW_INTERESTED: i64 = 2 |
| 20 | const NX_PW_NOT_INTERESTED: i64 = 3 |
| 21 | const NX_PW_HAVE: i64 = 4 |
| 22 | const NX_PW_BITFIELD: i64 = 5 |
| 23 | const NX_PW_REQUEST: i64 = 6 |
| 24 | const NX_PW_PIECE: i64 = 7 |
| 25 | const NX_PW_CANCEL: i64 = 8 |
functions
| 27 | func _pw_put_u32(out: *u8, off: i64, v: i64) -> i64 |
| 34 | func _pw_get_u32(buf: *u8, off: i64) -> i64 |
| 39 | func nx_pw_build_handshake(info_hash: *u8, peer_id: *u8, out: *u8) -> i64 |
| 54 | func nx_pw_parse_handshake(buf: *u8, n: i64, out_ih: *u8, out_pid: *u8) -> i64 |
| 68 | func nx_pw_build_msg(id: i64, payload: *u8, plen: i64, out: *u8) -> i64 |
| 76 | func nx_pw_msg_len(buf: *u8) -> i64 { return _pw_get_u32(buf, 0) } // payload+id len; 0 = keep-alive |
| 77 | func nx_pw_msg_id(buf: *u8) -> i64 { return buf[4] as i64 } // valid when msg_len > 0 |
| 79 | func nx_pw_build_have(piece_index: i64, out: *u8) -> i64 |
| 85 | func nx_pw_build_request(index: i64, begin: i64, length: i64, out: *u8) -> i64 |
| 94 | func nx_pw_bitfield_has(bitfield: *u8, byte_len: i64, piece_index: i64) -> i64 |