Commit 5076170f authored by Péter Szilágyi's avatar Péter Szilágyi Committed by Felix Lange

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

parent 6078aa08
...@@ -324,6 +324,7 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16 ...@@ -324,6 +324,7 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16
fails = tab.db.findFails(id) fails = tab.db.findFails(id)
} }
// If the node is unknown (non-bonded) or failed (remotely unknown), bond from scratch // If the node is unknown (non-bonded) or failed (remotely unknown), bond from scratch
var result error
if node == nil || fails > 0 { if node == nil || fails > 0 {
glog.V(logger.Detail).Infof("Bonding %x: known=%v, fails=%v", id[:8], node != nil, fails) glog.V(logger.Detail).Infof("Bonding %x: known=%v, fails=%v", id[:8], node != nil, fails)
...@@ -345,12 +346,14 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16 ...@@ -345,12 +346,14 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16
delete(tab.bonding, id) delete(tab.bonding, id)
tab.bondmu.Unlock() tab.bondmu.Unlock()
} }
// Retrieve the bonding results
result = w.err
if result == nil {
node = w.n 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() tab.mutex.Lock()
defer tab.mutex.Unlock() defer tab.mutex.Unlock()
...@@ -359,8 +362,8 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16 ...@@ -359,8 +362,8 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16
tab.pingreplace(node, b) tab.pingreplace(node, b)
} }
tab.db.updateFindFails(id, 0) 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) { func (tab *Table) pingpong(w *bondproc, pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment