Skip to content

Wire BEP 9 metadata exchange into wl get (peer fallback)#11

Merged
iksnerd merged 1 commit into
mainfrom
feat/bep9-metadata-fallback
Jun 13, 2026
Merged

Wire BEP 9 metadata exchange into wl get (peer fallback)#11
iksnerd merged 1 commit into
mainfrom
feat/bep9-metadata-fallback

Conversation

@iksnerd

@iksnerd iksnerd commented Jun 13, 2026

Copy link
Copy Markdown
Owner

The Code Nexus analysis flagged FetchMetadata as dead code — the BEP 9 ut_metadata implementation was built and tested but never called, so wl get always sourced the info dict from the registry API. A magnet only resolved if it was registered, and the README's BEP 9 claim was effectively dead. BEP 9 is a valid, core part of the magnet workflow, so this wires it in rather than deleting it.

Changes

  • wl get tries the registry first, then falls back to BEP 9: announce → connect to peers → fetch the info dict via ut_metadata → parse → download. The client chain already existed and is exported (ConnectHandshake, which does the BEP 10 extended handshake inline → FetchMetadata); this is the glue.
  • torrent.ParseInfo — parse a bare info dict (what a peer serves over BEP 9) into TorrentMeta, sharing parseInfoMap with Parse.
  • torrent.BuildMetainfo — rebuild a saveable .torrent from peer-fetched info bytes via bencode.RawMessage, preserving the info hash exactly.

Verification

  • TestFetchMetadataEndToEnd — real wire protocol against a BEP 9-speaking mock peer: BEP 3 handshake + BEP 10 extended handshake advertising metadata_size + multi-piece ut_metadata data (40 KB / 3 pieces). This is the first real end-to-end test for the metadata path (previously only a size-guard unit test existed — which is how it slipped to dead code).
  • TestParseInfoRoundTripParseInfo on a bare info dict matches Parse on the full torrent; BuildMetainfo round-trips with the v2 info hash byte-preserved.
  • go build / go vet / gofmt clean; full go test ./... green.

Scope / honest notes

  • BEP 9 ut_metadata verifies against the v1 (SHA-1) info hash, so v2-only magnets can't use the fallback — it errors clearly rather than silently.
  • weightless's own tracker is registry-only (registration stores the .torrent and enables peer tracking), so on it a registry miss also means no peers. The fallback therefore mainly helps in open-tracker mode or with external/public trackers — where peers exist but no registry entry does. Full multi-process verification (Transmission seeding via an open tracker) is the natural next manual step.

🤖 Generated with Claude Code

Previously the BEP 9 ut_metadata implementation (FetchMetadata) was built and
tested but never called — wl get always sourced the info dict from the registry
API, so a magnet only resolved if it was registered, and the README's BEP 9
claim was effectively dead. Rather than delete a valid protocol path, wire it in.

- wl get now tries the registry first, then falls back to BEP 9: announce →
  connect to peers → fetch the info dict via ut_metadata → parse → download.
  The whole client chain already existed and is exported (Connect → Handshake,
  which does the BEP 10 extended handshake inline → FetchMetadata).
- torrent.ParseInfo: parse a bare info dict (what a peer serves) into
  TorrentMeta, sharing parseInfoMap with Parse.
- torrent.BuildMetainfo: rebuild a saveable .torrent from peer-fetched info
  bytes via bencode.RawMessage, preserving the info hash exactly.

Verification:
- TestFetchMetadataEndToEnd: real wire protocol against a BEP 9-speaking mock
  peer (handshake + extended handshake with metadata_size + multi-piece
  ut_metadata data, 40 KB / 3 pieces). First real end-to-end test for the path.
- TestParseInfoRoundTrip: ParseInfo on a bare info dict matches Parse on the
  full torrent, and BuildMetainfo round-trips with the v2 info hash preserved.

Scope: BEP 9 fetch verifies against the v1 (SHA-1) hash, so v2-only magnets
can't use it (errors clearly). Because weightless's own tracker is registry-only
(registration stores the .torrent AND enables tracking), the fallback mainly
helps in open-tracker mode or with external/public trackers — where peers exist
but no registry entry does.
@iksnerd iksnerd merged commit 65ef60f into main Jun 13, 2026
1 check passed
@iksnerd iksnerd deleted the feat/bep9-metadata-fallback branch June 13, 2026 14:20
iksnerd added a commit that referenced this pull request Jun 21, 2026
Wire BEP 9 metadata exchange into wl get (peer fallback)
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.

1 participant