diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-09-27 22:33:50 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-09-27 22:40:19 +0200 |
commit | eadf4b7379049d32d7cfc5cffd4c88613f8a2a93 (patch) | |
tree | 74ae03df0080c9b72c4c827438b912436c6fba9a | |
parent | fa0907738dcc299ed62205a11c18241acd4761eb (diff) | |
download | gnunet-eadf4b7379049d32d7cfc5cffd4c88613f8a2a93.tar.gz gnunet-eadf4b7379049d32d7cfc5cffd4c88613f8a2a93.zip |
indent
-rw-r--r-- | src/arm/arm_api.c | 820 | ||||
-rw-r--r-- | src/util/client.c | 845 |
2 files changed, 862 insertions, 803 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index 4c3bb0488..dc5c9c25b 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2012, 2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2012, 2013, 2016, 2019 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -30,14 +30,15 @@ | |||
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "arm.h" | 31 | #include "arm.h" |
32 | 32 | ||
33 | #define LOG(kind, ...) GNUNET_log_from(kind, "arm-api", __VA_ARGS__) | 33 | #define LOG(kind, ...) GNUNET_log_from (kind, "arm-api", __VA_ARGS__) |
34 | 34 | ||
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Entry in a doubly-linked list of operations awaiting for replies | 37 | * Entry in a doubly-linked list of operations awaiting for replies |
38 | * (in-order) from the ARM service. | 38 | * (in-order) from the ARM service. |
39 | */ | 39 | */ |
40 | struct GNUNET_ARM_Operation { | 40 | struct GNUNET_ARM_Operation |
41 | { | ||
41 | /** | 42 | /** |
42 | * This is a doubly-linked list. | 43 | * This is a doubly-linked list. |
43 | */ | 44 | */ |
@@ -93,7 +94,8 @@ struct GNUNET_ARM_Operation { | |||
93 | /** | 94 | /** |
94 | * Handle for interacting with ARM. | 95 | * Handle for interacting with ARM. |
95 | */ | 96 | */ |
96 | struct GNUNET_ARM_Handle { | 97 | struct GNUNET_ARM_Handle |
98 | { | ||
97 | /** | 99 | /** |
98 | * Our connection to the ARM service. | 100 | * Our connection to the ARM service. |
99 | */ | 101 | */ |
@@ -164,7 +166,7 @@ struct GNUNET_ARM_Handle { | |||
164 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 166 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
165 | */ | 167 | */ |
166 | static int | 168 | static int |
167 | reconnect_arm(struct GNUNET_ARM_Handle *h); | 169 | reconnect_arm (struct GNUNET_ARM_Handle *h); |
168 | 170 | ||
169 | 171 | ||
170 | /** | 172 | /** |
@@ -173,12 +175,12 @@ reconnect_arm(struct GNUNET_ARM_Handle *h); | |||
173 | * @param cls the `struct GNUNET_ARM_Handle` | 175 | * @param cls the `struct GNUNET_ARM_Handle` |
174 | */ | 176 | */ |
175 | static void | 177 | static void |
176 | reconnect_arm_task(void *cls) | 178 | reconnect_arm_task (void *cls) |
177 | { | 179 | { |
178 | struct GNUNET_ARM_Handle *h = cls; | 180 | struct GNUNET_ARM_Handle *h = cls; |
179 | 181 | ||
180 | h->reconnect_task = NULL; | 182 | h->reconnect_task = NULL; |
181 | reconnect_arm(h); | 183 | reconnect_arm (h); |
182 | } | 184 | } |
183 | 185 | ||
184 | 186 | ||
@@ -189,31 +191,31 @@ reconnect_arm_task(void *cls) | |||
189 | * @param h our handle | 191 | * @param h our handle |
190 | */ | 192 | */ |
191 | static void | 193 | static void |
192 | reconnect_arm_later(struct GNUNET_ARM_Handle *h) | 194 | reconnect_arm_later (struct GNUNET_ARM_Handle *h) |
193 | { | 195 | { |
194 | struct GNUNET_ARM_Operation *op; | 196 | struct GNUNET_ARM_Operation *op; |
195 | 197 | ||
196 | if (NULL != h->mq) | 198 | if (NULL != h->mq) |
197 | { | 199 | { |
198 | GNUNET_MQ_destroy(h->mq); | 200 | GNUNET_MQ_destroy (h->mq); |
199 | h->mq = NULL; | 201 | h->mq = NULL; |
200 | } | 202 | } |
201 | h->currently_up = GNUNET_NO; | 203 | h->currently_up = GNUNET_NO; |
202 | GNUNET_assert(NULL == h->reconnect_task); | 204 | GNUNET_assert (NULL == h->reconnect_task); |
203 | h->reconnect_task = | 205 | h->reconnect_task = |
204 | GNUNET_SCHEDULER_add_delayed(h->retry_backoff, &reconnect_arm_task, h); | 206 | GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h); |
205 | while (NULL != (op = h->operation_pending_head)) | 207 | while (NULL != (op = h->operation_pending_head)) |
206 | { | 208 | { |
207 | if (NULL != op->result_cont) | 209 | if (NULL != op->result_cont) |
208 | op->result_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); | 210 | op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); |
209 | if (NULL != op->list_cont) | 211 | if (NULL != op->list_cont) |
210 | op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); | 212 | op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); |
211 | GNUNET_ARM_operation_cancel(op); | 213 | GNUNET_ARM_operation_cancel (op); |
212 | } | 214 | } |
213 | GNUNET_assert(NULL == h->operation_pending_head); | 215 | GNUNET_assert (NULL == h->operation_pending_head); |
214 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff); | 216 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); |
215 | if (NULL != h->conn_status) | 217 | if (NULL != h->conn_status) |
216 | h->conn_status(h->conn_status_cls, GNUNET_NO); | 218 | h->conn_status (h->conn_status_cls, GNUNET_NO); |
217 | } | 219 | } |
218 | 220 | ||
219 | 221 | ||
@@ -225,11 +227,11 @@ reconnect_arm_later(struct GNUNET_ARM_Handle *h) | |||
225 | * @return NULL if not found | 227 | * @return NULL if not found |
226 | */ | 228 | */ |
227 | static struct GNUNET_ARM_Operation * | 229 | static struct GNUNET_ARM_Operation * |
228 | find_op_by_id(struct GNUNET_ARM_Handle *h, uint64_t id) | 230 | find_op_by_id (struct GNUNET_ARM_Handle *h, |
231 | uint64_t id) | ||
229 | { | 232 | { |
230 | struct GNUNET_ARM_Operation *result; | 233 | for (struct GNUNET_ARM_Operation *result = h->operation_pending_head; |
231 | 234 | NULL != result; | |
232 | for (result = h->operation_pending_head; NULL != result; | ||
233 | result = result->next) | 235 | result = result->next) |
234 | if (id == result->id) | 236 | if (id == result->id) |
235 | return result; | 237 | return result; |
@@ -244,7 +246,8 @@ find_op_by_id(struct GNUNET_ARM_Handle *h, uint64_t id) | |||
244 | * @param res the message received from the arm service | 246 | * @param res the message received from the arm service |
245 | */ | 247 | */ |
246 | static void | 248 | static void |
247 | handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res) | 249 | handle_arm_result (void *cls, |
250 | const struct GNUNET_ARM_ResultMessage *res) | ||
248 | { | 251 | { |
249 | struct GNUNET_ARM_Handle *h = cls; | 252 | struct GNUNET_ARM_Handle *h = cls; |
250 | struct GNUNET_ARM_Operation *op; | 253 | struct GNUNET_ARM_Operation *op; |
@@ -253,43 +256,46 @@ handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res) | |||
253 | GNUNET_ARM_ResultCallback result_cont; | 256 | GNUNET_ARM_ResultCallback result_cont; |
254 | void *result_cont_cls; | 257 | void *result_cont_cls; |
255 | 258 | ||
256 | id = GNUNET_ntohll(res->arm_msg.request_id); | 259 | id = GNUNET_ntohll (res->arm_msg.request_id); |
257 | op = find_op_by_id(h, id); | 260 | op = find_op_by_id (h, id); |
258 | if (NULL == op) | 261 | if (NULL == op) |
259 | { | 262 | { |
260 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 263 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
261 | "Message with unknown id %llu\n", | 264 | "Message with unknown id %llu\n", |
262 | (unsigned long long)id); | 265 | (unsigned long long) id); |
263 | return; | 266 | return; |
264 | } | 267 | } |
265 | 268 | ||
266 | result = (enum GNUNET_ARM_Result)ntohl(res->result); | 269 | result = (enum GNUNET_ARM_Result) ntohl (res->result); |
267 | if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result)) | 270 | if ( (GNUNET_YES == op->is_arm_stop) && |
271 | (GNUNET_ARM_RESULT_STOPPING == result) ) | ||
272 | { | ||
273 | /* special case: if we are stopping 'gnunet-service-arm', we do not just | ||
274 | wait for the result message, but also wait for the service to close | ||
275 | the connection (and then we have to close our client handle as well); | ||
276 | this is done by installing a different receive handler, waiting for | ||
277 | the connection to go down */ | ||
278 | if (NULL != h->thm) | ||
268 | { | 279 | { |
269 | /* special case: if we are stopping 'gnunet-service-arm', we do not just | 280 | GNUNET_break (0); |
270 | wait for the result message, but also wait for the service to close | 281 | op->result_cont (h->thm->cont_cls, |
271 | the connection (and then we have to close our client handle as well); | 282 | GNUNET_ARM_REQUEST_SENT_OK, |
272 | this is done by installing a different receive handler, waiting for | 283 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); |
273 | the connection to go down */ | 284 | GNUNET_free (h->thm); |
274 | if (NULL != h->thm) | ||
275 | { | ||
276 | GNUNET_break(0); | ||
277 | op->result_cont(h->thm->cont_cls, | ||
278 | GNUNET_ARM_REQUEST_SENT_OK, | ||
279 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); | ||
280 | GNUNET_free(h->thm); | ||
281 | } | ||
282 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, | ||
283 | h->operation_pending_tail, | ||
284 | op); | ||
285 | h->thm = op; | ||
286 | return; | ||
287 | } | 285 | } |
286 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | ||
287 | h->operation_pending_tail, | ||
288 | op); | ||
289 | h->thm = op; | ||
290 | return; | ||
291 | } | ||
288 | result_cont = op->result_cont; | 292 | result_cont = op->result_cont; |
289 | result_cont_cls = op->cont_cls; | 293 | result_cont_cls = op->cont_cls; |
290 | GNUNET_ARM_operation_cancel(op); | 294 | GNUNET_ARM_operation_cancel (op); |
291 | if (NULL != result_cont) | 295 | if (NULL != result_cont) |
292 | result_cont(result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result); | 296 | result_cont (result_cont_cls, |
297 | GNUNET_ARM_REQUEST_SENT_OK, | ||
298 | result); | ||
293 | } | 299 | } |
294 | 300 | ||
295 | 301 | ||
@@ -303,7 +309,9 @@ handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res) | |||
303 | * NULL if the index is out of bounds | 309 | * NULL if the index is out of bounds |
304 | */ | 310 | */ |
305 | static const char * | 311 | static const char * |
306 | pool_get (const char *pool_start, size_t pool_size, size_t str_index) | 312 | pool_get (const char *pool_start, |
313 | size_t pool_size, | ||
314 | size_t str_index) | ||
307 | { | 315 | { |
308 | const char *str_start; | 316 | const char *str_start; |
309 | const char *end; | 317 | const char *end; |
@@ -311,7 +319,7 @@ pool_get (const char *pool_start, size_t pool_size, size_t str_index) | |||
311 | if (str_index >= pool_size) | 319 | if (str_index >= pool_size) |
312 | return NULL; | 320 | return NULL; |
313 | str_start = pool_start + str_index; | 321 | str_start = pool_start + str_index; |
314 | end = memchr(str_start, 0, pool_size - str_index); | 322 | end = memchr (str_start, 0, pool_size - str_index); |
315 | if (NULL == end) | 323 | if (NULL == end) |
316 | return NULL; | 324 | return NULL; |
317 | return str_start; | 325 | return str_start; |
@@ -326,42 +334,42 @@ pool_get (const char *pool_start, size_t pool_size, size_t str_index) | |||
326 | * @return #GNUNET_OK if message is well-formed | 334 | * @return #GNUNET_OK if message is well-formed |
327 | */ | 335 | */ |
328 | static int | 336 | static int |
329 | check_arm_list_result(void *cls, | 337 | check_arm_list_result (void *cls, |
330 | const struct GNUNET_ARM_ListResultMessage *lres) | 338 | const struct GNUNET_ARM_ListResultMessage *lres) |
331 | { | 339 | { |
332 | uint16_t rcount = ntohs(lres->count); | 340 | uint16_t rcount = ntohs (lres->count); |
333 | uint16_t msize = ntohs(lres->arm_msg.header.size) - sizeof(*lres); | 341 | uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof(*lres); |
334 | struct GNUNET_ARM_ServiceInfoMessage *ssm; | 342 | struct GNUNET_ARM_ServiceInfoMessage *ssm; |
335 | size_t pool_size; | 343 | size_t pool_size; |
336 | char *pool_start; | 344 | char *pool_start; |
337 | 345 | ||
346 | (void) cls; | ||
338 | if ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) > msize)) | 347 | if ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) > msize)) |
339 | { | 348 | { |
340 | GNUNET_break_op (0); | 349 | GNUNET_break_op (0); |
341 | return GNUNET_NO; | 350 | return GNUNET_NO; |
342 | } | 351 | } |
343 | |||
344 | ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1]; | 352 | ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1]; |
345 | pool_start = (char *) (ssm + rcount); | 353 | pool_start = (char *) (ssm + rcount); |
346 | pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage)); | 354 | pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage)); |
347 | |||
348 | (void)cls; | ||
349 | for (unsigned int i = 0; i < rcount; i++) | 355 | for (unsigned int i = 0; i < rcount; i++) |
356 | { | ||
357 | uint16_t name_index = ntohs (ssm->name_index); | ||
358 | uint16_t binary_index = ntohs (ssm->binary_index); | ||
359 | if (NULL == pool_get (pool_start, pool_size, name_index)) | ||
350 | { | 360 | { |
351 | uint16_t name_index = ntohs (ssm->name_index); | 361 | GNUNET_break_op (0); |
352 | uint16_t binary_index = ntohs (ssm->binary_index); | 362 | return GNUNET_NO; |
353 | if (NULL == pool_get (pool_start, pool_size, name_index)) | ||
354 | { | ||
355 | GNUNET_break_op (0); | ||
356 | return GNUNET_NO; | ||
357 | } | ||
358 | if (NULL == pool_get (pool_start, pool_size, binary_index)) | ||
359 | { | ||
360 | GNUNET_break_op (0); | ||
361 | return GNUNET_NO; | ||
362 | } | ||
363 | ssm++; | ||
364 | } | 363 | } |
364 | if (NULL == pool_get (pool_start, | ||
365 | pool_size, | ||
366 | binary_index)) | ||
367 | { | ||
368 | GNUNET_break_op (0); | ||
369 | return GNUNET_NO; | ||
370 | } | ||
371 | ssm++; | ||
372 | } | ||
365 | return GNUNET_OK; | 373 | return GNUNET_OK; |
366 | } | 374 | } |
367 | 375 | ||
@@ -373,12 +381,12 @@ check_arm_list_result(void *cls, | |||
373 | * @param lres the message received from the arm service | 381 | * @param lres the message received from the arm service |
374 | */ | 382 | */ |
375 | static void | 383 | static void |
376 | handle_arm_list_result(void *cls, | 384 | handle_arm_list_result (void *cls, |
377 | const struct GNUNET_ARM_ListResultMessage *lres) | 385 | const struct GNUNET_ARM_ListResultMessage *lres) |
378 | { | 386 | { |
379 | struct GNUNET_ARM_Handle *h = cls; | 387 | struct GNUNET_ARM_Handle *h = cls; |
380 | uint16_t rcount = ntohs(lres->count); | 388 | uint16_t rcount = ntohs (lres->count); |
381 | uint16_t msize = ntohs(lres->arm_msg.header.size) - sizeof(*lres); | 389 | uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof(*lres); |
382 | struct GNUNET_ARM_ServiceInfo list[rcount]; | 390 | struct GNUNET_ARM_ServiceInfo list[rcount]; |
383 | struct GNUNET_ARM_ServiceInfoMessage *ssm; | 391 | struct GNUNET_ARM_ServiceInfoMessage *ssm; |
384 | struct GNUNET_ARM_Operation *op; | 392 | struct GNUNET_ARM_Operation *op; |
@@ -386,44 +394,50 @@ handle_arm_list_result(void *cls, | |||
386 | size_t pool_size; | 394 | size_t pool_size; |
387 | char *pool_start; | 395 | char *pool_start; |
388 | 396 | ||
389 | id = GNUNET_ntohll(lres->arm_msg.request_id); | 397 | id = GNUNET_ntohll (lres->arm_msg.request_id); |
390 | op = find_op_by_id(h, id); | 398 | op = find_op_by_id (h, id); |
391 | if (NULL == op) | 399 | if (NULL == op) |
392 | { | 400 | { |
393 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 401 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
394 | "Message with unknown id %llu\n", | 402 | "Message with unknown id %llu\n", |
395 | (unsigned long long)id); | 403 | (unsigned long long) id); |
396 | return; | 404 | return; |
397 | } | 405 | } |
398 | 406 | ||
399 | GNUNET_assert ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) <= msize)); | 407 | GNUNET_assert ((rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage) <= |
408 | msize)); | ||
400 | 409 | ||
401 | ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1]; | 410 | ssm = (struct GNUNET_ARM_ServiceInfoMessage *) &lres[1]; |
402 | pool_start = (char *) (ssm + rcount); | 411 | pool_start = (char *) (ssm + rcount); |
403 | pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage)); | 412 | pool_size = msize - (rcount * sizeof (struct GNUNET_ARM_ServiceInfoMessage)); |
404 | 413 | ||
405 | for (unsigned int i = 0; i < rcount; i++) | 414 | for (unsigned int i = 0; i < rcount; i++) |
406 | { | 415 | { |
407 | uint16_t name_index = ntohs (ssm->name_index); | 416 | uint16_t name_index = ntohs (ssm->name_index); |
408 | uint16_t binary_index = ntohs (ssm->binary_index); | 417 | uint16_t binary_index = ntohs (ssm->binary_index); |
409 | const char *name; | 418 | const char *name; |
410 | const char *binary; | 419 | const char *binary; |
411 | 420 | ||
412 | GNUNET_assert (NULL != (name = pool_get (pool_start, pool_size, name_index))); | 421 | GNUNET_assert (NULL != (name = pool_get (pool_start, pool_size, |
413 | GNUNET_assert (NULL != (binary = pool_get (pool_start, pool_size, binary_index))); | 422 | name_index))); |
414 | list[i] = (struct GNUNET_ARM_ServiceInfo) { | 423 | GNUNET_assert (NULL != (binary = pool_get (pool_start, pool_size, |
415 | .name = name, | 424 | binary_index))); |
416 | .binary = binary, | 425 | list[i] = (struct GNUNET_ARM_ServiceInfo) { |
417 | .status = ntohl (ssm->status), | 426 | .name = name, |
418 | .last_started_at = GNUNET_TIME_absolute_ntoh (ssm->last_started_at), | 427 | .binary = binary, |
419 | .restart_at = GNUNET_TIME_absolute_ntoh (ssm->restart_at), | 428 | .status = ntohl (ssm->status), |
420 | .last_exit_status = ntohs (ssm->last_exit_status), | 429 | .last_started_at = GNUNET_TIME_absolute_ntoh (ssm->last_started_at), |
421 | }; | 430 | .restart_at = GNUNET_TIME_absolute_ntoh (ssm->restart_at), |
422 | ssm++; | 431 | .last_exit_status = ntohs (ssm->last_exit_status), |
423 | } | 432 | }; |
433 | ssm++; | ||
434 | } | ||
424 | if (NULL != op->list_cont) | 435 | if (NULL != op->list_cont) |
425 | op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list); | 436 | op->list_cont (op->cont_cls, |
426 | GNUNET_ARM_operation_cancel(op); | 437 | GNUNET_ARM_REQUEST_SENT_OK, |
438 | rcount, | ||
439 | list); | ||
440 | GNUNET_ARM_operation_cancel (op); | ||
427 | } | 441 | } |
428 | 442 | ||
429 | 443 | ||
@@ -434,18 +448,20 @@ handle_arm_list_result(void *cls, | |||
434 | * @param msg message received | 448 | * @param msg message received |
435 | */ | 449 | */ |
436 | static void | 450 | static void |
437 | handle_confirm(void *cls, const struct GNUNET_MessageHeader *msg) | 451 | handle_confirm (void *cls, |
452 | const struct GNUNET_MessageHeader *msg) | ||
438 | { | 453 | { |
439 | struct GNUNET_ARM_Handle *h = cls; | 454 | struct GNUNET_ARM_Handle *h = cls; |
440 | 455 | ||
441 | (void)msg; | 456 | (void) msg; |
442 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n"); | 457 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
458 | "Got confirmation from ARM that we are up!\n"); | ||
443 | if (GNUNET_NO == h->currently_up) | 459 | if (GNUNET_NO == h->currently_up) |
444 | { | 460 | { |
445 | h->currently_up = GNUNET_YES; | 461 | h->currently_up = GNUNET_YES; |
446 | if (NULL != h->conn_status) | 462 | if (NULL != h->conn_status) |
447 | h->conn_status(h->conn_status_cls, GNUNET_YES); | 463 | h->conn_status (h->conn_status_cls, GNUNET_YES); |
448 | } | 464 | } |
449 | } | 465 | } |
450 | 466 | ||
451 | 467 | ||
@@ -458,22 +474,23 @@ handle_confirm(void *cls, const struct GNUNET_MessageHeader *msg) | |||
458 | * @param error error code | 474 | * @param error error code |
459 | */ | 475 | */ |
460 | static void | 476 | static void |
461 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 477 | mq_error_handler (void *cls, |
478 | enum GNUNET_MQ_Error error) | ||
462 | { | 479 | { |
463 | struct GNUNET_ARM_Handle *h = cls; | 480 | struct GNUNET_ARM_Handle *h = cls; |
464 | struct GNUNET_ARM_Operation *op; | 481 | struct GNUNET_ARM_Operation *op; |
465 | 482 | ||
466 | (void)error; | 483 | (void) error; |
467 | h->currently_up = GNUNET_NO; | 484 | h->currently_up = GNUNET_NO; |
468 | if (NULL != (op = h->thm)) | 485 | if (NULL != (op = h->thm)) |
469 | { | 486 | { |
470 | h->thm = NULL; | 487 | h->thm = NULL; |
471 | op->result_cont(op->cont_cls, | 488 | op->result_cont (op->cont_cls, |
472 | GNUNET_ARM_REQUEST_SENT_OK, | 489 | GNUNET_ARM_REQUEST_SENT_OK, |
473 | GNUNET_ARM_RESULT_STOPPED); | 490 | GNUNET_ARM_RESULT_STOPPED); |
474 | GNUNET_free(op); | 491 | GNUNET_free (op); |
475 | } | 492 | } |
476 | reconnect_arm_later(h); | 493 | reconnect_arm_later (h); |
477 | } | 494 | } |
478 | 495 | ||
479 | 496 | ||
@@ -484,39 +501,48 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
484 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 501 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
485 | */ | 502 | */ |
486 | static int | 503 | static int |
487 | reconnect_arm(struct GNUNET_ARM_Handle *h) | 504 | reconnect_arm (struct GNUNET_ARM_Handle *h) |
488 | { | 505 | { |
489 | struct GNUNET_MQ_MessageHandler handlers[] = | 506 | struct GNUNET_MQ_MessageHandler handlers[] = { |
490 | { GNUNET_MQ_hd_fixed_size(arm_result, | 507 | GNUNET_MQ_hd_fixed_size (arm_result, |
491 | GNUNET_MESSAGE_TYPE_ARM_RESULT, | 508 | GNUNET_MESSAGE_TYPE_ARM_RESULT, |
492 | struct GNUNET_ARM_ResultMessage, | 509 | struct GNUNET_ARM_ResultMessage, |
493 | h), | 510 | h), |
494 | GNUNET_MQ_hd_var_size(arm_list_result, | 511 | GNUNET_MQ_hd_var_size (arm_list_result, |
495 | GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, | 512 | GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, |
496 | struct GNUNET_ARM_ListResultMessage, | 513 | struct GNUNET_ARM_ListResultMessage, |
497 | h), | 514 | h), |
498 | GNUNET_MQ_hd_fixed_size(confirm, | 515 | GNUNET_MQ_hd_fixed_size (confirm, |
499 | GNUNET_MESSAGE_TYPE_ARM_TEST, | 516 | GNUNET_MESSAGE_TYPE_ARM_TEST, |
500 | struct GNUNET_MessageHeader, | 517 | struct GNUNET_MessageHeader, |
501 | h), | 518 | h), |
502 | GNUNET_MQ_handler_end() }; | 519 | GNUNET_MQ_handler_end () |
520 | }; | ||
503 | struct GNUNET_MessageHeader *test; | 521 | struct GNUNET_MessageHeader *test; |
504 | struct GNUNET_MQ_Envelope *env; | 522 | struct GNUNET_MQ_Envelope *env; |
505 | 523 | ||
506 | if (NULL != h->mq) | 524 | if (NULL != h->mq) |
507 | return GNUNET_OK; | 525 | return GNUNET_OK; |
508 | GNUNET_assert(GNUNET_NO == h->currently_up); | 526 | GNUNET_assert (GNUNET_NO == h->currently_up); |
509 | h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h); | 527 | h->mq = GNUNET_CLIENT_connect (h->cfg, |
528 | "arm", | ||
529 | handlers, | ||
530 | &mq_error_handler, | ||
531 | h); | ||
510 | if (NULL == h->mq) | 532 | if (NULL == h->mq) |
511 | { | 533 | { |
512 | LOG(GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n"); | 534 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
513 | if (NULL != h->conn_status) | 535 | "GNUNET_CLIENT_connect returned NULL\n"); |
514 | h->conn_status(h->conn_status_cls, GNUNET_SYSERR); | 536 | if (NULL != h->conn_status) |
515 | return GNUNET_SYSERR; | 537 | h->conn_status (h->conn_status_cls, |
516 | } | 538 | GNUNET_SYSERR); |
517 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n"); | 539 | return GNUNET_SYSERR; |
518 | env = GNUNET_MQ_msg(test, GNUNET_MESSAGE_TYPE_ARM_TEST); | 540 | } |
519 | GNUNET_MQ_send(h->mq, env); | 541 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
542 | "Sending TEST message to ARM\n"); | ||
543 | env = GNUNET_MQ_msg (test, | ||
544 | GNUNET_MESSAGE_TYPE_ARM_TEST); | ||
545 | GNUNET_MQ_send (h->mq, env); | ||
520 | return GNUNET_OK; | 546 | return GNUNET_OK; |
521 | } | 547 | } |
522 | 548 | ||
@@ -533,21 +559,21 @@ reconnect_arm(struct GNUNET_ARM_Handle *h) | |||
533 | * @return context to use for further ARM operations, NULL on error. | 559 | * @return context to use for further ARM operations, NULL on error. |
534 | */ | 560 | */ |
535 | struct GNUNET_ARM_Handle * | 561 | struct GNUNET_ARM_Handle * |
536 | GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | 562 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
537 | GNUNET_ARM_ConnectionStatusCallback conn_status, | 563 | GNUNET_ARM_ConnectionStatusCallback conn_status, |
538 | void *conn_status_cls) | 564 | void *conn_status_cls) |
539 | { | 565 | { |
540 | struct GNUNET_ARM_Handle *h; | 566 | struct GNUNET_ARM_Handle *h; |
541 | 567 | ||
542 | h = GNUNET_new(struct GNUNET_ARM_Handle); | 568 | h = GNUNET_new (struct GNUNET_ARM_Handle); |
543 | h->cfg = cfg; | 569 | h->cfg = cfg; |
544 | h->conn_status = conn_status; | 570 | h->conn_status = conn_status; |
545 | h->conn_status_cls = conn_status_cls; | 571 | h->conn_status_cls = conn_status_cls; |
546 | if (GNUNET_OK != reconnect_arm(h)) | 572 | if (GNUNET_OK != reconnect_arm (h)) |
547 | { | 573 | { |
548 | GNUNET_free(h); | 574 | GNUNET_free (h); |
549 | return NULL; | 575 | return NULL; |
550 | } | 576 | } |
551 | return h; | 577 | return h; |
552 | } | 578 | } |
553 | 579 | ||
@@ -558,38 +584,43 @@ GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
558 | * @param h the handle that was being used | 584 | * @param h the handle that was being used |
559 | */ | 585 | */ |
560 | void | 586 | void |
561 | GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h) | 587 | GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h) |
562 | { | 588 | { |
563 | struct GNUNET_ARM_Operation *op; | 589 | struct GNUNET_ARM_Operation *op; |
564 | 590 | ||
565 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); | 591 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); |
566 | while (NULL != (op = h->operation_pending_head)) | 592 | while (NULL != (op = h->operation_pending_head)) |
593 | { | ||
594 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | ||
595 | h->operation_pending_tail, | ||
596 | op); | ||
597 | if (NULL != op->result_cont) | ||
598 | op->result_cont (op->cont_cls, | ||
599 | GNUNET_ARM_REQUEST_DISCONNECTED, | ||
600 | 0); | ||
601 | if (NULL != op->list_cont) | ||
602 | op->list_cont (op->cont_cls, | ||
603 | GNUNET_ARM_REQUEST_DISCONNECTED, | ||
604 | 0, | ||
605 | NULL); | ||
606 | if (NULL != op->async) | ||
567 | { | 607 | { |
568 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, | 608 | GNUNET_SCHEDULER_cancel (op->async); |
569 | h->operation_pending_tail, | 609 | op->async = NULL; |
570 | op); | ||
571 | if (NULL != op->result_cont) | ||
572 | op->result_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); | ||
573 | if (NULL != op->list_cont) | ||
574 | op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); | ||
575 | if (NULL != op->async) | ||
576 | { | ||
577 | GNUNET_SCHEDULER_cancel(op->async); | ||
578 | op->async = NULL; | ||
579 | } | ||
580 | GNUNET_free(op); | ||
581 | } | 610 | } |
611 | GNUNET_free (op); | ||
612 | } | ||
582 | if (NULL != h->mq) | 613 | if (NULL != h->mq) |
583 | { | 614 | { |
584 | GNUNET_MQ_destroy(h->mq); | 615 | GNUNET_MQ_destroy (h->mq); |
585 | h->mq = NULL; | 616 | h->mq = NULL; |
586 | } | 617 | } |
587 | if (NULL != h->reconnect_task) | 618 | if (NULL != h->reconnect_task) |
588 | { | 619 | { |
589 | GNUNET_SCHEDULER_cancel(h->reconnect_task); | 620 | GNUNET_SCHEDULER_cancel (h->reconnect_task); |
590 | h->reconnect_task = NULL; | 621 | h->reconnect_task = NULL; |
591 | } | 622 | } |
592 | GNUNET_free(h); | 623 | GNUNET_free (h); |
593 | } | 624 | } |
594 | 625 | ||
595 | 626 | ||
@@ -602,8 +633,8 @@ GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h) | |||
602 | * @return operation status code | 633 | * @return operation status code |
603 | */ | 634 | */ |
604 | static enum GNUNET_ARM_Result | 635 | static enum GNUNET_ARM_Result |
605 | start_arm_service(struct GNUNET_ARM_Handle *h, | 636 | start_arm_service (struct GNUNET_ARM_Handle *h, |
606 | enum GNUNET_OS_InheritStdioFlags std_inheritance) | 637 | enum GNUNET_OS_InheritStdioFlags std_inheritance) |
607 | { | 638 | { |
608 | struct GNUNET_OS_Process *proc; | 639 | struct GNUNET_OS_Process *proc; |
609 | char *cbinary; | 640 | char *cbinary; |
@@ -613,98 +644,111 @@ start_arm_service(struct GNUNET_ARM_Handle *h, | |||
613 | char *loprefix; | 644 | char *loprefix; |
614 | char *lopostfix; | 645 | char *lopostfix; |
615 | 646 | ||
616 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(h->cfg, | 647 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, |
617 | "arm", | 648 | "arm", |
618 | "PREFIX", | 649 | "PREFIX", |
619 | &loprefix)) | 650 | &loprefix)) |
620 | loprefix = GNUNET_strdup(""); | 651 | loprefix = GNUNET_strdup (""); |
621 | else | 652 | else |
622 | loprefix = GNUNET_CONFIGURATION_expand_dollar(h->cfg, loprefix); | 653 | loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix); |
623 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(h->cfg, | 654 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, |
624 | "arm", | 655 | "arm", |
625 | "OPTIONS", | 656 | "OPTIONS", |
626 | &lopostfix)) | 657 | &lopostfix)) |
627 | lopostfix = GNUNET_strdup(""); | 658 | lopostfix = GNUNET_strdup (""); |
628 | else | 659 | else |
629 | lopostfix = GNUNET_CONFIGURATION_expand_dollar(h->cfg, lopostfix); | 660 | lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, |
661 | lopostfix); | ||
630 | if (GNUNET_OK != | 662 | if (GNUNET_OK != |
631 | GNUNET_CONFIGURATION_get_value_string(h->cfg, "arm", "BINARY", &cbinary)) | 663 | GNUNET_CONFIGURATION_get_value_string (h->cfg, |
632 | { | 664 | "arm", |
633 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY"); | 665 | "BINARY", |
634 | GNUNET_free(loprefix); | 666 | &cbinary)) |
635 | GNUNET_free(lopostfix); | 667 | { |
636 | return GNUNET_ARM_RESULT_IS_NOT_KNOWN; | 668 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
637 | } | 669 | "arm", |
638 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, | 670 | "BINARY"); |
639 | "arm", | 671 | GNUNET_free (loprefix); |
640 | "CONFIG", | 672 | GNUNET_free (lopostfix); |
641 | &config)) | 673 | return GNUNET_ARM_RESULT_IS_NOT_KNOWN; |
674 | } | ||
675 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, | ||
676 | "arm", | ||
677 | "CONFIG", | ||
678 | &config)) | ||
642 | config = NULL; | 679 | config = NULL; |
643 | binary = GNUNET_OS_get_libexec_binary_path(cbinary); | 680 | binary = GNUNET_OS_get_libexec_binary_path (cbinary); |
644 | GNUNET_asprintf("edbinary, "\"%s\"", binary); | 681 | GNUNET_asprintf ("edbinary, |
645 | GNUNET_free(cbinary); | 682 | "\"%s\"", |
646 | if ((GNUNET_YES == | 683 | binary); |
647 | GNUNET_CONFIGURATION_have_value(h->cfg, "TESTING", "WEAKRANDOM")) && | 684 | GNUNET_free (cbinary); |
648 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(h->cfg, | 685 | if ( (GNUNET_YES == |
649 | "TESTING", | 686 | GNUNET_CONFIGURATION_have_value (h->cfg, |
650 | "WEAKRANDOM")) && | 687 | "TESTING", |
651 | (GNUNET_NO == | 688 | "WEAKRANDOM")) && |
652 | GNUNET_CONFIGURATION_have_value(h->cfg, "TESTING", "HOSTFILE"))) | 689 | (GNUNET_YES == |
653 | { | 690 | GNUNET_CONFIGURATION_get_value_yesno (h->cfg, |
654 | /* Means we are ONLY running locally */ | 691 | "TESTING", |
655 | /* we're clearly running a test, don't daemonize */ | 692 | "WEAKRANDOM")) && |
656 | if (NULL == config) | 693 | (GNUNET_NO == |
657 | proc = GNUNET_OS_start_process_s(GNUNET_NO, | 694 | GNUNET_CONFIGURATION_have_value (h->cfg, |
658 | std_inheritance, | 695 | "TESTING", |
659 | NULL, | 696 | "HOSTFILE")) ) |
660 | loprefix, | 697 | { |
661 | quotedbinary, | 698 | /* Means we are ONLY running locally */ |
662 | /* no daemonization! */ | 699 | /* we're clearly running a test, don't daemonize */ |
663 | lopostfix, | 700 | if (NULL == config) |
664 | NULL); | 701 | proc = GNUNET_OS_start_process_s (GNUNET_NO, |
665 | else | 702 | std_inheritance, |
666 | proc = GNUNET_OS_start_process_s(GNUNET_NO, | 703 | NULL, |
667 | std_inheritance, | 704 | loprefix, |
668 | NULL, | 705 | quotedbinary, |
669 | loprefix, | 706 | /* no daemonization! */ |
670 | quotedbinary, | 707 | lopostfix, |
671 | "-c", | 708 | NULL); |
672 | config, | 709 | else |
673 | /* no daemonization! */ | 710 | proc = GNUNET_OS_start_process_s (GNUNET_NO, |
674 | lopostfix, | 711 | std_inheritance, |
675 | NULL); | 712 | NULL, |
676 | } | 713 | loprefix, |
714 | quotedbinary, | ||
715 | "-c", | ||
716 | config, | ||
717 | /* no daemonization! */ | ||
718 | lopostfix, | ||
719 | NULL); | ||
720 | } | ||
677 | else | 721 | else |
678 | { | 722 | { |
679 | if (NULL == config) | 723 | if (NULL == config) |
680 | proc = GNUNET_OS_start_process_s(GNUNET_NO, | 724 | proc = GNUNET_OS_start_process_s (GNUNET_NO, |
681 | std_inheritance, | 725 | std_inheritance, |
682 | NULL, | 726 | NULL, |
683 | loprefix, | 727 | loprefix, |
684 | quotedbinary, | 728 | quotedbinary, |
685 | "-d", /* do daemonize */ | 729 | "-d", /* do daemonize */ |
686 | lopostfix, | 730 | lopostfix, |
687 | NULL); | 731 | NULL); |
688 | else | 732 | else |
689 | proc = GNUNET_OS_start_process_s(GNUNET_NO, | 733 | proc = GNUNET_OS_start_process_s (GNUNET_NO, |
690 | std_inheritance, | 734 | std_inheritance, |
691 | NULL, | 735 | NULL, |
692 | loprefix, | 736 | loprefix, |
693 | quotedbinary, | 737 | quotedbinary, |
694 | "-c", | 738 | "-c", |
695 | config, | 739 | config, |
696 | "-d", /* do daemonize */ | 740 | "-d", /* do daemonize */ |
697 | lopostfix, | 741 | lopostfix, |
698 | NULL); | 742 | NULL); |
699 | } | 743 | } |
700 | GNUNET_free(binary); | 744 | GNUNET_free (binary); |
701 | GNUNET_free(quotedbinary); | 745 | GNUNET_free (quotedbinary); |
702 | GNUNET_free_non_null(config); | 746 | GNUNET_free_non_null (config); |
703 | GNUNET_free(loprefix); | 747 | GNUNET_free (loprefix); |
704 | GNUNET_free(lopostfix); | 748 | GNUNET_free (lopostfix); |
705 | if (NULL == proc) | 749 | if (NULL == proc) |
706 | return GNUNET_ARM_RESULT_START_FAILED; | 750 | return GNUNET_ARM_RESULT_START_FAILED; |
707 | GNUNET_OS_process_destroy(proc); | 751 | GNUNET_OS_process_destroy (proc); |
708 | return GNUNET_ARM_RESULT_STARTING; | 752 | return GNUNET_ARM_RESULT_STARTING; |
709 | } | 753 | } |
710 | 754 | ||
@@ -716,19 +760,19 @@ start_arm_service(struct GNUNET_ARM_Handle *h, | |||
716 | * @param op operation to cancel | 760 | * @param op operation to cancel |
717 | */ | 761 | */ |
718 | void | 762 | void |
719 | GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op) | 763 | GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op) |
720 | { | 764 | { |
721 | struct GNUNET_ARM_Handle *h = op->h; | 765 | struct GNUNET_ARM_Handle *h = op->h; |
722 | 766 | ||
723 | if (h->thm == op) | 767 | if (h->thm == op) |
724 | { | 768 | { |
725 | op->result_cont = NULL; | 769 | op->result_cont = NULL; |
726 | return; | 770 | return; |
727 | } | 771 | } |
728 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, | 772 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, |
729 | h->operation_pending_tail, | 773 | h->operation_pending_tail, |
730 | op); | 774 | op); |
731 | GNUNET_free(op); | 775 | GNUNET_free (op); |
732 | } | 776 | } |
733 | 777 | ||
734 | 778 | ||
@@ -743,38 +787,38 @@ GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op) | |||
743 | * @return handle to queue, NULL on error | 787 | * @return handle to queue, NULL on error |
744 | */ | 788 | */ |
745 | static struct GNUNET_ARM_Operation * | 789 | static struct GNUNET_ARM_Operation * |
746 | change_service(struct GNUNET_ARM_Handle *h, | 790 | change_service (struct GNUNET_ARM_Handle *h, |
747 | const char *service_name, | 791 | const char *service_name, |
748 | GNUNET_ARM_ResultCallback cb, | 792 | GNUNET_ARM_ResultCallback cb, |
749 | void *cb_cls, | 793 | void *cb_cls, |
750 | uint16_t type) | 794 | uint16_t type) |
751 | { | 795 | { |
752 | struct GNUNET_ARM_Operation *op; | 796 | struct GNUNET_ARM_Operation *op; |
753 | size_t slen; | 797 | size_t slen; |
754 | struct GNUNET_MQ_Envelope *env; | 798 | struct GNUNET_MQ_Envelope *env; |
755 | struct GNUNET_ARM_Message *msg; | 799 | struct GNUNET_ARM_Message *msg; |
756 | 800 | ||
757 | slen = strlen(service_name) + 1; | 801 | slen = strlen (service_name) + 1; |
758 | if (slen + sizeof(struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE) | 802 | if (slen + sizeof(struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE) |
759 | { | 803 | { |
760 | GNUNET_break(0); | 804 | GNUNET_break (0); |
761 | return NULL; | 805 | return NULL; |
762 | } | 806 | } |
763 | if (0 == h->request_id_counter) | 807 | if (0 == h->request_id_counter) |
764 | h->request_id_counter++; | 808 | h->request_id_counter++; |
765 | op = GNUNET_new(struct GNUNET_ARM_Operation); | 809 | op = GNUNET_new (struct GNUNET_ARM_Operation); |
766 | op->h = h; | 810 | op->h = h; |
767 | op->result_cont = cb; | 811 | op->result_cont = cb; |
768 | op->cont_cls = cb_cls; | 812 | op->cont_cls = cb_cls; |
769 | op->id = h->request_id_counter++; | 813 | op->id = h->request_id_counter++; |
770 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, | 814 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, |
771 | h->operation_pending_tail, | 815 | h->operation_pending_tail, |
772 | op); | 816 | op); |
773 | env = GNUNET_MQ_msg_extra(msg, slen, type); | 817 | env = GNUNET_MQ_msg_extra (msg, slen, type); |
774 | msg->reserved = htonl(0); | 818 | msg->reserved = htonl (0); |
775 | msg->request_id = GNUNET_htonll(op->id); | 819 | msg->request_id = GNUNET_htonll (op->id); |
776 | GNUNET_memcpy(&msg[1], service_name, slen); | 820 | GNUNET_memcpy (&msg[1], service_name, slen); |
777 | GNUNET_MQ_send(h->mq, env); | 821 | GNUNET_MQ_send (h->mq, env); |
778 | return op; | 822 | return op; |
779 | } | 823 | } |
780 | 824 | ||
@@ -785,22 +829,24 @@ change_service(struct GNUNET_ARM_Handle *h, | |||
785 | * @param cls the operation that asked ARM to be started | 829 | * @param cls the operation that asked ARM to be started |
786 | */ | 830 | */ |
787 | static void | 831 | static void |
788 | notify_running(void *cls) | 832 | notify_running (void *cls) |
789 | { | 833 | { |
790 | struct GNUNET_ARM_Operation *op = cls; | 834 | struct GNUNET_ARM_Operation *op = cls; |
791 | struct GNUNET_ARM_Handle *h = op->h; | 835 | struct GNUNET_ARM_Handle *h = op->h; |
792 | 836 | ||
793 | op->async = NULL; | 837 | op->async = NULL; |
794 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, | 838 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, |
795 | h->operation_pending_tail, | 839 | h->operation_pending_tail, |
796 | op); | 840 | op); |
797 | if (NULL != op->result_cont) | 841 | if (NULL != op->result_cont) |
798 | op->result_cont(op->cont_cls, | 842 | op->result_cont (op->cont_cls, |
799 | GNUNET_ARM_REQUEST_SENT_OK, | 843 | GNUNET_ARM_REQUEST_SENT_OK, |
800 | GNUNET_ARM_RESULT_IS_STARTED_ALREADY); | 844 | GNUNET_ARM_RESULT_IS_STARTED_ALREADY); |
801 | if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status)) | 845 | if ( (GNUNET_YES == h->currently_up) && |
802 | h->conn_status(h->conn_status_cls, GNUNET_YES); | 846 | (NULL != h->conn_status) ) |
803 | GNUNET_free(op); | 847 | h->conn_status (h->conn_status_cls, |
848 | GNUNET_YES); | ||
849 | GNUNET_free (op); | ||
804 | } | 850 | } |
805 | 851 | ||
806 | 852 | ||
@@ -810,22 +856,22 @@ notify_running(void *cls) | |||
810 | * @param cls the operation that asked ARM to be started | 856 | * @param cls the operation that asked ARM to be started |
811 | */ | 857 | */ |
812 | static void | 858 | static void |
813 | notify_starting(void *cls) | 859 | notify_starting (void *cls) |
814 | { | 860 | { |
815 | struct GNUNET_ARM_Operation *op = cls; | 861 | struct GNUNET_ARM_Operation *op = cls; |
816 | struct GNUNET_ARM_Handle *h = op->h; | 862 | struct GNUNET_ARM_Handle *h = op->h; |
817 | 863 | ||
818 | op->async = NULL; | 864 | op->async = NULL; |
819 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 865 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
820 | "Notifying client that we started the ARM service\n"); | 866 | "Notifying client that we started the ARM service\n"); |
821 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, | 867 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, |
822 | h->operation_pending_tail, | 868 | h->operation_pending_tail, |
823 | op); | 869 | op); |
824 | if (NULL != op->result_cont) | 870 | if (NULL != op->result_cont) |
825 | op->result_cont(op->cont_cls, | 871 | op->result_cont (op->cont_cls, |
826 | GNUNET_ARM_REQUEST_SENT_OK, | 872 | GNUNET_ARM_REQUEST_SENT_OK, |
827 | op->starting_ret); | 873 | op->starting_ret); |
828 | GNUNET_free(op); | 874 | GNUNET_free (op); |
829 | } | 875 | } |
830 | 876 | ||
831 | 877 | ||
@@ -840,23 +886,26 @@ notify_starting(void *cls) | |||
840 | * @return handle for the operation, NULL on error | 886 | * @return handle for the operation, NULL on error |
841 | */ | 887 | */ |
842 | struct GNUNET_ARM_Operation * | 888 | struct GNUNET_ARM_Operation * |
843 | GNUNET_ARM_request_service_start( | 889 | GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, |
844 | struct GNUNET_ARM_Handle *h, | 890 | const char *service_name, |
845 | const char *service_name, | 891 | enum GNUNET_OS_InheritStdioFlags |
846 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | 892 | std_inheritance, |
847 | GNUNET_ARM_ResultCallback cont, | 893 | GNUNET_ARM_ResultCallback cont, |
848 | void *cont_cls) | 894 | void *cont_cls) |
849 | { | 895 | { |
850 | struct GNUNET_ARM_Operation *op; | 896 | struct GNUNET_ARM_Operation *op; |
851 | enum GNUNET_ARM_Result ret; | 897 | enum GNUNET_ARM_Result ret; |
852 | 898 | ||
853 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name); | 899 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
854 | if (0 != strcasecmp("arm", service_name)) | 900 | "Starting service `%s'\n", |
855 | return change_service(h, | 901 | service_name); |
856 | service_name, | 902 | if (0 != strcasecmp ("arm", |
857 | cont, | 903 | service_name)) |
858 | cont_cls, | 904 | return change_service (h, |
859 | GNUNET_MESSAGE_TYPE_ARM_START); | 905 | service_name, |
906 | cont, | ||
907 | cont_cls, | ||
908 | GNUNET_MESSAGE_TYPE_ARM_START); | ||
860 | 909 | ||
861 | /* Possible cases: | 910 | /* Possible cases: |
862 | * 1) We're connected to ARM already. Invoke the callback immediately. | 911 | * 1) We're connected to ARM already. Invoke the callback immediately. |
@@ -865,37 +914,39 @@ GNUNET_ARM_request_service_start( | |||
865 | * a service test. | 914 | * a service test. |
866 | */ | 915 | */ |
867 | if (GNUNET_YES == h->currently_up) | 916 | if (GNUNET_YES == h->currently_up) |
868 | { | 917 | { |
869 | LOG(GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n"); | 918 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
870 | op = GNUNET_new(struct GNUNET_ARM_Operation); | 919 | "ARM is already running\n"); |
871 | op->h = h; | 920 | op = GNUNET_new (struct GNUNET_ARM_Operation); |
872 | op->result_cont = cont; | 921 | op->h = h; |
873 | op->cont_cls = cont_cls; | 922 | op->result_cont = cont; |
874 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, | 923 | op->cont_cls = cont_cls; |
875 | h->operation_pending_tail, | 924 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, |
876 | op); | 925 | h->operation_pending_tail, |
877 | op->async = GNUNET_SCHEDULER_add_now(¬ify_running, op); | 926 | op); |
878 | return op; | 927 | op->async = GNUNET_SCHEDULER_add_now (¬ify_running, op); |
879 | } | 928 | return op; |
929 | } | ||
880 | /* This is an inherently uncertain choice, as it is of course | 930 | /* This is an inherently uncertain choice, as it is of course |
881 | theoretically possible that ARM is up and we just did not | 931 | theoretically possible that ARM is up and we just did not |
882 | yet complete the MQ handshake. However, given that users | 932 | yet complete the MQ handshake. However, given that users |
883 | are unlikely to hammer 'gnunet-arm -s' on a busy system, | 933 | are unlikely to hammer 'gnunet-arm -s' on a busy system, |
884 | the above check should catch 99.99% of the cases where ARM | 934 | the above check should catch 99.99% of the cases where ARM |
885 | is already running. */ | 935 | is already running. */ |
886 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); | 936 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); |
887 | ret = start_arm_service(h, std_inheritance); | 937 | ret = start_arm_service (h, std_inheritance); |
888 | if (GNUNET_ARM_RESULT_STARTING == ret) | 938 | if (GNUNET_ARM_RESULT_STARTING == ret) |
889 | reconnect_arm(h); | 939 | reconnect_arm (h); |
890 | op = GNUNET_new(struct GNUNET_ARM_Operation); | 940 | op = GNUNET_new (struct GNUNET_ARM_Operation); |
891 | op->h = h; | 941 | op->h = h; |
892 | op->result_cont = cont; | 942 | op->result_cont = cont; |
893 | op->cont_cls = cont_cls; | 943 | op->cont_cls = cont_cls; |
894 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, | 944 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, |
895 | h->operation_pending_tail, | 945 | h->operation_pending_tail, |
896 | op); | 946 | op); |
897 | op->starting_ret = ret; | 947 | op->starting_ret = ret; |
898 | op->async = GNUNET_SCHEDULER_add_now(¬ify_starting, op); | 948 | op->async = GNUNET_SCHEDULER_add_now (¬ify_starting, |
949 | op); | ||
899 | return op; | 950 | return op; |
900 | } | 951 | } |
901 | 952 | ||
@@ -915,24 +966,27 @@ GNUNET_ARM_request_service_start( | |||
915 | * @return handle for the operation, NULL on error | 966 | * @return handle for the operation, NULL on error |
916 | */ | 967 | */ |
917 | struct GNUNET_ARM_Operation * | 968 | struct GNUNET_ARM_Operation * |
918 | GNUNET_ARM_request_service_stop(struct GNUNET_ARM_Handle *h, | 969 | GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, |
919 | const char *service_name, | 970 | const char *service_name, |
920 | GNUNET_ARM_ResultCallback cont, | 971 | GNUNET_ARM_ResultCallback cont, |
921 | void *cont_cls) | 972 | void *cont_cls) |
922 | { | 973 | { |
923 | struct GNUNET_ARM_Operation *op; | 974 | struct GNUNET_ARM_Operation *op; |
924 | 975 | ||
925 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name); | 976 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
926 | op = change_service(h, | 977 | "Stopping service `%s'\n", |
927 | service_name, | 978 | service_name); |
928 | cont, | 979 | op = change_service (h, |
929 | cont_cls, | 980 | service_name, |
930 | GNUNET_MESSAGE_TYPE_ARM_STOP); | 981 | cont, |
982 | cont_cls, | ||
983 | GNUNET_MESSAGE_TYPE_ARM_STOP); | ||
931 | if (NULL == op) | 984 | if (NULL == op) |
932 | return NULL; | 985 | return NULL; |
933 | /* If the service is ARM, set a flag as we will use MQ errors | 986 | /* If the service is ARM, set a flag as we will use MQ errors |
934 | to detect that the process is really gone. */ | 987 | to detect that the process is really gone. */ |
935 | if (0 == strcasecmp(service_name, "arm")) | 988 | if (0 == strcasecmp (service_name, |
989 | "arm")) | ||
936 | op->is_arm_stop = GNUNET_YES; | 990 | op->is_arm_stop = GNUNET_YES; |
937 | return op; | 991 | return op; |
938 | } | 992 | } |
@@ -947,29 +1001,31 @@ GNUNET_ARM_request_service_stop(struct GNUNET_ARM_Handle *h, | |||
947 | * @return handle for the operation, NULL on error | 1001 | * @return handle for the operation, NULL on error |
948 | */ | 1002 | */ |
949 | struct GNUNET_ARM_Operation * | 1003 | struct GNUNET_ARM_Operation * |
950 | GNUNET_ARM_request_service_list(struct GNUNET_ARM_Handle *h, | 1004 | GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, |
951 | GNUNET_ARM_ServiceListCallback cont, | 1005 | GNUNET_ARM_ServiceListCallback cont, |
952 | void *cont_cls) | 1006 | void *cont_cls) |
953 | { | 1007 | { |
954 | struct GNUNET_ARM_Operation *op; | 1008 | struct GNUNET_ARM_Operation *op; |
955 | struct GNUNET_MQ_Envelope *env; | 1009 | struct GNUNET_MQ_Envelope *env; |
956 | struct GNUNET_ARM_Message *msg; | 1010 | struct GNUNET_ARM_Message *msg; |
957 | 1011 | ||
958 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n"); | 1012 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1013 | "Requesting LIST from ARM service\n"); | ||
959 | if (0 == h->request_id_counter) | 1014 | if (0 == h->request_id_counter) |
960 | h->request_id_counter++; | 1015 | h->request_id_counter++; |
961 | op = GNUNET_new(struct GNUNET_ARM_Operation); | 1016 | op = GNUNET_new (struct GNUNET_ARM_Operation); |
962 | op->h = h; | 1017 | op->h = h; |
963 | op->list_cont = cont; | 1018 | op->list_cont = cont; |
964 | op->cont_cls = cont_cls; | 1019 | op->cont_cls = cont_cls; |
965 | op->id = h->request_id_counter++; | 1020 | op->id = h->request_id_counter++; |
966 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, | 1021 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, |
967 | h->operation_pending_tail, | 1022 | h->operation_pending_tail, |
968 | op); | 1023 | op); |
969 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_LIST); | 1024 | env = GNUNET_MQ_msg (msg, |
970 | msg->reserved = htonl(0); | 1025 | GNUNET_MESSAGE_TYPE_ARM_LIST); |
971 | msg->request_id = GNUNET_htonll(op->id); | 1026 | msg->reserved = htonl (0); |
972 | GNUNET_MQ_send(h->mq, env); | 1027 | msg->request_id = GNUNET_htonll (op->id); |
1028 | GNUNET_MQ_send (h->mq, env); | ||
973 | return op; | 1029 | return op; |
974 | } | 1030 | } |
975 | 1031 | ||
diff --git a/src/util/client.c b/src/util/client.c index e3585af2e..5a77b9238 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2001-2016 GNUnet e.V. | 3 | Copyright (C) 2001-2016, 2019 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -33,7 +33,7 @@ | |||
33 | #include "gnunet_socks.h" | 33 | #include "gnunet_socks.h" |
34 | 34 | ||
35 | 35 | ||
36 | #define LOG(kind, ...) GNUNET_log_from(kind, "util-client", __VA_ARGS__) | 36 | #define LOG(kind, ...) GNUNET_log_from (kind, "util-client", __VA_ARGS__) |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Timeout we use on TCP connect before trying another | 39 | * Timeout we use on TCP connect before trying another |
@@ -41,7 +41,8 @@ | |||
41 | * is this value divided by the number of address families. | 41 | * is this value divided by the number of address families. |
42 | * Default is 5s. | 42 | * Default is 5s. |
43 | */ | 43 | */ |
44 | #define CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 44 | #define CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply ( \ |
45 | GNUNET_TIME_UNIT_SECONDS, 5) | ||
45 | 46 | ||
46 | 47 | ||
47 | 48 | ||
@@ -55,7 +56,8 @@ struct ClientState; | |||
55 | * During connect, we try multiple possible IP addresses | 56 | * During connect, we try multiple possible IP addresses |
56 | * to find out which one might work. | 57 | * to find out which one might work. |
57 | */ | 58 | */ |
58 | struct AddressProbe { | 59 | struct AddressProbe |
60 | { | ||
59 | /** | 61 | /** |
60 | * This is a linked list. | 62 | * This is a linked list. |
61 | */ | 63 | */ |
@@ -96,7 +98,8 @@ struct AddressProbe { | |||
96 | /** | 98 | /** |
97 | * Internal state for a client connected to a GNUnet service. | 99 | * Internal state for a client connected to a GNUnet service. |
98 | */ | 100 | */ |
99 | struct ClientState { | 101 | struct ClientState |
102 | { | ||
100 | /** | 103 | /** |
101 | * The connection handle, NULL if not live | 104 | * The connection handle, NULL if not live |
102 | */ | 105 | */ |
@@ -205,7 +208,7 @@ struct ClientState { | |||
205 | * @param cls the `struct ClientState` to try to connect to the service | 208 | * @param cls the `struct ClientState` to try to connect to the service |
206 | */ | 209 | */ |
207 | static void | 210 | static void |
208 | start_connect(void *cls); | 211 | start_connect (void *cls); |
209 | 212 | ||
210 | 213 | ||
211 | /** | 214 | /** |
@@ -215,26 +218,26 @@ start_connect(void *cls); | |||
215 | * @param cstate the connection we tried to establish | 218 | * @param cstate the connection we tried to establish |
216 | */ | 219 | */ |
217 | static void | 220 | static void |
218 | connect_fail_continuation(struct ClientState *cstate) | 221 | connect_fail_continuation (struct ClientState *cstate) |
219 | { | 222 | { |
220 | GNUNET_break(NULL == cstate->ap_head); | 223 | GNUNET_break (NULL == cstate->ap_head); |
221 | GNUNET_break(NULL == cstate->ap_tail); | 224 | GNUNET_break (NULL == cstate->ap_tail); |
222 | GNUNET_break(NULL == cstate->dns_active); | 225 | GNUNET_break (NULL == cstate->dns_active); |
223 | GNUNET_break(NULL == cstate->sock); | 226 | GNUNET_break (NULL == cstate->sock); |
224 | GNUNET_assert(NULL == cstate->send_task); | 227 | GNUNET_assert (NULL == cstate->send_task); |
225 | GNUNET_assert(NULL == cstate->recv_task); | 228 | GNUNET_assert (NULL == cstate->recv_task); |
226 | // GNUNET_assert (NULL == cstate->proxy_handshake); | 229 | // GNUNET_assert (NULL == cstate->proxy_handshake); |
227 | 230 | ||
228 | cstate->back_off = GNUNET_TIME_STD_BACKOFF(cstate->back_off); | 231 | cstate->back_off = GNUNET_TIME_STD_BACKOFF (cstate->back_off); |
229 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 232 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
230 | "Failed to establish connection to `%s', no further addresses to try, will try again in %s.\n", | 233 | "Failed to establish connection to `%s', no further addresses to try, will try again in %s.\n", |
231 | cstate->service_name, | 234 | cstate->service_name, |
232 | GNUNET_STRINGS_relative_time_to_string(cstate->back_off, | 235 | GNUNET_STRINGS_relative_time_to_string (cstate->back_off, |
233 | GNUNET_YES)); | 236 | GNUNET_YES)); |
234 | cstate->retry_task | 237 | cstate->retry_task |
235 | = GNUNET_SCHEDULER_add_delayed(cstate->back_off, | 238 | = GNUNET_SCHEDULER_add_delayed (cstate->back_off, |
236 | &start_connect, | 239 | &start_connect, |
237 | cstate); | 240 | cstate); |
238 | } | 241 | } |
239 | 242 | ||
240 | 243 | ||
@@ -244,7 +247,7 @@ connect_fail_continuation(struct ClientState *cstate) | |||
244 | * @param cls the `struct ClientState` with the `msg` to transmit | 247 | * @param cls the `struct ClientState` with the `msg` to transmit |
245 | */ | 248 | */ |
246 | static void | 249 | static void |
247 | transmit_ready(void *cls) | 250 | transmit_ready (void *cls) |
248 | { | 251 | { |
249 | struct ClientState *cstate = cls; | 252 | struct ClientState *cstate = cls; |
250 | ssize_t ret; | 253 | ssize_t ret; |
@@ -255,56 +258,56 @@ transmit_ready(void *cls) | |||
255 | cstate->send_task = NULL; | 258 | cstate->send_task = NULL; |
256 | if (GNUNET_YES == cstate->in_destroy) | 259 | if (GNUNET_YES == cstate->in_destroy) |
257 | return; | 260 | return; |
258 | pos = (const char *)cstate->msg; | 261 | pos = (const char *) cstate->msg; |
259 | len = ntohs(cstate->msg->size); | 262 | len = ntohs (cstate->msg->size); |
260 | GNUNET_assert(cstate->msg_off < len); | 263 | GNUNET_assert (cstate->msg_off < len); |
261 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 264 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
262 | "message of type %u trying to send with socket %p (MQ: %p\n", | 265 | "message of type %u trying to send with socket %p (MQ: %p\n", |
263 | ntohs(cstate->msg->type), | 266 | ntohs (cstate->msg->type), |
264 | cstate->sock, | 267 | cstate->sock, |
265 | cstate->mq); | 268 | cstate->mq); |
266 | 269 | ||
267 | RETRY: | 270 | RETRY: |
268 | ret = GNUNET_NETWORK_socket_send(cstate->sock, | 271 | ret = GNUNET_NETWORK_socket_send (cstate->sock, |
269 | &pos[cstate->msg_off], | 272 | &pos[cstate->msg_off], |
270 | len - cstate->msg_off); | 273 | len - cstate->msg_off); |
271 | if (-1 == ret) | 274 | if (-1 == ret) |
275 | { | ||
276 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
277 | "Error during sending message of type %u\n", | ||
278 | ntohs (cstate->msg->type)); | ||
279 | if (EINTR == errno) | ||
272 | { | 280 | { |
273 | LOG(GNUNET_ERROR_TYPE_WARNING, | 281 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
274 | "Error during sending message of type %u\n", | 282 | "Retrying message of type %u\n", |
275 | ntohs(cstate->msg->type)); | 283 | ntohs (cstate->msg->type)); |
276 | if (EINTR == errno) | 284 | goto RETRY; |
277 | { | ||
278 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
279 | "Retrying message of type %u\n", | ||
280 | ntohs(cstate->msg->type)); | ||
281 | goto RETRY; | ||
282 | } | ||
283 | GNUNET_MQ_inject_error(cstate->mq, | ||
284 | GNUNET_MQ_ERROR_WRITE); | ||
285 | return; | ||
286 | } | 285 | } |
286 | GNUNET_MQ_inject_error (cstate->mq, | ||
287 | GNUNET_MQ_ERROR_WRITE); | ||
288 | return; | ||
289 | } | ||
287 | notify_in_flight = (0 == cstate->msg_off); | 290 | notify_in_flight = (0 == cstate->msg_off); |
288 | cstate->msg_off += ret; | 291 | cstate->msg_off += ret; |
289 | if (cstate->msg_off < len) | 292 | if (cstate->msg_off < len) |
290 | { | 293 | { |
291 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 294 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
292 | "rescheduling message of type %u\n", | 295 | "rescheduling message of type %u\n", |
293 | ntohs(cstate->msg->type)); | 296 | ntohs (cstate->msg->type)); |
294 | cstate->send_task | 297 | cstate->send_task |
295 | = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, | 298 | = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
296 | cstate->sock, | 299 | cstate->sock, |
297 | &transmit_ready, | 300 | &transmit_ready, |
298 | cstate); | 301 | cstate); |
299 | if (notify_in_flight) | 302 | if (notify_in_flight) |
300 | GNUNET_MQ_impl_send_in_flight(cstate->mq); | 303 | GNUNET_MQ_impl_send_in_flight (cstate->mq); |
301 | return; | 304 | return; |
302 | } | 305 | } |
303 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 306 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
304 | "sending message of type %u successful\n", | 307 | "sending message of type %u successful\n", |
305 | ntohs(cstate->msg->type)); | 308 | ntohs (cstate->msg->type)); |
306 | cstate->msg = NULL; | 309 | cstate->msg = NULL; |
307 | GNUNET_MQ_impl_send_continue(cstate->mq); | 310 | GNUNET_MQ_impl_send_continue (cstate->mq); |
308 | } | 311 | } |
309 | 312 | ||
310 | 313 | ||
@@ -319,20 +322,20 @@ RETRY: | |||
319 | * #GNUNET_SYSERR to stop further processing due to error | 322 | * #GNUNET_SYSERR to stop further processing due to error |
320 | */ | 323 | */ |
321 | static int | 324 | static int |
322 | recv_message(void *cls, | 325 | recv_message (void *cls, |
323 | const struct GNUNET_MessageHeader *msg) | 326 | const struct GNUNET_MessageHeader *msg) |
324 | { | 327 | { |
325 | struct ClientState *cstate = cls; | 328 | struct ClientState *cstate = cls; |
326 | 329 | ||
327 | if (GNUNET_YES == cstate->in_destroy) | 330 | if (GNUNET_YES == cstate->in_destroy) |
328 | return GNUNET_NO; | 331 | return GNUNET_NO; |
329 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 332 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
330 | "Received message of type %u and size %u from %s\n", | 333 | "Received message of type %u and size %u from %s\n", |
331 | ntohs(msg->type), | 334 | ntohs (msg->type), |
332 | ntohs(msg->size), | 335 | ntohs (msg->size), |
333 | cstate->service_name); | 336 | cstate->service_name); |
334 | GNUNET_MQ_inject_message(cstate->mq, | 337 | GNUNET_MQ_inject_message (cstate->mq, |
335 | msg); | 338 | msg); |
336 | if (GNUNET_YES == cstate->in_destroy) | 339 | if (GNUNET_YES == cstate->in_destroy) |
337 | return GNUNET_NO; | 340 | return GNUNET_NO; |
338 | return GNUNET_OK; | 341 | return GNUNET_OK; |
@@ -345,20 +348,20 @@ recv_message(void *cls, | |||
345 | * @param cstate handle of the client state to process | 348 | * @param cstate handle of the client state to process |
346 | */ | 349 | */ |
347 | static void | 350 | static void |
348 | cancel_aps(struct ClientState *cstate) | 351 | cancel_aps (struct ClientState *cstate) |
349 | { | 352 | { |
350 | struct AddressProbe *pos; | 353 | struct AddressProbe *pos; |
351 | 354 | ||
352 | while (NULL != (pos = cstate->ap_head)) | 355 | while (NULL != (pos = cstate->ap_head)) |
353 | { | 356 | { |
354 | GNUNET_break(GNUNET_OK == | 357 | GNUNET_break (GNUNET_OK == |
355 | GNUNET_NETWORK_socket_close(pos->sock)); | 358 | GNUNET_NETWORK_socket_close (pos->sock)); |
356 | GNUNET_SCHEDULER_cancel(pos->task); | 359 | GNUNET_SCHEDULER_cancel (pos->task); |
357 | GNUNET_CONTAINER_DLL_remove(cstate->ap_head, | 360 | GNUNET_CONTAINER_DLL_remove (cstate->ap_head, |
358 | cstate->ap_tail, | 361 | cstate->ap_tail, |
359 | pos); | 362 | pos); |
360 | GNUNET_free(pos); | 363 | GNUNET_free (pos); |
361 | } | 364 | } |
362 | } | 365 | } |
363 | 366 | ||
364 | 367 | ||
@@ -370,51 +373,51 @@ cancel_aps(struct ClientState *cstate) | |||
370 | * @param impl_state our `struct ClientState` | 373 | * @param impl_state our `struct ClientState` |
371 | */ | 374 | */ |
372 | static void | 375 | static void |
373 | connection_client_destroy_impl(struct GNUNET_MQ_Handle *mq, | 376 | connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, |
374 | void *impl_state) | 377 | void *impl_state) |
375 | { | 378 | { |
376 | struct ClientState *cstate = impl_state; | 379 | struct ClientState *cstate = impl_state; |
377 | 380 | ||
378 | (void)mq; | 381 | (void) mq; |
379 | if (NULL != cstate->dns_active) | 382 | if (NULL != cstate->dns_active) |
380 | { | 383 | { |
381 | GNUNET_RESOLVER_request_cancel(cstate->dns_active); | 384 | GNUNET_RESOLVER_request_cancel (cstate->dns_active); |
382 | cstate->dns_active = NULL; | 385 | cstate->dns_active = NULL; |
383 | } | 386 | } |
384 | if (NULL != cstate->send_task) | 387 | if (NULL != cstate->send_task) |
385 | { | 388 | { |
386 | GNUNET_SCHEDULER_cancel(cstate->send_task); | 389 | GNUNET_SCHEDULER_cancel (cstate->send_task); |
387 | cstate->send_task = NULL; | 390 | cstate->send_task = NULL; |
388 | } | 391 | } |
389 | if (NULL != cstate->retry_task) | 392 | if (NULL != cstate->retry_task) |
390 | { | 393 | { |
391 | GNUNET_SCHEDULER_cancel(cstate->retry_task); | 394 | GNUNET_SCHEDULER_cancel (cstate->retry_task); |
392 | cstate->retry_task = NULL; | 395 | cstate->retry_task = NULL; |
393 | } | 396 | } |
394 | if (GNUNET_SYSERR == cstate->in_destroy) | 397 | if (GNUNET_SYSERR == cstate->in_destroy) |
395 | { | 398 | { |
396 | /* defer destruction */ | 399 | /* defer destruction */ |
397 | cstate->in_destroy = GNUNET_YES; | 400 | cstate->in_destroy = GNUNET_YES; |
398 | cstate->mq = NULL; | 401 | cstate->mq = NULL; |
399 | return; | 402 | return; |
400 | } | 403 | } |
401 | if (NULL != cstate->recv_task) | 404 | if (NULL != cstate->recv_task) |
402 | { | 405 | { |
403 | GNUNET_SCHEDULER_cancel(cstate->recv_task); | 406 | GNUNET_SCHEDULER_cancel (cstate->recv_task); |
404 | cstate->recv_task = NULL; | 407 | cstate->recv_task = NULL; |
405 | } | 408 | } |
406 | if (NULL != cstate->sock) | 409 | if (NULL != cstate->sock) |
407 | { | 410 | { |
408 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 411 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
409 | "destroying socket: %p\n", | 412 | "destroying socket: %p\n", |
410 | cstate->sock); | 413 | cstate->sock); |
411 | GNUNET_NETWORK_socket_close(cstate->sock); | 414 | GNUNET_NETWORK_socket_close (cstate->sock); |
412 | } | 415 | } |
413 | cancel_aps(cstate); | 416 | cancel_aps (cstate); |
414 | GNUNET_free(cstate->service_name); | 417 | GNUNET_free (cstate->service_name); |
415 | GNUNET_free_non_null(cstate->hostname); | 418 | GNUNET_free_non_null (cstate->hostname); |
416 | GNUNET_MST_destroy(cstate->mst); | 419 | GNUNET_MST_destroy (cstate->mst); |
417 | GNUNET_free(cstate); | 420 | GNUNET_free (cstate); |
418 | } | 421 | } |
419 | 422 | ||
420 | 423 | ||
@@ -424,39 +427,39 @@ connection_client_destroy_impl(struct GNUNET_MQ_Handle *mq, | |||
424 | * @param cls `struct ClientState` with connection to read from | 427 | * @param cls `struct ClientState` with connection to read from |
425 | */ | 428 | */ |
426 | static void | 429 | static void |
427 | receive_ready(void *cls) | 430 | receive_ready (void *cls) |
428 | { | 431 | { |
429 | struct ClientState *cstate = cls; | 432 | struct ClientState *cstate = cls; |
430 | int ret; | 433 | int ret; |
431 | 434 | ||
432 | cstate->recv_task = NULL; | 435 | cstate->recv_task = NULL; |
433 | cstate->in_destroy = GNUNET_SYSERR; | 436 | cstate->in_destroy = GNUNET_SYSERR; |
434 | ret = GNUNET_MST_read(cstate->mst, | 437 | ret = GNUNET_MST_read (cstate->mst, |
435 | cstate->sock, | 438 | cstate->sock, |
436 | GNUNET_NO, | 439 | GNUNET_NO, |
437 | GNUNET_NO); | 440 | GNUNET_NO); |
438 | if (GNUNET_SYSERR == ret) | 441 | if (GNUNET_SYSERR == ret) |
439 | { | 442 | { |
440 | if (NULL != cstate->mq) | 443 | if (NULL != cstate->mq) |
441 | GNUNET_MQ_inject_error(cstate->mq, | 444 | GNUNET_MQ_inject_error (cstate->mq, |
442 | GNUNET_MQ_ERROR_READ); | 445 | GNUNET_MQ_ERROR_READ); |
443 | if (GNUNET_YES == cstate->in_destroy) | 446 | if (GNUNET_YES == cstate->in_destroy) |
444 | connection_client_destroy_impl(cstate->mq, | 447 | connection_client_destroy_impl (cstate->mq, |
445 | cstate); | 448 | cstate); |
446 | return; | 449 | return; |
447 | } | 450 | } |
448 | if (GNUNET_YES == cstate->in_destroy) | 451 | if (GNUNET_YES == cstate->in_destroy) |
449 | { | 452 | { |
450 | connection_client_destroy_impl(cstate->mq, | 453 | connection_client_destroy_impl (cstate->mq, |
451 | cstate); | 454 | cstate); |
452 | return; | 455 | return; |
453 | } | 456 | } |
454 | cstate->in_destroy = GNUNET_NO; | 457 | cstate->in_destroy = GNUNET_NO; |
455 | cstate->recv_task | 458 | cstate->recv_task |
456 | = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | 459 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
457 | cstate->sock, | 460 | cstate->sock, |
458 | &receive_ready, | 461 | &receive_ready, |
459 | cstate); | 462 | cstate); |
460 | } | 463 | } |
461 | 464 | ||
462 | 465 | ||
@@ -466,23 +469,23 @@ receive_ready(void *cls) | |||
466 | * @param cstate the connection we tried to establish | 469 | * @param cstate the connection we tried to establish |
467 | */ | 470 | */ |
468 | static void | 471 | static void |
469 | connect_success_continuation(struct ClientState *cstate) | 472 | connect_success_continuation (struct ClientState *cstate) |
470 | { | 473 | { |
471 | GNUNET_assert(NULL == cstate->recv_task); | 474 | GNUNET_assert (NULL == cstate->recv_task); |
472 | cstate->recv_task | 475 | cstate->recv_task |
473 | = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | 476 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
474 | cstate->sock, | 477 | cstate->sock, |
475 | &receive_ready, | 478 | &receive_ready, |
476 | cstate); | 479 | cstate); |
477 | if (NULL != cstate->msg) | 480 | if (NULL != cstate->msg) |
478 | { | 481 | { |
479 | GNUNET_assert(NULL == cstate->send_task); | 482 | GNUNET_assert (NULL == cstate->send_task); |
480 | cstate->send_task | 483 | cstate->send_task |
481 | = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, | 484 | = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
482 | cstate->sock, | 485 | cstate->sock, |
483 | &transmit_ready, | 486 | &transmit_ready, |
484 | cstate); | 487 | cstate); |
485 | } | 488 | } |
486 | } | 489 | } |
487 | 490 | ||
488 | 491 | ||
@@ -494,8 +497,8 @@ connect_success_continuation(struct ClientState *cstate) | |||
494 | * @return NULL on error, socket connected to UNIX otherwise | 497 | * @return NULL on error, socket connected to UNIX otherwise |
495 | */ | 498 | */ |
496 | static struct GNUNET_NETWORK_Handle * | 499 | static struct GNUNET_NETWORK_Handle * |
497 | try_unixpath(const char *service_name, | 500 | try_unixpath (const char *service_name, |
498 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 501 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
499 | { | 502 | { |
500 | #if AF_UNIX | 503 | #if AF_UNIX |
501 | struct GNUNET_NETWORK_Handle *sock; | 504 | struct GNUNET_NETWORK_Handle *sock; |
@@ -504,67 +507,67 @@ try_unixpath(const char *service_name, | |||
504 | 507 | ||
505 | unixpath = NULL; | 508 | unixpath = NULL; |
506 | if ((GNUNET_OK == | 509 | if ((GNUNET_OK == |
507 | GNUNET_CONFIGURATION_get_value_filename(cfg, | 510 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
508 | service_name, | 511 | service_name, |
509 | "UNIXPATH", | 512 | "UNIXPATH", |
510 | &unixpath)) && | 513 | &unixpath)) && |
511 | (0 < strlen(unixpath))) | 514 | (0 < strlen (unixpath))) |
515 | { | ||
516 | /* We have a non-NULL unixpath, need to validate it */ | ||
517 | if (strlen (unixpath) >= sizeof(s_un.sun_path)) | ||
512 | { | 518 | { |
513 | /* We have a non-NULL unixpath, need to validate it */ | 519 | LOG (GNUNET_ERROR_TYPE_WARNING, |
514 | if (strlen(unixpath) >= sizeof(s_un.sun_path)) | 520 | _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), |
515 | { | 521 | unixpath, |
516 | LOG(GNUNET_ERROR_TYPE_WARNING, | 522 | (unsigned long long) sizeof(s_un.sun_path)); |
517 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), | 523 | unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); |
518 | unixpath, | 524 | LOG (GNUNET_ERROR_TYPE_INFO, |
519 | (unsigned long long)sizeof(s_un.sun_path)); | 525 | _ ("Using `%s' instead\n"), |
520 | unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath); | 526 | unixpath); |
521 | LOG(GNUNET_ERROR_TYPE_INFO, | 527 | if (NULL == unixpath) |
522 | _("Using `%s' instead\n"), | 528 | return NULL; |
523 | unixpath); | 529 | } |
524 | if (NULL == unixpath) | 530 | memset (&s_un, |
525 | return NULL; | 531 | 0, |
526 | } | 532 | sizeof(s_un)); |
527 | memset(&s_un, | 533 | s_un.sun_family = AF_UNIX; |
528 | 0, | 534 | GNUNET_strlcpy (s_un.sun_path, |
529 | sizeof(s_un)); | 535 | unixpath, |
530 | s_un.sun_family = AF_UNIX; | 536 | sizeof(s_un.sun_path)); |
531 | GNUNET_strlcpy(s_un.sun_path, | ||
532 | unixpath, | ||
533 | sizeof(s_un.sun_path)); | ||
534 | #ifdef LINUX | 537 | #ifdef LINUX |
535 | { | 538 | { |
536 | int abstract; | 539 | int abstract; |
537 | 540 | ||
538 | abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, | 541 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
539 | "TESTING", | 542 | "TESTING", |
540 | "USE_ABSTRACT_SOCKETS"); | 543 | "USE_ABSTRACT_SOCKETS"); |
541 | if (GNUNET_YES == abstract) | 544 | if (GNUNET_YES == abstract) |
542 | s_un.sun_path[0] = '\0'; | 545 | s_un.sun_path[0] = '\0'; |
543 | } | 546 | } |
544 | #endif | 547 | #endif |
545 | #if HAVE_SOCKADDR_UN_SUN_LEN | 548 | #if HAVE_SOCKADDR_UN_SUN_LEN |
546 | s_un.sun_len = (u_char)sizeof(struct sockaddr_un); | 549 | s_un.sun_len = (u_char) sizeof(struct sockaddr_un); |
547 | #endif | 550 | #endif |
548 | sock = GNUNET_NETWORK_socket_create(AF_UNIX, | 551 | sock = GNUNET_NETWORK_socket_create (AF_UNIX, |
549 | SOCK_STREAM, | 552 | SOCK_STREAM, |
550 | 0); | 553 | 0); |
551 | if ((NULL != sock) && | 554 | if ((NULL != sock) && |
552 | ((GNUNET_OK == | 555 | ((GNUNET_OK == |
553 | GNUNET_NETWORK_socket_connect(sock, | 556 | GNUNET_NETWORK_socket_connect (sock, |
554 | (struct sockaddr *)&s_un, | 557 | (struct sockaddr *) &s_un, |
555 | sizeof(s_un))) || | 558 | sizeof(s_un))) || |
556 | (EINPROGRESS == errno))) | 559 | (EINPROGRESS == errno))) |
557 | { | 560 | { |
558 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 561 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
559 | "Successfully connected to unixpath `%s'!\n", | 562 | "Successfully connected to unixpath `%s'!\n", |
560 | unixpath); | 563 | unixpath); |
561 | GNUNET_free(unixpath); | 564 | GNUNET_free (unixpath); |
562 | return sock; | 565 | return sock; |
563 | } | ||
564 | if (NULL != sock) | ||
565 | GNUNET_NETWORK_socket_close(sock); | ||
566 | } | 566 | } |
567 | GNUNET_free_non_null(unixpath); | 567 | if (NULL != sock) |
568 | GNUNET_NETWORK_socket_close (sock); | ||
569 | } | ||
570 | GNUNET_free_non_null (unixpath); | ||
568 | #endif | 571 | #endif |
569 | return NULL; | 572 | return NULL; |
570 | } | 573 | } |
@@ -577,7 +580,7 @@ try_unixpath(const char *service_name, | |||
577 | * @param cls the `struct AddressProbe *` with the address that we are probing | 580 | * @param cls the `struct AddressProbe *` with the address that we are probing |
578 | */ | 581 | */ |
579 | static void | 582 | static void |
580 | connect_probe_continuation(void *cls) | 583 | connect_probe_continuation (void *cls) |
581 | { | 584 | { |
582 | struct AddressProbe *ap = cls; | 585 | struct AddressProbe *ap = cls; |
583 | struct ClientState *cstate = ap->cstate; | 586 | struct ClientState *cstate = ap->cstate; |
@@ -586,40 +589,40 @@ connect_probe_continuation(void *cls) | |||
586 | socklen_t len; | 589 | socklen_t len; |
587 | 590 | ||
588 | ap->task = NULL; | 591 | ap->task = NULL; |
589 | GNUNET_assert(NULL != ap->sock); | 592 | GNUNET_assert (NULL != ap->sock); |
590 | GNUNET_CONTAINER_DLL_remove(cstate->ap_head, | 593 | GNUNET_CONTAINER_DLL_remove (cstate->ap_head, |
591 | cstate->ap_tail, | 594 | cstate->ap_tail, |
592 | ap); | 595 | ap); |
593 | len = sizeof(error); | 596 | len = sizeof(error); |
594 | error = 0; | 597 | error = 0; |
595 | tc = GNUNET_SCHEDULER_get_task_context(); | 598 | tc = GNUNET_SCHEDULER_get_task_context (); |
596 | if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || | 599 | if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || |
597 | (GNUNET_OK != | 600 | (GNUNET_OK != |
598 | GNUNET_NETWORK_socket_getsockopt(ap->sock, | 601 | GNUNET_NETWORK_socket_getsockopt (ap->sock, |
599 | SOL_SOCKET, | 602 | SOL_SOCKET, |
600 | SO_ERROR, | 603 | SO_ERROR, |
601 | &error, | 604 | &error, |
602 | &len)) || | 605 | &len)) || |
603 | (0 != error)) | 606 | (0 != error)) |
604 | { | 607 | { |
605 | GNUNET_break(GNUNET_OK == | 608 | GNUNET_break (GNUNET_OK == |
606 | GNUNET_NETWORK_socket_close(ap->sock)); | 609 | GNUNET_NETWORK_socket_close (ap->sock)); |
607 | GNUNET_free(ap); | 610 | GNUNET_free (ap); |
608 | if ((NULL == cstate->ap_head) && | 611 | if ((NULL == cstate->ap_head) && |
609 | // (NULL == cstate->proxy_handshake) && | 612 | // (NULL == cstate->proxy_handshake) && |
610 | (NULL == cstate->dns_active)) | 613 | (NULL == cstate->dns_active)) |
611 | connect_fail_continuation(cstate); | 614 | connect_fail_continuation (cstate); |
612 | return; | 615 | return; |
613 | } | 616 | } |
614 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 617 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
615 | "Connection to `%s' succeeded!\n", | 618 | "Connection to `%s' succeeded!\n", |
616 | cstate->service_name); | 619 | cstate->service_name); |
617 | /* trigger jobs that waited for the connection */ | 620 | /* trigger jobs that waited for the connection */ |
618 | GNUNET_assert(NULL == cstate->sock); | 621 | GNUNET_assert (NULL == cstate->sock); |
619 | cstate->sock = ap->sock; | 622 | cstate->sock = ap->sock; |
620 | GNUNET_free(ap); | 623 | GNUNET_free (ap); |
621 | cancel_aps(cstate); | 624 | cancel_aps (cstate); |
622 | connect_success_continuation(cstate); | 625 | connect_success_continuation (cstate); |
623 | } | 626 | } |
624 | 627 | ||
625 | 628 | ||
@@ -632,82 +635,82 @@ connect_probe_continuation(void *cls) | |||
632 | * @param addrlen length of @a addr | 635 | * @param addrlen length of @a addr |
633 | */ | 636 | */ |
634 | static void | 637 | static void |
635 | try_connect_using_address(void *cls, | 638 | try_connect_using_address (void *cls, |
636 | const struct sockaddr *addr, | 639 | const struct sockaddr *addr, |
637 | socklen_t addrlen) | 640 | socklen_t addrlen) |
638 | { | 641 | { |
639 | struct ClientState *cstate = cls; | 642 | struct ClientState *cstate = cls; |
640 | struct AddressProbe *ap; | 643 | struct AddressProbe *ap; |
641 | 644 | ||
642 | if (NULL == addr) | 645 | if (NULL == addr) |
643 | { | 646 | { |
644 | cstate->dns_active = NULL; | 647 | cstate->dns_active = NULL; |
645 | if ((NULL == cstate->ap_head) && | 648 | if ((NULL == cstate->ap_head) && |
646 | // (NULL == cstate->proxy_handshake) && | 649 | // (NULL == cstate->proxy_handshake) && |
647 | (NULL == cstate->sock)) | 650 | (NULL == cstate->sock)) |
648 | connect_fail_continuation(cstate); | 651 | connect_fail_continuation (cstate); |
649 | return; | 652 | return; |
650 | } | 653 | } |
651 | if (NULL != cstate->sock) | 654 | if (NULL != cstate->sock) |
652 | return; /* already connected */ | 655 | return; /* already connected */ |
653 | /* try to connect */ | 656 | /* try to connect */ |
654 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 657 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
655 | "Trying to connect using address `%s:%u'\n", | 658 | "Trying to connect using address `%s:%u'\n", |
656 | GNUNET_a2s(addr, | 659 | GNUNET_a2s (addr, |
657 | addrlen), | 660 | addrlen), |
658 | cstate->port); | 661 | cstate->port); |
659 | ap = GNUNET_malloc(sizeof(struct AddressProbe) + addrlen); | 662 | ap = GNUNET_malloc (sizeof(struct AddressProbe) + addrlen); |
660 | ap->addr = (const struct sockaddr *)&ap[1]; | 663 | ap->addr = (const struct sockaddr *) &ap[1]; |
661 | GNUNET_memcpy(&ap[1], | 664 | GNUNET_memcpy (&ap[1], |
662 | addr, | 665 | addr, |
663 | addrlen); | 666 | addrlen); |
664 | ap->addrlen = addrlen; | 667 | ap->addrlen = addrlen; |
665 | ap->cstate = cstate; | 668 | ap->cstate = cstate; |
666 | 669 | ||
667 | switch (ap->addr->sa_family) | 670 | switch (ap->addr->sa_family) |
668 | { | 671 | { |
669 | case AF_INET: | 672 | case AF_INET: |
670 | ((struct sockaddr_in *)ap->addr)->sin_port = htons(cstate->port); | 673 | ((struct sockaddr_in *) ap->addr)->sin_port = htons (cstate->port); |
671 | break; | 674 | break; |
672 | 675 | ||
673 | case AF_INET6: | 676 | case AF_INET6: |
674 | ((struct sockaddr_in6 *)ap->addr)->sin6_port = htons(cstate->port); | 677 | ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (cstate->port); |
675 | break; | 678 | break; |
676 | 679 | ||
677 | default: | 680 | default: |
678 | GNUNET_break(0); | 681 | GNUNET_break (0); |
679 | GNUNET_free(ap); | 682 | GNUNET_free (ap); |
680 | return; /* not supported by us */ | 683 | return; /* not supported by us */ |
681 | } | 684 | } |
682 | ap->sock = GNUNET_NETWORK_socket_create(ap->addr->sa_family, | 685 | ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, |
683 | SOCK_STREAM, | 686 | SOCK_STREAM, |
684 | 0); | 687 | 0); |
685 | if (NULL == ap->sock) | 688 | if (NULL == ap->sock) |
686 | { | 689 | { |
687 | GNUNET_free(ap); | 690 | GNUNET_free (ap); |
688 | return; /* not supported by OS */ | 691 | return; /* not supported by OS */ |
689 | } | 692 | } |
690 | if ((GNUNET_OK != | 693 | if ((GNUNET_OK != |
691 | GNUNET_NETWORK_socket_connect(ap->sock, | 694 | GNUNET_NETWORK_socket_connect (ap->sock, |
692 | ap->addr, | 695 | ap->addr, |
693 | ap->addrlen)) && | 696 | ap->addrlen)) && |
694 | (EINPROGRESS != errno)) | 697 | (EINPROGRESS != errno)) |
695 | { | 698 | { |
696 | /* maybe refused / unsupported address, try next */ | 699 | /* maybe refused / unsupported address, try next */ |
697 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_INFO, | 700 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, |
698 | "connect"); | 701 | "connect"); |
699 | GNUNET_break(GNUNET_OK == | 702 | GNUNET_break (GNUNET_OK == |
700 | GNUNET_NETWORK_socket_close(ap->sock)); | 703 | GNUNET_NETWORK_socket_close (ap->sock)); |
701 | GNUNET_free(ap); | 704 | GNUNET_free (ap); |
702 | return; | 705 | return; |
703 | } | 706 | } |
704 | GNUNET_CONTAINER_DLL_insert(cstate->ap_head, | 707 | GNUNET_CONTAINER_DLL_insert (cstate->ap_head, |
705 | cstate->ap_tail, | 708 | cstate->ap_tail, |
706 | ap); | 709 | ap); |
707 | ap->task = GNUNET_SCHEDULER_add_write_net(CONNECT_RETRY_TIMEOUT, | 710 | ap->task = GNUNET_SCHEDULER_add_write_net (CONNECT_RETRY_TIMEOUT, |
708 | ap->sock, | 711 | ap->sock, |
709 | &connect_probe_continuation, | 712 | &connect_probe_continuation, |
710 | ap); | 713 | ap); |
711 | } | 714 | } |
712 | 715 | ||
713 | 716 | ||
@@ -720,8 +723,8 @@ try_connect_using_address(void *cls, | |||
720 | * @return #GNUNET_OK if the configuration is valid, #GNUNET_SYSERR if not | 723 | * @return #GNUNET_OK if the configuration is valid, #GNUNET_SYSERR if not |
721 | */ | 724 | */ |
722 | static int | 725 | static int |
723 | test_service_configuration(const char *service_name, | 726 | test_service_configuration (const char *service_name, |
724 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 727 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
725 | { | 728 | { |
726 | int ret = GNUNET_SYSERR; | 729 | int ret = GNUNET_SYSERR; |
727 | char *hostname = NULL; | 730 | char *hostname = NULL; |
@@ -731,45 +734,45 @@ test_service_configuration(const char *service_name, | |||
731 | char *unixpath = NULL; | 734 | char *unixpath = NULL; |
732 | 735 | ||
733 | if ((GNUNET_OK == | 736 | if ((GNUNET_OK == |
734 | GNUNET_CONFIGURATION_get_value_filename(cfg, | 737 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
735 | service_name, | 738 | service_name, |
736 | "UNIXPATH", | 739 | "UNIXPATH", |
737 | &unixpath)) && | 740 | &unixpath)) && |
738 | (0 < strlen(unixpath))) | 741 | (0 < strlen (unixpath))) |
739 | ret = GNUNET_OK; | 742 | ret = GNUNET_OK; |
740 | else if ((GNUNET_OK == | 743 | else if ((GNUNET_OK == |
741 | GNUNET_CONFIGURATION_have_value(cfg, | 744 | GNUNET_CONFIGURATION_have_value (cfg, |
742 | service_name, | 745 | service_name, |
743 | "UNIXPATH"))) | 746 | "UNIXPATH"))) |
744 | { | 747 | { |
745 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | 748 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
746 | service_name, | 749 | service_name, |
747 | "UNIXPATH", | 750 | "UNIXPATH", |
748 | _("not a valid filename")); | 751 | _ ("not a valid filename")); |
749 | return GNUNET_SYSERR; /* UNIXPATH specified but invalid! */ | 752 | return GNUNET_SYSERR; /* UNIXPATH specified but invalid! */ |
750 | } | 753 | } |
751 | GNUNET_free_non_null(unixpath); | 754 | GNUNET_free_non_null (unixpath); |
752 | #endif | 755 | #endif |
753 | 756 | ||
754 | if ((GNUNET_YES == | 757 | if ((GNUNET_YES == |
755 | GNUNET_CONFIGURATION_have_value(cfg, | 758 | GNUNET_CONFIGURATION_have_value (cfg, |
756 | service_name, | 759 | service_name, |
757 | "PORT")) && | 760 | "PORT")) && |
758 | (GNUNET_OK == | 761 | (GNUNET_OK == |
759 | GNUNET_CONFIGURATION_get_value_number(cfg, | 762 | GNUNET_CONFIGURATION_get_value_number (cfg, |
760 | service_name, | 763 | service_name, |
761 | "PORT", | 764 | "PORT", |
762 | &port)) && | 765 | &port)) && |
763 | (port <= 65535) && | 766 | (port <= 65535) && |
764 | (0 != port) && | 767 | (0 != port) && |
765 | (GNUNET_OK == | 768 | (GNUNET_OK == |
766 | GNUNET_CONFIGURATION_get_value_string(cfg, | 769 | GNUNET_CONFIGURATION_get_value_string (cfg, |
767 | service_name, | 770 | service_name, |
768 | "HOSTNAME", | 771 | "HOSTNAME", |
769 | &hostname)) && | 772 | &hostname)) && |
770 | (0 != strlen(hostname))) | 773 | (0 != strlen (hostname))) |
771 | ret = GNUNET_OK; | 774 | ret = GNUNET_OK; |
772 | GNUNET_free_non_null(hostname); | 775 | GNUNET_free_non_null (hostname); |
773 | return ret; | 776 | return ret; |
774 | } | 777 | } |
775 | 778 | ||
@@ -780,7 +783,7 @@ test_service_configuration(const char *service_name, | |||
780 | * @param cls the `struct ClientState` to try to connect to the service | 783 | * @param cls the `struct ClientState` to try to connect to the service |
781 | */ | 784 | */ |
782 | static void | 785 | static void |
783 | start_connect(void *cls) | 786 | start_connect (void *cls) |
784 | { | 787 | { |
785 | struct ClientState *cstate = cls; | 788 | struct ClientState *cstate = cls; |
786 | 789 | ||
@@ -788,41 +791,41 @@ start_connect(void *cls) | |||
788 | #if 0 | 791 | #if 0 |
789 | /* Never use a local source if a proxy is configured */ | 792 | /* Never use a local source if a proxy is configured */ |
790 | if (GNUNET_YES == | 793 | if (GNUNET_YES == |
791 | GNUNET_SOCKS_check_service(cstate->service_name, | 794 | GNUNET_SOCKS_check_service (cstate->service_name, |
792 | cstate->cfg)) | 795 | cstate->cfg)) |
793 | { | 796 | { |
794 | socks_connect(cstate); | 797 | socks_connect (cstate); |
795 | return; | 798 | return; |
796 | } | 799 | } |
797 | #endif | 800 | #endif |
798 | 801 | ||
799 | if ((0 == (cstate->attempts++ % 2)) || | 802 | if ((0 == (cstate->attempts++ % 2)) || |
800 | (0 == cstate->port) || | 803 | (0 == cstate->port) || |
801 | (NULL == cstate->hostname)) | 804 | (NULL == cstate->hostname)) |
805 | { | ||
806 | /* on even rounds, try UNIX first, or always | ||
807 | if we do not have a DNS name and TCP port. */ | ||
808 | cstate->sock = try_unixpath (cstate->service_name, | ||
809 | cstate->cfg); | ||
810 | if (NULL != cstate->sock) | ||
802 | { | 811 | { |
803 | /* on even rounds, try UNIX first, or always | 812 | connect_success_continuation (cstate); |
804 | if we do not have a DNS name and TCP port. */ | 813 | return; |
805 | cstate->sock = try_unixpath(cstate->service_name, | ||
806 | cstate->cfg); | ||
807 | if (NULL != cstate->sock) | ||
808 | { | ||
809 | connect_success_continuation(cstate); | ||
810 | return; | ||
811 | } | ||
812 | } | 814 | } |
815 | } | ||
813 | if ((NULL == cstate->hostname) || | 816 | if ((NULL == cstate->hostname) || |
814 | (0 == cstate->port)) | 817 | (0 == cstate->port)) |
815 | { | 818 | { |
816 | /* All options failed. Boo! */ | 819 | /* All options failed. Boo! */ |
817 | connect_fail_continuation(cstate); | 820 | connect_fail_continuation (cstate); |
818 | return; | 821 | return; |
819 | } | 822 | } |
820 | cstate->dns_active | 823 | cstate->dns_active |
821 | = GNUNET_RESOLVER_ip_get(cstate->hostname, | 824 | = GNUNET_RESOLVER_ip_get (cstate->hostname, |
822 | AF_UNSPEC, | 825 | AF_UNSPEC, |
823 | CONNECT_RETRY_TIMEOUT, | 826 | CONNECT_RETRY_TIMEOUT, |
824 | &try_connect_using_address, | 827 | &try_connect_using_address, |
825 | cstate); | 828 | cstate); |
826 | } | 829 | } |
827 | 830 | ||
828 | 831 | ||
@@ -834,30 +837,30 @@ start_connect(void *cls) | |||
834 | * @param impl_state our `struct ClientState` | 837 | * @param impl_state our `struct ClientState` |
835 | */ | 838 | */ |
836 | static void | 839 | static void |
837 | connection_client_send_impl(struct GNUNET_MQ_Handle *mq, | 840 | connection_client_send_impl (struct GNUNET_MQ_Handle *mq, |
838 | const struct GNUNET_MessageHeader *msg, | 841 | const struct GNUNET_MessageHeader *msg, |
839 | void *impl_state) | 842 | void *impl_state) |
840 | { | 843 | { |
841 | struct ClientState *cstate = impl_state; | 844 | struct ClientState *cstate = impl_state; |
842 | 845 | ||
843 | (void)mq; | 846 | (void) mq; |
844 | /* only one message at a time allowed */ | 847 | /* only one message at a time allowed */ |
845 | GNUNET_assert(NULL == cstate->msg); | 848 | GNUNET_assert (NULL == cstate->msg); |
846 | GNUNET_assert(NULL == cstate->send_task); | 849 | GNUNET_assert (NULL == cstate->send_task); |
847 | cstate->msg = msg; | 850 | cstate->msg = msg; |
848 | cstate->msg_off = 0; | 851 | cstate->msg_off = 0; |
849 | if (NULL == cstate->sock) | 852 | if (NULL == cstate->sock) |
850 | { | 853 | { |
851 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 854 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
852 | "message of type %u waiting for socket\n", | 855 | "message of type %u waiting for socket\n", |
853 | ntohs(msg->type)); | 856 | ntohs (msg->type)); |
854 | return; /* still waiting for connection */ | 857 | return; /* still waiting for connection */ |
855 | } | 858 | } |
856 | cstate->send_task | 859 | cstate->send_task |
857 | = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, | 860 | = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
858 | cstate->sock, | 861 | cstate->sock, |
859 | &transmit_ready, | 862 | &transmit_ready, |
860 | cstate); | 863 | cstate); |
861 | } | 864 | } |
862 | 865 | ||
863 | 866 | ||
@@ -868,20 +871,20 @@ connection_client_send_impl(struct GNUNET_MQ_Handle *mq, | |||
868 | * @param impl_state our `struct ClientState` | 871 | * @param impl_state our `struct ClientState` |
869 | */ | 872 | */ |
870 | static void | 873 | static void |
871 | connection_client_cancel_impl(struct GNUNET_MQ_Handle *mq, | 874 | connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq, |
872 | void *impl_state) | 875 | void *impl_state) |
873 | { | 876 | { |
874 | struct ClientState *cstate = impl_state; | 877 | struct ClientState *cstate = impl_state; |
875 | 878 | ||
876 | (void)mq; | 879 | (void) mq; |
877 | GNUNET_assert(NULL != cstate->msg); | 880 | GNUNET_assert (NULL != cstate->msg); |
878 | GNUNET_assert(0 == cstate->msg_off); | 881 | GNUNET_assert (0 == cstate->msg_off); |
879 | cstate->msg = NULL; | 882 | cstate->msg = NULL; |
880 | if (NULL != cstate->send_task) | 883 | if (NULL != cstate->send_task) |
881 | { | 884 | { |
882 | GNUNET_SCHEDULER_cancel(cstate->send_task); | 885 | GNUNET_SCHEDULER_cancel (cstate->send_task); |
883 | cstate->send_task = NULL; | 886 | cstate->send_task = NULL; |
884 | } | 887 | } |
885 | } | 888 | } |
886 | 889 | ||
887 | 890 | ||
@@ -897,57 +900,57 @@ connection_client_cancel_impl(struct GNUNET_MQ_Handle *mq, | |||
897 | * @return the message queue, NULL on error | 900 | * @return the message queue, NULL on error |
898 | */ | 901 | */ |
899 | struct GNUNET_MQ_Handle * | 902 | struct GNUNET_MQ_Handle * |
900 | GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | 903 | GNUNET_CLIENT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
901 | const char *service_name, | 904 | const char *service_name, |
902 | const struct GNUNET_MQ_MessageHandler *handlers, | 905 | const struct GNUNET_MQ_MessageHandler *handlers, |
903 | GNUNET_MQ_ErrorHandler error_handler, | 906 | GNUNET_MQ_ErrorHandler error_handler, |
904 | void *error_handler_cls) | 907 | void *error_handler_cls) |
905 | { | 908 | { |
906 | struct ClientState *cstate; | 909 | struct ClientState *cstate; |
907 | 910 | ||
908 | if (GNUNET_OK != | 911 | if (GNUNET_OK != |
909 | test_service_configuration(service_name, | 912 | test_service_configuration (service_name, |
910 | cfg)) | 913 | cfg)) |
911 | return NULL; | 914 | return NULL; |
912 | cstate = GNUNET_new(struct ClientState); | 915 | cstate = GNUNET_new (struct ClientState); |
913 | cstate->service_name = GNUNET_strdup(service_name); | 916 | cstate->service_name = GNUNET_strdup (service_name); |
914 | cstate->cfg = cfg; | 917 | cstate->cfg = cfg; |
915 | cstate->retry_task = GNUNET_SCHEDULER_add_now(&start_connect, | 918 | cstate->retry_task = GNUNET_SCHEDULER_add_now (&start_connect, |
916 | cstate); | 919 | cstate); |
917 | cstate->mst = GNUNET_MST_create(&recv_message, | 920 | cstate->mst = GNUNET_MST_create (&recv_message, |
918 | cstate); | 921 | cstate); |
919 | if (GNUNET_YES == | 922 | if (GNUNET_YES == |
920 | GNUNET_CONFIGURATION_have_value(cfg, | 923 | GNUNET_CONFIGURATION_have_value (cfg, |
921 | service_name, | 924 | service_name, |
922 | "PORT")) | 925 | "PORT")) |
923 | { | 926 | { |
924 | if (!((GNUNET_OK != | 927 | if (! ((GNUNET_OK != |
925 | GNUNET_CONFIGURATION_get_value_number(cfg, | 928 | GNUNET_CONFIGURATION_get_value_number (cfg, |
926 | service_name, | 929 | service_name, |
927 | "PORT", | 930 | "PORT", |
928 | &cstate->port)) || | 931 | &cstate->port)) || |
929 | (cstate->port > 65535) || | 932 | (cstate->port > 65535) || |
930 | (GNUNET_OK != | 933 | (GNUNET_OK != |
931 | GNUNET_CONFIGURATION_get_value_string(cfg, | 934 | GNUNET_CONFIGURATION_get_value_string (cfg, |
932 | service_name, | 935 | service_name, |
933 | "HOSTNAME", | 936 | "HOSTNAME", |
934 | &cstate->hostname))) && | 937 | &cstate->hostname))) && |
935 | (0 == strlen(cstate->hostname))) | 938 | (0 == strlen (cstate->hostname))) |
936 | { | 939 | { |
937 | GNUNET_free(cstate->hostname); | 940 | GNUNET_free (cstate->hostname); |
938 | cstate->hostname = NULL; | 941 | cstate->hostname = NULL; |
939 | LOG(GNUNET_ERROR_TYPE_WARNING, | 942 | LOG (GNUNET_ERROR_TYPE_WARNING, |
940 | _("Need a non-empty hostname for service `%s'.\n"), | 943 | _ ("Need a non-empty hostname for service `%s'.\n"), |
941 | service_name); | 944 | service_name); |
942 | } | ||
943 | } | 945 | } |
944 | cstate->mq = GNUNET_MQ_queue_for_callbacks(&connection_client_send_impl, | 946 | } |
945 | &connection_client_destroy_impl, | 947 | cstate->mq = GNUNET_MQ_queue_for_callbacks (&connection_client_send_impl, |
946 | &connection_client_cancel_impl, | 948 | &connection_client_destroy_impl, |
947 | cstate, | 949 | &connection_client_cancel_impl, |
948 | handlers, | 950 | cstate, |
949 | error_handler, | 951 | handlers, |
950 | error_handler_cls); | 952 | error_handler, |
953 | error_handler_cls); | ||
951 | return cstate->mq; | 954 | return cstate->mq; |
952 | } | 955 | } |
953 | 956 | ||