]> Sergey Matveev's repositories - btrtrc.git/blob - dht.go
Merge branch 'fuse-email-issue'
[btrtrc.git] / dht.go
1 package torrent
2
3 import (
4         "io"
5         "net"
6
7         "github.com/anacrolix/dht/v2"
8         "github.com/anacrolix/dht/v2/krpc"
9         peer_store "github.com/anacrolix/dht/v2/peer-store"
10 )
11
12 type DhtServer interface {
13         Stats() interface{}
14         ID() [20]byte
15         Addr() net.Addr
16         AddNode(ni krpc.NodeInfo) error
17         Ping(addr *net.UDPAddr)
18         Announce(hash [20]byte, port int, impliedPort bool) (DhtAnnounce, error)
19         WriteStatus(io.Writer)
20 }
21
22 // Optional interface for DhtServer's that can expose their peer store (if any).
23 type PeerStorer interface {
24         PeerStore() peer_store.Interface
25 }
26
27 type DhtAnnounce interface {
28         Close()
29         Peers() <-chan dht.PeersValues
30 }
31
32 type anacrolixDhtServerWrapper struct {
33         *dht.Server
34 }
35
36 func (me anacrolixDhtServerWrapper) Stats() interface{} {
37         return me.Server.Stats()
38 }
39
40 type anacrolixDhtAnnounceWrapper struct {
41         *dht.Announce
42 }
43
44 func (me anacrolixDhtAnnounceWrapper) Peers() <-chan dht.PeersValues {
45         return me.Announce.Peers
46 }
47
48 func (me anacrolixDhtServerWrapper) Announce(hash [20]byte, port int, impliedPort bool) (DhtAnnounce, error) {
49         ann, err := me.Server.Announce(hash, port, impliedPort)
50         return anacrolixDhtAnnounceWrapper{ann}, err
51 }
52
53 func (me anacrolixDhtServerWrapper) Ping(addr *net.UDPAddr) {
54         me.Server.Ping(addr, nil)
55 }
56
57 var _ DhtServer = anacrolixDhtServerWrapper{}