Skip to content

Commit

Permalink
[misc] Moved peer-limiting to mc
Browse files Browse the repository at this point in the history
  • Loading branch information
giaki3003 committed Nov 26, 2019
1 parent d9880ed commit aba5fe2
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 74 deletions.
1 change: 0 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ std::string HelpMessage(HelpMessageMode mode)

strUsage += HelpMessageGroup(_("Connection options:"));
strUsage += HelpMessageOpt("-addnode=<ip>", _("Add a node to connect to and attempt to keep the connection open"));
strUsage += HelpMessageOpt("-peerlimit=<n>", _("limit the number of peers used while syncing to increase syncing speed. (limit removed after wallet is synced)"));
strUsage += HelpMessageOpt("-banscore=<n>", strprintf(_("Threshold for disconnecting misbehaving peers (default: %u)"), 100));
strUsage += HelpMessageOpt("-bantime=<n>", strprintf(_("Number of seconds to keep misbehaving peers from reconnecting (default: %u)"), 86400));
strUsage += HelpMessageOpt("-bind=<addr>", _("Bind to given address and always listen on it. Use [host]:port notation for IPv6"));
Expand Down
58 changes: 0 additions & 58 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,59 +1577,6 @@ void ThreadOpenAddedConnections()
}
}
MilliSleep(120000); // Retry every 2 minutes

}
}

double getVerificationProgress(const CBlockIndex *tipIn) // here to avoid include loops
{
CBlockIndex *tip = const_cast<CBlockIndex *>(tipIn);
if (!tip)
{
LOCK(cs_main);
tip = chainActive.Tip();
}
return Checkpoints::GuessVerificationProgress(Params().Checkpoints(), tip);
}

void limit_peers(int i);
void Threadlimitpeers(){

if(mapArgs.count("-peerlimit")){ // don't read what is not readable
std::string str = mapArgs["-peerlimit"];
int num = std::stoi( str );

if (num==0){ // peer sync limit off. mapArgs should do the job but, peerlimit=0 is more reassuring to the user then peerlimit not being there
return;
}

if (num <= 3){ // don't allow less then 4 peers
num = 4;
}

for ( ; getVerificationProgress(NULL) < 0.999 ; ){ // 99.9%
limit_peers(num);
MilliSleep(1000);
}
}
}

void limit_peers(int i)
{
i--;
LOCK(cs_main);
vector<CNodeStats> vstats;
CopyNodeStats_h(vstats);
int k = 0;
for (CNodeStats& stats : vstats) {

if (i < k){
string strNode = stats.addrName;
CNode *bannedNode = FindNode(strNode);
bannedNode->CloseSocketDisconnect();
}
k++;

}
}

Expand Down Expand Up @@ -1943,11 +1890,6 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler) {
// Process messages
threadGroup.create_thread(boost::bind(&TraceThread<void (*)()>, "msghand", &ThreadMessageHandler));

// peer limiting
threadGroup.create_thread(boost::bind(&TraceThread<void (*)()>, "peer_limit", &Threadlimitpeers));



// Dump network addresses every 900 secs
// The second input is milliseconds. So, we must re-calculate the input time interval
scheduler.scheduleEvery(&DumpData, DUMP_ADDRESSES_INTERVAL * 1000);
Expand Down
1 change: 0 additions & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ class CNodeStats
std::string addrLocal;
};

void CopyNodeStats_h(std::vector<CNodeStats>& vstats);

class CNetMessage
{
Expand Down
14 changes: 0 additions & 14 deletions src/rpcnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,6 @@ static void CopyNodeStats(std::vector<CNodeStats>& vstats)
}
}

void CopyNodeStats_h(std::vector<CNodeStats>& vstats)
{
vstats.clear();

LOCK(cs_vNodes);
vstats.reserve(vNodes.size());
for (CNode* pnode : vNodes) {
if (!pnode) continue;
CNodeStats stats;
pnode->copyStats(stats);
vstats.push_back(stats);
}
}

UniValue getpeerinfo(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
Expand Down

0 comments on commit aba5fe2

Please sign in to comment.