diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -145,10 +145,28 @@ std::vector vWhitelistedRange; std::vector vBinds, vWhiteBinds; }; + + void Init(const Options &connOptions) { + nLocalServices = connOptions.nLocalServices; + nRelevantServices = connOptions.nRelevantServices; + nMaxConnections = connOptions.nMaxConnections; + nMaxOutbound = + std::min(connOptions.nMaxOutbound, connOptions.nMaxConnections); + nMaxAddnode = connOptions.nMaxAddnode; + nMaxFeeler = connOptions.nMaxFeeler; + nBestHeight = connOptions.nBestHeight; + clientInterface = connOptions.uiInterface; + nSendBufferMaxSize = connOptions.nSendBufferMaxSize; + nReceiveFloodSize = connOptions.nReceiveFloodSize; + nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe; + nMaxOutboundLimit = connOptions.nMaxOutboundLimit; + vWhitelistedRange = connOptions.vWhitelistedRange; + } + CConnman(const Config &configIn, uint64_t seed0, uint64_t seed1); ~CConnman(); - bool Start(CScheduler &scheduler, Options options); + bool Start(CScheduler &scheduler, const Options &options); void Stop(); void Interrupt(); bool GetNetworkActive() const { return fNetworkActive; }; diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -2362,12 +2362,10 @@ nReceiveFloodSize = 0; semOutbound = nullptr; semAddnode = nullptr; - nMaxConnections = 0; - nMaxOutbound = 0; - nMaxAddnode = 0; - nBestHeight = 0; - clientInterface = nullptr; flagInterruptMsgProc = false; + + Options connOptions; + Init(connOptions); } NodeId CConnman::GetNewNodeId() { @@ -2409,29 +2407,14 @@ return fBound; } -bool CConnman::Start(CScheduler &scheduler, Options connOptions) { +bool CConnman::Start(CScheduler &scheduler, const Options &connOptions) { + Init(connOptions); + nTotalBytesRecv = 0; nTotalBytesSent = 0; nMaxOutboundTotalBytesSentInCycle = 0; nMaxOutboundCycleStartTime = 0; - nRelevantServices = connOptions.nRelevantServices; - nLocalServices = connOptions.nLocalServices; - nMaxConnections = connOptions.nMaxConnections; - nMaxOutbound = std::min((connOptions.nMaxOutbound), nMaxConnections); - nMaxAddnode = connOptions.nMaxAddnode; - nMaxFeeler = connOptions.nMaxFeeler; - - nSendBufferMaxSize = connOptions.nSendBufferMaxSize; - nReceiveFloodSize = connOptions.nReceiveFloodSize; - - nMaxOutboundLimit = connOptions.nMaxOutboundLimit; - nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe; - - SetBestHeight(connOptions.nBestHeight); - - clientInterface = connOptions.uiInterface; - if (fListen && !InitBinds(connOptions.vBinds, connOptions.vWhiteBinds)) { if (clientInterface) { clientInterface->ThreadSafeMessageBox( @@ -2442,8 +2425,6 @@ return false; } - vWhitelistedRange = connOptions.vWhitelistedRange; - for (const auto &strDest : connOptions.vSeedNodes) { AddOneShot(strDest); }