mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 09:45:31 +00:00
Run cargo clippy --fix and cargo fmt
This commit is contained in:
parent
22e151d0f0
commit
5401eaf85f
28 changed files with 94 additions and 107 deletions
|
|
@ -27,17 +27,11 @@ impl TaskSetCpuList {
|
|||
let indicator = self.0.iter().map(|indicator| match indicator {
|
||||
TaskSetCpuIndicator::Single(i) => i.to_string(),
|
||||
TaskSetCpuIndicator::Range(range) => {
|
||||
format!(
|
||||
"{}-{}",
|
||||
range.start,
|
||||
range.clone().into_iter().last().unwrap()
|
||||
)
|
||||
format!("{}-{}", range.start, range.clone().last().unwrap())
|
||||
}
|
||||
});
|
||||
|
||||
Itertools::intersperse_with(indicator, || ",".to_string())
|
||||
.into_iter()
|
||||
.collect()
|
||||
Itertools::intersperse_with(indicator, || ",".to_string()).collect()
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
|
|
@ -163,7 +157,7 @@ pub fn simple_load_test_runs(
|
|||
workers: &[(usize, Priority)],
|
||||
) -> Vec<(usize, Priority, TaskSetCpuList)> {
|
||||
workers
|
||||
.into_iter()
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|(workers, priority)| {
|
||||
(
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ pub fn html_all_runs(all_results: &[TrackerCoreCountResults]) -> String {
|
|||
load_test_key_names = load_test_key_names.iter()
|
||||
.map(|name| format!("<th>Load test {}</th>", name))
|
||||
.join("\n"),
|
||||
body = results.into_iter().map(|r| {
|
||||
body = results.iter_mut().map(|r| {
|
||||
formatdoc! {
|
||||
"
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -59,9 +59,7 @@ impl<C> RunConfig<C> {
|
|||
.run(command, &self.tracker_vcpus, &mut tracker_config_file)
|
||||
{
|
||||
Ok(handle) => ChildWrapper(handle),
|
||||
Err(err) => {
|
||||
return Err(RunErrorResults::new(self).set_error(err.into(), "run tracker"))
|
||||
}
|
||||
Err(err) => return Err(RunErrorResults::new(self).set_error(err, "run tracker")),
|
||||
};
|
||||
|
||||
::std::thread::sleep(Duration::from_secs(1));
|
||||
|
|
@ -74,7 +72,7 @@ impl<C> RunConfig<C> {
|
|||
Ok(handle) => ChildWrapper(handle),
|
||||
Err(err) => {
|
||||
return Err(RunErrorResults::new(self)
|
||||
.set_error(err.into(), "run load test")
|
||||
.set_error(err, "run load test")
|
||||
.set_tracker_outputs(tracker))
|
||||
}
|
||||
};
|
||||
|
|
@ -328,7 +326,7 @@ impl FromStr for ProcessStats {
|
|||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let mut parts = s.trim().split_whitespace();
|
||||
let mut parts = s.split_whitespace();
|
||||
|
||||
let avg_cpu_utilization = parts.next().ok_or(())?.parse().map_err(|_| ())?;
|
||||
let peak_rss_kb: f32 = parts.next().ok_or(())?.parse().map_err(|_| ())?;
|
||||
|
|
|
|||
|
|
@ -73,13 +73,13 @@ pub fn run_sets<C, F, I>(
|
|||
(minutes / 60, minutes % 60)
|
||||
};
|
||||
|
||||
println!("");
|
||||
println!();
|
||||
println!("Total number of load test runs: {}", total_num_runs);
|
||||
println!(
|
||||
"Estimated duration: {} hours, {} minutes",
|
||||
estimated_hours, estimated_minutes
|
||||
);
|
||||
println!("");
|
||||
println!();
|
||||
|
||||
let results = set_configs
|
||||
.into_iter()
|
||||
|
|
@ -115,7 +115,7 @@ pub fn run_sets<C, F, I>(
|
|||
&load_test_gen,
|
||||
load_test_parameters,
|
||||
implementation,
|
||||
&tracker_run,
|
||||
tracker_run,
|
||||
tracker_vcpus.clone(),
|
||||
load_test_vcpus,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ fn main() {
|
|||
::std::process::exit(match run() {
|
||||
Ok(()) => 0,
|
||||
Err(None) => {
|
||||
print_help(|| gen_info(), None);
|
||||
print_help(gen_info, None);
|
||||
|
||||
0
|
||||
}
|
||||
Err(opt_err @ Some(_)) => {
|
||||
print_help(|| gen_info(), opt_err);
|
||||
print_help(gen_info, opt_err);
|
||||
|
||||
1
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ fn run() -> Result<(), Option<String>> {
|
|||
arg => {
|
||||
let opt_err = if arg == "-h" || arg == "--help" {
|
||||
None
|
||||
} else if arg.chars().next() == Some('-') {
|
||||
} else if arg.starts_with('-') {
|
||||
Some("First argument must be protocol".to_string())
|
||||
} else {
|
||||
Some("Invalid protocol".to_string())
|
||||
|
|
|
|||
|
|
@ -383,7 +383,7 @@ where
|
|||
|
||||
let body_len = response
|
||||
.write(&mut &mut self.response_buffer[position..])
|
||||
.map_err(|err| ConnectionError::ResponseBufferWrite(err))?;
|
||||
.map_err(ConnectionError::ResponseBufferWrite)?;
|
||||
|
||||
position += body_len;
|
||||
|
||||
|
|
@ -391,7 +391,7 @@ where
|
|||
return Err(ConnectionError::ResponseBufferFull);
|
||||
}
|
||||
|
||||
(&mut self.response_buffer[position..position + 2]).copy_from_slice(b"\r\n");
|
||||
self.response_buffer[position..position + 2].copy_from_slice(b"\r\n");
|
||||
|
||||
position += 2;
|
||||
|
||||
|
|
@ -403,7 +403,7 @@ where
|
|||
let start = RESPONSE_HEADER_A.len();
|
||||
let end = start + RESPONSE_HEADER_B.len();
|
||||
|
||||
(&mut self.response_buffer[start..end]).copy_from_slice(RESPONSE_HEADER_B);
|
||||
self.response_buffer[start..end].copy_from_slice(RESPONSE_HEADER_B);
|
||||
}
|
||||
|
||||
// Set content-len header value
|
||||
|
|
@ -415,7 +415,7 @@ where
|
|||
let start = RESPONSE_HEADER_A.len();
|
||||
let end = start + content_len_bytes.len();
|
||||
|
||||
(&mut self.response_buffer[start..end]).copy_from_slice(content_len_bytes);
|
||||
self.response_buffer[start..end].copy_from_slice(content_len_bytes);
|
||||
}
|
||||
|
||||
// Write buffer to stream
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ fn parse_forwarded_header(
|
|||
header_format: ReverseProxyPeerIpHeaderFormat,
|
||||
headers: &[httparse::Header<'_>],
|
||||
) -> anyhow::Result<IpAddr> {
|
||||
for header in headers.into_iter().rev() {
|
||||
for header in headers.iter().rev() {
|
||||
if header.name == header_name {
|
||||
match header_format {
|
||||
ReverseProxyPeerIpHeaderFormat::LastAddress => {
|
||||
|
|
|
|||
|
|
@ -66,16 +66,14 @@ impl TorrentMaps {
|
|||
valid_until,
|
||||
);
|
||||
|
||||
let response = AnnounceResponse {
|
||||
AnnounceResponse {
|
||||
complete: seeders,
|
||||
incomplete: leechers,
|
||||
announce_interval: config.protocol.peer_announce_interval,
|
||||
peers: ResponsePeerListV4(response_peers),
|
||||
peers6: ResponsePeerListV6(vec![]),
|
||||
warning_message: None,
|
||||
};
|
||||
|
||||
response
|
||||
}
|
||||
}
|
||||
IpAddr::V6(peer_ip_address) => {
|
||||
let (seeders, leechers, response_peers) = self
|
||||
|
|
@ -90,16 +88,14 @@ impl TorrentMaps {
|
|||
valid_until,
|
||||
);
|
||||
|
||||
let response = AnnounceResponse {
|
||||
AnnounceResponse {
|
||||
complete: seeders,
|
||||
incomplete: leechers,
|
||||
announce_interval: config.protocol.peer_announce_interval,
|
||||
peers: ResponsePeerListV4(vec![]),
|
||||
peers6: ResponsePeerListV6(response_peers),
|
||||
warning_message: None,
|
||||
};
|
||||
|
||||
response
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub fn create_random_request(
|
|||
|
||||
let items = [RequestType::Announce, RequestType::Scrape];
|
||||
|
||||
let dist = WeightedIndex::new(&weights).expect("random request weighted index");
|
||||
let dist = WeightedIndex::new(weights).expect("random request weighted index");
|
||||
|
||||
match items[dist.sample(rng)] {
|
||||
RequestType::Announce => create_announce_request(config, state, rng),
|
||||
|
|
@ -37,7 +37,7 @@ fn create_announce_request(config: &Config, state: &LoadTestState, rng: &mut imp
|
|||
}
|
||||
};
|
||||
|
||||
let info_hash_index = select_info_hash_index(config, &state, rng);
|
||||
let info_hash_index = select_info_hash_index(config, state, rng);
|
||||
|
||||
Request::Announce(AnnounceRequest {
|
||||
info_hash: state.info_hashes[info_hash_index],
|
||||
|
|
@ -57,7 +57,7 @@ fn create_scrape_request(config: &Config, state: &LoadTestState, rng: &mut impl
|
|||
let mut scrape_hashes = Vec::with_capacity(5);
|
||||
|
||||
for _ in 0..5 {
|
||||
let info_hash_index = select_info_hash_index(config, &state, rng);
|
||||
let info_hash_index = select_info_hash_index(config, state, rng);
|
||||
|
||||
scrape_hashes.push(state.info_hashes[info_hash_index]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ impl AnnounceRequest {
|
|||
let mut position = 0usize;
|
||||
|
||||
for equal_sign_index in ::memchr::memchr_iter(b'=', query_string_bytes) {
|
||||
let segment_end = ampersand_iter.next().unwrap_or_else(|| query_string.len());
|
||||
let segment_end = ampersand_iter.next().unwrap_or(query_string.len());
|
||||
|
||||
let key = query_string
|
||||
.get(position..equal_sign_index)
|
||||
|
|
@ -207,7 +207,7 @@ impl ScrapeRequest {
|
|||
let mut position = 0usize;
|
||||
|
||||
for equal_sign_index in ::memchr::memchr_iter(b'=', query_string_bytes) {
|
||||
let segment_end = ampersand_iter.next().unwrap_or_else(|| query_string.len());
|
||||
let segment_end = ampersand_iter.next().unwrap_or(query_string.len());
|
||||
|
||||
let key = query_string
|
||||
.get(position..equal_sign_index)
|
||||
|
|
@ -348,7 +348,7 @@ mod tests {
|
|||
let mut bytes = Vec::new();
|
||||
|
||||
bytes.extend_from_slice(b"GET ");
|
||||
bytes.extend_from_slice(&ANNOUNCE_REQUEST_PATH.as_bytes());
|
||||
bytes.extend_from_slice(ANNOUNCE_REQUEST_PATH.as_bytes());
|
||||
bytes.extend_from_slice(b" HTTP/1.1\r\n\r\n");
|
||||
|
||||
let parsed_request = Request::from_bytes(&bytes[..]).unwrap().unwrap();
|
||||
|
|
@ -362,7 +362,7 @@ mod tests {
|
|||
let mut bytes = Vec::new();
|
||||
|
||||
bytes.extend_from_slice(b"GET ");
|
||||
bytes.extend_from_slice(&SCRAPE_REQUEST_PATH.as_bytes());
|
||||
bytes.extend_from_slice(SCRAPE_REQUEST_PATH.as_bytes());
|
||||
bytes.extend_from_slice(b" HTTP/1.1\r\n\r\n");
|
||||
|
||||
let parsed_request = Request::from_bytes(&bytes[..]).unwrap().unwrap();
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ pub fn urldecode_20_bytes(value: &str) -> anyhow::Result<[u8; 20]> {
|
|||
|
||||
let hex = [first as u8, second as u8];
|
||||
|
||||
hex::decode_to_slice(&hex, &mut out_arr[i..i + 1])
|
||||
hex::decode_to_slice(hex, &mut out_arr[i..i + 1])
|
||||
.map_err(|err| anyhow::anyhow!("hex decode error: {:?}", err))?;
|
||||
} else {
|
||||
out_arr[i] = c as u8;
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ mod tests {
|
|||
|
||||
let len = bytes.len();
|
||||
|
||||
(&mut peer_id.0[..len]).copy_from_slice(bytes);
|
||||
peer_id.0[..len].copy_from_slice(bytes);
|
||||
|
||||
peer_id
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ impl Statistics {
|
|||
}
|
||||
|
||||
fn create_atomic_usize_vec(len: usize) -> Vec<AtomicUsize> {
|
||||
::std::iter::repeat_with(|| AtomicUsize::default())
|
||||
::std::iter::repeat_with(AtomicUsize::default)
|
||||
.take(len)
|
||||
.collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ impl SocketWorker {
|
|||
if let Err(HandleRequestError::RequestChannelFull(failed_requests)) =
|
||||
self.handle_request(pending_scrape_valid_until, request, src)
|
||||
{
|
||||
self.pending_requests.extend(failed_requests.into_iter());
|
||||
self.pending_requests.extend(failed_requests);
|
||||
self.polling_mode = PollMode::SkipReceiving;
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl PendingScrapeResponseSlab {
|
|||
|
||||
for (i, info_hash) in request.info_hashes.into_iter().enumerate() {
|
||||
let split_request = split_requests
|
||||
.entry(SwarmWorkerIndex::from_info_hash(&config, info_hash))
|
||||
.entry(SwarmWorkerIndex::from_info_hash(config, info_hash))
|
||||
.or_insert_with(|| PendingScrapeRequest {
|
||||
slab_key,
|
||||
info_hashes: BTreeMap::new(),
|
||||
|
|
|
|||
|
|
@ -59,8 +59,8 @@ impl ConnectionValidator {
|
|||
|
||||
let mut connection_id_bytes = [0u8; 8];
|
||||
|
||||
(&mut connection_id_bytes[..4]).copy_from_slice(&elapsed);
|
||||
(&mut connection_id_bytes[4..]).copy_from_slice(&hash);
|
||||
connection_id_bytes[..4].copy_from_slice(&elapsed);
|
||||
connection_id_bytes[4..].copy_from_slice(&hash);
|
||||
|
||||
ConnectionId::new(i64::from_ne_bytes(connection_id_bytes))
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ impl ConnectionValidator {
|
|||
return false;
|
||||
}
|
||||
|
||||
let tracker_elapsed = u64::from(self.start_time.elapsed().as_secs());
|
||||
let tracker_elapsed = self.start_time.elapsed().as_secs();
|
||||
let client_elapsed = u64::from(u32::from_ne_bytes(elapsed));
|
||||
let client_expiration_time = client_elapsed + self.max_connection_age;
|
||||
|
||||
|
|
|
|||
|
|
@ -365,14 +365,15 @@ impl<I: Ip> SmallPeerMap<I> {
|
|||
self.0.retain(|(_, peer)| {
|
||||
let keep = peer.valid_until.valid(now);
|
||||
|
||||
if !keep && config.statistics.peer_clients {
|
||||
if let Err(_) =
|
||||
statistics_sender.try_send(StatisticsMessage::PeerRemoved(peer.peer_id))
|
||||
if !keep
|
||||
&& config.statistics.peer_clients
|
||||
&& statistics_sender
|
||||
.try_send(StatisticsMessage::PeerRemoved(peer.peer_id))
|
||||
.is_err()
|
||||
{
|
||||
// Should never happen in practice
|
||||
::log::error!("Couldn't send StatisticsMessage::PeerRemoved");
|
||||
}
|
||||
}
|
||||
|
||||
keep
|
||||
});
|
||||
|
|
@ -480,15 +481,15 @@ impl<I: Ip> LargePeerMap<I> {
|
|||
if peer.is_seeder {
|
||||
self.num_seeders -= 1;
|
||||
}
|
||||
if config.statistics.peer_clients {
|
||||
if let Err(_) =
|
||||
statistics_sender.try_send(StatisticsMessage::PeerRemoved(peer.peer_id))
|
||||
if config.statistics.peer_clients
|
||||
&& statistics_sender
|
||||
.try_send(StatisticsMessage::PeerRemoved(peer.peer_id))
|
||||
.is_err()
|
||||
{
|
||||
// Should never happen in practice
|
||||
::log::error!("Couldn't send StatisticsMessage::PeerRemoved");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
keep
|
||||
});
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ pub fn connect(socket: &UdpSocket, tracker_addr: SocketAddr) -> anyhow::Result<C
|
|||
transaction_id: TransactionId::new(0),
|
||||
});
|
||||
|
||||
let response = request_and_response(&socket, tracker_addr, request)?;
|
||||
let response = request_and_response(socket, tracker_addr, request)?;
|
||||
|
||||
if let Response::Connect(response) = response {
|
||||
Ok(response.connection_id)
|
||||
|
|
@ -69,7 +69,7 @@ pub fn announce(
|
|||
port: Port::new(peer_port),
|
||||
});
|
||||
|
||||
Ok(request_and_response(&socket, tracker_addr, request)?)
|
||||
request_and_response(socket, tracker_addr, request)
|
||||
}
|
||||
|
||||
pub fn scrape(
|
||||
|
|
@ -84,12 +84,12 @@ pub fn scrape(
|
|||
info_hashes,
|
||||
});
|
||||
|
||||
let response = request_and_response(&socket, tracker_addr, request)?;
|
||||
let response = request_and_response(socket, tracker_addr, request)?;
|
||||
|
||||
if let Response::Scrape(response) = response {
|
||||
Ok(response)
|
||||
} else {
|
||||
return Err(anyhow::anyhow!("not scrape response: {:?}", response));
|
||||
Err(anyhow::anyhow!("not scrape response: {:?}", response))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -119,6 +119,6 @@ pub fn request_and_response(
|
|||
.recv_from(&mut buffer)
|
||||
.with_context(|| "recv response")?;
|
||||
|
||||
Ok(Response::from_bytes(&buffer[..bytes_read], true).with_context(|| "parse response")?)
|
||||
Response::from_bytes(&buffer[..bytes_read], true).with_context(|| "parse response")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,12 +63,10 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
|
||||
let ip = if config.server_address.is_ipv6() {
|
||||
Ipv6Addr::LOCALHOST.into()
|
||||
} else {
|
||||
if config.network.multiple_client_ipv4s {
|
||||
} else if config.network.multiple_client_ipv4s {
|
||||
Ipv4Addr::new(127, 0, 0, 1 + i).into()
|
||||
} else {
|
||||
Ipv4Addr::LOCALHOST.into()
|
||||
}
|
||||
};
|
||||
|
||||
let addr = SocketAddr::new(ip, port);
|
||||
|
|
|
|||
|
|
@ -104,15 +104,15 @@ pub struct Ipv4AddrBytes(pub [u8; 4]);
|
|||
|
||||
impl Ip for Ipv4AddrBytes {}
|
||||
|
||||
impl Into<Ipv4Addr> for Ipv4AddrBytes {
|
||||
fn into(self) -> Ipv4Addr {
|
||||
Ipv4Addr::from(self.0)
|
||||
impl From<Ipv4AddrBytes> for Ipv4Addr {
|
||||
fn from(val: Ipv4AddrBytes) -> Self {
|
||||
Ipv4Addr::from(val.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Ipv4AddrBytes> for Ipv4Addr {
|
||||
fn into(self) -> Ipv4AddrBytes {
|
||||
Ipv4AddrBytes(self.octets())
|
||||
impl From<Ipv4Addr> for Ipv4AddrBytes {
|
||||
fn from(val: Ipv4Addr) -> Self {
|
||||
Ipv4AddrBytes(val.octets())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -122,15 +122,15 @@ pub struct Ipv6AddrBytes(pub [u8; 16]);
|
|||
|
||||
impl Ip for Ipv6AddrBytes {}
|
||||
|
||||
impl Into<Ipv6Addr> for Ipv6AddrBytes {
|
||||
fn into(self) -> Ipv6Addr {
|
||||
Ipv6Addr::from(self.0)
|
||||
impl From<Ipv6AddrBytes> for Ipv6Addr {
|
||||
fn from(val: Ipv6AddrBytes) -> Self {
|
||||
Ipv6Addr::from(val.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Ipv6AddrBytes> for Ipv6Addr {
|
||||
fn into(self) -> Ipv6AddrBytes {
|
||||
Ipv6AddrBytes(self.octets())
|
||||
impl From<Ipv6Addr> for Ipv6AddrBytes {
|
||||
fn from(val: Ipv6Addr) -> Self {
|
||||
Ipv6AddrBytes(val.octets())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ impl Response {
|
|||
// Error
|
||||
3 => {
|
||||
let transaction_id = read_i32_ne(&mut bytes).map(TransactionId)?;
|
||||
let message = String::from_utf8_lossy(&bytes).into_owned().into();
|
||||
let message = String::from_utf8_lossy(bytes).into_owned().into();
|
||||
|
||||
Ok((ErrorResponse {
|
||||
transaction_id,
|
||||
|
|
|
|||
|
|
@ -57,12 +57,12 @@ pub struct OutMessageMeta {
|
|||
pub pending_scrape_id: Option<PendingScrapeId>,
|
||||
}
|
||||
|
||||
impl Into<OutMessageMeta> for InMessageMeta {
|
||||
fn into(self) -> OutMessageMeta {
|
||||
impl From<InMessageMeta> for OutMessageMeta {
|
||||
fn from(val: InMessageMeta) -> Self {
|
||||
OutMessageMeta {
|
||||
out_message_consumer_id: self.out_message_consumer_id,
|
||||
connection_id: self.connection_id,
|
||||
pending_scrape_id: self.pending_scrape_id,
|
||||
out_message_consumer_id: val.out_message_consumer_id,
|
||||
connection_id: val.connection_id,
|
||||
pending_scrape_id: val.pending_scrape_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ impl ConnectionRunner {
|
|||
clean_up_data.before_open();
|
||||
|
||||
let config = self.config.clone();
|
||||
let connection_id = self.connection_id.clone();
|
||||
let connection_id = self.connection_id;
|
||||
|
||||
race(
|
||||
async {
|
||||
|
|
@ -608,7 +608,7 @@ impl ConnectionCleanupData {
|
|||
let mut announced_info_hashes = HashMap::new();
|
||||
|
||||
for (info_hash, peer_id) in self.announced_info_hashes.take().into_iter() {
|
||||
let consumer_index = calculate_in_message_consumer_index(&config, info_hash);
|
||||
let consumer_index = calculate_in_message_consumer_index(config, info_hash);
|
||||
|
||||
announced_info_hashes
|
||||
.entry(consumer_index)
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ async fn handle_request_stream<S>(
|
|||
match in_message {
|
||||
InMessage::AnnounceRequest(request) => {
|
||||
torrents.borrow_mut().handle_announce_request(
|
||||
&config,
|
||||
config,
|
||||
&mut rng.borrow_mut(),
|
||||
&mut out_messages,
|
||||
server_start_instant,
|
||||
|
|
@ -150,7 +150,7 @@ async fn handle_request_stream<S>(
|
|||
}
|
||||
InMessage::ScrapeRequest(request) => torrents
|
||||
.borrow_mut()
|
||||
.handle_scrape_request(&config, &mut out_messages, meta, request),
|
||||
.handle_scrape_request(config, &mut out_messages, meta, request),
|
||||
};
|
||||
|
||||
for (meta, out_message) in out_messages {
|
||||
|
|
|
|||
|
|
@ -248,7 +248,11 @@ impl TorrentMaps {
|
|||
regarding_offer_id: offer_id,
|
||||
};
|
||||
|
||||
if let Some(_) = answer_receiver.expecting_answers.remove(&expecting_answer) {
|
||||
if answer_receiver
|
||||
.expecting_answers
|
||||
.remove(&expecting_answer)
|
||||
.is_some()
|
||||
{
|
||||
let answer_out_message = AnswerOutMessage {
|
||||
action: AnnounceAction::Announce,
|
||||
peer_id: request.peer_id,
|
||||
|
|
@ -426,15 +430,13 @@ impl TorrentMaps {
|
|||
#[cfg(feature = "metrics")]
|
||||
self.peers_gauge_ipv4.decrement(1.0);
|
||||
}
|
||||
} else {
|
||||
if let Some(torrent_data) = self.ipv6.get_mut(&info_hash) {
|
||||
} else if let Some(torrent_data) = self.ipv6.get_mut(&info_hash) {
|
||||
torrent_data.remove_peer(peer_id);
|
||||
|
||||
#[cfg(feature = "metrics")]
|
||||
self.peers_gauge_ipv6.decrement(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct TorrentData {
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ pub fn random_request_type(config: &Config, rng: &mut impl Rng) -> RequestType {
|
|||
|
||||
let items = [RequestType::Announce, RequestType::Scrape];
|
||||
|
||||
let dist = WeightedIndex::new(&weights).expect("random request weighted index");
|
||||
let dist = WeightedIndex::new(weights).expect("random request weighted index");
|
||||
|
||||
items[dist.sample(rng)]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ mod tests {
|
|||
|
||||
assert!(bytes.len() == 20);
|
||||
|
||||
arr.copy_from_slice(&bytes[..]);
|
||||
arr.copy_from_slice(bytes);
|
||||
|
||||
InfoHash(arr)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ mod tests {
|
|||
|
||||
assert!(bytes.len() == 20);
|
||||
|
||||
arr.copy_from_slice(&bytes[..]);
|
||||
arr.copy_from_slice(bytes);
|
||||
|
||||
InfoHash(arr)
|
||||
}
|
||||
|
|
@ -372,8 +372,6 @@ mod tests {
|
|||
|
||||
let success = info_hashes == deserialized;
|
||||
|
||||
if !success {}
|
||||
|
||||
success
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue