7 "github.com/anacrolix/dht/v2"
8 "github.com/anacrolix/dht/v2/krpc"
9 peer_store "github.com/anacrolix/dht/v2/peer-store"
12 // DHT server interface for use by a Torrent or Client. It's reasonable for this to make assumptions
13 // for torrent-use that might not be the default behaviour for the DHT server.
14 type DhtServer interface {
18 AddNode(ni krpc.NodeInfo) error
19 // This is called asynchronously when receiving PORT messages.
20 Ping(addr *net.UDPAddr)
21 Announce(hash [20]byte, port int, impliedPort bool) (DhtAnnounce, error)
22 WriteStatus(io.Writer)
25 // Optional interface for DhtServer's that can expose their peer store (if any).
26 type PeerStorer interface {
27 PeerStore() peer_store.Interface
30 type DhtAnnounce interface {
32 Peers() <-chan dht.PeersValues
35 type AnacrolixDhtServerWrapper struct {
39 func (me AnacrolixDhtServerWrapper) Stats() interface{} {
40 return me.Server.Stats()
43 type anacrolixDhtAnnounceWrapper struct {
47 func (me anacrolixDhtAnnounceWrapper) Peers() <-chan dht.PeersValues {
48 return me.Announce.Peers
51 func (me AnacrolixDhtServerWrapper) Announce(hash [20]byte, port int, impliedPort bool) (DhtAnnounce, error) {
52 ann, err := me.Server.Announce(hash, port, impliedPort)
53 return anacrolixDhtAnnounceWrapper{ann}, err
56 func (me AnacrolixDhtServerWrapper) Ping(addr *net.UDPAddr) {
57 me.Server.PingQueryInput(addr, dht.QueryInput{
58 RateLimiting: dht.QueryRateLimiting{NoWaitFirst: true},
62 var _ DhtServer = AnacrolixDhtServerWrapper{}