Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy-contentviews/src/protobuf/raw_to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, typ: Type| {
descriptor.field.push(FieldDescriptorProto {
number: Some(field_index as i32),
Expand Down
8 changes: 4 additions & 4 deletions mitmproxy-contentviews/src/protobuf/yaml_to_pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -95,7 +95,7 @@ pub(super) fn apply_replacements(yaml_str: &str) -> anyhow::Result<String> {

/// Ensure that floating point numbers have a ".0" component so that we roundtrip.
fn format_float<T: Display>(val: T) -> String {
let mut ret = format!("{:.}", val);
let mut ret = format!("{val:.}");
if !ret.contains(".") {
ret.push_str(".0");
}
Expand Down
4 changes: 2 additions & 2 deletions mitmproxy-rs/src/contentviews.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Contentview {
pub fn prettify(&self, data: Vec<u8>, metadata: PythonMetadata) -> PyResult<String> {
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.
Expand Down Expand Up @@ -153,7 +153,7 @@ impl InteractiveContentview {
pub fn reencode(&self, data: &str, metadata: PythonMetadata) -> PyResult<Vec<u8>> {
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<String> {
Expand Down
5 changes: 2 additions & 3 deletions mitmproxy-rs/src/dns_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -74,7 +73,7 @@ impl DnsResolver {
#[pyfunction]
pub fn get_system_dns_servers() -> PyResult<Vec<String>> {
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}"))
})
}

Expand Down
2 changes: 1 addition & 1 deletion mitmproxy-rs/src/process_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn active_executables() -> PyResult<Vec<Process>> {
{
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(
Expand Down
4 changes: 2 additions & 2 deletions mitmproxy-rs/src/server/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy-rs/src/server/local_redirector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
fn describe_spec(spec: &str) -> PyResult<String> {
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.
Expand Down Expand Up @@ -97,7 +97,7 @@
#[pyfunction]
#[allow(unused_variables)]
pub fn start_local_redirector(
py: Python<'_>,

Check warning on line 100 in mitmproxy-rs/src/server/local_redirector.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --package mitmproxy-linux-ebpf)

lifetime flowing from input to output with different syntax can be confusing
handle_tcp_stream: PyObject,
handle_udp_stream: PyObject,
) -> PyResult<Bound<PyAny>> {
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy-rs/src/syntax_highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn highlight(text: String, language: &str) -> PyResult<Vec<(&'static str, St
.map(|(tag, text)| (tag.as_str(), text))
.collect()
})
.map_err(|e| PyValueError::new_err(format!("{:?}", e)))
.map_err(|e| PyValueError::new_err(format!("{e:?}")))
}

/// Return the list of all possible syntax highlight tags.
Expand Down
11 changes: 4 additions & 7 deletions mitmproxy-rs/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl PyInteropTask {
if let Err(err) = future.await {
let is_cancelled = Python::with_gil(|py| err.is_instance_of::<CancelledError>(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);
Expand All @@ -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}");
};
},
}
Expand All @@ -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
Expand All @@ -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}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy-rs/src/udp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#[pyfunction]
#[pyo3(signature = (host, port, *, local_addr = None))]
pub fn open_udp_connection(
py: Python<'_>,

Check warning on line 24 in mitmproxy-rs/src/udp_client.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --package mitmproxy-linux-ebpf)

lifetime flowing from input to output with different syntax can be confusing
host: String,
port: u16,
local_addr: Option<(String, u16)>,
Expand Down Expand Up @@ -72,7 +72,7 @@
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,
Expand Down
6 changes: 2 additions & 4 deletions mitmproxy-rs/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<PyOSError, _>(format!(
"Failed to add certificate: {:?}",
e
"Failed to add certificate: {e:?}"
))),
}
}
Expand All @@ -89,8 +88,7 @@ pub fn remove_cert() -> PyResult<()> {
match certificates::remove_cert() {
Ok(_) => Ok(()),
Err(e) => Err(PyErr::new::<PyOSError, _>(format!(
"Failed to remove certificate: {:?}",
e
"Failed to remove certificate: {e:?}"
))),
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/intercept_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ 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}"),
}
}
}

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}"),
}
}
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/network/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/network/icmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down Expand Up @@ -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;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/network/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/network/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
Expand Down
2 changes: 1 addition & 1 deletion src/network/virtual_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}")
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/packet_sources/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/packet_sources/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(crate) fn create_and_bind_udp_socket(addr: SocketAddr) -> Result<UdpSocket>

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
Expand Down Expand Up @@ -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 {
Expand Down
Loading
Loading