connection_or.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 connection_or.h
  8. * \brief Header file for connection_or.c.
  9. **/
  10. #ifndef TOR_CONNECTION_OR_H
  11. #define TOR_CONNECTION_OR_H
  12. #include "core/or/orconn_event.h"
  13. #include "lib/evloop/events.h"
  14. extern event_label_t or_conn_link_protocol_version_ev;
  15. extern event_label_t or_conn_open_ev;
  16. extern event_label_t or_conn_closed_ev;
  17. extern event_label_t or_conn_outgoing_packed_cell;
  18. extern event_label_t or_conn_outgoing_fixed_cell;
  19. extern event_label_t or_conn_outgoing_variable_cell;
  20. struct ed25519_public_key_t;
  21. struct ed25519_keypair_t;
  22. or_connection_t *TO_OR_CONN(connection_t *);
  23. void or_conn_register_events(event_registry_t *registry);
  24. void connection_or_clear_identity(or_connection_t *conn);
  25. void connection_or_clear_identity_map(void);
  26. void clear_broken_connection_map(int disable);
  27. or_connection_t *connection_or_get_for_extend(const char *digest,
  28. const tor_addr_t *target_addr,
  29. const char **msg_out,
  30. int *launch_out);
  31. void connection_or_block_renegotiation(or_connection_t *conn);
  32. int connection_or_reached_eof(or_connection_t *conn);
  33. int connection_or_process_inbuf(or_connection_t *conn);
  34. ssize_t connection_or_num_cells_writeable(or_connection_t *conn);
  35. int connection_or_flushed_some(or_connection_t *conn);
  36. int connection_or_finished_flushing(or_connection_t *conn);
  37. int connection_or_finished_connecting(or_connection_t *conn);
  38. void connection_or_about_to_close(or_connection_t *conn);
  39. int connection_or_digest_is_known_relay(const char *id_digest);
  40. void connection_or_update_token_buckets(smartlist_t *conns,
  41. const or_options_t *options);
  42. void connection_or_connect_failed(or_connection_t *conn,
  43. int reason, const char *msg);
  44. void connection_or_notify_error(or_connection_t *conn,
  45. int reason, const char *msg);
  46. MOCK_DECL(or_connection_t *,
  47. connection_or_connect,
  48. (const tor_addr_t *addr, uint16_t port,
  49. const char *id_digest,
  50. const struct ed25519_public_key_t *ed_id,
  51. channel_tls_t *chan));
  52. void connection_or_close_normally(or_connection_t *orconn, int flush);
  53. MOCK_DECL(void,connection_or_close_for_error,
  54. (or_connection_t *orconn, int flush));
  55. void connection_or_report_broken_states(int severity, int domain);
  56. void connection_or_event_status(or_connection_t *conn,
  57. or_conn_status_event_t tp, int reason);
  58. //MOCK_DECL(int,connection_tls_start_handshake,(or_connection_t *conn,
  59. // int receiving));
  60. int connection_tls_continue_handshake(or_connection_t *conn);
  61. void connection_or_set_canonical(or_connection_t *or_conn,
  62. int is_canonical);
  63. int connection_init_or_handshake_state(or_connection_t *conn,
  64. int started_here);
  65. void connection_or_init_conn_from_address(or_connection_t *conn,
  66. const tor_addr_t *addr,
  67. uint16_t port,
  68. const char *rsa_id_digest,
  69. const struct ed25519_public_key_t *ed_id,
  70. int started_here);
  71. int connection_or_client_learned_peer_id(or_connection_t *conn,
  72. const uint8_t *rsa_peer_id,
  73. const struct ed25519_public_key_t *ed_peer_id);
  74. time_t connection_or_client_used(or_connection_t *conn);
  75. MOCK_DECL(int, connection_or_get_num_circuits, (or_connection_t *conn));
  76. void connection_or_process_event(event_label_t label, event_data_t data,
  77. void *context);
  78. void or_handshake_state_free_(or_handshake_state_t *state);
  79. #define or_handshake_state_free(state) \
  80. FREE_AND_NULL(or_handshake_state_t, or_handshake_state_free_, (state))
  81. void or_handshake_state_record_cell(or_connection_t *conn,
  82. or_handshake_state_t *state,
  83. const cell_t *cell,
  84. int incoming);
  85. void or_handshake_state_record_var_cell(or_connection_t *conn,
  86. or_handshake_state_t *state,
  87. const var_cell_t *cell,
  88. int incoming);
  89. int connection_or_set_state_open(or_connection_t *conn);
  90. void connection_or_write_cell_to_buf(const cell_t *cell,
  91. or_connection_t *conn);
  92. MOCK_DECL(void,connection_or_write_var_cell_to_buf,(const var_cell_t *cell,
  93. or_connection_t *conn));
  94. int connection_or_send_versions(or_connection_t *conn, int v3_plus);
  95. MOCK_DECL(int,connection_or_send_netinfo,(or_connection_t *conn));
  96. int connection_or_send_certs_cell(or_connection_t *conn);
  97. int connection_or_send_auth_challenge_cell(or_connection_t *conn);
  98. int authchallenge_type_is_supported(uint16_t challenge_type);
  99. int authchallenge_type_is_better(uint16_t challenge_type_a,
  100. uint16_t challenge_type_b);
  101. var_cell_t *connection_or_compute_authenticate_cell_body(
  102. or_connection_t *conn,
  103. const int authtype,
  104. crypto_pk_t *signing_key,
  105. const struct ed25519_keypair_t *ed_signing_key,
  106. int server);
  107. MOCK_DECL(int,connection_or_send_authenticate_cell,
  108. (or_connection_t *conn, int type));
  109. int is_or_protocol_version_known(uint16_t version);
  110. void cell_pack(packed_cell_t *dest, const cell_t *src, int wide_circ_ids);
  111. void cell_unpack(cell_t *dest, const char *src, int wide_circ_ids);
  112. int var_cell_pack_header(const var_cell_t *cell, char *hdr_out,
  113. int wide_circ_ids);
  114. var_cell_t *var_cell_new(uint16_t payload_len);
  115. var_cell_t *var_cell_copy(const var_cell_t *src);
  116. void var_cell_free_(var_cell_t *cell);
  117. #define var_cell_free(cell) FREE_AND_NULL(var_cell_t, var_cell_free_, (cell))
  118. /* DOCDOC */
  119. #define MIN_LINK_PROTO_FOR_WIDE_CIRC_IDS 4
  120. #define MIN_LINK_PROTO_FOR_CHANNEL_PADDING 5
  121. #define MAX_LINK_PROTO MIN_LINK_PROTO_FOR_CHANNEL_PADDING
  122. int connection_or_single_set_badness_(time_t now,
  123. or_connection_t *or_conn,
  124. int force);
  125. void connection_or_group_set_badness_(smartlist_t *group, int force);
  126. #ifdef CONNECTION_OR_PRIVATE
  127. STATIC int should_connect_to_relay(const or_connection_t *or_conn);
  128. STATIC void note_or_connect_failed(const or_connection_t *or_conn);
  129. #endif
  130. #ifdef TOR_UNIT_TESTS
  131. extern int certs_cell_ed25519_disabled_for_testing;
  132. extern int testing__connection_or_pretend_TLSSECRET_is_supported;
  133. #endif
  134. #endif /* !defined(TOR_CONNECTION_OR_H) */