Пример #1
0
        public async Task CheckPeersHealthAsync()
        {
            foreach (var peer in _peerPool.GetPeers(true))
            {
                Logger.LogDebug($"Health checking: {peer}");

                if (peer.IsInvalid)
                {
                    _peerPool.RemovePeer(peer.Info.Pubkey);
                    await peer.DisconnectAsync(false);

                    Logger.LogInformation($"Remove invalid peer: {peer}");
                    continue;
                }

                try
                {
                    await peer.CheckHealthAsync();
                }
                catch (NetworkException ex)
                {
                    if (ex.ExceptionType == NetworkExceptionType.Unrecoverable ||
                        ex.ExceptionType == NetworkExceptionType.PeerUnstable)
                    {
                        Logger.LogInformation(ex, $"Removing unhealthy peer {peer}.");
                        await _networkServer.TrySchedulePeerReconnectionAsync(peer);
                    }
                }
            }
        }
Пример #2
0
        public async Task TrySchedulePeerReconnection_Test()
        {
            var peer   = AddPeerToPool();
            var result = await _networkServer.TrySchedulePeerReconnectionAsync(peer);

            result.ShouldBeTrue();

            _reconnectionService.GetReconnectingPeer(peer.RemoteEndpoint.ToString()).ShouldNotBeNull();
        }
Пример #3
0
        public async Task SendHealthChecksAsync()
        {
            foreach (var peer in _peerPool.GetPeers())
            {
                Logger.LogDebug($"Health checking: {peer}");

                try
                {
                    await peer.CheckHealthAsync();
                }
                catch (NetworkException ex)
                {
                    if (ex.ExceptionType == NetworkExceptionType.Unrecoverable)
                    {
                        Logger.LogError(ex, $"Removing unhealthy peer {peer}.");
                        await _networkServer.TrySchedulePeerReconnectionAsync(peer);
                    }
                }
            }
        }
Пример #4
0
        public async Task CheckPeersHealthAsync()
        {
            foreach (var peer in _peerPool.GetPeers(true))
            {
                Logger.LogDebug($"Health checking: {peer}");

                try
                {
                    await peer.PingAsync();
                }
                catch (NetworkException ex)
                {
                    if (ex.ExceptionType == NetworkExceptionType.Unrecoverable ||
                        ex.ExceptionType == NetworkExceptionType.PeerUnstable)
                    {
                        Logger.LogInformation(ex, $"Removing unhealthy peer {peer}.");
                        await _networkServer.TrySchedulePeerReconnectionAsync(peer);
                    }
                }
            }
        }