예제 #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 PeerChallengeRequest(
                Substitute.For <ILogger>(),
                _peerClient,
                peerSettings,
                PeerChallengeTimeoutSeconds);

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

            _peerRepository.GetAll().Returns(peers);
            _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
        public override async Task StartAsync()
        {
            var observableChannel = await ChannelFactory.BuildChannelAsync(EventLoopGroupFactory, _peerSettings.BindAddress, _peerSettings.Port).ConfigureAwait(false);

            Channel = observableChannel.Channel;

            MessageStream = observableChannel.MessageStream;
            _messageHandlers.ToList()
            .ForEach(h => h.StartObserving(MessageStream));
            Discovery?.DiscoveryAsync();
            _healthChecker.Run();
        }