-
Notifications
You must be signed in to change notification settings - Fork 44
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
Review format for peer id in announce
response
#164
Labels
Easy
Good for Newcomers
Comments
It is fine for the "Display" function to return a Hex Encoded Array, however best to prefix the Hex String with a ´0x´, to make it explicit. |
josecelano
added a commit
to josecelano/torrust-tracker
that referenced
this issue
Mar 16, 2023
josecelano
added a commit
to josecelano/torrust-tracker
that referenced
this issue
Mar 16, 2023
josecelano
added a commit
that referenced
this issue
Mar 16, 2023
d51aae0 feat(tracker): [#164] add prefix 0x to peer ID hex string (Jose Celano) Pull request description: A peer id like this: ```rust peer::Id(*b"-qB00000000000000000") ``` has now this hex string representation: ```s 0x2d71423030303030303030303030303030303030 ``` with the `0x` prefix as suggested by @da2ce7 [here](#164 (comment)). Top commit has no ACKs. Tree-SHA512: 28d5522e14bf6e2159d7c0e3377a4b5d2242b45124d01403b50d32bf01e8c4e48eb8f86f1e1bbccea062ae2d48f7f2e3a9aa1c79dd9ae7593996c73e9dac3afa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A comment on this PR originated a discussion and finally this issue.
The HTTP tracker response (non compact response) for an announce request looks like this:
Bencoded bytes:
And the deserialized data into a Rust struct:
Before merging this PR the
peer_id
field was always empty. This was the commit were it was fixed.Not it returns the hex string of the peer id.
I think we should not convert the peer ID into an UTF8 string since bencode serialization allows any byte array for what they call a "string".
A byte string (a sequence of bytes, not necessarily characters) is encoded as :. The length is encoded in base 10, like integers, but must be non-negative (zero is allowed); the contents are just the bytes that make up the string. The string "spam" would be encoded as 4:spam. The specification does not deal with encoding of characters outside the ASCII set; to mitigate this, some BitTorrent applications explicitly communicate the encoding (most commonly UTF-8) in various non-standard ways. This is identical to how netstrings work, except that netstrings additionally append a comma suffix after the byte sequence.
Code
This is the function the build the announce response:
https://github.com/torrust/torrust-tracker/blob/develop/src/http/handlers.rs#L134-L169
It uses the
torrust_tracker::tracker::peer::to_string()
function.For a random 20-byte array you cannot always build a UTF8 string but you can always generate the hex representation. I decided to use the hex format for displaying the peer ID.
Review format in the announce reqeust
I think we should return the 20-byte array without converting it into a Rust String.
I have installed a different tracker and confirmed they are returning the 20-byte array:
#162 (comment)
Although for some reason they are returning an extra byte.
Review the
Display
trait implementationEven if we change what we return we could keep the
Display
trait as it is, returning the hex representation, but I do not know if that the right solution.Prons:
Cons:
Display
trait is intended for user-friendly output. It could lead to misinterpretation since the original value is a 20-byte array.Proposal:
I think most client uses a sequqence of ASCII bytes that can be represented as a String with this format
-qB00000000000000001
. That probably what a BitTorrent client will show or other interfaces to read byte sequences like:I think we could try to build a valid
String
and show the string if possible or the byte array or hex representation if we cannot convert the byte array into a validString
. But I do not like to display different formats. Maybe we could print the byte array and an extra value if that array is also a valid string, like this;What do you think @WarmBeer @da2ce7?
The text was updated successfully, but these errors were encountered: