Search in sources :

Example 1 with NodeId

use of tech.pegasys.teku.networking.p2p.peer.NodeId in project teku by ConsenSys.

the class GetIdentityTest method shouldReturnExpectedObjectType.

@Test
public void shouldReturnExpectedObjectType() throws Exception {
    final MetadataMessage defaultMetadata = spec.getGenesisSchemaDefinitions().getMetadataMessageSchema().createDefault();
    GetIdentity handler = new GetIdentity(network, jsonProvider);
    NodeId nodeid = mock(NodeId.class);
    when(eth2P2PNetwork.getMetadata()).thenReturn(defaultMetadata);
    when(eth2P2PNetwork.getNodeId()).thenReturn(nodeid);
    when(nodeid.toBase58()).thenReturn("aeiou");
    when(eth2P2PNetwork.getNodeAddress()).thenReturn("address");
    handler.handle(context);
    verifyCacheStatus(CACHE_NONE);
    IdentityResponse response = getResponseObject(IdentityResponse.class);
    assertThat(response.data.peerId).isEqualTo("aeiou");
    assertThat(response.data.p2pAddresses.get(0)).isEqualTo("address");
}
Also used : MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) IdentityResponse(tech.pegasys.teku.api.response.v1.node.IdentityResponse) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) Test(org.junit.jupiter.api.Test) AbstractBeaconHandlerTest(tech.pegasys.teku.beaconrestapi.AbstractBeaconHandlerTest)

Example 2 with NodeId

use of tech.pegasys.teku.networking.p2p.peer.NodeId in project teku by ConsenSys.

the class Eth2PeerManagerTest method createEth2Peer.

private Eth2Peer createEth2Peer(final Peer peer) {
    final Eth2Peer eth2Peer = mock(Eth2Peer.class);
    when(eth2Peer.idMatches(peer)).thenReturn(true);
    when(peer.idMatches(eth2Peer)).thenReturn(true);
    final NodeId peerId = peer.getId();
    when(eth2Peer.getId()).thenReturn(peerId);
    return eth2Peer;
}
Also used : MockNodeId(tech.pegasys.teku.networking.p2p.mock.MockNodeId) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId)

Example 3 with NodeId

use of tech.pegasys.teku.networking.p2p.peer.NodeId in project teku by ConsenSys.

the class RpcHandler method initChannel.

@NotNull
@Override
public SafeFuture<Controller<TOutgoingHandler>> initChannel(final P2PChannel channel, final String selectedProtocol) {
    final Connection connection = ((io.libp2p.core.Stream) channel).getConnection();
    final NodeId nodeId = new LibP2PNodeId(connection.secureSession().getRemoteId());
    final Controller<TOutgoingHandler> controller = new Controller<>(nodeId, channel);
    if (!channel.isInitiator()) {
        controller.setIncomingRequestHandler(rpcMethod.createIncomingRequestHandler(selectedProtocol));
    }
    channel.pushHandler(controller);
    return controller.activeFuture;
}
Also used : Connection(io.libp2p.core.Connection) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) RpcStream(tech.pegasys.teku.networking.p2p.rpc.RpcStream) Stream(io.libp2p.core.Stream) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) Controller(tech.pegasys.teku.networking.p2p.libp2p.rpc.RpcHandler.Controller) RpcStreamController(tech.pegasys.teku.networking.p2p.rpc.RpcStreamController) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with NodeId

use of tech.pegasys.teku.networking.p2p.peer.NodeId in project teku by ConsenSys.

the class LibP2PNetworkBuilder method build.

public P2PNetwork<Peer> build() {
    gossipNetwork = createGossipNetwork();
    // Setup rpc methods
    rpcHandlers = createRpcHandlers();
    // Setup peers
    peerManager = createPeerManager();
    host = createHost();
    NodeId nodeId = new LibP2PNodeId(host.getPeerId());
    Multiaddr advertisedAddr = MultiaddrUtil.fromInetSocketAddress(new InetSocketAddress(config.getAdvertisedIp(), config.getAdvertisedPort()), nodeId);
    return new LibP2PNetwork(host.getPrivKey(), nodeId, host, peerManager, advertisedAddr, gossipNetwork, config.getListenPort());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) Multiaddr(io.libp2p.core.multiformats.Multiaddr)

Example 5 with NodeId

use of tech.pegasys.teku.networking.p2p.peer.NodeId in project teku by ConsenSys.

the class LibP2PNetworkBuilder method createHost.

protected Host createHost() {
    PrivKey privKey = privateKeyProvider.get();
    NodeId nodeId = new LibP2PNodeId(PeerId.fromPubKey(privKey.publicKey()));
    Multiaddr advertisedAddr = MultiaddrUtil.fromInetSocketAddress(new InetSocketAddress(config.getAdvertisedIp(), config.getAdvertisedPort()), nodeId);
    final Multiaddr listenAddr = MultiaddrUtil.fromInetSocketAddress(new InetSocketAddress(config.getNetworkInterface(), config.getListenPort()));
    return BuilderJKt.hostJ(hostBuilderDefaults, b -> {
        b.getIdentity().setFactory(() -> privKey);
        b.getTransports().add(TcpTransport::new);
        b.getSecureChannels().add(NoiseXXSecureChannel::new);
        b.getMuxers().add(StreamMuxerProtocol.getMplex());
        b.getNetwork().listen(listenAddr.toString());
        b.getProtocols().addAll(getDefaultProtocols(privKey.publicKey(), advertisedAddr));
        b.getProtocols().add(gossipNetwork.getGossip());
        b.getProtocols().addAll(rpcHandlers);
        if (config.getWireLogsConfig().isLogWireCipher()) {
            b.getDebug().getBeforeSecureHandler().addLogger(LogLevel.DEBUG, "wire.ciphered");
        }
        b.getDebug().getBeforeSecureHandler().addNettyHandler(firewall);
        if (config.getWireLogsConfig().isLogWirePlain()) {
            b.getDebug().getAfterSecureHandler().addLogger(LogLevel.DEBUG, "wire.plain");
        }
        if (config.getWireLogsConfig().isLogWireMuxFrames()) {
            b.getDebug().getMuxFramesHandler().addLogger(LogLevel.DEBUG, "wire.mux");
        }
        b.getConnectionHandlers().add(peerManager);
        b.getDebug().getMuxFramesHandler().addHandler(mplexFirewall);
    });
}
Also used : NoiseXXSecureChannel(io.libp2p.security.noise.NoiseXXSecureChannel) InetSocketAddress(java.net.InetSocketAddress) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) PrivKey(io.libp2p.core.crypto.PrivKey) TcpTransport(io.libp2p.transport.tcp.TcpTransport) Multiaddr(io.libp2p.core.multiformats.Multiaddr)

Aggregations

NodeId (tech.pegasys.teku.networking.p2p.peer.NodeId)5 Multiaddr (io.libp2p.core.multiformats.Multiaddr)2 InetSocketAddress (java.net.InetSocketAddress)2 Connection (io.libp2p.core.Connection)1 Stream (io.libp2p.core.Stream)1 PrivKey (io.libp2p.core.crypto.PrivKey)1 NoiseXXSecureChannel (io.libp2p.security.noise.NoiseXXSecureChannel)1 TcpTransport (io.libp2p.transport.tcp.TcpTransport)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.jupiter.api.Test)1 IdentityResponse (tech.pegasys.teku.api.response.v1.node.IdentityResponse)1 AbstractBeaconHandlerTest (tech.pegasys.teku.beaconrestapi.AbstractBeaconHandlerTest)1 LibP2PNodeId (tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId)1 Controller (tech.pegasys.teku.networking.p2p.libp2p.rpc.RpcHandler.Controller)1 MockNodeId (tech.pegasys.teku.networking.p2p.mock.MockNodeId)1 RpcStream (tech.pegasys.teku.networking.p2p.rpc.RpcStream)1 RpcStreamController (tech.pegasys.teku.networking.p2p.rpc.RpcStreamController)1 MetadataMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage)1