Esempio n. 1
0
 def checkTCPEndpoint(self, hint, expected_host, expected_port):
     with mock.patch("foolscap.connections.tcp.HostnameEndpoint",
                     side_effect=FakeHostnameEndpoint):
         d = get_endpoint(hint, {"tcp": tcp.default()}, ConnectionInfo())
     (ep, host) = self.successResultOf(d)
     self.assertTrue(isinstance(ep, FakeHostnameEndpoint), ep)
     self.assertIs(ep.reactor, reactor)
     self.assertEqual(ep.host, expected_host)
     self.assertEqual(ep.port, expected_port)
Esempio n. 2
0
    def __init__(self, parent, tubref, connectionPlugins):
        self._logparent = log.msg(format="TubConnector created from "
                                  "%(fromtubid)s to %(totubid)s",
                                  fromtubid=parent.tubID,
                                  totubid=tubref.getTubID(),
                                  level=OPERATIONAL,
                                  facility="foolscap.connection",
                                  umid="pH4QDA")
        self.tub = parent
        self.target = tubref
        self.connectionPlugins = connectionPlugins
        self._connectionInfo = ConnectionInfo()
        self.remainingLocations = list(self.target.getLocations())
        # attemptedLocations keeps track of where we've already tried to
        # connect, so we don't try them twice, even if they appear in the
        # hints multiple times. this isn't too clever: slight variations of
        # the same hint will fool it, but it should be enough to avoid
        # infinite redirection loops.
        self.attemptedLocations = []

        # validHints tracks which hints were successfully turned into
        # endpoints. If we don't recognize any hint type in a FURL,
        # validHints will be empty when we're done, and we'll signal
        # NoLocationHintsError
        self.validHints = []

        # pendingConnections contains a Deferred for each endpoint.connect()
        # that has started (but not yet established) a connection. We keep
        # track of these so we can shut them down (using d.cancel()) when we
        # stop connecting (either because one of the other connections
        # succeeded, or because someone told us to give up).
        self.pendingConnections = set()

        # self.pendingNegotiations maps Negotiation instances (connected but
        # not finished negotiation) to the hint that got us the connection.
        # We track these so we can abandon the negotiation.
        self.pendingNegotiations = {}
Esempio n. 3
0
 def checkUnknownEndpoint(self, hint):
     d = get_endpoint(hint, {"tcp": tcp.default()}, ConnectionInfo())
     self.failureResultOf(d, ipb.InvalidHintError)