Skip to content

Commit 25ecdce

Browse files
committed
Merge #837: Bump aquatic_udp_protocol from 0.8.0 to 0.9.0
801d913 chore(deps): bump aquatic_udp_protocol from 0.8.0 to 0.9.0 (Jose Celano) Pull request description: Bump `aquatic_udp_protocol` from `0.8.0` to `0.9.0`. There are breaking changes. ACKs for top commit: josecelano: ACK 801d913 Tree-SHA512: 5ae9daacf52176850f24cb2421be8795fd8abe8cb7503a7a0f6be3c3ed081a8f384230d3ce5a3a0122508bfa3d8c5ff94c4763a67d99b3191fefdd0bc8b4c278
2 parents 2719d5e + 801d913 commit 25ecdce

File tree

14 files changed

+225
-136
lines changed

14 files changed

+225
-136
lines changed

Cargo.lock

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

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ version = "3.0.0-alpha.12-develop"
3131

3232
[dependencies]
3333
anyhow = "1"
34-
aquatic_udp_protocol = "0.8"
34+
aquatic_udp_protocol = "0"
3535
async-trait = "0"
3636
axum = { version = "0", features = ["macros"] }
3737
axum-client-ip = "0"
@@ -76,6 +76,7 @@ trace = "0"
7676
tracing = "0"
7777
url = "2"
7878
uuid = { version = "1", features = ["v4"] }
79+
zerocopy = "0.7.33"
7980

8081
[package.metadata.cargo-machete]
8182
ignored = ["serde_bytes", "crossbeam-skiplist", "dashmap", "parking_lot"]

cSpell.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@
170170
"Xtorrent",
171171
"Xunlei",
172172
"xxxxxxxxxxxxxxxxxxxxd",
173-
"yyyyyyyyyyyyyyyyyyyyd"
173+
"yyyyyyyyyyyyyyyyyyyyd",
174+
"zerocopy"
174175
],
175176
"enableFiletypes": [
176177
"dockerfile",

src/console/clients/checker/checks/udp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub async fn run(udp_trackers: &Vec<SocketAddr>, check_results: &mut Vec<CheckRe
2727

2828
debug!("UDP tracker: {:?}", udp_tracker);
2929

30-
let transaction_id = TransactionId(RANDOM_TRANSACTION_ID);
30+
let transaction_id = TransactionId::new(RANDOM_TRANSACTION_ID);
3131

3232
let mut client = checker::Client::default();
3333

@@ -58,7 +58,7 @@ pub async fn run(udp_trackers: &Vec<SocketAddr>, check_results: &mut Vec<CheckRe
5858
debug!("Send announce request");
5959

6060
if (client
61-
.send_announce_request(connection_id, transaction_id, info_hash, Port(bound_to.port()))
61+
.send_announce_request(connection_id, transaction_id, info_hash, Port(bound_to.port().into()))
6262
.await)
6363
.is_ok()
6464
{

src/console/clients/udp/app.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn setup_logging(level: LevelFilter) {
142142
}
143143

144144
async fn handle_announce(tracker_socket_addr: &SocketAddr, info_hash: &TorrustInfoHash) -> anyhow::Result<Response> {
145-
let transaction_id = TransactionId(RANDOM_TRANSACTION_ID);
145+
let transaction_id = TransactionId::new(RANDOM_TRANSACTION_ID);
146146

147147
let mut client = checker::Client::default();
148148

@@ -151,12 +151,12 @@ async fn handle_announce(tracker_socket_addr: &SocketAddr, info_hash: &TorrustIn
151151
let connection_id = client.send_connection_request(transaction_id).await?;
152152

153153
client
154-
.send_announce_request(connection_id, transaction_id, *info_hash, Port(bound_to.port()))
154+
.send_announce_request(connection_id, transaction_id, *info_hash, Port(bound_to.port().into()))
155155
.await
156156
}
157157

158158
async fn handle_scrape(tracker_socket_addr: &SocketAddr, info_hashes: &[TorrustInfoHash]) -> anyhow::Result<Response> {
159-
let transaction_id = TransactionId(RANDOM_TRANSACTION_ID);
159+
let transaction_id = TransactionId::new(RANDOM_TRANSACTION_ID);
160160

161161
let mut client = checker::Client::default();
162162

src/console/clients/udp/checker.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::net::{Ipv4Addr, SocketAddr};
33
use anyhow::Context;
44
use aquatic_udp_protocol::common::InfoHash;
55
use aquatic_udp_protocol::{
6-
AnnounceEvent, AnnounceRequest, ConnectRequest, ConnectionId, NumberOfBytes, NumberOfPeers, PeerId, PeerKey, Port, Response,
7-
ScrapeRequest, TransactionId,
6+
AnnounceActionPlaceholder, AnnounceEvent, AnnounceRequest, ConnectRequest, ConnectionId, NumberOfBytes, NumberOfPeers,
7+
PeerId, PeerKey, Port, Response, ScrapeRequest, TransactionId,
88
};
99
use log::debug;
1010
use thiserror::Error;
@@ -148,16 +148,17 @@ impl Client {
148148

149149
let announce_request = AnnounceRequest {
150150
connection_id,
151+
action_placeholder: AnnounceActionPlaceholder::default(),
151152
transaction_id,
152153
info_hash: InfoHash(info_hash.bytes()),
153154
peer_id: PeerId(*b"-qB00000000000000001"),
154-
bytes_downloaded: NumberOfBytes(0i64),
155-
bytes_uploaded: NumberOfBytes(0i64),
156-
bytes_left: NumberOfBytes(0i64),
157-
event: AnnounceEvent::Started,
158-
ip_address: Some(Ipv4Addr::new(0, 0, 0, 0)),
159-
key: PeerKey(0u32),
160-
peers_wanted: NumberOfPeers(1i32),
155+
bytes_downloaded: NumberOfBytes(0i64.into()),
156+
bytes_uploaded: NumberOfBytes(0i64.into()),
157+
bytes_left: NumberOfBytes(0i64.into()),
158+
event: AnnounceEvent::Started.into(),
159+
ip_address: Ipv4Addr::new(0, 0, 0, 0).into(),
160+
key: PeerKey::new(0i32),
161+
peers_wanted: NumberOfPeers(1i32.into()),
161162
port: client_port,
162163
};
163164

src/console/clients/udp/responses.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Aquatic responses are not serializable. These are the serializable wrappers.
22
use std::net::{Ipv4Addr, Ipv6Addr};
33

4-
use aquatic_udp_protocol::{AnnounceResponse, ScrapeResponse};
4+
use aquatic_udp_protocol::{AnnounceResponse, Ipv4AddrBytes, Ipv6AddrBytes, ScrapeResponse};
55
use serde::Serialize;
66

77
#[derive(Serialize)]
@@ -13,33 +13,33 @@ pub struct AnnounceResponseDto {
1313
peers: Vec<String>,
1414
}
1515

16-
impl From<AnnounceResponse<Ipv4Addr>> for AnnounceResponseDto {
17-
fn from(announce: AnnounceResponse<Ipv4Addr>) -> Self {
16+
impl From<AnnounceResponse<Ipv4AddrBytes>> for AnnounceResponseDto {
17+
fn from(announce: AnnounceResponse<Ipv4AddrBytes>) -> Self {
1818
Self {
19-
transaction_id: announce.transaction_id.0,
20-
announce_interval: announce.announce_interval.0,
21-
leechers: announce.leechers.0,
22-
seeders: announce.seeders.0,
19+
transaction_id: announce.fixed.transaction_id.0.into(),
20+
announce_interval: announce.fixed.announce_interval.0.into(),
21+
leechers: announce.fixed.leechers.0.into(),
22+
seeders: announce.fixed.seeders.0.into(),
2323
peers: announce
2424
.peers
2525
.iter()
26-
.map(|peer| format!("{}:{}", peer.ip_address, peer.port.0))
26+
.map(|peer| format!("{}:{}", Ipv4Addr::from(peer.ip_address), peer.port.0))
2727
.collect::<Vec<_>>(),
2828
}
2929
}
3030
}
3131

32-
impl From<AnnounceResponse<Ipv6Addr>> for AnnounceResponseDto {
33-
fn from(announce: AnnounceResponse<Ipv6Addr>) -> Self {
32+
impl From<AnnounceResponse<Ipv6AddrBytes>> for AnnounceResponseDto {
33+
fn from(announce: AnnounceResponse<Ipv6AddrBytes>) -> Self {
3434
Self {
35-
transaction_id: announce.transaction_id.0,
36-
announce_interval: announce.announce_interval.0,
37-
leechers: announce.leechers.0,
38-
seeders: announce.seeders.0,
35+
transaction_id: announce.fixed.transaction_id.0.into(),
36+
announce_interval: announce.fixed.announce_interval.0.into(),
37+
leechers: announce.fixed.leechers.0.into(),
38+
seeders: announce.fixed.seeders.0.into(),
3939
peers: announce
4040
.peers
4141
.iter()
42-
.map(|peer| format!("{}:{}", peer.ip_address, peer.port.0))
42+
.map(|peer| format!("{}:{}", Ipv6Addr::from(peer.ip_address), peer.port.0))
4343
.collect::<Vec<_>>(),
4444
}
4545
}
@@ -54,14 +54,14 @@ pub struct ScrapeResponseDto {
5454
impl From<ScrapeResponse> for ScrapeResponseDto {
5555
fn from(scrape: ScrapeResponse) -> Self {
5656
Self {
57-
transaction_id: scrape.transaction_id.0,
57+
transaction_id: scrape.transaction_id.0.into(),
5858
torrent_stats: scrape
5959
.torrent_stats
6060
.iter()
6161
.map(|torrent_scrape_statistics| TorrentStats {
62-
seeders: torrent_scrape_statistics.seeders.0,
63-
completed: torrent_scrape_statistics.completed.0,
64-
leechers: torrent_scrape_statistics.leechers.0,
62+
seeders: torrent_scrape_statistics.seeders.0.into(),
63+
completed: torrent_scrape_statistics.completed.0.into(),
64+
leechers: torrent_scrape_statistics.leechers.0.into(),
6565
})
6666
.collect::<Vec<_>>(),
6767
}

src/servers/udp/connection_cookie.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ use std::panic::Location;
7171

7272
use aquatic_udp_protocol::ConnectionId;
7373
use torrust_tracker_clock::time_extent::{Extent, TimeExtent};
74+
use zerocopy::network_endian::I64;
75+
use zerocopy::AsBytes;
7476

7577
use super::error::Error;
7678

@@ -83,13 +85,15 @@ pub const COOKIE_LIFETIME: TimeExtent = TimeExtent::from_sec(2, &60);
8385
/// Converts a connection ID into a connection cookie.
8486
#[must_use]
8587
pub fn from_connection_id(connection_id: &ConnectionId) -> Cookie {
86-
connection_id.0.to_le_bytes()
88+
let mut cookie = [0u8; 8];
89+
connection_id.write_to(&mut cookie);
90+
cookie
8791
}
8892

8993
/// Converts a connection cookie into a connection ID.
9094
#[must_use]
9195
pub fn into_connection_id(connection_cookie: &Cookie) -> ConnectionId {
92-
ConnectionId(i64::from_le_bytes(*connection_cookie))
96+
ConnectionId(I64::new(i64::from_be_bytes(*connection_cookie)))
9397
}
9498

9599
/// Generates a new connection cookie.

0 commit comments

Comments
 (0)