Skip to content

Commit

Permalink
make futures small again (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils authored Sep 6, 2024
1 parent 337a1ac commit 0070192
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/network/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn add_network_layer(
transport_commands_rx,
shutdown,
)?;
let h = tokio::spawn(async move { task.run().await });
let h = tokio::spawn(Box::pin(async move { task.run().await }));
Ok((h, network_events_tx, network_commands_rx))
}

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 @@ -101,7 +101,7 @@ pub struct UdpTask {
impl PacketSourceTask for UdpTask {
async fn run(mut self) -> Result<()> {
let transport_events_tx = self.transport_events_tx.clone();
let mut udp_buf = [0; MAX_PACKET_SIZE];
let mut udp_buf = vec![0; MAX_PACKET_SIZE];

let mut packet_needs_sending = false;
let mut packet_payload = Vec::new();
Expand All @@ -120,7 +120,7 @@ impl PacketSourceTask for UdpTask {
permit = Some(p);
},
// ... or process incoming packets
r = self.socket.recv_from(&mut udp_buf), if py_tx_available => {
r = self.socket.recv_from(udp_buf.as_mut_slice()), if py_tx_available => {
if remote_host_closed_conn(&r) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/packet_sources/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl PacketSourceConf for WindowsConf {
Ok((
WindowsTask {
ipc_server,
buf: [0u8; IPC_BUF_SIZE],
buf: vec![0u8; IPC_BUF_SIZE],
net_tx,
net_rx,
conf_rx,
Expand All @@ -123,7 +123,7 @@ impl PacketSourceConf for WindowsConf {

pub struct WindowsTask {
ipc_server: NamedPipeServer,
buf: [u8; IPC_BUF_SIZE],
buf: Vec<u8>,

net_tx: Sender<NetworkEvent>,
net_rx: Receiver<NetworkCommand>,
Expand Down
8 changes: 4 additions & 4 deletions src/packet_sources/wireguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl PacketSourceConf for WireGuardConf {
peers_by_idx,
peers_by_key,
peers_by_ip: HashMap::new(),
wg_buf: [0u8; MAX_PACKET_SIZE],
wg_buf: vec![0u8; MAX_PACKET_SIZE],

net_tx,
net_rx,
Expand All @@ -141,7 +141,7 @@ pub struct WireGuardTask {
net_tx: Sender<NetworkEvent>,
net_rx: Receiver<NetworkCommand>,

wg_buf: [u8; MAX_PACKET_SIZE],
wg_buf: Vec<u8>,
network_task_handle: tokio::task::JoinHandle<Result<()>>,
}

Expand All @@ -151,13 +151,13 @@ impl PacketSourceTask for WireGuardTask {
return Err(anyhow!("No WireGuard peers were configured."));
}

let mut udp_buf = [0; MAX_PACKET_SIZE];
let mut udp_buf = vec![0; MAX_PACKET_SIZE];

loop {
tokio::select! {
exit = &mut self.network_task_handle => break exit.context("network task panic")?.context("network task error")?,
// wait for WireGuard packets incoming on the UDP socket
r = self.socket.recv_from(&mut udp_buf) => {
r = self.socket.recv_from(udp_buf.as_mut_slice()) => {
if remote_host_closed_conn(&r) {
continue;
}
Expand Down

0 comments on commit 0070192

Please sign in to comment.