diff --git a/nim-test-node/regression/env.nim b/nim-test-node/regression/env.nim index 8fc69e6..f5eb79a 100644 --- a/nim-test-node/regression/env.nim +++ b/nim-test-node/regression/env.nim @@ -1,11 +1,25 @@ import strutils, os, osproc import chronos, metrics/chronos_httpserver, chronicles -from nativesockets import getHostname +from nativesockets import getHostname, getHostByName type NodeType* = enum RoleBootstrap, RoleNormal +proc shadowSelfIp(hostname: string): string = + ## Shadow doesn't expand a 0.0.0.0 listen into a routable address, so + ## switch.peerInfo.addrs ends up empty and kad-dht can't advertise a dialable + ## address for us. Resolve our own hostname to the Shadow-assigned IP and listen + ## on that instead (host names resolve fine inside Shadow). + try: + for ip in getHostByName(hostname).addrList: + if not ip.startsWith("127.") and ip != "0.0.0.0": + return ip + except CatchableError as e: + warn "Could not resolve self IP; falling back to 0.0.0.0", + hostname = hostname, error = e.msg + return "0.0.0.0" + let inShadow* = getEnv("SHADOWENV").cmpIgnoreCase("true") == 0 #If Running for shadow simulator httpPublishPort* = Port(8645) @@ -24,10 +38,12 @@ proc getPeerDetails*(): Result[(int, int, int, string, string, string, NodeType, connectTo = parseInt(getEnv("CONNECTTO", "10")) muxer = getEnv("MUXER", "yamux") filePath = if inShadow: "../" else: getEnv("FILEPATH", "./") + # k8s expands 0.0.0.0 to the pod IP; Shadow can't, so resolve our own IP there. + listenIp = if inShadow: shadowSelfIp(hostname) else: "0.0.0.0" address = if muxer.toLowerAscii() == "quic": - "/ip4/0.0.0.0/udp/" & $myPort & "/quic-v1" + "/ip4/" & listenIp & "/udp/" & $myPort & "/quic-v1" else: - "/ip4/0.0.0.0/tcp/" & $myPort + "/ip4/" & listenIp & "/tcp/" & $myPort # RoleNormal + static discovery keep the legacy behaviour when the env is unset. nodeRole = parseEnum[NodeType](getEnv("NODE_ROLE", "RoleNormal")) discovery = getEnv("DISCOVERY", "static") diff --git a/nim-test-node/regression/test_node.nimble b/nim-test-node/regression/test_node.nimble index 4deae2c..45e62bf 100644 --- a/nim-test-node/regression/test_node.nimble +++ b/nim-test-node/regression/test_node.nimble @@ -11,5 +11,5 @@ skipDirs = @[] requires "nim >= 2.2.0", "nimcrypto 0.6.4", - "https://github.com/vacp2p/nim-libp2p#26e181e4dd65188051ab4783bcc538ed9579644f", # 2.0.0 + "https://github.com/vacp2p/nim-libp2p#c470b1146fa2ef23ab88c5a0940923cf7645e9c5", # 2.1.0 "ggplotnim" \ No newline at end of file