Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Aug 1, 2023
1 parent b80e787 commit 6182c0c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
16 changes: 8 additions & 8 deletions ffi/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::net::SocketAddr;
use std::sync::Arc;
use crate::task::PyInteropTask;
use crate::util::{socketaddr_to_py, string_to_key};
#[allow(unused_imports)]
use anyhow::{anyhow, Result};
use pyo3::prelude::*;
use tokio::{sync::broadcast, sync::mpsc, sync::Notify};
use x25519_dalek::PublicKey;
use mitmproxy::intercept_conf::InterceptConf;
use mitmproxy::network::NetworkTask;
#[cfg(target_os = "macos")]
Expand All @@ -15,8 +12,11 @@ use mitmproxy::packet_sources::wireguard::WireGuardConf;
#[allow(unused_imports)]
use mitmproxy::packet_sources::{ipc, PacketSourceConf, PacketSourceTask};
use mitmproxy::shutdown::ShutdownTask;
use crate::task::PyInteropTask;
use crate::util::{socketaddr_to_py, string_to_key};
use pyo3::prelude::*;
use std::net::SocketAddr;
use std::sync::Arc;
use tokio::{sync::broadcast, sync::mpsc, sync::Notify};
use x25519_dalek::PublicKey;

#[derive(Debug)]
pub struct Server {
Expand Down Expand Up @@ -160,7 +160,7 @@ impl OsProxy {
/// Set a new intercept spec.
pub fn set_intercept(&self, spec: String) -> PyResult<()> {
InterceptConf::try_from(spec.as_str())?;
#[cfg(any(windows, target_os="macos"))]
#[cfg(any(windows, target_os = "macos"))]
self.conf_tx
.send(ipc::FromProxy {
message: Some(ipc::from_proxy::Message::InterceptSpec(spec)),
Expand Down
2 changes: 1 addition & 1 deletion src/intercept_conf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashSet;
use anyhow::bail;
use std::collections::HashSet;

pub type PID = u32;

Expand Down
43 changes: 25 additions & 18 deletions src/packet_sources/macos.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use std::process::Command;
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use std::path::{Path, PathBuf};
use nix::{sys::stat::Mode, unistd::mkfifo};
use tokio::net::unix::pipe;
use tokio::sync::broadcast;
use tokio::sync::mpsc::Sender;
use tokio::sync::mpsc::{unbounded_channel, Receiver, UnboundedReceiver, UnboundedSender};
use crate::messages::{IpPacket, NetworkCommand, NetworkEvent, TunnelInfo};
use crate::network::MAX_PACKET_SIZE;
use crate::packet_sources::ipc::from_redirector::Message::Packet;
use crate::packet_sources::ipc::{FromRedirector, PacketWithMeta};
use crate::packet_sources::{ipc, PacketSourceConf, PacketSourceTask};
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use home::home_dir;
use nix::{sys::stat::Mode, unistd::mkfifo};
use prost::Message;
use std::io::Cursor;
use std::path::{Path, PathBuf};
use std::process::Command;
use tokio::net::unix::pipe;
use tokio::sync::broadcast;
use tokio::sync::mpsc::Sender;
use tokio::sync::mpsc::{unbounded_channel, Receiver, UnboundedReceiver, UnboundedSender};

pub const IPC_BUF_SIZE: usize = MAX_PACKET_SIZE + 4;

Expand All @@ -25,7 +25,7 @@ pub struct PipeServer {
net_rx: pipe::Receiver,
net_tx: pipe::Sender,
filter_rx: pipe::Receiver,
filter_tx:pipe::Sender,
filter_tx: pipe::Sender,
ip_path: PathBuf,
net_path: PathBuf,
filter_path: PathBuf,
Expand All @@ -46,10 +46,20 @@ impl PipeServer {
let (net_rx, net_tx) = Self::create_pipe(&net_path)?;
let (filter_rx, filter_tx) = Self::create_pipe(&filter_path)?;

Ok(PipeServer { ip_rx, ip_tx, net_rx, net_tx, filter_rx, filter_tx, ip_path, net_path, filter_path })
Ok(PipeServer {
ip_rx,
ip_tx,
net_rx,
net_tx,
filter_rx,
filter_tx,
ip_path,
net_path,
filter_path,
})
}

fn create_pipe(path: &PathBuf) -> Result<(pipe::Receiver, pipe::Sender)>{
fn create_pipe(path: &PathBuf) -> Result<(pipe::Receiver, pipe::Sender)> {
if !path.exists() {
match mkfifo(path, Mode::S_IRWXU) {
Ok(_) => println!("created {:?}", path),
Expand All @@ -63,13 +73,10 @@ impl PipeServer {
Ok(rx) => rx,
Err(e) => Err(anyhow!("Failed to open fifo receiver: {:?}", e))?,
};
let tx = match pipe::OpenOptions::new()
.unchecked(true)
.open_sender(&path)
{
let tx = match pipe::OpenOptions::new().unchecked(true).open_sender(&path) {
Ok(tx) => tx,
Err(e) => Err(anyhow!("Failed to open fifo receiver: {:?}", e))?,
};
};

Ok((rx, tx))
}
Expand Down Expand Up @@ -214,7 +221,7 @@ impl PacketSourceTask for MacosTask {
}
},
}
}
}

log::info!("Macos OS proxy task shutting down.");
Ok(())
Expand Down

0 comments on commit 6182c0c

Please sign in to comment.