This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use base64::{decode, encode};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::hash::Hash;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::io;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::time::Instant;
|
||||
@@ -71,7 +71,7 @@ impl Base64Backed for ECCKey {
|
||||
}
|
||||
|
||||
impl ECCKey {
|
||||
pub fn extract_public_key(&self) -> Option<ECCKey> {
|
||||
pub fn public_key(&self) -> Option<ECCKey> {
|
||||
//TODO: Determine whether Self is a private key and only the return public part
|
||||
Some(self.clone())
|
||||
}
|
||||
@@ -95,14 +95,20 @@ impl Base64Backed for SharedKey {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Builder, PartialEq, Eq, Hash, Clone)]
|
||||
#[derive(Debug, Builder, PartialEq, Eq, Clone)]
|
||||
pub struct Interface {
|
||||
pub key: ECCKey,
|
||||
pub port: usize,
|
||||
pub fwmark: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Builder, PartialEq, Eq, Hash, Clone)]
|
||||
impl Hash for Interface {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.key.public_key().hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Builder, PartialEq, Eq, Clone)]
|
||||
pub struct Peer {
|
||||
pub key: ECCKey,
|
||||
#[builder(default = "None")]
|
||||
@@ -121,10 +127,18 @@ pub struct Peer {
|
||||
pub parsed: Instant,
|
||||
}
|
||||
|
||||
impl Hash for Peer {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.key.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Peer {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn dis_opt<'a, T: fmt::Display + 'a>(opt: &Option<T>) -> String {
|
||||
opt.as_ref().map(|s| s.to_string()).unwrap_or(" ".to_string())
|
||||
opt.as_ref()
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or(" ".to_string())
|
||||
}
|
||||
write!(
|
||||
f,
|
||||
@@ -132,9 +146,11 @@ impl fmt::Display for Peer {
|
||||
self.key,
|
||||
dis_opt(&self.shared_key),
|
||||
dis_opt(&self.endpoint),
|
||||
self.allowed_ips.iter()
|
||||
self.allowed_ips
|
||||
.iter()
|
||||
.map(|(ip, sub)| format!(" {}/{}", ip, sub))
|
||||
.collect::<Vec<_>>().join(",")
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user