mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_http: AnnounceRequest: make numwant optional, remove trackerid
This commit is contained in:
parent
6b7ce0e211
commit
2f2da8deb0
3 changed files with 17 additions and 14 deletions
|
|
@ -143,10 +143,9 @@ pub fn handle_announce_requests(
|
|||
}
|
||||
}
|
||||
|
||||
let max_num_peers_to_take = if request.numwant <= 0 {
|
||||
config.protocol.max_peers
|
||||
} else {
|
||||
request.numwant.min(config.protocol.max_peers)
|
||||
let max_num_peers_to_take = match request.numwant {
|
||||
Some(0) | None => config.protocol.max_peers,
|
||||
Some(numwant) => numwant.min(config.protocol.max_peers),
|
||||
};
|
||||
|
||||
let response_peers: Vec<ResponsePeer> = extract_response_peers(
|
||||
|
|
@ -161,7 +160,6 @@ pub fn handle_announce_requests(
|
|||
incomplete: torrent_data.num_leechers,
|
||||
announce_interval: config.protocol.peer_announce_interval,
|
||||
peers: response_peers,
|
||||
tracker_id: "".to_string()
|
||||
});
|
||||
|
||||
(request_sender_meta, response)
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ pub struct AnnounceRequest {
|
|||
pub bytes_left: usize,
|
||||
pub event: AnnounceEvent,
|
||||
pub compact: bool,
|
||||
/// Requested number of peers to return
|
||||
pub numwant: usize,
|
||||
/// Number of response peers wanted
|
||||
pub numwant: Option<usize>,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -68,6 +68,17 @@ impl Request {
|
|||
}
|
||||
|
||||
if location == "/announce" {
|
||||
let numwant = if let Some(s) = data.get("numwant"){
|
||||
let numwant = s.parse::<usize>()
|
||||
.map_err(|err|
|
||||
anyhow::anyhow!("parse 'numwant': {}", err)
|
||||
)?;
|
||||
|
||||
Some(numwant)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let request = AnnounceRequest {
|
||||
info_hash: info_hashes.get(0)
|
||||
.with_context(|| "no info_hash")
|
||||
|
|
@ -91,12 +102,7 @@ impl Request {
|
|||
compact: data.get("compact")
|
||||
.map(|s| s == "1")
|
||||
.unwrap_or(true),
|
||||
numwant: data.get("numwant")
|
||||
.with_context(|| "no numwant")
|
||||
.and_then(|s| s.parse()
|
||||
.map_err(|err|
|
||||
anyhow::anyhow!("parse 'numwant': {}", err)
|
||||
))?,
|
||||
numwant,
|
||||
};
|
||||
|
||||
Ok(Request::Announce(request))
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ pub struct ScrapeStatistics {
|
|||
pub struct AnnounceResponse {
|
||||
#[serde(rename = "interval")]
|
||||
pub announce_interval: usize,
|
||||
pub tracker_id: String, // Optional??
|
||||
pub complete: usize,
|
||||
pub incomplete: usize,
|
||||
#[serde(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue