prevent parent nodes from forcing coord oscillation, have dht.handleRes clean up the old request info immediately

This commit is contained in:
Arceliar 2018-06-14 12:32:18 -05:00
parent 6c556da05e
commit 7fe038f87e
3 changed files with 20 additions and 6 deletions

View File

@ -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)
}
//*/

View File

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

View File

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