forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhttp.rs
More file actions
31 lines (26 loc) · 974 Bytes
/
Copy pathhttp.rs
File metadata and controls
31 lines (26 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! HTTP tracker test helpers.
use std::time::Duration;
use torrust_tracker_client::http::client::Client;
use torrust_tracker_http_protocol::v1::requests::announce::{Announce, Event, PeerIp};
use url::Url;
/// Sends an HTTP announce to the given tracker URL.
///
/// # Panics
///
/// Panics if the client cannot build, send, or receive.
pub async fn http_announce(tracker_url: &Url, info_hash: &[u8; 20], peer_id: &[u8; 20], port: u16) {
let client = Client::new(tracker_url.clone(), Duration::from_secs(5)).expect("failed to create HTTP client");
let query = Announce {
info_hash: torrust_info_hash::InfoHash(*info_hash),
peer_id: torrust_peer_id::PeerId(*peer_id),
port,
ip: PeerIp::Absent,
downloaded: None,
uploaded: None,
left: None,
event: Some(Event::Started),
compact: None,
numwant: None,
};
client.announce(&query).await.expect("HTTP announce should succeed");
}