1
- //! `Announce` response for the HTTP tracker [`announce`](crate::servers::http ::v1::requests::announce::Announce) request.
1
+ //! `Announce` response for the HTTP tracker [`announce`](bittorrent_http_protocol ::v1::requests::announce::Announce) request.
2
2
//!
3
3
//! Data structures and logic to build the `announce` response.
4
4
use std:: io:: Write ;
5
5
use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
6
6
7
- use axum:: http:: StatusCode ;
8
7
use derive_more:: { AsRef , Constructor , From } ;
9
8
use torrust_tracker_contrib_bencode:: { ben_bytes, ben_int, ben_list, ben_map, BMutAccess , BencodeMut } ;
9
+ use torrust_tracker_primitives:: core:: AnnounceData ;
10
10
use torrust_tracker_primitives:: peer;
11
11
12
- use super :: Response ;
13
- use crate :: core:: AnnounceData ;
14
- use crate :: servers:: http:: v1:: responses;
15
-
16
12
/// An [`Announce`] response, that can be anything that is convertible from [`AnnounceData`].
17
13
///
18
14
/// The [`Announce`] can built from any data that implements: [`From<AnnounceData>`] and [`Into<Vec<u8>>`].
@@ -35,7 +31,7 @@ pub struct Announce<E>
35
31
where
36
32
E : From < AnnounceData > + Into < Vec < u8 > > ,
37
33
{
38
- data : E ,
34
+ pub data : E ,
39
35
}
40
36
41
37
/// Build any [`Announce`] from an [`AnnounceData`].
@@ -45,24 +41,6 @@ impl<E: From<AnnounceData> + Into<Vec<u8>>> From<AnnounceData> for Announce<E> {
45
41
}
46
42
}
47
43
48
- /// Convert any Announce [`Announce`] into a [`axum::response::Response`]
49
- impl < E : From < AnnounceData > + Into < Vec < u8 > > > axum:: response:: IntoResponse for Announce < E >
50
- where
51
- Announce < E > : Response ,
52
- {
53
- fn into_response ( self ) -> axum:: response:: Response {
54
- axum:: response:: IntoResponse :: into_response ( self . body ( ) . map ( |bytes| ( StatusCode :: OK , bytes) ) )
55
- }
56
- }
57
-
58
- /// Implement the [`Response`] for the [`Announce`].
59
- ///
60
- impl < E : From < AnnounceData > + Into < Vec < u8 > > > Response for Announce < E > {
61
- fn body ( self ) -> Result < Vec < u8 > , responses:: error:: Error > {
62
- Ok ( self . data . into ( ) )
63
- }
64
- }
65
-
66
44
/// Format of the [`Normal`] (Non-Compact) Encoding
67
45
pub struct Normal {
68
46
complete : i64 ,
@@ -152,9 +130,9 @@ impl Into<Vec<u8>> for Compact {
152
130
153
131
/// A [`NormalPeer`], for the [`Normal`] form.
154
132
///
155
- /// ```text
133
+ /// ```rust
156
134
/// use std::net::{IpAddr, Ipv4Addr};
157
- /// use torrust_tracker_lib::servers::http ::v1::responses::announce::{Normal, NormalPeer};
135
+ /// use bittorrent_http_protocol ::v1::responses::announce::{Normal, NormalPeer};
158
136
///
159
137
/// let peer = NormalPeer {
160
138
/// peer_id: *b"-qB00000000000000001",
@@ -204,9 +182,9 @@ impl From<&NormalPeer> for BencodeMut<'_> {
204
182
/// A part from reducing the size of the response, this format does not contain
205
183
/// the peer's ID.
206
184
///
207
- /// ```text
185
+ /// ```rust
208
186
/// use std::net::{IpAddr, Ipv4Addr};
209
- /// use torrust_tracker_lib::servers::http ::v1::responses::announce::{Compact, CompactPeer, CompactPeerData};
187
+ /// use bittorrent_http_protocol ::v1::responses::announce::{Compact, CompactPeer, CompactPeerData};
210
188
///
211
189
/// let peer = CompactPeer::V4(CompactPeerData {
212
190
/// ip: Ipv4Addr::new(0x69, 0x69, 0x69, 0x69), // 105.105.105.105
@@ -302,11 +280,11 @@ mod tests {
302
280
303
281
use aquatic_udp_protocol:: PeerId ;
304
282
use torrust_tracker_configuration:: AnnouncePolicy ;
283
+ use torrust_tracker_primitives:: core:: AnnounceData ;
305
284
use torrust_tracker_primitives:: peer:: fixture:: PeerBuilder ;
306
285
use torrust_tracker_primitives:: swarm_metadata:: SwarmMetadata ;
307
286
308
- use crate :: core:: AnnounceData ;
309
- use crate :: servers:: http:: v1:: responses:: announce:: { Announce , Compact , Normal , Response } ;
287
+ use crate :: v1:: responses:: announce:: { Announce , Compact , Normal } ;
310
288
311
289
// Some ascii values used in tests:
312
290
//
@@ -345,7 +323,7 @@ mod tests {
345
323
#[ test]
346
324
fn non_compact_announce_response_can_be_bencoded ( ) {
347
325
let response: Announce < Normal > = setup_announce_data ( ) . into ( ) ;
348
- let bytes = response. body ( ) . expect ( "it should encode the response" ) ;
326
+ let bytes = response. data . into ( ) ;
349
327
350
328
// cspell:disable-next-line
351
329
let expected_bytes = b"d8:completei333e10:incompletei444e8:intervali111e12:min intervali222e5:peersld2:ip15:105.105.105.1057:peer id20:-qB000000000000000014:porti28784eed2:ip39:6969:6969:6969:6969:6969:6969:6969:69697:peer id20:-qB000000000000000024:porti28784eeee" ;
@@ -359,7 +337,7 @@ mod tests {
359
337
#[ test]
360
338
fn compact_announce_response_can_be_bencoded ( ) {
361
339
let response: Announce < Compact > = setup_announce_data ( ) . into ( ) ;
362
- let bytes = response. body ( ) . expect ( "it should encode the response" ) ;
340
+ let bytes = response. data . into ( ) ;
363
341
364
342
let expected_bytes =
365
343
// cspell:disable-next-line
0 commit comments