Skip to content

Conversation

@leoherzog
Copy link
Contributor

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[ ] Bug fix
[ X ] New feature
[ ] Other, please explain:

What changes did you make? (Give an overview)

Added parsing of infoHash and/or infoHashv2, as well as generation of v1, v2, or Hybrid torrents.

Which issue (if any) does this pull request address?

Issue #88

leoherzog and others added 3 commits May 28, 2025 09:38
- Support both SHA1 (v1) and SHA256 (v2) infohashes in validation
- Add v2 hex string (64 chars) and buffer (32 bytes) detection
- Update magnet parsing to accept both btih and btmh URNs
- Add v2 torrent file parsing with file tree structure
- Generate both SHA1 and SHA256 hashes for v2 torrents
- Update validation logic to require either v1 or v2 hash

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced May 28, 2025
@sneakers-the-rat
Copy link

Thanks for getting to this so quick, my week filled up faster than in anticipated. We will probably need to follow this up with some convenience methods for getting piece roots and piece layers at file offsets when working on the downstream webtorrent impl, but it looks like most of the parts we need are in place here, modulo open comments

This ensures that pure v2 torrents don't appear to be invalid hybrids to downstream consumers, while still providing the flattened file structure for easier processing
@leoherzog
Copy link
Contributor Author

@ThaUnknown @sneakers-the-rat Incorporated your feedback and made a bunch of tweaks. Can rebase/squash before merging, if you'd like.

@leoherzog leoherzog changed the title Feat: BitTorrent v2 Support Feat: BitTorrent v2 Support [BEP 52] Jun 27, 2025
@leoherzog
Copy link
Contributor Author

@ThaUnknown @sneakers-the-rat Awaiting feedback

@ThaUnknown
Copy link
Member

I'm aware I'm holding this back, the PR itself for the most part looks fine, but I don't know about the functionality, since I'd need to go into the specifics of btv2, read the spec, and test it myself, for which I don't have time as of now

@leoherzog
Copy link
Contributor Author

@ThaUnknown Cool. Let me know if I can be helpful in that somehow.

https://blog.libtorrent.org/2020/09/bittorrent-v2/

@sneakers-the-rat
Copy link

Sorry dropped off my radar. I know the spec and have written a parser and generator so can evaluate. Marking unread to check out tmrw

Copy link

@sneakers-the-rat sneakers-the-rat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok cool, this is much smaller than i thought it would be - this pretty much covers it if the goal is just to load it into a js object rather than validating.

can't really comment on compatibility with downstream use, but flatting the file tree is sort of the main thing, and downstream consumers will have to figure out how to deal with the absence of v1 pieces and validate with the file trees instead.

one thing that might be useful is to have an additional version field that is "v1" | "v2" | "hybrid" so that downstream consumers can check that without needing to repeat the sort of awkward checks for presence of different fields

@leoherzog
Copy link
Contributor Author

Thanks for looking at this, @sneakers-the-rat. I really appreciate your time and thoughts.

I think I've addressed all of the raised points. It's a lot cleaner now. Again, I'll leave the commits all separate for clarity in this PR for now, but I can merge/squash into a couple of clearer commits when we think everything's resolved.

Also, I'm not sure if it's you maintainers' job to "resolve conversation" on the comment threads, or mine :)

Copy link

@sneakers-the-rat sneakers-the-rat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(fwiw for maintainers, all my comments addressed :)

@parthibx24
Copy link

why is this stale 😭

@leoherzog
Copy link
Contributor Author

@ThaUnknown I have "resolved" all of the open comments from @sneakers-the-rat

@ThaUnknown
Copy link
Member

yes but webtorrent is dead until @feross fixes the NPM keys that have expired, so this won't be published until that's done anyways

my general lack of interest, or deep understanding of the protocol doesnt help, neither does the utter hatered for how horrificly this package is structured and written

@sneakers-the-rat
Copy link

so where does that leave us? surely it can't take too much time for @feross to fix the keys right? this little bitty thing is just the first step in v2 support, so should we take this as a sign not to bother and treat webtorrent as abandoned? or do we merge this and continue even if we have feeling about the code structure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants