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.2.11 → v0.2.12

4 files · +96 · −20 · 24ba1b64e · 2010-06-18 · s_nakamoto

Release commit message: use seed nodes as fallback if IRC fails or with TOR -- version 0.2.12

Previous diff: v0.2.10 → v0.2.11. Next: v0.2.12 → v0.2.13.

main.cpp (modified)

1--- v0.2.11/main.cpp2+++ v0.2.12/main.cpp3@@ -493,7 +493,7 @@4     if (!CheckTransaction())5         return error("AcceptTransaction() : CheckTransaction failed");6 7-    // To help v0.1.5 clients who would see it as negative number. please delete this later.8+    // To help v0.1.5 clients who would see it as a negative number9     if (nLockTime > INT_MAX)10         return error("AcceptTransaction() : not accepting nLockTime beyond 2038");11 12@@ -1896,10 +1896,10 @@13             pfrom->vRecv.SetVersion(min(pfrom->nVersion, VERSION));14 15         // Ask the first connected node for block updates16-        static bool fAskedForBlocks;17-        if (!fAskedForBlocks && !pfrom->fClient)18-        {19-            fAskedForBlocks = true;20+        static int nAskedForBlocks;21+        if (!pfrom->fClient && (nAskedForBlocks < 1 || vNodes.size() <= 1))22+        {23+            nAskedForBlocks++;24             pfrom->PushGetBlocks(pindexBest, uint256(0));25         }26 27@@ -1939,18 +1939,24 @@28             addr.nTime = GetAdjustedTime() - 2 * 60 * 60;29             if (pfrom->fGetAddr || vAddr.size() > 10)30                 addr.nTime -= 5 * 24 * 60 * 60;31-            AddAddress(addr, false);32+            AddAddress(addr);33             pfrom->AddAddressKnown(addr);34             if (!pfrom->fGetAddr && addr.IsRoutable())35             {36                 // Relay to a limited number of other nodes37                 CRITICAL_BLOCK(cs_vNodes)38                 {39-                    multimap<int, CNode*> mapMix;40+                    // Use deterministic randomness to send to41+                    // the same places for an hour at a time42+                    static uint256 hashSalt;43+                    if (hashSalt == 0)44+                        RAND_bytes((unsigned char*)&hashSalt, sizeof(hashSalt));45+                    uint256 hashRand = addr.ip ^ (GetTime()/3600) ^ hashSalt;46+                    multimap<uint256, CNode*> mapMix;47                     foreach(CNode* pnode, vNodes)48-                        mapMix.insert(make_pair(GetRand(INT_MAX), pnode));49-                    int nRelayNodes = 5;50-                    for (multimap<int, CNode*>::iterator mi = mapMix.begin(); mi != mapMix.end() && nRelayNodes-- > 0; ++mi)51+                        mapMix.insert(make_pair(hashRand = Hash(BEGIN(hashRand), END(hashRand)), pnode));52+                    int nRelayNodes = 10; // reduce this to 5 when the network is large53+                    for (multimap<uint256, CNode*>::iterator mi = mapMix.begin(); mi != mapMix.end() && nRelayNodes-- > 0; ++mi)54                         ((*mi).second)->PushAddress(addr);55                 }56             }57@@ -2158,8 +2164,10 @@58 59     else if (strCommand == "getaddr")60     {61+        // This includes all nodes that are currently online,62+        // since they rebroadcast an addr every 24 hours63         pfrom->vAddrToSend.clear();64-        int64 nSince = GetAdjustedTime() - 5 * 24 * 60 * 60; // in the last 5 days65+        int64 nSince = GetAdjustedTime() - 24 * 60 * 60; // in the last 24 hours66         CRITICAL_BLOCK(cs_mapAddresses)67         {68             unsigned int nSize = mapAddresses.size();69@@ -2348,7 +2356,7 @@70                     static uint256 hashSalt;71                     if (hashSalt == 0)72                         RAND_bytes((unsigned char*)&hashSalt, sizeof(hashSalt));73-                    uint256 hashRand = (inv.hash ^ hashSalt);74+                    uint256 hashRand = inv.hash ^ hashSalt;75                     hashRand = Hash(BEGIN(hashRand), END(hashRand));76                     bool fTrickleWait = ((hashRand & 3) != 0);77 

net.cpp (modified)

1--- v0.2.11/net.cpp2+++ v0.2.12/net.cpp3@@ -223,14 +223,12 @@4 5 6 7-bool AddAddress(CAddress addr, bool fCurrentlyOnline)8+bool AddAddress(CAddress addr)9 {10     if (!addr.IsRoutable())11         return false;12     if (addr.ip == addrLocalHost.ip)13         return false;14-    if (fCurrentlyOnline)15-        addr.nTime = GetAdjustedTime();16     CRITICAL_BLOCK(cs_mapAddresses)17     {18         map<vector<unsigned char>, CAddress>::iterator it = mapAddresses.find(addr.GetKey());19@@ -252,6 +250,7 @@20                 addrFound.nServices |= addr.nServices;21                 fUpdated = true;22             }23+            bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);24             int64 nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);25             if (addrFound.nTime < addr.nTime - nUpdateInterval)26             {27@@ -798,6 +797,25 @@28 29 30 31+32+33+34+unsigned int pnSeed[] =35+{36+    0x35218252, 0x9c9c9618, 0xda6bacad, 0xb9aca862, 0x97c235c6,37+    0x146f9562, 0xb67b9e4b, 0x87cf4bc0, 0xb83945d0, 0x984333ad,38+    0xbbeec555, 0x6f0eb440, 0xe0005318, 0x7797e460, 0xddc60fcc,39+    0xb3bbd24a, 0x1ac85746, 0x641846a6, 0x85ee1155, 0xbb2e7a4c,40+    0x9cb8514b, 0xfc342648, 0x62958fae, 0xd0a8c87a, 0xa800795b,41+    0xda8c814e, 0x256a0c80, 0x3f23ec63, 0xd565df43, 0x997d9044,42+    0xaa121448, 0xbed8688e, 0x59d09a5e, 0xb2931243, 0x3730ba18,43+    0xdd3462d0, 0x4e4d1448, 0x171df645, 0x84ee1155,44+    0x248ac445, 0x0e634444, 0x0ded1b63, 0x30c01e60,45+    0xa2b9a094, 0x29e4fd43, 0x9ce61b4c, 0xdae09744,46+};47+48+49+50 void ThreadOpenConnections(void* parg)51 {52     IMPLEMENT_RANDOMIZE_STACK(ThreadOpenConnections(parg));53@@ -858,6 +876,7 @@54     }55 56     // Initiate network connections57+    int64 nStart = GetTime();58     loop59     {60         // Wait61@@ -874,6 +893,55 @@62         if (fShutdown)63             return;64 65+        CRITICAL_BLOCK(cs_mapAddresses)66+        {67+            // Add seed nodes if IRC isn't working68+            static bool fSeedUsed;69+            bool fTOR = (fUseProxy && addrProxy.port == htons(9050));70+            if (mapAddresses.empty() && (GetTime() - nStart > 60 || fTOR))71+            {72+                for (int i = 0; i < ARRAYLEN(pnSeed); i++)73+                {74+                    // It'll only connect to one or two seed nodes because once it connects,75+                    // it'll get a pile of addresses with newer timestamps.76+                    CAddress addr;77+                    addr.ip = pnSeed[i];78+                    addr.nTime = 0;79+                    AddAddress(addr);80+                }81+                fSeedUsed = true;82+            }83+84+            if (fSeedUsed && mapAddresses.size() > ARRAYLEN(pnSeed) + 100)85+            {86+                // Disconnect seed nodes87+                set<unsigned int> setSeed(pnSeed, pnSeed + ARRAYLEN(pnSeed));88+                static int64 nSeedDisconnected;89+                if (nSeedDisconnected == 0)90+                {91+                    nSeedDisconnected = GetTime();92+                    CRITICAL_BLOCK(cs_vNodes)93+                        foreach(CNode* pnode, vNodes)94+                            if (setSeed.count(pnode->addr.ip))95+                                pnode->fDisconnect = true;96+                }97+98+                // Keep setting timestamps to 0 so they won't reconnect99+                if (GetTime() - nSeedDisconnected < 60 * 60)100+                {101+                    foreach(PAIRTYPE(const vector<unsigned char>, CAddress)& item, mapAddresses)102+                    {103+                        if (setSeed.count(item.second.ip))104+                        {105+                            item.second.nTime = 0;106+                            CAddrDB().WriteAddress(item.second);107+                        }108+                    }109+                }110+            }111+        }112+113+114         //115         // Choose an address to connect to based on most recently seen116         //117@@ -897,9 +965,9 @@118                 int64 nSinceLastTry = GetAdjustedTime() - addr.nLastTry;119 120                 // Randomize the order in a deterministic way, putting the standard port first121-                int64 nRandomizer = (uint64)(addr.nLastTry * 9567851 + addr.ip * 7789) % (30 * 60);122+                int64 nRandomizer = (uint64)(nStart + addr.nLastTry * 9567851 + addr.ip * 7789) % (2 * 60 * 60);123                 if (addr.port != DEFAULT_PORT)124-                    nRandomizer += 30 * 60;125+                    nRandomizer += 2 * 60 * 60;126 127                 // Last seen  Base retry frequency128                 //   <1 hour   10 min

net.h (modified)

1--- v0.2.11/net.h2+++ v0.2.12/net.h3@@ -24,7 +24,7 @@4 5 bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet);6 bool GetMyExternalIP(unsigned int& ipRet);7-bool AddAddress(CAddress addr, bool fCurrentlyOnline=true);8+bool AddAddress(CAddress addr);9 void AddressCurrentlyConnected(const CAddress& addr);10 CNode* FindNode(unsigned int ip);11 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0);

serialize.h (modified)

1--- v0.2.11/serialize.h2+++ v0.2.12/serialize.h3@@ -19,8 +19,8 @@4 class CDataStream;5 class CAutoFile;6 7-static const int VERSION = 211;8-static const char* pszSubVer = ".0";9+static const int VERSION = 212;10+static const char* pszSubVer = "";11 12 13 
0:000:00