Esempio n. 1
0
        public void Report(bool accepted)
        {
            TryReset();

            if (!accepted)
            {
                _notAcceptedSinceLastCheck++;
                if (!IsDowngraded && _notAcceptedSinceLastCheck / _checkInterval.TotalSeconds > 10)
                {
                    if (_logger.IsDebug)
                    {
                        _logger.Debug($"Downgrading {_protocolHandler} due to tx flooding");
                    }
                    IsDowngraded = true;
                }
                else if (_notAcceptedSinceLastCheck / _checkInterval.TotalSeconds > 100)
                {
                    if (_logger.IsDebug)
                    {
                        _logger.Debug($"Disconnecting {_protocolHandler} due to tx flooding");
                    }
                    _protocolHandler.Disconnect(
                        DisconnectReason.UselessPeer,
                        $"tx flooding {_notAcceptedSinceLastCheck}/{_checkInterval.TotalSeconds > 100}");
                }
            }
        }
Esempio n. 2
0
        public void ReportNotAccepted()
        {
            DateTime now = DateTime.UtcNow;

            if (now >= _checkpoint + _checkInterval)
            {
                _checkpoint = now;
                _notAcceptedSinceLastCheck = 0;
            }

            _notAcceptedSinceLastCheck++;
            if (!IsDowngraded && _notAcceptedSinceLastCheck / _checkInterval.TotalSeconds > 10)
            {
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Downgrading {_protocolHandler} due to tx flooding");
                }
                IsDowngraded = true;
            }
            else if (_notAcceptedSinceLastCheck / _checkInterval.TotalSeconds > 100)
            {
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Disconnecting {_protocolHandler} due to tx flooding");
                }
                _protocolHandler.Disconnect(
                    DisconnectReason.UselessPeer,
                    $"tx flooding {_notAcceptedSinceLastCheck}/{_checkInterval.TotalSeconds > 100}");
            }
        }