Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_NET_PROCESSING_H | #ifndef BITCOIN_NET_PROCESSING_H | ||||
#define BITCOIN_NET_PROCESSING_H | #define BITCOIN_NET_PROCESSING_H | ||||
#include "consensus/params.h" | #include "consensus/params.h" | ||||
#include "net.h" | #include "net.h" | ||||
#include "rwcollection.h" | |||||
#include "validationinterface.h" | #include "validationinterface.h" | ||||
class Config; | class Config; | ||||
/** | /** | ||||
* Default for -maxorphantx, maximum number of orphan transactions kept in | * Default for -maxorphantx, maximum number of orphan transactions kept in | ||||
* memory. | * memory. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | struct CNodeStateStats { | ||||
std::vector<int> vHeightInFlight; | std::vector<int> vHeightInFlight; | ||||
}; | }; | ||||
/** Get statistics from node state */ | /** Get statistics from node state */ | ||||
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats); | bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats); | ||||
/** Increase a node's misbehavior score. */ | /** Increase a node's misbehavior score. */ | ||||
void Misbehaving(NodeId nodeid, int howmuch, const std::string &reason); | void Misbehaving(NodeId nodeid, int howmuch, const std::string &reason); | ||||
struct COrphanTx { | |||||
// When modifying, adapt the copy of this definition in tests/DoS_tests. | |||||
CTransactionRef tx; | |||||
NodeId fromPeer; | |||||
int64_t nTimeExpire; | |||||
}; | |||||
////////////////////////////////////////////////////////////////////////////// | |||||
// | |||||
// OrphanPool | |||||
// | |||||
struct IteratorComparator { | |||||
template <typename I> bool operator()(const I &a, const I &b) { | |||||
return &(*a) < &(*b); | |||||
} | |||||
}; | |||||
class OrphanPool { | |||||
private: | |||||
typedef RWCollection<std::map<uint256, COrphanTx>> MapTxns; | |||||
MapTxns mapOrphanTransactions; | |||||
typedef RWCollection< | |||||
std::map<COutPoint, std::set<std::map<uint256, COrphanTx>::iterator, | |||||
IteratorComparator>>> | |||||
MapTxnsByPrev; | |||||
MapTxnsByPrev mapOrphanTransactionsByPrev; | |||||
mutable CCriticalSection cs_extraTxn; | |||||
size_t vExtraTxnForCompactIt = 0; | |||||
typedef RWCollection<std::vector<std::pair<uint256, CTransactionRef>>> | |||||
TxnForCompact; | |||||
TxnForCompact vExtraTxnForCompact; | |||||
// For internal use | |||||
int EraseOrphanTxInternal(uint256 hash, MapTxns::WriteView &orphanTxns, | |||||
MapTxnsByPrev::WriteView &orphanTxnsByPrev); | |||||
public: | |||||
int EraseOrphanTx(uint256 hash); | |||||
void AddToCompactExtraTransactions(const CTransactionRef &tx); | |||||
bool AddOrphanTx(const CTransactionRef &tx, NodeId peer); | |||||
void EraseOrphansFor(NodeId peer); | |||||
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans); | |||||
bool HaveTransaction(uint256 txid) { | |||||
return mapOrphanTransactions.getReadView()->count(txid) > 0; | |||||
} | |||||
MapTxns::ReadView OrphanTransactions() { | |||||
return mapOrphanTransactions.getReadView(); | |||||
} | |||||
MapTxnsByPrev::ReadView OrphanTransactionsByPrev() { | |||||
return mapOrphanTransactionsByPrev.getReadView(); | |||||
} | |||||
TxnForCompact::ReadView ExtraTxnForCompact() { | |||||
return vExtraTxnForCompact.getReadView(); | |||||
} | |||||
void clear() { | |||||
mapOrphanTransactions.getWriteView()->clear(); | |||||
mapOrphanTransactionsByPrev.getWriteView()->clear(); | |||||
} | |||||
}; | |||||
extern OrphanPool g_orphanPool; | |||||
#endif // BITCOIN_NET_PROCESSING_H | #endif // BITCOIN_NET_PROCESSING_H |