Merge pull request #1749 from ManfredKarrer/small-fixes

Small fixes
This commit is contained in:
Manfred Karrer 2018-10-07 00:45:44 -05:00 committed by GitHub
commit 7d9a53adc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 76 additions and 69 deletions

View file

@ -19,7 +19,7 @@ package bisq.core;
import bisq.core.alert.AlertModule;
import bisq.core.app.AppOptionKeys;
import bisq.core.app.AvoidStandbyMode;
import bisq.core.app.AvoidStandbyModeService;
import bisq.core.app.BisqEnvironment;
import bisq.core.app.BisqFacade;
import bisq.core.app.BisqSetup;
@ -94,7 +94,7 @@ public class CoreModule extends AppModule {
bind(Preferences.class).in(Singleton.class);
bind(BridgeAddressProvider.class).to(Preferences.class).in(Singleton.class);
bind(CorruptedDatabaseFilesHandler.class).in(Singleton.class);
bind(AvoidStandbyMode.class).in(Singleton.class);
bind(AvoidStandbyModeService.class).in(Singleton.class);
bind(SeedNodeAddressLookup.class).in(Singleton.class);
bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class).in(Singleton.class);

View file

@ -40,18 +40,18 @@ import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
@Slf4j
public class AvoidStandbyMode {
public class AvoidStandbyModeService {
private final Preferences preferences;
private volatile boolean isStopped;
@Inject
public AvoidStandbyMode(Preferences preferences) {
public AvoidStandbyModeService(Preferences preferences) {
this.preferences = preferences;
preferences.getUseStandbyModeProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) {
isStopped = true;
log.info("AvoidStandbyMode stopped");
log.info("AvoidStandbyModeService stopped");
} else {
start();
}
@ -67,9 +67,9 @@ public class AvoidStandbyMode {
private void start() {
isStopped = false;
log.info("AvoidStandbyMode started");
log.info("AvoidStandbyModeService started");
Thread thread = new Thread(this::play);
thread.setName("AvoidStandbyMode-thread");
thread.setName("AvoidStandbyModeService-thread");
thread.start();
}

View file

@ -405,7 +405,6 @@ public class BisqSetup {
step3();
});
} catch (Throwable e) {
log.info("Localhost Bitcoin node not detected.");
UserThread.execute(BisqSetup.this::step3);
} finally {
if (socket != null) {

View file

@ -77,8 +77,6 @@ public class P2PNetworkSetup {
}
BooleanProperty init(Runnable initWalletServiceHandler, @Nullable Consumer<Boolean> displayTorNetworkSettingsHandler) {
log.info("init");
StringProperty bootstrapState = new SimpleStringProperty();
StringProperty bootstrapWarning = new SimpleStringProperty();
BooleanProperty hiddenServicePublished = new SimpleBooleanProperty();

View file

@ -68,7 +68,7 @@ public class MobileModel {
}
public void applyKeyAndToken(String keyAndToken) {
log.info("phoneId={}", keyAndToken);
log.info("applyKeyAndToken: keyAndToken={}", keyAndToken.substring(0, 20) + "...(truncated in log for privacy reasons)");
String[] tokens = keyAndToken.split(PHONE_SEPARATOR_ESCAPED);
String magic = tokens[0];
descriptor = tokens[1];

View file

@ -130,8 +130,7 @@ public class MobileNotificationService {
}
public boolean sendMessage(MobileMessage message, boolean useSound) throws Exception {
log.info("sendMessage\n" +
"Title: " + message.getTitle() + "\nMessage: " + message.getMessage());
log.info("Send message: '{}'", message.getMessage());
if (mobileModel.getKey() == null)
return false;

View file

@ -33,7 +33,7 @@ import bisq.desktop.util.ImageUtil;
import bisq.core.alert.AlertManager;
import bisq.core.app.AppOptionKeys;
import bisq.core.app.AvoidStandbyMode;
import bisq.core.app.AvoidStandbyModeService;
import bisq.core.app.BisqEnvironment;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletsManager;
@ -131,7 +131,7 @@ public class BisqApp extends Application implements UncaughtExceptionHandler {
scene = createAndConfigScene(mainView, injector);
setupStage(scene);
injector.getInstance(AvoidStandbyMode.class).init();
injector.getInstance(AvoidStandbyModeService.class).init();
UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), LOG_MEMORY_PERIOD_MIN, TimeUnit.MINUTES);
} catch (Throwable throwable) {
@ -312,7 +312,7 @@ public class BisqApp extends Application implements UncaughtExceptionHandler {
// We show a popup to inform user that open offers will be removed if Bisq is not running.
String key = "showOpenOfferWarnPopupAtShutDown";
if (injector.getInstance(Preferences.class).showAgain(key)) {
if (injector.getInstance(Preferences.class).showAgain(key) && !DevEnv.isDevMode()) {
new Popup<>().information(Res.get("popup.info.shutDownWithOpenOffers"))
.dontShowAgainId(key)
.useShutDownButton()

View file

@ -57,6 +57,7 @@ import bisq.core.util.BSFormatter;
import bisq.network.p2p.NodeAddress;
import bisq.common.app.DevEnv;
import bisq.common.util.Tuple3;
import org.bitcoinj.core.Coin;
@ -393,7 +394,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
Res.get("popup.warning.noTradingAccountSetup.msg"),
FiatAccountsView.class,
"navigation.account");
} else if (!model.hasPaymentAccountForCurrency()) {
} else if (!model.hasPaymentAccountForCurrency() && !DevEnv.isDevMode()) {
new Popup<>().headLine(Res.get("offerbook.warning.noTradingAccountForCurrency.headline"))
.instruction(Res.get("offerbook.warning.noTradingAccountForCurrency.msg"))
.actionButtonText(Res.get("offerbook.yesCreateOffer"))

View file

@ -301,7 +301,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
referralIdService.setReferralId(newValue);
};
// AvoidStandbyMode
// AvoidStandbyModeService
avoidStandbyModeCheckBox = addLabelCheckBox(root, ++gridRow,
Res.get("setting.preferences.avoidStandbyMode"), "").second;
}

View file

@ -197,19 +197,12 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
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();
});
}
}
@ -291,6 +284,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
if (!seedNodesAvailable) {
isBootstrapped = true;
maybeProcessAllMailboxEntries();
p2pServiceListeners.stream().forEach(P2PServiceListener::onNoSeedNodeAvailable);
}
}
@ -354,6 +348,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
public void onUpdatedDataReceived() {
if (!isBootstrapped) {
isBootstrapped = true;
maybeProcessAllMailboxEntries();
p2pServiceListeners.stream().forEach(P2PServiceListener::onUpdatedDataReceived);
p2PDataStorage.onBootstrapComplete();
}
@ -449,7 +444,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
@Override
public void onAdded(ProtectedStorageEntry protectedStorageEntry) {
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry)
processProtectedMailboxStorageEntry((ProtectedMailboxStorageEntry) protectedStorageEntry);
processMailboxEntry((ProtectedMailboxStorageEntry) protectedStorageEntry);
}
@Override
@ -523,9 +518,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
// 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();
@ -541,8 +535,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
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 {
@ -660,6 +653,14 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
}
private void maybeProcessAllMailboxEntries() {
if (isBootstrapped) {
p2PDataStorage.getMap().values().forEach(protectedStorageEntry -> {
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry)
processMailboxEntry((ProtectedMailboxStorageEntry) protectedStorageEntry);
});
}
}
private void addMailboxData(MailboxStoragePayload expirableMailboxStoragePayload,
PublicKey receiversPublicKey,
@ -755,36 +756,37 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
private void delayedRemoveEntryFromMailbox(DecryptedMessageWithPubKey decryptedMessageWithPubKey) {
Log.traceCall();
if (isBootstrapped()) {
MailboxMessage mailboxMessage = (MailboxMessage) decryptedMessageWithPubKey.getNetworkEnvelope();
String uid = mailboxMessage.getUid();
if (mailboxMap.containsKey(uid)) {
ProtectedMailboxStorageEntry mailboxData = mailboxMap.get(uid);
if (mailboxData != null && mailboxData.getProtectedStoragePayload() instanceof MailboxStoragePayload) {
MailboxStoragePayload expirableMailboxStoragePayload = (MailboxStoragePayload) mailboxData.getProtectedStoragePayload();
PublicKey receiversPubKey = mailboxData.getReceiversPubKey();
checkArgument(receiversPubKey.equals(keyRing.getSignatureKeyPair().getPublic()),
"receiversPubKey is not matching with our key. That must not happen.");
try {
ProtectedMailboxStorageEntry protectedMailboxStorageEntry = p2PDataStorage.getMailboxDataWithSignedSeqNr(
expirableMailboxStoragePayload,
keyRing.getSignatureKeyPair(),
receiversPubKey);
p2PDataStorage.removeMailboxData(protectedMailboxStorageEntry, networkNode.getNodeAddress(), true);
} catch (CryptoException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen.");
}
mailboxMap.remove(uid);
log.info("Removed successfully decryptedMsgWithPubKey. uid={}", uid);
}
} else {
log.warn("uid for mailbox entry not found in mailboxMap." + "uid={}", uid);
}
} else {
throw new NetworkNotReadyException();
if (!isBootstrapped()) {
// We don't throw an NetworkNotReadyException here.
// 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.");
}
MailboxMessage mailboxMessage = (MailboxMessage) decryptedMessageWithPubKey.getNetworkEnvelope();
String uid = mailboxMessage.getUid();
if (mailboxMap.containsKey(uid)) {
ProtectedMailboxStorageEntry mailboxData = mailboxMap.get(uid);
if (mailboxData != null && mailboxData.getProtectedStoragePayload() instanceof MailboxStoragePayload) {
MailboxStoragePayload expirableMailboxStoragePayload = (MailboxStoragePayload) mailboxData.getProtectedStoragePayload();
PublicKey receiversPubKey = mailboxData.getReceiversPubKey();
checkArgument(receiversPubKey.equals(keyRing.getSignatureKeyPair().getPublic()),
"receiversPubKey is not matching with our key. That must not happen.");
try {
ProtectedMailboxStorageEntry protectedMailboxStorageEntry = p2PDataStorage.getMailboxDataWithSignedSeqNr(
expirableMailboxStoragePayload,
keyRing.getSignatureKeyPair(),
receiversPubKey);
p2PDataStorage.removeMailboxData(protectedMailboxStorageEntry, networkNode.getNodeAddress(), true);
} catch (CryptoException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen.");
}
mailboxMap.remove(uid);
log.info("Removed successfully decryptedMsgWithPubKey. uid={}", uid);
}
} else {
log.warn("uid for mailbox entry not found in mailboxMap." + "uid={}", uid);
}
}

View file

@ -178,8 +178,19 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
@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() {
@ -648,7 +659,7 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
.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;
}

View file

@ -64,9 +64,6 @@ public final class Peer implements NetworkPayload, PersistablePayload, Supported
this.nodeAddress = nodeAddress;
this.date = date;
this.supportedCapabilities = supportedCapabilities;
if (supportedCapabilities.isEmpty())
log.warn("SupportedCapabilities is empty. nodeAddress={}", nodeAddress);
}
@Override

View file

@ -139,9 +139,9 @@ public abstract class StoreService<T extends PersistableEnvelope, R extends Pers
final String fileName = getFileName();
store = storage.initAndGetPersistedWithFileName(fileName, 100);
if (store != null) {
log.info("{}: size of {}: {} kb", this.getClass().getSimpleName(),
log.info("{}: size of {}: {} MB", this.getClass().getSimpleName(),
storage.getClass().getSimpleName(),
store.toProtoMessage().toByteArray().length / 100D);
store.toProtoMessage().toByteArray().length / 1_000_000D);
} else {
store = createStore();
}