Exemple #1
0
        private static void Start()
        {
            var privateKeyProvider = new PrivateKeyProvider(PrivateKey);
            var config             = new DiscoveryConfigurationProvider(new NetworkHelper(Logger));
            var signer             = new Signer();
            var cryptoRandom       = new CryptoRandom();
            var configProvider     = new ConfigurationProvider();

            var nodeFactory = new NodeFactory();
            var calculator  = new NodeDistanceCalculator(config);

            var nodeTable = new NodeTable(config, nodeFactory, new FileKeyStore(configProvider, new JsonSerializer(Logger), new AesEncrypter(configProvider, Logger), cryptoRandom, Logger), Logger, calculator);

            var evictionManager  = new EvictionManager(nodeTable, Logger);
            var lifecycleFactory = new NodeLifecycleManagerFactory(nodeFactory, nodeTable, Logger, config, new DiscoveryMessageFactory(config), evictionManager);

            var discoveryManager = new DiscoveryManager(Logger, config, lifecycleFactory, nodeFactory, nodeTable);

            var nodesLocator           = new NodesLocator(nodeTable, discoveryManager, config, Logger);
            var discoveryMesageFactory = new DiscoveryMessageFactory(config);
            var nodeIdResolver         = new NodeIdResolver(signer);

            var pingSerializer      = new PingMessageSerializer(signer, privateKeyProvider, discoveryMesageFactory, nodeIdResolver, nodeFactory);
            var pongSerializer      = new PongMessageSerializer(signer, privateKeyProvider, discoveryMesageFactory, nodeIdResolver, nodeFactory);
            var findNodeSerializer  = new FindNodeMessageSerializer(signer, privateKeyProvider, discoveryMesageFactory, nodeIdResolver, nodeFactory);
            var neighborsSerializer = new NeighborsMessageSerializer(signer, privateKeyProvider, discoveryMesageFactory, nodeIdResolver, nodeFactory);

            var messageSerializationService = new MessageSerializationService();

            messageSerializationService.Register(pingSerializer);
            messageSerializationService.Register(pongSerializer);
            messageSerializationService.Register(findNodeSerializer);
            messageSerializationService.Register(neighborsSerializer);


            //P2P initialization
            IMessagePad eip8Pad = new Eip8MessagePad(cryptoRandom);

            messageSerializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            messageSerializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            messageSerializationService.Register(new HelloMessageSerializer());
            messageSerializationService.Register(new DisconnectMessageSerializer());
            messageSerializationService.Register(new Nethermind.Network.P2P.PingMessageSerializer());
            messageSerializationService.Register(new Nethermind.Network.P2P.PongMessageSerializer());
            messageSerializationService.Register(new StatusMessageSerializer());
            IEciesCipher eciesCipher = new EciesCipher(cryptoRandom);
            IEncryptionHandshakeService encryptionHandshakeService = new EncryptionHandshakeService(messageSerializationService, eciesCipher, cryptoRandom, signer, PrivateKey, Logger);
            var p2pManager = new P2PManager(encryptionHandshakeService, Logger, messageSerializationService, Substitute.For <ISynchronizationManager>());

            //Connect discovery with P2P
            discoveryManager.RegisterDiscoveryListener(p2pManager);

            _discoveryApp = new DiscoveryApp(config, nodesLocator, Logger, discoveryManager, nodeFactory, nodeTable, messageSerializationService, cryptoRandom);
            _discoveryApp.Start(PrivateKey.PublicKey);
        }
        public DiscoveryMsgSerializersProvider(IMessageSerializationService messageSerializationService, ISigner signer, IPrivateKeyProvider privateKeyProvider, IDiscoveryMessageFactory messageFactory, INodeIdResolver nodeIdResolver, INodeFactory nodeFactory)
        {
            var pingSerializer      = new PingMessageSerializer(signer, privateKeyProvider, messageFactory, nodeIdResolver, nodeFactory);
            var pongSerializer      = new PongMessageSerializer(signer, privateKeyProvider, messageFactory, nodeIdResolver, nodeFactory);
            var findNodeSerializer  = new FindNodeMessageSerializer(signer, privateKeyProvider, messageFactory, nodeIdResolver, nodeFactory);
            var neighborsSerializer = new NeighborsMessageSerializer(signer, privateKeyProvider, messageFactory, nodeIdResolver, nodeFactory);

            _messageSerializationService = messageSerializationService;
            _pingMessageSerializer       = pingSerializer;
            _pongMessageSerializer       = pongSerializer;
            _findNodeMessageSerializer   = findNodeSerializer;
            _neighborsMessageSerializer  = neighborsSerializer;
        }