mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Filter banned seednodes with wrong format
This commit is contained in:
parent
177067ea08
commit
35ede06037
2 changed files with 34 additions and 2 deletions
|
@ -33,6 +33,7 @@ import java.util.ArrayList;
|
|||
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;
|
||||
|
@ -40,6 +41,8 @@ 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
|
||||
|
@ -69,11 +72,12 @@ public class DefaultSeedNodeRepository implements SeedNodeRepository {
|
|||
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);
|
||||
|
@ -124,4 +128,14 @@ public class DefaultSeedNodeRepository implements SeedNodeRepository {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import bisq.network.p2p.NodeAddress;
|
|||
|
||||
import bisq.common.config.Config;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -45,4 +46,21 @@ public class DefaultSeedNodeRepositoryTest {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue