Serialization no longer changes torrent hash. #253
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.
Repeatedly serializing and de-serializing no longer changes the torrent hash. This can create hard to debug issues when saving, loading or transmitting
TorrentMetadata
. "Let's save the torrent. It is saved. But where is it? (I cannot find it by the hash.)"There are two issues:
TorrentSerializer
places ainfo.private=1
only if the torrent is private otherwise it does not include that key. On the other hand, the newerMetadataBuilder
would always include that key and put either a0
or1
depending if it private or not.According to bep_0027 :
There is nothing about "private=0", so I assume we can omit it like in the serializer.
2. Single file torrents described in a multi-file format. This has a valid use case like giving the file a custom path like in
testMultiFileModeWithOneFile
.TorrentSerializer
treated a single file in multi-file mode a one in single-file mode. It did not have enough information to distinguish between the two case in scenario like intestMultiFileModeWithOneFileSameName
wherefileName == directoryName
. There is a difference betweenabc
andabc/abc
.Previously
getDirectoryName
could also return the file name in single-file mode. Then it should be simplygetName
.If you find any value in this pull request please tag it with
hacktoberfest-accepted
so I get credit towards the https://hacktoberfest.digitalocean.com/ event.