Permalink
Browse files

started on core functions

  • Loading branch information...
1 parent accf6bb commit caee406f1e60f1d12ee58ece6dad4652440e1afe @aallai committed Nov 25, 2011
Showing with 44 additions and 11 deletions.
  1. +40 −11 core.py
  2. BIN core.pyc
  3. +4 −0 mediums.py
View
51 core.py
@@ -1,33 +1,62 @@
import sys
import random
+import hashlib
+import time
'''
Functions to send and receive messages using the protocol
'''
-def send(medium_list, data, sender_key) :
+def send(medium_list, data, sender_key, receiver_key) :
+ # unique message id
+ mid = hashlib.md5(sender_key + receiver_key + str(time.time())).hexdigest()
+ data_len = len(data)
+ med_len = len(medium_list)
+
+ min_mtu = 5
- min_mtu = sys.maxint
-
for medium in medium_list :
if medium.mtu < min_mtu :
min_mtu = medium.mtu
- # split up the data in (len(data) / min_mtu) chunks of size min_mtu
+ '''
+ split up the data in (data_len / min_mtu) chunks of size min_mtu
+ the smaller our chunks the more obfuscated the data is, will have to
+ revisit this
+ '''
+
segments = []
- for i in xrange(len(data) / min_mtu) :
- segments.append( (i, data[i*min_mtu: i*min_mtu + min_mtu]) )
+ for i in xrange(data_len / min_mtu) :
+ segments.append( (i, data[i*min_mtu : i*min_mtu + min_mtu]) )
- messages_per_medium = len(segments) / len(medium_list)
+ seq_len = len(segments)
+ if (data_len % min_mtu != 0) :
+ segments.append( (seq_len, data[seq_len * min_mtu :]) )
+ seq_len += 1
+
+ print segments
+
+
+ messages_per_medium = len(segments) / med_len
+
# permute segments
random.shuffle(segments)
-
- for i in xrange(len(medium_list)) :
- for (seq, segment) in segments[i*messages_per_medium : i*messages_per_medium + messages_per_medium] :
- medium_list[i].send()
+ for i in xrange(med_len) :
+ send_range(medium_list[i], segments[i * messages_per_medium : i*messages_per_medium + messages_per_medium], receiver_key, mid)
+
+ if (med_len * messages_per_medium % seq_len != 0) :
+ send_range(medium_list[0], segments[med_len * messages_per_medium :], receiver_key, mid)
+
+
+
+def send_range(medium, segments, key, mid) :
+
+ for (seq, segment) in segments :
+ medium.send(segment, seq, mid, key)
+
View
BIN core.pyc
Binary file not shown.
View
@@ -46,6 +46,10 @@ def __init__(self, reason) :
class EmailMedium(Medium) :
+ '''
+Represents an email account to which messages can be sent (and possbly received if we have the password for it).
+ '''
+
# use POP as default, some webmail services don't offer IMAP
def __init__(self, address, passwd=None, proto=None) :

0 comments on commit caee406

Please sign in to comment.