nskinkel / oppy

A Tor client (onion proxy) implementation in Python
BSD 3-Clause "New" or "Revised" License
24 stars 3 forks source link

Download router descriptors at correct intervals #111

Closed nskinkel closed 9 years ago

nskinkel commented 9 years ago

Right now, oppy just downloads all server descriptors at once from a single directory authority/cache once an hour immediately after downloading a new consensus. According to Tor's "dir-spec.txt":

Clients try to have the best descriptor for each router.  A descriptor is
"best" if:
   * It is listed in the consensus network-status document.

Periodically (currently every 10 seconds) clients check whether there are
any "downloadable" descriptors.  A descriptor is downloadable if:
   - It is the "best" descriptor for some router.
   - The descriptor was published at least 10 minutes in the past.
     (This prevents clients from trying to fetch descriptors that the
     mirrors have probably not yet retrieved and cached.)
   - The client does not currently have it.
   - The client is not currently trying to download it.
   - The client would not discard it immediately upon receiving it.
   - The client thinks it is running and valid (see section 5.4.1 below).

If at least 16 known routers have downloadable descriptors, or if
enough time (currently 10 minutes) has passed since the last time the
client tried to download descriptors, it launches requests for all
downloadable descriptors.

When downloading multiple server descriptors, the client chooses multiple
mirrors so that:
  - At least 3 different mirrors are used, except when this would result
    in more than one request for under 4 descriptors.
  - No more than 128 descriptors are requested from a single mirror.
  - Otherwise, as few mirrors as possible are used.
After choosing mirrors, the client divides the descriptors among them
randomly.

After receiving any response client MUST discard any descriptors that it
did not request.

When a descriptor download fails, the client notes it, and does not
consider the descriptor downloadable again until a certain amount of time
has passed. (Currently 0 seconds for the first failure, 60 seconds for the
second, 5 minutes for the third, 10 minutes for the fourth, and 1 day
thereafter.)  Periodically (currently once an hour) clients reset the
failure count.

Clients retain the most recent descriptor they have downloaded for each
router so long as it is not too old (currently, 48 hours), OR so long as
no better descriptor has been downloaded for the same router.
nskinkel commented 9 years ago

Implemented in 3bda6b5fb6