use of io.libp2p.core.crypto.PrivKey in project teku by ConsenSys.
the class LibP2PPrivateKeyLoaderTest method testPrivateKeyGeneration.
@Test
void testPrivateKeyGeneration() {
final LibP2PPrivateKeyLoader loader = new LibP2PPrivateKeyLoader(store, Optional.empty());
// check that new key is generated
final PrivKey generatedPK = loader.get();
assertThat(generatedPK).isNotNull();
assertRoundTrip(generatedPK);
// check the same key loaded next time
PrivKey loadedPK = loader.get();
assertThat(loadedPK).isEqualTo(generatedPK);
// If store is cleared, we should generate a new key
store.remove(LibP2PPrivateKeyLoader.GENERATED_NODE_KEY_KEY);
// check that another key is generated after old key is deleted
PrivKey generatedAnotherPK = loader.get();
assertThat(generatedAnotherPK).isNotNull();
assertRoundTrip(generatedAnotherPK);
assertThat(generatedAnotherPK).isNotEqualTo(generatedPK);
}
use of io.libp2p.core.crypto.PrivKey in project teku by ConsenSys.
the class LibP2PPrivateKeyLoaderTest method testPrivateKeyLoaded.
@Test
void testPrivateKeyLoaded() {
// check that user supplied private key file has precedence over generated file
final PrivKey privKey = PrivateKeyGenerator.generate();
final Bytes privKeyBytes = Bytes.wrap(privKey.bytes());
PrivateKeySource privKeySource = () -> privKeyBytes;
final LibP2PPrivateKeyLoader loader = new LibP2PPrivateKeyLoader(store, Optional.of(privKeySource));
assertThat(loader.get()).isEqualTo(privKey);
}
use of io.libp2p.core.crypto.PrivKey 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