This commit is contained in:
Manfred Karrer 2016-07-25 18:14:20 +02:00
parent 2240daf9c0
commit a41e78290e
24 changed files with 54 additions and 100 deletions

View File

@ -90,7 +90,6 @@ public class Version {
// We don't use the Enum in any serialized data, as changes in the enum would break backwards compatibility. We use the ordinal integer instead.
// Sequence in the enum must not be changed (append only).
public enum Capability {
SEED_NODE,
TRADE_STATISTICS
}

View File

@ -2,5 +2,4 @@ package io.bitsquare.common;
public class CommonOptionKeys {
public static final String LOG_LEVEL_KEY = "logLevel";
}

View File

@ -80,7 +80,6 @@ public class BitsquareEnvironment extends StandardEnvironment {
private final String appName;
private final String userDataDir;
private final String appDataDir;
private final String btcNetworkDir;
private final String logLevel;

View File

@ -3,5 +3,4 @@ package io.bitsquare.app;
public class CoreOptionKeys {
public static final String IGNORE_DEV_MSG_KEY = "ignoreDevMsg";
public static final String DUMP_STATISTICS = "dumpStatistics";
}

View File

@ -268,18 +268,16 @@ public class WalletService {
// 1333 / (2800 + 1333) = 0.32 -> 32 % probability that a pub key is in our wallet
walletAppKit.setBloomFilterFalsePositiveRate(0.00005);
log.debug("seedNodes: " + seedNodes.toString());
boolean setPeerNodes = false;
log.debug("seedNodes: " + seedNodes);
boolean usePeerNodes = false;
// Pass custom seed nodes if set in options
if (seedNodes != null && !seedNodes.isEmpty()) {
if (!seedNodes.isEmpty()) {
// todo: this parsing should be more robust,
// TODO: this parsing should be more robust,
// give validation error if needed.
// also: it seems the peer nodes can be overridden in the case
// of regtest mode below. is that wanted?
String[] nodes = seedNodes.split(",");
List<PeerAddress> peerAddressList = new ArrayList<PeerAddress>();
String[] nodes = seedNodes.replace(", ", ",").split(",");
List<PeerAddress> peerAddressList = new ArrayList<>();
for (String node : nodes) {
String[] parts = node.split(":");
if (parts.length == 1) {
@ -300,9 +298,8 @@ public class WalletService {
addr = new InetSocketAddress(parts[0], Integer.parseInt(parts[1]));
}
// note: isUnresolved check should be removed once we fix PeerAddress
if (addr != null && !addr.isUnresolved()) {
if (addr != null && !addr.isUnresolved())
peerAddressList.add(new PeerAddress(addr.getAddress(), addr.getPort()));
}
}
}
if (peerAddressList.size() > 0) {
@ -310,23 +307,17 @@ public class WalletService {
log.debug("seedNodes parsed: " + Arrays.toString(peerAddressListFixed));
walletAppKit.setPeerNodes(peerAddressList.toArray(peerAddressListFixed));
setPeerNodes = true;
usePeerNodes = true;
}
}
// We do not call walletAppKit.useTor() anymore because that would turn
// on orchid Tor, which we do not want. Instead, we create a Tor proxy
// later.
// if (useTor && params.getId().equals(NetworkParameters.ID_MAINNET))
// walletAppKit.useTor();
// Now configure and start the appkit. This will take a second or two - we could show a temporary splash screen
// or progress widget to keep the user engaged whilst we initialise, but we don't.
if (params == RegTestParams.get()) {
if (regTestHost == RegTestHost.REG_TEST_SERVER) {
try {
walletAppKit.setPeerNodes(new PeerAddress(InetAddress.getByName(RegTestHost.SERVER_IP), params.getPort()));
setPeerNodes = true;
usePeerNodes = true;
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
@ -359,8 +350,9 @@ public class WalletService {
// be private by default when using proxy/tor. However, the seedpeers
// could become outdated, so it is important that the user be able to
// disable it, but should be made aware of the reduced privacy.
if (proxy != null && !setPeerNodes) {
if (proxy != null && !usePeerNodes) {
// SeedPeersSocks5Dns should replace SeedPeers once working reliably.
// SeedPeers uses hard coded stable addresses (from MainNetParams). It should be updated from time to time.
walletAppKit.setDiscovery(new SeedPeers(params));
}
@ -779,7 +771,8 @@ public class WalletService {
// in some cases getFee did not calculate correctly and we still get an InsufficientMoneyException
log.warn("We still have a missing fee " + (e.missing != null ? e.missing.toFriendlyString() : ""));
amount = (amount.subtract(e.missing));
if (e != null)
amount = amount.subtract(e.missing);
newTransaction.clearOutputs();
newTransaction.addOutput(amount, toAddress);
@ -1017,7 +1010,8 @@ public class WalletService {
if (!addressEntry.isPresent())
throw new AddressEntryException("WithdrawFromAddress is not found in our wallet.");
checkNotNull(addressEntry.get().getAddress(), "addressEntry.get().getAddress() must nto be null");
checkNotNull(addressEntry.get(), "addressEntry.get() must not be null");
checkNotNull(addressEntry.get().getAddress(), "addressEntry.get().getAddress() must not be null");
sendRequest.coinSelector = new TradeWalletCoinSelector(params, addressEntry.get().getAddress());
sendRequest.changeAddress = addressEntry.get().getAddress();
sendRequest.feePerKb = FeePolicy.getNonTradeFeePerKb();

View File

@ -209,10 +209,8 @@ public class TradeManager {
removePreparedTrade(trade);
for (Tradable tradable : closedTradableManager.getClosedTrades()) {
if (tradable instanceof Trade) {
Trade trade = (Trade) tradable;
addTradeStatistics(trade);
}
if (tradable instanceof Trade)
addTradeStatistics((Trade) tradable);
}
pendingTradesInitialized.set(true);
@ -316,7 +314,7 @@ public class TradeManager {
if (offer.getState() == Offer.State.AVAILABLE)
createTrade(amount, tradePrice, fundsNeededForTrade, offer, paymentAccountId, useSavingsWallet, model, tradeResultHandler);
},
errorMessage -> errorMessageHandler.handleErrorMessage(errorMessage));
errorMessageHandler::handleErrorMessage);
}
private void createTrade(Coin amount,

View File

@ -22,7 +22,7 @@ public final class TradeStatistics implements StoragePayload, CapabilityRequirin
@JsonExclude
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
@JsonExclude
public static final long TTL = TimeUnit.DAYS.toMillis(10);
public static final long TTL = TimeUnit.DAYS.toMillis(30);
public final String currency;
public final Offer.Direction direction;

View File

@ -20,10 +20,10 @@ import java.util.stream.Collectors;
public class TradeStatisticsManager {
private static final Logger log = LoggerFactory.getLogger(TradeStatisticsManager.class);
private final Storage<HashSet<TradeStatistics>> storage;
private Storage<String> jsonStorage;
private boolean dumpStatistics;
private ObservableSet<TradeStatistics> observableTradeStatisticsSet = FXCollections.observableSet();
private HashSet<TradeStatistics> tradeStatisticsSet = new HashSet<>();
@ -38,7 +38,7 @@ public class TradeStatisticsManager {
HashSet<TradeStatistics> persisted = storage.initAndGetPersistedWithFileName("TradeStatistics");
if (persisted != null)
persisted.stream().forEach(e -> add(e));
persisted.stream().forEach(this::add);
p2PService.addHashSetChangedListener(new HashMapChangedListener() {
@Override

View File

@ -24,12 +24,16 @@ import io.bitsquare.p2p.messaging.SupportedCapabilitiesMessage;
import javax.annotation.Nullable;
import java.util.ArrayList;
// We add here the SupportedCapabilitiesMessage interface as that message always predates a direct connection
// to the trading peer
public final class OfferAvailabilityRequest extends OfferMessage implements SupportedCapabilitiesMessage {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
private final PubKeyRing pubKeyRing;
public final long takersTradePrice;
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
public OfferAvailabilityRequest(String offerId, PubKeyRing pubKeyRing, long takersTradePrice) {
super(offerId);
@ -37,9 +41,6 @@ public final class OfferAvailabilityRequest extends OfferMessage implements Supp
this.takersTradePrice = takersTradePrice;
}
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {

View File

@ -25,6 +25,8 @@ import io.bitsquare.trade.protocol.availability.AvailabilityResult;
import javax.annotation.Nullable;
import java.util.ArrayList;
// We add here the SupportedCapabilitiesMessage interface as that message always predates a direct connection
// to the trading peer
public final class OfferAvailabilityResponse extends OfferMessage implements SupportedCapabilitiesMessage {
// That object is sent over the wire, so we need to take care of version compatibility.
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
@ -33,6 +35,8 @@ public final class OfferAvailabilityResponse extends OfferMessage implements Sup
// TODO keep for backward compatibility. Can be removed once everyone is on v0.4.9
public boolean isAvailable;
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
public OfferAvailabilityResponse(String offerId, AvailabilityResult availabilityResult) {
super(offerId);
@ -40,9 +44,6 @@ public final class OfferAvailabilityResponse extends OfferMessage implements Sup
isAvailable = availabilityResult == AvailabilityResult.AVAILABLE;
}
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {

View File

@ -39,7 +39,6 @@ public abstract class TradeMessage implements DirectMessage {
TradeMessage that = (TradeMessage) o;
return !(tradeId != null ? !tradeId.equals(that.tradeId) : that.tradeId != null);
}
@Override

View File

@ -21,12 +21,8 @@ import io.bitsquare.common.taskrunner.TaskRunner;
import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeStatistics;
import io.bitsquare.trade.protocol.trade.tasks.TradeTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PublishTradeStatistics extends TradeTask {
private static final Logger log = LoggerFactory.getLogger(PublishTradeStatistics.class);
public PublishTradeStatistics(TaskRunner taskHandler, Trade trade) {
super(taskHandler, trade);
}
@ -35,7 +31,7 @@ public class PublishTradeStatistics extends TradeTask {
protected void run() {
try {
runInterceptHook();
// Offerer publishes directly
// Offerer is responsible for publishing. Only in case the offerer uses an old verison the taker publishes.
TradeStatistics tradeStatistics = new TradeStatistics(trade.getOffer(),
trade.getTradePrice(),
trade.getTradeAmount(),

View File

@ -37,7 +37,7 @@ public class PublishTradeStatistics extends TradeTask {
protected void run() {
try {
runInterceptHook();
// taker only publishes if the offerer uses an old version
// Taker only publishes if the offerer uses an old version
processModel.getP2PService().getNetworkNode().getConfirmedConnections()
.stream()
.filter(c -> c.getPeersNodeAddressOptional().isPresent() && c.getPeersNodeAddressOptional().get().equals(trade.getTradingPeerNodeAddress()))
@ -64,10 +64,10 @@ public class PublishTradeStatistics extends TradeTask {
}
}
if (!matches) {
log.error("We publish tradeStatistics because the offerer does use an old version.");
log.warn("We publish tradeStatistics because the offerer uses an old version.");
processModel.getP2PService().addData(tradeStatistics, true);
} else {
log.error("We do not publish tradeStatistics because the offerer support the capabilities.");
log.trace("We do not publish tradeStatistics because the offerer support the capabilities.");
}
});
complete();

View File

@ -111,8 +111,7 @@ public final class Preferences implements Persistable {
private boolean autoSelectArbitrators = true;
private final Map<String, Boolean> dontShowAgainMap;
private boolean tacAccepted;
//TODO we set it to false for now as it is not ready yet
private boolean useTorForBitcoinJ = false;
private boolean useTorForBitcoinJ = true;
private boolean showOwnOffersInOfferBook = true;
private Locale preferredLocale;
private TradeCurrency preferredTradeCurrency;
@ -262,8 +261,8 @@ public final class Preferences implements Persistable {
storage.queueUpForSave();
});
fiatCurrenciesAsObservable.addListener((ListChangeListener<FiatCurrency>) this::updateTradeCurrencies);
cryptoCurrenciesAsObservable.addListener((ListChangeListener<CryptoCurrency>) this::updateTradeCurrencies);
fiatCurrenciesAsObservable.addListener(this::updateTradeCurrencies);
cryptoCurrenciesAsObservable.addListener(this::updateTradeCurrencies);
tradeCurrenciesAsObservable.addAll(fiatCurrencies);
tradeCurrenciesAsObservable.addAll(cryptoCurrencies);
}
@ -661,5 +660,4 @@ public final class Preferences implements Persistable {
this.blockChainExplorerMainNet = blockChainExplorerMainNet;
storage.queueUpForSave(2000);
}
}

View File

@ -88,16 +88,6 @@
-fx-effect: dropshadow(two-pass-box, rgba(0, 0, 0, 0.4), 10, 0.0, 2, 4);
}
/*.default-color0.chart-series-line {
-fx-stroke: blue;
}
.default-color0.chart-line-symbol {
-fx-background-color: red, green;
}*/
.chart-alternative-row-fill {
-fx-fill: transparent;
-fx-stroke: transparent;
@ -107,14 +97,3 @@
.chart-plot-background {
-fx-background-color: transparent;
}
/*
.chart-legend {
-fx-background-color: transparent;
-fx-padding: 20px;
}
.chart-legend-item-symbol {
-fx-background-radius: 0;
}
*/

View File

@ -42,7 +42,6 @@ public class VolumeChart extends XYChart<Number, Number> {
super(xAxis, yAxis);
}
public final void setToolTipStringConverter(StringConverter<Number> toolTipStringConverter) {
this.toolTipStringConverter = toolTipStringConverter;
}
@ -109,9 +108,7 @@ public class VolumeChart extends XYChart<Number, Number> {
if (shouldAnimate()) {
FadeTransition ft = new FadeTransition(Duration.millis(500), node);
ft.setToValue(0);
ft.setOnFinished((ActionEvent actionEvent) -> {
getPlotChildren().remove(node);
});
ft.setOnFinished((ActionEvent actionEvent) -> getPlotChildren().remove(node));
ft.play();
} else {
getPlotChildren().remove(node);
@ -142,9 +139,7 @@ public class VolumeChart extends XYChart<Number, Number> {
if (shouldAnimate()) {
FadeTransition ft = new FadeTransition(Duration.millis(500), volumeBar);
ft.setToValue(0);
ft.setOnFinished((ActionEvent actionEvent) -> {
getPlotChildren().remove(volumeBar);
});
ft.setOnFinished((ActionEvent actionEvent) -> getPlotChildren().remove(volumeBar));
ft.play();
} else {
getPlotChildren().remove(volumeBar);

View File

@ -128,8 +128,6 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
@Override
public void activate() {
// TODO we deactive atm as its not ready now
useTorCheckBox.setDisable(true);
useTorCheckBox.setSelected(preferences.getUseTorForBitcoinJ());
useTorCheckBox.setOnAction(event -> {
boolean selected = useTorCheckBox.isSelected();

View File

@ -159,7 +159,6 @@ public class BSFormatter {
* @param input
* @return
*/
public Coin parseToCoinWith4Decimals(String input) {
try {
return Coin.valueOf(new BigDecimal(parseToCoin(cleanInput(input)).value).setScale(-scale - 1,
@ -301,7 +300,7 @@ public class BSFormatter {
}
public String arbitratorAddressesToString(List<NodeAddress> nodeAddresses) {
return nodeAddresses.stream().map(e -> e.getFullAddress()).collect(Collectors.joining(", "));
return nodeAddresses.stream().map(NodeAddress::getFullAddress).collect(Collectors.joining(", "));
}
public String languageCodesToString(List<String> languageLocales) {
@ -452,7 +451,7 @@ public class BSFormatter {
duration = StringUtils.replaceOnce(duration, " 1 minutes", " 1 minute");
duration = StringUtils.replaceOnce(duration, " 1 hours", " 1 hour");
duration = StringUtils.replaceOnce(duration, " 1 days", " 1 day");
if (duration.startsWith(", "))
if (duration.startsWith(" ,"))
duration = duration.replace(" ,", "");
else if (duration.startsWith(", "))
duration = duration.replace(", ", "");

View File

@ -96,8 +96,7 @@ public class TorNetworkNode extends NetworkNode {
@Override
protected Socket createSocket(NodeAddress peerNodeAddress) throws IOException {
// FIXME: disabling temporarily.
// checkArgument(peerNodeAddress.hostName.endsWith(".onion"), "PeerAddress is not an onion address");
checkArgument(peerNodeAddress.hostName.endsWith(".onion"), "PeerAddress is not an onion address");
return torNetworkNode.connectToHiddenService(peerNodeAddress.hostName, peerNodeAddress.port);
}

View File

@ -15,15 +15,14 @@ public final class GetDataResponse implements SupportedCapabilitiesMessage {
public final HashSet<ProtectedStorageEntry> dataSet;
public final int requestNonce;
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
public GetDataResponse(HashSet<ProtectedStorageEntry> dataSet, int requestNonce) {
this.dataSet = dataSet;
this.requestNonce = requestNonce;
}
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
@ -41,6 +40,7 @@ public final class GetDataResponse implements SupportedCapabilitiesMessage {
"messageVersion=" + messageVersion +
", dataSet.size()=" + dataSet.size() +
", requestNonce=" + requestNonce +
", supportedCapabilities=" + supportedCapabilities +
'}';
}
}

View File

@ -13,14 +13,13 @@ public final class PreliminaryGetDataRequest implements AnonymousMessage, GetDat
private final int messageVersion = Version.getP2PMessageVersion();
private final int nonce;
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
public PreliminaryGetDataRequest(int nonce) {
this.nonce = nonce;
}
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
@ -42,6 +41,7 @@ public final class PreliminaryGetDataRequest implements AnonymousMessage, GetDat
return "PreliminaryGetDataRequest{" +
"messageVersion=" + messageVersion +
", nonce=" + nonce +
", supportedCapabilities=" + supportedCapabilities +
'}';
}
}

View File

@ -19,6 +19,8 @@ public final class GetPeersRequest extends PeerExchangeMessage implements Sender
private final NodeAddress senderNodeAddress;
public final int nonce;
public final HashSet<Peer> reportedPeers;
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
public GetPeersRequest(NodeAddress senderNodeAddress, int nonce, HashSet<Peer> reportedPeers) {
checkNotNull(senderNodeAddress, "senderNodeAddress must not be null at GetPeersRequest");
@ -27,9 +29,6 @@ public final class GetPeersRequest extends PeerExchangeMessage implements Sender
this.reportedPeers = reportedPeers;
}
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
public ArrayList<Integer> getSupportedCapabilities() {
@ -47,6 +46,7 @@ public final class GetPeersRequest extends PeerExchangeMessage implements Sender
"senderNodeAddress=" + senderNodeAddress +
", nonce=" + nonce +
", reportedPeers.size()=" + reportedPeers.size() +
", supportedCapabilities=" + supportedCapabilities +
"} " + super.toString();
}
}

View File

@ -15,13 +15,13 @@ public final class GetPeersResponse extends PeerExchangeMessage implements Suppo
public final int requestNonce;
public final HashSet<Peer> reportedPeers;
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
public GetPeersResponse(int requestNonce, HashSet<Peer> reportedPeers) {
this.requestNonce = requestNonce;
this.reportedPeers = reportedPeers;
}
@Nullable
private ArrayList<Integer> supportedCapabilities = Version.getCapabilities();
@Override
@Nullable
@ -34,6 +34,7 @@ public final class GetPeersResponse extends PeerExchangeMessage implements Suppo
return "GetPeersResponse{" +
"requestNonce=" + requestNonce +
", reportedPeers.size()=" + reportedPeers.size() +
", supportedCapabilities=" + supportedCapabilities +
"} " + super.toString();
}
}

View File

@ -119,7 +119,7 @@ public class SeedNode {
}
});
// Wee want to persist trade statistics so we need to instantiate the tradeStatisticsManager
// We want to persist trade statistics so we need to instantiate the tradeStatisticsManager
tradeStatisticsManager = injector.getInstance(TradeStatisticsManager.class);
}