@@ -683,7 +683,7 @@ static void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vec
683
683
684
684
} // namespace
685
685
686
- void PeerManager ::PushNodeVersion (CNode& pnode, int64_t nTime)
686
+ void PeerManagerImpl ::PushNodeVersion (CNode& pnode, int64_t nTime)
687
687
{
688
688
// Note that pnode->GetLocalServices() is a reflection of the local
689
689
// services we were offering when the CNode object was created for this
@@ -709,7 +709,7 @@ void PeerManager::PushNodeVersion(CNode& pnode, int64_t nTime)
709
709
}
710
710
}
711
711
712
- void PeerManager ::AddTxAnnouncement (const CNode& node, const GenTxid& gtxid, std::chrono::microseconds current_time)
712
+ void PeerManagerImpl ::AddTxAnnouncement (const CNode& node, const GenTxid& gtxid, std::chrono::microseconds current_time)
713
713
{
714
714
AssertLockHeld (::cs_main); // For m_txrequest
715
715
NodeId nodeid = node.GetId ();
@@ -745,7 +745,8 @@ void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
745
745
if (state) state->m_last_block_announcement = time_in_seconds;
746
746
}
747
747
748
- void PeerManager::InitializeNode (CNode *pnode) {
748
+ void PeerManagerImpl::InitializeNode (CNode *pnode)
749
+ {
749
750
CAddress addr = pnode->addr ;
750
751
std::string addrName = pnode->GetAddrName ();
751
752
NodeId nodeid = pnode->GetId ();
@@ -764,7 +765,7 @@ void PeerManager::InitializeNode(CNode *pnode) {
764
765
}
765
766
}
766
767
767
- void PeerManager ::ReattemptInitialBroadcast (CScheduler& scheduler) const
768
+ void PeerManagerImpl ::ReattemptInitialBroadcast (CScheduler& scheduler) const
768
769
{
769
770
std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs ();
770
771
@@ -785,7 +786,8 @@ void PeerManager::ReattemptInitialBroadcast(CScheduler& scheduler) const
785
786
scheduler.scheduleFromNow ([&] { ReattemptInitialBroadcast (scheduler); }, delta);
786
787
}
787
788
788
- void PeerManager::FinalizeNode (const CNode& node, bool & fUpdateConnectionTime ) {
789
+ void PeerManagerImpl::FinalizeNode (const CNode& node, bool & fUpdateConnectionTime )
790
+ {
789
791
NodeId nodeid = node.GetId ();
790
792
fUpdateConnectionTime = false ;
791
793
LOCK (cs_main);
@@ -839,14 +841,14 @@ void PeerManager::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) {
839
841
LogPrint (BCLog::NET, " Cleared nodestate for peer=%d\n " , nodeid);
840
842
}
841
843
842
- PeerRef PeerManager ::GetPeerRef (NodeId id) const
844
+ PeerRef PeerManagerImpl ::GetPeerRef (NodeId id) const
843
845
{
844
846
LOCK (m_peer_mutex);
845
847
auto it = m_peer_map.find (id);
846
848
return it != m_peer_map.end () ? it->second : nullptr ;
847
849
}
848
850
849
- PeerRef PeerManager ::RemovePeer (NodeId id)
851
+ PeerRef PeerManagerImpl ::RemovePeer (NodeId id)
850
852
{
851
853
PeerRef ret;
852
854
LOCK (m_peer_mutex);
@@ -858,7 +860,8 @@ PeerRef PeerManager::RemovePeer(NodeId id)
858
860
return ret;
859
861
}
860
862
861
- bool PeerManager::GetNodeStateStats (NodeId nodeid, CNodeStateStats &stats) {
863
+ bool PeerManagerImpl::GetNodeStateStats (NodeId nodeid, CNodeStateStats &stats)
864
+ {
862
865
{
863
866
LOCK (cs_main);
864
867
CNodeState* state = State (nodeid);
@@ -1015,7 +1018,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
1015
1018
return nEvicted;
1016
1019
}
1017
1020
1018
- void PeerManager ::Misbehaving (const NodeId pnode, const int howmuch, const std::string& message)
1021
+ void PeerManagerImpl ::Misbehaving (const NodeId pnode, const int howmuch, const std::string& message)
1019
1022
{
1020
1023
assert (howmuch > 0 );
1021
1024
@@ -1033,8 +1036,8 @@ void PeerManager::Misbehaving(const NodeId pnode, const int howmuch, const std::
1033
1036
}
1034
1037
}
1035
1038
1036
- bool PeerManager ::MaybePunishNodeForBlock (NodeId nodeid, const BlockValidationState& state,
1037
- bool via_compact_block, const std::string& message)
1039
+ bool PeerManagerImpl ::MaybePunishNodeForBlock (NodeId nodeid, const BlockValidationState& state,
1040
+ bool via_compact_block, const std::string& message)
1038
1041
{
1039
1042
switch (state.GetResult ()) {
1040
1043
case BlockValidationResult::BLOCK_RESULT_UNSET:
@@ -1083,7 +1086,7 @@ bool PeerManager::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationSt
1083
1086
return false ;
1084
1087
}
1085
1088
1086
- bool PeerManager ::MaybePunishNodeForTx (NodeId nodeid, const TxValidationState& state, const std::string& message)
1089
+ bool PeerManagerImpl ::MaybePunishNodeForTx (NodeId nodeid, const TxValidationState& state, const std::string& message)
1087
1090
{
1088
1091
switch (state.GetResult ()) {
1089
1092
case TxValidationResult::TX_RESULT_UNSET:
@@ -1129,9 +1132,16 @@ static bool BlockRequestAllowed(const CBlockIndex* pindex, const Consensus::Para
1129
1132
(GetBlockProofEquivalentTime (*pindexBestHeader, *pindex, *pindexBestHeader, consensusParams) < STALE_RELAY_AGE_LIMIT);
1130
1133
}
1131
1134
1132
- PeerManager::PeerManager (const CChainParams& chainparams, CConnman& connman, BanMan* banman,
1133
- CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool,
1134
- bool ignore_incoming_txs)
1135
+ std::unique_ptr<PeerManager> PeerManager::make (const CChainParams& chainparams, CConnman& connman, BanMan* banman,
1136
+ CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool,
1137
+ bool ignore_incoming_txs)
1138
+ {
1139
+ return std::make_unique<PeerManagerImpl>(chainparams, connman, banman, scheduler, chainman, pool, ignore_incoming_txs);
1140
+ }
1141
+
1142
+ PeerManagerImpl::PeerManagerImpl (const CChainParams& chainparams, CConnman& connman, BanMan* banman,
1143
+ CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool,
1144
+ bool ignore_incoming_txs)
1135
1145
: m_chainparams(chainparams),
1136
1146
m_connman(connman),
1137
1147
m_banman(banman),
@@ -1171,7 +1181,7 @@ PeerManager::PeerManager(const CChainParams& chainparams, CConnman& connman, Ban
1171
1181
* block, remember the recently confirmed transactions, and delete tracked
1172
1182
* announcements for them. Also save the time of the last tip update.
1173
1183
*/
1174
- void PeerManager ::BlockConnected (const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
1184
+ void PeerManagerImpl ::BlockConnected (const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
1175
1185
{
1176
1186
{
1177
1187
LOCK (g_cs_orphans);
@@ -1222,7 +1232,7 @@ void PeerManager::BlockConnected(const std::shared_ptr<const CBlock>& pblock, co
1222
1232
}
1223
1233
}
1224
1234
1225
- void PeerManager ::BlockDisconnected (const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex)
1235
+ void PeerManagerImpl ::BlockDisconnected (const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex)
1226
1236
{
1227
1237
// To avoid relay problems with transactions that were previously
1228
1238
// confirmed, clear our filter of recently confirmed transactions whenever
@@ -1247,7 +1257,8 @@ static bool fWitnessesPresentInMostRecentCompactBlock GUARDED_BY(cs_most_recent_
1247
1257
* Maintain state about the best-seen block and fast-announce a compact block
1248
1258
* to compatible peers.
1249
1259
*/
1250
- void PeerManager::NewPoWValidBlock (const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) {
1260
+ void PeerManagerImpl::NewPoWValidBlock (const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock)
1261
+ {
1251
1262
std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true );
1252
1263
const CNetMsgMaker msgMaker (PROTOCOL_VERSION);
1253
1264
@@ -1294,9 +1305,9 @@ void PeerManager::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_
1294
1305
* Update our best height and announce any block hashes which weren't previously
1295
1306
* in ::ChainActive() to our peers.
1296
1307
*/
1297
- void PeerManager ::UpdatedBlockTip (const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload )
1308
+ void PeerManagerImpl ::UpdatedBlockTip (const CBlockIndex * pindexNew, const CBlockIndex * pindexFork, bool fInitialDownload )
1298
1309
{
1299
- m_best_height = pindexNew->nHeight ;
1310
+ SetBestHeight ( pindexNew->nHeight ) ;
1300
1311
SetServiceFlagsIBDCache (!fInitialDownload );
1301
1312
1302
1313
// Don't relay inventory during initial block download.
@@ -1333,7 +1344,8 @@ void PeerManager::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockInde
1333
1344
* Handle invalid block rejection and consequent peer discouragement, maintain which
1334
1345
* peers announce compact blocks.
1335
1346
*/
1336
- void PeerManager::BlockChecked (const CBlock& block, const BlockValidationState& state) {
1347
+ void PeerManagerImpl::BlockChecked (const CBlock& block, const BlockValidationState& state)
1348
+ {
1337
1349
LOCK (cs_main);
1338
1350
1339
1351
const uint256 hash (block.GetHash ());
@@ -1761,7 +1773,8 @@ static uint32_t GetFetchFlags(const CNode& pfrom) EXCLUSIVE_LOCKS_REQUIRED(cs_ma
1761
1773
return nFetchFlags;
1762
1774
}
1763
1775
1764
- void PeerManager::SendBlockTransactions (CNode& pfrom, const CBlock& block, const BlockTransactionsRequest& req) {
1776
+ void PeerManagerImpl::SendBlockTransactions (CNode& pfrom, const CBlock& block, const BlockTransactionsRequest& req)
1777
+ {
1765
1778
BlockTransactions resp (req);
1766
1779
for (size_t i = 0 ; i < req.indexes .size (); i++) {
1767
1780
if (req.indexes [i] >= block.vtx .size ()) {
@@ -1776,9 +1789,9 @@ void PeerManager::SendBlockTransactions(CNode& pfrom, const CBlock& block, const
1776
1789
m_connman.PushMessage (&pfrom, msgMaker.Make (nSendFlags, NetMsgType::BLOCKTXN, resp));
1777
1790
}
1778
1791
1779
- void PeerManager ::ProcessHeadersMessage (CNode& pfrom, const Peer& peer,
1780
- const std::vector<CBlockHeader>& headers,
1781
- bool via_compact_block)
1792
+ void PeerManagerImpl ::ProcessHeadersMessage (CNode& pfrom, const Peer& peer,
1793
+ const std::vector<CBlockHeader>& headers,
1794
+ bool via_compact_block)
1782
1795
{
1783
1796
const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
1784
1797
size_t nCount = headers.size ();
@@ -1970,7 +1983,7 @@ void PeerManager::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
1970
1983
* may be added to if accepting an orphan causes its children to be
1971
1984
* reconsidered.
1972
1985
*/
1973
- void PeerManager ::ProcessOrphanTx (std::set<uint256>& orphan_work_set)
1986
+ void PeerManagerImpl ::ProcessOrphanTx (std::set<uint256>& orphan_work_set)
1974
1987
{
1975
1988
AssertLockHeld (cs_main);
1976
1989
AssertLockHeld (g_cs_orphans);
@@ -2267,9 +2280,9 @@ static void ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv, const CChainPar
2267
2280
connman.PushMessage (&peer, std::move (msg));
2268
2281
}
2269
2282
2270
- void PeerManager ::ProcessMessage (CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
2271
- const std::chrono::microseconds time_received,
2272
- const std::atomic<bool >& interruptMsgProc)
2283
+ void PeerManagerImpl ::ProcessMessage (CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
2284
+ const std::chrono::microseconds time_received,
2285
+ const std::atomic<bool >& interruptMsgProc)
2273
2286
{
2274
2287
LogPrint (BCLog::NET, " received: %s (%u bytes) peer=%d\n " , SanitizeString (msg_type), vRecv.size (), pfrom.GetId ());
2275
2288
@@ -3756,7 +3769,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
3756
3769
return ;
3757
3770
}
3758
3771
3759
- bool PeerManager ::MaybeDiscourageAndDisconnect (CNode& pnode)
3772
+ bool PeerManagerImpl ::MaybeDiscourageAndDisconnect (CNode& pnode)
3760
3773
{
3761
3774
const NodeId peer_id{pnode.GetId ()};
3762
3775
PeerRef peer = GetPeerRef (peer_id);
@@ -3798,7 +3811,7 @@ bool PeerManager::MaybeDiscourageAndDisconnect(CNode& pnode)
3798
3811
return true ;
3799
3812
}
3800
3813
3801
- bool PeerManager ::ProcessMessages (CNode* pfrom, std::atomic<bool >& interruptMsgProc)
3814
+ bool PeerManagerImpl ::ProcessMessages (CNode* pfrom, std::atomic<bool >& interruptMsgProc)
3802
3815
{
3803
3816
bool fMoreWork = false ;
3804
3817
@@ -3873,7 +3886,7 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgP
3873
3886
return fMoreWork ;
3874
3887
}
3875
3888
3876
- void PeerManager ::ConsiderEviction (CNode& pto, int64_t time_in_seconds)
3889
+ void PeerManagerImpl ::ConsiderEviction (CNode& pto, int64_t time_in_seconds)
3877
3890
{
3878
3891
AssertLockHeld (cs_main);
3879
3892
@@ -3926,7 +3939,7 @@ void PeerManager::ConsiderEviction(CNode& pto, int64_t time_in_seconds)
3926
3939
}
3927
3940
}
3928
3941
3929
- void PeerManager ::EvictExtraOutboundPeers (int64_t time_in_seconds)
3942
+ void PeerManagerImpl ::EvictExtraOutboundPeers (int64_t time_in_seconds)
3930
3943
{
3931
3944
// If we have any extra block-relay-only peers, disconnect the youngest unless
3932
3945
// it's given us a block -- in which case, compare with the second-youngest, and
@@ -4027,7 +4040,7 @@ void PeerManager::EvictExtraOutboundPeers(int64_t time_in_seconds)
4027
4040
}
4028
4041
}
4029
4042
4030
- void PeerManager ::CheckForStaleTipAndEvictPeers ()
4043
+ void PeerManagerImpl ::CheckForStaleTipAndEvictPeers ()
4031
4044
{
4032
4045
LOCK (cs_main);
4033
4046
@@ -4074,7 +4087,7 @@ class CompareInvMempoolOrder
4074
4087
};
4075
4088
}
4076
4089
4077
- bool PeerManager ::SendMessages (CNode* pto)
4090
+ bool PeerManagerImpl ::SendMessages (CNode* pto)
4078
4091
{
4079
4092
PeerRef peer = GetPeerRef (pto->GetId ());
4080
4093
const Consensus::Params& consensusParams = m_chainparams.GetConsensus ();
0 commit comments