upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/main_gui.cpp
diff options
context:
space:
mode:
authorBitflash <btf01@proton.me>2026-07-29 12:45:48 -0300
committerGitHub <noreply@github.com>2026-07-29 12:45:48 -0300
commit1227068a504418521f3238acf9c4dca297141d27 (patch)
tree096e1dfb472e09783cb1a1fba1ab4961111bdfb5 /src/main_gui.cpp
parent137a166fe0b95ccdef444041e907358bd26bc226 (diff)
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.
Diffstat (limited to 'src/main_gui.cpp')
-rw-r--r--src/main_gui.cpp20
1 files changed, 20 insertions, 0 deletions
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()
59 printf(" /rvrelay=HOST:PORT\n"); 59 printf(" /rvrelay=HOST:PORT\n");
60 printf(" /announcerelay=HOST:PORT\n"); 60 printf(" /announcerelay=HOST:PORT\n");
61 printf("\n"); 61 printf("\n");
62 printf("Network:\n");
63 printf(" /port=N (P2P listen port, default 8433)\n");
64 printf("\n");
62 printf("Each option also accepts '-' instead of '/'.\n"); 65 printf("Each option also accepts '-' instead of '/'.\n");
63} 66}
64 67
@@ -113,6 +116,23 @@ static void ParseStartupArguments(int argc, char* argv[])
113 string announceRelay = argval2(argc, argv, "/announcerelay", "-announcerelay"); 116 string announceRelay = argval2(argc, argv, "/announcerelay", "-announcerelay");
114 if (!announceRelay.empty()) 117 if (!announceRelay.empty())
115 strBtfAnnounceRelay = announceRelay; 118 strBtfAnnounceRelay = announceRelay;
119
120 // net.cpp has described nListenPort as "tunable via /port" since it was
121 // written, but nothing ever read the option, so the port was fixed at 8433
122 // and a second node could not start on a machine already running one.
123 string strPort = argval2(argc, argv, "/port", "-port");
124 if (!strPort.empty())
125 {
126 int nPort = atoi(strPort.c_str());
127 if (nPort <= 0 || nPort > 65535)
128 fprintf(stderr, "Ignoring /port=%s: not a port number\n", strPort.c_str());
129 else
130 {
131 nListenPort = htons((unsigned short)nPort);
132 // Or we would announce a port we never bound.
133 addrLocalHost.port = nListenPort;
134 }
135 }
116} 136}
117 137
118int main(int argc, char* argv[]) 138int main(int argc, char* argv[])