I will make description and implementation about Mainline DHT.
Let's coding RootingTable
- Implements KId
- Implements kBucket
- Implements RootingTable
express InfoHash and PeerID as KID.We must tot calc xor distance of InfoHash and InfoHash, Peer ID and InfoHash, Peer ID and Peer. Those ID can define 20 byte array. It's call KID in sentense.
- It isn't necessary to change KID into the numerical value.KID is 160bit valiue. but, dartlang support 53bit only. SO I have usually implemented biginteger. but It isn't necessary to change KID into the numerical value to use in kbucket rooting table.
First. First definition, KID has 20 byte array
- add func that calc xor
- add func that big small comparisonWe must to add big and small comparison function to sort KID in rooting table.
We has become possible to find close peer in KID list by sorting function.
Implements kBucketkBucket is container that can contain K-number of peer info. We can implements as list with limit on when you want to add value.
Implements RootingTableRooting table has 161- number of kBucket.
Implements calc rooting table index.I explain kid into the numerical value to calc rooting table index in previous section.
|2, 3||010, 011||2|
|4, 5, 6, 7||100, 101, 110, 111||3|
And went to check one by 1bit from left to right, by the first place was a 1, you will see that kBucket position is determined.
Add peer info in kBucket.
Now, the creation of RootingTable is complete. I will explain findNode in next section. and append fincNode function in RootingTable class.
- GitBook Nazenani Torrent for japanesehttps://www.gitbook.com/book/kyorohiro/doc_hetimatorrent/details
- kyorohiro work torrent library and dht demohttps://github.com/kyorohiro/dart_hetimatorrent