Exemplo n.º 1
0
        public SimpleRpcClient(IUserOutput userOutput,
                               IPasswordRegistry passwordRegistry,
                               X509Certificate2 certificate,
                               ILogger logger,
                               SigningContext signingContextProvider)
        {
            _logger      = logger;
            _certificate = certificate;

            var fileSystem = new FileSystem();

            var consolePasswordReader = new ConsolePasswordReader(userOutput, new ConsoleUserInput());
            var passwordManager       = new PasswordManager(consolePasswordReader, passwordRegistry);

            var cryptoContext = new FfiWrapper();

            var hashProvider = new HashProvider(HashingAlgorithm.GetAlgorithmMetadata("keccak-256"));

            var peerSettings = Substitute.For <IPeerSettings>();

            peerSettings.NetworkType.Returns(signingContextProvider.NetworkType);

            var localKeyStore = new LocalKeyStore(passwordManager, cryptoContext, fileSystem, hashProvider, _logger);

            var keyRegistry = new KeyRegistry();
            var keySigner   = new KeySigner(localKeyStore, cryptoContext, keyRegistry);

            var memoryCacheOptions        = new MemoryCacheOptions();
            var memoryCache               = new MemoryCache(memoryCacheOptions);
            var changeTokenProvider       = new TtlChangeTokenProvider(10000);
            var messageCorrelationManager = new RpcMessageCorrelationManager(memoryCache, _logger, changeTokenProvider);
            var peerIdValidator           = new PeerIdValidator(cryptoContext);

            var nodeRpcClientChannelFactory =
                new RpcClientChannelFactory(keySigner, messageCorrelationManager, peerIdValidator, peerSettings);

            var eventLoopGroupFactoryConfiguration = new EventLoopGroupFactoryConfiguration
            {
                TcpClientHandlerWorkerThreads = 4
            };

            var tcpClientEventLoopGroupFactory = new TcpClientEventLoopGroupFactory(eventLoopGroupFactoryConfiguration);

            var handlers = new List <IRpcResponseObserver>
            {
                new BroadcastRawTransactionResponseObserver(_logger),
                new GetVersionResponseObserver(_logger)
            };

            _rpcClientFactory =
                new RpcClientFactory(nodeRpcClientChannelFactory, tcpClientEventLoopGroupFactory, handlers);

            //PeerId for RPC/TCP is currently redundant.
            var publicKey = keyRegistry.GetItemFromRegistry(KeyRegistryTypes.DefaultKey).GetPublicKey().Bytes;

            _senderPeerId = publicKey.BuildPeerIdFromPublicKey(IPAddress.Any, 1026);
        }
        public RpcMessageCorrelationManagerTests()
        {
            CorrelationManager = new RpcMessageCorrelationManager(Cache,
                                                                  SubbedLogger,
                                                                  ChangeTokenProvider,
                                                                  _testScheduler
                                                                  );

            PrepareCacheWithPendingRequests <GetInfoRequest>();
        }
Exemplo n.º 3
0
        public RpcMessageCorrelationManagerCacheTests()
        {
            _testScheduler = new TestScheduler();

            var memoryCacheOptions = new MemoryCacheOptions();
            var memoryCache        = new MemoryCache(memoryCacheOptions);

            var logger = Substitute.For <ILogger>();
            var changeTokenProvider = Substitute.For <IChangeTokenProvider>();

            _cancellationTokenSource = new CancellationTokenSource();
            var expirationToken = new CancellationChangeToken(_cancellationTokenSource.Token);

            changeTokenProvider.GetChangeToken().Returns(expirationToken);

            _rpcMessageCorrelationManager =
                new RpcMessageCorrelationManager(memoryCache, logger, changeTokenProvider, _testScheduler);
        }