diff --git a/mitmproxy-contentviews/src/protobuf/existing_proto_definitions.rs b/mitmproxy-contentviews/src/protobuf/existing_proto_definitions.rs index b3a85030..91607355 100644 --- a/mitmproxy-contentviews/src/protobuf/existing_proto_definitions.rs +++ b/mitmproxy-contentviews/src/protobuf/existing_proto_definitions.rs @@ -169,13 +169,12 @@ fn walk_proto_directory(definitions_path: &Path, parser: &mut Parser) -> anyhow: for entry in definitions_path .read_dir() .context("failed to read protobuf directory")? + .flatten() { - if let Ok(entry) = entry { - if entry.metadata()?.is_dir() { - walk_proto_directory(entry.path().as_path(), parser)?; - } else if entry.file_name().to_string_lossy().ends_with(".proto") { - parser.input(entry.path()); - } + if entry.metadata()?.is_dir() { + walk_proto_directory(entry.path().as_path(), parser)?; + } else if entry.file_name().to_string_lossy().ends_with(".proto") { + parser.input(entry.path()); } } Ok(()) diff --git a/mitmproxy-contentviews/src/protobuf/raw_to_proto.rs b/mitmproxy-contentviews/src/protobuf/raw_to_proto.rs index ddb9600e..6a38fbe6 100644 --- a/mitmproxy-contentviews/src/protobuf/raw_to_proto.rs +++ b/mitmproxy-contentviews/src/protobuf/raw_to_proto.rs @@ -111,7 +111,7 @@ fn create_descriptor_proto( } for (field_index, field_values) in field_groups.into_iter() { - let name = Some(format!("unknown_field_{}", field_index)); + let name = Some(format!("unknown_field_{field_index}")); let mut add_int = |name: Option, typ: Type| { descriptor.field.push(FieldDescriptorProto { number: Some(field_index as i32), diff --git a/mitmproxy-contentviews/src/protobuf/yaml_to_pretty.rs b/mitmproxy-contentviews/src/protobuf/yaml_to_pretty.rs index 2a10971f..f9df7bd5 100644 --- a/mitmproxy-contentviews/src/protobuf/yaml_to_pretty.rs +++ b/mitmproxy-contentviews/src/protobuf/yaml_to_pretty.rs @@ -29,12 +29,12 @@ impl Display for NumReprs { .unwrap(); let mut i = self.0.iter().filter(|(t, _)| t != min_typ); - write!(f, "{}", min_val)?; + write!(f, "{min_val}")?; if let Some((t, v)) = i.next() { - write!(f, " # {}: {}", t, v)?; + write!(f, " # {t}: {v}")?; } for (t, v) in i { - write!(f, ", {}: {}", t, v)?; + write!(f, ", {t}: {v}")?; } Ok(()) } @@ -95,7 +95,7 @@ pub(super) fn apply_replacements(yaml_str: &str) -> anyhow::Result { /// Ensure that floating point numbers have a ".0" component so that we roundtrip. fn format_float(val: T) -> String { - let mut ret = format!("{:.}", val); + let mut ret = format!("{val:.}"); if !ret.contains(".") { ret.push_str(".0"); } diff --git a/mitmproxy-rs/src/contentviews.rs b/mitmproxy-rs/src/contentviews.rs index 5fbe0c9f..8da1f62e 100644 --- a/mitmproxy-rs/src/contentviews.rs +++ b/mitmproxy-rs/src/contentviews.rs @@ -107,7 +107,7 @@ impl Contentview { pub fn prettify(&self, data: Vec, metadata: PythonMetadata) -> PyResult { self.0 .prettify(&data, &metadata) - .map_err(|e| PyValueError::new_err(format!("{:?}", e))) + .map_err(|e| PyValueError::new_err(format!("{e:?}"))) } /// Return the priority of this view for rendering data. @@ -153,7 +153,7 @@ impl InteractiveContentview { pub fn reencode(&self, data: &str, metadata: PythonMetadata) -> PyResult> { self.0 .reencode(data, &metadata) - .map_err(|e| PyValueError::new_err(format!("{:?}", e))) + .map_err(|e| PyValueError::new_err(format!("{e:?}"))) } fn __repr__(self_: PyRef<'_, Self>) -> PyResult { diff --git a/mitmproxy-rs/src/dns_resolver.rs b/mitmproxy-rs/src/dns_resolver.rs index 6a473cf9..a367bf2f 100644 --- a/mitmproxy-rs/src/dns_resolver.rs +++ b/mitmproxy-rs/src/dns_resolver.rs @@ -26,8 +26,7 @@ impl DnsResolver { let resolver = mitmproxy::dns::DnsResolver::new(name_servers, use_hosts_file).map_err(|e| { pyo3::exceptions::PyRuntimeError::new_err(format!( - "failed to create dns resolver: {}", - e + "failed to create dns resolver: {e}" )) })?; Ok(Self(Arc::new(resolver))) @@ -74,7 +73,7 @@ impl DnsResolver { #[pyfunction] pub fn get_system_dns_servers() -> PyResult> { DNS_SERVERS.clone().map_err(|e| { - pyo3::exceptions::PyRuntimeError::new_err(format!("failed to get dns servers: {}", e)) + pyo3::exceptions::PyRuntimeError::new_err(format!("failed to get dns servers: {e}")) }) } diff --git a/mitmproxy-rs/src/process_info.rs b/mitmproxy-rs/src/process_info.rs index d90775ca..142b7909 100644 --- a/mitmproxy-rs/src/process_info.rs +++ b/mitmproxy-rs/src/process_info.rs @@ -57,7 +57,7 @@ pub fn active_executables() -> PyResult> { { processes::active_executables() .map(|p| p.into_iter().map(Process).collect()) - .map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(format!("{}", e))) + .map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(format!("{e}"))) } #[cfg(not(any(windows, target_os = "macos", target_os = "linux")))] Err(pyo3::exceptions::PyNotImplementedError::new_err( diff --git a/mitmproxy-rs/src/server/base.rs b/mitmproxy-rs/src/server/base.rs index 9f97472e..cd559d48 100644 --- a/mitmproxy-rs/src/server/base.rs +++ b/mitmproxy-rs/src/server/base.rs @@ -45,7 +45,7 @@ impl Server { T: PacketSourceConf, { let typ = packet_source_conf.name(); - log::debug!("Initializing {} ...", typ); + log::debug!("Initializing {typ} ..."); // Channel used to notify Python land of incoming connections. let (transport_events_tx, transport_events_rx) = mpsc::channel(256); @@ -80,7 +80,7 @@ impl Server { let (shutdown_done_tx, shutdown_done_rx) = shutdown::channel(); tokio::spawn(shutdown_task(tasks, shutdown_done_tx)); - log::debug!("{} successfully initialized.", typ); + log::debug!("{typ} successfully initialized."); Ok(( Server { diff --git a/mitmproxy-rs/src/server/local_redirector.rs b/mitmproxy-rs/src/server/local_redirector.rs index 6390a9e0..a2697f5a 100644 --- a/mitmproxy-rs/src/server/local_redirector.rs +++ b/mitmproxy-rs/src/server/local_redirector.rs @@ -39,7 +39,7 @@ impl LocalRedirector { fn describe_spec(spec: &str) -> PyResult { InterceptConf::try_from(spec) .map(|conf| conf.description()) - .map_err(|e| PyValueError::new_err(format!("{:?}", e))) + .map_err(|e| PyValueError::new_err(format!("{e:?}"))) } /// Set a new intercept spec. diff --git a/mitmproxy-rs/src/syntax_highlight.rs b/mitmproxy-rs/src/syntax_highlight.rs index 9b366cfa..d3326e96 100644 --- a/mitmproxy-rs/src/syntax_highlight.rs +++ b/mitmproxy-rs/src/syntax_highlight.rs @@ -25,7 +25,7 @@ pub fn highlight(text: String, language: &str) -> PyResult(py)); if !is_cancelled { - log::error!("TCP connection handler coroutine raised an exception:\n{}", err); + log::error!("TCP connection handler coroutine raised an exception:\n{err}"); } } active_streams.lock().await.remove(&connection_id); @@ -112,7 +112,7 @@ impl PyInteropTask { Ok(()) }) { - log::error!("Failed to spawn connection handler:\n{}", err); + log::error!("Failed to spawn connection handler:\n{err}"); }; }, } @@ -127,10 +127,7 @@ impl PyInteropTask { // Future is already finished: just await; // Python exceptions are already logged by the wrapper coroutine if let Err(err) = handle.await { - log::warn!( - "TCP connection handler coroutine could not be joined: {}", - err - ); + log::warn!("TCP connection handler coroutine could not be joined: {err}"); } } else { // Future is not finished: abort tokio task @@ -139,7 +136,7 @@ impl PyInteropTask { if let Err(err) = handle.await { if !err.is_cancelled() { // JoinError was not caused by cancellation: coroutine panicked, log error - log::error!("TCP connection handler coroutine panicked: {}", err); + log::error!("TCP connection handler coroutine panicked: {err}"); } } } diff --git a/mitmproxy-rs/src/udp_client.rs b/mitmproxy-rs/src/udp_client.rs index 315404c9..0f26aca0 100644 --- a/mitmproxy-rs/src/udp_client.rs +++ b/mitmproxy-rs/src/udp_client.rs @@ -72,7 +72,7 @@ async fn udp_connect( let socket = if let Some((host, port)) = local_addr { UdpSocket::bind((host.as_str(), port)) .await - .with_context(|| format!("unable to bind to ({}, {})", host, port))? + .with_context(|| format!("unable to bind to ({host}, {port})"))? } else if addrs.iter().any(|x| x.is_ipv4()) { // we initially tried to bind to IPv6 by default if that doesn't fail, // but binding mysteriously works if there are only IPv4 addresses in addrs, diff --git a/mitmproxy-rs/src/util.rs b/mitmproxy-rs/src/util.rs index 02029936..d5a5cfb7 100644 --- a/mitmproxy-rs/src/util.rs +++ b/mitmproxy-rs/src/util.rs @@ -70,8 +70,7 @@ pub fn add_cert(py: Python<'_>, pem: String) -> PyResult<()> { match certificates::add_cert(der, executable_path.to_str().unwrap()) { Ok(_) => Ok(()), Err(e) => Err(PyErr::new::(format!( - "Failed to add certificate: {:?}", - e + "Failed to add certificate: {e:?}" ))), } } @@ -89,8 +88,7 @@ pub fn remove_cert() -> PyResult<()> { match certificates::remove_cert() { Ok(_) => Ok(()), Err(e) => Err(PyErr::new::(format!( - "Failed to remove certificate: {:?}", - e + "Failed to remove certificate: {e:?}" ))), } } diff --git a/src/intercept_conf.rs b/src/intercept_conf.rs index 8cd83554..f9ea8b3a 100755 --- a/src/intercept_conf.rs +++ b/src/intercept_conf.rs @@ -92,8 +92,8 @@ impl TryFrom<&str> for Pattern { impl std::fmt::Display for Action { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Action::Include(pat) => write!(f, "{}", pat), - Action::Exclude(pat) => write!(f, "!{}", pat), + Action::Include(pat) => write!(f, "{pat}"), + Action::Exclude(pat) => write!(f, "!{pat}"), } } } @@ -101,8 +101,8 @@ impl std::fmt::Display for Action { impl std::fmt::Display for Pattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Pattern::Pid(pid) => write!(f, "{}", pid), - Pattern::Process(name) => write!(f, "{}", name), + Pattern::Pid(pid) => write!(f, "{pid}"), + Pattern::Process(name) => write!(f, "{name}"), } } } @@ -148,13 +148,13 @@ impl InterceptConf { .actions .iter() .map(|a| match a { - Action::Include(Pattern::Pid(pid)) => format!("Include PID {}.", pid), + Action::Include(Pattern::Pid(pid)) => format!("Include PID {pid}."), Action::Include(Pattern::Process(name)) => { - format!("Include processes matching \"{}\".", name) + format!("Include processes matching \"{name}\".") } - Action::Exclude(Pattern::Pid(pid)) => format!("Exclude PID {}.", pid), + Action::Exclude(Pattern::Pid(pid)) => format!("Exclude PID {pid}."), Action::Exclude(Pattern::Process(name)) => { - format!("Exclude processes matching \"{}\".", name) + format!("Exclude processes matching \"{name}\".") } }) .collect(); diff --git a/src/messages.rs b/src/messages.rs index b302b58c..5c778d72 100755 --- a/src/messages.rs +++ b/src/messages.rs @@ -205,7 +205,7 @@ impl SmolPacket { IpProtocol::Icmp => IpProtocol::Icmp, IpProtocol::Icmpv6 => IpProtocol::Icmpv6, other => { - log::debug!("TODO: Implement IPv6 next_header logic: {}", other); + log::debug!("TODO: Implement IPv6 next_header logic: {other}"); other } }, diff --git a/src/network/core.rs b/src/network/core.rs index 5ff8a59d..9888210e 100644 --- a/src/network/core.rs +++ b/src/network/core.rs @@ -53,7 +53,7 @@ impl NetworkStack<'_> { IpProtocol::Udp => { match UdpPacket::try_from(packet) { Ok(packet) => self.udp.receive_data(packet, tunnel_info, permit), - Err(e) => log::debug!("Received invalid UDP packet: {}", e), + Err(e) => log::debug!("Received invalid UDP packet: {e}"), }; Ok(()) } diff --git a/src/network/icmp.rs b/src/network/icmp.rs index a89e7b73..613dc822 100644 --- a/src/network/icmp.rs +++ b/src/network/icmp.rs @@ -15,7 +15,7 @@ pub(super) fn handle_icmpv4_echo_request( let mut input_icmpv4_packet = match Icmpv4Packet::new_checked(input_packet.payload_mut()) { Ok(p) => p, Err(e) => { - log::debug!("Received invalid ICMPv4 packet: {}", e); + log::debug!("Received invalid ICMPv4 packet: {e}"); return None; } }; @@ -64,7 +64,7 @@ pub(super) fn handle_icmpv6_echo_request( let mut input_icmpv6_packet = match Icmpv6Packet::new_checked(input_packet.payload_mut()) { Ok(p) => p, Err(e) => { - log::debug!("Received invalid ICMPv6 packet: {}", e); + log::debug!("Received invalid ICMPv6 packet: {e}"); return None; } }; diff --git a/src/network/task.rs b/src/network/task.rs index b1a194aa..6c9e443d 100755 --- a/src/network/task.rs +++ b/src/network/task.rs @@ -79,7 +79,7 @@ impl NetworkTask<'_> { #[cfg(debug_assertions)] if let Some(d) = delay { - log::debug!("Waiting for device timeout: {:?} ...", d); + log::debug!("Waiting for device timeout: {d:?} ..."); } #[cfg(debug_assertions)] diff --git a/src/network/tcp.rs b/src/network/tcp.rs index 36fae2ba..58b135c2 100644 --- a/src/network/tcp.rs +++ b/src/network/tcp.rs @@ -111,7 +111,7 @@ impl TcpHandler<'_> { } // packet with incorrect length Err(e) => { - log::debug!("Received invalid TCP packet ({}) with payload:", e); + log::debug!("Received invalid TCP packet ({e}) with payload:"); log::debug!("{}", pretty_hex(&packet.payload_mut())); return Ok(()); } diff --git a/src/network/virtual_device.rs b/src/network/virtual_device.rs index c0c451ed..3b41c5bb 100755 --- a/src/network/virtual_device.rs +++ b/src/network/virtual_device.rs @@ -86,7 +86,7 @@ impl TxToken for VirtualTxToken<'_> { self.permit.send(NetworkCommand::SendPacket(packet)); } Err(err) => { - log::error!("Failed to parse packet from smol: {:?}", err) + log::error!("Failed to parse packet from smol: {err:?}") } } diff --git a/src/packet_sources/macos.rs b/src/packet_sources/macos.rs index 75554abd..00b1fff3 100644 --- a/src/packet_sources/macos.rs +++ b/src/packet_sources/macos.rs @@ -147,7 +147,7 @@ impl PacketSourceTask for MacOsTask { ); self.connections.spawn(task.run()); }, - Err(e) => log::error!("Error accepting connection from macos-redirector: {}", e) + Err(e) => log::error!("Error accepting connection from macos-redirector: {e}") } }, // pipe through changes to the intercept list @@ -234,7 +234,7 @@ impl ConnectionTask { bail!("no local address") }; SocketAddr::try_from(addr) - .with_context(|| format!("invalid local_address: {:?}", addr))? + .with_context(|| format!("invalid local_address: {addr:?}"))? }; let mut remote_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0); let (command_tx, mut command_rx) = unbounded_channel(); @@ -252,7 +252,7 @@ impl ConnectionTask { ).context("invalid IPC message")?; let dst_addr = { let Some(dst_addr) = &packet.remote_address else { bail!("no remote addr") }; - SocketAddr::try_from(dst_addr).with_context(|| format!("invalid remote_address: {:?}", dst_addr))? + SocketAddr::try_from(dst_addr).with_context(|| format!("invalid remote_address: {dst_addr:?}"))? }; // We can only send ConnectionEstablished once we know the destination address. diff --git a/src/packet_sources/udp.rs b/src/packet_sources/udp.rs index 9fee2ee4..66eb4003 100644 --- a/src/packet_sources/udp.rs +++ b/src/packet_sources/udp.rs @@ -42,7 +42,7 @@ pub(crate) fn create_and_bind_udp_socket(addr: SocketAddr) -> Result sock2 .bind(&addr.into()) - .context(format!("Failed to bind UDP socket to {}", addr))?; + .context(format!("Failed to bind UDP socket to {addr}"))?; let std_sock: std::net::UdpSocket = sock2.into(); std_sock @@ -74,7 +74,7 @@ impl PacketSourceConf for UdpConf { let socket = create_and_bind_udp_socket(self.listen_addr)?; let local_addr: SocketAddr = socket.local_addr()?; - log::debug!("UDP server listening on {} ...", local_addr); + log::debug!("UDP server listening on {local_addr} ..."); Ok(( UdpTask { diff --git a/src/packet_sources/wireguard.rs b/src/packet_sources/wireguard.rs index bd3ea24c..4e0fe7a0 100755 --- a/src/packet_sources/wireguard.rs +++ b/src/packet_sources/wireguard.rs @@ -85,10 +85,7 @@ impl PacketSourceConf for WireGuardConf { let socket = create_and_bind_udp_socket(self.listen_addr)?; let local_addr = socket.local_addr()?; - log::debug!( - "WireGuard server listening for UDP connections on {} ...", - local_addr - ); + log::debug!("WireGuard server listening for UDP connections on {local_addr} ..."); let public_key = PublicKey::from(&self.private_key); @@ -177,7 +174,7 @@ impl WireGuardTask { let packet = match Tunn::parse_incoming_packet(data) { Ok(p) => p, Err(error) => { - log::error!("Received invalid WireGuard packet: {:?}", error); + log::error!("Received invalid WireGuard packet: {error:?}"); return None; } }; @@ -189,10 +186,7 @@ impl WireGuardTask { let handshake = match parsed { Ok(hs) => hs, Err(error) => { - log::info!( - "Failed to process a WireGuard handshake packet: {:?}", - error - ); + log::info!("Failed to process a WireGuard handshake packet: {error:?}"); return None; } }; @@ -254,7 +248,7 @@ impl WireGuardTask { Wait for the next session handshake or reconnect your client." ); } else { - log::debug!("WG::process_incoming_datagram: Err: {:?}", error); + log::debug!("WG::process_incoming_datagram: Err: {error:?}"); } } TunnResult::WriteToTunnelV4(buf, src_addr) => { @@ -284,7 +278,7 @@ impl WireGuardTask { }; } Err(error) => { - log::warn!("Invalid IPv4 packet: {}", error); + log::warn!("Invalid IPv4 packet: {error}"); } } } @@ -315,7 +309,7 @@ impl WireGuardTask { }; } Err(error) => { - log::warn!("Invalid IPv6 packet: {}", error); + log::warn!("Invalid IPv6 packet: {error}"); } } } @@ -361,7 +355,7 @@ impl WireGuardTask { log::trace!("WG::process_outgoing_packet: Done"); } TunnResult::Err(error) => { - log::error!("WG::process_outgoing_packet: Err: {:?}", error); + log::error!("WG::process_outgoing_packet: Err: {error:?}"); } TunnResult::WriteToNetwork(buf) => { let dst_addr = peer.endpoint.unwrap(); diff --git a/src/shutdown.rs b/src/shutdown.rs index da19307e..b232280e 100755 --- a/src/shutdown.rs +++ b/src/shutdown.rs @@ -41,9 +41,9 @@ pub async fn shutdown_task(mut tasks: JoinSet>, shutdown_done: watch: } Err(error) => { if error.is_cancelled() { - log::error!("Task cancelled: {}", error); + log::error!("Task cancelled: {error}"); } else { - log::error!("Task panicked: {}", error); + log::error!("Task panicked: {error}"); } tasks.shutdown().await; }