mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 10:41:40 +00:00
prevent parent nodes from forcing coord oscillation, have dht.handleRes clean up the old request info immediately
This commit is contained in:
parent
6c556da05e
commit
7fe038f87e
@ -10,7 +10,7 @@ package yggdrasil
|
|||||||
|
|
||||||
import _ "golang.org/x/net/ipv6" // TODO put this somewhere better
|
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 "fmt"
|
||||||
import "net"
|
import "net"
|
||||||
@ -353,6 +353,7 @@ func (c *Core) DEBUG_addPeer(addr string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func (c *Core) DEBUG_addSOCKSConn(socksaddr, peeraddr string) {
|
func (c *Core) DEBUG_addSOCKSConn(socksaddr, peeraddr string) {
|
||||||
go func() {
|
go func() {
|
||||||
dialer, err := proxy.SOCKS5("tcp", socksaddr, nil, proxy.Direct)
|
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) {
|
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) {
|
func (c *Core) DEBUG_addTCPConn(saddr string) {
|
||||||
c.tcp.call(saddr)
|
c.tcp.call(saddr, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
//*/
|
//*/
|
||||||
|
@ -126,8 +126,10 @@ func (t *dht) handleReq(req *dhtReq) {
|
|||||||
key: req.Key,
|
key: req.Key,
|
||||||
coords: req.Coords,
|
coords: req.Coords,
|
||||||
}
|
}
|
||||||
t.insertIfNew(&info, false) // This seems DoSable (we just trust their coords...)
|
// For bootstrapping to work, we need to add these nodes to the table
|
||||||
//if req.dest != t.nodeID { t.ping(&info, info.getNodeID()) } // Or spam...
|
// 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.
|
// 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 {
|
if !isIn {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
delete(reqs, res.Dest)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
rinfo := dhtInfo{
|
rinfo := dhtInfo{
|
||||||
key: res.Key,
|
key: res.Key,
|
||||||
|
@ -364,7 +364,7 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort) {
|
|||||||
doUpdate := false
|
doUpdate := false
|
||||||
if !equiv(&sender.locator, &oldSender.locator) {
|
if !equiv(&sender.locator, &oldSender.locator) {
|
||||||
doUpdate = true
|
doUpdate = true
|
||||||
//sender.firstSeen = now // TODO? uncomment to prevent flapping?
|
sender.firstSeen = now
|
||||||
}
|
}
|
||||||
t.data.peers[fromPort] = sender
|
t.data.peers[fromPort] = sender
|
||||||
updateRoot := false
|
updateRoot := false
|
||||||
@ -402,7 +402,16 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort) {
|
|||||||
updateRoot = true
|
updateRoot = true
|
||||||
case sender.port != t.parent: // do nothing
|
case sender.port != t.parent: // do nothing
|
||||||
case !equiv(&sender.locator, &t.data.locator):
|
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 now.Sub(t.time) < switch_throttle: // do nothing
|
||||||
case sender.locator.tstamp > t.data.locator.tstamp:
|
case sender.locator.tstamp > t.data.locator.tstamp:
|
||||||
updateRoot = true
|
updateRoot = true
|
||||||
|
Loading…
Reference in New Issue
Block a user