-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7306 from alvasw/Move_federated_BTC_node_selectio…
…n_to_FederatedBtcNodeProvider Move federated BTC node selection to FederatedBtcNodeProvider
- Loading branch information
Showing
2 changed files
with
51 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
core/src/main/java/bisq/core/btc/nodes/FederatedBtcNodeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |