fix mailbox bootstrap issue

This commit is contained in:
jmacxx 2021-03-02 13:42:34 -06:00
parent 411395bf94
commit f936210717
No known key found for this signature in database
GPG key ID: 155297BABFE94A1B
2 changed files with 15 additions and 9 deletions

View file

@ -334,12 +334,14 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
p2PDataStorage.onBootstrapped(); p2PDataStorage.onBootstrapped();
// We don't use a listener at mailboxMessageService as we require the correct
// order of execution. The mailboxMessageService must be called before.
mailboxMessageService.onBootstrapped();
// Once we have applied the state in the P2P domain we notify our listeners // Once we have applied the state in the P2P domain we notify our listeners
p2pServiceListeners.forEach(listenerHandler); p2pServiceListeners.forEach(listenerHandler);
// We don't use a listener at mailboxMessageService as we require the correct mailboxMessageService.initAfterBootstrapped();
// order of execution. The p2pServiceListeners must be called before.
mailboxMessageService.onBootstrapped();
} }
} }

View file

@ -221,12 +221,17 @@ public class MailboxMessageService implements HashMapChangedListener, PersistedD
public void onBootstrapped() { public void onBootstrapped() {
if (!isBootstrapped) { if (!isBootstrapped) {
isBootstrapped = true; isBootstrapped = true;
}
}
// second stage starup for MailboxMessageService ... apply existing messages to their modules
public void initAfterBootstrapped() {
// Only now we start listening and processing. The p2PDataStorage is our cache for data we have received // Only now we start listening and processing. The p2PDataStorage is our cache for data we have received
// after the hidden service was ready. // after the hidden service was ready.
addHashMapChangedListenerAndApply(); addHashMapChangedListener();
onAdded(p2PDataStorage.getMap().values());
maybeRepublishMailBoxMessages(); maybeRepublishMailBoxMessages();
} }
}
public void sendEncryptedMailboxMessage(NodeAddress peer, public void sendEncryptedMailboxMessage(NodeAddress peer,
@ -374,9 +379,8 @@ public class MailboxMessageService implements HashMapChangedListener, PersistedD
// Private // Private
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void addHashMapChangedListenerAndApply() { private void addHashMapChangedListener() {
p2PDataStorage.addHashMapChangedListener(this); p2PDataStorage.addHashMapChangedListener(this);
onAdded(p2PDataStorage.getMap().values());
} }
private void processSingleMailboxEntry(Collection<ProtectedMailboxStorageEntry> protectedMailboxStorageEntries) { private void processSingleMailboxEntry(Collection<ProtectedMailboxStorageEntry> protectedMailboxStorageEntries) {