use of bisq.core.btc.BitcoinNodes.BtcNode in project bisq-core by bisq-network.
the class WalletSetupPreferences method selectPreferredNodes.
List<BtcNode> selectPreferredNodes(BitcoinNodes nodes) {
List<BtcNode> result;
BitcoinNodesOption nodesOption = BitcoinNodesOption.values()[preferences.getBitcoinNodesOptionOrdinal()];
switch(nodesOption) {
case CUSTOM:
String bitcoinNodes = preferences.getBitcoinNodes();
Set<String> distinctNodes = Utilities.commaSeparatedListToSet(bitcoinNodes, false);
result = BitcoinNodes.toBtcNodesList(distinctNodes);
if (result.isEmpty()) {
log.warn("Custom nodes is set but no valid nodes are provided. " + "We fall back to provided nodes option.");
preferences.setBitcoinNodesOptionOrdinal(BitcoinNodesOption.PROVIDED.ordinal());
result = nodes.getProvidedBtcNodes();
}
break;
case PUBLIC:
result = Collections.emptyList();
break;
case PROVIDED:
default:
result = nodes.getProvidedBtcNodes();
break;
}
return result;
}
use of bisq.core.btc.BitcoinNodes.BtcNode in project bisq-core by bisq-network.
the class BtcNodeConverterTest method testConvertOnionHostOnFailure.
@Test
public void testConvertOnionHostOnFailure() throws UnknownHostException {
BtcNode node = mock(BtcNode.class);
when(node.getOnionAddress()).thenReturn("aaa.onion");
Facade facade = mock(Facade.class);
when(facade.onionHostToInetAddress(any())).thenThrow(UnknownHostException.class);
PeerAddress peerAddress = new BtcNodeConverter(facade).convertOnionHost(node);
assertNull(peerAddress);
}
use of bisq.core.btc.BitcoinNodes.BtcNode in project bisq-core by bisq-network.
the class BtcNodeConverterTest method testConvertOnionHost.
@Test
public void testConvertOnionHost() throws UnknownHostException {
BtcNode node = mock(BtcNode.class);
when(node.getOnionAddress()).thenReturn("aaa.onion");
InetAddress inetAddress = mock(InetAddress.class);
Facade facade = mock(Facade.class);
when(facade.onionHostToInetAddress(any())).thenReturn(inetAddress);
PeerAddress peerAddress = new BtcNodeConverter(facade).convertOnionHost(node);
// noinspection ConstantConditions
assertEquals(inetAddress, peerAddress.getAddr());
}
use of bisq.core.btc.BitcoinNodes.BtcNode in project bisq-core by bisq-network.
the class PeerAddressesRepositoryTest method testGetPeerAddressesWhenConverterReturnsNull.
@Test
public void testGetPeerAddressesWhenConverterReturnsNull() {
BtcNodeConverter converter = mock(BtcNodeConverter.class);
when(converter.convertClearNode(any())).thenReturn(null);
BtcNode node = mock(BtcNode.class);
when(node.hasClearNetAddress()).thenReturn(true);
PeerAddressesRepository repository = new PeerAddressesRepository(converter, Collections.singletonList(node));
List<PeerAddress> peers = repository.getPeerAddresses(null, false);
verify(converter).convertClearNode(any());
assertTrue(peers.isEmpty());
}
use of bisq.core.btc.BitcoinNodes.BtcNode in project bisq-core by bisq-network.
the class WalletSetupPreferencesTest method testSelectPreferredNodesWhenCustomOption.
@Test
public void testSelectPreferredNodesWhenCustomOption() {
Preferences delegate = mock(Preferences.class);
when(delegate.getBitcoinNodesOptionOrdinal()).thenReturn(CUSTOM.ordinal());
when(delegate.getBitcoinNodes()).thenReturn("aaa.onion,bbb.onion");
WalletSetupPreferences preferences = new WalletSetupPreferences(delegate);
List<BtcNode> nodes = preferences.selectPreferredNodes(mock(BitcoinNodes.class));
assertEquals(2, nodes.size());
}
Aggregations