[tor-commits] [stem/master] Drop TTL from addresses

atagar at torproject.org atagar at torproject.org
Sun Jan 21 02:04:04 UTC 2018


commit 5619151f3a26b689449a007346bca7eeb8d23e07
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Jan 15 10:23:22 2018 -0800

    Drop TTL from addresses
    
    Damn, that cost me a few hours. Netinfo addresses are of the form specified in
    section 6.4 of the tor-spec but they actually lack the TTL field. I'll clarify
    the spec in a bit.
---
 stem/client/__init__.py   | 11 +++--------
 test/unit/client/types.py |  3 +--
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/stem/client/__init__.py b/stem/client/__init__.py
index 931dbab1..271237d8 100644
--- a/stem/client/__init__.py
+++ b/stem/client/__init__.py
@@ -79,7 +79,7 @@ class Certificate(collections.namedtuple('Certificate', ['type', 'value'])):
   """
 
 
-class Address(collections.namedtuple('Address', ['type', 'type_int', 'value', 'value_bin', 'ttl'])):
+class Address(collections.namedtuple('Address', ['type', 'type_int', 'value', 'value_bin'])):
   """
   Relay address.
 
@@ -87,7 +87,6 @@ class Address(collections.namedtuple('Address', ['type', 'type_int', 'value', 'v
   :var int type_int: integer value of the address type
   :var unicode value: address value
   :var bytes value_bin: encoded address value
-  :var int ttl: seconds the record can be validly cached for
   """
 
   @staticmethod
@@ -103,20 +102,16 @@ class Address(collections.namedtuple('Address', ['type', 'type_int', 'value', 'v
 
     if len(content) < addr_length:
       raise ValueError('Address specified a payload of %i bytes, but only had %i' % (addr_length, len(content)))
-    elif len(content) < addr_length + 4:
-      raise ValueError('Address missing a TTL at its end')
-
-    address_bin, content = content[:addr_length], content[addr_length:]
-    ttl, content = Size.LONG.pop(content)
 
     # TODO: add support for other address types
 
+    address_bin, content = content[:addr_length], content[addr_length:]
     address = None
 
     if addr_type == AddrType.IPv4 and len(address_bin) == 4:
       address = '.'.join([str(Size.CHAR.unpack(address_bin[i])) for i in range(4)])
 
-    return Address(addr_type, addr_type_int, address, address_bin, ttl), content
+    return Address(addr_type, addr_type_int, address, address_bin), content
 
 
 class Size(object):
diff --git a/test/unit/client/types.py b/test/unit/client/types.py
index fdf4e085..a85a0b8d 100644
--- a/test/unit/client/types.py
+++ b/test/unit/client/types.py
@@ -10,10 +10,9 @@ from stem.client import Address
 class TestClientTypes(unittest.TestCase):
   def test_address_ipv4(self):
     addr, content = Address.pop('\x04\x04\x7f\x00\x00\x01\x01\x04\x04aq\x0f\x02\x00\x00\x00\x00')
-    self.assertEqual('q\x0f\x02\x00\x00\x00\x00', content)
+    self.assertEqual('\x01\x04\x04aq\x0f\x02\x00\x00\x00\x00', content)
 
     self.assertEqual('IPv4', addr.type)
     self.assertEqual(4, addr.type_int)
     self.assertEqual('127.0.0.1', addr.value)
     self.assertEqual('\x7f\x00\x00\x01', addr.value_bin)
-    self.assertEqual(17040481, addr.ttl)





More information about the tor-commits mailing list