-
Notifications
You must be signed in to change notification settings - Fork 103
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
Draft: base protocol with merkle trees and new hash algorithms #59
Merged
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
39670fb
First Draft: base protocol with merkle trees and new hash algorithms
the8472 6c7b87a
dictionary file trees, zero-paddeding when hashing
the8472 a56c940
reject message, replace digest function field with version indicator
the8472 e25fa15
add metadata exchange for piece layers
the8472 8628126
describe legacy/v2 hybrid format
the8472 57f4f26
omit hashes which can be reconstructed
the8472 f7ef8ee
v2 and hybrid magnets
the8472 e7d2f7c
choose hash algo, change piece layers to a dictionary
the8472 5790658
terrible typo
the8472 33077e2
add hash request messages to the core protocol
131b288
updates based on review feedback
cd1574a
Merge pull request #2 from bittorrent/hash-transfer
the8472 cfd7cd5
fix missing markup
the8472 48dfdcb
changes from reviews
the8472 b0634bc
Document client version field in DHT messages
369b2bc
add note about possible absence of the version key
6034458
Merge pull request #61 from bittorrent/dht-version-string
ssiloti 940d1c6
regenerate html
a160be6
byte[] vs. String vs. path component clarifications
the8472 42501e5
minor fixes
the8472 5afecdc
relax path name restrictions
the8472 4c3f888
typo
the8472 4bdc9f6
add v2 torrent creation script
6c2e56d
go back to using the file length to filter for 'piece layers'
ssiloti 655e385
include padding for the last file of a multi-file torrent
ssiloti 96de012
normalize path before setting name
ssiloti 055446e
set pad attribute on pad files
ssiloti 7baf1c9
walk the directory tree in lexicographic order
ssiloti 96aa178
Merge pull request #3 from bittorrent/new-hash-algos
the8472 47ed76d
add infohash output
the8472 e14a7a6
link torrent creator script
the8472 6a0b817
move v2 spec to new bep
the8472 bd77a55
restore bep 0003
the8472 9a34522
change status to draft
the8472 9049d0c
from review: simplify hex output
the8472 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 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 |
---|---|---|
|
@@ -9,8 +9,10 @@ | |
import string | ||
import itertools as it | ||
import os | ||
import binascii | ||
from hashlib import sha1, sha256 | ||
|
||
|
||
BLOCK_SIZE = 2**14 # 16KB | ||
|
||
def encode(obj): | ||
|
@@ -166,6 +168,7 @@ def __init__(self, path, piece_length): | |
self.piece_layers = [] # v2 piece hashes | ||
self.pieces = [] # v1 piece hashes | ||
self.files = [] | ||
self.info = [] | ||
|
||
self.base_path = path | ||
|
||
|
@@ -229,8 +232,15 @@ def create(self, tracker, hybrid=True): | |
info[b'pieces'] = self.pieces | ||
try: info[b'files'] = self.files | ||
except AttributeError: info[b'length'] = self.length | ||
self.info = info | ||
return {b'announce': tracker, b'info': info, b'piece layers': {f.root: f.piecesv2 for f in self.piece_layers if f.length > self.piece_length}} | ||
|
||
|
||
def info_hash_v2(self): | ||
return binascii.hexlify(sha256(encode(self.info)).digest()).decode('ascii') | ||
|
||
def info_hash_v1(self): | ||
return binascii.hexlify(sha1(encode(self.info)).digest()).decode('ascii') | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
@@ -243,3 +253,7 @@ def create(self, tracker, hybrid=True): | |
args = parser.parse_args() | ||
t = Torrent(args.path, args.piece_length) | ||
open(t.name + '.torrent', 'wb').write(encode(t.create(args.tracker, args.v2_only))) | ||
if args.v2_only: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There needs to be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait no it's correct as it is. Clearly the naming here is not the best. |
||
print("v1 infohash {0:s}".format(t.info_hash_v1())) | ||
print("v2 infohash {0:s}".format(t.info_hash_v2())) | ||
|
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.
there's no need to use binascii here, just call
hexdigest()
instead ofdigest()