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

[tor-commits] [stem/master] Integ test downloading descriptors from ORPort



commit d0374a7b70e836abe70b15a827abf55314ce5825
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue Apr 24 12:10:33 2018 -0700

    Integ test downloading descriptors from ORPort
    
    Sweet, finally it's working for realz!
---
 docs/change_log.rst             |  3 ++-
 stem/descriptor/remote.py       |  9 ++++++---
 test/integ/descriptor/remote.py | 27 +++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/docs/change_log.rst b/docs/change_log.rst
index 18005e1e..b237f25f 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -55,8 +55,9 @@ The following are only available within Stem's `git repository
 
  * **Descriptors**
 
+  * `stem.descriptor.remote <api/descriptor/remote.html>`_ can now download from relay ORPorts
+  * Zstd and lzma compression support (:spec:`1cb56af`)
   * `Fallback directory v2 support <https://lists.torproject.org/pipermail/tor-dev/2017-December/012721.html>`_, which adds *nickname* and *extrainfo*
-  * Added zstd and lzma compression support (:spec:`1cb56af`)
   * Added server descriptor's new is_hidden_service_dir attribute
   * Don't retry downloading descriptors when we've timed out
   * Added :func:`~stem.descriptor.remote.their_server_descriptor`
diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py
index 5bd186c3..fda73327 100644
--- a/stem/descriptor/remote.py
+++ b/stem/descriptor/remote.py
@@ -282,12 +282,12 @@ def _download_from_orport(endpoint, resource):
     * :class:`stem.SocketError` if unable to establish a connection
   """
 
-  link_protocol = endpoint.link_protocols if endpoint.link_protocols else [3]
+  link_protocols = endpoint.link_protocols if endpoint.link_protocols else [3]
 
-  with stem.client.Relay.connect(endpoint.address, endpoint.port, link_protocol) as relay:
+  with stem.client.Relay.connect(endpoint.address, endpoint.port, link_protocols) as relay:
     with relay.create_circuit() as circ:
       circ.send('RELAY_BEGIN_DIR', stream_id = 1)
-      lines = b''.join([cell.data for cell in circ.send('RELAY_DATA', resource, stream_id = 1)]).splitlines()
+      lines = b''.join([cell.data for cell in circ.send('RELAY_DATA', 'GET %s HTTP/1.0\r\n\r\n' % resource, stream_id = 1)]).splitlines()
       first_line = lines.pop(0)
 
       if first_line != 'HTTP/1.0 200 OK':
@@ -447,6 +447,9 @@ class Query(object):
   argument is overwritten with Compression.GZIP.
 
   .. versionchanged:: 1.7.0
+     Added support for downloading from ORPorts.
+
+  .. versionchanged:: 1.7.0
      Added the compression argument.
 
   .. versionchanged:: 1.7.0
diff --git a/test/integ/descriptor/remote.py b/test/integ/descriptor/remote.py
index 3123ef06..f56e1b02 100644
--- a/test/integ/descriptor/remote.py
+++ b/test/integ/descriptor/remote.py
@@ -4,6 +4,7 @@ Integration tests for stem.descriptor.remote.
 
 import unittest
 
+import stem
 import stem.descriptor
 import stem.descriptor.extrainfo_descriptor
 import stem.descriptor.networkstatus
@@ -16,6 +17,32 @@ import test.require
 class TestDescriptorDownloader(unittest.TestCase):
   @test.require.only_run_once
   @test.require.online
+  def test_downloading_via_orport(self):
+    moria1 = stem.descriptor.remote.get_authorities()['moria1']
+
+    desc = list(stem.descriptor.remote.their_server_descriptor(
+      endpoints = [stem.ORPort(moria1.address, moria1.or_port)],
+      fall_back_to_authority = False,
+    ).run())[0]
+
+    self.assertEqual('moria1', desc.nickname)
+    self.assertTrue(isinstance(desc, stem.descriptor.stem.descriptor.server_descriptor.ServerDescriptor))
+
+  @test.require.only_run_once
+  @test.require.online
+  def test_downloading_via_dirport(self):
+    moria1 = stem.descriptor.remote.get_authorities()['moria1']
+
+    desc = list(stem.descriptor.remote.their_server_descriptor(
+      endpoints = [stem.DirPort(moria1.address, moria1.dir_port)],
+      fall_back_to_authority = False,
+    ).run())[0]
+
+    self.assertEqual('moria1', desc.nickname)
+    self.assertTrue(isinstance(desc, stem.descriptor.stem.descriptor.server_descriptor.ServerDescriptor))
+
+  @test.require.only_run_once
+  @test.require.online
   def test_shorthand_aliases(self):
     """
     Quick sanity test that we can call our shorthand aliases for getting



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