diff options
author | Hristo Venev <hristo@venev.name> | 2019-09-28 16:20:06 +0000 |
---|---|---|
committer | Hristo Venev <hristo@venev.name> | 2019-09-28 16:20:43 +0000 |
commit | 3a5552509439612accf579becc7cb85a596bd466 (patch) | |
tree | cbb6af2c4217e1ac6c57f904c9de2976e72b052d | |
parent | b20d7f8b89f5e4b065b0a3fee52ece8db6f99a74 (diff) |
PeerConfig -> GlobalConfig
-rw-r--r-- | src/config.rs | 30 | ||||
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/manager/builder.rs | 10 | ||||
-rw-r--r-- | src/manager/mod.rs | 6 |
4 files changed, 25 insertions, 25 deletions
diff --git a/src/config.rs b/src/config.rs index 98a795f..ccdb042 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,14 +20,14 @@ pub struct Source { #[serde(deny_unknown_fields)] #[derive(serde_derive::Serialize, serde_derive::Deserialize, Clone, PartialEq, Eq, Debug)] -pub struct PeerConfig { +pub struct GlobalConfig { #[serde(default = "default_min_keepalive")] pub min_keepalive: u32, #[serde(default = "default_max_keepalive")] pub max_keepalive: u32, } -impl Default for PeerConfig { +impl Default for GlobalConfig { #[inline] fn default() -> Self { Self { @@ -37,6 +37,18 @@ impl Default for PeerConfig { } } +impl GlobalConfig { + 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 + } +} + #[serde(deny_unknown_fields)] #[derive(serde_derive::Serialize, serde_derive::Deserialize, Clone, PartialEq, Eq, Debug)] pub struct UpdaterConfig { @@ -63,7 +75,7 @@ pub struct Config { pub runtime_directory: Option<PathBuf>, #[serde(flatten)] - pub peer_config: PeerConfig, + pub global: GlobalConfig, #[serde(flatten)] pub updater: UpdaterConfig, @@ -72,18 +84,6 @@ pub struct Config { pub sources: HashMap<String, 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 - } -} - #[inline] const fn default_min_keepalive() -> u32 { 10 diff --git a/src/main.rs b/src/main.rs index cfd9c82..438cb3c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,13 +77,13 @@ fn cli_config(args: &mut impl Iterator<Item = OsString>) -> Option<config::Confi if key == "min_keepalive" { arg = args.next()?; let arg = arg.to_str()?; - cfg.peer_config.min_keepalive = u32::from_str(arg).ok()?; + cfg.global.min_keepalive = u32::from_str(arg).ok()?; continue; } if key == "max_keepalive" { arg = args.next()?; let arg = arg.to_str()?; - cfg.peer_config.max_keepalive = u32::from_str(arg).ok()?; + cfg.global.max_keepalive = u32::from_str(arg).ok()?; continue; } if key == "refresh_sec" { diff --git a/src/manager/builder.rs b/src/manager/builder.rs index 9fc2291..3f3e227 100644 --- a/src/manager/builder.rs +++ b/src/manager/builder.rs @@ -47,17 +47,17 @@ pub struct ConfigBuilder<'a> { c: model::Config, err: Vec<ConfigError>, public_key: model::Key, - pc: &'a config::PeerConfig, + gc: &'a config::GlobalConfig, } impl<'a> ConfigBuilder<'a> { #[inline] - pub fn new(public_key: model::Key, pc: &'a config::PeerConfig) -> Self { + pub fn new(public_key: model::Key, gc: &'a config::GlobalConfig) -> Self { Self { c: model::Config::default(), err: vec![], public_key, - pc, + gc, } } @@ -72,11 +72,11 @@ impl<'a> ConfigBuilder<'a> { return; } - let pc = self.pc; + let gc = self.gc; let ent = insert_peer(&mut self.c, &mut self.err, s, &p.peer, |ent| { ent.psk = s.psk.clone(); ent.endpoint = Some(p.endpoint.clone()); - ent.keepalive = pc.fix_keepalive(p.keepalive); + ent.keepalive = gc.fix_keepalive(p.keepalive); }); add_peer(&mut self.err, ent, s, &p.peer) diff --git a/src/manager/mod.rs b/src/manager/mod.rs index 2efa370..680cbad 100644 --- a/src/manager/mod.rs +++ b/src/manager/mod.rs @@ -67,7 +67,7 @@ fn load_file(path: &Path) -> io::Result<Option<Vec<u8>>> { pub struct Manager { dev: wg::Device, - peer_config: config::PeerConfig, + global_config: config::GlobalConfig, sources: Vec<Source>, current: model::Config, runtime_directory: Option<PathBuf>, @@ -78,7 +78,7 @@ impl Manager { pub fn new(ifname: OsString, c: config::Config) -> io::Result<Self> { let mut m = Self { dev: wg::Device::new(ifname)?, - peer_config: c.peer_config, + global_config: c.global, sources: vec![], current: model::Config::default(), runtime_directory: c.runtime_directory, @@ -211,7 +211,7 @@ impl Manager { sources.push((src, sc)); } - let mut cfg = builder::ConfigBuilder::new(public_key, &self.peer_config); + let mut cfg = builder::ConfigBuilder::new(public_key, &self.global_config); for (src, sc) in &sources { for peer in &sc.servers { |