mirror of
https://github.com/yann-shi/dht.git
synced 2026-10-17 04:30:53 +08:00
ba80173b6a4e4a2d03459f264907403eb698d789
DHT
DHT implements the bittorrent DHT protocol in Go. Now it includes:
It contains two modes, the standard mode and the crawling mode. The standard mode follows the BEPs, and you can use it as a standard dht server. The crawling mode aims to spide as more medata info as possiple. It doesn't follow the standard BEPs protocol. With the crawling mode, you can build another Pirate Bay.
bthub.io is a BT search engine based on the crawling mode.
Install
go get github.com/shiyanhui/dht
Example
Below is a simple spider. You can move here to see more samples. And you can also download the binary file to run on your machine.
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()
}
License
MIT.
Languages
Go
100%
