Path: blob/master/lib/msf/core/exploit/retry.rb
19848 views
module Msf::Exploit::Retry1# Retry the block until it returns a truthy value. Each iteration attempt will2# be performed with an exponential backoff. If the timeout period surpasses,3# nil is returned.4#5# @param Integer timeout the number of seconds to wait before the operation times out6# @return the truthy value of the block is returned or nil if it timed out7def retry_until_truthy(timeout:)8start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)9ending_time = start_time + timeout10retry_count = 011while Process.clock_gettime(Process::CLOCK_MONOTONIC, :second) < ending_time12result = yield13return result if result1415retry_count += 116remaining_time_budget = ending_time - Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)17break if remaining_time_budget <= 01819delay = 2**retry_count20if delay >= remaining_time_budget21delay = remaining_time_budget22vprint_status("Final attempt. Sleeping for the remaining #{delay} seconds out of total timeout #{timeout}")23else24vprint_status("Sleeping for #{delay} seconds before attempting again")25end2627sleep delay28end2930nil31end32end333435