Add handling for mailbox messages after all is initialized

This commit is contained in:
Manfred Karrer 2016-07-13 16:07:04 +02:00
parent 2d05ad99b6
commit b4917c1822
5 changed files with 33 additions and 5 deletions

View File

@ -528,6 +528,8 @@ public class MainViewModel implements ViewModel {
privateNotificationManager.privateNotificationProperty().addListener((observable, oldValue, newValue) -> displayPrivateNotification(newValue));
displayAlertIfPresent(alertManager.alertMessageProperty().get());
p2PService.onAllServicesInitialized();
setupBtcNumPeersWatcher();
setupP2PNumPeersWatcher();
updateBalance();

View File

@ -65,6 +65,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
private final int maxConnections;
private final File torDir;
private Clock clock;
//TODO optional can be removed as seednode are created with those objects now
private final Optional<EncryptionService> optionalEncryptionService;
private final Optional<KeyRing> optionalKeyRing;
@ -173,7 +174,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
BanList.setList(Arrays.asList(banList.replace(" ", "").split(",")).stream().map(NodeAddress::new).collect(Collectors.toList()));
if (myAddress != null && !myAddress.isEmpty())
seedNodesRepository.setNodeAddressToExclude(new NodeAddress(myAddress));
networkNode = useLocalhost ? new LocalhostNetworkNode(port) : new TorNetworkNode(port, torDir);
networkNode.addConnectionListener(this);
networkNode.addMessageListener(this);
@ -221,6 +222,24 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
networkNode.start(useBridges, this);
}
public void onAllServicesInitialized() {
if (networkNode.getNodeAddress() != null) {
p2PDataStorage.getMap().values().stream().forEach(protectedStorageEntry -> {
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry)
processProtectedMailboxStorageEntry((ProtectedMailboxStorageEntry) protectedStorageEntry);
});
} else {
networkNode.nodeAddressProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
p2PDataStorage.getMap().values().stream().forEach(protectedStorageEntry -> {
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry)
processProtectedMailboxStorageEntry((ProtectedMailboxStorageEntry) protectedStorageEntry);
});
}
});
}
}
public void shutDown(Runnable shutDownCompleteHandler) {
Log.traceCall();
if (!shutDownInProgress) {
@ -510,8 +529,9 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
///////////////////////////////////////////////////////////////////////////////////////////
private void processProtectedMailboxStorageEntry(ProtectedMailboxStorageEntry protectedMailboxStorageEntry) {
// Seed nodes don't have set the encryptionService
if (optionalEncryptionService.isPresent()) {
final NodeAddress nodeAddress = networkNode.getNodeAddress();
// Seed nodes don't receive mailbox messages
if (optionalEncryptionService.isPresent() && nodeAddress != null && !seedNodesRepository.isSeedNode(nodeAddress)) {
Log.traceCall();
MailboxStoragePayload mailboxStoragePayload = protectedMailboxStorageEntry.getMailboxStoragePayload();
PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage = mailboxStoragePayload.prefixedSealedAndSignedMessage;

View File

@ -44,7 +44,7 @@ public final class PrefixedSealedAndSignedMessage implements MailboxMessage, Sen
@Override
public String toString() {
return "SealedAndSignedMessage{" +
return "PrefixedSealedAndSignedMessage{" +
"uid=" + uid +
", messageVersion=" + messageVersion +
", sealedAndSigned=" + sealedAndSigned +

View File

@ -106,7 +106,7 @@ public class RequestDataManager implements MessageListener, ConnectionListener,
public void requestUpdateData() {
Log.traceCall();
checkArgument(nodeAddressOfPreliminaryDataRequest.isPresent(), "seedNodeOfPreliminaryDataRequest must be present");
checkArgument(nodeAddressOfPreliminaryDataRequest.isPresent(), "nodeAddressOfPreliminaryDataRequest must be present");
dataUpdateRequested = true;
List<NodeAddress> remainingNodeAddresses = new ArrayList<>(seedNodeAddresses);
if (!remainingNodeAddresses.isEmpty()) {

View File

@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class SeedNodesRepository {
private static final Logger log = LoggerFactory.getLogger(SeedNodesRepository.class);
@ -95,6 +96,11 @@ public class SeedNodesRepository {
this.localhostSeedNodeAddresses = localhostSeedNodeAddresses;
}
public boolean isSeedNode(NodeAddress nodeAddress) {
return Stream.concat(localhostSeedNodeAddresses.stream(), torSeedNodeAddresses.stream())
.filter(e -> e.equals(nodeAddress)).findAny().isPresent();
}
public void setNodeAddressToExclude(NodeAddress nodeAddress) {
this.nodeAddressToExclude = nodeAddress;
}