aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/discover
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-05-25 20:22:54 +0800
committerFelix Lange <fjl@twurst.com>2015-05-27 05:30:40 +0800
commit5076170f344afb970c1adc91429ced6ce93b5989 (patch)
treeb1c140feae55e74fddceade52c621bacc43d2101 /p2p/discover
parent6078aa08ebf165e523cc00b67d89f0f946ba4fb5 (diff)
downloaddexon-5076170f344afb970c1adc91429ced6ce93b5989.tar
dexon-5076170f344afb970c1adc91429ced6ce93b5989.tar.gz
dexon-5076170f344afb970c1adc91429ced6ce93b5989.tar.bz2
dexon-5076170f344afb970c1adc91429ced6ce93b5989.tar.lz
dexon-5076170f344afb970c1adc91429ced6ce93b5989.tar.xz
dexon-5076170f344afb970c1adc91429ced6ce93b5989.tar.zst
dexon-5076170f344afb970c1adc91429ced6ce93b5989.zip
p2p/discover: permit temporary bond failures for previously known nodes
Diffstat (limited to 'p2p/discover')
-rw-r--r--p2p/discover/table.go27
1 files changed, 15 insertions, 12 deletions
diff --git a/p2p/discover/table.go b/p2p/discover/table.go
index c45143307..ee1d58cae 100644
--- a/p2p/discover/table.go
+++ b/p2p/discover/table.go
@@ -324,6 +324,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)
@@ -345,22 +346,24 @@ func (tab *Table) bond(pinged bool, id NodeID, addr *net.UDPAddr, tcpPort uint16
delete(tab.bonding, id)
tab.bondmu.Unlock()
}
- node = w.n
- if w.err != nil {
- return nil, w.err
+ // Retrieve the bonding results
+ result = w.err
+ if result == nil {
+ node = w.n
}
}
- // Bonding succeeded, add to the table and reset previous findnode failures
- tab.mutex.Lock()
- defer tab.mutex.Unlock()
+ // Even if bonding temporarily failed, give the node a chance
+ if node != nil {
+ tab.mutex.Lock()
+ defer tab.mutex.Unlock()
- b := tab.buckets[logdist(tab.self.sha, node.sha)]
- if !b.bump(node) {
- tab.pingreplace(node, b)
+ b := tab.buckets[logdist(tab.self.sha, node.sha)]
+ if !b.bump(node) {
+ 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) {