WIP [CI SKIP]

This commit is contained in:
shimunn
2019-03-19 08:10:45 +01:00
committed by Drone CI
parent 22dd07cc14
commit fc494fe4c0
5 changed files with 196 additions and 259 deletions

47
wg-event-gen/src/model.rs Normal file
View File

@@ -0,0 +1,47 @@
#[macro_use]
extern crate structopt;
#[macro_use]
extern crate derive_builder;
use std::io::Result;
use base64::{decode};
pub enum ECCKey{
PublicKey([u8; 32]),
PrivateKey([u8; 32])
}
impl ECCKey {
fn from_base64<I: AsRef<str>>(key: I) -> Result<ECCKey> {
let key = decode(key.as_ref::<str>())?;
let bytes = [0; 32];
bytes.copy_from_slice(key);
ECCKey::PublicKey(bytes)
}
}
struct SharedKey([u8; 32]);
#[derive(Debug,Builder, PartialEq, Eq, Hash, Clone)]
pub struct Peer {
key: ECCKey,
shared_key: Option<SharedKey>,
endpoint: Option<SocketAddr>,
allowed_ips: Vec<(IpAddr, u8)>,
last_handshake: Option<Duration>,
persistent_keepalive: Option<Duration>,
traffic: (u64, u64),
parsed: time::Timespec,
}
trait WireguardController {
fn peers<'a>(&'a mut self) -> Box<Iterator<Item=Result<Peer>> + 'a>;
fn update_peer(&mut self, peer: &Peer) -> Result<()>;
}