diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-23 12:08:35 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-23 12:08:35 +0200 |
commit | ee3599d5507ceee23ef3382dbda9de8e73c54a00 (patch) | |
tree | d681a3f8a5a2d5e7bea779acecd1fc0798285d9e /src/configuration/config.rs | |
parent | Work on platform specific code (Linux) (diff) | |
download | wireguard-rs-ee3599d5507ceee23ef3382dbda9de8e73c54a00.tar.xz wireguard-rs-ee3599d5507ceee23ef3382dbda9de8e73c54a00.zip |
Moved IO traits into platform module
Diffstat (limited to '')
-rw-r--r-- | src/configuration/config.rs | 25 |
1 files changed, 16 insertions, 9 deletions
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<O: BindOwner> { +struct UDPState<O: bind::Owner> { fwmark: Option<u32>, owner: O, port: u16, } -pub struct WireguardConfig<T: Tun, B: PlatformBind> { +pub struct WireguardConfig<T: tun::Tun, B: bind::Platform> { wireguard: Wireguard<T, B>, network: Mutex<Option<UDPState<B::Owner>>>, } +impl<T: tun::Tun, B: bind::Platform> WireguardConfig<T, B> { + fn new(wg: Wireguard<T, B>) -> WireguardConfig<T, B> { + 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<PeerState>; } -impl<T: Tun, B: PlatformBind> Configuration for WireguardConfig<T, B> { +impl<T: tun::Tun, B: bind::Platform> Configuration for WireguardConfig<T, B> { fn set_private_key(&self, sk: Option<StaticSecret>) { self.wireguard.set_key(sk) } |