diff --git a/src/seeder/bitcoin.cpp b/src/seeder/bitcoin.cpp --- a/src/seeder/bitcoin.cpp +++ b/src/seeder/bitcoin.cpp @@ -20,7 +20,7 @@ int nStartingHeight; std::vector *vAddr; int ban; - int64 doneAfter; + int64_t doneAfter; CAddress you; int GetTimeout() { return you.IsTor() ? 120 : 30; } @@ -73,9 +73,9 @@ } void PushVersion() { - int64 nTime = time(nullptr); - uint64 nLocalNonce = BITCOIN_SEED_NONCE; - int64 nLocalServices = 0; + int64_t nTime = time(nullptr); + uint64_t nLocalNonce = BITCOIN_SEED_NONCE; + int64_t nLocalServices = 0; CAddress me(CService("0.0.0.0")); BeginMessage("version"); int nBestHeight = GetRequireHeight(); @@ -100,10 +100,10 @@ // printf("%s: RECV %s\n", ToString(you).c_str(), // strCommand.c_str()); if (strCommand == "version") { - int64 nTime; + int64_t nTime; CAddress addrMe; CAddress addrFrom; - uint64 nNonce = 1; + uint64_t nNonce = 1; vRecv >> nVersion >> you.nServices >> nTime >> addrMe; if (nVersion == 10300) nVersion = 300; if (nVersion >= 106 && !vRecv.empty()) vRecv >> addrFrom >> nNonce; @@ -133,7 +133,7 @@ vRecv >> vAddrNew; // printf("%s: got %i addresses\n", ToString(you).c_str(), // (int)vAddrNew.size()); - int64 now = time(nullptr); + int64_t now = time(nullptr); std::vector::iterator it = vAddrNew.begin(); if (vAddrNew.size() > 1) { if (doneAfter == 0 || doneAfter > now + 1) doneAfter = now + 1; @@ -231,7 +231,7 @@ if (!ConnectSocket(you, sock)) return false; PushVersion(); Send(); - int64 now; + int64_t now; while (now = time(nullptr), ban == 0 && (doneAfter == 0 || doneAfter > now) && sock != INVALID_SOCKET) { diff --git a/src/seeder/db.h b/src/seeder/db.h --- a/src/seeder/db.h +++ b/src/seeder/db.h @@ -36,7 +36,7 @@ public: CAddrStat() : weight(0), count(0), reliability(0) {} - void Update(bool good, int64 age, double tau) { + void Update(bool good, int64_t age, double tau) { double f = exp(-age / tau); reliability = reliability * f + (good ? (1.0 - f) : 0); count = count * f + 1; @@ -65,10 +65,10 @@ private: CService ip; uint64_t services; - int64 lastTry; - int64 ourLastTry; - int64 ourLastSuccess; - int64 ignoreTill; + int64_t lastTry; + int64_t ourLastTry; + int64_t ourLastSuccess; + int64_t ignoreTill; CAddrStat stat2H; CAddrStat stat8H; CAddrStat stat1D; @@ -204,7 +204,7 @@ int nHeight; int nClientV; std::string strClientV; - int64 ourLastSuccess; + int64_t ourLastSuccess; }; // seen nodes diff --git a/src/seeder/db.cpp b/src/seeder/db.cpp --- a/src/seeder/db.cpp +++ b/src/seeder/db.cpp @@ -35,7 +35,7 @@ } bool CAddrDb::Get_(CServiceResult &ip, int &wait) { - int64 now = time(nullptr); + int64_t now = time(nullptr); int cont = 0; int tot = unkId.size() + ourId.size(); if (tot == 0) { diff --git a/src/seeder/main.cpp b/src/seeder/main.cpp --- a/src/seeder/main.cpp +++ b/src/seeder/main.cpp @@ -176,7 +176,7 @@ std::vector ips; int wait = 5; db.GetMany(ips, 16, wait); - int64 now = time(nullptr); + int64_t now = time(nullptr); if (ips.empty()) { wait *= 1000; wait += rand() % (500 * *nThreads); diff --git a/src/seeder/netbase.h b/src/seeder/netbase.h --- a/src/seeder/netbase.h +++ b/src/seeder/netbase.h @@ -68,7 +68,7 @@ std::string ToString() const; std::string ToStringIP() const; unsigned int GetByte(int n) const; - uint64 GetHash() const; + uint64_t GetHash() const; bool GetInAddr(struct in_addr *pipv4Addr) const; std::vector GetGroup() const; int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const; diff --git a/src/seeder/netbase.cpp b/src/seeder/netbase.cpp --- a/src/seeder/netbase.cpp +++ b/src/seeder/netbase.cpp @@ -817,9 +817,9 @@ return vchRet; } -uint64 CNetAddr::GetHash() const { +uint64_t CNetAddr::GetHash() const { uint256 hash = Hash(&ip[0], &ip[16]); - uint64 nRet; + uint64_t nRet; memcpy(&nRet, &hash, sizeof(nRet)); return nRet; } diff --git a/src/seeder/protocol.h b/src/seeder/protocol.h --- a/src/seeder/protocol.h +++ b/src/seeder/protocol.h @@ -81,7 +81,7 @@ // TODO: make private (improves encapsulation) public: - uint64 nServices; + uint64_t nServices; // disk and network only unsigned int nTime; diff --git a/src/seeder/serialize.h b/src/seeder/serialize.h --- a/src/seeder/serialize.h +++ b/src/seeder/serialize.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -19,13 +20,6 @@ #include #include -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef __int64 int64; -typedef unsigned __int64 uint64; -#else -typedef long long int64; -typedef unsigned long long uint64; -#endif #if defined(_MSC_VER) && _MSC_VER < 1300 #define for if (false); else for #endif @@ -132,37 +126,28 @@ #define WRITEDATA(s, obj) s.write((char *)&(obj), sizeof(obj)) #define READDATA(s, obj) s.read((char *)&(obj), sizeof(obj)) -inline unsigned int GetSerializeSize(char a, int, int = 0) { - return sizeof(a); -} -inline unsigned int GetSerializeSize(signed char a, int, int = 0) { +inline unsigned int GetSerializeSize(int8_t a, int, int = 0) { return sizeof(a); } inline unsigned int GetSerializeSize(uint8_t a, int, int = 0) { return sizeof(a); } -inline unsigned int GetSerializeSize(signed short a, int, int = 0) { - return sizeof(a); -} -inline unsigned int GetSerializeSize(unsigned short a, int, int = 0) { - return sizeof(a); -} -inline unsigned int GetSerializeSize(signed int a, int, int = 0) { +inline unsigned int GetSerializeSize(int16_t a, int, int = 0) { return sizeof(a); } -inline unsigned int GetSerializeSize(unsigned int a, int, int = 0) { +inline unsigned int GetSerializeSize(uint16_t a, int, int = 0) { return sizeof(a); } -inline unsigned int GetSerializeSize(signed long a, int, int = 0) { +inline unsigned int GetSerializeSize(int32_t a, int, int = 0) { return sizeof(a); } -inline unsigned int GetSerializeSize(unsigned long a, int, int = 0) { +inline unsigned int GetSerializeSize(uint32_t a, int, int = 0) { return sizeof(a); } -inline unsigned int GetSerializeSize(int64 a, int, int = 0) { +inline unsigned int GetSerializeSize(int64_t a, int, int = 0) { return sizeof(a); } -inline unsigned int GetSerializeSize(uint64 a, int, int = 0) { +inline unsigned int GetSerializeSize(uint64_t a, int, int = 0) { return sizeof(a); } inline unsigned int GetSerializeSize(float a, int, int = 0) { @@ -173,11 +158,7 @@ } template -inline void Serialize(Stream &s, char a, int, int = 0) { - WRITEDATA(s, a); -} -template -inline void Serialize(Stream &s, signed char a, int, int = 0) { +inline void Serialize(Stream &s, int8_t a, int, int = 0) { WRITEDATA(s, a); } template @@ -185,35 +166,27 @@ WRITEDATA(s, a); } template -inline void Serialize(Stream &s, signed short a, int, int = 0) { - WRITEDATA(s, a); -} -template -inline void Serialize(Stream &s, unsigned short a, int, int = 0) { +inline void Serialize(Stream &s, int16_t a, int, int = 0) { WRITEDATA(s, a); } template -inline void Serialize(Stream &s, signed int a, int, int = 0) { +inline void Serialize(Stream &s, uint16_t a, int, int = 0) { WRITEDATA(s, a); } template -inline void Serialize(Stream &s, unsigned int a, int, int = 0) { +inline void Serialize(Stream &s, int32_t a, int, int = 0) { WRITEDATA(s, a); } template -inline void Serialize(Stream &s, signed long a, int, int = 0) { +inline void Serialize(Stream &s, uint32_t a, int, int = 0) { WRITEDATA(s, a); } template -inline void Serialize(Stream &s, unsigned long a, int, int = 0) { +inline void Serialize(Stream &s, int64_t a, int, int = 0) { WRITEDATA(s, a); } template -inline void Serialize(Stream &s, int64 a, int, int = 0) { - WRITEDATA(s, a); -} -template -inline void Serialize(Stream &s, uint64 a, int, int = 0) { +inline void Serialize(Stream &s, uint64_t a, int, int = 0) { WRITEDATA(s, a); } template @@ -226,11 +199,7 @@ } template -inline void Unserialize(Stream &s, char &a, int, int = 0) { - READDATA(s, a); -} -template -inline void Unserialize(Stream &s, signed char &a, int, int = 0) { +inline void Unserialize(Stream &s, int8_t &a, int, int = 0) { READDATA(s, a); } template @@ -238,35 +207,27 @@ READDATA(s, a); } template -inline void Unserialize(Stream &s, signed short &a, int, int = 0) { +inline void Unserialize(Stream &s, int16_t &a, int, int = 0) { READDATA(s, a); } template -inline void Unserialize(Stream &s, unsigned short &a, int, int = 0) { +inline void Unserialize(Stream &s, uint16_t &a, int, int = 0) { READDATA(s, a); } template -inline void Unserialize(Stream &s, signed int &a, int, int = 0) { +inline void Unserialize(Stream &s, int32_t &a, int, int = 0) { READDATA(s, a); } template -inline void Unserialize(Stream &s, unsigned int &a, int, int = 0) { +inline void Unserialize(Stream &s, uint32_t &a, int, int = 0) { READDATA(s, a); } template -inline void Unserialize(Stream &s, signed long &a, int, int = 0) { +inline void Unserialize(Stream &s, int64_t &a, int, int = 0) { READDATA(s, a); } template -inline void Unserialize(Stream &s, unsigned long &a, int, int = 0) { - READDATA(s, a); -} -template -inline void Unserialize(Stream &s, int64 &a, int, int = 0) { - READDATA(s, a); -} -template -inline void Unserialize(Stream &s, uint64 &a, int, int = 0) { +inline void Unserialize(Stream &s, uint64_t &a, int, int = 0) { READDATA(s, a); } template @@ -300,61 +261,62 @@ // size <= UINT_MAX -- 5 bytes (254 + 4 bytes) // size > UINT_MAX -- 9 bytes (255 + 8 bytes) // -inline unsigned int GetSizeOfCompactSize(uint64 nSize) { +inline unsigned int GetSizeOfCompactSize(uint64_t nSize) { if (nSize < 253) return sizeof(uint8_t); else if (nSize <= USHRT_MAX) - return sizeof(uint8_t) + sizeof(unsigned short); + return sizeof(uint8_t) + sizeof(uint16_t); else if (nSize <= UINT_MAX) - return sizeof(uint8_t) + sizeof(unsigned int); + return sizeof(uint8_t) + sizeof(uint32_t); else - return sizeof(uint8_t) + sizeof(uint64); + return sizeof(uint8_t) + sizeof(uint64_t); } -template void WriteCompactSize(Stream &os, uint64 nSize) { +template void WriteCompactSize(Stream &os, uint64_t nSize) { if (nSize < 253) { uint8_t chSize = nSize; WRITEDATA(os, chSize); } else if (nSize <= USHRT_MAX) { uint8_t chSize = 253; - unsigned short xSize = nSize; + uint16_t xSize = nSize; WRITEDATA(os, chSize); WRITEDATA(os, xSize); } else if (nSize <= UINT_MAX) { uint8_t chSize = 254; - unsigned int xSize = nSize; + uint32_t xSize = nSize; WRITEDATA(os, chSize); WRITEDATA(os, xSize); } else { uint8_t chSize = 255; - uint64 xSize = nSize; + uint64_t xSize = nSize; WRITEDATA(os, chSize); WRITEDATA(os, xSize); } return; } -template uint64 ReadCompactSize(Stream &is) { +template uint64_t ReadCompactSize(Stream &is) { uint8_t chSize; READDATA(is, chSize); - uint64 nSizeRet = 0; + uint64_t nSizeRet = 0; if (chSize < 253) { nSizeRet = chSize; } else if (chSize == 253) { - unsigned short xSize; + uint16_t xSize; READDATA(is, xSize); nSizeRet = xSize; } else if (chSize == 254) { - unsigned int xSize; + uint32_t xSize; READDATA(is, xSize); nSizeRet = xSize; } else { - uint64 xSize; + uint64_t xSize; READDATA(is, xSize); nSizeRet = xSize; } - if (nSizeRet > (uint64)MAX_SIZE) + if (nSizeRet > uint64_t(MAX_SIZE)) { throw std::ios_base::failure("ReadCompactSize() : size too large"); + } return nSizeRet; } diff --git a/src/seeder/uint256.h b/src/seeder/uint256.h --- a/src/seeder/uint256.h +++ b/src/seeder/uint256.h @@ -8,16 +8,10 @@ #include "serialize.h" #include +#include #include #include -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef __int64 int64; -typedef unsigned __int64 uint64; -#else -typedef long long int64; -typedef unsigned long long uint64; -#endif #if defined(_MSC_VER) && _MSC_VER < 1300 #define for if (false); else for #endif @@ -53,7 +47,7 @@ return ret; } - base_uint &operator=(uint64 b) { + base_uint &operator=(uint64_t b) { pn[0] = (unsigned int)b; pn[1] = (unsigned int)(b >> 32); for (int i = 2; i < WIDTH; i++) @@ -79,19 +73,19 @@ return *this; } - base_uint &operator^=(uint64 b) { + base_uint &operator^=(uint64_t b) { pn[0] ^= (unsigned int)b; pn[1] ^= (unsigned int)(b >> 32); return *this; } - base_uint &operator&=(uint64 b) { + base_uint &operator&=(uint64_t b) { pn[0] &= (unsigned int)b; pn[1] &= (unsigned int)(b >> 32); return *this; } - base_uint &operator|=(uint64 b) { + base_uint &operator|=(uint64_t b) { pn[0] |= (unsigned int)b; pn[1] |= (unsigned int)(b >> 32); return *this; @@ -126,9 +120,9 @@ } base_uint &operator+=(const base_uint &b) { - uint64 carry = 0; + uint64_t carry = 0; for (int i = 0; i < WIDTH; i++) { - uint64 n = carry + pn[i] + b.pn[i]; + uint64_t n = carry + pn[i] + b.pn[i]; pn[i] = n & 0xffffffff; carry = n >> 32; } @@ -140,14 +134,14 @@ return *this; } - base_uint &operator+=(uint64 b64) { + base_uint &operator+=(uint64_t b64) { base_uint b; b = b64; *this += b; return *this; } - base_uint &operator-=(uint64 b64) { + base_uint &operator-=(uint64_t b64) { base_uint b; b = b64; *this += -b; @@ -230,7 +224,7 @@ return true; } - friend inline bool operator==(const base_uint &a, uint64 b) { + friend inline bool operator==(const base_uint &a, uint64_t b) { if (a.pn[0] != (unsigned int)b) return false; if (a.pn[1] != (unsigned int)(b >> 32)) return false; for (int i = 2; i < base_uint::WIDTH; i++) @@ -242,7 +236,7 @@ return (!(a == b)); } - friend inline bool operator!=(const base_uint &a, uint64 b) { + friend inline bool operator!=(const base_uint &a, uint64_t b) { return (!(a == b)); } @@ -353,14 +347,14 @@ return *this; } - uint160(uint64 b) { + uint160(uint64_t b) { pn[0] = (unsigned int)b; pn[1] = (unsigned int)(b >> 32); for (int i = 2; i < WIDTH; i++) pn[i] = 0; } - uint160 &operator=(uint64 b) { + uint160 &operator=(uint64_t b) { pn[0] = (unsigned int)b; pn[1] = (unsigned int)(b >> 32); for (int i = 2; i < WIDTH; i++) @@ -378,10 +372,10 @@ } }; -inline bool operator==(const uint160 &a, uint64 b) { +inline bool operator==(const uint160 &a, uint64_t b) { return (base_uint160)a == b; } -inline bool operator!=(const uint160 &a, uint64 b) { +inline bool operator!=(const uint160 &a, uint64_t b) { return (base_uint160)a != b; } inline const uint160 operator<<(const base_uint160 &a, unsigned int shift) { @@ -540,14 +534,14 @@ return *this; } - uint256(uint64 b) { + uint256(uint64_t b) { pn[0] = (unsigned int)b; pn[1] = (unsigned int)(b >> 32); for (int i = 2; i < WIDTH; i++) pn[i] = 0; } - uint256 &operator=(uint64 b) { + uint256 &operator=(uint64_t b) { pn[0] = (unsigned int)b; pn[1] = (unsigned int)(b >> 32); for (int i = 2; i < WIDTH; i++) @@ -565,10 +559,10 @@ } }; -inline bool operator==(const uint256 &a, uint64 b) { +inline bool operator==(const uint256 &a, uint64_t b) { return (base_uint256)a == b; } -inline bool operator!=(const uint256 &a, uint64 b) { +inline bool operator!=(const uint256 &a, uint64_t b) { return (base_uint256)a != b; } inline const uint256 operator<<(const base_uint256 &a, unsigned int shift) {