[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Moving relay/bridge differentation into parse_file_v3()
commit 785b22f274c30c2e52703c97bee3f2fb5a23e247
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Thu Apr 12 09:36:49 2012 -0700
Moving relay/bridge differentation into parse_file_v3()
It was confusing for parse_file_v3() to only work for relay server descriptors
so moving the hack to differentiate relay from bridge descriptors there. This
is also nice because it moves server descriptor logic out of the general
__init__ module and into the one that's specifically for handling server
descriptors.
---
stem/descriptor/__init__.py | 10 +---------
stem/descriptor/server_descriptor.py | 21 +++++++++++++++++++--
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 0e90546..21f40c2 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -40,15 +40,7 @@ def parse_file(path, descriptor_file):
first_line = descriptor_file.readline()
descriptor_file.seek(0)
- if first_line.startswith("router Unnamed 10."):
- # bridge descriptors are scrubbed so their nickname is 'Unnamed' and their
- # ip address is in the 10.x.x.x space, which is normally reserved for
- # private networks
-
- desc = stem.descriptor.server_descriptor.BridgeDescriptorV3(descriptor_file.read())
- desc._set_path(path)
- yield desc
- elif filename == "cached-descriptors" or first_line.startswith("router "):
+ if filename == "cached-descriptors" or first_line.startswith("router "):
for desc in stem.descriptor.server_descriptor.parse_file_v3(descriptor_file):
desc._set_path(path)
yield desc
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index aedcb31..52bca94 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -64,7 +64,8 @@ SINGLE_FIELDS = (
def parse_file_v3(descriptor_file, validate = True):
"""
- Iterates over the version 3 server descriptors in a file.
+ Iterates over the version 3 server descriptors in a file. This can read
+ either relay or bridge v3 server descriptors.
Arguments:
descriptor_file (file) - file with descriptor content
@@ -72,13 +73,29 @@ def parse_file_v3(descriptor_file, validate = True):
True, skips these checks otherwise
Returns:
- iterator for RelayDescriptorV3 instances in the file
+ iterator for ServerDescriptorV3 instances in the file
Raises:
ValueError if the contents is malformed and validate is True
IOError if the file can't be read
"""
+ # Handler for bridge descriptors
+ #
+ # Bridge descriptors are scrubbed so their nickname is 'Unnamed' and their
+ # ip address is in the 10.x.x.x space, which is normally reserved for
+ # private networks. Bride descriptors only come from metrics so a file only
+ # contains a single descriptor.
+
+ first_line = descriptor_file.readline()
+ descriptor_file.seek(0)
+
+ if first_line.startswith("router Unnamed 10."):
+ yield BridgeDescriptorV3(descriptor_file.read())
+ return
+
+ # Handler for relay descriptors
+ #
# Cached descriptors consist of annotations followed by the descriptor
# itself. For instance...
#
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits