[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[minion-cvs] Add client-side timeout capability; appease pychecker.
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv15740/lib/mixminion
Modified Files:
MMTPClient.py test.py
Log Message:
Add client-side timeout capability; appease pychecker.
Index: MMTPClient.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/MMTPClient.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- MMTPClient.py 13 Jan 2003 06:16:42 -0000 1.16
+++ MMTPClient.py 14 Jan 2003 09:20:17 -0000 1.17
@@ -17,10 +17,15 @@
__all__ = [ "BlockingClientConnection", "sendMessages" ]
+import errno
+import signal
import socket
import mixminion._minionlib as _ml
from mixminion.Crypto import sha1, getCommonPRNG
-from mixminion.Common import MixProtocolError, LOG
+from mixminion.Common import MixProtocolError, LOG, MixError
+
+class TimeoutError(MixError):
+ pass
class BlockingClientConnection:
"""A BlockingClientConnection represents a MMTP connection to a single
@@ -48,15 +53,28 @@
self.tls = None
self.sock = None
- def connect(self):
+ def connect(self, timeout=None):
"""Negotiate the handshake and protocol."""
+ def sigalarmHandler(sig, _):
+ assert sig == signal.SIGALRM
+ if timeout:
+ signal.signal(signal.SIGALRM, sigalarmHandler)
+
# Connect to the server
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setblocking(1)
LOG.debug("Connecting to %s:%s", self.targetIP, self.targetPort)
# Do the TLS handshaking
- self.sock.connect((self.targetIP,self.targetPort))
+ if timeout:
+ signal.alarm(timeout)
+ try:
+ self.sock.connect((self.targetIP,self.targetPort))
+ except socket.error, e:
+ if e[0] == errno.EINTR:
+ raise TimeoutError("Connection timed out")
+ else:
+ raise e
LOG.debug("Handshaking with %s:%s",self.targetIP, self.targetPort)
self.tls = self.context.sock(self.sock.fileno())
# FFFF session resumption
Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- test.py 13 Jan 2003 06:35:52 -0000 1.73
+++ test.py 14 Jan 2003 09:20:17 -0000 1.74
@@ -1969,12 +1969,12 @@
# A one-hop/one-hop message.
m = bfm(p, SMTP_TYPE, "nobody@invalid", [self.server1], [self.server3])
- pkt = self.do_test_chain(m,
- [self.sp1,self.sp3],
- [FWD_TYPE, SMTP_TYPE],
- [self.server3.getRoutingInfo().pack(),
- "nobody@invalid"],
- p)
+ self.do_test_chain(m,
+ [self.sp1,self.sp3],
+ [FWD_TYPE, SMTP_TYPE],
+ [self.server3.getRoutingInfo().pack(),
+ "nobody@invalid"],
+ p)
# Try servers with multiple keys
m = bfm(p, SMTP_TYPE, "nobody@invalid", [self.server2], [self.server3])