Commit 6e001215 authored by acud's avatar acud Committed by GitHub

kademlia: dont connect to the same peer again in short interval (#352)

parent 584343e1
...@@ -30,6 +30,7 @@ const ( ...@@ -30,6 +30,7 @@ const (
var ( var (
errMissingAddressBookEntry = errors.New("addressbook underlay entry not found") errMissingAddressBookEntry = errors.New("addressbook underlay entry not found")
timeToRetry = 60 * time.Second timeToRetry = 60 * time.Second
shortRetry = 30 * time.Second
) )
type binSaturationFunc func(bin, depth uint8, peers *pslice.PSlice) bool type binSaturationFunc func(bin, depth uint8, peers *pslice.PSlice) bool
...@@ -161,12 +162,12 @@ func (k *Kad) manage() { ...@@ -161,12 +162,12 @@ func (k *Kad) manage() {
return false, false, nil return false, false, nil
} }
k.connectedPeers.Add(peer, po)
k.waitNextMu.Lock() k.waitNextMu.Lock()
delete(k.waitNext, peer.String()) k.waitNext[peer.String()] = retryInfo{tryAfter: time.Now().Add(shortRetry)}
k.waitNextMu.Unlock() k.waitNextMu.Unlock()
k.connectedPeers.Add(peer, po)
k.depthMu.Lock() k.depthMu.Lock()
k.depth = k.recalcDepth() k.depth = k.recalcDepth()
k.depthMu.Unlock() k.depthMu.Unlock()
......
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