Skip to content

Commit

Permalink
Merge pull request #4489 from chimp1984/various-small-improvements
Browse files Browse the repository at this point in the history
Various small improvements
  • Loading branch information
ripcurlx authored Sep 7, 2020
2 parents ee8e931 + a4b43f6 commit e7d24ef
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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;
Expand Down Expand Up @@ -718,10 +717,8 @@ private boolean isNotFiltered(Dispute dispute) {
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(
Expand Down
25 changes: 10 additions & 15 deletions core/src/main/java/bisq/core/filter/FilterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,24 +371,19 @@ public boolean requireUpdateToNewVersionForDAO() {
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;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,19 @@ public void removeListener(Listener listener) {

private Map<String, List<Dispute>> getAllDisputesByTraderMap() {
Map<String, List<Dispute>> 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<Dispute> disputes = allDisputesByTraderMap.get(traderPubKeyHash);
disputes.add(dispute);
}
return paymentAccountPayload instanceof PayloadWithHolderName;
})
.forEach(dispute -> {
String traderPubKeyHash = getSigPubKeyHashAsHex(dispute);
allDisputesByTraderMap.putIfAbsent(traderPubKeyHash, new ArrayList<>());
List<Dispute> disputes = allDisputesByTraderMap.get(traderPubKeyHash);
disputes.add(dispute);
});
return allDisputesByTraderMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,9 +41,8 @@ protected void run() {
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)) {
Expand All @@ -56,13 +54,12 @@ protected void run() {
} 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void testArbitratorSignWitness() {
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);
Expand Down
5 changes: 3 additions & 2 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
24 changes: 17 additions & 7 deletions p2p/src/main/java/bisq/network/p2p/network/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
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;
Expand Down Expand Up @@ -283,12 +285,20 @@ public void sendMessage(NetworkEnvelope networkEnvelope) {
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);
}
}
}
Expand Down Expand Up @@ -876,7 +886,7 @@ && reportInvalidRequest(RuleViolation.WRONG_NETWORK_ID)) {
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);
Expand Down

0 comments on commit e7d24ef

Please sign in to comment.