diff --git a/src/init.cpp b/src/init.cpp index 890a7d03..837d73f9 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -463,7 +463,7 @@ bool AppInit2(int argc, char* argv[]) if (mapArgs.count("-proxy")) { fUseProxy = true; - addrProxy = CAddress(mapArgs["-proxy"]); + addrProxy = CService(mapArgs["-proxy"], 9050); if (!addrProxy.IsValid()) { wxMessageBox(_("Invalid -proxy address"), "Bitcoin"); @@ -512,7 +512,7 @@ bool AppInit2(int argc, char* argv[]) { BOOST_FOREACH(string strAddr, mapMultiArgs["-addnode"]) { - CAddress addr(strAddr, fAllowDNS); + CAddress addr(CService(strAddr, GetDefaultPort(), fAllowDNS)); addr.nTime = 0; // so it won't relay unless successfully connected if (addr.IsValid()) AddAddress(addr); diff --git a/src/net.cpp b/src/net.cpp index cdd72fdd..b91a8f69 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -137,7 +137,7 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha // We now get our external IP from the IRC server first and only use this as a backup bool GetMyExternalIP(CNetAddr& ipRet) { - CAddress addrConnect; + CService addrConnect; const char* pszGet; const char* pszKeyword; @@ -153,7 +153,7 @@ bool GetMyExternalIP(CNetAddr& ipRet) // if (nHost == 1) { - addrConnect = CAddress("91.198.22.70",80); // checkip.dyndns.org + addrConnect = CService("91.198.22.70",80); // checkip.dyndns.org if (nLookup == 1) { @@ -172,7 +172,7 @@ bool GetMyExternalIP(CNetAddr& ipRet) } else if (nHost == 2) { - addrConnect = CAddress("74.208.43.192", 80); // www.showmyip.com + addrConnect = CService("74.208.43.192", 80); // www.showmyip.com if (nLookup == 1) { @@ -529,8 +529,8 @@ void CNode::PushVersion() { /// when NTP implemented, change to just nTime = GetAdjustedTime() int64 nTime = (fInbound ? GetAdjustedTime() : GetTime()); - CAddress addrYou = (fUseProxy ? CAddress("0.0.0.0") : addr); - CAddress addrMe = (fUseProxy ? CAddress("0.0.0.0") : addrLocalHost); + CAddress addrYou = (fUseProxy ? CAddress(CService("0.0.0.0",0)) : addr); + CAddress addrMe = (fUseProxy ? CAddress(CService("0.0.0.0",0)) : addrLocalHost); RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector()), nBestHeight); @@ -1204,7 +1204,7 @@ void ThreadOpenConnections2(void* parg) { BOOST_FOREACH(string strAddr, mapMultiArgs["-connect"]) { - CAddress addr(strAddr, fAllowDNS); + CAddress addr(CService(strAddr, GetDefaultPort(), fAllowDNS)); if (addr.IsValid()) OpenNetworkConnection(addr); for (int i = 0; i < 10 && i < nLoop; i++) diff --git a/src/netbase.cpp b/src/netbase.cpp index 48db3625..54e31191 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -627,11 +627,12 @@ CService::CService(const char *pszIpPort, bool fAllowLookup) *this = ip; } -CService::CService(const char *pszIp, int portIn, bool fAllowLookup) +CService::CService(const char *pszIpPort, int portDefault, bool fAllowLookup) { - std::vector ip; - if (LookupHost(pszIp, ip, 1, fAllowLookup)) - *this = CService(ip[0], portIn); + Init(); + CService ip; + if (Lookup(pszIpPort, ip, portDefault, fAllowLookup)) + *this = ip; } CService::CService(const std::string &strIpPort, bool fAllowLookup) @@ -642,11 +643,12 @@ CService::CService(const std::string &strIpPort, bool fAllowLookup) *this = ip; } -CService::CService(const std::string &strIp, int portIn, bool fAllowLookup) +CService::CService(const std::string &strIpPort, int portDefault, bool fAllowLookup) { - std::vector ip; - if (LookupHost(strIp.c_str(), ip, 1, fAllowLookup)) - *this = CService(ip[0], portIn); + Init(); + CService ip; + if (Lookup(strIpPort.c_str(), ip, portDefault, fAllowLookup)) + *this = ip; } unsigned short CService::GetPort() const diff --git a/src/netbase.h b/src/netbase.h index b12fb004..04ced182 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -39,8 +39,8 @@ class CNetAddr public: CNetAddr(); CNetAddr(const struct in_addr& ipv4Addr); - CNetAddr(const char *pszIp, bool fAllowLookup = false); - CNetAddr(const std::string &strIp, bool fAllowLookup = false); + explicit CNetAddr(const char *pszIp, bool fAllowLookup = false); + explicit CNetAddr(const std::string &strIp, bool fAllowLookup = false); void Init(); void SetIP(const CNetAddr& ip); bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0) @@ -91,10 +91,10 @@ class CService : public CNetAddr CService(const CNetAddr& ip, unsigned short port); CService(const struct in_addr& ipv4Addr, unsigned short port); CService(const struct sockaddr_in& addr); - CService(const char *pszIp, int port, bool fAllowLookup = false); - CService(const char *pszIpPort, bool fAllowLookup = false); - CService(const std::string& strIp, int port, bool fAllowLookup = false); - CService(const std::string& strIpPort, bool fAllowLookup = false); + explicit CService(const char *pszIpPort, int portDefault, bool fAllowLookup = false); + explicit CService(const char *pszIpPort, bool fAllowLookup = false); + explicit CService(const std::string& strIpPort, int portDefault, bool fAllowLookup = false); + explicit CService(const std::string& strIpPort, bool fAllowLookup = false); void Init(); void SetPort(unsigned short portIn); unsigned short GetPort() const; diff --git a/src/protocol.h b/src/protocol.h index 67e20d94..a0bf677a 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -67,7 +67,7 @@ class CAddress : public CService { public: CAddress(); - CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK); + explicit CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK); void Init();