Browse Source

net: pass CClientUIInterface into CConnman

0.14
Cory Fields 9 years ago
parent
commit
e81a602cf0
  1. 2
      src/init.cpp
  2. 27
      src/net.cpp
  3. 7
      src/net.h

2
src/init.cpp

@ -1510,7 +1510,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
std::string strNodeError; std::string strNodeError;
int nMaxOutbound = std::min(MAX_OUTBOUND_CONNECTIONS, nMaxConnections); int nMaxOutbound = std::min(MAX_OUTBOUND_CONNECTIONS, nMaxConnections);
if(!StartNode(connman, threadGroup, scheduler, nLocalServices, nRelevantServices, nMaxConnections, nMaxOutbound, chainActive.Height(), strNodeError)) if(!StartNode(connman, threadGroup, scheduler, nLocalServices, nRelevantServices, nMaxConnections, nMaxOutbound, chainActive.Height(), &uiInterface, strNodeError))
return InitError(strNodeError); return InitError(strNodeError);
// ********************************************************* Step 12: finished // ********************************************************* Step 12: finished

27
src/net.cpp

@ -474,7 +474,8 @@ void CConnman::ClearBanned()
setBannedIsDirty = true; setBannedIsDirty = true;
} }
DumpBanlist(); //store banlist to disk DumpBanlist(); //store banlist to disk
uiInterface.BannedListChanged(); if(clientInterface)
clientInterface->BannedListChanged();
} }
bool CConnman::IsBanned(CNetAddr ip) bool CConnman::IsBanned(CNetAddr ip)
@ -534,7 +535,8 @@ void CConnman::Ban(const CSubNet& subNet, const BanReason &banReason, int64_t ba
else else
return; return;
} }
uiInterface.BannedListChanged(); if(clientInterface)
clientInterface->BannedListChanged();
{ {
LOCK(cs_vNodes); LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes) { BOOST_FOREACH(CNode* pnode, vNodes) {
@ -558,7 +560,8 @@ bool CConnman::Unban(const CSubNet &subNet) {
return false; return false;
setBannedIsDirty = true; setBannedIsDirty = true;
} }
uiInterface.BannedListChanged(); if(clientInterface)
clientInterface->BannedListChanged();
DumpBanlist(); //store banlist to disk immediately DumpBanlist(); //store banlist to disk immediately
return true; return true;
} }
@ -1104,7 +1107,8 @@ void CConnman::ThreadSocketHandler()
} }
if(vNodes.size() != nPrevNodeCount) { if(vNodes.size() != nPrevNodeCount) {
nPrevNodeCount = vNodes.size(); nPrevNodeCount = vNodes.size();
uiInterface.NotifyNumConnectionsChanged(nPrevNodeCount); if(clientInterface)
clientInterface->NotifyNumConnectionsChanged(nPrevNodeCount);
} }
// //
@ -2037,13 +2041,14 @@ CConnman::CConnman()
nMaxConnections = 0; nMaxConnections = 0;
nMaxOutbound = 0; nMaxOutbound = 0;
nBestHeight = 0; nBestHeight = 0;
clientInterface = NULL;
} }
bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServices, ServiceFlags nRelevantServices, int nMaxConnectionsIn, int nMaxOutboundIn, int nBestHeightIn, std::string& strNodeError) bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServices, ServiceFlags nRelevantServices, int nMaxConnectionsIn, int nMaxOutboundIn, int nBestHeightIn, CClientUIInterface* interfaceIn, std::string& strNodeError)
{ {
Discover(threadGroup); Discover(threadGroup);
bool ret = connman.Start(threadGroup, scheduler, nLocalServices, nRelevantServices, nMaxConnectionsIn, nMaxOutboundIn, nBestHeightIn, strNodeError); bool ret = connman.Start(threadGroup, scheduler, nLocalServices, nRelevantServices, nMaxConnectionsIn, nMaxOutboundIn, nBestHeightIn, interfaceIn, strNodeError);
return ret; return ret;
} }
@ -2053,7 +2058,7 @@ NodeId CConnman::GetNewNodeId()
return nLastNodeId.fetch_add(1, std::memory_order_relaxed); 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, std::string& strNodeError) bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServicesIn, ServiceFlags nRelevantServicesIn, int nMaxConnectionsIn, int nMaxOutboundIn, int nBestHeightIn, CClientUIInterface* interfaceIn, std::string& strNodeError)
{ {
nTotalBytesRecv = 0; nTotalBytesRecv = 0;
nTotalBytesSent = 0; nTotalBytesSent = 0;
@ -2072,7 +2077,9 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, Se
SetBestHeight(nBestHeightIn); SetBestHeight(nBestHeightIn);
uiInterface.InitMessage(_("Loading addresses...")); clientInterface = interfaceIn;
if (clientInterface)
clientInterface->InitMessage(_("Loading addresses..."));
// Load addresses from peers.dat // Load addresses from peers.dat
int64_t nStart = GetTimeMillis(); int64_t nStart = GetTimeMillis();
{ {
@ -2085,8 +2092,8 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, Se
DumpAddresses(); DumpAddresses();
} }
} }
if (clientInterface)
uiInterface.InitMessage(_("Loading banlist...")); clientInterface->InitMessage(_("Loading banlist..."));
// Load addresses from banlist.dat // Load addresses from banlist.dat
nStart = GetTimeMillis(); nStart = GetTimeMillis();
CBanDB bandb; CBanDB bandb;

7
src/net.h

@ -96,6 +96,8 @@ struct AddedNodeInfo
class CTransaction; class CTransaction;
class CNodeStats; class CNodeStats;
class CClientUIInterface;
class CConnman class CConnman
{ {
public: public:
@ -109,7 +111,7 @@ public:
CConnman(); CConnman();
~CConnman(); ~CConnman();
bool Start(boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServicesIn, ServiceFlags nRelevantServicesIn, int nMaxConnectionsIn, int nMaxOutboundIn, int nBestHeightIn, std::string& strNodeError); bool Start(boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServicesIn, ServiceFlags nRelevantServicesIn, int nMaxConnectionsIn, int nMaxOutboundIn, int nBestHeightIn, CClientUIInterface* interfaceIn, std::string& strNodeError);
void Stop(); void Stop();
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false); 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); bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
@ -293,12 +295,13 @@ private:
int nMaxConnections; int nMaxConnections;
int nMaxOutbound; int nMaxOutbound;
std::atomic<int> nBestHeight; std::atomic<int> nBestHeight;
CClientUIInterface* clientInterface;
}; };
extern std::unique_ptr<CConnman> g_connman; extern std::unique_ptr<CConnman> g_connman;
void MapPort(bool fUseUPnP); void MapPort(bool fUseUPnP);
unsigned short GetListenPort(); unsigned short GetListenPort();
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false); bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServices, ServiceFlags nRelevantServices, int nMaxConnections, int nMaxOutbound, int nBestHeightIn, std::string& strNodeError); bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServices, ServiceFlags nRelevantServices, int nMaxConnections, int nMaxOutbound, int nBestHeightIn, CClientUIInterface* interfaceIn, std::string& strNodeError);
bool StopNode(CConnman& connman); bool StopNode(CConnman& connman);
size_t SocketSendData(CNode *pnode); size_t SocketSendData(CNode *pnode);

Loading…
Cancel
Save