onClose []func()
dialers []Dialer
listeners []Listener
- dhtServers []*dht.Server
+ dhtServers []DhtServer
ipBlockList iplist.Ranger
// Our BitTorrent protocol extension bytes, sent in our BT handshakes.
extensionBytes pp.PeerExtensionBits
return
}
-func writeDhtServerStatus(w io.Writer, s *dht.Server) {
+func writeDhtServerStatus(w io.Writer, s DhtServer) {
dhtStats := s.Stats()
- fmt.Fprintf(w, "\t# Nodes: %d (%d good, %d banned)\n", dhtStats.Nodes, dhtStats.GoodNodes, dhtStats.BadNodes)
fmt.Fprintf(w, "\tServer ID: %x\n", s.ID())
- fmt.Fprintf(w, "\tAnnounces: %d\n", dhtStats.SuccessfulOutboundAnnouncePeerQueries)
- fmt.Fprintf(w, "\tOutstanding transactions: %d\n", dhtStats.OutstandingTransactions)
+ spew.Fdump(w, dhtStats)
}
// Writes out a human readable status of the client, such as for writing to a
fmt.Fprintf(w, "Peer ID: %+q\n", cl.PeerID())
fmt.Fprintf(w, "Announce key: %x\n", cl.announceKey())
fmt.Fprintf(w, "Banned IPs: %d\n", len(cl.badPeerIPsLocked()))
- cl.eachDhtServer(func(s *dht.Server) {
+ cl.eachDhtServer(func(s DhtServer) {
fmt.Fprintf(w, "%s DHT server at %s:\n", s.Addr().Network(), s.Addr().String())
writeDhtServerStatus(w, s)
})
if !cfg.NoDHT {
for _, s := range sockets {
if pc, ok := s.(net.PacketConn); ok {
- ds, err := cl.newDhtServer(pc)
+ ds, err := cl.newAnacrolixDhtServer(pc)
if err != nil {
panic(err)
}
- cl.dhtServers = append(cl.dhtServers, ds)
+ cl.dhtServers = append(cl.dhtServers, anacrolixDhtServerWrapper{ds})
cl.onClose = append(cl.onClose, func() { ds.Close() })
}
}
return
}
+func (cl *Client) AddDhtServer(d DhtServer) {
+ cl.dhtServers = append(cl.dhtServers, d)
+}
+
// Adds a Dialer for outgoing connections. All Dialers are used when attempting to connect to a
// given address for any Torrent.
func (cl *Client) AddDialer(d Dialer) {
return
}
-func (cl *Client) newDhtServer(conn net.PacketConn) (s *dht.Server, err error) {
+func (cl *Client) newAnacrolixDhtServer(conn net.PacketConn) (s *dht.Server, err error) {
cfg := dht.ServerConfig{
IPBlocklist: cl.ipBlockList,
Conn: conn,
return cl.closed.C()
}
-func (cl *Client) eachDhtServer(f func(*dht.Server)) {
+func (cl *Client) eachDhtServer(f func(DhtServer)) {
for _, ds := range cl.dhtServers {
f(ds)
}
}
func (cl *Client) dhtPort() (ret uint16) {
- cl.eachDhtServer(func(s *dht.Server) {
+ cl.eachDhtServer(func(s DhtServer) {
ret = uint16(missinggo.AddrPort(s.Addr()))
})
return
}
func (cl *Client) haveDhtServer() (ret bool) {
- cl.eachDhtServer(func(_ *dht.Server) {
+ cl.eachDhtServer(func(_ DhtServer) {
ret = true
})
return
new = true
t = cl.newTorrent(infoHash, specStorage)
- cl.eachDhtServer(func(s *dht.Server) {
+ cl.eachDhtServer(func(s DhtServer) {
go t.dhtAnnouncer(s)
})
cl.torrents[infoHash] = t
return cl.AddTorrent(mi)
}
-func (cl *Client) DhtServers() []*dht.Server {
+func (cl *Client) DhtServers() []DhtServer {
return cl.dhtServers
}
Port: hmp.Port,
},
}
- cl.eachDhtServer(func(s *dht.Server) {
+ cl.eachDhtServer(func(s DhtServer) {
s.AddNode(ni)
})
}