some cleanups
[strongswan.git] / src / charon / sa / task_manager.h
1 /**
2 * @file task_manager.h
3 *
4 * @brief Interface of task_manager_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef TASK_MANAGER_H_
24 #define TASK_MANAGER_H_
25
26 typedef struct task_manager_t task_manager_t;
27
28 #include <library.h>
29 #include <encoding/message.h>
30 #include <sa/ike_sa.h>
31 #include <sa/tasks/task.h>
32
33 /**
34 * @brief The task manager, juggles task and handles message exchanges.
35 *
36 * On incoming requests, the task manager creates new tasks on demand and
37 * juggles the request through all available tasks. Each task inspects the
38 * request and adds payloads as necessary to the response.
39 * On outgoing requests, the task manager delivers the request through the tasks
40 * to build it, the response gets processed by each task to complete.
41 * The task manager has an internal Queue to store task which should get
42 * completed.
43 * For the initial IKE_SA setup, several tasks are queued: One for the
44 * unauthenticated IKE_SA setup, one for authentication, one for CHILD_SA setup
45 * and maybe one for virtual IP assignement.
46 *
47 * @b Constructors:
48 * - task_manager_create()
49 *
50 * @ingroup sa
51 */
52 struct task_manager_t {
53
54 /**
55 * @brief Process an incoming message.
56 *
57 * @param this calling object
58 * @param message message to add payloads to
59 * @return
60 * - DESTROY_ME if IKE_SA must be closed
61 * - SUCCESS otherwise
62 */
63 status_t (*process_message) (task_manager_t *this, message_t *message);
64
65 /**
66 * @brief Initiate an exchange with the currently queued tasks.
67 *
68 * @param this calling object
69 */
70 status_t (*initiate) (task_manager_t *this);
71
72 /**
73 * @brief Queue a task in the manager.
74 *
75 * @param this calling object
76 * @param task task to queue
77 */
78 void (*queue_task) (task_manager_t *this, task_t *task);
79
80 /**
81 * @brief Retransmit a request if it hasn't been acknowledged yet.
82 *
83 * A return value of INVALID_STATE means that the message was already
84 * acknowledged and has not to be retransmitted. A return value of SUCCESS
85 * means retransmission was required and the message has been resent.
86 *
87 * @param this calling object
88 * @param message_id ID of the message to retransmit
89 * @return
90 * - INVALID_STATE if retransmission not required
91 * - SUCCESS if retransmission sent
92 */
93 status_t (*retransmit) (task_manager_t *this, u_int32_t message_id);
94
95 /**
96 * @brief Migrate all tasks from other to this.
97 *
98 * To rekey or reestablish an IKE_SA completely, all queued or active
99 * tasks should get migrated to the new IKE_SA.
100 *
101 * @param this manager which gets all tasks
102 * @param other manager which gives away its tasks
103 */
104 void (*adopt_tasks) (task_manager_t *this, task_manager_t *other);
105
106 /**
107 * @brief Reset message ID counters of the task manager.
108 *
109 * The IKEv2 protocol requires to restart exchanges with message IDs
110 * reset to zero (INVALID_KE_PAYLOAD, COOKIES, ...). The reset() method
111 * resets the message IDs and resets all active tasks using the migrate()
112 * method.
113 *
114 * @param this calling object
115 * @param other manager which gives away its tasks
116 */
117 void (*reset) (task_manager_t *this);
118
119 /**
120 * @brief Check if we are currently waiting for a reply.
121 *
122 * @param this calling object
123 * @return TRUE if we are waiting, FALSE otherwise
124 */
125 bool (*busy) (task_manager_t *this);
126
127 /**
128 * @brief Destroy the task_manager_t.
129 *
130 * @param this calling object
131 */
132 void (*destroy) (task_manager_t *this);
133 };
134
135 /**
136 * @brief Create an instance of the task manager.
137 *
138 * @param ike_sa IKE_SA to manage.
139 *
140 * @ingroup sa
141 */
142 task_manager_t *task_manager_create(ike_sa_t *ike_sa);
143
144 #endif /* TASK_MANAGER_H_ */