[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Implementing get_extrainfo_descriptors() method
commit a014b9b967e8b825a9a4c99514ce2098ab6ba614
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Wed Jul 17 09:58:35 2013 -0700
Implementing get_extrainfo_descriptors() method
Very similar to the get_server_descriptors() counterpart.
---
stem/descriptor/remote.py | 33 +++++++++++++++++++++++++++++++--
test/integ/descriptor/remote.py | 28 ++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py
index 3021f63..a18d991 100644
--- a/stem/descriptor/remote.py
+++ b/stem/descriptor/remote.py
@@ -272,7 +272,8 @@ class DescriptorDownloader(object):
:returns: :class:`~stem.descriptor.remote.Query` for the server descriptors
- :raises: **ValueError** if we request descriptors by fingerprints and there are more than 96 of them (this is a limitation of tor).
+ :raises: **ValueError** if we request more than 96 descriptors by their
+ fingerprints (this is due to a limit on the url length by squid proxies).
"""
resource = '/tor/server/all'
@@ -282,12 +283,40 @@ class DescriptorDownloader(object):
resource = '/tor/server/fp/%s' % fingerprints
else:
if len(fingerprints) > MAX_BATCH_SIZE:
- raise ValueError('We can request at most %i descritors at a time when retrieving by fingerprints' % MAX_BATCH_SIZE)
+ raise ValueError("Unable to request more than %i descriptors at a time by their fingerprints" % MAX_BATCH_SIZE)
resource = '/tor/server/fp/%s' % '+'.join(fingerprints)
return self._query(resource, 'server-descriptor 1.0')
+ def get_extrainfo_descriptors(self, fingerprints = None):
+ """
+ Provides the extrainfo descriptors with the given fingerprints. If no
+ fingerprints are provided then this returns all descriptors in the present
+ consensus.
+
+ :param str,list fingerprints: fingerprint or list of fingerprints to be
+ retrieved, gets all descriptors if **None**
+
+ :returns: :class:`~stem.descriptor.remote.Query` for the extrainfo descriptors
+
+ :raises: **ValueError** if we request more than 96 descriptors by their
+ fingerprints (this is due to a limit on the url length by squid proxies).
+ """
+
+ resource = '/tor/extra/all'
+
+ if fingerprints:
+ if isinstance(fingerprints, str):
+ resource = '/tor/extra/fp/%s' % fingerprints
+ else:
+ if len(fingerprints) > MAX_BATCH_SIZE:
+ raise ValueError("Unable to request more than %i descriptors at a time by their fingerprints" % MAX_BATCH_SIZE)
+
+ resource = '/tor/extra/fp/%s' % '+'.join(fingerprints)
+
+ return self._query(resource, 'extra-info 1.0')
+
def _query(self, resource, descriptor_type):
"""
Issues a request for the given resource.
diff --git a/test/integ/descriptor/remote.py b/test/integ/descriptor/remote.py
index 6e1f426..62348ab 100644
--- a/test/integ/descriptor/remote.py
+++ b/test/integ/descriptor/remote.py
@@ -4,6 +4,8 @@ Integration tests for stem.descriptor.remote.
import unittest
+import stem.descriptor.server_descriptor
+import stem.descriptor.extrainfo_descriptor
import stem.descriptor.remote
import test.runner
@@ -71,6 +73,32 @@ class TestDescriptorReader(unittest.TestCase):
single_query_results = list(single_query)
self.assertEqual(1, len(single_query_results))
self.assertEqual('moria1', single_query_results[0].nickname)
+ self.assertTrue(isinstance(single_query_results[0], stem.descriptor.stem.descriptor.server_descriptor.ServerDescriptor))
self.assertEqual(2, len(list(multiple_query)))
+ def test_get_extrainfo_descriptors(self):
+ """
+ Exercises the downloader's get_extrainfo_descriptors() method.
+ """
+
+ downloader = stem.descriptor.remote.DescriptorDownloader()
+
+ single_query = downloader.get_extrainfo_descriptors('9695DFC35FFEB861329B9F1AB04C46397020CE31')
+
+ multiple_query = downloader.get_extrainfo_descriptors([
+ '9695DFC35FFEB861329B9F1AB04C46397020CE31',
+ '847B1F850344D7876491A54892F904934E4EB85D',
+ ])
+
+ single_query.run()
+ multiple_query.run()
+
+ single_query_results = list(single_query)
+ self.assertEqual(1, len(single_query_results))
+ self.assertEqual('moria1', single_query_results[0].nickname)
+ self.assertTrue(isinstance(single_query_results[0], stem.descriptor.extrainfo_descriptor.ExtraInfoDescriptor))
+
+ self.assertEqual(2, len(list(multiple_query)))
+
+
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits