From ee3599d5507ceee23ef3382dbda9de8e73c54a00 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Wed, 23 Oct 2019 12:08:35 +0200 Subject: Moved IO traits into platform module --- src/configuration/config.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/configuration/config.rs') diff --git a/src/configuration/config.rs b/src/configuration/config.rs index 24b1349..f42b53b 100644 --- a/src/configuration/config.rs +++ b/src/configuration/config.rs @@ -2,10 +2,8 @@ use spin::Mutex; use std::net::{IpAddr, SocketAddr}; use x25519_dalek::{PublicKey, StaticSecret}; -use super::BindOwner; -use super::PlatformBind; -use super::Tun; -use super::Wireguard; +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), @@ -21,17 +19,26 @@ pub struct PeerState { allowed_ips: Vec<(IpAddr, u32)>, } -struct UDPState { +struct UDPState { fwmark: Option, owner: O, port: u16, } -pub struct WireguardConfig { +pub struct WireguardConfig { wireguard: Wireguard, network: Mutex>>, } +impl WireguardConfig { + fn new(wg: Wireguard) -> WireguardConfig { + WireguardConfig { + wireguard: wg, + network: Mutex::new(None), + } + } +} + pub enum ConfigError { NoSuchPeer, NotListening, @@ -41,8 +48,8 @@ impl ConfigError { fn errno(&self) -> i32 { // TODO: obtain the correct error values match self { - NoSuchPeer => 1, - NotListening => 2, + ConfigError::NoSuchPeer => 1, + ConfigError::NotListening => 2, } } } @@ -180,7 +187,7 @@ pub trait Configuration { fn get_peers(&self) -> Vec; } -impl Configuration for WireguardConfig { +impl Configuration for WireguardConfig { fn set_private_key(&self, sk: Option) { self.wireguard.set_key(sk) } -- cgit v1.2.3-59-g8ed1b