commit 7d157f9ad852b3f2020df45fb35a18accaef23fa Author: Taylor Yu catalyst@torproject.org Date: Thu Jun 29 18:38:18 2017 -0400
Stop generating too-long nicknames
Some platforms have sys.maxint large enough that the random router nicknames were too long (especially for BridgeDescriptor). Factor out the random nickname generation into _random_nickname() and use it consistently. --- stem/descriptor/__init__.py | 5 +++++ stem/descriptor/server_descriptor.py | 9 +++------ 2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py index f293c6c..5f8d1ca 100644 --- a/stem/descriptor/__init__.py +++ b/stem/descriptor/__init__.py @@ -46,6 +46,7 @@ import os import random import re import string +import sys import tarfile
import stem.prereq @@ -1055,6 +1056,10 @@ def _random_crypto_blob(block_type = None): return crypto_blob
+def _random_nickname(): + return ('Unnamed%i' % random.randint(0, sys.maxint))[:19] + + def _descriptor_components(raw_contents, validate, extra_keywords = (), non_ascii_fields = ()): """ Initial breakup of the server descriptor contents to make parsing easier. diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py index 8228b1d..5826bb6 100644 --- a/stem/descriptor/server_descriptor.py +++ b/stem/descriptor/server_descriptor.py @@ -35,9 +35,7 @@ import base64 import binascii import functools import hashlib -import random import re -import sys
import stem.descriptor.certificate import stem.descriptor.extrainfo_descriptor @@ -71,6 +69,7 @@ from stem.descriptor import ( _random_ipv4_address, _random_date, _random_crypto_blob, + _random_nickname, )
try: @@ -806,10 +805,8 @@ class RelayDescriptor(ServerDescriptor): if attr is None: attr = {}
- nickname = ('Unnamed%i' % random.randint(0, sys.maxint))[:19] - base_header = ( - ('router', '%s %s 9001 0 0' % (nickname, _random_ipv4_address())), + ('router', '%s %s 9001 0 0' % (_random_nickname(), _random_ipv4_address())), ('published', _random_date()), ('bandwidth', '153600 256000 104590'), ('reject', '*:*'), @@ -927,7 +924,7 @@ class BridgeDescriptor(ServerDescriptor): raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
return _descriptor_content(attr, exclude, sign, ( - ('router', 'Unnamed%s %s 9001 0 0' % (random.randint(0, sys.maxint), _random_ipv4_address())), + ('router', '%s %s 9001 0 0' % (_random_nickname(), _random_ipv4_address())), ('router-digest', '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4'), ('published', _random_date()), ('bandwidth', '409600 819200 5120'),
tor-commits@lists.torproject.org