diff options
Diffstat (limited to 'src/transport/plugin_transport_unix.c')
-rw-r--r-- | src/transport/plugin_transport_unix.c | 453 |
1 files changed, 212 insertions, 241 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 5d095236d..2c408ebf5 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -68,9 +68,10 @@ enum UNIX_ADDRESS_OPTIONS | |||
68 | /** | 68 | /** |
69 | * How long until we give up on transmitting the welcome message? | 69 | * How long until we give up on transmitting the welcome message? |
70 | */ | 70 | */ |
71 | #define HOSTNAME_RESOLVE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 71 | #define HOSTNAME_RESOLVE_TIMEOUT \ |
72 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
72 | 73 | ||
73 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-unix",__VA_ARGS__) | 74 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-unix", __VA_ARGS__) |
74 | 75 | ||
75 | 76 | ||
76 | GNUNET_NETWORK_STRUCT_BEGIN | 77 | GNUNET_NETWORK_STRUCT_BEGIN |
@@ -108,7 +109,6 @@ struct UNIXMessage | |||
108 | * What is the identity of the sender (GNUNET_hash of public key) | 109 | * What is the identity of the sender (GNUNET_hash of public key) |
109 | */ | 110 | */ |
110 | struct GNUNET_PeerIdentity sender; | 111 | struct GNUNET_PeerIdentity sender; |
111 | |||
112 | }; | 112 | }; |
113 | 113 | ||
114 | GNUNET_NETWORK_STRUCT_END | 114 | GNUNET_NETWORK_STRUCT_END |
@@ -218,13 +218,12 @@ struct GNUNET_ATS_Session | |||
218 | /** | 218 | /** |
219 | * Session timeout task. | 219 | * Session timeout task. |
220 | */ | 220 | */ |
221 | struct GNUNET_SCHEDULER_Task * timeout_task; | 221 | struct GNUNET_SCHEDULER_Task *timeout_task; |
222 | 222 | ||
223 | /** | 223 | /** |
224 | * Number of messages we currently have in our write queue. | 224 | * Number of messages we currently have in our write queue. |
225 | */ | 225 | */ |
226 | unsigned int msgs_in_queue; | 226 | unsigned int msgs_in_queue; |
227 | |||
228 | }; | 227 | }; |
229 | 228 | ||
230 | 229 | ||
@@ -255,17 +254,17 @@ struct Plugin | |||
255 | /** | 254 | /** |
256 | * ID of task used to update our addresses when one expires. | 255 | * ID of task used to update our addresses when one expires. |
257 | */ | 256 | */ |
258 | struct GNUNET_SCHEDULER_Task * address_update_task; | 257 | struct GNUNET_SCHEDULER_Task *address_update_task; |
259 | 258 | ||
260 | /** | 259 | /** |
261 | * ID of read task | 260 | * ID of read task |
262 | */ | 261 | */ |
263 | struct GNUNET_SCHEDULER_Task * read_task; | 262 | struct GNUNET_SCHEDULER_Task *read_task; |
264 | 263 | ||
265 | /** | 264 | /** |
266 | * ID of write task | 265 | * ID of write task |
267 | */ | 266 | */ |
268 | struct GNUNET_SCHEDULER_Task * write_task; | 267 | struct GNUNET_SCHEDULER_Task *write_task; |
269 | 268 | ||
270 | /** | 269 | /** |
271 | * Number of bytes we currently have in our write queues. | 270 | * Number of bytes we currently have in our write queues. |
@@ -321,7 +320,6 @@ struct Plugin | |||
321 | * Are we using an abstract UNIX domain socket? | 320 | * Are we using an abstract UNIX domain socket? |
322 | */ | 321 | */ |
323 | int is_abstract; | 322 | int is_abstract; |
324 | |||
325 | }; | 323 | }; |
326 | 324 | ||
327 | 325 | ||
@@ -352,9 +350,7 @@ notify_session_monitor (struct Plugin *plugin, | |||
352 | to receive from others) */ | 350 | to receive from others) */ |
353 | info.session_timeout = session->timeout; | 351 | info.session_timeout = session->timeout; |
354 | info.address = session->address; | 352 | info.address = session->address; |
355 | plugin->sic (plugin->sic_cls, | 353 | plugin->sic (plugin->sic_cls, session, &info); |
356 | session, | ||
357 | &info); | ||
358 | } | 354 | } |
359 | 355 | ||
360 | 356 | ||
@@ -370,9 +366,7 @@ notify_session_monitor (struct Plugin *plugin, | |||
370 | * @return string representing the same address | 366 | * @return string representing the same address |
371 | */ | 367 | */ |
372 | static const char * | 368 | static const char * |
373 | unix_plugin_address_to_string (void *cls, | 369 | unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) |
374 | const void *addr, | ||
375 | size_t addrlen) | ||
376 | { | 370 | { |
377 | static char rbuf[1024]; | 371 | static char rbuf[1024]; |
378 | struct UnixAddress *ua = (struct UnixAddress *) addr; | 372 | struct UnixAddress *ua = (struct UnixAddress *) addr; |
@@ -382,25 +376,25 @@ unix_plugin_address_to_string (void *cls, | |||
382 | 376 | ||
383 | if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) | 377 | if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) |
384 | { | 378 | { |
385 | GNUNET_break(0); | 379 | GNUNET_break (0); |
386 | return NULL; | 380 | return NULL; |
387 | } | 381 | } |
388 | addrstr = (char *) &ua[1]; | 382 | addrstr = (char *) &ua[1]; |
389 | addr_str_len = ntohl (ua->addrlen); | 383 | addr_str_len = ntohl (ua->addrlen); |
390 | 384 | ||
391 | if (addr_str_len != addrlen - sizeof(struct UnixAddress)) | 385 | if (addr_str_len != addrlen - sizeof (struct UnixAddress)) |
392 | { | 386 | { |
393 | GNUNET_break(0); | 387 | GNUNET_break (0); |
394 | return NULL; | 388 | return NULL; |
395 | } | 389 | } |
396 | if ('\0' != addrstr[addr_str_len - 1]) | 390 | if ('\0' != addrstr[addr_str_len - 1]) |
397 | { | 391 | { |
398 | GNUNET_break(0); | 392 | GNUNET_break (0); |
399 | return NULL; | 393 | return NULL; |
400 | } | 394 | } |
401 | if (strlen (addrstr) + 1 != addr_str_len) | 395 | if (strlen (addrstr) + 1 != addr_str_len) |
402 | { | 396 | { |
403 | GNUNET_break(0); | 397 | GNUNET_break (0); |
404 | return NULL; | 398 | return NULL; |
405 | } | 399 | } |
406 | 400 | ||
@@ -430,8 +424,7 @@ unix_plugin_address_to_string (void *cls, | |||
430 | * @return #GNUNET_OK on success | 424 | * @return #GNUNET_OK on success |
431 | */ | 425 | */ |
432 | static int | 426 | static int |
433 | unix_plugin_session_disconnect (void *cls, | 427 | unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session) |
434 | struct GNUNET_ATS_Session *session) | ||
435 | { | 428 | { |
436 | struct Plugin *plugin = cls; | 429 | struct Plugin *plugin = cls; |
437 | struct UNIXMessageWrapper *msgw; | 430 | struct UNIXMessageWrapper *msgw; |
@@ -443,9 +436,7 @@ unix_plugin_session_disconnect (void *cls, | |||
443 | unix_plugin_address_to_string (NULL, | 436 | unix_plugin_address_to_string (NULL, |
444 | session->address->address, | 437 | session->address->address, |
445 | session->address->address_length)); | 438 | session->address->address_length)); |
446 | plugin->env->session_end (plugin->env->cls, | 439 | plugin->env->session_end (plugin->env->cls, session->address, session); |
447 | session->address, | ||
448 | session); | ||
449 | next = plugin->msg_head; | 440 | next = plugin->msg_head; |
450 | while (NULL != next) | 441 | while (NULL != next) |
451 | { | 442 | { |
@@ -453,9 +444,7 @@ unix_plugin_session_disconnect (void *cls, | |||
453 | next = msgw->next; | 444 | next = msgw->next; |
454 | if (msgw->session != session) | 445 | if (msgw->session != session) |
455 | continue; | 446 | continue; |
456 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, | 447 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); |
457 | plugin->msg_tail, | ||
458 | msgw); | ||
459 | session->msgs_in_queue--; | 448 | session->msgs_in_queue--; |
460 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 449 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); |
461 | session->bytes_in_queue -= msgw->msgsize; | 450 | session->bytes_in_queue -= msgw->msgsize; |
@@ -465,27 +454,27 @@ unix_plugin_session_disconnect (void *cls, | |||
465 | msgw->cont (msgw->cont_cls, | 454 | msgw->cont (msgw->cont_cls, |
466 | &msgw->session->target, | 455 | &msgw->session->target, |
467 | GNUNET_SYSERR, | 456 | GNUNET_SYSERR, |
468 | msgw->payload, 0); | 457 | msgw->payload, |
458 | 0); | ||
469 | GNUNET_free (msgw->msg); | 459 | GNUNET_free (msgw->msg); |
470 | GNUNET_free (msgw); | 460 | GNUNET_free (msgw); |
471 | } | 461 | } |
472 | GNUNET_assert (GNUNET_YES == | 462 | GNUNET_assert (GNUNET_YES == |
473 | GNUNET_CONTAINER_multipeermap_remove (plugin->session_map, | 463 | GNUNET_CONTAINER_multipeermap_remove (plugin->session_map, |
474 | &session->target, | 464 | &session->target, |
475 | session)); | 465 | session)); |
476 | GNUNET_STATISTICS_set (plugin->env->stats, | 466 | GNUNET_STATISTICS_set (plugin->env->stats, |
477 | "# UNIX sessions active", | 467 | "# UNIX sessions active", |
478 | GNUNET_CONTAINER_multipeermap_size (plugin->session_map), | 468 | GNUNET_CONTAINER_multipeermap_size ( |
479 | GNUNET_NO); | 469 | plugin->session_map), |
470 | GNUNET_NO); | ||
480 | if (NULL != session->timeout_task) | 471 | if (NULL != session->timeout_task) |
481 | { | 472 | { |
482 | GNUNET_SCHEDULER_cancel (session->timeout_task); | 473 | GNUNET_SCHEDULER_cancel (session->timeout_task); |
483 | session->timeout_task = NULL; | 474 | session->timeout_task = NULL; |
484 | session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; | 475 | session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; |
485 | } | 476 | } |
486 | notify_session_monitor (plugin, | 477 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_DONE); |
487 | session, | ||
488 | GNUNET_TRANSPORT_SS_DONE); | ||
489 | GNUNET_HELLO_address_free (session->address); | 478 | GNUNET_HELLO_address_free (session->address); |
490 | GNUNET_break (0 == session->bytes_in_queue); | 479 | GNUNET_break (0 == session->bytes_in_queue); |
491 | GNUNET_break (0 == session->msgs_in_queue); | 480 | GNUNET_break (0 == session->msgs_in_queue); |
@@ -514,16 +503,16 @@ session_timeout (void *cls) | |||
514 | notify_session_monitor (session->plugin, | 503 | notify_session_monitor (session->plugin, |
515 | session, | 504 | session, |
516 | GNUNET_TRANSPORT_SS_UPDATE); | 505 | GNUNET_TRANSPORT_SS_UPDATE); |
517 | session->timeout_task = GNUNET_SCHEDULER_add_delayed (left, | 506 | session->timeout_task = |
518 | &session_timeout, | 507 | GNUNET_SCHEDULER_add_delayed (left, &session_timeout, session); |
519 | session); | ||
520 | return; | 508 | return; |
521 | } | 509 | } |
522 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 510 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
523 | "Session %p was idle for %s, disconnecting\n", | 511 | "Session %p was idle for %s, disconnecting\n", |
524 | session, | 512 | session, |
525 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 513 | GNUNET_STRINGS_relative_time_to_string ( |
526 | GNUNET_YES)); | 514 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
515 | GNUNET_YES)); | ||
527 | unix_plugin_session_disconnect (session->plugin, session); | 516 | unix_plugin_session_disconnect (session->plugin, session); |
528 | } | 517 | } |
529 | 518 | ||
@@ -539,7 +528,8 @@ static void | |||
539 | reschedule_session_timeout (struct GNUNET_ATS_Session *session) | 528 | reschedule_session_timeout (struct GNUNET_ATS_Session *session) |
540 | { | 529 | { |
541 | GNUNET_assert (NULL != session->timeout_task); | 530 | GNUNET_assert (NULL != session->timeout_task); |
542 | session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 531 | session->timeout = |
532 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
543 | } | 533 | } |
544 | 534 | ||
545 | 535 | ||
@@ -551,13 +541,12 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *session) | |||
551 | * @return converted unix path | 541 | * @return converted unix path |
552 | */ | 542 | */ |
553 | static struct sockaddr_un * | 543 | static struct sockaddr_un * |
554 | unix_address_to_sockaddr (const char *unixpath, | 544 | unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) |
555 | socklen_t *sock_len) | ||
556 | { | 545 | { |
557 | struct sockaddr_un *un; | 546 | struct sockaddr_un *un; |
558 | size_t slen; | 547 | size_t slen; |
559 | 548 | ||
560 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ | 549 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ |
561 | un = GNUNET_new (struct sockaddr_un); | 550 | un = GNUNET_new (struct sockaddr_un); |
562 | un->sun_family = AF_UNIX; | 551 | un->sun_family = AF_UNIX; |
563 | slen = strlen (unixpath); | 552 | slen = strlen (unixpath); |
@@ -601,14 +590,13 @@ struct LookupCtx | |||
601 | */ | 590 | */ |
602 | static int | 591 | static int |
603 | lookup_session_it (void *cls, | 592 | lookup_session_it (void *cls, |
604 | const struct GNUNET_PeerIdentity * key, | 593 | const struct GNUNET_PeerIdentity *key, |
605 | void *value) | 594 | void *value) |
606 | { | 595 | { |
607 | struct LookupCtx *lctx = cls; | 596 | struct LookupCtx *lctx = cls; |
608 | struct GNUNET_ATS_Session *session = value; | 597 | struct GNUNET_ATS_Session *session = value; |
609 | 598 | ||
610 | if (0 == GNUNET_HELLO_address_cmp (lctx->address, | 599 | if (0 == GNUNET_HELLO_address_cmp (lctx->address, session->address)) |
611 | session->address)) | ||
612 | { | 600 | { |
613 | lctx->res = session; | 601 | lctx->res = session; |
614 | return GNUNET_NO; | 602 | return GNUNET_NO; |
@@ -633,8 +621,9 @@ lookup_session (struct Plugin *plugin, | |||
633 | lctx.address = address; | 621 | lctx.address = address; |
634 | lctx.res = NULL; | 622 | lctx.res = NULL; |
635 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, | 623 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, |
636 | &address->peer, | 624 | &address->peer, |
637 | &lookup_session_it, &lctx); | 625 | &lookup_session_it, |
626 | &lctx); | ||
638 | return lctx.res; | 627 | return lctx.res; |
639 | } | 628 | } |
640 | 629 | ||
@@ -707,16 +696,15 @@ unix_real_send (void *cls, | |||
707 | } | 696 | } |
708 | 697 | ||
709 | /* Prepare address */ | 698 | /* Prepare address */ |
710 | unixpath = (const char *) &addr[1]; | 699 | unixpath = (const char *) &addr[1]; |
711 | if (NULL == (un = unix_address_to_sockaddr (unixpath, | 700 | if (NULL == (un = unix_address_to_sockaddr (unixpath, &un_len))) |
712 | &un_len))) | ||
713 | { | 701 | { |
714 | GNUNET_break (0); | 702 | GNUNET_break (0); |
715 | return -1; | 703 | return -1; |
716 | } | 704 | } |
717 | 705 | ||
718 | if ((GNUNET_YES == plugin->is_abstract) && | 706 | if ((GNUNET_YES == plugin->is_abstract) && |
719 | (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options) )) ) | 707 | (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl (addr->options)))) |
720 | { | 708 | { |
721 | un->sun_path[0] = '\0'; | 709 | un->sun_path[0] = '\0'; |
722 | } | 710 | } |
@@ -729,8 +717,7 @@ resend: | |||
729 | un_len); | 717 | un_len); |
730 | if (GNUNET_SYSERR == sent) | 718 | if (GNUNET_SYSERR == sent) |
731 | { | 719 | { |
732 | if ( (EAGAIN == errno) || | 720 | if ((EAGAIN == errno) || (ENOBUFS == errno)) |
733 | (ENOBUFS == errno) ) | ||
734 | { | 721 | { |
735 | GNUNET_free (un); | 722 | GNUNET_free (un); |
736 | return RETRY; /* We have to retry later */ | 723 | return RETRY; /* We have to retry later */ |
@@ -741,7 +728,10 @@ resend: | |||
741 | socklen_t len = sizeof (size); | 728 | socklen_t len = sizeof (size); |
742 | 729 | ||
743 | GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *) | 730 | GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *) |
744 | send_handle, SOL_SOCKET, SO_SNDBUF, &size, | 731 | send_handle, |
732 | SOL_SOCKET, | ||
733 | SO_SNDBUF, | ||
734 | &size, | ||
745 | &len); | 735 | &len); |
746 | if (size < msgbuf_size) | 736 | if (size < msgbuf_size) |
747 | { | 737 | { |
@@ -752,9 +742,12 @@ resend: | |||
752 | (unsigned int) msgbuf_size); | 742 | (unsigned int) msgbuf_size); |
753 | size = ((msgbuf_size / 1000) + 2) * 1000; | 743 | size = ((msgbuf_size / 1000) + 2) * 1000; |
754 | if (GNUNET_OK == | 744 | if (GNUNET_OK == |
755 | GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) send_handle, | 745 | GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) |
756 | SOL_SOCKET, SO_SNDBUF, | 746 | send_handle, |
757 | &size, sizeof (size))) | 747 | SOL_SOCKET, |
748 | SO_SNDBUF, | ||
749 | &size, | ||
750 | sizeof (size))) | ||
758 | goto resend; /* Increased buffer size, retry sending */ | 751 | goto resend; /* Increased buffer size, retry sending */ |
759 | else | 752 | else |
760 | { | 753 | { |
@@ -778,9 +771,9 @@ resend: | |||
778 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 771 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
779 | "UNIX transmitted %u-byte message to %s (%d: %s)\n", | 772 | "UNIX transmitted %u-byte message to %s (%d: %s)\n", |
780 | (unsigned int) msgbuf_size, | 773 | (unsigned int) msgbuf_size, |
781 | GNUNET_a2s ((const struct sockaddr *)un, un_len), | 774 | GNUNET_a2s ((const struct sockaddr *) un, un_len), |
782 | (int) sent, | 775 | (int) sent, |
783 | (sent < 0) ? STRERROR (errno) : "ok"); | 776 | (sent < 0) ? strerror (errno) : "ok"); |
784 | GNUNET_free (un); | 777 | GNUNET_free (un); |
785 | return sent; | 778 | return sent; |
786 | } | 779 | } |
@@ -794,8 +787,7 @@ resend: | |||
794 | * @return the network type in HBO or #GNUNET_SYSERR | 787 | * @return the network type in HBO or #GNUNET_SYSERR |
795 | */ | 788 | */ |
796 | static enum GNUNET_NetworkType | 789 | static enum GNUNET_NetworkType |
797 | unix_plugin_get_network (void *cls, | 790 | unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) |
798 | struct GNUNET_ATS_Session *session) | ||
799 | { | 791 | { |
800 | GNUNET_assert (NULL != session); | 792 | GNUNET_assert (NULL != session); |
801 | return GNUNET_NT_LOOPBACK; | 793 | return GNUNET_NT_LOOPBACK; |
@@ -827,19 +819,18 @@ unix_plugin_get_network_for_address (void *cls, | |||
827 | * @return the session or NULL of max connections exceeded | 819 | * @return the session or NULL of max connections exceeded |
828 | */ | 820 | */ |
829 | static struct GNUNET_ATS_Session * | 821 | static struct GNUNET_ATS_Session * |
830 | unix_plugin_get_session (void *cls, | 822 | unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) |
831 | const struct GNUNET_HELLO_Address *address) | ||
832 | { | 823 | { |
833 | struct Plugin *plugin = cls; | 824 | struct Plugin *plugin = cls; |
834 | struct GNUNET_ATS_Session *session; | 825 | struct GNUNET_ATS_Session *session; |
835 | struct UnixAddress *ua; | 826 | struct UnixAddress *ua; |
836 | char * addrstr; | 827 | char *addrstr; |
837 | uint32_t addr_str_len; | 828 | uint32_t addr_str_len; |
838 | uint32_t addr_option; | 829 | uint32_t addr_option; |
839 | 830 | ||
840 | ua = (struct UnixAddress *) address->address; | 831 | ua = (struct UnixAddress *) address->address; |
841 | if ((NULL == address->address) || (0 == address->address_length) || | 832 | if ((NULL == address->address) || (0 == address->address_length) || |
842 | (sizeof (struct UnixAddress) > address->address_length)) | 833 | (sizeof (struct UnixAddress) > address->address_length)) |
843 | { | 834 | { |
844 | GNUNET_break (0); | 835 | GNUNET_break (0); |
845 | return NULL; | 836 | return NULL; |
@@ -848,8 +839,8 @@ unix_plugin_get_session (void *cls, | |||
848 | addr_str_len = ntohl (ua->addrlen); | 839 | addr_str_len = ntohl (ua->addrlen); |
849 | addr_option = ntohl (ua->options); | 840 | addr_option = ntohl (ua->options); |
850 | 841 | ||
851 | if ( (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && | 842 | if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && |
852 | (GNUNET_NO == plugin->is_abstract)) | 843 | (GNUNET_NO == plugin->is_abstract)) |
853 | { | 844 | { |
854 | return NULL; | 845 | return NULL; |
855 | } | 846 | } |
@@ -871,13 +862,12 @@ unix_plugin_get_session (void *cls, | |||
871 | } | 862 | } |
872 | 863 | ||
873 | /* Check if a session for this address already exists */ | 864 | /* Check if a session for this address already exists */ |
874 | if (NULL != (session = lookup_session (plugin, | 865 | if (NULL != (session = lookup_session (plugin, address))) |
875 | address))) | 866 | { |
876 | { | ||
877 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 867 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
878 | "Found existing session %p for address `%s'\n", | 868 | "Found existing session %p for address `%s'\n", |
879 | session, | 869 | session, |
880 | unix_plugin_address_to_string (NULL, | 870 | unix_plugin_address_to_string (NULL, |
881 | address->address, | 871 | address->address, |
882 | address->address_length)); | 872 | address->address_length)); |
883 | return session; | 873 | return session; |
@@ -888,29 +878,30 @@ unix_plugin_get_session (void *cls, | |||
888 | session->target = address->peer; | 878 | session->target = address->peer; |
889 | session->address = GNUNET_HELLO_address_copy (address); | 879 | session->address = GNUNET_HELLO_address_copy (address); |
890 | session->plugin = plugin; | 880 | session->plugin = plugin; |
891 | session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 881 | session->timeout = |
892 | session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 882 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
893 | &session_timeout, | 883 | session->timeout_task = |
894 | session); | 884 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
885 | &session_timeout, | ||
886 | session); | ||
895 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 887 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
896 | "Creating a new session %p for address `%s'\n", | 888 | "Creating a new session %p for address `%s'\n", |
897 | session, | 889 | session, |
898 | unix_plugin_address_to_string (NULL, | 890 | unix_plugin_address_to_string (NULL, |
899 | address->address, | 891 | address->address, |
900 | address->address_length)); | 892 | address->address_length)); |
901 | (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map, | 893 | (void) GNUNET_CONTAINER_multipeermap_put ( |
902 | &address->peer, session, | 894 | plugin->session_map, |
903 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 895 | &address->peer, |
896 | session, | ||
897 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
904 | GNUNET_STATISTICS_set (plugin->env->stats, | 898 | GNUNET_STATISTICS_set (plugin->env->stats, |
905 | "# UNIX sessions active", | 899 | "# UNIX sessions active", |
906 | GNUNET_CONTAINER_multipeermap_size (plugin->session_map), | 900 | GNUNET_CONTAINER_multipeermap_size ( |
907 | GNUNET_NO); | 901 | plugin->session_map), |
908 | notify_session_monitor (plugin, | 902 | GNUNET_NO); |
909 | session, | 903 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); |
910 | GNUNET_TRANSPORT_SS_INIT); | 904 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); |
911 | notify_session_monitor (plugin, | ||
912 | session, | ||
913 | GNUNET_TRANSPORT_SS_UP); | ||
914 | return session; | 905 | return session; |
915 | } | 906 | } |
916 | 907 | ||
@@ -967,15 +958,17 @@ unix_demultiplexer (struct Plugin *plugin, | |||
967 | "Received message from %s\n", | 958 | "Received message from %s\n", |
968 | unix_plugin_address_to_string (NULL, ua, ua_len)); | 959 | unix_plugin_address_to_string (NULL, ua, ua_len)); |
969 | GNUNET_STATISTICS_update (plugin->env->stats, | 960 | GNUNET_STATISTICS_update (plugin->env->stats, |
970 | "# bytes received via UNIX", | 961 | "# bytes received via UNIX", |
971 | ntohs (currhdr->size), | 962 | ntohs (currhdr->size), |
972 | GNUNET_NO); | 963 | GNUNET_NO); |
973 | 964 | ||
974 | /* Look for existing session */ | 965 | /* Look for existing session */ |
975 | address = GNUNET_HELLO_address_allocate (sender, | 966 | address = GNUNET_HELLO_address_allocate ( |
976 | PLUGIN_NAME, | 967 | sender, |
977 | ua, ua_len, | 968 | PLUGIN_NAME, |
978 | GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ | 969 | ua, |
970 | ua_len, | ||
971 | GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ | ||
979 | session = lookup_session (plugin, address); | 972 | session = lookup_session (plugin, address); |
980 | if (NULL == session) | 973 | if (NULL == session) |
981 | { | 974 | { |
@@ -991,10 +984,7 @@ unix_demultiplexer (struct Plugin *plugin, | |||
991 | reschedule_session_timeout (session); | 984 | reschedule_session_timeout (session); |
992 | } | 985 | } |
993 | GNUNET_HELLO_address_free (address); | 986 | GNUNET_HELLO_address_free (address); |
994 | plugin->env->receive (plugin->env->cls, | 987 | plugin->env->receive (plugin->env->cls, session->address, session, currhdr); |
995 | session->address, | ||
996 | session, | ||
997 | currhdr); | ||
998 | } | 988 | } |
999 | 989 | ||
1000 | 990 | ||
@@ -1024,23 +1014,23 @@ unix_plugin_do_read (struct Plugin *plugin) | |||
1024 | addrlen = sizeof (un); | 1014 | addrlen = sizeof (un); |
1025 | memset (&un, 0, sizeof (un)); | 1015 | memset (&un, 0, sizeof (un)); |
1026 | ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, | 1016 | ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, |
1027 | buf, sizeof (buf), | 1017 | buf, |
1018 | sizeof (buf), | ||
1028 | (struct sockaddr *) &un, | 1019 | (struct sockaddr *) &un, |
1029 | &addrlen); | 1020 | &addrlen); |
1030 | if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) | 1021 | if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) |
1031 | return; | 1022 | return; |
1032 | if (GNUNET_SYSERR == ret) | 1023 | if (GNUNET_SYSERR == ret) |
1033 | { | 1024 | { |
1034 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 1025 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); |
1035 | "recvfrom"); | ||
1036 | return; | 1026 | return; |
1037 | } | 1027 | } |
1038 | else | 1028 | else |
1039 | { | 1029 | { |
1040 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1030 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1041 | "Read %d bytes from socket %s\n", | 1031 | "Read %d bytes from socket %s\n", |
1042 | (int) ret, | 1032 | (int) ret, |
1043 | un.sun_path); | 1033 | un.sun_path); |
1044 | } | 1034 | } |
1045 | 1035 | ||
1046 | GNUNET_assert (AF_UNIX == (un.sun_family)); | 1036 | GNUNET_assert (AF_UNIX == (un.sun_family)); |
@@ -1053,12 +1043,12 @@ unix_plugin_do_read (struct Plugin *plugin) | |||
1053 | 1043 | ||
1054 | ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1; | 1044 | ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1; |
1055 | ua = GNUNET_malloc (ua_len); | 1045 | ua = GNUNET_malloc (ua_len); |
1056 | ua->addrlen = htonl (strlen (&un.sun_path[0]) +1); | 1046 | ua->addrlen = htonl (strlen (&un.sun_path[0]) + 1); |
1057 | GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); | 1047 | GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); |
1058 | if (is_abstract) | 1048 | if (is_abstract) |
1059 | ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); | 1049 | ua->options = htonl (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); |
1060 | else | 1050 | else |
1061 | ua->options = htonl(UNIX_OPTIONS_NONE); | 1051 | ua->options = htonl (UNIX_OPTIONS_NONE); |
1062 | 1052 | ||
1063 | msg = (struct UNIXMessage *) buf; | 1053 | msg = (struct UNIXMessage *) buf; |
1064 | csize = ntohs (msg->header.size); | 1054 | csize = ntohs (msg->header.size); |
@@ -1069,9 +1059,7 @@ unix_plugin_do_read (struct Plugin *plugin) | |||
1069 | return; | 1059 | return; |
1070 | } | 1060 | } |
1071 | msgbuf = (char *) &msg[1]; | 1061 | msgbuf = (char *) &msg[1]; |
1072 | GNUNET_memcpy (&sender, | 1062 | GNUNET_memcpy (&sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); |
1073 | &msg->sender, | ||
1074 | sizeof (struct GNUNET_PeerIdentity)); | ||
1075 | offset = 0; | 1063 | offset = 0; |
1076 | tsize = csize - sizeof (struct UNIXMessage); | 1064 | tsize = csize - sizeof (struct UNIXMessage); |
1077 | while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) | 1065 | while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) |
@@ -1113,11 +1101,9 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1113 | /* Message has a timeout */ | 1101 | /* Message has a timeout */ |
1114 | did_delete = GNUNET_YES; | 1102 | did_delete = GNUNET_YES; |
1115 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1103 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1116 | "Timeout for message with %u bytes \n", | 1104 | "Timeout for message with %u bytes \n", |
1117 | (unsigned int) msgw->msgsize); | 1105 | (unsigned int) msgw->msgsize); |
1118 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, | 1106 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); |
1119 | plugin->msg_tail, | ||
1120 | msgw); | ||
1121 | session = msgw->session; | 1107 | session = msgw->session; |
1122 | session->msgs_in_queue--; | 1108 | session->msgs_in_queue--; |
1123 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 1109 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); |
@@ -1125,28 +1111,26 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1125 | GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); | 1111 | GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); |
1126 | plugin->bytes_in_queue -= msgw->msgsize; | 1112 | plugin->bytes_in_queue -= msgw->msgsize; |
1127 | GNUNET_STATISTICS_set (plugin->env->stats, | 1113 | GNUNET_STATISTICS_set (plugin->env->stats, |
1128 | "# bytes currently in UNIX buffers", | 1114 | "# bytes currently in UNIX buffers", |
1129 | plugin->bytes_in_queue, | 1115 | plugin->bytes_in_queue, |
1130 | GNUNET_NO); | 1116 | GNUNET_NO); |
1131 | GNUNET_STATISTICS_update (plugin->env->stats, | 1117 | GNUNET_STATISTICS_update (plugin->env->stats, |
1132 | "# UNIX bytes discarded", | 1118 | "# UNIX bytes discarded", |
1133 | msgw->msgsize, | 1119 | msgw->msgsize, |
1134 | GNUNET_NO); | 1120 | GNUNET_NO); |
1135 | if (NULL != msgw->cont) | 1121 | if (NULL != msgw->cont) |
1136 | msgw->cont (msgw->cont_cls, | 1122 | msgw->cont (msgw->cont_cls, |
1137 | &msgw->session->target, | 1123 | &msgw->session->target, |
1138 | GNUNET_SYSERR, | 1124 | GNUNET_SYSERR, |
1139 | msgw->payload, | 1125 | msgw->payload, |
1140 | 0); | 1126 | 0); |
1141 | GNUNET_free (msgw->msg); | 1127 | GNUNET_free (msgw->msg); |
1142 | GNUNET_free (msgw); | 1128 | GNUNET_free (msgw); |
1143 | } | 1129 | } |
1144 | if (NULL == msgw) | 1130 | if (NULL == msgw) |
1145 | { | 1131 | { |
1146 | if (GNUNET_YES == did_delete) | 1132 | if (GNUNET_YES == did_delete) |
1147 | notify_session_monitor (plugin, | 1133 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1148 | session, | ||
1149 | GNUNET_TRANSPORT_SS_UPDATE); | ||
1150 | return; /* Nothing to send at the moment */ | 1134 | return; /* Nothing to send at the moment */ |
1151 | } | 1135 | } |
1152 | session = msgw->session; | 1136 | session = msgw->session; |
@@ -1160,20 +1144,18 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1160 | msgw->session->address->address, | 1144 | msgw->session->address->address, |
1161 | msgw->session->address->address_length, | 1145 | msgw->session->address->address_length, |
1162 | msgw->payload, | 1146 | msgw->payload, |
1163 | msgw->cont, msgw->cont_cls); | 1147 | msgw->cont, |
1148 | msgw->cont_cls); | ||
1164 | if (RETRY == sent) | 1149 | if (RETRY == sent) |
1165 | { | 1150 | { |
1166 | GNUNET_STATISTICS_update (plugin->env->stats, | 1151 | GNUNET_STATISTICS_update (plugin->env->stats, |
1167 | "# UNIX retry attempts", | 1152 | "# UNIX retry attempts", |
1168 | 1, GNUNET_NO); | 1153 | 1, |
1169 | notify_session_monitor (plugin, | 1154 | GNUNET_NO); |
1170 | session, | 1155 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1171 | GNUNET_TRANSPORT_SS_UPDATE); | ||
1172 | return; | 1156 | return; |
1173 | } | 1157 | } |
1174 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, | 1158 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); |
1175 | plugin->msg_tail, | ||
1176 | msgw); | ||
1177 | session->msgs_in_queue--; | 1159 | session->msgs_in_queue--; |
1178 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 1160 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); |
1179 | session->bytes_in_queue -= msgw->msgsize; | 1161 | session->bytes_in_queue -= msgw->msgsize; |
@@ -1181,10 +1163,9 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1181 | plugin->bytes_in_queue -= msgw->msgsize; | 1163 | plugin->bytes_in_queue -= msgw->msgsize; |
1182 | GNUNET_STATISTICS_set (plugin->env->stats, | 1164 | GNUNET_STATISTICS_set (plugin->env->stats, |
1183 | "# bytes currently in UNIX buffers", | 1165 | "# bytes currently in UNIX buffers", |
1184 | plugin->bytes_in_queue, GNUNET_NO); | 1166 | plugin->bytes_in_queue, |
1185 | notify_session_monitor (plugin, | 1167 | GNUNET_NO); |
1186 | session, | 1168 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1187 | GNUNET_TRANSPORT_SS_UPDATE); | ||
1188 | if (GNUNET_SYSERR == sent) | 1169 | if (GNUNET_SYSERR == sent) |
1189 | { | 1170 | { |
1190 | /* failed and no retry */ | 1171 | /* failed and no retry */ |
@@ -1192,11 +1173,12 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1192 | msgw->cont (msgw->cont_cls, | 1173 | msgw->cont (msgw->cont_cls, |
1193 | &msgw->session->target, | 1174 | &msgw->session->target, |
1194 | GNUNET_SYSERR, | 1175 | GNUNET_SYSERR, |
1195 | msgw->payload, 0); | 1176 | msgw->payload, |
1177 | 0); | ||
1196 | GNUNET_STATISTICS_update (plugin->env->stats, | 1178 | GNUNET_STATISTICS_update (plugin->env->stats, |
1197 | "# UNIX bytes discarded", | 1179 | "# UNIX bytes discarded", |
1198 | msgw->msgsize, | 1180 | msgw->msgsize, |
1199 | GNUNET_NO); | 1181 | GNUNET_NO); |
1200 | GNUNET_free (msgw->msg); | 1182 | GNUNET_free (msgw->msg); |
1201 | GNUNET_free (msgw); | 1183 | GNUNET_free (msgw); |
1202 | return; | 1184 | return; |
@@ -1204,15 +1186,15 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1204 | /* successfully sent bytes */ | 1186 | /* successfully sent bytes */ |
1205 | GNUNET_break (sent > 0); | 1187 | GNUNET_break (sent > 0); |
1206 | GNUNET_STATISTICS_update (plugin->env->stats, | 1188 | GNUNET_STATISTICS_update (plugin->env->stats, |
1207 | "# bytes transmitted via UNIX", | 1189 | "# bytes transmitted via UNIX", |
1208 | msgw->msgsize, | 1190 | msgw->msgsize, |
1209 | GNUNET_NO); | 1191 | GNUNET_NO); |
1210 | if (NULL != msgw->cont) | 1192 | if (NULL != msgw->cont) |
1211 | msgw->cont (msgw->cont_cls, | 1193 | msgw->cont (msgw->cont_cls, |
1212 | &msgw->session->target, | 1194 | &msgw->session->target, |
1213 | GNUNET_OK, | 1195 | GNUNET_OK, |
1214 | msgw->payload, | 1196 | msgw->payload, |
1215 | msgw->msgsize); | 1197 | msgw->msgsize); |
1216 | GNUNET_free (msgw->msg); | 1198 | GNUNET_free (msgw->msg); |
1217 | GNUNET_free (msgw); | 1199 | GNUNET_free (msgw); |
1218 | } | 1200 | } |
@@ -1237,7 +1219,8 @@ unix_plugin_select_read (void *cls) | |||
1237 | plugin->read_task = | 1219 | plugin->read_task = |
1238 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1220 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1239 | plugin->unix_sock.desc, | 1221 | plugin->unix_sock.desc, |
1240 | &unix_plugin_select_read, plugin); | 1222 | &unix_plugin_select_read, |
1223 | plugin); | ||
1241 | } | 1224 | } |
1242 | 1225 | ||
1243 | 1226 | ||
@@ -1262,7 +1245,8 @@ unix_plugin_select_write (void *cls) | |||
1262 | plugin->write_task = | 1245 | plugin->write_task = |
1263 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1246 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1264 | plugin->unix_sock.desc, | 1247 | plugin->unix_sock.desc, |
1265 | &unix_plugin_select_write, plugin); | 1248 | &unix_plugin_select_write, |
1249 | plugin); | ||
1266 | } | 1250 | } |
1267 | 1251 | ||
1268 | 1252 | ||
@@ -1310,13 +1294,13 @@ unix_plugin_send (void *cls, | |||
1310 | 1294 | ||
1311 | if (GNUNET_OK != | 1295 | if (GNUNET_OK != |
1312 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, | 1296 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, |
1313 | &session->target, | 1297 | &session->target, |
1314 | session)) | 1298 | session)) |
1315 | { | 1299 | { |
1316 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1300 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1317 | "Invalid session for peer `%s' `%s'\n", | 1301 | "Invalid session for peer `%s' `%s'\n", |
1318 | GNUNET_i2s (&session->target), | 1302 | GNUNET_i2s (&session->target), |
1319 | unix_plugin_address_to_string (NULL, | 1303 | unix_plugin_address_to_string (NULL, |
1320 | session->address->address, | 1304 | session->address->address, |
1321 | session->address->address_length)); | 1305 | session->address->address_length)); |
1322 | GNUNET_break (0); | 1306 | GNUNET_break (0); |
@@ -1333,16 +1317,16 @@ unix_plugin_send (void *cls, | |||
1333 | message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); | 1317 | message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); |
1334 | message->header.size = htons (ssize); | 1318 | message->header.size = htons (ssize); |
1335 | message->header.type = htons (0); | 1319 | message->header.type = htons (0); |
1336 | GNUNET_memcpy (&message->sender, plugin->env->my_identity, | 1320 | GNUNET_memcpy (&message->sender, |
1337 | sizeof (struct GNUNET_PeerIdentity)); | 1321 | plugin->env->my_identity, |
1322 | sizeof (struct GNUNET_PeerIdentity)); | ||
1338 | GNUNET_memcpy (&message[1], msgbuf, msgbuf_size); | 1323 | GNUNET_memcpy (&message[1], msgbuf, msgbuf_size); |
1339 | wrapper = GNUNET_new (struct UNIXMessageWrapper); | 1324 | wrapper = GNUNET_new (struct UNIXMessageWrapper); |
1340 | wrapper->msg = message; | 1325 | wrapper->msg = message; |
1341 | wrapper->msgsize = ssize; | 1326 | wrapper->msgsize = ssize; |
1342 | wrapper->payload = msgbuf_size; | 1327 | wrapper->payload = msgbuf_size; |
1343 | wrapper->priority = priority; | 1328 | wrapper->priority = priority; |
1344 | wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | 1329 | wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to); |
1345 | to); | ||
1346 | wrapper->cont = cont; | 1330 | wrapper->cont = cont; |
1347 | wrapper->cont_cls = cont_cls; | 1331 | wrapper->cont_cls = cont_cls; |
1348 | wrapper->session = session; | 1332 | wrapper->session = session; |
@@ -1353,17 +1337,16 @@ unix_plugin_send (void *cls, | |||
1353 | session->bytes_in_queue += ssize; | 1337 | session->bytes_in_queue += ssize; |
1354 | session->msgs_in_queue++; | 1338 | session->msgs_in_queue++; |
1355 | GNUNET_STATISTICS_set (plugin->env->stats, | 1339 | GNUNET_STATISTICS_set (plugin->env->stats, |
1356 | "# bytes currently in UNIX buffers", | 1340 | "# bytes currently in UNIX buffers", |
1357 | plugin->bytes_in_queue, | 1341 | plugin->bytes_in_queue, |
1358 | GNUNET_NO); | 1342 | GNUNET_NO); |
1359 | notify_session_monitor (plugin, | 1343 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1360 | session, | ||
1361 | GNUNET_TRANSPORT_SS_UPDATE); | ||
1362 | if (NULL == plugin->write_task) | 1344 | if (NULL == plugin->write_task) |
1363 | plugin->write_task = | 1345 | plugin->write_task = |
1364 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1346 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1365 | plugin->unix_sock.desc, | 1347 | plugin->unix_sock.desc, |
1366 | &unix_plugin_select_write, plugin); | 1348 | &unix_plugin_select_write, |
1349 | plugin); | ||
1367 | return ssize; | 1350 | return ssize; |
1368 | } | 1351 | } |
1369 | 1352 | ||
@@ -1381,15 +1364,14 @@ unix_transport_server_start (void *cls) | |||
1381 | struct sockaddr_un *un; | 1364 | struct sockaddr_un *un; |
1382 | socklen_t un_len; | 1365 | socklen_t un_len; |
1383 | 1366 | ||
1384 | un = unix_address_to_sockaddr (plugin->unix_socket_path, | 1367 | un = unix_address_to_sockaddr (plugin->unix_socket_path, &un_len); |
1385 | &un_len); | ||
1386 | if (GNUNET_YES == plugin->is_abstract) | 1368 | if (GNUNET_YES == plugin->is_abstract) |
1387 | { | 1369 | { |
1388 | plugin->unix_socket_path[0] = '@'; | 1370 | plugin->unix_socket_path[0] = '@'; |
1389 | un->sun_path[0] = '\0'; | 1371 | un->sun_path[0] = '\0'; |
1390 | } | 1372 | } |
1391 | plugin->unix_sock.desc = | 1373 | plugin->unix_sock.desc = |
1392 | GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); | 1374 | GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); |
1393 | if (NULL == plugin->unix_sock.desc) | 1375 | if (NULL == plugin->unix_sock.desc) |
1394 | { | 1376 | { |
1395 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 1377 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
@@ -1400,33 +1382,32 @@ unix_transport_server_start (void *cls) | |||
1400 | { | 1382 | { |
1401 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path)) | 1383 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path)) |
1402 | { | 1384 | { |
1403 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot create path to `%s'\n"), | 1385 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1404 | un->sun_path); | 1386 | _ ("Cannot create path to `%s'\n"), |
1387 | un->sun_path); | ||
1405 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); | 1388 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); |
1406 | plugin->unix_sock.desc = NULL; | 1389 | plugin->unix_sock.desc = NULL; |
1407 | GNUNET_free (un); | 1390 | GNUNET_free (un); |
1408 | return GNUNET_SYSERR; | 1391 | return GNUNET_SYSERR; |
1409 | } | 1392 | } |
1410 | } | 1393 | } |
1411 | if (GNUNET_OK != | 1394 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, |
1412 | GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, | 1395 | (const struct sockaddr *) un, |
1413 | (const struct sockaddr *) un, un_len)) | 1396 | un_len)) |
1414 | { | 1397 | { |
1415 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 1398 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); |
1416 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot bind to `%s'\n"), | 1399 | LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot bind to `%s'\n"), un->sun_path); |
1417 | un->sun_path); | ||
1418 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); | 1400 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); |
1419 | plugin->unix_sock.desc = NULL; | 1401 | plugin->unix_sock.desc = NULL; |
1420 | GNUNET_free (un); | 1402 | GNUNET_free (un); |
1421 | return GNUNET_SYSERR; | 1403 | return GNUNET_SYSERR; |
1422 | } | 1404 | } |
1423 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1405 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path); |
1424 | "Bound to `%s'\n", | ||
1425 | plugin->unix_socket_path); | ||
1426 | plugin->read_task = | 1406 | plugin->read_task = |
1427 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1407 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1428 | plugin->unix_sock.desc, | 1408 | plugin->unix_sock.desc, |
1429 | &unix_plugin_select_read, plugin); | 1409 | &unix_plugin_select_read, |
1410 | plugin); | ||
1430 | GNUNET_free (un); | 1411 | GNUNET_free (un); |
1431 | return 1; | 1412 | return 1; |
1432 | } | 1413 | } |
@@ -1449,18 +1430,15 @@ unix_transport_server_start (void *cls) | |||
1449 | * | 1430 | * |
1450 | */ | 1431 | */ |
1451 | static int | 1432 | static int |
1452 | unix_plugin_check_address (void *cls, | 1433 | unix_plugin_check_address (void *cls, const void *addr, size_t addrlen) |
1453 | const void *addr, | ||
1454 | size_t addrlen) | ||
1455 | { | 1434 | { |
1456 | struct Plugin* plugin = cls; | 1435 | struct Plugin *plugin = cls; |
1457 | const struct UnixAddress *ua = addr; | 1436 | const struct UnixAddress *ua = addr; |
1458 | char *addrstr; | 1437 | char *addrstr; |
1459 | size_t addr_str_len; | 1438 | size_t addr_str_len; |
1460 | 1439 | ||
1461 | if ( (NULL == addr) || | 1440 | if ((NULL == addr) || (0 == addrlen) || |
1462 | (0 == addrlen) || | 1441 | (sizeof (struct UnixAddress) > addrlen)) |
1463 | (sizeof (struct UnixAddress) > addrlen) ) | ||
1464 | { | 1442 | { |
1465 | GNUNET_break (0); | 1443 | GNUNET_break (0); |
1466 | return GNUNET_SYSERR; | 1444 | return GNUNET_SYSERR; |
@@ -1479,7 +1457,7 @@ unix_plugin_check_address (void *cls, | |||
1479 | } | 1457 | } |
1480 | 1458 | ||
1481 | if (0 == strcmp (plugin->unix_socket_path, addrstr)) | 1459 | if (0 == strcmp (plugin->unix_socket_path, addrstr)) |
1482 | return GNUNET_OK; | 1460 | return GNUNET_OK; |
1483 | return GNUNET_SYSERR; | 1461 | return GNUNET_SYSERR; |
1484 | } | 1462 | } |
1485 | 1463 | ||
@@ -1499,7 +1477,8 @@ unix_plugin_check_address (void *cls, | |||
1499 | * @param asc_cls closure for @a asc | 1477 | * @param asc_cls closure for @a asc |
1500 | */ | 1478 | */ |
1501 | static void | 1479 | static void |
1502 | unix_plugin_address_pretty_printer (void *cls, const char *type, | 1480 | unix_plugin_address_pretty_printer (void *cls, |
1481 | const char *type, | ||
1503 | const void *addr, | 1482 | const void *addr, |
1504 | size_t addrlen, | 1483 | size_t addrlen, |
1505 | int numeric, | 1484 | int numeric, |
@@ -1509,15 +1488,11 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, | |||
1509 | { | 1488 | { |
1510 | const char *ret; | 1489 | const char *ret; |
1511 | 1490 | ||
1512 | if ( (NULL != addr) && (addrlen > 0)) | 1491 | if ((NULL != addr) && (addrlen > 0)) |
1513 | ret = unix_plugin_address_to_string (NULL, | 1492 | ret = unix_plugin_address_to_string (NULL, addr, addrlen); |
1514 | addr, | ||
1515 | addrlen); | ||
1516 | else | 1493 | else |
1517 | ret = NULL; | 1494 | ret = NULL; |
1518 | asc (asc_cls, | 1495 | asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); |
1519 | ret, | ||
1520 | (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); | ||
1521 | asc (asc_cls, NULL, GNUNET_OK); | 1496 | asc (asc_cls, NULL, GNUNET_OK); |
1522 | } | 1497 | } |
1523 | 1498 | ||
@@ -1538,7 +1513,8 @@ static int | |||
1538 | unix_plugin_string_to_address (void *cls, | 1513 | unix_plugin_string_to_address (void *cls, |
1539 | const char *addr, | 1514 | const char *addr, |
1540 | uint16_t addrlen, | 1515 | uint16_t addrlen, |
1541 | void **buf, size_t *added) | 1516 | void **buf, |
1517 | size_t *added) | ||
1542 | { | 1518 | { |
1543 | struct UnixAddress *ua; | 1519 | struct UnixAddress *ua; |
1544 | char *address; | 1520 | char *address; |
@@ -1587,7 +1563,7 @@ unix_plugin_string_to_address (void *cls, | |||
1587 | } | 1563 | } |
1588 | address[0] = '\0'; | 1564 | address[0] = '\0'; |
1589 | address++; | 1565 | address++; |
1590 | if (0 != strcmp(plugin, PLUGIN_NAME)) | 1566 | if (0 != strcmp (plugin, PLUGIN_NAME)) |
1591 | { | 1567 | { |
1592 | GNUNET_break (0); | 1568 | GNUNET_break (0); |
1593 | GNUNET_free (plugin); | 1569 | GNUNET_free (plugin); |
@@ -1624,9 +1600,11 @@ address_notification (void *cls) | |||
1624 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; | 1600 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; |
1625 | ua = GNUNET_malloc (len); | 1601 | ua = GNUNET_malloc (len); |
1626 | ua->options = htonl (plugin->myoptions); | 1602 | ua->options = htonl (plugin->myoptions); |
1627 | ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); | 1603 | ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1); |
1628 | unix_path = (char *) &ua[1]; | 1604 | unix_path = (char *) &ua[1]; |
1629 | GNUNET_memcpy (unix_path, plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); | 1605 | GNUNET_memcpy (unix_path, |
1606 | plugin->unix_socket_path, | ||
1607 | strlen (plugin->unix_socket_path) + 1); | ||
1630 | 1608 | ||
1631 | plugin->address_update_task = NULL; | 1609 | plugin->address_update_task = NULL; |
1632 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 1610 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
@@ -1634,9 +1612,7 @@ address_notification (void *cls) | |||
1634 | ua, | 1612 | ua, |
1635 | len, | 1613 | len, |
1636 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 1614 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1637 | plugin->env->notify_address (plugin->env->cls, | 1615 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); |
1638 | GNUNET_YES, | ||
1639 | address); | ||
1640 | GNUNET_free (ua); | 1616 | GNUNET_free (ua); |
1641 | GNUNET_free (address); | 1617 | GNUNET_free (address); |
1642 | } | 1618 | } |
@@ -1652,8 +1628,8 @@ address_notification (void *cls) | |||
1652 | */ | 1628 | */ |
1653 | static int | 1629 | static int |
1654 | get_session_delete_it (void *cls, | 1630 | get_session_delete_it (void *cls, |
1655 | const struct GNUNET_PeerIdentity *key, | 1631 | const struct GNUNET_PeerIdentity *key, |
1656 | void *value) | 1632 | void *value) |
1657 | { | 1633 | { |
1658 | struct Plugin *plugin = cls; | 1634 | struct Plugin *plugin = cls; |
1659 | struct GNUNET_ATS_Session *session = value; | 1635 | struct GNUNET_ATS_Session *session = value; |
@@ -1677,8 +1653,9 @@ unix_plugin_peer_disconnect (void *cls, | |||
1677 | struct Plugin *plugin = cls; | 1653 | struct Plugin *plugin = cls; |
1678 | 1654 | ||
1679 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, | 1655 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, |
1680 | target, | 1656 | target, |
1681 | &get_session_delete_it, plugin); | 1657 | &get_session_delete_it, |
1658 | plugin); | ||
1682 | } | 1659 | } |
1683 | 1660 | ||
1684 | 1661 | ||
@@ -1699,12 +1676,8 @@ send_session_info_iter (void *cls, | |||
1699 | struct Plugin *plugin = cls; | 1676 | struct Plugin *plugin = cls; |
1700 | struct GNUNET_ATS_Session *session = value; | 1677 | struct GNUNET_ATS_Session *session = value; |
1701 | 1678 | ||
1702 | notify_session_monitor (plugin, | 1679 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); |
1703 | session, | 1680 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); |
1704 | GNUNET_TRANSPORT_SS_INIT); | ||
1705 | notify_session_monitor (plugin, | ||
1706 | session, | ||
1707 | GNUNET_TRANSPORT_SS_UP); | ||
1708 | return GNUNET_OK; | 1681 | return GNUNET_OK; |
1709 | } | 1682 | } |
1710 | 1683 | ||
@@ -1786,9 +1759,10 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1786 | 1759 | ||
1787 | /* Initialize my flags */ | 1760 | /* Initialize my flags */ |
1788 | #ifdef LINUX | 1761 | #ifdef LINUX |
1789 | plugin->is_abstract = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 1762 | plugin->is_abstract = |
1790 | "testing", | 1763 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, |
1791 | "USE_ABSTRACT_SOCKETS"); | 1764 | "testing", |
1765 | "USE_ABSTRACT_SOCKETS"); | ||
1792 | #endif | 1766 | #endif |
1793 | plugin->myoptions = UNIX_OPTIONS_NONE; | 1767 | plugin->myoptions = UNIX_OPTIONS_NONE; |
1794 | if (GNUNET_YES == plugin->is_abstract) | 1768 | if (GNUNET_YES == plugin->is_abstract) |
@@ -1812,16 +1786,15 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1812 | sockets_created = unix_transport_server_start (plugin); | 1786 | sockets_created = unix_transport_server_start (plugin); |
1813 | if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) | 1787 | if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) |
1814 | { | 1788 | { |
1815 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1789 | LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UNIX listen socket\n")); |
1816 | _("Failed to open UNIX listen socket\n")); | ||
1817 | GNUNET_free (api); | 1790 | GNUNET_free (api); |
1818 | GNUNET_free (plugin->unix_socket_path); | 1791 | GNUNET_free (plugin->unix_socket_path); |
1819 | GNUNET_free (plugin); | 1792 | GNUNET_free (plugin); |
1820 | return NULL; | 1793 | return NULL; |
1821 | } | 1794 | } |
1822 | plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 1795 | plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
1823 | plugin->address_update_task = GNUNET_SCHEDULER_add_now (&address_notification, | 1796 | plugin->address_update_task = |
1824 | plugin); | 1797 | GNUNET_SCHEDULER_add_now (&address_notification, plugin); |
1825 | return api; | 1798 | return api; |
1826 | } | 1799 | } |
1827 | 1800 | ||
@@ -1838,7 +1811,7 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1838 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 1811 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
1839 | struct Plugin *plugin = api->cls; | 1812 | struct Plugin *plugin = api->cls; |
1840 | struct GNUNET_HELLO_Address *address; | 1813 | struct GNUNET_HELLO_Address *address; |
1841 | struct UNIXMessageWrapper * msgw; | 1814 | struct UNIXMessageWrapper *msgw; |
1842 | struct UnixAddress *ua; | 1815 | struct UnixAddress *ua; |
1843 | size_t len; | 1816 | size_t len; |
1844 | struct GNUNET_ATS_Session *session; | 1817 | struct GNUNET_ATS_Session *session; |
@@ -1851,26 +1824,23 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1851 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; | 1824 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; |
1852 | ua = GNUNET_malloc (len); | 1825 | ua = GNUNET_malloc (len); |
1853 | ua->options = htonl (plugin->myoptions); | 1826 | ua->options = htonl (plugin->myoptions); |
1854 | ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); | 1827 | ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1); |
1855 | GNUNET_memcpy (&ua[1], | 1828 | GNUNET_memcpy (&ua[1], |
1856 | plugin->unix_socket_path, | 1829 | plugin->unix_socket_path, |
1857 | strlen (plugin->unix_socket_path) + 1); | 1830 | strlen (plugin->unix_socket_path) + 1); |
1858 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 1831 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1859 | PLUGIN_NAME, | 1832 | PLUGIN_NAME, |
1860 | ua, len, | 1833 | ua, |
1834 | len, | ||
1861 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 1835 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1862 | plugin->env->notify_address (plugin->env->cls, | 1836 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); |
1863 | GNUNET_NO, | ||
1864 | address); | ||
1865 | 1837 | ||
1866 | GNUNET_free (address); | 1838 | GNUNET_free (address); |
1867 | GNUNET_free (ua); | 1839 | GNUNET_free (ua); |
1868 | 1840 | ||
1869 | while (NULL != (msgw = plugin->msg_head)) | 1841 | while (NULL != (msgw = plugin->msg_head)) |
1870 | { | 1842 | { |
1871 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, | 1843 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); |
1872 | plugin->msg_tail, | ||
1873 | msgw); | ||
1874 | session = msgw->session; | 1844 | session = msgw->session; |
1875 | session->msgs_in_queue--; | 1845 | session->msgs_in_queue--; |
1876 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 1846 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); |
@@ -1881,7 +1851,8 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1881 | msgw->cont (msgw->cont_cls, | 1851 | msgw->cont (msgw->cont_cls, |
1882 | &msgw->session->target, | 1852 | &msgw->session->target, |
1883 | GNUNET_SYSERR, | 1853 | GNUNET_SYSERR, |
1884 | msgw->payload, 0); | 1854 | msgw->payload, |
1855 | 0); | ||
1885 | GNUNET_free (msgw->msg); | 1856 | GNUNET_free (msgw->msg); |
1886 | GNUNET_free (msgw); | 1857 | GNUNET_free (msgw); |
1887 | } | 1858 | } |
@@ -1908,7 +1879,7 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1908 | plugin->unix_sock.desc = NULL; | 1879 | plugin->unix_sock.desc = NULL; |
1909 | } | 1880 | } |
1910 | GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, | 1881 | GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, |
1911 | &get_session_delete_it, | 1882 | &get_session_delete_it, |
1912 | plugin); | 1883 | plugin); |
1913 | GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map); | 1884 | GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map); |
1914 | GNUNET_break (0 == plugin->bytes_in_queue); | 1885 | GNUNET_break (0 == plugin->bytes_in_queue); |