always make 8 outbound connections even if have inbound,
limit one outbound connection per a.b.?.? range, switch -maxconnections=# git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@125 1a98c847-1fd6-4fd8-948a-caf3550aa51b
This commit is contained in:
parent
e6b7ab5749
commit
94cfec07fd
2
main.cpp
2
main.cpp
@ -885,7 +885,7 @@ void Lockdown(CBlockIndex* pindexNew)
|
|||||||
printf("Lockdown: current best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,22).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());
|
printf("Lockdown: current best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,22).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());
|
||||||
printf("Lockdown: IsLockdown()=%d\n", (IsLockdown() ? 1 : 0));
|
printf("Lockdown: IsLockdown()=%d\n", (IsLockdown() ? 1 : 0));
|
||||||
if (IsLockdown())
|
if (IsLockdown())
|
||||||
printf("Lockdown: WARNING: Displayed transactions may not be correct! You may need to upgrade.\n");
|
printf("Lockdown: WARNING: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
28
net.cpp
28
net.cpp
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "headers.h"
|
#include "headers.h"
|
||||||
|
|
||||||
|
static const int MAX_OUTBOUND_CONNECTIONS = 8;
|
||||||
|
|
||||||
void ThreadMessageHandler2(void* parg);
|
void ThreadMessageHandler2(void* parg);
|
||||||
void ThreadSocketHandler2(void* parg);
|
void ThreadSocketHandler2(void* parg);
|
||||||
void ThreadOpenConnections2(void* parg);
|
void ThreadOpenConnections2(void* parg);
|
||||||
@ -653,6 +655,10 @@ void ThreadSocketHandler2(void* parg)
|
|||||||
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
||||||
printf("socket error accept failed: %d\n", WSAGetLastError());
|
printf("socket error accept failed: %d\n", WSAGetLastError());
|
||||||
}
|
}
|
||||||
|
else if (mapArgs.count("-maxconnections") && (int)vNodes.size() >= atoi(mapArgs["-maxconnections"]) - MAX_OUTBOUND_CONNECTIONS)
|
||||||
|
{
|
||||||
|
closesocket(hSocket);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("accepted connection %s\n", addr.ToStringLog().c_str());
|
printf("accepted connection %s\n", addr.ToStringLog().c_str());
|
||||||
@ -879,12 +885,21 @@ void ThreadOpenConnections2(void* parg)
|
|||||||
int64 nStart = GetTime();
|
int64 nStart = GetTime();
|
||||||
loop
|
loop
|
||||||
{
|
{
|
||||||
// Wait
|
// Limit outbound connections
|
||||||
vnThreadsRunning[1]--;
|
vnThreadsRunning[1]--;
|
||||||
Sleep(500);
|
Sleep(500);
|
||||||
const int nMaxConnections = 8;
|
loop
|
||||||
while (vNodes.size() >= nMaxConnections)
|
|
||||||
{
|
{
|
||||||
|
int nOutbound = 0;
|
||||||
|
CRITICAL_BLOCK(cs_vNodes)
|
||||||
|
foreach(CNode* pnode, vNodes)
|
||||||
|
if (!pnode->fInbound)
|
||||||
|
nOutbound++;
|
||||||
|
int nMaxOutboundConnections = MAX_OUTBOUND_CONNECTIONS;
|
||||||
|
if (mapArgs.count("-maxconnections"))
|
||||||
|
nMaxOutboundConnections = min(nMaxOutboundConnections, atoi(mapArgs["-maxconnections"]));
|
||||||
|
if (nOutbound < nMaxOutboundConnections)
|
||||||
|
break;
|
||||||
Sleep(2000);
|
Sleep(2000);
|
||||||
if (fShutdown)
|
if (fShutdown)
|
||||||
return;
|
return;
|
||||||
@ -948,18 +963,19 @@ void ThreadOpenConnections2(void* parg)
|
|||||||
CAddress addrConnect;
|
CAddress addrConnect;
|
||||||
int64 nBest = INT64_MIN;
|
int64 nBest = INT64_MIN;
|
||||||
|
|
||||||
// Do this here so we don't have to critsect vNodes inside mapAddresses critsect
|
// Only connect to one address per a.b.?.? range.
|
||||||
|
// Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
|
||||||
set<unsigned int> setConnected;
|
set<unsigned int> setConnected;
|
||||||
CRITICAL_BLOCK(cs_vNodes)
|
CRITICAL_BLOCK(cs_vNodes)
|
||||||
foreach(CNode* pnode, vNodes)
|
foreach(CNode* pnode, vNodes)
|
||||||
setConnected.insert(pnode->addr.ip);
|
setConnected.insert(pnode->addr.ip & 0x0000ffff);
|
||||||
|
|
||||||
CRITICAL_BLOCK(cs_mapAddresses)
|
CRITICAL_BLOCK(cs_mapAddresses)
|
||||||
{
|
{
|
||||||
foreach(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses)
|
foreach(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses)
|
||||||
{
|
{
|
||||||
const CAddress& addr = item.second;
|
const CAddress& addr = item.second;
|
||||||
if (!addr.IsIPv4() || !addr.IsValid() || setConnected.count(addr.ip))
|
if (!addr.IsIPv4() || !addr.IsValid() || setConnected.count(addr.ip & 0x0000ffff))
|
||||||
continue;
|
continue;
|
||||||
int64 nSinceLastSeen = GetAdjustedTime() - addr.nTime;
|
int64 nSinceLastSeen = GetAdjustedTime() - addr.nTime;
|
||||||
int64 nSinceLastTry = GetAdjustedTime() - addr.nLastTry;
|
int64 nSinceLastTry = GetAdjustedTime() - addr.nLastTry;
|
||||||
|
@ -20,7 +20,7 @@ class CDataStream;
|
|||||||
class CAutoFile;
|
class CAutoFile;
|
||||||
|
|
||||||
static const int VERSION = 308;
|
static const int VERSION = 308;
|
||||||
static const char* pszSubVer = ".1";
|
static const char* pszSubVer = ".2";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
2
ui.cpp
2
ui.cpp
@ -1015,7 +1015,7 @@ void CMainFrame::OnPaintListCtrl(wxPaintEvent& event)
|
|||||||
// Update status bar
|
// Update status bar
|
||||||
static bool fPrevLockdown;
|
static bool fPrevLockdown;
|
||||||
if (IsLockdown())
|
if (IsLockdown())
|
||||||
m_statusBar->SetStatusText(string(" ") + _("WARNING: Displayed transactions may not be correct! You may need to upgrade."), 0);
|
m_statusBar->SetStatusText(string(" ") + _("WARNING: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade."), 0);
|
||||||
else if (fPrevLockdown)
|
else if (fPrevLockdown)
|
||||||
m_statusBar->SetStatusText("", 0);
|
m_statusBar->SetStatusText("", 0);
|
||||||
fPrevLockdown = IsLockdown();
|
fPrevLockdown = IsLockdown();
|
||||||
|
Loading…
Reference in New Issue
Block a user