use of io.libp2p.core.multiformats.Multiaddr in project teku by ConsenSys.
the class PeerManagerTest method shouldReportFailedConnectionsToReputationManager.
@Test
public void shouldReportFailedConnectionsToReputationManager() {
final Multiaddr multiaddr = Multiaddr.fromString("/ip4/127.0.0.1/tcp/9000");
final MultiaddrPeerAddress peerAddress = new MultiaddrPeerAddress(new MockNodeId(1), multiaddr);
when(network.connect(multiaddr)).thenReturn(CompletableFuture.failedFuture(new RuntimeException("Nope")));
final SafeFuture<Peer> result = peerManager.connect(peerAddress, network);
assertThat(result).isCompletedExceptionally();
verify(reputationManager).reportInitiatedConnectionFailed(peerAddress);
verify(reputationManager, never()).reportInitiatedConnectionSuccessful(peerAddress);
}
use of io.libp2p.core.multiformats.Multiaddr in project teku by ConsenSys.
the class MultiaddrUtilTest method fromInetSocketAddress_shouldConvertIpV4Peer.
@Test
public void fromInetSocketAddress_shouldConvertIpV4Peer() throws Exception {
final byte[] ipAddress = { 123, 34, 58, 22 };
final int port = 5883;
final InetSocketAddress address = new InetSocketAddress(InetAddress.getByAddress(ipAddress), port);
final Multiaddr result = MultiaddrUtil.fromInetSocketAddress(address);
assertThat(result).isEqualTo(Multiaddr.fromString("/ip4/123.34.58.22/tcp/5883/"));
assertThatComponent(result, Protocol.IP4).isEqualTo(ipAddress);
assertThatComponent(result, Protocol.TCP).isEqualTo(Protocol.TCP.addressToBytes("5883"));
assertThat(result.getFirstComponent(Protocol.P2P)).isNull();
}
use of io.libp2p.core.multiformats.Multiaddr in project teku by ConsenSys.
the class MultiaddrUtilTest method fromInetSocketAddress_shouldConvertIpV6Peer.
@Test
public void fromInetSocketAddress_shouldConvertIpV6Peer() throws Exception {
final byte[] ipAddress = Bytes.fromHexString("0x33000004500007800000001200000001").toArray();
final int port = 5883;
final InetSocketAddress address = new InetSocketAddress(InetAddress.getByAddress(ipAddress), port);
final Multiaddr result = MultiaddrUtil.fromInetSocketAddress(address);
assertThat(result).isEqualTo(Multiaddr.fromString("/ip6/3300:4:5000:780:0:12:0:1/tcp/5883/"));
assertThatComponent(result, Protocol.IP6).isEqualTo(ipAddress);
assertThatComponent(result, Protocol.TCP).isEqualTo(Protocol.TCP.addressToBytes("5883"));
assertThat(result.getFirstComponent(Protocol.P2P)).isNull();
}
use of io.libp2p.core.multiformats.Multiaddr in project xdagj by XDagger.
the class Libp2pNetwork method dail.
public void dail(String peer) {
Multiaddr address = Multiaddr.fromString(peer);
protocol.dial(host, address);
}
use of io.libp2p.core.multiformats.Multiaddr in project xdagj by XDagger.
the class MultiaddrTest method testGetIpAndPort.
@Test
public void testGetIpAndPort() {
Multiaddr multiaddr = Multiaddr.fromString("/ip4/127.0.0.1/tcp/40002");
String ip = Protocol.IP4.bytesToAddress(multiaddr.getComponent(Protocol.IP4));
String port = Protocol.TCP.bytesToAddress(multiaddr.getComponent(Protocol.TCP));
assertEquals("127.0.0.1", ip);
assertEquals("40002", port);
}
Aggregations