closer [CI SKIP]
This commit is contained in:
@@ -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>>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user