X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=dht.go;h=77975a2f5d19337db3fd18e32d106a4b5fc39542;hb=b6291ed12507149913a5f9b2134cc2864a3024de;hp=da79aee472b853e153175ef2b752a68a867fc8f2;hpb=afe4d8795daa14a80d3d1ed1e72d1261f566a1b7;p=btrtrc.git diff --git a/dht.go b/dht.go index da79aee4..77975a2f 100644 --- a/dht.go +++ b/dht.go @@ -6,28 +6,37 @@ import ( "github.com/anacrolix/dht/v2" "github.com/anacrolix/dht/v2/krpc" + 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) } +// Optional interface for DhtServer's that can expose their peer store (if any). +type PeerStorer interface { + PeerStore() peer_store.Interface +} + type DhtAnnounce interface { Close() 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() } @@ -39,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{}