anacrolix / torrent

Full-featured BitTorrent client package and utilities
Mozilla Public License 2.0
5.51k stars 622 forks source link

Does repo support to build private dht bootstrap server? #912

Closed obitoquilt closed 5 months ago

obitoquilt commented 6 months ago

Thanks for your great job. I try to build private dht bootstrap server with the following code. Then i seed some file to dht bootstrap node (127.0.0.1:42080), the seeder (127.0.0.1:42069) can find node from bootstrap node successfully. But the leecher cannot get peers.

When i set download subcmd param TestPeer to 127.0.0.1:42069, it works. Does repo support to build private dht bootstrap server or i miss some configurations?

package main

import (
    "encoding/hex"
    "fmt"
    "github.com/anacrolix/torrent"
    "log"
    "net"
    "net/http"
)

func main() {
    cfg := torrent.NewDefaultClientConfig()
    cfg.Debug = true
    cfg.NoDefaultPortForwarding = true
    cfg.DisableIPv6 = true
    cfg.DataDir = "E:/p2ptest/c6"
    cfg.ListenPort = 42080
    d, _ := hex.DecodeString("2d4754303030332d5ab3f840890738ce30681f6f")
    cfg.PeerID = string(d)
    cfg.PublicIp4 = net.ParseIP("1xx.1x.1xx.2xx")

    cl, err := torrent.NewClient(cfg)
    if err != nil {
        log.Fatal(err)
    }
    defer cl.Close()
    fmt.Printf("************** %x **************\n", cl.PeerID())
    defer cl.Close()
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        cl.WriteStatus(w)
    })
    go http.ListenAndServe(":8080", nil)

    select {}
}
anacrolix commented 6 months ago

I don't quite follow what you are trying to achieve. You can bootstrap into your own DHT by setting StartingNodes in https://pkg.go.dev/github.com/anacrolix/dht/v2#ServerConfig.