[Pkg-privacy-commits] [obfsproxy] 28/353: Fixed pumping
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 651d07ce7981ddb2bab7cc8e87a9c053231cdbb6
Author: Brandon Wiley <brandon at blanu.net>
Date: Tue Aug 7 11:45:30 2012 -0500
Fixed pumping
---
src/obfsproxy/framework/pump.py | 109 ++++++++++++++++++++++----------------
src/obfsproxy/framework/socks.py | 30 ++++++-----
src/obfsproxy/framework/tunnel.py | 13 ++++-
src/obfsproxy/transports/base.py | 6 +--
src/obfsproxy/transports/dummy.py | 13 +++--
5 files changed, 104 insertions(+), 67 deletions(-)
diff --git a/src/obfsproxy/framework/pump.py b/src/obfsproxy/framework/pump.py
index 1b93c54..aae3680 100644
--- a/src/obfsproxy/framework/pump.py
+++ b/src/obfsproxy/framework/pump.py
@@ -1,7 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
+import logging
+
import monocle
+monocle.init('tornado')
+
from monocle import _o, Return
from monocle.stack.network import ConnectionLost
@@ -11,72 +15,85 @@ from obfsproxy.framework.tunnel import Tunnel
class Pump(object):
def __init__(self, local, remote, transportClass):
+ logging.error('pump init')
self.local=local
self.remote=remote
- tunnel=Tunnel()
- self.transport=transportClass(tunnel)
- self.tunnel=tunnel.invert()
+ self.tunnel=Tunnel()
+ self.transport=transportClass(self.tunnel.invert())
+
+ logging.error('Buffers:')
+ logging.error('local in: '+str(self.tunnel.local.incomingBuffer))
+ logging.error('local out: '+str(self.tunnel.local.outgoingBuffer))
+ logging.error('remote in: '+str(self.tunnel.remote.incomingBuffer))
+ logging.error('remote out: '+str(self.tunnel.remote.outgoingBuffer))
+ @_o
def run(self):
+ logging.error('pump run')
self.transport.start()
+
+ self.drain()
+
monocle.launch(self.pumpLocal)
yield self.pumpRemote()
+ logging.error('end pump run')
@_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
+ def drain(self):
+ logging.error('drain')
+ yield self.pumpOut(self.tunnel.local, self.local)
+ yield self.pumpOut(self.tunnel.remote, self.remote)
+ @_o
+ def pumpIn(self, input, output, callback):
+ logging.error('pumpIn')
+ data=yield input.read_some()
+ if data:
+ logging.error('Pump read '+str(len(data))+' from tunnel')
try:
- data = yield self.local.read_some()
- if data:
- self.tunnel.local.write(data)
- self.transport.decodedReceived()
+ output.write(data)
+ callback()
except ConnectionLost:
- print 'Client connection closed'
+ print 'Connection lost'
return
except IOError:
+ print 'IOError'
+ return
+ except Exception, e:
+ print 'Exception'
+ print e
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
-
+ def pumpOut(self, input, output):
+ logging.error('pumpOut')
+ data=input.read_some()
+ if data:
+ logging.error('Pump read '+str(len(data))+' from tunnel')
try:
- data = yield self.remote.read_some()
- if data:
- self.tunnel.remote.write(data)
- self.transport.encodedReceived()
+ yield output.write(data)
except ConnectionLost:
- print 'Client connection closed'
+ print 'Connection lost'
return
except IOError:
+ print 'IOError'
+ return
+ except Exception, e:
+ print 'Exception'
+ print e
return
+
+ @_o
+ def pumpLocal(self):
+ logging.error('pump local')
+ while True:
+ yield self.pumpIn(self.local, self.tunnel.local, self.transport.decodedReceived)
+ yield self.drain()
+
+ @_o
+ def pumpRemote(self):
+ logging.error('pump remote')
+ while True:
+ yield self.pumpIn(self.remote, self.tunnel.remote, self.transport.encodedReceived)
+ yield self.drain()
diff --git a/src/obfsproxy/framework/socks.py b/src/obfsproxy/framework/socks.py
index f615796..156a34e 100644
--- a/src/obfsproxy/framework/socks.py
+++ b/src/obfsproxy/framework/socks.py
@@ -23,7 +23,7 @@ def uncompact(x):
@_o
def readHandshake(input):
version = (yield input.read(1))
- logging.info('version: %s' % (encode(str(version))))
+ logging.error('version: %s' % (encode(str(version))))
nauth = (yield input.read(1))
nauth = unpack('B', nauth)[0]
auths = []
@@ -63,27 +63,33 @@ class SocksHandler:
@_o
def handle(self, conn):
- logging.info('handle_socks')
+ logging.error('new socks connection')
+ logging.error('handle_socks')
yield readHandshake(conn)
- logging.info('read handshake')
+ logging.error('read handshake')
yield sendHandshake(conn)
- logging.info('send handshake')
+ logging.error('send handshake')
dest = (yield readRequest(conn))
- logging.info('read request: %s' % (str(dest)))
+ logging.error('read request: %s' % (str(dest)))
yield sendResponse(dest, conn)
- logging.info('sent response')
+ logging.error('sent response')
(addr, port) = uncompact(dest)
# addr='127.0.0.1'
# port=8183
- logging.info(addr)
- logging.info(port)
+ logging.error(addr)
+ logging.error(port)
client = Client()
yield client.connect(addr, port)
- logging.info('connected %s:%d' % (addr, port))
-
- self.pump=Pump(conn, client, self.transport)
- self.pump.run()
+ logging.error('connected %s:%d' % (addr, port))
+
+ try:
+ self.pump=Pump(conn, client, self.transport)
+ logging.error('Pump: '+str(self.pump))
+ yield self.pump.run()
+ logging.error('ran pump')
+ except Exception as e:
+ logging.error('Pump error: '+str(e))
diff --git a/src/obfsproxy/framework/tunnel.py b/src/obfsproxy/framework/tunnel.py
index 28ec8bc..2b5107a 100644
--- a/src/obfsproxy/framework/tunnel.py
+++ b/src/obfsproxy/framework/tunnel.py
@@ -1,6 +1,8 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
+import logging
+
class Buffer(object):
def __init__(self):
self.buffer=bytes('')
@@ -14,10 +16,17 @@ class Buffer(object):
return data
def read_some(self):
- return self.read(len(self.buffer))
+ logging.error('buffer read_some '+str(len(self.buffer))+' '+str(self))
+ logging.error('before '+str(self.buffer))
+ data=self.read(len(self.buffer))
+ logging.error('after '+str(self.buffer))
+ return data
def write(self, bs):
+ logging.error('buffer write '+str(len(bs))+' '+str(self))
+ logging.error('before '+str(self.buffer))
self.buffer=self.buffer+bs
+ logging.error('after '+str(self.buffer))
class Channel(object):
def __init__(self, incoming=None, outgoing=None):
@@ -49,7 +58,7 @@ class Tunnel(object):
self.local=local
else:
self.local=Channel()
- if remove:
+ if remote:
self.remote=remote
else:
self.remote=Channel()
diff --git a/src/obfsproxy/transports/base.py b/src/obfsproxy/transports/base.py
index bb011d5..1fccb08 100644
--- a/src/obfsproxy/transports/base.py
+++ b/src/obfsproxy/transports/base.py
@@ -4,9 +4,9 @@
class BaseDaemon:
- def __init__(self, decodedSocket, encodedSocket):
- self.decodedSocket = decodedSocket
- self.encodedSocket = encodedSocket
+ def __init__(self, tunnel):
+ self.decodedSocket = tunnel.local
+ self.encodedSocket = tunnel.remote
def read(
self,
diff --git a/src/obfsproxy/transports/dummy.py b/src/obfsproxy/transports/dummy.py
index 7f1e69c..dc5dbe6 100644
--- a/src/obfsproxy/transports/dummy.py
+++ b/src/obfsproxy/transports/dummy.py
@@ -1,17 +1,22 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
+import logging
+
from obfsproxy.transports.base import BaseDaemon
class DummyDaemon(BaseDaemon):
- def receivedDecoded(self):
- data = self.decodedSocket.readAll()
+ def decodedReceived(self):
+ logging.error('dummy decoded received')
+ data = self.decodedSocket.read_some()
self.encodedSocket.write(data)
+ logging.error('wrote '+str(len(data))+' encoded')
- def receivedEncoded(self):
- data = self.encodedSocket.readAll()
+ def encodedReceived(self):
+ logging.error('dummy encoded received')
+ data = self.encodedSocket.read_some()
self.decodedSocket.write(data)
--
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