fix flag/ref order + cs_vNodes in ConnectNode (#1300)
* fix flag/ref order * hold cs_vNodes in ConnectNode a little bit longer * fix
This commit is contained in:
parent
c8466cfb04
commit
3bfa5392fa
@ -392,6 +392,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fConnectToMas
|
|||||||
if (IsLocal(addrConnect) && !fConnectToMasternode)
|
if (IsLocal(addrConnect) && !fConnectToMasternode)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
LOCK(cs_vNodes);
|
||||||
// Look for an existing connection
|
// Look for an existing connection
|
||||||
CNode* pnode = FindNode((CService)addrConnect);
|
CNode* pnode = FindNode((CService)addrConnect);
|
||||||
if (pnode)
|
if (pnode)
|
||||||
@ -399,8 +400,8 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fConnectToMas
|
|||||||
// we have existing connection to this node but it was not a connection to masternode,
|
// we have existing connection to this node but it was not a connection to masternode,
|
||||||
// change flag and add reference so that we can correctly clear it later
|
// change flag and add reference so that we can correctly clear it later
|
||||||
if(fConnectToMasternode && !pnode->fMasternode) {
|
if(fConnectToMasternode && !pnode->fMasternode) {
|
||||||
pnode->fMasternode = true;
|
|
||||||
pnode->AddRef();
|
pnode->AddRef();
|
||||||
|
pnode->fMasternode = true;
|
||||||
}
|
}
|
||||||
return pnode;
|
return pnode;
|
||||||
}
|
}
|
||||||
@ -428,15 +429,13 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fConnectToMas
|
|||||||
// Add node
|
// Add node
|
||||||
CNode* pnode = new CNode(hSocket, addrConnect, pszDest ? pszDest : "", false, true);
|
CNode* pnode = new CNode(hSocket, addrConnect, pszDest ? pszDest : "", false, true);
|
||||||
|
|
||||||
{
|
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
vNodes.push_back(pnode);
|
vNodes.push_back(pnode);
|
||||||
}
|
|
||||||
|
|
||||||
pnode->nTimeConnected = GetTime();
|
pnode->nTimeConnected = GetTime();
|
||||||
if(fConnectToMasternode) {
|
if(fConnectToMasternode) {
|
||||||
pnode->fMasternode = true;
|
|
||||||
pnode->AddRef();
|
pnode->AddRef();
|
||||||
|
pnode->fMasternode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pnode;
|
return pnode;
|
||||||
|
Loading…
Reference in New Issue
Block a user