diff --git a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java index 4747e3feb4..c1a55e2bb0 100644 --- a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java +++ b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java @@ -20,7 +20,6 @@ package bisq.core.account.witness; import bisq.core.account.sign.SignedWitness; import bisq.core.account.sign.SignedWitnessService; import bisq.core.filter.FilterManager; -import bisq.core.filter.PaymentAccountFilter; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; import bisq.core.offer.Offer; @@ -718,10 +717,8 @@ public class AccountAgeWitnessService { filterManager.isCurrencyBanned(dispute.getContract().getOfferPayload().getCurrencyCode()) || filterManager.isPaymentMethodBanned( PaymentMethod.getPaymentMethodById(dispute.getContract().getPaymentMethodId())) || - filterManager.arePeersPaymentAccountDataBanned(dispute.getContract().getBuyerPaymentAccountPayload(), - new PaymentAccountFilter[1]) || - filterManager.arePeersPaymentAccountDataBanned(dispute.getContract().getSellerPaymentAccountPayload(), - new PaymentAccountFilter[1]) || + filterManager.arePeersPaymentAccountDataBanned(dispute.getContract().getBuyerPaymentAccountPayload()) || + filterManager.arePeersPaymentAccountDataBanned(dispute.getContract().getSellerPaymentAccountPayload()) || filterManager.isWitnessSignerPubKeyBanned( Utils.HEX.encode(dispute.getContract().getBuyerPubKeyRing().getSignaturePubKeyBytes())) || filterManager.isWitnessSignerPubKeyBanned( diff --git a/core/src/main/java/bisq/core/filter/FilterManager.java b/core/src/main/java/bisq/core/filter/FilterManager.java index 0302fc24f7..cd5bb84cf0 100644 --- a/core/src/main/java/bisq/core/filter/FilterManager.java +++ b/core/src/main/java/bisq/core/filter/FilterManager.java @@ -371,24 +371,19 @@ public class FilterManager { return requireUpdateToNewVersion; } - public boolean arePeersPaymentAccountDataBanned(PaymentAccountPayload paymentAccountPayload, - PaymentAccountFilter[] appliedPaymentAccountFilter) { + public boolean arePeersPaymentAccountDataBanned(PaymentAccountPayload paymentAccountPayload) { return getFilter() != null && getFilter().getBannedPaymentAccounts().stream() + .filter(paymentAccountFilter -> paymentAccountFilter.getPaymentMethodId().equals( + paymentAccountPayload.getPaymentMethodId())) .anyMatch(paymentAccountFilter -> { - final boolean samePaymentMethodId = paymentAccountFilter.getPaymentMethodId().equals( - paymentAccountPayload.getPaymentMethodId()); - if (samePaymentMethodId) { - try { - Method method = paymentAccountPayload.getClass().getMethod(paymentAccountFilter.getGetMethodName()); - String result = (String) method.invoke(paymentAccountPayload); - appliedPaymentAccountFilter[0] = paymentAccountFilter; - return result.toLowerCase().equals(paymentAccountFilter.getValue().toLowerCase()); - } catch (Throwable e) { - log.error(e.getMessage()); - return false; - } - } else { + try { + Method method = paymentAccountPayload.getClass().getMethod(paymentAccountFilter.getGetMethodName()); + // We invoke getter methods (no args), e.g. getHolderName + String valueFromInvoke = (String) method.invoke(paymentAccountPayload); + return valueFromInvoke.equalsIgnoreCase(paymentAccountFilter.getValue()); + } catch (Throwable e) { + log.error(e.getMessage()); return false; } }); diff --git a/core/src/main/java/bisq/core/support/dispute/agent/MultipleHolderNameDetection.java b/core/src/main/java/bisq/core/support/dispute/agent/MultipleHolderNameDetection.java index 48025ae266..80a64808c6 100644 --- a/core/src/main/java/bisq/core/support/dispute/agent/MultipleHolderNameDetection.java +++ b/core/src/main/java/bisq/core/support/dispute/agent/MultipleHolderNameDetection.java @@ -200,18 +200,19 @@ public class MultipleHolderNameDetection { private Map> getAllDisputesByTraderMap() { Map> allDisputesByTraderMap = new HashMap<>(); - disputeManager.getDisputesAsObservableList() - .forEach(dispute -> { + disputeManager.getDisputesAsObservableList().stream() + .filter(dispute -> { Contract contract = dispute.getContract(); PaymentAccountPayload paymentAccountPayload = isBuyer(dispute) ? contract.getBuyerPaymentAccountPayload() : contract.getSellerPaymentAccountPayload(); - if (paymentAccountPayload instanceof PayloadWithHolderName) { - String traderPubKeyHash = getSigPubKeyHashAsHex(dispute); - allDisputesByTraderMap.putIfAbsent(traderPubKeyHash, new ArrayList<>()); - List disputes = allDisputesByTraderMap.get(traderPubKeyHash); - disputes.add(dispute); - } + return paymentAccountPayload instanceof PayloadWithHolderName; + }) + .forEach(dispute -> { + String traderPubKeyHash = getSigPubKeyHashAsHex(dispute); + allDisputesByTraderMap.putIfAbsent(traderPubKeyHash, new ArrayList<>()); + List disputes = allDisputesByTraderMap.get(traderPubKeyHash); + disputes.add(dispute); }); return allDisputesByTraderMap; } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/ApplyFilter.java b/core/src/main/java/bisq/core/trade/protocol/tasks/ApplyFilter.java index 55e40c120f..cbcb0ae8c2 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/ApplyFilter.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/ApplyFilter.java @@ -18,7 +18,6 @@ package bisq.core.trade.protocol.tasks; import bisq.core.filter.FilterManager; -import bisq.core.filter.PaymentAccountFilter; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.trade.Trade; @@ -42,9 +41,8 @@ public class ApplyFilter extends TradeTask { try { runInterceptHook(); - final NodeAddress nodeAddress = processModel.getTempTradingPeerNodeAddress(); + NodeAddress nodeAddress = processModel.getTempTradingPeerNodeAddress(); PaymentAccountPayload paymentAccountPayload = checkNotNull(processModel.getTradingPeer().getPaymentAccountPayload()); - final PaymentAccountFilter[] appliedPaymentAccountFilter = new PaymentAccountFilter[1]; FilterManager filterManager = processModel.getFilterManager(); if (nodeAddress != null && filterManager.isNodeAddressBanned(nodeAddress)) { @@ -56,13 +54,12 @@ public class ApplyFilter extends TradeTask { } else if (trade.getOffer() != null && filterManager.isCurrencyBanned(trade.getOffer().getCurrencyCode())) { failed("Currency is banned.\n" + "Currency code=" + trade.getOffer().getCurrencyCode()); - } else if (filterManager.isPaymentMethodBanned(trade.getOffer().getPaymentMethod())) { + } else if (filterManager.isPaymentMethodBanned(checkNotNull(trade.getOffer()).getPaymentMethod())) { failed("Payment method is banned.\n" + "Payment method=" + trade.getOffer().getPaymentMethod().getId()); - } else if (filterManager.arePeersPaymentAccountDataBanned(paymentAccountPayload, appliedPaymentAccountFilter)) { + } else if (filterManager.arePeersPaymentAccountDataBanned(paymentAccountPayload)) { failed("Other trader is banned by their trading account data.\n" + - "paymentAccountPayload=" + paymentAccountPayload.getPaymentDetails() + "\n" + - "banFilter=" + appliedPaymentAccountFilter[0].toString()); + "paymentAccountPayload=" + paymentAccountPayload.getPaymentDetails()); } else if (filterManager.requireUpdateToNewVersionForTrading()) { failed("Your version of Bisq is not compatible for trading anymore. " + "Please update to the latest Bisq version at https://bisq.network/downloads."); diff --git a/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java b/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java index b37a47d057..2b2d11e562 100644 --- a/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java +++ b/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java @@ -218,7 +218,7 @@ public class AccountAgeWitnessServiceTest { when(filterManager.isNodeAddressBanned(any())).thenReturn(false); when(filterManager.isCurrencyBanned(any())).thenReturn(false); when(filterManager.isPaymentMethodBanned(any())).thenReturn(false); - when(filterManager.arePeersPaymentAccountDataBanned(any(), any())).thenReturn(false); + when(filterManager.arePeersPaymentAccountDataBanned(any())).thenReturn(false); when(filterManager.isWitnessSignerPubKeyBanned(any())).thenReturn(false); when(chargeBackRisk.hasChargebackRisk(any(), any())).thenReturn(true); diff --git a/docs/build.md b/docs/build.md index ca3ab06457..ea054c7936 100644 --- a/docs/build.md +++ b/docs/build.md @@ -7,7 +7,7 @@ Bisq uses Git LFS to track certain large binary files. Follow the instructions a $ git lfs version git-lfs/2.10.0 (GitHub; darwin amd64; go 1.13.6) - + ## Clone @@ -17,8 +17,9 @@ Bisq uses Git LFS to track certain large binary files. Follow the instructions a ## Build -You do _not_ need to install Gradle to complete the following command. The `gradlew` shell script will install it for you if necessary. +You do _not_ need to install Gradle to complete the following command. The `gradlew` shell script will install it for you if necessary. Pull the lfs data first. + git lfs pull ./gradlew build If on Windows run `gradlew.bat build` instead. diff --git a/p2p/src/main/java/bisq/network/p2p/network/Connection.java b/p2p/src/main/java/bisq/network/p2p/network/Connection.java index 050978d969..86aa7d4fc7 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -48,6 +48,8 @@ import bisq.common.proto.network.NetworkEnvelope; import bisq.common.proto.network.NetworkProtoResolver; import bisq.common.util.Utilities; +import com.google.protobuf.InvalidProtocolBufferException; + import javax.inject.Inject; import com.google.common.util.concurrent.MoreExecutors; @@ -283,12 +285,20 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { bundleSender.schedule(() -> { if (!stopped) { synchronized (lock) { - BundleOfEnvelopes current = queueOfBundles.poll(); - if (current != null && !stopped) { - if (current.getEnvelopes().size() == 1) { - protoOutputStream.writeEnvelope(current.getEnvelopes().get(0)); - } else { - protoOutputStream.writeEnvelope(current); + BundleOfEnvelopes bundle = queueOfBundles.poll(); + if (bundle != null && !stopped) { + NetworkEnvelope envelope = bundle.getEnvelopes().size() == 1 ? + bundle.getEnvelopes().get(0) : + bundle; + try { + protoOutputStream.writeEnvelope(envelope); + } catch (Throwable t) { + log.error("Sending envelope of class {} to address {} " + + "failed due {}", + envelope.getClass().getSimpleName(), + this.getPeersNodeAddressOptional(), + t.toString()); + log.error("envelope: {}", envelope); } } } @@ -876,7 +886,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { log.error(e.getMessage()); e.printStackTrace(); reportInvalidRequest(RuleViolation.INVALID_CLASS); - } catch (ProtobufferException | NoClassDefFoundError e) { + } catch (ProtobufferException | NoClassDefFoundError | InvalidProtocolBufferException e) { log.error(e.getMessage()); e.printStackTrace(); reportInvalidRequest(RuleViolation.INVALID_DATA_TYPE);