commit e2b94720b634f99ca0ae8c0be08edf369b667224 Author: Isis Lovecruft isis@torproject.org Date: Fri Oct 11 01:08:56 2013 +0000
Move generatedescriptors.py → scripts/gen_bridge_descriptors.
* ADD scripts/gen_bridge_descriptors to setup.py so that the crunchbang is appropriately rewritten upon installation. --- generatedescriptors.py | 107 ---------------------------------------- scripts/gen_bridge_descriptors | 107 ++++++++++++++++++++++++++++++++++++++++ setup.py | 3 +- 3 files changed, 109 insertions(+), 108 deletions(-)
diff --git a/generatedescriptors.py b/generatedescriptors.py deleted file mode 100644 index 6f64ca0..0000000 --- a/generatedescriptors.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/sbin/env python -tt - -import sys -import random -import time -import ipaddr -from datetime import datetime -import binascii - - -def usage(): - print "syntax: generatedescriptors.py <count>\n"\ - " count: number of descriptors to generate\n" - -def randomIP(): - return randomIP4() - -def randomIP4(): - return ipaddr.IPAddress(random.getrandbits(32)) - -def randomPort(): - return random.randint(1,65535) - -def gettimestamp(): - return time.strftime("%Y-%m-%d %H:%M:%S") - -def getHexString(size): - s = "" - for i in xrange(size): - s+= random.choice("ABCDEF0123456789") - return s - -def generateDesc(): - - baseDesc = "router Unnamed %s %s 0 %s\n"\ - "opt fingerprint %s\n"\ - "opt @purpose bridge\n"\ - "opt published %s\n"\ - "router-signature\n" - fp = "DEAD BEEF F00F DEAD BEEF F00F " + \ - getHexString(4) + " " + getHexString(4) + " " + \ - getHexString(4) + " " + getHexString(4) - ip = randomIP() - orport = randomPort() - dirport = randomPort() - ID = binascii.a2b_hex(fp.replace(" ", "")) - df = baseDesc % (ip, orport, dirport, fp, gettimestamp()) - return (df, (ID, ip, orport, dirport)) - -def generateStatus(info, ID=None, ip=None, orport=None, dirport=None): - baseStatus = "r %s %s %s %s %s %d %d\n"\ - "s Running Stable\n" - - if info and len(info) == 4: - ID = info[0] - ip = info[1] - orport = info[2] - dirport = info[3] - return "".join(baseStatus % ("namedontmattah", binascii.b2a_base64(ID)[:-2], - "randomstring", gettimestamp(), ip, - orport, dirport)) - -def generateExtraInfo(fp, ip=None): - baseExtraInfo = "extra-info %s %s\n"\ - "transport %s %s:%d\n"\ - "router-signature\n" - if not ip: - ip = randomIP() - return "".join(baseExtraInfo % ("namedontmattah", fp, - random.choice(["obfs2", "obfs3", "obfs2"]), - ip, randomPort())) -if __name__ == "__main__": - if len(sys.argv) != 2: - usage() - sys.exit(0) - - df = '' - sf = '' - ei = '' - count = int(sys.argv[1]) - for i in xrange(count): - desc, info = generateDesc() - df += desc - - sf += generateStatus(info) - ei += generateExtraInfo(binascii.b2a_hex(info[0])) - - try: - f = open("networkstatus-bridges", 'w') - f.write(sf) - f.close() - except: - print "Failed to open or write to status file" - - try: - f = open("bridge-descriptors", 'w') - f.write(df) - f.close() - except: - print "Failed to open or write to descriptor file" - - try: - f = open("extra-infos", 'w') - f.write(ei) - f.close() - except: - print "Failed to open or write to extra-info file" diff --git a/scripts/gen_bridge_descriptors b/scripts/gen_bridge_descriptors new file mode 100644 index 0000000..6f64ca0 --- /dev/null +++ b/scripts/gen_bridge_descriptors @@ -0,0 +1,107 @@ +#!/usr/sbin/env python -tt + +import sys +import random +import time +import ipaddr +from datetime import datetime +import binascii + + +def usage(): + print "syntax: generatedescriptors.py <count>\n"\ + " count: number of descriptors to generate\n" + +def randomIP(): + return randomIP4() + +def randomIP4(): + return ipaddr.IPAddress(random.getrandbits(32)) + +def randomPort(): + return random.randint(1,65535) + +def gettimestamp(): + return time.strftime("%Y-%m-%d %H:%M:%S") + +def getHexString(size): + s = "" + for i in xrange(size): + s+= random.choice("ABCDEF0123456789") + return s + +def generateDesc(): + + baseDesc = "router Unnamed %s %s 0 %s\n"\ + "opt fingerprint %s\n"\ + "opt @purpose bridge\n"\ + "opt published %s\n"\ + "router-signature\n" + fp = "DEAD BEEF F00F DEAD BEEF F00F " + \ + getHexString(4) + " " + getHexString(4) + " " + \ + getHexString(4) + " " + getHexString(4) + ip = randomIP() + orport = randomPort() + dirport = randomPort() + ID = binascii.a2b_hex(fp.replace(" ", "")) + df = baseDesc % (ip, orport, dirport, fp, gettimestamp()) + return (df, (ID, ip, orport, dirport)) + +def generateStatus(info, ID=None, ip=None, orport=None, dirport=None): + baseStatus = "r %s %s %s %s %s %d %d\n"\ + "s Running Stable\n" + + if info and len(info) == 4: + ID = info[0] + ip = info[1] + orport = info[2] + dirport = info[3] + return "".join(baseStatus % ("namedontmattah", binascii.b2a_base64(ID)[:-2], + "randomstring", gettimestamp(), ip, + orport, dirport)) + +def generateExtraInfo(fp, ip=None): + baseExtraInfo = "extra-info %s %s\n"\ + "transport %s %s:%d\n"\ + "router-signature\n" + if not ip: + ip = randomIP() + return "".join(baseExtraInfo % ("namedontmattah", fp, + random.choice(["obfs2", "obfs3", "obfs2"]), + ip, randomPort())) +if __name__ == "__main__": + if len(sys.argv) != 2: + usage() + sys.exit(0) + + df = '' + sf = '' + ei = '' + count = int(sys.argv[1]) + for i in xrange(count): + desc, info = generateDesc() + df += desc + + sf += generateStatus(info) + ei += generateExtraInfo(binascii.b2a_hex(info[0])) + + try: + f = open("networkstatus-bridges", 'w') + f.write(sf) + f.close() + except: + print "Failed to open or write to status file" + + try: + f = open("bridge-descriptors", 'w') + f.write(df) + f.close() + except: + print "Failed to open or write to descriptor file" + + try: + f = open("extra-infos", 'w') + f.write(ei) + f.close() + except: + print "Failed to open or write to extra-info file" diff --git a/setup.py b/setup.py index 0e3dba4..d7ef9f5 100644 --- a/setup.py +++ b/setup.py @@ -132,7 +132,8 @@ setuptools.setup( url='https://www.torproject.org', package_dir= {'' : 'lib'}, packages=['bridgedb'], - scripts=['scripts/bridgedb',], + scripts=['scripts/bridgedb', + 'scripts/gen_bridge_descriptors'], extras_require={'test': ["sure>=0.4.5", "trialcoverage>=0.3.12"]}, zip_safe=False,
tor-commits@lists.torproject.org