Skip to content

ryu_ldn::network::ReconnectManager

Reconnection manager with exponential backoff.

Manages retry timing for network reconnection attempts. Provides exponential backoff with optional jitter to spread out retry attempts and avoid overwhelming the server.State Diagram[Initial]||()v[Waiting]<—+|||()v|[]---+||()v[Initial]classryu__ldn_1_1network_1_1ReconnectManager_1

Type: ReconnectConfig

Configuration parameters.

Type: uint32_t

Number of retries since reset.

Type: uint32_t

Current calculated delay.

void ReconnectManager()

Constructor with default configuration.

Creates a reconnect manager with default settings:Initializes the manager with default settings suitable for most reconnection scenarios:The retry count starts at 0 and the initial delay is pre-calculated.

void ReconnectManager(const& config)

Constructor with custom configuration.

Allows customizing all backoff parameters for specific use cases. For example, a more aggressive retry strategy might use:configCustom configuration parametersparam

Parameters:

  • config (const&)
uint32_t get_next_delay_ms()

Get the delay for the next retry attempt.

Calculates the delay based on the current retry count and configuration. Does NOT increment the retry counter - callafter a failed attempt.Returns the pre-calculated delay based on the current retry count. This method is const and does not modify state - callafter a failed connection attempt to increment the counter.Delay in milliseconds before the next retry should be attemptedreturn

Returns: uint32_t

uint32_t get_next_delay_ms_with_jitter(uint32_t seed)

Get delay with jitter applied.

Get delay with random jitter applied.Same asbut applies random jitter based on the configured jitter percentage.Adds random variation to the base delay to prevent thundering herd. The jitter is calculated using a simple hash of the provided seed to generate pseudo-random variation within the configured range.For example, with 10% jitter and 1000ms base delay:seedRandom seed (e.g., system tick count, time)paramDelay in milliseconds with jitter appliedreturn

Parameters:

  • seed (uint32_t)

Returns: uint32_t

RetryResult should_retry()

Check if retry should be attempted.

Checks whether a retry should be attempted based on the maximum retry configuration.Evaluates whether a retry attempt is permitted based on the maximum retry configuration. If max_retries is 0 (default), infinite retries are allowed.if retry is permittedreturnif limit exceededreturn

Returns: RetryResult

void record_failure()

Record a connection failure.

Increments the retry counter, which increases the backoff delay for the next attempt.Increments the retry counter and recalculates the delay for the next attempt. Call this method after each failed connection attempt to increase the backoff delay.The delay will grow exponentially until reaching max_delay_ms, after which it stays constant.

void reset()

Reset the manager after successful connection.

Resets the retry counter to zero, so the next failure will start with the initial delay again.Resets the retry counter to zero, so the next failure will start the backoff sequence from the beginning. Call this method after a successful connection is established.

uint32_t get_retry_count()

Get current retry attempt count.

Number of retries since last resetreturn

Returns: uint32_t

uint32_t get_current_delay_ms()

Get current calculated delay (without jitter)

Current delay in millisecondsreturn

Returns: uint32_t

const& get_config()

Get the configuration.

Reference to current configurationreturn

Returns: const&

void set_config(const& config)

Update configuration.

Update configuration at runtime.Allows changing configuration at runtime. Does NOT reset the retry counter.Allows changing the backoff parameters without creating a new manager instance. The retry count is preserved, but the delay is recalculated with the new parameters.configNew configuration to useparam

Parameters:

  • config (const&)
void calculate_delay()

Calculate delay for current retry count.

Calculate delay based on current retry count.Internal helper that computes the delay based on the exponential backoff formula.Implements the exponential backoff formula:The calculation is done using integer arithmetic to avoid floating-point operations on embedded systems. Overflow is prevented by checking against max_delay before multiplying.Special case: When retry_count is 0 (first attempt), the delay is set to initial_delay_ms.