From 289f1ce7c22fa317e5d06184e86fe903e039ca2a Mon Sep 17 00:00:00 2001 From: Arceliar Date: Wed, 14 Nov 2018 21:58:48 -0600 Subject: [PATCH 1/2] set packet version in sim, so it plays nice with new parsing from the new ckr code --- misc/sim/treesim.go | 1 + 1 file changed, 1 insertion(+) diff --git a/misc/sim/treesim.go b/misc/sim/treesim.go index 4aa463d..3391e1a 100644 --- a/misc/sim/treesim.go +++ b/misc/sim/treesim.go @@ -267,6 +267,7 @@ func pingNodes(store map[[32]byte]*Node) { copy(packet[8:24], sourceAddr) copy(packet[24:40], destAddr) copy(packet[40:], bs) + packet[0] = 6 << 4 source.send <- packet } destCount := 0 From ef6cece7207d2921bb2576eb4f4c6cb31078641c Mon Sep 17 00:00:00 2001 From: Arceliar Date: Fri, 16 Nov 2018 19:32:12 -0600 Subject: [PATCH 2/2] fix sim and tune dht to bootstrap a little faster --- misc/sim/treesim.go | 2 +- src/yggdrasil/dht.go | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/misc/sim/treesim.go b/misc/sim/treesim.go index 3391e1a..3a0959e 100644 --- a/misc/sim/treesim.go +++ b/misc/sim/treesim.go @@ -439,7 +439,7 @@ func main() { pingNodes(kstore) //pingBench(kstore) // Only after disabling debug output //stressTest(kstore) - time.Sleep(120 * time.Second) + //time.Sleep(120 * time.Second) dumpDHTSize(kstore) // note that this uses racey functions to read things... if false { // This connects the sim to the local network diff --git a/src/yggdrasil/dht.go b/src/yggdrasil/dht.go index 9891ec9..220e291 100644 --- a/src/yggdrasil/dht.go +++ b/src/yggdrasil/dht.go @@ -82,10 +82,16 @@ func (t *dht) lookup(nodeID *NodeID, everything bool) []*dhtInfo { for _, info := range t.table { results = append(results, info) } - sort.SliceStable(results, func(i, j int) bool { - return dht_ordered(nodeID, results[i].getNodeID(), results[j].getNodeID()) - }) if len(results) > dht_lookup_size { + // Drop the middle part, so we keep some nodes before and after. + // This should help to bootstrap / recover more quickly. + sort.SliceStable(results, func(i, j int) bool { + return dht_ordered(nodeID, results[i].getNodeID(), results[j].getNodeID()) + }) + newRes := make([]*dhtInfo, 0, len(results)) + newRes = append(newRes, results[len(results)-dht_lookup_size/2:]...) + newRes = append(newRes, results[:len(results)-dht_lookup_size/2]...) + results = newRes results = results[:dht_lookup_size] } return results @@ -168,7 +174,7 @@ func (t *dht) handleReq(req *dhtReq) { coords: req.Coords, } if _, isIn := t.table[*info.getNodeID()]; !isIn && t.isImportant(&info) { - t.insert(&info) + t.ping(&info, nil) } } @@ -276,7 +282,7 @@ func (t *dht) doMaintenance() { } for _, info := range t.getImportant() { if now.Sub(info.recv) > info.throttle { - t.ping(info, info.getNodeID()) + t.ping(info, nil) info.pings++ info.throttle += time.Second if info.throttle > 30*time.Second {