@@ -905,6 +905,8 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
905905 case MSG_BLOCK:
906906 case MSG_WITNESS_BLOCK:
907907 return mapBlockIndex.count (inv.hash );
908+ case MSG_REFERRAL:
909+ return false ;
908910 }
909911 // Don't know what it is, just say we already got one
910912 return true ;
@@ -1123,6 +1125,13 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
11231125 if (!push) {
11241126 vNotFound.push_back (inv);
11251127 }
1128+ } else if (inv.type == MSG_REFERRAL) {
1129+ auto it = mempoolReferral.mapRTx .find (inv.hash );
1130+ int nSendFlags = 0 ;
1131+
1132+ if (it != mempoolReferral.mapRTx .end ()) {
1133+ connman.PushMessage (pfrom, msgMaker.Make (nSendFlags, NetMsgType::REF, *it->second ));
1134+ }
11261135 }
11271136
11281137 // Track requests for our stuff.
@@ -1526,7 +1535,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
15261535 }
15271536 }
15281537
1529-
15301538 else if (strCommand == NetMsgType::INV)
15311539 {
15321540 std::vector<CInv> vInv;
@@ -1777,6 +1785,15 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
17771785 connman.PushMessage (pfrom, msgMaker.Make (NetMsgType::HEADERS, vHeaders));
17781786 }
17791787
1788+ else if (strCommand == NetMsgType::REF) {
1789+ ReferralRef rtx;
1790+ vRecv >> rtx;
1791+
1792+ LogPrintf (" Referral message received\n " );
1793+
1794+ AcceptToReferralMemoryPool (mempoolReferral, rtx);
1795+ }
1796+
17801797
17811798 else if (strCommand == NetMsgType::TX)
17821799 {
@@ -2659,6 +2676,26 @@ static bool SendRejectsAndCheckIfBanned(CNode* pnode, CConnman& connman)
26592676 return false ;
26602677}
26612678
2679+ void SendInventoryReferralsRequest (CNode* pto, CConnman& connman, const CNetMsgMaker& msgMaker)
2680+ {
2681+ std::vector<CInv> vInv;
2682+
2683+ vInv.reserve (std::max<size_t >(pto->setInventoryReferralToSend .size (), INVENTORY_BROADCAST_MAX));
2684+
2685+ for (const uint256& hash: pto->setInventoryReferralToSend ) {
2686+ vInv.push_back (CInv (MSG_REFERRAL, hash));
2687+ if (vInv.size () == MAX_INV_SZ) {
2688+ connman.PushMessage (pto, msgMaker.Make (NetMsgType::INV, vInv));
2689+ vInv.clear ();
2690+ }
2691+ }
2692+
2693+ pto->setInventoryReferralToSend .clear ();
2694+
2695+ if (!vInv.empty ())
2696+ connman.PushMessage (pto, msgMaker.Make (NetMsgType::INV, vInv));
2697+ }
2698+
26622699bool ProcessMessages (CNode* pfrom, CConnman& connman, const std::atomic<bool >& interruptMsgProc)
26632700{
26642701 const CChainParams& chainparams = Params ();
@@ -3072,6 +3109,9 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic<bool>& interr
30723109 }
30733110 pto->vInventoryBlockToSend .clear ();
30743111
3112+ // Add referrals
3113+ SendInventoryReferralsRequest (pto, connman, msgMaker);
3114+
30753115 // Check whether periodic sends should happen
30763116 bool fSendTrickle = pto->fWhitelisted ;
30773117 if (pto->nNextInvSend < nNow) {
0 commit comments