p2p/discover: permit temporary bond failures for previously known nodes

This commit is contained in:
Péter Szilágyi 2015-05-25 15:22:54 +03:00
parent 6ba1dead72
commit 5114806a0f

View file

@ -275,6 +275,7 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16
fails = tab.db.findFails(id)
}
// If the node is unknown (non-bonded) or failed (remotely unknown), bond from scratch
var result error
if node == nil || fails > 0 {
glog.V(logger.Detail).Infof("Bonding %x: known=%v, fails=%v", id[:8], node != nil, fails)
@ -296,12 +297,14 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16
delete(tab.bonding, id)
tab.bondmu.Unlock()
}
// Retrieve the bonding results
result = w.err
if result == nil {
node = w.n
if w.err != nil {
return nil, w.err
}
}
// Bonding succeeded, add to the table and reset previous findnode failures
// Even if bonding temporarily failed, give the node a chance
if node != nil {
tab.mutex.Lock()
defer tab.mutex.Unlock()
@ -310,8 +313,8 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16
tab.pingreplace(node, b)
}
tab.db.updateFindFails(id, 0)
return node, nil
}
return node, result
}
func (tab *Table) pingpong(w *bondproc, pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16) {