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

add v2 torrent creation script #3

Merged
merged 6 commits into from
May 14, 2017

Conversation

ssiloti
Copy link

@ssiloti ssiloti commented May 12, 2017

No description provided.

@the8472
Copy link
Owner

the8472 commented May 13, 2017

For the hybrid format in multi-file mode it would make sense to add another padding file at the end so. This allows torrents to be assembled from smaller torrents without rehashing. It's mostly relevant for torrent feeds.

@the8472
Copy link
Owner

the8472 commented May 13, 2017

$ ls -lR test
test:
total 196
-rw-r--r-- 1 the8472 the8472 196605 May 13 06:20 a
-rw-r--r-- 1 the8472 the8472   1024 May 13 06:20 b
drwxr-xr-x 1 the8472 the8472      4 May 13 06:50 dir

test/dir:
total 64
-rw-r--r-- 1 the8472 the8472     0 May 13 06:50 c
-rw-r--r-- 1 the8472 the8472 65536 May 13 06:51 d

$ python bep_0052_torrent_creator.py test
Traceback (most recent call last):
  File "bep_0052_torrent_creator.py", line 239, in <module>
    open(t.name + '.torrent', 'wb').write(encode(t.create(args.tracker, args.v2_only)))
  File "bep_0052_torrent_creator.py", line 226, in create
    return {b'announce': tracker, b'info': info, b'piece layers': {f.root: f.piecesv2 for f in self.piece_layers if hasattr(f, 'piecesv2')}}
  File "bep_0052_torrent_creator.py", line 226, in <dictcomp>
    return {b'announce': tracker, b'info': info, b'piece layers': {f.root: f.piecesv2 for f in self.piece_layers if hasattr(f, 'piecesv2')}}
AttributeError: 'FileHasher' object has no attribute 'root'

@the8472
Copy link
Owner

the8472 commented May 13, 2017

Directory listings in filesystems are not guaranteed to be sorted (it's ls that sorts)

$ ls -AUlR test
test:
total 196
-rw-r--r-- 1 the8472 the8472 196605 May 13 06:20 a
-rw-r--r-- 1 the8472 the8472   1024 May 13 06:20 b
drwxr-xr-x 1 the8472 the8472      8 May 13 20:01 dir

test/dir:
total 64
-rw-r--r-- 1 the8472 the8472     0 May 13 06:50 c
-rw-r--r-- 1 the8472 the8472 65536 May 13 06:51 d
-rw-r--r-- 1 the8472 the8472     0 May 13 20:01 01

This results in the v1 list to be in encounter order while the file tree is sorted per bencoding. Which leads to an invalid hybrid torrent.

filesld6:lengthi196605e4:pathl1:aeed6:lengthi3e4:pathl4:.pad1:3eed6:lengthi1024e4:pathl1:beed6:lengthi64512e4:pathl4:.pad5:64512eed6:lengthi0e4:pathl3:dir1:ceed6:lengthi65536e4:pathl3:dir1:deed6:lengthi0e4:pathl3:dir2:01eee

Also, the last v1 file still does not seem to be padded to a full piece size.

@ssiloti
Copy link
Author

ssiloti commented May 13, 2017

In that case the last file is empty. Why would padding be needed for an empty file?

@the8472
Copy link
Owner

the8472 commented May 13, 2017

The one before it is not empty and yet not padded.

@ssiloti
Copy link
Author

ssiloti commented May 13, 2017

The default piece size is 64KB, so assuming you didn't change it that file doesn't need to be padded.

@the8472
Copy link
Owner

the8472 commented May 13, 2017

Oh duh. Off by one. I intended to make it 1 longer than the piece size.

@the8472
Copy link
Owner

the8472 commented May 13, 2017

Although the attr: p is missing from the padding files.

@the8472
Copy link
Owner

the8472 commented May 13, 2017

another small issue

  • python bep_0052_torrent_creator.py test/ results in a 0-length name
  • python bep_0052_torrent_creator.py test works fine

@the8472 the8472 merged commit 96aa178 into the8472:new-hash-algos May 14, 2017
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.

3 participants