Handle both IPv4 and IPv6

use net.JoinHostPort(minerIP, minerPort) to handle both IPv4 and IPv6 addresses.
This commit is contained in:
Phi 2023-09-25 13:56:35 +02:00
parent 65638ae0c1
commit 8c30e06eb6

View File

@ -806,13 +806,8 @@ func extractRoutableIP(timeout time.Duration) (string, error) {
}
minerPort, _ := maddr.ValueForProtocol(multiaddr.P_TCP)
// 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
}
// Format the address appropriately
addressToDial := net.JoinHostPort(minerIP, minerPort)
conn, err := net.DialTimeout("tcp", addressToDial, timeout)
if err != nil {