From 7fe038f87e9a8f0a18d02810bf4fe33e48b50f38 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 14 Jun 2018 12:32:18 -0500 Subject: [PATCH] prevent parent nodes from forcing coord oscillation, have dht.handleRes clean up the old request info immediately --- src/yggdrasil/debug.go | 6 ++++-- src/yggdrasil/dht.go | 7 +++++-- src/yggdrasil/switch.go | 13 +++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/yggdrasil/debug.go b/src/yggdrasil/debug.go index 61b4c2f1..2cf90401 100644 --- a/src/yggdrasil/debug.go +++ b/src/yggdrasil/debug.go @@ -10,7 +10,7 @@ package yggdrasil import _ "golang.org/x/net/ipv6" // TODO put this somewhere better -import "golang.org/x/net/proxy" +//import "golang.org/x/net/proxy" import "fmt" import "net" @@ -353,6 +353,7 @@ func (c *Core) DEBUG_addPeer(addr string) { } } +/* func (c *Core) DEBUG_addSOCKSConn(socksaddr, peeraddr string) { go func() { dialer, err := proxy.SOCKS5("tcp", socksaddr, nil, proxy.Direct) @@ -370,6 +371,7 @@ func (c *Core) DEBUG_addSOCKSConn(socksaddr, peeraddr string) { } }() } +*/ //* func (c *Core) DEBUG_setupAndStartGlobalTCPInterface(addrport string) { @@ -384,7 +386,7 @@ func (c *Core) DEBUG_getGlobalTCPAddr() *net.TCPAddr { } func (c *Core) DEBUG_addTCPConn(saddr string) { - c.tcp.call(saddr) + c.tcp.call(saddr, nil) } //*/ diff --git a/src/yggdrasil/dht.go b/src/yggdrasil/dht.go index 4e53be31..955ef839 100644 --- a/src/yggdrasil/dht.go +++ b/src/yggdrasil/dht.go @@ -126,8 +126,10 @@ func (t *dht) handleReq(req *dhtReq) { key: req.Key, coords: req.Coords, } - t.insertIfNew(&info, false) // This seems DoSable (we just trust their coords...) - //if req.dest != t.nodeID { t.ping(&info, info.getNodeID()) } // Or spam... + // For bootstrapping to work, we need to add these nodes to the table + // Using insertIfNew, they can lie about coords, but searches will route around them + // Using the mill would mean trying to block off the mill becomes an attack vector + t.insertIfNew(&info, false) } // Reads a lookup response, checks that we had sent a matching request, and processes the response info. @@ -142,6 +144,7 @@ func (t *dht) handleRes(res *dhtRes) { if !isIn { return } + delete(reqs, res.Dest) now := time.Now() rinfo := dhtInfo{ key: res.Key, diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 9c0e3f17..d3b28710 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -364,7 +364,7 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort) { doUpdate := false if !equiv(&sender.locator, &oldSender.locator) { doUpdate = true - //sender.firstSeen = now // TODO? uncomment to prevent flapping? + sender.firstSeen = now } t.data.peers[fromPort] = sender updateRoot := false @@ -402,7 +402,16 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort) { updateRoot = true case sender.port != t.parent: // do nothing case !equiv(&sender.locator, &t.data.locator): - updateRoot = true + // Special case + // If coords changed, then this may now be a worse parent than before + // Re-parent the node (de-parent and reprocess the message) + // Then reprocess *all* messages to look for a better parent + // This is so we don't keep using this node as our parent if there's something better + t.parent = 0 + t.unlockedHandleMsg(msg, fromPort) + for _, info := range t.data.peers { + t.unlockedHandleMsg(&info.msg, info.port) + } case now.Sub(t.time) < switch_throttle: // do nothing case sender.locator.tstamp > t.data.locator.tstamp: updateRoot = true