mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 02:05:30 +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 {
|
let max_num_peers_to_take = match request.numwant {
|
||||||
config.protocol.max_peers
|
Some(0) | None => config.protocol.max_peers,
|
||||||
} else {
|
Some(numwant) => numwant.min(config.protocol.max_peers),
|
||||||
request.numwant.min(config.protocol.max_peers)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let response_peers: Vec<ResponsePeer> = extract_response_peers(
|
let response_peers: Vec<ResponsePeer> = extract_response_peers(
|
||||||
|
|
@ -161,7 +160,6 @@ pub fn handle_announce_requests(
|
||||||
incomplete: torrent_data.num_leechers,
|
incomplete: torrent_data.num_leechers,
|
||||||
announce_interval: config.protocol.peer_announce_interval,
|
announce_interval: config.protocol.peer_announce_interval,
|
||||||
peers: response_peers,
|
peers: response_peers,
|
||||||
tracker_id: "".to_string()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
(request_sender_meta, response)
|
(request_sender_meta, response)
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ pub struct AnnounceRequest {
|
||||||
pub bytes_left: usize,
|
pub bytes_left: usize,
|
||||||
pub event: AnnounceEvent,
|
pub event: AnnounceEvent,
|
||||||
pub compact: bool,
|
pub compact: bool,
|
||||||
/// Requested number of peers to return
|
/// Number of response peers wanted
|
||||||
pub numwant: usize,
|
pub numwant: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -68,6 +68,17 @@ impl Request {
|
||||||
}
|
}
|
||||||
|
|
||||||
if location == "/announce" {
|
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 {
|
let request = AnnounceRequest {
|
||||||
info_hash: info_hashes.get(0)
|
info_hash: info_hashes.get(0)
|
||||||
.with_context(|| "no info_hash")
|
.with_context(|| "no info_hash")
|
||||||
|
|
@ -91,12 +102,7 @@ impl Request {
|
||||||
compact: data.get("compact")
|
compact: data.get("compact")
|
||||||
.map(|s| s == "1")
|
.map(|s| s == "1")
|
||||||
.unwrap_or(true),
|
.unwrap_or(true),
|
||||||
numwant: data.get("numwant")
|
numwant,
|
||||||
.with_context(|| "no numwant")
|
|
||||||
.and_then(|s| s.parse()
|
|
||||||
.map_err(|err|
|
|
||||||
anyhow::anyhow!("parse 'numwant': {}", err)
|
|
||||||
))?,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Request::Announce(request))
|
Ok(Request::Announce(request))
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ pub struct ScrapeStatistics {
|
||||||
pub struct AnnounceResponse {
|
pub struct AnnounceResponse {
|
||||||
#[serde(rename = "interval")]
|
#[serde(rename = "interval")]
|
||||||
pub announce_interval: usize,
|
pub announce_interval: usize,
|
||||||
pub tracker_id: String, // Optional??
|
|
||||||
pub complete: usize,
|
pub complete: usize,
|
||||||
pub incomplete: usize,
|
pub incomplete: usize,
|
||||||
#[serde(
|
#[serde(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue