// ServerConfig allows to set up a configuration of the `Server` instance
// to be created with NewServer
type ServerConfig struct {
- Addr string // Listen address. Used if Conn is nil.
+ // Listen address. Used if Conn is nil.
+ Addr string
Conn net.PacketConn
// Don't respond to queries from other nodes.
Passive bool
// DHT Bootstrap nodes
BootstrapNodes []string
+ // Disable bootstrapping from global servers even if given no BootstrapNodes.
+ // This creates a solitary node that awaits other nodes; it's only useful if
+ // you're creating your own DHT and want to avoid accidental crossover, without
+ // spoofing a bootstrap node and filling your logs with connection errors.
+ NoDefaultBootstrap bool
+
// Disable the DHT security extension:
// http://www.libtorrent.org/dht_sec.html.
NoSecurity bool
}
return true
}
+
func jitterDuration(average time.Duration, plusMinus time.Duration) time.Duration {
return average - plusMinus/2 + time.Duration(rand.Int63n(int64(plusMinus)))
}
}
func TestPing(t *testing.T) {
- srv, err := NewServer(nil)
- if err != nil {
- t.Fatal(err)
- }
+ srv, err := NewServer(&ServerConfig{
+ Addr: "127.0.0.1:5680",
+ NoDefaultBootstrap: true,
+ })
+ require.NoError(t, err)
defer srv.Close()
- srv0, err := NewServer(nil)
- if err != nil {
- t.Fatal(err)
- }
+ srv0, err := NewServer(&ServerConfig{
+ Addr: "127.0.0.1:5681",
+ BootstrapNodes: []string{"127.0.0.1:5680"},
+ })
+ require.NoError(t, err)
defer srv0.Close()
tn, err := srv.Ping(&net.UDPAddr{
IP: []byte{127, 0, 0, 1},
Port: srv0.Addr().(*net.UDPAddr).Port,
})
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
defer tn.Close()
ok := make(chan bool)
tn.SetResponseHandler(func(msg Msg, msgOk bool) {
} {
ip := net.ParseIP(case_.ipStr)
id, err := hex.DecodeString(case_.nodeIDHex)
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
secure := NodeIdSecure(string(id), ip)
if secure != case_.valid {
t.Fatalf("case failed: %v", case_)