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