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