mirror of
https://github.com/vacp2p/dst-libp2p-test-node.git
synced 2026-08-27 12:51:12 +00:00
Pin nim-libp2p v2.1.0 + Shadow self-IP for v2.1.0 regression
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
c49227c6bc
commit
68818fac7f
@@ -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")
|
||||
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user