mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-01 01:32:17 +01:00
Move federated BTC node selection to FederatedBtcNodeProvider
This commit is contained in:
parent
22aa759a0a
commit
43b07c2838
2 changed files with 51 additions and 36 deletions
|
@ -20,24 +20,16 @@ package bisq.core.btc.nodes;
|
|||
import bisq.core.btc.nodes.BtcNodes.BtcNode;
|
||||
import bisq.core.user.Preferences;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
|
||||
import bisq.common.config.Config;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
public class BtcNodesSetupPreferences {
|
||||
private static final Logger log = LoggerFactory.getLogger(BtcNodesSetupPreferences.class);
|
||||
|
||||
|
@ -74,24 +66,7 @@ public class BtcNodesSetupPreferences {
|
|||
break;
|
||||
case PROVIDED:
|
||||
default:
|
||||
Set<BtcNode> providedBtcNodes = new HashSet<>(btcNodes.getProvidedBtcNodes());
|
||||
Set<BtcNode> filterProvidedBtcNodes = config.filterProvidedBtcNodes.stream()
|
||||
.filter(n -> !n.isEmpty())
|
||||
.map(this::getNodeAddress)
|
||||
.filter(Objects::nonNull)
|
||||
.map(nodeAddress -> new BtcNode(null, nodeAddress.getHostName(), null, nodeAddress.getPort(), "Provided by filter"))
|
||||
.collect(Collectors.toSet());
|
||||
providedBtcNodes.addAll(filterProvidedBtcNodes);
|
||||
|
||||
Set<String> bannedBtcNodeHostNames = config.bannedBtcNodes.stream()
|
||||
.filter(n -> !n.isEmpty())
|
||||
.map(this::getNodeAddress)
|
||||
.filter(Objects::nonNull)
|
||||
.map(NodeAddress::getHostName)
|
||||
.collect(Collectors.toSet());
|
||||
result = providedBtcNodes.stream()
|
||||
.filter(e -> !bannedBtcNodeHostNames.contains(e.getHostName()))
|
||||
.collect(Collectors.toList());
|
||||
result = FederatedBtcNodeProvider.getNodes(btcNodes, config);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -125,14 +100,4 @@ public class BtcNodesSetupPreferences {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private NodeAddress getNodeAddress(String address) {
|
||||
try {
|
||||
return new NodeAddress(address);
|
||||
} catch (Throwable t) {
|
||||
log.error("exception when filtering banned seednodes", t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package bisq.core.btc.nodes;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
|
||||
import bisq.common.config.Config;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Slf4j
|
||||
public class FederatedBtcNodeProvider {
|
||||
|
||||
static List<BtcNodes.BtcNode> getNodes(BtcNodes btcNodes, Config config) {
|
||||
Set<BtcNodes.BtcNode> providedBtcNodes = new HashSet<>(btcNodes.getProvidedBtcNodes());
|
||||
Set<BtcNodes.BtcNode> filterProvidedBtcNodes = config.filterProvidedBtcNodes.stream()
|
||||
.filter(n -> !n.isEmpty())
|
||||
.map(FederatedBtcNodeProvider::getNodeAddress)
|
||||
.filter(Objects::nonNull)
|
||||
.map(nodeAddress -> new BtcNodes.BtcNode(null, nodeAddress.getHostName(), null, nodeAddress.getPort(), "Provided by filter"))
|
||||
.collect(Collectors.toSet());
|
||||
providedBtcNodes.addAll(filterProvidedBtcNodes);
|
||||
|
||||
Set<String> bannedBtcNodeHostNames = config.bannedBtcNodes.stream()
|
||||
.filter(n -> !n.isEmpty())
|
||||
.map(FederatedBtcNodeProvider::getNodeAddress)
|
||||
.filter(Objects::nonNull)
|
||||
.map(NodeAddress::getHostName)
|
||||
.collect(Collectors.toSet());
|
||||
return providedBtcNodes.stream()
|
||||
.filter(e -> !bannedBtcNodeHostNames.contains(e.getHostName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static NodeAddress getNodeAddress(String address) {
|
||||
try {
|
||||
return new NodeAddress(address);
|
||||
} catch (Throwable t) {
|
||||
log.error("exception when filtering banned seednodes", t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue