X-Git-Url: https://git.distorted.org.uk/~mdw/hippotat/blobdiff_plain/5510890e40f44f7851829b3bb1e319188e993798..74934d63b06bf4fc045ac9aabac381cedfe9f10f:/server diff --git a/server b/server index bdd893c..9772679 100755 --- a/server +++ b/server @@ -24,10 +24,10 @@ def route(packet, iface, saddr, daddr): if dclient is not None: lt('client') dclient.queue_outbound(packet) - elif daddr == c.server or daddr not in c.network: + elif daddr == c.vaddr or daddr not in c.vnetwork: lt('inbound') queue_inbound(packet) - elif daddr == relay: + elif daddr == c.relay: lt('discard relay') log_discard(packet, iface, saddr, daddr, 'relay') else: @@ -37,28 +37,15 @@ def route(packet, iface, saddr, daddr): #---------- client ---------- class Client(): - def __init__(self, ip, cs, pw): + def __init__(self, ip, cc): # instance data members self._ip = ip - self._cs = cs - self.pw = pw + self.cc = cc self._rq = collections.deque() # requests - # self._pq = PacketQueue(...) - # plus from config: - # .max_batch_down - # .max_queue_time - # .target_requests_outstanding + self._pq = PacketQueue(str(ip), self.cc.max_queue_time) - if ip not in c.network: - raise ValueError('client %s not in network' % ip) - - for k in ('max_batch_down','max_queue_time','http_timeout', - 'target_requests_outstanding'): - req = cfg.getint(cs, k) - limit = cfg.getint('limits',k) - self.__dict__[k] = min(req, limit) - - self._pq = PacketQueue(str(ip), self.max_queue_time) + if ip not in c.vnetwork: + raise ValueError('client %s not in vnetwork' % ip) if ip in clients: raise ValueError('multiple client cfg sections for %s' % ip) @@ -97,7 +84,7 @@ class Client(): def new_request(self, request): request.setHeader('Content-Type','application/octet-stream') - cl = reactor.callLater(self.http_timeout, self._req_cancel, request) + cl = reactor.callLater(self.cc.http_timeout, self._req_cancel, request) nf = request.notifyFinish() nf.addErrback(self._req_error, request) nf.addCallback(self._req_fin, request, cl) @@ -132,7 +119,7 @@ class Client(): # request, and also some non-expired packets self._pq.process((lambda: request.sentLength), (lambda d: self._req_write(request, d)), - self.max_batch_down) + self.cc.max_batch_down) assert(request.sentLength) self._rq.popleft() @@ -140,7 +127,7 @@ class Client(): self._log(DBG.HTTP, 'complete', idof=request) # round again, looking for more to do - while len(self._rq) > self.target_requests_outstanding: + while len(self._rq) > self.cc.target_requests_outstanding: request = self._rq.popleft() self._log(DBG.HTTP, 'CHKO above target, returning empty', idof=request) request.finish() @@ -157,14 +144,14 @@ def process_request(request, desca): ci = ipaddr(ci_s) desca['ci'] = ci cl = clients[ci] - if pw != cl.pw: raise ValueError('bad password') + if pw != cl.cc.password: raise ValueError('bad password') desca['pwok']=True - if tro != cl.target_requests_outstanding: - raise ValueError('tro must be %d' % cl.target_requests_outstanding) + if tro != cl.cc.target_requests_outstanding: + raise ValueError('tro must be %d' % cl.cc.target_requests_outstanding) - if cto < cl.http_timeout: - raise ValueError('cto must be >= %d' % cl.http_timeout) + if cto < cl.cc.http_timeout: + raise ValueError('cto must be >= %d' % cl.cc.http_timeout) try: d = request.args[b'd'][0] @@ -220,26 +207,37 @@ def start_http(): #---------- config and setup ---------- -def process_cfg(): - process_cfg_common_always() - process_cfg_server() - process_cfg_network() +def process_cfg(putative_servers, putative_clients): + global c + c = ConfigResults() + c.server = cfg.get('SERVER','server') + + cfg_process_common(c, c.server) + cfg_process_saddrs(c, c.server) + cfg_process_vnetwork(c, c.server) + cfg_process_vaddr(c, c.server) + + for (ci,cs) in putative_clients.items(): + cc = ConfigResults() + sections = cfg_process_client_common(cc,c.server,cs,ci) + if not sections: continue + cfg_process_client_limited(cc,c.server,sections, 'max_batch_down') + cfg_process_client_limited(cc,c.server,sections, 'max_queue_time') + Client(ci, cc) try: - c.relay = cfg.get('virtual','relay') + c.vrelay = cfg.get(c.server, 'vrelay') except NoOptionError: - for search in c.network.hosts(): - if search == c.server: continue - c.relay = search + for search in c.vnetwork.hosts(): + if search == c.vaddr: continue + c.vrelay = search break - process_cfg_saddrs() - process_cfg_clients(Client) - - process_cfg_ipif('server', - (('local','server'), - ('peer', 'relay'), - ('rnets','network'))) + cfg_process_ipif(c, + [c.server, 'DEFAULT'], + (('local','vaddr'), + ('peer', 'vrelay'), + ('rnets','vnetwork'))) common_startup(process_cfg) start_ipif(c.ipif_command, (lambda p,s,d: route(p,"[ipif]",s,d)))