mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-23 00:51:35 +00:00
more debugging
This commit is contained in:
parent
95201669fe
commit
6c59ae862a
@ -1,6 +1,12 @@
|
|||||||
package yggdrasil
|
package yggdrasil
|
||||||
|
|
||||||
|
// TODO signal to predecessor when we replace them?
|
||||||
|
// Sending a ping with an extra 0 at the end of our coords should be enough to reset our throttle in their table
|
||||||
|
// That should encorage them to ping us again sooner, and then we can reply with new info
|
||||||
|
// Maybe remember old predecessor and check this during maintenance?
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -146,22 +152,32 @@ func (t *dht) insert(info *dhtInfo) {
|
|||||||
// Return true if first/second/third are (partially) ordered correctly
|
// Return true if first/second/third are (partially) ordered correctly
|
||||||
// FIXME? maybe total ordering makes more sense
|
// FIXME? maybe total ordering makes more sense
|
||||||
func dht_ordered(first, second, third *NodeID) bool {
|
func dht_ordered(first, second, third *NodeID) bool {
|
||||||
var ordered bool
|
lessOrEqual := func(first, second *NodeID) bool {
|
||||||
for idx := 0; idx < NodeIDLen; idx++ {
|
for idx := 0; idx < NodeIDLen; idx++ {
|
||||||
f, s, t := first[idx], second[idx], third[idx]
|
if first[idx] > second[idx] {
|
||||||
switch {
|
return false
|
||||||
case f == s && s == t:
|
}
|
||||||
continue
|
if first[idx] < second[idx] {
|
||||||
case f <= s && s <= t:
|
return true
|
||||||
ordered = true // nothing wrapped around 0
|
}
|
||||||
case t <= f && f <= s:
|
|
||||||
ordered = true // 0 is between second and third
|
|
||||||
case s <= t && t <= f:
|
|
||||||
ordered = true // 0 is between first and second
|
|
||||||
}
|
}
|
||||||
break
|
return true
|
||||||
}
|
}
|
||||||
return ordered
|
firstLessThanSecond := lessOrEqual(first, second)
|
||||||
|
secondLessThanThird := lessOrEqual(second, third)
|
||||||
|
thirdLessThanFirst := lessOrEqual(third, first)
|
||||||
|
switch {
|
||||||
|
case firstLessThanSecond && secondLessThanThird:
|
||||||
|
// Nothing wrapped around 0, the easy case
|
||||||
|
return true
|
||||||
|
case thirdLessThanFirst && firstLessThanSecond:
|
||||||
|
// Third wrapped around 0
|
||||||
|
return true
|
||||||
|
case secondLessThanThird && thirdLessThanFirst:
|
||||||
|
// Second (and third) wrapped around 0
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads a request, performs a lookup, and responds.
|
// Reads a request, performs a lookup, and responds.
|
||||||
@ -254,6 +270,9 @@ func (t *dht) handleRes(res *dhtRes) {
|
|||||||
predecessor = info
|
predecessor = info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(res.Infos) > dht_lookup_size {
|
||||||
|
res.Infos = res.Infos[:dht_lookup_size]
|
||||||
|
}
|
||||||
for _, info := range res.Infos {
|
for _, info := range res.Infos {
|
||||||
if *info.getNodeID() == t.nodeID {
|
if *info.getNodeID() == t.nodeID {
|
||||||
continue
|
continue
|
||||||
@ -331,8 +350,29 @@ func (t *dht) doMaintenance() {
|
|||||||
t.ping(successor, nil)
|
t.ping(successor, nil)
|
||||||
successor.pings++
|
successor.pings++
|
||||||
successor.throttle += time.Second
|
successor.throttle += time.Second
|
||||||
|
/////
|
||||||
|
if now.Sub(t.search) > 30*time.Second {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
t.core.searches.continueSearch(sinfo)
|
||||||
|
}
|
||||||
|
/////
|
||||||
|
return
|
||||||
|
fmt.Println("DEBUG self:", t.nodeID[:8], "throttle:", successor.throttle, "nodeID:", successor.getNodeID()[:8], "coords:", successor.coords)
|
||||||
|
for infoID := range t.table {
|
||||||
|
fmt.Println("DEBUG other info:", infoID[:8], "ordered", dht_ordered(&t.nodeID, &infoID, successor.getNodeID()), "swapped:", dht_ordered(&t.nodeID, successor.getNodeID(), &infoID))
|
||||||
|
}
|
||||||
if successor.throttle > 30*time.Second {
|
if successor.throttle > 30*time.Second {
|
||||||
successor.throttle = 30 * time.Second
|
successor.throttle = 30 * time.Second
|
||||||
}
|
}
|
||||||
|
fmt.Println("Table size:", len(t.table))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,8 +183,10 @@ func (p *peer) linkLoop() {
|
|||||||
}
|
}
|
||||||
p.sendSwitchMsg()
|
p.sendSwitchMsg()
|
||||||
case _ = <-tick.C:
|
case _ = <-tick.C:
|
||||||
if p.dinfo != nil {
|
pdinfo := p.dinfo // FIXME this is a bad workarond NPE on the next line
|
||||||
p.core.dht.peers <- p.dinfo
|
if pdinfo != nil {
|
||||||
|
dinfo := *pdinfo
|
||||||
|
p.core.dht.peers <- &dinfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ func (r *router) mainLoop() {
|
|||||||
r.sendPacket(p)
|
r.sendPacket(p)
|
||||||
case info := <-r.core.dht.peers:
|
case info := <-r.core.dht.peers:
|
||||||
r.core.dht.insert(info)
|
r.core.dht.insert(info)
|
||||||
|
info.throttle = 0
|
||||||
case <-r.reset:
|
case <-r.reset:
|
||||||
r.core.sessions.resetInits()
|
r.core.sessions.resetInits()
|
||||||
r.core.dht.reset()
|
r.core.dht.reset()
|
||||||
|
Loading…
Reference in New Issue
Block a user