Skip to content

Commit c4fe27e

Browse files
theuniFuzzbawls
authored andcommitted
net: Split resolving out of CService
1 parent 502343a commit c4fe27e

File tree

8 files changed

+84
-97
lines changed

8 files changed

+84
-97
lines changed

src/httpserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ CService HTTPRequest::GetPeer()
630630
const char* address = "";
631631
uint16_t port = 0;
632632
evhttp_connection_get_peer(con, (char**)&address, &port);
633-
peer = CService(address, port);
633+
LookupNumeric(address, peer, port);
634634
}
635635
return peer;
636636
}

src/net.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6>& vSeedsIn
173173
// one by discovery.
174174
CAddress GetLocalAddress(const CNetAddr* paddrPeer)
175175
{
176-
CAddress ret(CService("0.0.0.0", GetListenPort()), NODE_NONE);
176+
CAddress ret(CService(CNetAddr(), GetListenPort()), NODE_NONE);
177177
CService addr;
178178
if (GetLocal(addr, paddrPeer)) {
179179
ret = CAddress(addr, nLocalServices);
@@ -495,7 +495,7 @@ void CNode::PushVersion()
495495

496496
/// when NTP implemented, change to just nTime = GetAdjustedTime()
497497
int64_t nTime = (fInbound ? GetAdjustedTime() : GetTime());
498-
CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService("0.0.0.0", 0), addr.nServices));
498+
CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService(), addr.nServices));
499499
CAddress addrMe = GetLocalAddress(&addr);
500500
GetRandBytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));
501501
if (fLogIPs)
@@ -1505,7 +1505,8 @@ std::vector<AddedNodeInfo> GetAddedNodeInfo()
15051505
}
15061506

15071507
for (std::string& strAddNode : lAddresses) {
1508-
CService service(strAddNode, Params().GetDefaultPort());
1508+
CService service;
1509+
LookupNumeric(strAddNode.c_str(), service, Params().GetDefaultPort());
15091510
if (service.IsValid()) {
15101511
// strAddNode is an IP:port
15111512
auto it = mapConnected.find(service);
@@ -1542,7 +1543,8 @@ void ThreadOpenAddedConnections()
15421543
CSemaphoreGrant grant(*semOutbound);
15431544
// If strAddedNode is an IP/port, decode it immediately, so
15441545
// OpenNetworkConnection can detect existing connections to that IP/port.
1545-
CService service(info.strAddedNode, Params().GetDefaultPort());
1546+
CService service;
1547+
LookupNumeric(info.strAddedNode.c_str(), service, Params().GetDefaultPort());
15461548
OpenNetworkConnection(CAddress(service, NODE_NONE), false, &grant, info.strAddedNode.c_str(), false);
15471549
MilliSleep(500);
15481550
}
@@ -1823,8 +1825,11 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler)
18231825
semOutbound = new CSemaphore(nMaxOutbound);
18241826
}
18251827

1826-
if (pnodeLocalHost == NULL)
1827-
pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress(CService("127.0.0.1", 0), nLocalServices));
1828+
if (pnodeLocalHost == NULL) {
1829+
CNetAddr local;
1830+
LookupHost("127.0.0.1", local, false);
1831+
pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress(CService(local, 0), nLocalServices));
1832+
}
18281833

18291834
Discover(threadGroup);
18301835

src/netbase.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ bool ConnectSocketByName(CService& addr, SOCKET& hSocketRet, const char* pszDest
659659
}
660660
}
661661

662-
addr = CService("0.0.0.0:0");
662+
addr = CService();
663663

664664
if (!HaveNameProxy())
665665
return false;
@@ -1148,38 +1148,6 @@ bool CService::SetSockAddr(const struct sockaddr* paddr)
11481148
}
11491149
}
11501150

1151-
CService::CService(const char* pszIpPort)
1152-
{
1153-
Init();
1154-
CService ip;
1155-
if (Lookup(pszIpPort, ip, 0, false))
1156-
*this = ip;
1157-
}
1158-
1159-
CService::CService(const char* pszIpPort, int portDefault)
1160-
{
1161-
Init();
1162-
CService ip;
1163-
if (Lookup(pszIpPort, ip, portDefault, false))
1164-
*this = ip;
1165-
}
1166-
1167-
CService::CService(const std::string& strIpPort)
1168-
{
1169-
Init();
1170-
CService ip;
1171-
if (Lookup(strIpPort.c_str(), ip, 0, false))
1172-
*this = ip;
1173-
}
1174-
1175-
CService::CService(const std::string& strIpPort, int portDefault)
1176-
{
1177-
Init();
1178-
CService ip;
1179-
if (Lookup(strIpPort.c_str(), ip, portDefault, false))
1180-
*this = ip;
1181-
}
1182-
11831151
unsigned short CService::GetPort() const
11841152
{
11851153
return port;

src/netbase.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ class CService : public CNetAddr
152152
CService(const CNetAddr& ip, unsigned short port);
153153
CService(const struct in_addr& ipv4Addr, unsigned short port);
154154
CService(const struct sockaddr_in& addr);
155-
explicit CService(const char* pszIpPort, int portDefault);
156-
explicit CService(const char* pszIpPort);
157-
explicit CService(const std::string& strIpPort, int portDefault);
158-
explicit CService(const std::string& strIpPort);
159155
void Init();
160156
void SetPort(unsigned short portIn);
161157
unsigned short GetPort() const;

src/qt/clientmodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ bool ClientModel::getTorInfo(std::string& ip_port) const
309309
LOCK(cs_mapLocalHost);
310310
for (const std::pair<const CNetAddr, LocalServiceInfo>& item : mapLocalHost) {
311311
if (item.first.IsTor()) {
312-
CService addrOnion = CService(item.first.ToString(), item.second.nPort);
312+
CService addrOnion;
313+
LookupNumeric(item.first.ToString().c_str(), addrOnion, item.second.nPort);
313314
ip_port = addrOnion.ToStringIPPort();
314315
return true;
315316
}

0 commit comments

Comments
 (0)