Ticket #4021: 4021_address_eventTransport.2.patch

File 4021_address_eventTransport.2.patch, 7.2 KB (added by jasonjwwilliams, 6 years ago)

Changed portNumber to generic address on log messages in format "host:port" & added eventTransport field.

  • twisted/internet/protocol.py

    diff --git a/twisted/internet/protocol.py b/twisted/internet/protocol.py
    index 0eda004..d7973ca 100644
    a b class AbstractDatagramProtocol: 
    622622        This will be called by makeConnection(), users should not call it.
    623623        """
    624624        if not self.numPorts:
    625             log.msg(eventSource=self, eventType="start", protocol=self)
     625            log.msg(eventSource=self, eventType="start", eventTransport="udp",
     626                    address="", protocol=self)
    626627            self.startProtocol()
    627628        self.numPorts = self.numPorts + 1
    628629
    class AbstractDatagramProtocol: 
    636637        self.numPorts = self.numPorts - 1
    637638        self.transport = None
    638639        if not self.numPorts:
    639             log.msg(eventSource=self, eventType="stop", protocol=self)
     640            log.msg(eventSource=self, eventType="stop", eventTransport="udp",
     641                    address="", protocol=self)
    640642            self.stopProtocol()
    641643
    642644
  • twisted/internet/tcp.py

    diff --git a/twisted/internet/tcp.py b/twisted/internet/tcp.py
    index 44cb5f9..0df7d6f 100644
    a b class Port(base.BasePort, _SocketCloser): 
    859859        # Make sure that if we listened on port 0, we update that to
    860860        # reflect what the OS actually assigned us.
    861861        self._realPortNumber = skt.getsockname()[1]
     862       
     863        _ip = self.interface if self.interface else "0.0.0.0"
    862864
    863         log.msg(eventSource=self, eventType="start", factory=self.factory,
    864                 portNumber=self._realPortNumber)
     865        log.msg(eventSource=self, eventType="start", eventTransport="tcp",
     866                factory=self.factory,
     867                address="%s:%d" % (_ip,self._realPortNumber))
    865868
    866869        # The order of the next 6 lines is kind of bizarre.  If no one
    867870        # can explain it, perhaps we should re-arrange them.
    class Port(base.BasePort, _SocketCloser): 
    976979        """
    977980        Log message for closing port
    978981        """
    979         log.msg(eventSource=self, eventType="stop", factory=self.factory,
    980                 portNumber=self._realPortNumber)
     982        _ip = self.interface if self.interface else "0.0.0.0"
     983        log.msg(eventSource=self, eventType="stop", eventTransport="tcp",
     984                factory=self.factory,
     985                address="%s:%d" % (_ip,self._realPortNumber))
    981986
    982987
    983988    def connectionLost(self, reason):
  • twisted/internet/test/test_protocol.py

    diff --git a/twisted/internet/test/test_protocol.py b/twisted/internet/test/test_protocol.py
    index 726f02e..780533b 100644
    a b class AbstractDatagramProtocolTestCase(TestCase, DictSubsetMixin): 
    360360            self.events[0],
    361361            {"eventSource": self.proto,
    362362             "protocol": self.proto,
    363              "eventType": "start"})
     363             "eventType": "start",
     364             "eventTransport" : "udp",
     365             "address" : ""})
    364366
    365367
    366368    def test_doStopLogMessage(self):
    class AbstractDatagramProtocolTestCase(TestCase, DictSubsetMixin): 
    375377            self.events[0],
    376378            {"eventSource": self.proto,
    377379             "protocol": self.proto,
    378              "eventType": "stop"})
     380             "eventType": "stop",
     381             "eventTransport" : "udp",
     382             "address" : ""})
  • twisted/internet/test/test_tcp.py

    diff --git a/twisted/internet/test/test_tcp.py b/twisted/internet/test/test_tcp.py
    index 3497b0a..00ffaf8 100644
    a b class TCPPortTestsBuilder(ReactorBuilder, ObjectModelIntegrationMixin, 
    325325        ReactorBuilder.setUp(self)
    326326        self.factory = ServerFactory()
    327327        self.events = []
     328        self.transportType = "tcp"
    328329        log.addObserver(self.events.append)
    329330        self.addCleanup(log.removeObserver, self.events.append)
    330331
    class TCPPortTestsBuilder(ReactorBuilder, ObjectModelIntegrationMixin, 
    341342        Get the expected port number for the TCP port that experienced
    342343        the connection event.
    343344        """
    344         return port.getHost().port
     345        return str(port.getHost().port)
     346       
     347    def getExpectedConnectionPortHost(self, port):
     348        """
     349        Get the expected hostname/IP for the TCP port that experienced
     350        the connection event.
     351        """
     352        return port.getHost().host
    345353
    346354
    347355    def test_portStartStopLogMessage(self):
    class TCPPortTestsBuilder(ReactorBuilder, ObjectModelIntegrationMixin, 
    353361        reactor = self.buildReactor()
    354362        p = self.getListeningPort(reactor)
    355363        listenPort = self.getExpectedConnectionPortNumber(p)
     364        listenHost = self.getExpectedConnectionPortHost(p)
    356365
    357366        def stopReactor(ignored):
    358367            reactor.stop()
    class TCPPortTestsBuilder(ReactorBuilder, ObjectModelIntegrationMixin, 
    364373        self.runReactor(reactor)
    365374
    366375        expected = {
    367             "eventSource": p, "portNumber": listenPort, "factory": self.factory}
     376            "eventSource": p, "address": "%s:%s" % (listenHost, listenPort),
     377            "eventTransport" : self.transportType, "factory": self.factory}
    368378
    369379        for event in self.events:
    370380            if event.get("eventType") == "start":
  • twisted/internet/test/test_unix.py

    diff --git a/twisted/internet/test/test_unix.py b/twisted/internet/test/test_unix.py
    index 293e965..7a3040a 100644
    a b class UNIXPortTestsBuilder(TCPPortTestsBuilder): 
    147147    """
    148148
    149149    requiredInterfaces = [interfaces.IReactorUNIX]
     150   
     151    def setUp(self):
     152        """
     153        Extend TCP test setUp to set transportType to 'unix'.
     154        """
     155        TCPPortTestsBuilder.setUp(self)
     156        self.transportType = "unix"
    150157
    151158    def getListeningPort(self, reactor):
    152159        """
    class UNIXPortTestsBuilder(TCPPortTestsBuilder): 
    160167        Get the expected UNIX socket path from the given UNIX listening port.
    161168        """
    162169        return port.getHost().name
     170   
     171    def getExpectedConnectionPortHost(self, port):
     172        """
     173        Return an empty string, since there is no hostname for a UNIX socket.
     174        """
     175       
     176        return ""
    163177
    164178
    165179globals().update(UNIXTestsBuilder.makeTestCaseClasses())
  • twisted/internet/unix.py

    diff --git a/twisted/internet/unix.py b/twisted/internet/unix.py
    index 1cfe8cd..c84f548 100644
    a b class Port(_UNIXPort, tcp.Port): 
    112112                    except:
    113113                        pass
    114114
    115         log.msg(eventSource=self, eventType="start", factory=self.factory,
    116                 portNumber=self.port)
     115        log.msg(eventSource=self, eventType="start", eventTransport="unix",
     116                address=":%s" % self.port,factory=self.factory)
    117117        self.factory.doStart()
    118118        try:
    119119            skt = self.createInternetSocket()
    class Port(_UNIXPort, tcp.Port): 
    136136        """
    137137        Log message for closing socket
    138138        """
    139         log.msg(eventSource=self, eventType="stop", factory=self.factory,
    140                 portNumber=self.port)
     139        log.msg(eventSource=self, eventType="stop", eventTransport="unix",
     140                address=":%s" % self.port, factory=self.factory)
    141141
    142142
    143143    def connectionLost(self, reason):