Skip to content
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 35 commits into from
May 15, 2017
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 Feb 26, 2017
6c7b87a
dictionary file trees, zero-paddeding when hashing
the8472 Feb 27, 2017
a56c940
reject message, replace digest function field with version indicator
the8472 Feb 28, 2017
e25fa15
add metadata exchange for piece layers
the8472 Mar 1, 2017
8628126
describe legacy/v2 hybrid format
the8472 Mar 1, 2017
57f4f26
omit hashes which can be reconstructed
the8472 Mar 1, 2017
f7ef8ee
v2 and hybrid magnets
the8472 Mar 2, 2017
e7d2f7c
choose hash algo, change piece layers to a dictionary
the8472 Mar 2, 2017
5790658
terrible typo
the8472 Mar 2, 2017
33077e2
add hash request messages to the core protocol
Mar 23, 2017
131b288
updates based on review feedback
Mar 24, 2017
cd1574a
Merge pull request #2 from bittorrent/hash-transfer
the8472 Mar 24, 2017
cfd7cd5
fix missing markup
the8472 Mar 26, 2017
48dfdcb
changes from reviews
the8472 Mar 26, 2017
b0634bc
Document client version field in DHT messages
Apr 28, 2017
369b2bc
add note about possible absence of the version key
May 1, 2017
6034458
Merge pull request #61 from bittorrent/dht-version-string
ssiloti May 2, 2017
940d1c6
regenerate html
May 2, 2017
a160be6
byte[] vs. String vs. path component clarifications
the8472 May 8, 2017
42501e5
minor fixes
the8472 May 9, 2017
5afecdc
relax path name restrictions
the8472 May 9, 2017
4c3f888
typo
the8472 May 9, 2017
4bdc9f6
add v2 torrent creation script
May 12, 2017
6c2e56d
go back to using the file length to filter for 'piece layers'
ssiloti May 13, 2017
655e385
include padding for the last file of a multi-file torrent
ssiloti May 13, 2017
96de012
normalize path before setting name
ssiloti May 13, 2017
055446e
set pad attribute on pad files
ssiloti May 13, 2017
7baf1c9
walk the directory tree in lexicographic order
ssiloti May 13, 2017
96aa178
Merge pull request #3 from bittorrent/new-hash-algos
the8472 May 14, 2017
47ed76d
add infohash output
the8472 May 14, 2017
e14a7a6
link torrent creator script
the8472 May 14, 2017
6a0b817
move v2 spec to new bep
the8472 May 14, 2017
bd77a55
restore bep 0003
the8472 May 14, 2017
9a34522
change status to draft
the8472 May 14, 2017
9049d0c
from review: simplify hex output
the8472 May 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion beps/bep_0052_torrent_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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')
Copy link
Contributor

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 of digest()


def info_hash_v1(self):
return binascii.hexlify(sha1(encode(self.info)).digest()).decode('ascii')


if __name__ == "__main__":
import argparse
Expand All @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

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

There needs to be a not here.

Copy link
Contributor

Choose a reason for hiding this comment

The 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()))