[Pkg-privacy-commits] [pyptlib] 04/136: First pass at implementing the methods
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:24:59 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 0b8538bd1e5e4943b0eff9a39ffe8820368f256a
Author: Brandon Wiley <brandon at blanu.net>
Date: Fri Jun 1 10:35:23 2012 -0500
First pass at implementing the methods
---
src/pyptlib/client.py | 21 ++++++++++++----
src/pyptlib/config.py | 32 ++++++++++++++++++++---
src/pyptlib/server.py | 70 ++++++++++++++++++++++++++++++++++++---------------
3 files changed, 95 insertions(+), 28 deletions(-)
diff --git a/src/pyptlib/client.py b/src/pyptlib/client.py
index 474a7f2..99fe730 100644
--- a/src/pyptlib/client.py
+++ b/src/pyptlib/client.py
@@ -1,9 +1,15 @@
+import os
+
+from config import Config
+
class ClientConfig(Config):
clientTransports=[] # TOR_PT_CLIENT_TRANSPORTS
def __init__(self): # throws EnvError
Config.__init__(self)
+ clientTransports=get('TOR_PT_CLIENT_TRANSPORTS').split(',')
+
# Returns a list of strings representing the client transports reported by Tor. If present, '*' is stripped from this list and used to set allTransportsEnabled to True.
def getClientTransports(self):
return clientTransports
@@ -11,13 +17,18 @@ class ClientConfig(Config):
# Write a message to stdout specifying a supported transport
# Takes: str, int, (str, int), [str], [str]
def writeMethod(self, name, socksVersion, address, args, optArgs): # CMETHOD
- pass
-
+ s='CMETHOD '+str(name)+' socks'+str(socksVersion)+' '+str(address[0])+':'+str(address[1])
+ if args and len(args)>0:
+ s=s+' ARGS='+args.join(',')
+ if optArgs and len(optArgs)>0:
+ s=s+' OPT-ARGS='+args.join(',')
+ print(s)
+
# Write a message to stdout specifying that an error occurred setting up the specified method
# Takes: str, str
def writeMethodError(self, name, message): # CMETHOD-ERROR
- pass
+ print('CMETHOD-ERROR '+str(name)+' '+str(message))
# Write a message to stdout specifying that the list of supported transports has ended
- def writeMethodEnd(self) # CMETHODS DONE
- pass
+ def writeMethodEnd(self): # CMETHODS DONE
+ print('CMETHODS DONE')
diff --git a/src/pyptlib/config.py b/src/pyptlib/config.py
index e441132..203fded 100644
--- a/src/pyptlib/config.py
+++ b/src/pyptlib/config.py
@@ -1,28 +1,54 @@
+import os
+
class Config:
stateLocation=None # TOR_PT_STATE_LOCATION
managedTransportVer=[] # TOR_PT_MANAGED_TRANSPORT_VER
allTransportsEnabled=False
def __init__(self): # throws EnvError
- pass
+ stateLocation=get('TOR_PT_STATE_LOCATION')
+ managedTransportVer=get('TOR_PT_MANAGED_TRANSPORT_VER').split(',')
+ if '*' in managedTransportVer:
+ allTransportsEnabled=True
+ managedTransportVer.remove('*')
+
+ def get(self, key):
+ if key in os.environ:
+ return os.environ[key]
+ else:
+ raise EnvException()
# Returns a string representing the path to the state storage directory (which may not exist, but should be creatable) reported by Tor
def getStateLocation(self):
return stateLocation
# Returns a list of strings representing supported versions as reported by Tor
- def getManagedTransportVersions(self)
+ def getManagedTransportVersions(self):
return managedTransportVer
# Checks to see if the specified version is included in those reported by Tor
# Returns True if the version is included and False if it is not
def checkManagedTransportVersion(self, version):
- pass
+ return allTransportsEnabled or version in managedTransportVer
# Returns a bool, True if the transport '*' was specified by Tor, otherwise False.
def getAllTransportsEnabled(self):
return allTransportsEnabled
+ # Write a message to stdout specifying that an error parsing the environment variables has occurred
+ # Takes: str
+ def writeEnvError(self, message): # ENV-ERROR
+ print('ENV-ERROR '+str(message))
+
+ # Write a message to stdout specifying that the specified configuration protocol version is supported
+ # Takes: str
+ def writeVersion(self, version): # VERSION
+ print('VERSION '+str(version))
+
+ # Write a message to stdout specifying that none of the specified configuration protocol versions are supported
+ def writeVersionError(self): # VERSION-ERROR
+ print('VERSION-ERROR no-version')
+
# Exception thrown when there is an error parsing the configuration parameters provided by Tor in environment variables
class EnvException(Exception):
pass
diff --git a/src/pyptlib/server.py b/src/pyptlib/server.py
index f21dd98..98dde52 100644
--- a/src/pyptlib/server.py
+++ b/src/pyptlib/server.py
@@ -1,3 +1,7 @@
+import os
+
+from config import Config
+
class ServerConfig(Config):
extendedServerPort=None # TOR_PT_EXTENDED_SERVER_PORT
ORPort=None # TOR_PT_ORPORT
@@ -7,6 +11,16 @@ class ServerConfig(Config):
def __init__(self): # throws EnvError
Config.__init__(self)
+ extendedServerPort=get('TOR_PT_EXTENDED_SERVER_PORT')
+ ORPort=get('TOR_PT_ORPORT')
+
+ binds=get('TOR_PT_SERVER_BINADDR').split(',')
+ for bind in binds:
+ key,value=bind.split(',')
+ serverBindAddr[key]=value
+
+ serverTransports=get('TOR_PT_SERVER_TRANSPORTS').split(',')
+
# Returns a tuple (str,int) representing the address of the Tor server port as reported by Tor
def getExtendedServerPort(self):
return extendedServerPort
@@ -23,29 +37,22 @@ class ServerConfig(Config):
def getServerTransports(self):
return serverTransports
- # Write a message to stdout specifying that an error parsing the environment variables has occurred
- # Takes: str
- def writeEnvError(self, message): # ENV-ERROR
- pass
-
- # Write a message to stdout specifying that the specified configuration protocol version is supported
- # Takes: str
- def writeVersion(self, version): # VERSION
- pass
-
# Write a message to stdout specifying a supported transport
# Takes: str, (str, int), MethodOptions
def writeMethod(self, name, address, options): # SMETHOD
- pass
+ s='SMETHOD '+str(name)+' '+str(address[0])+':'+str(address[1])
+ if options:
+ s=s+' '+str(options)
+ print(s)
# Write a message to stdout specifying that an error occurred setting up the specified method
# Takes: str, str
def writeMethodError(self, name, message): # SMETHOD-ERROR
- pass
+ print('SMETHOD-ERROR '+str(name)+' '+str(message))
# Write a message to stdout specifying that the list of supported transports has ended
- def writeMethodEnd(self) # SMETHODS DONE
- pass
+ def writeMethodEnd(self): # SMETHODS DONE
+ print('SMETHODS DONE')
class MethodOptions:
forward=False # FORWARD
@@ -57,17 +64,40 @@ class MethodOptions:
pass
# Sets forward to True
- def setForward(self)
- pass
+ def setForward(self):
+ forward=True
# Adds a key-value pair to args
def addArg(self, key, value):
- pass
+ args[key]=value
# Adds a key-value pair to declare
def addDeclare(self, key, value):
- pass
+ declare[key]=value
# Sets useExtendedPort to True
- def setUserExtendedPort(self)
- pass
+ def setUserExtendedPort(self):
+ useExtendedPort=True
+
+ def __str__(self):
+ options=[]
+ if forward:
+ options.append('FORWARD:1')
+ if len(args)>0:
+ argstr='ARGS:'
+ for key in args:
+ value=args[key]
+ argstr=argstr+key+'='+value+','
+ argstr=argstr[:-1] # Remove trailing comma
+ options.append(argstr)
+ if len(declare)>0:
+ decs='DECLARE:'
+ for key in declare:
+ value=args[key]
+ argstr=argstr+key+'='+value+','
+ decs=decs[:-1] # Remove trailing comma
+ options.append(decs)
+ if useExtendedPort:
+ options.append('USE-EXTENDED-PORT:1')
+
+ return options.join(' ')
--
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