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): |
331 | 331 | # we are using an encrypted Tub is separate, and expressed in our |
332 | 332 | # Hello block. |
333 | 333 | 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']) |
334 | 339 | if self.target.encrypted: |
335 | 340 | self.log("sendPlaintextClient: GET for tubID %s" % |
336 | 341 | 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)) |
338 | 343 | else: |
339 | 344 | 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) |
341 | 346 | req.append("Host: %s" % self.targetHost) |
342 | 347 | self.log("sendPlaintextClient: wantEncryption=%s" % self.wantEncryption) |
343 | 348 | if self.wantEncryption: |
… |
… |
class TubConnector(object): |
1379 | 1384 | if location in self.attemptedLocations: |
1380 | 1385 | continue |
1381 | 1386 | 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 |
1383 | 1393 | 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) |
1386 | 1396 | self.pendingConnections[f] = c |
1387 | 1397 | # the tcp.Connector that we get back from reactor.connectTCP will |
1388 | 1398 | # retain a reference to the transport that it creates, so we can |
diff --git a/foolscap/pb.py b/foolscap/pb.py
index 473d853..ff7adb6 100644
a
|
b
|
class Tub(service.MultiService): |
205 | 205 | connection negotiation. Currently defined keys are: |
206 | 206 | - debug_slow: if True, wait half a second between |
207 | 207 | each negotiation response |
| 208 | - outbound-proxy: if set, connect using this HTTP proxy |
208 | 209 | |
209 | 210 | @ivar brokers: maps TubIDs to L{Broker} instances |
210 | 211 | |
… |
… |
class Tub(service.MultiService): |
363 | 364 | self.setLogGathererFURL(value) |
364 | 365 | elif name == "log-gatherer-furlfile": |
365 | 366 | self.setLogGathererFURLFile(value) |
| 367 | elif name == "outbound-proxy": |
| 368 | self.options['outbound-proxy'] = value |
366 | 369 | elif name == "bridge-twisted-logs": |
367 | 370 | assert value is not False, "cannot unbridge twisted logs" |
368 | 371 | if value is True: |