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) {
// Update our lookup table to indicate that this peer holds data for this signature
String peerAddress = peer.getPeerData().getAddress().toString();
LOGGER.debug("Adding arbitrary peer: {} for signature {}", peerAddress, Base58.encode(signature));
ArbitraryPeerData arbitraryPeerData = new ArbitraryPeerData(signature, peer);
repository.discardChanges();
if (!arbitraryPeerData.isPeerAddressValid()) {
return false;
}
if (arbitraryPeerData.isPeerAddressValid()) {
LOGGER.debug("Adding arbitrary peer: {} for signature {}", peerAddress, Base58.encode(signature));
repository.getArbitraryRepository().save(arbitraryPeerData);
repository.saveChanges();
}
// Invalidate the hosted transactions cache as we are now hosting something new
ArbitraryDataStorageManager.getInstance().invalidateHostedTransactionsCache();

View File

@ -413,12 +413,10 @@ public class ArbitraryDataManager extends Thread {
if (existingEntry == null) {
// 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);
repository.discardChanges();
if (!arbitraryPeerData.isPeerAddressValid()) {
return;
}
if (arbitraryPeerData.isPeerAddressValid()) {
LOGGER.debug("Adding arbitrary peer: {} for signature {}", peerAddress, Base58.encode(signature));
repository.getArbitraryRepository().save(arbitraryPeerData);
repository.saveChanges();
@ -426,6 +424,7 @@ public class ArbitraryDataManager extends Thread {
containsNewEntry = true;
}
}
}
// If at least one signature in this batch was new to us, we should rebroadcast the message to the
// network in case some peers haven't received it yet