Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Razz4780 committed Oct 20, 2023
1 parent ba4f164 commit 1feb20b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 34 deletions.
2 changes: 1 addition & 1 deletion mirrord/intproxy/src/agent_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl AgentConnection {

wrap_raw_connection(stream)
} else {
return Err(AgentConnectionError::NoConnectionMethod.into());
return Err(AgentConnectionError::NoConnectionMethod);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion mirrord/intproxy/src/proxies/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl IncomingProxy {
self.remote_subscriptions.clone_all(child, parent);
}

async fn handle_layer_close(&mut self, msg: LayerClosed, message_bus: &mut MessageBus<Self>) {
async fn handle_layer_close(&mut self, msg: LayerClosed, message_bus: &MessageBus<Self>) {
let LayerClosed { id } = msg;
for to_close in self.remote_subscriptions.remove_all(id) {
let Some(subscription) = self.subscriptions.remove(&to_close) else {
Expand Down
2 changes: 1 addition & 1 deletion mirrord/intproxy/src/proxies/incoming/raw_interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl BackgroundTask for RawInterceptor {

res = read_half.read(&mut buffer[..]) => match res {
Err(e) if e.kind() == ErrorKind::WouldBlock => {},
Err(e) => break Err(e.into()),
Err(e) => break Err(e),
Ok(0) => break Ok(()),
Ok(read) => {
message_bus.send(InterceptorMessageOut::Bytes(buffer.get(..read).unwrap().to_vec())).await;
Expand Down
12 changes: 1 addition & 11 deletions mirrord/intproxy/src/proxies/outgoing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl fmt::Display for InterceptorId {
/// 6. The proxy passes the data between the agent and the [`Interceptor`] task.
/// 7. If the layer closes the connection, the [`Interceptor`] exits and the proxy notifies the
/// agent. If the agent closes the connection, the proxy shuts down the [`Interceptor`].
#[derive(Default)]
pub struct OutgoingProxy {
/// For [`OutgoingConnectRequest`]s related to [`NetProtocol::Datagrams`].
datagrams_reqs: RequestQueue,
Expand All @@ -87,17 +88,6 @@ pub struct OutgoingProxy {
background_tasks: BackgroundTasks<InterceptorId, Vec<u8>, io::Error>,
}

impl Default for OutgoingProxy {
fn default() -> Self {
Self {
datagrams_reqs: Default::default(),
stream_reqs: Default::default(),
txs: Default::default(),
background_tasks: Default::default(),
}
}
}

impl OutgoingProxy {
/// Used when registering new [`Interceptor`] tasks in the [`BackgroundTasks`] struct.
const CHANNEL_SIZE: usize = 512;
Expand Down
2 changes: 1 addition & 1 deletion mirrord/intproxy/src/proxies/outgoing/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl BackgroundTask for Interceptor {
continue;
},
Err(e) => break Err(e),
Ok(bytes) if bytes.len() == 0 => break Ok(()),
Ok(bytes) if bytes.is_empty() => break Ok(()),
Ok(bytes) => message_bus.send(bytes).await,
},

Expand Down
24 changes: 12 additions & 12 deletions mirrord/layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
extern crate alloc;
extern crate core;

use std::{ffi::OsString, panic, sync::OnceLock, time::Duration};
use std::{cmp::Ordering, ffi::OsString, panic, sync::OnceLock, time::Duration};

use ctor::ctor;
use error::{LayerError, Result};
Expand Down Expand Up @@ -474,19 +474,19 @@ pub(crate) unsafe extern "C" fn fork_detour() -> pid_t {

let res = FN_FORK();

if res == 0 {
tracing::debug!("Child process initializing layer.");
match res.cmp(&0) {
Ordering::Equal => {
tracing::debug!("Child process initializing layer.");

PROXY_CONNECTION.take();
PROXY_CONNECTION
.set(new_connection)
.expect("setting PROXY_CONNECTION");
PROXY_CONNECTION.take();
PROXY_CONNECTION
.set(new_connection)
.expect("setting PROXY_CONNECTION");

mirrord_layer_entry_point()
} else if res > 0 {
tracing::debug!("Child process id is {res}.");
} else {
tracing::debug!("fork failed");
mirrord_layer_entry_point()
}
Ordering::Greater => tracing::debug!("Child process id is {res}."),
Ordering::Less => tracing::debug!("fork failed"),
}

res
Expand Down
13 changes: 7 additions & 6 deletions mirrord/layer/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,13 @@ impl OutgoingSelector {
protocol: NetProtocol,
) -> Detour<ConnectionThrough> {
// Closure that checks if the current filter matches the enabled protocols.
let filter_protocol = move |outgoing: &&OutgoingFilter| match (outgoing.protocol, protocol)
{
(ProtocolFilter::Any, _) => true,
(ProtocolFilter::Tcp, NetProtocol::Stream) => true,
(ProtocolFilter::Udp, NetProtocol::Datagrams) => true,
_ => false,
let filter_protocol = move |outgoing: &&OutgoingFilter| {
matches!(
(outgoing.protocol, protocol),
(ProtocolFilter::Any, _)
| (ProtocolFilter::Tcp, NetProtocol::Stream)
| (ProtocolFilter::Udp, NetProtocol::Datagrams)
)
};

// Closure to skip hostnames, as these filters will be dealt with after being resolved.
Expand Down
2 changes: 1 addition & 1 deletion mirrord/layer/src/socket/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ pub(super) fn listen(sockfd: RawFd, backlog: c_int) -> Detour<i32> {
}

common::make_proxy_request_with_response(PortSubscribe {
listening_on: address.into(),
listening_on: address,
subscription: crate::setup()
.incoming_mode()
.subscription(requested_address.port()),
Expand Down

0 comments on commit 1feb20b

Please sign in to comment.