2020-02-20 06:46:29 +00:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/anacrolix/dht/v2"
|
|
|
|
"github.com/anacrolix/dht/v2/krpc"
|
2021-02-21 06:17:57 +00:00
|
|
|
peer_store "github.com/anacrolix/dht/v2/peer-store"
|
2020-02-20 06:46:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type DhtServer interface {
|
|
|
|
Stats() interface{}
|
|
|
|
ID() [20]byte
|
|
|
|
Addr() net.Addr
|
|
|
|
AddNode(ni krpc.NodeInfo) error
|
|
|
|
Ping(addr *net.UDPAddr)
|
|
|
|
Announce(hash [20]byte, port int, impliedPort bool) (DhtAnnounce, error)
|
|
|
|
WriteStatus(io.Writer)
|
|
|
|
}
|
|
|
|
|
2021-02-21 06:17:57 +00:00
|
|
|
// Optional interface for DhtServer's that can expose their peer store (if any).
|
|
|
|
type PeerStorer interface {
|
|
|
|
PeerStore() peer_store.Interface
|
|
|
|
}
|
|
|
|
|
2020-02-20 06:46:29 +00:00
|
|
|
type DhtAnnounce interface {
|
|
|
|
Close()
|
|
|
|
Peers() <-chan dht.PeersValues
|
|
|
|
}
|
|
|
|
|
2021-05-24 07:37:04 +00:00
|
|
|
type AnacrolixDhtServerWrapper struct {
|
2020-02-20 06:46:29 +00:00
|
|
|
*dht.Server
|
|
|
|
}
|
|
|
|
|
2021-05-24 07:37:04 +00:00
|
|
|
func (me AnacrolixDhtServerWrapper) Stats() interface{} {
|
2020-02-20 06:46:29 +00:00
|
|
|
return me.Server.Stats()
|
|
|
|
}
|
|
|
|
|
|
|
|
type anacrolixDhtAnnounceWrapper struct {
|
|
|
|
*dht.Announce
|
|
|
|
}
|
|
|
|
|
|
|
|
func (me anacrolixDhtAnnounceWrapper) Peers() <-chan dht.PeersValues {
|
|
|
|
return me.Announce.Peers
|
|
|
|
}
|
|
|
|
|
2021-05-24 07:37:04 +00:00
|
|
|
func (me AnacrolixDhtServerWrapper) Announce(hash [20]byte, port int, impliedPort bool) (DhtAnnounce, error) {
|
2020-02-20 06:46:29 +00:00
|
|
|
ann, err := me.Server.Announce(hash, port, impliedPort)
|
|
|
|
return anacrolixDhtAnnounceWrapper{ann}, err
|
|
|
|
}
|
|
|
|
|
2021-05-24 07:37:04 +00:00
|
|
|
func (me AnacrolixDhtServerWrapper) Ping(addr *net.UDPAddr) {
|
2021-03-11 00:32:31 +00:00
|
|
|
me.Server.Ping(addr)
|
2020-02-20 06:46:29 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 07:37:04 +00:00
|
|
|
var _ DhtServer = AnacrolixDhtServerWrapper{}
|