mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-23 02:01:36 +00:00
add search for successor, via parent, to the dht maintenance cycle
This commit is contained in:
parent
d851d9afe7
commit
3dbffae99f
@ -52,6 +52,7 @@ type dht struct {
|
|||||||
table map[NodeID]*dhtInfo
|
table map[NodeID]*dhtInfo
|
||||||
peers chan *dhtInfo // other goroutines put incoming dht updates here
|
peers chan *dhtInfo // other goroutines put incoming dht updates here
|
||||||
reqs map[boxPubKey]map[NodeID]time.Time
|
reqs map[boxPubKey]map[NodeID]time.Time
|
||||||
|
search time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes the DHT
|
// Initializes the DHT
|
||||||
@ -79,6 +80,7 @@ func (t *dht) reset() {
|
|||||||
}
|
}
|
||||||
t.reqs = make(map[boxPubKey]map[NodeID]time.Time)
|
t.reqs = make(map[boxPubKey]map[NodeID]time.Time)
|
||||||
t.table = make(map[NodeID]*dhtInfo)
|
t.table = make(map[NodeID]*dhtInfo)
|
||||||
|
t.search = time.Now().Add(-time.Minute)
|
||||||
if successor != nil {
|
if successor != nil {
|
||||||
t.ping(successor, &t.nodeID)
|
t.ping(successor, &t.nodeID)
|
||||||
}
|
}
|
||||||
@ -323,8 +325,37 @@ func (t *dht) doMaintenance() {
|
|||||||
}
|
}
|
||||||
if successor != nil &&
|
if successor != nil &&
|
||||||
now.Sub(successor.recv) > successor.throttle &&
|
now.Sub(successor.recv) > successor.throttle &&
|
||||||
now.Sub(successor.send) > 6*time.Second {
|
now.Sub(successor.send) > 3*time.Second {
|
||||||
t.ping(successor, nil)
|
t.ping(successor, nil)
|
||||||
successor.pings++
|
successor.pings++
|
||||||
|
if now.Sub(t.search) > time.Minute {
|
||||||
|
// Start a search for our successor, beginning at this node's parent
|
||||||
|
// This should (hopefully) help bootstrap
|
||||||
|
t.core.switchTable.mutex.RLock()
|
||||||
|
parentPort := t.core.switchTable.parent
|
||||||
|
t.core.switchTable.mutex.RUnlock()
|
||||||
|
ports := t.core.peers.getPorts()
|
||||||
|
if parent, isIn := ports[parentPort]; isIn {
|
||||||
|
t.search = now
|
||||||
|
target := successor.getNodeID().prev()
|
||||||
|
sinfo, isIn := t.core.searches.searches[target]
|
||||||
|
if !isIn {
|
||||||
|
var mask NodeID
|
||||||
|
for idx := range mask {
|
||||||
|
mask[idx] = 0xff
|
||||||
|
}
|
||||||
|
sinfo = t.core.searches.newIterSearch(&target, &mask)
|
||||||
|
toVisit := sinfo.toVisit
|
||||||
|
parentNodeID := getNodeID(&parent.box)
|
||||||
|
for _, ninfo := range toVisit {
|
||||||
|
if *ninfo.getNodeID() == *parentNodeID {
|
||||||
|
toVisit = append(toVisit, ninfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sinfo.toVisit = toVisit
|
||||||
|
}
|
||||||
|
t.core.searches.continueSearch(sinfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,9 +158,9 @@ type switchTable struct {
|
|||||||
core *Core
|
core *Core
|
||||||
key sigPubKey // Our own key
|
key sigPubKey // Our own key
|
||||||
time time.Time // Time when locator.tstamp was last updated
|
time time.Time // Time when locator.tstamp was last updated
|
||||||
parent switchPort // Port of whatever peer is our parent, or self if we're root
|
|
||||||
drop map[sigPubKey]int64 // Tstamp associated with a dropped root
|
drop map[sigPubKey]int64 // Tstamp associated with a dropped root
|
||||||
mutex sync.RWMutex // Lock for reads/writes of switchData
|
mutex sync.RWMutex // Lock for reads/writes of switchData
|
||||||
|
parent switchPort // Port of whatever peer is our parent, or self if we're root
|
||||||
data switchData //
|
data switchData //
|
||||||
updater atomic.Value // *sync.Once
|
updater atomic.Value // *sync.Once
|
||||||
table atomic.Value // lookupTable
|
table atomic.Value // lookupTable
|
||||||
|
Loading…
Reference in New Issue
Block a user