Sha256: 4f792c4f62b91736d41abebdd2aae45e93d5a3d25ceab47b09ca07436e0dd00b

Contents?: true

Size: 1.36 KB

Versions: 9

Compression:

Stored size: 1.36 KB

Contents

# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

module Contrast
  module Agent
    module Reporting
      # Keeps track of the state of connections to TeamServer.
      class ConnectionStatus
        def initialize
          @last_success = nil
          @last_failure = nil
          @startup_messages_sent = false
          @_startup_server_message_sent = false
        end

        # Whether we have sent startup message to TeamServer. True after successfully sending startup messages to
        # TeamServer and reset to false if we lose connection.
        #
        # @return [Boolean]
        def startup_messages_sent?
          @startup_messages_sent
        end

        # The last message sent was successful or not
        #
        # @return [Boolean]
        def connected?
          @last_success && (@last_failure.nil? || @last_success > @last_failure)
        end

        # The current state of the TeamServer is active with a successful message sent
        def success!
          @startup_messages_sent = true
          @last_success = Time.now.to_f
        end

        # The TeamServer may be in some sort of error state
        def failure!
          @startup_messages_sent = false
          @last_failure = Time.now.to_f
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
contrast-agent-7.1.0 lib/contrast/agent/reporting/connection_status.rb
contrast-agent-7.0.0 lib/contrast/agent/reporting/connection_status.rb
contrast-agent-6.15.3 lib/contrast/agent/reporting/connection_status.rb
contrast-agent-6.15.2 lib/contrast/agent/reporting/connection_status.rb
contrast-agent-6.15.1 lib/contrast/agent/reporting/connection_status.rb
contrast-agent-6.15.0 lib/contrast/agent/reporting/connection_status.rb
contrast-agent-6.14.0 lib/contrast/agent/reporting/connection_status.rb
contrast-agent-6.13.0 lib/contrast/agent/reporting/connection_status.rb
contrast-agent-6.12.0 lib/contrast/agent/reporting/connection_status.rb