BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file PacketPassInactivityMonitor.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 | * A {@link PacketPassInterface} layer for detecting inactivity. |
||
32 | */ |
||
33 | |||
34 | #ifndef BADVPN_PACKETPASSINACTIVITYMONITOR_H |
||
35 | #define BADVPN_PACKETPASSINACTIVITYMONITOR_H |
||
36 | |||
37 | #include <base/DebugObject.h> |
||
38 | #include <system/BReactor.h> |
||
39 | #include <flow/PacketPassInterface.h> |
||
40 | |||
41 | /** |
||
42 | * Handler function invoked when inactivity is detected. |
||
43 | * It is guaranteed that the interfaces are in not sending state. |
||
44 | * |
||
45 | * @param user value given to {@link PacketPassInactivityMonitor_Init} |
||
46 | */ |
||
47 | typedef void (*PacketPassInactivityMonitor_handler) (void *user); |
||
48 | |||
49 | /** |
||
50 | * A {@link PacketPassInterface} layer for detecting inactivity. |
||
51 | * It reports inactivity to a user provided handler function. |
||
52 | * |
||
53 | * The object behaves like that: |
||
54 | * ("timer set" means started with the given timeout whether if was running or not, |
||
55 | * "timer unset" means stopped if it was running) |
||
56 | * - There is a timer. |
||
57 | * - The timer is set when the object is initialized. |
||
58 | * - When the input calls Send, the call is passed on to the output. |
||
59 | * If the output accepted the packet, the timer is set. If the output |
||
60 | * blocked the packet, the timer is unset. |
||
61 | * - When the output calls Done, the timer is set, and the call is |
||
62 | * passed on to the input. |
||
63 | * - When the input calls Cancel, the timer is set, and the call is |
||
64 | * passed on to the output. |
||
65 | * - When the timer expires, the timer is set, ant the user's handler |
||
66 | * function is invoked. |
||
67 | */ |
||
68 | typedef struct { |
||
69 | DebugObject d_obj; |
||
70 | PacketPassInterface *output; |
||
71 | BReactor *reactor; |
||
72 | PacketPassInactivityMonitor_handler handler; |
||
73 | void *user; |
||
74 | PacketPassInterface input; |
||
75 | BTimer timer; |
||
76 | } PacketPassInactivityMonitor; |
||
77 | |||
78 | /** |
||
79 | * Initializes the object. |
||
80 | * See {@link PacketPassInactivityMonitor} for details. |
||
81 | * |
||
82 | * @param o the object |
||
83 | * @param output output interface |
||
84 | * @param reactor reactor we live in |
||
85 | * @param interval timer value in milliseconds |
||
86 | * @param handler handler function for reporting inactivity, or NULL to disable |
||
87 | * @param user value passed to handler functions |
||
88 | */ |
||
89 | void PacketPassInactivityMonitor_Init (PacketPassInactivityMonitor *o, PacketPassInterface *output, BReactor *reactor, btime_t interval, PacketPassInactivityMonitor_handler handler, void *user); |
||
90 | |||
91 | /** |
||
92 | * Frees the object. |
||
93 | * |
||
94 | * @param o the object |
||
95 | */ |
||
96 | void PacketPassInactivityMonitor_Free (PacketPassInactivityMonitor *o); |
||
97 | |||
98 | /** |
||
99 | * Returns the input interface. |
||
100 | * The MTU of the interface will be the same as of the output interface. |
||
101 | * The interface supports cancel functionality if the output interface supports it. |
||
102 | * |
||
103 | * @param o the object |
||
104 | * @return input interface |
||
105 | */ |
||
106 | PacketPassInterface * PacketPassInactivityMonitor_GetInput (PacketPassInactivityMonitor *o); |
||
107 | |||
108 | /** |
||
109 | * Sets or removes the inactivity handler. |
||
110 | * |
||
111 | * @param o the object |
||
112 | * @param handler handler function for reporting inactivity, or NULL to disable |
||
113 | * @param user value passed to handler functions |
||
114 | */ |
||
115 | void PacketPassInactivityMonitor_SetHandler (PacketPassInactivityMonitor *o, PacketPassInactivityMonitor_handler handler, void *user); |
||
116 | |||
117 | /** |
||
118 | * Sets the timer to expire immediately in order to force an inactivity report. |
||
119 | * |
||
120 | * @param o the object |
||
121 | */ |
||
122 | void PacketPassInactivityMonitor_Force (PacketPassInactivityMonitor *o); |
||
123 | |||
124 | #endif |