Search in sources :

Example 1 with PeerOutboundBootstrap

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));
        }
    });
}
Also used : Key(com.google.inject.Key) DefaultSerialization(com.radixdlt.DefaultSerialization) DatabaseCacheSize(com.radixdlt.store.DatabaseCacheSize) DispatcherModule(com.radixdlt.modules.DispatcherModule) JSONObject(org.json.JSONObject) ForkConfig(com.radixdlt.statecomputer.forks.ForkConfig) PeerOutboundBootstrap(com.radixdlt.network.p2p.transport.PeerOutboundBootstrap) SystemCounters(com.radixdlt.counters.SystemCounters) DatabaseEnvironment(com.radixdlt.store.DatabaseEnvironment) Multibinder(com.google.inject.multibindings.Multibinder) Objects(java.util.Objects) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) P2PModule(com.radixdlt.network.p2p.P2PModule) FixedEpochForkConfig(com.radixdlt.statecomputer.forks.FixedEpochForkConfig) ParseException(org.apache.commons.cli.ParseException) NetworkId(com.radixdlt.networks.NetworkId) StartProcessorOnRunner(com.radixdlt.environment.StartProcessorOnRunner) IntStream(java.util.stream.IntStream) PeerManager(com.radixdlt.network.p2p.PeerManager) Serialization(com.radixdlt.serialization.Serialization) Modules(com.google.inject.util.Modules) PeerLivenessMonitorModule(com.radixdlt.network.p2p.PeerLivenessMonitorModule) ECPublicKey(com.radixdlt.crypto.ECPublicKey) DeterministicNetwork(com.radixdlt.environment.deterministic.network.DeterministicNetwork) RuntimeProperties(com.radixdlt.properties.RuntimeProperties) ImmutableList(com.google.common.collect.ImmutableList) DatabaseLocation(com.radixdlt.store.DatabaseLocation) MessageSelector(com.radixdlt.environment.deterministic.network.MessageSelector) PeerDiscoveryModule(com.radixdlt.network.p2p.PeerDiscoveryModule) AddressBook(com.radixdlt.network.p2p.addressbook.AddressBook) Addressing(com.radixdlt.networks.Addressing) NewestForkConfig(com.radixdlt.statecomputer.forks.NewestForkConfig) Network(com.radixdlt.networks.Network) ECKeyOps(com.radixdlt.crypto.ECKeyOps) Environment(com.radixdlt.environment.Environment) RadixNodeUri(com.radixdlt.network.p2p.RadixNodeUri) IOException(java.io.IOException) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) Scopes(com.google.inject.Scopes) Injector(com.google.inject.Injector) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) P2PConfig(com.radixdlt.network.p2p.P2PConfig) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) MessageMutator(com.radixdlt.environment.deterministic.network.MessageMutator) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) Self(com.radixdlt.hotstuff.bft.Self) StartProcessorOnRunner(com.radixdlt.environment.StartProcessorOnRunner) TemporaryFolder(org.junit.rules.TemporaryFolder) FixedEpochForkConfig(com.radixdlt.statecomputer.forks.FixedEpochForkConfig) RuntimeProperties(com.radixdlt.properties.RuntimeProperties) PeerLivenessMonitorModule(com.radixdlt.network.p2p.PeerLivenessMonitorModule) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ForkConfig(com.radixdlt.statecomputer.forks.ForkConfig) FixedEpochForkConfig(com.radixdlt.statecomputer.forks.FixedEpochForkConfig) NewestForkConfig(com.radixdlt.statecomputer.forks.NewestForkConfig) P2PConfig(com.radixdlt.network.p2p.P2PConfig) ECKeyPair(com.radixdlt.crypto.ECKeyPair) IOException(java.io.IOException) AbstractModule(com.google.inject.AbstractModule) JSONObject(org.json.JSONObject) ECPublicKey(com.radixdlt.crypto.ECPublicKey) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) DispatcherModule(com.radixdlt.modules.DispatcherModule) P2PModule(com.radixdlt.network.p2p.P2PModule) PeerDiscoveryModule(com.radixdlt.network.p2p.PeerDiscoveryModule)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 AbstractModule (com.google.inject.AbstractModule)1 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 Key (com.google.inject.Key)1 Provides (com.google.inject.Provides)1 Scopes (com.google.inject.Scopes)1 Multibinder (com.google.inject.multibindings.Multibinder)1 Modules (com.google.inject.util.Modules)1 DefaultSerialization (com.radixdlt.DefaultSerialization)1 SystemCounters (com.radixdlt.counters.SystemCounters)1 SystemCountersImpl (com.radixdlt.counters.SystemCountersImpl)1 ECKeyOps (com.radixdlt.crypto.ECKeyOps)1 ECKeyPair (com.radixdlt.crypto.ECKeyPair)1 ECPublicKey (com.radixdlt.crypto.ECPublicKey)1 Environment (com.radixdlt.environment.Environment)1 StartProcessorOnRunner (com.radixdlt.environment.StartProcessorOnRunner)1 DeterministicProcessor (com.radixdlt.environment.deterministic.DeterministicProcessor)1 DeterministicNetwork (com.radixdlt.environment.deterministic.network.DeterministicNetwork)1 MessageMutator (com.radixdlt.environment.deterministic.network.MessageMutator)1