clippy work
This commit is contained in:
@@ -244,12 +244,12 @@ impl AddressFilter {
|
||||
self.unlocked_inner.max_connections_per_ip6_prefix_size,
|
||||
addr,
|
||||
);
|
||||
self.is_ip_addr_punished_inner(&*inner, ipblock)
|
||||
self.is_ip_addr_punished_inner(&inner, ipblock)
|
||||
}
|
||||
|
||||
pub fn get_dial_info_failed_ts(&self, dial_info: &DialInfo) -> Option<Timestamp> {
|
||||
let inner = self.inner.lock();
|
||||
self.get_dial_info_failed_ts_inner(&*inner, dial_info)
|
||||
self.get_dial_info_failed_ts_inner(&inner, dial_info)
|
||||
}
|
||||
|
||||
pub fn set_dial_info_failed(&self, dial_info: DialInfo) {
|
||||
@@ -301,7 +301,7 @@ impl AddressFilter {
|
||||
|
||||
pub fn is_node_id_punished(&self, node_id: TypedKey) -> bool {
|
||||
let inner = self.inner.lock();
|
||||
self.is_node_id_punished_inner(&*inner, node_id)
|
||||
self.is_node_id_punished_inner(&inner, node_id)
|
||||
}
|
||||
|
||||
pub fn punish_node_id(&self, node_id: TypedKey) {
|
||||
@@ -333,8 +333,8 @@ impl AddressFilter {
|
||||
) -> EyreResult<()> {
|
||||
//
|
||||
let mut inner = self.inner.lock();
|
||||
self.purge_old_timestamps(&mut *inner, cur_ts);
|
||||
self.purge_old_punishments(&mut *inner, cur_ts);
|
||||
self.purge_old_timestamps(&mut inner, cur_ts);
|
||||
self.purge_old_punishments(&mut inner, cur_ts);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -411,7 +411,7 @@ impl AddressFilter {
|
||||
);
|
||||
|
||||
let ts = get_aligned_timestamp();
|
||||
self.purge_old_timestamps(&mut *inner, ts);
|
||||
self.purge_old_timestamps(&mut inner, ts);
|
||||
|
||||
match ipblock {
|
||||
IpAddr::V4(v4) => {
|
||||
|
||||
@@ -31,7 +31,7 @@ impl ConnectionHandle {
|
||||
}
|
||||
|
||||
pub fn connection_descriptor(&self) -> ConnectionDescriptor {
|
||||
self.descriptor.clone()
|
||||
self.descriptor
|
||||
}
|
||||
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level="trace", skip(self, message), fields(message.len = message.len())))]
|
||||
|
||||
@@ -117,13 +117,12 @@ impl ConnectionManager {
|
||||
// Remove the inner from the lock
|
||||
let mut inner = {
|
||||
let mut inner_lock = self.arc.inner.lock();
|
||||
let inner = match inner_lock.take() {
|
||||
match inner_lock.take() {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
panic!("not started");
|
||||
}
|
||||
};
|
||||
inner
|
||||
}
|
||||
};
|
||||
|
||||
// Stop all the connections and the async processor
|
||||
@@ -251,7 +250,7 @@ impl ConnectionManager {
|
||||
dial_info: DialInfo,
|
||||
) -> EyreResult<NetworkResult<ConnectionHandle>> {
|
||||
let peer_address = dial_info.to_peer_address();
|
||||
let remote_addr = peer_address.to_socket_addr();
|
||||
let remote_addr = peer_address.socket_addr();
|
||||
let mut preferred_local_address = self
|
||||
.network_manager()
|
||||
.net()
|
||||
|
||||
@@ -164,7 +164,7 @@ impl ConnectionTable {
|
||||
}
|
||||
|
||||
// Filter by ip for connection limits
|
||||
let ip_addr = descriptor.remote_address().to_ip_addr();
|
||||
let ip_addr = descriptor.remote_address().ip_addr();
|
||||
match inner.address_filter.add_connection(ip_addr) {
|
||||
Ok(()) => {}
|
||||
Err(e) => {
|
||||
@@ -196,7 +196,7 @@ impl ConnectionTable {
|
||||
}
|
||||
|
||||
log_net!(debug "== LRU Connection Killed: {} -> {}", lruk, lru_conn.debug_print(get_aligned_timestamp()));
|
||||
out_conn = Some(Self::remove_connection_records(&mut *inner, lruk));
|
||||
out_conn = Some(Self::remove_connection_records(&mut inner, lruk));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -237,11 +237,11 @@ impl ConnectionTable {
|
||||
best_port: Option<u16>,
|
||||
remote: PeerAddress,
|
||||
) -> Option<ConnectionHandle> {
|
||||
let mut inner = self.inner.lock();
|
||||
let inner = &mut *self.inner.lock();
|
||||
|
||||
let all_ids_by_remote = inner.ids_by_remote.get(&remote)?;
|
||||
let protocol_index = Self::protocol_to_index(remote.protocol_type());
|
||||
if all_ids_by_remote.len() == 0 {
|
||||
if all_ids_by_remote.is_empty() {
|
||||
// no connections
|
||||
return None;
|
||||
}
|
||||
@@ -253,11 +253,11 @@ impl ConnectionTable {
|
||||
}
|
||||
// multiple connections, find the one that matches the best port, or the most recent
|
||||
if let Some(best_port) = best_port {
|
||||
for id in all_ids_by_remote.iter().copied() {
|
||||
let nc = inner.conn_by_id[protocol_index].peek(&id).unwrap();
|
||||
for id in all_ids_by_remote {
|
||||
let nc = inner.conn_by_id[protocol_index].peek(id).unwrap();
|
||||
if let Some(local_addr) = nc.connection_descriptor().local() {
|
||||
if local_addr.port() == best_port {
|
||||
let nc = inner.conn_by_id[protocol_index].get(&id).unwrap();
|
||||
let nc = inner.conn_by_id[protocol_index].get(id).unwrap();
|
||||
return Some(nc.get_handle());
|
||||
}
|
||||
}
|
||||
@@ -331,7 +331,7 @@ impl ConnectionTable {
|
||||
}
|
||||
}
|
||||
// address_filter
|
||||
let ip_addr = remote.to_socket_addr().ip();
|
||||
let ip_addr = remote.socket_addr().ip();
|
||||
inner
|
||||
.address_filter
|
||||
.remove_connection(ip_addr)
|
||||
@@ -347,7 +347,7 @@ impl ConnectionTable {
|
||||
if !inner.conn_by_id[protocol_index].contains_key(&id) {
|
||||
return None;
|
||||
}
|
||||
let conn = Self::remove_connection_records(&mut *inner, id);
|
||||
let conn = Self::remove_connection_records(&mut inner, id);
|
||||
Some(conn)
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ impl ConnectionTable {
|
||||
for t in 0..inner.conn_by_id.len() {
|
||||
out += &format!(
|
||||
" {} Connections: ({}/{})\n",
|
||||
Self::index_to_protocol(t).to_string(),
|
||||
Self::index_to_protocol(t),
|
||||
inner.conn_by_id[t].len(),
|
||||
inner.max_connections[t]
|
||||
);
|
||||
|
||||
@@ -61,7 +61,7 @@ pub const PUBLIC_ADDRESS_CHECK_TASK_INTERVAL_SECS: u32 = 60;
|
||||
pub const PUBLIC_ADDRESS_INCONSISTENCY_TIMEOUT_US: TimestampDuration =
|
||||
TimestampDuration::new(300_000_000u64); // 5 minutes
|
||||
pub const PUBLIC_ADDRESS_INCONSISTENCY_PUNISHMENT_TIMEOUT_US: TimestampDuration =
|
||||
TimestampDuration::new(3600_000_000u64); // 60 minutes
|
||||
TimestampDuration::new(3_600_000_000_u64); // 60 minutes
|
||||
pub const ADDRESS_FILTER_TASK_INTERVAL_SECS: u32 = 60;
|
||||
pub const BOOT_MAGIC: &[u8; 4] = b"BOOT";
|
||||
|
||||
@@ -261,7 +261,7 @@ impl NetworkManager {
|
||||
where
|
||||
F: FnOnce(&VeilidConfigInner) -> R,
|
||||
{
|
||||
f(&*self.unlocked_inner.config.get())
|
||||
f(&self.unlocked_inner.config.get())
|
||||
}
|
||||
pub fn storage_manager(&self) -> StorageManager {
|
||||
self.unlocked_inner.storage_manager.clone()
|
||||
@@ -892,7 +892,7 @@ impl NetworkManager {
|
||||
data.len(),
|
||||
connection_descriptor
|
||||
);
|
||||
let remote_addr = connection_descriptor.remote_address().to_ip_addr();
|
||||
let remote_addr = connection_descriptor.remote_address().ip_addr();
|
||||
|
||||
// Network accounting
|
||||
self.stats_packet_rcvd(remote_addr, ByteCount::new(data.len() as u64));
|
||||
@@ -900,7 +900,7 @@ impl NetworkManager {
|
||||
// If this is a zero length packet, just drop it, because these are used for hole punching
|
||||
// and possibly other low-level network connectivity tasks and will never require
|
||||
// more processing or forwarding
|
||||
if data.len() == 0 {
|
||||
if data.is_empty() {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -52,7 +52,7 @@ pub struct DummyNetworkConnection {
|
||||
|
||||
impl DummyNetworkConnection {
|
||||
pub fn descriptor(&self) -> ConnectionDescriptor {
|
||||
self.descriptor.clone()
|
||||
self.descriptor
|
||||
}
|
||||
// pub fn close(&self) -> io::Result<()> {
|
||||
// Ok(())
|
||||
@@ -144,7 +144,7 @@ impl NetworkConnection {
|
||||
local_stop_token,
|
||||
manager_stop_token,
|
||||
connection_id,
|
||||
descriptor.clone(),
|
||||
descriptor,
|
||||
receiver,
|
||||
protocol_connection,
|
||||
stats.clone(),
|
||||
@@ -168,11 +168,11 @@ impl NetworkConnection {
|
||||
}
|
||||
|
||||
pub fn connection_descriptor(&self) -> ConnectionDescriptor {
|
||||
self.descriptor.clone()
|
||||
self.descriptor
|
||||
}
|
||||
|
||||
pub fn get_handle(&self) -> ConnectionHandle {
|
||||
ConnectionHandle::new(self.connection_id, self.descriptor.clone(), self.sender.clone())
|
||||
ConnectionHandle::new(self.connection_id, self.descriptor, self.sender.clone())
|
||||
}
|
||||
|
||||
pub fn is_protected(&self) -> bool {
|
||||
@@ -197,12 +197,12 @@ impl NetworkConnection {
|
||||
message: Vec<u8>,
|
||||
) -> io::Result<NetworkResult<()>> {
|
||||
let ts = get_aligned_timestamp();
|
||||
let out = network_result_try!(protocol_connection.send(message).await?);
|
||||
network_result_try!(protocol_connection.send(message).await?);
|
||||
|
||||
let mut stats = stats.lock();
|
||||
stats.last_message_sent_time.max_assign(Some(ts));
|
||||
|
||||
Ok(NetworkResult::Value(out))
|
||||
Ok(NetworkResult::Value(()))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature="verbose-tracing", instrument(level="trace", skip(stats), fields(ret.len)))]
|
||||
@@ -234,6 +234,7 @@ impl NetworkConnection {
|
||||
}
|
||||
|
||||
// Connection receiver loop
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn process_connection(
|
||||
connection_manager: ConnectionManager,
|
||||
local_stop_token: StopToken,
|
||||
@@ -316,19 +317,19 @@ impl NetworkConnection {
|
||||
let peer_address = protocol_connection.descriptor().remote();
|
||||
|
||||
// Check to see if it is punished
|
||||
if address_filter.is_ip_addr_punished(peer_address.to_socket_addr().ip()) {
|
||||
if address_filter.is_ip_addr_punished(peer_address.socket_addr().ip()) {
|
||||
return RecvLoopAction::Finish;
|
||||
}
|
||||
|
||||
// Check for connection close
|
||||
if v.is_no_connection() {
|
||||
log_net!(debug "Connection closed from: {} ({})", peer_address.to_socket_addr(), peer_address.protocol_type());
|
||||
log_net!(debug "Connection closed from: {} ({})", peer_address.socket_addr(), peer_address.protocol_type());
|
||||
return RecvLoopAction::Finish;
|
||||
}
|
||||
|
||||
// Punish invalid framing (tcp framing or websocket framing)
|
||||
if v.is_invalid_message() {
|
||||
address_filter.punish_ip_addr(peer_address.to_socket_addr().ip());
|
||||
address_filter.punish_ip_addr(peer_address.socket_addr().ip());
|
||||
return RecvLoopAction::Finish;
|
||||
}
|
||||
|
||||
|
||||
@@ -338,7 +338,7 @@ impl NetworkManager {
|
||||
let routing_table = self.routing_table();
|
||||
|
||||
// If a node is punished, then don't try to contact it
|
||||
if target_node_ref.node_ids().iter().find(|nid| self.address_filter().is_node_id_punished(**nid)).is_some() {
|
||||
if target_node_ref.node_ids().iter().any(|nid| self.address_filter().is_node_id_punished(*nid)) {
|
||||
return Ok(NodeContactMethod::Unreachable);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ impl NetworkManager {
|
||||
) -> EyreResult<()> {
|
||||
// go through public_address_inconsistencies_table and time out things that have expired
|
||||
let mut inner = self.inner.lock();
|
||||
for (_, pait_v) in &mut inner.public_address_inconsistencies_table {
|
||||
for pait_v in inner.public_address_inconsistencies_table.values_mut() {
|
||||
let mut expired = Vec::new();
|
||||
for (addr, exp_ts) in pait_v.iter() {
|
||||
if *exp_ts <= cur_ts {
|
||||
@@ -79,7 +79,7 @@ impl NetworkManager {
|
||||
// Get the ip(block) this report is coming from
|
||||
let reporting_ipblock = ip_to_ipblock(
|
||||
ip6_prefix_size,
|
||||
connection_descriptor.remote_address().to_ip_addr(),
|
||||
connection_descriptor.remote_address().ip_addr(),
|
||||
);
|
||||
|
||||
// Reject public address reports from nodes that we know are behind symmetric nat or
|
||||
@@ -94,7 +94,7 @@ impl NetworkManager {
|
||||
// If the socket address reported is the same as the reporter, then this is coming through a relay
|
||||
// or it should be ignored due to local proximity (nodes on the same network block should not be trusted as
|
||||
// public ip address reporters, only disinterested parties)
|
||||
if reporting_ipblock == ip_to_ipblock(ip6_prefix_size, socket_address.to_ip_addr()) {
|
||||
if reporting_ipblock == ip_to_ipblock(ip6_prefix_size, socket_address.ip_addr()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ impl NetworkManager {
|
||||
let pait = inner
|
||||
.public_address_inconsistencies_table
|
||||
.entry(addr_proto_type_key)
|
||||
.or_insert_with(|| HashMap::new());
|
||||
.or_insert_with(HashMap::new);
|
||||
for i in &inconsistencies {
|
||||
pait.insert(*i, exp_ts);
|
||||
}
|
||||
@@ -204,7 +204,7 @@ impl NetworkManager {
|
||||
let pait = inner
|
||||
.public_address_inconsistencies_table
|
||||
.entry(addr_proto_type_key)
|
||||
.or_insert_with(|| HashMap::new());
|
||||
.or_insert_with(HashMap::new);
|
||||
let exp_ts = get_aligned_timestamp()
|
||||
+ PUBLIC_ADDRESS_INCONSISTENCY_PUNISHMENT_TIMEOUT_US;
|
||||
for i in inconsistencies {
|
||||
|
||||
@@ -71,16 +71,16 @@ impl Address {
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn to_ip_addr(&self) -> IpAddr {
|
||||
pub fn ip_addr(&self) -> IpAddr {
|
||||
match self {
|
||||
Self::IPV4(a) => IpAddr::V4(*a),
|
||||
Self::IPV6(a) => IpAddr::V6(*a),
|
||||
}
|
||||
}
|
||||
pub fn to_socket_addr(&self, port: u16) -> SocketAddr {
|
||||
SocketAddr::new(self.to_ip_addr(), port)
|
||||
pub fn socket_addr(&self, port: u16) -> SocketAddr {
|
||||
SocketAddr::new(self.ip_addr(), port)
|
||||
}
|
||||
pub fn to_canonical(&self) -> Address {
|
||||
pub fn canonical(&self) -> Address {
|
||||
match self {
|
||||
Address::IPV4(v4) => Address::IPV4(*v4),
|
||||
Address::IPV6(v6) => match v6.to_ipv4() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![allow(non_snake_case)]
|
||||
use super::*;
|
||||
|
||||
#[allow(clippy::derive_hash_xor_eq)]
|
||||
#[allow(clippy::derived_hash_with_manual_eq)]
|
||||
#[derive(Debug, PartialOrd, Ord, Hash, Serialize, Deserialize, EnumSetType)]
|
||||
#[enumset(repr = "u8")]
|
||||
pub enum AddressType {
|
||||
|
||||
@@ -36,10 +36,10 @@ impl fmt::Display for DialInfo {
|
||||
let split_url = SplitUrl::from_str(&url).unwrap();
|
||||
match split_url.host {
|
||||
SplitUrlHost::Hostname(_) => {
|
||||
write!(f, "ws|{}|{}", di.socket_address.to_ip_addr(), di.request)
|
||||
write!(f, "ws|{}|{}", di.socket_address.ip_addr(), di.request)
|
||||
}
|
||||
SplitUrlHost::IpAddr(a) => {
|
||||
if di.socket_address.to_ip_addr() == a {
|
||||
if di.socket_address.ip_addr() == a {
|
||||
write!(f, "ws|{}", di.request)
|
||||
} else {
|
||||
panic!("resolved address does not match url: {}", di.request);
|
||||
@@ -52,7 +52,7 @@ impl fmt::Display for DialInfo {
|
||||
let split_url = SplitUrl::from_str(&url).unwrap();
|
||||
match split_url.host {
|
||||
SplitUrlHost::Hostname(_) => {
|
||||
write!(f, "wss|{}|{}", di.socket_address.to_ip_addr(), di.request)
|
||||
write!(f, "wss|{}|{}", di.socket_address.ip_addr(), di.request)
|
||||
}
|
||||
SplitUrlHost::IpAddr(_) => {
|
||||
panic!(
|
||||
@@ -143,22 +143,22 @@ impl FromStr for DialInfo {
|
||||
impl DialInfo {
|
||||
pub fn udp_from_socketaddr(socket_addr: SocketAddr) -> Self {
|
||||
Self::UDP(DialInfoUDP {
|
||||
socket_address: SocketAddress::from_socket_addr(socket_addr).to_canonical(),
|
||||
socket_address: SocketAddress::from_socket_addr(socket_addr).canonical(),
|
||||
})
|
||||
}
|
||||
pub fn tcp_from_socketaddr(socket_addr: SocketAddr) -> Self {
|
||||
Self::TCP(DialInfoTCP {
|
||||
socket_address: SocketAddress::from_socket_addr(socket_addr).to_canonical(),
|
||||
socket_address: SocketAddress::from_socket_addr(socket_addr).canonical(),
|
||||
})
|
||||
}
|
||||
pub fn udp(socket_address: SocketAddress) -> Self {
|
||||
Self::UDP(DialInfoUDP {
|
||||
socket_address: socket_address.to_canonical(),
|
||||
socket_address: socket_address.canonical(),
|
||||
})
|
||||
}
|
||||
pub fn tcp(socket_address: SocketAddress) -> Self {
|
||||
Self::TCP(DialInfoTCP {
|
||||
socket_address: socket_address.to_canonical(),
|
||||
socket_address: socket_address.canonical(),
|
||||
})
|
||||
}
|
||||
pub fn try_ws(socket_address: SocketAddress, url: String) -> VeilidAPIResult<Self> {
|
||||
@@ -173,7 +173,7 @@ impl DialInfo {
|
||||
apibail_parse_error!("socket address port doesn't match url port", url);
|
||||
}
|
||||
if let SplitUrlHost::IpAddr(a) = split_url.host {
|
||||
if socket_address.to_ip_addr() != a {
|
||||
if socket_address.ip_addr() != a {
|
||||
apibail_parse_error!(
|
||||
format!("request address does not match socket address: {}", a),
|
||||
socket_address
|
||||
@@ -181,7 +181,7 @@ impl DialInfo {
|
||||
}
|
||||
}
|
||||
Ok(Self::WS(DialInfoWS {
|
||||
socket_address: socket_address.to_canonical(),
|
||||
socket_address: socket_address.canonical(),
|
||||
request: url[5..].to_string(),
|
||||
}))
|
||||
}
|
||||
@@ -203,7 +203,7 @@ impl DialInfo {
|
||||
);
|
||||
}
|
||||
Ok(Self::WSS(DialInfoWSS {
|
||||
socket_address: socket_address.to_canonical(),
|
||||
socket_address: socket_address.canonical(),
|
||||
request: url[6..].to_string(),
|
||||
}))
|
||||
}
|
||||
@@ -244,10 +244,10 @@ impl DialInfo {
|
||||
}
|
||||
pub fn to_ip_addr(&self) -> IpAddr {
|
||||
match self {
|
||||
Self::UDP(di) => di.socket_address.to_ip_addr(),
|
||||
Self::TCP(di) => di.socket_address.to_ip_addr(),
|
||||
Self::WS(di) => di.socket_address.to_ip_addr(),
|
||||
Self::WSS(di) => di.socket_address.to_ip_addr(),
|
||||
Self::UDP(di) => di.socket_address.ip_addr(),
|
||||
Self::TCP(di) => di.socket_address.ip_addr(),
|
||||
Self::WS(di) => di.socket_address.ip_addr(),
|
||||
Self::WSS(di) => di.socket_address.ip_addr(),
|
||||
}
|
||||
}
|
||||
pub fn port(&self) -> u16 {
|
||||
@@ -268,10 +268,10 @@ impl DialInfo {
|
||||
}
|
||||
pub fn to_socket_addr(&self) -> SocketAddr {
|
||||
match self {
|
||||
Self::UDP(di) => di.socket_address.to_socket_addr(),
|
||||
Self::TCP(di) => di.socket_address.to_socket_addr(),
|
||||
Self::WS(di) => di.socket_address.to_socket_addr(),
|
||||
Self::WSS(di) => di.socket_address.to_socket_addr(),
|
||||
Self::UDP(di) => di.socket_address.socket_addr(),
|
||||
Self::TCP(di) => di.socket_address.socket_addr(),
|
||||
Self::WS(di) => di.socket_address.socket_addr(),
|
||||
Self::WSS(di) => di.socket_address.socket_addr(),
|
||||
}
|
||||
}
|
||||
pub fn to_peer_address(&self) -> PeerAddress {
|
||||
@@ -376,11 +376,11 @@ impl DialInfo {
|
||||
"udp" => Self::udp_from_socketaddr(sa),
|
||||
"tcp" => Self::tcp_from_socketaddr(sa),
|
||||
"ws" => Self::try_ws(
|
||||
SocketAddress::from_socket_addr(sa).to_canonical(),
|
||||
SocketAddress::from_socket_addr(sa).canonical(),
|
||||
url.to_string(),
|
||||
)?,
|
||||
"wss" => Self::try_wss(
|
||||
SocketAddress::from_socket_addr(sa).to_canonical(),
|
||||
SocketAddress::from_socket_addr(sa).canonical(),
|
||||
url.to_string(),
|
||||
)?,
|
||||
_ => {
|
||||
@@ -395,13 +395,13 @@ impl DialInfo {
|
||||
match self {
|
||||
DialInfo::UDP(di) => (
|
||||
format!("U{}", di.socket_address.port()),
|
||||
intf::ptr_lookup(di.socket_address.to_ip_addr())
|
||||
intf::ptr_lookup(di.socket_address.ip_addr())
|
||||
.await
|
||||
.unwrap_or_else(|_| di.socket_address.to_string()),
|
||||
),
|
||||
DialInfo::TCP(di) => (
|
||||
format!("T{}", di.socket_address.port()),
|
||||
intf::ptr_lookup(di.socket_address.to_ip_addr())
|
||||
intf::ptr_lookup(di.socket_address.ip_addr())
|
||||
.await
|
||||
.unwrap_or_else(|_| di.socket_address.to_string()),
|
||||
),
|
||||
@@ -447,11 +447,11 @@ impl DialInfo {
|
||||
}
|
||||
pub async fn to_url(&self) -> String {
|
||||
match self {
|
||||
DialInfo::UDP(di) => intf::ptr_lookup(di.socket_address.to_ip_addr())
|
||||
DialInfo::UDP(di) => intf::ptr_lookup(di.socket_address.ip_addr())
|
||||
.await
|
||||
.map(|h| format!("udp://{}:{}", h, di.socket_address.port()))
|
||||
.unwrap_or_else(|_| format!("udp://{}", di.socket_address)),
|
||||
DialInfo::TCP(di) => intf::ptr_lookup(di.socket_address.to_ip_addr())
|
||||
DialInfo::TCP(di) => intf::ptr_lookup(di.socket_address.ip_addr())
|
||||
.await
|
||||
.map(|h| format!("tcp://{}:{}", h, di.socket_address.port()))
|
||||
.unwrap_or_else(|_| format!("tcp://{}", di.socket_address)),
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::*;
|
||||
|
||||
// Keep member order appropriate for sorting < preference
|
||||
// Must match DialInfo order
|
||||
#[allow(clippy::derive_hash_xor_eq)]
|
||||
#[allow(clippy::derived_hash_with_manual_eq)]
|
||||
#[derive(Debug, PartialOrd, Ord, Hash, EnumSetType, Serialize, Deserialize)]
|
||||
#[enumset(repr = "u8")]
|
||||
pub enum LowLevelProtocolType {
|
||||
|
||||
@@ -10,7 +10,7 @@ pub struct PeerAddress {
|
||||
impl PeerAddress {
|
||||
pub fn new(socket_address: SocketAddress, protocol_type: ProtocolType) -> Self {
|
||||
Self {
|
||||
socket_address: socket_address.to_canonical(),
|
||||
socket_address: socket_address.canonical(),
|
||||
protocol_type,
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,8 @@ impl PeerAddress {
|
||||
self.protocol_type
|
||||
}
|
||||
|
||||
pub fn to_socket_addr(&self) -> SocketAddr {
|
||||
self.socket_address.to_socket_addr()
|
||||
pub fn socket_addr(&self) -> SocketAddr {
|
||||
self.socket_address.socket_addr()
|
||||
}
|
||||
|
||||
pub fn address_type(&self) -> AddressType {
|
||||
@@ -42,7 +42,10 @@ impl FromStr for PeerAddress {
|
||||
type Err = VeilidAPIError;
|
||||
fn from_str(s: &str) -> VeilidAPIResult<PeerAddress> {
|
||||
let Some((first, second)) = s.split_once(':') else {
|
||||
return Err(VeilidAPIError::parse_error("PeerAddress is missing a colon: {}", s));
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"PeerAddress is missing a colon: {}",
|
||||
s,
|
||||
));
|
||||
};
|
||||
let protocol_type = ProtocolType::from_str(first)?;
|
||||
let socket_address = SocketAddress::from_str(second)?;
|
||||
|
||||
@@ -3,7 +3,7 @@ use super::*;
|
||||
|
||||
// Keep member order appropriate for sorting < preference
|
||||
// Must match DialInfo order
|
||||
#[allow(clippy::derive_hash_xor_eq)]
|
||||
#[allow(clippy::derived_hash_with_manual_eq)]
|
||||
#[derive(Debug, PartialOrd, Ord, Hash, EnumSetType, Serialize, Deserialize)]
|
||||
#[enumset(repr = "u8")]
|
||||
pub enum ProtocolType {
|
||||
|
||||
@@ -34,27 +34,27 @@ impl SocketAddress {
|
||||
self.port = port
|
||||
}
|
||||
pub fn with_port(&self, port: u16) -> Self {
|
||||
let mut sa = self.clone();
|
||||
let mut sa = *self;
|
||||
sa.port = port;
|
||||
sa
|
||||
}
|
||||
pub fn to_canonical(&self) -> SocketAddress {
|
||||
pub fn canonical(&self) -> SocketAddress {
|
||||
SocketAddress {
|
||||
address: self.address.to_canonical(),
|
||||
address: self.address.canonical(),
|
||||
port: self.port,
|
||||
}
|
||||
}
|
||||
pub fn to_ip_addr(&self) -> IpAddr {
|
||||
self.address.to_ip_addr()
|
||||
pub fn ip_addr(&self) -> IpAddr {
|
||||
self.address.ip_addr()
|
||||
}
|
||||
pub fn to_socket_addr(&self) -> SocketAddr {
|
||||
self.address.to_socket_addr(self.port)
|
||||
pub fn socket_addr(&self) -> SocketAddr {
|
||||
self.address.socket_addr(self.port)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SocketAddress {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "{}", self.to_socket_addr())
|
||||
write!(f, "{}", self.socket_addr())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user