Search in sources :

Example 1 with BtcNode

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;
}
Also used : BitcoinNodesOption(bisq.core.btc.BitcoinNodes.BitcoinNodesOption) BtcNode(bisq.core.btc.BitcoinNodes.BtcNode)

Example 2 with BtcNode

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);
}
Also used : Facade(bisq.core.btc.wallet.BtcNodeConverter.Facade) PeerAddress(org.bitcoinj.core.PeerAddress) BtcNode(bisq.core.btc.BitcoinNodes.BtcNode) Test(org.junit.Test)

Example 3 with BtcNode

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());
}
Also used : Facade(bisq.core.btc.wallet.BtcNodeConverter.Facade) PeerAddress(org.bitcoinj.core.PeerAddress) BtcNode(bisq.core.btc.BitcoinNodes.BtcNode) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 4 with BtcNode

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());
}
Also used : PeerAddress(org.bitcoinj.core.PeerAddress) BtcNode(bisq.core.btc.BitcoinNodes.BtcNode) Test(org.junit.Test)

Example 5 with BtcNode

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());
}
Also used : BtcNode(bisq.core.btc.BitcoinNodes.BtcNode) Preferences(bisq.core.user.Preferences) BitcoinNodes(bisq.core.btc.BitcoinNodes) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

BtcNode (bisq.core.btc.BitcoinNodes.BtcNode)11 Test (org.junit.Test)10 PeerAddress (org.bitcoinj.core.PeerAddress)8 Facade (bisq.core.btc.wallet.BtcNodeConverter.Facade)3 Socks5Proxy (com.runjva.sourceforge.jsocks.protocol.Socks5Proxy)3 InetAddress (java.net.InetAddress)3 BitcoinNodes (bisq.core.btc.BitcoinNodes)2 Preferences (bisq.core.user.Preferences)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 BitcoinNodesOption (bisq.core.btc.BitcoinNodes.BitcoinNodesOption)1 Ignore (org.junit.Ignore)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1