def connect(self, From, to,
                protocolName, clientFactory,
                chooser):

        publicIP = self._determinePublicIP()

        A = dict(From=From,
                 to=to,
                 protocol=protocolName)

        if self.service.dispatcher is not None:
            # tell them exactly where they can shove it
            A['udp_source'] = (publicIP,
                               self.service.sharedUDPPortnum)
        else:
            # don't tell them because we don't know
            log.msg("dispatcher unavailable when connecting")

        D = self.callRemote(Inbound, **A)

        def _connected(answer):
            listenersD = defer.maybeDeferred(chooser, answer['listeners'])
            def gotListeners(listeners):
                allConnectionAttempts = []
                for listener in listeners:
                    d = self.attemptConnectionMethods(
                        listener['methods'],
                        listener['id'],
                        From, to,
                        protocolName, clientFactory,
                        )
                    allConnectionAttempts.append(d)
                return defer.DeferredList(allConnectionAttempts)
            listenersD.addCallback(gotListeners)
            def finishedAllAttempts(results):
                succeededAny = False
                failures = []
                if not results:
                    return Failure(NoAttemptsMade(
                            "there was no available path for connections "
                            "(%r->%r/%s)" % (From, to, protocolName)))
                for succeeded, result in results:
                    if succeeded:
                        succeededAny = True
                        randomConnection = result
                        break
                    else:
                        failures.append(result)
                if not succeededAny:
                    return Failure(AttemptsFailed(
                            [failure.getBriefTraceback() for failure in failures]))

                # XXX TODO: this connection is really random; connectQ2Q should
                # not return one of the connections it's made, put it into your
                # protocol's connectionMade handler

                return randomConnection

            return listenersD.addCallback(finishedAllAttempts)
        return D.addCallback(_connected)
Issue an INBOUND command, creating a virtual connection to the peer,
dataset/ETHPy150Open twisted/vertex/vertex/q2q.py/Q2Q.connect