[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Add a make_router_status_entry method



commit 984497610ebc1efbf474b5dbd3fcc7e89c88fedd
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Jun 30 11:06:51 2017 -0700

    Add a make_router_status_entry method
    
    Little helper to make router status entries that are derived from a server
    descriptor. This presently populates just the base router status entry fields,
    not the optional v3 fields. Happy to have it expanded if folks need that
    though.
---
 stem/descriptor/server_descriptor.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 643831b..edd1612 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -21,6 +21,7 @@ etc). This information is provided from a few sources...
 
   ServerDescriptor - Tor server descriptor.
     |- RelayDescriptor - Server descriptor for a relay.
+    |  +- make_router_status_entry - Creates a router status entry for this descriptor.
     |
     |- BridgeDescriptor - Scrubbed server descriptor for a bridge.
     |  |- is_scrubbed - checks if our content has been properly scrubbed
@@ -46,6 +47,7 @@ import stem.util.str_tools
 import stem.util.tor_tools
 import stem.version
 
+from stem.descriptor.router_status_entry import RouterStatusEntryV3
 from stem.util import str_type
 
 from stem.descriptor import (
@@ -855,6 +857,33 @@ class RelayDescriptor(ServerDescriptor):
 
     return self._digest_for_content(b'router ', b'\nrouter-signature\n')
 
+  def make_router_status_entry(self):
+    """
+    Provides a RouterStatusEntryV3 for this descriptor content.
+
+    .. versionadded:: 1.6.0
+
+    :returns: :class:`~stem.descriptor.router_status_entry.RouterStatusEntryV3`
+      that would be in the consensus
+    """
+
+    attr = {
+      'r': ' '.join([
+        self.nickname,
+        base64.b64encode(binascii.unhexlify(self.fingerprint)).rstrip('='),
+        base64.b64encode(binascii.unhexlify(self.digest())).rstrip('='),
+        self.published.strftime('%Y-%m-%d %H:%M:%S'),
+        self.address,
+        str(self.or_port),
+        str(self.dir_port) if self.dir_port else '0',
+      ]),
+    }
+
+    if self.tor_version:
+      attr['v'] = self.tor_version
+
+    return RouterStatusEntryV3.create(attr)
+
   @lru_cache()
   def onion_key_crosscert_digest(self):
     """

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits