code wiki / (root) / nx_bencode.nx

nx_bencode.nx

buildroot/runtime/nx_bencode.nx

5353 B134 linesdepth 2pulls 2 transitivereach 31 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_bencode.nx -- bencoding parser (bits-up), the BitTorrent keystone. module: nishi-core.torrent.bencode depends: nx_syscalls.nx capability: CORE_COMPUTE wired_status: FULLY_WIRED genealogy_id: bittorrent_bep0003_bencoding The format ALL of BitTorrent is built on (.torrent metainfo, tracker responses, the peer wire protocol's extended messages): integers (i<d>e), byte strings (<len>:<bytes>), lists (l..e), dicts (d<key><val>..e). Parsing is length-driven (strings carry their length), so a real parser is required (you cannot byte-count 'e's -- strings contain arbitrary bytes). First piece of the sovereign torrent client; the tracker-announce step reuses nx_http_get_ua + nx_net_governor (the primitives extracted this session). Iterative skip (no recursion); offsets returned, no copying. Deterministic.

dependencies 1 imports · 13 importers

nx_syscalls.nx nx_bencode.nx nx_bencode_test.nx nx_dht.nx nx_http_tracker.nx nx_metainfo.nx nx_peer_ext_handshake.nx nx_peer_meta_live.nx nx_peer_metadata.nx nx_pex.nx nx_torrent_daemon.nx nx_torrent_extract.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_bencode_test.nxnx_dht.nxnx_http_tracker.nxnx_metainfo.nxnx_peer_ext_handshake.nxnx_peer_meta_live.nxnx_peer_metadata.nxnx_pex.nxnx_torrent_daemon.nxnx_torrent_extract.nxnx_torrent_peer_dl.nxnx_torrent_seedeval.nxnx_tracker.nx

structs

none

consts

21const NX_BC_ERR: i64 = 0
22const NX_BC_INT: i64 = 1
23const NX_BC_STR: i64 = 2
24const NX_BC_LIST: i64 = 3
25const NX_BC_DICT: i64 = 4

functions

27func _bc_is_digit(c: i64) -> i64 { if c >= 0x30 { if c <= 0x39 { return 1 } } return 0 }
29func _bc_bytes_eq(buf: *u8, off: i64, key: *u8, keylen: i64) -> i64
called by 1: nx_bc_dict_get
36func nx_bc_type(buf: *u8, off: i64, n: i64) -> i64
47func nx_bc_int(buf: *u8, off: i64, n: i64, out_val: *i64) -> i64
64func nx_bc_str(buf: *u8, off: i64, n: i64, out_so: *i64, out_sl: *i64) -> i64
79func nx_bc_skip(buf: *u8, off: i64, n: i64) -> i64
110func nx_bc_dict_get(buf: *u8, dict_off: i64, n: i64, key: *u8, keylen: i64) -> i64