Ticket #150: 150_http_proxy.txt

File 150_http_proxy.txt, 3.1 KB (added by duck, 14 years ago)

HTTP proxy support in Negotiate

Line 
1diff --git foolscap/negotiate.py foolscap/negotiate.py
2index f74daba..1eade3d 100644
3--- foolscap/negotiate.py
4+++ foolscap/negotiate.py
5@@ -329,13 +329,19 @@ class Negotiation(protocol.Protocol):
6         # we are using an encrypted Tub is separate, and expressed in our
7         # Hello block.
8         req = []
9+        # I2P: use HTTP Proxy protocol
10+        proxyPrefix = ''
11+        if 'httpProxy' in self.tub.options:
12+            proxyPrefix = 'http://' + self.targetHost
13+            self.log("sendPlaintextClient: using HTTP Proxy %s"
14+                % self.tub.options['httpProxy'])
15         if self.target.encrypted:
16             self.log("sendPlaintextClient: GET for tubID %s" %
17                      self.target.tubID)
18-            req.append("GET /id/%s HTTP/1.1" % self.target.tubID)
19+            req.append("GET %s/id/%s HTTP/1.1" % (proxyPrefix, self.target.tubID))
20         else:
21             self.log("sendPlaintextClient: GET for no tubID")
22-            req.append("GET /id/ HTTP/1.1")
23+            req.append("GET %s/id/ HTTP/1.1" % proxyPrefix)
24         req.append("Host: %s" % self.targetHost)
25         self.log("sendPlaintextClient: wantEncryption=%s" % self.wantEncryption)
26         if self.wantEncryption:
27@@ -1353,10 +1359,16 @@ class TubConnector(object):
28             if location in self.attemptedLocations:
29                 continue
30             self.attemptedLocations.append(location)
31-            host, port = location
32+            # I2P: Connect to HTTP Proxy instead of to destination
33+            if 'httpProxy' in self.tub.options:
34+                host, port = self.tub.options['httpProxy'].split(':')
35+                destination = location[0]
36+            else:
37+                host, port = location
38+                destination = host
39             lp = self.log("connectTCP to %s" % (location,))
40-            f = TubConnectorClientFactory(self, host, lp)
41-            c = reactor.connectTCP(host, port, f)
42+            f = TubConnectorClientFactory(self, destination, lp)
43+            c = reactor.connectTCP(host, int(port), f)
44             self.pendingConnections[f] = c
45             # the tcp.Connector that we get back from reactor.connectTCP will
46             # retain a reference to the transport that it creates, so we can
47diff --git foolscap/pb.py foolscap/pb.py
48index 35c8981..19b3ed8 100644
49--- foolscap/pb.py
50+++ foolscap/pb.py
51@@ -190,6 +190,7 @@ class Tub(service.MultiService):
52                     connection negotiation. Currently defined keys are:
53                      - debug_slow: if True, wait half a second between
54                                    each negotiation response
55+                     - http_proxy: if set, connect using this http_proxy
56 
57     @ivar brokers: maps TubIDs to L{Broker} instances
58 
59@@ -344,6 +345,8 @@ class Tub(service.MultiService):
60             self.setLogGathererFURL(value)
61         elif name == "log-gatherer-furlfile":
62             self.setLogGathererFURLFile(value)
63+        elif name == "httpProxy":
64+            self.options['httpProxy'] = value
65         elif name == "bridge-twisted-logs":
66             assert value is not False, "cannot unbridge twisted logs"
67             if value is True: