mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-18 02:51:06 +00:00
net: Move socket binding into CConnman
This commit is contained in:
parent
5b446dd5b1
commit
02137f11e2
12
src/init.cpp
12
src/init.cpp
@ -273,11 +273,11 @@ void HandleSIGHUP(int)
|
|||||||
fReopenDebugLog = true;
|
fReopenDebugLog = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool static Bind(const CService &addr, unsigned int flags) {
|
bool static Bind(CConnman& connman, const CService &addr, unsigned int flags) {
|
||||||
if (!(flags & BF_EXPLICIT) && IsLimited(addr))
|
if (!(flags & BF_EXPLICIT) && IsLimited(addr))
|
||||||
return false;
|
return false;
|
||||||
std::string strError;
|
std::string strError;
|
||||||
if (!BindListenPort(addr, strError, (flags & BF_WHITELIST) != 0)) {
|
if (!connman.BindListenPort(addr, strError, (flags & BF_WHITELIST) != 0)) {
|
||||||
if (flags & BF_REPORT_ERROR)
|
if (flags & BF_REPORT_ERROR)
|
||||||
return InitError(strError);
|
return InitError(strError);
|
||||||
return false;
|
return false;
|
||||||
@ -1198,7 +1198,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
CService addrBind;
|
CService addrBind;
|
||||||
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false))
|
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false))
|
||||||
return InitError(ResolveErrMsg("bind", strBind));
|
return InitError(ResolveErrMsg("bind", strBind));
|
||||||
fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR));
|
fBound |= Bind(connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR));
|
||||||
}
|
}
|
||||||
BOOST_FOREACH(const std::string& strBind, mapMultiArgs["-whitebind"]) {
|
BOOST_FOREACH(const std::string& strBind, mapMultiArgs["-whitebind"]) {
|
||||||
CService addrBind;
|
CService addrBind;
|
||||||
@ -1206,14 +1206,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
return InitError(ResolveErrMsg("whitebind", strBind));
|
return InitError(ResolveErrMsg("whitebind", strBind));
|
||||||
if (addrBind.GetPort() == 0)
|
if (addrBind.GetPort() == 0)
|
||||||
return InitError(strprintf(_("Need to specify a port with -whitebind: '%s'"), strBind));
|
return InitError(strprintf(_("Need to specify a port with -whitebind: '%s'"), strBind));
|
||||||
fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST));
|
fBound |= Bind(connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
struct in_addr inaddr_any;
|
struct in_addr inaddr_any;
|
||||||
inaddr_any.s_addr = INADDR_ANY;
|
inaddr_any.s_addr = INADDR_ANY;
|
||||||
fBound |= Bind(CService(in6addr_any, GetListenPort()), BF_NONE);
|
fBound |= Bind(connman, CService(in6addr_any, GetListenPort()), BF_NONE);
|
||||||
fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound ? BF_REPORT_ERROR : BF_NONE);
|
fBound |= Bind(connman, CService(inaddr_any, GetListenPort()), !fBound ? BF_REPORT_ERROR : BF_NONE);
|
||||||
}
|
}
|
||||||
if (!fBound)
|
if (!fBound)
|
||||||
return InitError(_("Failed to listen on any port. Use -listen=0 if you want this."));
|
return InitError(_("Failed to listen on any port. Use -listen=0 if you want this."));
|
||||||
|
@ -84,7 +84,6 @@ std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
|
|||||||
static bool vfLimited[NET_MAX] = {};
|
static bool vfLimited[NET_MAX] = {};
|
||||||
static CNode* pnodeLocalHost = NULL;
|
static CNode* pnodeLocalHost = NULL;
|
||||||
uint64_t nLocalHostNonce = 0;
|
uint64_t nLocalHostNonce = 0;
|
||||||
static std::vector<ListenSocket> vhListenSocket;
|
|
||||||
CAddrMan addrman;
|
CAddrMan addrman;
|
||||||
int nMaxConnections = DEFAULT_MAX_PEER_CONNECTIONS;
|
int nMaxConnections = DEFAULT_MAX_PEER_CONNECTIONS;
|
||||||
bool fAddressesInitialized = false;
|
bool fAddressesInitialized = false;
|
||||||
@ -1908,7 +1907,7 @@ void CConnman::ThreadMessageHandler()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool BindListenPort(const CService &addrBind, std::string& strError, bool fWhitelisted)
|
bool CConnman::BindListenPort(const CService &addrBind, std::string& strError, bool fWhitelisted)
|
||||||
{
|
{
|
||||||
strError = "";
|
strError = "";
|
||||||
int nOne = 1;
|
int nOne = 1;
|
||||||
|
18
src/net.h
18
src/net.h
@ -95,13 +95,6 @@ CNode* FindNode(const CService& ip);
|
|||||||
CNode* FindNode(const NodeId id); //TODO: Remove this
|
CNode* FindNode(const NodeId id); //TODO: Remove this
|
||||||
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);
|
||||||
|
|
||||||
struct ListenSocket {
|
|
||||||
SOCKET socket;
|
|
||||||
bool whitelisted;
|
|
||||||
|
|
||||||
ListenSocket(SOCKET socket_, bool whitelisted_) : socket(socket_), whitelisted(whitelisted_) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CConnman
|
class CConnman
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -109,7 +102,16 @@ public:
|
|||||||
~CConnman();
|
~CConnman();
|
||||||
bool Start(boost::thread_group& threadGroup, std::string& strNodeError);
|
bool Start(boost::thread_group& threadGroup, std::string& strNodeError);
|
||||||
void Stop();
|
void Stop();
|
||||||
|
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct ListenSocket {
|
||||||
|
SOCKET socket;
|
||||||
|
bool whitelisted;
|
||||||
|
|
||||||
|
ListenSocket(SOCKET socket_, bool whitelisted_) : socket(socket_), whitelisted(whitelisted_) {}
|
||||||
|
};
|
||||||
|
|
||||||
void ThreadOpenAddedConnections();
|
void ThreadOpenAddedConnections();
|
||||||
void ProcessOneShot();
|
void ProcessOneShot();
|
||||||
void ThreadOpenConnections();
|
void ThreadOpenConnections();
|
||||||
@ -117,6 +119,8 @@ private:
|
|||||||
void AcceptConnection(const ListenSocket& hListenSocket);
|
void AcceptConnection(const ListenSocket& hListenSocket);
|
||||||
void ThreadSocketHandler();
|
void ThreadSocketHandler();
|
||||||
void ThreadDNSAddressSeed();
|
void ThreadDNSAddressSeed();
|
||||||
|
|
||||||
|
std::vector<ListenSocket> vhListenSocket;
|
||||||
};
|
};
|
||||||
extern std::unique_ptr<CConnman> g_connman;
|
extern std::unique_ptr<CConnman> g_connman;
|
||||||
void MapPort(bool fUseUPnP);
|
void MapPort(bool fUseUPnP);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user