Darknet Routing

Darknets are a very useful and common aspect of peer-to-peer networks, which tend to arise when the overlay position is determined by what nodes are directly connected to a node, rather than what 'coordinate' (e.g. DHT ID) has been assigned to the node. As a result, many overlay networks can be mapped to a darknet structure, and this algorithm can be used to find short paths between any two nodes in the darknet (which clearly don't have to be neighbours), which is generally the hardest problem of darknets.

Aims

 * Find short paths (or even optimally shortest if possible)
 * Only allow communication with immediate neighbours
 * Find paths quickly
 * Minimum network overhead

Expected Network Behaviour
The effectiveness of a darknet routing generally relies on some expectations about the underlying network: in this case it is expected that structural changes will occur slowly. For networks with rapidly changing structures use a different algorithm, however such algorithms usually can't route as efficiently and generally produce more network overhead. The algorithm should function effectively where nodes regularly enter and leave the network.

Addressing
Each node has an address, the least significant part being its own ID and the other parts represent groups of which it is a member. The address can be variable length, or it can be (and usually is expected to be) fixed length. From the node ID, as the parts of the address are more significant, they denote a group allowing a certain distance from the creator of that group. For example, the next most significant part of the address after the node ID is the ID of a group of which the node must either be the creator or one step away from the creator. The next most significant allows it to be 2 steps away, and so on.

When a node starts, it considers itself to have no neighbours, and therefore generates its own address. It also notes that it is 0 steps from the creator of each of the groups in the address, since it is the creator. When it adds a neighbour, it receives and remembers the address of that node.

At random intervals, it looks at the addresses of all of its neighbours, and starts working out what its own address should be, for each part of the address:


 * 1) It ignores those groups of its neighbours which it can't be a part of because its step count would be too high (it must be one more than the least of its neighbours in that group).
 * 2) It adds up how much of its neighbours are members of each group it can join.
 * 3) If there are no available groups to join, it creates its own, otherwise it joins the group with the greatest number of neighbours in it (using some appropriate mechanism to break ties) and sets it step count to one greater than the least of its neighbours.

If nodes haven't received messages from a neighbour, it checks that the neighbour is still available. If it determines the neighbour is unavailable, it must identify any groups it shares with that neighbour. For any groups it does share, it should apply the previous procedure for that part of the address. Whenever nodes change their address, they should immediately inform their neighbours. Note that this means that if the creator of a group becomes unavailable, members of the group rapidly increase their step count until they are forced to join another group or create their own. As a result, the system tends to stabilize with creators as long-lived nodes, which also tend to live longer in the future.

Routing
In order to identify where to route messages, nodes use a gossip protocol to disseminate routing information.