[Pkg-privacy-commits] [obfsproxy] 282/353: Use transport_config.py instead of making a new settings.py.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:02:11 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository obfsproxy.
commit e9cab2b64be1c5d4d4aad2378f384dea42162eda
Author: George Kadianakis <desnacked at riseup.net>
Date: Sun Apr 6 01:58:39 2014 +0100
Use transport_config.py instead of making a new settings.py.
TransportConfig already carries global obfsproxy information (like the
state location, etc.). The only difference with the settings.py idea
that settings.py:Config was a singleton.
---
obfsproxy/common/settings.py | 5 -----
obfsproxy/common/transport_config.py | 11 +++++++++++
obfsproxy/managed/client.py | 8 +++-----
obfsproxy/network/network.py | 4 ++--
obfsproxy/network/socks.py | 10 +++++-----
obfsproxy/pyobfsproxy.py | 30 ++++++++++++++++++++----------
6 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/obfsproxy/common/settings.py b/obfsproxy/common/settings.py
deleted file mode 100644
index 4f58ce8..0000000
--- a/obfsproxy/common/settings.py
+++ /dev/null
@@ -1,5 +0,0 @@
-class Config(object):
- def __init__(self):
- self.proxy = None
-
-config = Config()
diff --git a/obfsproxy/common/transport_config.py b/obfsproxy/common/transport_config.py
index 648b903..84c97f4 100644
--- a/obfsproxy/common/transport_config.py
+++ b/obfsproxy/common/transport_config.py
@@ -28,6 +28,17 @@ class TransportConfig( object ):
# True if we are in external mode. False otherwise.
self.weAreExternal = None
+ # Information about the outgoing SOCKS/HTTP proxy we need to
+ # connect to. See pyptlib.client_config.parseProxyURI().
+ self.proxy = None
+
+ def setProxy( self, proxy ):
+ """
+ Set the given 'proxy'.
+ """
+
+ self.proxy = proxy
+
def setStateLocation( self, stateLocation ):
"""
Set the given `stateLocation'.
diff --git a/obfsproxy/managed/client.py b/obfsproxy/managed/client.py
index f5aeb0d..1df6baf 100644
--- a/obfsproxy/managed/client.py
+++ b/obfsproxy/managed/client.py
@@ -6,7 +6,6 @@ from twisted.internet import reactor, error
import obfsproxy.network.launch_transport as launch_transport
import obfsproxy.transports.transports as transports
import obfsproxy.common.log as logging
-import obfsproxy.common.settings as settings
import obfsproxy.common.transport_config as transport_config
from pyptlib.client import ClientTransportPlugin
@@ -33,13 +32,11 @@ def do_managed_client():
# Apply the proxy settings if any
proxy = ptclient.config.getProxy()
if proxy:
+ # XXX temporarily: till we implement HTTP
if proxy.scheme == "http":
log.error("HTTP CONNECT proxy not supported yet")
- ptclient.reportProxyError("Invalid scheme (%s)" % (proxy.scheme))
+ ptclient.reportProxyError("HTTP CONNECT not supported yet")
return
- if settings.config.proxy:
- log.warning("Proxy specified via commandline and by managed-proxy protocol, using manage-proxy's")
- settings.config.proxy = proxy
ptclient.reportProxySuccess()
for transport in ptclient.getTransports():
@@ -49,6 +46,7 @@ def do_managed_client():
pt_config.setStateLocation(ptclient.config.getStateLocation())
pt_config.setListenerMode("socks")
pt_config.setObfsproxyMode("managed")
+ pt_config.setProxy(proxy)
# Call setup() method for this transport.
transport_class = transports.get_transport_class(transport, 'socks')
diff --git a/obfsproxy/network/network.py b/obfsproxy/network/network.py
index 41e923f..a6c135e 100644
--- a/obfsproxy/network/network.py
+++ b/obfsproxy/network/network.py
@@ -371,9 +371,9 @@ class StaticDestinationServerFactory(Factory):
# XXX instantiates a new factory for each client
clientFactory = StaticDestinationClientFactory(circuit, self.mode)
- if settings.config.proxy:
+ if self.pt_config.proxy:
create_proxy_client(self.remote_host, self.remote_port,
- settings.config.proxy,
+ self.pt_config.proxy,
clientFactory)
else:
reactor.connectTCP(self.remote_host, self.remote_port, clientFactory)
diff --git a/obfsproxy/network/socks.py b/obfsproxy/network/socks.py
index 04874fe..ceb230f 100644
--- a/obfsproxy/network/socks.py
+++ b/obfsproxy/network/socks.py
@@ -6,7 +6,6 @@ import obfsproxy.common.log as logging
import obfsproxy.network.network as network
import obfsproxy.network.socks5 as socks5
import obfsproxy.transports.base as base
-from obfsproxy.common import settings
log = logging.get_obfslogger()
@@ -86,8 +85,9 @@ class OBFSSOCKSv5Protocol(socks5.SOCKSv5Protocol, network.GenericProtocol):
to have a circuit and obfuscate traffic before proxying it.
"""
- def __init__(self, circuit):
+ def __init__(self, circuit, pt_config):
self.name = "socks_up_%s" % hex(id(self))
+ self.pt_config = pt_config
network.GenericProtocol.__init__(self, circuit)
socks5.SOCKSv5Protocol.__init__(self)
@@ -145,9 +145,9 @@ class OBFSSOCKSv5Protocol(socks5.SOCKSv5Protocol, network.GenericProtocol):
and a proxy is optionally used for the outgoing connection.
"""
- if settings.config.proxy:
+ if self.pt_config.proxy:
instance = OBFSSOCKSv5OutgoingFactory(self)
- return network.create_proxy_client(addr, port, settings.config.proxy, instance)
+ return network.create_proxy_client(addr, port, self.pt_config.proxy, instance)
else:
return protocol.ClientCreator(reactor, OBFSSOCKSv5Outgoing, self).connectTCP(addr, port)
@@ -175,4 +175,4 @@ class OBFSSOCKSv5Factory(protocol.Factory):
circuit = network.Circuit(self.transport_class())
- return OBFSSOCKSv5Protocol(circuit)
+ return OBFSSOCKSv5Protocol(circuit, pt_config)
diff --git a/obfsproxy/pyobfsproxy.py b/obfsproxy/pyobfsproxy.py
index 4cde4ad..6a31646 100755
--- a/obfsproxy/pyobfsproxy.py
+++ b/obfsproxy/pyobfsproxy.py
@@ -18,7 +18,6 @@ import obfsproxy.common.transport_config as transport_config
import obfsproxy.managed.server as managed_server
import obfsproxy.managed.client as managed_client
from obfsproxy import __version__
-from obfsproxy.common import settings
from pyptlib.config import checkClientMode
from pyptlib.client_config import parseProxyURI
@@ -89,6 +88,8 @@ def do_external_mode(args):
pt_config.setStateLocation(args.data_dir)
pt_config.setListenerMode(args.mode)
pt_config.setObfsproxyMode("external")
+ proxy = parseProxyURI(args.proxy)
+ pt_config.setProxy(proxy)
# Run setup() method.
run_transport_setup(pt_config)
@@ -109,12 +110,6 @@ def consider_cli_args(args):
log.disable_logs()
if args.no_safe_logging:
log.set_no_safe_logging()
- if args.proxy:
- try:
- settings.config.proxy = parseProxyURI(args.proxy)
- except Exception as e:
- log.error("Failed to parse proxy specifier: %s" % e)
- sys.exit(1)
# validate:
if (args.name == 'managed') and (not args.log_file) and (args.log_min_severity):
@@ -124,9 +119,24 @@ def consider_cli_args(args):
# managed proxies without a logfile must not log at all.
log.disable_logs()
- if settings.config.proxy and settings.config.proxy.scheme == 'http':
- log.error("obfsproxy does not yet support HTTP CONNECT")
- sys.exit(1)
+ if args.proxy:
+ # CLI proxy is only supported in external mode.
+ if args.name == 'managed':
+ log.error("Don't set the proxy using the CLI in managed mode. " \
+ "Use the managed-proxy configuration protocol instead!")
+ sys.exit(1)
+
+ # Make sure that the proxy URI parses smoothly.
+ try:
+ proxy = parseProxyURI(args.proxy)
+ except Exception as e:
+ log.error("Failed to parse proxy specifier: %s" % e)
+ sys.exit(1)
+
+ # XXX temporarily: till we implement HTTP
+ if proxy.scheme == 'http':
+ log.error("obfsproxy does not yet support HTTP CONNECT")
+ sys.exit(1)
def run_transport_setup(pt_config):
"""Run the setup() method for our transports."""
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfsproxy.git
More information about the Pkg-privacy-commits
mailing list