commit 6c99a28e83490537615de9388484c574aa1b85dd Author: Damian Johnson atagar@torproject.org Date: Sun Feb 3 20:43:28 2013 -0800
Using port lists for addresses_v6 rather than ranges
Huh, I wonder where I got the idea that 'a' lines had port ranges. Dropping that. According to the spec the 'a' lines should be parsed in the same way as 'or-address'. However, I suspect that the spec is a little off here - checking if it can contain IPv4 addresses...
Caught by Karsten on...
https://trac.torproject.org/8036 --- stem/descriptor/router_status_entry.py | 25 +++++++++---------------- test/unit/descriptor/router_status_entry.py | 11 ++++------- 2 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py index ce5a7db..2cd6632 100644 --- a/stem/descriptor/router_status_entry.py +++ b/stem/descriptor/router_status_entry.py @@ -299,7 +299,7 @@ class RouterStatusEntryV3(RouterStatusEntry): status document.
:var dict addresses_v6: ***** relay's IPv6 OR addresses, this is a mapping - of IPv6 addresses to a listing of [(min port, max port)...] it accepts + of IPv6 addresses to a tuple with the ports it accepts :var str digest: ***** router's digest
:var int bandwidth: bandwidth claimed by the relay (in kb/s) @@ -521,28 +521,21 @@ def _parse_a_line(desc, value, validate):
raise ValueError("%s 'a' line must be of the form '[address]:[ports]': a %s" % (desc._name(), value))
- address, ports = value.rsplit(':', 1) + address, port_label = value.rsplit(':', 1)
if validate and not stem.util.connection.is_valid_ipv6_address(address, allow_brackets = True): raise ValueError("%s 'a' line must start with an IPv6 address: a %s" % (desc._name(), value))
address = address.lstrip('[').rstrip(']') + ports = []
- for port_entry in ports.split(','): - if '-' in port_entry: - min_port, max_port = port_entry.split('-', 1) - else: - min_port = max_port = port_entry - - if not stem.util.connection.is_valid_port(min_port) or \ - not stem.util.connection.is_valid_port(max_port): - - if not validate: - continue - - raise ValueError("%s 'a' line had an invalid port range (%s): a %s" % (desc._name(), port_entry, value)) + for port in port_label.split(','): + if stem.util.connection.is_valid_port(port): + ports.append(int(port)) + elif validate: + raise ValueError("%s 'a' line had an invalid port (%s): a %s" % (desc._name(), port, value))
- desc.addresses_v6.setdefault(address, []).append((int(min_port), int(max_port))) + desc.addresses_v6[address] = tuple(ports)
def _parse_s_line(desc, value, validate): diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py index 21795f2..b9d3649 100644 --- a/test/unit/descriptor/router_status_entry.py +++ b/test/unit/descriptor/router_status_entry.py @@ -313,11 +313,9 @@ class TestRouterStatusEntry(unittest.TestCase):
test_values = { "[2607:fcd0:daaa:101::602c:bd62]:443": { - '2607:fcd0:daaa:101::602c:bd62': [(443, 443)]}, + '2607:fcd0:daaa:101::602c:bd62': (443,)}, "[2607:fcd0:daaa:101::602c:bd62]:80,443": { - '2607:fcd0:daaa:101::602c:bd62': [(80, 80), (443, 443)]}, - "[2607:fcd0:daaa:101::602c:bd62]:443-512": { - '2607:fcd0:daaa:101::602c:bd62': [(443, 512)]}, + '2607:fcd0:daaa:101::602c:bd62': (80, 443)}, }
for a_line, expected in test_values.items(): @@ -328,12 +326,11 @@ class TestRouterStatusEntry(unittest.TestCase):
content = get_router_status_entry_v3(content = True) content += "\na [2607:fcd0:daaa:101::602c:bd62]:80,443" - content += "\na [2607:fcd0:daaa:101::602c:bd62]:512-600" content += "\na [1148:fcd0:daaa:101::602c:bd62]:80"
expected = { - '2607:fcd0:daaa:101::602c:bd62': [(80, 80), (443, 443), (512, 600)], - '1148:fcd0:daaa:101::602c:bd62': [(80, 80)], + '2607:fcd0:daaa:101::602c:bd62': (80, 443), + '1148:fcd0:daaa:101::602c:bd62': (80,), }
entry = RouterStatusEntryV3(content)