diff --git a/src/alert.cpp b/src/alert.cpp index 48920629..3db85de2 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -48,8 +48,8 @@ std::string CUnsignedAlert::ToString() const return strprintf( "CAlert(\n" " nVersion = %d\n" - " nRelayUntil = %"PRI64d"\n" - " nExpiration = %"PRI64d"\n" + " nRelayUntil = %" PRI64d"\n" + " nExpiration = %" PRI64d"\n" " nID = %d\n" " nCancel = %d\n" " setCancel = %s\n" diff --git a/src/base58.h b/src/base58.h index 2d871546..11999fa1 100644 --- a/src/base58.h +++ b/src/base58.h @@ -49,7 +49,11 @@ inline std::string EncodeBase58(const unsigned char* pbegin, const unsigned char CBigNum rem; while (bn > bn0) { + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_div(&dv, &rem, &bn, &bn58, pctx)) + #else + if (!BN_div(dv.get(), rem.get(), bn.cget(), bn58.cget(), pctx)) + #endif throw bignum_error("EncodeBase58 : BN_div failed"); bn = dv; unsigned int c = rem.getulong(); @@ -96,7 +100,11 @@ inline bool DecodeBase58(const char* psz, std::vector& vchRet) break; } bnChar.setulong(p1 - pszBase58); + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_mul(&bn, &bn, &bn58, pctx)) + #else + if (!BN_mul(bn.get(), bn.cget(), bn58.cget(), pctx)) + #endif throw bignum_error("DecodeBase58 : BN_mul failed"); bn += bnChar; } diff --git a/src/bignum.h b/src/bignum.h index 379140ed..7cbb6b77 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -47,38 +47,81 @@ class CAutoBN_CTX bool operator!() { return (pctx == NULL); } }; - +#if OPENSSL_VERSION_NUMBER < 0x10100000L /** C++ wrapper for BIGNUM (OpenSSL bignum) */ class CBigNum : public BIGNUM { +#else +/** C++ wrapper for BIGNUM (OpenSSL 1.1 bignum) */ +class CBigNum +{ +private: + BIGNUM *self = NULL; + + void init() + { + if (self) BN_clear_free(self); + self = BN_new(); + if (!self) + throw bignum_error("CBigNum::init() : BN_new() returned NULL"); + } +#endif + public: + #if OPENSSL_VERSION_NUMBER >= 0x10100000L + BIGNUM* get() { return self; } + const BIGNUM* cget() const { return self; } + #endif + CBigNum() { + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_init(this); + #else + init(); + #endif } CBigNum(const CBigNum& b) { + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_init(this); if (!BN_copy(this, &b)) { BN_clear_free(this); throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed"); } + #else + init(); + if (!BN_copy(self, b.cget())) + { + BN_clear_free(self); + throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed"); + } + #endif } CBigNum& operator=(const CBigNum& b) { + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_copy(this, &b)) + #else + if (!BN_copy(self, b.cget())) + #endif throw bignum_error("CBigNum::operator= : BN_copy failed"); return (*this); } ~CBigNum() { + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_clear_free(this); + #else + if (self) BN_clear_free(self); + #endif } + #if OPENSSL_VERSION_NUMBER < 0x10100000L //CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'. CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } @@ -91,33 +134,67 @@ class CBigNum : public BIGNUM CBigNum(unsigned long n) { BN_init(this); setulong(n); } CBigNum(uint64 n) { BN_init(this); setuint64(n); } explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); } - + #else + //CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'. + CBigNum(signed char n) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(short n) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(int n) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(long n) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(int64 n) { init(); setint64(n); } + CBigNum(unsigned char n) { init(); setulong(n); } + CBigNum(unsigned short n) { init(); setulong(n); } + CBigNum(unsigned int n) { init(); setulong(n); } + CBigNum(unsigned long n) { init(); setulong(n); } + CBigNum(uint64 n) { init(); setuint64(n); } + explicit CBigNum(uint256 n) { init(); setuint256(n); } + #endif explicit CBigNum(const std::vector& vch) { + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_init(this); + #else + init(); + #endif setvch(vch); } void setulong(unsigned long n) { + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_set_word(this, n)) + #else + if (!BN_set_word(self, n)) + #endif throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed"); } unsigned long getulong() const { + #if OPENSSL_VERSION_NUMBER < 0x10100000L return BN_get_word(this); + #else + return BN_get_word(self); + #endif } unsigned int getuint() const { + #if OPENSSL_VERSION_NUMBER < 0x10100000L return BN_get_word(this); + #else + return BN_get_word(self); + #endif } int getint() const { + #if OPENSSL_VERSION_NUMBER < 0x10100000L unsigned long n = BN_get_word(this); if (!BN_is_negative(this)) + #else + unsigned long n = BN_get_word(self); + if (!BN_is_negative(self)) + #endif return (n > (unsigned long)std::numeric_limits::max() ? std::numeric_limits::max() : n); else return (n > (unsigned long)std::numeric_limits::max() ? std::numeric_limits::min() : -(int)n); @@ -163,7 +240,11 @@ class CBigNum : public BIGNUM pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize) & 0xff; + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_mpi2bn(pch, p - pch, this); + #else + BN_mpi2bn(pch, p - pch, self); + #endif } void setuint64(uint64 n) @@ -190,7 +271,11 @@ class CBigNum : public BIGNUM pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize) & 0xff; + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_mpi2bn(pch, p - pch, this); + #else + BN_mpi2bn(pch, p - pch, self); + #endif } void setuint256(uint256 n) @@ -218,16 +303,28 @@ class CBigNum : public BIGNUM pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize >> 0) & 0xff; + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_mpi2bn(pch, p - pch, this); + #else + BN_mpi2bn(pch, p - pch, self); + #endif } uint256 getuint256() { + #if OPENSSL_VERSION_NUMBER < 0x10100000L unsigned int nSize = BN_bn2mpi(this, NULL); + #else + unsigned int nSize = BN_bn2mpi(self, NULL); + #endif if (nSize < 4) return 0; std::vector vch(nSize); + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_bn2mpi(this, &vch[0]); + #else + BN_bn2mpi(self, &vch[0]); + #endif if (vch.size() > 4) vch[4] &= 0x7f; uint256 n = 0; @@ -248,16 +345,28 @@ class CBigNum : public BIGNUM vch2[3] = (nSize >> 0) & 0xff; // swap data to big endian reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4); + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_mpi2bn(&vch2[0], vch2.size(), this); + #else + BN_mpi2bn(&vch2[0], vch2.size(), self); + #endif } std::vector getvch() const { + #if OPENSSL_VERSION_NUMBER < 0x10100000L unsigned int nSize = BN_bn2mpi(this, NULL); + #else + unsigned int nSize = BN_bn2mpi(self, NULL); + #endif if (nSize <= 4) return std::vector(); std::vector vch(nSize); + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_bn2mpi(this, &vch[0]); + #else + BN_bn2mpi(self, &vch[0]); + #endif vch.erase(vch.begin(), vch.begin() + 4); reverse(vch.begin(), vch.end()); return vch; @@ -271,16 +380,28 @@ class CBigNum : public BIGNUM if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff; if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff; if (nSize >= 3) vch[6] = (nCompact >> 0) & 0xff; + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_mpi2bn(&vch[0], vch.size(), this); + #else + BN_mpi2bn(&vch[0], vch.size(), self); + #endif return *this; } unsigned int GetCompact() const { + #if OPENSSL_VERSION_NUMBER < 0x10100000L unsigned int nSize = BN_bn2mpi(this, NULL); + #else + unsigned int nSize = BN_bn2mpi(self, NULL); + #endif std::vector vch(nSize); nSize -= 4; + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_bn2mpi(this, &vch[0]); + #else + BN_bn2mpi(self, &vch[0]); + #endif unsigned int nCompact = nSize << 24; if (nSize >= 1) nCompact |= (vch[4] << 16); if (nSize >= 2) nCompact |= (vch[5] << 8); @@ -324,21 +445,41 @@ class CBigNum : public BIGNUM CBigNum bnBase = nBase; CBigNum bn0 = 0; std::string str; + #if OPENSSL_VERSION_NUMBER < 0x10100000L CBigNum bn = *this; BN_set_negative(&bn, false); + #else + CBigNum bn = *this; + BN_set_negative(bn.get(), false); + #endif CBigNum dv; CBigNum rem; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (BN_cmp(&bn, &bn0) == 0) + #else + if (BN_cmp(bn.get(), bn0.cget()) == 0) + #endif return "0"; + #if OPENSSL_VERSION_NUMBER < 0x10100000L while (BN_cmp(&bn, &bn0) > 0) { if (!BN_div(&dv, &rem, &bn, &bnBase, pctx)) throw bignum_error("CBigNum::ToString() : BN_div failed"); + #else + while (BN_cmp(bn.get(), bn0.cget()) > 0) + { + if (!BN_div(dv.get(), rem.get(), bn.cget(), bnBase.cget(), pctx)) + throw bignum_error("CBigNum::ToString() : BN_div failed"); + #endif bn = dv; unsigned int c = rem.getulong(); str += "0123456789abcdef"[c]; } + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (BN_is_negative(this)) + #else + if (BN_is_negative(self)) + #endif str += "-"; reverse(str.begin(), str.end()); return str; @@ -371,12 +512,20 @@ class CBigNum : public BIGNUM bool operator!() const { + #if OPENSSL_VERSION_NUMBER < 0x10100000L return BN_is_zero(this); + #else + return BN_is_zero(self); + #endif } CBigNum& operator+=(const CBigNum& b) { + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_add(this, this, &b)) + #else + if (!BN_add(self, self, b.cget())) + #endif throw bignum_error("CBigNum::operator+= : BN_add failed"); return *this; } @@ -390,7 +539,11 @@ class CBigNum : public BIGNUM CBigNum& operator*=(const CBigNum& b) { CAutoBN_CTX pctx; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_mul(this, this, &b, pctx)) + #else + if (!BN_mul(self, self, b.cget(), pctx)) + #endif throw bignum_error("CBigNum::operator*= : BN_mul failed"); return *this; } @@ -409,7 +562,11 @@ class CBigNum : public BIGNUM CBigNum& operator<<=(unsigned int shift) { + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_lshift(this, this, shift)) + #else + if (!BN_lshift(self, self, shift)) + #endif throw bignum_error("CBigNum:operator<<= : BN_lshift failed"); return *this; } @@ -420,13 +577,21 @@ class CBigNum : public BIGNUM // if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL CBigNum a = 1; a <<= shift; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (BN_cmp(&a, this) > 0) + #else + if (BN_cmp(a.cget(), self) > 0) + #endif { *this = 0; return *this; } + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_rshift(this, this, shift)) + #else + if (!BN_rshift(self, self, shift)) + #endif throw bignum_error("CBigNum:operator>>= : BN_rshift failed"); return *this; } @@ -435,7 +600,11 @@ class CBigNum : public BIGNUM CBigNum& operator++() { // prefix operator + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_add(this, this, BN_value_one())) + #else + if (!BN_add(self, self, BN_value_one())) + #endif throw bignum_error("CBigNum::operator++ : BN_add failed"); return *this; } @@ -452,7 +621,11 @@ class CBigNum : public BIGNUM { // prefix operator CBigNum r; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_sub(&r, this, BN_value_one())) + #else + if (!BN_sub(r.get(), self, BN_value_one())) + #endif throw bignum_error("CBigNum::operator-- : BN_sub failed"); *this = r; return *this; @@ -477,7 +650,11 @@ class CBigNum : public BIGNUM inline const CBigNum operator+(const CBigNum& a, const CBigNum& b) { CBigNum r; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_add(&r, &a, &b)) + #else + if (!BN_add(r.get(), a.cget(), b.cget())) + #endif throw bignum_error("CBigNum::operator+ : BN_add failed"); return r; } @@ -485,7 +662,11 @@ inline const CBigNum operator+(const CBigNum& a, const CBigNum& b) inline const CBigNum operator-(const CBigNum& a, const CBigNum& b) { CBigNum r; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_sub(&r, &a, &b)) + #else + if (!BN_sub(r.get(), a.cget(), b.cget())) + #endif throw bignum_error("CBigNum::operator- : BN_sub failed"); return r; } @@ -493,7 +674,11 @@ inline const CBigNum operator-(const CBigNum& a, const CBigNum& b) inline const CBigNum operator-(const CBigNum& a) { CBigNum r(a); + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_set_negative(&r, !BN_is_negative(&r)); + #else + BN_set_negative(r.get(), !BN_is_negative(r.cget())); + #endif return r; } @@ -501,7 +686,11 @@ inline const CBigNum operator*(const CBigNum& a, const CBigNum& b) { CAutoBN_CTX pctx; CBigNum r; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_mul(&r, &a, &b, pctx)) + #else + if (!BN_mul(r.get(), a.cget(), b.cget(), pctx)) + #endif throw bignum_error("CBigNum::operator* : BN_mul failed"); return r; } @@ -510,7 +699,11 @@ inline const CBigNum operator/(const CBigNum& a, const CBigNum& b) { CAutoBN_CTX pctx; CBigNum r; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_div(&r, NULL, &a, &b, pctx)) + #else + if (!BN_div(r.get(), NULL, a.cget(), b.cget(), pctx)) + #endif throw bignum_error("CBigNum::operator/ : BN_div failed"); return r; } @@ -519,7 +712,11 @@ inline const CBigNum operator%(const CBigNum& a, const CBigNum& b) { CAutoBN_CTX pctx; CBigNum r; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_mod(&r, &a, &b, pctx)) + #else + if (!BN_mod(r.get(), a.cget(), b.cget(), pctx)) + #endif throw bignum_error("CBigNum::operator% : BN_div failed"); return r; } @@ -527,7 +724,11 @@ inline const CBigNum operator%(const CBigNum& a, const CBigNum& b) inline const CBigNum operator<<(const CBigNum& a, unsigned int shift) { CBigNum r; + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_lshift(&r, &a, shift)) + #else + if (!BN_lshift(r.get(), a.cget(), shift)) + #endif throw bignum_error("CBigNum:operator<< : BN_lshift failed"); return r; } @@ -539,11 +740,20 @@ inline const CBigNum operator>>(const CBigNum& a, unsigned int shift) return r; } +#if OPENSSL_VERSION_NUMBER < 0x10100000L inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); } inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); } inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); } inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); } inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) < 0); } inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) > 0); } +#else +inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) == 0); } +inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) != 0); } +inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) <= 0); } +inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) >= 0); } +inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) < 0); } +inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.cget(), b.cget()) > 0); } +#endif #endif /* BIGNUM_H */ diff --git a/src/crypter.cpp b/src/crypter.cpp index 181b8fa0..0eb39e95 100644 --- a/src/crypter.cpp +++ b/src/crypter.cpp @@ -56,15 +56,27 @@ bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector (nCLen); + #if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX ctx; + #else + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + #endif bool fOk = true; + #if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX_init(&ctx); if (fOk) fOk = EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); if (fOk) fOk = EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen); if (fOk) fOk = EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0])+nCLen, &nFLen); EVP_CIPHER_CTX_cleanup(&ctx); + #else + EVP_CIPHER_CTX_init(ctx); + if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); + if (fOk) fOk = EVP_EncryptUpdate(ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen); + if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (&vchCiphertext[0])+nCLen, &nFLen); + EVP_CIPHER_CTX_free(ctx); + #endif if (!fOk) return false; @@ -83,15 +95,27 @@ bool CCrypter::Decrypt(const std::vector& vchCiphertext, CKeyingM vchPlaintext = CKeyingMaterial(nPLen); + #if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX ctx; + #else + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + #endif bool fOk = true; + #if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_CIPHER_CTX_init(&ctx); if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); if (fOk) fOk = EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen); if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0])+nPLen, &nFLen); EVP_CIPHER_CTX_cleanup(&ctx); + #else + EVP_CIPHER_CTX_init(ctx); + if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); + if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen); + if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0])+nPLen, &nFLen); + EVP_CIPHER_CTX_free(ctx); + #endif if (!fOk) return false; diff --git a/src/db.cpp b/src/db.cpp index 98494abb..225c9cbe 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -459,7 +459,7 @@ void CDBEnv::Flush(bool fShutdown) else mi++; } - printf("DBFlush(%s)%s ended %15"PRI64d"ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); + printf("DBFlush(%s)%s ended %15" PRI64d"ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); if (fShutdown) { char** listp; @@ -770,8 +770,7 @@ bool CTxDB::LoadBlockIndexGuts() // Load mapBlockIndex unsigned int fFlags = DB_SET_RANGE; - loop - { + while (true){ // Read next record CDataStream ssKey(SER_DISK, CLIENT_VERSION); if (fFlags == DB_SET_RANGE) diff --git a/src/init.cpp b/src/init.cpp index e77eb355..1f4cec17 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -689,7 +689,7 @@ bool AppInit2() printf("Shutdown requested. Exiting.\n"); return false; } - printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart); + printf( "block index %15" PRI64d"ms\n", GetTimeMillis() - nStart); if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree")) { @@ -781,7 +781,7 @@ bool AppInit2() } printf("%s", strErrors.str().c_str()); - printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart); + printf(" wallet %15" PRI64d"ms\n", GetTimeMillis() - nStart); RegisterWallet(pwalletMain); @@ -801,7 +801,7 @@ bool AppInit2() printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight); nStart = GetTimeMillis(); pwalletMain->ScanForWalletTransactions(pindexRescan, true); - printf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart); + printf(" rescan %15" PRI64d"ms\n", GetTimeMillis() - nStart); } // ********************************************************* Step 9: import blocks @@ -842,7 +842,7 @@ bool AppInit2() printf("Invalid or missing peers.dat; recreating\n"); } - printf("Loaded %i addresses from peers.dat %"PRI64d"ms\n", + printf("Loaded %i addresses from peers.dat %" PRI64d"ms\n", addrman.size(), GetTimeMillis() - nStart); // ********************************************************* Step 11: start node @@ -853,11 +853,11 @@ bool AppInit2() RandAddSeedPerfmon(); //// debug print - printf("mapBlockIndex.size() = %"PRIszu"\n", mapBlockIndex.size()); + printf("mapBlockIndex.size() = %" PRIszu"\n", mapBlockIndex.size()); printf("nBestHeight = %d\n", nBestHeight); - printf("setKeyPool.size() = %"PRIszu"\n", pwalletMain->setKeyPool.size()); - printf("mapWallet.size() = %"PRIszu"\n", pwalletMain->mapWallet.size()); - printf("mapAddressBook.size() = %"PRIszu"\n", pwalletMain->mapAddressBook.size()); + printf("setKeyPool.size() = %" PRIszu"\n", pwalletMain->setKeyPool.size()); + printf("mapWallet.size() = %" PRIszu"\n", pwalletMain->mapWallet.size()); + printf("mapAddressBook.size() = %" PRIszu"\n", pwalletMain->mapAddressBook.size()); if (!NewThread(StartNode, NULL)) InitError(_("Error: could not start node")); diff --git a/src/irc.cpp b/src/irc.cpp index 2830df77..4fcc183a 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -77,7 +77,7 @@ static bool Send(SOCKET hSocket, const char* pszSend) bool RecvLineIRC(SOCKET hSocket, string& strLine) { - loop + while (true) { bool fRet = RecvLine(hSocket, strLine); if (fRet) @@ -100,7 +100,7 @@ bool RecvLineIRC(SOCKET hSocket, string& strLine) int RecvUntil(SOCKET hSocket, const char* psz1, const char* psz2=NULL, const char* psz3=NULL, const char* psz4=NULL) { - loop + while (true) { string strLine; strLine.reserve(10000); @@ -135,7 +135,7 @@ bool Wait(int nSeconds) bool RecvCodeLine(SOCKET hSocket, const char* psz1, string& strRet) { strRet.clear(); - loop + while (true) { string strLine; if (!RecvLineIRC(hSocket, strLine)) diff --git a/src/key.cpp b/src/key.cpp index 23f31520..ccb58a34 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -6,7 +6,9 @@ #include #include - +#if OPENSSL_VERSION_NUMBER < 0x10100000L +#include +#endif #include "key.h" // Generate a private key from just the secret parameter @@ -53,6 +55,11 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch { if (!eckey) return 0; + #if OPENSSL_VERSION_NUMBER > 0x10100000L + const BIGNUM *sig_r, *sig_s; + ECDSA_SIG_get0(ecsig, &sig_r, &sig_s); + #endif + int ret = 0; BN_CTX *ctx = NULL; @@ -78,7 +85,11 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch x = BN_CTX_get(ctx); if (!BN_copy(x, order)) { ret=-1; goto err; } if (!BN_mul_word(x, i)) { ret=-1; goto err; } + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_add(x, x, ecsig->r)) { ret=-1; goto err; } + #else + if (!BN_add(x, x, sig_r)) { ret=-1; goto err; } + #endif field = BN_CTX_get(ctx); if (!EC_GROUP_get_curve_GFp(group, field, NULL, NULL, ctx)) { ret=-2; goto err; } if (BN_cmp(x, field) >= 0) { ret=0; goto err; } @@ -99,9 +110,17 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch if (!BN_zero(zero)) { ret=-1; goto err; } if (!BN_mod_sub(e, zero, e, order, ctx)) { ret=-1; goto err; } rr = BN_CTX_get(ctx); + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_mod_inverse(rr, ecsig->r, order, ctx)) { ret=-1; goto err; } + #else + if (!BN_mod_inverse(rr, sig_r, order, ctx)) { ret=-1; goto err; } + #endif sor = BN_CTX_get(ctx); + #if OPENSSL_VERSION_NUMBER < 0x10100000L if (!BN_mod_mul(sor, ecsig->s, rr, order, ctx)) { ret=-1; goto err; } + #else + if (!BN_mod_mul(sor, sig_s, rr, order, ctx)) { ret=-1; goto err; } + #endif eor = BN_CTX_get(ctx); if (!BN_mod_mul(eor, e, rr, order, ctx)) { ret=-1; goto err; } if (!EC_POINT_mul(group, Q, eor, R, sor, ctx)) { ret=-2; goto err; } @@ -308,8 +327,16 @@ bool CKey::SignCompact(uint256 hash, std::vector& vchSig) return false; vchSig.clear(); vchSig.resize(65,0); + #if OPENSSL_VERSION_NUMBER < 0x10100000L int nBitsR = BN_num_bits(sig->r); int nBitsS = BN_num_bits(sig->s); + #else + const BIGNUM *sig_r, *sig_s; + ECDSA_SIG_get0(sig, &sig_r, &sig_s); + + int nBitsR = BN_num_bits(sig_r); + int nBitsS = BN_num_bits(sig_s); + #endif if (nBitsR <= 256 && nBitsS <= 256) { int nRecId = -1; @@ -331,8 +358,13 @@ bool CKey::SignCompact(uint256 hash, std::vector& vchSig) throw key_error("CKey::SignCompact() : unable to construct recoverable key"); vchSig[0] = nRecId+27+(fCompressedPubKey ? 4 : 0); + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_bn2bin(sig->r,&vchSig[33-(nBitsR+7)/8]); BN_bn2bin(sig->s,&vchSig[65-(nBitsS+7)/8]); + #else + BN_bn2bin(sig_r,&vchSig[33-(nBitsR+7)/8]); + BN_bn2bin(sig_s,&vchSig[65-(nBitsS+7)/8]); + #endif fOk = true; } ECDSA_SIG_free(sig); @@ -351,8 +383,19 @@ bool CKey::SetCompactSignature(uint256 hash, const std::vector& v if (nV<27 || nV>=35) return false; ECDSA_SIG *sig = ECDSA_SIG_new(); + if (!sig) return false; + #if OPENSSL_VERSION_NUMBER < 0x10100000L BN_bin2bn(&vchSig[1],32,sig->r); BN_bin2bn(&vchSig[33],32,sig->s); + #else + // sig_r and sig_s are deallocated by ECDSA_SIG_free(sig); + BIGNUM *sig_r = BN_bin2bn(&vchSig[1],32,BN_new()); + BIGNUM *sig_s = BN_bin2bn(&vchSig[33],32,BN_new()); + if (!sig_r || !sig_s) return false; + // copy and transfer ownership to sig + ECDSA_SIG_set0(sig, sig_r, sig_s); + #endif + EC_KEY_free(pkey); pkey = EC_KEY_new_by_curve_name(NID_secp256k1); diff --git a/src/main.cpp b/src/main.cpp index cf10d034..7ee3a947 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -189,7 +189,7 @@ bool AddOrphanTx(const CDataStream& vMsg) // at most 500 megabytes of orphans: if (pvMsg->size() > 5000) { - printf("ignoring large orphan tx (size: %"PRIszu", hash: %s)\n", pvMsg->size(), hash.ToString().substr(0,10).c_str()); + printf("ignoring large orphan tx (size: %" PRIszu", hash: %s)\n", pvMsg->size(), hash.ToString().substr(0,10).c_str()); delete pvMsg; return false; } @@ -198,7 +198,7 @@ bool AddOrphanTx(const CDataStream& vMsg) BOOST_FOREACH(const CTxIn& txin, tx.vin) mapOrphanTransactionsByPrev[txin.prevout.hash].insert(make_pair(hash, pvMsg)); - printf("stored orphan tx %s (mapsz %"PRIszu")\n", hash.ToString().substr(0,10).c_str(), + printf("stored orphan tx %s (mapsz %" PRIszu")\n", hash.ToString().substr(0,10).c_str(), mapOrphanTransactions.size()); return true; } @@ -622,7 +622,7 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, // Don't accept it if it can't get into a block int64 txMinFee = tx.GetMinFee(1000, true, GMF_RELAY); if (nFees < txMinFee) - return error("CTxMemPool::accept() : not enough fees %s, %"PRI64d" < %"PRI64d, + return error("CTxMemPool::accept() : not enough fees %s, %" PRI64d" < %" PRI64d, hash.ToString().c_str(), nFees, txMinFee); @@ -675,7 +675,7 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, if (ptxOld) EraseFromWallets(ptxOld->GetHash()); - printf("CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n", + printf("CTxMemPool::accept() : accepted %s (poolsz %" PRIszu")\n", hash.ToString().substr(0,10).c_str(), mapTx.size()); return true; @@ -1280,7 +1280,7 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map& mapTes // Revisit this if/when transaction replacement is implemented and allows // adding inputs: fInvalid = true; - return DoS(100, error("FetchInputs() : %s prevout.n out of range %d %"PRIszu" %"PRIszu" prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str())); + return DoS(100, error("FetchInputs() : %s prevout.n out of range %d %" PRIszu" %" PRIszu" prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str())); } } @@ -1349,7 +1349,7 @@ bool CTransaction::ConnectInputs(MapPrevTx inputs, CTransaction& txPrev = inputs[prevout.hash].second; if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size()) - return DoS(100, error("ConnectInputs() : %s prevout.n out of range %d %"PRIszu" %"PRIszu" prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str())); + return DoS(100, error("ConnectInputs() : %s prevout.n out of range %d %" PRIszu" %" PRIszu" prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str())); // If prev is coinbase, check that it's matured if (txPrev.IsCoinBase()) @@ -1578,7 +1578,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) } if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees)) - return error("ConnectBlock() : coinbase pays too much (actual=%"PRI64d" vs limit=%"PRI64d")", vtx[0].GetValueOut(), GetBlockValue(pindex->nHeight, nFees)); + return error("ConnectBlock() : coinbase pays too much (actual=%" PRI64d" vs limit=%" PRI64d")", vtx[0].GetValueOut(), GetBlockValue(pindex->nHeight, nFees)); if (fJustCheck) return true; @@ -1636,8 +1636,8 @@ bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) vConnect.push_back(pindex); reverse(vConnect.begin(), vConnect.end()); - printf("REORGANIZE: Disconnect %"PRIszu" blocks; %s..%s\n", vDisconnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexBest->GetBlockHash().ToString().substr(0,20).c_str()); - printf("REORGANIZE: Connect %"PRIszu" blocks; %s..%s\n", vConnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexNew->GetBlockHash().ToString().substr(0,20).c_str()); + printf("REORGANIZE: Disconnect %" PRIszu" blocks; %s..%s\n", vDisconnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexBest->GetBlockHash().ToString().substr(0,20).c_str()); + printf("REORGANIZE: Connect %" PRIszu" blocks; %s..%s\n", vConnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexNew->GetBlockHash().ToString().substr(0,20).c_str()); // Disconnect shorter branch vector vResurrect; @@ -1765,7 +1765,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) } if (!vpindexSecondary.empty()) - printf("Postponing %"PRIszu" reconnects\n", vpindexSecondary.size()); + printf("Postponing %" PRIszu" reconnects\n", vpindexSecondary.size()); // Switch to new best branch if (!Reorganize(txdb, pindexIntermediate)) @@ -2215,7 +2215,7 @@ static unsigned int nCurrentBlockFile = 1; FILE* AppendBlockFile(unsigned int& nFileRet) { nFileRet = 0; - loop + while (true) { FILE* file = OpenBlockFile(nCurrentBlockFile, 0, "ab"); if (!file) @@ -2413,7 +2413,7 @@ void PrintBlockTree() // print item CBlock block; block.ReadFromDisk(pindex); - printf("%d (%u,%u) %s %s tx %"PRIszu"", + printf("%d (%u,%u) %s %s tx %" PRIszu"", pindex->nHeight, pindex->nFile, pindex->nBlockPos, block.GetHash().ToString().substr(0,20).c_str(), DateTimeStrFormat(block.GetBlockTime()).c_str(), @@ -2494,7 +2494,7 @@ bool LoadExternalBlockFile(FILE* fileIn) __PRETTY_FUNCTION__); } } - printf("Loaded %i blocks from external file in %"PRI64d"ms\n", nLoaded, GetTimeMillis() - nStart); + printf("Loaded %i blocks from external file in %" PRI64d"ms\n", nLoaded, GetTimeMillis() - nStart); return nLoaded > 0; } @@ -2601,7 +2601,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) static map mapReuseKey; RandAddSeedPerfmon(); if (fDebug) - printf("received: %s (%"PRIszu" bytes)\n", strCommand.c_str(), vRecv.size()); + printf("received: %s (%" PRIszu" bytes)\n", strCommand.c_str(), vRecv.size()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { printf("dropmessagestest DROPPING RECV MESSAGE\n"); @@ -2795,7 +2795,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (vInv.size() > MAX_INV_SZ) { pfrom->Misbehaving(20); - return error("message inv size() = %"PRIszu"", vInv.size()); + return error("message inv size() = %" PRIszu"", vInv.size()); } // find last block in inv vector @@ -2845,11 +2845,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (vInv.size() > MAX_INV_SZ) { pfrom->Misbehaving(20); - return error("message getdata size() = %"PRIszu"", vInv.size()); + return error("message getdata size() = %" PRIszu"", vInv.size()); } if (fDebugNet || (vInv.size() != 1)) - printf("received getdata (%"PRIszu" invsz)\n", vInv.size()); + printf("received getdata (%" PRIszu" invsz)\n", vInv.size()); BOOST_FOREACH(const CInv& inv, vInv) { @@ -3218,7 +3218,7 @@ bool ProcessMessages(CNode* pfrom) // (x) data // - loop + while (true) { // Don't bother if send buffer is too full to respond anyway if (pfrom->vSend.size() >= SendBufferSize()) @@ -3237,7 +3237,7 @@ bool ProcessMessages(CNode* pfrom) break; } if (pstart - vRecv.begin() > 0) - printf("\n\nPROCESSMESSAGE SKIPPED %"PRIpdd" BYTES\n\n", pstart - vRecv.begin()); + printf("\n\nPROCESSMESSAGE SKIPPED %" PRIpdd" BYTES\n\n", pstart - vRecv.begin()); vRecv.erase(vRecv.begin(), pstart); // Read header @@ -3646,9 +3646,15 @@ class TxPriorityCompare CBlock* CreateNewBlock(CReserveKey& reservekey) { + // Create new block + #if __cplusplus > 199711L + unique_ptr pblock(new CBlock()); + if (!pblock.get()) + #else auto_ptr pblock(new CBlock()); if (!pblock.get()) + #endif return NULL; // Create coinbase tx @@ -3864,7 +3870,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - printf("CreateNewBlock(): total size %"PRI64u"\n", nBlockSize); + printf("CreateNewBlock(): total size %" PRI64u"\n", nBlockSize); pblock->vtx[0].vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees); @@ -4023,8 +4029,13 @@ void static CoinMiner(CWallet *pwallet) { unsigned int nTransactionsUpdatedLast = nTransactionsUpdated; CBlockIndex* pindexPrev = pindexBest; + #if __cplusplus > 199711L + unique_ptr pblock(CreateNewBlock(reservekey)); + if (!pblock.get()) + #else auto_ptr pblock(CreateNewBlock(reservekey)); if (!pblock.get()) + #endif return; IncrementExtraNonce(pblock.get(), pindexPrev, nExtraNonce); @@ -4054,7 +4065,7 @@ void static CoinMiner(CWallet *pwallet) { uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); uint256 hashbuf[2]; uint256& hash = *alignup<16>(hashbuf); - loop + while (true) { unsigned int nHashesDone = 0; unsigned int nNonceFound; diff --git a/src/main.h b/src/main.h index 207269c6..692617be 100644 --- a/src/main.h +++ b/src/main.h @@ -416,7 +416,7 @@ class CTxOut { if (scriptPubKey.size() < 6) return "CTxOut(error)"; - return strprintf("CTxOut(nValue=%"PRI64d".%08"PRI64d", scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30).c_str()); + return strprintf("CTxOut(nValue=%" PRI64d".%08" PRI64d", scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30).c_str()); } void print() const @@ -641,7 +641,7 @@ class CTransaction std::string ToString() const { std::string str; - str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%"PRIszu", vout.size=%"PRIszu", nLockTime=%u)\n", + str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%" PRIszu", vout.size=%" PRIszu", nLockTime=%u)\n", GetHash().ToString().substr(0,10).c_str(), nVersion, vin.size(), @@ -1057,7 +1057,7 @@ class CBlock void print() const { - printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu")\n", + printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%" PRIszu")\n", GetHash().ToString().substr(0,20).c_str(), nVersion, hashPrevBlock.ToString().substr(0,20).c_str(), diff --git a/src/makefile.unix b/src/makefile.unix index e7efa607..0e7c939c 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -61,7 +61,7 @@ DEBUGFLAGS= # CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only # adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work. -xCXXFLAGS=-O2 -fomit-frame-pointer -fno-stack-protector -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \ +xCXXFLAGS=-O2 -fomit-frame-pointer -fno-stack-protector -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -Wno-class-memaccess -Wno-stringop-truncation \ $(DEBUGFLAGS) $(DEFS) $(CXXFLAGS) # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only diff --git a/src/net.cpp b/src/net.cpp index b9d7ad68..23ca95c5 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -58,7 +58,7 @@ static bool vfReachable[NET_MAX] = {}; static bool vfLimited[NET_MAX] = {}; static CNode* pnodeLocalHost = NULL; uint64 nLocalHostNonce = 0; -array vnThreadsRunning; +boost::array vnThreadsRunning; static std::vector vhListenSocket; CAddrMan addrman; @@ -145,7 +145,7 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer) bool RecvLine(SOCKET hSocket, string& strLine) { strLine = ""; - loop + while (true) { char c; int nBytes = recv(hSocket, &c, 1, 0); @@ -318,7 +318,7 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha { if (strLine.empty()) // HTTP response is separated from headers by blank line { - loop + while (true) { if (!RecvLine(hSocket, strLine)) { @@ -671,7 +671,7 @@ void ThreadSocketHandler2(void* parg) list vNodesDisconnected; unsigned int nPrevNodeCount = 0; - loop + while (true) { // // Disconnect nodes @@ -892,7 +892,7 @@ void ThreadSocketHandler2(void* parg) if (nPos > ReceiveBufferSize()) { if (!pnode->fDisconnect) - printf("socket recv flood control disconnect (%"PRIszu" bytes)\n", vRecv.size()); + printf("socket recv flood control disconnect (%" PRIszu" bytes)\n", vRecv.size()); pnode->CloseSocketDisconnect(); } else { @@ -1089,7 +1089,7 @@ void ThreadMapPort2(void* parg) else printf("UPnP Port Mapping successful.\n"); int i = 1; - loop { + while (true) { if (fShutdown || !fUseUPnP) { r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0); @@ -1124,7 +1124,7 @@ void ThreadMapPort2(void* parg) freeUPNPDevlist(devlist); devlist = 0; if (r != 0) FreeUPNPUrls(&urls); - loop { + while (true) { if (fShutdown || !fUseUPnP) return; Sleep(2000); @@ -1319,7 +1319,7 @@ void DumpAddresses() CAddrDB adb; adb.Write(addrman); - printf("Flushed %d addresses to peers.dat %"PRI64d"ms\n", + printf("Flushed %d addresses to peers.dat %" PRI64d"ms\n", addrman.size(), GetTimeMillis() - nStart); } @@ -1417,7 +1417,7 @@ void ThreadOpenConnections2(void* parg) // Initiate network connections int64 nStart = GetTime(); - loop + while (true) { ProcessOneShot(); @@ -1476,7 +1476,7 @@ void ThreadOpenConnections2(void* parg) int64 nANow = GetAdjustedTime(); int nTries = 0; - loop + while (true) { // use an nUnkBias between 10 (no outgoing connections) and 90 (8 outgoing connections) CAddress addr = addrman.Select(10 + min(nOutbound,8)*10); @@ -1569,7 +1569,7 @@ void ThreadOpenAddedConnections2(void* parg) } } } - loop + while (true) { vector > vservConnectAddresses = vservAddressesToAdd; // Attempt to connect to each IP for each addnode entry until at least one is successful per addnode entry diff --git a/src/net.h b/src/net.h index a09e095a..296d3928 100644 --- a/src/net.h +++ b/src/net.h @@ -324,7 +324,7 @@ class CNode // the key is the earliest time the request can be sent int64& nRequestTime = mapAlreadyAskedFor[inv]; if (fDebugNet) - printf("askfor %s %"PRI64d" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str()); + printf("askfor %s %" PRI64d" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str()); // Make sure not to reuse time indexes to keep things in the same order int64 nNow = (GetTime() - 1) * 1000000; diff --git a/src/qt/qtipcserver.cpp b/src/qt/qtipcserver.cpp index 8c2ce62e..2859bda9 100644 --- a/src/qt/qtipcserver.cpp +++ b/src/qt/qtipcserver.cpp @@ -97,7 +97,7 @@ static void ipcThread2(void* pArg) size_t nSize = 0; unsigned int nPriority = 0; - loop + while (true) { ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(100); if (mq->timed_receive(&buffer, sizeof(buffer), nSize, nPriority, d)) diff --git a/src/rpc.cpp b/src/rpc.cpp index eb115afb..3dde313a 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -345,7 +345,7 @@ static string HTTPReply(int nStatus, const string& strMsg, bool keepalive) "HTTP/1.1 %d %s\r\n" "Date: %s\r\n" "Connection: %s\r\n" - "Content-Length: %"PRIszu"\r\n" + "Content-Length: %" PRIszu"\r\n" "Content-Type: application/json\r\n" "Server: pxc-json-rpc/%s\r\n" "\r\n" @@ -377,7 +377,7 @@ int ReadHTTPStatus(std::basic_istream& stream, int &proto) int ReadHTTPHeader(std::basic_istream& stream, map& mapHeadersRet) { int nLen = 0; - loop + while (true) { string str; std::getline(stream, str); @@ -956,7 +956,7 @@ void ThreadRPCServer3(void* parg) AcceptedConnection *conn = (AcceptedConnection *) parg; bool fRun = true; - loop { + while (true) { if (fShutdown || !fRun) { conn->close(); diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 590d006e..9d9836a1 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -48,7 +48,7 @@ Value getpeerinfo(const Array& params, bool fHelp) Object obj; obj.push_back(Pair("addr", stats.addrName)); - obj.push_back(Pair("services", strprintf("%08"PRI64x, stats.nServices))); + obj.push_back(Pair("services", strprintf("%08" PRI64x, stats.nServices))); obj.push_back(Pair("lastsend", DateTimeStrFormat(stats.nLastSend))); obj.push_back(Pair("lastrecv", DateTimeStrFormat(stats.nLastRecv))); obj.push_back(Pair("conntime", DateTimeStrFormat(stats.nTimeConnected))); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index b7e42f31..d30cc725 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -725,7 +725,7 @@ Value addmultisigaddress(const Array& params, bool fHelp) if ((int)keys.size() < nRequired) throw runtime_error( strprintf("not enough keys supplied " - "(got %"PRIszu" keys, but need at least %d to redeem)", keys.size(), nRequired)); + "(got %" PRIszu" keys, but need at least %d to redeem)", keys.size(), nRequired)); std::vector pubkeys; pubkeys.resize(keys.size()); for (unsigned int i = 0; i < keys.size(); i++) diff --git a/src/script.cpp b/src/script.cpp index 4357a9a1..39be52ec 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -600,6 +600,7 @@ bool EvalScript(vector >& stack, const CScript& script, co // // Splice ops // + #if OPENSSL_VERSION_NUMBER < 0x10100000L case OP_CAT: { // (x1 x2 -- out) @@ -654,7 +655,7 @@ bool EvalScript(vector >& stack, const CScript& script, co popstack(stack); } break; - + #endif case OP_SIZE: { // (in -- in size) @@ -669,6 +670,7 @@ bool EvalScript(vector >& stack, const CScript& script, co // // Bitwise logic // + #if OPENSSL_VERSION_NUMBER < 0x10100000L case OP_INVERT: { // (in - out) @@ -713,7 +715,7 @@ bool EvalScript(vector >& stack, const CScript& script, co popstack(stack); } break; - + #endif case OP_EQUAL: case OP_EQUALVERIFY: //case OP_NOTEQUAL: // use OP_NUMNOTEQUAL @@ -748,8 +750,10 @@ bool EvalScript(vector >& stack, const CScript& script, co // case OP_1ADD: case OP_1SUB: + #if OPENSSL_VERSION_NUMBER < 0x10100000L case OP_2MUL: case OP_2DIV: + #endif case OP_NEGATE: case OP_ABS: case OP_NOT: @@ -763,8 +767,10 @@ bool EvalScript(vector >& stack, const CScript& script, co { case OP_1ADD: bn += bnOne; break; case OP_1SUB: bn -= bnOne; break; + #if OPENSSL_VERSION_NUMBER < 0x10100000L case OP_2MUL: bn <<= 1; break; case OP_2DIV: bn >>= 1; break; + #endif case OP_NEGATE: bn = -bn; break; case OP_ABS: if (bn < bnZero) bn = -bn; break; case OP_NOT: bn = (bn == bnZero); break; @@ -778,11 +784,13 @@ bool EvalScript(vector >& stack, const CScript& script, co case OP_ADD: case OP_SUB: + #if OPENSSL_VERSION_NUMBER < 0x10100000L case OP_MUL: case OP_DIV: case OP_MOD: case OP_LSHIFT: case OP_RSHIFT: + #endif case OP_BOOLAND: case OP_BOOLOR: case OP_NUMEQUAL: @@ -811,6 +819,7 @@ bool EvalScript(vector >& stack, const CScript& script, co bn = bn1 - bn2; break; + #if OPENSSL_VERSION_NUMBER < 0x10100000L case OP_MUL: if (!BN_mul(&bn, &bn1, &bn2, pctx)) return false; @@ -837,6 +846,7 @@ bool EvalScript(vector >& stack, const CScript& script, co return false; bn = bn1 >> bn2.getulong(); break; + #endif case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero); break; case OP_BOOLOR: bn = (bn1 != bnZero || bn2 != bnZero); break; @@ -1260,7 +1270,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector& v) return; string::size_type i1 = 0; string::size_type i2; - loop + while (true) { i2 = str.find(c, i1); if (i2 == str.npos) @@ -363,7 +363,7 @@ string FormatMoney(int64 n, bool fPlus) int64 n_abs = (n > 0 ? n : -n); int64 quotient = n_abs/COIN; int64 remainder = n_abs%COIN; - string str = strprintf("%"PRI64d".%08"PRI64d, quotient, remainder); + string str = strprintf("%" PRI64d".%08" PRI64d, quotient, remainder); // Right-trim excess zeros before the decimal point: int nTrim = 0; @@ -458,7 +458,7 @@ vector ParseHex(const char* psz) { // convert hex dump to vector vector vch; - loop + while (true) { while (isspace(*psz)) psz++; @@ -912,7 +912,7 @@ string DecodeBase32(const string& str) bool WildcardMatch(const char* psz, const char* mask) { - loop + while (true) { switch (*mask) { @@ -1211,7 +1211,7 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) // Add data vTimeOffsets.input(nOffsetSample); - printf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); + printf("Added time data, samples %d, offset %+" PRI64d" (%+" PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) { int64 nMedian = vTimeOffsets.median(); @@ -1246,10 +1246,10 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) } if (fDebug) { BOOST_FOREACH(int64 n, vSorted) - printf("%+"PRI64d" ", n); + printf("%+" PRI64d" ", n); printf("| "); } - printf("nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60); + printf("nTimeOffset = %+" PRI64d" (%+" PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60); } } diff --git a/src/util.h b/src/util.h index f8181609..c6b6b82e 100644 --- a/src/util.h +++ b/src/util.h @@ -39,7 +39,6 @@ typedef unsigned char uchar; static const int64 COIN = 100000000; static const int64 CENT = 1000000; -#define loop for (;;) #define BEGIN(a) ((char*)&(a)) #define END(a) ((char*)&((&(a))[1])) #define UBEGIN(a) ((unsigned char*)&(a)) @@ -235,7 +234,7 @@ void runCommand(std::string strCommand); inline std::string i64tostr(int64 n) { - return strprintf("%"PRI64d, n); + return strprintf("%" PRI64d, n); } inline std::string itostr(int n) @@ -587,14 +586,68 @@ template class CMedianFilter } }; +#if (BOOST_VERSION > 106501) bool NewThread(void(*pfn)(void*), void* parg); +#endif + + + + + + +// Note: It turns out we might have been able to use boost::thread +// by using TerminateThread(boost::thread.native_handle(), 0); +#ifdef WINDOWS + +#if (BOOST_VERSION <= 106501) +inline HANDLE NewThread(void(*pfn)(void*), void* parg, bool fWantHandle=false) +{ + DWORD nUnused = 0; + HANDLE hthread = + NewThread( + NULL, // default security + 0, // inherit stack size from parent + (LPTHREAD_START_ROUTINE)pfn, // function pointer + parg, // argument + 0, // creation option, start immediately + &nUnused); // thread identifier + if (hthread == NULL) + { + printf("Error: CreateThread() returned %d\n", GetLastError()); + return (HANDLE)0; + } + if (!fWantHandle) + { + CloseHandle(hthread); + return (HANDLE)-1; + } + return hthread; +} +#endif -#ifdef WIN32 inline void SetThreadPriority(int nPriority) { SetThreadPriority(GetCurrentThread(), nPriority); } #else +#if (BOOST_VERSION <= 106501) +inline pthread_t NewThread(void(*pfn)(void*), void* parg, bool fWantHandle=false) +{ + pthread_t hthread = 0; + int ret = pthread_create(&hthread, NULL, (void*(*)(void*))pfn, parg); + if (ret != 0) + { + printf("Error: pthread_create() returned %d\n", ret); + return (pthread_t)0; + } + if (!fWantHandle) + { + pthread_detach(hthread); + return (pthread_t)-1; + } + return hthread; +} +#endif #define THREAD_PRIORITY_LOWEST PRIO_MAX #define THREAD_PRIORITY_BELOW_NORMAL 2 diff --git a/src/wallet.cpp b/src/wallet.cpp index 1727365d..ad270822 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -810,7 +810,7 @@ void CWallet::ReacceptWalletTransactions() // Update fSpent if a tx got spent somewhere else by a copy of wallet.dat if (txindex.vSpent.size() != wtx.vout.size()) { - printf("ERROR: ReacceptWalletTransactions() : txindex.vSpent.size() %"PRIszu" != wtx.vout.size() %"PRIszu"\n", txindex.vSpent.size(), wtx.vout.size()); + printf("ERROR: ReacceptWalletTransactions() : txindex.vSpent.size() %" PRIszu" != wtx.vout.size() %" PRIszu"\n", txindex.vSpent.size(), wtx.vout.size()); continue; } for (unsigned int i = 0; i < txindex.vSpent.size(); i++) @@ -1170,7 +1170,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, CW CTxDB txdb("r"); { nFeeRet = nTransactionFee; - loop + while (true) { wtxNew.vin.clear(); wtxNew.vout.clear(); @@ -1430,7 +1430,7 @@ void CWallet::PrintWallet(const CBlock& block) if (mapWallet.count(block.vtx[0].GetHash())) { CWalletTx& wtx = mapWallet[block.vtx[0].GetHash()]; - printf(" mine: %d %d %"PRI64d"", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit()); + printf(" mine: %d %d %" PRI64d"", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit()); } } printf("\n"); @@ -1492,7 +1492,7 @@ bool CWallet::NewKeyPool() walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey())); setKeyPool.insert(nIndex); } - printf("CWallet::NewKeyPool wrote %"PRI64d" new keys\n", nKeys); + printf("CWallet::NewKeyPool wrote %" PRI64d" new keys\n", nKeys); } return true; } @@ -1517,7 +1517,7 @@ bool CWallet::TopUpKeyPool() if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey()))) throw runtime_error("TopUpKeyPool() : writing generated key failed"); setKeyPool.insert(nEnd); - printf("keypool added key %"PRI64d", size=%"PRIszu"\n", nEnd, setKeyPool.size()); + printf("keypool added key %" PRI64d", size=%" PRIszu"\n", nEnd, setKeyPool.size()); } } return true; @@ -1546,7 +1546,7 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool) if (!HaveKey(keypool.vchPubKey.GetID())) throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); assert(keypool.vchPubKey.IsValid()); - printf("keypool reserve %"PRI64d"\n", nIndex); + printf("keypool reserve %" PRI64d"\n", nIndex); } } @@ -1573,7 +1573,7 @@ void CWallet::KeepKey(int64 nIndex) CWalletDB walletdb(strWalletFile); walletdb.ErasePool(nIndex); } - printf("keypool keep %"PRI64d"\n", nIndex); + printf("keypool keep %" PRI64d"\n", nIndex); } void CWallet::ReturnKey(int64 nIndex) @@ -1583,7 +1583,7 @@ void CWallet::ReturnKey(int64 nIndex) LOCK(cs_wallet); setKeyPool.insert(nIndex); } - printf("keypool return %"PRI64d"\n", nIndex); + printf("keypool return %" PRI64d"\n", nIndex); } bool CWallet::GetKeyFromPool(CPubKey& result, bool fAllowReuse) diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 9d944722..430c42cb 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -72,7 +72,7 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, list