chiark / gitweb /
peerdb/tripe-newpeers.in: Introduce the idea of multiple address families.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 26 Sep 2017 22:06:42 +0000 (23:06 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 16 Jun 2018 18:14:10 +0000 (19:14 +0100)
Have `ResolvingHost' track a list per address family.  Add a `4' flag
requesting just the IPv4 address(es), as if we had any other kind to
return.

peerdb/peers.in.5.in
peerdb/tripe-newpeers.in

index be9b8006998904837dbf796a7e701420bbaa20a7..4e6d5cadd765bcb1f7154f69a7dc10ff9299d8e1 100644 (file)
@@ -93,6 +93,10 @@ may itself contain
 substitutions.  The
 .I flags
 consist of zero or more of the following characters:
+.RB ` 4 '
+looks up the
+.IR host 's
+IPv4 address(es);
 .RB ` * '
 returns all of the found addresses, separated by spaces, rather than
 just the first one.
index 8297d5690db6f9ca08134dcc297cf046f7c140d3..88d315496cfd5aa96fd0b03aee9dd1e46bc3c614 100644 (file)
@@ -71,12 +71,16 @@ class ResolvingHost (object):
   def __init__(me, name):
     """Make a new resolving-host object for the host NAME."""
     me.name = name
-    me.addr = []
+    me.addr = { 'INET': [] }
     me.failure = None
 
-  def addaddr(me, addr):
-    """Add the address ADDR."""
-    me.addr.append(addr)
+  def addaddr(me, af, addr):
+    """
+    Add the address ADDR with address family AF.
+
+    The address family must currently be `INET'.
+    """
+    me.addr[af].append(addr)
 
   def failed(me, msg):
     """
@@ -87,11 +91,14 @@ class ResolvingHost (object):
   def get(me, flags):
     """Return a list of addresses according to the FLAGS string."""
     if me.failure is not None: raise ResolverFailure(me.name, me.failure)
-    aa = me.addr
-    all = False
+    aa = []
+    a4 = me.addr['INET']
+    all, any = False, False
     for ch in flags:
       if ch == '*': all = True
+      elif ch == '4': aa += a4; any = True
       else: raise ValueError("unknown address-resolution flag `%s'" % ch)
+    if not any: aa = a4
     if not aa: raise ResolverFailure(me.name, 'no matching addresses found')
     if not all: aa = [aa[0]]
     return aa
@@ -141,7 +148,7 @@ class BulkResolver (object):
       host.failed('(unknown failure)')
     else:
       if cname is not None: host.name = cname
-      for a in addr: host.addaddr(a)
+      for a in addr: host.addaddr('INET', a)
     host._resolv = None
     me._noutstand -= 1
 
@@ -171,7 +178,7 @@ RX_REF = RX.compile(r'(?x) \$ \( ([^)]+) \)')
 
 ## Match a $FLAGS[HOST] name resolution reference; group 1 are the flags;
 ## group 2 is the HOST.
-RX_RESOLVE = RX.compile(r'(?x) \$ ([*]*) \[ ([^]]+) \]')
+RX_RESOLVE = RX.compile(r'(?x) \$ ([4*]*) \[ ([^]]+) \]')
 
 class ConfigSyntaxError (ExpectedError):
   def __init__(me, fname, lno, msg):
@@ -390,8 +397,8 @@ class MyConfigParser (object):
       expansion and processes them correctly.
 
     * It recognizes `$FLAGS[HOST]' name-resolver requests and handles them
-      correctly.  FLAGS may be empty, or `*' (all addresses, space-separated,
-      rather than just the first).
+      correctly.  FLAGS consists of characters `4' (IPv4 addresses), and `*'
+      (all addresses, space-separated, rather than just the first).
 
     * Its parsing behaviour is well-defined.