def handlePLAINTEXTServer(self, header): """ Parse a complete HTTP-like Foolscap negotiation request and begin proxying to a destination selected based on the extract TubID. """ # the client sends us a GET message lines = header.split("\r\n") if not lines[0].startswith("GET "): raise BananaError("not right") command, url, version = lines[0].split() if not url.startswith("/id/"): # probably a web browser raise BananaError("not right") targetTubID = url[4:] Message.log(event_type=u"handlePLAINTEXTServer", tub_id=targetTubID) if targetTubID == "": # they're asking for an old UnauthenticatedTub. Refuse. raise NegotiationError("secure Tubs require encryption") if isSubstring("Upgrade: TLS/1.0\r\n", header): wantEncrypted = True else: wantEncrypted = False Message.log(event_type=u"handlePLAINTEXTServer", want_encrypted=wantEncrypted) self._handleTubRequest(header, targetTubID)
def checkForFailure(self): if not self.active: return if (self.remainingLocations or self.pendingConnections or self.pendingNegotiations): return if not self.validHints: self.failureReason = Failure(NoLocationHintsError()) # we have no more options, so the connection attempt will fail. The # getBrokerForTubRef may have succeeded, however, if the other side # tried to connect to us at exactly the same time, they were the # master, they established their connection first (but the final # decision is still in flight), and they hung up on our connection # because they felt it was a duplicate. So, if self.failureReason # indicates a duplicate connection, do not signal a failure here. We # leave the connection timer in place in case they lied about having # a duplicate connection ready to go. if (self.failureReason.check(RemoteNegotiationError) and isSubstring(self.failureReason.value.args[0], "Duplicate connection")): self.log("TubConnector.checkForFailure: connection attempt " "failed because the other end decided ours was a " "duplicate connection, so we won't signal the " "failure here") return self.failed()