Tor  0.4.7.0-alpha-dev
Macros | Functions
dlstatus.c File Reference

Track status and retry schedule of a downloadable object. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "feature/client/entrynodes.h"
#include "feature/dirclient/dlstatus.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/relay/routermode.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "feature/dirclient/download_status_st.h"

Go to the source code of this file.

Functions

STATIC int find_dl_min_delay (const download_status_t *dls, const or_options_t *options)
 
STATIC void next_random_exponential_delay_range (int *low_bound_out, int *high_bound_out, int delay, int base_delay)
 
STATIC int next_random_exponential_delay (int delay, int base_delay)
 
STATIC int download_status_schedule_get_delay (download_status_t *dls, int min_delay, time_t now)
 
static void download_status_log_helper (const char *item, int was_schedule_incremented, const char *increment_action, const char *not_incremented_response, uint8_t dls_n_download_increments, int increment, time_t dls_next_attempt_at, time_t now)
 
time_t download_status_increment_failure (download_status_t *dls, int status_code, const char *item, int server, time_t now)
 
time_t download_status_increment_attempt (download_status_t *dls, const char *item, time_t now)
 
static time_t download_status_get_initial_delay_from_now (const download_status_t *dls)
 
void download_status_reset (download_status_t *dls)
 
int download_status_is_ready (download_status_t *dls, time_t now)
 
void download_status_mark_impossible (download_status_t *dl)
 
int download_status_get_n_failures (const download_status_t *dls)
 
int download_status_get_n_attempts (const download_status_t *dls)
 
time_t download_status_get_next_attempt_at (const download_status_t *dls)
 

Detailed Description

Track status and retry schedule of a downloadable object.

Definition in file dlstatus.c.

Function Documentation

◆ download_status_get_n_attempts()

int download_status_get_n_attempts ( const download_status_t dls)

Return the number of attempts to download dls since the last success (if any). This can differ from download_status_get_n_failures() due to outstanding concurrent attempts.

Definition at line 411 of file dlstatus.c.

◆ download_status_get_n_failures()

int download_status_get_n_failures ( const download_status_t dls)

Return the number of failures on dls since the last success (if any).

Definition at line 402 of file dlstatus.c.

Referenced by authority_cert_dl_looks_uncertain().

◆ download_status_get_next_attempt_at()

time_t download_status_get_next_attempt_at ( const download_status_t dls)

Return the next time to attempt to download dls.

Definition at line 418 of file dlstatus.c.

Referenced by download_status_is_ready().

◆ download_status_increment_attempt()

time_t download_status_increment_attempt ( download_status_t dls,
const char *  item,
time_t  now 
)

Determine when the next download attempt should be made when using an attempt-based (potentially concurrent) download schedule. Called when an attempt to download dls is being initiated. Increment the attempt count and set dls->next_attempt_at to an appropriate time in the future and return it. If dls->increment_on is DL_SCHED_INCREMENT_FAILURE, don't increment the attempts, and return a time in the far future (to avoid launching a concurrent attempt).

Definition at line 309 of file dlstatus.c.

◆ download_status_increment_failure()

time_t download_status_increment_failure ( download_status_t dls,
int  status_code,
const char *  item,
int  server,
time_t  now 
)

Determine when a failed download attempt should be retried. Called when an attempt to download dls has failed with HTTP status status_code. Increment the failure count (if the code indicates a real failure, or if we're a server) and set dls->next_attempt_at to an appropriate time in the future and return it. If dls->increment_on is DL_SCHED_INCREMENT_ATTEMPT, increment the failure count, and return a time in the far future for the next attempt (to avoid an immediate retry).

Definition at line 250 of file dlstatus.c.

◆ download_status_is_ready()

int download_status_is_ready ( download_status_t dls,
time_t  now 
)

Return true iff, as of now, the resource tracked by dls is ready to get its download reattempted.

Definition at line 381 of file dlstatus.c.

Referenced by download_status_is_ready_by_sk_in_cl(), and fetch_bridge_descriptors().

◆ download_status_mark_impossible()

void download_status_mark_impossible ( download_status_t dl)

Mark dl as never downloadable.

Definition at line 393 of file dlstatus.c.

Referenced by fetch_bridge_descriptors(), and launch_direct_bridge_descriptor_fetch().

◆ download_status_reset()

void download_status_reset ( download_status_t dls)

Reset dls so that it will be considered downloadable immediately, and/or to show that we don't need it anymore.

Must be called to initialise a download schedule, otherwise the zeroth item in the schedule will never be used.

(We find the zeroth element of the download schedule, and set next_attempt_at to be the appropriate offset from 'now'. In most cases this means setting it to 'now', so the item will be immediately downloadable; when using authorities with fallbacks, there is a few seconds' delay.)

Definition at line 364 of file dlstatus.c.

Referenced by download_status_increment_attempt(), download_status_increment_failure(), download_status_is_ready(), and learned_bridge_descriptor().

◆ download_status_schedule_get_delay()

STATIC int download_status_schedule_get_delay ( download_status_t dls,
int  min_delay,
time_t  now 
)

Find the current delay for dls based on min_delay.

This function sets dls->next_attempt_at based on now, and returns the delay. Helper for download_status_increment_failure and download_status_increment_attempt.

Definition at line 154 of file dlstatus.c.

◆ find_dl_min_delay()

STATIC int find_dl_min_delay ( const download_status_t dls,
const or_options_t options 
)

Decide which download schedule we want to use based on descriptor type in dls and options.

Then, return the initial delay for that download schedule, in seconds.

Helper function for download_status_increment_failure(), download_status_reset(), and download_status_increment_attempt().

Definition at line 32 of file dlstatus.c.

◆ next_random_exponential_delay()

STATIC int next_random_exponential_delay ( int  delay,
int  base_delay 
)

Advance one delay step. The algorithm will generate a random delay, such that each failure is possibly (random) longer than the ones before.

We then clamp that value to be no larger than max_delay, and return it.

The base_delay parameter is lowest possible delay time (can't be zero); the backoff_position parameter is the number of times we've generated a delay; and the delay argument is the most recently used delay.

Definition at line 130 of file dlstatus.c.

◆ next_random_exponential_delay_range()

STATIC void next_random_exponential_delay_range ( int *  low_bound_out,
int *  high_bound_out,
int  delay,
int  base_delay 
)

As next_random_exponential_delay() below, but does not compute a random value. Instead, compute the range of values that next_random_exponential_delay() should use when computing its random value. Store the low bound into *low_bound_out, and the high bound into *high_bound_out. Guarantees that the low bound is strictly less than the high bound.

Definition at line 100 of file dlstatus.c.