]> Sergey Matveev's repositories - btrtrc.git/blobdiff - dht.go
Drop support for go 1.20
[btrtrc.git] / dht.go
diff --git a/dht.go b/dht.go
index b69c28845196458ec22d2aadc372f4ee5e7467da..77975a2f5d19337db3fd18e32d106a4b5fc39542 100644 (file)
--- a/dht.go
+++ b/dht.go
@@ -9,11 +9,14 @@ import (
        peer_store "github.com/anacrolix/dht/v2/peer-store"
 )
 
+// DHT server interface for use by a Torrent or Client. It's reasonable for this to make assumptions
+// for torrent-use that might not be the default behaviour for the DHT server.
 type DhtServer interface {
        Stats() interface{}
        ID() [20]byte
        Addr() net.Addr
        AddNode(ni krpc.NodeInfo) error
+       // This is called asynchronously when receiving PORT messages.
        Ping(addr *net.UDPAddr)
        Announce(hash [20]byte, port int, impliedPort bool) (DhtAnnounce, error)
        WriteStatus(io.Writer)
@@ -29,11 +32,11 @@ type DhtAnnounce interface {
        Peers() <-chan dht.PeersValues
 }
 
-type anacrolixDhtServerWrapper struct {
+type AnacrolixDhtServerWrapper struct {
        *dht.Server
 }
 
-func (me anacrolixDhtServerWrapper) Stats() interface{} {
+func (me AnacrolixDhtServerWrapper) Stats() interface{} {
        return me.Server.Stats()
 }
 
@@ -45,13 +48,15 @@ func (me anacrolixDhtAnnounceWrapper) Peers() <-chan dht.PeersValues {
        return me.Announce.Peers
 }
 
-func (me anacrolixDhtServerWrapper) Announce(hash [20]byte, port int, impliedPort bool) (DhtAnnounce, error) {
+func (me AnacrolixDhtServerWrapper) Announce(hash [20]byte, port int, impliedPort bool) (DhtAnnounce, error) {
        ann, err := me.Server.Announce(hash, port, impliedPort)
        return anacrolixDhtAnnounceWrapper{ann}, err
 }
 
-func (me anacrolixDhtServerWrapper) Ping(addr *net.UDPAddr) {
-       me.Server.Ping(addr, nil)
+func (me AnacrolixDhtServerWrapper) Ping(addr *net.UDPAddr) {
+       me.Server.PingQueryInput(addr, dht.QueryInput{
+               RateLimiting: dht.QueryRateLimiting{NoWaitFirst: true},
+       })
 }
 
-var _ DhtServer = anacrolixDhtServerWrapper{}
+var _ DhtServer = AnacrolixDhtServerWrapper{}