orconn_event.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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-2019, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file orconn_event.h
  8. * \brief Header file for orconn_event.c
  9. *
  10. * The OR_CONN_STATE_* symbols are here to make it easier for
  11. * subscribers to make decisions based on the messages that they
  12. * receive.
  13. **/
  14. #ifndef TOR_ORCONN_EVENT_H
  15. #define TOR_ORCONN_EVENT_H
  16. /**
  17. * @name States of OR connections
  18. *
  19. * These must be in a partial ordering such that usually no OR
  20. * connection will transition from a higher-numbered state to a
  21. * lower-numbered one. Code such as bto_update_best() depends on this
  22. * ordering to determine the best state it's seen so far.
  23. * @{ */
  24. #define OR_CONN_STATE_MIN_ 1
  25. /** State for a connection to an OR: waiting for connect() to finish. */
  26. #define OR_CONN_STATE_CONNECTING 1
  27. /** State for a connection to an OR: waiting for proxy handshake to complete */
  28. #define OR_CONN_STATE_PROXY_HANDSHAKING 2
  29. /** State for an OR connection client: SSL is handshaking, not done
  30. * yet. */
  31. #define OR_CONN_STATE_TLS_HANDSHAKING 3
  32. /** State for a connection to an OR: We're doing a second SSL handshake for
  33. * renegotiation purposes. (V2 handshake only.) */
  34. #define OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING 4
  35. /** State for a connection at an OR: We're waiting for the client to
  36. * renegotiate (to indicate a v2 handshake) or send a versions cell (to
  37. * indicate a v3 handshake) */
  38. #define OR_CONN_STATE_TLS_SERVER_RENEGOTIATING 5
  39. /** State for an OR connection: We're done with our SSL handshake, we've done
  40. * renegotiation, but we haven't yet negotiated link protocol versions and
  41. * sent a netinfo cell. */
  42. #define OR_CONN_STATE_OR_HANDSHAKING_V2 6
  43. /** State for an OR connection: We're done with our SSL handshake, but we
  44. * haven't yet negotiated link protocol versions, done a V3 handshake, and
  45. * sent a netinfo cell. */
  46. #define OR_CONN_STATE_OR_HANDSHAKING_V3 7
  47. /** State for an OR connection: Ready to send/receive cells. */
  48. #define OR_CONN_STATE_OPEN 8
  49. #define OR_CONN_STATE_MAX_ 8
  50. /** @} */
  51. /** Used to indicate the type of an OR connection event passed to the
  52. * controller. The various types are defined in control-spec.txt */
  53. typedef enum or_conn_status_event_t {
  54. OR_CONN_EVENT_LAUNCHED = 0,
  55. OR_CONN_EVENT_CONNECTED = 1,
  56. OR_CONN_EVENT_FAILED = 2,
  57. OR_CONN_EVENT_CLOSED = 3,
  58. OR_CONN_EVENT_NEW = 4,
  59. } or_conn_status_event_t;
  60. /** Discriminant values for orconn event message */
  61. typedef enum orconn_msgtype_t {
  62. ORCONN_MSGTYPE_STATE,
  63. ORCONN_MSGTYPE_STATUS,
  64. } orconn_msgtype_t;
  65. /**
  66. * Message for orconn state update
  67. *
  68. * This contains information about internal state changes of
  69. * or_connection_t objects. The chan and proxy_type fields are
  70. * additional information that a subscriber may need to make
  71. * decisions.
  72. **/
  73. typedef struct orconn_state_msg_t {
  74. uint64_t gid; /**< connection's global ID */
  75. uint64_t chan; /**< associated channel ID */
  76. int proxy_type; /**< connection's proxy type */
  77. uint8_t state; /**< new connection state */
  78. } orconn_state_msg_t;
  79. /**
  80. * Message for orconn status event
  81. *
  82. * This contains information that ends up in ORCONN control protocol
  83. * events.
  84. **/
  85. typedef struct orconn_status_msg_t {
  86. uint64_t gid; /**< connection's global ID */
  87. int status; /**< or_conn_status_event_t */
  88. int reason; /**< reason */
  89. } orconn_status_msg_t;
  90. /** Discriminated union for the actual message */
  91. typedef struct orconn_event_msg_t {
  92. int type;
  93. union {
  94. orconn_state_msg_t state;
  95. orconn_status_msg_t status;
  96. } u;
  97. } orconn_event_msg_t;
  98. /**
  99. * Receiver function pointer for OR subscribers
  100. *
  101. * This function gets called synchronously by the publisher.
  102. **/
  103. typedef void (*orconn_event_rcvr_t)(const orconn_event_msg_t *);
  104. void orconn_event_subscribe(orconn_event_rcvr_t);
  105. #ifdef ORCONN_EVENT_PRIVATE
  106. void orconn_event_publish(const orconn_event_msg_t *);
  107. #endif
  108. #endif /* defined(TOR_ORCONN_EVENT_H) */