closer [CI SKIP]

This commit is contained in:
Drone CI
2019-03-19 15:23:06 +01:00
parent 7491902b34
commit fac5c7c442
2 changed files with 61 additions and 26 deletions

View File

@@ -32,7 +32,6 @@ impl ECCKey {
struct SharedKey([u8; 32]);
#[derive(Debug, Builder, PartialEq, Eq, Hash, Clone)]
#[builder(public)]
pub struct Peer {
key: ECCKey,
#[builder(default = "None")]
@@ -49,6 +48,37 @@ pub struct Peer {
parsed: Instant,
}
impl PeerBuilder {
fn validate(&self) -> Result<(), String> {
if let Some(ref key) = self.key {
Ok(())
} else {
Err("No key supplied".into())
}
}
pub fn is_whole(&self) -> bool {
self.validate().is_ok()
}
pub fn add_allowed_ip(&mut self, ip: (IpAddr, u8)) {
if !self.allowed_ips.is_some() {
self.allowed_ips = Some(Vec::new());
}
self.allowed_ips.map(|ips| ips.push(ip));
}
pub fn add_last_handshake(&mut self, d: Duration) {
if !self.last_handshake.is_some() {
self.last_handshake = Some(Some(d));
} else {
self.last_handshake = self
.last_handshake
.map(|shake| shake.map(|shake| shake + d));
}
}
}
pub trait WireguardController {
fn peers<'a>(&'a mut self) -> io::Result<Box<Iterator<Item = io::Result<Peer>> + 'a>>;