clippy work

This commit is contained in:
Christien Rioux
2023-09-17 19:37:02 -04:00
parent 8a1260ed48
commit 6438a64fc7
62 changed files with 414 additions and 310 deletions
@@ -141,10 +141,8 @@ impl DiscoveryContext {
let dial_info_filter = DialInfoFilter::all()
.with_protocol_type(protocol_type)
.with_address_type(address_type);
let inbound_dial_info_entry_filter = RoutingTable::make_inbound_dial_info_entry_filter(
routing_domain,
dial_info_filter.clone(),
);
let inbound_dial_info_entry_filter =
RoutingTable::make_inbound_dial_info_entry_filter(routing_domain, dial_info_filter);
let disallow_relays_filter = Box::new(
move |rti: &RoutingTableInner, v: Option<Arc<BucketEntry>>| {
let v = v.unwrap();
@@ -199,7 +197,7 @@ impl DiscoveryContext {
let node = node.filtered_clone(
NodeRefFilter::new()
.with_routing_domain(routing_domain)
.with_dial_info_filter(dial_info_filter.clone()),
.with_dial_info_filter(dial_info_filter),
);
async move {
if let Some(address) = this.request_public_address(node.clone()).await {
@@ -219,9 +217,7 @@ impl DiscoveryContext {
let mut external_address_infos = Vec::new();
for ni in 0..nodes.len() - 1 {
let node = nodes[ni].clone();
for node in nodes.iter().take(nodes.len() - 1).cloned() {
let gpa_future = get_public_address_func(node);
unord.push(gpa_future);
@@ -277,15 +273,15 @@ impl DiscoveryContext {
node_ref.set_filter(None);
// ask the node to send us a dial info validation receipt
let out = rpc_processor
rpc_processor
.rpc_call_validate_dial_info(node_ref.clone(), dial_info, redirect)
.await
.map_err(logthru_net!(
"failed to send validate_dial_info to {:?}",
node_ref
))
.unwrap_or(false);
out
.unwrap_or(false)
}
#[instrument(level = "trace", skip(self), ret)]
@@ -307,9 +303,14 @@ impl DiscoveryContext {
// Attempt a port mapping. If this doesn't succeed, it's not going to
let Some(mapped_external_address) = igd_manager
.map_any_port(low_level_protocol_type, address_type, local_port, Some(external_1.address.to_ip_addr()))
.await else
{
.map_any_port(
low_level_protocol_type,
address_type,
local_port,
Some(external_1.address.ip_addr()),
)
.await
else {
return None;
};
@@ -184,7 +184,7 @@ impl IGDManager {
let mut found = None;
for (pmk, pmv) in &inner.port_maps {
if pmk.llpt == llpt && pmk.at == at && pmv.mapped_port == mapped_port {
found = Some(pmk.clone());
found = Some(*pmk);
break;
}
}
@@ -192,7 +192,7 @@ impl IGDManager {
let _pmv = inner.port_maps.remove(&pmk).expect("key found but remove failed");
// Find gateway
let gw = Self::find_gateway(&mut *inner, at)?;
let gw = Self::find_gateway(&mut inner, at)?;
// Unmap port
match gw.remove_port(convert_llpt(llpt), mapped_port) {
@@ -230,10 +230,10 @@ impl IGDManager {
}
// Get local ip address
let local_ip = Self::find_local_ip(&mut *inner, at)?;
let local_ip = Self::find_local_ip(&mut inner, at)?;
// Find gateway
let gw = Self::find_gateway(&mut *inner, at)?;
let gw = Self::find_gateway(&mut inner, at)?;
// Get external address
let ext_ip = match gw.get_external_ip() {
@@ -245,16 +245,12 @@ impl IGDManager {
};
// Ensure external IP matches address type
if ext_ip.is_ipv4() {
if at != AddressType::IPV4 {
log_net!(debug "mismatched ip address type from igd, wanted v4, got v6");
return None;
}
} else if ext_ip.is_ipv6() {
if at != AddressType::IPV6 {
log_net!(debug "mismatched ip address type from igd, wanted v6, got v4");
return None;
}
if ext_ip.is_ipv4() && at != AddressType::IPV4 {
log_net!(debug "mismatched ip address type from igd, wanted v4, got v6");
return None;
} else if ext_ip.is_ipv6() && at != AddressType::IPV6 {
log_net!(debug "mismatched ip address type from igd, wanted v6, got v4");
return None;
}
if let Some(expected_external_address) = expected_external_address {
@@ -421,7 +421,7 @@ impl Network {
if self
.network_manager()
.address_filter()
.is_ip_addr_punished(dial_info.address().to_ip_addr())
.is_ip_addr_punished(dial_info.address().ip_addr())
{
return Ok(NetworkResult::no_connection_other("punished"));
}
@@ -491,7 +491,7 @@ impl Network {
if self
.network_manager()
.address_filter()
.is_ip_addr_punished(dial_info.address().to_ip_addr())
.is_ip_addr_punished(dial_info.address().ip_addr())
{
return Ok(NetworkResult::no_connection_other("punished"));
}
@@ -519,7 +519,7 @@ impl Network {
.into_network_result())
.wrap_err("recv_message failure")?;
let recv_socket_addr = recv_addr.remote_address().to_socket_addr();
let recv_socket_addr = recv_addr.remote_address().socket_addr();
self.network_manager()
.stats_packet_rcvd(recv_socket_addr.ip(), ByteCount::new(recv_len as u64));
@@ -583,10 +583,10 @@ impl Network {
// Handle connectionless protocol
if descriptor.protocol_type() == ProtocolType::UDP {
// send over the best udp socket we have bound since UDP is not connection oriented
let peer_socket_addr = descriptor.remote().to_socket_addr();
let peer_socket_addr = descriptor.remote().socket_addr();
if let Some(ph) = self.find_best_udp_protocol_handler(
&peer_socket_addr,
&descriptor.local().map(|sa| sa.to_socket_addr()),
&descriptor.local().map(|sa| sa.socket_addr()),
) {
network_result_value_or_log!(ph.clone()
.send_message(data.clone(), peer_socket_addr)
@@ -612,7 +612,7 @@ impl Network {
ConnectionHandleSendResult::Sent => {
// Network accounting
self.network_manager().stats_packet_sent(
descriptor.remote().to_socket_addr().ip(),
descriptor.remote().socket_addr().ip(),
ByteCount::new(data_len as u64),
);
@@ -701,7 +701,7 @@ impl Network {
.with_interfaces(|interfaces| {
trace!("interfaces: {:#?}", interfaces);
for (_name, intf) in interfaces {
for intf in interfaces.values() {
// Skip networks that we should never encounter
if intf.is_loopback() || !intf.is_running() {
continue;
@@ -68,7 +68,7 @@ impl Network {
Ok(Ok((size, descriptor))) => {
// Network accounting
network_manager.stats_packet_rcvd(
descriptor.remote_address().to_ip_addr(),
descriptor.remote_address().ip_addr(),
ByteCount::new(size as u64),
);
@@ -24,7 +24,7 @@ impl ProtocolNetworkConnection {
timeout_ms: u32,
address_filter: AddressFilter,
) -> io::Result<NetworkResult<ProtocolNetworkConnection>> {
if address_filter.is_ip_addr_punished(dial_info.address().to_ip_addr()) {
if address_filter.is_ip_addr_punished(dial_info.address().ip_addr()) {
return Ok(NetworkResult::no_connection_other("punished"));
}
match dial_info.protocol_type() {
@@ -19,7 +19,7 @@ impl RawTcpNetworkConnection {
}
pub fn descriptor(&self) -> ConnectionDescriptor {
self.descriptor.clone()
self.descriptor
}
// #[instrument(level = "trace", err, skip(self))]
@@ -132,11 +132,12 @@ impl RawTcpProtocolHandler {
) -> io::Result<Option<ProtocolNetworkConnection>> {
log_net!("TCP: on_accept_async: enter");
let mut peekbuf: [u8; PEEK_DETECT_LEN] = [0u8; PEEK_DETECT_LEN];
if let Err(_) = timeout(
if (timeout(
self.connection_initial_timeout_ms,
ps.peek_exact(&mut peekbuf),
)
.await
.await)
.is_err()
{
return Ok(None);
}
@@ -79,9 +79,9 @@ impl RawUdpProtocolHandler {
};
#[cfg(feature = "verbose-tracing")]
tracing::Span::current().record("ret.len", &message_len);
tracing::Span::current().record("ret.len", message_len);
#[cfg(feature = "verbose-tracing")]
tracing::Span::current().record("ret.descriptor", &format!("{:?}", descriptor).as_str());
tracing::Span::current().record("ret.descriptor", format!("{:?}", descriptor).as_str());
Ok((message_len, descriptor))
}
@@ -134,7 +134,7 @@ impl RawUdpProtocolHandler {
);
#[cfg(feature = "verbose-tracing")]
tracing::Span::current().record("ret.descriptor", &format!("{:?}", descriptor).as_str());
tracing::Span::current().record("ret.descriptor", format!("{:?}", descriptor).as_str());
Ok(NetworkResult::value(descriptor))
}
@@ -143,7 +143,7 @@ impl RawUdpProtocolHandler {
socket_addr: &SocketAddr,
) -> io::Result<RawUdpProtocolHandler> {
// get local wildcard address for bind
let local_socket_addr = compatible_unspecified_socket_addr(&socket_addr);
let local_socket_addr = compatible_unspecified_socket_addr(socket_addr);
let socket = UdpSocket::bind(local_socket_addr).await?;
Ok(RawUdpProtocolHandler::new(Arc::new(socket), None))
}
@@ -20,7 +20,7 @@ const MAX_WS_BEFORE_BODY: usize = 2048;
cfg_if! {
if #[cfg(feature="rt-async-std")] {
pub type WebsocketNetworkConnectionWSS =
WebsocketNetworkConnection<async_tls::client::TlsStream<TcpStream>>;
DialInfo::WS { field1: _ }ketNetworkConnection<async_tls::client::TlsStream<TcpStream>>;
pub type WebsocketNetworkConnectionWS = WebsocketNetworkConnection<TcpStream>;
} else if #[cfg(feature="rt-tokio")] {
pub type WebsocketNetworkConnectionWSS =
@@ -74,7 +74,7 @@ where
}
pub fn descriptor(&self) -> ConnectionDescriptor {
self.descriptor.clone()
self.descriptor
}
// #[instrument(level = "trace", err, skip(self))]
@@ -232,7 +232,7 @@ impl WebsocketProtocolHandler {
// This check could be loosened if necessary, but until we have a reason to do so
// a stricter interpretation of HTTP is possible and desirable to reduce attack surface
if peek_buf.windows(4).position(|w| w == b"\r\n\r\n").is_none() {
if !peek_buf.windows(4).any(|w| w == b"\r\n\r\n") {
return Ok(None);
}
@@ -339,8 +339,7 @@ impl Callback for WebsocketProtocolHandler {
|| request
.headers()
.iter()
.find(|h| (h.0.as_str().len() + h.1.as_bytes().len()) > MAX_WS_HEADER_LENGTH)
.is_some()
.any(|h| (h.0.as_str().len() + h.1.as_bytes().len()) > MAX_WS_HEADER_LENGTH)
{
let mut error_response = ErrorResponse::new(None);
*error_response.status_mut() = StatusCode::NOT_FOUND;
@@ -312,7 +312,7 @@ impl Network {
// if no other public address is specified
if !detect_address_changes
&& public_address.is_none()
&& routing_table.ensure_dial_info_is_valid(RoutingDomain::PublicInternet, &di)
&& routing_table.ensure_dial_info_is_valid(RoutingDomain::PublicInternet, di)
{
editor_public_internet.register_dial_info(di.clone(), DialInfoClass::Direct)?;
static_public = true;
@@ -449,7 +449,7 @@ impl Network {
for socket_address in socket_addresses {
// Skip addresses we already did
if registered_addresses.contains(&socket_address.to_ip_addr()) {
if registered_addresses.contains(&socket_address.ip_addr()) {
continue;
}
// Build dial info request url
@@ -628,7 +628,7 @@ impl Network {
}
// Register interface dial info
editor_local_network.register_dial_info(di.clone(), DialInfoClass::Direct)?;
registered_addresses.insert(socket_address.to_ip_addr());
registered_addresses.insert(socket_address.ip_addr());
}
// Add static public dialinfo if it's configured