From 1227068a504418521f3238acf9c4dca297141d27 Mon Sep 17 00:00:00 2001 From: Bitflash Date: Wed, 29 Jul 2026 12:45:48 -0300 Subject: main_gui: implement /port, which net.cpp already documented (#28) net.cpp has described nListenPort as "tunable via /port" since it was written: unsigned short nListenPort = DEFAULT_PORT; // local P2P port (tunable via /port) Nothing ever parsed the option. The port was fixed at 8433, so a second node could not start on a machine already running one -- StartNode fails the bind and the node comes up with no networking at all. That makes local multi-node testing impossible, which is how this was found: a two-node test could not be run. Sets addrLocalHost.port alongside nListenPort, or the node announces a port it never bound. An out-of-range value is rejected with a message and the default kept, rather than silently wrapping through the unsigned short cast. --- src/main_gui.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/main_gui.cpp') diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 842b0d5..63bdbb7 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -59,6 +59,9 @@ static void PrintUsage() printf(" /rvrelay=HOST:PORT\n"); printf(" /announcerelay=HOST:PORT\n"); printf("\n"); + printf("Network:\n"); + printf(" /port=N (P2P listen port, default 8433)\n"); + printf("\n"); printf("Each option also accepts '-' instead of '/'.\n"); } @@ -113,6 +116,23 @@ static void ParseStartupArguments(int argc, char* argv[]) string announceRelay = argval2(argc, argv, "/announcerelay", "-announcerelay"); if (!announceRelay.empty()) strBtfAnnounceRelay = announceRelay; + + // net.cpp has described nListenPort as "tunable via /port" since it was + // written, but nothing ever read the option, so the port was fixed at 8433 + // and a second node could not start on a machine already running one. + string strPort = argval2(argc, argv, "/port", "-port"); + if (!strPort.empty()) + { + int nPort = atoi(strPort.c_str()); + if (nPort <= 0 || nPort > 65535) + fprintf(stderr, "Ignoring /port=%s: not a port number\n", strPort.c_str()); + else + { + nListenPort = htons((unsigned short)nPort); + // Or we would announce a port we never bound. + addrLocalHost.port = nListenPort; + } + } } int main(int argc, char* argv[]) -- cgit v1.2.3