From 94e48ae86056052d366ba0817a5cdb0469a8367a Mon Sep 17 00:00:00 2001 From: Phi Date: Tue, 8 Aug 2023 13:18:36 +0200 Subject: [PATCH] Add IPv6 check and format appropriately Add IPv6 check and format appropriately --- cmd/lotus-worker/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-worker/main.go b/cmd/lotus-worker/main.go index 0a5d4efc5..d23b3860a 100644 --- a/cmd/lotus-worker/main.go +++ b/cmd/lotus-worker/main.go @@ -779,7 +779,15 @@ func extractRoutableIP(timeout time.Duration) (string, error) { minerIP, _ := maddr.ValueForProtocol(multiaddr.P_IP6) minerPort, _ := maddr.ValueForProtocol(multiaddr.P_TCP) - conn, err := net.DialTimeout("tcp", minerIP+":"+minerPort, timeout) + // Check if the IP is IPv6 and format the address appropriately + var addressToDial string + if ip := net.ParseIP(minerIP); ip.To4() == nil && ip.To16() != nil { + addressToDial = "[" + minerIP + "]:" + minerPort + } else { + addressToDial = minerIP + ":" + minerPort + } + + conn, err := net.DialTimeout("tcp", addressToDial, timeout) if err != nil { return "", err }