diff options
Diffstat (limited to 'src/arm/arm_monitor_api.c')
-rw-r--r-- | src/arm/arm_monitor_api.c | 150 |
1 files changed, 74 insertions, 76 deletions
diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c index 55b12240f..c6e1e2683 100644 --- a/src/arm/arm_monitor_api.c +++ b/src/arm/arm_monitor_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file arm/arm_monitor_api.c | 22 | * @file arm/arm_monitor_api.c |
@@ -30,16 +30,14 @@ | |||
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "arm.h" | 31 | #include "arm.h" |
32 | 32 | ||
33 | #define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 33 | #define INIT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from(kind, "arm-monitor-api", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Handle for interacting with ARM. | 38 | * Handle for interacting with ARM. |
39 | */ | 39 | */ |
40 | struct GNUNET_ARM_MonitorHandle | 40 | struct GNUNET_ARM_MonitorHandle { |
41 | { | ||
42 | |||
43 | /** | 41 | /** |
44 | * Our control connection to the ARM service. | 42 | * Our control connection to the ARM service. |
45 | */ | 43 | */ |
@@ -79,7 +77,7 @@ struct GNUNET_ARM_MonitorHandle | |||
79 | * @return #GNUNET_OK on success | 77 | * @return #GNUNET_OK on success |
80 | */ | 78 | */ |
81 | static int | 79 | static int |
82 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h); | 80 | reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h); |
83 | 81 | ||
84 | 82 | ||
85 | /** | 83 | /** |
@@ -88,14 +86,14 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h); | |||
88 | * @param cls the `struct GNUNET_ARM_MonitorHandle` | 86 | * @param cls the `struct GNUNET_ARM_MonitorHandle` |
89 | */ | 87 | */ |
90 | static void | 88 | static void |
91 | reconnect_arm_monitor_task (void *cls) | 89 | reconnect_arm_monitor_task(void *cls) |
92 | { | 90 | { |
93 | struct GNUNET_ARM_MonitorHandle *h = cls; | 91 | struct GNUNET_ARM_MonitorHandle *h = cls; |
94 | 92 | ||
95 | h->reconnect_task = NULL; | 93 | h->reconnect_task = NULL; |
96 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 94 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
97 | "Connecting to ARM service for monitoring after delay\n"); | 95 | "Connecting to ARM service for monitoring after delay\n"); |
98 | GNUNET_break (GNUNET_OK == reconnect_arm_monitor (h)); | 96 | GNUNET_break(GNUNET_OK == reconnect_arm_monitor(h)); |
99 | } | 97 | } |
100 | 98 | ||
101 | 99 | ||
@@ -106,18 +104,18 @@ reconnect_arm_monitor_task (void *cls) | |||
106 | * @param h our handle | 104 | * @param h our handle |
107 | */ | 105 | */ |
108 | static void | 106 | static void |
109 | reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) | 107 | reconnect_arm_monitor_later(struct GNUNET_ARM_MonitorHandle *h) |
110 | { | 108 | { |
111 | if (NULL != h->mq) | 109 | if (NULL != h->mq) |
112 | { | 110 | { |
113 | GNUNET_MQ_destroy (h->mq); | 111 | GNUNET_MQ_destroy(h->mq); |
114 | h->mq = NULL; | 112 | h->mq = NULL; |
115 | } | 113 | } |
116 | GNUNET_assert (NULL == h->reconnect_task); | 114 | GNUNET_assert(NULL == h->reconnect_task); |
117 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, | 115 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed(h->retry_backoff, |
118 | &reconnect_arm_monitor_task, | 116 | &reconnect_arm_monitor_task, |
119 | h); | 117 | h); |
120 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); | 118 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff); |
121 | } | 119 | } |
122 | 120 | ||
123 | 121 | ||
@@ -129,18 +127,18 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) | |||
129 | * @return #GNUNET_OK if the message is well-formed | 127 | * @return #GNUNET_OK if the message is well-formed |
130 | */ | 128 | */ |
131 | static int | 129 | static int |
132 | check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg) | 130 | check_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *msg) |
133 | { | 131 | { |
134 | size_t sl = | 132 | size_t sl = |
135 | ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage); | 133 | ntohs(msg->header.size) - sizeof(struct GNUNET_ARM_StatusMessage); |
136 | const char *name = (const char *) &msg[1]; | 134 | const char *name = (const char *)&msg[1]; |
137 | 135 | ||
138 | (void) cls; | 136 | (void)cls; |
139 | if ((0 == sl) || ('\0' != name[sl - 1])) | 137 | if ((0 == sl) || ('\0' != name[sl - 1])) |
140 | { | 138 | { |
141 | GNUNET_break (0); | 139 | GNUNET_break(0); |
142 | return GNUNET_SYSERR; | 140 | return GNUNET_SYSERR; |
143 | } | 141 | } |
144 | return GNUNET_OK; | 142 | return GNUNET_OK; |
145 | } | 143 | } |
146 | 144 | ||
@@ -152,18 +150,18 @@ check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg) | |||
152 | * @param res the message received from the arm service | 150 | * @param res the message received from the arm service |
153 | */ | 151 | */ |
154 | static void | 152 | static void |
155 | handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res) | 153 | handle_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *res) |
156 | { | 154 | { |
157 | struct GNUNET_ARM_MonitorHandle *h = cls; | 155 | struct GNUNET_ARM_MonitorHandle *h = cls; |
158 | enum GNUNET_ARM_ServiceStatus status; | 156 | enum GNUNET_ARM_ServiceStatus status; |
159 | 157 | ||
160 | status = (enum GNUNET_ARM_ServiceStatus) ntohl (res->status); | 158 | status = (enum GNUNET_ARM_ServiceStatus)ntohl(res->status); |
161 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 159 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
162 | "Received notification from ARM for service `%s' with status %d\n", | 160 | "Received notification from ARM for service `%s' with status %d\n", |
163 | (const char *) &res[1], | 161 | (const char *)&res[1], |
164 | (int) status); | 162 | (int)status); |
165 | if (NULL != h->service_status) | 163 | if (NULL != h->service_status) |
166 | h->service_status (h->service_status_cls, (const char *) &res[1], status); | 164 | h->service_status(h->service_status_cls, (const char *)&res[1], status); |
167 | } | 165 | } |
168 | 166 | ||
169 | 167 | ||
@@ -176,12 +174,12 @@ handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res) | |||
176 | * @param error error code | 174 | * @param error error code |
177 | */ | 175 | */ |
178 | static void | 176 | static void |
179 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 177 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
180 | { | 178 | { |
181 | struct GNUNET_ARM_MonitorHandle *h = cls; | 179 | struct GNUNET_ARM_MonitorHandle *h = cls; |
182 | 180 | ||
183 | (void) error; | 181 | (void)error; |
184 | reconnect_arm_monitor_later (h); | 182 | reconnect_arm_monitor_later(h); |
185 | } | 183 | } |
186 | 184 | ||
187 | 185 | ||
@@ -192,29 +190,29 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
192 | * @return #GNUNET_OK on success | 190 | * @return #GNUNET_OK on success |
193 | */ | 191 | */ |
194 | static int | 192 | static int |
195 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | 193 | reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h) |
196 | { | 194 | { |
197 | struct GNUNET_MQ_MessageHandler handlers[] = | 195 | struct GNUNET_MQ_MessageHandler handlers[] = |
198 | {GNUNET_MQ_hd_var_size (monitor_notify, | 196 | { GNUNET_MQ_hd_var_size(monitor_notify, |
199 | GNUNET_MESSAGE_TYPE_ARM_STATUS, | 197 | GNUNET_MESSAGE_TYPE_ARM_STATUS, |
200 | struct GNUNET_ARM_StatusMessage, | 198 | struct GNUNET_ARM_StatusMessage, |
201 | h), | 199 | h), |
202 | GNUNET_MQ_handler_end ()}; | 200 | GNUNET_MQ_handler_end() }; |
203 | struct GNUNET_MessageHeader *msg; | 201 | struct GNUNET_MessageHeader *msg; |
204 | struct GNUNET_MQ_Envelope *env; | 202 | struct GNUNET_MQ_Envelope *env; |
205 | 203 | ||
206 | GNUNET_assert (NULL == h->mq); | 204 | GNUNET_assert(NULL == h->mq); |
207 | h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); | 205 | h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h); |
208 | if (NULL == h->mq) | 206 | if (NULL == h->mq) |
209 | { | 207 | { |
210 | if (NULL != h->service_status) | 208 | if (NULL != h->service_status) |
211 | h->service_status (h->service_status_cls, | 209 | h->service_status(h->service_status_cls, |
212 | NULL, | 210 | NULL, |
213 | GNUNET_ARM_SERVICE_STOPPED); | 211 | GNUNET_ARM_SERVICE_STOPPED); |
214 | return GNUNET_SYSERR; | 212 | return GNUNET_SYSERR; |
215 | } | 213 | } |
216 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); | 214 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); |
217 | GNUNET_MQ_send (h->mq, env); | 215 | GNUNET_MQ_send(h->mq, env); |
218 | return GNUNET_OK; | 216 | return GNUNET_OK; |
219 | } | 217 | } |
220 | 218 | ||
@@ -231,21 +229,21 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | |||
231 | * @return context to use for further ARM monitor operations, NULL on error. | 229 | * @return context to use for further ARM monitor operations, NULL on error. |
232 | */ | 230 | */ |
233 | struct GNUNET_ARM_MonitorHandle * | 231 | struct GNUNET_ARM_MonitorHandle * |
234 | GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 232 | GNUNET_ARM_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, |
235 | GNUNET_ARM_ServiceStatusCallback cont, | 233 | GNUNET_ARM_ServiceStatusCallback cont, |
236 | void *cont_cls) | 234 | void *cont_cls) |
237 | { | 235 | { |
238 | struct GNUNET_ARM_MonitorHandle *h; | 236 | struct GNUNET_ARM_MonitorHandle *h; |
239 | 237 | ||
240 | h = GNUNET_new (struct GNUNET_ARM_MonitorHandle); | 238 | h = GNUNET_new(struct GNUNET_ARM_MonitorHandle); |
241 | h->cfg = cfg; | 239 | h->cfg = cfg; |
242 | h->service_status = cont; | 240 | h->service_status = cont; |
243 | h->service_status_cls = cont_cls; | 241 | h->service_status_cls = cont_cls; |
244 | if (GNUNET_OK != reconnect_arm_monitor (h)) | 242 | if (GNUNET_OK != reconnect_arm_monitor(h)) |
245 | { | 243 | { |
246 | GNUNET_free (h); | 244 | GNUNET_free(h); |
247 | return NULL; | 245 | return NULL; |
248 | } | 246 | } |
249 | return h; | 247 | return h; |
250 | } | 248 | } |
251 | 249 | ||
@@ -256,19 +254,19 @@ GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
256 | * @param h the handle that was being used | 254 | * @param h the handle that was being used |
257 | */ | 255 | */ |
258 | void | 256 | void |
259 | GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h) | 257 | GNUNET_ARM_monitor_stop(struct GNUNET_ARM_MonitorHandle *h) |
260 | { | 258 | { |
261 | if (NULL != h->mq) | 259 | if (NULL != h->mq) |
262 | { | 260 | { |
263 | GNUNET_MQ_destroy (h->mq); | 261 | GNUNET_MQ_destroy(h->mq); |
264 | h->mq = NULL; | 262 | h->mq = NULL; |
265 | } | 263 | } |
266 | if (NULL != h->reconnect_task) | 264 | if (NULL != h->reconnect_task) |
267 | { | 265 | { |
268 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 266 | GNUNET_SCHEDULER_cancel(h->reconnect_task); |
269 | h->reconnect_task = NULL; | 267 | h->reconnect_task = NULL; |
270 | } | 268 | } |
271 | GNUNET_free (h); | 269 | GNUNET_free(h); |
272 | } | 270 | } |
273 | 271 | ||
274 | 272 | ||