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

[minion-cvs] Make servers download and use directories



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

Modified Files:
	ServerMain.py 
Log Message:
Make servers download and use directories

Index: ServerMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerMain.py,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- ServerMain.py	8 Jan 2004 22:33:33 -0000	1.113
+++ ServerMain.py	9 Jan 2004 01:03:27 -0000	1.114
@@ -20,6 +20,7 @@
 #                        hash_2*     corresponding to key sets]
 #                          ...
 #               stats.tmp         [Cache of stats from latest period]
+#               dir/...           [Directory dowloaded from directory server.]
 #
 #    QUEUEDIR defaults to ${WORKDIR}/queues
 #    ${QUEUEDIR}/incoming/        [Queue of received,unprocessed pkts]
@@ -55,6 +56,7 @@
 # ServerQueue.py)
 from mixminion.ThreadUtils import MessageQueue, ClearableQueue, QueueEmpty
 
+import mixminion.ClientDirectory
 import mixminion.Config
 import mixminion.Crypto
 import mixminion.Filestore
@@ -71,7 +73,7 @@
 from mixminion.Common import LOG, LogStream, MixError, MixFatalError,\
      UIError, ceilDiv, createPrivateDir, disp64, formatTime, \
      installSIGCHLDHandler, Lockfile, LockfileLocked, readFile, secureDelete, \
-     tryUnlink, waitForChildren, writeFile
+     succeedingMidnight, tryUnlink, waitForChildren, writeFile
 
 # Version number for server home-directory.
 #
@@ -364,7 +366,7 @@
                 for pending in packets ]
             LOG.trace("Delivering packets OUT:[%s] to %s",
                       " ".join([p.getHandle() for p in packets]),
-                      routing)
+                      mixminion.ServerInfo.displayServer(routing))
             self.server.sendPacketsByRouting(routing, deliverable)
 
 class _MMTPServer(mixminion.server.MMTPServer.MMTPAsyncServer):
@@ -716,6 +718,11 @@
         self.descriptorFile = os.path.join(homeDir, "current-desc")
         self.keyring.updateKeys(self.packetHandler, self.mmtpServer,
                                 self.descriptorFile)
+        LOG.debug("Initializing directory client")
+        self.dirClient = mixminion.ClientDirectory.ClientDirectory(
+            os.path.join(config.getWorkDir(),"dir"))
+        self.dirClient.updateDirectory()
+        self.dirClient._installAsKeyIDResolver()
 
         publishedIP, publishedPort, publishedKeyID = self.keyring.getAddress()
 
@@ -813,6 +820,18 @@
 
         self.processingThread.addJob(c)
 
+    def updateDirectoryClient(self):
+        def c(self=self):
+            self.dirClient.updateDirectory()
+            prng = mixminion.Crypto.getCommonPRNG()
+            nextUpdate = succeedingMidnight(time.time())
+            # Randomly retrieve the directory within an hour after midnight, to
+            # avoid hosing the server.
+            nextUpdate += prng.getInt(60)*60
+            self.scheduleOnce(nextUpdate, "UPDATE_DIR_CLIENT",
+                              self.updateDirectoryClient)
+        self.processingThread.addJob(c)
+
     def run(self):
         """Run the server; don't return unless we hit an exception."""
         global GOT_HUP
@@ -853,6 +872,9 @@
                           "KEY_GEN",
                           self.generateKeys)
 
+        # Makes next update get scheduled.
+        self.updateDirectoryClient()
+
         nextMix = self.mixPool.getNextMixTime(now)
         LOG.debug("First mix at %s", formatTime(nextMix,1))
         self.scheduleRecurringComplex(self.mixPool.getNextMixTime(now),