Skip to content

Commit

Permalink
Included PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
freimair committed Sep 1, 2020
1 parent 630efa4 commit 435cc3d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,27 +252,33 @@ private Set<byte[]> getKnownPayloadHashes() {
// an object gets removed in between PreliminaryGetDataRequest and the GetUpdatedDataRequest and we would
// miss that event if we do not load the full set or use some delta handling.
Set<byte[]> excludedKeys;
if (seedNodeRepository != null && seedNodeRepository.isSeedNode(networkNode.getNodeAddress())) {
excludedKeys = this.appendOnlyDataStoreService.getMap().keySet().stream()
.map(e -> e.bytes)
.collect(Collectors.toSet());
boolean weAreASeedNode = seedNodeRepository != null && seedNodeRepository.isSeedNode(networkNode.getNodeAddress());
if (weAreASeedNode) {
excludedKeys = getKeySetInBytes(this.appendOnlyDataStoreService.getMap());
} else {
excludedKeys = this.appendOnlyDataStoreService.getMap("since " + Version.VERSION).keySet().stream()
.map(e -> e.bytes)
.collect(Collectors.toSet());
excludedKeys = getKeySetInBytes(this.appendOnlyDataStoreService.getMap("since " + Version.VERSION));
}

Set<byte[]> excludedKeysFromPersistedEntryMap = this.map.keySet()
.stream()
.map(e -> e.bytes)
.collect(Collectors.toSet());
Set<byte[]> excludedKeysFromPersistedEntryMap = getKeySetInBytes(this.map);

excludedKeys.addAll(excludedKeysFromPersistedEntryMap);
excludedKeys.add(getSpecialKey());

return excludedKeys;
}

/**
* Helper for extracting hash bytes from a map of objects.
*
* @param input a map of objects
* @return a list of hash bytes of the objects in the input map
*/
private Set<byte[]> getKeySetInBytes(Map<ByteArray, ?> input) {
return input.keySet().stream()
.map(e -> e.bytes)
.collect(Collectors.toSet());
}

/**
* Generic function that can be used to filter a Map<ByteArray, ProtectedStorageEntry || PersistableNetworkPayload>
* by a given set of keys and peer capabilities.
Expand Down

0 comments on commit 435cc3d

Please sign in to comment.