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

Filter banned seednodes with wrong format #5469

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;

import org.jetbrains.annotations.Nullable;

// If a new BaseCurrencyNetwork type gets added we need to add the resource file for it as well!
@Slf4j
@Singleton
Expand Down Expand Up @@ -69,11 +72,12 @@ private void reload() {
List<NodeAddress> result = getSeedNodeAddressesFromPropertyFile(config.baseCurrencyNetwork.name().toLowerCase());
cache.addAll(result);

// filter
// let values configured by filter fail more gracefully
cache.removeAll(
config.bannedSeedNodes.stream()
.filter(n -> !n.isEmpty())
.map(NodeAddress::new)
.map(this::getNodeAddress)
.filter(Objects::nonNull)
.collect(Collectors.toSet()));

log.info("Seed nodes: {}", cache);
Expand Down Expand Up @@ -124,4 +128,14 @@ public boolean isSeedNode(NodeAddress nodeAddress) {
reload();
return cache.contains(nodeAddress);
}

@Nullable
private NodeAddress getNodeAddress(String n) {
try {
return new NodeAddress(n);
} catch (Throwable t) {
log.error("exception when filtering banned seednodes", t);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import bisq.common.config.Config;

import org.junit.After;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -45,4 +46,21 @@ public void manualSeedNodes() {
Assert.assertTrue(DUT.getSeedNodeAddresses().contains(new NodeAddress(seed1)));
Assert.assertTrue(DUT.getSeedNodeAddresses().contains(new NodeAddress(seed2)));
}

@Test
public void ignoreBannedSeedNodesWithWrongFormat() {
String seed1 = "asdfbroken";
String seed2 = "localhost:2002";
String baseCurrencyNetwork = format("--%s=%s", Config.BASE_CURRENCY_NETWORK, "btc_regtest");
String bannedSeedNodesOption = format("--%s=%s,%s", Config.BANNED_SEED_NODES, seed1, seed2);
Config config = new Config(baseCurrencyNetwork, bannedSeedNodesOption);
DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(config);
Assert.assertFalse(DUT.getSeedNodeAddresses().contains(new NodeAddress(seed2)));
}

@After
public void tearDown() {
//restore default Config
new Config();
}
}