+def _cfg_process_putatives():
+ servers = { }
+ clients = { }
+ # maps from abstract object to canonical name for cs's
+
+ def putative(cmap, abstract, canoncs):
+ try:
+ current_canoncs = cmap[abstract]
+ except KeyError:
+ pass
+ else:
+ assert(current_canoncs == canoncs)
+ cmap[abstract] = canoncs
+
+ server_pat = r'[-.0-9A-Za-z]+'
+ client_pat = r'[.:0-9a-f]+'
+ server_re = regexp.compile(server_pat)
+ serverclient_re = regexp.compile(server_pat + r' ' + client_pat)
+
+ for cs in cfg.sections():
+ if cs == 'LIMIT':
+ # plan A "[LIMIT]"
+ continue
+
+ try:
+ # plan B "[<client>]" part 1
+ ci = ipaddr(cs)
+ except AddressValueError:
+
+ if server_re.fullmatch(cs):
+ # plan C "[<servername>]"
+ putative(servers, cs, cs)
+ continue
+
+ if serverclient_re.fullmatch(cs):
+ # plan D "[<servername> <client>]" part 1
+ (pss,pcs) = cs.split(' ')
+
+ if pcs == 'LIMIT':
+ # plan E "[<servername> LIMIT]"
+ continue
+
+ try:
+ # plan D "[<servername> <client>]" part 2
+ ci = ipaddr(pc)
+ except AddressValueError:
+ # plan F "[<some thing we do not understand>]"
+ # well, we ignore this
+ print('warning: ignoring config section %s' % cs, file=sys.stderr)
+ continue
+
+ else: # no AddressValueError
+ # plan D "[<servername> <client]" part 3
+ putative(clients, ci, pcs)
+ putative(servers, pss, pss)
+ continue
+
+ else: # no AddressValueError
+ # plan B "[<client>" part 2
+ putative(clients, ci, cs)
+ continue
+
+ return (servers, clients)
+
+def cfg_process_common(ss):
+ c.mtu = cfg.getint(ss, 'mtu')
+
+def cfg_process_saddrs(c, ss):
+ class ServerAddr():
+ def __init__(self, port, addrspec):
+ self.port = port
+ # also self.addr
+ try:
+ self.addr = ipaddress.IPv4Address(addrspec)
+ self._endpointfactory = twisted.internet.endpoints.TCP4ServerEndpoint
+ self._inurl = b'%s'
+ except AddressValueError:
+ self.addr = ipaddress.IPv6Address(addrspec)
+ self._endpointfactory = twisted.internet.endpoints.TCP6ServerEndpoint
+ self._inurl = b'[%s]'
+ def make_endpoint(self):
+ return self._endpointfactory(reactor, self.port, self.addr)
+ def url(self):
+ url = b'http://' + (self._inurl % str(self.addr).encode('ascii'))
+ if self.port != 80: url += b':%d' % self.port
+ url += b'/'
+ return url
+
+ c.port = cfg.getint(ss,'port')
+ c.saddrs = [ ]
+ for addrspec in cfg.get(ss, 'addrs').split():
+ sa = ServerAddr(c.port, addrspec)
+ c.saddrs.append(sa)
+
+def cfg_process_vnetwork(c, ss):
+ c.vnetwork = ipnetwork(cfg.get(ss,'vnetwork'))
+ if c.vnetwork.num_addresses < 3 + 2:
+ raise ValueError('vnetwork needs at least 2^3 addresses')