aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorJosh Lehan <krellan@krellan.net>2014-11-16 03:19:23 -0800
committerJosh Lehan <krellan@krellan.net>2015-06-14 02:07:15 -0700
commite3cae525382520ddbef92bf86f43eaf0521f4325 (patch)
tree15309359eda1a6cfed1a50ef74c45eaa17a04c09 /src/net.cpp
parentab0ec6790355473e96176ec3c2c2b1564ddb296d (diff)
Added -whiteconnections=<n> option
This sets aside a number of connection slots for whitelisted peers, useful for ensuring your local users and miners can always get in, even if your limit on inbound connections has already been reached.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 42ac0e50ea..541318e743 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -79,6 +79,7 @@ uint64_t nLocalHostNonce = 0;
static std::vector<ListenSocket> vhListenSocket;
CAddrMan addrman;
int nMaxConnections = 125;
+int nWhiteConnections = 0;
bool fAddressesInitialized = false;
vector<CNode*> vNodes;
@@ -827,6 +828,7 @@ void ThreadSocketHandler()
SOCKET hSocket = accept(hListenSocket.socket, (struct sockaddr*)&sockaddr, &len);
CAddress addr;
int nInbound = 0;
+ int nMaxInbound = nMaxConnections - MAX_OUTBOUND_CONNECTIONS;
if (hSocket != INVALID_SOCKET)
if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr))
@@ -846,8 +848,14 @@ void ThreadSocketHandler()
if (nErr != WSAEWOULDBLOCK)
LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr));
}
- else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS)
+ else if (nInbound >= nMaxInbound)
{
+ LogPrint("net", "connection from %s dropped (full)\n", addr.ToString());
+ CloseSocket(hSocket);
+ }
+ else if (!whitelisted && (nInbound >= (nMaxInbound - nWhiteConnections)))
+ {
+ LogPrint("net", "connection from %s dropped (non-whitelisted)\n", addr.ToString());
CloseSocket(hSocket);
}
else if (CNode::IsBanned(addr) && !whitelisted)
@@ -861,6 +869,8 @@ void ThreadSocketHandler()
pnode->AddRef();
pnode->fWhitelisted = whitelisted;
+ LogPrint("net", "connection from %s accepted\n", addr.ToString());
+
{
LOCK(cs_vNodes);
vNodes.push_back(pnode);