Ticket #150: 150-proxy.patch

File 150-proxy.patch, 3.4 KB (added by killyourtv, 11 years ago)
  • foolscap/negotiate.py

    From 44cfa90d5efcad3146064d915c9ddef8cd276ea9 Mon Sep 17 00:00:00 2001
    From: Kill Your TV <killyourtv@mail.i2p>
    Date: Wed, 27 Jun 2012 20:46:07 +0000
    Subject: [PATCH] proxy support
    
    ---
     foolscap/negotiate.py | 20 +++++++++++++++-----
     foolscap/pb.py        |  3 +++
     2 files changed, 18 insertions(+), 5 deletions(-)
    
    diff --git a/foolscap/negotiate.py b/foolscap/negotiate.py
    index 36b08ec..cb2ecdf 100644
    a b class Negotiation(protocol.Protocol): 
    331331        # we are using an encrypted Tub is separate, and expressed in our
    332332        # Hello block.
    333333        req = []
     334        proxyPrefix = ''
     335        if 'outbound-proxy' in self.tub.options:
     336            proxyPrefix = 'http://' + self.targetHost
     337            self.log("sendPlaintextClient: using HTTP Proxy %s"
     338                % self.tub.options['outbound-proxy'])
    334339        if self.target.encrypted:
    335340            self.log("sendPlaintextClient: GET for tubID %s" %
    336341                     self.target.tubID)
    337             req.append("GET /id/%s HTTP/1.1" % self.target.tubID)
     342            req.append("GET %s/id/%s HTTP/1.1" % (proxyPrefix, self.target.tubID))
    338343        else:
    339344            self.log("sendPlaintextClient: GET for no tubID")
    340             req.append("GET /id/ HTTP/1.1")
     345            req.append("GET %s/id/ HTTP/1.1" % proxyPrefix)
    341346        req.append("Host: %s" % self.targetHost)
    342347        self.log("sendPlaintextClient: wantEncryption=%s" % self.wantEncryption)
    343348        if self.wantEncryption:
    class TubConnector(object): 
    13791384            if location in self.attemptedLocations:
    13801385                continue
    13811386            self.attemptedLocations.append(location)
    1382             host, port = location
     1387            if 'outbound-proxy' in self.tub.options:
     1388                host, port = self.tub.options['outbound-proxy'].split(':')
     1389                destination = location[0]
     1390            else:
     1391                host, port = location
     1392                destination = host
    13831393            lp = self.log("connectTCP to %s" % (location,))
    1384             f = TubConnectorClientFactory(self, host, lp)
    1385             c = reactor.connectTCP(host, port, f)
     1394            f = TubConnectorClientFactory(self, destination, lp)
     1395            c = reactor.connectTCP(host, int(port), f)
    13861396            self.pendingConnections[f] = c
    13871397            # the tcp.Connector that we get back from reactor.connectTCP will
    13881398            # retain a reference to the transport that it creates, so we can
  • foolscap/pb.py

    diff --git a/foolscap/pb.py b/foolscap/pb.py
    index 473d853..ff7adb6 100644
    a b class Tub(service.MultiService): 
    205205                    connection negotiation. Currently defined keys are:
    206206                     - debug_slow: if True, wait half a second between
    207207                                   each negotiation response
     208                     - outbound-proxy: if set, connect using this HTTP proxy
    208209
    209210    @ivar brokers: maps TubIDs to L{Broker} instances
    210211
    class Tub(service.MultiService): 
    363364            self.setLogGathererFURL(value)
    364365        elif name == "log-gatherer-furlfile":
    365366            self.setLogGathererFURLFile(value)
     367        elif name == "outbound-proxy":
     368            self.options['outbound-proxy'] = value
    366369        elif name == "bridge-twisted-logs":
    367370            assert value is not False, "cannot unbridge twisted logs"
    368371            if value is True: