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

[minion-cvs] Fail gracefully on unexpected close



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

Modified Files:
	MMTPClient.py test.py 
Log Message:
Fail gracefully on unexpected close

Index: MMTPClient.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/MMTPClient.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- MMTPClient.py	5 May 2003 00:38:45 -0000	1.29
+++ MMTPClient.py	5 May 2003 00:42:49 -0000	1.30
@@ -67,7 +67,7 @@
            errors."""
         try:
             self._connect(connectTimeout)
-        except (socket.error, _ml.TLSError), e:
+        except (socket.error, _ml.TLSError, _ml.TLSClosed), e:
             self._raise(e, "connecting")
 
     def _raise(self, err, action):
@@ -78,10 +78,14 @@
             tp = "Socket"
         elif isinstance(err, _ml.TLSError):
             tp = "TLS"
+        elif isinstance(err, _ml.TLSClosed):
+            tp = "TLSClosed"
         else:
             tp = str(type(err))
-        raise MixProtocolError("%s error while %s to %s:%s: %s",
-             tp, action, self.targetIP, self.targetPort, err)
+        e = MixProtocolError("%s error while %s to %s:%s: %s",
+                             tp, action, self.targetIP, self.targetPort, err)
+        e.base = err
+        raise e
 
     def _connect(self, connectTimeout=None):
         """Helper method; implements _connect."""
@@ -148,7 +152,7 @@
         try:
             self.tls.renegotiate()
             self.tls.do_handshake()
-        except (socket.error, _ml.TLSError), e:
+        except (socket.error, _ml.TLSError, _ml.TLSClosed), e:
             self._raise(e, "renegotiating connection")
 
     def sendPacket(self, packet):
@@ -193,7 +197,7 @@
                 LOG.warn("Received bad ACK from server")
                 raise MixProtocolError("Bad ACK received")
             LOG.debug("ACK received; packet successfully delivered")
-        except (socket.error, _ml.TLSError), e:
+        except (socket.error, _ml.TLSError, _ml.TLSClosed), e:
             self._raise(e, "sending packet")
             
     def shutdown(self):
@@ -205,7 +209,7 @@
                 self.tls.shutdown()
             if self.sock is not None:
                 self.sock.close()
-        except (socket.error, _ml.TLSError), e:
+        except (socket.error, _ml.TLSError, _ml.TLSClosed), e:
             self._raise(e, "closing connection")
         LOG.debug("Connection closed")
 

Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- test.py	5 May 2003 00:38:45 -0000	1.101
+++ test.py	5 May 2003 00:42:49 -0000	1.102
@@ -3136,7 +3136,9 @@
         # Was an exception raised?
         self.assertEquals(1, len(excList))
         # Was it the right exception?
-        self.assert_(isinstance(excList[0][1], _ml.TLSClosed))
+        ex = excList[0][1]
+        self.assert_(isinstance(ex, MixError))
+        self.assert_(isinstance(ex.base, _ml.TLSClosed))
 
         for _ in xrange(3):
             server.process(0.1)