ocirc_event.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (c) 2007-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file ocirc_event.h
  5. * \brief Header file for ocirc_event.c
  6. **/
  7. #ifndef TOR_OCIRC_EVENT_H
  8. #define TOR_OCIRC_EVENT_H
  9. #include <stdbool.h>
  10. #include "lib/cc/torint.h"
  11. /** Used to indicate the type of a circuit event passed to the controller.
  12. * The various types are defined in control-spec.txt */
  13. typedef enum circuit_status_event_t {
  14. CIRC_EVENT_LAUNCHED = 0,
  15. CIRC_EVENT_BUILT = 1,
  16. CIRC_EVENT_EXTENDED = 2,
  17. CIRC_EVENT_FAILED = 3,
  18. CIRC_EVENT_CLOSED = 4,
  19. } circuit_status_event_t;
  20. /** Message for origin circuit state update */
  21. typedef struct ocirc_state_msg_t {
  22. uint32_t gid; /**< global ID (only origin circuits have them) */
  23. int state; /**< new circuit state */
  24. bool onehop; /**< one-hop circuit? */
  25. } ocirc_state_msg_t;
  26. /**
  27. * Message when a channel gets associated to a circuit.
  28. *
  29. * This doesn't always correspond to something in circuitbuild.c
  30. * setting the n_chan field in the circuit. For some reason, if
  31. * circuit_handle_first_hop() launches a new circuit, it doesn't set
  32. * the n_chan field.
  33. */
  34. typedef struct ocirc_chan_msg_t {
  35. uint32_t gid; /**< global ID */
  36. uint64_t chan; /**< channel ID */
  37. bool onehop; /**< one-hop circuit? */
  38. } ocirc_chan_msg_t;
  39. /**
  40. * Message for origin circuit status event
  41. *
  42. * This contains information that ends up in CIRC control protocol events.
  43. */
  44. typedef struct ocirc_cevent_msg_t {
  45. uint32_t gid; /**< global ID */
  46. int evtype; /**< event type */
  47. int reason; /**< reason */
  48. bool onehop; /**< one-hop circuit? */
  49. } ocirc_cevent_msg_t;
  50. /** Discriminant values for origin circuit event message */
  51. typedef enum ocirc_msgtype_t {
  52. OCIRC_MSGTYPE_STATE,
  53. OCIRC_MSGTYPE_CHAN,
  54. OCIRC_MSGTYPE_CEVENT,
  55. } ocirc_msgtype_t;
  56. /** Discriminated union for the actual message */
  57. typedef struct ocirc_event_msg_t {
  58. int type;
  59. union {
  60. ocirc_state_msg_t state;
  61. ocirc_chan_msg_t chan;
  62. ocirc_cevent_msg_t cevent;
  63. } u;
  64. } ocirc_event_msg_t;
  65. /**
  66. * Receiver function pointer for origin circuit subscribers
  67. *
  68. * This function gets called synchronously by the publisher.
  69. **/
  70. typedef void (*ocirc_event_rcvr_t)(const ocirc_event_msg_t *);
  71. void ocirc_event_subscribe(ocirc_event_rcvr_t fn);
  72. #ifdef OCIRC_EVENT_PRIVATE
  73. void ocirc_event_publish(const ocirc_event_msg_t *msg);
  74. #endif
  75. #endif /* defined(TOR_OCIRC_EVENT_STATE_H) */