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

bep47 #526

Merged
merged 24 commits into from May 26, 2022
Merged

bep47 #526

merged 24 commits into from May 26, 2022

Conversation

jpmikkers
Copy link
Contributor

@jpmikkers jpmikkers commented Apr 12, 2022

Todo:

  • partition function tests
  • md5 hashing tests, should not be affected by padding
  • not sure what to do on torrent.cs line 429 for hybrid torrents..

@alanmcgovern
Copy link
Owner

I didn't review it in full - i'll do that tomorrow!

jpmikkers and others added 4 commits April 13, 2022 16:16
Fails because md5sum isn't present in the torrent
as the previous file in the torrent.

Ensures empty files at the end of a torrent are never the only file
in a piece.

Makes some tests green again.
@@ -116,6 +116,7 @@ public void LoadV2OnlyTorrent ()
Assert.AreEqual (InfoHash.FromHex ("caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e"), V2OnlyTorrent.InfoHashes.V2);
}

// TODO: fails with MonoTorrent.TorrentException : the 'piece layers' dictionary did not contain an entry for the file 'tbl-tint.mpg'
Copy link
Owner

Choose a reason for hiding this comment

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

I pushed a tiny change which fixes this. When zeroing out the padding for the last file in the torrent you had forgotten to copy over the RootHash property. This is what caused the file to not be found in the piece layers dictionary :)

@alanmcgovern
Copy link
Owner

Overall this looks pretty good! The extra validations are great.

I've had a busy week or so in work and am flying out for a 2 week holiday on Saturday. As such I'm not likely to get back to you with reviews until I'm back :(

I haven't had much time to thoroughly think through PaddingAwareReadAsyncForCreator , though from an initial review it feels like it could be the right approach.

Thanks for the work so far, and i'm looking forward to getting this merged after i'm back!


// padding of last torrent must be 0.
var last = files.Last ();
files[files.Count - 1] = new TorrentFile (last.Path, last.Length, last.StartPieceIndex, last.EndPieceIndex, last.OffsetInTorrent, last.PiecesRoot, TorrentFileAttributes.None, 0);
Copy link
Owner

Choose a reason for hiding this comment

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

I added last.PiecesRoot here to propagate that data!

@jpmikkers
Copy link
Contributor Author

Alan no worries on the review, have a great holiday!

@jpmikkers
Copy link
Contributor Author

I verified that md5 hashing is also broken on master, file.MD5 is never set in HashAllDataAsync().
See the test here: https://github.com/jpmikkers/monotorrent/commit/d2a8a8c297f9509bd4842acb5c9b69fd3e57cbd8

This will unblock bep 0047 from merging as md5 hashes are computed
correctly now.

The sha sums are the same before and after now!
@alanmcgovern
Copy link
Owner

@jpmikkers I fixed the MD5 issue last night - finally!

What's left to complete in this change? If it's pretty much done now I'll give it a final review and land any minor tweaks as needed before, or after, merging :)

@jpmikkers
Copy link
Contributor Author

jpmikkers commented May 23, 2022

I also had a small fix for the remaining // TODO: JMIK (the endindex rounding issue) but suddenly vs2022 doesn't let me push that commit, groan

Torrent.cs line 790 should probably be this, can you confirm?:
length > 0 ? totalPieces + (int) ((length - 1) / pieceLength) : totalPieces,

@alanmcgovern
Copy link
Owner

totalPieces + (int) ((length - 1) / pieceLength) : totalPieces

96fa486

You were right!

@jpmikkers jpmikkers changed the title Do not merge, preview of bep47 bep47 May 24, 2022
@@ -232,6 +234,11 @@ internal async Task<BEncodedDictionary> CreateAsync (string name, List<InputFile
info["name"] = (BEncodedString) name;
AddCommonStuff (torrent);

foreach (var file in files.Take (files.Count - 1)) {
file.Padding = (UsePadding && file.Length > 0) ? PieceLength - (file.Length % PieceLength) : 0;
Copy link
Owner

Choose a reason for hiding this comment

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

I just realised that this would add PieceLength padding if file.Length is an exact multiple of PieceLength.

I added a test and fixed the bug!

startOffsetInTorrent = i > 0 ? results[i - 1].OffsetInTorrent : 0;
// catch pathological case of too much padding
if (pieceEnd != pieceEndWithPadding) {
throw new ArgumentException ("A file in the torrent has more padding than needed.");
Copy link
Owner

Choose a reason for hiding this comment

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

This check was helpful as it triggered when I created the testcase to see what happened when file.Length == PieceLength :)

@alanmcgovern alanmcgovern merged commit c172228 into alanmcgovern:master May 26, 2022
@alanmcgovern
Copy link
Owner

I gave this a few rounds of checks and didn't find any more issues! Thanks for the great work! I'll let this continue baking as I (slowly) slipstream in the final bits for bep52 :D

Thanks for the patch!

@jpmikkers jpmikkers deleted the bep0047 branch May 27, 2022 10:43
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.

None yet

2 participants