Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
octol committed Oct 24, 2023
1 parent 1e2f898 commit e5d567b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions common/wireguard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub async fn start_wireguard(
let (tun, tun_task_tx, tun_task_response_rx) = tun_device::TunDevice::new(peers_by_ip.clone());
tun.start();

// If we want to have the tun device on a separate host, it's the tun_task and
// tun_task_response channels that needs to be sent over the network to the host where the tun
// device is running.

// The packet relayer's responsibility is to route packets between the correct tunnel and the
// tun device. The tun device may or may not be on a separate host, which is why we can't do
// this routing in the tun device itself.
Expand Down
12 changes: 7 additions & 5 deletions common/wireguard/src/wg_tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use boringtun::{
};
use bytes::Bytes;
use log::{debug, error, info, warn};
use rand::RngCore;
use tap::TapFallible;
use tokio::{
net::UdpSocket,
Expand Down Expand Up @@ -90,7 +91,7 @@ impl WireGuardTunnel {
index,
rate_limiter,
)
.unwrap(),
.expect("failed to create Tunn instance"),
));

// Channels with incoming data that is received by the main event loop
Expand All @@ -102,10 +103,7 @@ impl WireGuardTunnel {
let mut allowed_ips = NetworkTable::new();
allowed_ips.insert(peer_allowed_ips, ());

// random u64
use rand::RngCore;
let mut rng = rand::rngs::OsRng;
let tag = rng.next_u64();
let tag = Self::new_tag();

let tunnel = WireGuardTunnel {
peer_rx,
Expand All @@ -122,6 +120,10 @@ impl WireGuardTunnel {
(tunnel, peer_tx, tag)
}

fn new_tag() -> u64 {
rand::thread_rng().next_u64()
}

fn close(&self) {
let _ = self.close_tx.send(());
}
Expand Down

0 comments on commit e5d567b

Please sign in to comment.