+class IphttpResource(twisted.web.resource.Resource):
+ def render_POST(self, request):
+ # find client, update config, etc.
+ ci = ipaddress(request.args['i'])
+ c = clients[ci]
+ pw = request.args['pw']
+ if pw != c.pw: raise ValueError('bad password')
+
+ # update config
+ for r, w in (('mbd', 'max_batch_down'),
+ ('mqt', 'max_queue_time'),
+ ('mrt', 'max_request_time')):
+ try: v = request.args[r]
+ except KeyError: continue
+ v = int(v)
+ c.__dict__[w] = v
+
+ try: d = request.args['d']
+ except KeyError: d = ''
+
+ c.process_arriving_data(d)
+ c.new_request(request)
+
+def start_http():
+ resource = IphttpResource()
+ sitefactory = twisted.web.server.Site(resource)
+ for addrspec in cfg.get('server','addresses').split():
+ try:
+ addr = ipaddress.IPv4Address(addrspec)
+ endpointfactory = twisted.internet.endpoints.TCP4ServerEndpoint
+ except AddressValueError:
+ addr = ipaddress.IPv6Address(addrspec)
+ endpointfactory = twisted.internet.endpoints.TCP6ServerEndpoint
+ ep = endpointfactory(reactor, cfg.getint('server','port'), addr)
+ ep.listen(sitefactory)
+
+#---------- config and setup ----------
+