コード例 #1
0
        private async Task RunHeartbeatChecker(bool sendResponse = false, int maxNonResponsiveCounter = 1)
        {
            var peers = new List <Peer> {
                _testPeer
            };
            var peerSettings   = _testPeer.PeerId.ToSubstitutedPeerSettings();
            var peerChallenger = new PeerChallenger(
                Substitute.For <ILogger>(),
                _peerClient,
                peerSettings,
                PeerChallengeTimeoutSeconds);

            if (sendResponse)
            {
                peerChallenger.ChallengeResponseMessageStreamer.OnNext(new PeerChallengerResponse(_testPeer.PeerId));
            }

            _peerRepository.GetAll().Returns(peers);
            _peerRepository.AsQueryable().Returns(peers.AsQueryable());
            _peerHeartbeatChecker = new PeerHeartbeatChecker(
                Substitute.For <ILogger>(),
                _peerRepository,
                peerChallenger,
                PeerHeartbeatCheckSeconds,
                maxNonResponsiveCounter);

            _peerHeartbeatChecker.Run();
            await Task.Delay(TimeSpan.FromSeconds(PeerHeartbeatCheckSeconds * (maxNonResponsiveCounter + 1)).Add(TimeSpan.FromSeconds(1))).ConfigureAwait(false);
        }
コード例 #2
0
        private void PopulatePeers(int count)
        {
            var peerList = new List <Peer>();

            for (var i = 10; i < count + 10; i++)
            {
                var peer = new Peer
                {
                    PeerId = PeerIdHelper.GetPeerId(i.ToString())
                };
                peerList.Add(peer);
                _peers.Get(peer.DocumentId).Returns(peer);
            }

            _peers.AsQueryable().Returns(peerList.AsQueryable());
        }
コード例 #3
0
        public PoaTestNode(string name,
                           IPrivateKey privateKey,
                           IPeerSettings nodeSettings,
                           IEnumerable <PeerId> knownPeerIds,
                           IFileSystem parentTestFileSystem,
                           ITestOutputHelper output)
        {
            Name          = name;
            _nodeSettings = nodeSettings;

            _nodeDirectory = parentTestFileSystem.GetCatalystDataDir().SubDirectoryInfo(Name);
            var nodeFileSystem = Substitute.ForPartsOf <FileSystem>();

            nodeFileSystem.GetCatalystDataDir().Returns(_nodeDirectory);

            _rpcSettings = RpcSettingsHelper.GetRpcServerSettings(nodeSettings.Port + 100);
            _nodePeerId  = nodeSettings.PeerId;

            var baseDfsFolder = Path.Combine(parentTestFileSystem.GetCatalystDataDir().FullName, "dfs");
            var hashProvider  = new HashProvider(HashingAlgorithm.GetAlgorithmMetadata("blake2b-256"));

            _dfs = new DevDfs(parentTestFileSystem, hashProvider, baseDfsFolder);

            _memPool        = new Mempool(new TestMempoolRepository(new InMemoryRepository <TransactionBroadcastDao, string>()));
            _peerRepository = Substitute.For <IPeerRepository>();
            var peersInRepo = knownPeerIds.Select(p => new Peer
            {
                PeerId = p
            }).ToList();

            _peerRepository.AsQueryable().Returns(peersInRepo.AsQueryable());
            _peerRepository.GetAll().Returns(peersInRepo);
            _peerRepository.Get(Arg.Any <string>()).Returns(ci =>
            {
                return(peersInRepo.First(p => p.DocumentId.Equals((string)ci[0])));
            });

            _containerProvider = new ContainerProvider(new[]
            {
                Constants.NetworkConfigFile(NetworkType.Devnet),
                Constants.SerilogJsonConfigFile
            }
                                                       .Select(f => Path.Combine(Constants.ConfigSubFolder, f)), parentTestFileSystem, output);

            Program.RegisterNodeDependencies(_containerProvider.ContainerBuilder,
                                             excludedModules: new List <Type> {
                typeof(ApiModule), typeof(RpcServerModule)
            }
                                             );
            _containerProvider.ConfigureContainerBuilder(true, true);
            OverrideContainerBuilderRegistrations();

            _scope = _containerProvider.Container.BeginLifetimeScope(Name);
            _node  = _scope.Resolve <ICatalystNode>();

            var keyStore    = _scope.Resolve <IKeyStore>();
            var keyRegistry = _scope.Resolve <IKeyRegistry>();

            keyRegistry.AddItemToRegistry(KeyRegistryTypes.DefaultKey, privateKey);

            keyStore.KeyStoreEncryptAsync(privateKey, nodeSettings.NetworkType, KeyRegistryTypes.DefaultKey).ConfigureAwait(false).GetAwaiter()
            .GetResult();
        }
コード例 #4
0
 /// <summary>Gets the random peers.</summary>
 /// <param name="count">The count.</param>
 /// <returns></returns>
 private List <PeerId> GetRandomPeers(int count)
 {
     return(_peers
            .AsQueryable().Select(c => c.DocumentId).Shuffle().Take(count).Select(_peers.Get).Select(p => p.PeerId).ToList());
 }