nx_lsd.nx
buildroot/runtime/nx_lsd.nx
about
nx_lsd.nx -- SOVEREIGN BitTorrent Local Service Discovery (BEP-14): find/announce peers on the LAN via
multicast 239.192.152.143:6771, no tracker. Two halves: ANNOUNCE (multicast BT-SEARCH for each seeded
info_hash) + LISTEN (join the group, receive BT-SEARCH, map the info_hash -> a local download via
SHA1(download.meta), append the sender's ip:port to that download.pex -> the worker's peer set folds it in).
Verbs: announce <ih_hex> [port] | announceall <seed_registry> [port] | listen <area..> <seconds> | selftest.
license_tier: ORIGINAL depends: nx_syscalls, nx_sha1
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_sha1.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 9 | const LSD_MAGIC_6881: i64 = 6881 |
| 10 | const LSD_MAGIC_131072: i64 = 131072 |
| 11 | const LSD_MAGIC_131071: i64 = 131071 |
| 12 | const LSD_MAGIC_2048: i64 = 2048 |
| 13 | const LSD_MAGIC_2047: i64 = 2047 |
| 15 | const LSD_PORT: i64 = 6771 |
functions
| 17 | func lsd_group(oct: *u8) -> i64 { oct[0]=239 as u8; oct[1]=192 as u8; oct[2]=152 as u8; oct[3]=143 as u8; return 0 } called by 1: lsd_join |
| 19 | func lp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 20 | func lpn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(28); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } while k>0 { k=k-1; sys_write(1,(((t as i64)+k) as *u8),1) } return 0 } |
| 21 | func lsd_sock4(out: *u8, port: i64, a: i64, b: i64, c: i64, d: i64) -> i64 |
| 26 | func lsd_app(dst: *u8, o: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8) { dst[o]=s[i]; o=o+1; i=i+1 } return o } called by 1: lsd_build |
| 27 | func lsd_appn(dst: *u8, o: i64, v: i64) -> i64 { if v==0 { dst[o]=48 as u8; return o+1 } var m: i64=v; let t: *u8=sys_mmap(28); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } while k>0 { k=k-1; dst[o]=t[k]; o=o+1 } return o } |
| 28 | func lsd_find(buf: *u8, n: i64, start: i64, ndl: *u8, nl: i64) -> i64 { if nl<=0 { return 0-1 } var s: i64=start; while s+nl<=n { var m: i64=1; var k: i64=0; while k<nl { if buf[s+k]!=ndl[k] { m=0; k=nl } else { k=k+1 } } if m==1 { return s } s=s+1 } return 0-1 } |
| 29 | func lsd_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8) { if a[i]!=b[i] { return 0 } i=i+1 } if b[i]!=(0 as u8) { return 0 } return 1 } called by 1: main |
| 30 | func lsd_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8) { if s[i]>=(48 as u8) { if s[i]<=(57 as u8) { v=v*10+((s[i] as i64)-48) } } i=i+1 } return v } called by 1: main |
| 33 | func lsd_build(ih_hex: *u8, port: i64, out: *u8) -> i64 |
| 41 | func lsd_parse(buf: *u8, n: i64, out_ih: *u8, out_port: *i64) -> i64 |
| 52 | func lsd_join(fd: i64) -> i64 |
| 59 | func lsd_announce_one(ih_hex: *u8, port: i64) -> i64 |
| 66 | func lsd_read_file(path: *u8, buf: *u8, cap: i64) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0 { return 0-1 } var t: i64=0; var r: i64=1; while r>0 { r=sys_read(fd,(((buf as i64)+t) as *u8),cap-t); if r>0 { t=t+r } } sys_close(fd); return t } |
| 68 | func main(argc: i64, argv: *i64) -> i64 |