relay.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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-2013, 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. int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
  15. cell_direction_t cell_direction);
  16. void relay_header_pack(uint8_t *dest, const relay_header_t *src);
  17. void relay_header_unpack(relay_header_t *dest, const uint8_t *src);
  18. int relay_send_command_from_edge_(streamid_t stream_id, circuit_t *circ,
  19. uint8_t relay_command, const char *payload,
  20. size_t payload_len, crypt_path_t *cpath_layer,
  21. const char *filename, int lineno);
  22. #define relay_send_command_from_edge(stream_id, circ, relay_command, payload, \
  23. payload_len, cpath_layer) \
  24. relay_send_command_from_edge_((stream_id), (circ), (relay_command), \
  25. (payload), (payload_len), (cpath_layer), \
  26. __FILE__, __LINE__)
  27. int connection_edge_send_command(edge_connection_t *fromconn,
  28. uint8_t relay_command, const char *payload,
  29. size_t payload_len);
  30. int connection_edge_package_raw_inbuf(edge_connection_t *conn,
  31. int package_partial,
  32. int *max_cells);
  33. void connection_edge_consider_sending_sendme(edge_connection_t *conn);
  34. extern uint64_t stats_n_data_cells_packaged;
  35. extern uint64_t stats_n_data_bytes_packaged;
  36. extern uint64_t stats_n_data_cells_received;
  37. extern uint64_t stats_n_data_bytes_received;
  38. void init_cell_pool(void);
  39. void free_cell_pool(void);
  40. void clean_cell_pool(void);
  41. void dump_cell_pool_usage(int severity);
  42. size_t packed_cell_mem_cost(void);
  43. /* For channeltls.c */
  44. void packed_cell_free(packed_cell_t *cell);
  45. void cell_queue_clear(cell_queue_t *queue);
  46. void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell);
  47. void cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell,
  48. int wide_circ_ids, int use_stats);
  49. void append_cell_to_circuit_queue(circuit_t *circ, channel_t *chan,
  50. cell_t *cell, cell_direction_t direction,
  51. streamid_t fromstream);
  52. void channel_unlink_all_circuits(channel_t *chan);
  53. int channel_flush_from_first_active_circuit(channel_t *chan, int max);
  54. void assert_circuit_mux_okay(channel_t *chan);
  55. void update_circuit_on_cmux_(circuit_t *circ, cell_direction_t direction,
  56. const char *file, int lineno);
  57. #define update_circuit_on_cmux(circ, direction) \
  58. update_circuit_on_cmux_((circ), (direction), SHORT_FILE__, __LINE__)
  59. int append_address_to_payload(uint8_t *payload_out, const tor_addr_t *addr);
  60. const uint8_t *decode_address_from_payload(tor_addr_t *addr_out,
  61. const uint8_t *payload,
  62. int payload_len);
  63. void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan);
  64. void stream_choice_seed_weak_rng(void);
  65. int relay_crypt(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction,
  66. crypt_path_t **layer_hint, char *recognized);
  67. #ifdef RELAY_PRIVATE
  68. STATIC int connected_cell_parse(const relay_header_t *rh, const cell_t *cell,
  69. tor_addr_t *addr_out, int *ttl_out);
  70. #endif
  71. #endif