Search in sources :

Example 1 with Multiaddr

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);
}
Also used : MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) Peer(tech.pegasys.teku.networking.p2p.peer.Peer) Multiaddr(io.libp2p.core.multiformats.Multiaddr) Test(org.junit.jupiter.api.Test)

Example 2 with Multiaddr

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();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Multiaddr(io.libp2p.core.multiformats.Multiaddr) Test(org.junit.jupiter.api.Test)

Example 3 with Multiaddr

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();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Multiaddr(io.libp2p.core.multiformats.Multiaddr) Test(org.junit.jupiter.api.Test)

Example 4 with Multiaddr

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);
}
Also used : Multiaddr(io.libp2p.core.multiformats.Multiaddr)

Example 5 with Multiaddr

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);
}
Also used : Multiaddr(io.libp2p.core.multiformats.Multiaddr) Test(org.junit.Test)

Aggregations

Multiaddr (io.libp2p.core.multiformats.Multiaddr)12 InetSocketAddress (java.net.InetSocketAddress)8 Test (org.junit.jupiter.api.Test)8 DiscoveryPeer (tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer)4 MockNodeId (tech.pegasys.teku.networking.p2p.mock.MockNodeId)2 NodeId (tech.pegasys.teku.networking.p2p.peer.NodeId)2 Peer (tech.pegasys.teku.networking.p2p.peer.Peer)2 Connection (io.libp2p.core.Connection)1 PrivKey (io.libp2p.core.crypto.PrivKey)1 Session (io.libp2p.core.security.SecureChannel.Session)1 NoiseXXSecureChannel (io.libp2p.security.noise.NoiseXXSecureChannel)1 TcpTransport (io.libp2p.transport.tcp.TcpTransport)1 Test (org.junit.Test)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1