Skip to content

Commit

Permalink
Qt: Ask user to use standard port on startup if specified port is in use
Browse files Browse the repository at this point in the history
If the port (specified by -port or GUI setting) is already in use when
starting the GUI client, and it's not the standard port, ask the user if
they want to listen via the standard network port instead.

Github-Pull: bitcoin#7107
Rebased-From: 1f37c87
  • Loading branch information
hsjoberg authored and luke-jr committed Nov 6, 2018
1 parent e12b747 commit 5542d56
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/net.cpp
Expand Up @@ -2258,6 +2258,27 @@ bool CConnman::InitBinds(const std::vector<CService>& binds, const std::vector<C
struct in6_addr inaddr6_any = IN6ADDR_ANY_INIT;
fBound |= Bind(CService(inaddr6_any, GetListenPort()), BF_NONE);
fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound ? BF_REPORT_ERROR : BF_NONE);

if (!fBound) {
int defaultPort = Params().GetDefaultPort();
// If listening failed and another port than the standard port was specified,
// ask if the user wants to connect via the standard port for the network instead
if (GetListenPort() != defaultPort) {
bool fRet = uiInterface.ThreadSafeQuestion(
_("Do you want to use the standard network port for ") + _(PACKAGE_NAME) + " (port " + i64tostr(defaultPort) + ") instead?",
_("Listen on port ") + i64tostr(GetListenPort()) + _(" failed."),
"", CClientUIInterface::MSG_INFORMATION | CClientUIInterface::MODAL | CClientUIInterface::BTN_OK | CClientUIInterface::BTN_ABORT);

if (fRet) {
gArgs.ForceSetArg("-port", defaultPort);
// Attempt to use standard port
struct in_addr inaddr_any;
inaddr_any.s_addr = INADDR_ANY;
fBound |= Bind(CService(in6addr_any, defaultPort), BF_NONE);
fBound |= Bind(CService(inaddr_any, defaultPort), BF_NONE);
}
}
}
}
return fBound;
}
Expand Down

0 comments on commit 5542d56

Please sign in to comment.