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

[minion-cvs] Bump copyrights, resolve xxxxs, minor cleanups



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

Modified Files:
	HashLog.py Modules.py PacketHandler.py ServerConfig.py 
	ServerKeys.py ServerMain.py ServerQueue.py __init__.py 
Log Message:
Bump copyrights, resolve xxxxs, minor cleanups

Index: HashLog.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/HashLog.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- HashLog.py	9 Jan 2003 17:43:20 -0000	1.5
+++ HashLog.py	9 Feb 2003 22:30:58 -0000	1.6
@@ -1,4 +1,4 @@
-# Copyright 2002 Nick Mathewson.  See LICENSE for licensing information.
+# Copyright 2002-2003 Nick Mathewson.  See LICENSE for licensing information.
 # $Id$
 
 """mixminion.HashLog
@@ -17,7 +17,7 @@
 
 # FFFF Mechanism to force a different default db module.
 
-# FFFF two-copy journaling to protect against catastrophic failure that
+# FFFF Two-copy journaling to protect against catastrophic failure that
 # FFFF underlying DB code can't handle.
 
 # flags to pass to os.open when opening the journal file.
@@ -74,7 +74,6 @@
         self.journal = {}
         if os.path.exists(self.journalFileName):
             f = open(self.journalFileName, 'r')
-            # FFFF deal with really big journals?
             j = f.read()
             for i in xrange(0, len(j), DIGEST_LEN):
                 self.journal[j[i:i+DIGEST_LEN]] = 1

Index: Modules.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/Modules.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- Modules.py	5 Feb 2003 07:10:54 -0000	1.29
+++ Modules.py	9 Feb 2003 22:30:58 -0000	1.30
@@ -180,21 +180,20 @@
                 self.deliveryFailed(handle, 0)
 
 class DeliveryThread(threading.Thread):
+    "DOCDOC"
+    #DOCDOC
     def __init__(self, moduleManager):
         threading.Thread.__init__(self)
         self.moduleManager = moduleManager
         self.event = threading.Event()
-        self.__stoppinglock = threading.Lock() # UGLY. XXXX
-        self.isStopping = 0
+        self.__stoppingevent = threading.Event()
 
     def beginSending(self):
         self.event.set()
 
     def shutdown(self):
         LOG.info("Telling delivery thread to shut down.")
-        self.__stoppinglock.acquire()
-        self.isStopping = 1
-        self.__stoppinglock.release()
+        self.__stoppingevent.set()
         self.event.set()
 
     def run(self):
@@ -202,9 +201,7 @@
             while 1:
                 self.event.wait()
                 self.event.clear()
-                self.__stoppinglock.acquire()
-                stop = self.isStopping
-                self.__stoppinglock.release()
+                stop = self.__stoppingevent.isSet()
                 if stop:
                     LOG.info("Delivery thread shutting down.")
                     return

Index: PacketHandler.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/PacketHandler.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- PacketHandler.py	5 Feb 2003 06:28:31 -0000	1.8
+++ PacketHandler.py	9 Feb 2003 22:30:58 -0000	1.9
@@ -1,4 +1,4 @@
-# Copyright 2002 Nick Mathewson.  See LICENSE for licensing information.
+# Copyright 2002-2003 Nick Mathewson.  See LICENSE for licensing information.
 # $Id$
 
 """mixminion.PacketHandler: Code to process mixminion packets on a server"""
@@ -189,6 +189,7 @@
         return RelayedPacket(address, msg)
         
 class RelayedPacket:
+    """DOCDOC"""
     def __init__(self, address, msg):
         assert isinstance(address, Packet.IPV4Info)
         self.address = address
@@ -204,6 +205,7 @@
         return self.msg
 
 class DeliveryPacket:
+    """DOCDOC"""
     def __init__(self, routingType, routingInfo, applicationKey,
                  tag, payload):
         self.exitType = routingType

Index: ServerConfig.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerConfig.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- ServerConfig.py	17 Jan 2003 06:18:06 -0000	1.17
+++ ServerConfig.py	9 Feb 2003 22:30:58 -0000	1.18
@@ -207,11 +207,6 @@
                      'Comments': ('ALLOW', None, None),
                      'ModulePath': ('ALLOW', None, None),
                      'Module': ('ALLOW*', None, None),
-
-##                      'MixAlgorithm' : ('ALLOW', _parseMixRule, "Cottrell"),
-##                      'MixInterval' : ('ALLOW', C._parseInterval, "30 min"),
-##                      'MixPoolRate' : ('ALLOW', _parseFraction, "60%"),
-##                      'MixPoolMinSize' : ('ALLOW', C._parseInt, "5"),
                      'MixAlgorithm' : ('ALLOW', _parseMixRule, "Timed"),
                      'MixInterval' : ('ALLOW', C._parseInterval, "30 min"),
                      'MixPoolRate' : ('ALLOW', _parseFraction, "60%"),

Index: ServerKeys.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerKeys.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- ServerKeys.py	17 Jan 2003 06:18:06 -0000	1.10
+++ ServerKeys.py	9 Feb 2003 22:30:58 -0000	1.11
@@ -498,9 +498,9 @@
         Valid-Until: %(ValidUntil)s
         Packet-Key: %(PacketKey)s
         """ % fields
-    # XXXX003 add 'packet-formats'
+    # XXXX004 add 'packet-formats'
     #   Packet-Formats: 0.2
-    # XXXX003 add 'software'
+    # XXXX004 add 'software'
     #   Software: Mixminion %(version)s
     if contact:
         info += "Contact: %s\n"%contact

Index: ServerMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerMain.py,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- ServerMain.py	6 Feb 2003 20:20:03 -0000	1.36
+++ ServerMain.py	9 Feb 2003 22:30:58 -0000	1.37
@@ -35,6 +35,8 @@
      createPrivateDir, formatBase64, formatTime, installSIGCHLDHandler, \
      Lockfile, secureDelete, waitForChildren
 
+#DOCDOC Re-check fields and args for all classes, methods here!
+
 class IncomingQueue(mixminion.server.ServerQueue.Queue):
     """A DeliveryQueue to accept packets from incoming MMTP connections,
        and hold them until they can be processed.  As packets arrive, and
@@ -46,12 +48,10 @@
         mixminion.server.ServerQueue.Queue.__init__(self, location, create=1)
         self.packetHandler = packetHandler
         self.mixPool = None
-        self.moduleManager = None
 
-    def connectQueues(self, mixPool, manager, processingThread):
+    def connectQueues(self, mixPool, processingThread):
         """Sets the target mix queue"""
         self.mixPool = mixPool
-        self.moduleManager = manager #XXXX003 refactor.
         self.processingThread = processingThread
         for h in self.getAllMessages():
             assert h is not None
@@ -145,7 +145,6 @@
 
     def queueObject(self, obj):
         """Insert an object into the queue."""
-        obj.isDelivery() #XXXX003 remove this implicit typecheck.
         self.queue.queueObject(obj)
 
     def count(self):
@@ -214,8 +213,12 @@
         "Implementation of abstract method from DeliveryQueue."
         # Map from addr -> [ (handle, msg) ... ]
         msgs = {}
-        # XXXX003 SKIP DEAD MESSAGES!!!!
         for handle, packet, n_retries in msgList:
+            if not isinstance(packet,
+                              mixminion.server.PacketHandler.RelayedPacket):
+                LOG.warn("Skipping packet in obsolete format")
+                self.deliverySucceeded(handle)
+                continue
             addr = packet.getAddress()
             message = packet.getPacket()
             msgs.setdefault(addr, []).append( (handle, message) )
@@ -384,7 +387,6 @@
         createPrivateDir(homeDir)
 
         # Lock file.
-        # FFFF Refactor this part into common?
         self.lockFile = Lockfile(os.path.join(homeDir, "lock"))
         try:
             self.lockFile.acquire()
@@ -443,8 +445,7 @@
 
         LOG.debug("Connecting queues")
         self.incomingQueue.connectQueues(mixPool=self.mixPool,
-                                         manager=self.moduleManager,
-                                        processingThread=self.processingThread)
+                                       processingThread=self.processingThread)
         self.mixPool.connectQueues(outgoing=self.outgoingQueue,
                                    manager=self.moduleManager)
         self.outgoingQueue.connectQueues(server=self.mmtpServer)
@@ -485,6 +486,7 @@
             while timeLeft > 0:
                 # Handle pending network events
                 self.mmtpServer.process(2)
+                # Check for signals
                 if STOPPING:
                     LOG.info("Caught sigterm; shutting down.")
                     return
@@ -493,17 +495,18 @@
                     LOG.info("Resetting logs")
                     LOG.reset()
                     GOT_HUP = 0
-                # ???? This could slow us down a good bit.  Move it?
+                # Make sure that our worker threads are still running.
                 if not (self.cleaningThread.isAlive() and
                         self.processingThread.isAlive() and
                         self.moduleManager.thread.isAlive()):
                     LOG.fatal("One of our threads has halted; shutting down.")
                     return
                 
-                # Calculate remaining time.
+                # Calculate remaining time until the next event.
                 now = time.time()
                 timeLeft = nextEventTime - now
 
+            # It's time for an event.
             event = scheduledEvents[0][1]
             del scheduledEvents[0]
 
@@ -517,8 +520,6 @@
                 insort(scheduledEvents, (now + 600, "SHRED"))
             elif event == 'MIX':
                 # Before we mix, we need to log the hashes to avoid replays.
-                # FFFF We need to recover on server failure.
-
                 try:
                     # There's a potential threading problem here... in
                     # between this sync and the 'mix' below, nobody should
@@ -548,6 +549,9 @@
     def cleanQueues(self):
         """Remove all deleted messages from queues"""
         LOG.trace("Expunging deleted messages from queues")
+        # We use the 'deleteFiles' method from 'cleaningThread' so that
+        # we schedule old files to get deleted in the background, rather than
+        # blocking while they're deleted.
         df = self.cleaningThread.deleteFiles
         self.incomingQueue.cleanQueue(df)
         self.mixPool.queue.cleanQueue(df)
@@ -574,7 +578,6 @@
 #----------------------------------------------------------------------
 def daemonize():
     """Put the server into daemon mode with the standard trickery."""
-    # ??? This 'daemonize' logic should go in Common.
 
     # This logic is more-or-less verbatim from Stevens's _Advanced
     # Programming in the Unix Environment_:
@@ -583,6 +586,7 @@
     pid = os.fork()
     if pid != 0:
         os._exit(0)
+
     # Call 'setsid' to make ourselves a new session.
     if hasattr(os, 'setsid'):
         # Setsid is not available everywhere.

Index: ServerQueue.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerQueue.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ServerQueue.py	4 Feb 2003 02:08:37 -0000	1.5
+++ ServerQueue.py	9 Feb 2003 22:30:58 -0000	1.6
@@ -1,4 +1,4 @@
-# Copyright 2002 Nick Mathewson.  See LICENSE for licensing information.
+# Copyright 2002-2003 Nick Mathewson.  See LICENSE for licensing information.
 # $Id$
 
 """mixminion.server.ServerQueue
@@ -9,6 +9,7 @@
 import os
 import time
 import stat
+import sys
 import cPickle
 import threading
 
@@ -376,7 +377,7 @@
         """Returns a (n_retries, msg, nextAttempt) tuple for a given
            message handle."""
         o = self.getObject(handle)
-        if len(o) == 3:# XXXX For legacy queues; delete after 0.0.3
+        if len(o) == 3:# XXXX004 For legacy queues; delete after 0.0.3
             o = o + (0,)
         return o[0], o[2], o[3]
 
@@ -423,9 +424,16 @@
         """
         try:
             self._lock.acquire()
-            #XXXX003 be more robust in the presence of errors here.
-            self.removeMessage(handle)
-            del self.pending[handle]
+            try:
+                self.removeMessage(handle)
+            except:
+                # This should never happen.
+                LOG.error_exc(sys.exc_info(), "Error removing message")
+            try:
+                del self.pending[handle]
+            except KeyError:
+                # This should never happen.
+                LOG.error("Handle %s was not pending", handle)
         finally:
             self._lock.release()
 
@@ -435,10 +443,15 @@
            invoked after the corresponding message has been
            successfully delivered."""
         try:
-            #XXXX003 be more robust in the presence of errors here.
             self._lock.acquire()
-            lastAttempt = self.pending[handle]
-            del self.pending[handle]
+            try:
+                lastAttempt = self.pending[handle]
+                del self.pending[handle]
+            except KeyError:
+                # This should never happen
+                LOG.error("Handle %s was not pending")
+                lastAttempt = 0
+                
             if retriable:
                 # Queue the new one before removing the old one, for
                 # crash-proofness.  First, fetch the old information...
@@ -464,7 +477,7 @@
                     if retries <= len(self.retrySchedule):
                         self.queueDeliveryMessage(msg, retries, nextAttempt)
                 elif not self.retrySchedule:
-                    #LEGACY XXXX003
+                    #LEGACY XXXX004
                     retries += 1
                     nextAttempt = 0
                     if retries < 10:

Index: __init__.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/__init__.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- __init__.py	9 Jan 2003 06:28:58 -0000	1.3
+++ __init__.py	9 Feb 2003 22:30:58 -0000	1.4
@@ -1,4 +1,4 @@
-# Copyright 2002 Nick Mathewson.  See LICENSE for licensing information.
+# Copyright 2002-2003 Nick Mathewson.  See LICENSE for licensing information.
 # $Id$
 
 """mixminion.server