Friday, August 14, 2015

Let's coding mainline dht.(6) End

Can find value to use get_peers message


  • use get_peers message to find value
  • use announce_peer message  to save value in p2p network


We could create p2p network in previous section. I explain to save value in p2p network.

get_peers message and find_node are almost similar.


MainLine DHT use get_peers message to set value in p2p network. get_peers message have two role.

  • when receive get_peers query, if knode have request value, knode  send response message about value.
  • if knode dont have value, knode send reposese message about close peer from kid.

Knode repose to send get_peers message, then, knode can find close peer, and value.

Those system and find_nodes is almost simillar.

  •  introduce close peer form KID
  •  repeate to send meesage 




save data to use announce_peer message

When Knode find k-number of close knode to repeat sending get_peers message. Knode send announce_peer message to save value.

Knode send announce_peer message into k-number node.
A robustness rises by requesting value into multiple node.


  • It is easy to find valie
  • It is safe to disconnect node
  • It's possible to disperse a load.


message struct


```
arguments:
{
  "t":"aa",
  "y":"q",
  "q":"get_peers",
  "a": {
    "id" : "<querying nodes id>",
    "info_hash" : "<20-byte infohash of target torrent>"
  }
}

response: have value
{
  "id" : "<queried nodes id>",
  "token" :"<opaque write token>",
  "values" :
  ["<peer 1 info string>", "<peer 2 info string>"]
}

response: have node info
{
 "t":"aa",
 "y":"r",
 "r": {
  "id" : "<queried nodes id>",
  "token" :"<opaque write token>",
  "nodes" : "<compact node info>"
  }
}
```

"token" and "values" is  appeared for the first time int this blog.
"token" is byte date that responser define this byte data and byte data length. This value ise used to send announce_peers query.
"value" is list that contain 6bytes data[<IP 4bute> ,<Port 2byte>]. this values is peer ip and port that's peer can share file to use torrent client bep003.

ref http://www.bittorrent.org/beps/bep_0005.html


About Implements 


get_peers implements is almost similar as find_node. We can code get_peers to use find_node implements 's know-how.



Test DHT


  •  test dht

You'll make them move actually. I explain mainline dht sample to use hetimatorrent library.

find value from special kid  int p2p network.


```

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
main() {
  KNode node = new KNode(new HetiSocketBuilderChrome(), verbose: true);

  //
  node.start(ip: "0.0.0.0", port: 28080).then((_) {
    node.onGetPeerValue.listen((KGetPeerValue v) {
      print("---onGetPeerValue ${v.ipAsString} ${v.port} ${v.infoHashAsString} ");
    });
  });

  // initial node
  String initailNodeIp = "0.0.0.0";
  int initailNodePort = 38080;
  node.addBootNode(initailNodeIp, initailNodePort);
  
  // search target
  List<int> infoHash = new List.filled(20, 4);
  node.startSearchValue(new KId(infoHash), 18080, getPeerOnly: true);
  
  new Future.delayed(new Duration(minutes:30)).then((_){
    print(node.rootingtable.toInfo());
    return node.stop();
  });

}
```


Sample app with gui.

https://github.com/kyorohiro/dart_hetimatorrent/tree/master/example/TorrentDHT




Ref


http://www.bittorrent.org/beps/bep_0005.html
http://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf


PS

GitBook nazenani Torrent for japanese
- https://www.gitbook.com/book/kyorohiro/doc_hetimatorrent/details
hetima torrent library
- https://github.com/kyorohiro/dart_hetimatorrent
- https://github.com/kyorohiro/dart_hetimatorrent/tree/master/example/TorrentDHT


-------
Kyorohiro work

http://kyorohiro.strikingly.com

No comments:

Post a Comment