chiark / gitweb /
move effective_http_timeout into InstanceConfig
[hippotat.git] / src / config.rs
index 5a1c89f6a581202842d965cfcfb2ab54f4d9d844..dd78d75733dbdcfddebf33978e63cc39f7ab219c 100644 (file)
@@ -40,6 +40,9 @@ pub struct InstanceConfig {
   #[client]  pub http_retry:                   Duration,
   #[client]  pub url:                          Uri,
   #[client]  pub vroutes:                      Vec<IpNet>,
+
+  // Computed, rather than looked up.  Client only:
+  #[computed]  pub effective_http_timeout:     Duration,
 }
 
 static DEFAULT_CONFIG: &str = r#"
@@ -628,6 +631,13 @@ impl<'c> ResolveContext<'c> {
     }
   }
 
+  #[throws(AE)]
+  pub fn computed<T>(&self, _key: &'static str) -> T
+  where T: Default
+  {
+    default()
+  }
+
   #[throws(AE)]
   pub fn special_ipif(&self, key: &'static str) -> String {
     match self.end {
@@ -694,6 +704,14 @@ impl InstanceConfig {
             .parse().unwrap()
         }
 
+        self.effective_http_timeout = {
+          let a = self.http_timeout;
+          let b = self.http_timeout_grace;
+          a.checked_add(b).ok_or_else(
+            || anyhow!("calculate effective http timeout ({:?} + {:?})", a, b)
+          )?
+        };
+
         check_batch(self.max_batch_up, "max_batch_up")?;
       },