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;
}
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;
}
}
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);
}
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());
}
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());
}
Aggregations