use of bisq.common.app.Version in project bisq-desktop by bisq-network.
the class MainViewModel method initP2PNetwork.
// /////////////////////////////////////////////////////////////////////////////////////////
// Initialisation
// /////////////////////////////////////////////////////////////////////////////////////////
private BooleanProperty initP2PNetwork() {
log.info("initP2PNetwork");
StringProperty bootstrapState = new SimpleStringProperty();
StringProperty bootstrapWarning = new SimpleStringProperty();
BooleanProperty hiddenServicePublished = new SimpleBooleanProperty();
BooleanProperty initialP2PNetworkDataReceived = new SimpleBooleanProperty();
p2PNetworkInfoBinding = EasyBind.combine(bootstrapState, bootstrapWarning, p2PService.getNumConnectedPeers(), hiddenServicePublished, initialP2PNetworkDataReceived, (state, warning, numPeers, hiddenService, dataReceived) -> {
String result = "";
int peers = (int) numPeers;
if (warning != null && peers == 0) {
result = warning;
} else {
String p2pInfo = Res.get("mainView.footer.p2pInfo", numPeers);
if (dataReceived && hiddenService) {
result = p2pInfo;
} else if (peers == 0)
result = state;
else
result = state + " / " + p2pInfo;
}
return result;
});
p2PNetworkInfoBinding.subscribe((observable, oldValue, newValue) -> {
p2PNetworkInfo.set(newValue);
});
bootstrapState.set(Res.get("mainView.bootstrapState.connectionToTorNetwork"));
p2PService.getNetworkNode().addConnectionListener(new ConnectionListener() {
@Override
public void onConnection(Connection connection) {
}
@Override
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
// Other disconnects might be caused by peers running an older version
if (connection.getPeerType() == Connection.PeerType.SEED_NODE && closeConnectionReason == CloseConnectionReason.RULE_VIOLATION) {
log.warn("RULE_VIOLATION onDisconnect closeConnectionReason=" + closeConnectionReason);
log.warn("RULE_VIOLATION onDisconnect connection=" + connection);
}
}
@Override
public void onError(Throwable throwable) {
}
});
final BooleanProperty p2pNetworkInitialized = new SimpleBooleanProperty();
p2PService.start(new P2PServiceListener() {
@Override
public void onTorNodeReady() {
log.debug("onTorNodeReady");
bootstrapState.set(Res.get("mainView.bootstrapState.torNodeCreated"));
p2PNetworkIconId.set("image-connection-tor");
if (preferences.getUseTorForBitcoinJ())
initWalletService();
// We want to get early connected to the price relay so we call it already now
priceFeedService.setCurrencyCodeOnInit();
priceFeedService.initialRequestPriceFeed();
}
@Override
public void onHiddenServicePublished() {
log.debug("onHiddenServicePublished");
hiddenServicePublished.set(true);
bootstrapState.set(Res.get("mainView.bootstrapState.hiddenServicePublished"));
}
@Override
public void onDataReceived() {
log.debug("onRequestingDataCompleted");
initialP2PNetworkDataReceived.set(true);
bootstrapState.set(Res.get("mainView.bootstrapState.initialDataReceived"));
splashP2PNetworkAnimationVisible.set(false);
p2pNetworkInitialized.set(true);
}
@Override
public void onNoSeedNodeAvailable() {
log.warn("onNoSeedNodeAvailable");
if (p2PService.getNumConnectedPeers().get() == 0)
bootstrapWarning.set(Res.get("mainView.bootstrapWarning.noSeedNodesAvailable"));
else
bootstrapWarning.set(null);
splashP2PNetworkAnimationVisible.set(false);
p2pNetworkInitialized.set(true);
}
@Override
public void onNoPeersAvailable() {
log.warn("onNoPeersAvailable");
if (p2PService.getNumConnectedPeers().get() == 0) {
p2pNetworkWarnMsg.set(Res.get("mainView.p2pNetworkWarnMsg.noNodesAvailable"));
bootstrapWarning.set(Res.get("mainView.bootstrapWarning.noNodesAvailable"));
p2pNetworkLabelId.set("splash-error-state-msg");
} else {
bootstrapWarning.set(null);
p2pNetworkLabelId.set("footer-pane");
}
splashP2PNetworkAnimationVisible.set(false);
p2pNetworkInitialized.set(true);
}
@Override
public void onUpdatedDataReceived() {
log.debug("onBootstrapComplete");
splashP2PNetworkAnimationVisible.set(false);
bootstrapComplete.set(true);
}
@Override
public void onSetupFailed(Throwable throwable) {
log.warn("onSetupFailed");
p2pNetworkWarnMsg.set(Res.get("mainView.p2pNetworkWarnMsg.connectionToP2PFailed", throwable.getMessage()));
splashP2PNetworkAnimationVisible.set(false);
bootstrapWarning.set(Res.get("mainView.bootstrapWarning.bootstrappingToP2PFailed"));
p2pNetworkLabelId.set("splash-error-state-msg");
}
@Override
public void onRequestCustomBridges() {
showTorNetworkSettingsWindow();
}
});
return p2pNetworkInitialized;
}
Aggregations