aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2016-04-16 15:46:00 -0400
committerCory Fields <cory-nospam-@coryfields.com>2016-09-08 12:06:24 -0400
commit02137f11e2ea5d153f433493639730587836a1e3 (patch)
tree9d46cc20dbc21c6220adb1f62fe1485ae7f724f1 /src
parent5b446dd5b11d4f403554bc2dd5a7a94c7d20422a (diff)
net: Move socket binding into CConnman
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp12
-rw-r--r--src/net.cpp3
-rw-r--r--src/net.h18
3 files changed, 18 insertions, 15 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 6aaa7bfc5d..b0ffb7a40e 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -273,11 +273,11 @@ void HandleSIGHUP(int)
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))
return false;
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)
return InitError(strError);
return false;
@@ -1198,7 +1198,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
CService addrBind;
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false))
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"]) {
CService addrBind;
@@ -1206,14 +1206,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
return InitError(ResolveErrMsg("whitebind", strBind));
if (addrBind.GetPort() == 0)
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 {
struct in_addr inaddr_any;
inaddr_any.s_addr = INADDR_ANY;
- fBound |= Bind(CService(in6addr_any, GetListenPort()), BF_NONE);
- fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound ? BF_REPORT_ERROR : BF_NONE);
+ fBound |= Bind(connman, CService(in6addr_any, GetListenPort()), BF_NONE);
+ fBound |= Bind(connman, CService(inaddr_any, GetListenPort()), !fBound ? BF_REPORT_ERROR : BF_NONE);
}
if (!fBound)
return InitError(_("Failed to listen on any port. Use -listen=0 if you want this."));
diff --git a/src/net.cpp b/src/net.cpp
index b99989b289..0069820004 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -84,7 +84,6 @@ std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
static bool vfLimited[NET_MAX] = {};
static CNode* pnodeLocalHost = NULL;
uint64_t nLocalHostNonce = 0;
-static std::vector<ListenSocket> vhListenSocket;
CAddrMan addrman;
int nMaxConnections = DEFAULT_MAX_PEER_CONNECTIONS;
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 = "";
int nOne = 1;
diff --git a/src/net.h b/src/net.h
index d2a38e7dc4..4d87408e32 100644
--- a/src/net.h
+++ b/src/net.h
@@ -95,13 +95,6 @@ CNode* FindNode(const CService& ip);
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);
-struct ListenSocket {
- SOCKET socket;
- bool whitelisted;
-
- ListenSocket(SOCKET socket_, bool whitelisted_) : socket(socket_), whitelisted(whitelisted_) {}
-};
-
class CConnman
{
public:
@@ -109,7 +102,16 @@ public:
~CConnman();
bool Start(boost::thread_group& threadGroup, std::string& strNodeError);
void Stop();
+ bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
+
private:
+ struct ListenSocket {
+ SOCKET socket;
+ bool whitelisted;
+
+ ListenSocket(SOCKET socket_, bool whitelisted_) : socket(socket_), whitelisted(whitelisted_) {}
+ };
+
void ThreadOpenAddedConnections();
void ProcessOneShot();
void ThreadOpenConnections();
@@ -117,6 +119,8 @@ private:
void AcceptConnection(const ListenSocket& hListenSocket);
void ThreadSocketHandler();
void ThreadDNSAddressSeed();
+
+ std::vector<ListenSocket> vhListenSocket;
};
extern std::unique_ptr<CConnman> g_connman;
void MapPort(bool fUseUPnP);