5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 11:50:28 +00:00

check root before accepting that a message is good and unblocking a new peer

This commit is contained in:
Arceliar 2018-06-08 17:33:16 -05:00
parent f30d040366
commit 1dcc60f054
2 changed files with 28 additions and 0 deletions

View File

@ -297,6 +297,13 @@ func (p *peer) handleSwitchMsg(packet []byte) {
prevKey = hop.Next
}
p.core.switchTable.handleMsg(&msg, p.port)
if !p.core.switchTable.checkRoot(&msg) {
// Bad switch message
// Stop forwarding traffic from it
// Stop refreshing it in the DHT
p.dinfo = nil
return
}
// Pass a mesage to the dht informing it that this peer (still) exists
loc.coords = loc.coords[:len(loc.coords)-1]
dinfo := dhtInfo{

View File

@ -263,6 +263,27 @@ func (t *switchTable) getMsg() *switchMsg {
}
}
func (t *switchTable) checkRoot(msg *switchMsg) bool {
// returns false if it's a dropped root, not a better root, or has an older timestamp
// returns true otherwise
// used elsewhere to keep inserting peers into the dht only if root info is OK
t.mutex.RLock()
defer t.mutex.RUnlock()
dropTstamp, isIn := t.drop[msg.Root]
switch {
case isIn && dropTstamp >= msg.TStamp:
return false
case firstIsBetter(&msg.Root, &t.data.locator.root):
return true
case t.data.locator.root != msg.Root:
return false
case t.data.locator.tstamp > msg.TStamp:
return false
default:
return true
}
}
func (t *switchTable) handleMsg(msg *switchMsg, fromPort switchPort) {
t.mutex.Lock()
defer t.mutex.Unlock()