Refactor: rename

This commit is contained in:
chimp1984 2021-01-12 17:34:28 -05:00
parent 364a7f524c
commit a21d79ad63
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -437,27 +437,27 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
} }
} }
private void onBundleOfEnvelopes(BundleOfEnvelopes networkEnvelope, Connection connection) { private void onBundleOfEnvelopes(BundleOfEnvelopes bundleOfEnvelopes, Connection connection) {
Map<P2PDataStorage.ByteArray, Set<NetworkEnvelope>> itemsByHash = new HashMap<>(); Map<P2PDataStorage.ByteArray, Set<NetworkEnvelope>> itemsByHash = new HashMap<>();
Set<NetworkEnvelope> envelopesToProcess = new HashSet<>(); Set<NetworkEnvelope> envelopesToProcess = new HashSet<>();
List<NetworkEnvelope> networkEnvelopes = networkEnvelope.getEnvelopes(); List<NetworkEnvelope> networkEnvelopes = bundleOfEnvelopes.getEnvelopes();
for (NetworkEnvelope current : networkEnvelopes) { for (NetworkEnvelope networkEnvelope : networkEnvelopes) {
if (current instanceof AddPersistableNetworkPayloadMessage) { if (networkEnvelope instanceof AddPersistableNetworkPayloadMessage) {
PersistableNetworkPayload persistableNetworkPayload = ((AddPersistableNetworkPayloadMessage) current).getPersistableNetworkPayload(); PersistableNetworkPayload persistableNetworkPayload = ((AddPersistableNetworkPayloadMessage) networkEnvelope).getPersistableNetworkPayload();
byte[] hash = persistableNetworkPayload.getHash(); byte[] hash = persistableNetworkPayload.getHash();
String itemName = persistableNetworkPayload.getClass().getSimpleName(); String itemName = persistableNetworkPayload.getClass().getSimpleName();
P2PDataStorage.ByteArray byteArray = new P2PDataStorage.ByteArray(hash); P2PDataStorage.ByteArray byteArray = new P2PDataStorage.ByteArray(hash);
itemsByHash.putIfAbsent(byteArray, new HashSet<>()); itemsByHash.putIfAbsent(byteArray, new HashSet<>());
Set<NetworkEnvelope> envelopesByHash = itemsByHash.get(byteArray); Set<NetworkEnvelope> envelopesByHash = itemsByHash.get(byteArray);
if (!envelopesByHash.contains(current)) { if (!envelopesByHash.contains(networkEnvelope)) {
envelopesByHash.add(current); envelopesByHash.add(networkEnvelope);
envelopesToProcess.add(current); envelopesToProcess.add(networkEnvelope);
} else { } else {
log.debug("We got duplicated items for {}. We ignore the duplicates. Hash: {}", log.debug("We got duplicated items for {}. We ignore the duplicates. Hash: {}",
itemName, Utilities.encodeToHex(hash)); itemName, Utilities.encodeToHex(hash));
} }
} else { } else {
envelopesToProcess.add(current); envelopesToProcess.add(networkEnvelope);
} }
} }
envelopesToProcess.forEach(envelope -> UserThread.execute(() -> envelopesToProcess.forEach(envelope -> UserThread.execute(() ->