mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-14 11:26:09 -05:00
init: error out if -maxconnections is negative
This commit is contained in:
parent
c773649481
commit
d4c7c4009d
1 changed files with 5 additions and 3 deletions
|
@ -994,12 +994,14 @@ bool AppInitParameterInteraction(const ArgsManager& args)
|
||||||
int nBind = std::max(nUserBind, size_t(1));
|
int nBind = std::max(nUserBind, size_t(1));
|
||||||
// Maximum number of connections with other nodes, this accounts for all types of outbounds and inbounds except for manual
|
// Maximum number of connections with other nodes, this accounts for all types of outbounds and inbounds except for manual
|
||||||
int user_max_connection = args.GetIntArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
|
int user_max_connection = args.GetIntArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
|
||||||
nMaxConnections = std::max(user_max_connection, 0);
|
if (user_max_connection < 0) {
|
||||||
|
return InitError(Untranslated("-maxconnections must be greater or equal than zero"));
|
||||||
|
}
|
||||||
// Reserve enough FDs to account for the bare minimum, plus any manual connections, plus the bound interfaces
|
// Reserve enough FDs to account for the bare minimum, plus any manual connections, plus the bound interfaces
|
||||||
int min_required_fds = MIN_CORE_FDS + MAX_ADDNODE_CONNECTIONS + nBind;
|
int min_required_fds = MIN_CORE_FDS + MAX_ADDNODE_CONNECTIONS + nBind;
|
||||||
|
|
||||||
// Try raising the FD limit to what we need (available_fds may be smaller than the requested amount if this fails)
|
// Try raising the FD limit to what we need (available_fds may be smaller than the requested amount if this fails)
|
||||||
available_fds = RaiseFileDescriptorLimit(nMaxConnections + min_required_fds);
|
available_fds = RaiseFileDescriptorLimit(user_max_connection + min_required_fds);
|
||||||
// If we are using select instead of poll, our actual limit may be even smaller
|
// If we are using select instead of poll, our actual limit may be even smaller
|
||||||
#ifndef USE_POLL
|
#ifndef USE_POLL
|
||||||
available_fds = std::min(FD_SETSIZE, available_fds);
|
available_fds = std::min(FD_SETSIZE, available_fds);
|
||||||
|
@ -1008,7 +1010,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
|
||||||
return InitError(strprintf(_("Not enough file descriptors available. %d available, %d required."), available_fds, min_required_fds));
|
return InitError(strprintf(_("Not enough file descriptors available. %d available, %d required."), available_fds, min_required_fds));
|
||||||
|
|
||||||
// Trim requested connection counts, to fit into system limitations
|
// Trim requested connection counts, to fit into system limitations
|
||||||
nMaxConnections = std::min(available_fds - min_required_fds, nMaxConnections);
|
nMaxConnections = std::min(available_fds - min_required_fds, user_max_connection);
|
||||||
|
|
||||||
if (nMaxConnections < user_max_connection)
|
if (nMaxConnections < user_max_connection)
|
||||||
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), user_max_connection, nMaxConnections));
|
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), user_max_connection, nMaxConnections));
|
||||||
|
|
Loading…
Add table
Reference in a new issue