download_status_st.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #ifndef DOWNLOAD_STATUS_ST_H
  7. #define DOWNLOAD_STATUS_ST_H
  8. /** Information about our plans for retrying downloads for a downloadable
  9. * directory object.
  10. * Each type of downloadable directory object has a corresponding retry
  11. * <b>schedule</b>, which can be different depending on whether the object is
  12. * being downloaded from an authority or a mirror (<b>want_authority</b>).
  13. * <b>next_attempt_at</b> contains the next time we will attempt to download
  14. * the object.
  15. * For schedules that <b>increment_on</b> failure, <b>n_download_failures</b>
  16. * is used to determine the position in the schedule. (Each schedule is a
  17. * smartlist of integer delays, parsed from a CSV option.) Every time a
  18. * connection attempt fails, <b>n_download_failures</b> is incremented,
  19. * the new delay value is looked up from the schedule, and
  20. * <b>next_attempt_at</b> is set delay seconds from the time the previous
  21. * connection failed. Therefore, at most one failure-based connection can be
  22. * in progress for each download_status_t.
  23. * For schedules that <b>increment_on</b> attempt, <b>n_download_attempts</b>
  24. * is used to determine the position in the schedule. Every time a
  25. * connection attempt is made, <b>n_download_attempts</b> is incremented,
  26. * the new delay value is looked up from the schedule, and
  27. * <b>next_attempt_at</b> is set delay seconds from the time the previous
  28. * connection was attempted. Therefore, multiple concurrent attempted-based
  29. * connections can be in progress for each download_status_t.
  30. * After an object is successfully downloaded, any other concurrent connections
  31. * are terminated. A new schedule which starts at position 0 is used for
  32. * subsequent downloads of the same object.
  33. */
  34. struct download_status_t {
  35. time_t next_attempt_at; /**< When should we try downloading this object
  36. * again? */
  37. uint8_t n_download_failures; /**< Number of failed downloads of the most
  38. * recent object, since the last success. */
  39. uint8_t n_download_attempts; /**< Number of (potentially concurrent) attempts
  40. * to download the most recent object, since
  41. * the last success. */
  42. download_schedule_bitfield_t schedule : 8; /**< What kind of object is being
  43. * downloaded? This determines the
  44. * schedule used for the download.
  45. */
  46. download_want_authority_bitfield_t want_authority : 1; /**< Is the download
  47. * happening from an authority
  48. * or a mirror? This determines
  49. * the schedule used for the
  50. * download. */
  51. download_schedule_increment_bitfield_t increment_on : 1; /**< does this
  52. * schedule increment on each attempt,
  53. * or after each failure? */
  54. uint8_t last_backoff_position; /**< number of attempts/failures, depending
  55. * on increment_on, when we last recalculated
  56. * the delay. Only updated if backoff
  57. * == 1. */
  58. int last_delay_used; /**< last delay used for random exponential backoff;
  59. * only updated if backoff == 1 */
  60. };
  61. #endif