Small code reorganization to improve logic when adding arbitrary peer data

This commit is contained in:
CalDescent 2022-01-05 19:26:06 +00:00
parent 3394543705
commit b42674ac06
2 changed files with 11 additions and 13 deletions

View File

@ -136,14 +136,13 @@ public class ArbitraryDataFileManager {
if (receivedAtLeastOneFile) { if (receivedAtLeastOneFile) {
// Update our lookup table to indicate that this peer holds data for this signature // Update our lookup table to indicate that this peer holds data for this signature
String peerAddress = peer.getPeerData().getAddress().toString(); String peerAddress = peer.getPeerData().getAddress().toString();
LOGGER.debug("Adding arbitrary peer: {} for signature {}", peerAddress, Base58.encode(signature));
ArbitraryPeerData arbitraryPeerData = new ArbitraryPeerData(signature, peer); ArbitraryPeerData arbitraryPeerData = new ArbitraryPeerData(signature, peer);
repository.discardChanges(); repository.discardChanges();
if (!arbitraryPeerData.isPeerAddressValid()) { if (arbitraryPeerData.isPeerAddressValid()) {
return false; LOGGER.debug("Adding arbitrary peer: {} for signature {}", peerAddress, Base58.encode(signature));
repository.getArbitraryRepository().save(arbitraryPeerData);
repository.saveChanges();
} }
repository.getArbitraryRepository().save(arbitraryPeerData);
repository.saveChanges();
// Invalidate the hosted transactions cache as we are now hosting something new // Invalidate the hosted transactions cache as we are now hosting something new
ArbitraryDataStorageManager.getInstance().invalidateHostedTransactionsCache(); ArbitraryDataStorageManager.getInstance().invalidateHostedTransactionsCache();

View File

@ -413,17 +413,16 @@ public class ArbitraryDataManager extends Thread {
if (existingEntry == null) { if (existingEntry == null) {
// We haven't got a record of this mapping yet, so add it // We haven't got a record of this mapping yet, so add it
LOGGER.debug("Adding arbitrary peer: {} for signature {}", peerAddress, Base58.encode(signature));
ArbitraryPeerData arbitraryPeerData = new ArbitraryPeerData(signature, peerAddress); ArbitraryPeerData arbitraryPeerData = new ArbitraryPeerData(signature, peerAddress);
repository.discardChanges(); repository.discardChanges();
if (!arbitraryPeerData.isPeerAddressValid()) { if (arbitraryPeerData.isPeerAddressValid()) {
return; LOGGER.debug("Adding arbitrary peer: {} for signature {}", peerAddress, Base58.encode(signature));
} repository.getArbitraryRepository().save(arbitraryPeerData);
repository.getArbitraryRepository().save(arbitraryPeerData); repository.saveChanges();
repository.saveChanges();
// Remember that this data is new, so that it can be rebroadcast later // Remember that this data is new, so that it can be rebroadcast later
containsNewEntry = true; containsNewEntry = true;
}
} }
} }