[Pkg-privacy-commits] [obfsproxy] 07/353: Converted to high-level API
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:32 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 72366d9bb1e3e893bd08bfad0147d785a6ec6e01
Author: Brandon Wiley <brandon at blanu.net>
Date: Fri Jun 29 14:39:05 2012 -0500
Converted to high-level API
---
src/obfsproxy/framework/managed/client.py | 65 ++++++++++--------------------
src/obfsproxy/framework/managed/server.py | 66 ++++++++++---------------------
2 files changed, 41 insertions(+), 90 deletions(-)
diff --git a/src/obfsproxy/framework/managed/client.py b/src/obfsproxy/framework/managed/client.py
index 50beb8a..1fe97fa 100755
--- a/src/obfsproxy/framework/managed/client.py
+++ b/src/obfsproxy/framework/managed/client.py
@@ -1,59 +1,37 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-import os
-import sys
-
-import argparse
-
-from struct import unpack
-from socket import inet_ntoa
-
import monocle
from monocle import _o, Return
monocle.init('tornado')
from monocle.stack import eventloop
-from monocle.stack.network import add_service, Service, Client, \
- ConnectionLost
-from pyptlib.framework.loopback import FakeSocket
-
-from pyptlib.framework.socks import SocksHandler
+from monocle.stack.network import add_service
-from pyptlib.config.config import EnvException
-from pyptlib.config.client import ClientConfig
-from pyptlib.framework.daemon import *
+from obfsproxy.framework.socks import SocksHandler
+from obfsproxy.transports.dummy import DummyClient
-from pyptlib.transports.dummy import DummyClient
+from pyptlib.easy.client import init, reportSucess, reportFailure, reportEnd
+class TransportLaunchException(Exception):
+ pass
-class ManagedClient(Daemon):
-
+class ManagedClient:
def __init__(self):
- try:
- Daemon.__init__(self, ClientConfig(), SocksHandler())
- except EnvException:
- print 'error 0'
- return
- except UnsupportedManagedTransportVersionException:
- print 'error 1'
- return
- except NoSupportedTransportsException:
- print 'error 2'
- return
-
- try:
- self.launchClient(self.supportedTransport, 8182)
- self.config.writeMethod(self.supportedTransport, 5,
- ('127.0.0.1', 8182), None, None)
- except TransportLaunchException, e:
- print 'error 3'
- self.config.writeMethodError(self.supportedTransport,
- e.message)
+ self.handler=SocksHandler()
+
+ supportedTransports = ['dummy', 'rot13']
- self.config.writeMethodEnd()
+ matchedTransports=init(supportedTransports)
+ for transport in matchedTransports:
+ try:
+ self.launchClient(transport, 8182)
+ reportSuccess(transport, 5, ('127.0.0.1', 8182), None, None)
+ except TransportLaunchException:
+ reportFailure(transport, 'Failed to launch')
+ reportEnd()
- self.run()
+ eventloop.run()
def launchClient(self, name, port):
if name != self.supportedTransport:
@@ -64,8 +42,5 @@ class ManagedClient(Daemon):
self.handler.setTransport(client)
add_service(Service(self.handler, port=port))
-
if __name__ == '__main__':
- sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
- server = ManagedClient()
-
+ client = ManagedClient()
diff --git a/src/obfsproxy/framework/managed/server.py b/src/obfsproxy/framework/managed/server.py
index 61c0d1b..2d6671b 100755
--- a/src/obfsproxy/framework/managed/server.py
+++ b/src/obfsproxy/framework/managed/server.py
@@ -1,70 +1,46 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-import os
-import sys
-
-from struct import unpack
-from socket import inet_ntoa
-
import monocle
from monocle import _o, Return
monocle.init('tornado')
from monocle.stack import eventloop
-from monocle.stack.network import add_service, Service, Client
-
-from pyptlib.framework.shared import pump
-
-from pyptlib.config.config import EnvException
-from pyptlib.config.server import ServerConfig, MethodOptions
-from pyptlib.framework.daemon import *
+from monocle.stack.network import add_service
-from pyptlib.framework.proxy import ProxyHandler
+from obfsproxy.framework.proxy import ProxyHandler
+from obfsproxy.transports.dummy import DummyClient
-from pyptlib.transports.dummy import DummyServer
+from pyptlib.easy.server import init, reportSucess, reportFailure, reportEnd
+class TransportLaunchException(Exception):
+ pass
-class ManagedServer(Daemon):
-
+class ManagedServer:
def __init__(self):
- try:
- Daemon.__init__(self, ServerConfig(), ProxyHandler())
- except EnvException:
- print 'error 0'
- return
- except UnsupportedManagedTransportVersionException:
- print 'error 1'
- return
- except NoSupportedTransportsException:
- print 'error 2'
- return
-
- try:
- self.launchServer(self.supportedTransport, 8182)
- self.config.writeMethod(self.supportedTransport,
- ('127.0.0.1', 8182),
- MethodOptions())
- except TransportLaunchException, e:
- print 'error 3'
- self.config.writeMethodError(self.supportedTransport,
- e.message)
+ self.handler=ProxyHandler()
+
+ supportedTransports = ['dummy', 'rot13']
- self.config.writeMethodEnd()
+ matchedTransports=init(supportedTransports)
+ for transport in matchedTransports:
+ try:
+ self.launchServer(transport, 8182)
+ reportSuccess(transport, ('127.0.0.1', 8182), None)
+ except TransportLaunchException:
+ reportFailure(transport, 'Failed to launch')
+ reportEnd()
- self.run()
+ eventloop.run()
def launchServer(self, name, port):
if name != self.supportedTransport:
raise TransportLaunchException('Tried to launch unsupported transport %s'
% name)
- client = DummyServer()
- self.handler.setTransport(client)
+ server = DummyServer()
+ self.handler.setTransport(server)
add_service(Service(self.handler, port=port))
-
if __name__ == '__main__':
- sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
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