Filter out DHT peers with port 0

Probably not necessary now we ban the nodes that send them, but it's appropriate to check here too.
This commit is contained in:
Matt Joiner 2015-08-04 01:20:10 +10:00
parent f3317322f8
commit bbe58bbd73
1 changed files with 19 additions and 17 deletions

View File

@ -2261,24 +2261,26 @@ func (cl *Client) announceTorrentDHT(t *torrent, impliedPort bool) {
if !ok {
break getPeers
}
peersFoundByDHT.Add(int64(len(v.Peers)))
for _, p := range v.Peers {
allAddrs[(&net.UDPAddr{
IP: p.IP[:],
Port: int(p.Port),
}).String()] = struct{}{}
}
cl.mu.Lock()
cl.addPeers(t, func() (ret []Peer) {
for _, cp := range v.Peers {
ret = append(ret, Peer{
IP: cp.IP[:],
Port: int(cp.Port),
Source: peerSourceDHT,
})
addPeers := make([]Peer, 0, len(v.Peers))
for _, cp := range v.Peers {
if cp.Port == 0 {
// Can't do anything with this.
continue
}
return
}())
addPeers = append(addPeers, Peer{
IP: cp.IP[:],
Port: int(cp.Port),
Source: peerSourceDHT,
})
key := (&net.UDPAddr{
IP: cp.IP[:],
Port: int(cp.Port),
}).String()
allAddrs[key] = struct{}{}
}
peersFoundByDHT.Add(int64(len(addPeers)))
cl.mu.Lock()
cl.addPeers(t, addPeers)
numPeers := len(t.Peers)
cl.mu.Unlock()
if numPeers >= torrentPeersHighWater {