Fix duplicates in BtcNode list

When the user uses our federated BTC nodes, we merge the hard-coded
nodes with the ones provided by the filter. The hard-coded node's
operator field is set to the node's operator and operator field of the
nodes from the filter is set to "Provided by filter". When the same BTC
node is in the hard-coded list and the filter, Bisq adds both to the
merged list because the operator field is different.

This change explicitly marks the onionAddress, hostName, address, and
port field to be used in the hashCode and equals implementation.
This commit is contained in:
Alva Swanson 2024-11-18 21:59:56 +00:00
parent 8ef76bb408
commit 840319a955
No known key found for this signature in database
GPG Key ID: 004760E77F753090
2 changed files with 27 additions and 2 deletions

View File

@ -80,19 +80,23 @@ public class BtcNodes {
.collect(Collectors.toList());
}
@EqualsAndHashCode
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Getter
public static class BtcNode {
private static final int DEFAULT_PORT = Config.baseCurrencyNetworkParameters().getPort(); //8333
static final int DEFAULT_PORT = Config.baseCurrencyNetworkParameters().getPort(); //8333
@EqualsAndHashCode.Include
@Nullable
private final String onionAddress;
@EqualsAndHashCode.Include
@Nullable
private final String hostName;
@Nullable
private final String operator; // null in case the user provides a list of custom btc nodes
@EqualsAndHashCode.Include
@Nullable
private final String address; // IPv4 address
@EqualsAndHashCode.Include
private int port = DEFAULT_PORT;
/**

View File

@ -0,0 +1,21 @@
package bisq.core.btc.nodes;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
public class BtcNodeTest {
@Test
void hardcodedAndFilterProvidedNodeShouldBeEqual() {
var aliceHardcodedBtcNode = new BtcNodes.BtcNode(null,
"alice_btc_node.onion", null,
BtcNodes.BtcNode.DEFAULT_PORT, "@Alice");
var aliceNodeFromFilter = new BtcNodes.BtcNode(null,
"alice_btc_node.onion", null,
BtcNodes.BtcNode.DEFAULT_PORT, "Provided by filter");
assertThat(aliceHardcodedBtcNode, equalTo(aliceNodeFromFilter));
}
}