[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Checking in (somewhat stale) fragmentation work



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv22372/lib/mixminion

Modified Files:
	BuildMessage.py Packet.py 
Log Message:
Checking in (somewhat stale) fragmentation work

Index: BuildMessage.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/BuildMessage.py,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- BuildMessage.py	13 Jul 2003 16:43:35 -0000	1.50
+++ BuildMessage.py	28 Jul 2003 01:02:33 -0000	1.51
@@ -13,6 +13,7 @@
 import mixminion.Crypto as Crypto
 from mixminion.Packet import *
 from mixminion.Common import MixError, MixFatalError, LOG, UIError
+import mixminion._minionlib
 
 if sys.version_info[:3] < (2,2,0):
     import mixminion._zlibutil as zlibutil
@@ -598,6 +599,62 @@
 
 #----------------------------------------------------------------------
 # Payload-related helpers
+
+MAX_FRAGMENTS_PER_CHUNK = 32
+EXP_FACTOR = 1.33333333333
+
+def _encodePayloads(message, overhead, paddingPRNG):
+    assert overhead in (0, ENC_FWD_OVERHEAD)
+    origLength = len(message)
+    payload = compress(message)
+    length = len(payload)
+
+    if length > 1024 and length*20 <= origLength:
+        LOG.warn("Message is very compressible and will look like a zlib bomb")
+
+    paddingLen = PAYLOAD_LEN - SINGLETON_PAYLOAD_OVERHEAD - overhead - length
+
+    # If the compressed payload fits in 28K, we're set.
+    if paddingLen >= 0:
+        # We pad the payload, and construct a new SingletonPayload,
+        # including this payload's size and checksum.
+        payload += paddingPRNG.getBytes(paddingLen)
+        return [SingletonPayload(length, Crypto.sha1(payload), payload).pack()]
+
+    # XXXX005 Whiten payload!!!
+
+    fragCapacity = PAYLOAD_LEN - FRAGMENT_PAYLOAD_OVERHEAD - overhead
+    minFragments = ceilDiv(length, fragCapacity)
+    k = 2
+    while k < minFragments and k < 16:
+        k *= 2
+    nChunks = ceilDiv(minFragments, k)
+    paddingLen = nChunks*fragCapacity*k
+    payload += paddingPRNG.getBytes(paddingLen)
+    chunks = []
+    for i in xrange(nChunks):
+        chunk[i] = payload[fragCapacity*k*i:fragCapacity*k*(i+1)]
+    n = math.ceil(EXP_FACTOR*k)
+    fragments = []
+    fec = getFEC(k,n)
+    messageid = getCommonPRNG().getBytes(20)
+    
+    idx = 0
+    for i in xrange(nChunks):
+        blocks = []
+        for j in xrange(k):
+            blocks[j] = chunks[i][j*fragCapacity:(j+1)*fragCapacity]
+        chunks[i] = None
+        for j in xrange(n):
+            frag = fec.encode(j, blocks)
+            fragments.append(idx, Crypto.sha1())
+
+            idx += 1
+
+
+        
+    
+
 
 def _encodePayload(payload, overhead, paddingPRNG):
     """Helper: compress a payload, pad it, and add extra fields (size and hash)

Index: Packet.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Packet.py,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- Packet.py	13 Jul 2003 03:45:34 -0000	1.52
+++ Packet.py	28 Jul 2003 01:02:33 -0000	1.53
@@ -24,7 +24,9 @@
             'parseMBOXInfo', 'parseMessage', 'parseMessageAndHeaders',
             'parsePayload', 'parseReplyBlock',
             'parseReplyBlocks', 'parseSMTPInfo', 'parseSubheader',
-            'parseTextEncodedMessages', 'parseTextReplyBlocks', 'uncompressData'            ]
+            'parseTextEncodedMessages', 'parseTextReplyBlocks', 
+            'uncompressData'            
+            ]
 
 import binascii
 import re
@@ -289,6 +291,7 @@
 class _Payload:
     pass
 
+
 class SingletonPayload(_Payload):
     """Represents the payload for a standalone mixminion message.
        Fields:  size, hash, data.  (Note that data is padded.)"""
@@ -329,6 +332,11 @@
         self.msgLen = msgLen
         self.data = data
 
+    def computeHash(self):
+        self.hash = "X"*DIGEST_LEN
+        p = self.pack()
+        self.hash = sha1("XXXX")
+
     def isSingleton(self):
         """Return false; not a singleton"""
         return 0
@@ -345,6 +353,9 @@
         header = struct.pack(FRAGMENT_UNPACK_PATTERN, idx, self.hash,
                              self.msgID, self.msgLen)
         return "%s%s" % (header, self.data)
+
+    
+
 
 #----------------------------------------------------------------------
 # REPLY BLOCKS