From 7084b4cf54ac56b49c3abde10924dfd7a748eed0 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 23 May 2012 09:55:15 +0200 Subject: [PATCH] Implement channels --- distribution-server/dist-daemon | 13 ++++++++++++- node/node-daemon | 12 ++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/distribution-server/dist-daemon b/distribution-server/dist-daemon index a462090..6704fc4 100755 --- a/distribution-server/dist-daemon +++ b/distribution-server/dist-daemon @@ -27,9 +27,11 @@ select_outputs = [] class Client: buff = "" + channel_map = {} def __init__(self, connstream): self.stream = connstream + self.channel_map[0] = Channel() def process_data(self, data): self.buff += data @@ -45,7 +47,16 @@ class Client: data = chunk[2:] channel_numeric = to_numeric(channel_identifier) - print "Received data on channel %d: %s" % (channel_numeric, data) + + if channel_numeric in self.channel_map: + print "Received data on channel %d: %s" % (channel_numeric, data) + else: + print "Received data on NON-EXISTENT channel %d" % channel_numeric + +class Channel: + numeric = 0 + binary = False + handler = None bindsocket = socket.socket() bindsocket.bind(('0.0.0.0', 9151)) diff --git a/node/node-daemon b/node/node-daemon index 2384368..9da0871 100755 --- a/node/node-daemon +++ b/node/node-daemon @@ -8,12 +8,20 @@ allowed_certs = '/home/sven/ssl/allowed' # Configuration ends here ################################ -import socket, ssl, pprint, time +EOC = "\0" + +import socket, ssl, time, math + +def to_numeric(identifier): + return ((ord(identifier[:1]) - 1) * 255) + (ord(identifier[1:]) - 1) + +def to_identifier(numeric): + return chr(int(math.floor(numeric / 255) + 1)) + chr((numeric % 255) + 1) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ssl_sock = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED, ca_certs=allowed_certs) ssl_sock.connect(('localhost', 9151)) -ssl_sock.write('test data') +ssl_sock.write(to_identifier(3) + 'test data' + EOC + to_identifier(4190) + 'SAMPLEDATA' + EOC) ssl_sock.close()