relay.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-2017, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file relay.h
  8. * \brief Header file for relay.c.
  9. **/
  10. #ifndef TOR_RELAY_H
  11. #define TOR_RELAY_H
  12. extern uint64_t stats_n_relay_cells_relayed;
  13. extern uint64_t stats_n_relay_cells_delivered;
  14. void relay_consensus_has_changed(const networkstatus_t *ns);
  15. int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
  16. cell_direction_t cell_direction);
  17. size_t cell_queues_get_total_allocation(void);
  18. void relay_header_pack(uint8_t *dest, const relay_header_t *src);
  19. void relay_header_unpack(relay_header_t *dest, const uint8_t *src);
  20. MOCK_DECL(int,
  21. relay_send_command_from_edge_,(streamid_t stream_id, circuit_t *circ,
  22. uint8_t relay_command, const char *payload,
  23. size_t payload_len, crypt_path_t *cpath_layer,
  24. const char *filename, int lineno));
  25. /* Indicates to relay_send_command_from_edge() that it is a control cell. */
  26. #define CONTROL_CELL_ID 0
  27. #define relay_send_command_from_edge(stream_id, circ, relay_command, payload, \
  28. payload_len, cpath_layer) \
  29. relay_send_command_from_edge_((stream_id), (circ), (relay_command), \
  30. (payload), (payload_len), (cpath_layer), \
  31. __FILE__, __LINE__)
  32. int connection_edge_send_command(edge_connection_t *fromconn,
  33. uint8_t relay_command, const char *payload,
  34. size_t payload_len);
  35. int connection_edge_package_raw_inbuf(edge_connection_t *conn,
  36. int package_partial,
  37. int *max_cells);
  38. void connection_edge_consider_sending_sendme(edge_connection_t *conn);
  39. extern uint64_t stats_n_data_cells_packaged;
  40. extern uint64_t stats_n_data_bytes_packaged;
  41. extern uint64_t stats_n_data_cells_received;
  42. extern uint64_t stats_n_data_bytes_received;
  43. void dump_cell_pool_usage(int severity);
  44. size_t packed_cell_mem_cost(void);
  45. int have_been_under_memory_pressure(void);
  46. /* For channeltls.c */
  47. void packed_cell_free_(packed_cell_t *cell);
  48. #define packed_cell_free(cell) \
  49. FREE_AND_NULL(packed_cell_t, packed_cell_free_, (cell))
  50. void cell_queue_init(cell_queue_t *queue);
  51. void cell_queue_clear(cell_queue_t *queue);
  52. void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell);
  53. void cell_queue_append_packed_copy(circuit_t *circ, cell_queue_t *queue,
  54. int exitward, const cell_t *cell,
  55. int wide_circ_ids, int use_stats);
  56. void append_cell_to_circuit_queue(circuit_t *circ, channel_t *chan,
  57. cell_t *cell, cell_direction_t direction,
  58. streamid_t fromstream);
  59. void destroy_cell_queue_init(destroy_cell_queue_t *queue);
  60. void destroy_cell_queue_clear(destroy_cell_queue_t *queue);
  61. void destroy_cell_queue_append(destroy_cell_queue_t *queue,
  62. circid_t circid,
  63. uint8_t reason);
  64. void channel_unlink_all_circuits(channel_t *chan, smartlist_t *detached_out);
  65. MOCK_DECL(int, channel_flush_from_first_active_circuit,
  66. (channel_t *chan, int max));
  67. void assert_circuit_mux_okay(channel_t *chan);
  68. void update_circuit_on_cmux_(circuit_t *circ, cell_direction_t direction,
  69. const char *file, int lineno);
  70. #define update_circuit_on_cmux(circ, direction) \
  71. update_circuit_on_cmux_((circ), (direction), SHORT_FILE__, __LINE__)
  72. int append_address_to_payload(uint8_t *payload_out, const tor_addr_t *addr);
  73. const uint8_t *decode_address_from_payload(tor_addr_t *addr_out,
  74. const uint8_t *payload,
  75. int payload_len);
  76. void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan);
  77. void stream_choice_seed_weak_rng(void);
  78. int relay_crypt(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction,
  79. crypt_path_t **layer_hint, char *recognized);
  80. circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids);
  81. #ifdef RELAY_PRIVATE
  82. STATIC int connected_cell_parse(const relay_header_t *rh, const cell_t *cell,
  83. tor_addr_t *addr_out, int *ttl_out);
  84. /** An address-and-ttl tuple as yielded by resolved_cell_parse */
  85. typedef struct address_ttl_s {
  86. tor_addr_t addr;
  87. char *hostname;
  88. int ttl;
  89. } address_ttl_t;
  90. STATIC void address_ttl_free_(address_ttl_t *addr);
  91. #define address_ttl_free(addr) \
  92. FREE_AND_NULL(address_ttl_t, address_ttl_free_, (addr))
  93. STATIC int resolved_cell_parse(const cell_t *cell, const relay_header_t *rh,
  94. smartlist_t *addresses_out, int *errcode_out);
  95. STATIC int connection_edge_process_resolved_cell(edge_connection_t *conn,
  96. const cell_t *cell,
  97. const relay_header_t *rh);
  98. STATIC packed_cell_t *packed_cell_new(void);
  99. STATIC packed_cell_t *cell_queue_pop(cell_queue_t *queue);
  100. STATIC destroy_cell_t *destroy_cell_queue_pop(destroy_cell_queue_t *queue);
  101. STATIC int cell_queues_check_size(void);
  102. #endif /* defined(RELAY_PRIVATE) */
  103. #endif /* !defined(TOR_RELAY_H) */