mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 06:47:54 +01:00
Peer: Disconnect peers that doesn't send announced transactions.
This is to prevent a memory leak of pendingTxDownloads.
This commit is contained in:
parent
89efe3d47e
commit
9267e7178d
1 changed files with 6 additions and 0 deletions
|
@ -128,6 +128,7 @@ public class Peer extends PeerSocketHandler {
|
|||
// to keep it pinned to the root set if they care about this data.
|
||||
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
|
||||
private final HashSet<TransactionConfidence> pendingTxDownloads = new HashSet<>();
|
||||
private static final int PENDING_TX_DOWNLOADS_LIMIT = 100;
|
||||
// The lowest version number we're willing to accept. Lower than this will result in an immediate disconnect.
|
||||
private volatile int vMinProtocolVersion;
|
||||
// When an API user explicitly requests a block or transaction from a peer, the InventoryItem is put here
|
||||
|
@ -1215,6 +1216,11 @@ public class Peer extends PeerSocketHandler {
|
|||
} else {
|
||||
log.debug("{}: getdata on tx {}", getAddress(), item.hash);
|
||||
getdata.addTransaction(item.hash, vPeerVersionMessage.isWitnessSupported());
|
||||
if (pendingTxDownloads.size() > PENDING_TX_DOWNLOADS_LIMIT) {
|
||||
log.info("{}: Too many pending transactions, disconnecting", this);
|
||||
close();
|
||||
return;
|
||||
}
|
||||
// Register with the garbage collector that we care about the confidence data for a while.
|
||||
pendingTxDownloads.add(conf);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue