

def getConnection(self, micro_status_entry):
    "Return a deferred which will fire (if connection attempt is\n        successful) with a Connection Protocol made to *relay*.\n\n        There are three general cases to handle for incoming connection\n        requests:\n\n            1. We already have an open TLS connection to the requested relay.\n               In this case, immediately callback the deferred with the\n               open connection.\n            2. We're currently trying to connect to this relay. In this case,\n               add the request to a pending request list for this relay.\n               When the connection is made successfully, callback all\n               pending request deferreds with the Connection, or errback\n               all pending request deferreds on failure.\n            3. We have no open or pending connections to this relay (i.e.\n               this is the first connection request to this relay). In this\n               case, create a new list of pending requests for this connection\n               and add the current request. Create an SSL endpoint and add an\n               appropriate callback and errback. If the request is successful,\n               callback all pending requests with the open connection when\n               it opens; errback all pending requests on failure.\n\n        :param stem.descriptor.server_descriptor.RelayDescriptor relay:\n            relay to make a TLS connection to\n        :returns: **twisted.internet.defer.Deferred** which, on success, will\n            callback with an oppy.connection.connection.Connection Protocol\n            object\n\n        XXX raises:\n        "
    from twisted.internet import reactor
    m = micro_status_entry
    d = defer.Deferred()
    if (m.fingerprint in self._connection_dict):
        d.callback(self._connection_dict[m.fingerprint])
    elif (m.fingerprint in self._pending_request_dict):
        self._pending_request_dict[m.fingerprint].append(d)
    else:
        try:
            f = endpoints.connectProtocol(endpoints.SSL4ClientEndpoint(reactor, m.address, m.or_port, TLSClientContextFactory()), ConnectionBuildTask(self, m))
            f.addErrback(self._initialConnectionFailed, m.fingerprint)
            self._pending_request_dict[m.fingerprint] = [d]
        except Exception as e:
            self._initialConnectionFailed(e, m.fingerprint)
    return d

dataset/ETHPy150Open nskinkel/oppy/oppy/connection/connectionmanager.py ConnectionManager.getConnection/original