[Pkg-privacy-commits] [pyptlib] 12/136: Beginning of framework
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:00 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository pyptlib.
commit 17d9f65e5674708c89ddacf47679276edad083fc
Author: Brandon Wiley <brandon at blanu.net>
Date: Mon Jun 4 14:48:43 2012 -0500
Beginning of framework
---
src/pyptlib/{ => config}/client.py | 0
src/pyptlib/{ => config}/config.py | 0
src/pyptlib/{ => config}/server.py | 0
src/pyptlib/{ => framework}/__init__.py | 0
src/pyptlib/framework/client.py | 41 ++++++++++++++++++++
src/pyptlib/framework/loopback.py | 64 ++++++++++++++++++++++++++++++++
src/pyptlib/framework/server.py | 28 ++++++++++++++
src/pyptlib/framework/shared.py | 47 +++++++++++++++++++++++
src/pyptlib/framework/socks.py | 41 ++++++++++++++++++++
src/pyptlib/{ => manager}/__init__.py | 0
src/pyptlib/manager/clientManager.py | 11 ++++++
src/pyptlib/manager/manager.py | 8 ++++
src/pyptlib/manager/serverManager.py | 14 +++++++
src/pyptlib/{ => transports}/__init__.py | 0
src/pyptlib/transports/dummy.py | 10 +++++
15 files changed, 264 insertions(+)
diff --git a/src/pyptlib/client.py b/src/pyptlib/config/client.py
similarity index 100%
rename from src/pyptlib/client.py
rename to src/pyptlib/config/client.py
diff --git a/src/pyptlib/config.py b/src/pyptlib/config/config.py
similarity index 100%
rename from src/pyptlib/config.py
rename to src/pyptlib/config/config.py
diff --git a/src/pyptlib/server.py b/src/pyptlib/config/server.py
similarity index 100%
rename from src/pyptlib/server.py
rename to src/pyptlib/config/server.py
diff --git a/src/pyptlib/__init__.py b/src/pyptlib/framework/__init__.py
similarity index 100%
copy from src/pyptlib/__init__.py
copy to src/pyptlib/framework/__init__.py
diff --git a/src/pyptlib/framework/client.py b/src/pyptlib/framework/client.py
new file mode 100644
index 0000000..fdca3f4
--- /dev/null
+++ b/src/pyptlib/framework/client.py
@@ -0,0 +1,41 @@
+import sys
+import time
+
+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 loopback import FakeSocket
+
+from shared import *
+from socks import *
+
+ at _o
+def handle_socks(conn):
+ print('handle_socks')
+ yield readHandshake(conn)
+ print('read handshake')
+ yield sendHandshake(conn)
+ print('send handshake')
+ dest=yield readRequest(conn)
+ print('read request: '+str(dest))
+ yield sendResponse(dest, conn)
+ print('sent response')
+
+ addr, port=uncompact(dest)
+ print(addr)
+ print(port)
+
+ client = Client()
+ yield client.connect(addr, port)
+ print('connected '+str(addr)+', '+str(port))
+ monocle.launch(pump, conn, client, None)
+ yield pump(client, conn, None)
+
+add_service(Service(handle_socks, port=7051))
+eventloop.run()
diff --git a/src/pyptlib/framework/loopback.py b/src/pyptlib/framework/loopback.py
new file mode 100644
index 0000000..ecdb4d3
--- /dev/null
+++ b/src/pyptlib/framework/loopback.py
@@ -0,0 +1,64 @@
+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=b''
+ self.outBuff=b''
+
+ 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=b''
+ yield Return(data)
+ else:
+ data=b''
+ 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/pyptlib/framework/server.py b/src/pyptlib/framework/server.py
new file mode 100644
index 0000000..b805ff6
--- /dev/null
+++ b/src/pyptlib/framework/server.py
@@ -0,0 +1,28 @@
+import sys
+import time
+
+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 shared import pump
+
+ at _o
+def handle_proxy(conn):
+ print('connection')
+ client = Client()
+ yield client.connect('blanu.net', 7051)
+
+ coder=yield handshake(client)
+
+ monocle.launch(pump, conn, client, coder.encrypt)
+ yield pump(client, conn, coder.decrypt)
+
+add_service(Service(handle_proxy, port=7050))
+eventloop.run()
diff --git a/src/pyptlib/framework/shared.py b/src/pyptlib/framework/shared.py
new file mode 100644
index 0000000..24d35ee
--- /dev/null
+++ b/src/pyptlib/framework/shared.py
@@ -0,0 +1,47 @@
+import monocle
+from monocle import _o, Return
+
+from monocle.stack.network import ConnectionLost
+
+from dust.core.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/pyptlib/framework/socks.py b/src/pyptlib/framework/socks.py
new file mode 100644
index 0000000..3aa337a
--- /dev/null
+++ b/src/pyptlib/framework/socks.py
@@ -0,0 +1,41 @@
+from struct import unpack
+from socket import inet_ntoa
+
+import monocle
+from monocle import _o, Return
+
+from dust.core.util import encode
+
+def uncompact(x):
+ ip, port = unpack("!4sH", x)
+ return inet_ntoa(ip), port
+
+ at _o
+def readHandshake(input):
+ version=yield input.read(1)
+ print('version: '+encode(str(version)))
+ nauth=yield input.read(1)
+ nauth=unpack('B', nauth)[0]
+ auths=[]
+ for x in range(nauth):
+ auth=yield input.read(1)
+ auth=unpack('B', auth)[0]
+ auths.append(auth)
+
+ at _o
+def sendHandshake(output):
+ yield output.write(b"\x05\x00")
+
+ at _o
+def readRequest(input):
+ version=yield input.read(1)
+ command=yield input.read(1)
+ reserved=yield input.read(1)
+ addrtype=yield input.read(1)
+ dest=yield input.read(6)
+
+ yield Return(dest)
+
+ at _o
+def sendResponse(dest, output):
+ yield output.write(b"\x05\x00\x00\x01"+dest)
diff --git a/src/pyptlib/__init__.py b/src/pyptlib/manager/__init__.py
similarity index 100%
copy from src/pyptlib/__init__.py
copy to src/pyptlib/manager/__init__.py
diff --git a/src/pyptlib/manager/clientManager.py b/src/pyptlib/manager/clientManager.py
new file mode 100644
index 0000000..e064db0
--- /dev/null
+++ b/src/pyptlib/manager/clientManager.py
@@ -0,0 +1,11 @@
+import os
+
+from manager import manager
+
+class ClientManager(Manager):
+ def __init__(self):
+ Manager.__init__(self)
+
+ os.environ['TOR_PT_CLIENT_TRANSPORTS']='dummy'
+
+
\ No newline at end of file
diff --git a/src/pyptlib/manager/manager.py b/src/pyptlib/manager/manager.py
new file mode 100644
index 0000000..68c3f12
--- /dev/null
+++ b/src/pyptlib/manager/manager.py
@@ -0,0 +1,8 @@
+import os
+
+class Manager:
+ def __init__(self):
+ os.environ['TOR_PT_STATE_LOCATION']='/'
+ os.environ['TOR_PT_MANAGED_TRANSPORT_VER']='1'
+
+
\ No newline at end of file
diff --git a/src/pyptlib/manager/serverManager.py b/src/pyptlib/manager/serverManager.py
new file mode 100644
index 0000000..e572d45
--- /dev/null
+++ b/src/pyptlib/manager/serverManager.py
@@ -0,0 +1,14 @@
+import os
+
+from manager import Manager
+
+class ServerManager(Manager):
+ def __init__(self):
+ Manager.__init__(self)
+
+ os.environ['TOR_PT_EXTENDED_SERVER_PORT']='127.0.0.1:22211'
+ os.environ['TOR_PT_ORPORT']='127.0.0.1:43210'),
+ os.environ['TOR_PT_SERVER_BINDADDR']'dummy-127.0.0.1:46466'
+ os.environ['TOR_PT_SERVER_TRANSPORTS']='dummy'
+
+
\ No newline at end of file
diff --git a/src/pyptlib/__init__.py b/src/pyptlib/transports/__init__.py
similarity index 100%
copy from src/pyptlib/__init__.py
copy to src/pyptlib/transports/__init__.py
diff --git a/src/pyptlib/transports/dummy.py b/src/pyptlib/transports/dummy.py
new file mode 100644
index 0000000..4a7b5f3
--- /dev/null
+++ b/src/pyptlib/transports/dummy.py
@@ -0,0 +1,10 @@
+class Dummy:
+ def __init__(self):
+ pass
+
+ def read(self, len):
+ pass
+
+ def write(self, buf):
+ pass
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/pyptlib.git
More information about the Pkg-privacy-commits
mailing list