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

[minion-cvs] Put a lock around servercontext changes



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

Modified Files:
	MMTPServer.py 
Log Message:
Put a lock around servercontext changes 

Index: MMTPServer.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/MMTPServer.py,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- MMTPServer.py	22 Jan 2004 05:42:07 -0000	1.72
+++ MMTPServer.py	27 Jan 2004 05:56:21 -0000	1.73
@@ -23,6 +23,7 @@
 import socket
 import select
 import re
+import threading
 import time
 from types import StringType
 
@@ -423,12 +424,15 @@
     # dnsCache: An instance of mixminion.server.DNSFarm.DNSCache.
     # msgQueue: An instance of MessageQueue to receive notification from DNS
     #     DNS threads.  See _queueSendablePackets for more information.
+    # _lock: protects only serverContext.
 
     def __init__(self, config, servercontext):
         AsyncServer.__init__(self)
-        
+
         self.serverContext = servercontext
         self.clientContext = _ml.TLSContext_new()
+        self._lock = threading.Lock()
+
         # FFFF Don't always listen; don't always retransmit!
         # FFFF Support listening on multiple IPs
 
@@ -477,7 +481,9 @@
     def setServerContext(self, servercontext):
         """Change the TLS context used for newly received connections.
            Used to rotate keys."""
+        self._lock.acquire()
         self.serverContext = servercontext
+        self._lock.release()
 
     def getNextTimeoutTime(self, now=None):
         """Return the time at which we next purge connections, if we have
@@ -490,7 +496,11 @@
         """helper method.  Creates and registers a new server connection when
            the listener socket gets a hit."""
         # FFFF Check whether incoming IP is allowed!
-        tls = self.serverContext.sock(sock, serverMode=1)
+        self._lock.acquire()
+        try:
+            tls = self.serverContext.sock(sock, serverMode=1)
+        finally:
+            self._lock.release()
         sock.setblocking(0)
         con = MMTPServerConnection(sock, tls, self.onPacketReceived)
         self.register(con)