@ -1199,50 +1199,51 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
@@ -1199,50 +1199,51 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
CAddress addrFrom ;
uint64_t nNonce = 1 ;
uint64_t nServiceInt ;
vRecv > > pfrom - > nVersion > > nServiceInt > > nTime > > addrMe ;
pfrom - > nServices = ServiceFlags ( nServiceInt ) ;
ServiceFlags nServices ;
int nVersion ;
int nSendVersion ;
std : : string strSubVer ;
int nStartingHeight = - 1 ;
bool fRelay = true ;
vRecv > > nVersion > > nServiceInt > > nTime > > addrMe ;
nSendVersion = std : : min ( nVersion , PROTOCOL_VERSION ) ;
nServices = ServiceFlags ( nServiceInt ) ;
if ( ! pfrom - > fInbound )
{
connman . SetServices ( pfrom - > addr , pfrom - > nServices ) ;
connman . SetServices ( pfrom - > addr , nServices ) ;
}
if ( pfrom - > nServicesExpected & ~ pfrom - > nServices )
if ( pfrom - > nServicesExpected & ~ nServices )
{
LogPrint ( " net " , " peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting \n " , pfrom - > id , pfrom - > nServices , pfrom - > nServicesExpected ) ;
LogPrint ( " net " , " peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting \n " , pfrom - > id , nServices , pfrom - > nServicesExpected ) ;
connman . PushMessage ( pfrom , CNetMsgMaker ( INIT_PROTO_VERSION ) . Make ( NetMsgType : : REJECT , strCommand , REJECT_NONSTANDARD ,
strprintf ( " Expected to offer services %08x " , pfrom - > nServicesExpected ) ) ) ;
pfrom - > fDisconnect = true ;
return false ;
}
if ( pfrom - > nVersion < MIN_PEER_PROTO_VERSION )
if ( nVersion < MIN_PEER_PROTO_VERSION )
{
// disconnect from peers older than this proto version
LogPrintf ( " peer=%d using obsolete version %i; disconnecting \n " , pfrom - > id , pfrom - > nVersion ) ;
LogPrintf ( " peer=%d using obsolete version %i; disconnecting \n " , pfrom - > id , nVersion ) ;
connman . PushMessage ( pfrom , CNetMsgMaker ( INIT_PROTO_VERSION ) . Make ( NetMsgType : : REJECT , strCommand , REJECT_OBSOLETE ,
strprintf ( " Version must be %d or greater " , MIN_PEER_PROTO_VERSION ) ) ) ;
pfrom - > fDisconnect = true ;
return false ;
}
if ( pfrom - > nVersion = = 10300 )
pfrom - > nVersion = 300 ;
if ( nVersion = = 10300 )
nVersion = 300 ;
if ( ! vRecv . empty ( ) )
vRecv > > addrFrom > > nNonce ;
if ( ! vRecv . empty ( ) ) {
vRecv > > LIMITED_STRING ( pfrom - > strSubVer , MAX_SUBVERSION_LENGTH ) ;
pfrom - > cleanSubVer = SanitizeString ( pfrom - > strSubVer ) ;
vRecv > > LIMITED_STRING ( strSubVer , MAX_SUBVERSION_LENGTH ) ;
}
if ( ! vRecv . empty ( ) ) {
vRecv > > pfrom - > nStartingHeight ;
vRecv > > nStartingHeight ;
}
{
LOCK ( pfrom - > cs_filter ) ;
if ( ! vRecv . empty ( ) )
vRecv > > pfrom - > fRelayTxes ; // set to true after we get the first filter* message
else
pfrom - > fRelayTxes = true ;
}
if ( ! vRecv . empty ( ) )
vRecv > > fRelay ;
// Disconnect if we connected to ourself
if ( pfrom - > fInbound & & ! connman . CheckIncomingNonce ( nNonce ) )
{
@ -1251,7 +1252,6 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
@@ -1251,7 +1252,6 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
return true ;
}
pfrom - > addrLocal = addrMe ;
if ( pfrom - > fInbound & & addrMe . IsRoutable ( ) )
{
SeenLocal ( addrMe ) ;
@ -1261,9 +1261,24 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
@@ -1261,9 +1261,24 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
if ( pfrom - > fInbound )
PushNodeVersion ( pfrom , connman , GetAdjustedTime ( ) ) ;
pfrom - > fClient = ! ( pfrom - > nServices & NODE_NETWORK ) ;
connman . PushMessage ( pfrom , CNetMsgMaker ( INIT_PROTO_VERSION ) . Make ( NetMsgType : : VERACK ) ) ;
if ( ( pfrom - > nServices & NODE_WITNESS ) )
pfrom - > nServices = nServices ;
pfrom - > addrLocal = addrMe ;
pfrom - > strSubVer = strSubVer ;
pfrom - > cleanSubVer = SanitizeString ( strSubVer ) ;
pfrom - > nStartingHeight = nStartingHeight ;
pfrom - > fClient = ! ( nServices & NODE_NETWORK ) ;
{
LOCK ( pfrom - > cs_filter ) ;
pfrom - > fRelayTxes = fRelay ; // set to true after we get the first filter* message
}
// Change version
pfrom - > SetSendVersion ( nSendVersion ) ;
pfrom - > nVersion = nVersion ;
if ( ( nServices & NODE_WITNESS ) )
{
LOCK ( cs_main ) ;
State ( pfrom - > GetId ( ) ) - > fHaveWitness = true ;
@ -1275,11 +1290,6 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
@@ -1275,11 +1290,6 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
UpdatePreferredDownload ( pfrom , State ( pfrom - > GetId ( ) ) ) ;
}
// Change version
connman . PushMessage ( pfrom , CNetMsgMaker ( INIT_PROTO_VERSION ) . Make ( NetMsgType : : VERACK ) ) ;
int nSendVersion = std : : min ( pfrom - > nVersion , PROTOCOL_VERSION ) ;
pfrom - > SetSendVersion ( nSendVersion ) ;
if ( ! pfrom - > fInbound )
{
// Advertise our address
@ -1307,8 +1317,6 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
@@ -1307,8 +1317,6 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
connman . MarkAddressGood ( pfrom - > addr ) ;
}
pfrom - > fSuccessfullyConnected = true ;
std : : string remoteAddr ;
if ( fLogIPs )
remoteAddr = " , peeraddr= " + pfrom - > addr . ToString ( ) ;
@ -1350,7 +1358,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
@@ -1350,7 +1358,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
if ( strCommand = = NetMsgType : : VERACK )
{
pfrom - > SetRecvVersion ( std : : min ( pfrom - > nVersion , PROTOCOL_VERSION ) ) ;
pfrom - > SetRecvVersion ( std : : min ( pfrom - > nVersion . load ( ) , PROTOCOL_VERSION ) ) ;
if ( ! pfrom - > fInbound ) {
// 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,6 +1386,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
nCMPCTBLOCKVersion = 1 ;
connman . PushMessage ( pfrom , msgMaker . Make ( NetMsgType : : SENDCMPCT , fAnnounceUsingCMPCTBLOCK , nCMPCTBLOCKVersion ) ) ;
}
pfrom - > fSuccessfullyConnected = true ;
}
@ -2716,8 +2725,8 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
@@ -2716,8 +2725,8 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
{
const Consensus : : Params & consensusParams = Params ( ) . GetConsensus ( ) ;
{
// Don't send anything until we get its version messag e
if ( pto - > nVersion = = 0 | | pto - > fDisconnect )
// Don't send anything until the version handshake is complet e
if ( ! pto - > fSuccessfullyConnected | | pto - > fDisconnect )
return true ;
// If we get here, the outgoing message serialization version is set and can't change.