Merge pull request #4494 from chimp1984/fix-xmr-tool-bug-with-single-httpClient

Bugfix: Create new HttpClient for each request.
This commit is contained in:
Christoph Atteneder 2020-09-07 09:59:18 +02:00 committed by GitHub
commit ee8e931e34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 228 deletions

View file

@ -26,8 +26,6 @@ import bisq.core.trade.failed.FailedTradesManager;
import bisq.core.trade.statistics.ReferralIdService; import bisq.core.trade.statistics.ReferralIdService;
import bisq.core.trade.statistics.TradeStatistics2StorageService; import bisq.core.trade.statistics.TradeStatistics2StorageService;
import bisq.core.trade.statistics.TradeStatisticsManager; import bisq.core.trade.statistics.TradeStatisticsManager;
import bisq.core.trade.txproof.AssetTxProofHttpClient;
import bisq.core.trade.txproof.xmr.XmrTxProofHttpClient;
import bisq.common.app.AppModule; import bisq.common.app.AppModule;
import bisq.common.config.Config; import bisq.common.config.Config;
@ -58,8 +56,6 @@ public class TradeModule extends AppModule {
bind(SignedWitnessStorageService.class).in(Singleton.class); bind(SignedWitnessStorageService.class).in(Singleton.class);
bind(ReferralIdService.class).in(Singleton.class); bind(ReferralIdService.class).in(Singleton.class);
bind(AssetTxProofHttpClient.class).to(XmrTxProofHttpClient.class);
bindConstant().annotatedWith(named(DUMP_STATISTICS)).to(config.dumpStatistics); bindConstant().annotatedWith(named(DUMP_STATISTICS)).to(config.dumpStatistics);
bindConstant().annotatedWith(named(DUMP_DELAYED_PAYOUT_TXS)).to(config.dumpDelayedPayoutTxs); bindConstant().annotatedWith(named(DUMP_DELAYED_PAYOUT_TXS)).to(config.dumpDelayedPayoutTxs);
bindConstant().annotatedWith(named(ALLOW_FAULTY_DELAYED_TXS)).to(config.allowFaultyDelayedTxs); bindConstant().annotatedWith(named(ALLOW_FAULTY_DELAYED_TXS)).to(config.allowFaultyDelayedTxs);

View file

@ -1,206 +0,0 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.core.trade.txproof.xmr;
import bisq.core.trade.txproof.AssetTxProofHttpClient;
import bisq.network.Socks5ProxyProvider;
import bisq.network.http.HttpClientImpl;
import bisq.common.app.DevEnv;
import javax.inject.Inject;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
import static bisq.core.trade.txproof.xmr.XmrTxProofParser.MAX_DATE_TOLERANCE;
/**
* This should help to test error scenarios in dev testing the app. This is additional to unit test which test the
* correct data but do not test the context of the results and how it behaves in the UI.
*
* You have to change the binding in TradeModule to
* bind(AssetTxProofHttpClient.class).to(DevTestXmrTxProofHttpClient.class); to use that class.
*
* This class can be removed once done testing, but as multiple devs are testing its useful to share it for now.
*/
@Slf4j
public class DevTestXmrTxProofHttpClient extends HttpClientImpl implements AssetTxProofHttpClient {
enum ApiInvalidDetails {
EMPTY_JSON,
MISSING_DATA,
MISSING_STATUS,
UNHANDLED_STATUS,
MISSING_ADDRESS,
MISSING_TX_ID,
MISSING_VIEW_KEY,
MISSING_TS,
MISSING_CONF,
EXCEPTION
}
@Inject
public DevTestXmrTxProofHttpClient(@Nullable Socks5ProxyProvider socks5ProxyProvider) {
super(socks5ProxyProvider);
}
private static int counter;
@Override
public String requestWithGET(String param,
@Nullable String headerKey,
@Nullable String headerValue) {
XmrTxProofRequest.Result result = XmrTxProofRequest.Result.PENDING;
XmrTxProofRequest.Detail detail = XmrTxProofRequest.Detail.TX_NOT_FOUND;
ApiInvalidDetails apiInvalidDetails = ApiInvalidDetails.EXCEPTION;
int delay = counter == 0 ? 2000 : 100;
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (counter >= 2) {
detail = XmrTxProofRequest.Detail.PENDING_CONFIRMATIONS.numConfirmations(counter - 2);
}
counter++;
switch (result) {
case PENDING:
switch (detail) {
case TX_NOT_FOUND:
return validJson().replace("success",
"fail");
case PENDING_CONFIRMATIONS:
return validJson().replace("201287",
String.valueOf(detail.getNumConfirmations()));
default:
return null;
}
case SUCCESS:
return validJson();
case FAILED:
switch (detail) {
case TX_HASH_INVALID:
return validJson().replace("5e665addf6d7c6300670e8a89564ed12b5c1a21c336408e2835668f9a6a0d802",
"-");
case TX_KEY_INVALID:
return validJson().replace("f3ce66c9d395e5e460c8802b2c3c1fff04e508434f9738ee35558aac4678c906",
"-");
case ADDRESS_INVALID:
return validJson().replace("590f7263428051068bb45cdfcf93407c15b6e291d20c92d0251fcfbf53cc745cdf53319f7d6d7a8e21ea39041aabf31d220a32a875e3ca2087a777f1201c0571",
"-");
case NO_MATCH_FOUND:
return validJson().replace("match\": true",
"match\": false");
case AMOUNT_NOT_MATCHING:
return validJson().replace("8902597360000",
"18902597360000");
case TRADE_DATE_NOT_MATCHING:
DevEnv.setDevMode(false);
long date = (new Date(1574922644 * 1000L).getTime() - (MAX_DATE_TOLERANCE * 1000L + 1)) / 1000;
return validJson().replace("1574922644",
String.valueOf(date));
default:
return null;
}
case ERROR:
switch (detail) {
case CONNECTION_FAILURE:
// Not part of parser level testing
return null;
case API_INVALID:
switch (apiInvalidDetails) {
case EMPTY_JSON:
return null;
case MISSING_DATA:
return validJson().replace("data",
"missing");
case MISSING_STATUS:
return validJson().replace("status",
"missing");
case UNHANDLED_STATUS:
return validJson().replace("success",
"missing");
case MISSING_ADDRESS:
return validJson().replace("address",
"missing");
case MISSING_TX_ID:
return validJson().replace("tx_hash",
"missing");
case MISSING_VIEW_KEY:
return validJson().replace("viewkey",
"missing");
case MISSING_TS:
return validJson().replace("tx_timestamp",
"missing");
case MISSING_CONF:
return validJson().replace("tx_confirmations",
"missing");
case EXCEPTION:
return validJson().replace("} ",
"");
default:
return null;
}
case NO_RESULTS_TIMEOUT:
// Not part of parser level testing
return null;
default:
return null;
}
default:
return null;
}
}
private String validJson() {
return "{\n" +
" \"data\": {\n" +
" \"address\": \"590f7263428051068bb45cdfcf93407c15b6e291d20c92d0251fcfbf53cc745cdf53319f7d6d7a8e21ea39041aabf31d220a32a875e3ca2087a777f1201c0571\",\n" +
" \"outputs\": [\n" +
" {\n" +
" \"amount\": 8902597360000,\n" +
" \"match\": true,\n" +
" \"output_idx\": 0,\n" +
" \"output_pubkey\": \"2b6d2296f2591c198cd1aa47de9a5d74270963412ed30bbcc63b8eff29f0d43e\"\n" +
" },\n" +
" {\n" +
" \"amount\": 0,\n" +
" \"match\": false,\n" +
" \"output_idx\": 1,\n" +
" \"output_pubkey\": \"f53271624847507d80b746e91e689e88bc41678d55246275f5ad3c0f7e8a9ced\"\n" +
" }\n" +
" ],\n" +
" \"tx_confirmations\": 201287,\n" +
" \"tx_hash\": \"5e665addf6d7c6300670e8a89564ed12b5c1a21c336408e2835668f9a6a0d802\",\n" +
" \"tx_prove\": true,\n" +
" \"tx_timestamp\": 1574922644,\n" +
" \"viewkey\": \"f3ce66c9d395e5e460c8802b2c3c1fff04e508434f9738ee35558aac4678c906\"\n" +
" },\n" +
" \"status\": \"success\"\n" +
"} ";
}
}

View file

@ -22,14 +22,11 @@ import bisq.core.trade.txproof.AssetTxProofHttpClient;
import bisq.network.Socks5ProxyProvider; import bisq.network.Socks5ProxyProvider;
import bisq.network.http.HttpClientImpl; import bisq.network.http.HttpClientImpl;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class XmrTxProofHttpClient extends HttpClientImpl implements AssetTxProofHttpClient { class XmrTxProofHttpClient extends HttpClientImpl implements AssetTxProofHttpClient {
@Inject XmrTxProofHttpClient(Socks5ProxyProvider socks5ProxyProvider) {
public XmrTxProofHttpClient(Socks5ProxyProvider socks5ProxyProvider) {
super(socks5ProxyProvider); super(socks5ProxyProvider);
} }
} }

View file

@ -21,6 +21,8 @@ import bisq.core.trade.txproof.AssetTxProofHttpClient;
import bisq.core.trade.txproof.AssetTxProofParser; import bisq.core.trade.txproof.AssetTxProofParser;
import bisq.core.trade.txproof.AssetTxProofRequest; import bisq.core.trade.txproof.AssetTxProofRequest;
import bisq.network.Socks5ProxyProvider;
import bisq.common.UserThread; import bisq.common.UserThread;
import bisq.common.app.Version; import bisq.common.app.Version;
import bisq.common.handlers.FaultHandler; import bisq.common.handlers.FaultHandler;
@ -140,9 +142,9 @@ class XmrTxProofRequest implements AssetTxProofRequest<XmrTxProofRequest.Result>
private final ListeningExecutorService executorService = Utilities.getListeningExecutorService( private final ListeningExecutorService executorService = Utilities.getListeningExecutorService(
"XmrTransferProofRequester", 3, 5, 10 * 60); "XmrTransferProofRequester", 3, 5, 10 * 60);
private final AssetTxProofHttpClient httpClient;
private final AssetTxProofParser<XmrTxProofRequest.Result, XmrTxProofModel> parser; private final AssetTxProofParser<XmrTxProofRequest.Result, XmrTxProofModel> parser;
private final XmrTxProofModel model; private final XmrTxProofModel model;
private final AssetTxProofHttpClient httpClient;
private final long firstRequest; private final long firstRequest;
private boolean terminated; private boolean terminated;
@ -155,12 +157,12 @@ class XmrTxProofRequest implements AssetTxProofRequest<XmrTxProofRequest.Result>
// Constructor // Constructor
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
XmrTxProofRequest(AssetTxProofHttpClient httpClient, XmrTxProofRequest(Socks5ProxyProvider socks5ProxyProvider,
XmrTxProofModel model) { XmrTxProofModel model) {
this.httpClient = httpClient;
this.parser = new XmrTxProofParser(); this.parser = new XmrTxProofParser();
this.model = model; this.model = model;
httpClient = new XmrTxProofHttpClient(socks5ProxyProvider);
httpClient.setBaseUrl("http://" + model.getServiceAddress()); httpClient.setBaseUrl("http://" + model.getServiceAddress());
if (model.getServiceAddress().matches("^192.*|^localhost.*")) { if (model.getServiceAddress().matches("^192.*|^localhost.*")) {
log.info("Ignoring Socks5 proxy for local net address: {}", model.getServiceAddress()); log.info("Ignoring Socks5 proxy for local net address: {}", model.getServiceAddress());

View file

@ -22,11 +22,12 @@ import bisq.core.support.dispute.Dispute;
import bisq.core.support.dispute.mediation.MediationManager; import bisq.core.support.dispute.mediation.MediationManager;
import bisq.core.support.dispute.refund.RefundManager; import bisq.core.support.dispute.refund.RefundManager;
import bisq.core.trade.Trade; import bisq.core.trade.Trade;
import bisq.core.trade.txproof.AssetTxProofHttpClient;
import bisq.core.trade.txproof.AssetTxProofRequestsPerTrade; import bisq.core.trade.txproof.AssetTxProofRequestsPerTrade;
import bisq.core.trade.txproof.AssetTxProofResult; import bisq.core.trade.txproof.AssetTxProofResult;
import bisq.core.user.AutoConfirmSettings; import bisq.core.user.AutoConfirmSettings;
import bisq.network.Socks5ProxyProvider;
import bisq.common.handlers.FaultHandler; import bisq.common.handlers.FaultHandler;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
@ -54,7 +55,7 @@ class XmrTxProofRequestsPerTrade implements AssetTxProofRequestsPerTrade {
private final AutoConfirmSettings autoConfirmSettings; private final AutoConfirmSettings autoConfirmSettings;
private final MediationManager mediationManager; private final MediationManager mediationManager;
private final RefundManager refundManager; private final RefundManager refundManager;
private final AssetTxProofHttpClient httpClient; private final Socks5ProxyProvider socks5ProxyProvider;
private int numRequiredSuccessResults; private int numRequiredSuccessResults;
private final Set<XmrTxProofRequest> requests = new HashSet<>(); private final Set<XmrTxProofRequest> requests = new HashSet<>();
@ -69,12 +70,12 @@ class XmrTxProofRequestsPerTrade implements AssetTxProofRequestsPerTrade {
// Constructor // Constructor
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
XmrTxProofRequestsPerTrade(AssetTxProofHttpClient httpClient, XmrTxProofRequestsPerTrade(Socks5ProxyProvider socks5ProxyProvider,
Trade trade, Trade trade,
AutoConfirmSettings autoConfirmSettings, AutoConfirmSettings autoConfirmSettings,
MediationManager mediationManager, MediationManager mediationManager,
RefundManager refundManager) { RefundManager refundManager) {
this.httpClient = httpClient; this.socks5ProxyProvider = socks5ProxyProvider;
this.trade = trade; this.trade = trade;
this.autoConfirmSettings = autoConfirmSettings; this.autoConfirmSettings = autoConfirmSettings;
this.mediationManager = mediationManager; this.mediationManager = mediationManager;
@ -140,7 +141,7 @@ class XmrTxProofRequestsPerTrade implements AssetTxProofRequestsPerTrade {
for (String serviceAddress : serviceAddresses) { for (String serviceAddress : serviceAddresses) {
XmrTxProofModel model = new XmrTxProofModel(trade, serviceAddress, autoConfirmSettings); XmrTxProofModel model = new XmrTxProofModel(trade, serviceAddress, autoConfirmSettings);
XmrTxProofRequest request = new XmrTxProofRequest(httpClient, model); XmrTxProofRequest request = new XmrTxProofRequest(socks5ProxyProvider, model);
log.info("{} created", request); log.info("{} created", request);
requests.add(request); requests.add(request);

View file

@ -27,12 +27,12 @@ import bisq.core.trade.Trade;
import bisq.core.trade.TradeManager; import bisq.core.trade.TradeManager;
import bisq.core.trade.closed.ClosedTradableManager; import bisq.core.trade.closed.ClosedTradableManager;
import bisq.core.trade.failed.FailedTradesManager; import bisq.core.trade.failed.FailedTradesManager;
import bisq.core.trade.txproof.AssetTxProofHttpClient;
import bisq.core.trade.txproof.AssetTxProofResult; import bisq.core.trade.txproof.AssetTxProofResult;
import bisq.core.trade.txproof.AssetTxProofService; import bisq.core.trade.txproof.AssetTxProofService;
import bisq.core.user.AutoConfirmSettings; import bisq.core.user.AutoConfirmSettings;
import bisq.core.user.Preferences; import bisq.core.user.Preferences;
import bisq.network.Socks5ProxyProvider;
import bisq.network.p2p.BootstrapListener; import bisq.network.p2p.BootstrapListener;
import bisq.network.p2p.P2PService; import bisq.network.p2p.P2PService;
@ -76,7 +76,7 @@ public class XmrTxProofService implements AssetTxProofService {
private final RefundManager refundManager; private final RefundManager refundManager;
private final P2PService p2PService; private final P2PService p2PService;
private final WalletsSetup walletsSetup; private final WalletsSetup walletsSetup;
private final AssetTxProofHttpClient httpClient; private final Socks5ProxyProvider socks5ProxyProvider;
private final Map<String, XmrTxProofRequestsPerTrade> servicesByTradeId = new HashMap<>(); private final Map<String, XmrTxProofRequestsPerTrade> servicesByTradeId = new HashMap<>();
private AutoConfirmSettings autoConfirmSettings; private AutoConfirmSettings autoConfirmSettings;
private Map<String, ChangeListener<Trade.State>> tradeStateListenerMap = new HashMap<>(); private Map<String, ChangeListener<Trade.State>> tradeStateListenerMap = new HashMap<>();
@ -101,7 +101,7 @@ public class XmrTxProofService implements AssetTxProofService {
RefundManager refundManager, RefundManager refundManager,
P2PService p2PService, P2PService p2PService,
WalletsSetup walletsSetup, WalletsSetup walletsSetup,
AssetTxProofHttpClient httpClient) { Socks5ProxyProvider socks5ProxyProvider) {
this.filterManager = filterManager; this.filterManager = filterManager;
this.preferences = preferences; this.preferences = preferences;
this.tradeManager = tradeManager; this.tradeManager = tradeManager;
@ -111,7 +111,7 @@ public class XmrTxProofService implements AssetTxProofService {
this.refundManager = refundManager; this.refundManager = refundManager;
this.p2PService = p2PService; this.p2PService = p2PService;
this.walletsSetup = walletsSetup; this.walletsSetup = walletsSetup;
this.httpClient = httpClient; this.socks5ProxyProvider = socks5ProxyProvider;
} }
@ -247,7 +247,7 @@ public class XmrTxProofService implements AssetTxProofService {
} }
private void startRequests(SellerTrade trade) { private void startRequests(SellerTrade trade) {
XmrTxProofRequestsPerTrade service = new XmrTxProofRequestsPerTrade(httpClient, XmrTxProofRequestsPerTrade service = new XmrTxProofRequestsPerTrade(socks5ProxyProvider,
trade, trade,
autoConfirmSettings, autoConfirmSettings,
mediationManager, mediationManager,