mirror of
https://github.com/aramperes/onetun.git
synced 2025-09-09 12:18:31 -04:00
Working (slow for some reason)
This commit is contained in:
parent
f65a1e4e89
commit
4f10afd323
1 changed files with 8 additions and 4 deletions
|
@ -3,15 +3,20 @@ use smoltcp::phy::{Device, DeviceCapabilities, Medium};
|
||||||
use smoltcp::time::Instant;
|
use smoltcp::time::Instant;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct VirtualIpDevice {
|
pub struct VirtualIpDevice {
|
||||||
/// Tunnel to send IP packets to.
|
/// Tunnel to send IP packets to.
|
||||||
wg: Arc<WireGuardTunnel>,
|
wg: Arc<WireGuardTunnel>,
|
||||||
|
ip_broadcast_rx: tokio::sync::broadcast::Receiver<Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualIpDevice {
|
impl VirtualIpDevice {
|
||||||
pub fn new(wg: Arc<WireGuardTunnel>) -> Self {
|
pub fn new(wg: Arc<WireGuardTunnel>) -> Self {
|
||||||
Self { wg }
|
let ip_broadcast_rx = wg.subscribe();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
wg,
|
||||||
|
ip_broadcast_rx,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +25,7 @@ impl<'a> Device<'a> for VirtualIpDevice {
|
||||||
type TxToken = TxToken;
|
type TxToken = TxToken;
|
||||||
|
|
||||||
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
|
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
|
||||||
let mut consumer = self.wg.subscribe();
|
match self.ip_broadcast_rx.try_recv() {
|
||||||
match consumer.try_recv() {
|
|
||||||
Ok(buffer) => Some((
|
Ok(buffer) => Some((
|
||||||
Self::RxToken { buffer },
|
Self::RxToken { buffer },
|
||||||
Self::TxToken {
|
Self::TxToken {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue