Skip to content

Commit

Permalink
Resolve FIXMEs in src/net.cpp (pass config through CConnman)
Browse files Browse the repository at this point in the history
Summary: The config is added to CConnman so that its member functions can access it.

Test Plan:
make check
../qa/pull-tester/rpc-tests.py

Reviewers: #bitcoin_abc, sickpig, awemany, dagurval, CCulianu, freetrader

Reviewed By: #bitcoin_abc, dagurval, CCulianu

Differential Revision: https://reviews.bitcoinabc.org/D311
  • Loading branch information
ftrader authored and deadalnix committed Aug 21, 2017
1 parent 315c602 commit f17b195
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ bool AppInitMain(Config &config, boost::thread_group &threadGroup,

assert(!g_connman);
g_connman = std::unique_ptr<CConnman>(
new CConnman(GetRand(std::numeric_limits<uint64_t>::max()),
new CConnman(config, GetRand(std::numeric_limits<uint64_t>::max()),
GetRand(std::numeric_limits<uint64_t>::max())));
CConnman &connman = *g_connman;

Expand Down
15 changes: 6 additions & 9 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,7 @@ void CConnman::AcceptConnection(const ListenSocket &hListenSocket) {
pnode->AddRef();
pnode->fWhitelisted = whitelisted;

// FIXME: Pass config down rather than use GetConfig
GetNodeSignals().InitializeNode(GetConfig(), pnode, *this);
GetNodeSignals().InitializeNode(*config, pnode, *this);

LogPrint("net", "connection from %s accepted\n", addr.ToString());

Expand Down Expand Up @@ -2065,8 +2064,7 @@ bool CConnman::OpenNetworkConnection(const CAddress &addrConnect,
pnode->fAddnode = true;
}

// FIXME: Pass the config down rather than use GetConfig()
GetNodeSignals().InitializeNode(GetConfig(), pnode, *this);
GetNodeSignals().InitializeNode(*config, pnode, *this);
{
LOCK(cs_vNodes);
vNodes.push_back(pnode);
Expand Down Expand Up @@ -2094,9 +2092,8 @@ void CConnman::ThreadMessageHandler() {
}

// Receive messages
// FIXME: Pass the config down here.
bool fMoreNodeWork = GetNodeSignals().ProcessMessages(
GetConfig(), pnode, *this, flagInterruptMsgProc);
*config, pnode, *this, flagInterruptMsgProc);
fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend);
if (flagInterruptMsgProc) {
return;
Expand All @@ -2105,7 +2102,7 @@ void CConnman::ThreadMessageHandler() {
// Send messages
{
LOCK(pnode->cs_sendProcessing);
GetNodeSignals().SendMessages(GetConfig(), pnode, *this,
GetNodeSignals().SendMessages(*config, pnode, *this,
flagInterruptMsgProc);
}
if (flagInterruptMsgProc) {
Expand Down Expand Up @@ -2319,8 +2316,8 @@ void CConnman::SetNetworkActive(bool active) {
uiInterface.NotifyNetworkActiveChanged(fNetworkActive);
}

CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In)
: nSeed0(nSeed0In), nSeed1(nSeed1In) {
CConnman::CConnman(const Config &configIn, uint64_t nSeed0In, uint64_t nSeed1In)
: config(&configIn), nSeed0(nSeed0In), nSeed1(nSeed1In) {
fNetworkActive = true;
setBannedIsDirty = false;
fAddressesInitialized = false;
Expand Down
5 changes: 4 additions & 1 deletion src/net.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Copyright (c) 2017 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -149,7 +150,7 @@ class CConnman {
uint64_t nMaxOutboundTimeframe = 0;
uint64_t nMaxOutboundLimit = 0;
};
CConnman(uint64_t seed0, uint64_t seed1);
CConnman(const Config &configIn, uint64_t seed0, uint64_t seed1);
~CConnman();
bool Start(CScheduler &scheduler, std::string &strNodeError,
Options options);
Expand Down Expand Up @@ -338,6 +339,8 @@ class CConnman {
// Whether the node should be passed out in ForEach* callbacks
static bool NodeFullyConnected(const CNode *pnode);

const Config *config;

// Network usage totals
CCriticalSection cs_totalBytesRecv;
CCriticalSection cs_totalBytesSent;
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ TestingSetup::TestingSetup(const std::string &chainName)
}

// Deterministic randomness for tests.
g_connman = std::unique_ptr<CConnman>(new CConnman(0x1337, 0x1337));
g_connman = std::unique_ptr<CConnman>(new CConnman(config, 0x1337, 0x1337));
connman = g_connman.get();
RegisterNodeSignals(GetNodeSignals());
}
Expand Down

0 comments on commit f17b195

Please sign in to comment.