orconn_event.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 client: SSL is handshaking, not done
  31. * yet. */
  32. #define OR_CONN_STATE_TLS_HANDSHAKING 3
  33. /** State for a connection to an OR: We're doing a second SSL handshake for
  34. * renegotiation purposes. (V2 handshake only.) */
  35. #define OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING 4
  36. /** State for a connection at an OR: We're waiting for the client to
  37. * renegotiate (to indicate a v2 handshake) or send a versions cell (to
  38. * indicate a v3 handshake) */
  39. #define OR_CONN_STATE_TLS_SERVER_RENEGOTIATING 5
  40. /** State for an OR connection: We're done with our SSL handshake, we've done
  41. * renegotiation, but we haven't yet negotiated link protocol versions and
  42. * sent a netinfo cell. */
  43. #define OR_CONN_STATE_OR_HANDSHAKING_V2 6
  44. /** State for an OR connection: We're done with our SSL handshake, but we
  45. * haven't yet negotiated link protocol versions, done a V3 handshake, and
  46. * sent a netinfo cell. */
  47. #define OR_CONN_STATE_OR_HANDSHAKING_V3 7
  48. /** State for an OR connection: Ready to send/receive cells. */
  49. #define OR_CONN_STATE_OPEN 8
  50. #define OR_CONN_STATE_MAX_ 8
  51. /** @} */
  52. /** Used to indicate the type of an OR connection event passed to the
  53. * controller. The various types are defined in control-spec.txt */
  54. typedef enum or_conn_status_event_t {
  55. OR_CONN_EVENT_LAUNCHED = 0,
  56. OR_CONN_EVENT_CONNECTED = 1,
  57. OR_CONN_EVENT_FAILED = 2,
  58. OR_CONN_EVENT_CLOSED = 3,
  59. OR_CONN_EVENT_NEW = 4,
  60. } or_conn_status_event_t;
  61. /**
  62. * Message for orconn state update
  63. *
  64. * This contains information about internal state changes of
  65. * or_connection_t objects. The chan and proxy_type fields are
  66. * additional information that a subscriber may need to make
  67. * decisions.
  68. **/
  69. typedef struct orconn_state_msg_t {
  70. uint64_t gid; /**< connection's global ID */
  71. uint64_t chan; /**< associated channel ID */
  72. int proxy_type; /**< connection's proxy type */
  73. uint8_t state; /**< new connection state */
  74. } orconn_state_msg_t;
  75. DECLARE_MESSAGE(orconn_state, orconn_state, orconn_state_msg_t *);
  76. /**
  77. * Message for orconn status event
  78. *
  79. * This contains information that ends up in ORCONN control protocol
  80. * events.
  81. **/
  82. typedef struct orconn_status_msg_t {
  83. uint64_t gid; /**< connection's global ID */
  84. int status; /**< or_conn_status_event_t */
  85. int reason; /**< reason */
  86. } orconn_status_msg_t;
  87. DECLARE_MESSAGE(orconn_status, orconn_status, orconn_status_msg_t *);
  88. #ifdef ORCONN_EVENT_PRIVATE
  89. void orconn_state_publish(orconn_state_msg_t *);
  90. void orconn_status_publish(orconn_status_msg_t *);
  91. #endif
  92. #endif /* !defined(TOR_ORCONN_EVENT_H) */