forked from webtorrent/bittorrent-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/megatorrent reference 2716865330907683697 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
robertpelloni
merged 2 commits into
master
from
feature/megatorrent-reference-2716865330907683697
Dec 18, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "qbittorrent"] | ||
| path = qbittorrent | ||
| url = https://github.com/robertpelloni/qbittorrent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Megatorrent Monorepo | ||
|
|
||
| This repository contains the reference implementation for the Megatorrent protocol, a decentralized, mutable successor to BitTorrent. | ||
|
|
||
| ## Structure | ||
|
|
||
| * `docs/`: Architecture and Protocol Specifications. | ||
| * `tracker/`: Node.js implementation of the Tracker and Reference Client (the root of this repo, historically). | ||
| * `qbittorrent/`: C++ Client Fork (Submodule). | ||
|
|
||
| ## Getting Started | ||
|
|
||
| ### Node.js Tracker & Reference Client | ||
| Run the tracker and client tests: | ||
| ```bash | ||
| npm install | ||
| npm test | ||
| ``` | ||
|
|
||
| ### qBittorrent Client | ||
| See `qbittorrent/README.md` for C++ build instructions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
|
|
||
| ## 6. Obfuscated Storage Protocol (Phase 2) | ||
| To achieve plausible deniability and distributed redundancy, data is not stored as "files" but as "Blobs" of high-entropy data. | ||
|
|
||
| ### Concepts | ||
| * **Blob**: A fixed-size (or variable) container stored by a Host. To the Host, it is just random bytes. | ||
| * **Chunk**: A segment of a user's file. | ||
| * **Encryption**: Each Chunk is encrypted with a *unique* random key (ChaCha20-Poly1305) before being placed into a Blob. | ||
| * **Muxing**: A Blob may contain multiple Chunks (potentially from different files) or padding. | ||
|
|
||
| ### Data Structure: The `FileEntry` | ||
| This structure replaces the simple "magnet link" in the Megatorrent Manifest. | ||
|
|
||
| ```json | ||
| { | ||
| "name": "episode1.mkv", | ||
| "mime": "video/x-matroska", | ||
| "size": 104857600, | ||
| "chunks": [ | ||
| { | ||
| "blobId": "<SHA256 Hash of the Blob>", | ||
| "offset": 0, // Byte offset in the Blob | ||
| "length": 1048576, // Length of the encrypted chunk | ||
| "key": "<32-byte Hex Key>", | ||
| "nonce": "<12-byte Hex Nonce>", | ||
| "authTag": "<16-byte Hex Tag>" | ||
| }, | ||
| ... | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ### Process | ||
| 1. **Ingest**: | ||
| * File is split into N chunks. | ||
| * For each chunk: | ||
| * Generate random Key & Nonce. | ||
| * Encrypt Chunk -> EncryptedChunk. | ||
| * (Simplification for Ref Impl) EncryptedChunk becomes a "Blob" directly (or is wrapped). | ||
| * Blob ID = SHA256(Blob). | ||
| * Result: A list of Blobs (to be uploaded) and a `FileEntry` (to be put in the Manifest). | ||
|
|
||
| 2. **Access**: | ||
| * Subscriber receives Manifest. | ||
| * Parses `FileEntry`. | ||
| * Requests Blob(ID) from the network (simulated via local dir or tracker relay). | ||
| * Extracts bytes at `offset` for `length`. | ||
| * Decrypts using `key` and `nonce`. | ||
| * Reassembles file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import stringify from 'fast-json-stable-stringify' | ||
| import sodium from 'sodium-native' | ||
|
|
||
| export function verify (message, signature, publicKey) { | ||
| const msgBuffer = Buffer.isBuffer(message) ? message : Buffer.from(message) | ||
| return sodium.crypto_sign_verify_detached(signature, msgBuffer, publicKey) | ||
| } | ||
|
|
||
| export function validateManifest (manifest) { | ||
| if (!manifest || typeof manifest !== 'object') throw new Error('Invalid manifest') | ||
| if (!manifest.publicKey || !manifest.signature) throw new Error('Missing keys') | ||
|
|
||
| // Validation | ||
| if (typeof manifest.publicKey !== 'string' || !/^[0-9a-fA-F]{64}$/.test(manifest.publicKey)) { | ||
| throw new Error('Invalid public key format') | ||
| } | ||
| if (typeof manifest.signature !== 'string' || !/^[0-9a-fA-F]{128}$/.test(manifest.signature)) { | ||
| throw new Error('Invalid signature format') | ||
| } | ||
| if (typeof manifest.sequence !== 'number') throw new Error('Invalid sequence') | ||
| if (typeof manifest.timestamp !== 'number') throw new Error('Invalid timestamp') | ||
| if (!Array.isArray(manifest.collections)) throw new Error('Invalid collections') | ||
|
|
||
| // Reconstruct the payload to verify (exclude signature) | ||
| const payload = { | ||
| publicKey: manifest.publicKey, | ||
| sequence: manifest.sequence, | ||
| timestamp: manifest.timestamp, | ||
| collections: manifest.collections | ||
| } | ||
|
|
||
| const jsonString = stringify(payload) | ||
| const publicKey = Buffer.from(manifest.publicKey, 'hex') | ||
| const signature = Buffer.from(manifest.signature, 'hex') | ||
|
|
||
| return verify(jsonString, signature, publicKey) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |||||||
| "compact2string": "^1.4.1", | ||||||||
| "cross-fetch-ponyfill": "^1.0.3", | ||||||||
| "debug": "^4.3.4", | ||||||||
| "fast-json-stable-stringify": "^2.1.0", | ||||||||
| "ip": "^2.0.1", | ||||||||
| "lru": "^3.1.0", | ||||||||
|
||||||||
| "lru": "^3.1.0", | |
| "lru": "^3.1.0", | |
| "lru-cache": "^7.18.3", |
Submodule qbittorrent
added at
5abf45
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern allows both uppercase and lowercase hex characters, but the error handling doesn't normalize case before validation. While this is technically correct, consider documenting this behavior or normalizing to lowercase consistently throughout the codebase for consistency with how keys are generated and stored elsewhere.