Search in sources :

Example 1 with PeerAddress

use of org.bitcoinj.core.PeerAddress in project bisq-core by bisq-network.

the class BtcNodeConverter method convertClearNode.

@Nullable
PeerAddress convertClearNode(BtcNode node) {
    int port = node.getPort();
    PeerAddress result = create(node.getHostNameOrAddress(), port);
    if (result == null) {
        String address = node.getAddress();
        if (address != null) {
            result = create(address, port);
        } else {
            log.warn("Lookup failed, no address for node", node);
        }
    }
    return result;
}
Also used : PeerAddress(org.bitcoinj.core.PeerAddress) Nullable(javax.annotation.Nullable)

Example 2 with PeerAddress

use of org.bitcoinj.core.PeerAddress in project bisq-core by bisq-network.

the class BtcNodeConverter method convertOnionHost.

@Nullable
PeerAddress convertOnionHost(BtcNode node) {
    // no DNS lookup for onion addresses
    String onionAddress = Objects.requireNonNull(node.getOnionAddress());
    try {
        // OnionCat.onionHostToInetAddress converts onion to ipv6 representation
        // inetAddress is not used but required for wallet persistence. Throws nullPointer if not set.
        InetAddress inetAddress = facade.onionHostToInetAddress(onionAddress);
        PeerAddress result = new PeerAddress(onionAddress, node.getPort());
        result.setAddr(inetAddress);
        return result;
    } catch (UnknownHostException e) {
        log.error("Failed to convert node", e);
        return null;
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) PeerAddress(org.bitcoinj.core.PeerAddress) InetAddress(java.net.InetAddress) Nullable(javax.annotation.Nullable)

Example 3 with PeerAddress

use of org.bitcoinj.core.PeerAddress 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 4 with PeerAddress

use of org.bitcoinj.core.PeerAddress 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 5 with PeerAddress

use of org.bitcoinj.core.PeerAddress 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)

Aggregations

PeerAddress (org.bitcoinj.core.PeerAddress)14 BtcNode (bisq.core.btc.BitcoinNodes.BtcNode)8 Test (org.junit.Test)8 InetAddress (java.net.InetAddress)5 Nullable (javax.annotation.Nullable)4 Facade (bisq.core.btc.wallet.BtcNodeConverter.Facade)3 Socks5Proxy (com.runjva.sourceforge.jsocks.protocol.Socks5Proxy)3 UnknownHostException (java.net.UnknownHostException)2 DnsLookupException (bisq.network.DnsLookupException)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 InetSocketAddress (java.net.InetSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AddressMessage (org.bitcoinj.core.AddressMessage)1 BlockChain (org.bitcoinj.core.BlockChain)1 Peer (org.bitcoinj.core.Peer)1 PeerGroup (org.bitcoinj.core.PeerGroup)1