aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2016-05-26 23:53:08 -0400
committerCory Fields <cory-nospam-@coryfields.com>2016-09-08 13:04:29 -0400
commita19553b992f40b9f98e6e0be4cd529a89746ef50 (patch)
tree7d8bdf280d59714df83e438324867ff374d15bb6 /src
parentbafa5fc5a1ba33337b5eb3d8ae24ba2fac2949f8 (diff)
downloadbitcoin-a19553b992f40b9f98e6e0be4cd529a89746ef50.tar.xz
net: Introduce CConnection::Options to avoid passing so many params
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp11
-rw-r--r--src/net.cpp14
-rw-r--r--src/net.h11
3 files changed, 26 insertions, 10 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 4e1c8e1b61..e108036439 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1515,8 +1515,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
MapPort(GetBoolArg("-upnp", DEFAULT_UPNP));
std::string strNodeError;
- int nMaxOutbound = std::min(MAX_OUTBOUND_CONNECTIONS, nMaxConnections);
- if(!connman.Start(threadGroup, scheduler, nLocalServices, nRelevantServices, nMaxConnections, nMaxOutbound, chainActive.Height(), &uiInterface, strNodeError))
+ CConnman::Options connOptions;
+ connOptions.nLocalServices = nLocalServices;
+ connOptions.nRelevantServices = nRelevantServices;
+ connOptions.nMaxConnections = nMaxConnections;
+ connOptions.nMaxOutbound = std::min(MAX_OUTBOUND_CONNECTIONS, connOptions.nMaxConnections);
+ connOptions.nBestHeight = chainActive.Height();
+ connOptions.uiInterface = &uiInterface;
+
+ if(!connman.Start(threadGroup, scheduler, strNodeError, connOptions))
return InitError(strNodeError);
// ********************************************************* Step 12: finished
diff --git a/src/net.cpp b/src/net.cpp
index 15c066cd7c..8ea600b371 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2049,26 +2049,26 @@ NodeId CConnman::GetNewNodeId()
return nLastNodeId.fetch_add(1, std::memory_order_relaxed);
}
-bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServicesIn, ServiceFlags nRelevantServicesIn, int nMaxConnectionsIn, int nMaxOutboundIn, int nBestHeightIn, CClientUIInterface* interfaceIn, std::string& strNodeError)
+bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, std::string& strNodeError, Options connOptions)
{
nTotalBytesRecv = 0;
nTotalBytesSent = 0;
nMaxOutboundLimit = 0;
nMaxOutboundTotalBytesSentInCycle = 0;
nMaxOutboundTimeframe = 60*60*24; //1 day
- nLocalServices = nLocalServicesIn;
- nRelevantServices = nRelevantServicesIn;
nMaxOutboundCycleStartTime = 0;
- nMaxConnections = nMaxConnectionsIn;
- nMaxOutbound = std::min((nMaxOutboundIn), nMaxConnections);
+ nRelevantServices = connOptions.nRelevantServices;
+ nLocalServices = connOptions.nLocalServices;
+ nMaxConnections = connOptions.nMaxConnections;
+ nMaxOutbound = std::min((connOptions.nMaxOutbound), nMaxConnections);
nSendBufferMaxSize = 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
nReceiveFloodSize = 1000*GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);
- SetBestHeight(nBestHeightIn);
+ SetBestHeight(connOptions.nBestHeight);
- clientInterface = interfaceIn;
+ clientInterface = connOptions.uiInterface;
if (clientInterface)
clientInterface->InitMessage(_("Loading addresses..."));
// Load addresses from peers.dat
diff --git a/src/net.h b/src/net.h
index e08409e81e..8067ee68a7 100644
--- a/src/net.h
+++ b/src/net.h
@@ -109,9 +109,18 @@ public:
CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT),
};
+ struct Options
+ {
+ ServiceFlags nLocalServices = NODE_NONE;
+ ServiceFlags nRelevantServices = NODE_NONE;
+ int nMaxConnections = 0;
+ int nMaxOutbound = 0;
+ int nBestHeight = 0;
+ CClientUIInterface* uiInterface = nullptr;
+ };
CConnman();
~CConnman();
- bool Start(boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServicesIn, ServiceFlags nRelevantServicesIn, int nMaxConnectionsIn, int nMaxOutboundIn, int nBestHeightIn, CClientUIInterface* interfaceIn, std::string& strNodeError);
+ bool Start(boost::thread_group& threadGroup, CScheduler& scheduler, std::string& strNodeError, Options options);
void Stop();
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);