use of com.radixdlt.network.p2p.transport.PeerOutboundBootstrap in project radixdlt by radixdlt.
the class P2PTestNetworkRunner method createInjector.
private static Injector createInjector(MockP2PNetwork p2pNetwork, DeterministicNetwork network, P2PConfig p2pConfig, ECKeyPair nodeKey, RadixNodeUri selfUri, int selfNodeIndex) throws ParseException {
final var properties = new RuntimeProperties(new JSONObject(), new String[] {});
return Guice.createInjector(Modules.override(new P2PModule(properties)).with(new AbstractModule() {
@Override
protected void configure() {
bind(TestCounters.class).toInstance(new TestCounters());
bind(P2PConfig.class).toInstance(p2pConfig);
bind(RadixNodeUri.class).annotatedWith(Self.class).toInstance(selfUri);
bind(SystemCounters.class).to(SystemCountersImpl.class).in(Scopes.SINGLETON);
}
@Provides
public PeerOutboundBootstrap peerOutboundBootstrap(TestCounters testCounters) {
return uri -> {
testCounters.outboundChannelsBootstrapped += 1;
p2pNetwork.createChannel(selfNodeIndex, uri);
};
}
}), new PeerDiscoveryModule(), new PeerLivenessMonitorModule(), new DispatcherModule(), new AbstractModule() {
@Override
protected void configure() {
final var dbDir = new TemporaryFolder();
try {
dbDir.create();
} catch (IOException e) {
throw new RuntimeException(e);
}
bindConstant().annotatedWith(NetworkId.class).to(Network.LOCALNET.getId());
bind(Addressing.class).toInstance(Addressing.ofNetwork(Network.LOCALNET));
bindConstant().annotatedWith(DatabaseLocation.class).to(dbDir.getRoot().getAbsolutePath());
bindConstant().annotatedWith(DatabaseCacheSize.class).to(100_000L);
bind(ECKeyPair.class).annotatedWith(Self.class).toInstance(nodeKey);
bind(ECPublicKey.class).annotatedWith(Self.class).toInstance(nodeKey.getPublicKey());
bind(BFTNode.class).annotatedWith(Self.class).toInstance(BFTNode.create(nodeKey.getPublicKey()));
bind(String.class).annotatedWith(Self.class).toInstance(Addressing.ofNetwork(Network.LOCALNET).forValidators().of(nodeKey.getPublicKey()).substring(0, 10));
bind(ECKeyOps.class).toInstance(ECKeyOps.fromKeyPair(nodeKey));
bind(Environment.class).toInstance(network.createSender(BFTNode.create(nodeKey.getPublicKey())));
bind(RuntimeProperties.class).toInstance(properties);
bind(Serialization.class).toInstance(DefaultSerialization.getInstance());
bind(DeterministicProcessor.class);
Multibinder.newSetBinder(binder(), StartProcessorOnRunner.class);
bind(ForkConfig.class).annotatedWith(NewestForkConfig.class).toInstance(new FixedEpochForkConfig("genesis", null, 0L));
}
});
}
Aggregations