Browse Source

Fix handling of default ports

pull/145/head
Pieter Wuille 13 years ago
parent
commit
c981d768b3
  1. 4
      src/init.cpp
  2. 12
      src/net.cpp
  3. 18
      src/netbase.cpp
  4. 12
      src/netbase.h
  5. 2
      src/protocol.h

4
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);

12
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++)

18
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

12
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;

2
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();

Loading…
Cancel
Save