From 47dc4337ba165da17e1561b238958af516456705 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 21 Nov 2024 14:06:49 +0100 Subject: [PATCH] fix(p2p): parse maddr correctly (#4219) Previously in case of not specifying a value it would pass a slice of 1 empty element Signed-off-by: Ettore Di Giacinto --- core/p2p/p2p.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/p2p/p2p.go b/core/p2p/p2p.go index 8d317963..651dde31 100644 --- a/core/p2p/p2p.go +++ b/core/p2p/p2p.go @@ -386,8 +386,20 @@ func newNodeOpts(token string) ([]node.Option, error) { // TODO: move this up, expose more config options when creating a node noDHT := os.Getenv("LOCALAI_P2P_DISABLE_DHT") == "true" noLimits := os.Getenv("LOCALAI_P2P_ENABLE_LIMITS") == "true" - listenMaddrs := strings.Split(os.Getenv("LOCALAI_P2P_LISTEN_MADDRS"), ",") - bootstrapPeers := strings.Split(os.Getenv("LOCALAI_P2P_BOOTSTRAP_PEERS_MADDRS"), ",") + + var listenMaddrs []string + var bootstrapPeers []string + + laddrs := os.Getenv("LOCALAI_P2P_LISTEN_MADDRS") + if laddrs != "" { + listenMaddrs = strings.Split(laddrs, ",") + } + + bootmaddr := os.Getenv("LOCALAI_P2P_BOOTSTRAP_PEERS_MADDRS") + if bootmaddr != "" { + bootstrapPeers = strings.Split(bootmaddr, ",") + } + dhtAnnounceMaddrs := stringsToMultiAddr(strings.Split(os.Getenv("LOCALAI_P2P_DHT_ANNOUNCE_MADDRS"), ",")) libp2ploglevel := os.Getenv("LOCALAI_P2P_LIB_LOGLEVEL")