diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/transport/plugin_transport_unix.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/transport/plugin_transport_unix.c')
-rw-r--r-- | src/transport/plugin_transport_unix.c | 1603 |
1 files changed, 796 insertions, 807 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 2c408ebf5..5f7b38479 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file transport/plugin_transport_unix.c | 22 | * @file transport/plugin_transport_unix.c |
@@ -51,8 +51,7 @@ | |||
51 | /** | 51 | /** |
52 | * Options for UNIX Domain addresses. | 52 | * Options for UNIX Domain addresses. |
53 | */ | 53 | */ |
54 | enum UNIX_ADDRESS_OPTIONS | 54 | enum UNIX_ADDRESS_OPTIONS { |
55 | { | ||
56 | /** | 55 | /** |
57 | * No special options. | 56 | * No special options. |
58 | */ | 57 | */ |
@@ -69,9 +68,9 @@ enum UNIX_ADDRESS_OPTIONS | |||
69 | * How long until we give up on transmitting the welcome message? | 68 | * How long until we give up on transmitting the welcome message? |
70 | */ | 69 | */ |
71 | #define HOSTNAME_RESOLVE_TIMEOUT \ | 70 | #define HOSTNAME_RESOLVE_TIMEOUT \ |
72 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 71 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) |
73 | 72 | ||
74 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-unix", __VA_ARGS__) | 73 | #define LOG(kind, ...) GNUNET_log_from(kind, "transport-unix", __VA_ARGS__) |
75 | 74 | ||
76 | 75 | ||
77 | GNUNET_NETWORK_STRUCT_BEGIN | 76 | GNUNET_NETWORK_STRUCT_BEGIN |
@@ -79,8 +78,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
79 | /** | 78 | /** |
80 | * Binary format for an UNIX Domain Socket address in GNUnet. | 79 | * Binary format for an UNIX Domain Socket address in GNUnet. |
81 | */ | 80 | */ |
82 | struct UnixAddress | 81 | struct UnixAddress { |
83 | { | ||
84 | /** | 82 | /** |
85 | * Options to use for the address, in NBO | 83 | * Options to use for the address, in NBO |
86 | */ | 84 | */ |
@@ -98,8 +96,7 @@ struct UnixAddress | |||
98 | /** | 96 | /** |
99 | * UNIX Message-Packet header. | 97 | * UNIX Message-Packet header. |
100 | */ | 98 | */ |
101 | struct UNIXMessage | 99 | struct UNIXMessage { |
102 | { | ||
103 | /** | 100 | /** |
104 | * Message header. | 101 | * Message header. |
105 | */ | 102 | */ |
@@ -117,8 +114,7 @@ GNUNET_NETWORK_STRUCT_END | |||
117 | /** | 114 | /** |
118 | * Information we track for a message awaiting transmission. | 115 | * Information we track for a message awaiting transmission. |
119 | */ | 116 | */ |
120 | struct UNIXMessageWrapper | 117 | struct UNIXMessageWrapper { |
121 | { | ||
122 | /** | 118 | /** |
123 | * We keep messages in a doubly linked list. | 119 | * We keep messages in a doubly linked list. |
124 | */ | 120 | */ |
@@ -174,9 +170,7 @@ struct UNIXMessageWrapper | |||
174 | /** | 170 | /** |
175 | * Handle for a session. | 171 | * Handle for a session. |
176 | */ | 172 | */ |
177 | struct GNUNET_ATS_Session | 173 | struct GNUNET_ATS_Session { |
178 | { | ||
179 | |||
180 | /** | 174 | /** |
181 | * Sessions with pending messages (!) are kept in a DLL. | 175 | * Sessions with pending messages (!) are kept in a DLL. |
182 | */ | 176 | */ |
@@ -236,8 +230,7 @@ struct Plugin; | |||
236 | /** | 230 | /** |
237 | * Information we keep for each of our listen sockets. | 231 | * Information we keep for each of our listen sockets. |
238 | */ | 232 | */ |
239 | struct UNIX_Sock_Info | 233 | struct UNIX_Sock_Info { |
240 | { | ||
241 | /** | 234 | /** |
242 | * The network handle | 235 | * The network handle |
243 | */ | 236 | */ |
@@ -248,9 +241,7 @@ struct UNIX_Sock_Info | |||
248 | /** | 241 | /** |
249 | * Encapsulation of all of the state of the plugin. | 242 | * Encapsulation of all of the state of the plugin. |
250 | */ | 243 | */ |
251 | struct Plugin | 244 | struct Plugin { |
252 | { | ||
253 | |||
254 | /** | 245 | /** |
255 | * ID of task used to update our addresses when one expires. | 246 | * ID of task used to update our addresses when one expires. |
256 | */ | 247 | */ |
@@ -332,15 +323,15 @@ struct Plugin | |||
332 | * @param state new state of the session | 323 | * @param state new state of the session |
333 | */ | 324 | */ |
334 | static void | 325 | static void |
335 | notify_session_monitor (struct Plugin *plugin, | 326 | notify_session_monitor(struct Plugin *plugin, |
336 | struct GNUNET_ATS_Session *session, | 327 | struct GNUNET_ATS_Session *session, |
337 | enum GNUNET_TRANSPORT_SessionState state) | 328 | enum GNUNET_TRANSPORT_SessionState state) |
338 | { | 329 | { |
339 | struct GNUNET_TRANSPORT_SessionInfo info; | 330 | struct GNUNET_TRANSPORT_SessionInfo info; |
340 | 331 | ||
341 | if (NULL == plugin->sic) | 332 | if (NULL == plugin->sic) |
342 | return; | 333 | return; |
343 | memset (&info, 0, sizeof (info)); | 334 | memset(&info, 0, sizeof(info)); |
344 | info.state = state; | 335 | info.state = state; |
345 | info.is_inbound = GNUNET_SYSERR; /* hard to say */ | 336 | info.is_inbound = GNUNET_SYSERR; /* hard to say */ |
346 | info.num_msg_pending = session->msgs_in_queue; | 337 | info.num_msg_pending = session->msgs_in_queue; |
@@ -350,7 +341,7 @@ notify_session_monitor (struct Plugin *plugin, | |||
350 | to receive from others) */ | 341 | to receive from others) */ |
351 | info.session_timeout = session->timeout; | 342 | info.session_timeout = session->timeout; |
352 | info.address = session->address; | 343 | info.address = session->address; |
353 | plugin->sic (plugin->sic_cls, session, &info); | 344 | plugin->sic(plugin->sic_cls, session, &info); |
354 | } | 345 | } |
355 | 346 | ||
356 | 347 | ||
@@ -366,50 +357,50 @@ notify_session_monitor (struct Plugin *plugin, | |||
366 | * @return string representing the same address | 357 | * @return string representing the same address |
367 | */ | 358 | */ |
368 | static const char * | 359 | static const char * |
369 | unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | 360 | unix_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) |
370 | { | 361 | { |
371 | static char rbuf[1024]; | 362 | static char rbuf[1024]; |
372 | struct UnixAddress *ua = (struct UnixAddress *) addr; | 363 | struct UnixAddress *ua = (struct UnixAddress *)addr; |
373 | char *addrstr; | 364 | char *addrstr; |
374 | size_t addr_str_len; | 365 | size_t addr_str_len; |
375 | unsigned int off; | 366 | unsigned int off; |
376 | 367 | ||
377 | if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) | 368 | if ((NULL == addr) || (sizeof(struct UnixAddress) > addrlen)) |
378 | { | 369 | { |
379 | GNUNET_break (0); | 370 | GNUNET_break(0); |
380 | return NULL; | 371 | return NULL; |
381 | } | 372 | } |
382 | addrstr = (char *) &ua[1]; | 373 | addrstr = (char *)&ua[1]; |
383 | addr_str_len = ntohl (ua->addrlen); | 374 | addr_str_len = ntohl(ua->addrlen); |
384 | 375 | ||
385 | if (addr_str_len != addrlen - sizeof (struct UnixAddress)) | 376 | if (addr_str_len != addrlen - sizeof(struct UnixAddress)) |
386 | { | 377 | { |
387 | GNUNET_break (0); | 378 | GNUNET_break(0); |
388 | return NULL; | 379 | return NULL; |
389 | } | 380 | } |
390 | if ('\0' != addrstr[addr_str_len - 1]) | 381 | if ('\0' != addrstr[addr_str_len - 1]) |
391 | { | 382 | { |
392 | GNUNET_break (0); | 383 | GNUNET_break(0); |
393 | return NULL; | 384 | return NULL; |
394 | } | 385 | } |
395 | if (strlen (addrstr) + 1 != addr_str_len) | 386 | if (strlen(addrstr) + 1 != addr_str_len) |
396 | { | 387 | { |
397 | GNUNET_break (0); | 388 | GNUNET_break(0); |
398 | return NULL; | 389 | return NULL; |
399 | } | 390 | } |
400 | 391 | ||
401 | off = 0; | 392 | off = 0; |
402 | if ('\0' == addrstr[0]) | 393 | if ('\0' == addrstr[0]) |
403 | off++; | 394 | off++; |
404 | memset (rbuf, 0, sizeof (rbuf)); | 395 | memset(rbuf, 0, sizeof(rbuf)); |
405 | GNUNET_snprintf (rbuf, | 396 | GNUNET_snprintf(rbuf, |
406 | sizeof (rbuf) - 1, | 397 | sizeof(rbuf) - 1, |
407 | "%s.%u.%s%.*s", | 398 | "%s.%u.%s%.*s", |
408 | PLUGIN_NAME, | 399 | PLUGIN_NAME, |
409 | ntohl (ua->options), | 400 | ntohl(ua->options), |
410 | (off == 1) ? "@" : "", | 401 | (off == 1) ? "@" : "", |
411 | (int) (addr_str_len - off), | 402 | (int)(addr_str_len - off), |
412 | &addrstr[off]); | 403 | &addrstr[off]); |
413 | return rbuf; | 404 | return rbuf; |
414 | } | 405 | } |
415 | 406 | ||
@@ -424,61 +415,61 @@ unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
424 | * @return #GNUNET_OK on success | 415 | * @return #GNUNET_OK on success |
425 | */ | 416 | */ |
426 | static int | 417 | static int |
427 | unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session) | 418 | unix_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *session) |
428 | { | 419 | { |
429 | struct Plugin *plugin = cls; | 420 | struct Plugin *plugin = cls; |
430 | struct UNIXMessageWrapper *msgw; | 421 | struct UNIXMessageWrapper *msgw; |
431 | struct UNIXMessageWrapper *next; | 422 | struct UNIXMessageWrapper *next; |
432 | 423 | ||
433 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 424 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
434 | "Disconnecting session for peer `%s' `%s'\n", | 425 | "Disconnecting session for peer `%s' `%s'\n", |
435 | GNUNET_i2s (&session->target), | 426 | GNUNET_i2s(&session->target), |
436 | unix_plugin_address_to_string (NULL, | 427 | unix_plugin_address_to_string(NULL, |
437 | session->address->address, | 428 | session->address->address, |
438 | session->address->address_length)); | 429 | session->address->address_length)); |
439 | plugin->env->session_end (plugin->env->cls, session->address, session); | 430 | plugin->env->session_end(plugin->env->cls, session->address, session); |
440 | next = plugin->msg_head; | 431 | next = plugin->msg_head; |
441 | while (NULL != next) | 432 | while (NULL != next) |
442 | { | 433 | { |
443 | msgw = next; | 434 | msgw = next; |
444 | next = msgw->next; | 435 | next = msgw->next; |
445 | if (msgw->session != session) | 436 | if (msgw->session != session) |
446 | continue; | 437 | continue; |
447 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); | 438 | GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); |
448 | session->msgs_in_queue--; | 439 | session->msgs_in_queue--; |
449 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 440 | GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); |
450 | session->bytes_in_queue -= msgw->msgsize; | 441 | session->bytes_in_queue -= msgw->msgsize; |
451 | GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); | 442 | GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); |
452 | plugin->bytes_in_queue -= msgw->msgsize; | 443 | plugin->bytes_in_queue -= msgw->msgsize; |
453 | if (NULL != msgw->cont) | 444 | if (NULL != msgw->cont) |
454 | msgw->cont (msgw->cont_cls, | 445 | msgw->cont(msgw->cont_cls, |
455 | &msgw->session->target, | 446 | &msgw->session->target, |
456 | GNUNET_SYSERR, | 447 | GNUNET_SYSERR, |
457 | msgw->payload, | 448 | msgw->payload, |
458 | 0); | 449 | 0); |
459 | GNUNET_free (msgw->msg); | 450 | GNUNET_free(msgw->msg); |
460 | GNUNET_free (msgw); | 451 | GNUNET_free(msgw); |
461 | } | 452 | } |
462 | GNUNET_assert (GNUNET_YES == | 453 | GNUNET_assert(GNUNET_YES == |
463 | GNUNET_CONTAINER_multipeermap_remove (plugin->session_map, | 454 | GNUNET_CONTAINER_multipeermap_remove(plugin->session_map, |
464 | &session->target, | 455 | &session->target, |
465 | session)); | 456 | session)); |
466 | GNUNET_STATISTICS_set (plugin->env->stats, | 457 | GNUNET_STATISTICS_set(plugin->env->stats, |
467 | "# UNIX sessions active", | 458 | "# UNIX sessions active", |
468 | GNUNET_CONTAINER_multipeermap_size ( | 459 | GNUNET_CONTAINER_multipeermap_size( |
469 | plugin->session_map), | 460 | plugin->session_map), |
470 | GNUNET_NO); | 461 | GNUNET_NO); |
471 | if (NULL != session->timeout_task) | 462 | if (NULL != session->timeout_task) |
472 | { | 463 | { |
473 | GNUNET_SCHEDULER_cancel (session->timeout_task); | 464 | GNUNET_SCHEDULER_cancel(session->timeout_task); |
474 | session->timeout_task = NULL; | 465 | session->timeout_task = NULL; |
475 | session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; | 466 | session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; |
476 | } | 467 | } |
477 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_DONE); | 468 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_DONE); |
478 | GNUNET_HELLO_address_free (session->address); | 469 | GNUNET_HELLO_address_free(session->address); |
479 | GNUNET_break (0 == session->bytes_in_queue); | 470 | GNUNET_break(0 == session->bytes_in_queue); |
480 | GNUNET_break (0 == session->msgs_in_queue); | 471 | GNUNET_break(0 == session->msgs_in_queue); |
481 | GNUNET_free (session); | 472 | GNUNET_free(session); |
482 | return GNUNET_OK; | 473 | return GNUNET_OK; |
483 | } | 474 | } |
484 | 475 | ||
@@ -489,31 +480,31 @@ unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session) | |||
489 | * @param cls the `struct GNUNET_ATS_Session *` to disconnect | 480 | * @param cls the `struct GNUNET_ATS_Session *` to disconnect |
490 | */ | 481 | */ |
491 | static void | 482 | static void |
492 | session_timeout (void *cls) | 483 | session_timeout(void *cls) |
493 | { | 484 | { |
494 | struct GNUNET_ATS_Session *session = cls; | 485 | struct GNUNET_ATS_Session *session = cls; |
495 | struct GNUNET_TIME_Relative left; | 486 | struct GNUNET_TIME_Relative left; |
496 | 487 | ||
497 | session->timeout_task = NULL; | 488 | session->timeout_task = NULL; |
498 | left = GNUNET_TIME_absolute_get_remaining (session->timeout); | 489 | left = GNUNET_TIME_absolute_get_remaining(session->timeout); |
499 | if (0 != left.rel_value_us) | 490 | if (0 != left.rel_value_us) |
500 | { | 491 | { |
501 | /* not actually our turn yet, but let's at least update | 492 | /* not actually our turn yet, but let's at least update |
502 | the monitor, it may think we're about to die ... */ | 493 | the monitor, it may think we're about to die ... */ |
503 | notify_session_monitor (session->plugin, | 494 | notify_session_monitor(session->plugin, |
504 | session, | 495 | session, |
505 | GNUNET_TRANSPORT_SS_UPDATE); | 496 | GNUNET_TRANSPORT_SS_UPDATE); |
506 | session->timeout_task = | 497 | session->timeout_task = |
507 | GNUNET_SCHEDULER_add_delayed (left, &session_timeout, session); | 498 | GNUNET_SCHEDULER_add_delayed(left, &session_timeout, session); |
508 | return; | 499 | return; |
509 | } | 500 | } |
510 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 501 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
511 | "Session %p was idle for %s, disconnecting\n", | 502 | "Session %p was idle for %s, disconnecting\n", |
512 | session, | 503 | session, |
513 | GNUNET_STRINGS_relative_time_to_string ( | 504 | GNUNET_STRINGS_relative_time_to_string( |
514 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 505 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
515 | GNUNET_YES)); | 506 | GNUNET_YES)); |
516 | unix_plugin_session_disconnect (session->plugin, session); | 507 | unix_plugin_session_disconnect(session->plugin, session); |
517 | } | 508 | } |
518 | 509 | ||
519 | 510 | ||
@@ -525,11 +516,11 @@ session_timeout (void *cls) | |||
525 | * @param session session for which the timeout should be rescheduled | 516 | * @param session session for which the timeout should be rescheduled |
526 | */ | 517 | */ |
527 | static void | 518 | static void |
528 | reschedule_session_timeout (struct GNUNET_ATS_Session *session) | 519 | reschedule_session_timeout(struct GNUNET_ATS_Session *session) |
529 | { | 520 | { |
530 | GNUNET_assert (NULL != session->timeout_task); | 521 | GNUNET_assert(NULL != session->timeout_task); |
531 | session->timeout = | 522 | session->timeout = |
532 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 523 | GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
533 | } | 524 | } |
534 | 525 | ||
535 | 526 | ||
@@ -541,22 +532,22 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *session) | |||
541 | * @return converted unix path | 532 | * @return converted unix path |
542 | */ | 533 | */ |
543 | static struct sockaddr_un * | 534 | static struct sockaddr_un * |
544 | unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) | 535 | unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len) |
545 | { | 536 | { |
546 | struct sockaddr_un *un; | 537 | struct sockaddr_un *un; |
547 | size_t slen; | 538 | size_t slen; |
548 | 539 | ||
549 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ | 540 | GNUNET_assert(0 < strlen(unixpath)); /* sanity check */ |
550 | un = GNUNET_new (struct sockaddr_un); | 541 | un = GNUNET_new(struct sockaddr_un); |
551 | un->sun_family = AF_UNIX; | 542 | un->sun_family = AF_UNIX; |
552 | slen = strlen (unixpath); | 543 | slen = strlen(unixpath); |
553 | if (slen >= sizeof (un->sun_path)) | 544 | if (slen >= sizeof(un->sun_path)) |
554 | slen = sizeof (un->sun_path) - 1; | 545 | slen = sizeof(un->sun_path) - 1; |
555 | GNUNET_memcpy (un->sun_path, unixpath, slen); | 546 | GNUNET_memcpy(un->sun_path, unixpath, slen); |
556 | un->sun_path[slen] = '\0'; | 547 | un->sun_path[slen] = '\0'; |
557 | slen = sizeof (struct sockaddr_un); | 548 | slen = sizeof(struct sockaddr_un); |
558 | #if HAVE_SOCKADDR_UN_SUN_LEN | 549 | #if HAVE_SOCKADDR_UN_SUN_LEN |
559 | un->sun_len = (u_char) slen; | 550 | un->sun_len = (u_char)slen; |
560 | #endif | 551 | #endif |
561 | (*sock_len) = slen; | 552 | (*sock_len) = slen; |
562 | return un; | 553 | return un; |
@@ -566,8 +557,7 @@ unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) | |||
566 | /** | 557 | /** |
567 | * Closure to #lookup_session_it(). | 558 | * Closure to #lookup_session_it(). |
568 | */ | 559 | */ |
569 | struct LookupCtx | 560 | struct LookupCtx { |
570 | { | ||
571 | /** | 561 | /** |
572 | * Location to store the session, if found. | 562 | * Location to store the session, if found. |
573 | */ | 563 | */ |
@@ -589,18 +579,18 @@ struct LookupCtx | |||
589 | * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success | 579 | * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success |
590 | */ | 580 | */ |
591 | static int | 581 | static int |
592 | lookup_session_it (void *cls, | 582 | lookup_session_it(void *cls, |
593 | const struct GNUNET_PeerIdentity *key, | 583 | const struct GNUNET_PeerIdentity *key, |
594 | void *value) | 584 | void *value) |
595 | { | 585 | { |
596 | struct LookupCtx *lctx = cls; | 586 | struct LookupCtx *lctx = cls; |
597 | struct GNUNET_ATS_Session *session = value; | 587 | struct GNUNET_ATS_Session *session = value; |
598 | 588 | ||
599 | if (0 == GNUNET_HELLO_address_cmp (lctx->address, session->address)) | 589 | if (0 == GNUNET_HELLO_address_cmp(lctx->address, session->address)) |
600 | { | 590 | { |
601 | lctx->res = session; | 591 | lctx->res = session; |
602 | return GNUNET_NO; | 592 | return GNUNET_NO; |
603 | } | 593 | } |
604 | return GNUNET_YES; | 594 | return GNUNET_YES; |
605 | } | 595 | } |
606 | 596 | ||
@@ -613,17 +603,17 @@ lookup_session_it (void *cls, | |||
613 | * @return NULL if session was not found | 603 | * @return NULL if session was not found |
614 | */ | 604 | */ |
615 | static struct GNUNET_ATS_Session * | 605 | static struct GNUNET_ATS_Session * |
616 | lookup_session (struct Plugin *plugin, | 606 | lookup_session(struct Plugin *plugin, |
617 | const struct GNUNET_HELLO_Address *address) | 607 | const struct GNUNET_HELLO_Address *address) |
618 | { | 608 | { |
619 | struct LookupCtx lctx; | 609 | struct LookupCtx lctx; |
620 | 610 | ||
621 | lctx.address = address; | 611 | lctx.address = address; |
622 | lctx.res = NULL; | 612 | lctx.res = NULL; |
623 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, | 613 | GNUNET_CONTAINER_multipeermap_get_multiple(plugin->session_map, |
624 | &address->peer, | 614 | &address->peer, |
625 | &lookup_session_it, | 615 | &lookup_session_it, |
626 | &lctx); | 616 | &lctx); |
627 | return lctx.res; | 617 | return lctx.res; |
628 | } | 618 | } |
629 | 619 | ||
@@ -637,7 +627,7 @@ lookup_session (struct Plugin *plugin, | |||
637 | * @return keepalive factor | 627 | * @return keepalive factor |
638 | */ | 628 | */ |
639 | static unsigned int | 629 | static unsigned int |
640 | unix_plugin_query_keepalive_factor (void *cls) | 630 | unix_plugin_query_keepalive_factor(void *cls) |
641 | { | 631 | { |
642 | return 3; | 632 | return 3; |
643 | } | 633 | } |
@@ -665,18 +655,18 @@ unix_plugin_query_keepalive_factor (void *cls) | |||
665 | * @return on success the number of bytes written, RETRY for retry, -1 on errors | 655 | * @return on success the number of bytes written, RETRY for retry, -1 on errors |
666 | */ | 656 | */ |
667 | static ssize_t | 657 | static ssize_t |
668 | unix_real_send (void *cls, | 658 | unix_real_send(void *cls, |
669 | struct GNUNET_NETWORK_Handle *send_handle, | 659 | struct GNUNET_NETWORK_Handle *send_handle, |
670 | const struct GNUNET_PeerIdentity *target, | 660 | const struct GNUNET_PeerIdentity *target, |
671 | const char *msgbuf, | 661 | const char *msgbuf, |
672 | size_t msgbuf_size, | 662 | size_t msgbuf_size, |
673 | unsigned int priority, | 663 | unsigned int priority, |
674 | struct GNUNET_TIME_Absolute timeout, | 664 | struct GNUNET_TIME_Absolute timeout, |
675 | const struct UnixAddress *addr, | 665 | const struct UnixAddress *addr, |
676 | size_t addrlen, | 666 | size_t addrlen, |
677 | size_t payload, | 667 | size_t payload, |
678 | GNUNET_TRANSPORT_TransmitContinuation cont, | 668 | GNUNET_TRANSPORT_TransmitContinuation cont, |
679 | void *cont_cls) | 669 | void *cont_cls) |
680 | { | 670 | { |
681 | struct Plugin *plugin = cls; | 671 | struct Plugin *plugin = cls; |
682 | ssize_t sent; | 672 | ssize_t sent; |
@@ -685,96 +675,96 @@ unix_real_send (void *cls, | |||
685 | const char *unixpath; | 675 | const char *unixpath; |
686 | 676 | ||
687 | if (NULL == send_handle) | 677 | if (NULL == send_handle) |
688 | { | 678 | { |
689 | GNUNET_break (0); /* We do not have a send handle */ | 679 | GNUNET_break(0); /* We do not have a send handle */ |
690 | return GNUNET_SYSERR; | 680 | return GNUNET_SYSERR; |
691 | } | 681 | } |
692 | if ((NULL == addr) || (0 == addrlen)) | 682 | if ((NULL == addr) || (0 == addrlen)) |
693 | { | 683 | { |
694 | GNUNET_break (0); /* Can never send if we don't have an address */ | 684 | GNUNET_break(0); /* Can never send if we don't have an address */ |
695 | return GNUNET_SYSERR; | 685 | return GNUNET_SYSERR; |
696 | } | 686 | } |
697 | 687 | ||
698 | /* Prepare address */ | 688 | /* Prepare address */ |
699 | unixpath = (const char *) &addr[1]; | 689 | unixpath = (const char *)&addr[1]; |
700 | if (NULL == (un = unix_address_to_sockaddr (unixpath, &un_len))) | 690 | if (NULL == (un = unix_address_to_sockaddr(unixpath, &un_len))) |
701 | { | 691 | { |
702 | GNUNET_break (0); | 692 | GNUNET_break(0); |
703 | return -1; | 693 | return -1; |
704 | } | 694 | } |
705 | 695 | ||
706 | if ((GNUNET_YES == plugin->is_abstract) && | 696 | if ((GNUNET_YES == plugin->is_abstract) && |
707 | (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl (addr->options)))) | 697 | (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options)))) |
708 | { | 698 | { |
709 | un->sun_path[0] = '\0'; | 699 | un->sun_path[0] = '\0'; |
710 | } | 700 | } |
711 | resend: | 701 | resend: |
712 | /* Send the data */ | 702 | /* Send the data */ |
713 | sent = GNUNET_NETWORK_socket_sendto (send_handle, | 703 | sent = GNUNET_NETWORK_socket_sendto(send_handle, |
714 | msgbuf, | 704 | msgbuf, |
715 | msgbuf_size, | 705 | msgbuf_size, |
716 | (const struct sockaddr *) un, | 706 | (const struct sockaddr *)un, |
717 | un_len); | 707 | un_len); |
718 | if (GNUNET_SYSERR == sent) | 708 | if (GNUNET_SYSERR == sent) |
719 | { | ||
720 | if ((EAGAIN == errno) || (ENOBUFS == errno)) | ||
721 | { | 709 | { |
722 | GNUNET_free (un); | 710 | if ((EAGAIN == errno) || (ENOBUFS == errno)) |
723 | return RETRY; /* We have to retry later */ | ||
724 | } | ||
725 | if (EMSGSIZE == errno) | ||
726 | { | ||
727 | socklen_t size = 0; | ||
728 | socklen_t len = sizeof (size); | ||
729 | |||
730 | GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *) | ||
731 | send_handle, | ||
732 | SOL_SOCKET, | ||
733 | SO_SNDBUF, | ||
734 | &size, | ||
735 | &len); | ||
736 | if (size < msgbuf_size) | ||
737 | { | ||
738 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
739 | "Trying to increase socket buffer size from %u to %u for message size %u\n", | ||
740 | (unsigned int) size, | ||
741 | (unsigned int) ((msgbuf_size / 1000) + 2) * 1000, | ||
742 | (unsigned int) msgbuf_size); | ||
743 | size = ((msgbuf_size / 1000) + 2) * 1000; | ||
744 | if (GNUNET_OK == | ||
745 | GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) | ||
746 | send_handle, | ||
747 | SOL_SOCKET, | ||
748 | SO_SNDBUF, | ||
749 | &size, | ||
750 | sizeof (size))) | ||
751 | goto resend; /* Increased buffer size, retry sending */ | ||
752 | else | ||
753 | { | 711 | { |
754 | /* Could not increase buffer size: error, no retry */ | 712 | GNUNET_free(un); |
755 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt"); | 713 | return RETRY; /* We have to retry later */ |
756 | GNUNET_free (un); | 714 | } |
757 | return GNUNET_SYSERR; | 715 | if (EMSGSIZE == errno) |
716 | { | ||
717 | socklen_t size = 0; | ||
718 | socklen_t len = sizeof(size); | ||
719 | |||
720 | GNUNET_NETWORK_socket_getsockopt((struct GNUNET_NETWORK_Handle *) | ||
721 | send_handle, | ||
722 | SOL_SOCKET, | ||
723 | SO_SNDBUF, | ||
724 | &size, | ||
725 | &len); | ||
726 | if (size < msgbuf_size) | ||
727 | { | ||
728 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
729 | "Trying to increase socket buffer size from %u to %u for message size %u\n", | ||
730 | (unsigned int)size, | ||
731 | (unsigned int)((msgbuf_size / 1000) + 2) * 1000, | ||
732 | (unsigned int)msgbuf_size); | ||
733 | size = ((msgbuf_size / 1000) + 2) * 1000; | ||
734 | if (GNUNET_OK == | ||
735 | GNUNET_NETWORK_socket_setsockopt((struct GNUNET_NETWORK_Handle *) | ||
736 | send_handle, | ||
737 | SOL_SOCKET, | ||
738 | SO_SNDBUF, | ||
739 | &size, | ||
740 | sizeof(size))) | ||
741 | goto resend; /* Increased buffer size, retry sending */ | ||
742 | else | ||
743 | { | ||
744 | /* Could not increase buffer size: error, no retry */ | ||
745 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt"); | ||
746 | GNUNET_free(un); | ||
747 | return GNUNET_SYSERR; | ||
748 | } | ||
749 | } | ||
750 | else | ||
751 | { | ||
752 | /* Buffer is bigger than message: error, no retry | ||
753 | * This should never happen!*/ | ||
754 | GNUNET_break(0); | ||
755 | GNUNET_free(un); | ||
756 | return GNUNET_SYSERR; | ||
757 | } | ||
758 | } | 758 | } |
759 | } | ||
760 | else | ||
761 | { | ||
762 | /* Buffer is bigger than message: error, no retry | ||
763 | * This should never happen!*/ | ||
764 | GNUNET_break (0); | ||
765 | GNUNET_free (un); | ||
766 | return GNUNET_SYSERR; | ||
767 | } | ||
768 | } | 759 | } |
769 | } | 760 | |
770 | 761 | LOG(GNUNET_ERROR_TYPE_DEBUG, | |
771 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 762 | "UNIX transmitted %u-byte message to %s (%d: %s)\n", |
772 | "UNIX transmitted %u-byte message to %s (%d: %s)\n", | 763 | (unsigned int)msgbuf_size, |
773 | (unsigned int) msgbuf_size, | 764 | GNUNET_a2s((const struct sockaddr *)un, un_len), |
774 | GNUNET_a2s ((const struct sockaddr *) un, un_len), | 765 | (int)sent, |
775 | (int) sent, | 766 | (sent < 0) ? strerror(errno) : "ok"); |
776 | (sent < 0) ? strerror (errno) : "ok"); | 767 | GNUNET_free(un); |
777 | GNUNET_free (un); | ||
778 | return sent; | 768 | return sent; |
779 | } | 769 | } |
780 | 770 | ||
@@ -787,9 +777,9 @@ resend: | |||
787 | * @return the network type in HBO or #GNUNET_SYSERR | 777 | * @return the network type in HBO or #GNUNET_SYSERR |
788 | */ | 778 | */ |
789 | static enum GNUNET_NetworkType | 779 | static enum GNUNET_NetworkType |
790 | unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) | 780 | unix_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) |
791 | { | 781 | { |
792 | GNUNET_assert (NULL != session); | 782 | GNUNET_assert(NULL != session); |
793 | return GNUNET_NT_LOOPBACK; | 783 | return GNUNET_NT_LOOPBACK; |
794 | } | 784 | } |
795 | 785 | ||
@@ -802,9 +792,8 @@ unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) | |||
802 | * @return the network type | 792 | * @return the network type |
803 | */ | 793 | */ |
804 | static enum GNUNET_NetworkType | 794 | static enum GNUNET_NetworkType |
805 | unix_plugin_get_network_for_address (void *cls, | 795 | unix_plugin_get_network_for_address(void *cls, |
806 | const struct GNUNET_HELLO_Address *address) | 796 | const struct GNUNET_HELLO_Address *address) |
807 | |||
808 | { | 797 | { |
809 | return GNUNET_NT_LOOPBACK; | 798 | return GNUNET_NT_LOOPBACK; |
810 | } | 799 | } |
@@ -819,7 +808,7 @@ unix_plugin_get_network_for_address (void *cls, | |||
819 | * @return the session or NULL of max connections exceeded | 808 | * @return the session or NULL of max connections exceeded |
820 | */ | 809 | */ |
821 | static struct GNUNET_ATS_Session * | 810 | static struct GNUNET_ATS_Session * |
822 | unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) | 811 | unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) |
823 | { | 812 | { |
824 | struct Plugin *plugin = cls; | 813 | struct Plugin *plugin = cls; |
825 | struct GNUNET_ATS_Session *session; | 814 | struct GNUNET_ATS_Session *session; |
@@ -828,80 +817,80 @@ unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) | |||
828 | uint32_t addr_str_len; | 817 | uint32_t addr_str_len; |
829 | uint32_t addr_option; | 818 | uint32_t addr_option; |
830 | 819 | ||
831 | ua = (struct UnixAddress *) address->address; | 820 | ua = (struct UnixAddress *)address->address; |
832 | if ((NULL == address->address) || (0 == address->address_length) || | 821 | if ((NULL == address->address) || (0 == address->address_length) || |
833 | (sizeof (struct UnixAddress) > address->address_length)) | 822 | (sizeof(struct UnixAddress) > address->address_length)) |
834 | { | 823 | { |
835 | GNUNET_break (0); | 824 | GNUNET_break(0); |
836 | return NULL; | 825 | return NULL; |
837 | } | 826 | } |
838 | addrstr = (char *) &ua[1]; | 827 | addrstr = (char *)&ua[1]; |
839 | addr_str_len = ntohl (ua->addrlen); | 828 | addr_str_len = ntohl(ua->addrlen); |
840 | addr_option = ntohl (ua->options); | 829 | addr_option = ntohl(ua->options); |
841 | 830 | ||
842 | if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && | 831 | if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && |
843 | (GNUNET_NO == plugin->is_abstract)) | 832 | (GNUNET_NO == plugin->is_abstract)) |
844 | { | 833 | { |
845 | return NULL; | 834 | return NULL; |
846 | } | 835 | } |
847 | 836 | ||
848 | if (addr_str_len != address->address_length - sizeof (struct UnixAddress)) | 837 | if (addr_str_len != address->address_length - sizeof(struct UnixAddress)) |
849 | { | 838 | { |
850 | return NULL; /* This can be a legacy address */ | 839 | return NULL; /* This can be a legacy address */ |
851 | } | 840 | } |
852 | 841 | ||
853 | if ('\0' != addrstr[addr_str_len - 1]) | 842 | if ('\0' != addrstr[addr_str_len - 1]) |
854 | { | 843 | { |
855 | GNUNET_break (0); | 844 | GNUNET_break(0); |
856 | return NULL; | 845 | return NULL; |
857 | } | 846 | } |
858 | if (strlen (addrstr) + 1 != addr_str_len) | 847 | if (strlen(addrstr) + 1 != addr_str_len) |
859 | { | 848 | { |
860 | GNUNET_break (0); | 849 | GNUNET_break(0); |
861 | return NULL; | 850 | return NULL; |
862 | } | 851 | } |
863 | 852 | ||
864 | /* Check if a session for this address already exists */ | 853 | /* Check if a session for this address already exists */ |
865 | if (NULL != (session = lookup_session (plugin, address))) | 854 | if (NULL != (session = lookup_session(plugin, address))) |
866 | { | 855 | { |
867 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 856 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
868 | "Found existing session %p for address `%s'\n", | 857 | "Found existing session %p for address `%s'\n", |
869 | session, | 858 | session, |
870 | unix_plugin_address_to_string (NULL, | 859 | unix_plugin_address_to_string(NULL, |
871 | address->address, | 860 | address->address, |
872 | address->address_length)); | 861 | address->address_length)); |
873 | return session; | 862 | return session; |
874 | } | 863 | } |
875 | 864 | ||
876 | /* create a new session */ | 865 | /* create a new session */ |
877 | session = GNUNET_new (struct GNUNET_ATS_Session); | 866 | session = GNUNET_new(struct GNUNET_ATS_Session); |
878 | session->target = address->peer; | 867 | session->target = address->peer; |
879 | session->address = GNUNET_HELLO_address_copy (address); | 868 | session->address = GNUNET_HELLO_address_copy(address); |
880 | session->plugin = plugin; | 869 | session->plugin = plugin; |
881 | session->timeout = | 870 | session->timeout = |
882 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 871 | GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
883 | session->timeout_task = | 872 | session->timeout_task = |
884 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 873 | GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
885 | &session_timeout, | 874 | &session_timeout, |
886 | session); | 875 | session); |
887 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 876 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
888 | "Creating a new session %p for address `%s'\n", | 877 | "Creating a new session %p for address `%s'\n", |
889 | session, | 878 | session, |
890 | unix_plugin_address_to_string (NULL, | 879 | unix_plugin_address_to_string(NULL, |
891 | address->address, | 880 | address->address, |
892 | address->address_length)); | 881 | address->address_length)); |
893 | (void) GNUNET_CONTAINER_multipeermap_put ( | 882 | (void)GNUNET_CONTAINER_multipeermap_put( |
894 | plugin->session_map, | 883 | plugin->session_map, |
895 | &address->peer, | 884 | &address->peer, |
896 | session, | 885 | session, |
897 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 886 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
898 | GNUNET_STATISTICS_set (plugin->env->stats, | 887 | GNUNET_STATISTICS_set(plugin->env->stats, |
899 | "# UNIX sessions active", | 888 | "# UNIX sessions active", |
900 | GNUNET_CONTAINER_multipeermap_size ( | 889 | GNUNET_CONTAINER_multipeermap_size( |
901 | plugin->session_map), | 890 | plugin->session_map), |
902 | GNUNET_NO); | 891 | GNUNET_NO); |
903 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); | 892 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); |
904 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); | 893 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); |
905 | return session; | 894 | return session; |
906 | } | 895 | } |
907 | 896 | ||
@@ -916,21 +905,21 @@ unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) | |||
916 | * @param session which session is being updated | 905 | * @param session which session is being updated |
917 | */ | 906 | */ |
918 | static void | 907 | static void |
919 | unix_plugin_update_session_timeout (void *cls, | 908 | unix_plugin_update_session_timeout(void *cls, |
920 | const struct GNUNET_PeerIdentity *peer, | 909 | const struct GNUNET_PeerIdentity *peer, |
921 | struct GNUNET_ATS_Session *session) | 910 | struct GNUNET_ATS_Session *session) |
922 | { | 911 | { |
923 | struct Plugin *plugin = cls; | 912 | struct Plugin *plugin = cls; |
924 | 913 | ||
925 | if (GNUNET_OK != | 914 | if (GNUNET_OK != |
926 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, | 915 | GNUNET_CONTAINER_multipeermap_contains_value(plugin->session_map, |
927 | &session->target, | 916 | &session->target, |
928 | session)) | 917 | session)) |
929 | { | 918 | { |
930 | GNUNET_break (0); | 919 | GNUNET_break(0); |
931 | return; | 920 | return; |
932 | } | 921 | } |
933 | reschedule_session_timeout (session); | 922 | reschedule_session_timeout(session); |
934 | } | 923 | } |
935 | 924 | ||
936 | 925 | ||
@@ -944,47 +933,47 @@ unix_plugin_update_session_timeout (void *cls, | |||
944 | * @param ua_len length of the address @a ua | 933 | * @param ua_len length of the address @a ua |
945 | */ | 934 | */ |
946 | static void | 935 | static void |
947 | unix_demultiplexer (struct Plugin *plugin, | 936 | unix_demultiplexer(struct Plugin *plugin, |
948 | struct GNUNET_PeerIdentity *sender, | 937 | struct GNUNET_PeerIdentity *sender, |
949 | const struct GNUNET_MessageHeader *currhdr, | 938 | const struct GNUNET_MessageHeader *currhdr, |
950 | const struct UnixAddress *ua, | 939 | const struct UnixAddress *ua, |
951 | size_t ua_len) | 940 | size_t ua_len) |
952 | { | 941 | { |
953 | struct GNUNET_ATS_Session *session; | 942 | struct GNUNET_ATS_Session *session; |
954 | struct GNUNET_HELLO_Address *address; | 943 | struct GNUNET_HELLO_Address *address; |
955 | 944 | ||
956 | GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); | 945 | GNUNET_assert(ua_len >= sizeof(struct UnixAddress)); |
957 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 946 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
958 | "Received message from %s\n", | 947 | "Received message from %s\n", |
959 | unix_plugin_address_to_string (NULL, ua, ua_len)); | 948 | unix_plugin_address_to_string(NULL, ua, ua_len)); |
960 | GNUNET_STATISTICS_update (plugin->env->stats, | 949 | GNUNET_STATISTICS_update(plugin->env->stats, |
961 | "# bytes received via UNIX", | 950 | "# bytes received via UNIX", |
962 | ntohs (currhdr->size), | 951 | ntohs(currhdr->size), |
963 | GNUNET_NO); | 952 | GNUNET_NO); |
964 | 953 | ||
965 | /* Look for existing session */ | 954 | /* Look for existing session */ |
966 | address = GNUNET_HELLO_address_allocate ( | 955 | address = GNUNET_HELLO_address_allocate( |
967 | sender, | 956 | sender, |
968 | PLUGIN_NAME, | 957 | PLUGIN_NAME, |
969 | ua, | 958 | ua, |
970 | ua_len, | 959 | ua_len, |
971 | GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ | 960 | GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ |
972 | session = lookup_session (plugin, address); | 961 | session = lookup_session(plugin, address); |
973 | if (NULL == session) | 962 | if (NULL == session) |
974 | { | 963 | { |
975 | session = unix_plugin_get_session (plugin, address); | 964 | session = unix_plugin_get_session(plugin, address); |
976 | /* Notify transport and ATS about new inbound session */ | 965 | /* Notify transport and ATS about new inbound session */ |
977 | plugin->env->session_start (NULL, | 966 | plugin->env->session_start(NULL, |
978 | session->address, | 967 | session->address, |
979 | session, | 968 | session, |
980 | GNUNET_NT_LOOPBACK); | 969 | GNUNET_NT_LOOPBACK); |
981 | } | 970 | } |
982 | else | 971 | else |
983 | { | 972 | { |
984 | reschedule_session_timeout (session); | 973 | reschedule_session_timeout(session); |
985 | } | 974 | } |
986 | GNUNET_HELLO_address_free (address); | 975 | GNUNET_HELLO_address_free(address); |
987 | plugin->env->receive (plugin->env->cls, session->address, session, currhdr); | 976 | plugin->env->receive(plugin->env->cls, session->address, session, currhdr); |
988 | } | 977 | } |
989 | 978 | ||
990 | 979 | ||
@@ -994,7 +983,7 @@ unix_demultiplexer (struct Plugin *plugin, | |||
994 | * @param plugin the plugin | 983 | * @param plugin the plugin |
995 | */ | 984 | */ |
996 | static void | 985 | static void |
997 | unix_plugin_do_read (struct Plugin *plugin) | 986 | unix_plugin_do_read(struct Plugin *plugin) |
998 | { | 987 | { |
999 | char buf[65536] GNUNET_ALIGN; | 988 | char buf[65536] GNUNET_ALIGN; |
1000 | struct UnixAddress *ua; | 989 | struct UnixAddress *ua; |
@@ -1011,71 +1000,71 @@ unix_plugin_do_read (struct Plugin *plugin) | |||
1011 | uint16_t csize; | 1000 | uint16_t csize; |
1012 | size_t ua_len; | 1001 | size_t ua_len; |
1013 | 1002 | ||
1014 | addrlen = sizeof (un); | 1003 | addrlen = sizeof(un); |
1015 | memset (&un, 0, sizeof (un)); | 1004 | memset(&un, 0, sizeof(un)); |
1016 | ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, | 1005 | ret = GNUNET_NETWORK_socket_recvfrom(plugin->unix_sock.desc, |
1017 | buf, | 1006 | buf, |
1018 | sizeof (buf), | 1007 | sizeof(buf), |
1019 | (struct sockaddr *) &un, | 1008 | (struct sockaddr *)&un, |
1020 | &addrlen); | 1009 | &addrlen); |
1021 | if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) | 1010 | if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) |
1022 | return; | 1011 | return; |
1023 | if (GNUNET_SYSERR == ret) | 1012 | if (GNUNET_SYSERR == ret) |
1024 | { | 1013 | { |
1025 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); | 1014 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom"); |
1026 | return; | 1015 | return; |
1027 | } | 1016 | } |
1028 | else | 1017 | else |
1029 | { | 1018 | { |
1030 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1019 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1031 | "Read %d bytes from socket %s\n", | 1020 | "Read %d bytes from socket %s\n", |
1032 | (int) ret, | 1021 | (int)ret, |
1033 | un.sun_path); | 1022 | un.sun_path); |
1034 | } | 1023 | } |
1035 | 1024 | ||
1036 | GNUNET_assert (AF_UNIX == (un.sun_family)); | 1025 | GNUNET_assert(AF_UNIX == (un.sun_family)); |
1037 | is_abstract = GNUNET_NO; | 1026 | is_abstract = GNUNET_NO; |
1038 | if ('\0' == un.sun_path[0]) | 1027 | if ('\0' == un.sun_path[0]) |
1039 | { | 1028 | { |
1040 | un.sun_path[0] = '@'; | 1029 | un.sun_path[0] = '@'; |
1041 | is_abstract = GNUNET_YES; | 1030 | is_abstract = GNUNET_YES; |
1042 | } | 1031 | } |
1043 | 1032 | ||
1044 | ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1; | 1033 | ua_len = sizeof(struct UnixAddress) + strlen(un.sun_path) + 1; |
1045 | ua = GNUNET_malloc (ua_len); | 1034 | ua = GNUNET_malloc(ua_len); |
1046 | ua->addrlen = htonl (strlen (&un.sun_path[0]) + 1); | 1035 | ua->addrlen = htonl(strlen(&un.sun_path[0]) + 1); |
1047 | GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); | 1036 | GNUNET_memcpy(&ua[1], &un.sun_path[0], strlen(un.sun_path) + 1); |
1048 | if (is_abstract) | 1037 | if (is_abstract) |
1049 | ua->options = htonl (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); | 1038 | ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); |
1050 | else | 1039 | else |
1051 | ua->options = htonl (UNIX_OPTIONS_NONE); | 1040 | ua->options = htonl(UNIX_OPTIONS_NONE); |
1052 | 1041 | ||
1053 | msg = (struct UNIXMessage *) buf; | 1042 | msg = (struct UNIXMessage *)buf; |
1054 | csize = ntohs (msg->header.size); | 1043 | csize = ntohs(msg->header.size); |
1055 | if ((csize < sizeof (struct UNIXMessage)) || (csize > ret)) | 1044 | if ((csize < sizeof(struct UNIXMessage)) || (csize > ret)) |
1056 | { | 1045 | { |
1057 | GNUNET_break_op (0); | 1046 | GNUNET_break_op(0); |
1058 | GNUNET_free (ua); | 1047 | GNUNET_free(ua); |
1059 | return; | 1048 | return; |
1060 | } | 1049 | } |
1061 | msgbuf = (char *) &msg[1]; | 1050 | msgbuf = (char *)&msg[1]; |
1062 | GNUNET_memcpy (&sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); | 1051 | GNUNET_memcpy(&sender, &msg->sender, sizeof(struct GNUNET_PeerIdentity)); |
1063 | offset = 0; | 1052 | offset = 0; |
1064 | tsize = csize - sizeof (struct UNIXMessage); | 1053 | tsize = csize - sizeof(struct UNIXMessage); |
1065 | while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) | 1054 | while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize) |
1066 | { | ||
1067 | currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset]; | ||
1068 | csize = ntohs (currhdr->size); | ||
1069 | if ((csize < sizeof (struct GNUNET_MessageHeader)) || | ||
1070 | (csize > tsize - offset)) | ||
1071 | { | 1055 | { |
1072 | GNUNET_break_op (0); | 1056 | currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset]; |
1073 | break; | 1057 | csize = ntohs(currhdr->size); |
1058 | if ((csize < sizeof(struct GNUNET_MessageHeader)) || | ||
1059 | (csize > tsize - offset)) | ||
1060 | { | ||
1061 | GNUNET_break_op(0); | ||
1062 | break; | ||
1063 | } | ||
1064 | unix_demultiplexer(plugin, &sender, currhdr, ua, ua_len); | ||
1065 | offset += csize; | ||
1074 | } | 1066 | } |
1075 | unix_demultiplexer (plugin, &sender, currhdr, ua, ua_len); | 1067 | GNUNET_free(ua); |
1076 | offset += csize; | ||
1077 | } | ||
1078 | GNUNET_free (ua); | ||
1079 | } | 1068 | } |
1080 | 1069 | ||
1081 | 1070 | ||
@@ -1085,7 +1074,7 @@ unix_plugin_do_read (struct Plugin *plugin) | |||
1085 | * @param plugin handle to the plugin | 1074 | * @param plugin handle to the plugin |
1086 | */ | 1075 | */ |
1087 | static void | 1076 | static void |
1088 | unix_plugin_do_write (struct Plugin *plugin) | 1077 | unix_plugin_do_write(struct Plugin *plugin) |
1089 | { | 1078 | { |
1090 | ssize_t sent = 0; | 1079 | ssize_t sent = 0; |
1091 | struct UNIXMessageWrapper *msgw; | 1080 | struct UNIXMessageWrapper *msgw; |
@@ -1095,108 +1084,108 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1095 | session = NULL; | 1084 | session = NULL; |
1096 | did_delete = GNUNET_NO; | 1085 | did_delete = GNUNET_NO; |
1097 | while (NULL != (msgw = plugin->msg_head)) | 1086 | while (NULL != (msgw = plugin->msg_head)) |
1098 | { | 1087 | { |
1099 | if (GNUNET_TIME_absolute_get_remaining (msgw->timeout).rel_value_us > 0) | 1088 | if (GNUNET_TIME_absolute_get_remaining(msgw->timeout).rel_value_us > 0) |
1100 | break; /* Message is ready for sending */ | 1089 | break; /* Message is ready for sending */ |
1101 | /* Message has a timeout */ | 1090 | /* Message has a timeout */ |
1102 | did_delete = GNUNET_YES; | 1091 | did_delete = GNUNET_YES; |
1103 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1092 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1104 | "Timeout for message with %u bytes \n", | 1093 | "Timeout for message with %u bytes \n", |
1105 | (unsigned int) msgw->msgsize); | 1094 | (unsigned int)msgw->msgsize); |
1106 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); | 1095 | GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); |
1107 | session = msgw->session; | 1096 | session = msgw->session; |
1108 | session->msgs_in_queue--; | 1097 | session->msgs_in_queue--; |
1109 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 1098 | GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); |
1110 | session->bytes_in_queue -= msgw->msgsize; | 1099 | session->bytes_in_queue -= msgw->msgsize; |
1111 | GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); | 1100 | GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); |
1112 | plugin->bytes_in_queue -= msgw->msgsize; | 1101 | plugin->bytes_in_queue -= msgw->msgsize; |
1113 | GNUNET_STATISTICS_set (plugin->env->stats, | 1102 | GNUNET_STATISTICS_set(plugin->env->stats, |
1114 | "# bytes currently in UNIX buffers", | 1103 | "# bytes currently in UNIX buffers", |
1115 | plugin->bytes_in_queue, | 1104 | plugin->bytes_in_queue, |
1116 | GNUNET_NO); | 1105 | GNUNET_NO); |
1117 | GNUNET_STATISTICS_update (plugin->env->stats, | 1106 | GNUNET_STATISTICS_update(plugin->env->stats, |
1118 | "# UNIX bytes discarded", | 1107 | "# UNIX bytes discarded", |
1119 | msgw->msgsize, | 1108 | msgw->msgsize, |
1120 | GNUNET_NO); | 1109 | GNUNET_NO); |
1121 | if (NULL != msgw->cont) | 1110 | if (NULL != msgw->cont) |
1122 | msgw->cont (msgw->cont_cls, | 1111 | msgw->cont(msgw->cont_cls, |
1123 | &msgw->session->target, | 1112 | &msgw->session->target, |
1124 | GNUNET_SYSERR, | 1113 | GNUNET_SYSERR, |
1125 | msgw->payload, | 1114 | msgw->payload, |
1126 | 0); | 1115 | 0); |
1127 | GNUNET_free (msgw->msg); | 1116 | GNUNET_free(msgw->msg); |
1128 | GNUNET_free (msgw); | 1117 | GNUNET_free(msgw); |
1129 | } | 1118 | } |
1130 | if (NULL == msgw) | 1119 | if (NULL == msgw) |
1131 | { | 1120 | { |
1132 | if (GNUNET_YES == did_delete) | 1121 | if (GNUNET_YES == did_delete) |
1133 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); | 1122 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1134 | return; /* Nothing to send at the moment */ | 1123 | return; /* Nothing to send at the moment */ |
1135 | } | 1124 | } |
1136 | session = msgw->session; | 1125 | session = msgw->session; |
1137 | sent = unix_real_send (plugin, | 1126 | sent = unix_real_send(plugin, |
1138 | plugin->unix_sock.desc, | 1127 | plugin->unix_sock.desc, |
1139 | &session->target, | 1128 | &session->target, |
1140 | (const char *) msgw->msg, | 1129 | (const char *)msgw->msg, |
1141 | msgw->msgsize, | 1130 | msgw->msgsize, |
1142 | msgw->priority, | 1131 | msgw->priority, |
1143 | msgw->timeout, | 1132 | msgw->timeout, |
1144 | msgw->session->address->address, | 1133 | msgw->session->address->address, |
1145 | msgw->session->address->address_length, | 1134 | msgw->session->address->address_length, |
1146 | msgw->payload, | 1135 | msgw->payload, |
1147 | msgw->cont, | 1136 | msgw->cont, |
1148 | msgw->cont_cls); | 1137 | msgw->cont_cls); |
1149 | if (RETRY == sent) | 1138 | if (RETRY == sent) |
1150 | { | 1139 | { |
1151 | GNUNET_STATISTICS_update (plugin->env->stats, | 1140 | GNUNET_STATISTICS_update(plugin->env->stats, |
1152 | "# UNIX retry attempts", | 1141 | "# UNIX retry attempts", |
1153 | 1, | 1142 | 1, |
1154 | GNUNET_NO); | 1143 | GNUNET_NO); |
1155 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); | 1144 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1156 | return; | 1145 | return; |
1157 | } | 1146 | } |
1158 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); | 1147 | GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); |
1159 | session->msgs_in_queue--; | 1148 | session->msgs_in_queue--; |
1160 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 1149 | GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); |
1161 | session->bytes_in_queue -= msgw->msgsize; | 1150 | session->bytes_in_queue -= msgw->msgsize; |
1162 | GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); | 1151 | GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); |
1163 | plugin->bytes_in_queue -= msgw->msgsize; | 1152 | plugin->bytes_in_queue -= msgw->msgsize; |
1164 | GNUNET_STATISTICS_set (plugin->env->stats, | 1153 | GNUNET_STATISTICS_set(plugin->env->stats, |
1165 | "# bytes currently in UNIX buffers", | 1154 | "# bytes currently in UNIX buffers", |
1166 | plugin->bytes_in_queue, | 1155 | plugin->bytes_in_queue, |
1167 | GNUNET_NO); | 1156 | GNUNET_NO); |
1168 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); | 1157 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1169 | if (GNUNET_SYSERR == sent) | 1158 | if (GNUNET_SYSERR == sent) |
1170 | { | 1159 | { |
1171 | /* failed and no retry */ | 1160 | /* failed and no retry */ |
1172 | if (NULL != msgw->cont) | 1161 | if (NULL != msgw->cont) |
1173 | msgw->cont (msgw->cont_cls, | 1162 | msgw->cont(msgw->cont_cls, |
1174 | &msgw->session->target, | 1163 | &msgw->session->target, |
1175 | GNUNET_SYSERR, | 1164 | GNUNET_SYSERR, |
1176 | msgw->payload, | 1165 | msgw->payload, |
1177 | 0); | 1166 | 0); |
1178 | GNUNET_STATISTICS_update (plugin->env->stats, | 1167 | GNUNET_STATISTICS_update(plugin->env->stats, |
1179 | "# UNIX bytes discarded", | 1168 | "# UNIX bytes discarded", |
1180 | msgw->msgsize, | 1169 | msgw->msgsize, |
1181 | GNUNET_NO); | 1170 | GNUNET_NO); |
1182 | GNUNET_free (msgw->msg); | 1171 | GNUNET_free(msgw->msg); |
1183 | GNUNET_free (msgw); | 1172 | GNUNET_free(msgw); |
1184 | return; | 1173 | return; |
1185 | } | 1174 | } |
1186 | /* successfully sent bytes */ | 1175 | /* successfully sent bytes */ |
1187 | GNUNET_break (sent > 0); | 1176 | GNUNET_break(sent > 0); |
1188 | GNUNET_STATISTICS_update (plugin->env->stats, | 1177 | GNUNET_STATISTICS_update(plugin->env->stats, |
1189 | "# bytes transmitted via UNIX", | 1178 | "# bytes transmitted via UNIX", |
1190 | msgw->msgsize, | 1179 | msgw->msgsize, |
1191 | GNUNET_NO); | 1180 | GNUNET_NO); |
1192 | if (NULL != msgw->cont) | 1181 | if (NULL != msgw->cont) |
1193 | msgw->cont (msgw->cont_cls, | 1182 | msgw->cont(msgw->cont_cls, |
1194 | &msgw->session->target, | 1183 | &msgw->session->target, |
1195 | GNUNET_OK, | 1184 | GNUNET_OK, |
1196 | msgw->payload, | 1185 | msgw->payload, |
1197 | msgw->msgsize); | 1186 | msgw->msgsize); |
1198 | GNUNET_free (msgw->msg); | 1187 | GNUNET_free(msgw->msg); |
1199 | GNUNET_free (msgw); | 1188 | GNUNET_free(msgw); |
1200 | } | 1189 | } |
1201 | 1190 | ||
1202 | 1191 | ||
@@ -1207,20 +1196,20 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1207 | * @param cls the plugin handle | 1196 | * @param cls the plugin handle |
1208 | */ | 1197 | */ |
1209 | static void | 1198 | static void |
1210 | unix_plugin_select_read (void *cls) | 1199 | unix_plugin_select_read(void *cls) |
1211 | { | 1200 | { |
1212 | struct Plugin *plugin = cls; | 1201 | struct Plugin *plugin = cls; |
1213 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 1202 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
1214 | 1203 | ||
1215 | plugin->read_task = NULL; | 1204 | plugin->read_task = NULL; |
1216 | tc = GNUNET_SCHEDULER_get_task_context (); | 1205 | tc = GNUNET_SCHEDULER_get_task_context(); |
1217 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) | 1206 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) |
1218 | unix_plugin_do_read (plugin); | 1207 | unix_plugin_do_read(plugin); |
1219 | plugin->read_task = | 1208 | plugin->read_task = |
1220 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1209 | GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
1221 | plugin->unix_sock.desc, | 1210 | plugin->unix_sock.desc, |
1222 | &unix_plugin_select_read, | 1211 | &unix_plugin_select_read, |
1223 | plugin); | 1212 | plugin); |
1224 | } | 1213 | } |
1225 | 1214 | ||
1226 | 1215 | ||
@@ -1231,22 +1220,22 @@ unix_plugin_select_read (void *cls) | |||
1231 | * @param cls the plugin handle | 1220 | * @param cls the plugin handle |
1232 | */ | 1221 | */ |
1233 | static void | 1222 | static void |
1234 | unix_plugin_select_write (void *cls) | 1223 | unix_plugin_select_write(void *cls) |
1235 | { | 1224 | { |
1236 | struct Plugin *plugin = cls; | 1225 | struct Plugin *plugin = cls; |
1237 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 1226 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
1238 | 1227 | ||
1239 | plugin->write_task = NULL; | 1228 | plugin->write_task = NULL; |
1240 | tc = GNUNET_SCHEDULER_get_task_context (); | 1229 | tc = GNUNET_SCHEDULER_get_task_context(); |
1241 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) | 1230 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) |
1242 | unix_plugin_do_write (plugin); | 1231 | unix_plugin_do_write(plugin); |
1243 | if (NULL == plugin->msg_head) | 1232 | if (NULL == plugin->msg_head) |
1244 | return; /* write queue empty */ | 1233 | return; /* write queue empty */ |
1245 | plugin->write_task = | 1234 | plugin->write_task = |
1246 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1235 | GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, |
1247 | plugin->unix_sock.desc, | 1236 | plugin->unix_sock.desc, |
1248 | &unix_plugin_select_write, | 1237 | &unix_plugin_select_write, |
1249 | plugin); | 1238 | plugin); |
1250 | } | 1239 | } |
1251 | 1240 | ||
1252 | 1241 | ||
@@ -1278,14 +1267,14 @@ unix_plugin_select_write (void *cls) | |||
1278 | * and does NOT mean that the message was not transmitted (DV) | 1267 | * and does NOT mean that the message was not transmitted (DV) |
1279 | */ | 1268 | */ |
1280 | static ssize_t | 1269 | static ssize_t |
1281 | unix_plugin_send (void *cls, | 1270 | unix_plugin_send(void *cls, |
1282 | struct GNUNET_ATS_Session *session, | 1271 | struct GNUNET_ATS_Session *session, |
1283 | const char *msgbuf, | 1272 | const char *msgbuf, |
1284 | size_t msgbuf_size, | 1273 | size_t msgbuf_size, |
1285 | unsigned int priority, | 1274 | unsigned int priority, |
1286 | struct GNUNET_TIME_Relative to, | 1275 | struct GNUNET_TIME_Relative to, |
1287 | GNUNET_TRANSPORT_TransmitContinuation cont, | 1276 | GNUNET_TRANSPORT_TransmitContinuation cont, |
1288 | void *cont_cls) | 1277 | void *cont_cls) |
1289 | { | 1278 | { |
1290 | struct Plugin *plugin = cls; | 1279 | struct Plugin *plugin = cls; |
1291 | struct UNIXMessageWrapper *wrapper; | 1280 | struct UNIXMessageWrapper *wrapper; |
@@ -1293,60 +1282,60 @@ unix_plugin_send (void *cls, | |||
1293 | int ssize; | 1282 | int ssize; |
1294 | 1283 | ||
1295 | if (GNUNET_OK != | 1284 | if (GNUNET_OK != |
1296 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, | 1285 | GNUNET_CONTAINER_multipeermap_contains_value(plugin->session_map, |
1297 | &session->target, | 1286 | &session->target, |
1298 | session)) | 1287 | session)) |
1299 | { | 1288 | { |
1300 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1289 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1301 | "Invalid session for peer `%s' `%s'\n", | 1290 | "Invalid session for peer `%s' `%s'\n", |
1302 | GNUNET_i2s (&session->target), | 1291 | GNUNET_i2s(&session->target), |
1303 | unix_plugin_address_to_string (NULL, | 1292 | unix_plugin_address_to_string(NULL, |
1304 | session->address->address, | 1293 | session->address->address, |
1305 | session->address->address_length)); | 1294 | session->address->address_length)); |
1306 | GNUNET_break (0); | 1295 | GNUNET_break(0); |
1307 | return GNUNET_SYSERR; | 1296 | return GNUNET_SYSERR; |
1308 | } | 1297 | } |
1309 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1298 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1310 | "Sending %u bytes with session for peer `%s' `%s'\n", | 1299 | "Sending %u bytes with session for peer `%s' `%s'\n", |
1311 | msgbuf_size, | 1300 | msgbuf_size, |
1312 | GNUNET_i2s (&session->target), | 1301 | GNUNET_i2s(&session->target), |
1313 | unix_plugin_address_to_string (NULL, | 1302 | unix_plugin_address_to_string(NULL, |
1314 | session->address->address, | 1303 | session->address->address, |
1315 | session->address->address_length)); | 1304 | session->address->address_length)); |
1316 | ssize = sizeof (struct UNIXMessage) + msgbuf_size; | 1305 | ssize = sizeof(struct UNIXMessage) + msgbuf_size; |
1317 | message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); | 1306 | message = GNUNET_malloc(sizeof(struct UNIXMessage) + msgbuf_size); |
1318 | message->header.size = htons (ssize); | 1307 | message->header.size = htons(ssize); |
1319 | message->header.type = htons (0); | 1308 | message->header.type = htons(0); |
1320 | GNUNET_memcpy (&message->sender, | 1309 | GNUNET_memcpy(&message->sender, |
1321 | plugin->env->my_identity, | 1310 | plugin->env->my_identity, |
1322 | sizeof (struct GNUNET_PeerIdentity)); | 1311 | sizeof(struct GNUNET_PeerIdentity)); |
1323 | GNUNET_memcpy (&message[1], msgbuf, msgbuf_size); | 1312 | GNUNET_memcpy(&message[1], msgbuf, msgbuf_size); |
1324 | wrapper = GNUNET_new (struct UNIXMessageWrapper); | 1313 | wrapper = GNUNET_new(struct UNIXMessageWrapper); |
1325 | wrapper->msg = message; | 1314 | wrapper->msg = message; |
1326 | wrapper->msgsize = ssize; | 1315 | wrapper->msgsize = ssize; |
1327 | wrapper->payload = msgbuf_size; | 1316 | wrapper->payload = msgbuf_size; |
1328 | wrapper->priority = priority; | 1317 | wrapper->priority = priority; |
1329 | wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to); | 1318 | wrapper->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); |
1330 | wrapper->cont = cont; | 1319 | wrapper->cont = cont; |
1331 | wrapper->cont_cls = cont_cls; | 1320 | wrapper->cont_cls = cont_cls; |
1332 | wrapper->session = session; | 1321 | wrapper->session = session; |
1333 | GNUNET_CONTAINER_DLL_insert_tail (plugin->msg_head, | 1322 | GNUNET_CONTAINER_DLL_insert_tail(plugin->msg_head, |
1334 | plugin->msg_tail, | 1323 | plugin->msg_tail, |
1335 | wrapper); | 1324 | wrapper); |
1336 | plugin->bytes_in_queue += ssize; | 1325 | plugin->bytes_in_queue += ssize; |
1337 | session->bytes_in_queue += ssize; | 1326 | session->bytes_in_queue += ssize; |
1338 | session->msgs_in_queue++; | 1327 | session->msgs_in_queue++; |
1339 | GNUNET_STATISTICS_set (plugin->env->stats, | 1328 | GNUNET_STATISTICS_set(plugin->env->stats, |
1340 | "# bytes currently in UNIX buffers", | 1329 | "# bytes currently in UNIX buffers", |
1341 | plugin->bytes_in_queue, | 1330 | plugin->bytes_in_queue, |
1342 | GNUNET_NO); | 1331 | GNUNET_NO); |
1343 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); | 1332 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1344 | if (NULL == plugin->write_task) | 1333 | if (NULL == plugin->write_task) |
1345 | plugin->write_task = | 1334 | plugin->write_task = |
1346 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1335 | GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, |
1347 | plugin->unix_sock.desc, | 1336 | plugin->unix_sock.desc, |
1348 | &unix_plugin_select_write, | 1337 | &unix_plugin_select_write, |
1349 | plugin); | 1338 | plugin); |
1350 | return ssize; | 1339 | return ssize; |
1351 | } | 1340 | } |
1352 | 1341 | ||
@@ -1358,57 +1347,57 @@ unix_plugin_send (void *cls, | |||
1358 | * @return number of sockets created or #GNUNET_SYSERR on error | 1347 | * @return number of sockets created or #GNUNET_SYSERR on error |
1359 | */ | 1348 | */ |
1360 | static int | 1349 | static int |
1361 | unix_transport_server_start (void *cls) | 1350 | unix_transport_server_start(void *cls) |
1362 | { | 1351 | { |
1363 | struct Plugin *plugin = cls; | 1352 | struct Plugin *plugin = cls; |
1364 | struct sockaddr_un *un; | 1353 | struct sockaddr_un *un; |
1365 | socklen_t un_len; | 1354 | socklen_t un_len; |
1366 | 1355 | ||
1367 | un = unix_address_to_sockaddr (plugin->unix_socket_path, &un_len); | 1356 | un = unix_address_to_sockaddr(plugin->unix_socket_path, &un_len); |
1368 | if (GNUNET_YES == plugin->is_abstract) | 1357 | if (GNUNET_YES == plugin->is_abstract) |
1369 | { | 1358 | { |
1370 | plugin->unix_socket_path[0] = '@'; | 1359 | plugin->unix_socket_path[0] = '@'; |
1371 | un->sun_path[0] = '\0'; | 1360 | un->sun_path[0] = '\0'; |
1372 | } | 1361 | } |
1373 | plugin->unix_sock.desc = | 1362 | plugin->unix_sock.desc = |
1374 | GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); | 1363 | GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0); |
1375 | if (NULL == plugin->unix_sock.desc) | 1364 | if (NULL == plugin->unix_sock.desc) |
1376 | { | 1365 | { |
1377 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 1366 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); |
1378 | GNUNET_free (un); | 1367 | GNUNET_free(un); |
1379 | return GNUNET_SYSERR; | 1368 | return GNUNET_SYSERR; |
1380 | } | 1369 | } |
1381 | if ('\0' != un->sun_path[0]) | 1370 | if ('\0' != un->sun_path[0]) |
1382 | { | ||
1383 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path)) | ||
1384 | { | 1371 | { |
1385 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1372 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path)) |
1386 | _ ("Cannot create path to `%s'\n"), | 1373 | { |
1387 | un->sun_path); | 1374 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1388 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); | 1375 | _("Cannot create path to `%s'\n"), |
1376 | un->sun_path); | ||
1377 | GNUNET_NETWORK_socket_close(plugin->unix_sock.desc); | ||
1378 | plugin->unix_sock.desc = NULL; | ||
1379 | GNUNET_free(un); | ||
1380 | return GNUNET_SYSERR; | ||
1381 | } | ||
1382 | } | ||
1383 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind(plugin->unix_sock.desc, | ||
1384 | (const struct sockaddr *)un, | ||
1385 | un_len)) | ||
1386 | { | ||
1387 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "bind"); | ||
1388 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Cannot bind to `%s'\n"), un->sun_path); | ||
1389 | GNUNET_NETWORK_socket_close(plugin->unix_sock.desc); | ||
1389 | plugin->unix_sock.desc = NULL; | 1390 | plugin->unix_sock.desc = NULL; |
1390 | GNUNET_free (un); | 1391 | GNUNET_free(un); |
1391 | return GNUNET_SYSERR; | 1392 | return GNUNET_SYSERR; |
1392 | } | 1393 | } |
1393 | } | 1394 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path); |
1394 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, | ||
1395 | (const struct sockaddr *) un, | ||
1396 | un_len)) | ||
1397 | { | ||
1398 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | ||
1399 | LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot bind to `%s'\n"), un->sun_path); | ||
1400 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); | ||
1401 | plugin->unix_sock.desc = NULL; | ||
1402 | GNUNET_free (un); | ||
1403 | return GNUNET_SYSERR; | ||
1404 | } | ||
1405 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path); | ||
1406 | plugin->read_task = | 1395 | plugin->read_task = |
1407 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1396 | GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
1408 | plugin->unix_sock.desc, | 1397 | plugin->unix_sock.desc, |
1409 | &unix_plugin_select_read, | 1398 | &unix_plugin_select_read, |
1410 | plugin); | 1399 | plugin); |
1411 | GNUNET_free (un); | 1400 | GNUNET_free(un); |
1412 | return 1; | 1401 | return 1; |
1413 | } | 1402 | } |
1414 | 1403 | ||
@@ -1430,7 +1419,7 @@ unix_transport_server_start (void *cls) | |||
1430 | * | 1419 | * |
1431 | */ | 1420 | */ |
1432 | static int | 1421 | static int |
1433 | unix_plugin_check_address (void *cls, const void *addr, size_t addrlen) | 1422 | unix_plugin_check_address(void *cls, const void *addr, size_t addrlen) |
1434 | { | 1423 | { |
1435 | struct Plugin *plugin = cls; | 1424 | struct Plugin *plugin = cls; |
1436 | const struct UnixAddress *ua = addr; | 1425 | const struct UnixAddress *ua = addr; |
@@ -1438,25 +1427,25 @@ unix_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1438 | size_t addr_str_len; | 1427 | size_t addr_str_len; |
1439 | 1428 | ||
1440 | if ((NULL == addr) || (0 == addrlen) || | 1429 | if ((NULL == addr) || (0 == addrlen) || |
1441 | (sizeof (struct UnixAddress) > addrlen)) | 1430 | (sizeof(struct UnixAddress) > addrlen)) |
1442 | { | 1431 | { |
1443 | GNUNET_break (0); | 1432 | GNUNET_break(0); |
1444 | return GNUNET_SYSERR; | 1433 | return GNUNET_SYSERR; |
1445 | } | 1434 | } |
1446 | addrstr = (char *) &ua[1]; | 1435 | addrstr = (char *)&ua[1]; |
1447 | addr_str_len = ntohl (ua->addrlen); | 1436 | addr_str_len = ntohl(ua->addrlen); |
1448 | if ('\0' != addrstr[addr_str_len - 1]) | 1437 | if ('\0' != addrstr[addr_str_len - 1]) |
1449 | { | 1438 | { |
1450 | GNUNET_break (0); | 1439 | GNUNET_break(0); |
1451 | return GNUNET_SYSERR; | 1440 | return GNUNET_SYSERR; |
1452 | } | 1441 | } |
1453 | if (strlen (addrstr) + 1 != addr_str_len) | 1442 | if (strlen(addrstr) + 1 != addr_str_len) |
1454 | { | 1443 | { |
1455 | GNUNET_break (0); | 1444 | GNUNET_break(0); |
1456 | return GNUNET_SYSERR; | 1445 | return GNUNET_SYSERR; |
1457 | } | 1446 | } |
1458 | 1447 | ||
1459 | if (0 == strcmp (plugin->unix_socket_path, addrstr)) | 1448 | if (0 == strcmp(plugin->unix_socket_path, addrstr)) |
1460 | return GNUNET_OK; | 1449 | return GNUNET_OK; |
1461 | return GNUNET_SYSERR; | 1450 | return GNUNET_SYSERR; |
1462 | } | 1451 | } |
@@ -1477,23 +1466,23 @@ unix_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1477 | * @param asc_cls closure for @a asc | 1466 | * @param asc_cls closure for @a asc |
1478 | */ | 1467 | */ |
1479 | static void | 1468 | static void |
1480 | unix_plugin_address_pretty_printer (void *cls, | 1469 | unix_plugin_address_pretty_printer(void *cls, |
1481 | const char *type, | 1470 | const char *type, |
1482 | const void *addr, | 1471 | const void *addr, |
1483 | size_t addrlen, | 1472 | size_t addrlen, |
1484 | int numeric, | 1473 | int numeric, |
1485 | struct GNUNET_TIME_Relative timeout, | 1474 | struct GNUNET_TIME_Relative timeout, |
1486 | GNUNET_TRANSPORT_AddressStringCallback asc, | 1475 | GNUNET_TRANSPORT_AddressStringCallback asc, |
1487 | void *asc_cls) | 1476 | void *asc_cls) |
1488 | { | 1477 | { |
1489 | const char *ret; | 1478 | const char *ret; |
1490 | 1479 | ||
1491 | if ((NULL != addr) && (addrlen > 0)) | 1480 | if ((NULL != addr) && (addrlen > 0)) |
1492 | ret = unix_plugin_address_to_string (NULL, addr, addrlen); | 1481 | ret = unix_plugin_address_to_string(NULL, addr, addrlen); |
1493 | else | 1482 | else |
1494 | ret = NULL; | 1483 | ret = NULL; |
1495 | asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); | 1484 | asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); |
1496 | asc (asc_cls, NULL, GNUNET_OK); | 1485 | asc(asc_cls, NULL, GNUNET_OK); |
1497 | } | 1486 | } |
1498 | 1487 | ||
1499 | 1488 | ||
@@ -1510,11 +1499,11 @@ unix_plugin_address_pretty_printer (void *cls, | |||
1510 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1499 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1511 | */ | 1500 | */ |
1512 | static int | 1501 | static int |
1513 | unix_plugin_string_to_address (void *cls, | 1502 | unix_plugin_string_to_address(void *cls, |
1514 | const char *addr, | 1503 | const char *addr, |
1515 | uint16_t addrlen, | 1504 | uint16_t addrlen, |
1516 | void **buf, | 1505 | void **buf, |
1517 | size_t *added) | 1506 | size_t *added) |
1518 | { | 1507 | { |
1519 | struct UnixAddress *ua; | 1508 | struct UnixAddress *ua; |
1520 | char *address; | 1509 | char *address; |
@@ -1529,53 +1518,53 @@ unix_plugin_string_to_address (void *cls, | |||
1529 | optionstr = NULL; | 1518 | optionstr = NULL; |
1530 | 1519 | ||
1531 | if ((NULL == addr) || (addrlen == 0)) | 1520 | if ((NULL == addr) || (addrlen == 0)) |
1532 | { | 1521 | { |
1533 | GNUNET_break (0); | 1522 | GNUNET_break(0); |
1534 | return GNUNET_SYSERR; | 1523 | return GNUNET_SYSERR; |
1535 | } | 1524 | } |
1536 | if ('\0' != addr[addrlen - 1]) | 1525 | if ('\0' != addr[addrlen - 1]) |
1537 | { | 1526 | { |
1538 | GNUNET_break (0); | 1527 | GNUNET_break(0); |
1539 | return GNUNET_SYSERR; | 1528 | return GNUNET_SYSERR; |
1540 | } | 1529 | } |
1541 | if (strlen (addr) != addrlen - 1) | 1530 | if (strlen(addr) != addrlen - 1) |
1542 | { | 1531 | { |
1543 | GNUNET_break (0); | 1532 | GNUNET_break(0); |
1544 | return GNUNET_SYSERR; | 1533 | return GNUNET_SYSERR; |
1545 | } | 1534 | } |
1546 | plugin = GNUNET_strdup (addr); | 1535 | plugin = GNUNET_strdup(addr); |
1547 | optionstr = strchr (plugin, '.'); | 1536 | optionstr = strchr(plugin, '.'); |
1548 | if (NULL == optionstr) | 1537 | if (NULL == optionstr) |
1549 | { | 1538 | { |
1550 | GNUNET_break (0); | 1539 | GNUNET_break(0); |
1551 | GNUNET_free (plugin); | 1540 | GNUNET_free(plugin); |
1552 | return GNUNET_SYSERR; | 1541 | return GNUNET_SYSERR; |
1553 | } | 1542 | } |
1554 | optionstr[0] = '\0'; | 1543 | optionstr[0] = '\0'; |
1555 | optionstr++; | 1544 | optionstr++; |
1556 | options = atol (optionstr); | 1545 | options = atol(optionstr); |
1557 | address = strchr (optionstr, '.'); | 1546 | address = strchr(optionstr, '.'); |
1558 | if (NULL == address) | 1547 | if (NULL == address) |
1559 | { | 1548 | { |
1560 | GNUNET_break (0); | 1549 | GNUNET_break(0); |
1561 | GNUNET_free (plugin); | 1550 | GNUNET_free(plugin); |
1562 | return GNUNET_SYSERR; | 1551 | return GNUNET_SYSERR; |
1563 | } | 1552 | } |
1564 | address[0] = '\0'; | 1553 | address[0] = '\0'; |
1565 | address++; | 1554 | address++; |
1566 | if (0 != strcmp (plugin, PLUGIN_NAME)) | 1555 | if (0 != strcmp(plugin, PLUGIN_NAME)) |
1567 | { | 1556 | { |
1568 | GNUNET_break (0); | 1557 | GNUNET_break(0); |
1569 | GNUNET_free (plugin); | 1558 | GNUNET_free(plugin); |
1570 | return GNUNET_SYSERR; | 1559 | return GNUNET_SYSERR; |
1571 | } | 1560 | } |
1572 | 1561 | ||
1573 | ua_size = sizeof (struct UnixAddress) + strlen (address) + 1; | 1562 | ua_size = sizeof(struct UnixAddress) + strlen(address) + 1; |
1574 | ua = GNUNET_malloc (ua_size); | 1563 | ua = GNUNET_malloc(ua_size); |
1575 | ua->options = htonl (options); | 1564 | ua->options = htonl(options); |
1576 | ua->addrlen = htonl (strlen (address) + 1); | 1565 | ua->addrlen = htonl(strlen(address) + 1); |
1577 | GNUNET_memcpy (&ua[1], address, strlen (address) + 1); | 1566 | GNUNET_memcpy(&ua[1], address, strlen(address) + 1); |
1578 | GNUNET_free (plugin); | 1567 | GNUNET_free(plugin); |
1579 | 1568 | ||
1580 | (*buf) = ua; | 1569 | (*buf) = ua; |
1581 | (*added) = ua_size; | 1570 | (*added) = ua_size; |
@@ -1589,7 +1578,7 @@ unix_plugin_string_to_address (void *cls, | |||
1589 | * @param cls the plugin | 1578 | * @param cls the plugin |
1590 | */ | 1579 | */ |
1591 | static void | 1580 | static void |
1592 | address_notification (void *cls) | 1581 | address_notification(void *cls) |
1593 | { | 1582 | { |
1594 | struct Plugin *plugin = cls; | 1583 | struct Plugin *plugin = cls; |
1595 | struct GNUNET_HELLO_Address *address; | 1584 | struct GNUNET_HELLO_Address *address; |
@@ -1597,24 +1586,24 @@ address_notification (void *cls) | |||
1597 | struct UnixAddress *ua; | 1586 | struct UnixAddress *ua; |
1598 | char *unix_path; | 1587 | char *unix_path; |
1599 | 1588 | ||
1600 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; | 1589 | len = sizeof(struct UnixAddress) + strlen(plugin->unix_socket_path) + 1; |
1601 | ua = GNUNET_malloc (len); | 1590 | ua = GNUNET_malloc(len); |
1602 | ua->options = htonl (plugin->myoptions); | 1591 | ua->options = htonl(plugin->myoptions); |
1603 | ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1); | 1592 | ua->addrlen = htonl(strlen(plugin->unix_socket_path) + 1); |
1604 | unix_path = (char *) &ua[1]; | 1593 | unix_path = (char *)&ua[1]; |
1605 | GNUNET_memcpy (unix_path, | 1594 | GNUNET_memcpy(unix_path, |
1606 | plugin->unix_socket_path, | 1595 | plugin->unix_socket_path, |
1607 | strlen (plugin->unix_socket_path) + 1); | 1596 | strlen(plugin->unix_socket_path) + 1); |
1608 | 1597 | ||
1609 | plugin->address_update_task = NULL; | 1598 | plugin->address_update_task = NULL; |
1610 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 1599 | address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, |
1611 | PLUGIN_NAME, | 1600 | PLUGIN_NAME, |
1612 | ua, | 1601 | ua, |
1613 | len, | 1602 | len, |
1614 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 1603 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1615 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); | 1604 | plugin->env->notify_address(plugin->env->cls, GNUNET_YES, address); |
1616 | GNUNET_free (ua); | 1605 | GNUNET_free(ua); |
1617 | GNUNET_free (address); | 1606 | GNUNET_free(address); |
1618 | } | 1607 | } |
1619 | 1608 | ||
1620 | 1609 | ||
@@ -1627,14 +1616,14 @@ address_notification (void *cls) | |||
1627 | * @return #GNUNET_YES (always, continue to iterate) | 1616 | * @return #GNUNET_YES (always, continue to iterate) |
1628 | */ | 1617 | */ |
1629 | static int | 1618 | static int |
1630 | get_session_delete_it (void *cls, | 1619 | get_session_delete_it(void *cls, |
1631 | const struct GNUNET_PeerIdentity *key, | 1620 | const struct GNUNET_PeerIdentity *key, |
1632 | void *value) | 1621 | void *value) |
1633 | { | 1622 | { |
1634 | struct Plugin *plugin = cls; | 1623 | struct Plugin *plugin = cls; |
1635 | struct GNUNET_ATS_Session *session = value; | 1624 | struct GNUNET_ATS_Session *session = value; |
1636 | 1625 | ||
1637 | unix_plugin_session_disconnect (plugin, session); | 1626 | unix_plugin_session_disconnect(plugin, session); |
1638 | return GNUNET_YES; | 1627 | return GNUNET_YES; |
1639 | } | 1628 | } |
1640 | 1629 | ||
@@ -1647,15 +1636,15 @@ get_session_delete_it (void *cls, | |||
1647 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed | 1636 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed |
1648 | */ | 1637 | */ |
1649 | static void | 1638 | static void |
1650 | unix_plugin_peer_disconnect (void *cls, | 1639 | unix_plugin_peer_disconnect(void *cls, |
1651 | const struct GNUNET_PeerIdentity *target) | 1640 | const struct GNUNET_PeerIdentity *target) |
1652 | { | 1641 | { |
1653 | struct Plugin *plugin = cls; | 1642 | struct Plugin *plugin = cls; |
1654 | 1643 | ||
1655 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, | 1644 | GNUNET_CONTAINER_multipeermap_get_multiple(plugin->session_map, |
1656 | target, | 1645 | target, |
1657 | &get_session_delete_it, | 1646 | &get_session_delete_it, |
1658 | plugin); | 1647 | plugin); |
1659 | } | 1648 | } |
1660 | 1649 | ||
1661 | 1650 | ||
@@ -1669,15 +1658,15 @@ unix_plugin_peer_disconnect (void *cls, | |||
1669 | * @return #GNUNET_OK (continue to iterate) | 1658 | * @return #GNUNET_OK (continue to iterate) |
1670 | */ | 1659 | */ |
1671 | static int | 1660 | static int |
1672 | send_session_info_iter (void *cls, | 1661 | send_session_info_iter(void *cls, |
1673 | const struct GNUNET_PeerIdentity *peer, | 1662 | const struct GNUNET_PeerIdentity *peer, |
1674 | void *value) | 1663 | void *value) |
1675 | { | 1664 | { |
1676 | struct Plugin *plugin = cls; | 1665 | struct Plugin *plugin = cls; |
1677 | struct GNUNET_ATS_Session *session = value; | 1666 | struct GNUNET_ATS_Session *session = value; |
1678 | 1667 | ||
1679 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); | 1668 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); |
1680 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); | 1669 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); |
1681 | return GNUNET_OK; | 1670 | return GNUNET_OK; |
1682 | } | 1671 | } |
1683 | 1672 | ||
@@ -1695,22 +1684,22 @@ send_session_info_iter (void *cls, | |||
1695 | * @param sic_cls closure for @a sic | 1684 | * @param sic_cls closure for @a sic |
1696 | */ | 1685 | */ |
1697 | static void | 1686 | static void |
1698 | unix_plugin_setup_monitor (void *cls, | 1687 | unix_plugin_setup_monitor(void *cls, |
1699 | GNUNET_TRANSPORT_SessionInfoCallback sic, | 1688 | GNUNET_TRANSPORT_SessionInfoCallback sic, |
1700 | void *sic_cls) | 1689 | void *sic_cls) |
1701 | { | 1690 | { |
1702 | struct Plugin *plugin = cls; | 1691 | struct Plugin *plugin = cls; |
1703 | 1692 | ||
1704 | plugin->sic = sic; | 1693 | plugin->sic = sic; |
1705 | plugin->sic_cls = sic_cls; | 1694 | plugin->sic_cls = sic_cls; |
1706 | if (NULL != sic) | 1695 | if (NULL != sic) |
1707 | { | 1696 | { |
1708 | GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, | 1697 | GNUNET_CONTAINER_multipeermap_iterate(plugin->session_map, |
1709 | &send_session_info_iter, | 1698 | &send_session_info_iter, |
1710 | plugin); | 1699 | plugin); |
1711 | /* signal end of first iteration */ | 1700 | /* signal end of first iteration */ |
1712 | sic (sic_cls, NULL, NULL); | 1701 | sic(sic_cls, NULL, NULL); |
1713 | } | 1702 | } |
1714 | } | 1703 | } |
1715 | 1704 | ||
1716 | 1705 | ||
@@ -1722,7 +1711,7 @@ unix_plugin_setup_monitor (void *cls, | |||
1722 | * @return NULL on error, plugin functions otherwise | 1711 | * @return NULL on error, plugin functions otherwise |
1723 | */ | 1712 | */ |
1724 | void * | 1713 | void * |
1725 | libgnunet_plugin_transport_unix_init (void *cls) | 1714 | libgnunet_plugin_transport_unix_init(void *cls) |
1726 | { | 1715 | { |
1727 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; | 1716 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; |
1728 | struct GNUNET_TRANSPORT_PluginFunctions *api; | 1717 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
@@ -1730,45 +1719,45 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1730 | int sockets_created; | 1719 | int sockets_created; |
1731 | 1720 | ||
1732 | if (NULL == env->receive) | 1721 | if (NULL == env->receive) |
1733 | { | 1722 | { |
1734 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 1723 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
1735 | initialze the plugin or the API */ | 1724 | initialze the plugin or the API */ |
1736 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 1725 | api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); |
1737 | api->cls = NULL; | 1726 | api->cls = NULL; |
1738 | api->address_pretty_printer = &unix_plugin_address_pretty_printer; | 1727 | api->address_pretty_printer = &unix_plugin_address_pretty_printer; |
1739 | api->address_to_string = &unix_plugin_address_to_string; | 1728 | api->address_to_string = &unix_plugin_address_to_string; |
1740 | api->string_to_address = &unix_plugin_string_to_address; | 1729 | api->string_to_address = &unix_plugin_string_to_address; |
1741 | return api; | 1730 | return api; |
1742 | } | 1731 | } |
1743 | 1732 | ||
1744 | plugin = GNUNET_new (struct Plugin); | 1733 | plugin = GNUNET_new(struct Plugin); |
1745 | if (GNUNET_OK != | 1734 | if (GNUNET_OK != |
1746 | GNUNET_CONFIGURATION_get_value_filename (env->cfg, | 1735 | GNUNET_CONFIGURATION_get_value_filename(env->cfg, |
1747 | "transport-unix", | 1736 | "transport-unix", |
1748 | "UNIXPATH", | 1737 | "UNIXPATH", |
1749 | &plugin->unix_socket_path)) | 1738 | &plugin->unix_socket_path)) |
1750 | { | 1739 | { |
1751 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 1740 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
1752 | "transport-unix", | 1741 | "transport-unix", |
1753 | "UNIXPATH"); | 1742 | "UNIXPATH"); |
1754 | GNUNET_free (plugin); | 1743 | GNUNET_free(plugin); |
1755 | return NULL; | 1744 | return NULL; |
1756 | } | 1745 | } |
1757 | 1746 | ||
1758 | plugin->env = env; | 1747 | plugin->env = env; |
1759 | 1748 | ||
1760 | /* Initialize my flags */ | 1749 | /* Initialize my flags */ |
1761 | #ifdef LINUX | 1750 | #ifdef LINUX |
1762 | plugin->is_abstract = | 1751 | plugin->is_abstract = |
1763 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 1752 | GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, |
1764 | "testing", | 1753 | "testing", |
1765 | "USE_ABSTRACT_SOCKETS"); | 1754 | "USE_ABSTRACT_SOCKETS"); |
1766 | #endif | 1755 | #endif |
1767 | plugin->myoptions = UNIX_OPTIONS_NONE; | 1756 | plugin->myoptions = UNIX_OPTIONS_NONE; |
1768 | if (GNUNET_YES == plugin->is_abstract) | 1757 | if (GNUNET_YES == plugin->is_abstract) |
1769 | plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS; | 1758 | plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS; |
1770 | 1759 | ||
1771 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 1760 | api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); |
1772 | api->cls = plugin; | 1761 | api->cls = plugin; |
1773 | api->get_session = &unix_plugin_get_session; | 1762 | api->get_session = &unix_plugin_get_session; |
1774 | api->send = &unix_plugin_send; | 1763 | api->send = &unix_plugin_send; |
@@ -1783,18 +1772,18 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1783 | api->get_network_for_address = &unix_plugin_get_network_for_address; | 1772 | api->get_network_for_address = &unix_plugin_get_network_for_address; |
1784 | api->update_session_timeout = &unix_plugin_update_session_timeout; | 1773 | api->update_session_timeout = &unix_plugin_update_session_timeout; |
1785 | api->setup_monitor = &unix_plugin_setup_monitor; | 1774 | api->setup_monitor = &unix_plugin_setup_monitor; |
1786 | sockets_created = unix_transport_server_start (plugin); | 1775 | sockets_created = unix_transport_server_start(plugin); |
1787 | if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) | 1776 | if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) |
1788 | { | 1777 | { |
1789 | LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UNIX listen socket\n")); | 1778 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX listen socket\n")); |
1790 | GNUNET_free (api); | 1779 | GNUNET_free(api); |
1791 | GNUNET_free (plugin->unix_socket_path); | 1780 | GNUNET_free(plugin->unix_socket_path); |
1792 | GNUNET_free (plugin); | 1781 | GNUNET_free(plugin); |
1793 | return NULL; | 1782 | return NULL; |
1794 | } | 1783 | } |
1795 | plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 1784 | plugin->session_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); |
1796 | plugin->address_update_task = | 1785 | plugin->address_update_task = |
1797 | GNUNET_SCHEDULER_add_now (&address_notification, plugin); | 1786 | GNUNET_SCHEDULER_add_now(&address_notification, plugin); |
1798 | return api; | 1787 | return api; |
1799 | } | 1788 | } |
1800 | 1789 | ||
@@ -1806,7 +1795,7 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1806 | * @return NULL (always) | 1795 | * @return NULL (always) |
1807 | */ | 1796 | */ |
1808 | void * | 1797 | void * |
1809 | libgnunet_plugin_transport_unix_done (void *cls) | 1798 | libgnunet_plugin_transport_unix_done(void *cls) |
1810 | { | 1799 | { |
1811 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 1800 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
1812 | struct Plugin *plugin = api->cls; | 1801 | struct Plugin *plugin = api->cls; |
@@ -1817,75 +1806,75 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1817 | struct GNUNET_ATS_Session *session; | 1806 | struct GNUNET_ATS_Session *session; |
1818 | 1807 | ||
1819 | if (NULL == plugin) | 1808 | if (NULL == plugin) |
1820 | { | 1809 | { |
1821 | GNUNET_free (api); | 1810 | GNUNET_free(api); |
1822 | return NULL; | 1811 | return NULL; |
1823 | } | 1812 | } |
1824 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; | 1813 | len = sizeof(struct UnixAddress) + strlen(plugin->unix_socket_path) + 1; |
1825 | ua = GNUNET_malloc (len); | 1814 | ua = GNUNET_malloc(len); |
1826 | ua->options = htonl (plugin->myoptions); | 1815 | ua->options = htonl(plugin->myoptions); |
1827 | ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1); | 1816 | ua->addrlen = htonl(strlen(plugin->unix_socket_path) + 1); |
1828 | GNUNET_memcpy (&ua[1], | 1817 | GNUNET_memcpy(&ua[1], |
1829 | plugin->unix_socket_path, | 1818 | plugin->unix_socket_path, |
1830 | strlen (plugin->unix_socket_path) + 1); | 1819 | strlen(plugin->unix_socket_path) + 1); |
1831 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 1820 | address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, |
1832 | PLUGIN_NAME, | 1821 | PLUGIN_NAME, |
1833 | ua, | 1822 | ua, |
1834 | len, | 1823 | len, |
1835 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 1824 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1836 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); | 1825 | plugin->env->notify_address(plugin->env->cls, GNUNET_NO, address); |
1837 | 1826 | ||
1838 | GNUNET_free (address); | 1827 | GNUNET_free(address); |
1839 | GNUNET_free (ua); | 1828 | GNUNET_free(ua); |
1840 | 1829 | ||
1841 | while (NULL != (msgw = plugin->msg_head)) | 1830 | while (NULL != (msgw = plugin->msg_head)) |
1842 | { | 1831 | { |
1843 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); | 1832 | GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); |
1844 | session = msgw->session; | 1833 | session = msgw->session; |
1845 | session->msgs_in_queue--; | 1834 | session->msgs_in_queue--; |
1846 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 1835 | GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); |
1847 | session->bytes_in_queue -= msgw->msgsize; | 1836 | session->bytes_in_queue -= msgw->msgsize; |
1848 | GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); | 1837 | GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); |
1849 | plugin->bytes_in_queue -= msgw->msgsize; | 1838 | plugin->bytes_in_queue -= msgw->msgsize; |
1850 | if (NULL != msgw->cont) | 1839 | if (NULL != msgw->cont) |
1851 | msgw->cont (msgw->cont_cls, | 1840 | msgw->cont(msgw->cont_cls, |
1852 | &msgw->session->target, | 1841 | &msgw->session->target, |
1853 | GNUNET_SYSERR, | 1842 | GNUNET_SYSERR, |
1854 | msgw->payload, | 1843 | msgw->payload, |
1855 | 0); | 1844 | 0); |
1856 | GNUNET_free (msgw->msg); | 1845 | GNUNET_free(msgw->msg); |
1857 | GNUNET_free (msgw); | 1846 | GNUNET_free(msgw); |
1858 | } | 1847 | } |
1859 | 1848 | ||
1860 | if (NULL != plugin->read_task) | 1849 | if (NULL != plugin->read_task) |
1861 | { | 1850 | { |
1862 | GNUNET_SCHEDULER_cancel (plugin->read_task); | 1851 | GNUNET_SCHEDULER_cancel(plugin->read_task); |
1863 | plugin->read_task = NULL; | 1852 | plugin->read_task = NULL; |
1864 | } | 1853 | } |
1865 | if (NULL != plugin->write_task) | 1854 | if (NULL != plugin->write_task) |
1866 | { | 1855 | { |
1867 | GNUNET_SCHEDULER_cancel (plugin->write_task); | 1856 | GNUNET_SCHEDULER_cancel(plugin->write_task); |
1868 | plugin->write_task = NULL; | 1857 | plugin->write_task = NULL; |
1869 | } | 1858 | } |
1870 | if (NULL != plugin->address_update_task) | 1859 | if (NULL != plugin->address_update_task) |
1871 | { | 1860 | { |
1872 | GNUNET_SCHEDULER_cancel (plugin->address_update_task); | 1861 | GNUNET_SCHEDULER_cancel(plugin->address_update_task); |
1873 | plugin->address_update_task = NULL; | 1862 | plugin->address_update_task = NULL; |
1874 | } | 1863 | } |
1875 | if (NULL != plugin->unix_sock.desc) | 1864 | if (NULL != plugin->unix_sock.desc) |
1876 | { | 1865 | { |
1877 | GNUNET_break (GNUNET_OK == | 1866 | GNUNET_break(GNUNET_OK == |
1878 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc)); | 1867 | GNUNET_NETWORK_socket_close(plugin->unix_sock.desc)); |
1879 | plugin->unix_sock.desc = NULL; | 1868 | plugin->unix_sock.desc = NULL; |
1880 | } | 1869 | } |
1881 | GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, | 1870 | GNUNET_CONTAINER_multipeermap_iterate(plugin->session_map, |
1882 | &get_session_delete_it, | 1871 | &get_session_delete_it, |
1883 | plugin); | 1872 | plugin); |
1884 | GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map); | 1873 | GNUNET_CONTAINER_multipeermap_destroy(plugin->session_map); |
1885 | GNUNET_break (0 == plugin->bytes_in_queue); | 1874 | GNUNET_break(0 == plugin->bytes_in_queue); |
1886 | GNUNET_free (plugin->unix_socket_path); | 1875 | GNUNET_free(plugin->unix_socket_path); |
1887 | GNUNET_free (plugin); | 1876 | GNUNET_free(plugin); |
1888 | GNUNET_free (api); | 1877 | GNUNET_free(api); |
1889 | return NULL; | 1878 | return NULL; |
1890 | } | 1879 | } |
1891 | 1880 | ||