Merge pull request #307 from svost/c++11
authorCryptoManiac <CryptoManiac@users.noreply.github.com>
Sun, 10 Apr 2016 19:21:20 +0000 (22:21 +0300)
committerCryptoManiac <CryptoManiac@users.noreply.github.com>
Sun, 10 Apr 2016 19:21:20 +0000 (22:21 +0300)
Minor restyle whith std=c++11

src/bitcoinrpc.cpp
src/irc.cpp
src/ministun.h
src/net.cpp
src/net.h
src/netbase.cpp
src/netbase.h
src/ntp.cpp
src/protocol.h

index 171e6ff..da691fa 100644 (file)
@@ -41,7 +41,7 @@ const Object emptyobj;
 
 void ThreadRPCServer3(void* parg);
 
-static inline unsigned short GetDefaultRPCPort()
+static inline uint16_t GetDefaultRPCPort()
 {
     return GetBoolArg("-testnet", false) ? 18344 : 8344;
 }
index a29874e..de789bd 100644 (file)
@@ -20,7 +20,7 @@ void ThreadIRCSeed2(void* parg);
 struct ircaddr
 {
     struct in_addr ip;
-    unsigned short port;
+    uint16_t port;
 };
 #pragma pack(pop)
 
index d2ad738..0581615 100644 (file)
@@ -41,7 +41,7 @@
     struct stun_addr {
         unsigned char unused;
         unsigned char family;
-        unsigned short port;
+        uint16_t port;
         unsigned int addr;
     } __attribute__((packed));
 #else
@@ -69,7 +69,7 @@
     struct stun_addr {
         unsigned char unused;
         unsigned char family;
-        unsigned short port;
+        uint16_t port;
         unsigned int addr;
     };
 #pragma pack(pop)
index 2c3cccd..db7b692 100644 (file)
@@ -85,9 +85,9 @@ void AddOneShot(string strDest)
     vOneShots.push_back(strDest);
 }
 
-unsigned short GetListenPort()
+uint16_t GetListenPort()
 {
-    return (unsigned short)(GetArg("-port", GetDefaultPort()));
+    return static_cast<uint16_t>(GetArg("-port", GetDefaultPort()));
 }
 
 void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd)
@@ -969,17 +969,6 @@ void ThreadSocketHandler2(void* parg)
     }
 }
 
-// DNS seeds
-// Each pair gives a source name and a seed name.
-// The first name is used as information source for addrman.
-// The second name should resolve to a list of seed addresses.
-static const char *strDNSSeed[][2] = {
-    {"novacoin.karelia.pro", "dnsseed.novacoin.karelia.pro"},
-    {"novacoin.ru", "dnsseed.novacoin.ru"},
-    {"novacoin.ru", "testseed.novacoin.ru"},
-    {"novaco.in", "dnsseed.novaco.in"},
-};
-
 void ThreadDNSAddressSeed(void* parg)
 {
     // Make this thread recognisable as the DNS seeding thread
@@ -1008,15 +997,25 @@ void ThreadDNSAddressSeed2(void* parg)
 
     if (!fTestNet)
     {
+        // DNS seeds
+        // Each pair gives a source name and a seed name.
+        // The first name is used as information source for addrman.
+        // The second name should resolve to a list of seed addresses.
+        static const vector<pair <string, string> > vstrDNSSeed = {
+            { "novacoin.karelia.pro", "dnsseed.novacoin.karelia.pro" },
+            { "novacoin.ru", "dnsseed.novacoin.ru" },
+            { "novacoin.ru", "testseed.novacoin.ru" },
+            { "novaco.in", "dnsseed.novaco.in" },
+        };
         printf("Loading addresses from DNS seeds (could take a while)\n");
 
-        for (unsigned int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) {
+        for (unsigned int seed_idx = 0; seed_idx < vstrDNSSeed.size(); seed_idx++) {
             if (HaveNameProxy()) {
-                AddOneShot(strDNSSeed[seed_idx][1]);
+                AddOneShot(vstrDNSSeed[seed_idx].second);
             } else {
                 vector<CNetAddr> vaddr;
                 vector<CAddress> vAdd;
-                if (LookupHost(strDNSSeed[seed_idx][1], vaddr))
+                if (LookupHost(vstrDNSSeed[seed_idx].second, vaddr))
                 {
                     for(CNetAddr& ip :  vaddr)
                     {
@@ -1026,7 +1025,7 @@ void ThreadDNSAddressSeed2(void* parg)
                         found++;
                     }
                 }
-                addrman.Add(vAdd, CNetAddr(strDNSSeed[seed_idx][0], true));
+                addrman.Add(vAdd, CNetAddr(vstrDNSSeed[seed_idx].first, true));
             }
         }
     }
@@ -1034,17 +1033,6 @@ void ThreadDNSAddressSeed2(void* parg)
     printf("%d addresses found from DNS seeds\n", found);
 }
 
-
-
-
-
-
-
-
-
-
-
-
 uint32_t pnSeed[] =
 {
     0xa52bf0da, 0x30aa43d8, 0x614488d5, 0x517b6fd5, 0xd4bf62d4, 0xb7d638d4, 0xbc12bcd1, 0xa2501bc6,
index cc6b20d..2539112 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -44,7 +44,7 @@ CNode* FindNode(const CService& ip);
 CNode* ConnectNode(CAddress addrConnect, const char *strDest = NULL, int64_t nTimeout=0);
 bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);
 void MapPort();
-unsigned short GetListenPort();
+uint16_t GetListenPort();
 bool BindListenPort(const CService &bindAddr, string& strError=REF(string()));
 void StartNode(void* parg);
 bool StopNode();
index 00025aa..a00fea7 100644 (file)
@@ -122,6 +122,19 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsign
     return (vIP.size() > 0);
 }
 
+bool LookupHost(const string strName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
+{
+    std::string strHost(strName);
+    if (strHost.empty())
+        return false;
+    if ((strHost.compare(0,1, "[") == 0) && (strHost.compare(strHost.length()-1,1, "]") == 0))
+    {
+        strHost = strHost.substr(1, strHost.size() - 2);
+    }
+
+    return LookupIntern(strHost.c_str(), vIP, nMaxSolutions, fAllowLookup);
+}
+
 bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
 {
     std::string strHost(pszName);
@@ -612,7 +625,7 @@ CNetAddr::CNetAddr(const std::string &strIp, bool fAllowLookup)
 {
     Init();
     std::vector<CNetAddr> vIP;
-    if (LookupHost(strIp.c_str(), vIP, 1, fAllowLookup))
+    if (LookupHost(strIp, vIP, 1, fAllowLookup))
         *this = vIP[0];
 }
 
@@ -1084,7 +1097,7 @@ CService::CService(const std::string &strIpPort, uint16_t portDefault, bool fAll
         *this = ip;
 }
 
-unsigned short CService::GetPort() const
+uint16_t CService::GetPort() const
 {
     return port;
 }
@@ -1164,7 +1177,7 @@ std::string CService::ToString() const
     return ToStringIPPort();
 }
 
-void CService::SetPort(unsigned short portIn)
+void CService::SetPort(uint16_t portIn)
 {
     port = portIn;
 }
index 95f93e9..9508b41 100644 (file)
@@ -91,7 +91,7 @@ class CNetAddr
 class CService : public CNetAddr
 {
     protected:
-        unsigned short port; // host order
+        uint16_t port; // host order
 
     public:
         CService();
@@ -104,7 +104,7 @@ class CService : public CNetAddr
         explicit CService(const std::string& strIpPort, bool fAllowLookup = false);
         void Init();
         void SetPort(uint16_t portIn);
-        unsigned short GetPort() const;
+        uint16_t GetPort() const;
         bool GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const;
         bool SetSockAddr(const struct sockaddr* paddr);
         friend bool operator==(const CService& a, const CService& b);
@@ -124,7 +124,7 @@ class CService : public CNetAddr
             (
              CService* pthis = const_cast<CService*>(this);
              READWRITE(FLATDATA(ip));
-             unsigned short portN = htons(port);
+             uint16_t portN = htons(port);
              READWRITE(portN);
              if (fRead)
                  pthis->port = ntohs(portN);
@@ -140,6 +140,7 @@ bool GetProxy(enum Network net, proxyType &proxyInfoOut);
 bool IsProxy(const CNetAddr &addr);
 bool SetNameProxy(CService addrProxy, int nSocksVersion = 5);
 bool HaveNameProxy();
+bool LookupHost(const std::string strName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions = 0, bool fAllowLookup = true);
 bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions = 0, bool fAllowLookup = true);
 bool Lookup(const char *pszName, CService& addr, uint16_t portDefault = 0, bool fAllowLookup = true);
 bool Lookup(const char *pszName, std::vector<CService>& vAddr, uint16_t portDefault = 0, bool fAllowLookup = true, unsigned int nMaxSolutions = 0);
index d05cfa5..c5ee734 100644 (file)
@@ -285,7 +285,7 @@ bool InitWithHost(const std::string &strHostName, SOCKET &sockfd, socklen_t &ser
     sockfd = INVALID_SOCKET;
 
     std::vector<CNetAddr> vIP;
-    bool fRet = LookupHost(strHostName.c_str(), vIP, 10, true);
+    bool fRet = LookupHost(strHostName, vIP, 10, true);
     if (!fRet) {
         return false;
     }
index 1fc86fc..88f4e4b 100644 (file)
@@ -18,9 +18,9 @@
 #include "uint256.h"
 
 extern bool fTestNet;
-inline unsigned short GetDefaultPort()
+inline uint16_t GetDefaultPort()
 {
-    return static_cast<unsigned short>(fTestNet ? 17777 : 7777);
+    return static_cast<uint16_t>(fTestNet ? 17777 : 7777);
 }
 
 extern uint8_t pchMessageStart[4];