mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Avoid unnecessarily allocating coords slice if it's unchanged.
This commit is contained in:
		
							parent
							
								
									67b8a7a53d
								
							
						
					
					
						commit
						b4db89ea9d
					
				
					 1 changed files with 8 additions and 3 deletions
				
			
		| 
						 | 
					@ -4,7 +4,10 @@ package yggdrasil
 | 
				
			||||||
// It's responsible for keeping track of open sessions to other nodes
 | 
					// It's responsible for keeping track of open sessions to other nodes
 | 
				
			||||||
// The session information consists of crypto keys and coords
 | 
					// The session information consists of crypto keys and coords
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "time"
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// All the information we know about an active session.
 | 
					// All the information we know about an active session.
 | 
				
			||||||
// This includes coords, permanent and ephemeral keys, handles and nonces, various sorts of timing information for timeout and maintenance, and some metadata for the admin API.
 | 
					// This includes coords, permanent and ephemeral keys, handles and nonces, various sorts of timing information for timeout and maintenance, and some metadata for the admin API.
 | 
				
			||||||
| 
						 | 
					@ -72,8 +75,10 @@ func (s *sessionInfo) update(p *sessionPing) bool {
 | 
				
			||||||
	if p.MTU >= 1280 || p.MTU == 0 {
 | 
						if p.MTU >= 1280 || p.MTU == 0 {
 | 
				
			||||||
		s.theirMTU = p.MTU
 | 
							s.theirMTU = p.MTU
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// allocate enough space for additional coords
 | 
						if !bytes.Equal(s.coords, p.Coords) {
 | 
				
			||||||
	s.coords = append(make([]byte, 0, len(p.Coords)+11), p.Coords...)
 | 
							// allocate enough space for additional coords
 | 
				
			||||||
 | 
							s.coords = append(make([]byte, 0, len(p.Coords)+11), p.Coords...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	now := time.Now()
 | 
						now := time.Now()
 | 
				
			||||||
	s.time = now
 | 
						s.time = now
 | 
				
			||||||
	s.tstamp = p.Tstamp
 | 
						s.tstamp = p.Tstamp
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue