diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/transport/gnunet-communicator-unix.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/transport/gnunet-communicator-unix.c')
-rw-r--r-- | src/transport/gnunet-communicator-unix.c | 911 |
1 files changed, 457 insertions, 454 deletions
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c index da610daa1..d8205addb 100644 --- a/src/transport/gnunet-communicator-unix.c +++ b/src/transport/gnunet-communicator-unix.c | |||
@@ -64,7 +64,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
64 | /** | 64 | /** |
65 | * UNIX Message-Packet header. | 65 | * UNIX Message-Packet header. |
66 | */ | 66 | */ |
67 | struct UNIXMessage { | 67 | struct UNIXMessage |
68 | { | ||
68 | /** | 69 | /** |
69 | * Message header. | 70 | * Message header. |
70 | */ | 71 | */ |
@@ -82,7 +83,8 @@ GNUNET_NETWORK_STRUCT_END | |||
82 | /** | 83 | /** |
83 | * Handle for a queue. | 84 | * Handle for a queue. |
84 | */ | 85 | */ |
85 | struct Queue { | 86 | struct Queue |
87 | { | ||
86 | /** | 88 | /** |
87 | * Queues with pending messages (!) are kept in a DLL. | 89 | * Queues with pending messages (!) are kept in a DLL. |
88 | */ | 90 | */ |
@@ -205,37 +207,37 @@ static struct GNUNET_TRANSPORT_AddressIdentifier *ai; | |||
205 | * @param queue queue to close down | 207 | * @param queue queue to close down |
206 | */ | 208 | */ |
207 | static void | 209 | static void |
208 | queue_destroy(struct Queue *queue) | 210 | queue_destroy (struct Queue *queue) |
209 | { | 211 | { |
210 | struct GNUNET_MQ_Handle *mq; | 212 | struct GNUNET_MQ_Handle *mq; |
211 | 213 | ||
212 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
213 | "Disconnecting queue for peer `%s'\n", | 215 | "Disconnecting queue for peer `%s'\n", |
214 | GNUNET_i2s(&queue->target)); | 216 | GNUNET_i2s (&queue->target)); |
215 | if (0 != queue->bytes_in_queue) | 217 | if (0 != queue->bytes_in_queue) |
216 | { | 218 | { |
217 | GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue); | 219 | GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); |
218 | queue->bytes_in_queue = 0; | 220 | queue->bytes_in_queue = 0; |
219 | } | 221 | } |
220 | if (NULL != (mq = queue->mq)) | 222 | if (NULL != (mq = queue->mq)) |
221 | { | 223 | { |
222 | queue->mq = NULL; | 224 | queue->mq = NULL; |
223 | GNUNET_MQ_destroy(mq); | 225 | GNUNET_MQ_destroy (mq); |
224 | } | 226 | } |
225 | GNUNET_assert( | 227 | GNUNET_assert ( |
226 | GNUNET_YES == | 228 | GNUNET_YES == |
227 | GNUNET_CONTAINER_multipeermap_remove(queue_map, &queue->target, queue)); | 229 | GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue)); |
228 | GNUNET_STATISTICS_set(stats, | 230 | GNUNET_STATISTICS_set (stats, |
229 | "# queues active", | 231 | "# queues active", |
230 | GNUNET_CONTAINER_multipeermap_size(queue_map), | 232 | GNUNET_CONTAINER_multipeermap_size (queue_map), |
231 | GNUNET_NO); | 233 | GNUNET_NO); |
232 | if (NULL != queue->timeout_task) | 234 | if (NULL != queue->timeout_task) |
233 | { | 235 | { |
234 | GNUNET_SCHEDULER_cancel(queue->timeout_task); | 236 | GNUNET_SCHEDULER_cancel (queue->timeout_task); |
235 | queue->timeout_task = NULL; | 237 | queue->timeout_task = NULL; |
236 | } | 238 | } |
237 | GNUNET_free(queue->address); | 239 | GNUNET_free (queue->address); |
238 | GNUNET_free(queue); | 240 | GNUNET_free (queue); |
239 | } | 241 | } |
240 | 242 | ||
241 | 243 | ||
@@ -245,28 +247,28 @@ queue_destroy(struct Queue *queue) | |||
245 | * @param cls the `struct Queue *` to disconnect | 247 | * @param cls the `struct Queue *` to disconnect |
246 | */ | 248 | */ |
247 | static void | 249 | static void |
248 | queue_timeout(void *cls) | 250 | queue_timeout (void *cls) |
249 | { | 251 | { |
250 | struct Queue *queue = cls; | 252 | struct Queue *queue = cls; |
251 | struct GNUNET_TIME_Relative left; | 253 | struct GNUNET_TIME_Relative left; |
252 | 254 | ||
253 | queue->timeout_task = NULL; | 255 | queue->timeout_task = NULL; |
254 | left = GNUNET_TIME_absolute_get_remaining(queue->timeout); | 256 | left = GNUNET_TIME_absolute_get_remaining (queue->timeout); |
255 | if (0 != left.rel_value_us) | 257 | if (0 != left.rel_value_us) |
256 | { | 258 | { |
257 | /* not actually our turn yet, but let's at least update | 259 | /* not actually our turn yet, but let's at least update |
258 | the monitor, it may think we're about to die ... */ | 260 | the monitor, it may think we're about to die ... */ |
259 | queue->timeout_task = | 261 | queue->timeout_task = |
260 | GNUNET_SCHEDULER_add_delayed(left, &queue_timeout, queue); | 262 | GNUNET_SCHEDULER_add_delayed (left, &queue_timeout, queue); |
261 | return; | 263 | return; |
262 | } | 264 | } |
263 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
264 | "Queue %p was idle for %s, disconnecting\n", | 266 | "Queue %p was idle for %s, disconnecting\n", |
265 | queue, | 267 | queue, |
266 | GNUNET_STRINGS_relative_time_to_string( | 268 | GNUNET_STRINGS_relative_time_to_string ( |
267 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 269 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
268 | GNUNET_YES)); | 270 | GNUNET_YES)); |
269 | queue_destroy(queue); | 271 | queue_destroy (queue); |
270 | } | 272 | } |
271 | 273 | ||
272 | 274 | ||
@@ -278,11 +280,11 @@ queue_timeout(void *cls) | |||
278 | * @param queue queue for which the timeout should be rescheduled | 280 | * @param queue queue for which the timeout should be rescheduled |
279 | */ | 281 | */ |
280 | static void | 282 | static void |
281 | reschedule_queue_timeout(struct Queue *queue) | 283 | reschedule_queue_timeout (struct Queue *queue) |
282 | { | 284 | { |
283 | GNUNET_assert(NULL != queue->timeout_task); | 285 | GNUNET_assert (NULL != queue->timeout_task); |
284 | queue->timeout = | 286 | queue->timeout = |
285 | GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 287 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
286 | } | 288 | } |
287 | 289 | ||
288 | 290 | ||
@@ -295,22 +297,22 @@ reschedule_queue_timeout(struct Queue *queue) | |||
295 | * @return converted unix path | 297 | * @return converted unix path |
296 | */ | 298 | */ |
297 | static struct sockaddr_un * | 299 | static struct sockaddr_un * |
298 | unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len) | 300 | unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) |
299 | { | 301 | { |
300 | struct sockaddr_un *un; | 302 | struct sockaddr_un *un; |
301 | size_t slen; | 303 | size_t slen; |
302 | 304 | ||
303 | GNUNET_assert(0 < strlen(unixpath)); /* sanity check */ | 305 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ |
304 | un = GNUNET_new(struct sockaddr_un); | 306 | un = GNUNET_new (struct sockaddr_un); |
305 | un->sun_family = AF_UNIX; | 307 | un->sun_family = AF_UNIX; |
306 | slen = strlen(unixpath); | 308 | slen = strlen (unixpath); |
307 | if (slen >= sizeof(un->sun_path)) | 309 | if (slen >= sizeof(un->sun_path)) |
308 | slen = sizeof(un->sun_path) - 1; | 310 | slen = sizeof(un->sun_path) - 1; |
309 | GNUNET_memcpy(un->sun_path, unixpath, slen); | 311 | GNUNET_memcpy (un->sun_path, unixpath, slen); |
310 | un->sun_path[slen] = '\0'; | 312 | un->sun_path[slen] = '\0'; |
311 | slen = sizeof(struct sockaddr_un); | 313 | slen = sizeof(struct sockaddr_un); |
312 | #if HAVE_SOCKADDR_UN_SUN_LEN | 314 | #if HAVE_SOCKADDR_UN_SUN_LEN |
313 | un->sun_len = (u_char)slen; | 315 | un->sun_len = (u_char) slen; |
314 | #endif | 316 | #endif |
315 | (*sock_len) = slen; | 317 | (*sock_len) = slen; |
316 | if ('@' == un->sun_path[0]) | 318 | if ('@' == un->sun_path[0]) |
@@ -322,7 +324,8 @@ unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len) | |||
322 | /** | 324 | /** |
323 | * Closure to #lookup_queue_it(). | 325 | * Closure to #lookup_queue_it(). |
324 | */ | 326 | */ |
325 | struct LookupCtx { | 327 | struct LookupCtx |
328 | { | ||
326 | /** | 329 | /** |
327 | * Location to store the queue, if found. | 330 | * Location to store the queue, if found. |
328 | */ | 331 | */ |
@@ -349,17 +352,17 @@ struct LookupCtx { | |||
349 | * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success | 352 | * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success |
350 | */ | 353 | */ |
351 | static int | 354 | static int |
352 | lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 355 | lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
353 | { | 356 | { |
354 | struct LookupCtx *lctx = cls; | 357 | struct LookupCtx *lctx = cls; |
355 | struct Queue *queue = value; | 358 | struct Queue *queue = value; |
356 | 359 | ||
357 | if ((queue->address_len = lctx->un_len) && | 360 | if ((queue->address_len = lctx->un_len) && |
358 | (0 == memcmp(lctx->un, queue->address, queue->address_len))) | 361 | (0 == memcmp (lctx->un, queue->address, queue->address_len))) |
359 | { | 362 | { |
360 | lctx->res = queue; | 363 | lctx->res = queue; |
361 | return GNUNET_NO; | 364 | return GNUNET_NO; |
362 | } | 365 | } |
363 | return GNUNET_YES; | 366 | return GNUNET_YES; |
364 | } | 367 | } |
365 | 368 | ||
@@ -372,18 +375,18 @@ lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
372 | * @return NULL if queue was not found | 375 | * @return NULL if queue was not found |
373 | */ | 376 | */ |
374 | static struct Queue * | 377 | static struct Queue * |
375 | lookup_queue(const struct GNUNET_PeerIdentity *peer, | 378 | lookup_queue (const struct GNUNET_PeerIdentity *peer, |
376 | const struct sockaddr_un *un, | 379 | const struct sockaddr_un *un, |
377 | socklen_t un_len) | 380 | socklen_t un_len) |
378 | { | 381 | { |
379 | struct LookupCtx lctx; | 382 | struct LookupCtx lctx; |
380 | 383 | ||
381 | lctx.un = un; | 384 | lctx.un = un; |
382 | lctx.un_len = un_len; | 385 | lctx.un_len = un_len; |
383 | GNUNET_CONTAINER_multipeermap_get_multiple(queue_map, | 386 | GNUNET_CONTAINER_multipeermap_get_multiple (queue_map, |
384 | peer, | 387 | peer, |
385 | &lookup_queue_it, | 388 | &lookup_queue_it, |
386 | &lctx); | 389 | &lctx); |
387 | return lctx.res; | 390 | return lctx.res; |
388 | } | 391 | } |
389 | 392 | ||
@@ -395,105 +398,105 @@ lookup_queue(const struct GNUNET_PeerIdentity *peer, | |||
395 | * @param cls NULL | 398 | * @param cls NULL |
396 | */ | 399 | */ |
397 | static void | 400 | static void |
398 | select_write_cb(void *cls) | 401 | select_write_cb (void *cls) |
399 | { | 402 | { |
400 | struct Queue *queue = queue_tail; | 403 | struct Queue *queue = queue_tail; |
401 | const struct GNUNET_MessageHeader *msg = queue->msg; | 404 | const struct GNUNET_MessageHeader *msg = queue->msg; |
402 | size_t msg_size = ntohs(msg->size); | 405 | size_t msg_size = ntohs (msg->size); |
403 | ssize_t sent; | 406 | ssize_t sent; |
404 | 407 | ||
405 | /* take queue of the ready list */ | 408 | /* take queue of the ready list */ |
406 | write_task = NULL; | 409 | write_task = NULL; |
407 | GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue); | 410 | GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); |
408 | if (NULL != queue_head) | 411 | if (NULL != queue_head) |
409 | write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, | 412 | write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
410 | unix_sock, | 413 | unix_sock, |
411 | &select_write_cb, | 414 | &select_write_cb, |
412 | NULL); | 415 | NULL); |
413 | 416 | ||
414 | /* send 'msg' */ | 417 | /* send 'msg' */ |
415 | queue->msg = NULL; | 418 | queue->msg = NULL; |
416 | GNUNET_MQ_impl_send_continue(queue->mq); | 419 | GNUNET_MQ_impl_send_continue (queue->mq); |
417 | resend: | 420 | resend: |
418 | /* Send the data */ | 421 | /* Send the data */ |
419 | sent = GNUNET_NETWORK_socket_sendto(unix_sock, | 422 | sent = GNUNET_NETWORK_socket_sendto (unix_sock, |
420 | msg, | 423 | msg, |
421 | msg_size, | 424 | msg_size, |
422 | (const struct sockaddr *)queue->address, | 425 | (const struct sockaddr *) queue->address, |
423 | queue->address_len); | 426 | queue->address_len); |
424 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
425 | "UNIX transmitted message to %s (%d/%u: %s)\n", | 428 | "UNIX transmitted message to %s (%d/%u: %s)\n", |
426 | GNUNET_i2s(&queue->target), | 429 | GNUNET_i2s (&queue->target), |
427 | (int)sent, | 430 | (int) sent, |
428 | (unsigned int)msg_size, | 431 | (unsigned int) msg_size, |
429 | (sent < 0) ? strerror(errno) : "ok"); | 432 | (sent < 0) ? strerror (errno) : "ok"); |
430 | if (-1 != sent) | 433 | if (-1 != sent) |
431 | { | 434 | { |
432 | GNUNET_STATISTICS_update(stats, | 435 | GNUNET_STATISTICS_update (stats, |
433 | "# bytes sent", | 436 | "# bytes sent", |
434 | (long long)sent, | 437 | (long long) sent, |
435 | GNUNET_NO); | 438 | GNUNET_NO); |
436 | reschedule_queue_timeout(queue); | 439 | reschedule_queue_timeout (queue); |
437 | return; /* all good */ | 440 | return; /* all good */ |
438 | } | 441 | } |
439 | GNUNET_STATISTICS_update(stats, | 442 | GNUNET_STATISTICS_update (stats, |
440 | "# network transmission failures", | 443 | "# network transmission failures", |
441 | 1, | 444 | 1, |
442 | GNUNET_NO); | 445 | GNUNET_NO); |
443 | switch (errno) | 446 | switch (errno) |
444 | { | 447 | { |
445 | case EAGAIN: | 448 | case EAGAIN: |
446 | case ENOBUFS: | 449 | case ENOBUFS: |
447 | /* We should retry later... */ | 450 | /* We should retry later... */ |
448 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "send"); | 451 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send"); |
449 | return; | 452 | return; |
450 | 453 | ||
451 | case EMSGSIZE: { | 454 | case EMSGSIZE: { |
452 | socklen_t size = 0; | 455 | socklen_t size = 0; |
453 | socklen_t len = sizeof(size); | 456 | socklen_t len = sizeof(size); |
454 | 457 | ||
455 | GNUNET_NETWORK_socket_getsockopt(unix_sock, | 458 | GNUNET_NETWORK_socket_getsockopt (unix_sock, |
456 | SOL_SOCKET, | 459 | SOL_SOCKET, |
457 | SO_SNDBUF, | 460 | SO_SNDBUF, |
458 | &size, | 461 | &size, |
459 | &len); | 462 | &len); |
460 | if (size > ntohs(msg->size)) | 463 | if (size > ntohs (msg->size)) |
461 | { | 464 | { |
462 | /* Buffer is bigger than message: error, no retry | 465 | /* Buffer is bigger than message: error, no retry |
463 | * This should never happen!*/ | 466 | * This should never happen!*/ |
464 | GNUNET_break(0); | 467 | GNUNET_break (0); |
465 | return; | 468 | return; |
466 | } | 469 | } |
467 | GNUNET_log( | 470 | GNUNET_log ( |
468 | GNUNET_ERROR_TYPE_DEBUG, | 471 | GNUNET_ERROR_TYPE_DEBUG, |
469 | "Trying to increase socket buffer size from %u to %u for message size %u\n", | 472 | "Trying to increase socket buffer size from %u to %u for message size %u\n", |
470 | (unsigned int)size, | 473 | (unsigned int) size, |
471 | (unsigned int)((msg_size / 1000) + 2) * 1000, | 474 | (unsigned int) ((msg_size / 1000) + 2) * 1000, |
472 | (unsigned int)msg_size); | 475 | (unsigned int) msg_size); |
473 | size = ((msg_size / 1000) + 2) * 1000; | 476 | size = ((msg_size / 1000) + 2) * 1000; |
474 | if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock, | 477 | if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock, |
475 | SOL_SOCKET, | 478 | SOL_SOCKET, |
476 | SO_SNDBUF, | 479 | SO_SNDBUF, |
477 | &size, | 480 | &size, |
478 | sizeof(size))) | 481 | sizeof(size))) |
479 | goto resend; /* Increased buffer size, retry sending */ | 482 | goto resend; /* Increased buffer size, retry sending */ |
480 | /* Ok, then just try very modest increase */ | 483 | /* Ok, then just try very modest increase */ |
481 | size = msg_size; | 484 | size = msg_size; |
482 | if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock, | 485 | if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock, |
483 | SOL_SOCKET, | 486 | SOL_SOCKET, |
484 | SO_SNDBUF, | 487 | SO_SNDBUF, |
485 | &size, | 488 | &size, |
486 | sizeof(size))) | 489 | sizeof(size))) |
487 | goto resend; /* Increased buffer size, retry sending */ | 490 | goto resend; /* Increased buffer size, retry sending */ |
488 | /* Could not increase buffer size: error, no retry */ | 491 | /* Could not increase buffer size: error, no retry */ |
489 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt"); | 492 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt"); |
490 | return; | 493 | return; |
491 | } | 494 | } |
492 | 495 | ||
493 | default: | 496 | default: |
494 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "send"); | 497 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "send"); |
495 | return; | 498 | return; |
496 | } | 499 | } |
497 | } | 500 | } |
498 | 501 | ||
499 | 502 | ||
@@ -506,22 +509,22 @@ resend: | |||
506 | * @param impl_state our `struct Queue` | 509 | * @param impl_state our `struct Queue` |
507 | */ | 510 | */ |
508 | static void | 511 | static void |
509 | mq_send(struct GNUNET_MQ_Handle *mq, | 512 | mq_send (struct GNUNET_MQ_Handle *mq, |
510 | const struct GNUNET_MessageHeader *msg, | 513 | const struct GNUNET_MessageHeader *msg, |
511 | void *impl_state) | 514 | void *impl_state) |
512 | { | 515 | { |
513 | struct Queue *queue = impl_state; | 516 | struct Queue *queue = impl_state; |
514 | 517 | ||
515 | GNUNET_assert(mq == queue->mq); | 518 | GNUNET_assert (mq == queue->mq); |
516 | GNUNET_assert(NULL == queue->msg); | 519 | GNUNET_assert (NULL == queue->msg); |
517 | queue->msg = msg; | 520 | queue->msg = msg; |
518 | GNUNET_CONTAINER_DLL_insert(queue_head, queue_tail, queue); | 521 | GNUNET_CONTAINER_DLL_insert (queue_head, queue_tail, queue); |
519 | GNUNET_assert(NULL != unix_sock); | 522 | GNUNET_assert (NULL != unix_sock); |
520 | if (NULL == write_task) | 523 | if (NULL == write_task) |
521 | write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, | 524 | write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
522 | unix_sock, | 525 | unix_sock, |
523 | &select_write_cb, | 526 | &select_write_cb, |
524 | NULL); | 527 | NULL); |
525 | } | 528 | } |
526 | 529 | ||
527 | 530 | ||
@@ -534,15 +537,15 @@ mq_send(struct GNUNET_MQ_Handle *mq, | |||
534 | * @param impl_state our `struct Queue` | 537 | * @param impl_state our `struct Queue` |
535 | */ | 538 | */ |
536 | static void | 539 | static void |
537 | mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) | 540 | mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) |
538 | { | 541 | { |
539 | struct Queue *queue = impl_state; | 542 | struct Queue *queue = impl_state; |
540 | 543 | ||
541 | if (mq == queue->mq) | 544 | if (mq == queue->mq) |
542 | { | 545 | { |
543 | queue->mq = NULL; | 546 | queue->mq = NULL; |
544 | queue_destroy(queue); | 547 | queue_destroy (queue); |
545 | } | 548 | } |
546 | } | 549 | } |
547 | 550 | ||
548 | 551 | ||
@@ -553,19 +556,19 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
553 | * @param impl_state our `struct Queue` | 556 | * @param impl_state our `struct Queue` |
554 | */ | 557 | */ |
555 | static void | 558 | static void |
556 | mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) | 559 | mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) |
557 | { | 560 | { |
558 | struct Queue *queue = impl_state; | 561 | struct Queue *queue = impl_state; |
559 | 562 | ||
560 | GNUNET_assert(NULL != queue->msg); | 563 | GNUNET_assert (NULL != queue->msg); |
561 | queue->msg = NULL; | 564 | queue->msg = NULL; |
562 | GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue); | 565 | GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); |
563 | GNUNET_assert(NULL != write_task); | 566 | GNUNET_assert (NULL != write_task); |
564 | if (NULL == queue_head) | 567 | if (NULL == queue_head) |
565 | { | 568 | { |
566 | GNUNET_SCHEDULER_cancel(write_task); | 569 | GNUNET_SCHEDULER_cancel (write_task); |
567 | write_task = NULL; | 570 | write_task = NULL; |
568 | } | 571 | } |
569 | } | 572 | } |
570 | 573 | ||
571 | 574 | ||
@@ -579,15 +582,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
579 | * @param error error code | 582 | * @param error error code |
580 | */ | 583 | */ |
581 | static void | 584 | static void |
582 | mq_error(void *cls, enum GNUNET_MQ_Error error) | 585 | mq_error (void *cls, enum GNUNET_MQ_Error error) |
583 | { | 586 | { |
584 | struct Queue *queue = cls; | 587 | struct Queue *queue = cls; |
585 | 588 | ||
586 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 589 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
587 | "UNIX MQ error in queue to %s: %d\n", | 590 | "UNIX MQ error in queue to %s: %d\n", |
588 | GNUNET_i2s(&queue->target), | 591 | GNUNET_i2s (&queue->target), |
589 | (int)error); | 592 | (int) error); |
590 | queue_destroy(queue); | 593 | queue_destroy (queue); |
591 | } | 594 | } |
592 | 595 | ||
593 | 596 | ||
@@ -602,60 +605,60 @@ mq_error(void *cls, enum GNUNET_MQ_Error error) | |||
602 | * @return the queue or NULL of max connections exceeded | 605 | * @return the queue or NULL of max connections exceeded |
603 | */ | 606 | */ |
604 | static struct Queue * | 607 | static struct Queue * |
605 | setup_queue(const struct GNUNET_PeerIdentity *target, | 608 | setup_queue (const struct GNUNET_PeerIdentity *target, |
606 | enum GNUNET_TRANSPORT_ConnectionStatus cs, | 609 | enum GNUNET_TRANSPORT_ConnectionStatus cs, |
607 | const struct sockaddr_un *un, | 610 | const struct sockaddr_un *un, |
608 | socklen_t un_len) | 611 | socklen_t un_len) |
609 | { | 612 | { |
610 | struct Queue *queue; | 613 | struct Queue *queue; |
611 | 614 | ||
612 | queue = GNUNET_new(struct Queue); | 615 | queue = GNUNET_new (struct Queue); |
613 | queue->target = *target; | 616 | queue->target = *target; |
614 | queue->address = GNUNET_memdup(un, un_len); | 617 | queue->address = GNUNET_memdup (un, un_len); |
615 | queue->address_len = un_len; | 618 | queue->address_len = un_len; |
616 | (void)GNUNET_CONTAINER_multipeermap_put( | 619 | (void) GNUNET_CONTAINER_multipeermap_put ( |
617 | queue_map, | 620 | queue_map, |
618 | &queue->target, | 621 | &queue->target, |
619 | queue, | 622 | queue, |
620 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 623 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
621 | GNUNET_STATISTICS_set(stats, | 624 | GNUNET_STATISTICS_set (stats, |
622 | "# queues active", | 625 | "# queues active", |
623 | GNUNET_CONTAINER_multipeermap_size(queue_map), | 626 | GNUNET_CONTAINER_multipeermap_size (queue_map), |
624 | GNUNET_NO); | 627 | GNUNET_NO); |
625 | queue->timeout = | 628 | queue->timeout = |
626 | GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 629 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
627 | queue->timeout_task = | 630 | queue->timeout_task = |
628 | GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 631 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
629 | &queue_timeout, | 632 | &queue_timeout, |
630 | queue); | 633 | queue); |
631 | queue->mq = GNUNET_MQ_queue_for_callbacks(&mq_send, | 634 | queue->mq = GNUNET_MQ_queue_for_callbacks (&mq_send, |
632 | &mq_destroy, | 635 | &mq_destroy, |
633 | &mq_cancel, | 636 | &mq_cancel, |
634 | queue, | 637 | queue, |
635 | NULL, | 638 | NULL, |
636 | &mq_error, | 639 | &mq_error, |
637 | queue); | 640 | queue); |
638 | { | 641 | { |
639 | char *foreign_addr; | 642 | char *foreign_addr; |
640 | 643 | ||
641 | if ('\0' == un->sun_path[0]) | 644 | if ('\0' == un->sun_path[0]) |
642 | GNUNET_asprintf(&foreign_addr, | 645 | GNUNET_asprintf (&foreign_addr, |
643 | "%s-@%s", | 646 | "%s-@%s", |
644 | COMMUNICATOR_ADDRESS_PREFIX, | 647 | COMMUNICATOR_ADDRESS_PREFIX, |
645 | &un->sun_path[1]); | 648 | &un->sun_path[1]); |
646 | else | 649 | else |
647 | GNUNET_asprintf(&foreign_addr, | 650 | GNUNET_asprintf (&foreign_addr, |
648 | "%s-%s", | 651 | "%s-%s", |
649 | COMMUNICATOR_ADDRESS_PREFIX, | 652 | COMMUNICATOR_ADDRESS_PREFIX, |
650 | un->sun_path); | 653 | un->sun_path); |
651 | queue->qh = GNUNET_TRANSPORT_communicator_mq_add(ch, | 654 | queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, |
652 | &queue->target, | 655 | &queue->target, |
653 | foreign_addr, | 656 | foreign_addr, |
654 | UNIX_MTU, | 657 | UNIX_MTU, |
655 | GNUNET_NT_LOOPBACK, | 658 | GNUNET_NT_LOOPBACK, |
656 | cs, | 659 | cs, |
657 | queue->mq); | 660 | queue->mq); |
658 | GNUNET_free(foreign_addr); | 661 | GNUNET_free (foreign_addr); |
659 | } | 662 | } |
660 | return queue; | 663 | return queue; |
661 | } | 664 | } |
@@ -669,7 +672,7 @@ setup_queue(const struct GNUNET_PeerIdentity *target, | |||
669 | * @param cls NULL | 672 | * @param cls NULL |
670 | */ | 673 | */ |
671 | static void | 674 | static void |
672 | select_read_cb(void *cls); | 675 | select_read_cb (void *cls); |
673 | 676 | ||
674 | 677 | ||
675 | /** | 678 | /** |
@@ -680,21 +683,21 @@ select_read_cb(void *cls); | |||
680 | * @param success #GNUNET_OK on success | 683 | * @param success #GNUNET_OK on success |
681 | */ | 684 | */ |
682 | static void | 685 | static void |
683 | receive_complete_cb(void *cls, int success) | 686 | receive_complete_cb (void *cls, int success) |
684 | { | 687 | { |
685 | (void)cls; | 688 | (void) cls; |
686 | delivering_messages--; | 689 | delivering_messages--; |
687 | if (GNUNET_OK != success) | 690 | if (GNUNET_OK != success) |
688 | GNUNET_STATISTICS_update(stats, | 691 | GNUNET_STATISTICS_update (stats, |
689 | "# transport transmission failures", | 692 | "# transport transmission failures", |
690 | 1, | 693 | 1, |
691 | GNUNET_NO); | 694 | GNUNET_NO); |
692 | GNUNET_assert(NULL != unix_sock); | 695 | GNUNET_assert (NULL != unix_sock); |
693 | if ((NULL == read_task) && (delivering_messages < max_queue_length)) | 696 | if ((NULL == read_task) && (delivering_messages < max_queue_length)) |
694 | read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | 697 | read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
695 | unix_sock, | 698 | unix_sock, |
696 | &select_read_cb, | 699 | &select_read_cb, |
697 | NULL); | 700 | NULL); |
698 | } | 701 | } |
699 | 702 | ||
700 | 703 | ||
@@ -706,7 +709,7 @@ receive_complete_cb(void *cls, int success) | |||
706 | * @param cls NULL | 709 | * @param cls NULL |
707 | */ | 710 | */ |
708 | static void | 711 | static void |
709 | select_read_cb(void *cls) | 712 | select_read_cb (void *cls) |
710 | { | 713 | { |
711 | char buf[65536] GNUNET_ALIGN; | 714 | char buf[65536] GNUNET_ALIGN; |
712 | struct Queue *queue; | 715 | struct Queue *queue; |
@@ -716,93 +719,93 @@ select_read_cb(void *cls) | |||
716 | ssize_t ret; | 719 | ssize_t ret; |
717 | uint16_t msize; | 720 | uint16_t msize; |
718 | 721 | ||
719 | GNUNET_assert(NULL != unix_sock); | 722 | GNUNET_assert (NULL != unix_sock); |
720 | read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | 723 | read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
721 | unix_sock, | 724 | unix_sock, |
722 | &select_read_cb, | 725 | &select_read_cb, |
723 | NULL); | 726 | NULL); |
724 | addrlen = sizeof(un); | 727 | addrlen = sizeof(un); |
725 | memset(&un, 0, sizeof(un)); | 728 | memset (&un, 0, sizeof(un)); |
726 | ret = GNUNET_NETWORK_socket_recvfrom(unix_sock, | 729 | ret = GNUNET_NETWORK_socket_recvfrom (unix_sock, |
727 | buf, | 730 | buf, |
728 | sizeof(buf), | 731 | sizeof(buf), |
729 | (struct sockaddr *)&un, | 732 | (struct sockaddr *) &un, |
730 | &addrlen); | 733 | &addrlen); |
731 | if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno))) | 734 | if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno))) |
732 | return; | 735 | return; |
733 | if (-1 == ret) | 736 | if (-1 == ret) |
734 | { | 737 | { |
735 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom"); | 738 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); |
736 | return; | 739 | return; |
737 | } | 740 | } |
738 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 741 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
739 | "Read %d bytes from socket %s\n", | 742 | "Read %d bytes from socket %s\n", |
740 | (int)ret, | 743 | (int) ret, |
741 | un.sun_path); | 744 | un.sun_path); |
742 | GNUNET_assert(AF_UNIX == (un.sun_family)); | 745 | GNUNET_assert (AF_UNIX == (un.sun_family)); |
743 | msg = (struct UNIXMessage *)buf; | 746 | msg = (struct UNIXMessage *) buf; |
744 | msize = ntohs(msg->header.size); | 747 | msize = ntohs (msg->header.size); |
745 | if ((msize < sizeof(struct UNIXMessage)) || (msize > ret)) | 748 | if ((msize < sizeof(struct UNIXMessage)) || (msize > ret)) |
746 | { | 749 | { |
747 | GNUNET_break_op(0); | 750 | GNUNET_break_op (0); |
748 | return; | 751 | return; |
749 | } | 752 | } |
750 | queue = lookup_queue(&msg->sender, &un, addrlen); | 753 | queue = lookup_queue (&msg->sender, &un, addrlen); |
751 | if (NULL == queue) | 754 | if (NULL == queue) |
752 | queue = | 755 | queue = |
753 | setup_queue(&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen); | 756 | setup_queue (&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen); |
754 | else | 757 | else |
755 | reschedule_queue_timeout(queue); | 758 | reschedule_queue_timeout (queue); |
756 | if (NULL == queue) | 759 | if (NULL == queue) |
757 | { | 760 | { |
758 | GNUNET_log( | 761 | GNUNET_log ( |
759 | GNUNET_ERROR_TYPE_ERROR, | 762 | GNUNET_ERROR_TYPE_ERROR, |
760 | _( | 763 | _ ( |
761 | "Maximum number of UNIX connections exceeded, dropping incoming message\n")); | 764 | "Maximum number of UNIX connections exceeded, dropping incoming message\n")); |
762 | return; | 765 | return; |
763 | } | 766 | } |
764 | 767 | ||
765 | { | 768 | { |
766 | uint16_t offset = 0; | 769 | uint16_t offset = 0; |
767 | uint16_t tsize = msize - sizeof(struct UNIXMessage); | 770 | uint16_t tsize = msize - sizeof(struct UNIXMessage); |
768 | const char *msgbuf = (const char *)&msg[1]; | 771 | const char *msgbuf = (const char *) &msg[1]; |
769 | 772 | ||
770 | while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize) | 773 | while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize) |
774 | { | ||
775 | const struct GNUNET_MessageHeader *currhdr; | ||
776 | struct GNUNET_MessageHeader al_hdr; | ||
777 | uint16_t csize; | ||
778 | |||
779 | currhdr = (const struct GNUNET_MessageHeader *) &msgbuf[offset]; | ||
780 | /* ensure aligned access */ | ||
781 | memcpy (&al_hdr, currhdr, sizeof(al_hdr)); | ||
782 | csize = ntohs (al_hdr.size); | ||
783 | if ((csize < sizeof(struct GNUNET_MessageHeader)) || | ||
784 | (csize > tsize - offset)) | ||
771 | { | 785 | { |
772 | const struct GNUNET_MessageHeader *currhdr; | 786 | GNUNET_break_op (0); |
773 | struct GNUNET_MessageHeader al_hdr; | 787 | break; |
774 | uint16_t csize; | ||
775 | |||
776 | currhdr = (const struct GNUNET_MessageHeader *)&msgbuf[offset]; | ||
777 | /* ensure aligned access */ | ||
778 | memcpy(&al_hdr, currhdr, sizeof(al_hdr)); | ||
779 | csize = ntohs(al_hdr.size); | ||
780 | if ((csize < sizeof(struct GNUNET_MessageHeader)) || | ||
781 | (csize > tsize - offset)) | ||
782 | { | ||
783 | GNUNET_break_op(0); | ||
784 | break; | ||
785 | } | ||
786 | ret = GNUNET_TRANSPORT_communicator_receive(ch, | ||
787 | &msg->sender, | ||
788 | currhdr, | ||
789 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
790 | &receive_complete_cb, | ||
791 | NULL); | ||
792 | if (GNUNET_SYSERR == ret) | ||
793 | return; /* transport not up */ | ||
794 | if (GNUNET_NO == ret) | ||
795 | break; | ||
796 | delivering_messages++; | ||
797 | offset += csize; | ||
798 | } | 788 | } |
789 | ret = GNUNET_TRANSPORT_communicator_receive (ch, | ||
790 | &msg->sender, | ||
791 | currhdr, | ||
792 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
793 | &receive_complete_cb, | ||
794 | NULL); | ||
795 | if (GNUNET_SYSERR == ret) | ||
796 | return; /* transport not up */ | ||
797 | if (GNUNET_NO == ret) | ||
798 | break; | ||
799 | delivering_messages++; | ||
800 | offset += csize; | ||
801 | } | ||
799 | } | 802 | } |
800 | if (delivering_messages >= max_queue_length) | 803 | if (delivering_messages >= max_queue_length) |
801 | { | 804 | { |
802 | /* we should try to apply 'back pressure' */ | 805 | /* we should try to apply 'back pressure' */ |
803 | GNUNET_SCHEDULER_cancel(read_task); | 806 | GNUNET_SCHEDULER_cancel (read_task); |
804 | read_task = NULL; | 807 | read_task = NULL; |
805 | } | 808 | } |
806 | } | 809 | } |
807 | 810 | ||
808 | 811 | ||
@@ -824,43 +827,43 @@ select_read_cb(void *cls) | |||
824 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid | 827 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid |
825 | */ | 828 | */ |
826 | static int | 829 | static int |
827 | mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | 830 | mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) |
828 | { | 831 | { |
829 | struct Queue *queue; | 832 | struct Queue *queue; |
830 | const char *path; | 833 | const char *path; |
831 | struct sockaddr_un *un; | 834 | struct sockaddr_un *un; |
832 | socklen_t un_len; | 835 | socklen_t un_len; |
833 | 836 | ||
834 | (void)cls; | 837 | (void) cls; |
835 | if (0 != strncmp(address, | 838 | if (0 != strncmp (address, |
836 | COMMUNICATOR_ADDRESS_PREFIX "-", | 839 | COMMUNICATOR_ADDRESS_PREFIX "-", |
837 | strlen(COMMUNICATOR_ADDRESS_PREFIX "-"))) | 840 | strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) |
838 | { | 841 | { |
839 | GNUNET_break_op(0); | 842 | GNUNET_break_op (0); |
840 | return GNUNET_SYSERR; | 843 | return GNUNET_SYSERR; |
841 | } | 844 | } |
842 | path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")]; | 845 | path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; |
843 | un = unix_address_to_sockaddr(path, &un_len); | 846 | un = unix_address_to_sockaddr (path, &un_len); |
844 | queue = lookup_queue(peer, un, un_len); | 847 | queue = lookup_queue (peer, un, un_len); |
845 | if (NULL != queue) | 848 | if (NULL != queue) |
846 | { | 849 | { |
847 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 850 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
848 | "Address `%s' for %s ignored, queue exists\n", | 851 | "Address `%s' for %s ignored, queue exists\n", |
849 | path, | 852 | path, |
850 | GNUNET_i2s(peer)); | 853 | GNUNET_i2s (peer)); |
851 | GNUNET_free(un); | 854 | GNUNET_free (un); |
852 | return GNUNET_OK; | 855 | return GNUNET_OK; |
853 | } | 856 | } |
854 | queue = setup_queue(peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len); | 857 | queue = setup_queue (peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len); |
855 | GNUNET_free(un); | 858 | GNUNET_free (un); |
856 | if (NULL == queue) | 859 | if (NULL == queue) |
857 | { | 860 | { |
858 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 861 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
859 | "Failed to setup queue to %s at `%s'\n", | 862 | "Failed to setup queue to %s at `%s'\n", |
860 | GNUNET_i2s(peer), | 863 | GNUNET_i2s (peer), |
861 | path); | 864 | path); |
862 | return GNUNET_NO; | 865 | return GNUNET_NO; |
863 | } | 866 | } |
864 | return GNUNET_OK; | 867 | return GNUNET_OK; |
865 | } | 868 | } |
866 | 869 | ||
@@ -874,15 +877,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
874 | * @return #GNUNET_OK to continue to iterate | 877 | * @return #GNUNET_OK to continue to iterate |
875 | */ | 878 | */ |
876 | static int | 879 | static int |
877 | get_queue_delete_it(void *cls, | 880 | get_queue_delete_it (void *cls, |
878 | const struct GNUNET_PeerIdentity *target, | 881 | const struct GNUNET_PeerIdentity *target, |
879 | void *value) | 882 | void *value) |
880 | { | 883 | { |
881 | struct Queue *queue = value; | 884 | struct Queue *queue = value; |
882 | 885 | ||
883 | (void)cls; | 886 | (void) cls; |
884 | (void)target; | 887 | (void) target; |
885 | queue_destroy(queue); | 888 | queue_destroy (queue); |
886 | return GNUNET_OK; | 889 | return GNUNET_OK; |
887 | } | 890 | } |
888 | 891 | ||
@@ -893,40 +896,40 @@ get_queue_delete_it(void *cls, | |||
893 | * @param cls NULL (always) | 896 | * @param cls NULL (always) |
894 | */ | 897 | */ |
895 | static void | 898 | static void |
896 | do_shutdown(void *cls) | 899 | do_shutdown (void *cls) |
897 | { | 900 | { |
898 | if (NULL != read_task) | 901 | if (NULL != read_task) |
899 | { | 902 | { |
900 | GNUNET_SCHEDULER_cancel(read_task); | 903 | GNUNET_SCHEDULER_cancel (read_task); |
901 | read_task = NULL; | 904 | read_task = NULL; |
902 | } | 905 | } |
903 | if (NULL != write_task) | 906 | if (NULL != write_task) |
904 | { | 907 | { |
905 | GNUNET_SCHEDULER_cancel(write_task); | 908 | GNUNET_SCHEDULER_cancel (write_task); |
906 | write_task = NULL; | 909 | write_task = NULL; |
907 | } | 910 | } |
908 | if (NULL != unix_sock) | 911 | if (NULL != unix_sock) |
909 | { | 912 | { |
910 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(unix_sock)); | 913 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (unix_sock)); |
911 | unix_sock = NULL; | 914 | unix_sock = NULL; |
912 | } | 915 | } |
913 | GNUNET_CONTAINER_multipeermap_iterate(queue_map, &get_queue_delete_it, NULL); | 916 | GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); |
914 | GNUNET_CONTAINER_multipeermap_destroy(queue_map); | 917 | GNUNET_CONTAINER_multipeermap_destroy (queue_map); |
915 | if (NULL != ai) | 918 | if (NULL != ai) |
916 | { | 919 | { |
917 | GNUNET_TRANSPORT_communicator_address_remove(ai); | 920 | GNUNET_TRANSPORT_communicator_address_remove (ai); |
918 | ai = NULL; | 921 | ai = NULL; |
919 | } | 922 | } |
920 | if (NULL != ch) | 923 | if (NULL != ch) |
921 | { | 924 | { |
922 | GNUNET_TRANSPORT_communicator_disconnect(ch); | 925 | GNUNET_TRANSPORT_communicator_disconnect (ch); |
923 | ch = NULL; | 926 | ch = NULL; |
924 | } | 927 | } |
925 | if (NULL != stats) | 928 | if (NULL != stats) |
926 | { | 929 | { |
927 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); | 930 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
928 | stats = NULL; | 931 | stats = NULL; |
929 | } | 932 | } |
930 | } | 933 | } |
931 | 934 | ||
932 | 935 | ||
@@ -942,14 +945,14 @@ do_shutdown(void *cls) | |||
942 | * @param msg payload | 945 | * @param msg payload |
943 | */ | 946 | */ |
944 | static void | 947 | static void |
945 | enc_notify_cb(void *cls, | 948 | enc_notify_cb (void *cls, |
946 | const struct GNUNET_PeerIdentity *sender, | 949 | const struct GNUNET_PeerIdentity *sender, |
947 | const struct GNUNET_MessageHeader *msg) | 950 | const struct GNUNET_MessageHeader *msg) |
948 | { | 951 | { |
949 | (void)cls; | 952 | (void) cls; |
950 | (void)sender; | 953 | (void) sender; |
951 | (void)msg; | 954 | (void) msg; |
952 | GNUNET_break_op(0); | 955 | GNUNET_break_op (0); |
953 | } | 956 | } |
954 | 957 | ||
955 | 958 | ||
@@ -962,110 +965,110 @@ enc_notify_cb(void *cls, | |||
962 | * @param cfg configuration | 965 | * @param cfg configuration |
963 | */ | 966 | */ |
964 | static void | 967 | static void |
965 | run(void *cls, | 968 | run (void *cls, |
966 | char *const *args, | 969 | char *const *args, |
967 | const char *cfgfile, | 970 | const char *cfgfile, |
968 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 971 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
969 | { | 972 | { |
970 | char *unix_socket_path; | 973 | char *unix_socket_path; |
971 | struct sockaddr_un *un; | 974 | struct sockaddr_un *un; |
972 | socklen_t un_len; | 975 | socklen_t un_len; |
973 | char *my_addr; | 976 | char *my_addr; |
974 | 977 | ||
975 | (void)cls; | 978 | (void) cls; |
976 | 979 | ||
977 | if (GNUNET_OK != | 980 | if (GNUNET_OK != |
978 | GNUNET_CONFIGURATION_get_value_filename(cfg, | 981 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
979 | COMMUNICATOR_CONFIG_SECTION, | 982 | COMMUNICATOR_CONFIG_SECTION, |
980 | "UNIXPATH", | 983 | "UNIXPATH", |
981 | &unix_socket_path)) | 984 | &unix_socket_path)) |
982 | { | 985 | { |
983 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 986 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
984 | COMMUNICATOR_CONFIG_SECTION, | 987 | COMMUNICATOR_CONFIG_SECTION, |
985 | "UNIXPATH"); | 988 | "UNIXPATH"); |
986 | return; | 989 | return; |
987 | } | 990 | } |
988 | if (GNUNET_OK != | 991 | if (GNUNET_OK != |
989 | GNUNET_CONFIGURATION_get_value_number(cfg, | 992 | GNUNET_CONFIGURATION_get_value_number (cfg, |
990 | COMMUNICATOR_CONFIG_SECTION, | 993 | COMMUNICATOR_CONFIG_SECTION, |
991 | "MAX_QUEUE_LENGTH", | 994 | "MAX_QUEUE_LENGTH", |
992 | &max_queue_length)) | 995 | &max_queue_length)) |
993 | max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; | 996 | max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; |
994 | 997 | ||
995 | un = unix_address_to_sockaddr(unix_socket_path, &un_len); | 998 | un = unix_address_to_sockaddr (unix_socket_path, &un_len); |
996 | if (NULL == un) | 999 | if (NULL == un) |
997 | { | 1000 | { |
998 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1001 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
999 | "Failed to setup UNIX domain socket address with path `%s'\n", | 1002 | "Failed to setup UNIX domain socket address with path `%s'\n", |
1000 | unix_socket_path); | 1003 | unix_socket_path); |
1001 | GNUNET_free(unix_socket_path); | 1004 | GNUNET_free (unix_socket_path); |
1002 | return; | 1005 | return; |
1003 | } | 1006 | } |
1004 | unix_sock = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0); | 1007 | unix_sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); |
1005 | if (NULL == unix_sock) | 1008 | if (NULL == unix_sock) |
1006 | { | 1009 | { |
1007 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); | 1010 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
1008 | GNUNET_free(un); | 1011 | GNUNET_free (un); |
1009 | GNUNET_free(unix_socket_path); | 1012 | GNUNET_free (unix_socket_path); |
1010 | return; | 1013 | return; |
1011 | } | 1014 | } |
1012 | if (('\0' != un->sun_path[0]) && | 1015 | if (('\0' != un->sun_path[0]) && |
1013 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path))) | 1016 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))) |
1014 | { | 1017 | { |
1015 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1018 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1016 | _("Cannot create path to `%s'\n"), | 1019 | _ ("Cannot create path to `%s'\n"), |
1017 | un->sun_path); | 1020 | un->sun_path); |
1018 | GNUNET_NETWORK_socket_close(unix_sock); | 1021 | GNUNET_NETWORK_socket_close (unix_sock); |
1019 | unix_sock = NULL; | 1022 | unix_sock = NULL; |
1020 | GNUNET_free(un); | 1023 | GNUNET_free (un); |
1021 | GNUNET_free(unix_socket_path); | 1024 | GNUNET_free (unix_socket_path); |
1022 | return; | 1025 | return; |
1023 | } | 1026 | } |
1024 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind(unix_sock, | 1027 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (unix_sock, |
1025 | (const struct sockaddr *)un, | 1028 | (const struct sockaddr *) un, |
1026 | un_len)) | 1029 | un_len)) |
1027 | { | 1030 | { |
1028 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path); | 1031 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path); |
1029 | GNUNET_NETWORK_socket_close(unix_sock); | 1032 | GNUNET_NETWORK_socket_close (unix_sock); |
1030 | unix_sock = NULL; | 1033 | unix_sock = NULL; |
1031 | GNUNET_free(un); | 1034 | GNUNET_free (un); |
1032 | GNUNET_free(unix_socket_path); | 1035 | GNUNET_free (unix_socket_path); |
1033 | return; | 1036 | return; |
1034 | } | 1037 | } |
1035 | GNUNET_free(un); | 1038 | GNUNET_free (un); |
1036 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path); | 1039 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path); |
1037 | stats = GNUNET_STATISTICS_create("C-UNIX", cfg); | 1040 | stats = GNUNET_STATISTICS_create ("C-UNIX", cfg); |
1038 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | 1041 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
1039 | read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | 1042 | read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1040 | unix_sock, | 1043 | unix_sock, |
1041 | &select_read_cb, | 1044 | &select_read_cb, |
1042 | NULL); | ||
1043 | queue_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); | ||
1044 | ch = GNUNET_TRANSPORT_communicator_connect(cfg, | ||
1045 | COMMUNICATOR_CONFIG_SECTION, | ||
1046 | COMMUNICATOR_ADDRESS_PREFIX, | ||
1047 | GNUNET_TRANSPORT_CC_RELIABLE, | ||
1048 | &mq_init, | ||
1049 | NULL, | ||
1050 | &enc_notify_cb, | ||
1051 | NULL); | 1045 | NULL); |
1046 | queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | ||
1047 | ch = GNUNET_TRANSPORT_communicator_connect (cfg, | ||
1048 | COMMUNICATOR_CONFIG_SECTION, | ||
1049 | COMMUNICATOR_ADDRESS_PREFIX, | ||
1050 | GNUNET_TRANSPORT_CC_RELIABLE, | ||
1051 | &mq_init, | ||
1052 | NULL, | ||
1053 | &enc_notify_cb, | ||
1054 | NULL); | ||
1052 | if (NULL == ch) | 1055 | if (NULL == ch) |
1053 | { | 1056 | { |
1054 | GNUNET_break(0); | 1057 | GNUNET_break (0); |
1055 | GNUNET_SCHEDULER_shutdown(); | 1058 | GNUNET_SCHEDULER_shutdown (); |
1056 | GNUNET_free(unix_socket_path); | 1059 | GNUNET_free (unix_socket_path); |
1057 | return; | 1060 | return; |
1058 | } | 1061 | } |
1059 | GNUNET_asprintf(&my_addr, | 1062 | GNUNET_asprintf (&my_addr, |
1060 | "%s-%s", | 1063 | "%s-%s", |
1061 | COMMUNICATOR_ADDRESS_PREFIX, | 1064 | COMMUNICATOR_ADDRESS_PREFIX, |
1062 | unix_socket_path); | 1065 | unix_socket_path); |
1063 | GNUNET_free(unix_socket_path); | 1066 | GNUNET_free (unix_socket_path); |
1064 | ai = GNUNET_TRANSPORT_communicator_address_add(ch, | 1067 | ai = GNUNET_TRANSPORT_communicator_address_add (ch, |
1065 | my_addr, | 1068 | my_addr, |
1066 | GNUNET_NT_LOOPBACK, | 1069 | GNUNET_NT_LOOPBACK, |
1067 | GNUNET_TIME_UNIT_FOREVER_REL); | 1070 | GNUNET_TIME_UNIT_FOREVER_REL); |
1068 | GNUNET_free(my_addr); | 1071 | GNUNET_free (my_addr); |
1069 | } | 1072 | } |
1070 | 1073 | ||
1071 | 1074 | ||
@@ -1077,27 +1080,27 @@ run(void *cls, | |||
1077 | * @return 0 ok, 1 on error | 1080 | * @return 0 ok, 1 on error |
1078 | */ | 1081 | */ |
1079 | int | 1082 | int |
1080 | main(int argc, char *const *argv) | 1083 | main (int argc, char *const *argv) |
1081 | { | 1084 | { |
1082 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 1085 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
1083 | GNUNET_GETOPT_OPTION_END | 1086 | GNUNET_GETOPT_OPTION_END |
1084 | }; | 1087 | }; |
1085 | int ret; | 1088 | int ret; |
1086 | 1089 | ||
1087 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 1090 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
1088 | return 2; | 1091 | return 2; |
1089 | 1092 | ||
1090 | ret = (GNUNET_OK == | 1093 | ret = (GNUNET_OK == |
1091 | GNUNET_PROGRAM_run(argc, | 1094 | GNUNET_PROGRAM_run (argc, |
1092 | argv, | 1095 | argv, |
1093 | "gnunet-communicator-unix", | 1096 | "gnunet-communicator-unix", |
1094 | _("GNUnet UNIX domain socket communicator"), | 1097 | _ ("GNUnet UNIX domain socket communicator"), |
1095 | options, | 1098 | options, |
1096 | &run, | 1099 | &run, |
1097 | NULL)) | 1100 | NULL)) |
1098 | ? 0 | 1101 | ? 0 |
1099 | : 1; | 1102 | : 1; |
1100 | GNUNET_free((void *)argv); | 1103 | GNUNET_free ((void *) argv); |
1101 | return ret; | 1104 | return ret; |
1102 | } | 1105 | } |
1103 | 1106 | ||
@@ -1108,11 +1111,11 @@ main(int argc, char *const *argv) | |||
1108 | /** | 1111 | /** |
1109 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 1112 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
1110 | */ | 1113 | */ |
1111 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init() | 1114 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () |
1112 | { | 1115 | { |
1113 | mallopt(M_TRIM_THRESHOLD, 4 * 1024); | 1116 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); |
1114 | mallopt(M_TOP_PAD, 1 * 1024); | 1117 | mallopt (M_TOP_PAD, 1 * 1024); |
1115 | malloc_trim(0); | 1118 | malloc_trim (0); |
1116 | } | 1119 | } |
1117 | #endif | 1120 | #endif |
1118 | 1121 | ||