hibernate.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 hibernate.h
  8. * \brief Header file for hibernate.c.
  9. **/
  10. #ifndef TOR_HIBERNATE_H
  11. #define TOR_HIBERNATE_H
  12. #include "lib/testsupport/testsupport.h"
  13. int accounting_parse_options(const or_options_t *options, int validate_only);
  14. MOCK_DECL(int, accounting_is_enabled, (const or_options_t *options));
  15. int accounting_get_interval_length(void);
  16. MOCK_DECL(time_t, accounting_get_end_time, (void));
  17. void configure_accounting(time_t now);
  18. uint64_t get_accounting_bytes(void);
  19. void accounting_run_housekeeping(time_t now);
  20. void accounting_add_bytes(size_t n_read, size_t n_written, int seconds);
  21. int accounting_record_bandwidth_usage(time_t now, or_state_t *state);
  22. void hibernate_begin_shutdown(void);
  23. MOCK_DECL(int, we_are_hibernating, (void));
  24. MOCK_DECL(int, we_are_fully_hibernating,(void));
  25. void consider_hibernation(time_t now);
  26. int getinfo_helper_accounting(control_connection_t *conn,
  27. const char *question, char **answer,
  28. const char **errmsg);
  29. uint64_t get_accounting_max_total(void);
  30. void accounting_free_all(void);
  31. #ifdef HIBERNATE_PRIVATE
  32. /** Possible values of hibernate_state */
  33. typedef enum {
  34. /** We are running normally. */
  35. HIBERNATE_STATE_LIVE=1,
  36. /** We're trying to shut down cleanly, and we'll kill all active connections
  37. * at shutdown_time. */
  38. HIBERNATE_STATE_EXITING=2,
  39. /** We're running low on allocated bandwidth for this period, so we won't
  40. * accept any new connections. */
  41. HIBERNATE_STATE_LOWBANDWIDTH=3,
  42. /** We are hibernating, and we won't wake up till there's more bandwidth to
  43. * use. */
  44. HIBERNATE_STATE_DORMANT=4,
  45. /** We start out in state default, which means we havent decided which state
  46. * we're in. */
  47. HIBERNATE_STATE_INITIAL=5
  48. } hibernate_state_t;
  49. #ifdef TOR_UNIT_TESTS
  50. void hibernate_set_state_for_testing_(hibernate_state_t newstate);
  51. #endif
  52. #endif /* defined(HIBERNATE_PRIVATE) */
  53. #endif /* !defined(TOR_HIBERNATE_H) */