if dhtCfg.Conn == nil && cl.utpSock != nil {
dhtCfg.Conn = cl.utpSock
}
+ if dhtCfg.OnAnnouncePeer == nil {
+ dhtCfg.OnAnnouncePeer = cl.onDHTAnnouncePeer
+ }
cl.dHT, err = dht.NewServer(&dhtCfg)
if err != nil {
return
c.r = rateLimitedReader{cl.downloadLimit, c.r}
return
}
+
+func (cl *Client) onDHTAnnouncePeer(ih metainfo.Hash, p dht.Peer) {
+ cl.mu.Lock()
+ defer cl.mu.Unlock()
+ t, ok := cl.Torrent(ih)
+ if !ok {
+ return
+ }
+ t.addPeers([]Peer{{
+ IP: p.IP,
+ Port: p.Port,
+ Source: peerSourceDHTAnnouncePeer,
+ }})
+}
var optimizedCancels = expvar.NewInt("optimizedCancels")
-type peerSource byte
+type peerSource string
const (
- peerSourceTracker = '\x00' // It's the default.
- peerSourceIncoming = 'I'
- peerSourceDHT = 'H'
- peerSourcePEX = 'X'
+ peerSourceTracker = "T" // It's the default.
+ peerSourceIncoming = "I"
+ peerSourceDHTGetPeers = "Hg"
+ peerSourceDHTAnnouncePeer = "Ha"
+ peerSourcePEX = "X"
)
// Maintains the state of a connection with a peer.
if cn.encrypted {
c('E')
}
- if cn.Discovery != 0 {
- c(byte(cn.Discovery))
- }
+ ret += string(cn.Discovery)
if cn.uTP {
c('T')
}
addPeers = append(addPeers, Peer{
IP: cp.IP[:],
Port: cp.Port,
- Source: peerSourceDHT,
+ Source: peerSourceDHTGetPeers,
})
key := (&net.UDPAddr{
IP: cp.IP[:],