Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,26 @@ func (cfg *Config) validate() error {
return errors.New("cannot use shared TCP listener with PSK")
}

// check for duplicate listen addresses and remove them
listenAddresses := cfg.ListenAddrs
// Remove duplicates while keeping the first occurrence of each address
seen := make(map[string]bool)
listenAddresses = slices.DeleteFunc(listenAddresses, func(addr ma.Multiaddr) bool {
addrStr := addr.String()
if seen[addrStr] {
return true // Remove this duplicate
}
seen[addrStr] = true
return false // Keep this first occurrence
})
cfg.ListenAddrs = listenAddresses
return nil
}

// NewNode constructs a new libp2p Host from the Config.
//
// This function consumes the config. Do not reuse it (really!).
func (cfg *Config) NewNode() (host.Host, error) {

validateErr := cfg.validate()
if validateErr != nil {
if cfg.ResourceManager != nil {
Expand Down