mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 15:26:03 -04:00
Fix mailbox behaviour, renamings
This commit is contained in:
parent
7b87c39ffd
commit
a91822803f
@ -26,7 +26,7 @@ import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.handlers.ErrorMessageHandler;
|
||||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.common.util.Utilities;
|
||||
import io.bitsquare.p2p.NetWorkReadyListener;
|
||||
import io.bitsquare.p2p.BootstrapListener;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.P2PService;
|
||||
import io.bitsquare.p2p.storage.HashMapChangedListener;
|
||||
@ -89,7 +89,7 @@ public class ArbitratorManager {
|
||||
));
|
||||
private static final String publicKeyForTesting = "027a381b5333a56e1cc3d90d3a7d07f26509adf7029ed06fc997c656621f8da1ee";
|
||||
private final boolean isDevTest;
|
||||
private NetWorkReadyListener netWorkReadyListener;
|
||||
private BootstrapListener bootstrapListener;
|
||||
private ScheduledThreadPoolExecutor republishArbitratorExecutor;
|
||||
|
||||
@Inject
|
||||
@ -121,14 +121,14 @@ public class ArbitratorManager {
|
||||
if (user.getRegisteredArbitrator() != null) {
|
||||
|
||||
P2PService p2PService = arbitratorService.getP2PService();
|
||||
if (!p2PService.isNetworkReady()) {
|
||||
netWorkReadyListener = new NetWorkReadyListener() {
|
||||
if (!p2PService.isBootstrapped()) {
|
||||
bootstrapListener = new BootstrapListener() {
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
republishArbitrator();
|
||||
}
|
||||
};
|
||||
p2PService.addP2PServiceListener(netWorkReadyListener);
|
||||
p2PService.addP2PServiceListener(bootstrapListener);
|
||||
|
||||
} else {
|
||||
republishArbitrator();
|
||||
@ -144,8 +144,8 @@ public class ArbitratorManager {
|
||||
}
|
||||
|
||||
private void republishArbitrator() {
|
||||
if (netWorkReadyListener != null)
|
||||
arbitratorService.getP2PService().removeP2PServiceListener(netWorkReadyListener);
|
||||
if (bootstrapListener != null)
|
||||
arbitratorService.getP2PService().removeP2PServiceListener(bootstrapListener);
|
||||
|
||||
Arbitrator registeredArbitrator = user.getRegisteredArbitrator();
|
||||
if (registeredArbitrator != null) {
|
||||
|
@ -27,8 +27,8 @@ import io.bitsquare.btc.exceptions.TransactionVerificationException;
|
||||
import io.bitsquare.btc.exceptions.WalletException;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.crypto.PubKeyRing;
|
||||
import io.bitsquare.p2p.BootstrapListener;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.NetWorkReadyListener;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.P2PService;
|
||||
import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey;
|
||||
@ -68,7 +68,7 @@ public class DisputeManager {
|
||||
private final DisputeList<Dispute> disputes;
|
||||
transient private final ObservableList<Dispute> disputesObservableList;
|
||||
private final String disputeInfo;
|
||||
private final NetWorkReadyListener netWorkReadyListener;
|
||||
private final BootstrapListener bootstrapListener;
|
||||
private final CopyOnWriteArraySet<DecryptedMsgWithPubKey> decryptedMailboxMessageWithPubKeys = new CopyOnWriteArraySet<>();
|
||||
private final CopyOnWriteArraySet<DecryptedMsgWithPubKey> decryptedDirectMessageWithPubKeys = new CopyOnWriteArraySet<>();
|
||||
|
||||
@ -105,24 +105,25 @@ public class DisputeManager {
|
||||
"Please read more in detail about the dispute process in our wiki:\nhttps://github" +
|
||||
".com/bitsquare/bitsquare/wiki/Dispute-process";
|
||||
|
||||
// We get first the message handler called then the onBootstrapped
|
||||
p2PService.addDecryptedDirectMessageListener((decryptedMessageWithPubKey, senderAddress) -> {
|
||||
decryptedDirectMessageWithPubKeys.add(decryptedMessageWithPubKey);
|
||||
if (p2PService.isNetworkReady())
|
||||
if (p2PService.isBootstrapped())
|
||||
applyMessages();
|
||||
});
|
||||
p2PService.addDecryptedMailboxListener((decryptedMessageWithPubKey, senderAddress) -> {
|
||||
decryptedMailboxMessageWithPubKeys.add(decryptedMessageWithPubKey);
|
||||
if (p2PService.isNetworkReady())
|
||||
if (p2PService.isBootstrapped())
|
||||
applyMessages();
|
||||
});
|
||||
|
||||
netWorkReadyListener = new NetWorkReadyListener() {
|
||||
bootstrapListener = new BootstrapListener() {
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
applyMessages();
|
||||
}
|
||||
};
|
||||
p2PService.addP2PServiceListener(netWorkReadyListener);
|
||||
p2PService.addP2PServiceListener(bootstrapListener);
|
||||
}
|
||||
|
||||
private void applyMessages() {
|
||||
@ -138,13 +139,12 @@ public class DisputeManager {
|
||||
log.debug("decryptedMessageWithPubKey.message " + message);
|
||||
if (message instanceof DisputeMessage) {
|
||||
dispatchMessage((DisputeMessage) message);
|
||||
//TODO
|
||||
//p2PService.removeEntryFromMailbox(decryptedMessageWithPubKey);
|
||||
p2PService.removeEntryFromMailbox(decryptedMessageWithPubKey);
|
||||
}
|
||||
});
|
||||
decryptedMailboxMessageWithPubKeys.clear();
|
||||
|
||||
p2PService.removeP2PServiceListener(netWorkReadyListener);
|
||||
p2PService.removeP2PServiceListener(bootstrapListener);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,8 +26,8 @@ import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.handlers.FaultHandler;
|
||||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.p2p.BootstrapListener;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.NetWorkReadyListener;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.P2PService;
|
||||
import io.bitsquare.p2p.messaging.DecryptedDirectMessageListener;
|
||||
@ -80,7 +80,7 @@ public class TradeManager {
|
||||
private final Storage<TradableList<Trade>> tradableListStorage;
|
||||
private final TradableList<Trade> trades;
|
||||
private final BooleanProperty pendingTradesInitialized = new SimpleBooleanProperty();
|
||||
private final NetWorkReadyListener netWorkReadyListener;
|
||||
private final BootstrapListener bootstrapListener;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -141,21 +141,23 @@ public class TradeManager {
|
||||
log.trace("Received TradeMessage: " + message);
|
||||
String tradeId = ((TradeMessage) message).tradeId;
|
||||
Optional<Trade> tradeOptional = trades.stream().filter(e -> e.getId().equals(tradeId)).findAny();
|
||||
// The mailbox message will be removed inside the tasks after they are processed successfully
|
||||
if (tradeOptional.isPresent())
|
||||
tradeOptional.get().setMailboxMessage(decryptedMsgWithPubKey);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
netWorkReadyListener = new NetWorkReadyListener() {
|
||||
bootstrapListener = new BootstrapListener() {
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
Log.traceCall("onNetworkReady");
|
||||
// Get called after onMailboxMessageAdded from initial data request
|
||||
// The mailbox message will be removed inside the tasks after they are processed successfully
|
||||
initPendingTrades();
|
||||
}
|
||||
};
|
||||
p2PService.addP2PServiceListener(netWorkReadyListener);
|
||||
p2PService.addP2PServiceListener(bootstrapListener);
|
||||
}
|
||||
|
||||
|
||||
@ -165,7 +167,7 @@ public class TradeManager {
|
||||
|
||||
private void initPendingTrades() {
|
||||
Log.traceCall();
|
||||
if (netWorkReadyListener != null) p2PService.removeP2PServiceListener(netWorkReadyListener);
|
||||
p2PService.removeP2PServiceListener(bootstrapListener);
|
||||
|
||||
//List<Trade> failedTrades = new ArrayList<>();
|
||||
for (Trade trade : trades) {
|
||||
@ -180,13 +182,7 @@ public class TradeManager {
|
||||
trade.updateDepositTxFromWallet(tradeWalletService);
|
||||
initTrade(trade);
|
||||
|
||||
// after network is ready we remove mailbox messages.
|
||||
DecryptedMsgWithPubKey mailboxMessage = trade.getMailboxMessage();
|
||||
if (mailboxMessage != null) {
|
||||
log.trace("initPendingTrades/removeEntryFromMailbox mailboxMessage = " + mailboxMessage);
|
||||
p2PService.removeEntryFromMailbox(mailboxMessage);
|
||||
trade.setMailboxMessage(null);
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
pendingTradesInitialized.set(true);
|
||||
|
@ -24,8 +24,8 @@ import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.handlers.ErrorMessageHandler;
|
||||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.p2p.BootstrapListener;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.NetWorkReadyListener;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.P2PService;
|
||||
import io.bitsquare.p2p.messaging.SendDirectMessageListener;
|
||||
@ -67,7 +67,7 @@ public class OpenOfferManager {
|
||||
private final TradableList<OpenOffer> openOffers;
|
||||
private final Storage<TradableList<OpenOffer>> openOffersStorage;
|
||||
private boolean shutDownRequested;
|
||||
private NetWorkReadyListener netWorkReadyListener;
|
||||
private BootstrapListener bootstrapListener;
|
||||
private final Timer timer = new Timer();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -126,14 +126,14 @@ public class OpenOfferManager {
|
||||
// Before the TTL is reached we re-publish our offers
|
||||
// If offer removal at shutdown fails we don't want to have long term dangling dead offers, so we set
|
||||
// TTL quite short and use re-publish as strategy. Offerers need to be online anyway.
|
||||
if (!p2PService.isNetworkReady()) {
|
||||
netWorkReadyListener = new NetWorkReadyListener() {
|
||||
if (!p2PService.isBootstrapped()) {
|
||||
bootstrapListener = new BootstrapListener() {
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
startRePublishThread();
|
||||
}
|
||||
};
|
||||
p2PService.addP2PServiceListener(netWorkReadyListener);
|
||||
p2PService.addP2PServiceListener(bootstrapListener);
|
||||
|
||||
} else {
|
||||
startRePublishThread();
|
||||
@ -141,8 +141,8 @@ public class OpenOfferManager {
|
||||
}
|
||||
|
||||
private void startRePublishThread() {
|
||||
if (netWorkReadyListener != null)
|
||||
p2PService.removeP2PServiceListener(netWorkReadyListener);
|
||||
if (bootstrapListener != null)
|
||||
p2PService.removeP2PServiceListener(bootstrapListener);
|
||||
|
||||
long period = (long) (Offer.TTL * 0.8); // republish sufficiently before offer would expire
|
||||
TimerTask timerTask = new TimerTask() {
|
||||
|
@ -239,7 +239,7 @@ public class MainViewModel implements ViewModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
updateP2pNetworkInfoWithPeersChanged(p2PService.getNumConnectedPeers().get());
|
||||
splashP2PNetworkProgress.set(1);
|
||||
}
|
||||
@ -566,14 +566,14 @@ public class MainViewModel implements ViewModel {
|
||||
if (!trade.isHalfTradePeriodReachedWarningDisplayed()) {
|
||||
new Popup().warning("Your trade with ID " + trade.getShortId() +
|
||||
" has reached the half of the max. allowed trading period and " +
|
||||
"is still not completed.\nPlease check your trade state at Portfolio/open trades for further information.").show();
|
||||
"is still not completed.\nPlease check your trade state at \"Portfolio/Open trades\" for further information.").show();
|
||||
trade.setHalfTradePeriodReachedWarningDisplayed(true);
|
||||
}
|
||||
break;
|
||||
case TRADE_PERIOD_OVER:
|
||||
if (!trade.isTradePeriodOverWarningDisplayed()) {
|
||||
new Popup().warning("Your trade with ID " + trade.getShortId() + " has reached the max. allowed trading period and is " +
|
||||
"not completed.\nPlease check your trade at Portfolio/Open trades for contacting the arbitrator.").show();
|
||||
"not completed.\nPlease check your trade at \"Portfolio/Open trades\" for contacting the arbitrator.").show();
|
||||
trade.setTradePeriodOverWarningDisplayed(true);
|
||||
}
|
||||
break;
|
||||
|
@ -219,7 +219,7 @@ public class ArbitratorRegistrationView extends ActivatableViewAndModel<VBox, Ar
|
||||
}
|
||||
|
||||
private void onRevoke() {
|
||||
if (model.isNetworkReady()) {
|
||||
if (model.isBootstrapped()) {
|
||||
model.onRevoke(
|
||||
() -> new Popup().information("You have successfully removed your arbitrator from the P2P network.").show(),
|
||||
(errorMessage) -> new Popup().error("Could not remove arbitrator.\nError message: " + errorMessage).show());
|
||||
@ -230,7 +230,7 @@ public class ArbitratorRegistrationView extends ActivatableViewAndModel<VBox, Ar
|
||||
}
|
||||
|
||||
private void onRegister() {
|
||||
if (model.isNetworkReady()) {
|
||||
if (model.isBootstrapped()) {
|
||||
model.onRegister(
|
||||
() -> new Popup().information("You have successfully registered your arbitrator to the P2P network.").show(),
|
||||
(errorMessage) -> new Popup().error("Could not register arbitrator.\nError message: " + errorMessage).show());
|
||||
|
@ -183,7 +183,7 @@ class ArbitratorRegistrationViewModel extends ActivatableViewModel {
|
||||
revokeButtonDisabled.set(!allDataValid || myArbitratorProperty.get() == null);
|
||||
}
|
||||
|
||||
boolean isNetworkReady() {
|
||||
return p2PService.isNetworkReady();
|
||||
boolean isBootstrapped() {
|
||||
return p2PService.isBootstrapped();
|
||||
}
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void onPlaceOffer() {
|
||||
if (model.isNetworkReady()) {
|
||||
if (model.isBootstrapped()) {
|
||||
Offer offer = model.createAndGetOffer();
|
||||
if (model.getShowPlaceOfferConfirmation()) {
|
||||
offerDetailsPopup.onPlaceOffer(o -> model.onPlaceOffer(o)).show(offer);
|
||||
|
@ -485,8 +485,8 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||
return dataModel.hasAcceptedArbitrators();
|
||||
}
|
||||
|
||||
boolean isNetworkReady() {
|
||||
return p2PService.isNetworkReady();
|
||||
boolean isBootstrapped() {
|
||||
return p2PService.isBootstrapped();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -230,7 +230,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
}
|
||||
|
||||
private void onTakeOffer(Offer offer) {
|
||||
if (model.isNetworkReady())
|
||||
if (model.isBootstrapped())
|
||||
offerActionHandler.onTakeOffer(offer);
|
||||
else
|
||||
new Popup().warning("You need to wait until your client is bootstrapped in the network.\n" +
|
||||
@ -238,7 +238,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
}
|
||||
|
||||
private void onRemoveOpenOffer(Offer offer) {
|
||||
if (model.isNetworkReady()) {
|
||||
if (model.isBootstrapped()) {
|
||||
new Popup().warning("Are you sure you want to remove that offer?\n" +
|
||||
"The offer fee you have paid will be lost if you remove that offer.")
|
||||
.actionButtonText("Remove offer")
|
||||
|
@ -157,8 +157,8 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
return list;
|
||||
}
|
||||
|
||||
boolean isNetworkReady() {
|
||||
return p2PService.isNetworkReady();
|
||||
boolean isBootstrapped() {
|
||||
return p2PService.isBootstrapped();
|
||||
}
|
||||
|
||||
public TradeCurrency getTradeCurrency() {
|
||||
|
@ -73,7 +73,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
}
|
||||
|
||||
private void onRemoveOpenOffer(OpenOffer openOffer) {
|
||||
if (model.isNetworkReady()) {
|
||||
if (model.isBootstrapped()) {
|
||||
new Popup().warning("Are you sure you want to remove that offer?\n" +
|
||||
"The offer fee you have paid will be lost if you remove that offer.")
|
||||
.actionButtonText("Remove offer")
|
||||
|
@ -73,7 +73,7 @@ class OpenOffersViewModel extends ActivatableWithDataModel<OpenOffersDataModel>
|
||||
return formatter.formatDateTime(item.getOffer().getDate());
|
||||
}
|
||||
|
||||
boolean isNetworkReady() {
|
||||
return p2PService.isNetworkReady();
|
||||
boolean isBootstrapped() {
|
||||
return p2PService.isBootstrapped();
|
||||
}
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
||||
}
|
||||
|
||||
private void onListChanged() {
|
||||
Log.traceCall();
|
||||
list.clear();
|
||||
list.addAll(tradeManager.getTrades().stream().map(PendingTradesListItem::new).collect(Collectors.toList()));
|
||||
|
||||
|
@ -26,6 +26,7 @@ import io.bitsquare.trade.Trade;
|
||||
import javafx.beans.property.ReadOnlyBooleanProperty;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Scene;
|
||||
@ -71,6 +72,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
||||
private ChangeListener<Trade> currentTradeChangeListener;
|
||||
private EventHandler<KeyEvent> keyEventEventHandler;
|
||||
private Scene scene;
|
||||
private ListChangeListener<PendingTradesListItem> listChangeListener;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -101,6 +103,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
||||
if (newValue != null)
|
||||
setNewSubView(newValue.getTrade());
|
||||
};
|
||||
listChangeListener = c -> updateSelectedItem();
|
||||
|
||||
appFocusChangeListener = (observable, oldValue, newValue) -> {
|
||||
if (newValue && model.getSelectedItem() != null) {
|
||||
@ -134,6 +137,15 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
||||
//setNewSubView(model.currentTrade().get());
|
||||
table.setItems(model.getList());
|
||||
table.getSelectionModel().selectedItemProperty().addListener(selectedItemChangeListener);
|
||||
updateSelectedItem();
|
||||
|
||||
if (model.getSelectedItem() == null)
|
||||
model.getList().addListener(listChangeListener);
|
||||
|
||||
scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEventEventHandler);
|
||||
}
|
||||
|
||||
private void updateSelectedItem() {
|
||||
PendingTradesListItem selectedItem = model.getSelectedItem();
|
||||
if (selectedItem != null) {
|
||||
// Select and focus selectedItem from model
|
||||
@ -144,13 +156,14 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
||||
UserThread.execute(() -> table.getFocusModel().focus(index));
|
||||
});
|
||||
}
|
||||
|
||||
scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEventEventHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void deactivate() {
|
||||
table.getSelectionModel().selectedItemProperty().removeListener(selectedItemChangeListener);
|
||||
|
||||
model.getList().removeListener(listChangeListener);
|
||||
|
||||
if (model.currentTrade() != null)
|
||||
model.currentTrade().removeListener(currentTradeChangeListener);
|
||||
|
||||
|
@ -221,8 +221,8 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
|
||||
return btcAddressValidator;
|
||||
}
|
||||
|
||||
public boolean isNetworkReady() {
|
||||
return p2PService.isNetworkReady();
|
||||
public boolean isBootstrapped() {
|
||||
return p2PService.isBootstrapped();
|
||||
}
|
||||
|
||||
// columns
|
||||
|
@ -107,7 +107,7 @@ public class ConfirmPaymentReceivedView extends TradeStepDetailsView {
|
||||
|
||||
private void onPaymentReceived(ActionEvent actionEvent) {
|
||||
log.debug("onPaymentReceived");
|
||||
if (model.isNetworkReady()) {
|
||||
if (model.isBootstrapped()) {
|
||||
Preferences preferences = model.dataModel.getPreferences();
|
||||
String key = PopupId.PAYMENT_RECEIVED;
|
||||
if (preferences.showAgain(key) && !BitsquareApp.DEV_MODE) {
|
||||
|
@ -140,7 +140,7 @@ public class StartPaymentView extends TradeStepDetailsView {
|
||||
|
||||
private void onPaymentStarted(ActionEvent actionEvent) {
|
||||
log.debug("onPaymentStarted");
|
||||
if (model.isNetworkReady()) {
|
||||
if (model.isBootstrapped()) {
|
||||
String key = PopupId.PAYMENT_SENT;
|
||||
if (preferences.showAgain(key) && !BitsquareApp.DEV_MODE) {
|
||||
new Popup().headLine("Confirmation")
|
||||
|
@ -107,42 +107,42 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
|
||||
return null;
|
||||
}
|
||||
});
|
||||
p2PServiceListener = new P2PServiceListener() {
|
||||
@Override
|
||||
public void onHiddenServicePublished() {
|
||||
onionAddress.setText(p2PService.getAddress().getFullAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestingDataCompleted() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoSeedNodeAvailable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoPeersAvailable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootstrapComplete() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetupFailed(Throwable throwable) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate() {
|
||||
NodeAddress nodeAddress = p2PService.getAddress();
|
||||
if (nodeAddress == null) {
|
||||
p2PServiceListener = new P2PServiceListener() {
|
||||
@Override
|
||||
public void onRequestingDataCompleted() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoSeedNodeAvailable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoPeersAvailable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHiddenServicePublished() {
|
||||
onionAddress.setText(p2PService.getAddress().getFullAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetupFailed(Throwable throwable) {
|
||||
}
|
||||
};
|
||||
p2PService.addP2PServiceListener(p2PServiceListener);
|
||||
} else {
|
||||
onionAddress.setText(nodeAddress.getFullAddress());
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.bitsquare.p2p;
|
||||
|
||||
|
||||
public abstract class NetWorkReadyListener implements P2PServiceListener {
|
||||
public abstract class BootstrapListener implements P2PServiceListener {
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
}
|
||||
@ -27,5 +27,5 @@ public abstract class NetWorkReadyListener implements P2PServiceListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
abstract public void onBootstrapped();
|
||||
abstract public void onBootstrapComplete();
|
||||
}
|
@ -79,6 +79,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
private boolean shutDownComplete;
|
||||
private ChangeListener<NodeAddress> connectionNodeAddressListener;
|
||||
private Subscription networkReadySubscription;
|
||||
private boolean isBootstrapped;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -266,7 +267,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
"seedNodeOfPreliminaryDataRequest must be present");
|
||||
peerExchangeManager.requestReportedPeers(seedNodeOfPreliminaryDataRequest.get());
|
||||
|
||||
p2pServiceListeners.stream().forEach(P2PServiceListener::onBootstrapped);
|
||||
isBootstrapped = true;
|
||||
p2pServiceListeners.stream().forEach(P2PServiceListener::onBootstrapComplete);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -377,7 +379,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
SendDirectMessageListener sendDirectMessageListener) {
|
||||
Log.traceCall();
|
||||
checkNotNull(peerNodeAddress, "PeerAddress must not be null (sendEncryptedDirectMessage)");
|
||||
if (isNetworkReady()) {
|
||||
if (isBootstrapped()) {
|
||||
doSendEncryptedDirectMessage(peerNodeAddress, pubKeyRing, message, sendDirectMessageListener);
|
||||
} else {
|
||||
throw new NetworkNotReadyException();
|
||||
@ -473,7 +475,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
checkArgument(optionalEncryptionService.isPresent(),
|
||||
"EncryptionService not set. Seems that is called on a seed node which must not happen.");
|
||||
|
||||
if (isNetworkReady()) {
|
||||
if (isBootstrapped()) {
|
||||
if (!networkNode.getAllConnections().isEmpty()) {
|
||||
try {
|
||||
log.info("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" +
|
||||
@ -527,7 +529,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
checkArgument(optionalKeyRing.isPresent(),
|
||||
"keyRing not set. Seems that is called on a seed node which must not happen.");
|
||||
|
||||
if (isNetworkReady()) {
|
||||
if (isBootstrapped()) {
|
||||
if (!networkNode.getAllConnections().isEmpty()) {
|
||||
try {
|
||||
ProtectedMailboxData protectedMailboxData = p2PDataStorage.getMailboxDataWithSignedSeqNr(
|
||||
@ -571,7 +573,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
public void removeEntryFromMailbox(DecryptedMsgWithPubKey decryptedMsgWithPubKey) {
|
||||
Log.traceCall();
|
||||
checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
|
||||
if (isNetworkReady()) {
|
||||
if (isBootstrapped()) {
|
||||
if (mailboxMap.containsKey(decryptedMsgWithPubKey)) {
|
||||
ProtectedMailboxData mailboxData = mailboxMap.get(decryptedMsgWithPubKey);
|
||||
if (mailboxData != null && mailboxData.expirablePayload instanceof ExpirableMailboxPayload) {
|
||||
@ -620,7 +622,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
private boolean doAddData(ExpirablePayload expirablePayload, boolean rePublish) {
|
||||
Log.traceCall();
|
||||
checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
|
||||
if (isNetworkReady()) {
|
||||
if (isBootstrapped()) {
|
||||
try {
|
||||
ProtectedData protectedData = p2PDataStorage.getDataWithSignedSeqNr(expirablePayload, optionalKeyRing.get().getSignatureKeyPair());
|
||||
if (rePublish)
|
||||
@ -639,7 +641,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
public boolean removeData(ExpirablePayload expirablePayload) {
|
||||
Log.traceCall();
|
||||
checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
|
||||
if (isNetworkReady()) {
|
||||
if (isBootstrapped()) {
|
||||
try {
|
||||
ProtectedData protectedData = p2PDataStorage.getDataWithSignedSeqNr(expirablePayload, optionalKeyRing.get().getSignatureKeyPair());
|
||||
return p2PDataStorage.remove(protectedData, networkNode.getNodeAddress());
|
||||
@ -686,8 +688,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public boolean isNetworkReady() {
|
||||
return hiddenServicePublished.get() && preliminaryDataReceived.get();
|
||||
public boolean isBootstrapped() {
|
||||
return isBootstrapped;
|
||||
}
|
||||
|
||||
public NetworkNode getNetworkNode() {
|
||||
@ -710,7 +712,6 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||
return p2PDataStorage.getMap();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -11,5 +11,5 @@ public interface P2PServiceListener extends SetupListener {
|
||||
|
||||
void onNoPeersAvailable();
|
||||
|
||||
void onBootstrapped();
|
||||
void onBootstrapComplete();
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -148,7 +148,7 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class PeerManagerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -155,7 +155,7 @@ public class PeerManagerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ public class PeerManagerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@ -430,7 +430,7 @@ public class PeerManagerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootstrapped() {
|
||||
public void onBootstrapComplete() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user