diff options
author | Pieter Wuille <sipa@ulyssis.org> | 2012-01-17 02:12:35 +0100 |
---|---|---|
committer | Pieter Wuille <sipa@ulyssis.org> | 2012-01-17 02:12:35 +0100 |
commit | c981d768b3cb0cf0879b3d70d3b548692fff0882 (patch) | |
tree | 3b350bb166cb07d8df1542b6fa0dc12614a8c1e8 /src | |
parent | 8498c591448d01a8a8ccc5ad1e8cbee9dbcf1500 (diff) |
Fix handling of default ports
Diffstat (limited to 'src')
-rw-r--r-- | src/init.cpp | 4 | ||||
-rw-r--r-- | src/net.cpp | 12 | ||||
-rw-r--r-- | src/netbase.cpp | 18 | ||||
-rw-r--r-- | src/netbase.h | 12 | ||||
-rw-r--r-- | src/protocol.h | 2 |
5 files changed, 25 insertions, 23 deletions
diff --git a/src/init.cpp b/src/init.cpp index 890a7d03a2..837d73f959 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 cdd72fddd3..b91a8f69c6 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) // <?php echo $_SERVER["REMOTE_ADDR"]; ?> 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<string>()), 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 48db3625c0..54e3119153 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<CNetAddr> 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<CNetAddr> 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 b12fb0045a..04ced18260 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 67e20d94e1..a0bf677aac 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(); |