DHTBitTorrent DHT 協(xié)議的 GO 實現(xiàn)
DHT 是BitTorrent DHT 協(xié)議的實現(xiàn),采用Go語言。主要包括以下部分:
展示截圖:
安裝:
go get github.com/shiyanhui/dht
使用示例:
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()
}評論
圖片
表情
