config: Abolish use of ConfigParser's DEFAULT feature
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 24 Apr 2017 00:00:29 +0000 (01:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 24 Apr 2017 00:00:29 +0000 (01:00 +0100)
ConfigParser provides no way to find out which sections a key is
_really_ in: in all of its views, keys in DEFAULT appear aliased in
all sections.

So instead we use a COMMON section, and implement the defaulting
ourselves.  This involves:

* Changing the cfg.get[int] calls to use cfg_search (these are
  the things which implictly use DEFAULT and now need to be
  explicit).
* Changing all our explicit references to and definitions of
  DEFAULT options to COMMON.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README.config
hippotatd
hippotatlib/__init__.py

index 81f791d..2b58512 100644 (file)
@@ -5,7 +5,7 @@ Sections
   [<servername> - <client>]
   [<client>]
   [<servername>]      often [SERVER]
   [<servername> - <client>]
   [<client>]
   [<servername>]      often [SERVER]
-  [DEFAULT]
+  [COMMON]
 
 Keys are looked up in that order, unless otherwise specified.
 <client> is the client's virtual address.
 
 Keys are looked up in that order, unless otherwise specified.
 <client> is the client's virtual address.
@@ -15,7 +15,7 @@ Exceptional settings:
 
   server
      Specifies <servername>.
 
   server
      Specifies <servername>.
-     Is looked up in [SERVER] and [DEFAULT] only.
+     Is looked up in [SERVER] and [COMMON] only.
      If not specified there, it is SERVER.
 
      Used by server to select the appropriate parts of the
      If not specified there, it is SERVER.
 
      Used by server to select the appropriate parts of the
@@ -54,7 +54,7 @@ Exceptional settings:
 Capped settings:
 
      Values in [<server> LIMIT] and [LIMIT] are a cap (maximum) on
 Capped settings:
 
      Values in [<server> LIMIT] and [LIMIT] are a cap (maximum) on
-     those from the other sections (including DEFAULT).
+     those from the other sections (including COMMON).
 
   max_batch_down
      Size limit for response payloads (used by server only)
 
   max_batch_down
      Size limit for response payloads (used by server only)
index c03ae48..0482876 100755 (executable)
--- a/hippotatd
+++ b/hippotatd
@@ -325,7 +325,7 @@ def process_cfg(_opts, putative_servers, putative_clients):
   except NoOptionError: pass
 
   cfg_process_ipif(c,
   except NoOptionError: pass
 
   cfg_process_ipif(c,
-                   [c.server, 'DEFAULT'],
+                   [c.server, 'COMMON'],
                    (('local','vaddr'),
                     ('peer', 'vrelay'),
                     ('rnets','vnetwork')))
                    (('local','vaddr'),
                     ('peer', 'vrelay'),
                     ('rnets','vnetwork')))
index ce94a86..8e00c15 100644 (file)
@@ -126,7 +126,7 @@ class LogNotBoringTwisted:
 #---------- default config ----------
 
 defcfg = '''
 #---------- default config ----------
 
 defcfg = '''
-[DEFAULT]
+[COMMON]
 max_batch_down = 65536
 max_queue_time = 10
 target_requests_outstanding = 3
 max_batch_down = 65536
 max_queue_time = 10
 target_requests_outstanding = 3
@@ -389,8 +389,8 @@ def _cfg_process_putatives():
   serverclient_re = regexp.compile(server_pat + r' ' + client_pat)
 
   for cs in cfg.sections():
   serverclient_re = regexp.compile(server_pat + r' ' + client_pat)
 
   for cs in cfg.sections():
-    if cs == 'LIMIT':
-      # plan A "[LIMIT]"
+    if cs == 'LIMIT' or cs == 'COMMON':
+      # plan A "[LIMIT]" or "[COMMON]"
       continue
 
     try:
       continue
 
     try:
@@ -492,11 +492,12 @@ def cfg_search(getter,key,sections):
   section = cfg_search_section(key,sections)
   return getter(section, key)
 
   section = cfg_search_section(key,sections)
   return getter(section, key)
 
-def cfg1get(*args, **kwargs):
-  return cfg.get(*args, **kwargs)
+def cfg1get(section,key, getter=cfg.get,**kwargs):
+  section = cfg_search_section(key,[section,'COMMON'])
+  return getter(section,key,**kwargs)
 
 
-def cfg1getint(*args, **kwargs):
-  return cfg.getint(*args, **kwargs)
+def cfg1getint(section,key, **kwargs):
+  return cfg1get(section,key, getter=cfg.getint,**kwargs);
 
 def cfg_process_client_limited(cc,ss,sections,key):
   val = cfg_search(cfg1getint, key, sections)
 
 def cfg_process_client_limited(cc,ss,sections,key):
   val = cfg_search(cfg1getint, key, sections)
@@ -510,7 +511,7 @@ def cfg_process_client_common(cc,ss,cs,ci):
   sections = ['%s %s' % (ss,cs),
               cs,
               ss,
   sections = ['%s %s' % (ss,cs),
               cs,
               ss,
-              'DEFAULT']
+              'COMMON']
 
   try: pwsection = cfg_search_section('password', sections)
   except NoOptionError: return None
 
   try: pwsection = cfg_search_section('password', sections)
   except NoOptionError: return None