File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -475,14 +475,26 @@ func (cfg *Config) validate() error {
475475		return  errors .New ("cannot use shared TCP listener with PSK" )
476476	}
477477
478+ 	// check for duplicate listen addresses and remove them 
479+ 	listenAddresses  :=  cfg .ListenAddrs 
480+ 	// Remove duplicates while keeping the first occurrence of each address 
481+ 	seen  :=  make (map [string ]bool )
482+ 	listenAddresses  =  slices .DeleteFunc (listenAddresses , func (addr  ma.Multiaddr ) bool  {
483+ 		addrStr  :=  addr .String ()
484+ 		if  seen [addrStr ] {
485+ 			return  true  // Remove this duplicate 
486+ 		}
487+ 		seen [addrStr ] =  true 
488+ 		return  false  // Keep this first occurrence 
489+ 	})
490+ 	cfg .ListenAddrs  =  listenAddresses 
478491	return  nil 
479492}
480493
481494// NewNode constructs a new libp2p Host from the Config. 
482495// 
483496// This function consumes the config. Do not reuse it (really!). 
484497func  (cfg  * Config ) NewNode () (host.Host , error ) {
485- 
486498	validateErr  :=  cfg .validate ()
487499	if  validateErr  !=  nil  {
488500		if  cfg .ResourceManager  !=  nil  {
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments