Commit ec1c6e28 authored by David Goulet's avatar David Goulet
Browse files

Make it relay packets



Signed-off-by: default avatarDavid Goulet <dgoulet@ev0ke.net>
parent 8bffcda7
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@
use std::collections::VecDeque;
use std::os::unix::prelude::{AsRawFd, RawFd};

use log::info;
use smoltcp::phy::{Device, DeviceCapabilities, RxToken as SmolRxToken};
use smoltcp::time::Instant;
use tokio::io::unix::AsyncFd;
@@ -50,6 +49,10 @@ where
        std::mem::take(&mut self.recv_queue)
    }

    pub fn put_packet(&mut self, packet: Packet) {
        self.recv_queue.push_back(packet);
    }

    fn queue(
        &'a mut self,
    ) -> Option<(
@@ -98,6 +101,7 @@ where
    }
}

#[derive(Debug)]
pub struct RxToken {
    packet: Packet,
}
@@ -143,6 +147,9 @@ where
    }

    fn transmit(&'a mut self) -> Option<Self::TxToken> {
        self.device.get_mut().transmit().map(|lower| TxToken { lower })
        self.device
            .get_mut()
            .transmit()
            .map(|lower| TxToken { lower })
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -71,10 +71,11 @@ impl OnionTunnel {

            // Handle incoming packet. Drain packets as we process them.
            while let Some(packet) = packets.pop_front() {
                if let Some(tcp_socket) = Parser::parse(packet).take() {
                if let Some(tcp_socket) = Parser::parse(packet.clone()).take() {
                    let socket = TcpSocket::new(self.iface.clone(), tcp_socket);
                    self.proxy(socket);
                }
                self.iface.lock().unwrap().device_mut().put_packet(packet);
            }

            // The second poll we do process packets in the receive queue from the first poll.
+2 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ impl ArtiProxy {
            info!("Reading on socket...");
            tokio::select! {
                r = self.socket.read(&mut buffer[..]) => match r {
                    Ok(_) => info!("{:?}", buffer),
                    Ok(_) => break,
                    Err(_) => break,
                }
            };