-
Notifications
You must be signed in to change notification settings - Fork 20
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
User forked version of serde-bencode
#316
User forked version of serde-bencode
#316
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #316 +/- ##
===========================================
+ Coverage 42.45% 42.47% +0.01%
===========================================
Files 79 79
Lines 4803 4801 -2
===========================================
Hits 2039 2039
+ Misses 2764 2762 -2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Finally, I've found the problem. The deserialisation works with the original But the struct can be changed to avoid using tuple structs. #[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct Torrent {
pub info: TorrentInfoDictionary, //
#[serde(default)]
pub announce: Option<String>,
#[serde(default)]
pub nodes: Option<Vec<TorrentNode>>, // <- change this to Option<Vec<(String, i64)>>,
#[serde(default)]
pub encoding: Option<String>,
#[serde(default)]
pub httpseeds: Option<Vec<String>>,
#[serde(default)]
#[serde(rename = "announce-list")]
pub announce_list: Option<Vec<Vec<String>>>,
#[serde(default)]
#[serde(rename = "creation date")]
pub creation_date: Option<i64>,
#[serde(default)]
pub comment: Option<String>,
#[serde(default)]
#[serde(rename = "created by")]
pub created_by: Option<String>,
} After changing that, you can rerun this command: x$ cargo run --bin parse_torrent ./tests/fixtures/torrents/not-working-with-two-nodes.torrent
Compiling torrust-index-backend v2.0.0-alpha.3 (/home/josecelano/Documents/git/committer/me/github/torrust/torrust-index)
Finished dev [unoptimized + debuginfo] target(s) in 6.01s
Running `target/debug/parse_torrent ./tests/fixtures/torrents/not-working-with-two-nodes.torrent`
Reading the torrent file ...
Decoding torrent with standard serde implementation ...
Parsed torrent:
Torrent {
info: TorrentInfoDictionary {
name: "minimal.txt",
pieces: Some(
[
48,
154,
132,
81,
74,
241,
9,
208,
140,
52,
66,
17,
38,
103,
127,
132,
179,
35,
77,
120,
],
),
piece_length: 16384,
md5sum: None,
length: Some(
8,
),
files: None,
private: None,
path: None,
root_hash: None,
source: None,
},
announce: None,
nodes: Some(
[
(
"188.163.121.224",
56711,
),
(
"162.250.131.26",
13386,
),
],
),
encoding: None,
httpseeds: None,
announce_list: None,
creation_date: None,
comment: None,
created_by: None,
} and you'll see the two nodes. I'm going to keep the fork because:
|
It works with the original @madadam was fixing that problem, but a new version was not published after the fixing. See the latest commits https://github.com/toby/serde-bencode/commits/master That's why it's working with the fork (latest commit) because it includes those fixes. I will continue working on the fork and publish a new version. After that we can use that version on this PR. |
I've published a new version ( |
There was a problem with list (nodes) containing other list (tuples) with different value types. ```json { "info": { "length": 8, "name": "minimal.txt", "piece length": 16384, "pieces": "<hex>30 9A 84 51 4A F1 09 D0 8C 34 42 11 26 67 7F 84 B3 23 4D 78</hex>" }, "nodes": [ [ "188.163.121.224", 56711 ], [ "162.250.131.26", 13386 ] ] } ```
c750cbb
to
3550c44
Compare
It's fixed with $ cargo run --bin parse_torrent ./tests/fixtures/torrents/not-working-with-two-nodes.torrent
Compiling torrust-index v3.0.0-alpha.3-develop (/home/josecelano/Documents/git/committer/me/github/torrust/torrust-index)
Finished dev [unoptimized + debuginfo] target(s) in 2.61s
Running `target/debug/parse_torrent ./tests/fixtures/torrents/not-working-with-two-nodes.torrent`
Reading the torrent file ...
Decoding torrent with standard serde implementation ...
Parsed torrent:
Torrent {
info: TorrentInfoDictionary {
name: "minimal.txt",
pieces: Some(
[
48,
154,
132,
81,
74,
241,
9,
208,
140,
52,
66,
17,
38,
103,
127,
132,
179,
35,
77,
120,
],
),
piece_length: 16384,
md5sum: None,
length: Some(
8,
),
files: None,
private: None,
path: None,
root_hash: None,
source: None,
},
announce: None,
nodes: Some(
[
(
"188.163.121.224",
56711,
),
(
"162.250.131.26",
13386,
),
],
),
encoding: None,
httpseeds: None,
announce_list: None,
creation_date: None,
comment: None,
created_by: None,
} |
ACK 3550c44 |
Using our crate
torrust-serde-bencode
instead of the upstream repo fixes the problem with some torrent deserializations described in this issue.There was a problem with lists (field
nodes
in the torrent) containing other lists (tuples) with different value types.I have been trying to reproduce the bug in our fork here, but it works. I've added a test using the same torrent file that does not work here.
If you run:
cargo run --bin parse_torrent ./tests/fixtures/torrents/not-working-with-two-nodes.torrent
With the current
develop
branch, you'll see that it does NOT work. But It works using our fork.For this PR, I have changed the
cargo.toml
file to include the latest commit from the fork. And it works.Surprisingly, it also works with:
Which was supposed to be the same code as:
So, no idea why it's working with an almost-exact copy of the original package.
Anyway,
serde_bencode
is not maintained. So I'll will:torrust-serde-bencode
.torrust-serde-bencode = "^0.2.4"
.