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

[minion-cvs] Add TOS flags to client connections; debug timeout impl...



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

Modified Files:
	MMTPClient.py NetUtils.py TLSConnection.py 
Log Message:
Add TOS flags to client connections; debug timeout implementation.

Index: MMTPClient.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/MMTPClient.py,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- MMTPClient.py	11 Jan 2004 07:38:27 -0000	1.48
+++ MMTPClient.py	12 Jan 2004 00:49:00 -0000	1.49
@@ -266,6 +266,9 @@
         LOG.debug("MMTP protocol negotaiated with %s: version %s",
                   self.address, self.protocol)
 
+        # Now that we're connected, optimize for throughput.
+        mixminion.NetUtils.optimizeThroughput(self.sock)
+
         self.onRead = self.onDataRead
         self.onWrite = self.onDataWritten
         self.beginReading()
@@ -445,7 +448,8 @@
         now = time.time()
         wr,ww,isopen=con.process(fd in rfds, fd in wfds)
         if isopen:
-            con.tryTimeout(now-timeout)
+            if con.tryTimeout(now-timeout):
+                isopen = 0
 
     # If anything wasn't delivered, raise MixProtocolError.
     for d in deliverables:
@@ -457,7 +461,7 @@
     if con._isFailed:
         raise MixProtocolError("Error occurred on connection to %s"%serverName)
 
-def pingServer(routing, timeout=5):
+def pingServer(routing, timeout=60):
     """Try to connect to a server and send a junk packet.
 
        May raise MixProtocolBadAuth, or other MixProtocolError if server

Index: NetUtils.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/NetUtils.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- NetUtils.py	8 Jan 2004 18:09:49 -0000	1.8
+++ NetUtils.py	12 Jan 2004 00:49:00 -0000	1.9
@@ -13,8 +13,10 @@
 import signal
 import socket
 import string
+import sys
 import time
 from mixminion.Common import LOG, TimeoutError, _ALLCHARS
+import mixminion._minionlib
 
 #======================================================================
 # Global vars
@@ -25,10 +27,7 @@
 # Local copies of socket.AF_INET4 and socket.AF_INET6.  (AF_INET6 may be
 #  unsupported.)
 AF_INET = socket.AF_INET
-try:
-    AF_INET6 = socket.AF_INET6
-except AttributeError:
-    AF_INET6 = "<Sorry, no IP6>"
+AF_INET6 = getattr(socket, "AF_INET6", "<Sorry, no IP6>")
 
 # For windows -- list of errno values that we can expect when blocking IO
 # blocks on a connect.
@@ -37,6 +36,20 @@
    if hasattr(errno,ename) ]
 del ename
 
+IPTOS_THROUGHPUT = getattr(mixminion._minionlib, "IPTOS_THROUGHPUT", None)
+
+#======================================================================
+def optimizeThroughput(sock):
+    """DOCDOC"""
+    if not IPTOS_THROUGHPUT: 
+        return
+    if sys.platform in ('cygwin', 'dgux', 'sni-sysv'):
+        # According to rumor, these platforms handle socket.IP_TOS
+        # incorrectly.  I'm too chicken to take the chance until
+        # I hear differetly.
+        return
+    sock.setsockopt(socket.SOL_IP, socket.IP_TOS, IPTOS_THROUGHPUT)
+
 #======================================================================
 if hasattr(socket, 'getaddrinfo'):
     def getIPs(name):

Index: TLSConnection.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/TLSConnection.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- TLSConnection.py	11 Jan 2004 07:38:27 -0000	1.4
+++ TLSConnection.py	12 Jan 2004 00:49:00 -0000	1.5
@@ -149,12 +149,15 @@
 
     def tryTimeout(self, cutoff):
         """Close self.sock if the last activity on this connection was
-           before 'cutoff'."""
+           before 'cutoff'.  Returns true iff the connection is timed out.
+        """
         if self.lastActivity <= cutoff:
-            LOG.warn("Connection to %s timed out: %s seconds without activity",
+            LOG.warn("Connection to %s timed out: %.2f seconds without activity",
                      self.address, time.time()-self.lastActivity)
             self.onTimeout()
             self.__close()
+            return 1
+        return 0
 
     def getInbuf(self, maxBytes=None, clear=0):
         """Return up to 'maxBytes' bytes from the front of the input buffer.
@@ -385,6 +388,8 @@
         """Given that we've received read/write events as indicated in r/w,
            advance the state of the connection as much as possible.  Return
            is as in 'getStatus'."""
+        if not (r or w):
+            return self.wantRead, self.wantWrite, (self.sock is not None)
         try:
             self.lastActivity = time.time()
             while self.__stateFn(r, w):