chiark / gitweb /
wip optiona nnd config parser
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 21 Jul 2021 22:38:43 +0000 (23:38 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 21 Jul 2021 22:38:43 +0000 (23:38 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
.dir-locals.el [new file with mode: 0644]
README.config
src/bin/client.rs
src/config.rs [new file with mode: 0644]
src/lib.rs
src/prelude.rs [new file with mode: 0644]

diff --git a/.dir-locals.el b/.dir-locals.el
new file mode 100644 (file)
index 0000000..7210430
--- /dev/null
@@ -0,0 +1 @@
+((rust-mode . ((rust-indent-offset . 2))))
index 842573cd6a153ca9d9f1e1f7041a2c066e8ea468..3c3a169b30fc531b49741e03b90378b1bef9b1b0 100644 (file)
@@ -11,6 +11,19 @@ Keys are looked up in that order, unless otherwise specified.
 <client> is the client's virtual address.
 <servername> must be a valid DNS hostname and not look like an address.
 
 <client> is the client's virtual address.
 <servername> 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
 Exceptional settings:
 
   server
index e00cb9c1bb43911992018d4ad5d149c3b2c06c1f..b8d2cf5a1edd586f017eb9679f04fa055466a9af 100644 (file)
@@ -2,4 +2,9 @@
 // SPDX-License-Identifier: AGPL-3.0-or-later
 // There is NO WARRANTY.
 
 // 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 (file)
index 0000000..a048245
--- /dev/null
@@ -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<PathBuf>,
+}
+
+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<IpAddr>,
+  pub vnetwork:                     Vec<CidrString>,
+  pub vaddr:                        Vec<IpAddr>,
+  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<CidrString>,
+}
index 89c165b5c95785149039e9f11070847af2548a29..acd51bd110b63523f5ba03743948150030784b6d 100644 (file)
@@ -2,3 +2,6 @@
 // SPDX-License-Identifier: AGPL-3.0-or-later
 // There is NO WARRANTY.
 
 // 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 (file)
index 0000000..6783d35
--- /dev/null
@@ -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;