mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-03 10:45:09 +03:00 
			
		
		
		
	Enforce maximum CKR routing cache size
This commit is contained in:
		
							parent
							
								
									f09adc2192
								
							
						
					
					
						commit
						65e34bbbab
					
				
					 1 changed files with 10 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -241,6 +241,16 @@ func (c *cryptokey) getPublicKeyForAddress(addr address, addrlen int) (boxPubKey
 | 
			
		|||
	for _, route := range *routingtable {
 | 
			
		||||
		// Does this subnet match the given IP?
 | 
			
		||||
		if route.subnet.Contains(ip) {
 | 
			
		||||
			// Check if the routing cache is above a certain size, if it is evict
 | 
			
		||||
			// a random entry so we can make room for this one. We take advantage
 | 
			
		||||
			// of the fact that the iteration order is random here
 | 
			
		||||
			if len(*routingcache) > 1024 {
 | 
			
		||||
				for k := range *routingcache {
 | 
			
		||||
					delete(*routingcache, k)
 | 
			
		||||
					break
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// Cache the entry for future packets to get a faster lookup
 | 
			
		||||
			(*routingcache)[addr] = route
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue