aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
blob: 833b546bd7b35c6a817a006d5a1d90b9ac8eb90f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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)]
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, 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, 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, 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
}