DHT 是BitTorrent DHT 协议的实现,采用Go语言。主要包括以下部分:
*
[BEP-3 (part)](http://www.bittorrent.org/beps/bep_0003.html)
*
[BEP-5](http://www.bittorrent.org/beps/bep_0005.html)
*
[BEP-9](http://www.bittorrent.org/beps/bep_0009.html)
*
[BEP-10](http://www.bittorrent.org/beps/bep_0010.html)
展示截图:
![image](http://static.oschina.net/uploads/space/2016/0809/113559_o4jK_1774694.png)
安装:
<pre class="brush:shell;toolbar: true; auto-links: false;">go get github.com/shiyanhui/dht</pre>
使用示例:
<pre class="brush:cpp ;toolbar: true; auto-links: false;">import (
"fmt"
"github.com/shiyanhui/dht"
)
func main() {
downloader := dht.NewWire()
go func() {
// once we got the request result
for resp := range downloader.Response() {
fmt.Println(resp.InfoHash, resp.MetadataInfo)
}
}()
go downloader.Run()
config := dht.NewCrawlConfig()
config.OnAnnouncePeer = func(infoHash, ip string, port int) {
// request to download the metadata info
downloader.Request([]byte(infoHash), ip, port)
}
d := dht.New(config)
d.Run()
}</pre>