Skip to content

Commit

Permalink
Merge pull request #7307 from alvasw/Pass_list_of_nodes_instead_of_Bt…
Browse files Browse the repository at this point in the history
…cNodes_class_to_FederatedBtcNodeProvider

Pass nodes instead of BtcNodes class to FederatedBtcNodeProvider
  • Loading branch information
alejandrogarcia83 authored Nov 20, 2024
2 parents 1ba9d84 + c4e82d5 commit 624467a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public List<BtcNode> selectPreferredNodes(BtcNodes btcNodes) {
break;
case PROVIDED:
default:
result = FederatedBtcNodeProvider.getNodes(btcNodes, config);
List<BtcNode> hardcodedBtcNodes = btcNodes.getProvidedBtcNodes();
List<String> filterProvidedBtcNodes = config.filterProvidedBtcNodes;
List<String> bannedBtcNodes = config.bannedBtcNodes;
result = FederatedBtcNodeProvider.getNodes(hardcodedBtcNodes, filterProvidedBtcNodes, bannedBtcNodes);
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

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;
Expand All @@ -17,23 +14,24 @@
@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()
static List<BtcNodes.BtcNode> getNodes(List<BtcNodes.BtcNode> hardcodedBtcNodes,
List<String> filterProvidedBtcNodesConfig,
List<String> bannedBtcNodesConfig) {
Set<BtcNodes.BtcNode> filterProvidedBtcNodes = filterProvidedBtcNodesConfig.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);
hardcodedBtcNodes.addAll(filterProvidedBtcNodes);

Set<String> bannedBtcNodeHostNames = config.bannedBtcNodes.stream()
Set<String> bannedBtcNodeHostNames = bannedBtcNodesConfig.stream()
.filter(n -> !n.isEmpty())
.map(FederatedBtcNodeProvider::getNodeAddress)
.filter(Objects::nonNull)
.map(NodeAddress::getHostName)
.collect(Collectors.toSet());
return providedBtcNodes.stream()
return hardcodedBtcNodes.stream()
.filter(e -> !bannedBtcNodeHostNames.contains(e.getHostName()))
.collect(Collectors.toList());
}
Expand Down

0 comments on commit 624467a

Please sign in to comment.