[Pkg-privacy-commits] [obfsproxy] 63/353: Fix managed-mode support.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:40 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 730f3798cda32d93bcce11eece29a66ee550ff8a
Author: George Kadianakis <desnacked at riseup.net>
Date: Mon Sep 17 04:07:32 2012 +0300
Fix managed-mode support.
- Port it to Twisted.
- Add documentation.
- Add more logging.
---
src/obfsproxy/framework/managed/client.py | 83 +++++++++++++++----------------
src/obfsproxy/framework/managed/server.py | 82 +++++++++++++++---------------
2 files changed, 82 insertions(+), 83 deletions(-)
diff --git a/src/obfsproxy/framework/managed/client.py b/src/obfsproxy/framework/managed/client.py
index c870a54..7e646ff 100755
--- a/src/obfsproxy/framework/managed/client.py
+++ b/src/obfsproxy/framework/managed/client.py
@@ -1,65 +1,62 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-import monocle
-from monocle import _o, Return
-monocle.init('tornado')
+# XXX put listener/client-creation functions in their own file
+import obfsproxy.framework.socks as socks
+from twisted.internet import reactor, error, address, tcp
-from monocle.stack import eventloop
-from monocle.stack.network import add_service, Service
-
-from obfsproxy.framework.socks import SocksHandler
-
-from obfsproxy.transports.dummy import DummyClient
-from obfsproxy.transports.rot13 import Rot13Client
-from obfsproxy.transports.dust_transport import DustClient
-from obfsproxy.transports.obfs3 import Obfs3Client
+import obfsproxy.transports.base as base
from pyptlib.easy.client import init, reportSuccess, reportFailure, \
reportEnd
import obfsproxy.common.log as log
-
-class TransportLaunchException(Exception):
-
- pass
-
+import pprint
class ManagedClient:
def __init__(self):
- self.handler = SocksHandler()
-
- self.supportedTransports = {
- 'dummy': DummyClient,
- 'rot13': Rot13Client,
- 'dust': DustClient,
- 'obfs3': Obfs3Client,
- }
-
- managed_info = init(self.supportedTransports.keys())
- if managed_info is None: # XXX what should we return?
+ managedInfo = init(base.transports.keys())
+ if managedInfo is None: # XXX what should we return?
return
- for transport in managed_info['transports']:
- try:
- log.error('Launching %s' % transport)
- self.launchClient(transport, 8182) # XXX hardcoded
- reportSuccess(transport, 5, ('127.0.0.1', 8182), None,
- None)
- except TransportLaunchException:
+ log.debug("pyptlib gave us the following data:\n'%s'", pprint.pformat(managedInfo))
+
+ for transport in managedInfo['transports']:
+ ok, addrport = self.launchClient(transport, managedInfo) # XXX start using exceptions
+ if ok:
+ log.debug("Successfully launched '%s' at '%s'" % (transport, str(addrport)))
+ reportSuccess(transport, 4, addrport, None, None) # XXX SOCKS v4 hardcoded
+ else:
+ log.info("Failed to launch '%s'" % transport)
reportFailure(transport, 'Failed to launch')
+
reportEnd()
- eventloop.run()
+ log.info("Starting up the event loop.")
+ reactor.run()
+
+ def launchClient(self, name, managedInfo):
+ """
+ Launch a client of transport 'name' using the environment
+ information in 'managedInfo'.
+
+ Return a tuple (<ok>, (<addr>, <port>)), where <ok> is whether
+ the function was successful, and (<addr>, <port> is a tuple
+ representing where we managed to bind.
+ """
- def launchClient(self, name, port):
- if not name in self.supportedTransports.keys():
- raise TransportLaunchException('Tried to launch unsupported transport %s'
- % name)
+ clientClass = base.get_transport_class_from_name_and_mode(name, 'client')
+ if not clientClass:
+ log.error("Could not find transport class for '%s' (%s)." % (name, 'client'))
+ return False, None
- clientClass = self.supportedTransports[name]
- self.handler.setTransport(clientClass)
- add_service(Service(self.handler.handle, port=port))
+ factory = socks.SOCKSv4Factory(clientClass())
+ try:
+ addrport = reactor.listenTCP(0, factory, interface='localhost')
+ except CannotListenError:
+ log.error("Could not set up a client listener.")
+ return False, None
+ return True, (addrport.getHost().host, addrport.getHost().port)
diff --git a/src/obfsproxy/framework/managed/server.py b/src/obfsproxy/framework/managed/server.py
index d5a069e..1d4844b 100755
--- a/src/obfsproxy/framework/managed/server.py
+++ b/src/obfsproxy/framework/managed/server.py
@@ -1,64 +1,66 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-import monocle
-from monocle import _o, Return
-monocle.init('tornado')
+# XXX put listener/client-creation functions in their own file
+import obfsproxy.framework.network as network
+from twisted.internet import reactor, error, address, tcp
-from monocle.stack import eventloop
-from monocle.stack.network import add_service, Service
-
-from obfsproxy.framework.proxy import ProxyHandler
-
-from obfsproxy.transports.dummy import DummyServer
-from obfsproxy.transports.rot13 import Rot13Server
-from obfsproxy.transports.dust_transport import DustServer
-from obfsproxy.transports.obfs3 import Obfs3Server
+import obfsproxy.transports.base as base
from pyptlib.easy.server import init, reportSuccess, reportFailure, \
reportEnd
-
-class TransportLaunchException(Exception):
-
- pass
-
+import obfsproxy.common.log as log
+import pprint
class ManagedServer:
def __init__(self):
- self.supportedTransports = {
- 'dummy': DummyServer,
- 'rot13': Rot13Server,
- 'dust': DustServer,
- 'obfs3': Obfs3Server,
- }
-
- managed_info = init(self.supportedTransports)
- if managed_info is None: # XXX what is this function supposed to return?!
+ managedInfo = init(base.transports.keys())
+ if managedInfo is None: # XXX what is this function supposed to return?!
+ log.warning("pyptlib failed to init().")
return
- self.orport_handler = ProxyHandler(*managed_info['orport'])
+ log.debug("pyptlib gave us the following data:\n'%s'", pprint.pformat(managedInfo))
- for transport, transport_bindaddr in managed_info['transports'].items():
- try:
- self.launchServer(transport, transport_bindaddr[1])
- reportSuccess(transport, transport_bindaddr, None)
- except TransportLaunchException:
+ for transport, transport_bindaddr in managedInfo['transports'].items():
+ ok, addrport = self.launchServer(transport, transport_bindaddr, managedInfo)
+ if ok:
+ log.debug("Successfully launched '%s' at '%s'" % (transport, str(addrport)))
+ reportSuccess(transport, addrport, None)
+ else:
+ log.info("Failed to launch '%s' at '%s'" % (transport, str(addrport)))
reportFailure(transport, 'Failed to launch')
+
reportEnd()
- eventloop.run()
+ log.info("Starting up the event loop.")
+ reactor.run()
+
+ def launchServer(self, name, bindaddr, managedInfo):
+ """
+ Launch a client of transport 'name' using the environment
+ information in 'managedInfo'.
+
+ Return a tuple (<ok>, (<addr>, <port>)), where <ok> is whether
+ the function was successful, and (<addr>, <port> is a tuple
+ representing where we managed to bind.
+ """
+
+ serverClass = base.get_transport_class_from_name_and_mode(name, 'server')
+ if not serverClass:
+ log.error("Could not find transport class for '%s' (%s)." % (name, 'server'))
+ return False, None
- def launchServer(self, name, port):
- if not name in self.supportedTransports:
- raise TransportLaunchException('Tried to launch unsupported transport %s'
- % name)
+ factory = network.StaticDestinationServerFactory(managedInfo['orport'], 'server', serverClass())
- serverClass = self.supportedTransports[name]
- self.orport_handler.setTransport(serverClass)
- add_service(Service(self.orport_handler.handle, port=port))
+ try:
+ addrport = reactor.listenTCP(int(bindaddr[1]), factory)
+ except CannotListenError:
+ log.error("Could not set up a listener for TCP port '%s'." % bindaddr[1])
+ return False, None
+ return True, (addrport.getHost().host, addrport.getHost().port)
if __name__ == '__main__':
server = ManagedServer()
--
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