You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//! [BEP 3. The `BitTorrent` Protocol Specification](https://www.bittorrent.org/beps/bep_0003.html)
1
4
use aquatic_udp_protocol::{AnnounceEvent,NumberOfBytes};
2
5
use serde::{Deserialize,Serialize};
3
6
7
+
/// The maximum number of torrents that can be returned in an `scrape` response.
8
+
/// It's also the maximum number of peers returned in an `announce` response.
9
+
///
10
+
/// The [BEP 15. UDP Tracker Protocol for `BitTorrent`](https://www.bittorrent.org/beps/bep_0015.html)
11
+
/// defines this limit:
12
+
///
13
+
/// "Up to about 74 torrents can be scraped at once. A full scrape can't be done
14
+
/// with this protocol."
15
+
///
16
+
/// The [BEP 48. Tracker Protocol Extension: Scrape](https://www.bittorrent.org/beps/bep_0048.html)
17
+
/// does not specifically mention this limit, but the limit is being used for
18
+
/// both the UDP and HTTP trackers since it's applied at the domain level.
4
19
pubconstMAX_SCRAPE_TORRENTS:u8 = 74;
20
+
21
+
/// HTTP tracker authentication key length.
22
+
///
23
+
/// See function to [`generate`](crate::tracker::auth::generate) the
24
+
/// [`ExpiringKeys`](crate::tracker::auth::ExpiringKey) for more information.
Copy file name to clipboardExpand all lines: src/shared/bit_torrent/info_hash.rs
+139-1Lines changed: 139 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,147 @@
1
+
//! A `BitTorrent` `InfoHash`. It's a unique identifier for a `BitTorrent` torrent.
2
+
//!
3
+
//! "The 20-byte sha1 hash of the bencoded form of the info value
4
+
//! from the metainfo file."
5
+
//!
6
+
//! See [BEP 3. The `BitTorrent` Protocol Specification](https://www.bittorrent.org/beps/bep_0003.html)
7
+
//! for the official specification.
8
+
//!
9
+
//! This modules provides a type that can be used to represent infohashes.
10
+
//!
11
+
//! > **NOTICE**: It only supports Info Hash v1.
12
+
//!
13
+
//! Typically infohashes are represented as hex strings, but internally they are
//! - Info Hash v1: `5452869be36f9f3350ccee6b4544e7e76caaadab`
23
+
//! - Sha1 hash of the info dictionary: `5452869BE36F9F3350CCEE6B4544E7E76CAAADAB`
24
+
//!
25
+
//! A torrent file is a binary file encoded with [Bencode encoding](https://en.wikipedia.org/wiki/Bencode):
//! You can hash that byte string with <https://www.pelock.com/products/hash-calculator>
130
+
//!
131
+
//! The result is a 20-char string: `5452869BE36F9F3350CCEE6B4544E7E76CAAADAB`
1
132
use std::panic::Location;
2
133
3
134
use thiserror::Error;
4
135
136
+
/// `BitTorrent` Info Hash v1
5
137
#[derive(PartialEq,Eq,Hash,Clone,Copy,Debug)]
6
138
pubstructInfoHash(pub[u8;20]);
7
139
8
140
constINFO_HASH_BYTES_LEN:usize = 20;
9
141
10
142
implInfoHash{
143
+
/// Create a new `InfoHash` from a byte slice.
144
+
///
11
145
/// # Panics
12
146
///
13
147
/// Will panic if byte slice does not contains the exact amount of bytes need for the `InfoHash`.
@@ -19,12 +153,13 @@ impl InfoHash {
19
153
ret
20
154
}
21
155
22
-
/// For readability, when accessing the bytes array
156
+
/// Returns the `InfoHash` internal byte array.
23
157
#[must_use]
24
158
pubfnbytes(&self) -> [u8;20]{
25
159
self.0
26
160
}
27
161
162
+
/// Returns the `InfoHash` as a hex string.
28
163
#[must_use]
29
164
pubfnto_hex_string(&self) -> String{
30
165
self.to_string()
@@ -79,13 +214,16 @@ impl std::convert::From<[u8; 20]> for InfoHash {
79
214
}
80
215
}
81
216
217
+
/// Errors that can occur when converting from a `Vec<u8>` to an `InfoHash`.
82
218
#[derive(Error,Debug)]
83
219
pubenumConversionError{
220
+
/// Not enough bytes for infohash. An infohash is 20 bytes.
84
221
#[error("not enough bytes for infohash: {message} {location}")]
85
222
NotEnoughBytes{
86
223
location:&'staticLocation<'static>,
87
224
message:String,
88
225
},
226
+
/// Too many bytes for infohash. An infohash is 20 bytes.
89
227
#[error("too many bytes for infohash: {message} {location}")]
0 commit comments