P2P network improvements, rename MarketPriceFeed to PriceFeed

This commit is contained in:
Manfred Karrer 2016-02-26 02:12:05 +01:00
parent 4bc8c70a83
commit 60c8de796a
22 changed files with 98 additions and 91 deletions

View File

@ -63,7 +63,7 @@ public class Log {
logbackLogger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
//TODO for now use always trace
logbackLogger.setLevel(useDetailedLogging ? Level.TRACE : Level.INFO);
logbackLogger.setLevel(useDetailedLogging ? Level.INFO : Level.INFO);
// logbackLogger.setLevel(useDetailedLogging ? Level.TRACE : Level.DEBUG);
logbackLogger.addAppender(appender);
}

View File

@ -20,7 +20,7 @@ package io.bitsquare.btc;
import com.google.inject.Singleton;
import io.bitsquare.app.AppModule;
import io.bitsquare.btc.blockchain.BlockchainService;
import io.bitsquare.btc.pricefeed.MarketPriceFeed;
import io.bitsquare.btc.pricefeed.PriceFeed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
@ -52,7 +52,7 @@ public class BitcoinModule extends AppModule {
bind(TradeWalletService.class).in(Singleton.class);
bind(WalletService.class).in(Singleton.class);
bind(BlockchainService.class).in(Singleton.class);
bind(MarketPriceFeed.class).in(Singleton.class);
bind(PriceFeed.class).in(Singleton.class);
}
}

View File

@ -30,7 +30,7 @@ public class MarketPrice {
}
public double getPrice(MarketPriceFeed.Type type) {
public double getPrice(PriceFeed.Type type) {
switch (type) {
case ASK:
return ask;

View File

@ -24,8 +24,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
public class MarketPriceFeed {
private static final Logger log = LoggerFactory.getLogger(MarketPriceFeed.class);
public class PriceFeed {
private static final Logger log = LoggerFactory.getLogger(PriceFeed.class);
///////////////////////////////////////////////////////////////////////////////////////////
// Enum
@ -62,7 +62,7 @@ public class MarketPriceFeed {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public MarketPriceFeed() {
public PriceFeed() {
}
@ -75,7 +75,6 @@ public class MarketPriceFeed {
this.faultHandler = faultHandler;
requestAllPrices(fiatPriceProvider, () -> {
log.trace("requestAllPrices result");
applyPrice();
UserThread.runPeriodically(() -> requestPrice(fiatPriceProvider), PERIOD_FIAT_SEC);
});

View File

@ -140,7 +140,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
log.info("remove all open offers at shutDown");
// we remove own offers from offerbook when we go offline
// Normally we use a delay for broadcasting to the peers, but at shut down we want to get it fast out
BroadcastHandler.setDelayMs(1);
BroadcastHandler.useDelay(false);
openOffers.forEach(openOffer -> offerBookService.removeOfferAtShutDown(openOffer.getOffer()));
if (completeHandler != null)

View File

@ -19,6 +19,7 @@ package io.bitsquare.trade.protocol.placeoffer.tasks;
import io.bitsquare.common.taskrunner.Task;
import io.bitsquare.common.taskrunner.TaskRunner;
import io.bitsquare.p2p.peers.BroadcastHandler;
import io.bitsquare.trade.protocol.placeoffer.PlaceOfferModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -34,9 +35,11 @@ public class AddOfferToRemoteOfferBook extends Task<PlaceOfferModel> {
protected void run() {
try {
runInterceptHook();
BroadcastHandler.useDelay(false);
model.offerBookService.addOffer(model.offer,
() -> {
model.offerAddedToOfferBook = true;
BroadcastHandler.useDelay(true);
complete();
},
errorMessage -> {

View File

@ -22,6 +22,7 @@ import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.FeePolicy;
import io.bitsquare.common.taskrunner.Task;
import io.bitsquare.common.taskrunner.TaskRunner;
import io.bitsquare.p2p.peers.BroadcastHandler;
import io.bitsquare.trade.offer.Offer;
import io.bitsquare.trade.protocol.placeoffer.PlaceOfferModel;
import org.bitcoinj.core.Coin;
@ -61,15 +62,19 @@ public class BroadcastCreateOfferFeeTx extends Task<PlaceOfferModel> {
log.warn("Tx malleability happened after broadcast. We publish the changed offer to the P2P network again.");
// Tx malleability happened after broadcast. We first remove the malleable offer.
// Then we publish the changed offer to the P2P network again after setting the new TxId.
// Normally we use a delay for broadcasting to the peers, but at shut down we want to get it fast out
BroadcastHandler.useDelay(false);
model.offerBookService.removeOffer(model.offer,
() -> {
log.info("We store now the changed txID to the offer and add that again.");
// We store now the changed txID to the offer and add that again.
model.offer.setOfferFeePaymentTxID(transaction.getHashAsString());
model.setTransaction(transaction);
model.offerBookService.addOffer(model.offer,
BroadcastCreateOfferFeeTx.this::complete,
() -> {
BroadcastHandler.useDelay(true);
complete();
},
errorMessage -> {
log.error("addOffer failed");
addOfferFailed = true;

View File

@ -13,9 +13,9 @@ public class MarketPriceFeedTest {
@Test
public void testGetPrice() throws InterruptedException {
MarketPriceFeed marketPriceFeed = new MarketPriceFeed();
marketPriceFeed.setCurrencyCode("EUR");
marketPriceFeed.init(tradeCurrency -> {
PriceFeed priceFeed = new PriceFeed();
priceFeed.setCurrencyCode("EUR");
priceFeed.init(tradeCurrency -> {
log.debug(tradeCurrency.toString());
assertTrue(true);
},

View File

@ -866,7 +866,7 @@ textfield */
-fx-text-fill: white;
-fx-font-weight: bold;
-fx-font-size: 15;
/*-fx-background-radius: 20;*/
-fx-background-radius: 5;
}
#buy-button-big:hover {
@ -878,7 +878,7 @@ textfield */
-fx-text-fill: white;
-fx-font-weight: bold;
-fx-font-size: 15;
/* -fx-background-radius: 20;*/
-fx-background-radius: 5;
}
#sell-button-big:hover {
@ -889,7 +889,6 @@ textfield */
-fx-base: -bs-buy;
-fx-text-fill: white;
-fx-font-weight: bold;
/* -fx-background-radius: 13;*/
}
#buy-button:hover {
@ -900,7 +899,6 @@ textfield */
-fx-base: -bs-sell;
-fx-text-fill: white;
-fx-font-weight: bold;
/* -fx-background-radius: 13;*/
}
#sell-button:hover {
@ -911,7 +909,6 @@ textfield */
-fx-base: -bs-light-grey;
-fx-text-fill: white;
-fx-font-weight: bold;
/* -fx-background-radius: 13;*/
}
#cancel-button:hover {

View File

@ -19,7 +19,7 @@ package io.bitsquare.gui.main;
import io.bitsquare.BitsquareException;
import io.bitsquare.app.BitsquareApp;
import io.bitsquare.btc.pricefeed.MarketPriceFeed;
import io.bitsquare.btc.pricefeed.PriceFeed;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.util.Tuple2;
import io.bitsquare.common.util.Tuple3;
@ -133,7 +133,7 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
model.marketPriceCurrency, model.marketPrice));
marketPriceBox.second.textProperty().bind(createStringBinding(
() -> {
MarketPriceFeed.Type type = model.typeProperty.get();
PriceFeed.Type type = model.typeProperty.get();
return type != null ? "Market price (" + type.name + ")" : "";
},
model.marketPriceCurrency, model.typeProperty));

View File

@ -31,7 +31,7 @@ import io.bitsquare.btc.FeePolicy;
import io.bitsquare.btc.TradeWalletService;
import io.bitsquare.btc.WalletService;
import io.bitsquare.btc.listeners.BalanceListener;
import io.bitsquare.btc.pricefeed.MarketPriceFeed;
import io.bitsquare.btc.pricefeed.PriceFeed;
import io.bitsquare.common.Clock;
import io.bitsquare.common.Timer;
import io.bitsquare.common.UserThread;
@ -103,7 +103,7 @@ public class MainViewModel implements ViewModel {
final StringProperty btcSplashSyncIconId = new SimpleStringProperty();
final StringProperty marketPrice = new SimpleStringProperty("N/A");
final StringProperty marketPriceCurrency = new SimpleStringProperty("");
final ObjectProperty<MarketPriceFeed.Type> typeProperty = new SimpleObjectProperty<>(MarketPriceFeed.Type.LAST);
final ObjectProperty<PriceFeed.Type> typeProperty = new SimpleObjectProperty<>(PriceFeed.Type.LAST);
final StringProperty availableBalance = new SimpleStringProperty();
final StringProperty reservedBalance = new SimpleStringProperty();
final StringProperty lockedBalance = new SimpleStringProperty();
@ -130,7 +130,7 @@ public class MainViewModel implements ViewModel {
final StringProperty p2pNetworkLabelId = new SimpleStringProperty("footer-pane");
private MonadicBinding<Boolean> allServicesDone, tradesAndUIReady;
private final MarketPriceFeed marketPriceFeed;
private final PriceFeed priceFeed;
private final User user;
private int numBtcPeers = 0;
private Timer checkNumberOfBtcPeersTimer;
@ -146,13 +146,13 @@ public class MainViewModel implements ViewModel {
@Inject
public MainViewModel(WalletService walletService, TradeWalletService tradeWalletService,
MarketPriceFeed marketPriceFeed,
PriceFeed priceFeed,
ArbitratorManager arbitratorManager, P2PService p2PService, TradeManager tradeManager,
OpenOfferManager openOfferManager, DisputeManager disputeManager, Preferences preferences,
User user, AlertManager alertManager, WalletPasswordPopup walletPasswordPopup,
NotificationCenter notificationCenter, TacPopup tacPopup, Clock clock,
Navigation navigation, BSFormatter formatter) {
this.marketPriceFeed = marketPriceFeed;
this.priceFeed = priceFeed;
this.user = user;
this.walletService = walletService;
this.tradeWalletService = tradeWalletService;
@ -615,18 +615,18 @@ public class MainViewModel implements ViewModel {
}
private void setupMarketPriceFeed() {
if (marketPriceFeed.getCurrencyCode() == null)
marketPriceFeed.setCurrencyCode(preferences.getPreferredTradeCurrency().getCode());
if (marketPriceFeed.getType() == null)
marketPriceFeed.setType(MarketPriceFeed.Type.LAST);
marketPriceFeed.init(price -> {
if (priceFeed.getCurrencyCode() == null)
priceFeed.setCurrencyCode(preferences.getPreferredTradeCurrency().getCode());
if (priceFeed.getType() == null)
priceFeed.setType(PriceFeed.Type.LAST);
priceFeed.init(price -> {
marketPrice.set(formatter.formatMarketPrice(price));
},
(errorMessage, throwable) -> {
marketPrice.set("N/A");
});
marketPriceCurrency.bind(marketPriceFeed.currencyCodeProperty());
typeProperty.bind(marketPriceFeed.typeProperty());
marketPriceCurrency.bind(priceFeed.currencyCodeProperty());
typeProperty.bind(priceFeed.typeProperty());
}
private void displayAlertIfPresent(Alert alert) {

View File

@ -19,7 +19,7 @@ package io.bitsquare.gui.main.markets.charts;
import com.google.common.math.LongMath;
import com.google.inject.Inject;
import io.bitsquare.btc.pricefeed.MarketPriceFeed;
import io.bitsquare.btc.pricefeed.PriceFeed;
import io.bitsquare.gui.common.model.ActivatableViewModel;
import io.bitsquare.gui.main.offer.offerbook.OfferBook;
import io.bitsquare.gui.main.offer.offerbook.OfferBookListItem;
@ -42,7 +42,7 @@ class MarketsChartsViewModel extends ActivatableViewModel {
private final OfferBook offerBook;
private final Preferences preferences;
private final MarketPriceFeed marketPriceFeed;
private final PriceFeed priceFeed;
final ObjectProperty<TradeCurrency> tradeCurrency = new SimpleObjectProperty<>(CurrencyUtil.getDefaultTradeCurrency());
private final List<XYChart.Data> buyData = new ArrayList();
@ -58,10 +58,10 @@ class MarketsChartsViewModel extends ActivatableViewModel {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public MarketsChartsViewModel(OfferBook offerBook, Preferences preferences, MarketPriceFeed marketPriceFeed) {
public MarketsChartsViewModel(OfferBook offerBook, Preferences preferences, PriceFeed priceFeed) {
this.offerBook = offerBook;
this.preferences = preferences;
this.marketPriceFeed = marketPriceFeed;
this.priceFeed = priceFeed;
offerBookListItems = offerBook.getOfferBookListItems();
listChangeListener = c -> updateChartData(offerBookListItems);
@ -69,11 +69,11 @@ class MarketsChartsViewModel extends ActivatableViewModel {
@Override
protected void activate() {
marketPriceFeed.setType(MarketPriceFeed.Type.LAST);
priceFeed.setType(PriceFeed.Type.LAST);
offerBookListItems.addListener(listChangeListener);
offerBook.fillOfferBookListItems();
updateChartData(offerBookListItems);
marketPriceFeed.setCurrencyCode(tradeCurrency.get().getCode());
priceFeed.setCurrencyCode(tradeCurrency.get().getCode());
}
@Override
@ -139,7 +139,7 @@ class MarketsChartsViewModel extends ActivatableViewModel {
public void onSetTradeCurrency(TradeCurrency tradeCurrency) {
this.tradeCurrency.set(tradeCurrency);
updateChartData(offerBookListItems);
marketPriceFeed.setCurrencyCode(tradeCurrency.getCode());
priceFeed.setCurrencyCode(tradeCurrency.getCode());
}
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -17,7 +17,7 @@
package io.bitsquare.gui.main.offer;
import io.bitsquare.btc.pricefeed.MarketPriceFeed;
import io.bitsquare.btc.pricefeed.PriceFeed;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.common.view.FxmlView;
import io.bitsquare.gui.common.view.ViewLoader;
@ -28,8 +28,8 @@ import javax.inject.Inject;
public class BuyOfferView extends OfferView {
@Inject
public BuyOfferView(ViewLoader viewLoader, Navigation navigation, MarketPriceFeed marketPriceFeed) {
super(viewLoader, navigation, marketPriceFeed);
public BuyOfferView(ViewLoader viewLoader, Navigation navigation, PriceFeed priceFeed) {
super(viewLoader, navigation, priceFeed);
}
@Override

View File

@ -17,7 +17,7 @@
package io.bitsquare.gui.main.offer;
import io.bitsquare.btc.pricefeed.MarketPriceFeed;
import io.bitsquare.btc.pricefeed.PriceFeed;
import io.bitsquare.common.UserThread;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.common.view.ActivatableView;
@ -52,7 +52,7 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
private final ViewLoader viewLoader;
private final Navigation navigation;
private final MarketPriceFeed marketPriceFeed;
private final PriceFeed priceFeed;
private final Offer.Direction direction;
private Tab takeOfferTab, createOfferTab, offerBookTab;
private TradeCurrency tradeCurrency;
@ -60,10 +60,10 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
private ChangeListener<Tab> tabChangeListener;
private ListChangeListener<Tab> tabListChangeListener;
protected OfferView(ViewLoader viewLoader, Navigation navigation, MarketPriceFeed marketPriceFeed) {
protected OfferView(ViewLoader viewLoader, Navigation navigation, PriceFeed priceFeed) {
this.viewLoader = viewLoader;
this.navigation = navigation;
this.marketPriceFeed = marketPriceFeed;
this.priceFeed = priceFeed;
this.direction = (this instanceof BuyOfferView) ? Offer.Direction.BUY : Offer.Direction.SELL;
}
@ -127,7 +127,7 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
View view;
boolean isBuy = direction == Offer.Direction.BUY;
marketPriceFeed.setType(isBuy ? MarketPriceFeed.Type.ASK : MarketPriceFeed.Type.BID);
priceFeed.setType(isBuy ? PriceFeed.Type.ASK : PriceFeed.Type.BID);
if (viewClass == OfferBookView.class && offerBookView == null) {
view = viewLoader.load(viewClass);

View File

@ -17,7 +17,7 @@
package io.bitsquare.gui.main.offer;
import io.bitsquare.btc.pricefeed.MarketPriceFeed;
import io.bitsquare.btc.pricefeed.PriceFeed;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.common.view.FxmlView;
import io.bitsquare.gui.common.view.ViewLoader;
@ -28,8 +28,8 @@ import javax.inject.Inject;
public class SellOfferView extends OfferView {
@Inject
public SellOfferView(ViewLoader viewLoader, Navigation navigation, MarketPriceFeed marketPriceFeed) {
super(viewLoader, navigation, marketPriceFeed);
public SellOfferView(ViewLoader viewLoader, Navigation navigation, PriceFeed priceFeed) {
super(viewLoader, navigation, priceFeed);
}
@Override

View File

@ -25,7 +25,7 @@ import io.bitsquare.arbitration.Arbitrator;
import io.bitsquare.btc.*;
import io.bitsquare.btc.blockchain.BlockchainService;
import io.bitsquare.btc.listeners.BalanceListener;
import io.bitsquare.btc.pricefeed.MarketPriceFeed;
import io.bitsquare.btc.pricefeed.PriceFeed;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.crypto.KeyRing;
import io.bitsquare.gui.common.model.ActivatableDataModel;
@ -71,7 +71,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
private final User user;
private final KeyRing keyRing;
private final P2PService p2PService;
private final MarketPriceFeed marketPriceFeed;
private final PriceFeed priceFeed;
private final WalletPasswordPopup walletPasswordPopup;
private final BlockchainService blockchainService;
private final BSFormatter formatter;
@ -112,7 +112,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
@Inject
CreateOfferDataModel(OpenOfferManager openOfferManager, WalletService walletService, TradeWalletService tradeWalletService,
Preferences preferences, User user, KeyRing keyRing, P2PService p2PService, MarketPriceFeed marketPriceFeed,
Preferences preferences, User user, KeyRing keyRing, P2PService p2PService, PriceFeed priceFeed,
WalletPasswordPopup walletPasswordPopup, BlockchainService blockchainService, BSFormatter formatter) {
this.openOfferManager = openOfferManager;
this.walletService = walletService;
@ -121,7 +121,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
this.user = user;
this.keyRing = keyRing;
this.p2PService = p2PService;
this.marketPriceFeed = marketPriceFeed;
this.priceFeed = priceFeed;
this.walletPasswordPopup = walletPasswordPopup;
this.blockchainService = blockchainService;
this.formatter = formatter;
@ -178,7 +178,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
calculateTotalToPay();
if (isTabSelected)
marketPriceFeed.setCurrencyCode(tradeCurrencyCode.get());
priceFeed.setCurrencyCode(tradeCurrencyCode.get());
}
@Override
@ -220,13 +220,13 @@ class CreateOfferDataModel extends ActivatableDataModel {
if (account != null)
paymentAccount = account;
marketPriceFeed.setCurrencyCode(tradeCurrencyCode.get());
priceFeed.setCurrencyCode(tradeCurrencyCode.get());
}
void onTabSelected(boolean isSelected) {
this.isTabSelected = isSelected;
if (isTabSelected)
marketPriceFeed.setCurrencyCode(tradeCurrencyCode.get());
priceFeed.setCurrencyCode(tradeCurrencyCode.get());
}
///////////////////////////////////////////////////////////////////////////////////////////
@ -289,7 +289,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
paymentAccount.setSelectedTradeCurrency(tradeCurrency);
marketPriceFeed.setCurrencyCode(code);
priceFeed.setCurrencyCode(code);
}
}

View File

@ -19,7 +19,7 @@ package io.bitsquare.gui.main.offer.offerbook;
import com.google.inject.Inject;
import io.bitsquare.app.Version;
import io.bitsquare.btc.pricefeed.MarketPriceFeed;
import io.bitsquare.btc.pricefeed.PriceFeed;
import io.bitsquare.common.handlers.ErrorMessageHandler;
import io.bitsquare.common.handlers.ResultHandler;
import io.bitsquare.gui.common.model.ActivatableViewModel;
@ -55,7 +55,7 @@ class OfferBookViewModel extends ActivatableViewModel {
private final OfferBook offerBook;
private final Preferences preferences;
private final P2PService p2PService;
private final MarketPriceFeed marketPriceFeed;
private final PriceFeed priceFeed;
final BSFormatter formatter;
private final FilteredList<OfferBookListItem> filteredItems;
@ -85,7 +85,7 @@ class OfferBookViewModel extends ActivatableViewModel {
@Inject
public OfferBookViewModel(User user, OpenOfferManager openOfferManager, OfferBook offerBook,
Preferences preferences, P2PService p2PService, MarketPriceFeed marketPriceFeed,
Preferences preferences, P2PService p2PService, PriceFeed priceFeed,
BSFormatter formatter) {
super();
@ -94,7 +94,7 @@ class OfferBookViewModel extends ActivatableViewModel {
this.offerBook = offerBook;
this.preferences = preferences;
this.p2PService = p2PService;
this.marketPriceFeed = marketPriceFeed;
this.priceFeed = priceFeed;
this.formatter = formatter;
offerBookListItems = offerBook.getOfferBookListItems();
@ -143,9 +143,9 @@ class OfferBookViewModel extends ActivatableViewModel {
private void setMarketPriceFeedCurrency() {
if (isTabSelected) {
if (showAllTradeCurrenciesProperty.get())
marketPriceFeed.setCurrencyCode(CurrencyUtil.getDefaultTradeCurrency().getCode());
priceFeed.setCurrencyCode(CurrencyUtil.getDefaultTradeCurrency().getCode());
else
marketPriceFeed.setCurrencyCode(tradeCurrencyCode.get());
priceFeed.setCurrencyCode(tradeCurrencyCode.get());
}
}

View File

@ -26,7 +26,7 @@ import io.bitsquare.arbitration.Arbitrator;
import io.bitsquare.btc.*;
import io.bitsquare.btc.blockchain.BlockchainService;
import io.bitsquare.btc.listeners.BalanceListener;
import io.bitsquare.btc.pricefeed.MarketPriceFeed;
import io.bitsquare.btc.pricefeed.PriceFeed;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.handlers.ResultHandler;
import io.bitsquare.gui.common.model.ActivatableDataModel;
@ -69,7 +69,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
private final User user;
private final WalletPasswordPopup walletPasswordPopup;
private final Preferences preferences;
private final MarketPriceFeed marketPriceFeed;
private final PriceFeed priceFeed;
private final BlockchainService blockchainService;
private final BSFormatter formatter;
@ -101,7 +101,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
@Inject
TakeOfferDataModel(TradeManager tradeManager, TradeWalletService tradeWalletService,
WalletService walletService, User user, WalletPasswordPopup walletPasswordPopup,
Preferences preferences, MarketPriceFeed marketPriceFeed, BlockchainService blockchainService,
Preferences preferences, PriceFeed priceFeed, BlockchainService blockchainService,
BSFormatter formatter) {
this.tradeManager = tradeManager;
this.tradeWalletService = tradeWalletService;
@ -109,7 +109,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
this.user = user;
this.walletPasswordPopup = walletPasswordPopup;
this.preferences = preferences;
this.marketPriceFeed = marketPriceFeed;
this.priceFeed = priceFeed;
this.blockchainService = blockchainService;
this.formatter = formatter;
@ -134,7 +134,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
feeFromFundingTxProperty.set(FeePolicy.getMinRequiredFeeForFundingTx());
if (isTabSelected)
marketPriceFeed.setCurrencyCode(offer.getCurrencyCode());
priceFeed.setCurrencyCode(offer.getCurrencyCode());
}
@Override
@ -200,7 +200,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
};
offer.resetState();
marketPriceFeed.setCurrencyCode(offer.getCurrencyCode());
priceFeed.setCurrencyCode(offer.getCurrencyCode());
}
void checkOfferAvailability(ResultHandler resultHandler) {
@ -210,7 +210,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
void onTabSelected(boolean isSelected) {
this.isTabSelected = isSelected;
if (isTabSelected)
marketPriceFeed.setCurrencyCode(offer.getCurrencyCode());
priceFeed.setCurrencyCode(offer.getCurrencyCode());
}
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -35,7 +35,7 @@ public class P2pNetworkListItem {
private final Statistic statistic;
private final Connection connection;
private final Subscription sentBytesSubscription, receivedBytesSubscription;
private final Subscription sentBytesSubscription, receivedBytesSubscription, onionAddressSubscription;
private final Clock clock;
private final BSFormatter formatter;
@ -57,6 +57,8 @@ public class P2pNetworkListItem {
e -> sentBytes.set(formatter.formatBytes((int) e)));
receivedBytesSubscription = EasyBind.subscribe(statistic.receivedBytesProperty(),
e -> receivedBytes.set(formatter.formatBytes((int) e)));
onionAddressSubscription = EasyBind.subscribe(connection.peersNodeAddressProperty(),
nodeAddress -> onionAddress.set(nodeAddress != null ? nodeAddress.getFullAddress() : "Not known yet"));
listener = new Clock.Listener() {
@Override
@ -64,7 +66,6 @@ public class P2pNetworkListItem {
onLastActivityChanged(statistic.getLastActivityTimestamp());
updatePeerType();
updateConnectionType();
updateOnionAddress();
}
@Override
@ -79,7 +80,6 @@ public class P2pNetworkListItem {
onLastActivityChanged(statistic.getLastActivityTimestamp());
updatePeerType();
updateConnectionType();
updateOnionAddress();
}
private void onLastActivityChanged(long timeStamp) {
@ -89,14 +89,10 @@ public class P2pNetworkListItem {
public void cleanup() {
sentBytesSubscription.unsubscribe();
receivedBytesSubscription.unsubscribe();
onionAddressSubscription.unsubscribe();
clock.removeListener(listener);
}
public void updateOnionAddress() {
onionAddress.set(connection.getPeersNodeAddressOptional().isPresent() ?
connection.getPeersNodeAddressOptional().get().getFullAddress() : "Not known yet");
}
public void updateConnectionType() {
connectionType.set(connection instanceof OutboundConnection ? "outbound" : "inbound");
}
@ -118,7 +114,7 @@ public class P2pNetworkListItem {
return onionAddress.get();
}
public StringProperty getOnionAddressProperty() {
public StringProperty onionAddressProperty() {
return onionAddress;
}
@ -126,7 +122,7 @@ public class P2pNetworkListItem {
return connectionType.get();
}
public StringProperty getConnectionTypeProperty() {
public StringProperty connectionTypeProperty() {
return connectionType;
}
@ -134,7 +130,7 @@ public class P2pNetworkListItem {
return peerType.get();
}
public StringProperty getPeerTypeProperty() {
public StringProperty peerTypeProperty() {
return peerType;
}

View File

@ -59,8 +59,9 @@ public class Connection implements MessageListener {
///////////////////////////////////////////////////////////////////////////////////////////
private static final int MAX_MSG_SIZE = 100 * 1024; // 100 kb of compressed data
private static final int MSG_THROTTLE_PER_SEC = 20; // With MAX_MSG_SIZE of 100kb results in bandwidth of 20 mbit/sec
private static final int MSG_THROTTLE_PER_10_SEC = 100; // With MAX_MSG_SIZE of 100kb results in bandwidth of 10 mbit/sec for 10 sec
//TODO decrease limits again after testing
private static final int MSG_THROTTLE_PER_SEC = 100; // With MAX_MSG_SIZE of 100kb results in bandwidth of 100 mbit/sec
private static final int MSG_THROTTLE_PER_10_SEC = 1000; // With MAX_MSG_SIZE of 100kb results in bandwidth of 1000 mbit/sec for 10 sec
private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(60);
public static int getMaxMsgSize() {

View File

@ -29,12 +29,13 @@ public class BroadcastHandler implements PeerManager.Listener {
private static final Logger log = LoggerFactory.getLogger(BroadcastHandler.class);
private static final long TIMEOUT_PER_PEER_SEC = Timer.STRESS_TEST ? 5 : 30;
private static final long DELAY_MS = Timer.STRESS_TEST ? 1000 : 2000;
private static boolean USE_DELAY;
public static void setDelayMs(long delayMs) {
DELAY_MS = delayMs;
public static void useDelay(boolean useDelay) {
USE_DELAY = useDelay;
}
private static long DELAY_MS = Timer.STRESS_TEST ? 1000 : 2000;
interface ResultHandler {
void onCompleted(BroadcastHandler broadcastHandler);
@ -129,8 +130,12 @@ public class BroadcastHandler implements PeerManager.Listener {
onFault(errorMessage);
}, timeoutDelay);
receivers.stream().forEach(connection -> UserThread.runAfterRandomDelay(() ->
sendToPeer(connection, message), DELAY_MS, DELAY_MS * 2, TimeUnit.MILLISECONDS));
if (USE_DELAY) {
receivers.stream().forEach(connection -> UserThread.runAfterRandomDelay(() ->
sendToPeer(connection, message), DELAY_MS, DELAY_MS * 2, TimeUnit.MILLISECONDS));
} else {
receivers.stream().forEach(connection -> sendToPeer(connection, message));
}
} else {
onFault("Message not broadcasted because we have no available peers yet.\n\t" +
"message = " + StringUtils.abbreviate(message.toString(), 100), false);

View File

@ -25,7 +25,8 @@ public class PeerManager implements ConnectionListener {
private static final Logger log = LoggerFactory.getLogger(PeerManager.class);
private static final long CHECK_MAX_CONN_DELAY_SEC = Timer.STRESS_TEST ? 1 : 5;
private static final long REMOVE_ANONYMOUS_PEER_SEC = Timer.STRESS_TEST ? 1 : 30;
// Use a long delay as the bootstrapping peer might need a while until it knows its onion address
private static final long REMOVE_ANONYMOUS_PEER_SEC = Timer.STRESS_TEST ? 10 : 120;
private static int MAX_CONNECTIONS;
private static int MIN_CONNECTIONS;