Few networking fixes (#1341)

* Few networking fixes:
- skip "masternode"/inbound connections for sync related processes
- do not sync gov data to other nodes until fully synced ourselves
- do not accept incoming connections until fully synced

* inbound connections could be harmful only if our node is a masternode

* same for CGovernanceManager::Sync
This commit is contained in:
UdjinM6 2017-02-16 19:14:42 +04:00 committed by GitHub
parent 23fa1f5f13
commit 80b71d9746
3 changed files with 21 additions and 3 deletions

View File

@ -665,6 +665,9 @@ void CGovernanceManager::Sync(CNode* pfrom, const uint256& nProp, const CBloomFi
budget object to see if they're OK. If all checks pass, we'll send it to the peer.
*/
// do not provide any data until our node is synced
if(fMasterNode && !masternodeSync.IsSynced()) return;
int nObjCount = 0;
int nVoteCount = 0;
@ -1045,9 +1048,11 @@ void CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
}
bool fAsked = false;
BOOST_FOREACH(CNode* pnode, vNodesCopy) {
// only use reqular peers, don't try to ask from temporary nodes we connected to -
// they stay connected for a short period of time and it's possible that we won't get everything we should
if(pnode->fMasternode) continue;
// Only use reqular peers, don't try to ask from outbound "masternode" connections -
// they stay connected for a short period of time and it's possible that we won't get everything we should.
// Only use outbound connections - inbound connection could be a "masternode" connection
// initialted from another node, so skip it too.
if(pnode->fMasternode || (fMasterNode && pnode->fInbound)) continue;
// only use up to date peers
if(pnode->nVersion < MIN_GOVERNANCE_PEER_PROTO_VERSION) continue;
// stop early to prevent setAskFor overflow

View File

@ -334,6 +334,12 @@ void CMasternodeSync::ProcessTick()
BOOST_FOREACH(CNode* pnode, vNodesCopy)
{
// Don't try to sync any data from outbound "masternode" connections -
// they are temporary and should be considered unreliable for a sync process.
// Inbound connection this early is most likely a "masternode" connection
// initialted from another node, so skip it too.
if(pnode->fMasternode || (fMasterNode && pnode->fInbound)) continue;
// QUICK MODE (REGTEST ONLY!)
if(Params().NetworkIDString() == CBaseChainParams::REGTEST)
{

View File

@ -24,6 +24,7 @@
#include "darksend.h"
#include "instantx.h"
#include "masternode-sync.h"
#include "masternodeman.h"
#ifdef WIN32
@ -962,6 +963,12 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
}
static void AcceptConnection(const ListenSocket& hListenSocket) {
// don't accept incoming connections until fully synced
if(fMasterNode && !masternodeSync.IsSynced()) {
LogPrintf("AcceptConnection -- masternode is not synced yet, skipping inbound connection attempt\n");
return;
}
struct sockaddr_storage sockaddr;
socklen_t len = sizeof(sockaddr);
SOCKET hSocket = accept(hListenSocket.socket, (struct sockaddr*)&sockaddr, &len);