[tor-commits] [stem/master] Rejecting requests for more than 96 descriptors

atagar at torproject.org atagar at torproject.org
Mon Jul 22 03:10:17 UTC 2013


commit 871a957f23097807f67e502fd6e2c9a9b9a6c456
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Jul 16 09:28:18 2013 -0700

    Rejecting requests for more than 96 descriptors
    
    In our tor-dev@ discussion Karsten mentioned that we could request at most 96
    descriptors at a time when polling by their fingerprints...
    
    https://lists.torproject.org/pipermail/tor-dev/2013-June/005005.html
    
    I've emailed him to clarify where this limitation comes from (the url length or
    something within tor?), but in the meantime adding a check for this to our
    get_sever_descriptors() method.
---
 stem/descriptor/remote.py |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py
index a4b21d4..3021f63 100644
--- a/stem/descriptor/remote.py
+++ b/stem/descriptor/remote.py
@@ -50,6 +50,11 @@ import stem.descriptor
 
 from stem.util import log
 
+# Tor has a limit on the number of descriptors we can fetch explicitly by their
+# fingerprint.
+
+MAX_BATCH_SIZE = 96
+
 # Tor directory authorities as of commit f631b73 (7/4/13). This should only
 # include authorities with 'v3ident':
 #
@@ -266,6 +271,8 @@ class DescriptorDownloader(object):
       retrieved, gets all descriptors if **None**
 
     :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).
     """
 
     resource = '/tor/server/all'
@@ -274,6 +281,9 @@ class DescriptorDownloader(object):
       if isinstance(fingerprints, str):
         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)
+
         resource = '/tor/server/fp/%s' % '+'.join(fingerprints)
 
     return self._query(resource, 'server-descriptor 1.0')





More information about the tor-commits mailing list