[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Setting zero ports to None in server descriptors
commit dc15e682be37ea450a9b5e45f05958f676eabded
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Mon Aug 20 22:58:11 2012 -0700
Setting zero ports to None in server descriptors
When writing the server descriptor parser I faithfully translated zero ports as
zero because I wanted users to be able to differentiate between 'malformed' and
'zero' when validation was disabled. However, on reflection I don't really care
about catoring to non-validation use cases.
Ravi made the router status entries interpret a zero port as being None which
makes perfect sense - zero means that the port doesn't exist. Doing this for
the server descriptors too.
---
stem/descriptor/server_descriptor.py | 6 +++---
test/integ/descriptor/server_descriptor.py | 18 +++++++++---------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 9b8ef0d..6eb3883 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -134,7 +134,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
:var str address: **\*** IPv4 address of the relay
:var int or_port: **\*** port used for relaying
- :var int socks_port: **\*** port used as client (deprecated, always zero)
+ :var int socks_port: **\*** port used as client (deprecated, always None)
:var int dir_port: **\*** port used for descriptor mirroring
:var str platform: line with operating system and tor version
@@ -340,8 +340,8 @@ class ServerDescriptor(stem.descriptor.Descriptor):
self.nickname = router_comp[0]
self.address = router_comp[1]
self.or_port = int(router_comp[2])
- self.socks_port = int(router_comp[3])
- self.dir_port = int(router_comp[4])
+ self.socks_port = None if router_comp[3] == '0' else int(router_comp[3])
+ self.dir_port = None if router_comp[4] == '0' else int(router_comp[4])
elif keyword == "bandwidth":
# "bandwidth" bandwidth-avg bandwidth-burst bandwidth-observed
bandwidth_comp = value.split()
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py
index 38d633c..55e6545 100644
--- a/test/integ/descriptor/server_descriptor.py
+++ b/test/integ/descriptor/server_descriptor.py
@@ -62,8 +62,8 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
self.assertEquals("A7569A83B5706AB1B1A9CB52EFF7D2D32E4553EB", desc.fingerprint)
self.assertEquals("71.35.133.197", desc.address)
self.assertEquals(9001, desc.or_port)
- self.assertEquals(0, desc.socks_port)
- self.assertEquals(0, desc.dir_port)
+ self.assertEquals(None, desc.socks_port)
+ self.assertEquals(None, desc.dir_port)
self.assertEquals("Tor 0.2.1.30 on Linux x86_64", desc.platform)
self.assertEquals(stem.version.Version("0.2.1.30"), desc.tor_version)
self.assertEquals("Linux x86_64", desc.operating_system)
@@ -105,8 +105,8 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
self.assertEquals("3E2F63E2356F52318B536A12B6445373808A5D6C", desc.fingerprint)
self.assertEquals("212.37.39.59", desc.address)
self.assertEquals(8000, desc.or_port)
- self.assertEquals(0, desc.socks_port)
- self.assertEquals(0, desc.dir_port)
+ self.assertEquals(None, desc.socks_port)
+ self.assertEquals(None, desc.dir_port)
self.assertEquals("Tor 0.1.0.14 on FreeBSD i386", desc.platform)
self.assertEquals(stem.version.Version("0.1.0.14"), desc.tor_version)
self.assertEquals("FreeBSD i386", desc.operating_system)
@@ -161,7 +161,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
self.assertEquals(None, desc.read_history_end)
self.assertEquals(None, desc.write_history_end)
self.assertEquals(None, desc.eventdns)
- self.assertEquals(0, desc.socks_port)
+ self.assertEquals(None, desc.socks_port)
unrecognized_lines = desc.get_unrecognized_lines()
@@ -193,8 +193,8 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
self.assertEquals("FEBC7F992AC418BBE42BC13FE94EFCFE6549197E", desc.fingerprint)
self.assertEquals("130.243.230.116", desc.address)
self.assertEquals(9001, desc.or_port)
- self.assertEquals(0, desc.socks_port)
- self.assertEquals(0, desc.dir_port)
+ self.assertEquals(None, desc.socks_port)
+ self.assertEquals(None, desc.dir_port)
self.assertEquals("Tor 0.2.2.35 (git-4f42b0a93422f70e) on Linux x86_64", desc.platform)
self.assertEquals(stem.version.Version("0.2.2.35"), desc.tor_version)
self.assertEquals("Linux x86_64", desc.operating_system)
@@ -291,8 +291,8 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
self.assertEquals("AE54E28ED069CDF45F3009F963EE3B3D6FA26A2E", desc.fingerprint)
self.assertEquals("10.45.227.253", desc.address)
self.assertEquals(9001, desc.or_port)
- self.assertEquals(0, desc.socks_port)
- self.assertEquals(0, desc.dir_port)
+ self.assertEquals(None, desc.socks_port)
+ self.assertEquals(None, desc.dir_port)
self.assertEquals("Tor 0.2.3.12-alpha (git-800942b4176ca31c) on Linux x86_64", desc.platform)
self.assertEquals(stem.version.Version("0.2.3.12-alpha"), desc.tor_version)
self.assertEquals("Linux x86_64", desc.operating_system)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits