Skip to content

Commit 36966a1

Browse files
committed
Merge #9626: Clean up a few CConnman cs_vNodes/CNode things
2366180 Do not add to vNodes until fOneShot/fFeeler/fAddNode have been set (Matt Corallo) 3c37dc4 Ensure cs_vNodes is held when using the return value from FindNode (Matt Corallo) 5be0190 Delete some unused (and broken) functions in CConnman (Matt Corallo)
2 parents d2c9e4d + 2366180 commit 36966a1

File tree

2 files changed

+14
-46
lines changed

2 files changed

+14
-46
lines changed

src/net.cpp

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
342342
CNode* pnode = FindNode((CService)addrConnect);
343343
if (pnode)
344344
{
345-
pnode->AddRef();
346-
return pnode;
345+
LogPrintf("Failed to open new connection, already connected\n");
346+
return NULL;
347347
}
348348
}
349349

@@ -369,18 +369,16 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
369369
// In that case, drop the connection that was just created, and return the existing CNode instead.
370370
// Also store the name we used to connect in that CNode, so that future FindNode() calls to that
371371
// name catch this early.
372+
LOCK(cs_vNodes);
372373
CNode* pnode = FindNode((CService)addrConnect);
373374
if (pnode)
374375
{
375-
pnode->AddRef();
376-
{
377-
LOCK(cs_vNodes);
378-
if (pnode->addrName.empty()) {
379-
pnode->addrName = std::string(pszDest);
380-
}
376+
if (pnode->addrName.empty()) {
377+
pnode->addrName = std::string(pszDest);
381378
}
382379
CloseSocket(hSocket);
383-
return pnode;
380+
LogPrintf("Failed to open new connection, already connected\n");
381+
return NULL;
384382
}
385383
}
386384

@@ -393,11 +391,6 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
393391
pnode->nServicesExpected = ServiceFlags(addrConnect.nServices & nRelevantServices);
394392
pnode->nTimeConnected = GetSystemTimeInSeconds();
395393
pnode->AddRef();
396-
GetNodeSignals().InitializeNode(pnode, *this);
397-
{
398-
LOCK(cs_vNodes);
399-
vNodes.push_back(pnode);
400-
}
401394

402395
return pnode;
403396
} else if (!proxyConnectionFailed) {
@@ -1840,6 +1833,12 @@ bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
18401833
if (fAddnode)
18411834
pnode->fAddnode = true;
18421835

1836+
{
1837+
LOCK(cs_vNodes);
1838+
vNodes.push_back(pnode);
1839+
}
1840+
GetNodeSignals().InitializeNode(pnode, *this);
1841+
18431842
return true;
18441843
}
18451844

@@ -2371,26 +2370,9 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats)
23712370
}
23722371
}
23732372

2374-
bool CConnman::DisconnectAddress(const CNetAddr& netAddr)
2375-
{
2376-
if (CNode* pnode = FindNode(netAddr)) {
2377-
pnode->fDisconnect = true;
2378-
return true;
2379-
}
2380-
return false;
2381-
}
2382-
2383-
bool CConnman::DisconnectSubnet(const CSubNet& subNet)
2384-
{
2385-
if (CNode* pnode = FindNode(subNet)) {
2386-
pnode->fDisconnect = true;
2387-
return true;
2388-
}
2389-
return false;
2390-
}
2391-
23922373
bool CConnman::DisconnectNode(const std::string& strNode)
23932374
{
2375+
LOCK(cs_vNodes);
23942376
if (CNode* pnode = FindNode(strNode)) {
23952377
pnode->fDisconnect = true;
23962378
return true;
@@ -2409,16 +2391,6 @@ bool CConnman::DisconnectNode(NodeId id)
24092391
return false;
24102392
}
24112393

2412-
void CConnman::RelayTransaction(const CTransaction& tx)
2413-
{
2414-
CInv inv(MSG_TX, tx.GetHash());
2415-
LOCK(cs_vNodes);
2416-
BOOST_FOREACH(CNode* pnode, vNodes)
2417-
{
2418-
pnode->PushInventory(inv);
2419-
}
2420-
}
2421-
24222394
void CConnman::RecordBytesRecv(uint64_t bytes)
24232395
{
24242396
LOCK(cs_totalBytesRecv);

src/net.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ class CConnman
243243
post();
244244
};
245245

246-
void RelayTransaction(const CTransaction& tx);
247-
248246
// Addrman functions
249247
size_t GetAddressCount() const;
250248
void SetServices(const CService &addr, ServiceFlags nServices);
@@ -286,10 +284,8 @@ class CConnman
286284

287285
size_t GetNodeCount(NumConnections num);
288286
void GetNodeStats(std::vector<CNodeStats>& vstats);
289-
bool DisconnectAddress(const CNetAddr& addr);
290287
bool DisconnectNode(const std::string& node);
291288
bool DisconnectNode(NodeId id);
292-
bool DisconnectSubnet(const CSubNet& subnet);
293289

294290
unsigned int GetSendBufferSize() const;
295291

0 commit comments

Comments
 (0)