chiark
/
gitweb
/
~mdw
/
hippotat
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ec88b1f
)
wip
author
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Sun, 19 Mar 2017 14:25:55 +0000
(14:25 +0000)
committer
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Sun, 19 Mar 2017 14:25:55 +0000
(14:25 +0000)
server
patch
|
blob
|
blame
|
history
diff --git
a/server
b/server
index 1a9049b845131db9c6148373e6f121853fd60e9a..46ce5ed9cc4558966dd1b97f0a79701c59590d5e 100755
(executable)
--- a/
server
+++ b/
server
@@
-8,6
+8,8
@@
from twisted.internet import reactor
import ConfigParser
import ipaddress
import ConfigParser
import ipaddress
+import syslog
+
clients = { }
def ipaddress(input):
clients = { }
def ipaddress(input):
@@
-36,22
+38,48
@@
max_queue_time: 121
max_request_time: 121
'''
max_request_time: 121
'''
+def route(packet. daddr):
+ try: client = clients[daddr]
+ except KeyError: dclient = None
+ if dclient is not None:
+ dclient.queue_outbound_data(packet)
+ else if daddr = server or daddr not in network:
+ queue_inbound_data(packet)
+ else:
+ syslog.syslog(syslog.LOG_DEBUG, 'no client for %s' % daddr)
+
class Client():
class Client():
- def __init__(ip, cs):
+ def __init__(
self,
ip, cs):
# instance data members
self._ip = ip
self._cs = cs
self.pw = cfg.get(cs, 'password')
# instance data members
self._ip = ip
self._cs = cs
self.pw = cfg.get(cs, 'password')
- # plus:
- # .cfg[<config-key>]
- self.cfg = { }
+ # plus from config:
+ # .max_batch_down
+ # .max_queue_time
+ # .max_request_time
for k in ('max_batch_down','max_queue_time','max_request_time'):
req = cfg.getint(cs, k)
limit = cfg.getint('global',k)
for k in ('max_batch_down','max_queue_time','max_request_time'):
req = cfg.getint(cs, k)
limit = cfg.getint('global',k)
- self.cfg[k] = min(req, limit)
+ self.__dict__[k] = min(req, limit)
+
+ def process_arriving_data(self, d):
+ for packet in slip_decode(d):
+ (saddr, daddr) = ip_64_addrs(packet)
+ if saddr != self._ip:
+ raise ValueError('wrong source address %s' % saddr)
+ route(packet, daddr)
- def process_arriving_data(d):
-
+ def _req_cancel(self, request):
+ request.finish()
+
+ def _req_error(self, err, request):
+ self._req_cancel(request)
+
+ def http_request(self, request):
+ request.setHeader('Content-Type','application/octet-stream')
+ reactor.callLater(self.max_request_time, self._req_cancel, request)
+ request.notifyFinish().addErrback(self._req_error, request)
def process_cfg():
global network
def process_cfg():
global network
@@
-87,11
+115,10
@@
class FormPage(Resource):
try: v = request.args[r]
except KeyError: continue
v = int(v)
try: v = request.args[r]
except KeyError: continue
v = int(v)
- c.
cfg
[w] = v
+ c.
__dict__
[w] = v
try: d = request.args['d']
except KeyError: d = ''
c.process_arriving_data(d)
try: d = request.args['d']
except KeyError: d = ''
c.process_arriving_data(d)
-
- reactor.
+ c.new_request(request)