chiark / gitweb /
wip server
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 Aug 2021 23:22:36 +0000 (00:22 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 Aug 2021 23:22:36 +0000 (00:22 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Cargo.toml
src/bin/client.rs
src/bin/server.rs [new file with mode: 0644]
src/reporter.rs

index dbc828592a420488490c7aecf272a966477c4be3..121227544b07c1f64a3418cda6ecb42b811e6880 100644 (file)
@@ -17,6 +17,10 @@ members = ["macros"]
 name="hippotat"
 path="src/bin/client.rs"
 
+[[bin]]
+name="hippotatd"
+path="src/bin/server.rs"
+
 [dependencies]
 
 hippotat-macros = { path = "macros" }
index 8bd80133573c18443acd4a2d816615179baaf746..74b1d4ba3674b74c9ad4078b904342c434a17f8b 100644 (file)
@@ -9,9 +9,8 @@ const MAX_BATCH_DOWN_RESP_OVERHEAD: usize = 10_000;
 
 #[derive(StructOpt,Debug)]
 pub struct Opts {
-  /// Increase debug level
-  #[structopt(long, short="D", parse(from_occurrences))]
-  debug: usize,
+  #[structopt(flatten)]
+  log: LogOpts,
 
   #[structopt(flatten)]
   config: config::Opts,
@@ -319,22 +318,7 @@ async fn main() -> Result<(), AE> {
   let ics = config::read(&opts.config, LinkEnd::Client)?;
   if ics.is_empty() { throw!(anyhow!("no associations with server(s)")); }
 
-  {
-    let env = env_logger::Env::new()
-      .filter("HIPPOTAT_LOG")
-      .write_style("HIPPOTAT_LOG_STYLE");
-  
-    let mut logb = env_logger::Builder::new();
-    logb.filter(Some("hippotat"),
-                *[ log::LevelFilter::Info,
-                   log::LevelFilter::Debug ]
-                .get(opts.debug)
-                .unwrap_or(
-                  &log::LevelFilter::Trace
-                ));
-    logb.parse_env(env);
-    logb.init();
-  }
+  opts.log.log_init()?;
 
   let https = HttpsConnector::new();
   let hclient = hyper::Client::builder().build::<_, hyper::Body>(https);
diff --git a/src/bin/server.rs b/src/bin/server.rs
new file mode 100644 (file)
index 0000000..d97cf1c
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright 2021 Ian Jackson and contributors to Hippotat
+// SPDX-License-Identifier: GPL-3.0-or-later
+// There is NO WARRANTY.
+
+use hippotat::prelude::*;
+
+#[derive(StructOpt,Debug)]
+pub struct Opts {
+  #[structopt(flatten)]
+  log: LogOpts,
+
+  #[structopt(flatten)]
+  config: config::Opts,
+}
+
+#[tokio::main]
+async fn main() -> Result<(), AE> {
+  let opts = Opts::from_args();
+
+  let ics = config::read(&opts.config, LinkEnd::Server)?;
+
+  opts.log.log_init()?;
+
+  dbg!(ics);
+
+  Ok(())
+}
index 24cd6b82822f44756b3b95aafc725e18a4445251..0d199ecee06a0523586313aebb08f2f0c78fa0e1 100644 (file)
@@ -4,6 +4,33 @@
 
 use crate::prelude::*;
 
+#[derive(StructOpt,Debug)]
+pub struct LogOpts {
+  /// Increase debug level
+  #[structopt(long, short="D", parse(from_occurrences))]
+  debug: usize,
+}
+
+impl LogOpts {
+  #[throws(AE)]
+  pub fn log_init(&self) {
+    let env = env_logger::Env::new()
+      .filter("HIPPOTAT_LOG")
+      .write_style("HIPPOTAT_LOG_STYLE");
+  
+    let mut logb = env_logger::Builder::new();
+    logb.filter(Some("hippotat"),
+                *[ log::LevelFilter::Info,
+                   log::LevelFilter::Debug ]
+                .get(self.debug)
+                .unwrap_or(
+                  &log::LevelFilter::Trace
+                ));
+    logb.parse_env(env);
+    logb.init();
+  }
+}
+
 // For clients only, really.
 pub struct Reporter<'r> {
   ic: &'r InstanceConfig,