BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file PacketPassPriorityQueue.h |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions are met: |
||
9 | * 1. Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * 2. Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * 3. Neither the name of the author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | * |
||
29 | * @section DESCRIPTION |
||
30 | * |
||
31 | * Priority queue using {@link PacketPassInterface}. |
||
32 | */ |
||
33 | |||
34 | #ifndef BADVPN_FLOW_PACKETPASSPRIORITYQUEUE_H |
||
35 | #define BADVPN_FLOW_PACKETPASSPRIORITYQUEUE_H |
||
36 | |||
37 | #include <stdint.h> |
||
38 | |||
39 | #include <misc/debugcounter.h> |
||
40 | #include <structure/SAvl.h> |
||
41 | #include <base/DebugObject.h> |
||
42 | #include <base/BPending.h> |
||
43 | #include <flow/PacketPassInterface.h> |
||
44 | |||
45 | typedef void (*PacketPassPriorityQueue_handler_busy) (void *user); |
||
46 | |||
47 | struct PacketPassPriorityQueueFlow_s; |
||
48 | |||
49 | #include "PacketPassPriorityQueue_tree.h" |
||
50 | #include <structure/SAvl_decl.h> |
||
51 | |||
52 | typedef struct PacketPassPriorityQueueFlow_s { |
||
53 | struct PacketPassPriorityQueue_s *m; |
||
54 | int priority; |
||
55 | PacketPassPriorityQueue_handler_busy handler_busy; |
||
56 | void *user; |
||
57 | PacketPassInterface input; |
||
58 | int is_queued; |
||
59 | struct { |
||
60 | PacketPassPriorityQueue__TreeNode tree_node; |
||
61 | uint8_t *data; |
||
62 | int data_len; |
||
63 | } queued; |
||
64 | DebugObject d_obj; |
||
65 | } PacketPassPriorityQueueFlow; |
||
66 | |||
67 | /** |
||
68 | * Priority queue using {@link PacketPassInterface}. |
||
69 | */ |
||
70 | typedef struct PacketPassPriorityQueue_s { |
||
71 | PacketPassInterface *output; |
||
72 | BPendingGroup *pg; |
||
73 | int use_cancel; |
||
74 | struct PacketPassPriorityQueueFlow_s *sending_flow; |
||
75 | PacketPassPriorityQueue__Tree queued_tree; |
||
76 | int freeing; |
||
77 | BPending schedule_job; |
||
78 | DebugObject d_obj; |
||
79 | DebugCounter d_ctr; |
||
80 | } PacketPassPriorityQueue; |
||
81 | |||
82 | /** |
||
83 | * Initializes the queue. |
||
84 | * |
||
85 | * @param m the object |
||
86 | * @param output output interface |
||
87 | * @param pg pending group |
||
88 | * @param use_cancel whether cancel functionality is required. Must be 0 or 1. |
||
89 | * If 1, output must support cancel functionality. |
||
90 | */ |
||
91 | void PacketPassPriorityQueue_Init (PacketPassPriorityQueue *m, PacketPassInterface *output, BPendingGroup *pg, int use_cancel); |
||
92 | |||
93 | /** |
||
94 | * Frees the queue. |
||
95 | * All flows must have been freed. |
||
96 | * |
||
97 | * @param m the object |
||
98 | */ |
||
99 | void PacketPassPriorityQueue_Free (PacketPassPriorityQueue *m); |
||
100 | |||
101 | /** |
||
102 | * Prepares for freeing the entire queue. Must be called to allow freeing |
||
103 | * the flows in the process of freeing the entire queue. |
||
104 | * After this function is called, flows and the queue must be freed |
||
105 | * before any further I/O. |
||
106 | * May be called multiple times. |
||
107 | * The queue enters freeing state. |
||
108 | * |
||
109 | * @param m the object |
||
110 | */ |
||
111 | void PacketPassPriorityQueue_PrepareFree (PacketPassPriorityQueue *m); |
||
112 | |||
113 | /** |
||
114 | * Returns the MTU of the queue. |
||
115 | * |
||
116 | * @param m the object |
||
117 | */ |
||
118 | int PacketPassPriorityQueue_GetMTU (PacketPassPriorityQueue *m); |
||
119 | |||
120 | /** |
||
121 | * Initializes a queue flow. |
||
122 | * Queue must not be in freeing state. |
||
123 | * Must not be called from queue calls to output. |
||
124 | * |
||
125 | * @param flow the object |
||
126 | * @param m queue to attach to |
||
127 | * @param priority flow priority. Lower value means higher priority. |
||
128 | */ |
||
129 | void PacketPassPriorityQueueFlow_Init (PacketPassPriorityQueueFlow *flow, PacketPassPriorityQueue *m, int priority); |
||
130 | |||
131 | /** |
||
132 | * Frees a queue flow. |
||
133 | * Unless the queue is in freeing state: |
||
134 | * - The flow must not be busy as indicated by {@link PacketPassPriorityQueueFlow_IsBusy}. |
||
135 | * - Must not be called from queue calls to output. |
||
136 | * |
||
137 | * @param flow the object |
||
138 | */ |
||
139 | void PacketPassPriorityQueueFlow_Free (PacketPassPriorityQueueFlow *flow); |
||
140 | |||
141 | /** |
||
142 | * Does nothing. |
||
143 | * It must be possible to free the flow (see {@link PacketPassPriorityQueueFlow}). |
||
144 | * |
||
145 | * @param flow the object |
||
146 | */ |
||
147 | void PacketPassPriorityQueueFlow_AssertFree (PacketPassPriorityQueueFlow *flow); |
||
148 | |||
149 | /** |
||
150 | * Determines if the flow is busy. If the flow is considered busy, it must not |
||
151 | * be freed. At any given time, at most one flow will be indicated as busy. |
||
152 | * Queue must not be in freeing state. |
||
153 | * Must not be called from queue calls to output. |
||
154 | * |
||
155 | * @param flow the object |
||
156 | * @return 0 if not busy, 1 is busy |
||
157 | */ |
||
158 | int PacketPassPriorityQueueFlow_IsBusy (PacketPassPriorityQueueFlow *flow); |
||
159 | |||
160 | /** |
||
161 | * Requests the output to stop processing the current packet as soon as possible. |
||
162 | * Cancel functionality must be enabled for the queue. |
||
163 | * The flow must be busy as indicated by {@link PacketPassPriorityQueueFlow_IsBusy}. |
||
164 | * Queue must not be in freeing state. |
||
165 | * |
||
166 | * @param flow the object |
||
167 | */ |
||
168 | void PacketPassPriorityQueueFlow_RequestCancel (PacketPassPriorityQueueFlow *flow); |
||
169 | |||
170 | /** |
||
171 | * Sets up a callback to be called when the flow is no longer busy. |
||
172 | * The handler will be called as soon as the flow is no longer busy, i.e. it is not |
||
173 | * possible that this flow is no longer busy before the handler is called. |
||
174 | * The flow must be busy as indicated by {@link PacketPassPriorityQueueFlow_IsBusy}. |
||
175 | * Queue must not be in freeing state. |
||
176 | * Must not be called from queue calls to output. |
||
177 | * |
||
178 | * @param flow the object |
||
179 | * @param handler callback function. NULL to disable. |
||
180 | * @param user value passed to callback function. Ignored if handler is NULL. |
||
181 | */ |
||
182 | void PacketPassPriorityQueueFlow_SetBusyHandler (PacketPassPriorityQueueFlow *flow, PacketPassPriorityQueue_handler_busy handler, void *user); |
||
183 | |||
184 | /** |
||
185 | * Returns the input interface of the flow. |
||
186 | * |
||
187 | * @param flow the object |
||
188 | * @return input interface |
||
189 | */ |
||
190 | PacketPassInterface * PacketPassPriorityQueueFlow_GetInput (PacketPassPriorityQueueFlow *flow); |
||
191 | |||
192 | #endif |