[Pkg-privacy-commits] [obfsproxy] 195/353: Use the new `TransportConfig' class to store the state location and pass it the `TransportConfig' object into the pluggable transport's constructor.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:58 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 8a5ab984f99bd3a3f5dfd385151cf5a9e5372a7e
Author: Philipp Winter <phw at torproject.org>
Date:   Thu Sep 26 23:08:37 2013 +0200

    Use the new `TransportConfig' class to store the state location and pass it the
    `TransportConfig' object into the pluggable transport's constructor.
---
 obfsproxy/managed/client.py           |  8 +++++++-
 obfsproxy/managed/server.py           | 10 +++++++++-
 obfsproxy/network/extended_orport.py  |  5 +++--
 obfsproxy/network/launch_transport.py | 11 +++++++----
 obfsproxy/network/network.py          |  6 ++++--
 obfsproxy/network/socks.py            |  5 +++--
 obfsproxy/pyobfsproxy.py              |  8 +++++++-
 7 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/obfsproxy/managed/client.py b/obfsproxy/managed/client.py
index d4f6924..f847b76 100644
--- a/obfsproxy/managed/client.py
+++ b/obfsproxy/managed/client.py
@@ -6,6 +6,7 @@ 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.transport_config as transport_config
 
 from pyptlib.client import ClientTransportPlugin
 from pyptlib.config import EnvError
@@ -29,8 +30,13 @@ def do_managed_client():
     log.debug("pyptlib gave us the following data:\n'%s'", pprint.pformat(ptclient.getDebugData()))
 
     for transport in ptclient.getTransports():
+
+        # Will hold configuration parameters for the pluggable transport module.
+        pt_config = transport_config.TransportConfig()
+        pt_config.setStateLocation(ptclient.config.getStateLocation())
+
         try:
-            addrport = launch_transport.launch_transport_listener(transport, None, 'socks', None)
+            addrport = launch_transport.launch_transport_listener(transport, None, 'socks', None, pt_config)
         except transports.TransportNotFound:
             log.warning("Could not find transport '%s'" % transport)
             ptclient.reportMethodError(transport, "Could not find transport.")
diff --git a/obfsproxy/managed/server.py b/obfsproxy/managed/server.py
index 09352aa..3f760a8 100644
--- a/obfsproxy/managed/server.py
+++ b/obfsproxy/managed/server.py
@@ -9,6 +9,7 @@ from pyptlib.config import EnvError
 import obfsproxy.transports.transports as transports
 import obfsproxy.network.launch_transport as launch_transport
 import obfsproxy.common.log as logging
+import obfsproxy.common.transport_config as transport_config
 
 import pprint
 
@@ -32,18 +33,25 @@ def do_managed_server():
     authcookie = ptserver.config.getAuthCookieFile()
     orport = ptserver.config.getORPort()
     for transport, transport_bindaddr in ptserver.getBindAddresses().items():
+
+        # Will hold configuration parameters for the pluggable transport module.
+        pt_config = transport_config.TransportConfig()
+        pt_config.setStateLocation(ptserver.config.getStateLocation())
+
         try:
             if ext_orport:
                 addrport = launch_transport.launch_transport_listener(transport,
                                                                       transport_bindaddr,
                                                                       'ext_server',
                                                                       ext_orport,
+                                                                      pt_config,
                                                                       authcookie)
             else:
                 addrport = launch_transport.launch_transport_listener(transport,
                                                                       transport_bindaddr,
                                                                       'server',
-                                                                      orport)
+                                                                      orport,
+                                                                      pt_config)
         except transports.TransportNotFound:
             log.warning("Could not find transport '%s'" % transport)
             ptserver.reportMethodError(transport, "Could not find transport.")
diff --git a/obfsproxy/network/extended_orport.py b/obfsproxy/network/extended_orport.py
index c4cacea..f9153bd 100644
--- a/obfsproxy/network/extended_orport.py
+++ b/obfsproxy/network/extended_orport.py
@@ -352,13 +352,14 @@ class ExtORPortClientFactory(network.StaticDestinationClientFactory):
         return ExtORPortProtocol(self.circuit, addr, self.cookie_file, self.peer_addr, self.transport_name)
 
 class ExtORPortServerFactory(network.StaticDestinationClientFactory):
-    def __init__(self, ext_or_addrport, ext_or_cookie_file, transport_name, transport_class):
+    def __init__(self, ext_or_addrport, ext_or_cookie_file, transport_name, transport_class, pt_config):
         self.ext_or_host = ext_or_addrport[0]
         self.ext_or_port = ext_or_addrport[1]
         self.cookie_file = ext_or_cookie_file
 
         self.transport_name = transport_name
         self.transport_class = transport_class
+        self.pt_config = pt_config
 
         self.name = "fact_ext_s_%s" % hex(id(self))
 
@@ -368,7 +369,7 @@ class ExtORPortServerFactory(network.StaticDestinationClientFactory):
     def buildProtocol(self, addr):
         log.debug("%s: New connection from %s:%d." % (self.name, log.safe_addr_str(addr.host), addr.port))
 
-        circuit = network.Circuit(self.transport_class())
+        circuit = network.Circuit(self.transport_class(self.pt_config))
 
         # XXX instantiates a new factory for each client
         clientFactory = ExtORPortClientFactory(circuit, self.cookie_file, addr, self.transport_name)
diff --git a/obfsproxy/network/launch_transport.py b/obfsproxy/network/launch_transport.py
index 1407123..8ffa6b4 100644
--- a/obfsproxy/network/launch_transport.py
+++ b/obfsproxy/network/launch_transport.py
@@ -5,7 +5,7 @@ import obfsproxy.network.extended_orport as extended_orport
 
 from twisted.internet import reactor
 
-def launch_transport_listener(transport, bindaddr, role, remote_addrport, ext_or_cookie_file=None):
+def launch_transport_listener(transport, bindaddr, role, remote_addrport, pt_config, ext_or_cookie_file=None):
     """
     Launch a listener for 'transport' in role 'role' (socks/client/server/ext_server).
 
@@ -14,6 +14,9 @@ def launch_transport_listener(transport, bindaddr, role, remote_addrport, ext_or
     'remote_addrport' is the TCP/IP address of the other end of the
     circuit. It's not used if we are in 'socks' role.
 
+    'pt_config' contains configuration options (such as the state location)
+    which are of interest to the pluggable transport.
+
     'ext_or_cookie_file' is the filesystem path where the Extended
     ORPort Authentication cookie is stored. It's only used in
     'ext_server' mode.
@@ -32,13 +35,13 @@ def launch_transport_listener(transport, bindaddr, role, remote_addrport, ext_or
     listen_port = int(bindaddr[1]) if bindaddr else 0
 
     if role == 'socks':
-        factory = socks.SOCKSv4Factory(transport_class)
+        factory = socks.SOCKSv4Factory(transport_class, pt_config)
     elif role == 'ext_server':
         assert(remote_addrport and ext_or_cookie_file)
-        factory = extended_orport.ExtORPortServerFactory(remote_addrport, ext_or_cookie_file, transport, transport_class)
+        factory = extended_orport.ExtORPortServerFactory(remote_addrport, ext_or_cookie_file, transport, transport_class, pt_config)
     else:
         assert(remote_addrport)
-        factory = network.StaticDestinationServerFactory(remote_addrport, role, transport_class)
+        factory = network.StaticDestinationServerFactory(remote_addrport, role, transport_class, pt_config)
 
     addrport = reactor.listenTCP(listen_port, factory, interface=listen_host)
 
diff --git a/obfsproxy/network/network.py b/obfsproxy/network/network.py
index d7a6cad..0f12083 100644
--- a/obfsproxy/network/network.py
+++ b/obfsproxy/network/network.py
@@ -340,12 +340,14 @@ class StaticDestinationServerFactory(Factory):
     mode: 'server' or 'client'
     transport: the pluggable transport we should use to
                obfuscate traffic on this connection.
+    pt_config: an object containing config options for the transport.
     """
-    def __init__(self, remote_addrport, mode, transport_class):
+    def __init__(self, remote_addrport, mode, transport_class, pt_config):
         self.remote_host = remote_addrport[0]
         self.remote_port = int(remote_addrport[1])
         self.mode = mode
         self.transport_class = transport_class
+        self.pt_config = pt_config
 
         self.name = "fact_s_%s" % hex(id(self))
 
@@ -357,7 +359,7 @@ class StaticDestinationServerFactory(Factory):
     def buildProtocol(self, addr):
         log.debug("%s: New connection from %s:%d." % (self.name, log.safe_addr_str(addr.host), addr.port))
 
-        circuit = Circuit(self.transport_class())
+        circuit = Circuit(self.transport_class(self.pt_config))
 
         # XXX instantiates a new factory for each client
         clientFactory = StaticDestinationClientFactory(circuit, self.mode)
diff --git a/obfsproxy/network/socks.py b/obfsproxy/network/socks.py
index 3857b73..7d48672 100644
--- a/obfsproxy/network/socks.py
+++ b/obfsproxy/network/socks.py
@@ -159,9 +159,10 @@ class SOCKSv4Factory(Factory):
     A SOCKSv4 factory.
     """
 
-    def __init__(self, transport_class):
+    def __init__(self, transport_class, pt_config):
         # XXX self.logging = log
         self.transport_class = transport_class
+        self.pt_config  = pt_config
 
         self.name = "socks_fact_%s" % hex(id(self))
 
@@ -171,6 +172,6 @@ class SOCKSv4Factory(Factory):
     def buildProtocol(self, addr):
         log.debug("%s: New connection." % self.name)
 
-        circuit = network.Circuit(self.transport_class())
+        circuit = network.Circuit(self.transport_class(self.pt_config))
 
         return SOCKSv4Protocol(circuit)
diff --git a/obfsproxy/pyobfsproxy.py b/obfsproxy/pyobfsproxy.py
index 357041f..1b1401a 100755
--- a/obfsproxy/pyobfsproxy.py
+++ b/obfsproxy/pyobfsproxy.py
@@ -14,6 +14,7 @@ import obfsproxy.transports.transports as transports
 import obfsproxy.common.log as logging
 import obfsproxy.common.argparser as argparser
 import obfsproxy.common.heartbeat as heartbeat
+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__
@@ -43,6 +44,8 @@ def set_up_cli_parsing():
     parser.add_argument('--no-safe-logging', action='store_true',
                         default=False,
                         help='disable safe (scrubbed address) logging')
+    parser.add_argument('--data-dir', help='where persistent information should be stored.',
+                        default=None)
 
     # Managed mode is a subparser for now because there are no
     # optional subparsers: bugs.python.org/issue9253
@@ -77,7 +80,10 @@ def do_external_mode(args):
 
     from twisted.internet import reactor
 
-    launch_transport.launch_transport_listener(args.name, args.listen_addr, args.mode, args.dest, args.ext_cookie_file)
+    pt_config = transport_config.TransportConfig()
+    pt_config.setStateLocation(args.data_dir)
+
+    launch_transport.launch_transport_listener(args.name, args.listen_addr, args.mode, args.dest, pt_config, args.ext_cookie_file)
     log.info("Launched '%s' listener at '%s:%s' for transport '%s'." % \
                  (args.mode, log.safe_addr_str(args.listen_addr[0]), args.listen_addr[1], args.name))
     reactor.run()

-- 
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