Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit max. nr. of PersistableNetworkPayload and ProtectedStorageEntries #3562

Merged
merged 6 commits into from Nov 5, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,6 +17,7 @@

package bisq.network.p2p.peers.getdata;

import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.network.CloseConnectionReason;
import bisq.network.p2p.network.Connection;
import bisq.network.p2p.network.NetworkNode;
Expand All @@ -39,6 +40,7 @@

import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -139,6 +141,7 @@ public void onFailure(@NotNull Throwable throwable) {
private Set<PersistableNetworkPayload> getFilteredPersistableNetworkPayload(GetDataRequest getDataRequest,
Connection connection) {
final Set<P2PDataStorage.ByteArray> tempLookupSet = new HashSet<>();
Optional<NodeAddress> peersNodeAddressOptional = connection.getPeersNodeAddressOptional();
Set<P2PDataStorage.ByteArray> excludedKeysAsByteArray = P2PDataStorage.ByteArray.convertBytesSetToByteArraySet(getDataRequest.getExcludedKeys());
AtomicInteger maxSize = new AtomicInteger(MAX_ENTRIES);
Set<PersistableNetworkPayload> result = dataStorage.getAppendOnlyDataStoreMap().entrySet().stream()
Expand All @@ -152,16 +155,20 @@ private Set<PersistableNetworkPayload> getFilteredPersistableNetworkPayload(GetD
})
.collect(Collectors.toSet());
if (maxSize.get() <= 0) {
log.warn("The peer request caused too much PersistableNetworkPayload entries to get delivered. We limited the entries for the response to {} entries", MAX_ENTRIES);
log.warn("The getData request from peer with node address {} caused too much PersistableNetworkPayload " +
"entries to get delivered. We limited the entries for the response to {} entries",
peersNodeAddressOptional, MAX_ENTRIES);
}
log.info("PersistableNetworkPayload set contains {} entries ", result.size());
log.info("The getData request from peer with node address {} contains {} PersistableNetworkPayload entries ",
peersNodeAddressOptional, result.size());
return result;
}

private Set<ProtectedStorageEntry> getFilteredProtectedStorageEntries(GetDataRequest getDataRequest,
Connection connection) {
final Set<ProtectedStorageEntry> filteredDataSet = new HashSet<>();
final Set<Integer> lookupSet = new HashSet<>();
Optional<NodeAddress> peersNodeAddressOptional = connection.getPeersNodeAddressOptional();

AtomicInteger maxSize = new AtomicInteger(MAX_ENTRIES);
Set<P2PDataStorage.ByteArray> excludedKeysAsByteArray = P2PDataStorage.ByteArray.convertBytesSetToByteArraySet(getDataRequest.getExcludedKeys());
Expand All @@ -171,7 +178,9 @@ private Set<ProtectedStorageEntry> getFilteredProtectedStorageEntries(GetDataReq
.map(Map.Entry::getValue)
.collect(Collectors.toSet());
if (maxSize.get() <= 0) {
log.warn("The peer request caused too much ProtectedStorageEntry entries to get delivered. We limited the entries for the response to {} entries", MAX_ENTRIES);
log.warn("The getData request from peer with node address {} caused too much ProtectedStorageEntry " +
"entries to get delivered. We limited the entries for the response to {} entries",
peersNodeAddressOptional, MAX_ENTRIES);
}
log.info("getFilteredProtectedStorageEntries " + filteredSet.size());

Expand All @@ -194,7 +203,8 @@ private Set<ProtectedStorageEntry> getFilteredProtectedStorageEntries(GetDataReq
}
}

log.info("ProtectedStorageEntry set contains {} entries ", filteredDataSet.size());
log.info("The getData request from peer with node address {} contains {} ProtectedStorageEntry entries ",
peersNodeAddressOptional, filteredDataSet.size());
return filteredDataSet;
}

Expand Down