Skip to content

shim: extended torrent control — flags, caps, queue, scrape, move (ABI v4)#18

Merged
SethMorrowSoftware merged 1 commit into
mainfrom
claude/relaxed-cerf-816pyn
Jun 27, 2026
Merged

shim: extended torrent control — flags, caps, queue, scrape, move (ABI v4)#18
SethMorrowSoftware merged 1 commit into
mainfrom
claude/relaxed-cerf-816pyn

Conversation

@SethMorrowSoftware

Copy link
Copy Markdown
Owner

Batch 1 of surfacing more of libtorrent's protocol. The audit found the event surface already rich, but torrent_handle actions had real gaps — and tellingly, several were missing even though their result alerts were already wired (A_SCRAPE_REPLY, A_STORAGE_MOVED). This batch fills the control/storage side.

New ABI (v3 → v4, append-only)

btx_* bt* what
set_torrent_flags / unset_torrent_flags btSetTorrentFlags / btUnsetTorrentFlags the full torrent_flags_t set, carried as a 64-bit decimal string
btSetSequentialDownload · btSetAutoManaged · btSetSuperSeeding · btSetShareMode · btSetUploadMode named conveniences over the generic flags pair
set_max_connections / set_max_uploads btSetMaxConnections / btSetMaxUploads per-torrent caps
torrent_clear_error btClearTorrentError clear a torrent's error so it resumes
scrape_tracker btScrapeTracker request seed/leecher counts (→ scrapeReply)
move_storage btMoveStorage relocate downloaded files (→ storageMoved / fileError)
queue_position / queue_move btQueuePosition · btQueueUp/Down/Top/Bottom download-queue positioning

39 → 56 public handlers. The LCB layer also gains the kFlag* bit-value constants (mirroring libtorrent/torrent_flags.hpp) so script can combine flags readably.

Design notes

  • Flags as a 64-bit decimal string — there is no 64-bit foreign int (ABI §4.1); set(flags, mask) writes only the masked bits, so it's a clean read-modify-write.
  • btQueuePosition returns -1, not 0, for "not queued" — the one int-getter that does, because 0 is a real queue position. Documented in btx_abi.h and the API reference.
  • Every handler follows the established idiom: validate via torrent_only, wrap in the BTX_GUARD_* firewall, no-op-with-error on a stale handle.

Verification

  • C++: built + run under gcc ASan/UBSan against real libtorrent — 416 checks, 0 failures, clean -Wall -Wextra. New entry points each assert a harmless error on a bogus handle, plus queue-op range validation.
  • Static gates green: check-livecodescript 7/7; check-record-registry 91 in sync (no record-schema change this batch); golden vectors OK; BTX_ABI_VERSIONkABIVersion both 4.
  • README + api-reference updated. CI rebuilds the committed src/code binaries on merge (they're ABI v3 until then — same refresh flow as the BEP44 batch).

Next batches (roadmap)

  1. Inspection getters — file list (names/sizes), per-file progress, piece availability, tracker list, read-back priorities (adds record fields).
  2. Tracker/webseed editing · 4. Session ops (pause/resume, listen port, find-by-hash, classic DHT announce/get_peers) · 5. IP filter + extended add.

🤖 Generated with Claude Code

https://claude.ai/code/session_01371AXB4CUUke7enHHS8okc


Generated by Claude Code

…I v4)

Batch 1 of surfacing more of libtorrent's protocol: nine new torrent_handle
actions, all fire-and-forget, several of whose result alerts were already wired
(A_SCRAPE_REPLY, A_STORAGE_MOVED) but had no trigger until now.

New btx_* ABI (v3 -> v4, append-only):
- btx_set_torrent_flags / btx_unset_torrent_flags - the full torrent_flags_t
  set (sequential_download, auto_managed, share/upload/super-seed modes,
  apply_ip_filter, stop_when_ready, ...), carried as a 64-bit decimal string.
- btx_set_max_connections / btx_set_max_uploads - per-torrent caps.
- btx_torrent_clear_error - clear a torrent's error so it can resume.
- btx_scrape_tracker - request seed/leecher counts (-> scrapeReply).
- btx_move_storage - relocate downloaded files (-> storageMoved / fileError).
- btx_queue_position (getter; -1 == not queued, the one int-getter using -1 not
  0 since 0 is a real position) + btx_queue_move (up/down/top/bottom).

LCB layer: kABIVersion -> 4; nine foreign decls + public bt* wrappers; the
kFlag* bit-value constants mirroring libtorrent/torrent_flags.hpp; and named
convenience wrappers (btSetSequentialDownload / AutoManaged / SuperSeeding /
ShareMode / UploadMode) over the generic flags pair. 39 -> 56 public handlers.

Smoke test: every new entry point is a harmless error on a bogus handle, plus
queue-op range validation. Built + run under gcc ASan/UBSan against real
libtorrent: 416 checks, 0 failures, clean -Wall -Wextra. Static gates green
(check-livecodescript 7/7; record-registry 91 in sync; golden OK). README +
api-reference updated. CI rebuilds the committed binaries on merge.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01371AXB4CUUke7enHHS8okc
@SethMorrowSoftware SethMorrowSoftware marked this pull request as ready for review June 27, 2026 03:28
@SethMorrowSoftware SethMorrowSoftware merged commit 552274f into main Jun 27, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants