mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	ignore root tstamp updates if we just updated, to throttle the rate at which updates (and new signatures) can propagate
This commit is contained in:
		
							parent
							
								
									a66a29779a
								
							
						
					
					
						commit
						71150fcb86
					
				
					 1 changed files with 8 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -11,11 +11,6 @@ package yggdrasil
 | 
			
		|||
// TODO? use a pre-computed lookup table (python version had this)
 | 
			
		||||
//  A little annoying to do with constant changes from bandwidth estimates
 | 
			
		||||
 | 
			
		||||
// FIXME (!) throttle how often root updates are accepted
 | 
			
		||||
//  If the root starts spaming with new timestamps, it should only affect their neighbors
 | 
			
		||||
//  The rest of the network should see announcements at a somewhat reasonable rate
 | 
			
		||||
//  Maybe no faster than 2x the usual update interval
 | 
			
		||||
 | 
			
		||||
import "time"
 | 
			
		||||
import "sync"
 | 
			
		||||
import "sync/atomic"
 | 
			
		||||
| 
						 | 
				
			
			@ -23,6 +18,8 @@ import "sync/atomic"
 | 
			
		|||
//import "fmt"
 | 
			
		||||
 | 
			
		||||
const switch_timeout = time.Minute
 | 
			
		||||
const switch_updateInterval = switch_timeout / 2
 | 
			
		||||
const switch_throttle = switch_updateInterval / 2
 | 
			
		||||
 | 
			
		||||
// You should be able to provide crypto signatures for this
 | 
			
		||||
// 1 signature per coord, from the *sender* to that coord
 | 
			
		||||
| 
						 | 
				
			
			@ -219,7 +216,7 @@ func (t *switchTable) cleanRoot() {
 | 
			
		|||
	}
 | 
			
		||||
	// Or, if we are the root, possibly update our timestamp
 | 
			
		||||
	if t.data.locator.root == t.key &&
 | 
			
		||||
		now.Sub(t.time) > switch_timeout/2 {
 | 
			
		||||
		now.Sub(t.time) > switch_updateInterval {
 | 
			
		||||
		//fmt.Println("root is self and old, updating", t.data.locator.Root)
 | 
			
		||||
		doUpdate = true
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -343,9 +340,11 @@ func (t *switchTable) handleMessage(msg *switchMessage, fromPort switchPort, sig
 | 
			
		|||
		updateRoot = true
 | 
			
		||||
	case cost < pCost:
 | 
			
		||||
		updateRoot = true
 | 
			
		||||
	case sender.port == t.parent &&
 | 
			
		||||
		(msg.locator.tstamp > t.data.locator.tstamp ||
 | 
			
		||||
			!equiv(&msg.locator, &t.data.locator)):
 | 
			
		||||
	case sender.port != t.parent: // do nothing
 | 
			
		||||
	case !equiv(&msg.locator, &t.data.locator):
 | 
			
		||||
		updateRoot = true
 | 
			
		||||
	case now.Sub(t.time) < switch_throttle: // do nothing
 | 
			
		||||
	case msg.locator.tstamp > t.data.locator.tstamp:
 | 
			
		||||
		updateRoot = true
 | 
			
		||||
	}
 | 
			
		||||
	if updateRoot {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue