btrack_orconn_cevent.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Copyright (c) 2007-2018, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file btrack_orconn_cevent.c
  5. * \brief Emit bootstrap status events for OR connections
  6. **/
  7. #include <stdbool.h>
  8. #include "core/or/or.h"
  9. #define BTRACK_ORCONN_PRIVATE
  10. #include "core/or/orconn_event.h"
  11. #include "feature/control/btrack_orconn.h"
  12. #include "feature/control/btrack_orconn_cevent.h"
  13. #include "feature/control/control.h"
  14. /**
  15. * Have we completed our first OR connection?
  16. *
  17. * Block display of application circuit progress until we do, to avoid
  18. * some misleading behavior of jumping to high progress.
  19. **/
  20. static bool bto_first_orconn = false;
  21. /**
  22. * Emit control events when we have updated our idea of the best state
  23. * that any OR connection has reached.
  24. **/
  25. void
  26. bto_cevent_anyconn(const bt_orconn_t *bto)
  27. {
  28. switch (bto->state) {
  29. case OR_CONN_STATE_CONNECTING:
  30. case OR_CONN_STATE_PROXY_HANDSHAKING:
  31. /* XXX This isn't quite right, because this isn't necessarily a
  32. directory server we're talking to, but we'll improve the
  33. bootstrap tags and messages later */
  34. control_event_bootstrap(BOOTSTRAP_STATUS_CONN_DIR, 0);
  35. break;
  36. case OR_CONN_STATE_TLS_HANDSHAKING:
  37. /* Here we should report a connection completed (TCP or proxied),
  38. if we had the states */
  39. break;
  40. case OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING:
  41. case OR_CONN_STATE_OR_HANDSHAKING_V2:
  42. case OR_CONN_STATE_OR_HANDSHAKING_V3:
  43. /* XXX Again, this isn't quite right, because it's not necessarily
  44. a directory server we're talking to. */
  45. control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE_DIR, 0);
  46. break;
  47. case OR_CONN_STATE_OPEN:
  48. /* Unblock directory progress display */
  49. control_event_boot_first_orconn();
  50. /* Unblock apconn progress display */
  51. bto_first_orconn = true;
  52. break;
  53. default:
  54. break;
  55. }
  56. }
  57. /**
  58. * Emit control events when we have updated our idea of the best state
  59. * that any application circuit OR connection has reached.
  60. **/
  61. void
  62. bto_cevent_apconn(const bt_orconn_t *bto)
  63. {
  64. if (!bto_first_orconn)
  65. return;
  66. switch (bto->state) {
  67. case OR_CONN_STATE_CONNECTING:
  68. case OR_CONN_STATE_PROXY_HANDSHAKING:
  69. control_event_bootstrap(BOOTSTRAP_STATUS_CONN_OR, 0);
  70. break;
  71. case OR_CONN_STATE_TLS_HANDSHAKING:
  72. /* Here we should report a connection completed (TCP or proxied) */
  73. break;
  74. case OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING:
  75. case OR_CONN_STATE_OR_HANDSHAKING_V2:
  76. case OR_CONN_STATE_OR_HANDSHAKING_V3:
  77. control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE_OR, 0);
  78. break;
  79. case OR_CONN_STATE_OPEN:
  80. /* XXX Not quite right, because it implictly reports the next
  81. state, but we'll improve it later. */
  82. control_event_bootstrap(BOOTSTRAP_STATUS_CIRCUIT_CREATE, 0);
  83. default:
  84. break;
  85. }
  86. }
  87. /** Forget that we completed our first OR connection */
  88. void
  89. bto_cevent_reset(void)
  90. {
  91. bto_first_orconn = false;
  92. }