cjdelisle/cjdns — pull request #477 by Arceliar (2014-03-16 20:43:01+00:00)
Title: Don't spam searches

My attempt to fix the spammed searches (without just disabling them entirely).

The total number of searches open at any given time should now be as follows:
* Searches started during the global maintenance cycle (every 30 seconds):
* One search to attempt to plug the largest hole in keyspace.
* One search to check on a part of keyspace that we think we already know routes to.
* Searches potentially started during the local maintenance cycle (every 1 second):
* One search to attempt to plug the largest keyspace hole, a small percentage of the time (extremely rare after the node has been up for more than a few seconds).
* Select one address we're actively trying to communicate with, and do the following:
* If we fail to lookup a (valid) next hop for the address, initiate a search.
* If we succeed in our lookup, take no action for now. (Maybe do something useful later, e.g. if the next hop doesn't lead directly to the destination.)

In all cases, a new search is not started if one is already running for the same target address. The global maintenance cycle takes what is, I think, the minimum actions necessary to keep the DHT healthy under normal circumstances. The local maintenance cycle makes bootstrapping less painful (speeds up very early bootstrapping and the triggered searches help to minimize blackholes while the routing table is still sparse). The number of active searches is almost never above 2, with an average that appears to be below 1 (almost entirely from global maintenance).