Skip to content

Commit 17e86c6

Browse files
committedNov 29, 2024··
Merge torrust#1112: Extract duplicate code into new package: bittorrent-http-protocol
2bc44af test: add test for percent_encode_byte_array (Jose Celano) a62ae82 fix: cargo machete warning (Jose Celano) 39716a8 ci: fix testing workflow. Run doc tests for all packages (Jose Celano) c61cc9a fix: doc tests (Jose Celano) 555d5b8 fix: [torrust#1097] by extracting duplicate module (Jose Celano) Pull request description: For now, it only contains percent encoding functions. This removes duplicate code and fixes the problem of slow doc tests. On my machine, it takes 40 seconds to run all doc tests with one job. ```console time cargo test --doc --workspace --jobs=1 real 0m40.443s user 6m6.863s sys 0m22.609s ``` I have also fixed the `testing` workflow, it was using `cargo test --doc` to run doc-tests without including doc-test is workspace packages. ACKs for top commit: josecelano: ACK 2bc44af Tree-SHA512: 82b6cfb3ac40ffce437717d800388ab3f4968dc0e73dbb25eae4160378f8280ec3569381d5b58f8d3884ad839b5be320f43e2e246b527932e72ca8572fa79397
2 parents e0245f0 + 2bc44af commit 17e86c6

File tree

16 files changed

+734
-144
lines changed

16 files changed

+734
-144
lines changed
 

‎.github/workflows/deployment.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
env:
5656
CARGO_REGISTRY_TOKEN: "${{ secrets.TORRUST_UPDATE_CARGO_REGISTRY_TOKEN }}"
5757
run: |
58+
cargo publish -p bittorrent-http-protocol
5859
cargo publish -p bittorrent-tracker-client
5960
cargo publish -p torrust-tracker
6061
cargo publish -p torrust-tracker-client

‎.github/workflows/testing.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ jobs:
140140

141141
- id: test-docs
142142
name: Run Documentation Tests
143-
run: cargo test --doc
143+
run: cargo test --doc --workspace
144144

145145
- id: test
146146
name: Run Unit Tests

‎Cargo.lock

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ axum = { version = "0", features = ["macros"] }
3636
axum-client-ip = "0"
3737
axum-extra = { version = "0", features = ["query"] }
3838
axum-server = { version = "0", features = ["tls-rustls-no-provider"] }
39+
bittorrent-http-protocol = { version = "3.0.0-develop", path = "packages/http-protocol" }
3940
bittorrent-primitives = "0.1.0"
4041
bittorrent-tracker-client = { version = "3.0.0-develop", path = "packages/tracker-client" }
4142
blowfish = "0"

‎contrib/bencode/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
//! Decoding bencoded data:
66
//!
77
//! ```rust
8-
//! extern crate bencode;
8+
//! extern crate torrust_tracker_contrib_bencode;
99
//!
10-
//! use bencode::{BencodeRef, BRefAccess, BDecodeOpt};
10+
//! use torrust_tracker_contrib_bencode::{BencodeRef, BRefAccess, BDecodeOpt};
1111
//!
1212
//! fn main() {
1313
//! let data = b"d12:lucky_numberi7ee"; // cspell:disable-line
@@ -22,7 +22,7 @@
2222
//!
2323
//! ```rust
2424
//! #[macro_use]
25-
//! extern crate bencode;
25+
//! extern crate torrust_tracker_contrib_bencode;
2626
//!
2727
//! fn main() {
2828
//! let message = (ben_map!{

‎packages/http-protocol/Cargo.toml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
description = "A library with the primitive types and functions for the BitTorrent HTTP tracker protocol."
3+
keywords = ["api", "library", "primitives"]
4+
name = "bittorrent-http-protocol"
5+
readme = "README.md"
6+
7+
authors.workspace = true
8+
documentation.workspace = true
9+
edition.workspace = true
10+
homepage.workspace = true
11+
license.workspace = true
12+
publish.workspace = true
13+
repository.workspace = true
14+
rust-version.workspace = true
15+
version.workspace = true
16+
17+
[dependencies]
18+
aquatic_udp_protocol = "0"
19+
bittorrent-primitives = "0.1.0"
20+
percent-encoding = "2"
21+
torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" }

‎packages/http-protocol/LICENSE

+661
Large diffs are not rendered by default.

‎packages/http-protocol/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# BitTorrent HTTP Tracker Protocol
2+
3+
A library with the primitive types and functions used by BitTorrent HTTP trackers.
4+
5+
## Documentation
6+
7+
[Crate documentation](https://docs.rs/bittorrent-http-protocol).
8+
9+
## License
10+
11+
The project is licensed under the terms of the [GNU AFFERO GENERAL PUBLIC LICENSE](./LICENSE).

‎packages/http-protocol/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//! Primitive types and function for `BitTorrent` HTTP trackers.
2+
pub mod percent_encoding;

‎src/servers/http/percent_encoding.rs ‎packages/http-protocol/src/percent_encoding.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use torrust_tracker_primitives::peer;
2727
///
2828
/// ```rust
2929
/// use std::str::FromStr;
30-
/// use torrust_tracker::servers::http::percent_encoding::percent_decode_info_hash;
30+
/// use bittorrent_http_protocol::percent_encoding::percent_decode_info_hash;
3131
/// use bittorrent_primitives::info_hash::InfoHash;
3232
/// use torrust_tracker_primitives::peer;
3333
///
@@ -60,7 +60,7 @@ pub fn percent_decode_info_hash(raw_info_hash: &str) -> Result<InfoHash, info_ha
6060
/// use std::str::FromStr;
6161
///
6262
/// use aquatic_udp_protocol::PeerId;
63-
/// use torrust_tracker::servers::http::percent_encoding::percent_decode_peer_id;
63+
/// use bittorrent_http_protocol::percent_encoding::percent_decode_peer_id;
6464
/// use bittorrent_primitives::info_hash::InfoHash;
6565
///
6666
/// let encoded_peer_id = "%2DqB00000000000000000";
@@ -85,7 +85,7 @@ mod tests {
8585
use aquatic_udp_protocol::PeerId;
8686
use bittorrent_primitives::info_hash::InfoHash;
8787

88-
use crate::servers::http::percent_encoding::{percent_decode_info_hash, percent_decode_peer_id};
88+
use crate::percent_encoding::{percent_decode_info_hash, percent_decode_peer_id};
8989

9090
#[test]
9191
fn it_should_decode_a_percent_encoded_info_hash() {

‎packages/located-error/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//! let b: LocatedError<TestError> = Located(e).into();
2424
//! let l = get_caller_location();
2525
//!
26-
//! assert!(b.to_string().contains("Test, src/lib.rs"));
26+
//! assert!(b.to_string().contains("src/lib.rs"));
2727
//! ```
2828
//!
2929
//! # Credits

‎packages/tracker-client/src/http/mod.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pub mod client;
2-
pub mod url_encoding;
32

43
use percent_encoding::NON_ALPHANUMERIC;
54

@@ -25,3 +24,19 @@ impl InfoHash {
2524
self.0
2625
}
2726
}
27+
28+
#[cfg(test)]
29+
mod tests {
30+
use crate::http::percent_encode_byte_array;
31+
32+
#[test]
33+
fn it_should_encode_a_20_byte_array() {
34+
assert_eq!(
35+
percent_encode_byte_array(&[
36+
0x3b, 0x24, 0x55, 0x04, 0xcf, 0x5f, 0x11, 0xbb, 0xdb, 0xe1, 0x20, 0x1c, 0xea, 0x6a, 0x6b, 0xf4, 0x5a, 0xee, 0x1b,
37+
0xc0,
38+
]),
39+
"%3B%24U%04%CF%5F%11%BB%DB%E1%20%1C%EAjk%F4Z%EE%1B%C0"
40+
);
41+
}
42+
}

‎packages/tracker-client/src/http/url_encoding.rs

-132
This file was deleted.

‎src/servers/http/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@
305305
//! - [Bencode to Json Online converter](https://chocobo1.github.io/bencode_online).
306306
use serde::{Deserialize, Serialize};
307307

308-
pub mod percent_encoding;
309308
pub mod server;
310309
pub mod v1;
311310

‎src/servers/http/v1/requests/announce.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use std::panic::Location;
66
use std::str::FromStr;
77

88
use aquatic_udp_protocol::{NumberOfBytes, PeerId};
9+
use bittorrent_http_protocol::percent_encoding::{percent_decode_info_hash, percent_decode_peer_id};
910
use bittorrent_primitives::info_hash::{self, InfoHash};
1011
use thiserror::Error;
1112
use torrust_tracker_located_error::{Located, LocatedError};
1213
use torrust_tracker_primitives::peer;
1314

14-
use crate::servers::http::percent_encoding::{percent_decode_info_hash, percent_decode_peer_id};
1515
use crate::servers::http::v1::query::{ParseQueryError, Query};
1616
use crate::servers::http::v1::responses;
1717

‎src/servers/http/v1/requests/scrape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
//! Data structures and logic for parsing the `scrape` request.
44
use std::panic::Location;
55

6+
use bittorrent_http_protocol::percent_encoding::percent_decode_info_hash;
67
use bittorrent_primitives::info_hash::{self, InfoHash};
78
use thiserror::Error;
89
use torrust_tracker_located_error::{Located, LocatedError};
910

10-
use crate::servers::http::percent_encoding::percent_decode_info_hash;
1111
use crate::servers::http::v1::query::Query;
1212
use crate::servers::http::v1::responses;
1313

0 commit comments

Comments
 (0)
Please sign in to comment.