aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-communicator-unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-communicator-unix.c')
-rw-r--r--src/transport/gnunet-communicator-unix.c117
1 files changed, 59 insertions, 58 deletions
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index d30acbd5f..642703f29 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -634,21 +634,21 @@ mq_error (void *cls,
634 */ 634 */
635static struct Queue * 635static struct Queue *
636setup_queue (const struct GNUNET_PeerIdentity *target, 636setup_queue (const struct GNUNET_PeerIdentity *target,
637 enum GNUNET_TRANSPORT_ConnectionStatus cs, 637 enum GNUNET_TRANSPORT_ConnectionStatus cs,
638 const struct sockaddr_un *un, 638 const struct sockaddr_un *un,
639 socklen_t un_len) 639 socklen_t un_len)
640{ 640{
641 struct Queue *queue; 641 struct Queue *queue;
642 642
643 queue = GNUNET_new (struct Queue); 643 queue = GNUNET_new (struct Queue);
644 queue->target = *target; 644 queue->target = *target;
645 queue->address = GNUNET_memdup (un, 645 queue->address = GNUNET_memdup (un,
646 un_len); 646 un_len);
647 queue->address_len = un_len; 647 queue->address_len = un_len;
648 (void) GNUNET_CONTAINER_multipeermap_put (queue_map, 648 (void) GNUNET_CONTAINER_multipeermap_put (queue_map,
649 &queue->target, 649 &queue->target,
650 queue, 650 queue,
651 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 651 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
652 GNUNET_STATISTICS_set (stats, 652 GNUNET_STATISTICS_set (stats,
653 "# queues active", 653 "# queues active",
654 GNUNET_CONTAINER_multipeermap_size (queue_map), 654 GNUNET_CONTAINER_multipeermap_size (queue_map),
@@ -656,37 +656,37 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
656 queue->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 656 queue->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
657 queue->timeout_task 657 queue->timeout_task
658 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 658 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
659 &queue_timeout, 659 &queue_timeout,
660 queue); 660 queue);
661 queue->mq 661 queue->mq
662 = GNUNET_MQ_queue_for_callbacks (&mq_send, 662 = GNUNET_MQ_queue_for_callbacks (&mq_send,
663 &mq_destroy, 663 &mq_destroy,
664 &mq_cancel, 664 &mq_cancel,
665 queue, 665 queue,
666 NULL, 666 NULL,
667 &mq_error, 667 &mq_error,
668 queue); 668 queue);
669 { 669 {
670 char *foreign_addr; 670 char *foreign_addr;
671 671
672 if ('\0' == un->sun_path[0]) 672 if ('\0' == un->sun_path[0])
673 GNUNET_asprintf (&foreign_addr, 673 GNUNET_asprintf (&foreign_addr,
674 "%s-@%s", 674 "%s-@%s",
675 COMMUNICATOR_ADDRESS_PREFIX, 675 COMMUNICATOR_ADDRESS_PREFIX,
676 &un->sun_path[1]); 676 &un->sun_path[1]);
677 else 677 else
678 GNUNET_asprintf (&foreign_addr, 678 GNUNET_asprintf (&foreign_addr,
679 "%s-%s", 679 "%s-%s",
680 COMMUNICATOR_ADDRESS_PREFIX, 680 COMMUNICATOR_ADDRESS_PREFIX,
681 un->sun_path); 681 un->sun_path);
682 queue->qh 682 queue->qh
683 = GNUNET_TRANSPORT_communicator_mq_add (ch, 683 = GNUNET_TRANSPORT_communicator_mq_add (ch,
684 &queue->target, 684 &queue->target,
685 foreign_addr, 685 foreign_addr,
686 UNIX_MTU, 686 UNIX_MTU,
687 GNUNET_NT_LOOPBACK, 687 GNUNET_NT_LOOPBACK,
688 cs, 688 cs,
689 queue->mq); 689 queue->mq);
690 GNUNET_free (foreign_addr); 690 GNUNET_free (foreign_addr);
691 } 691 }
692 return queue; 692 return queue;
@@ -718,16 +718,16 @@ receive_complete_cb (void *cls,
718 delivering_messages--; 718 delivering_messages--;
719 if (GNUNET_OK != success) 719 if (GNUNET_OK != success)
720 GNUNET_STATISTICS_update (stats, 720 GNUNET_STATISTICS_update (stats,
721 "# transport transmission failures", 721 "# transport transmission failures",
722 1, 722 1,
723 GNUNET_NO); 723 GNUNET_NO);
724 GNUNET_assert (NULL != unix_sock); 724 GNUNET_assert (NULL != unix_sock);
725 if ( (NULL == read_task) && 725 if ( (NULL == read_task) &&
726 (delivering_messages < max_queue_length) ) 726 (delivering_messages < max_queue_length) )
727 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 727 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
728 unix_sock, 728 unix_sock,
729 &select_read_cb, 729 &select_read_cb,
730 NULL); 730 NULL);
731} 731}
732 732
733 733
@@ -751,16 +751,16 @@ select_read_cb (void *cls)
751 751
752 GNUNET_assert (NULL != unix_sock); 752 GNUNET_assert (NULL != unix_sock);
753 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 753 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
754 unix_sock, 754 unix_sock,
755 &select_read_cb, 755 &select_read_cb,
756 NULL); 756 NULL);
757 addrlen = sizeof (un); 757 addrlen = sizeof (un);
758 memset (&un, 758 memset (&un,
759 0, 759 0,
760 sizeof (un)); 760 sizeof (un));
761 ret = GNUNET_NETWORK_socket_recvfrom (unix_sock, 761 ret = GNUNET_NETWORK_socket_recvfrom (unix_sock,
762 buf, 762 buf,
763 sizeof (buf), 763 sizeof (buf),
764 (struct sockaddr *) &un, 764 (struct sockaddr *) &un,
765 &addrlen); 765 &addrlen);
766 if ( (-1 == ret) && 766 if ( (-1 == ret) &&
@@ -774,9 +774,9 @@ select_read_cb (void *cls)
774 return; 774 return;
775 } 775 }
776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
777 "Read %d bytes from socket %s\n", 777 "Read %d bytes from socket %s\n",
778 (int) ret, 778 (int) ret,
779 un.sun_path); 779 un.sun_path);
780 GNUNET_assert (AF_UNIX == (un.sun_family)); 780 GNUNET_assert (AF_UNIX == (un.sun_family));
781 msg = (struct UNIXMessage *) buf; 781 msg = (struct UNIXMessage *) buf;
782 msize = ntohs (msg->header.size); 782 msize = ntohs (msg->header.size);
@@ -787,13 +787,13 @@ select_read_cb (void *cls)
787 return; 787 return;
788 } 788 }
789 queue = lookup_queue (&msg->sender, 789 queue = lookup_queue (&msg->sender,
790 &un, 790 &un,
791 addrlen); 791 addrlen);
792 if (NULL == queue) 792 if (NULL == queue)
793 queue = setup_queue (&msg->sender, 793 queue = setup_queue (&msg->sender,
794 GNUNET_TRANSPORT_CS_INBOUND, 794 GNUNET_TRANSPORT_CS_INBOUND,
795 &un, 795 &un,
796 addrlen); 796 addrlen);
797 else 797 else
798 reschedule_queue_timeout (queue); 798 reschedule_queue_timeout (queue);
799 if (NULL == queue) 799 if (NULL == queue)
@@ -821,16 +821,17 @@ select_read_cb (void *cls)
821 sizeof (al_hdr)); 821 sizeof (al_hdr));
822 csize = ntohs (al_hdr.size); 822 csize = ntohs (al_hdr.size);
823 if ( (csize < sizeof (struct GNUNET_MessageHeader)) || 823 if ( (csize < sizeof (struct GNUNET_MessageHeader)) ||
824 (csize > tsize - offset)) 824 (csize > tsize - offset))
825 { 825 {
826 GNUNET_break_op (0); 826 GNUNET_break_op (0);
827 break; 827 break;
828 } 828 }
829 ret = GNUNET_TRANSPORT_communicator_receive (ch, 829 ret = GNUNET_TRANSPORT_communicator_receive (ch,
830 &msg->sender, 830 &msg->sender,
831 currhdr, 831 currhdr,
832 &receive_complete_cb, 832 GNUNET_TIME_UNIT_FOREVER_REL,
833 NULL); 833 &receive_complete_cb,
834 NULL);
834 if (GNUNET_SYSERR == ret) 835 if (GNUNET_SYSERR == ret)
835 return; /* transport not up */ 836 return; /* transport not up */
836 if (GNUNET_NO == ret) 837 if (GNUNET_NO == ret)
@@ -898,16 +899,16 @@ mq_init (void *cls,
898 return GNUNET_OK; 899 return GNUNET_OK;
899 } 900 }
900 queue = setup_queue (peer, 901 queue = setup_queue (peer,
901 GNUNET_TRANSPORT_CS_OUTBOUND, 902 GNUNET_TRANSPORT_CS_OUTBOUND,
902 un, 903 un,
903 un_len); 904 un_len);
904 GNUNET_free (un); 905 GNUNET_free (un);
905 if (NULL == queue) 906 if (NULL == queue)
906 { 907 {
907 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 908 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
908 "Failed to setup queue to %s at `%s'\n", 909 "Failed to setup queue to %s at `%s'\n",
909 GNUNET_i2s (peer), 910 GNUNET_i2s (peer),
910 path); 911 path);
911 return GNUNET_NO; 912 return GNUNET_NO;
912 } 913 }
913 return GNUNET_OK; 914 return GNUNET_OK;