DHT: add bootstrapping, fix bugs, cleanup code

Review Request #130083 - Created April 11, 2017 and discarded

Fonic Maxxim
aacid, trufanov

Comprehensive revision of DHT codebase:

  • Implemented bootstrapping from well-known nodes (like most other torrent clients do) so that DHT is usable right away (i.e. when enabling it for the first time)
  • Transferred lots of important hard-coded values to constants in header files. This is a first step, in a second step those values should be made configurable from within KTorrent
  • Added comments for important constants, describing them and comparing their values to the specification and/or the DHT reference implementation
  • Updated several important values (timeouts, minimum/maximum limits) according to the values proposed by the current DHT reference implementation
  • Small bugfixes (e.g. Node::loadTable in src/dht/node.cpp, DHT::addDHTNode in src/dht/dht.cpp)
  • Performed general code cleanup (comments, newlines, whitespace, structuring etc.)

For further details, refer to '@author Fonic' comments within code.

The following files contain changes other than cleanup:

Notes on DHT bootstrapping:

  • To test DHT bootstrapping, (re)move any existing KTorrent user configuration, start KTorrent and enable DHT in settings. Then, watch the DHT entry in the status bar and/or the debug output in the log/console. Bootstrapping should only take a couple of seconds. After that, the number of known nodes should be in the range of 50 - 100. Here's a screenshot showing what should happen.
  • I chose to implement a simple/basic bootstrapping mechanism: add well-known bootstrap nodes, wait a specific amount of time (timer), compare DHT routing table entries to specific minimum amount to check if bootstrapping was successful, retry if bootstrapping failed. The DHT reference implementation uses a more sophisticated approach, evaluating the depth of the resulting DHT routing table to check if bootstrapping was successful. Currently, I'm not sure if the sophisticated approach is really necessary - I'll investigate this further.
  • Currently, the well-known DHT nodes used for bootstrapping are hard-coded (as it is with most other torrent clients). I think it might be best to create a new plugin for DHT bootstrapping that allows to specifiy a list of well-known DHT nodes and also allows to control when to bootstrap (i.e. only if routing table is empty, always on startup, ...)

Sorry that this is an all-in-one request with only one commit. This is due to the fact that I already did this in Dec. 2016 on GitHub before noticing that it's only used as an unmanaged mirror, so I had to port my changes from there, losing commit history.


Fonic Maxxim
Fonic Maxxim
Fonic Maxxim
Alexander Trufanov
Fonic Maxxim
Review request changed

Status: Discarded

Change Summary:

Will split this into separate pieces and post them in separate reviews to simplify review (as suggested by Alexander Trufanov)