circuitmux.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* * Copyright (c) 2012-2013, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file circuitmux.h
  5. * \brief Header file for circuitmux.c
  6. **/
  7. #ifndef TOR_CIRCUITMUX_H
  8. #define TOR_CIRCUITMUX_H
  9. #include "or.h"
  10. #include "testsupport.h"
  11. typedef struct circuitmux_policy_s circuitmux_policy_t;
  12. typedef struct circuitmux_policy_data_s circuitmux_policy_data_t;
  13. typedef struct circuitmux_policy_circ_data_s circuitmux_policy_circ_data_t;
  14. struct circuitmux_policy_s {
  15. /* Allocate cmux-wide policy-specific data */
  16. circuitmux_policy_data_t * (*alloc_cmux_data)(circuitmux_t *cmux);
  17. /* Free cmux-wide policy-specific data */
  18. void (*free_cmux_data)(circuitmux_t *cmux,
  19. circuitmux_policy_data_t *pol_data);
  20. /* Allocate circuit policy-specific data for a newly attached circuit */
  21. circuitmux_policy_circ_data_t *
  22. (*alloc_circ_data)(circuitmux_t *cmux,
  23. circuitmux_policy_data_t *pol_data,
  24. circuit_t *circ,
  25. cell_direction_t direction,
  26. unsigned int cell_count);
  27. /* Free circuit policy-specific data */
  28. void (*free_circ_data)(circuitmux_t *cmux,
  29. circuitmux_policy_data_t *pol_data,
  30. circuit_t *circ,
  31. circuitmux_policy_circ_data_t *pol_circ_data);
  32. /* Notify that a circuit has become active/inactive */
  33. void (*notify_circ_active)(circuitmux_t *cmux,
  34. circuitmux_policy_data_t *pol_data,
  35. circuit_t *circ,
  36. circuitmux_policy_circ_data_t *pol_circ_data);
  37. void (*notify_circ_inactive)(circuitmux_t *cmux,
  38. circuitmux_policy_data_t *pol_data,
  39. circuit_t *circ,
  40. circuitmux_policy_circ_data_t *pol_circ_data);
  41. /* Notify of arriving/transmitted cells on a circuit */
  42. void (*notify_set_n_cells)(circuitmux_t *cmux,
  43. circuitmux_policy_data_t *pol_data,
  44. circuit_t *circ,
  45. circuitmux_policy_circ_data_t *pol_circ_data,
  46. unsigned int n_cells);
  47. void (*notify_xmit_cells)(circuitmux_t *cmux,
  48. circuitmux_policy_data_t *pol_data,
  49. circuit_t *circ,
  50. circuitmux_policy_circ_data_t *pol_circ_data,
  51. unsigned int n_cells);
  52. /* Choose a circuit */
  53. circuit_t * (*pick_active_circuit)(circuitmux_t *cmux,
  54. circuitmux_policy_data_t *pol_data);
  55. };
  56. /*
  57. * Circuitmux policy implementations can subclass this to store circuitmux-
  58. * wide data; it just has the magic number in the base struct.
  59. */
  60. struct circuitmux_policy_data_s {
  61. uint32_t magic;
  62. };
  63. /*
  64. * Circuitmux policy implementations can subclass this to store circuit-
  65. * specific data; it just has the magic number in the base struct.
  66. */
  67. struct circuitmux_policy_circ_data_s {
  68. uint32_t magic;
  69. };
  70. /*
  71. * Upcast #defines for the above types
  72. */
  73. /**
  74. * Convert a circuitmux_policy_data_t subtype to a circuitmux_policy_data_t.
  75. */
  76. #define TO_CMUX_POL_DATA(x) (&((x)->base_))
  77. /**
  78. * Convert a circuitmux_policy_circ_data_t subtype to a
  79. * circuitmux_policy_circ_data_t.
  80. */
  81. #define TO_CMUX_POL_CIRC_DATA(x) (&((x)->base_))
  82. /* Consistency check */
  83. void circuitmux_assert_okay(circuitmux_t *cmux);
  84. /* Create/destroy */
  85. circuitmux_t * circuitmux_alloc(void);
  86. void circuitmux_detach_all_circuits(circuitmux_t *cmux);
  87. void circuitmux_free(circuitmux_t *cmux);
  88. /* Policy control */
  89. void circuitmux_clear_policy(circuitmux_t *cmux);
  90. const circuitmux_policy_t * circuitmux_get_policy(circuitmux_t *cmux);
  91. void circuitmux_set_policy(circuitmux_t *cmux,
  92. const circuitmux_policy_t *pol);
  93. /* Status inquiries */
  94. cell_direction_t circuitmux_attached_circuit_direction(
  95. circuitmux_t *cmux,
  96. circuit_t *circ);
  97. int circuitmux_is_circuit_attached(circuitmux_t *cmux, circuit_t *circ);
  98. int circuitmux_is_circuit_active(circuitmux_t *cmux, circuit_t *circ);
  99. unsigned int circuitmux_num_cells_for_circuit(circuitmux_t *cmux,
  100. circuit_t *circ);
  101. unsigned int circuitmux_num_cells(circuitmux_t *cmux);
  102. unsigned int circuitmux_num_circuits(circuitmux_t *cmux);
  103. unsigned int circuitmux_num_active_circuits(circuitmux_t *cmux);
  104. /* Channel interface */
  105. circuit_t * circuitmux_get_first_active_circuit(circuitmux_t *cmux,
  106. cell_queue_t **destroy_queue_out);
  107. void circuitmux_notify_xmit_cells(circuitmux_t *cmux, circuit_t *circ,
  108. unsigned int n_cells);
  109. void circuitmux_notify_xmit_destroy(circuitmux_t *cmux);
  110. /* Circuit interface */
  111. MOCK_DECL(void, circuitmux_attach_circuit, (circuitmux_t *cmux,
  112. circuit_t *circ,
  113. cell_direction_t direction));
  114. MOCK_DECL(void, circuitmux_detach_circuit,
  115. (circuitmux_t *cmux, circuit_t *circ));
  116. void circuitmux_clear_num_cells(circuitmux_t *cmux, circuit_t *circ);
  117. void circuitmux_set_num_cells(circuitmux_t *cmux, circuit_t *circ,
  118. unsigned int n_cells);
  119. void circuitmux_append_destroy_cell(channel_t *chan,
  120. circuitmux_t *cmux, circid_t circ_id,
  121. uint8_t reason);
  122. void circuitmux_mark_destroyed_circids_usable(circuitmux_t *cmux,
  123. channel_t *chan);
  124. #endif /* TOR_CIRCUITMUX_H */