[Pkg-privacy-commits] [obfsproxy] 50/353: Fixed bugs in I/O code

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:38 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 4adf50eef05649ef785f16b05df9523fe73ac991
Author: Brandon Wiley <brandon at blanu.net>
Date:   Mon Sep 3 17:54:22 2012 -0500

    Fixed bugs in I/O code
---
 src/obfsproxy/framework/proxy.py           | 14 ++++-
 src/obfsproxy/framework/pump.py            | 97 +++++++++++++++++++++---------
 src/obfsproxy/framework/socks.py           |  5 +-
 src/obfsproxy/transports/dummy.py          |  4 +-
 src/obfsproxy/transports/dust_transport.py |  8 +--
 src/obfsproxy/transports/obfs2.py          |  4 +-
 src/obfsproxy/transports/obfs3.py          |  8 +--
 7 files changed, 94 insertions(+), 46 deletions(-)

diff --git a/src/obfsproxy/framework/proxy.py b/src/obfsproxy/framework/proxy.py
index 672aa4a..2a9f70c 100644
--- a/src/obfsproxy/framework/proxy.py
+++ b/src/obfsproxy/framework/proxy.py
@@ -5,6 +5,8 @@
 The proxy module contains the ProxyHandler class, which implements the server-side handling of pluggable transports.
 """
 
+import logging
+
 from struct import unpack
 from socket import inet_ntoa
 
@@ -40,10 +42,16 @@ class ProxyHandler:
     def handle(self, conn):
         """ handle is called by the framework to establish a new proxy connection to the Tor server and start processing when an incoming client connection is established. """
 
-        print 'connection'
-        print 'connecting %s:%d' % (self.addr, self.port)
+        logging.error('connection')
+        logging.error('connecting %s:%d' % (self.addr, self.port))
+        logging.error('types: %s:%s' % (str(type(self.addr)), str(type(self.port))))
         client = Client()
-        yield client.connect(self.addr, self.port)
+
+	try:
+	    yield client.connect(self.addr, self.port)
+	except Exception as e:
+	    logging.error('Error connecting to destination')
+            return
 
         self.pump = Pump(conn, client, self.transport)
         self.pump.run()
diff --git a/src/obfsproxy/framework/pump.py b/src/obfsproxy/framework/pump.py
index ced7e88..f817a6e 100644
--- a/src/obfsproxy/framework/pump.py
+++ b/src/obfsproxy/framework/pump.py
@@ -44,8 +44,8 @@ class Pump(object):
 
         self.drain()
 
-        monocle.launch(self.pumpDownstream)
-        yield self.pumpUpstream()
+        monocle.launch(self.pumpUpstream)
+        yield self.pumpDownstream()
 
     @_o
     def drain(self):
@@ -61,54 +61,93 @@ class Pump(object):
         callback,
         ):
 
-        logging.error('pumpIn')
-        data = (yield input.read_some())
+        logging.error('pumpIn yielding '+str(input))
+	try:
+	    data = yield input.read_some()
+        except ConnectionLost:
+            logging.error('pumpIn: Connection lost')
+            yield Return(False)
+        except IOError:
+            print 'IOError'
+	    print_exc()		
+            yield Return(False)
+        except Exception, e:
+            print 'Exception'
+            print e
+            yield Return(False)
         if data:
-            logging.error('Pump read ' + str(len(data)) + ' from tunnel'
-                          )
+            logging.error('pumpIn read ' + str(len(data)))
             try:
-                data = (yield self.downstream.read_some())
-                if data:
-                    self.circuit.downstream.write(data)
-                    self.transport.receivedDownstream()
+	        output.write(data)
+		logging.error('pumpIn wrote %d' % (len(data)))
+                callback()
             except ConnectionLost:
-                print 'Connection lost'
-                return
+                print 'pumpIn: Connection lost'
+                yield Return(False)
             except IOError:
                 print 'IOError'
-		print_exc()
-                return
+		print_exc()		
+                yield Return(False)
             except Exception, e:
                 print 'Exception'
                 print e
-                return
+                yield Return(False)
+	else:
+		logging.error('pumpIn no data')
+
+        yield Return(True)
 
     @_o
     def pumpOut(self, input, output):
-        logging.error('pumpOut')
-        data = input.read_some()
+        logging.error('pumpOut yield')
+	try:
+            data = input.read_some()
+        except ConnectionLost:
+            print 'pumpOut: Connection lost'
+            return
+        except IOError:
+            print 'IOError'
+	    print_exc()
+		
+            return
+        except Exception, e:
+            print 'Exception'
+            print e
+            return
         if data:
-            logging.error('Pump read ' + str(len(data)) + ' from tunnel'
-                          )
+            logging.error('pumpOut read ' + str(len(data)))              
             try:
                 yield output.write(data)
-            except:
-                logging.error('Error pumping out')
+		logging.error('pumpOut wrote %d' % (len(data)))
+            except ConnectionLost:
+                print 'pumpOut: Connection lost'
+                return
+            except IOError:
+                print 'IOError'
+		print_exc()
+		
+                return
+            except Exception, e:
+                print 'Exception'
+                print e
+                return
+	else:
+	    logging.error('pumpOut no data')
 
     @_o
     def pumpUpstream(self):
-        logging.error('pump local')
-        while True:
-            yield self.pumpIn(self.dowstream, self.circuit.dowstream,
+        pumping=True
+        while pumping:
+	    logging.error('pump upstream')
+            pumping=yield self.pumpIn(self.downstream, self.circuit.downstream,
                               self.transport.receivedDownstream)
             yield self.drain()
 
     @_o
     def pumpDownstream(self):
-        logging.error('pump remote')
-        while True:
-            yield self.pumpIn(self.upstream, self.circuit.upstream,
+        pumping=True
+        while pumping:
+            logging.error('pump downstream')
+            pumping=yield self.pumpIn(self.upstream, self.circuit.upstream,
                               self.transport.receivedUpstream)
             yield self.drain()
-
-
diff --git a/src/obfsproxy/framework/socks.py b/src/obfsproxy/framework/socks.py
index af1ea9f..ed8404b 100644
--- a/src/obfsproxy/framework/socks.py
+++ b/src/obfsproxy/framework/socks.py
@@ -37,7 +37,7 @@ def readHandshake(conn):
     nauth = unpack('B', nauth)[0]
     auths = []
     for x in range(nauth):
-        auth = (yield input.read(1))
+        auth = (yield conn.read(1))
         auth = unpack('B', auth)[0]
         auths.append(auth)
 
@@ -92,11 +92,12 @@ class SocksHandler:
         yield sendHandshake(conn)
         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.error('sent response')
 
         (addr, port) = uncompact(dest)
+	logging.error('connecting %s:%d' % (addr, port))
 
         logging.info(addr)
         logging.info(port)
diff --git a/src/obfsproxy/transports/dummy.py b/src/obfsproxy/transports/dummy.py
index 4696d24..7d5e1f5 100644
--- a/src/obfsproxy/transports/dummy.py
+++ b/src/obfsproxy/transports/dummy.py
@@ -21,7 +21,7 @@ class DummyDaemon(BaseDaemon):
         The dummy protocol just writes these to the upstream socket.
         """
 
-        data = self.downstreamConnection.readAll()
+        data = self.downstreamConnection.read_some()
         self.upstreamConnection.write(data)
 
     def receivedUpstream(self):
@@ -30,7 +30,7 @@ class DummyDaemon(BaseDaemon):
         The dummy protocol just writes these to the downstream socket.
         """
 
-        data = self.upstreamConnection.readAll()
+        data = self.upstreamConnection.read_some()
         self.downstreamConnection.write(data)
 
 
diff --git a/src/obfsproxy/transports/dust_transport.py b/src/obfsproxy/transports/dust_transport.py
index 1cd245b..c5d2c96 100644
--- a/src/obfsproxy/transports/dust_transport.py
+++ b/src/obfsproxy/transports/dust_transport.py
@@ -53,7 +53,7 @@ class DustDaemon(BaseDaemon):
         # If we're in streaming mode, encode and write the incoming data
 
         if self.state == STREAM:
-            data = self.downstreamConnection.readAll()
+            data = self.downstreamConnection.read_some()
             if data:
                 self.upstreamConnection.write(self.coder.encode(data))
 
@@ -73,15 +73,15 @@ class DustDaemon(BaseDaemon):
                         self.epub)
                 self.coder = lite_socket(esession)
 
-                data = self.downstreamConnection.readAll()
+                data = self.downstreamConnection.read_some()
                 if data:
                     self.upstreamConnection.write(self.coder.encode(data))
 
-                data = self.upstreamConnection.readAll()
+                data = self.upstreamConnection.read_some()
                 if data:
                     self.downstreamConnection.write(self.coder.decode(data))
         else:
-            data = self.upstreamConnection.readAll()
+            data = self.upstreamConnection.read_some()
             if data:
                 self.downstreamConnection.write(self.coder.decode(data))
 
diff --git a/src/obfsproxy/transports/obfs2.py b/src/obfsproxy/transports/obfs2.py
index f1c0988..3039a48 100644
--- a/src/obfsproxy/transports/obfs2.py
+++ b/src/obfsproxy/transports/obfs2.py
@@ -148,7 +148,7 @@ class Obfs2Daemon(BaseDaemon):
         """
 
         if state == STREAM:
-            data = self.downstreamConnection.readAll()
+            data = self.downstreamConnection.read_some()
             encodedData = encode(data)
             self.upstreamConnection.write(encodedData)
 
@@ -214,7 +214,7 @@ class Obfs2Daemon(BaseDaemon):
                 self.otherCipher = initCipher(self.otheriv,
                         self.otherKey)
         elif state == STREAM:
-            data = self.upstreamConnection.readAll()
+            data = self.upstreamConnection.read_some()
             decodedData = decode(data)
             self.downstreamConnection.write(decodedData)
 
diff --git a/src/obfsproxy/transports/obfs3.py b/src/obfsproxy/transports/obfs3.py
index 9749b05..92e8832 100644
--- a/src/obfsproxy/transports/obfs3.py
+++ b/src/obfsproxy/transports/obfs3.py
@@ -54,7 +54,7 @@ class Obfs3Daemon(BaseDaemon):
         # If we're in streaming mode, encode and write the incoming data
 
         if self.state == STREAM:
-            data = self.downstreamConnection.readAll()
+            data = self.downstreamConnection.read_some()
             if data:
                 self.upstreamConnection.write(self.coder.encode(data))
 
@@ -74,15 +74,15 @@ class Obfs3Daemon(BaseDaemon):
                         self.epub)
                 self.coder = AESCoder(esession)
 
-                data = self.downstreamConnection.readAll()
+                data = self.downstreamConnection.read_some()
                 if data:
                     self.upstreamConnection.write(self.coder.encode(data))
 
-                data = self.upstreamConnection.readAll()
+                data = self.upstreamConnection.read_some()
                 if data:
                     self.downstreamConnection.write(self.coder.decode(data))
         else:
-            data = self.upstreamConnection.readAll()
+            data = self.upstreamConnection.read_some()
             if data:
                 self.downstreamConnection.write(self.coder.decode(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