Browse Source

net: resolve outside of storage structures

Rather than allowing CNetAddr/CService/CSubNet to launch DNS queries, require
that addresses are already resolved.

This greatly simplifies async resolve logic, and makes it harder to
accidentally leak DNS queries.
0.13
Cory Fields 9 years ago
parent
commit
367569926a
  1. 7
      src/init.cpp
  2. 4
      src/netbase.cpp

7
src/init.cpp

@ -1156,10 +1156,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if (mapArgs.count("-externalip")) { if (mapArgs.count("-externalip")) {
BOOST_FOREACH(const std::string& strAddr, mapMultiArgs["-externalip"]) { BOOST_FOREACH(const std::string& strAddr, mapMultiArgs["-externalip"]) {
CService addrLocal(strAddr, GetListenPort(), fNameLookup); CService addrLocal;
if (!addrLocal.IsValid()) if (Lookup(strAddr.c_str(), addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
AddLocal(addrLocal, LOCAL_MANUAL);
else
return InitError(ResolveErrMsg("externalip", strAddr)); return InitError(ResolveErrMsg("externalip", strAddr));
AddLocal(CService(strAddr, GetListenPort(), fNameLookup), LOCAL_MANUAL);
} }
} }

4
src/netbase.cpp

@ -614,11 +614,13 @@ bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest
proxyType nameProxy; proxyType nameProxy;
GetNameProxy(nameProxy); GetNameProxy(nameProxy);
CService addrResolved(CNetAddr(strDest, fNameLookup && !HaveNameProxy()), port); CService addrResolved;
if (Lookup(strDest.c_str(), addrResolved, port, fNameLookup && !HaveNameProxy())) {
if (addrResolved.IsValid()) { if (addrResolved.IsValid()) {
addr = addrResolved; addr = addrResolved;
return ConnectSocket(addr, hSocketRet, nTimeout); return ConnectSocket(addr, hSocketRet, nTimeout);
} }
}
addr = CService("0.0.0.0:0"); addr = CService("0.0.0.0:0");

Loading…
Cancel
Save