@@ -929,7 +929,7 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits)
929929
930930bool IsInitialBlockDownload ()
931931{
932- if (pindexBest == NULL )
932+ if (pindexBest == NULL || nBestHeight < 74000 )
933933 return true ;
934934 static int64 nLastUpdate;
935935 static CBlockIndex* pindexLastBest;
@@ -2172,6 +2172,24 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
21722172 if (pfrom->nVersion < 209 )
21732173 pfrom->vRecv .SetVersion (min (pfrom->nVersion , VERSION));
21742174
2175+ if (!pfrom->fInbound )
2176+ {
2177+ // Advertise our address
2178+ if (addrLocalHost.IsRoutable () && !fUseProxy )
2179+ {
2180+ CAddress addr (addrLocalHost);
2181+ addr.nTime = GetAdjustedTime ();
2182+ pfrom->PushAddress (addr);
2183+ }
2184+
2185+ // Get recent addresses
2186+ if (pfrom->nVersion >= 31402 || mapAddresses.size () < 1000 )
2187+ {
2188+ pfrom->PushMessage (" getaddr" );
2189+ pfrom->fGetAddr = true ;
2190+ }
2191+ }
2192+
21752193 // Ask the first connected node for block updates
21762194 static int nAskedForBlocks;
21772195 if (!pfrom->fClient && (nAskedForBlocks < 1 || vNodes.size () <= 1 ))
@@ -2208,27 +2226,30 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
22082226 {
22092227 vector<CAddress> vAddr;
22102228 vRecv >> vAddr;
2211- if (pfrom->nVersion < 200 ) // don't want addresses from 0.1.5
2229+
2230+ // Don't want addr from older versions unless seeding
2231+ if (pfrom->nVersion < 209 )
22122232 return true ;
2213- if (pfrom->nVersion < 209 && mapAddresses.size () > 1000 ) // don't want addr from 0.2.0 unless seeding
2233+ if (pfrom->nVersion < 31402 && mapAddresses.size () > 1000 )
22142234 return true ;
22152235 if (vAddr.size () > 1000 )
22162236 return error (" message addr size() = %d" , vAddr.size ());
22172237
22182238 // Store the new addresses
2239+ int64 nNow = GetAdjustedTime ();
2240+ int64 nSince = nNow - 10 * 60 ;
22192241 foreach (CAddress& addr, vAddr)
22202242 {
22212243 if (fShutdown )
22222244 return true ;
22232245 // ignore IPv6 for now, since it isn't implemented anyway
22242246 if (!addr.IsIPv4 ())
22252247 continue ;
2226- addr.nTime = GetAdjustedTime () - 2 * 60 * 60 ;
2227- if (pfrom->fGetAddr || vAddr.size () > 10 )
2228- addr.nTime -= 5 * 24 * 60 * 60 ;
2229- AddAddress (addr);
2248+ if (addr.nTime <= 100000000 || addr.nTime > nNow + 10 * 60 )
2249+ addr.nTime = nNow - 5 * 24 * 60 * 60 ;
2250+ AddAddress (addr, 2 * 60 * 60 );
22302251 pfrom->AddAddressKnown (addr);
2231- if (!pfrom->fGetAddr && vAddr.size () <= 10 && addr.IsRoutable ())
2252+ if (addr. nTime > nSince && !pfrom->fGetAddr && vAddr.size () <= 10 && addr.IsRoutable ())
22322253 {
22332254 // Relay to a limited number of other nodes
22342255 CRITICAL_BLOCK (cs_vNodes)
@@ -2243,6 +2264,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
22432264 multimap<uint256, CNode*> mapMix;
22442265 foreach (CNode* pnode, vNodes)
22452266 {
2267+ if (pnode->nVersion < 31402 )
2268+ continue ;
22462269 unsigned int nPointer;
22472270 memcpy (&nPointer, &pnode, sizeof (nPointer));
22482271 uint256 hashKey = hashRand ^ nPointer;
@@ -2610,9 +2633,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
26102633 if (pto->nLastSend && GetTime () - pto->nLastSend > 30 * 60 && pto->vSend .empty ())
26112634 pto->PushMessage (" ping" );
26122635
2636+ // Resend wallet transactions that haven't gotten in a block yet
2637+ ResendWalletTransactions ();
2638+
26132639 // Address refresh broadcast
26142640 static int64 nLastRebroadcast;
2615- if (GetTime () - nLastRebroadcast > 24 * 60 * 60 ) // every 24 hours
2641+ if (GetTime () - nLastRebroadcast > 24 * 60 * 60 )
26162642 {
26172643 nLastRebroadcast = GetTime ();
26182644 CRITICAL_BLOCK (cs_vNodes)
@@ -2624,13 +2650,42 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
26242650
26252651 // Rebroadcast our address
26262652 if (addrLocalHost.IsRoutable () && !fUseProxy )
2627- pnode->PushAddress (addrLocalHost);
2653+ {
2654+ CAddress addr (addrLocalHost);
2655+ addr.nTime = GetAdjustedTime ();
2656+ pnode->PushAddress (addr);
2657+ }
26282658 }
26292659 }
26302660 }
26312661
2632- // Resend wallet transactions that haven't gotten in a block yet
2633- ResendWalletTransactions ();
2662+ // Clear out old addresses periodically so it's not too much work at once
2663+ static int64 nLastClear;
2664+ if (nLastClear == 0 )
2665+ nLastClear = GetTime ();
2666+ if (GetTime () - nLastClear > 10 * 60 && vNodes.size () >= 3 )
2667+ {
2668+ nLastClear = GetTime ();
2669+ CRITICAL_BLOCK (cs_mapAddresses)
2670+ {
2671+ CAddrDB addrdb;
2672+ int64 nSince = GetAdjustedTime () - 14 * 24 * 60 * 60 ;
2673+ for (map<vector<unsigned char >, CAddress>::iterator mi = mapAddresses.begin ();
2674+ mi != mapAddresses.end ();)
2675+ {
2676+ const CAddress& addr = (*mi).second ;
2677+ if (addr.nTime < nSince)
2678+ {
2679+ if (mapAddresses.size () < 1000 || GetTime () > nLastClear + 20 )
2680+ break ;
2681+ addrdb.EraseAddress (addr);
2682+ mapAddresses.erase (mi++);
2683+ }
2684+ else
2685+ mi++;
2686+ }
2687+ }
2688+ }
26342689
26352690
26362691 //
0 commit comments