cjdelisle/cjdns — pull request #504 by Arceliar (2014-04-15 18:45:38+00:00)
Title: Patch from Testing (1/2): nospam

First of the two patch sets I've had running in my testing branch.

Does the following:
1. Cleans up what was left of the search spam code.
2. DHT fixes
1. Fixes a bug in some bit twiddling that was causing Janitor.c's plugLargestKeyspaceHole to do the wrong thing.
2. Changes the interface of plugLargestKeyspaceHole. It now accepts a boolean flag as its second argument. If true, it will always send a search (provided none is currently active). If false, it will only send a search if the target is different from the last time it tried to plug a hole. This allows it to run in the local maint cycle for faster bootstrapping, without constantly spamming searching.
3. RumorMill changes
1. Before adding a direct peer to the RumorMill, check that we don't have an active CA session. This is needed to prevent a bug I've been seeing, where one of my peers gets stuck in a bad state and pushes all other nodes out of the RumorMill.
2. This one is subtle. The RumorMill adds nodes in order until it fills. It then replaces the worst node with a new one every time a RumorMill_addNode() is called. In practice, the RumorMill is always full, except immediately after the Janitor pops the last node from the mill and sends a getPeers. This means that the first nodes are almost always good (if they were bad, they'd get replaced), and the last node is of basically random quality (as it is the only place where there's ever a vacancy, so it tends to start off as the 'worst' node and keep getting replaced by new worst nodes). The result is that the Janitor keeps sending pings to terrible nodes. So now, instead of selecting the last node on the list, it always selects the best one (based on the same getBadness criteria as worst node selection). The Janitor also tries to NodeStore_optimizePath() before adding anything to the mill.

The net effect of this (mostly 3, a little bit of 2) is reduced path length for the nodes on my routing table (particularly in the worse case scenario). YMMV.