[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] Make batching algorithm configurable



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

Modified Files:
	test.py 
Log Message:
Make batching algorithm configurable

Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- test.py	16 Dec 2002 02:40:11 -0000	1.49
+++ test.py	20 Dec 2002 23:52:07 -0000	1.50
@@ -97,7 +97,10 @@
 
 def floatEq(f1,f2):
     """Return true iff f1 is very close to f2."""
-    return abs(f1-f2)/min(f1,f2) < .00001
+    if min(f1, f2) != 0:
+        return abs(f1-f2)/min(f1,f2) < .00001
+    else:
+        return abs(f1-f2) < .00001
 
 def readFile(fname):
     """Return the contents of the file named 'fname'.  We could just say
@@ -1514,7 +1517,6 @@
         encoded1 = '\x00\x6D'+sha1(encoded1)+encoded1
         # Forward message.
         self.assertEquals(payload, BuildMessage._decodeForwardPayload(encoded1))
-
         # Encoded forward message
         efwd = (comp+"RWE/HGW"*4096)[:28*1024-22-38]
         efwd = '\x00\x6D'+sha1(efwd)+efwd
@@ -1553,7 +1555,6 @@
                      BuildMessage._decodeStatelessReplyPayload(m,tag,passwd))
         repl2, repl2tag = m, tag
 
-        #
         # Okay, now let's try out 'decodePayload' (and thereby test its
         # children).  First, we test all the cases that succeed; or that
         # fail and return None to indicate that another key might decrypt
@@ -1603,6 +1604,15 @@
                 self.assertEquals(None,
                             decodePayload(repl2, repl2tag, pk, None))
 
+
+        # Try decoding a payload that looks like a zlib bomb.  An easy way to
+        # get such a payload is to compress 25K of zeroes.
+        nils = "\x00"*(25*1024)
+        overcompressed_payload = \
+             BuildMessage._encodePayload(nils, 0, AESCounterPRNG())
+        self.failUnlessRaises(BuildMessage.CompressedDataTooLong, 
+             BuildMessage.decodePayload, overcompressed_payload, "X"*20)
+
         # And now the cases that fail hard.  This can only happen on:
         #   1) *: Hash checks out, but zlib or size is wrong.  Already tested.
         #   2) EFWD: OAEP checks out, but hash is wrong.
@@ -2662,6 +2672,21 @@
         tm = C._parseTime("2001/12/25 06:15:10")
         self.assertEquals(time.gmtime(tm)[:6], (2001,12,25,6,15,10))
 
+        SC = mixminion.server.ServerConfig
+        # Fractions
+        self.assert_(floatEq(SC._parseFraction("90 %"), .90))
+        self.assert_(floatEq(SC._parseFraction(" 90%"), .90))
+        self.assert_(floatEq(SC._parseFraction(".02"), .02))
+        self.assert_(floatEq(SC._parseFraction("1"), 1))
+        self.assert_(floatEq(SC._parseFraction("0"), 0))
+        self.assert_(floatEq(SC._parseFraction("100%"), 1))
+        self.assert_(floatEq(SC._parseFraction("0%"), 0))
+        # Mix algorithms
+        self.assertEquals(SC._parseMixRule(" Cottrell"), "CottrellMixQueue")
+        self.assertEquals(SC._parseMixRule("binomialCottrell"), 
+                          "BinomialCottrellMixQueue")
+        self.assertEquals(SC._parseMixRule("TIMED"), "TimedMixQueue")
+
         ##
         # Now, try the failing cases.
         def fails(fn, val, self=self):
@@ -2713,6 +2738,15 @@
             # This is what we expect
             pass
 
+        # Fractions
+        fails(SC._parseFraction, "90")
+        fails(SC._parseFraction, "-.01")
+        fails(SC._parseFraction, "101%")
+        fails(SC._parseFraction, "1.01")
+        fails(SC._parseFraction, "5")
+        # Mix algorithms
+        fails(SC._parseMixRule, "")
+        fails(SC._parseMixRule, "nonesuch")
 
 #----------------------------------------------------------------------
 # Server descriptors
@@ -3006,6 +3040,22 @@
         self.assertEquals(exampleMod.processedAll[i],
                           ("XYZZYZZY"*3584, "Z"*20, 1234, "Buenas noches"))
 
+        # Now a message that compressed too much.
+        # (first, erase the pending message.)
+        manager.queues[exampleMod.getName()].removeAll()
+        manager.queues[exampleMod.getName()]._rescan()
+        
+        p = "For whom is the funhouse fun?"*8192
+        msg = mixminion.BuildMessage._encodePayload(
+            p, 0, Crypto.getCommonPRNG())
+        manager.queueMessage(msg, "Z"*20, 1234, "Buenas noches")
+        exampleMod.processedAll = []
+        self.assertEquals(len(exampleMod.processedAll), 0)
+        manager.sendReadyMessages()
+        self.assertEquals(len(exampleMod.processedAll), 1)
+        self.assertEquals(exampleMod.processedAll[0], 
+            (BuildMessage.compressData(p), 'long', 1234, "Buenas noches"))
+
         # Check serverinfo generation.
         try:
             suspendLog()
@@ -3413,6 +3463,50 @@
         # Test getPacketHandler
         _ = keyring.getPacketHandler()
 
+
+#----------------------------------------------------------------------
+
+class ServerMainTests(unittest.TestCase):
+    def testMixPool(self):
+        ServerConfig = mixminion.server.ServerConfig.ServerConfig
+        MixPool = mixminion.server.ServerMain.MixPool
+        baseDir = mix_mktemp()
+        mixDir = mix_mktemp()
+        cfg = SERVER_CONFIG_SHORT % baseDir
+
+        configTimed = ServerConfig(string=(cfg+
+               "MixAlgorithm: timed\nMixInterval: 2 hours\n"))
+        configCottrell = ServerConfig(string=(cfg+
+               "MixAlgorithm: Mixmaster\nMixInterval: .5 days\n"+
+               "MixPoolMinSize: 10\nMixPoolRate: 40%\n"))
+        configBCottrell = ServerConfig(string=(cfg+
+               "MixAlgorithm: BinomialCottrell\nMixInterval: .25 days\n"+
+               "MixPoolMinSize: 10\nMixPoolRate: 40%\n"))
+
+        # Test pool configuration
+        pool = MixPool(configTimed, mixDir)
+        self.assert_(isinstance(pool.queue, 
+                                mixminion.server.Queue.TimedMixQueue))
+        self.assertEquals(pool.getNextMixTime(100), 100+2*60*60)
+
+        pool = MixPool(configCottrell, mixDir)
+        self.assert_(isinstance(pool.queue, 
+                                mixminion.server.Queue.CottrellMixQueue))
+        self.assertEquals(pool.getNextMixTime(100), 100+12*60*60)
+        self.assertEquals(pool.queue.minPool, 10)
+        self.assertEquals(pool.queue.minSend, 1)
+        self.assert_(floatEq(pool.queue.sendRate, .4))
+
+        pool = MixPool(configBCottrell, mixDir)
+        self.assert_(isinstance(pool.queue, 
+                             mixminion.server.Queue.BinomialCottrellMixQueue))
+        self.assertEquals(pool.getNextMixTime(100), 100+6*60*60)
+        self.assertEquals(pool.queue.minPool, 10)
+        self.assertEquals(pool.queue.minSend, 1)
+        self.assert_(floatEq(pool.queue.sendRate, .4))
+        
+        # FFFF test other mix pool behavior
+
 #----------------------------------------------------------------------
 
 _EXAMPLE_DESCRIPTORS = {} # name->list of str
@@ -3786,6 +3880,7 @@
 
     suite.addTest(tc(ClientMainTests))
     suite.addTest(tc(ServerKeysTests))
+    suite.addTest(tc(ServerMainTests))
 
     # These tests are slowest, so we do them last.
     suite.addTest(tc(ModuleManagerTests))