Peer: Disconnect peers that doesn't send announced transactions.

This is to prevent a memory leak of pendingTxDownloads.
This commit is contained in:
Premek 2019-03-14 11:52:38 +01:00 committed by Andreas Schildbach
parent 89efe3d47e
commit 9267e7178d

View file

@ -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);
}