34
34
#include < ctime>
35
35
#include < math.h>
36
36
37
- extern std::string NodeAddress (CNode* pfrom);
38
37
extern bool WalletOutOfSync ();
39
38
extern bool AskForOutstandingBlocks (uint256 hashStart);
40
39
extern void ResetTimerMain (std::string timer_name);
41
40
extern bool GridcoinServices ();
42
- std::string GetCommandNonce (std::string command);
43
41
44
42
unsigned int nNodeLifespan;
45
43
@@ -3740,7 +3738,7 @@ bool AskForOutstandingBlocks(uint256 hashStart)
3740
3738
LOCK (cs_vNodes);
3741
3739
for (auto const & pNode : vNodes)
3742
3740
{
3743
- if (!pNode->fClient && !pNode->fOneShot && (pNode->nStartingHeight > (nBestHeight - 144 )) && (pNode-> nVersion < NOBLKS_VERSION_START || pNode-> nVersion >= NOBLKS_VERSION_END) )
3741
+ if (!pNode->fClient && !pNode->fOneShot && (pNode->nStartingHeight > (nBestHeight - 144 )))
3744
3742
{
3745
3743
if (hashStart==uint256 ())
3746
3744
{
@@ -4376,19 +4374,6 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv)
4376
4374
// a large 4-byte int at any alignment.
4377
4375
unsigned char pchMessageStart[4 ] = { 0x70 , 0x35 , 0x22 , 0x05 };
4378
4376
4379
-
4380
- std::string NodeAddress (CNode* pfrom)
4381
- {
4382
- std::string ip = pfrom->addr .ToString ();
4383
- return ip;
4384
- }
4385
-
4386
- bool SecurityTest (CNode* pfrom, bool acid_test)
4387
- {
4388
- if (pfrom->nStartingHeight > (nBestHeight*.5 ) && acid_test) return true ;
4389
- return false ;
4390
- }
4391
-
4392
4377
bool static ProcessMessage (CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived)
4393
4378
{
4394
4379
RandAddSeedPerfmon ();
@@ -4427,40 +4412,35 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4427
4412
CAddress addrMe;
4428
4413
CAddress addrFrom;
4429
4414
uint64_t nNonce = 1 ;
4430
- std::string legacy_dummy;
4431
-
4432
- vRecv >> pfrom->nVersion
4433
- >> legacy_dummy // pfrom->boinchashnonce
4434
- >> legacy_dummy // pfrom->boinchashpw
4435
- >> legacy_dummy // pfrom->cpid
4436
- >> legacy_dummy // pfrom->enccpid
4437
- >> legacy_dummy // acid
4438
- >> pfrom->nServices
4439
- >> nTime
4440
- >> addrMe;
4415
+
4416
+ vRecv >> pfrom->nVersion ;
4417
+
4418
+ // In the version following 180324 (mandatory v5.0.0 - Fern), we can finally
4419
+ // drop the garbage legacy fields added to the version message:
4420
+ //
4421
+ if (pfrom->nVersion <= 180324 ) {
4422
+ std::string legacy_dummy;
4423
+ vRecv >> legacy_dummy // pfrom->boinchashnonce
4424
+ >> legacy_dummy // pfrom->boinchashpw
4425
+ >> legacy_dummy // pfrom->cpid
4426
+ >> legacy_dummy // pfrom->enccpid
4427
+ >> legacy_dummy; // acid
4428
+ }
4429
+
4430
+ vRecv >> pfrom->nServices >> nTime >> addrMe;
4441
4431
4442
4432
LogPrint (BCLog::LogFlags::NOISY, " received aries version %i ..." , pfrom->nVersion );
4443
4433
4444
4434
int64_t timedrift = std::abs (GetAdjustedTime () - nTime);
4445
4435
4446
- if (timedrift > (8 *60 ))
4447
- {
4436
+ if (timedrift > (8 *60 ))
4437
+ {
4448
4438
LogPrint (BCLog::LogFlags::NOISY, " Disconnecting unauthorized peer with Network Time so far off by %" PRId64 " seconds!" , timedrift);
4449
4439
pfrom->Misbehaving (100 );
4450
4440
pfrom->fDisconnect = true ;
4451
4441
return false ;
4452
4442
}
4453
4443
4454
-
4455
- // Ensure testnet users are running latest version as of 12-3-2015 (works in conjunction with block spamming)
4456
- if (pfrom->nVersion < 180321 && fTestNet )
4457
- {
4458
- // disconnect from peers older than this proto version
4459
- LogPrint (BCLog::LogFlags::NOISY, " Testnet partner %s using obsolete version %i; disconnecting" , pfrom->addr .ToString (), pfrom->nVersion );
4460
- pfrom->fDisconnect = true ;
4461
- return false ;
4462
- }
4463
-
4464
4444
if (pfrom->nVersion < MIN_PEER_PROTO_VERSION)
4465
4445
{
4466
4446
// disconnect from peers older than this proto version
@@ -4469,37 +4449,16 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4469
4449
return false ;
4470
4450
}
4471
4451
4472
- if (pfrom->nVersion < 180323 && !fTestNet && pindexBest->nHeight > 860500 )
4473
- {
4474
- // disconnect from peers older than this proto version - Enforce Beacon Age - 3-26-2017
4475
- LogPrint (BCLog::LogFlags::NOISY, " partner %s using obsolete version %i (before enforcing beacon age); disconnecting" , pfrom->addr .ToString (), pfrom->nVersion );
4476
- pfrom->fDisconnect = true ;
4477
- return false ;
4478
- }
4479
-
4480
- if (!fTestNet && pfrom->nVersion < 180314 )
4481
- {
4482
- // disconnect from peers older than this proto version
4483
- LogPrint (BCLog::LogFlags::NOISY, " ResearchAge: partner %s using obsolete version %i; disconnecting" , pfrom->addr .ToString (), pfrom->nVersion );
4484
- pfrom->fDisconnect = true ;
4485
- return false ;
4486
- }
4487
-
4488
- if (pfrom->nVersion == 10300 )
4489
- pfrom->nVersion = 300 ;
4490
4452
if (!vRecv.empty ())
4491
4453
vRecv >> addrFrom >> nNonce;
4492
4454
if (!vRecv.empty ())
4493
4455
vRecv >> pfrom->strSubVer ;
4494
-
4495
4456
if (!vRecv.empty ())
4496
4457
vRecv >> pfrom->nStartingHeight ;
4458
+
4497
4459
// 12-5-2015 - Append Trust fields
4498
4460
pfrom->nTrust = 0 ;
4499
4461
4500
- if (!vRecv.empty ()) vRecv >> legacy_dummy; // pfrom->sGRCAddress;
4501
-
4502
-
4503
4462
// Allow newbies to connect easily with 0 blocks
4504
4463
if (GetArgument (" autoban" ," true" ) == " true" )
4505
4464
{
@@ -4563,23 +4522,16 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4563
4522
}
4564
4523
4565
4524
// Get recent addresses
4566
- if (pfrom->fOneShot || pfrom->nVersion >= CADDR_TIME_VERSION || addrman.size () < 1000 )
4567
- {
4568
- pfrom->PushMessage (" getaddr" );
4569
- pfrom->fGetAddr = true ;
4570
- }
4525
+ pfrom->PushMessage (" getaddr" );
4526
+ pfrom->fGetAddr = true ;
4571
4527
addrman.Good (pfrom->addr );
4572
4528
}
4573
4529
else
4574
4530
{
4575
4531
if (((CNetAddr)pfrom->addr ) == (CNetAddr)addrFrom)
4576
4532
{
4577
- if (SecurityTest (pfrom,true ))
4578
- {
4579
- // Dont store the peer unless it passes the test
4580
- addrman.Add (addrFrom, addrFrom);
4581
- addrman.Good (addrFrom);
4582
- }
4533
+ addrman.Add (addrFrom, addrFrom);
4534
+ addrman.Good (addrFrom);
4583
4535
}
4584
4536
}
4585
4537
@@ -4588,8 +4540,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4588
4540
static int nAskedForBlocks = 0 ;
4589
4541
if (!pfrom->fClient && !pfrom->fOneShot &&
4590
4542
(pfrom->nStartingHeight > (nBestHeight - 144 )) &&
4591
- (pfrom->nVersion < NOBLKS_VERSION_START ||
4592
- pfrom->nVersion >= NOBLKS_VERSION_END) &&
4593
4543
(nAskedForBlocks < 1 || (vNodes.size () <= 1 && nAskedForBlocks < 1 )))
4594
4544
{
4595
4545
nAskedForBlocks++;
@@ -4619,7 +4569,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4619
4569
else if (pfrom->nVersion == 0 )
4620
4570
{
4621
4571
// Must have a version message before anything else 1-10-2015 Halford
4622
- LogPrintf (" Hack attempt from %s - %s (banned) " ,pfrom->addrName , NodeAddress ( pfrom));
4572
+ LogPrintf (" Hack attempt from %s - %s (banned) " , pfrom->addrName , pfrom-> addr . ToString ( ));
4623
4573
pfrom->Misbehaving (100 );
4624
4574
pfrom->fDisconnect =true ;
4625
4575
return false ;
@@ -4634,9 +4584,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4634
4584
vector<CAddress> vAddr;
4635
4585
vRecv >> vAddr;
4636
4586
4637
- // Don't want addr from older versions unless seeding
4638
- if (pfrom->nVersion < CADDR_TIME_VERSION && addrman.size () > 1000 )
4639
- return true ;
4640
4587
if (vAddr.size () > 1000 )
4641
4588
{
4642
4589
pfrom->Misbehaving (10 );
@@ -4678,8 +4625,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4678
4625
multimap<uint256, CNode*> mapMix;
4679
4626
for (auto const & pnode : vNodes)
4680
4627
{
4681
- if (pnode->nVersion < CADDR_TIME_VERSION)
4682
- continue ;
4683
4628
unsigned int nPointer;
4684
4629
memcpy (&nPointer, &pnode, sizeof (nPointer));
4685
4630
uint256 hashKey = ArithToUint256 (UintToArith256 (hashRand) ^ nPointer);
@@ -4794,9 +4739,16 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4794
4739
{
4795
4740
CBlock block;
4796
4741
block.ReadFromDisk ((*mi).second );
4797
- // HALFORD 12-26-2014
4798
- std::string acid = GetCommandNonce (" encrypt" );
4799
- pfrom->PushMessage (" encrypt" , block, acid);
4742
+
4743
+ // TODO: drop legacy "command nonce" removal transition in the next
4744
+ // release after the mandatory version:
4745
+ //
4746
+ if (pfrom->nVersion >= PROTOCOL_VERSION) {
4747
+ pfrom->PushMessage (" encrypt" , block);
4748
+ } else {
4749
+ std::string acid;
4750
+ pfrom->PushMessage (" encrypt" , block, acid);
4751
+ }
4800
4752
4801
4753
// Trigger them to send a getblocks request for the next batch of inventory
4802
4754
if (inv.hash == pfrom->hashContinue )
@@ -5020,8 +4972,16 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5020
4972
// Response from getblocks, message = block
5021
4973
5022
4974
CBlock block;
5023
- std::string acid = " " ;
5024
- vRecv >> block >> acid;
4975
+ vRecv >> block;
4976
+
4977
+ // TODO: drop legacy "command nonce" removal transition in the next
4978
+ // release after the mandatory version:
4979
+ //
4980
+ if (pfrom->nVersion < PROTOCOL_VERSION) {
4981
+ std::string acid;
4982
+ vRecv >> acid;
4983
+ }
4984
+
5025
4985
uint256 hashBlock = block.GetHash (true );
5026
4986
5027
4987
LogPrintf (" Received block %s; " , hashBlock.ToString ());
@@ -5095,25 +5055,29 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5095
5055
}
5096
5056
else if (strCommand == " ping" )
5097
5057
{
5098
- std::string acid = " " ;
5099
- if (pfrom->nVersion > BIP0031_VERSION)
5100
- {
5101
- uint64_t nonce = 0 ;
5102
- vRecv >> nonce >> acid;
5058
+ uint64_t nonce = 0 ;
5059
+ vRecv >> nonce;
5103
5060
5104
- // Echo the message back with the nonce. This allows for two useful features:
5105
- //
5106
- // 1) A remote node can quickly check if the connection is operational
5107
- // 2) Remote nodes can measure the latency of the network thread. If this node
5108
- // is overloaded it won't respond to pings quickly and the remote node can
5109
- // avoid sending us more work, like chain download requests.
5110
- //
5111
- // The nonce stops the remote getting confused between different pings: without
5112
- // it, if the remote node sends a ping once per second and this node takes 5
5113
- // seconds to respond to each, the 5th ping the remote sends would appear to
5114
- // return very quickly.
5115
- pfrom->PushMessage (" pong" , nonce);
5061
+ // TODO: drop legacy "command nonce" removal transition in the next
5062
+ // release after the mandatory version:
5063
+ //
5064
+ if (pfrom->nVersion < PROTOCOL_VERSION) {
5065
+ std::string acid;
5066
+ vRecv >> acid;
5116
5067
}
5068
+
5069
+ // Echo the message back with the nonce. This allows for two useful features:
5070
+ //
5071
+ // 1) A remote node can quickly check if the connection is operational
5072
+ // 2) Remote nodes can measure the latency of the network thread. If this node
5073
+ // is overloaded it won't respond to pings quickly and the remote node can
5074
+ // avoid sending us more work, like chain download requests.
5075
+ //
5076
+ // The nonce stops the remote getting confused between different pings: without
5077
+ // it, if the remote node sends a ping once per second and this node takes 5
5078
+ // seconds to respond to each, the 5th ping the remote sends would appear to
5079
+ // return very quickly.
5080
+ pfrom->PushMessage (" pong" , nonce);
5117
5081
}
5118
5082
else if (strCommand == " pong" )
5119
5083
{
@@ -5392,16 +5356,16 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
5392
5356
}
5393
5357
pto->fPingQueued = false ;
5394
5358
pto->nPingUsecStart = GetTimeMicros ();
5395
- if (pto->nVersion > BIP0031_VERSION)
5396
- {
5397
- pto->nPingNonceSent = nonce;
5398
- std::string acid = GetCommandNonce (" ping" );
5359
+ pto->nPingNonceSent = nonce;
5360
+
5361
+ // TODO: drop legacy "command nonce" removal transition in the next
5362
+ // release after the mandatory version:
5363
+ //
5364
+ if (pto->nVersion >= PROTOCOL_VERSION) {
5365
+ pto->PushMessage (" ping" , nonce);
5366
+ } else {
5367
+ std::string acid;
5399
5368
pto->PushMessage (" ping" , nonce, acid);
5400
- } else
5401
- {
5402
- // Peer is too old to support ping command with nonce, pong will never arrive.
5403
- pto->nPingNonceSent = 0 ;
5404
- pto->PushMessage (" ping" );
5405
5369
}
5406
5370
}
5407
5371
0 commit comments