1 /* * Copyright (c) 2012-2013, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 * \brief Header file for circuitmux.c
9 #ifndef TOR_CIRCUITMUX_H
10 #define TOR_CIRCUITMUX_H
13 #include "testsupport.h"
15 typedef struct circuitmux_policy_s circuitmux_policy_t
;
16 typedef struct circuitmux_policy_data_s circuitmux_policy_data_t
;
17 typedef struct circuitmux_policy_circ_data_s circuitmux_policy_circ_data_t
;
19 struct circuitmux_policy_s
{
20 /* Allocate cmux-wide policy-specific data */
21 circuitmux_policy_data_t
* (*alloc_cmux_data
)(circuitmux_t
*cmux
);
22 /* Free cmux-wide policy-specific data */
23 void (*free_cmux_data
)(circuitmux_t
*cmux
,
24 circuitmux_policy_data_t
*pol_data
);
25 /* Allocate circuit policy-specific data for a newly attached circuit */
26 circuitmux_policy_circ_data_t
*
27 (*alloc_circ_data
)(circuitmux_t
*cmux
,
28 circuitmux_policy_data_t
*pol_data
,
30 cell_direction_t direction
,
31 unsigned int cell_count
);
32 /* Free circuit policy-specific data */
33 void (*free_circ_data
)(circuitmux_t
*cmux
,
34 circuitmux_policy_data_t
*pol_data
,
36 circuitmux_policy_circ_data_t
*pol_circ_data
);
37 /* Notify that a circuit has become active/inactive */
38 void (*notify_circ_active
)(circuitmux_t
*cmux
,
39 circuitmux_policy_data_t
*pol_data
,
41 circuitmux_policy_circ_data_t
*pol_circ_data
);
42 void (*notify_circ_inactive
)(circuitmux_t
*cmux
,
43 circuitmux_policy_data_t
*pol_data
,
45 circuitmux_policy_circ_data_t
*pol_circ_data
);
46 /* Notify of arriving/transmitted cells on a circuit */
47 void (*notify_set_n_cells
)(circuitmux_t
*cmux
,
48 circuitmux_policy_data_t
*pol_data
,
50 circuitmux_policy_circ_data_t
*pol_circ_data
,
51 unsigned int n_cells
);
52 void (*notify_xmit_cells
)(circuitmux_t
*cmux
,
53 circuitmux_policy_data_t
*pol_data
,
55 circuitmux_policy_circ_data_t
*pol_circ_data
,
56 unsigned int n_cells
);
57 /* Choose a circuit */
58 circuit_t
* (*pick_active_circuit
)(circuitmux_t
*cmux
,
59 circuitmux_policy_data_t
*pol_data
);
63 * Circuitmux policy implementations can subclass this to store circuitmux-
64 * wide data; it just has the magic number in the base struct.
67 struct circuitmux_policy_data_s
{
72 * Circuitmux policy implementations can subclass this to store circuit-
73 * specific data; it just has the magic number in the base struct.
76 struct circuitmux_policy_circ_data_s
{
81 * Upcast #defines for the above types
85 * Convert a circuitmux_policy_data_t subtype to a circuitmux_policy_data_t.
88 #define TO_CMUX_POL_DATA(x) (&((x)->base_))
91 * Convert a circuitmux_policy_circ_data_t subtype to a
92 * circuitmux_policy_circ_data_t.
95 #define TO_CMUX_POL_CIRC_DATA(x) (&((x)->base_))
97 /* Consistency check */
98 void circuitmux_assert_okay(circuitmux_t
*cmux
);
101 circuitmux_t
* circuitmux_alloc(void);
102 void circuitmux_detach_all_circuits(circuitmux_t
*cmux
,
103 smartlist_t
*detached_out
);
104 void circuitmux_free(circuitmux_t
*cmux
);
107 void circuitmux_clear_policy(circuitmux_t
*cmux
);
108 const circuitmux_policy_t
* circuitmux_get_policy(circuitmux_t
*cmux
);
109 void circuitmux_set_policy(circuitmux_t
*cmux
,
110 const circuitmux_policy_t
*pol
);
112 /* Status inquiries */
113 cell_direction_t
circuitmux_attached_circuit_direction(
116 int circuitmux_is_circuit_attached(circuitmux_t
*cmux
, circuit_t
*circ
);
117 int circuitmux_is_circuit_active(circuitmux_t
*cmux
, circuit_t
*circ
);
118 unsigned int circuitmux_num_cells_for_circuit(circuitmux_t
*cmux
,
120 unsigned int circuitmux_num_cells(circuitmux_t
*cmux
);
121 unsigned int circuitmux_num_circuits(circuitmux_t
*cmux
);
122 unsigned int circuitmux_num_active_circuits(circuitmux_t
*cmux
);
124 /* Debuging interface - slow. */
125 int64_t circuitmux_count_queued_destroy_cells(const channel_t
*chan
,
126 const circuitmux_t
*cmux
);
128 /* Channel interface */
129 circuit_t
* circuitmux_get_first_active_circuit(circuitmux_t
*cmux
,
130 cell_queue_t
**destroy_queue_out
);
131 void circuitmux_notify_xmit_cells(circuitmux_t
*cmux
, circuit_t
*circ
,
132 unsigned int n_cells
);
133 void circuitmux_notify_xmit_destroy(circuitmux_t
*cmux
);
135 /* Circuit interface */
136 MOCK_DECL(void, circuitmux_attach_circuit
, (circuitmux_t
*cmux
,
138 cell_direction_t direction
));
139 MOCK_DECL(void, circuitmux_detach_circuit
,
140 (circuitmux_t
*cmux
, circuit_t
*circ
));
141 void circuitmux_clear_num_cells(circuitmux_t
*cmux
, circuit_t
*circ
);
142 void circuitmux_set_num_cells(circuitmux_t
*cmux
, circuit_t
*circ
,
143 unsigned int n_cells
);
145 void circuitmux_append_destroy_cell(channel_t
*chan
,
146 circuitmux_t
*cmux
, circid_t circ_id
,
148 void circuitmux_mark_destroyed_circids_usable(circuitmux_t
*cmux
,
151 #endif /* TOR_CIRCUITMUX_H */