[Pkg-privacy-commits] [txtorcon] 30/49: Use stem class for parsing relay descriptor

Ximin Luo infinity0 at debian.org
Mon Oct 19 13:49:52 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository txtorcon.

commit b55cc1b1b754dfcd1d397bd3248bd8c1ce1ff5c0
Author: Sambuddha Basu <sambuddhabasu1 at gmail.com>
Date:   Tue Jun 23 19:25:04 2015 +0400

    Use stem class for parsing relay descriptor
    
    Uses react() now
---
 docs/examples.rst                 | 16 ++++++++++++++++
 examples/stem_relay_descriptor.py | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/docs/examples.rst b/docs/examples.rst
index f5cd4f1..341e902 100644
--- a/docs/examples.rst
+++ b/docs/examples.rst
@@ -172,6 +172,22 @@ for logging things INFO, NOTICE, WARN, ERR.
 
 
 
+.. _stem_relay_descriptor.py:
+
+:file:`stem_relay_descriptor.py`
+--------------------------------
+
+:download: `Download the example <../examples/stem_relay_descriptor>`.
+
+Get information about a relay descriptor with the help of `Stem's
+Relay Descriptor class <https://stem.torproject.org/api/descriptor/server_descriptor.html#stem.descriptor.server_descriptor.RelayDescriptor>`. We need to specify the nickname or the fingerprint to get back
+the details.
+
+.. literalinclude:: ../examples/stem_relay_descriptor.py
+
+
+
+
 .. _circuit_failure_rates.py:
 
 :file:`circuit_failure_rates.py`
diff --git a/examples/stem_relay_descriptor.py b/examples/stem_relay_descriptor.py
new file mode 100755
index 0000000..fd300a7
--- /dev/null
+++ b/examples/stem_relay_descriptor.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+# This shows how to get the detailed information about a
+# relay descriptor and parse it into Stem's Relay Descriptor
+# class. More about the class can be read from
+#
+# https://stem.torproject.org/api/descriptor/server_descriptor.html#stem.descriptor.server_descriptor.RelayDescriptor
+#
+# We need to pass the nickname or the fingerprint of the onion
+# router for which we need the the descriptor information,
+
+from twisted.internet.task import react
+from twisted.internet.defer import inlineCallbacks
+import txtorcon
+
+
+ at inlineCallbacks
+def main(reactor):
+    proto = yield txtorcon.build_local_tor_connection(reactor, build_state=False)
+
+    or_nickname = "moria1"
+    print "Trying to get decriptor information about", or_nickname
+    # If the fingerprint is used in place of nickname then, desc/id/<OR identity>
+    # should be used.
+    descriptor_info = yield proto.get_info('desc/name/' + or_nickname)
+
+    descriptor_info = descriptor_info['desc/name/' + or_nickname]
+    try:
+        from stem.descriptor.server_descriptor import RelayDescriptor
+        relay_info = RelayDescriptor(descriptor_info) 
+        print "The relay's fingerprint is:", relay_info.fingerprint
+        print "Time in UTC when the descriptor was made:", relay_info.published
+    except ImportError as e:
+        print "Error:", e
+
+
+if __name__ == '__main__':
+    react(main)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/txtorcon.git



More information about the Pkg-privacy-commits mailing list