Merge pull request #355 from svost/c++11
authorCryptoManiac <CryptoManiac@users.noreply.github.com>
Mon, 3 Oct 2016 20:02:46 +0000 (00:02 +0400)
committerGitHub <noreply@github.com>
Mon, 3 Oct 2016 20:02:46 +0000 (00:02 +0400)
Minor restyle at c++11 branch

src/main.cpp
src/main.h
src/net.h
src/ntp.cpp
src/uint256.h
src/util.h
src/walletdb.h

index 90460db..08f089a 100644 (file)
@@ -897,8 +897,33 @@ bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock)
 }
 
 
+// Closure representing one script verification
+// Note that this stores references to the spending transaction
+class CScriptCheck
+{
+private:
+    CScript scriptPubKey;
+    const CTransaction *ptxTo = nullptr;
+    uint32_t nIn = 0;
+    unsigned int nFlags = 0;
+    int nHashType = 0;
+
+public:
+    CScriptCheck() {}
+    CScriptCheck(const CTransaction& txFromIn, const CTransaction& txToIn, uint32_t nInIn, unsigned int nFlagsIn, int nHashTypeIn) :
+        scriptPubKey(txFromIn.vout[txToIn.vin[nInIn].prevout.n].scriptPubKey),
+        ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), nHashType(nHashTypeIn) { }
 
+    bool operator()() const;
 
+    void swap(CScriptCheck &check) {
+        scriptPubKey.swap(check.scriptPubKey);
+        std::swap(ptxTo, check.ptxTo);
+        std::swap(nIn, check.nIn);
+        std::swap(nFlags, check.nFlags);
+        std::swap(nHashType, check.nHashType);
+    }
+};
 
 
 
index a937030..2247fa6 100644 (file)
@@ -727,34 +727,6 @@ protected:
     const CTxOut& GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const;
 };
 
-/** Closure representing one script verification
- *  Note that this stores references to the spending transaction */
-class CScriptCheck
-{
-private:
-    CScript scriptPubKey;
-    const CTransaction *ptxTo = nullptr;
-    uint32_t nIn = 0;
-    unsigned int nFlags = 0;
-    int nHashType = 0;
-
-public:
-    CScriptCheck() {}
-    CScriptCheck(const CTransaction& txFromIn, const CTransaction& txToIn, uint32_t nInIn, unsigned int nFlagsIn, int nHashTypeIn) :
-        scriptPubKey(txFromIn.vout[txToIn.vin[nInIn].prevout.n].scriptPubKey),
-        ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), nHashType(nHashTypeIn) { }
-
-    bool operator()() const;
-
-    void swap(CScriptCheck &check) {
-        scriptPubKey.swap(check.scriptPubKey);
-        std::swap(ptxTo, check.ptxTo);
-        std::swap(nIn, check.nIn);
-        std::swap(nFlags, check.nFlags);
-        std::swap(nHashType, check.nHashType);
-    }
-};
-
 
 
 
index 511788e..0d94116 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -16,7 +16,6 @@
 #include "addrman.h"
 #include "hash.h"
 
-using namespace std;
 
 class CRequestTracker;
 class CNode;
@@ -30,8 +29,8 @@ const uint16_t nPortZero = 0;
 inline uint64_t ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); }
 inline uint64_t SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); }
 
-void AddOneShot(string strDest);
-bool RecvLine(SOCKET hSocket, string& strLine);
+void AddOneShot(std::string strDest);
+bool RecvLine(SOCKET hSocket, std::string& strLine);
 bool GetMyExternalIP(CNetAddr& ipRet);
 void AddressCurrentlyConnected(const CService& addr);
 CNode* FindNode(const CNetAddr& ip);
@@ -39,7 +38,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);
 uint16_t GetListenPort();
-bool BindListenPort(const CService &bindAddr, string& strError=REF(string()));
+bool BindListenPort(const CService &bindAddr, std::string& strError=REF(std::string()));
 void StartNode(void* parg);
 bool StopNode();
 
@@ -123,17 +122,17 @@ extern bool fDiscover;
 extern uint64_t nLocalServices;
 extern uint64_t nLocalHostNonce;
 extern CAddress addrSeenByPeer;
-extern array<int, THREAD_MAX> vnThreadsRunning;
+extern std::array<int, THREAD_MAX> vnThreadsRunning;
 extern CAddrMan addrman;
 
-extern vector<CNode*> vNodes;
+extern std::vector<CNode*> vNodes;
 extern CCriticalSection cs_vNodes;
-extern vector<string> vAddedNodes;
+extern std::vector<std::string> vAddedNodes;
 extern CCriticalSection cs_vAddedNodes;
-extern map<CInv, CDataStream> mapRelay;
-extern deque<pair<int64_t, CInv> > vRelayExpiration;
+extern std::map<CInv, CDataStream> mapRelay;
+extern std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
 extern CCriticalSection cs_mapRelay;
-extern map<CInv, int64_t> mapAlreadyAskedFor;
+extern std::map<CInv, int64_t> mapAlreadyAskedFor;
 
 
 class CNodeStats
@@ -143,9 +142,9 @@ public:
     int64_t nLastSend;
     int64_t nLastRecv;
     int64_t nTimeConnected;
-    string addrName;
+    std::string addrName;
     int32_t nVersion;
-    string strSubVer;
+    std::string strSubVer;
     bool fInbound;
     int64_t nReleaseTime;
     int32_t nStartingHeight;
@@ -176,10 +175,10 @@ public:
     int32_t nHeaderStart;
     uint32_t nMessageStart;
     CAddress addr;
-    string addrName;
+    std::string addrName;
     CService addrLocal;
     int32_t nVersion;
-    string strSubVer;
+    std::string strSubVer;
     bool fOneShot;
     bool fClient;
     bool fInbound;
@@ -192,13 +191,13 @@ protected:
 
     // Denial-of-service detection/prevention
     // Key is IP address, value is banned-until-time
-    static map<CNetAddr, int64_t> setBanned;
+    static std::map<CNetAddr, int64_t> setBanned;
     static CCriticalSection cs_setBanned;
     int nMisbehavior;
 
 public:
     int64_t nReleaseTime;
-    map<uint256, CRequestTracker> mapRequests;
+    std::map<uint256, CRequestTracker> mapRequests;
     CCriticalSection cs_mapRequests;
     uint256 hashContinue;
     CBlockIndex* pindexLastGetBlocksBegin;
@@ -207,10 +206,10 @@ public:
     bool fStartSync;
 
     // flood relay
-    vector<CAddress> vAddrToSend;
-    set<CAddress> setAddrKnown;
+    std::vector<CAddress> vAddrToSend;
+    std::set<CAddress> setAddrKnown;
     bool fGetAddr;
-    set<uint256> setKnown;
+    std::set<uint256> setKnown;
     uint256 hashCheckpointKnown; // ppcoin: known sent sync-checkpoint
     int64_t nNextAddrSend;
     int64_t nNextLocalAddrSend;
@@ -218,11 +217,11 @@ public:
 
     // inventory based relay
     mruset<CInv> setInventoryKnown;
-    vector<CInv> vInventoryToSend;
+    std::vector<CInv> vInventoryToSend;
     CCriticalSection cs_inventory;
-    multimap<int64_t, CInv> mapAskFor;
+    std::multimap<int64_t, CInv> mapAskFor;
 
-    CNode(SOCKET hSocketIn, CAddress addrIn, string addrNameIn = "", bool fInboundIn=false);
+    CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn = "", bool fInboundIn=false);
     ~CNode();
 
 private:
index b9a524c..26450a1 100644 (file)
@@ -6,6 +6,8 @@
 #include "net.h"
 #include "ui_interface.h"
 
+using namespace std;
+
 extern int GetRandInt(int nMax);
 
 /*
@@ -72,7 +74,7 @@ struct pkt {
 
 const int nServersCount = 162;
 
-std::string NtpServers[162] = {
+string NtpServers[162] = {
     // Microsoft
     "time.windows.com",
 
@@ -270,11 +272,11 @@ std::string NtpServers[162] = {
     // ... To be continued
 };
 
-bool InitWithHost(const std::string &strHostName, SOCKET &sockfd, socklen_t &servlen, struct sockaddr *pcliaddr) {
+bool InitWithHost(const string &strHostName, SOCKET &sockfd, socklen_t &servlen, struct sockaddr *pcliaddr) {
   
     sockfd = INVALID_SOCKET;
 
-    std::vector<CNetAddr> vIP;
+    vector<CNetAddr> vIP;
     bool fRet = LookupHost(strHostName, vIP, 10, true);
     if (!fRet) {
         return false;
@@ -390,7 +392,7 @@ int64_t NtpGetTime(CNetAddr& ip) {
     return nTime;
 }
 
-int64_t NtpGetTime(const std::string &strHostName)
+int64_t NtpGetTime(const string &strHostName)
 {
     struct sockaddr cliaddr;
 
@@ -409,7 +411,7 @@ int64_t NtpGetTime(const std::string &strHostName)
 
 // NTP server, which we unconditionally trust. This may be your own installation of ntpd somewhere, for example. 
 // "localhost" means "trust no one"
-std::string strTrustedUpstream = "localhost";
+string strTrustedUpstream = "localhost";
 
 // Current offset
 int64_t nNtpOffset = numeric_limits<int64_t>::max();
@@ -423,7 +425,7 @@ void ThreadNtpSamples(void* parg) {
 
     printf("Trying to find NTP server at localhost...\n");
 
-    std::string strLocalHost = "127.0.0.1";
+    string strLocalHost = "127.0.0.1";
     if (NtpGetTime(strLocalHost) == GetTime()) {
         printf("There is NTP server active at localhost,  we don't need NTP thread.\n");
 
@@ -491,10 +493,10 @@ void ThreadNtpSamples(void* parg) {
         if (GetNodesOffset() == numeric_limits<int64_t>::max() && abs(nNtpOffset) > 40 * 60)
         {
             // If there is not enough node offsets data and NTP time offset is greater than 40 minutes then give a warning.
-            std::string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong NovaCoin will not work properly.");
+            string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong NovaCoin will not work properly.");
             strMiscWarning = strMessage;
             printf("*** %s\n", strMessage.c_str());
-            uiInterface.ThreadSafeMessageBox(strMessage+" ", std::string("NovaCoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION);
+            uiInterface.ThreadSafeMessageBox(strMessage+" ", string("NovaCoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION);
         }
 
         printf("nNtpOffset = %+" PRId64 "  (%+" PRId64 " minutes)\n", nNtpOffset, nNtpOffset/60);
index 526aa71..d6cd23f 100644 (file)
@@ -11,8 +11,6 @@
 #include <iomanip>
 #include <sstream>
 
-using namespace std;
-
 
 /** Base class without constructors for uint256 and uint160.
  * This makes the compiler let u use it in a union.
@@ -510,7 +508,7 @@ public:
         virtual const char* what() const throw () { return what_.c_str(); }
         virtual ~uint256_error() throw () {}
 private:
-        std::string what_; 
+        std::string what_;
 };
 
 /** 256-bit unsigned integer */
index d787141..7035091 100644 (file)
@@ -115,7 +115,9 @@ T* alignup(T* p)
 #define MAX_PATH            1024
 inline void Sleep(int64_t n)
 {
-    this_thread::sleep_for(std::chrono::milliseconds(n));
+    /*Boost has a year 2038 problem— if the request sleep time is past epoch+2^31 seconds the sleep returns instantly.
+      So we clamp our sleeps here to 10 years and hope that boost is fixed by 2028.*/
+    boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(n>315576000000LL?315576000000LL:n));
 }
 #endif
 
index c141db8..80c93c0 100644 (file)
@@ -8,7 +8,6 @@
 #include "db.h"
 #include "keystore.h"
 
-using namespace std;
 
 class CKeyPool;
 class CAccount;
@@ -49,19 +48,19 @@ public:
 class CWalletDB : public CDB
 {
 public:
-    CWalletDB(string strFilename, const char* pszMode="r+");
+    CWalletDB(std::string strFilename, const char* pszMode="r+");
 private:
     CWalletDB(const CWalletDB&);
     void operator=(const CWalletDB&);
 public:
-    bool WriteName(const string& strAddress, const string& strName);
-    bool EraseName(const string& strAddress);
+    bool WriteName(const std::string& strAddress, const std::string& strName);
+    bool EraseName(const std::string& strAddress);
     bool WriteTx(uint256 hash, const CWalletTx& wtx);
     bool EraseTx(uint256 hash);
     bool WriteKey(const CPubKey& key, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);
     bool WriteMalleableKey(const CMalleableKeyView& keyView, const CSecret& vchSecretH, const CKeyMetadata &keyMeta);
-    bool WriteCryptedMalleableKey(const CMalleableKeyView& keyView, const vector<unsigned char>& vchCryptedSecretH, const CKeyMetadata &keyMeta);
-    bool WriteCryptedKey(const CPubKey& key, const vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta);
+    bool WriteCryptedMalleableKey(const CMalleableKeyView& keyView, const std::vector<unsigned char>& vchCryptedSecretH, const CKeyMetadata &keyMeta);
+    bool WriteCryptedKey(const CPubKey& key, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta);
     bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey);
     bool EraseMasterKey(unsigned int nID);
     bool EraseCryptedKey(const CPubKey& key);
@@ -77,22 +76,22 @@ public:
     bool WritePool(int64_t nPool, const CKeyPool& keypool);
     bool ErasePool(int64_t nPool);
     bool WriteMinVersion(int nVersion);
-    bool ReadAccount(const string& strAccount, CAccount& account);
-    bool WriteAccount(const string& strAccount, const CAccount& account);
+    bool ReadAccount(const std::string& strAccount, CAccount& account);
+    bool WriteAccount(const std::string& strAccount, const CAccount& account);
 private:
     bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
 public:
     bool WriteAccountingEntry(const CAccountingEntry& acentry);
-    int64_t GetAccountCreditDebit(const string& strAccount);
-    void ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& acentries);
+    int64_t GetAccountCreditDebit(const std::string& strAccount);
+    void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
 
     DBErrors ReorderTransactions(CWallet*);
     DBErrors LoadWallet(CWallet* pwallet);
-    DBErrors FindWalletTx(CWallet* pwallet, vector<uint256>& vTxHash);
+    DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash);
     DBErrors ZapWalletTx(CWallet* pwallet);
 
-    static bool Recover(CDBEnv& dbenv, string filename, bool fOnlyKeys);
-    static bool Recover(CDBEnv& dbenv, string filename);
+    static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
+    static bool Recover(CDBEnv& dbenv, std::string filename);
 };
 
 #endif // BITCOIN_WALLETDB_H