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

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



commit 871a957f23097807f67e502fd6e2c9a9b9a6c456
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
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')



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