control.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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-2013, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file control.h
  8. * \brief Header file for control.c.
  9. **/
  10. #ifndef TOR_CONTROL_H
  11. #define TOR_CONTROL_H
  12. void control_update_global_event_mask(void);
  13. void control_adjust_event_log_severity(void);
  14. void control_ports_write_to_file(void);
  15. /** Log information about the connection <b>conn</b>, protecting it as with
  16. * CONN_LOG_PROTECT. Example:
  17. *
  18. * LOG_FN_CONN(conn, (LOG_DEBUG, "Socket %d wants to write", conn->s));
  19. **/
  20. #define LOG_FN_CONN(conn, args) \
  21. CONN_LOG_PROTECT(conn, log_fn args)
  22. int connection_control_finished_flushing(control_connection_t *conn);
  23. int connection_control_reached_eof(control_connection_t *conn);
  24. void connection_control_closed(control_connection_t *conn);
  25. int connection_control_process_inbuf(control_connection_t *conn);
  26. #define EVENT_AUTHDIR_NEWDESCS 0x000D
  27. #define EVENT_NS 0x000F
  28. int control_event_is_interesting(int event);
  29. int control_event_circuit_status(origin_circuit_t *circ,
  30. circuit_status_event_t e, int reason);
  31. int control_event_circuit_purpose_changed(origin_circuit_t *circ,
  32. int old_purpose);
  33. int control_event_circuit_cannibalized(origin_circuit_t *circ,
  34. int old_purpose,
  35. const struct timeval *old_tv_created);
  36. int control_event_stream_status(entry_connection_t *conn,
  37. stream_status_event_t e,
  38. int reason);
  39. int control_event_or_conn_status(or_connection_t *conn,
  40. or_conn_status_event_t e, int reason);
  41. int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written);
  42. int control_event_stream_bandwidth(edge_connection_t *edge_conn);
  43. int control_event_stream_bandwidth_used(void);
  44. void control_event_logmsg(int severity, uint32_t domain, const char *msg);
  45. int control_event_descriptors_changed(smartlist_t *routers);
  46. int control_event_address_mapped(const char *from, const char *to,
  47. time_t expires, const char *error,
  48. const int cached);
  49. int control_event_or_authdir_new_descriptor(const char *action,
  50. const char *desc,
  51. size_t desclen,
  52. const char *msg);
  53. int control_event_my_descriptor_changed(void);
  54. int control_event_networkstatus_changed(smartlist_t *statuses);
  55. int control_event_newconsensus(const networkstatus_t *consensus);
  56. int control_event_networkstatus_changed_single(const routerstatus_t *rs);
  57. int control_event_general_status(int severity, const char *format, ...)
  58. CHECK_PRINTF(2,3);
  59. int control_event_client_status(int severity, const char *format, ...)
  60. CHECK_PRINTF(2,3);
  61. int control_event_server_status(int severity, const char *format, ...)
  62. CHECK_PRINTF(2,3);
  63. int control_event_guard(const char *nickname, const char *digest,
  64. const char *status);
  65. int control_event_conf_changed(const smartlist_t *elements);
  66. int control_event_buildtimeout_set(buildtimeout_set_event_t type,
  67. const char *args);
  68. int control_event_signal(uintptr_t signal);
  69. int init_control_cookie_authentication(int enabled);
  70. smartlist_t *decode_hashed_passwords(config_line_t *passwords);
  71. void disable_control_logging(void);
  72. void enable_control_logging(void);
  73. void monitor_owning_controller_process(const char *process_spec);
  74. void control_event_bootstrap(bootstrap_status_t status, int progress);
  75. MOCK_DECL(void, control_event_bootstrap_problem,(const char *warn,
  76. int reason));
  77. void control_event_clients_seen(const char *controller_str);
  78. void control_event_transport_launched(const char *mode,
  79. const char *transport_name,
  80. tor_addr_t *addr, uint16_t port);
  81. void control_free_all(void);
  82. #ifdef CONTROL_PRIVATE
  83. /* Recognized asynchronous event types. It's okay to expand this list
  84. * because it is used both as a list of v0 event types, and as indices
  85. * into the bitfield to determine which controllers want which events.
  86. */
  87. #define EVENT_MIN_ 0x0001
  88. #define EVENT_CIRCUIT_STATUS 0x0001
  89. #define EVENT_STREAM_STATUS 0x0002
  90. #define EVENT_OR_CONN_STATUS 0x0003
  91. #define EVENT_BANDWIDTH_USED 0x0004
  92. #define EVENT_CIRCUIT_STATUS_MINOR 0x0005
  93. #define EVENT_NEW_DESC 0x0006
  94. #define EVENT_DEBUG_MSG 0x0007
  95. #define EVENT_INFO_MSG 0x0008
  96. #define EVENT_NOTICE_MSG 0x0009
  97. #define EVENT_WARN_MSG 0x000A
  98. #define EVENT_ERR_MSG 0x000B
  99. #define EVENT_ADDRMAP 0x000C
  100. /* Exposed above */
  101. // #define EVENT_AUTHDIR_NEWDESCS 0x000D
  102. #define EVENT_DESCCHANGED 0x000E
  103. /* Exposed above */
  104. // #define EVENT_NS 0x000F
  105. #define EVENT_STATUS_CLIENT 0x0010
  106. #define EVENT_STATUS_SERVER 0x0011
  107. #define EVENT_STATUS_GENERAL 0x0012
  108. #define EVENT_GUARD 0x0013
  109. #define EVENT_STREAM_BANDWIDTH_USED 0x0014
  110. #define EVENT_CLIENTS_SEEN 0x0015
  111. #define EVENT_NEWCONSENSUS 0x0016
  112. #define EVENT_BUILDTIMEOUT_SET 0x0017
  113. #define EVENT_SIGNAL 0x0018
  114. #define EVENT_CONF_CHANGED 0x0019
  115. #define EVENT_TRANSPORT_LAUNCHED 0x0020
  116. #define EVENT_MAX_ 0x0020
  117. /* If EVENT_MAX_ ever hits 0x0040, we need to make the mask into a
  118. * different structure. */
  119. /* Used only by control.c and test.c */
  120. STATIC size_t write_escaped_data(const char *data, size_t len, char **out);
  121. STATIC size_t read_escaped_data(const char *data, size_t len, char **out);
  122. /** Flag for event_format_t. Indicates that we should use the one standard
  123. format. (Other formats previous existed, and are now deprecated)
  124. */
  125. #define ALL_FORMATS 1
  126. /** Bit field of flags to select how to format a controller event. Recognized
  127. * flag is ALL_FORMATS. */
  128. typedef int event_format_t;
  129. #ifdef TOR_UNIT_TESTS
  130. MOCK_DECL(STATIC void,
  131. send_control_event_string,(uint16_t event, event_format_t which,
  132. const char *msg));
  133. void control_testing_set_global_event_mask(uint64_t mask);
  134. #endif
  135. #endif
  136. #endif