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

[tor-commits] [stem/master] Example for using the FallbackDirectories



commit 4ba079906e7890c0df1ab9602ac8240a8c4158a9
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Feb 21 18:44:44 2016 -0800

    Example for using the FallbackDirectories
    
    On reflection might as well include the example I just gave teor on #18177 in
    our pydocs as well.
---
 stem/descriptor/remote.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py
index dc40e41..e0923dc 100644
--- a/stem/descriptor/remote.py
+++ b/stem/descriptor/remote.py
@@ -819,6 +819,30 @@ class FallbackDirectory(Directory):
   Tor directories tor uses as alternates for the authorities. These relays are
   `hardcoded in tor <https://gitweb.torproject.org/tor.git/tree/src/or/fallback_dirs.inc>`_.
 
+  For example, following checks the performance of tor's fallback directories...
+
+  ::
+
+    import time
+    from stem.descriptor.remote import DescriptorDownloader, FallbackDirectory
+
+    downloader = DescriptorDownloader()
+
+    for fallback_directory in FallbackDirectory.from_cache().values():
+      start = time.time()
+      downloader.get_consensus(endpoints = [(fallback_directory.address, fallback_directory.dir_port)]).run()
+      print('Downloading the consensus took %0.2f from %s' % (time.time() - start, fallback_directory.nickname))
+
+  ::
+
+    % python example.py
+    Downloading the consensus took 5.07 from Doedel22
+    Downloading the consensus took 3.59 from tornoderdednl
+    Downloading the consensus took 4.16 from Logforme
+    Downloading the consensus took 6.76 from Doedel21
+    Downloading the consensus took 5.21 from kitten4
+    ...
+
   .. versionadded:: 1.5.0
   """
 

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