def _inboundimpl(self, ign, From, to, protocol, udp_source):

        # 2-tuples of factory, description
        srvfacts = self.service.getLocalFactories(From, to, protocol)

        result = []             # list of listener dicts

        if srvfacts:
            log.msg("local factories found for inbound request: %r" % (srvfacts,))
            localMethods = []
            publicIP = self._determinePublicIP()
            privateIP = self._determinePrivateIP()
            if self.service.inboundTCPPort is not None:
                tcpPort = self.service.inboundTCPPort.getHost().port
                localMethods.append(TCPMethod(
                        '%s:%d' %
                        (publicIP, tcpPort)))
                if publicIP != privateIP:
                    localMethods.append(TCPMethod(
                            '%s:%d' %
                            (privateIP, tcpPort)))

            if not self.service.udpEnabled:
                log.msg("udp not enabled -- but I so want to send udp traffic!")
            elif udp_source is None:
                log.msg("udp_source was none on inbound")
            else:
                if self.service.dispatcher is None:
                    log.msg("udp_source %s:%d, but dispatcher not running" %
                            udp_source)
                else:
                    remoteUDPHost, remoteUDPPort = udp_source
                    log.msg(
                        "remote PTCP: %s:%d, "
                        "local public IP: %s, local private IP: %s"
                        % (remoteUDPHost, remoteUDPPort, publicIP, privateIP) )

                    # Seed my NAT from my shared UDP port
                    udpPort = self.service.dispatcher.seedNAT(udp_source, self.service.sharedUDPPortnum)

                    if remoteUDPHost == publicIP and publicIP != privateIP:
                        log.msg(
                            "Remote IP matches local, public IP %r;"
                            " preferring internal IP %r" % (publicIP, privateIP))
                        localMethods.append(
                            PTCPMethod("%s:%d" % (privateIP, udpPort)))
                    localMethods.append(
                        PTCPMethod("%s:%d" % (publicIP, udpPort)))

                    # XXX CLEANUP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    privateUDPPort = self.service.dispatcher.seedNAT(udp_source)
                    localMethods.append(
                        PTCPMethod('%s:%d' % (publicIP, privateUDPPort)))

                    udpxPort = self.service.dispatcher.seedNAT(udp_source)
                    localMethods.append(
                        RPTCPMethod("%s:%d" % (publicIP, udpxPort)))

            if self.service.virtualEnabled:
                localMethods.append(VirtualMethod())
            log.msg('responding to inbound with local methods: %r' % (localMethods,))

            for serverFactory, description in srvfacts:
                expiryTime, listenID = self.service.mapListener(
                    to, From, protocol, serverFactory)
                result.append(dict(id=listenID,
                                   expires=expiryTime,
                                   methods=localMethods,
                                   description=description))

            # We've looked for our local factory.  Let's see if we have any
            # listening protocols elsewhere.


        key = (to, protocol)
        if key in self.service.listeningClients:
            args = dict(From=From,
                        to=to,
                        protocol=protocol,
                        udp_source=udp_source)
            DL = []
            lclients = self.service.listeningClients[key]
            log.msg("listeners found for %s:%r" % (to, protocol))
            for listener, listenCert, desc in lclients:
                log.msg("relaying inbound to %r via %r" % (to, listener))
                DL.append(listener.callRemote(Inbound, **args).addCallback(
                    self._massageClientInboundResponse, listener, result))

            def allListenerResponses(x):
                log.msg("all inbound responses received: %s" % (pformat(result),))
                return dict(listeners=result)
            return defer.DeferredList(DL).addCallback(allListenerResponses)
        else:
            log.msg("no listenening clients for %s:%r. local methods: %r" % (to,protocol, result))
            return dict(listeners=result)
dataset/ETHPy150Open twisted/vertex/vertex/q2q.py/Q2Q._inboundimpl/original