Research
Timechain
Search Donate
Sponsors
Cake Wallet, private Bitcoin and Monero walletSideShift.ai, no-signup crypto exchangeOrangeRock, non-custodial bitcoin spot and perps tradingBraiins Hashpower, buy and sell Bitcoin hashrateeCash.com
What changed

Bitcoin v0.3.22 → v0.3.23

10 files · +149 · −29 · ce148944c · 2011-06-11 · Jeff Garzik

Release commit message: Merge pull request #300 from sipa/connecttimeout

Previous diff: v0.3.21 → v0.3.22. Next: v0.3.23 → v0.3.24.

base58.h (modified)

1--- v0.3.22/base58.h2+++ v0.3.23/base58.h3@@ -38,6 +38,8 @@4 5     // Convert bignum to std::string6     std::string str;7+    // Expected size increase from base58 conversion is approximately 137%8+    // use 138% to be safe9     str.reserve((pend - pbegin) * 138 / 100 + 1);10     CBigNum dv;11     CBigNum rem;

bignum.h (modified)

1--- v0.3.22/bignum.h2+++ v0.3.23/bignum.h3@@ -228,10 +228,13 @@4     {5         std::vector<unsigned char> vch2(vch.size() + 4);6         unsigned int nSize = vch.size();7+        // BIGNUM's byte stream format expects 4 bytes of8+        // big endian size data info at the front9         vch2[0] = (nSize >> 24) & 0xff;10         vch2[1] = (nSize >> 16) & 0xff;11         vch2[2] = (nSize >> 8) & 0xff;12         vch2[3] = (nSize >> 0) & 0xff;13+        // swap data to big endian14         reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);15         BN_mpi2bn(&vch2[0], vch2.size(), this);16     }

db.cpp (modified)

1--- v0.3.22/db.cpp2+++ v0.3.23/db.cpp3@@ -845,12 +845,11 @@4     {5         // Create new keyUser and set as default key6         RandAddSeedPerfmon();7-        keyUser.MakeNewKey();8-        if (!AddKey(keyUser))9-            return false;10-        if (!SetAddressBookName(PubKeyToAddress(keyUser.GetPubKey()), ""))11-            return false;12-        CWalletDB().WriteDefaultKey(keyUser.GetPubKey());13+14+        CWalletDB walletdb;15+        vchDefaultKey = GetKeyFromKeyPool();16+        walletdb.WriteDefaultKey(vchDefaultKey);17+        walletdb.WriteName(PubKeyToAddress(vchDefaultKey), "");18     }19 20     CreateThread(ThreadFlushWalletDB, NULL);

init.cpp (modified)

1--- v0.3.22/init.cpp2+++ v0.3.23/init.cpp3@@ -137,7 +137,6 @@4 5     if (mapArgs.count("-?") || mapArgs.count("--help"))6     {7-        string beta = VERSION_IS_BETA ? _(" beta") : "";8         string strUsage = string() +9           _("Bitcoin version") + " " + FormatFullVersion() + "\n\n" +10           _("Usage:") + "\t\t\t\t\t\t\t\t\t\t\n" +11@@ -152,6 +151,7 @@12             "  -gen=0           \t\t  " + _("Don't generate coins\n") +13             "  -min             \t\t  " + _("Start minimized\n") +14             "  -datadir=<dir>   \t\t  " + _("Specify data directory\n") +15+            "  -timeout=<n>     \t  "   + _("Specify connection timeout (in milliseconds)\n") +16             "  -proxy=<ip:port> \t  "   + _("Connect through socks4 proxy\n") +17             "  -dns             \t  "   + _("Allow DNS lookups for addnode and connect\n") +18             "  -addnode=<ip>    \t  "   + _("Add a node to connect to\n") +19@@ -383,7 +383,7 @@20     {21         printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);22         nStart = GetTimeMillis();23-        ScanForWalletTransactions(pindexRescan);24+        ScanForWalletTransactions(pindexRescan, true);25         printf(" rescan      %15"PRI64d"ms\n", GetTimeMillis() - nStart);26     }27 28@@ -413,6 +413,13 @@29     {30         PrintBlockTree();31         return false;32+    }33+34+    if (mapArgs.count("-timeout"))35+    {36+        int nNewTimeout = GetArg("-timeout", 5000);37+        if (nNewTimeout > 0 && nNewTimeout < 600000)38+            nConnectTimeout = nNewTimeout;39     }40 41     if (mapArgs.count("-printblock"))

main.cpp (modified)

1--- v0.3.22/main.cpp2+++ v0.3.23/main.cpp3@@ -884,7 +884,7 @@4     return false;5 }6 7-int ScanForWalletTransactions(CBlockIndex* pindexStart)8+int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)9 {10     int ret = 0;11 12@@ -897,7 +897,7 @@13             block.ReadFromDisk(pindex, true);14             BOOST_FOREACH(CTransaction& tx, block.vtx)15             {16-                if (AddToWalletIfInvolvingMe(tx, &block))17+                if (AddToWalletIfInvolvingMe(tx, &block, fUpdate))18                     ret++;19             }20             pindex = pindex->pnext;21@@ -3854,9 +3854,18 @@22                     dPriority += (double)nCredit * pcoin.first->GetDepthInMainChain();23                 }24 25-                // Fill a vout back to self with any change26-                int64 nChange = nValueIn - nTotalValue;27-                if (nChange >= CENT)28+                int64 nChange = nValueIn - nValue - nFeeRet;29+30+                // if sub-cent change is required, the fee must be raised to at least MIN_TX_FEE31+                // or until nChange becomes zero32+                if (nFeeRet < MIN_TX_FEE && nChange > 0 && nChange < CENT)33+                {34+                    int64 nMoveToFee = min(nChange, MIN_TX_FEE - nFeeRet);35+                    nChange -= nMoveToFee;36+                    nFeeRet += nMoveToFee;37+                }38+39+                if (nChange > 0)40                 {41                     // Note: We use a new key here to keep it from being obvious which side is the change.42                     //  The drawback is that by not reusing a previous key, the change may be lost if a

main.h (modified)

1--- v0.3.22/main.h2+++ v0.3.23/main.h3@@ -29,8 +29,8 @@4 static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;5 static const int64 COIN = 100000000;6 static const int64 CENT = 1000000;7-static const int64 MIN_TX_FEE = CENT;8-static const int64 MIN_RELAY_TX_FEE = 50000;9+static const int64 MIN_TX_FEE = 50000;10+static const int64 MIN_RELAY_TX_FEE = 10000;11 static const int64 MAX_MONEY = 21000000 * COIN;12 inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }13 static const int COINBASE_MATURITY = 100;14@@ -79,7 +79,6 @@15 16 17 18-19 bool CheckDiskSpace(uint64 nAdditionalBytes=0);20 FILE* OpenBlockFile(unsigned int nFile, unsigned int nBlockPos, const char* pszMode="rb");21 FILE* AppendBlockFile(unsigned int& nFileRet);22@@ -87,7 +86,7 @@23 std::vector<unsigned char> GenerateNewKey();24 bool AddToWallet(const CWalletTx& wtxIn);25 void WalletUpdateSpent(const COutPoint& prevout);26-int ScanForWalletTransactions(CBlockIndex* pindexStart);27+int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);28 void ReacceptWalletTransactions();29 bool LoadBlockIndex(bool fAllowNew=true);30 void PrintBlockTree();

net.cpp (modified)

1--- v0.3.22/net.cpp2+++ v0.3.23/net.cpp3@@ -51,6 +51,7 @@4 5 // Settings6 int fUseProxy = false;7+int nConnectTimeout = 5000;8 CAddress addrProxy("127.0.0.1",9050);9 10 11@@ -76,7 +77,7 @@12 13 14 15-bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet)16+bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout)17 {18     hSocketRet = INVALID_SOCKET;19 20@@ -88,11 +89,89 @@21     setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));22 #endif23 24-    bool fRoutable = !(addrConnect.GetByte(3) == 10 || (addrConnect.GetByte(3) == 192 && addrConnect.GetByte(2) == 168));25-    bool fProxy = (fUseProxy && fRoutable);26+    bool fProxy = (fUseProxy && addrConnect.IsRoutable());27     struct sockaddr_in sockaddr = (fProxy ? addrProxy.GetSockAddr() : addrConnect.GetSockAddr());28 29+#ifdef __WXMSW__30+    u_long fNonblock = 1;31+    if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR)32+#else33+    int fFlags = fcntl(hSocket, F_GETFL, 0);34+    if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == -1)35+#endif36+    {37+        closesocket(hSocket);38+        return false;39+    }40+41+42     if (connect(hSocket, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == SOCKET_ERROR)43+    {44+        // WSAEINVAL is here because some legacy version of winsock uses it45+        if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK || WSAGetLastError() == WSAEINVAL)46+        {47+            struct timeval timeout;48+            timeout.tv_sec  = nTimeout / 1000;49+            timeout.tv_usec = (nTimeout % 1000) * 1000;50+51+            fd_set fdset;52+            FD_ZERO(&fdset);53+            FD_SET(hSocket, &fdset);54+            int nRet = select(hSocket + 1, NULL, &fdset, NULL, &timeout);55+            if (nRet == 0)56+            {57+                printf("connection timeout\n");58+                closesocket(hSocket);59+                return false;60+            }61+            if (nRet == SOCKET_ERROR)62+            {63+                printf("select() for connection failed: %i\n",WSAGetLastError());64+                closesocket(hSocket);65+                return false;66+            }67+            socklen_t nRetSize = sizeof(nRet);68+#ifdef __WXMSW__69+            if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, (char*)(&nRet), &nRetSize) == SOCKET_ERROR)70+#else71+            if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == SOCKET_ERROR)72+#endif73+            {74+                printf("getsockopt() for connection failed: %i\n",WSAGetLastError());75+                closesocket(hSocket);76+                return false;77+            }78+            if (nRet != 0)79+            {80+                printf("connect() failed after select(): %i\n",nRet);81+                closesocket(hSocket);82+                return false;83+            }84+        }85+#ifdef __WXMSW__86+        else if (WSAGetLastError() != WSAEISCONN)87+#else88+        else89+#endif90+        {91+            printf("connect() failed: %s\n",WSAGetLastError());92+            closesocket(hSocket);93+            return false;94+        }95+    }96+97+    /*98+    this isn't even strictly necessary99+    CNode::ConnectNode immediately turns the socket back to non-blocking100+    but we'll turn it back to blocking just in case101+    */102+#ifdef __WXMSW__103+    fNonblock = 0;104+    if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR)105+#else106+    fFlags = fcntl(hSocket, F_GETFL, 0);107+    if (fcntl(hSocket, F_SETFL, fFlags & !O_NONBLOCK) == SOCKET_ERROR)108+#endif109     {110         closesocket(hSocket);111         return false;112@@ -757,9 +836,12 @@113         if (nSelect == SOCKET_ERROR)114         {115             int nErr = WSAGetLastError();116-            printf("socket select error %d\n", nErr);117-            for (int i = 0; i <= hSocketMax; i++)118-                FD_SET(i, &fdsetRecv);119+            if (hSocketMax > -1)120+            {121+                printf("socket select error %d\n", nErr);122+                for (int i = 0; i <= hSocketMax; i++)123+                    FD_SET(i, &fdsetRecv);124+            }125             FD_ZERO(&fdsetSend);126             FD_ZERO(&fdsetError);127             Sleep(timeout.tv_usec/1000);

net.h (modified)

1--- v0.3.22/net.h2+++ v0.3.23/net.h3@@ -19,6 +19,7 @@4 class CNode;5 class CBlockIndex;6 extern int nBestHeight;7+extern int nConnectTimeout;8 9 10 11@@ -32,7 +33,7 @@12 13 14 15-bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet);16+bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout=nConnectTimeout);17 bool Lookup(const char *pszName, std::vector<CAddress>& vaddr, int nServices, int nMaxSolutions, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false);18 bool Lookup(const char *pszName, CAddress& addr, int nServices, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false);19 bool GetMyExternalIP(unsigned int& ipRet);20@@ -283,13 +284,29 @@21         return (memcmp(pchReserved, pchIPv4, sizeof(pchIPv4)) == 0);22     }23 24+    bool IsRFC1918() const25+    {26+      return IsIPv4() && (GetByte(3) == 10 ||27+        (GetByte(3) == 192 && GetByte(2) == 168) ||28+        (GetByte(3) == 172 &&29+          (GetByte(2) >= 16 && GetByte(2) <= 31)));30+    }31+32+    bool IsRFC3927() const33+    {34+      return IsIPv4() && (GetByte(3) == 169 && GetByte(2) == 254);35+    }36+37+    bool IsLocal() const38+    {39+      return IsIPv4() && (GetByte(3) == 127 ||40+          GetByte(3) == 0);41+    }42+43     bool IsRoutable() const44     {45         return IsValid() &&46-            !(GetByte(3) == 10 ||47-              (GetByte(3) == 192 && GetByte(2) == 168) ||48-              GetByte(3) == 127 ||49-              GetByte(3) == 0);50+            !(IsRFC1918() || IsRFC3927() || IsLocal());51     }52 53     bool IsValid() const

serialize.h (modified)

1--- v0.3.22/serialize.h2+++ v0.3.23/serialize.h3@@ -33,7 +33,7 @@4 class CAutoFile;5 static const unsigned int MAX_SIZE = 0x02000000;6 7-static const int VERSION = 32200;8+static const int VERSION = 32300;9 static const char* pszSubVer = "";10 static const bool VERSION_IS_BETA = true;11 

util.h (modified)

1--- v0.3.22/util.h2+++ v0.3.23/util.h3@@ -105,6 +105,8 @@4 typedef int socklen_t;5 #else6 #define WSAGetLastError()   errno7+#define WSAEINVAL           EINVAL8+#define WSAEALREADY         EALREADY9 #define WSAEWOULDBLOCK      EWOULDBLOCK10 #define WSAEMSGSIZE         EMSGSIZE11 #define WSAEINTR            EINTR
0:000:00