6 import twisted.web.client
10 def set_client(ci,cs,pw):
13 assert(client_cs is None)
16 c.max_outstanding = cfg.getint(cs, 'max_requests_outstanding')
17 c.target_outstanding = cfg.getint(cs, 'target_requests_outstanding')
22 global max_requests_outstanding
24 process_cfg_common_always()
28 c.url = cfg.get('server','url')
31 sa = c.saddrs[0].url()
33 process_cfg_clients(set_client)
35 c.routes = cfg.get('virtual','routes')
36 c.max_queue_time = cfg.getint(client_cs, 'max_queue_time')
37 c.max_batch_up = cfg.getint(client_cs, 'max_batch_up')
39 process_cfg_ipif(client_cs,
49 queue = PacketQueue(c.max_queue_time)
50 agent = twisted.web.client.Agent(reactor, connectTimeout = c.http_timeout)
52 def outbound(packet, saddr, daddr):
53 #print('OUT ', saddr, daddr, repr(packet))
57 class ResponseConsumer(twisted.internet.protocol.Protocol):
59 self._ssd = SlipStreamDecoder(queue_inbound)
60 def dataReceived(self, data):
61 self._ssd.inputdata(mime_translate(data))
62 def connectionMade(self): pass
63 def connectionLost(self, reason):
64 if isinstance(reason, twisted.internet.error.ConnectionDone):
67 print(reason, file=sys.stderr)
70 resp.deliverBody(ResponseConsumer())
73 print(err, file=sys.stderr)
80 if outstanding >= c.max_outstanding : break
81 if not queue.nonempty() and outstanding >= c.target_outstanding: break
84 def moredata(s): global d; d += s
85 queue.process((lambda: len(d)),
91 mime = (b'--b' + crlf +
92 b'Content-Disposition: form-data; name="m"' + crlf +
95 c.target_outstanding + crlf +
97 b'Content-Disposition: form-data; name="d"' + crlf +
98 mime_translate(d) + crlf +
101 hh = { 'User-Agent': ['hippotat'],
102 'Content-Type': ['multipart/form-data; boundary="b"'] }
103 req = agent.request(b'POST',
105 twisted.web.client.Headers(hh))
106 req.addTimeout(c.http_timeout)
107 req.addCallbacks(req_ok, req_err)
114 start_ipif(c.ipif_command, outbound)