Fix incorrect comparison at RemovedPayloadsService.readPersisted

Add comments
Cleanups
This commit is contained in:
chimp1984 2021-01-12 10:59:11 -05:00
parent d39a697611
commit b4ab8a4a0d
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3
4 changed files with 11 additions and 10 deletions

View File

@ -117,7 +117,7 @@ class TradesChartsViewModel extends ActivatableViewModel {
final int maxTicks = 90; final int maxTicks = 90;
private int selectedTabIndex; private int selectedTabIndex;
final Map<TickUnit, Map<Long, Long>> usdPriceMapsPerTickUnit = new HashMap<>(); final Map<TickUnit, Map<Long, Long>> usdPriceMapsPerTickUnit = new HashMap<>();
private boolean fillTradeCurrenciesOnActiavetCalled; private boolean fillTradeCurrenciesOnActivateCalled;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, lifecycle // Constructor, lifecycle
@ -152,9 +152,9 @@ class TradesChartsViewModel extends ActivatableViewModel {
@Override @Override
protected void activate() { protected void activate() {
tradeStatisticsManager.getObservableTradeStatisticsSet().addListener(setChangeListener); tradeStatisticsManager.getObservableTradeStatisticsSet().addListener(setChangeListener);
if (!fillTradeCurrenciesOnActiavetCalled) { if (!fillTradeCurrenciesOnActivateCalled) {
fillTradeCurrencies(); fillTradeCurrencies();
fillTradeCurrenciesOnActiavetCalled = true; fillTradeCurrenciesOnActivateCalled = true;
} }
buildUsdPricesPerDay(); buildUsdPricesPerDay();
updateSelectedTradeStatistics(getCurrencyCode()); updateSelectedTradeStatistics(getCurrencyCode());

View File

@ -32,8 +32,6 @@ import lombok.Value;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
@Value @Value
public class MailboxItem implements PersistablePayload { public class MailboxItem implements PersistablePayload {
private final ProtectedMailboxStorageEntry protectedMailboxStorageEntry; private final ProtectedMailboxStorageEntry protectedMailboxStorageEntry;
@ -78,7 +76,7 @@ public class MailboxItem implements PersistablePayload {
if (decryptedMessageWithPubKey != null) { if (decryptedMessageWithPubKey != null) {
// We use uid from mailboxMessage in case its ours as we have the at removeMailboxMsg only the // We use uid from mailboxMessage in case its ours as we have the at removeMailboxMsg only the
// decryptedMessageWithPubKey available which contains the mailboxMessage. // decryptedMessageWithPubKey available which contains the mailboxMessage.
MailboxMessage mailboxMessage = (MailboxMessage) checkNotNull(decryptedMessageWithPubKey).getNetworkEnvelope(); MailboxMessage mailboxMessage = (MailboxMessage) decryptedMessageWithPubKey.getNetworkEnvelope();
return mailboxMessage.getUid(); return mailboxMessage.getUid();
} else { } else {
// If its not our mailbox msg we take the uid from the prefixedSealedAndSignedMessage instead. // If its not our mailbox msg we take the uid from the prefixedSealedAndSignedMessage instead.

View File

@ -430,7 +430,6 @@ public class MailboxMessageService implements SetupListener, RequestDataManager.
if (ignoredMailboxService.isIgnored(uid)) { if (ignoredMailboxService.isIgnored(uid)) {
// We had persisted a past failed decryption attempt on that message so we don't try again and return early // We had persisted a past failed decryption attempt on that message so we don't try again and return early
return new MailboxItem(protectedMailboxStorageEntry, null); return new MailboxItem(protectedMailboxStorageEntry, null);
} }
try { try {
DecryptedMessageWithPubKey decryptedMessageWithPubKey = encryptionService.decryptAndVerify(sealedAndSigned); DecryptedMessageWithPubKey decryptedMessageWithPubKey = encryptionService.decryptAndVerify(sealedAndSigned);
@ -445,7 +444,6 @@ public class MailboxMessageService implements SetupListener, RequestDataManager.
e.getStackTrace(); e.getStackTrace();
} }
return new MailboxItem(protectedMailboxStorageEntry, null); return new MailboxItem(protectedMailboxStorageEntry, null);
} }
private void handleMailboxItem(MailboxItem mailboxItem) { private void handleMailboxItem(MailboxItem mailboxItem) {

View File

@ -28,6 +28,11 @@ import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
/**
* We persist the hashes and timestamp when a AddOncePayload payload got removed. This protects that it could be
* added again for instance if the sequence number map would be inconsistent/deleted or when we receive data from
* seed nodes where we do skip some checks.
*/
@Singleton @Singleton
@Slf4j @Slf4j
public class RemovedPayloadsService implements PersistedDataHost { public class RemovedPayloadsService implements PersistedDataHost {
@ -51,7 +56,7 @@ public class RemovedPayloadsService implements PersistedDataHost {
long cutOffDate = System.currentTimeMillis() - MailboxStoragePayload.TTL; long cutOffDate = System.currentTimeMillis() - MailboxStoragePayload.TTL;
persistenceManager.readPersisted(persisted -> { persistenceManager.readPersisted(persisted -> {
persisted.getDateByHashes().entrySet().stream() persisted.getDateByHashes().entrySet().stream()
.filter(e -> e.getValue() < cutOffDate) .filter(e -> e.getValue() > cutOffDate)
.forEach(e -> removedPayloadsMap.getDateByHashes().put(e.getKey(), e.getValue())); .forEach(e -> removedPayloadsMap.getDateByHashes().put(e.getKey(), e.getValue()));
log.trace("readPersisted: removedPayloadsMap={}", removedPayloadsMap); log.trace("readPersisted: removedPayloadsMap={}", removedPayloadsMap);
persistenceManager.requestPersistence(); persistenceManager.requestPersistence();
@ -67,7 +72,7 @@ public class RemovedPayloadsService implements PersistedDataHost {
public void addHash(P2PDataStorage.ByteArray hashOfPayload) { public void addHash(P2PDataStorage.ByteArray hashOfPayload) {
log.trace("called addHash: hashOfPayload={}, removedPayloadsMap={}", hashOfPayload.toString(), removedPayloadsMap); log.trace("called addHash: hashOfPayload={}, removedPayloadsMap={}", hashOfPayload.toString(), removedPayloadsMap);
removedPayloadsMap.getDateByHashes().put(hashOfPayload, System.currentTimeMillis()); removedPayloadsMap.getDateByHashes().putIfAbsent(hashOfPayload, System.currentTimeMillis());
persistenceManager.requestPersistence(); persistenceManager.requestPersistence();
} }
} }