5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 21:11:36 +00:00

more debugging

This commit is contained in:
Arceliar 2018-10-21 00:05:04 -05:00
parent 95201669fe
commit 6c59ae862a
3 changed files with 59 additions and 16 deletions

View File

@ -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] {
return false
}
if first[idx] < second[idx] {
return true
}
}
return true
}
firstLessThanSecond := lessOrEqual(first, second)
secondLessThanThird := lessOrEqual(second, third)
thirdLessThanFirst := lessOrEqual(third, first)
switch { switch {
case f == s && s == t: case firstLessThanSecond && secondLessThanThird:
continue // Nothing wrapped around 0, the easy case
case f <= s && s <= t: return true
ordered = true // nothing wrapped around 0 case thirdLessThanFirst && firstLessThanSecond:
case t <= f && f <= s: // Third wrapped around 0
ordered = true // 0 is between second and third return true
case s <= t && t <= f: case secondLessThanThird && thirdLessThanFirst:
ordered = true // 0 is between first and second // Second (and third) wrapped around 0
return true
} }
break return false
}
return ordered
} }
// 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))
} }
} }

View File

@ -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
} }
} }
} }

View File

@ -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()