[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[minion-cvs] First cut at an 0.0.2.2 maintenance release.
Update of /home/minion/cvsroot/src/minion/lib/mixminion/server
In directory moria.mit.edu:/tmp/cvs-serv7643/lib/mixminion/server
Modified Files:
Tag: mixminion-v0-0-2-patches
MMTPServer.py ServerMain.py
Log Message:
First cut at an 0.0.2.2 maintenance release.
Index: MMTPServer.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/MMTPServer.py,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -u -d -r1.12 -r1.12.2.1
--- MMTPServer.py 7 Jan 2003 19:17:57 -0000 1.12
+++ MMTPServer.py 10 Jan 2003 19:44:46 -0000 1.12.2.1
@@ -70,11 +70,6 @@
If we receive an unblocked signal, return immediately.
"""
-## trace("%s readers (%s), %s writers (%s)" % (len(self.readers),
-## readers,
-## len(self.writers),
-## writers))
-
readfds = self.readers.keys()
writefds = self.writers.keys()
try:
@@ -86,13 +81,10 @@
raise e
for fd in readfds:
- #trace("Select got a read on fd %s",fd)
self.readers[fd].handleRead()
for fd in writefds:
- #trace("Select got a write on fd %s", fd)
self.writers[fd].handleWrite()
for fd in exfds:
- #trace("Select got an exception on fd %s", fd)
if self.readers.has_key(fd): del self.readers[fd]
if self.writers.has_key(fd): del self.writers[fd]
@@ -438,10 +430,10 @@
self.handleFail(retriable=1)
self.__sock.close()
self.__server.unregister(self)
- except _ml.TLSError:
+ except _ml.TLSError, e:
if self.__state != self.__shutdownFn:
- warn("Unexpected error: closing connection to %s",
- self.address)
+ warn("Unexpected error: %s. Closing connection to %s.",
+ e, self.address)
self.shutdown(err=1, retriable=1)
else:
warn("Error while shutting down: closing connection to %s",
@@ -531,11 +523,13 @@
if not m:
warn("Bad protocol list. Closing connection to %s", self.address)
self.shutdown(err=1)
+ return
protocols = m.group(1).split(",")
if "0.1" not in protocols:
warn("Unsupported protocol list. Closing connection to %s",
self.address)
- self.shutdown(err=1); return
+ self.shutdown(err=1)
+ return
else:
trace("protocol ok (fd %s)", self.fd)
self.finished = self.__sentProtocol
@@ -599,6 +593,8 @@
def __init__(self, context, ip, port, keyID, messageList, handleList,
sentCallback=None, failCallback=None):
"""Create a connection to send messages to an MMTP server.
+ Raises socket.error if the connection fails.
+
ip -- The IP of the destination server.
port -- The port to connect to.
keyID -- None, or the expected SHA1 hash of the server's public key
@@ -616,10 +612,12 @@
self.ip = ip
try:
sock.connect((ip, port))
- except socket.error:
+ except socket.error, e:
# This will always raise an error, since we're nonblocking. That's
- # okay.
- pass
+ # okay... but it had better be EINPROGRESS.
+ if e[0] != errno.EINPROGRESS:
+ raise e
+
tls = context.sock(sock)
SimpleTLSConnection.__init__(self, sock, tls, 0, "%s:%s"%(ip,port))
@@ -638,9 +636,11 @@
keyID = sha1(self.getPeerPK().encode_key(public=1))
if self.keyID is not None:
if keyID != self.keyID:
- warn("Got unexpected Key ID from %s", self.address)
- # This may work again in a couple of hours
+ warn("Got unexpected Key ID from %s; shutting down connection",
+ self.address)
+ # The keyid may start being good in a while.
self.shutdown(err=1,retriable=1)
+ return
else:
debug("KeyID from %s is valid", self.address)
@@ -778,11 +778,17 @@
assert len(m) == MESSAGE_LEN
assert len(h) < 32
- con = MMTPClientConnection(self.context,
- ip, port, keyID, messages, handles,
- self.onMessageSent,
- self.onMessageUndeliverable)
- con.register(self)
+ try:
+ con = MMTPClientConnection(self.context,
+ ip, port, keyID, messages, handles,
+ self.onMessageSent,
+ self.onMessageUndeliverable)
+ con.register(self)
+ except socket.error, e:
+ LOG.error("Unexpected socket error connecting to %s:%s: %s",
+ ip, port, e)
+ for m,h in zip(messages, handles):
+ self.onMessageUndeliverable(m,h,1)
def onMessageReceived(self, msg):
pass
Index: ServerMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerMain.py,v
retrieving revision 1.26
retrieving revision 1.26.2.1
diff -u -d -r1.26 -r1.26.2.1
--- ServerMain.py 8 Jan 2003 03:56:54 -0000 1.26
+++ ServerMain.py 10 Jan 2003 19:44:46 -0000 1.26.2.1
@@ -13,6 +13,7 @@
import fcntl
import getopt
import os
+import signal
import sys
import time
@@ -191,6 +192,28 @@
def onMessageUndeliverable(self, msg, handle, retriable):
self.outgoingQueue.deliveryFailed(handle, retriable)
+
+#----------------------------------------------------------------------
+STOPPING = 0
+def _sigTermHandler(signal_num, _):
+ '''(Signal handler for SIGTERM)'''
+ signal.signal(signal_num, _sigTermHandler)
+ global STOPPING
+ STOPPING = 1
+
+GOT_HUP = 0
+def _sigHupHandler(signal_num, _):
+ '''(Signal handler for SIGTERM)'''
+ signal.signal(signal_num, _sigHupHandler)
+ global GOT_HUP
+ GOT_HUP = 1
+
+def installSignalHandlers():
+ "DOCDOC"
+ signal.signal(signal.SIGHUP, _sigHupHandler)
+ signal.signal(signal.SIGTERM, _sigTermHandler)
+
+#----------------------------------------------------------------------
class MixminionServer:
"""Wraps and drives all the queues, and the async net server. Handles
all timed events."""
@@ -286,7 +309,8 @@
def run(self):
"""Run the server; don't return unless we hit an exception."""
-
+ global GOT_HUP
+
f = open(self.pidFile, 'wt')
f.write("%s\n" % os.getpid())
f.close()
@@ -319,7 +343,15 @@
timeLeft = nextEventTime - now
while timeLeft > 0:
# Handle pending network events
- self.mmtpServer.process(timeLeft)
+ self.mmtpServer.process(2)
+ if STOPPING:
+ LOG.info("Caught sigterm; shutting down.")
+ return
+ elif GOT_HUP:
+ LOG.info("Caught sighup")
+ LOG.info("Resetting logs")
+ LOG.reset()
+ GOT_HUP = 0
# Process any new messages that have come in, placing them
# into the mix pool.
self.incomingQueue.sendReadyMessages()
@@ -494,6 +526,8 @@
LOG.fatal_exc(info,
"Exception while starting server in the background")
os._exit(0)
+
+ installSignalHandlers()
LOG.info("Starting server")
try: