diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2011-05-02 15:34:42 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2011-05-10 23:49:30 +0200 |
commit | a6a5bb7c204130dd4f3ced74446798eb67ea6472 (patch) | |
tree | 83d8c791956b4027fa9c63c05b670527c8755ab8 /src/net.h | |
parent | 04a667b0767a6c3fff8d24be784ccaec9edf712b (diff) |
Support for name lookups in -connect and -addnode
* A new option -dns is introduced that enables name lookups in
-connect and -addnode, which is not enabled by default,
as it may be considered a security issue.
* A Lookup function is added that supports retrieving one or
more addresses based on a host name
* CAddress constructors (optionally) support name lookups.
* The different places in the source code that did name lookups
are refactored to use NameLookup or CAddress instead (dns seeding,
irc server lookup, getexternalip, ...).
* Removed ToStringLog() from CAddress, and switched to ToString(),
since it was empty.
Diffstat (limited to 'src/net.h')
-rw-r--r-- | src/net.h | 62 |
1 files changed, 22 insertions, 40 deletions
@@ -12,7 +12,7 @@ extern int nBestHeight; -inline unsigned short GetDefaultPort() { return fTestNet ? htons(18333) : htons(8333); } +inline unsigned short GetDefaultPort() { return fTestNet ? 18333 : 8333; } static const unsigned int PUBLISH_HOPS = 5; enum { @@ -23,6 +23,8 @@ enum bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet); +bool Lookup(const char *pszName, vector<CAddress>& vaddr, int nServices, int nMaxSolutions, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false); +bool Lookup(const char *pszName, CAddress& addr, int nServices, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false); bool GetMyExternalIP(unsigned int& ipRet); bool AddAddress(CAddress addr, int64 nTimePenalty=0); void AddressCurrentlyConnected(const CAddress& addr); @@ -156,7 +158,7 @@ public: { Init(); ip = ipIn; - port = (portIn == 0 ? GetDefaultPort() : portIn); + port = htons(portIn == 0 ? GetDefaultPort() : portIn); nServices = nServicesIn; } @@ -168,54 +170,38 @@ public: nServices = nServicesIn; } - explicit CAddress(const char* pszIn, uint64 nServicesIn=NODE_NETWORK) + explicit CAddress(const char* pszIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK) { Init(); - SetAddress(pszIn); - nServices = nServicesIn; + Lookup(pszIn, *this, nServicesIn, fNameLookup, portIn); } - explicit CAddress(string strIn, uint64 nServicesIn=NODE_NETWORK) + explicit CAddress(const char* pszIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK) { Init(); - SetAddress(strIn.c_str()); - nServices = nServicesIn; + Lookup(pszIn, *this, nServicesIn, fNameLookup, 0, true); } - void Init() + explicit CAddress(string strIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK) { - nServices = NODE_NETWORK; - memcpy(pchReserved, pchIPv4, sizeof(pchReserved)); - ip = INADDR_NONE; - port = GetDefaultPort(); - nTime = 100000000; - nLastTry = 0; + Init(); + Lookup(strIn.c_str(), *this, nServicesIn, fNameLookup, portIn); } - bool SetAddress(const char* pszIn) + explicit CAddress(string strIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK) { - ip = INADDR_NONE; - port = GetDefaultPort(); - char psz[100]; - strlcpy(psz, pszIn, sizeof(psz)); - unsigned int a=0, b=0, c=0, d=0, e=0; - if (sscanf(psz, "%u.%u.%u.%u:%u", &a, &b, &c, &d, &e) < 4) - return false; - char* pszPort = strchr(psz, ':'); - if (pszPort) - { - *pszPort++ = '\0'; - port = htons(atoi(pszPort)); - if (atoi(pszPort) < 0 || atoi(pszPort) > USHRT_MAX) - port = htons(USHRT_MAX); - } - ip = inet_addr(psz); - return IsValid(); + Init(); + Lookup(strIn.c_str(), *this, nServicesIn, fNameLookup, 0, true); } - bool SetAddress(string strIn) + void Init() { - return SetAddress(strIn.c_str()); + nServices = NODE_NETWORK; + memcpy(pchReserved, pchIPv4, sizeof(pchReserved)); + ip = INADDR_NONE; + port = htons(GetDefaultPort()); + nTime = 100000000; + nLastTry = 0; } IMPLEMENT_SERIALIZE @@ -330,11 +316,6 @@ public: return strprintf("%u", ntohs(port)); } - string ToStringLog() const - { - return ""; - } - string ToString() const { return strprintf("%u.%u.%u.%u:%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0), ntohs(port)); @@ -460,6 +441,7 @@ public: extern bool fClient; +extern bool fAllowDNS; extern uint64 nLocalServices; extern CAddress addrLocalHost; extern CNode* pnodeLocalHost; |