chiark / gitweb /
new config definition
[hippotat.git] / hippotat / __init__.py
index 6b87da9f63919f64979e3bf8680bc361a99abdc3..8563834b5aca1ff16b48561d7bdba61f0034b9c1 100644 (file)
@@ -20,6 +20,7 @@ import ipaddress
 from ipaddress import AddressValueError
 
 from optparse import OptionParser
+import configparser
 from configparser import ConfigParser
 from configparser import NoOptionError
 
@@ -96,44 +97,42 @@ class LogNotBoringTwisted:
 
 defcfg = '''
 [DEFAULT]
-#[<client>] overrides
-max_batch_down = 65536           # used by server, subject to [limits]
-max_queue_time = 10              # used by server, subject to [limits]
-target_requests_outstanding = 3  # must match; subject to [limits] on server
-http_timeout = 30                # used by both } must be
-http_timeout_grace = 5           # used by both }  compatible
-max_requests_outstanding = 4     # used by client
-max_batch_up = 4000              # used by client
-http_retry = 5                   # used by client
+max_batch_down = 65536
+max_queue_time = 10
+target_requests_outstanding = 3
+http_timeout = 30
+http_timeout_grace = 5
+max_requests_outstanding = 6
+max_batch_up = 4000
+http_retry = 5
 
 #[server] or [<client>] overrides
 ipif = userv root ipif %(local)s,%(peer)s,%(mtu)s,slip %(rnets)s
-# extra interpolations:  %(local)s        %(peer)s          %(rnet)s
-#  obtained   on server  [virtual]server  [virtual]relay    [virtual]network
-#      from   on client  <client>         [virtual]server   [virtual]routes
 
-[virtual]
+# relating to virtual network
 mtu = 1500
-routes = ''
-# network = <prefix>/<len>  # mandatory for server
-# server  = <ipaddr>   # used by both, default is computed from `network'
-# relay   = <ipaddr>   # used by server, default from `network' and `server'
-#  default server is first host in network
-#  default relay is first host which is not server
 
 [server]
-# addrs = 127.0.0.1 ::1    # mandatory for server
-port = 80                  # used by server
-# url              # used by client; default from first `addrs' and `port'
+# addrs = 127.0.0.1 ::1
+port = 80
+# url
+
+# relating to virtual network
+routes = ''
+vnetwork = 172.24.230.192
+# network = <prefix>/<len>
+# server  = <ipaddr>
+# relay   = <ipaddr>
+
 
 # [<client-ip4-or-ipv6-address>]
 # password = <password>    # used by both, must match
 
 [limits]
-max_batch_down = 262144           # used by server
-max_queue_time = 121              # used by server
-http_timeout = 121                # used by server
-target_requests_outstanding = 10  # used by server
+max_batch_down = 262144
+max_queue_time = 121
+http_timeout = 121
+target_requests_outstanding = 10
 '''
 
 # these need to be defined here so that they can be imported by import *
@@ -403,9 +402,10 @@ def process_cfg_clients(constructor):
 
 #---------- startup ----------
 
-def common_startup():
-  re = regexp.compile('#.*')
-  cfg.read_string(re.sub('', defcfg))
+def common_startup(process_cfg):
+  # ConfigParser hates #-comments after values
+  trailingcomments_re = regexp.compile('#.*')
+  cfg.read_string(trailingcomments_re.sub('', defcfg))
   need_defcfg = True
 
   def readconfig(pathname, mandatory=True):
@@ -514,6 +514,12 @@ just `+': all DFLAGs.
     readconfig('/etc/hippotat/config',   False)
     readconfig('/etc/hippotat/config.d', False)
 
+  try: process_cfg()
+  except (configparser.Error, ValueError):
+    traceback.print_exc(file=sys.stderr)
+    print('\nInvalid configuration, giving up.', file=sys.stderr)
+    sys.exit(12)
+
   #print(repr(debug_set), file=sys.stderr)
 
   log_formatter = twisted.logger.formatEventAsClassicLogText