Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #1749

Merged
merged 6 commits into from Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 18 additions & 18 deletions p2p/src/main/java/bisq/network/p2p/P2PService.java
Expand Up @@ -197,19 +197,12 @@ public void start(@Nullable P2PServiceListener listener) {
public void onAllServicesInitialized() {
Log.traceCall();
if (networkNode.getNodeAddress() != null) {
p2PDataStorage.getMap().values().stream().forEach(protectedStorageEntry -> {
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry)
processProtectedMailboxStorageEntry((ProtectedMailboxStorageEntry) protectedStorageEntry);
});
maybeProcessAllMailboxEntries();
} else {
// If our HS is still not published
networkNode.nodeAddressProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
p2PDataStorage.getMap().values().stream().forEach(protectedStorageEntry -> {
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry)
processProtectedMailboxStorageEntry((ProtectedMailboxStorageEntry) protectedStorageEntry);
});
}
if (newValue != null)
maybeProcessAllMailboxEntries();
});
}
}
Expand Down Expand Up @@ -291,6 +284,7 @@ public void onTorNodeReady() {

if (!seedNodesAvailable) {
isBootstrapped = true;
maybeProcessAllMailboxEntries();
p2pServiceListeners.stream().forEach(P2PServiceListener::onNoSeedNodeAvailable);
}
}
Expand Down Expand Up @@ -354,6 +348,7 @@ public void onPreliminaryDataReceived() {
public void onUpdatedDataReceived() {
if (!isBootstrapped) {
isBootstrapped = true;
maybeProcessAllMailboxEntries();
p2pServiceListeners.stream().forEach(P2PServiceListener::onUpdatedDataReceived);
p2PDataStorage.onBootstrapComplete();
}
Expand Down Expand Up @@ -449,7 +444,7 @@ public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) {
@Override
public void onAdded(ProtectedStorageEntry protectedStorageEntry) {
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry)
processProtectedMailboxStorageEntry((ProtectedMailboxStorageEntry) protectedStorageEntry);
processMailboxEntry((ProtectedMailboxStorageEntry) protectedStorageEntry);
}

@Override
Expand Down Expand Up @@ -523,9 +518,8 @@ public void onFailure(@NotNull Throwable throwable) {
// MailboxMessages
///////////////////////////////////////////////////////////////////////////////////////////

private void processProtectedMailboxStorageEntry(ProtectedMailboxStorageEntry protectedMailboxStorageEntry) {
Log.traceCall();
final NodeAddress nodeAddress = networkNode.getNodeAddress();
private void processMailboxEntry(ProtectedMailboxStorageEntry protectedMailboxStorageEntry) {
NodeAddress nodeAddress = networkNode.getNodeAddress();
// Seed nodes don't receive mailbox network_messages
if (nodeAddress != null && !seedNodeRepository.isSeedNode(nodeAddress)) {
Log.traceCall();
Expand All @@ -541,8 +535,7 @@ private void processProtectedMailboxStorageEntry(ProtectedMailboxStorageEntry pr
checkNotNull(senderNodeAddress, "senderAddress must not be null for mailbox network_messages");

mailboxMap.put(mailboxMessage.getUid(), protectedMailboxStorageEntry);
log.trace("Decryption of SealedAndSignedMessage succeeded. senderAddress="
+ senderNodeAddress + " / my address=" + getAddress());
log.info("Received a {} mailbox message with messageUid {} and senderAddress {}", mailboxMessage.getClass().getSimpleName(), mailboxMessage.getUid(), senderNodeAddress);
decryptedMailboxListeners.forEach(
e -> e.onMailboxMessageAdded(decryptedMessageWithPubKey, senderNodeAddress));
} else {
Expand Down Expand Up @@ -660,6 +653,14 @@ private boolean capabilityRequiredAndCapabilityNotSupported(NodeAddress peersNod

}

private void maybeProcessAllMailboxEntries() {
if (isBootstrapped) {
p2PDataStorage.getMap().values().forEach(protectedStorageEntry -> {
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry)
processMailboxEntry((ProtectedMailboxStorageEntry) protectedStorageEntry);
});
}
}

private void addMailboxData(MailboxStoragePayload expirableMailboxStoragePayload,
PublicKey receiversPublicKey,
Expand Down Expand Up @@ -757,8 +758,7 @@ private void delayedRemoveEntryFromMailbox(DecryptedMessageWithPubKey decryptedM
Log.traceCall();
if (!isBootstrapped()) {
// We don't throw an NetworkNotReadyException here.
// This case should not happen anyway but we saw it in some rare cases.
// Needs more investigation why as that methods should only be called after isBootstrapped is set.
// This case should not happen anyway as we check for isBootstrapped in the callers.
log.warn("You must have bootstrapped before adding data to the P2P network.");
}

Expand Down
15 changes: 13 additions & 2 deletions p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java
Expand Up @@ -178,8 +178,19 @@ public void shutDown() {
@Override
public void readPersisted() {
PeerList persistedPeerList = storage.initAndGetPersistedWithFileName("PeerList", 1000);
if (persistedPeerList != null)
if (persistedPeerList != null) {
long peesWithNoCapabilitiesSet = persistedPeerList.getList().stream()
.filter(e -> e.getSupportedCapabilities().isEmpty())
.mapToInt(e -> 1)
.count();
if (peesWithNoCapabilitiesSet > 100) {
log.warn("peesWithNoCapabilitiesSet={}, persistedPeerList.size()={}", peesWithNoCapabilitiesSet, persistedPeerList.size());
} else {
log.info("peesWithNoCapabilitiesSet={}, persistedPeerList.size()={}", peesWithNoCapabilitiesSet, persistedPeerList.size());
}

this.persistedPeers.addAll(persistedPeerList.getList());
}
}

public int getMaxConnections() {
Expand Down Expand Up @@ -648,7 +659,7 @@ public Set<Peer> getLivePeers(NodeAddress excludedNodeAddress) {
.filter(peer -> peer.getDate().getTime() > maxAge)
.collect(Collectors.toSet());
if (oldNumLatestLivePeers != latestLivePeers.size())
log.info("Num of latestLivePeers={}, latestLivePeers={}", latestLivePeers.size(), latestLivePeers);
log.info("Num of latestLivePeers={}", latestLivePeers.size());
return latestLivePeers;
}

Expand Down
Expand Up @@ -64,9 +64,6 @@ private Peer(NodeAddress nodeAddress, long date, List<Integer> supportedCapabili
this.nodeAddress = nodeAddress;
this.date = date;
this.supportedCapabilities = supportedCapabilities;

if (supportedCapabilities.isEmpty())
log.warn("SupportedCapabilities is empty. nodeAddress={}", nodeAddress);
}

@Override
Expand Down