[Pkg-privacy-commits] [pyptlib] 45/136: Return more Tor info with init().
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:05 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 c93ce6fb586ef3d04ec89a0390075746374dfe18
Author: George Kadianakis <desnacked at riseup.net>
Date: Tue Sep 4 02:52:49 2012 +0300
Return more Tor info with init().
Now init() returns a dictionary that contains information like the
ORPort, the ExtendedORPort, the state location, etc.
---
src/examples/client.py | 8 ++++++--
src/examples/server.py | 12 ++++++++----
src/pyptlib/config.py | 9 +++++++++
src/pyptlib/easy/client.py | 29 ++++++++++++++++++++++------
src/pyptlib/easy/server.py | 47 ++++++++++++++++++++++++++++++++++------------
src/pyptlib/server.py | 29 ++++++++++++++--------------
6 files changed, 96 insertions(+), 38 deletions(-)
diff --git a/src/examples/client.py b/src/examples/client.py
index 8e882eb..dbaa7a0 100755
--- a/src/examples/client.py
+++ b/src/examples/client.py
@@ -21,8 +21,12 @@ def launchClient(self, name, port):
if __name__ == '__main__':
supportedTransports = ['dummy', 'rot13']
- matchedTransports = init(supportedTransports)
- for transport in matchedTransports:
+ managed_info = init(supportedTransports)
+ if managed_info is None:
+ print "Failed!"
+ return
+
+ for transport in managed_info['transports']:
try:
launchClient(transport, 8182)
reportSuccess(transport, 5, ('127.0.0.1', 8182), None, None)
diff --git a/src/examples/server.py b/src/examples/server.py
index 0217356..c2137a4 100755
--- a/src/examples/server.py
+++ b/src/examples/server.py
@@ -21,11 +21,15 @@ def launchServer(self, name, port):
if __name__ == '__main__':
supportedTransports = ['dummy', 'rot13']
- matchedTransports = init(supportedTransports)
- for transport in matchedTransports:
+ managed_info = init(supportedTransports)
+ if managed_info is None:
+ print "Failed!"
+ return
+
+ for transport, transport_bindaddr in managed_info['transports'].items():
try:
- launchServer(transport, 8182)
- reportSuccess(transport, ('127.0.0.1', 8182), None)
+ launchServer(transport, transport_bindaddr[1])
+ reportSuccess(transport, transport_bindaddr, None)
except TransportLaunchException:
reportFailure(transport, 'Failed to launch')
reportEnd()
diff --git a/src/pyptlib/config.py b/src/pyptlib/config.py
index 142bba6..9faea26 100644
--- a/src/pyptlib/config.py
+++ b/src/pyptlib/config.py
@@ -11,6 +11,15 @@ import logging
__docformat__ = 'restructuredtext'
+"""Receive "<addr>:<port>" in 'string', and return [<addr>,<port>]."""
+def parse_addrport(string):
+ addrport = string.split(':')
+
+ if (len(addrport) != 2):
+ return None
+ addrport[1] = int(addrport[1]) # XXX lame integer check
+
+ return addrport
class Config:
diff --git a/src/pyptlib/easy/client.py b/src/pyptlib/easy/client.py
index fc7acd8..a2244cd 100644
--- a/src/pyptlib/easy/client.py
+++ b/src/pyptlib/easy/client.py
@@ -9,9 +9,20 @@ from pyptlib.client import ClientConfig
def init(transports):
"""
- Initialize the pluggable transport by parsing the environment variables and generating output to report any errors.
- The given transports are checked against the transports enabled by Tor and a list of matching transports is returned.
- The client should then launched all of the transports in the list and report on the success or failure of those launches.
+ Initialize the pluggable transport by parsing the environment
+ variables and generating output to report any errors. The given
+ transports are checked against the transports enabled by a
+ dictionary containing information for the managed proxy is
+ returned.
+
+ The dictionary contains the following keys and values:
+
+ 'state_loc' : Directory where the managed proxy should dump its
+ state files (if needed).
+
+ 'transports' : The names of the transports that must be launched.
+
+ Returns None if something went wrong.
"""
supportedTransportVersion = '1'
@@ -19,20 +30,26 @@ def init(transports):
try:
config = ClientConfig()
except EnvException:
- return []
+ return None
if config.checkManagedTransportVersion(supportedTransportVersion):
config.writeVersion(supportedTransportVersion)
else:
config.writeVersionError()
- return []
+ return None
matchedTransports = []
for transport in transports:
if config.checkTransportEnabled(transport):
matchedTransports.append(transport)
- return matchedTransports
+ # XXX the XXXs from server.py are valid here too.
+
+ retval = {}
+ retval['state_loc'] = config.getStateLocation()
+ retval['transports'] = matchedTransports
+
+ return retval
def reportSuccess(
diff --git a/src/pyptlib/easy/server.py b/src/pyptlib/easy/server.py
index 02eca8a..6ed1870 100644
--- a/src/pyptlib/easy/server.py
+++ b/src/pyptlib/easy/server.py
@@ -9,36 +9,61 @@ from pyptlib.server import ServerConfig
def init(transports):
"""
- Initialize the pluggable transport by parsing the environment variables and generating output to report any errors.
- The given transports are checked against the transports enabled by Tor and a list of matching transports is returned.
- The server should then launch all of the transports in the list and report on the success or failure of those launches.
+ Initialize the pluggable transport by parsing the environment
+ variables and generating output to report any errors. The
+ given transports are checked against the transports enabled by
+ Tor and a dictionary containing information for the managed
+ proxy is returned.
+
+ The dictionary contains the following keys and values:
+
+ 'state_loc' : Directory where the managed proxy should dump its
+ state files (if needed).
+
+ 'orport' : [<addr>, <port>] tuple containing the address and port
+ of Tor's ORPort.
+
+ 'ext_orport' : [<addr>, <port>] tuple containing the address and
+ port of Tor's Extended ORPort.
+
+ 'transports' : A dictionary {<transport> : [<addr>, <port>]},
+ where <transport> is the name of the transport that must be
+ spawned, and [<addr>, <port>] is a list containing the location
+ where that transport should bind.
+
+ Returns None if something went wrong.
"""
supportedTransportVersion = '1'
try:
config = ServerConfig()
- except EnvException:
- return []
+ except EnvException: # don't throw exceptions; return None
+ return None
if config.checkManagedTransportVersion(supportedTransportVersion):
config.writeVersion(supportedTransportVersion)
else:
config.writeVersionError()
- return []
+ return None
matchedTransports = []
for transport in transports:
if config.checkTransportEnabled(transport):
matchedTransports.append(transport)
- return matchedTransports
+ # XXX Must issue SMETHOD-ERROR when Tor asked us to spawn a
+ # XXX transport but we don't support it!!!!
+ # XXX what to do if matchedTransports is empty ???
-def getORPort():
- config = ServerConfig()
- return config.ORPort
+ retval = {}
+ retval['state_loc'] = config.getStateLocation()
+ retval['orport'] = config.getORPort()
+ retval['ext_orport'] = config.getExtendedORPort()
+ retval['transports'] = config.getServerBindAddresses()
+ return retval
def reportSuccess(name, address, options):
"""
@@ -70,5 +95,3 @@ def reportEnd():
config = ServerConfig()
config.writeMethodEnd()
-
-
diff --git a/src/pyptlib/server.py b/src/pyptlib/server.py
index 84b22dc..854b55b 100644
--- a/src/pyptlib/server.py
+++ b/src/pyptlib/server.py
@@ -8,12 +8,11 @@
import os
-from pyptlib.config import Config
+import pyptlib.config as config
__docformat__ = 'restructuredtext'
-
-class ServerConfig(Config):
+class ServerConfig(config.Config):
"""
The ServerConfig class contains a low-level API which closely follows the Tor Proposal 180: Pluggable transports for circumvention.
@@ -32,29 +31,31 @@ class ServerConfig(Config):
This causes the state location, managed transport, and transports version to be set.
"""
- Config.__init__(self)
+ config.Config.__init__(self)
+
+ # extendedORPort can also be 'None'
+ self.extendedORPort = config.parse_addrport(self.get('TOR_PT_EXTENDED_SERVER_PORT'))
+ self.ORPort = config.parse_addrport(self.get('TOR_PT_ORPORT'))
+
+ if self.ORPort is None:
+ raise config.EnvException("ORPort was corrupted")
- self.extendedServerPort = self.get('TOR_PT_EXTENDED_SERVER_PORT'
- )
- orport = self.get('TOR_PT_ORPORT').split(':')
- orport[1]=int(orport[1])
- self.ORPort=orport
binds = self.get('TOR_PT_SERVER_BINDADDR').split(',')
for bind in binds:
(key, value) = bind.split('-')
- self.serverBindAddr[key] = value
+ self.serverBindAddr[key] = value.split(":") # XXX ugly code
+ self.serverBindAddr[key][1] = int(self.serverBindAddr[key][1]) # XXX ugly code
- self.transports = self.get('TOR_PT_SERVER_TRANSPORTS').split(','
- )
+ self.transports = self.get('TOR_PT_SERVER_TRANSPORTS').split(',')
if '*' in self.transports:
self.allTransportsEnabled = True
self.transports.remove('*')
- def getExtendedServerPort(self):
+ def getExtendedORPort(self):
""" Returns a tuple (str,int) representing the address of the Tor server port as reported by Tor """
- return self.extendedServerPort
+ return self.extendedORPort
def getORPort(self):
""" Returns a tuple (str,int) representing the address of the Tor OR port as reported by Tor """
--
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