aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorHristo Venev <hristo@venev.name>2019-03-18 13:42:37 +0200
committerHristo Venev <hristo@venev.name>2019-03-18 13:42:37 +0200
commit87aa7ff470e93e412502cd5341f110fa74de03a1 (patch)
treebc24251bc4a98a049a1a9c451282ddca2e138c8c /src/config.rs
parent761a87cc6e64990b9dd0e235047e1d1e7c7d6971 (diff)
Implement road warrior support.
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs
index 833b546..9124902 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,6 +1,5 @@
use crate::ip::{Ipv4Set, Ipv6Set};
use serde_derive;
-use std::collections::HashSet;
#[serde(deny_unknown_fields)]
#[derive(serde_derive::Serialize, serde_derive::Deserialize, Clone, PartialEq, Eq, Debug)]
@@ -14,12 +13,11 @@ pub struct Source {
#[serde(deny_unknown_fields)]
#[derive(serde_derive::Serialize, serde_derive::Deserialize, Clone, PartialEq, Eq, Debug)]
pub struct PeerConfig {
+ pub own_public_key: String,
#[serde(default = "default_min_keepalive")]
pub min_keepalive: u32,
#[serde(default = "default_max_keepalive")]
pub max_keepalive: u32,
-
- pub omit_peers: HashSet<String>,
}
#[serde(deny_unknown_fields)]
@@ -46,6 +44,18 @@ pub struct Config {
pub sources: Vec<Source>,
}
+impl PeerConfig {
+ pub fn fix_keepalive(&self, mut k: u32) -> u32 {
+ if self.max_keepalive != 0 && (k == 0 || k > self.max_keepalive) {
+ k = self.max_keepalive;
+ }
+ if k != 0 && k < self.min_keepalive {
+ k = self.min_keepalive;
+ }
+ k
+ }
+}
+
fn default_wg_command() -> String {
"wg".to_owned()
}