|
|
@ -13,18 +13,24 @@ def remove_from_list(ls, val):
|
|
|
|
return [value for value in ls if value is not val]
|
|
|
|
return [value for value in ls if value is not val]
|
|
|
|
|
|
|
|
|
|
|
|
class PingThread(threading.Thread):
|
|
|
|
class PingThread(threading.Thread):
|
|
|
|
|
|
|
|
aborted = False
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, channel):
|
|
|
|
def __init__(self, channel):
|
|
|
|
self.channel = channel
|
|
|
|
self.channel = channel
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.daemon = True
|
|
|
|
self.daemon = True
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
def run(self):
|
|
|
|
while True:
|
|
|
|
while self.aborted is False:
|
|
|
|
self.pingkey = ''.join(random.choice(string.letters + string.digits) for i in xrange(5))
|
|
|
|
self.pingkey = ''.join(random.choice(string.letters + string.digits) for i in xrange(5))
|
|
|
|
self.pingtime = datetime.time(datetime.now())
|
|
|
|
self.pingtime = datetime.time(datetime.now())
|
|
|
|
self.channel.send("PING %s" % self.pingkey)
|
|
|
|
self.channel.send("PING %s" % self.pingkey)
|
|
|
|
time.sleep(10)
|
|
|
|
time.sleep(10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def abort(self):
|
|
|
|
|
|
|
|
self.aborted = True
|
|
|
|
|
|
|
|
print "Aborted thread."
|
|
|
|
|
|
|
|
|
|
|
|
class Client:
|
|
|
|
class Client:
|
|
|
|
buff = ""
|
|
|
|
buff = ""
|
|
|
|
channel_map = {}
|
|
|
|
channel_map = {}
|
|
|
@ -60,6 +66,11 @@ class Client:
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print "WARNING: Received data on non-existent channel %d" % channel_numeric
|
|
|
|
print "WARNING: Received data on non-existent channel %d" % channel_numeric
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def end(self):
|
|
|
|
|
|
|
|
for key, chan in self.channel_map.iteritems():
|
|
|
|
|
|
|
|
print "Destructing handler for channel %d" % chan.numeric
|
|
|
|
|
|
|
|
chan.handler.destruct()
|
|
|
|
|
|
|
|
|
|
|
|
class Channel:
|
|
|
|
class Channel:
|
|
|
|
numeric = 0
|
|
|
|
numeric = 0
|
|
|
|
binary = False
|
|
|
|
binary = False
|
|
|
@ -87,6 +98,9 @@ class Handler:
|
|
|
|
def process(self, chunk):
|
|
|
|
def process(self, chunk):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def destruct(self):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ControlHandler(Handler):
|
|
|
|
class ControlHandler(Handler):
|
|
|
|
pingthread = None
|
|
|
|
pingthread = None
|
|
|
|
|
|
|
|
|
|
|
@ -135,6 +149,9 @@ class ControlHandler(Handler):
|
|
|
|
|
|
|
|
|
|
|
|
print "Latency: %f seconds" % (seconds_end - seconds_start)
|
|
|
|
print "Latency: %f seconds" % (seconds_end - seconds_start)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def destruct(self):
|
|
|
|
|
|
|
|
self.pingthread.abort()
|
|
|
|
|
|
|
|
|
|
|
|
class EchoHandler(Handler):
|
|
|
|
class EchoHandler(Handler):
|
|
|
|
def process(self, chunk):
|
|
|
|
def process(self, chunk):
|
|
|
|
print "Received %s" % chunk
|
|
|
|
print "Received %s" % chunk
|
|
|
@ -196,11 +213,12 @@ class SSLDaemon:
|
|
|
|
self.client_list.append(new_client)
|
|
|
|
self.client_list.append(new_client)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
data = sock.recv(1024)
|
|
|
|
data = sock.recv(1024)
|
|
|
|
|
|
|
|
cur_client = self.client_map[sock.fileno()]
|
|
|
|
|
|
|
|
|
|
|
|
if data:
|
|
|
|
if data:
|
|
|
|
cur_client = self.client_map[sock.fileno()]
|
|
|
|
|
|
|
|
cur_client.process_data(data)
|
|
|
|
cur_client.process_data(data)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
cur_client.end()
|
|
|
|
self.select_inputs = remove_from_list(self.select_inputs, sock)
|
|
|
|
self.select_inputs = remove_from_list(self.select_inputs, sock)
|
|
|
|
print "NOTICE: Client disconnected"
|
|
|
|
print "NOTICE: Client disconnected"
|
|
|
|
except ssl.SSLError, err:
|
|
|
|
except ssl.SSLError, err:
|
|
|
|