@@ -1199,50 +1199,51 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
1199
1199
CAddress addrFrom;
1200
1200
uint64_t nNonce = 1 ;
1201
1201
uint64_t nServiceInt;
1202
- vRecv >> pfrom->nVersion >> nServiceInt >> nTime >> addrMe;
1203
- pfrom->nServices = ServiceFlags (nServiceInt);
1202
+ ServiceFlags nServices;
1203
+ int nVersion;
1204
+ int nSendVersion;
1205
+ std::string strSubVer;
1206
+ int nStartingHeight = -1 ;
1207
+ bool fRelay = true ;
1208
+
1209
+ vRecv >> nVersion >> nServiceInt >> nTime >> addrMe;
1210
+ nSendVersion = std::min (nVersion, PROTOCOL_VERSION);
1211
+ nServices = ServiceFlags (nServiceInt);
1204
1212
if (!pfrom->fInbound )
1205
1213
{
1206
- connman.SetServices (pfrom->addr , pfrom-> nServices );
1214
+ connman.SetServices (pfrom->addr , nServices);
1207
1215
}
1208
- if (pfrom->nServicesExpected & ~pfrom-> nServices )
1216
+ if (pfrom->nServicesExpected & ~nServices)
1209
1217
{
1210
- LogPrint (" net" , " peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n " , pfrom->id , pfrom-> nServices , pfrom->nServicesExpected );
1218
+ LogPrint (" net" , " peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n " , pfrom->id , nServices, pfrom->nServicesExpected );
1211
1219
connman.PushMessage (pfrom, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::REJECT, strCommand, REJECT_NONSTANDARD,
1212
1220
strprintf (" Expected to offer services %08x" , pfrom->nServicesExpected )));
1213
1221
pfrom->fDisconnect = true ;
1214
1222
return false ;
1215
1223
}
1216
1224
1217
- if (pfrom-> nVersion < MIN_PEER_PROTO_VERSION)
1225
+ if (nVersion < MIN_PEER_PROTO_VERSION)
1218
1226
{
1219
1227
// disconnect from peers older than this proto version
1220
- LogPrintf (" peer=%d using obsolete version %i; disconnecting\n " , pfrom->id , pfrom-> nVersion );
1228
+ LogPrintf (" peer=%d using obsolete version %i; disconnecting\n " , pfrom->id , nVersion);
1221
1229
connman.PushMessage (pfrom, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
1222
1230
strprintf (" Version must be %d or greater" , MIN_PEER_PROTO_VERSION)));
1223
1231
pfrom->fDisconnect = true ;
1224
1232
return false ;
1225
1233
}
1226
1234
1227
- if (pfrom-> nVersion == 10300 )
1228
- pfrom-> nVersion = 300 ;
1235
+ if (nVersion == 10300 )
1236
+ nVersion = 300 ;
1229
1237
if (!vRecv.empty ())
1230
1238
vRecv >> addrFrom >> nNonce;
1231
1239
if (!vRecv.empty ()) {
1232
- vRecv >> LIMITED_STRING (pfrom->strSubVer , MAX_SUBVERSION_LENGTH);
1233
- pfrom->cleanSubVer = SanitizeString (pfrom->strSubVer );
1240
+ vRecv >> LIMITED_STRING (strSubVer, MAX_SUBVERSION_LENGTH);
1234
1241
}
1235
1242
if (!vRecv.empty ()) {
1236
- vRecv >> pfrom-> nStartingHeight ;
1243
+ vRecv >> nStartingHeight;
1237
1244
}
1238
- {
1239
- LOCK (pfrom->cs_filter );
1240
- if (!vRecv.empty ())
1241
- vRecv >> pfrom->fRelayTxes ; // set to true after we get the first filter* message
1242
- else
1243
- pfrom->fRelayTxes = true ;
1244
- }
1245
-
1245
+ if (!vRecv.empty ())
1246
+ vRecv >> fRelay ;
1246
1247
// Disconnect if we connected to ourself
1247
1248
if (pfrom->fInbound && !connman.CheckIncomingNonce (nNonce))
1248
1249
{
@@ -1251,7 +1252,6 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
1251
1252
return true ;
1252
1253
}
1253
1254
1254
- pfrom->addrLocal = addrMe;
1255
1255
if (pfrom->fInbound && addrMe.IsRoutable ())
1256
1256
{
1257
1257
SeenLocal (addrMe);
@@ -1261,9 +1261,24 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
1261
1261
if (pfrom->fInbound )
1262
1262
PushNodeVersion (pfrom, connman, GetAdjustedTime ());
1263
1263
1264
- pfrom-> fClient = ! (pfrom-> nServices & NODE_NETWORK );
1264
+ connman. PushMessage (pfrom, CNetMsgMaker (INIT_PROTO_VERSION). Make (NetMsgType::VERACK) );
1265
1265
1266
- if ((pfrom->nServices & NODE_WITNESS))
1266
+ pfrom->nServices = nServices;
1267
+ pfrom->addrLocal = addrMe;
1268
+ pfrom->strSubVer = strSubVer;
1269
+ pfrom->cleanSubVer = SanitizeString (strSubVer);
1270
+ pfrom->nStartingHeight = nStartingHeight;
1271
+ pfrom->fClient = !(nServices & NODE_NETWORK);
1272
+ {
1273
+ LOCK (pfrom->cs_filter );
1274
+ pfrom->fRelayTxes = fRelay ; // set to true after we get the first filter* message
1275
+ }
1276
+
1277
+ // Change version
1278
+ pfrom->SetSendVersion (nSendVersion);
1279
+ pfrom->nVersion = nVersion;
1280
+
1281
+ if ((nServices & NODE_WITNESS))
1267
1282
{
1268
1283
LOCK (cs_main);
1269
1284
State (pfrom->GetId ())->fHaveWitness = true ;
@@ -1275,11 +1290,6 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
1275
1290
UpdatePreferredDownload (pfrom, State (pfrom->GetId ()));
1276
1291
}
1277
1292
1278
- // Change version
1279
- connman.PushMessage (pfrom, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::VERACK));
1280
- int nSendVersion = std::min (pfrom->nVersion , PROTOCOL_VERSION);
1281
- pfrom->SetSendVersion (nSendVersion);
1282
-
1283
1293
if (!pfrom->fInbound )
1284
1294
{
1285
1295
// Advertise our address
@@ -1307,8 +1317,6 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
1307
1317
connman.MarkAddressGood (pfrom->addr );
1308
1318
}
1309
1319
1310
- pfrom->fSuccessfullyConnected = true ;
1311
-
1312
1320
std::string remoteAddr;
1313
1321
if (fLogIPs )
1314
1322
remoteAddr = " , peeraddr=" + pfrom->addr .ToString ();
@@ -1350,7 +1358,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
1350
1358
1351
1359
if (strCommand == NetMsgType::VERACK)
1352
1360
{
1353
- pfrom->SetRecvVersion (std::min (pfrom->nVersion , PROTOCOL_VERSION));
1361
+ pfrom->SetRecvVersion (std::min (pfrom->nVersion . load () , PROTOCOL_VERSION));
1354
1362
1355
1363
if (!pfrom->fInbound ) {
1356
1364
// Mark this node as currently connected, so we update its timestamp later.
@@ -1378,6 +1386,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
1378
1386
nCMPCTBLOCKVersion = 1 ;
1379
1387
connman.PushMessage (pfrom, msgMaker.Make (NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK , nCMPCTBLOCKVersion));
1380
1388
}
1389
+ pfrom->fSuccessfullyConnected = true ;
1381
1390
}
1382
1391
1383
1392
@@ -2716,8 +2725,8 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
2716
2725
{
2717
2726
const Consensus::Params& consensusParams = Params ().GetConsensus ();
2718
2727
{
2719
- // Don't send anything until we get its version message
2720
- if (pto->nVersion == 0 || pto->fDisconnect )
2728
+ // Don't send anything until the version handshake is complete
2729
+ if (! pto->fSuccessfullyConnected || pto->fDisconnect )
2721
2730
return true ;
2722
2731
2723
2732
// If we get here, the outgoing message serialization version is set and can't change.
0 commit comments