mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-12-23 00:17:35 +00:00
check root before accepting that a message is good and unblocking a new peer
This commit is contained in:
parent
f30d040366
commit
1dcc60f054
@ -297,6 +297,13 @@ func (p *peer) handleSwitchMsg(packet []byte) {
|
|||||||
prevKey = hop.Next
|
prevKey = hop.Next
|
||||||
}
|
}
|
||||||
p.core.switchTable.handleMsg(&msg, p.port)
|
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
|
// Pass a mesage to the dht informing it that this peer (still) exists
|
||||||
loc.coords = loc.coords[:len(loc.coords)-1]
|
loc.coords = loc.coords[:len(loc.coords)-1]
|
||||||
dinfo := dhtInfo{
|
dinfo := dhtInfo{
|
||||||
|
@ -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) {
|
func (t *switchTable) handleMsg(msg *switchMsg, fromPort switchPort) {
|
||||||
t.mutex.Lock()
|
t.mutex.Lock()
|
||||||
defer t.mutex.Unlock()
|
defer t.mutex.Unlock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user