Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter for min required version for DAO #2670

Merged
merged 2 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ message Filter {
bool prevent_public_btc_network = 12;
repeated string btc_nodes = 13;
bool disable_dao = 14;
string disable_dao_below_version = 15;
}

// not used anymore from v0.6 on. But leave it for receiving TradeStatistics objects from older
Expand Down
21 changes: 19 additions & 2 deletions core/src/main/java/bisq/core/dao/DaoKillSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@
import bisq.core.filter.Filter;
import bisq.core.filter.FilterManager;

import bisq.common.app.Version;

import javax.inject.Inject;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nullable;

@Slf4j
public class DaoKillSwitch implements DaoSetupService {
private static DaoKillSwitch INSTANCE;
private final FilterManager filterManager;
Expand All @@ -49,8 +55,19 @@ public void start() {
applyFilter(filterManager.getFilter());
}

private void applyFilter(Filter filter) {
daoDisabled = filter != null && filter.isDisableDao();
private void applyFilter(@Nullable Filter filter) {
if (filter == null) {
daoDisabled = false;
return;
}

boolean requireUpdateToNewVersion = false;
String disableDaoBelowVersion = filter.getDisableDaoBelowVersion();
if (disableDaoBelowVersion != null && !disableDaoBelowVersion.isEmpty()) {
requireUpdateToNewVersion = Version.isNewVersion(disableDaoBelowVersion);
}

daoDisabled = requireUpdateToNewVersion || filter.isDisableDao();
}

public static void assertDaoIsNotDisabled() {
Expand Down
16 changes: 13 additions & 3 deletions core/src/main/java/bisq/core/filter/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public final class Filter implements ProtectedStoragePayload, ExpirablePayload {
// added in v0.9.4
private final boolean disableDao;

// added in v0.9.8
@Nullable
private final String disableDaoBelowVersion;

public Filter(List<String> bannedOfferIds,
List<String> bannedNodeAddress,
List<PaymentAccountFilter> bannedPaymentAccounts,
Expand All @@ -100,7 +104,8 @@ public Filter(List<String> bannedOfferIds,
@Nullable List<String> priceRelayNodes,
boolean preventPublicBtcNetwork,
@Nullable List<String> btcNodes,
boolean disableDao) {
boolean disableDao,
@Nullable String disableDaoBelowVersion) {
this.bannedOfferIds = bannedOfferIds;
this.bannedNodeAddress = bannedNodeAddress;
this.bannedPaymentAccounts = bannedPaymentAccounts;
Expand All @@ -112,6 +117,7 @@ public Filter(List<String> bannedOfferIds,
this.preventPublicBtcNetwork = preventPublicBtcNetwork;
this.btcNodes = btcNodes;
this.disableDao = disableDao;
this.disableDaoBelowVersion = disableDaoBelowVersion;
}


Expand All @@ -131,6 +137,7 @@ public Filter(List<String> bannedOfferIds,
boolean preventPublicBtcNetwork,
@Nullable List<String> btcNodes,
boolean disableDao,
@Nullable String disableDaoBelowVersion,
String signatureAsBase64,
byte[] ownerPubKeyBytes,
@Nullable Map<String, String> extraDataMap) {
Expand All @@ -144,7 +151,8 @@ public Filter(List<String> bannedOfferIds,
priceRelayNodes,
preventPublicBtcNetwork,
btcNodes,
disableDao);
disableDao,
disableDaoBelowVersion);
this.signatureAsBase64 = signatureAsBase64;
this.ownerPubKeyBytes = ownerPubKeyBytes;
this.extraDataMap = ExtraDataMapValidator.getValidatedExtraDataMap(extraDataMap);
Expand Down Expand Up @@ -174,6 +182,7 @@ public PB.StoragePayload toProtoMessage() {
Optional.ofNullable(seedNodes).ifPresent(builder::addAllSeedNodes);
Optional.ofNullable(priceRelayNodes).ifPresent(builder::addAllPriceRelayNodes);
Optional.ofNullable(btcNodes).ifPresent(builder::addAllBtcNodes);
Optional.ofNullable(disableDaoBelowVersion).ifPresent(builder::setDisableDaoBelowVersion);
Optional.ofNullable(extraDataMap).ifPresent(builder::putAllExtraData);

return PB.StoragePayload.newBuilder().setFilter(builder).build();
Expand All @@ -193,6 +202,7 @@ public static Filter fromProto(PB.Filter proto) {
proto.getPreventPublicBtcNetwork(),
CollectionUtils.isEmpty(proto.getBtcNodesList()) ? null : new ArrayList<>(proto.getBtcNodesList()),
proto.getDisableDao(),
proto.getDisableDaoBelowVersion().isEmpty() ? null : proto.getDisableDaoBelowVersion(),
proto.getSignatureAsBase64(),
proto.getOwnerPubKeyBytes().toByteArray(),
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());
Expand All @@ -205,7 +215,7 @@ public static Filter fromProto(PB.Filter proto) {

@Override
public long getTTL() {
return TimeUnit.DAYS.toMillis(90);
return TimeUnit.DAYS.toMillis(180);
}

public void setSigAndPubKey(String signatureAsBase64, PublicKey ownerPubKey) {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,7 @@ filterWindow.priceRelayNode=Filtered price relay nodes (comma sep. onion address
filterWindow.btcNode=Filtered Bitcoin nodes (comma sep. addresses + port)
filterWindow.preventPublicBtcNetwork=Prevent usage of public Bitcoin network
filterWindow.disableDao=Disable DAO
filterWindow.disableDaoBelowVersion=Min. version required for DAO
filterWindow.add=Add filter
filterWindow.remove=Remove filter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testRoundtripFull() {
vo.setDisplayedAlert(new Alert("message", true, "version", new byte[]{12, -64, 12}, "string", null));
vo.setDevelopersFilter(new Filter(Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(),
Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(),
false, Lists.newArrayList(), false, "string", new byte[]{10, 0, 0}, null));
false, Lists.newArrayList(), false, null, "string", new byte[]{10, 0, 0}, null));
vo.setRegisteredArbitrator(ArbitratorTest.getArbitratorMock());
vo.setRegisteredMediator(MediatorTest.getMediatorMock());
vo.setAcceptedArbitrators(Lists.newArrayList(ArbitratorTest.getArbitratorMock()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ private void addContent() {
InputTextField btcNodesInputTextField = addInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.btcNode"));
CheckBox preventPublicBtcNetworkCheckBox = addLabelCheckBox(gridPane, ++rowIndex, Res.get("filterWindow.preventPublicBtcNetwork"));
CheckBox disableDaoCheckBox = addLabelCheckBox(gridPane, ++rowIndex, Res.get("filterWindow.disableDao"));
InputTextField disableDaoBelowVersionInputTextField = addInputTextField(gridPane, ++rowIndex, Res.get("filterWindow.disableDaoBelowVersion"));

final Filter filter = filterManager.getDevelopersFilter();
if (filter != null) {
Expand Down Expand Up @@ -182,6 +183,7 @@ private void addContent() {
preventPublicBtcNetworkCheckBox.setSelected(filter.isPreventPublicBtcNetwork());

disableDaoCheckBox.setSelected(filter.isDisableDao());
disableDaoBelowVersionInputTextField.setText(filter.getDisableDaoBelowVersion());
}
Button sendButton = new AutoTooltipButton(Res.get("filterWindow.add"));
sendButton.setOnAction(e -> {
Expand Down Expand Up @@ -267,7 +269,8 @@ private void addContent() {
priceRelayNodes,
preventPublicBtcNetworkCheckBox.isSelected(),
btcNodes,
disableDaoCheckBox.isSelected()),
disableDaoCheckBox.isSelected(),
disableDaoBelowVersionInputTextField.getText()),
keyInputTextField.getText()))
hide();
else
Expand Down