Add RawValue to save original bencodes bytes without deserializing.#10
Open
canoriz wants to merge 1 commit intobluk:trunkfrom
Open
Add RawValue to save original bencodes bytes without deserializing.#10canoriz wants to merge 1 commit intobluk:trunkfrom
canoriz wants to merge 1 commit intobluk:trunkfrom
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In BitTorrent specification, the
info_hashis calculated from sha1 of bencodedInfostruct. The specification explicitly says: info_hash should be calculated directly from the original bencode, not from the decoded then encoded bencode.For a long time, I calculated
info_hashfrom the decoded then encoded bencode. But recently I encounter a torrent file whoseinfofield has aprivate: 0field, which I don't support now. This resulted to a wronginfo_hash.I understand I can add a
private: Option<u8>field to myInfostruct, and set someserdeattribute likeskip_if_none, this will work perfectly. But I would like to add aRawValuetype, which have some advantages.Advantages
RawValueto calculate correctinfo_hash, no matter what unsupported fields a torrent file has.RawValueout directly, no more encoding fromInfostruct every time. Though it's possible withoutRawValue: we can always keepInfoand bencodedInfoin the same time.Implementation details
I mostly followed the approach of
RawValueinserde_jsonwith some small differences:serde_jsonhas two versions ofRawValue: borrowed and owned, represented by&'a RawValueandBox<RawValue>. I only implemented the owned version, in simpleRawValue, I don't see many use cases of borrowed version ofRawValuein BitTorrent uses.However, we might (I'm not sure by now) have break change if we want to add borrowed version of
RawValuein the future, if we use this only one owned version now.