dlstatus.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file dlstatus.h
  8. * \brief Header file for dlstatus.c.
  9. **/
  10. #ifndef TOR_DLSTATUS_H
  11. #define TOR_DLSTATUS_H
  12. time_t download_status_increment_failure(download_status_t *dls,
  13. int status_code, const char *item,
  14. int server, time_t now);
  15. time_t download_status_increment_attempt(download_status_t *dls,
  16. const char *item, time_t now);
  17. /** Increment the failure count of the download_status_t <b>dls</b>, with
  18. * the optional status code <b>sc</b>. */
  19. #define download_status_failed(dls, sc) \
  20. download_status_increment_failure((dls), (sc), NULL, \
  21. dir_server_mode(get_options()), \
  22. time(NULL))
  23. void download_status_reset(download_status_t *dls);
  24. int download_status_is_ready(download_status_t *dls, time_t now);
  25. time_t download_status_get_next_attempt_at(const download_status_t *dls);
  26. void download_status_mark_impossible(download_status_t *dl);
  27. int download_status_get_n_failures(const download_status_t *dls);
  28. int download_status_get_n_attempts(const download_status_t *dls);
  29. #ifdef DLSTATUS_PRIVATE
  30. STATIC int download_status_schedule_get_delay(download_status_t *dls,
  31. int min_delay,
  32. time_t now);
  33. STATIC int find_dl_min_delay(const download_status_t *dls,
  34. const or_options_t *options);
  35. STATIC int next_random_exponential_delay(int delay,
  36. int base_delay);
  37. STATIC void next_random_exponential_delay_range(int *low_bound_out,
  38. int *high_bound_out,
  39. int delay,
  40. int base_delay);
  41. /* no more than quadruple the previous delay (multiplier + 1) */
  42. #define DIR_DEFAULT_RANDOM_MULTIPLIER (3)
  43. /* no more than triple the previous delay */
  44. #define DIR_TEST_NET_RANDOM_MULTIPLIER (2)
  45. #endif
  46. #endif /* !defined(TOR_DLSTATUS_H) */