WIP [CI SKIP]
This commit is contained in:
47
wg-event-gen/src/model.rs
Normal file
47
wg-event-gen/src/model.rs
Normal 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<()>;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user