Make IO traits suitable for Tun events (up/down)

This commit is contained in:
Mathias Hall-Andersen
2019-11-24 18:41:43 +01:00
parent dee23969f5
commit 3bff078e3f
20 changed files with 186 additions and 126 deletions

View File

@@ -4,8 +4,8 @@ use std::sync::atomic::Ordering;
use std::time::{Duration, SystemTime};
use x25519_dalek::{PublicKey, StaticSecret};
use super::udp::Owner;
use super::*;
use bind::Owner;
/// The goal of the configuration interface is, among others,
/// to hide the IO implementations (over which the WG device is generic),
@@ -26,13 +26,13 @@ pub struct PeerState {
pub preshared_key: [u8; 32], // 0^32 is the "default value"
}
pub struct WireguardConfig<T: tun::Tun, B: bind::PlatformBind> {
pub struct WireguardConfig<T: tun::Tun, B: udp::PlatformUDP> {
wireguard: Wireguard<T, B>,
fwmark: Mutex<Option<u32>>,
network: Mutex<Option<B::Owner>>,
}
impl<T: tun::Tun, B: bind::PlatformBind> WireguardConfig<T, B> {
impl<T: tun::Tun, B: udp::PlatformUDP> WireguardConfig<T, B> {
pub fn new(wg: Wireguard<T, B>) -> WireguardConfig<T, B> {
WireguardConfig {
wireguard: wg,
@@ -170,7 +170,7 @@ pub trait Configuration {
fn get_fwmark(&self) -> Option<u32>;
}
impl<T: tun::Tun, B: bind::PlatformBind> Configuration for WireguardConfig<T, B> {
impl<T: tun::Tun, B: udp::PlatformUDP> Configuration for WireguardConfig<T, B> {
fn get_fwmark(&self) -> Option<u32> {
self.network
.lock()