orconn_event.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #include "lib/pubsub/pubsub.h"
  17. /**
  18. * @name States of OR connections
  19. *
  20. * These must be in a partial ordering such that usually no OR
  21. * connection will transition from a higher-numbered state to a
  22. * lower-numbered one. Code such as bto_update_best() depends on this
  23. * ordering to determine the best state it's seen so far.
  24. * @{ */
  25. #define OR_CONN_STATE_MIN_ 1
  26. /** State for a connection to an OR: waiting for connect() to finish. */
  27. #define OR_CONN_STATE_CONNECTING 1
  28. /** State for a connection to an OR: waiting for proxy handshake to complete */
  29. #define OR_CONN_STATE_PROXY_HANDSHAKING 2
  30. /** State for an OR connection: SSL is handshaking, not done 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. /**
  61. * Message for orconn state update
  62. *
  63. * This contains information about internal state changes of
  64. * or_connection_t objects. The chan and proxy_type fields are
  65. * additional information that a subscriber may need to make
  66. * decisions.
  67. **/
  68. typedef struct orconn_state_msg_t {
  69. uint64_t gid; /**< connection's global ID */
  70. uint64_t chan; /**< associated channel ID */
  71. int proxy_type; /**< connection's proxy type */
  72. uint8_t state; /**< new connection state */
  73. } orconn_state_msg_t;
  74. DECLARE_MESSAGE(orconn_state, orconn_state, orconn_state_msg_t *);
  75. /**
  76. * Message for orconn status event
  77. *
  78. * This contains information that ends up in ORCONN control protocol
  79. * events.
  80. **/
  81. typedef struct orconn_status_msg_t {
  82. uint64_t gid; /**< connection's global ID */
  83. int status; /**< or_conn_status_event_t */
  84. int reason; /**< reason */
  85. } orconn_status_msg_t;
  86. DECLARE_MESSAGE(orconn_status, orconn_status, orconn_status_msg_t *);
  87. #ifdef ORCONN_EVENT_PRIVATE
  88. void orconn_state_publish(orconn_state_msg_t *);
  89. void orconn_status_publish(orconn_status_msg_t *);
  90. #endif
  91. #endif /* !defined(TOR_ORCONN_EVENT_H) */