예제 #1
0
        public PasswordManagerTests()
        {
            _passwordRegistry = Substitute.For <IPasswordRegistry>();
            _passwordReader   = Substitute.For <IPasswordReader>();

            _secureString = new SecureString();

            _passwordManager = new PasswordManager(_passwordReader, _passwordRegistry);
        }
예제 #2
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);
        }
예제 #3
0
        public static IEnumerable <ClientRpcInfo> GenerateClientRpcInfoFromConfig(IUserOutput userOutput,
                                                                                  IPasswordRegistry passwordRegistry,
                                                                                  X509Certificate2 certificate,
                                                                                  ILogger logger,
                                                                                  SigningContext signingContext)
        {
            var simulationNodesFile =
                Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config", "simulation.nodes.json");
            var simulationNodes =
                JsonConvert.DeserializeObject <List <SimulationNode> >(File.ReadAllText(simulationNodesFile));

            foreach (var simulationNode in simulationNodes)
            {
                var simpleRpcClient = new SimpleRpcClient(userOutput, passwordRegistry, certificate, logger, signingContext);
                var clientRpcInfo   = new ClientRpcInfo(simulationNode.ToPeerIdentifier(), simpleRpcClient);
                yield return(clientRpcInfo);
            }
        }
예제 #4
0
 public PasswordRegistryLoader(IPasswordRegistry passwordRegistry)
 {
     _passwordRegistry = passwordRegistry;
 }
예제 #5
0
 public PasswordManager(IPasswordReader passwordReader, IPasswordRegistry passwordRegistry)
 {
     _passwordReader   = passwordReader;
     _passwordRegistry = passwordRegistry;
 }