From 57dcea424146d43ffa2c2d18689f8d2799257d15 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 21 Jul 2021 23:38:43 +0100 Subject: [PATCH] wip optiona nnd config parser Signed-off-by: Ian Jackson --- .dir-locals.el | 1 + README.config | 13 +++++++++++ src/bin/client.rs | 7 +++++- src/config.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 3 +++ src/prelude.rs | 12 ++++++++++ 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 .dir-locals.el create mode 100644 src/config.rs create mode 100644 src/prelude.rs diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..7210430 --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1 @@ +((rust-mode . ((rust-indent-offset . 2)))) diff --git a/README.config b/README.config index 842573c..3c3a169 100644 --- a/README.config +++ b/README.config @@ -11,6 +11,19 @@ Keys are looked up in that order, unless otherwise specified. is the client's virtual address. must be a valid DNS hostname and not look like an address. + +Both client and server read all files + /etc/hippotat/main.cfg + /etc/hippotat/config.d + /etc/hippotat/server.d +and in each case if it's a directory, all contained files whose +names consists of only ascii alphanumerics plus '-' and '_'. +The ini file format sections from these files are all unioned. + +(If main.cfg does not exist, master.cfg will be tried for backward +compatibility reasons.) + + Exceptional settings: server diff --git a/src/bin/client.rs b/src/bin/client.rs index e00cb9c..b8d2cf5 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -2,4 +2,9 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. -fn main() { } +use hippotat::prelude::*; + +fn main() { + let opts = config::Opts::from_args(); + eprintln!("{:#?}", &opts); +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..a048245 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,56 @@ +// Copyright 2021 Ian Jackson and contributors to Hippotat +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +use crate::prelude::*; + +#[derive(StructOpt,Debug)] +pub struct Opts { + /// Default config file or directory + /// + /// Look for `main.cfg`, `config.d` and `secrets.d` here. + /// + /// Or if this is a file, just read that file. + #[structopt(long, default_value="/etc/hippotat")] + pub config: PathBuf, + + /// Read this in addition, after the other config files + #[structopt(long, multiple=true, number_of_values=1)] + pub extra_config: Vec, +} + +pub struct CidrString(pub String); + +pub struct InstanceConfig { + // Exceptional settings + pub server: String, + pub secret: String, + pub ipif: String, + + // Capped settings: + pub max_batch_down: u32, + pub max_queue_time: Duration, + pub http_timeout: Duration, + + // Ordinary settings: + pub target_requests_outstanding: u32, + pub addrs: Vec, + pub vnetwork: Vec, + pub vaddr: Vec, + pub vrelay: IpAddr, + pub port: u16, + pub mtu: u32, + pub ifname_server: String, + pub ifname_client: String, + + // Ordinary settings, used by server only: + pub max_clock_skew: Duration, + + // Ordinary settings, used by client only: + pub http_timeout_grace: Duration, + pub max_requests_outstanding: u32, + pub max_batch_up: u32, + pub http_retry: Duration, + pub url: Uri, + pub vroutes: Vec, +} diff --git a/src/lib.rs b/src/lib.rs index 89c165b..acd51bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,3 +2,6 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. +pub mod prelude; + +pub mod config; diff --git a/src/prelude.rs b/src/prelude.rs new file mode 100644 index 0000000..6783d35 --- /dev/null +++ b/src/prelude.rs @@ -0,0 +1,12 @@ +// Copyright 2021 Ian Jackson and contributors to Hippotat +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +pub use hyper::Uri; +pub use structopt::StructOpt; +pub use tokio::time::Duration; + +pub use std::net::IpAddr; +pub use std::path::PathBuf; + +pub use crate::config; -- 2.30.2