use of io.bitsquare.p2p.network.ConnectionListener in project bitsquare by bitsquare.
the class TakeOfferViewModel method createListeners.
private void createListeners() {
amountListener = (ov, oldValue, newValue) -> {
if (isBtcInputValid(newValue).isValid) {
setAmountToModel();
calculateVolume();
dataModel.calculateTotalToPay();
}
updateButtonDisableState();
};
amountAsCoinListener = (ov, oldValue, newValue) -> amount.set(formatter.formatCoin(newValue));
isWalletFundedListener = (ov, oldValue, newValue) -> {
updateButtonDisableState();
};
tradeStateListener = (ov, oldValue, newValue) -> applyTradeState(newValue);
tradeErrorListener = (ov, oldValue, newValue) -> applyTradeErrorMessage(newValue);
offerStateListener = (ov, oldValue, newValue) -> applyOfferState(newValue);
connectionListener = new ConnectionListener() {
@Override
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
if (connection.getPeersNodeAddressOptional().isPresent() && connection.getPeersNodeAddressOptional().get().equals(offer.getOffererNodeAddress())) {
offerWarning.set("You lost connection to the offerer.\n" + "He might have gone offline or has closed the connection to you because of too " + "many open connections.\n\n" + "If you can still see his offer in the offerbook you can try to take the offer again.");
updateSpinnerInfo();
}
}
@Override
public void onConnection(Connection connection) {
}
@Override
public void onError(Throwable throwable) {
}
};
}
use of io.bitsquare.p2p.network.ConnectionListener in project bitsquare by bitsquare.
the class MainViewModel method initP2PNetwork.
///////////////////////////////////////////////////////////////////////////////////////////
// Initialisation
///////////////////////////////////////////////////////////////////////////////////////////
private BooleanProperty initP2PNetwork() {
Log.traceCall();
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 {
if (dataReceived && hiddenService)
result = "P2P network peers: " + numPeers;
else if (peers == 0)
result = state;
else
result = state + " / P2P network peers: " + numPeers;
}
return result;
});
p2PNetworkInfoBinding.subscribe((observable, oldValue, newValue) -> {
p2PNetworkInfo.set(newValue);
});
bootstrapState.set("Connecting to Tor network...");
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);
//TODO
/* new Popup()
.warning("You got disconnected from a seed node.\n\n" +
"Reason for getting disconnected: " + connection.getRuleViolation().name() + "\n\n" +
"It might be that your installed version is not compatible with " +
"the network.\n\n" +
"Please check if you run the latest software version.\n" +
"You can download the latest version of Bitsquare at:\n" +
"https://github.com/bitsquare/bitsquare/releases")
.show();*/
}
}
@Override
public void onError(Throwable throwable) {
}
});
final BooleanProperty p2pNetworkInitialized = new SimpleBooleanProperty();
p2PService.start(new P2PServiceListener() {
@Override
public void onTorNodeReady() {
bootstrapState.set("Tor node created");
p2PNetworkIconId.set("image-connection-tor");
if (preferences.getUseTorForBitcoinJ())
initWalletService();
}
@Override
public void onHiddenServicePublished() {
hiddenServicePublished.set(true);
bootstrapState.set("Hidden Service published");
}
@Override
public void onRequestingDataCompleted() {
initialP2PNetworkDataReceived.set(true);
bootstrapState.set("Initial data received");
splashP2PNetworkAnimationVisible.set(false);
p2pNetworkInitialized.set(true);
}
@Override
public void onNoSeedNodeAvailable() {
if (p2PService.getNumConnectedPeers().get() == 0)
bootstrapWarning.set("No seed nodes available");
else
bootstrapWarning.set(null);
splashP2PNetworkAnimationVisible.set(false);
p2pNetworkInitialized.set(true);
}
@Override
public void onNoPeersAvailable() {
if (p2PService.getNumConnectedPeers().get() == 0) {
p2pNetworkWarnMsg.set("There are no seed nodes or persisted peers available for requesting data.\n" + "Please check your internet connection or try to restart the application.");
bootstrapWarning.set("No seed nodes and peers available");
p2pNetworkLabelId.set("splash-error-state-msg");
} else {
bootstrapWarning.set(null);
p2pNetworkLabelId.set("footer-pane");
}
splashP2PNetworkAnimationVisible.set(false);
p2pNetworkInitialized.set(true);
}
@Override
public void onBootstrapComplete() {
splashP2PNetworkAnimationVisible.set(false);
bootstrapComplete.set(true);
}
@Override
public void onSetupFailed(Throwable throwable) {
p2pNetworkWarnMsg.set("Connecting to the P2P network failed (reported error: " + throwable.getMessage() + ").\n" + "Please check your internet connection or try to restart the application.");
splashP2PNetworkAnimationVisible.set(false);
bootstrapWarning.set("Bootstrapping to P2P network failed");
p2pNetworkLabelId.set("splash-error-state-msg");
}
});
return p2pNetworkInitialized;
}
Aggregations