[Pkg-privacy-commits] [obfsproxy] 25/353: Merged in the code for managing virtual socket buffers
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:34 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 cb7da585f01619b5add5e5cc1df2a54052f34e86
Author: Brandon Wiley <brandon at blanu.net>
Date: Fri Aug 3 14:24:44 2012 -0500
Merged in the code for managing virtual socket buffers
---
src/obfsproxy/framework/loopback.py | 71 --------------------------
src/obfsproxy/framework/managed/client.py | 4 +-
src/obfsproxy/framework/proxy.py | 6 +--
src/obfsproxy/framework/pump.py | 82 +++++++++++++++++++++++++++++++
src/obfsproxy/framework/shared.py | 61 -----------------------
src/obfsproxy/framework/socks.py | 8 ++-
src/obfsproxy/framework/tunnel.py | 59 ++++++++++++++++++++++
7 files changed, 149 insertions(+), 142 deletions(-)
diff --git a/src/obfsproxy/framework/loopback.py b/src/obfsproxy/framework/loopback.py
deleted file mode 100644
index ce6d094..0000000
--- a/src/obfsproxy/framework/loopback.py
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-import monocle
-from monocle import _o
-monocle.init('tornado')
-
-from monocle.core import Callback, Return
-from monocle.stack import eventloop
-
-from monocle.stack.network import Connection, ConnectionLost
-from monocle.experimental import Channel
-
-buffsize = 1024
-
-
-class FakeSocket(object):
-
- def __init__(self, a=None, b=None):
- if a == None:
- self.a = Channel(buffsize)
- else:
- self.a = a
- if b == None:
- self.b = Channel(buffsize)
- else:
- self.b = b
-
- self.inBuff = ''
- self.outBuff = ''
-
- def invert(self):
- return FakeSocket(a=self.b, b=self.a)
-
- @_o
- def read(self, x):
- while len(self.inBuff) < x:
- data = (yield self.a.recv())
- if data:
- self.inBuff = self.inBuff + data
- else:
- yield ConnectionLost()
-
- data = self.inBuff[:x]
- self.inBuff = self.inBuff[x:]
-
- yield Return(data)
-
- @_o
- def read_some(self):
- if len(self.inBuff) > 0:
- data = self.inBuff
- self.inBuff = ''
- yield Return(data)
- else:
- data = ''
- while len(data) == 0:
- data = (yield self.a.recv())
- if data:
- yield Return(data)
- else:
- yield ConnectionLost()
-
- @_o
- def write(self, bs):
- yield self.b.send(bs)
-
- def close(self):
- yield self.b.send(None)
-
-
diff --git a/src/obfsproxy/framework/managed/client.py b/src/obfsproxy/framework/managed/client.py
index d362816..25fac81 100755
--- a/src/obfsproxy/framework/managed/client.py
+++ b/src/obfsproxy/framework/managed/client.py
@@ -18,6 +18,7 @@ from obfsproxy.transports.obfs3 import Obfs3Client
from pyptlib.easy.client import init, reportSuccess, reportFailure, \
reportEnd
+from obfsproxy.framework.managed.virtual import Channel
class TransportLaunchException(Exception):
@@ -54,8 +55,7 @@ class ManagedClient:
% name)
clientClass = self.supportedTransports[name]
- client = clientClass(self)
- self.handler.setTransport(client)
+ self.handler.setTransport(clientClass)
add_service(Service(self.handler.handle, port=port))
diff --git a/src/obfsproxy/framework/proxy.py b/src/obfsproxy/framework/proxy.py
index 7940086..23f23cf 100644
--- a/src/obfsproxy/framework/proxy.py
+++ b/src/obfsproxy/framework/proxy.py
@@ -12,7 +12,7 @@ from monocle.stack.network import Client
from obfsproxy.util import encode
-from obfsproxy.framework.shared import pump
+from obfsproxy.framework.pump import Pump
class ProxyHandler:
@@ -28,7 +28,7 @@ class ProxyHandler:
client = Client()
yield client.connect('blanu.net', 80)
- monocle.launch(pump, conn, client, None)
- yield pump(client, conn, None)
+ self.pump=Pump(conn, client, self.transport)
+ self.pump.run()
diff --git a/src/obfsproxy/framework/pump.py b/src/obfsproxy/framework/pump.py
new file mode 100644
index 0000000..1b93c54
--- /dev/null
+++ b/src/obfsproxy/framework/pump.py
@@ -0,0 +1,82 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+import monocle
+from monocle import _o, Return
+
+from monocle.stack.network import ConnectionLost
+
+from obfsproxy.util import encode
+from obfsproxy.framework.tunnel import Tunnel
+
+class Pump(object):
+ def __init__(self, local, remote, transportClass):
+ self.local=local
+ self.remote=remote
+
+ tunnel=Tunnel()
+ self.transport=transportClass(tunnel)
+ self.tunnel=tunnel.invert()
+
+ def run(self):
+ self.transport.start()
+ monocle.launch(self.pumpLocal)
+ yield self.pumpRemote()
+
+ @_o
+ def pumpLocal(self):
+ while True:
+ data=self.tunnel.local.read_some()
+ if data:
+ try:
+ yield self.local.write(data)
+ except ConnectionLost:
+ print 'Connection lost'
+ return
+ except IOError:
+ print 'IOError'
+ return
+ except Exception, e:
+ print 'Exception'
+ print e
+ return
+
+ try:
+ data = yield self.local.read_some()
+ if data:
+ self.tunnel.local.write(data)
+ self.transport.decodedReceived()
+ except ConnectionLost:
+ print 'Client connection closed'
+ return
+ except IOError:
+ return
+
+ @_o
+ def pumpRemote(self):
+ while True:
+ data=self.tunnel.remote.read_some()
+ if data:
+ try:
+ yield self.remote.write(data)
+ except ConnectionLost:
+ print 'Connection lost'
+ return
+ except IOError:
+ print 'IOError'
+ return
+ except Exception, e:
+ print 'Exception'
+ print e
+ return
+
+ try:
+ data = yield self.remote.read_some()
+ if data:
+ self.tunnel.remote.write(data)
+ self.transport.encodedReceived()
+ except ConnectionLost:
+ print 'Client connection closed'
+ return
+ except IOError:
+ return
diff --git a/src/obfsproxy/framework/shared.py b/src/obfsproxy/framework/shared.py
deleted file mode 100644
index f50565b..0000000
--- a/src/obfsproxy/framework/shared.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-import monocle
-from monocle import _o, Return
-
-from monocle.stack.network import ConnectionLost
-
-from obfsproxy.util import encode
-
-
- at _o
-def pump(
- input,
- output,
- transform,
- debug=False,
- ):
-
- while True:
- try:
- message = (yield input.read_some())
-
-# message=yield input.read(1)
-
- if not message or len(message) == 0:
- print '0 from ' + str(input) + ' ' + str(type(message))
- raise Exception()
-
-# message=yield input.read(1)
-
- if debug:
- print 'receive ' + str(len(message))
- except ConnectionLost:
- print 'Client connection closed'
- output.close()
- break
- except IOError:
- output.close()
- break
-
- if transform:
- message = (yield transform(message))
-
- if debug:
- print 'sending ' + str(len(message))
- try:
- yield output.write(message)
- except ConnectionLost:
- print 'Connection lost'
- input.close()
- return
- except IOError:
- print 'IOError'
- input.close()
- return
- except Exception, e:
- print 'Exception'
- print e
- input.close()
- return
diff --git a/src/obfsproxy/framework/socks.py b/src/obfsproxy/framework/socks.py
index 233fc81..0731428 100644
--- a/src/obfsproxy/framework/socks.py
+++ b/src/obfsproxy/framework/socks.py
@@ -12,8 +12,7 @@ from monocle.stack.network import Client
from obfsproxy.util import encode
-from obfsproxy.framework.shared import pump
-
+from obfsproxy.framework.pump import Pump
def uncompact(x):
(ip, port) = unpack('!4sH', x)
@@ -84,7 +83,6 @@ class SocksHandler:
client = Client()
yield client.connect(addr, port)
print 'connected ' + str(addr) + ', ' + str(port)
- monocle.launch(pump, conn, client, None)
- yield pump(client, conn, None)
-
+ self.pump=Pump(conn, client, self.transport)
+ self.pump.run()
diff --git a/src/obfsproxy/framework/tunnel.py b/src/obfsproxy/framework/tunnel.py
new file mode 100644
index 0000000..f6508a1
--- /dev/null
+++ b/src/obfsproxy/framework/tunnel.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+class Buffer(object):
+ def __init__(self):
+ self.buffer=bytes('')
+
+ def read(self, x):
+ if len(self.buffer)<x:
+ return None
+ else:
+ data=self.buffer[:x]
+ self.buffer=self.buffer[x:]
+ return data
+
+ def read_some(self):
+ return self.read(len(self.buffer))
+
+ def write(self, bs):
+ self.buffer=self.buffer+bs
+
+class Channel(object):
+ def __init__(self, incoming=None, outgoing=None):
+ if incoming:
+ self.incomingBuffer=incoming
+ else:
+ self.incomingBuffer=Buffer()
+
+ if outgoing:
+ self.outgoingBuffer=outgoing
+ else:
+ self.outgoingBuffer=Buffer()
+
+ def invert(self):
+ return Channel(self.outgoingBuffer, self.incomingBuffer)
+
+ def read(self, x):
+ return self.incomingBuffer.read(x)
+
+ def read_some(self):
+ return self.incomingBuffer.read_some()
+
+ def write(self, bs):
+ self.outgoingBuffer.write(bs)
+
+class Tunnel(object):
+ def __init__(self, local=None, remote=None):
+ if local:
+ self.local=local
+ else:
+ self.local=Channel()
+ if remove:
+ self.remote=remote
+ else:
+ self.remote=Channel()
+
+ def invert(self)
+ return Tunnel(self.local.invert(), self.remote.invert())
+
--
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