commit 7947d69d4e20ca402e9d1d35fe6e62012d5e61fe Author: Damian Johnson atagar@torproject.org Date: Sun Jun 10 12:31:14 2012 -0700
Separating relay and bridge extra-info descriptors
Creating separate classes for relay and bridge extra-info descriptors. At present they're identical to their common parent (ExtraInfoDescriptor), adding their differences next. --- stem/descriptor/__init__.py | 6 ++++-- stem/descriptor/extrainfo_descriptor.py | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py index 37f9ec7..e4f23e5 100644 --- a/stem/descriptor/__init__.py +++ b/stem/descriptor/__init__.py @@ -70,8 +70,10 @@ def parse_file(path, descriptor_file): desc = stem.descriptor.server_descriptor.RelayDescriptor(descriptor_file.read()) elif first_line == "@type bridge-server-descriptor 1.0": desc = stem.descriptor.server_descriptor.BridgeDescriptor(descriptor_file.read()) - elif first_line in ("@type extra-info 1.0", "@type bridge-extra-info 1.0"): - desc = stem.descriptor.extrainfo_descriptor.ExtraInfoDescriptor(descriptor_file.read()) + elif first_line in ("@type bridge-extra-info 1.0"): + desc = stem.descriptor.extrainfo_descriptor.RelayExtraInfoDescriptor(descriptor_file.read()) + elif first_line in ("@type extra-info 1.0"): + desc = stem.descriptor.extrainfo_descriptor.BridgeExtraInfoDescriptor(descriptor_file.read())
if desc: desc._set_path(path) diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py index 9fbdd1d..03c7a37 100644 --- a/stem/descriptor/extrainfo_descriptor.py +++ b/stem/descriptor/extrainfo_descriptor.py @@ -42,6 +42,9 @@ Extra-info descriptors are available from a few sources...
parse_file - Iterates over the extra-info descriptors in a file. ExtraInfoDescriptor - Tor extra-info descriptor. + | |- RelayExtraInfoDescriptor - Extra-info descriptor for a relay. + | +- BridgeExtraInfoDescriptor - Extra-info descriptor for a bridge. + | +- get_unrecognized_lines - lines with unrecognized content """
@@ -270,13 +273,9 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
def __init__(self, raw_contents, validate = True): """ - Extra-info descriptor constructor, created from a relay's extra-info - content (as provided by "GETINFO extra-info/digest/*", cached contents, and - metrics). - - By default this validates the descriptor's content as it's parsed. This - validation can be disables to either improve performance or be accepting of - malformed data. + Extra-info descriptor constructor. By default this validates the + descriptor's content as it's parsed. This validation can be disables to + either improve performance or be accepting of malformed data.
:param str raw_contents: extra-info content provided by the relay :param bool validate: checks the validity of the extra-info descriptor if True, skips these checks otherwise @@ -683,3 +682,15 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): else: self._unrecognized_lines.append(line)
+class RelayExtraInfoDescriptor(ExtraInfoDescriptor): + """ + Relay extra-info descriptor, constructed from data such as that provided by + "GETINFO extra-info/digest/*", cached descriptors, and metrics + (`specification https://gitweb.torproject.org/torspec.git/blob/HEAD:/dir-spec.txt`_). + """ + +class BridgeExtraInfoDescriptor(ExtraInfoDescriptor): + """ + Bridge extra-info descriptor (`specification https://metrics.torproject.org/formats.html#bridgedesc`_) + """ +
tor-commits@lists.torproject.org