diff options
author | Hristo Venev <hristo@venev.name> | 2019-03-18 11:05:32 +0200 |
---|---|---|
committer | Hristo Venev <hristo@venev.name> | 2019-03-18 11:05:32 +0200 |
commit | ac554b8129d2c43d87a5a0abca6bd097d870fe6d (patch) | |
tree | bcab9de9eed98ccd33698942ce8cd4011ff4e93a /src/config.rs |
Initial commit.
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..6411b3a --- /dev/null +++ b/src/config.rs @@ -0,0 +1,67 @@ +use ::std::collections::HashSet; +use ::serde_derive; +use crate::ip::{Ipv4Set, Ipv6Set}; + +#[serde(deny_unknown_fields)] +#[derive(serde_derive::Serialize, serde_derive::Deserialize)] +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct Source { + pub url: String, + pub psk: Option<String>, + pub ipv4: Ipv4Set, + pub ipv6: Ipv6Set, +} + +#[serde(deny_unknown_fields)] +#[derive(serde_derive::Serialize, serde_derive::Deserialize)] +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct PeerConfig { + #[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)] +#[derive(serde_derive::Serialize, serde_derive::Deserialize)] +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct UpdateConfig { + // Number of seconds between regular updates. + #[serde(default = "default_refresh")] + pub refresh_period: u32, +} + +#[serde(deny_unknown_fields)] +#[derive(serde_derive::Serialize, serde_derive::Deserialize)] +#[derive(Clone, Debug)] +pub struct Config { + pub ifname: String, + #[serde(default = "default_wg_command")] + pub wg_command: String, + + #[serde(flatten)] + pub peers: PeerConfig, + + #[serde(flatten)] + pub update: UpdateConfig, + + pub sources: Vec<Source>, +} + +fn default_wg_command() -> String { + "wg".to_owned() +} + +fn default_min_keepalive() -> u32 { + 10 +} + +fn default_max_keepalive() -> u32 { + 0 +} + +fn default_refresh() -> u32 { + 1200 +} |