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