Revision
1475
Author
dreid@apple.com
Date
2007-04-11 14:36:28 -0700 (Wed, 11 Apr 2007)

Log Message

Ad an UnknownPortError on the server, and on the client trap it and log it.

Also tag the request so we don't end up asking pydirector for the resolved remoteAddr multiple times. (such as with request.locateResource())

Modified Paths

Diff

Modified: CalendarServer/trunk/lib-patches/PyDirector/pydirector.pdamp.patch (1474 => 1475)


--- CalendarServer/trunk/lib-patches/PyDirector/pydirector.pdamp.patch	2007-04-11 18:29:16 UTC (rev 1474)
+++ CalendarServer/trunk/lib-patches/PyDirector/pydirector.pdamp.patch	2007-04-11 21:36:28 UTC (rev 1475)
@@ -1,9 +1,12 @@
 --- pydirector/pdamp.py	1969-12-31 16:00:00.000000000 -0800
 +++ pydirector/pdamp.py	2007-04-10 17:25:22.000000000 -0700
-@@ -0,0 +1,26 @@
+@@ -0,0 +1,34 @@
 +from twisted.internet import protocol
 +from twisted.protocols import amp
 +
++class UnknownPortError(Exception):
++    pass
++
 +class GetClientAddress(amp.Command):
 +    arguments = [('host', amp.String()),
 +                 ('port', amp.Integer())]
@@ -11,13 +14,18 @@
 +    response = [('host', amp.String()),
 +                ('port', amp.Integer())]
 +
++    errors = {UnknownPortError: 'UNKNOWN_PORT'}
 +
++
 +class PDControlProtocol(amp.AMP):
 +    def __init__(self, director):
 +        self.director = director
 +
 +    def getClientAddress(self, host, port):
 +        host, port = self.director.getClientAddress(host, port)
++        if (host, port) == (None, None):
++            raise UnknownPortError()
++
 +        return {'host': host, 'port': port}
 +    GetClientAddress.responder(getClientAddress)
 +

Modified: CalendarServer/trunk/lib-patches/PyDirector/pydirector.pdmain.patch (1474 => 1475)


--- CalendarServer/trunk/lib-patches/PyDirector/pydirector.pdmain.patch	2007-04-11 18:29:16 UTC (rev 1474)
+++ CalendarServer/trunk/lib-patches/PyDirector/pydirector.pdmain.patch	2007-04-11 21:36:28 UTC (rev 1475)
@@ -21,7 +21,7 @@
 +                           pdamp.PDControlFactory(self))
 +
 +    def getClientAddress(self, host, port):
-+        return self._connections[(host, port)]
++        return self._connections.get((host, port), (None, None))
 +
 +    def setClientAddress(self, host, peer):
 +        self._connections[host] = peer

Modified: CalendarServer/trunk/twistedcaldav/pdmonster.py (1474 => 1475)


--- CalendarServer/trunk/twistedcaldav/pdmonster.py	2007-04-11 18:29:16 UTC (rev 1474)
+++ CalendarServer/trunk/twistedcaldav/pdmonster.py	2007-04-11 21:36:28 UTC (rev 1475)
@@ -22,20 +22,30 @@
 
             return self.hook(request)
 
+        def _gotError(result):
+            result.trap(amp.RemoteAmpError)
+            if result.value.errorCode != 'UNKNOWN_PORT':
+                return result
+            logging.err('Unknown Port: %s' % (request.remoteAddr,))
+
         def _gotAddress(result):
             logging.debug('result = %r' % (result,))
             request.remoteAddr = address.IPv4Address(
                 'TCP',
                 result['host'],
                 int(result['port']))
+            request._pdRewritten = True
 
         if self.protocol is not None:
+            if hasattr(request, '_pdRewritten'):
+                return
+
             host, port = request.remoteAddr.host, request.remoteAddr.port
             logging.debug("GetClientAddress(host=%r, port=%r)" % (host, port))
             d = self.protocol.callRemoteString("GetClientAddress",
                                                   host=host,
                                                   port=str(port))
-            d.addCallback(_gotAddress)
+            d.addCallbacks(_gotAddress, _gotError)
             return d
 
         else: