circuitmux.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* * Copyright (c) 2012, 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. typedef struct circuitmux_policy_s circuitmux_policy_t;
  11. typedef struct circuitmux_policy_data_s circuitmux_policy_data_t;
  12. typedef struct circuitmux_policy_circ_data_s circuitmux_policy_circ_data_t;
  13. struct circuitmux_policy_s {
  14. /* Allocate cmux-wide policy-specific data */
  15. circuitmux_policy_data_t * (*alloc_cmux_data)(circuitmux_t *cmux);
  16. /* Free cmux-wide policy-specific data */
  17. void (*free_cmux_data)(circuitmux_t *cmux,
  18. circuitmux_policy_data_t *pol_data);
  19. /* Allocate circuit policy-specific data for a newly attached circuit */
  20. circuitmux_policy_circ_data_t *
  21. (*alloc_circ_data)(circuitmux_t *cmux,
  22. circuitmux_policy_data_t *pol_data,
  23. circuit_t *circ,
  24. cell_direction_t direction,
  25. unsigned int cell_count);
  26. /* Free circuit policy-specific data */
  27. void (*free_circ_data)(circuitmux_t *cmux,
  28. circuitmux_policy_data_t *pol_data,
  29. circuit_t *circ,
  30. circuitmux_policy_circ_data_t *pol_circ_data);
  31. /* Notify that a circuit has become active/inactive */
  32. void (*notify_circ_active)(circuitmux_t *cmux,
  33. circuitmux_policy_data_t *pol_data,
  34. circuit_t *circ,
  35. circuitmux_policy_circ_data_t *pol_circ_data);
  36. void (*notify_circ_inactive)(circuitmux_t *cmux,
  37. circuitmux_policy_data_t *pol_data,
  38. circuit_t *circ,
  39. circuitmux_policy_circ_data_t *pol_circ_data);
  40. /* Notify of arriving/transmitted cells on a circuit */
  41. void (*notify_set_n_cells)(circuitmux_t *cmux,
  42. circuitmux_policy_data_t *pol_data,
  43. circuit_t *circ,
  44. circuitmux_policy_circ_data_t *pol_circ_data,
  45. unsigned int n_cells);
  46. void (*notify_xmit_cells)(circuitmux_t *cmux,
  47. circuitmux_policy_data_t *pol_data,
  48. circuit_t *circ,
  49. circuitmux_policy_circ_data_t *pol_circ_data,
  50. unsigned int n_cells);
  51. /* Choose a circuit */
  52. circuit_t * (*pick_active_circuit)(circuitmux_t *cmux,
  53. circuitmux_policy_data_t *pol_data);
  54. };
  55. /*
  56. * Circuitmux policy implementations can subclass this to store circuitmux-
  57. * wide data; it just has the magic number in the base struct.
  58. */
  59. struct circuitmux_policy_data_s {
  60. uint32_t magic;
  61. };
  62. /*
  63. * Circuitmux policy implementations can subclass this to store circuit-
  64. * specific data; it just has the magic number in the base struct.
  65. */
  66. struct circuitmux_policy_circ_data_s {
  67. uint32_t magic;
  68. };
  69. /*
  70. * Upcast #defines for the above types
  71. */
  72. /**
  73. * Convert a circuitmux_policy_data_t subtype to a circuitmux_policy_data_t.
  74. */
  75. #define TO_CMUX_POL_DATA(x) (&((x)->_base))
  76. /**
  77. * Convert a circuitmux_policy_circ_data_t subtype to a
  78. * circuitmux_policy_circ_data_t.
  79. */
  80. #define TO_CMUX_POL_CIRC_DATA(x) (&((x)->_base))
  81. /* Consistency check */
  82. void circuitmux_assert_okay(circuitmux_t *cmux);
  83. /* Create/destroy */
  84. circuitmux_t * circuitmux_alloc(void);
  85. void circuitmux_detach_all_circuits(circuitmux_t *cmux);
  86. void circuitmux_free(circuitmux_t *cmux);
  87. /* Policy control */
  88. void circuitmux_clear_policy(circuitmux_t *cmux);
  89. const circuitmux_policy_t * circuitmux_get_policy(circuitmux_t *cmux);
  90. void circuitmux_set_policy(circuitmux_t *cmux,
  91. const circuitmux_policy_t *pol);
  92. /* Status inquiries */
  93. cell_direction_t circuitmux_attached_circuit_direction(
  94. circuitmux_t *cmux,
  95. circuit_t *circ);
  96. int circuitmux_is_circuit_attached(circuitmux_t *cmux, circuit_t *circ);
  97. int circuitmux_is_circuit_active(circuitmux_t *cmux, circuit_t *circ);
  98. unsigned int circuitmux_num_cells_for_circuit(circuitmux_t *cmux,
  99. circuit_t *circ);
  100. unsigned int circuitmux_num_cells(circuitmux_t *cmux);
  101. unsigned int circuitmux_num_circuits(circuitmux_t *cmux);
  102. unsigned int circuitmux_num_active_circuits(circuitmux_t *cmux);
  103. /* Channel interface */
  104. circuit_t * circuitmux_get_first_active_circuit(circuitmux_t *cmux);
  105. void circuitmux_notify_xmit_cells(circuitmux_t *cmux, circuit_t *circ,
  106. unsigned int n_cells);
  107. /* Circuit interface */
  108. void circuitmux_attach_circuit(circuitmux_t *cmux, circuit_t *circ,
  109. cell_direction_t direction);
  110. void circuitmux_detach_circuit(circuitmux_t *cmux, circuit_t *circ);
  111. void circuitmux_clear_num_cells(circuitmux_t *cmux, circuit_t *circ);
  112. void circuitmux_set_num_cells(circuitmux_t *cmux, circuit_t *circ,
  113. unsigned int n_cells);
  114. #endif /* _TOR_CIRCUITMUX_H */