diff options
author | tg(x) <*@tg-x.net> | 2017-02-22 21:59:56 +0100 |
---|---|---|
committer | tg(x) <*@tg-x.net> | 2017-02-22 21:59:56 +0100 |
commit | e4418446a0ae54a4eaae9239ab81a267afc1d925 (patch) | |
tree | a9d1ef9b22ca649f54bee8b42caa76ee32d25a33 /src/multicast | |
parent | 945443b67fe95893ceb711e1bcd7049477f3cba7 (diff) | |
download | gnunet-e4418446a0ae54a4eaae9239ab81a267afc1d925.tar.gz gnunet-e4418446a0ae54a4eaae9239ab81a267afc1d925.zip |
multicast: switch to new cadet api
Diffstat (limited to 'src/multicast')
-rw-r--r-- | src/multicast/Makefile.am | 2 | ||||
-rw-r--r-- | src/multicast/gnunet-service-multicast.c | 909 | ||||
-rw-r--r-- | src/multicast/test_multicast_multipeer.c | 76 |
3 files changed, 555 insertions, 432 deletions
diff --git a/src/multicast/Makefile.am b/src/multicast/Makefile.am index d5bb0d46b..bac856b00 100644 --- a/src/multicast/Makefile.am +++ b/src/multicast/Makefile.am | |||
@@ -45,7 +45,7 @@ gnunet_service_multicast_SOURCES = \ | |||
45 | gnunet-service-multicast.c | 45 | gnunet-service-multicast.c |
46 | gnunet_service_multicast_LDADD = \ | 46 | gnunet_service_multicast_LDADD = \ |
47 | $(top_builddir)/src/util/libgnunetutil.la \ | 47 | $(top_builddir)/src/util/libgnunetutil.la \ |
48 | $(top_builddir)/src/cadet/libgnunetcadet.la \ | 48 | $(top_builddir)/src/cadet/libgnunetcadetnew.la \ |
49 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 49 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
50 | $(GN_LIBINTL) | 50 | $(GN_LIBINTL) |
51 | 51 | ||
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c index de65e0ab7..554962d99 100644 --- a/src/multicast/gnunet-service-multicast.c +++ b/src/multicast/gnunet-service-multicast.c | |||
@@ -163,6 +163,16 @@ struct Channel | |||
163 | struct GNUNET_PeerIdentity peer; | 163 | struct GNUNET_PeerIdentity peer; |
164 | 164 | ||
165 | /** | 165 | /** |
166 | * Current window size, set by cadet_notify_window_change() | ||
167 | */ | ||
168 | int32_t window_size; | ||
169 | |||
170 | /** | ||
171 | * Is the connection established? | ||
172 | */ | ||
173 | int8_t is_connected; | ||
174 | |||
175 | /** | ||
166 | * Is the remote peer admitted to the group? | 176 | * Is the remote peer admitted to the group? |
167 | * @see enum JoinStatus | 177 | * @see enum JoinStatus |
168 | */ | 178 | */ |
@@ -336,6 +346,17 @@ struct ReplayRequestKey | |||
336 | }; | 346 | }; |
337 | 347 | ||
338 | 348 | ||
349 | static struct Channel * | ||
350 | cadet_channel_create (struct Group *grp, struct GNUNET_PeerIdentity *peer); | ||
351 | |||
352 | static void | ||
353 | cadet_channel_destroy (struct Channel *chn); | ||
354 | |||
355 | static void | ||
356 | client_send_join_decision (struct Member *mem, | ||
357 | const struct MulticastJoinDecisionMessageHeader *hdcsn); | ||
358 | |||
359 | |||
339 | /** | 360 | /** |
340 | * Task run during shutdown. | 361 | * Task run during shutdown. |
341 | * | 362 | * |
@@ -672,36 +693,6 @@ struct CadetTransmitClosure | |||
672 | 693 | ||
673 | 694 | ||
674 | /** | 695 | /** |
675 | * CADET is ready to transmit a message. | ||
676 | */ | ||
677 | size_t | ||
678 | cadet_notify_transmit_ready (void *cls, size_t buf_size, void *buf) | ||
679 | { | ||
680 | if (0 == buf_size) | ||
681 | { | ||
682 | /* FIXME: connection closed */ | ||
683 | return 0; | ||
684 | } | ||
685 | struct CadetTransmitClosure *tcls = cls; | ||
686 | struct Channel *chn = tcls->chn; | ||
687 | uint16_t msg_size = ntohs (tcls->msg->size); | ||
688 | GNUNET_assert (msg_size <= buf_size); | ||
689 | GNUNET_memcpy (buf, tcls->msg, msg_size); | ||
690 | GNUNET_free (tcls); | ||
691 | |||
692 | if (0 == chn->msgs_pending) | ||
693 | { | ||
694 | GNUNET_break (0); | ||
695 | } | ||
696 | else if (0 == --chn->msgs_pending) | ||
697 | { | ||
698 | client_send_ack (&chn->group_pub_hash); | ||
699 | } | ||
700 | return msg_size; | ||
701 | } | ||
702 | |||
703 | |||
704 | /** | ||
705 | * Send a message to a CADET channel. | 696 | * Send a message to a CADET channel. |
706 | * | 697 | * |
707 | * @param chn Channel. | 698 | * @param chn Channel. |
@@ -710,53 +701,19 @@ cadet_notify_transmit_ready (void *cls, size_t buf_size, void *buf) | |||
710 | static void | 701 | static void |
711 | cadet_send_channel (struct Channel *chn, const struct GNUNET_MessageHeader *msg) | 702 | cadet_send_channel (struct Channel *chn, const struct GNUNET_MessageHeader *msg) |
712 | { | 703 | { |
713 | uint16_t msg_size = ntohs (msg->size); | 704 | struct GNUNET_MQ_Envelope * |
714 | struct GNUNET_MessageHeader *msg_copy = GNUNET_malloc (msg_size); | 705 | env = GNUNET_MQ_msg_copy (msg); |
715 | GNUNET_memcpy (msg_copy, msg, msg_size); | ||
716 | |||
717 | struct CadetTransmitClosure *tcls = GNUNET_malloc (sizeof (*tcls)); | ||
718 | tcls->chn = chn; | ||
719 | tcls->msg = msg_copy; | ||
720 | |||
721 | chn->msgs_pending++; | ||
722 | chn->tmit_handle | ||
723 | = GNUNET_CADET_notify_transmit_ready (chn->channel, GNUNET_NO, | ||
724 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
725 | msg_size, | ||
726 | &cadet_notify_transmit_ready, | ||
727 | tcls); | ||
728 | GNUNET_assert (NULL != chn->tmit_handle); | ||
729 | } | ||
730 | 706 | ||
707 | GNUNET_MQ_send (GNUNET_CADET_get_mq (chn->channel), env); | ||
731 | 708 | ||
732 | /** | 709 | if (0 < chn->window_size) |
733 | * Create new outgoing CADET channel. | 710 | { |
734 | * | 711 | client_send_ack (&chn->group_pub_hash); |
735 | * @param peer | 712 | } |
736 | * Peer to connect to. | 713 | else |
737 | * @param group_pub_key | 714 | { |
738 | * Public key of group the channel belongs to. | 715 | chn->msgs_pending++; |
739 | * @param group_pub_hash | 716 | } |
740 | * Hash of @a group_pub_key. | ||
741 | * | ||
742 | * @return Channel. | ||
743 | */ | ||
744 | static struct Channel * | ||
745 | cadet_channel_create (struct Group *grp, struct GNUNET_PeerIdentity *peer) | ||
746 | { | ||
747 | struct Channel *chn = GNUNET_malloc (sizeof (*chn)); | ||
748 | chn->group = grp; | ||
749 | chn->group_pub_key = grp->pub_key; | ||
750 | chn->group_pub_hash = grp->pub_key_hash; | ||
751 | chn->peer = *peer; | ||
752 | chn->direction = DIR_OUTGOING; | ||
753 | chn->join_status = JOIN_WAITING; | ||
754 | chn->channel = GNUNET_CADET_channel_create (cadet, chn, &chn->peer, | ||
755 | &grp->cadet_port_hash, | ||
756 | GNUNET_CADET_OPTION_RELIABLE); | ||
757 | GNUNET_CONTAINER_multihashmap_put (channels_out, &chn->group_pub_hash, chn, | ||
758 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
759 | return chn; | ||
760 | } | 717 | } |
761 | 718 | ||
762 | 719 | ||
@@ -787,7 +744,7 @@ cadet_send_join_decision_cb (void *cls, | |||
787 | const struct MulticastJoinDecisionMessageHeader *hdcsn = cls; | 744 | const struct MulticastJoinDecisionMessageHeader *hdcsn = cls; |
788 | struct Channel *chn = channel; | 745 | struct Channel *chn = channel; |
789 | 746 | ||
790 | const struct MulticastJoinDecisionMessage *dcsn = | 747 | const struct MulticastJoinDecisionMessage *dcsn = |
791 | (struct MulticastJoinDecisionMessage *) &hdcsn[1]; | 748 | (struct MulticastJoinDecisionMessage *) &hdcsn[1]; |
792 | 749 | ||
793 | if (0 == memcmp (&hdcsn->member_pub_key, &chn->member_pub_key, sizeof (chn->member_pub_key)) | 750 | if (0 == memcmp (&hdcsn->member_pub_key, &chn->member_pub_key, sizeof (chn->member_pub_key)) |
@@ -870,31 +827,69 @@ cadet_send_parents (struct GNUNET_HashCode *pub_key_hash, | |||
870 | 827 | ||
871 | 828 | ||
872 | /** | 829 | /** |
873 | * New incoming CADET channel. | 830 | * CADET channel connect handler. |
831 | * | ||
832 | * @see GNUNET_CADET_ConnectEventHandler() | ||
874 | */ | 833 | */ |
875 | static void * | 834 | static void * |
876 | cadet_notify_channel_new (void *cls, | 835 | cadet_notify_connect (void *cls, |
877 | struct GNUNET_CADET_Channel *channel, | 836 | struct GNUNET_CADET_Channel *channel, |
878 | const struct GNUNET_PeerIdentity *initiator, | 837 | const struct GNUNET_PeerIdentity *source) |
879 | const struct GNUNET_HashCode *port, | 838 | { |
880 | enum GNUNET_CADET_ChannelOption options) | 839 | struct Channel *chn = GNUNET_malloc (sizeof *chn); |
840 | chn->group = cls; | ||
841 | chn->channel = channel; | ||
842 | chn->direction = DIR_INCOMING; | ||
843 | chn->join_status = JOIN_NOT_ASKED; | ||
844 | |||
845 | GNUNET_CONTAINER_multihashmap_put (channels_in, &chn->group_pub_hash, chn, | ||
846 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
847 | return chn; | ||
848 | } | ||
849 | |||
850 | |||
851 | /** | ||
852 | * CADET window size change handler. | ||
853 | * | ||
854 | * @see GNUNET_CADET_WindowSizeEventHandler() | ||
855 | */ | ||
856 | static void | ||
857 | cadet_notify_window_change (void *cls, | ||
858 | const struct GNUNET_CADET_Channel *channel, | ||
859 | int window_size) | ||
881 | { | 860 | { |
882 | return NULL; | 861 | struct Channel *chn = cls; |
862 | chn->is_connected = GNUNET_YES; | ||
863 | chn->window_size = (int32_t) window_size; | ||
864 | |||
865 | for (int i = 0; i < window_size; i++) | ||
866 | { | ||
867 | if (0 < chn->msgs_pending) | ||
868 | { | ||
869 | client_send_ack (&chn->group_pub_hash); | ||
870 | --chn->msgs_pending; | ||
871 | } | ||
872 | else | ||
873 | { | ||
874 | break; | ||
875 | } | ||
876 | } | ||
883 | } | 877 | } |
884 | 878 | ||
885 | 879 | ||
886 | /** | 880 | /** |
887 | * CADET channel is being destroyed. | 881 | * CADET channel disconnect handler. |
882 | * | ||
883 | * @see GNUNET_CADET_DisconnectEventHandler() | ||
888 | */ | 884 | */ |
889 | static void | 885 | static void |
890 | cadet_notify_channel_end (void *cls, | 886 | cadet_notify_disconnect (void *cls, |
891 | const struct GNUNET_CADET_Channel *channel, | 887 | const struct GNUNET_CADET_Channel *channel) |
892 | void *ctx) | ||
893 | { | 888 | { |
894 | if (NULL == ctx) | 889 | if (NULL == cls) |
895 | return; | 890 | return; |
896 | 891 | ||
897 | struct Channel *chn = ctx; | 892 | struct Channel *chn = cls; |
898 | if (NULL != chn->group) | 893 | if (NULL != chn->group) |
899 | { | 894 | { |
900 | if (GNUNET_NO == chn->group->is_origin) | 895 | if (GNUNET_NO == chn->group->is_origin) |
@@ -905,12 +900,331 @@ cadet_notify_channel_end (void *cls, | |||
905 | } | 900 | } |
906 | } | 901 | } |
907 | 902 | ||
908 | while (GNUNET_YES == replay_req_remove_cadet (chn)); | 903 | int ret; |
904 | do | ||
905 | { | ||
906 | ret = replay_req_remove_cadet (chn); | ||
907 | } | ||
908 | while (GNUNET_YES == ret); | ||
909 | 909 | ||
910 | GNUNET_free (chn); | 910 | GNUNET_free (chn); |
911 | } | 911 | } |
912 | 912 | ||
913 | 913 | ||
914 | static int | ||
915 | check_cadet_join_request (void *cls, | ||
916 | const struct MulticastJoinRequestMessage *req) | ||
917 | { | ||
918 | struct Channel *chn = cls; | ||
919 | |||
920 | if (NULL == chn | ||
921 | || JOIN_NOT_ASKED != chn->join_status) | ||
922 | { | ||
923 | return GNUNET_SYSERR; | ||
924 | } | ||
925 | |||
926 | uint16_t size = ntohs (req->header.size); | ||
927 | if (size < sizeof (*req)) | ||
928 | { | ||
929 | GNUNET_break_op (0); | ||
930 | return GNUNET_SYSERR; | ||
931 | } | ||
932 | if (ntohl (req->purpose.size) != (size | ||
933 | - sizeof (req->header) | ||
934 | - sizeof (req->reserved) | ||
935 | - sizeof (req->signature))) | ||
936 | { | ||
937 | GNUNET_break_op (0); | ||
938 | return GNUNET_SYSERR; | ||
939 | } | ||
940 | if (GNUNET_OK != | ||
941 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST, | ||
942 | &req->purpose, &req->signature, | ||
943 | &req->member_pub_key)) | ||
944 | { | ||
945 | GNUNET_break_op (0); | ||
946 | return GNUNET_SYSERR; | ||
947 | } | ||
948 | |||
949 | return GNUNET_OK; | ||
950 | } | ||
951 | |||
952 | |||
953 | /** | ||
954 | * Incoming join request message from CADET. | ||
955 | */ | ||
956 | static void | ||
957 | handle_cadet_join_request (void *cls, | ||
958 | const struct MulticastJoinRequestMessage *req) | ||
959 | { | ||
960 | struct Channel *chn = cls; | ||
961 | GNUNET_CADET_receive_done (chn->channel); | ||
962 | |||
963 | struct GNUNET_HashCode group_pub_hash; | ||
964 | GNUNET_CRYPTO_hash (&req->group_pub_key, sizeof (req->group_pub_key), &group_pub_hash); | ||
965 | chn->group_pub_key = req->group_pub_key; | ||
966 | chn->group_pub_hash = group_pub_hash; | ||
967 | chn->member_pub_key = req->member_pub_key; | ||
968 | chn->peer = req->peer; | ||
969 | chn->join_status = JOIN_WAITING; | ||
970 | |||
971 | client_send_all (&group_pub_hash, &req->header); | ||
972 | } | ||
973 | |||
974 | |||
975 | static int | ||
976 | check_cadet_join_decision (void *cls, | ||
977 | const struct MulticastJoinDecisionMessageHeader *hdcsn) | ||
978 | { | ||
979 | uint16_t size = ntohs (hdcsn->header.size); | ||
980 | if (size < sizeof (struct MulticastJoinDecisionMessageHeader) + | ||
981 | sizeof (struct MulticastJoinDecisionMessage)) | ||
982 | { | ||
983 | GNUNET_break_op (0); | ||
984 | return GNUNET_SYSERR; | ||
985 | } | ||
986 | |||
987 | struct Channel *chn = cls; | ||
988 | if (NULL == chn) | ||
989 | { | ||
990 | GNUNET_break (0); | ||
991 | return GNUNET_SYSERR; | ||
992 | } | ||
993 | if (NULL == chn->group || GNUNET_NO != chn->group->is_origin) | ||
994 | { | ||
995 | GNUNET_break (0); | ||
996 | return GNUNET_SYSERR; | ||
997 | } | ||
998 | switch (chn->join_status) | ||
999 | { | ||
1000 | case JOIN_REFUSED: | ||
1001 | return GNUNET_SYSERR; | ||
1002 | |||
1003 | case JOIN_ADMITTED: | ||
1004 | return GNUNET_OK; | ||
1005 | |||
1006 | case JOIN_NOT_ASKED: | ||
1007 | case JOIN_WAITING: | ||
1008 | break; | ||
1009 | } | ||
1010 | |||
1011 | return GNUNET_OK; | ||
1012 | } | ||
1013 | |||
1014 | |||
1015 | /** | ||
1016 | * Incoming join decision message from CADET. | ||
1017 | */ | ||
1018 | static void | ||
1019 | handle_cadet_join_decision (void *cls, | ||
1020 | const struct MulticastJoinDecisionMessageHeader *hdcsn) | ||
1021 | { | ||
1022 | const struct MulticastJoinDecisionMessage * | ||
1023 | dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1]; | ||
1024 | |||
1025 | struct Channel *chn = cls; | ||
1026 | GNUNET_CADET_receive_done (chn->channel); | ||
1027 | |||
1028 | // FIXME: do we need to copy chn->peer or compare it with hdcsn->peer? | ||
1029 | struct Member *mem = (struct Member *) chn->group; | ||
1030 | client_send_join_decision (mem, hdcsn); | ||
1031 | if (GNUNET_YES == ntohl (dcsn->is_admitted)) | ||
1032 | { | ||
1033 | chn->join_status = JOIN_ADMITTED; | ||
1034 | } | ||
1035 | else | ||
1036 | { | ||
1037 | chn->join_status = JOIN_REFUSED; | ||
1038 | cadet_channel_destroy (chn); | ||
1039 | } | ||
1040 | } | ||
1041 | |||
1042 | |||
1043 | static int | ||
1044 | check_cadet_message (void *cls, | ||
1045 | const struct GNUNET_MULTICAST_MessageHeader *msg) | ||
1046 | { | ||
1047 | uint16_t size = ntohs (msg->header.size); | ||
1048 | if (size < sizeof (*msg)) | ||
1049 | { | ||
1050 | GNUNET_break_op (0); | ||
1051 | return GNUNET_SYSERR; | ||
1052 | } | ||
1053 | |||
1054 | struct Channel *chn = cls; | ||
1055 | if (NULL == chn) | ||
1056 | { | ||
1057 | GNUNET_break (0); | ||
1058 | return GNUNET_SYSERR; | ||
1059 | } | ||
1060 | if (ntohl (msg->purpose.size) != (size | ||
1061 | - sizeof (msg->header) | ||
1062 | - sizeof (msg->hop_counter) | ||
1063 | - sizeof (msg->signature))) | ||
1064 | { | ||
1065 | GNUNET_break_op (0); | ||
1066 | return GNUNET_SYSERR; | ||
1067 | } | ||
1068 | if (GNUNET_OK != | ||
1069 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_MULTICAST_MESSAGE, | ||
1070 | &msg->purpose, &msg->signature, | ||
1071 | &chn->group_pub_key)) | ||
1072 | { | ||
1073 | GNUNET_break_op (0); | ||
1074 | return GNUNET_SYSERR; | ||
1075 | } | ||
1076 | |||
1077 | return GNUNET_OK; | ||
1078 | } | ||
1079 | |||
1080 | |||
1081 | /** | ||
1082 | * Incoming multicast message from CADET. | ||
1083 | */ | ||
1084 | static void | ||
1085 | handle_cadet_message (void *cls, | ||
1086 | const struct GNUNET_MULTICAST_MessageHeader *msg) | ||
1087 | { | ||
1088 | struct Channel *chn = cls; | ||
1089 | GNUNET_CADET_receive_done (chn->channel); | ||
1090 | client_send_all (&chn->group_pub_hash, &msg->header); | ||
1091 | } | ||
1092 | |||
1093 | |||
1094 | static int | ||
1095 | check_cadet_request (void *cls, | ||
1096 | const struct GNUNET_MULTICAST_RequestHeader *req) | ||
1097 | { | ||
1098 | uint16_t size = ntohs (req->header.size); | ||
1099 | if (size < sizeof (*req)) | ||
1100 | { | ||
1101 | GNUNET_break_op (0); | ||
1102 | return GNUNET_SYSERR; | ||
1103 | } | ||
1104 | |||
1105 | struct Channel *chn = cls; | ||
1106 | if (NULL == chn) | ||
1107 | { | ||
1108 | GNUNET_break (0); | ||
1109 | return GNUNET_SYSERR; | ||
1110 | } | ||
1111 | if (ntohl (req->purpose.size) != (size | ||
1112 | - sizeof (req->header) | ||
1113 | - sizeof (req->member_pub_key) | ||
1114 | - sizeof (req->signature))) | ||
1115 | { | ||
1116 | GNUNET_break_op (0); | ||
1117 | return GNUNET_SYSERR; | ||
1118 | } | ||
1119 | if (GNUNET_OK != | ||
1120 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST, | ||
1121 | &req->purpose, &req->signature, | ||
1122 | &req->member_pub_key)) | ||
1123 | { | ||
1124 | GNUNET_break_op (0); | ||
1125 | return GNUNET_SYSERR; | ||
1126 | } | ||
1127 | |||
1128 | return GNUNET_OK; | ||
1129 | } | ||
1130 | |||
1131 | |||
1132 | /** | ||
1133 | * Incoming multicast request message from CADET. | ||
1134 | */ | ||
1135 | static void | ||
1136 | handle_cadet_request (void *cls, | ||
1137 | const struct GNUNET_MULTICAST_RequestHeader *req) | ||
1138 | { | ||
1139 | struct Channel *chn = cls; | ||
1140 | GNUNET_CADET_receive_done (chn->channel); | ||
1141 | client_send_origin (&chn->group_pub_hash, &req->header); | ||
1142 | } | ||
1143 | |||
1144 | |||
1145 | static int | ||
1146 | check_cadet_replay_request (void *cls, | ||
1147 | const struct MulticastReplayRequestMessage *req) | ||
1148 | { | ||
1149 | uint16_t size = ntohs (req->header.size); | ||
1150 | if (size < sizeof (*req)) | ||
1151 | { | ||
1152 | GNUNET_break_op (0); | ||
1153 | return GNUNET_SYSERR; | ||
1154 | } | ||
1155 | |||
1156 | struct Channel *chn = cls; | ||
1157 | if (NULL == chn) | ||
1158 | { | ||
1159 | GNUNET_break_op (0); | ||
1160 | return GNUNET_SYSERR; | ||
1161 | } | ||
1162 | |||
1163 | return GNUNET_OK; | ||
1164 | } | ||
1165 | |||
1166 | |||
1167 | /** | ||
1168 | * Incoming multicast replay request from CADET. | ||
1169 | */ | ||
1170 | static void | ||
1171 | handle_cadet_replay_request (void *cls, | ||
1172 | const struct MulticastReplayRequestMessage *req) | ||
1173 | { | ||
1174 | struct Channel *chn = cls; | ||
1175 | GNUNET_CADET_receive_done (chn->channel); | ||
1176 | |||
1177 | struct MulticastReplayRequestMessage rep = *req; | ||
1178 | GNUNET_memcpy (&rep.member_pub_key, &chn->member_pub_key, sizeof (chn->member_pub_key)); | ||
1179 | |||
1180 | struct GNUNET_CONTAINER_MultiHashMap * | ||
1181 | grp_replay_req = GNUNET_CONTAINER_multihashmap_get (replay_req_cadet, | ||
1182 | &chn->group->pub_key_hash); | ||
1183 | if (NULL == grp_replay_req) | ||
1184 | { | ||
1185 | grp_replay_req = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | ||
1186 | GNUNET_CONTAINER_multihashmap_put (replay_req_cadet, | ||
1187 | &chn->group->pub_key_hash, grp_replay_req, | ||
1188 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
1189 | } | ||
1190 | struct GNUNET_HashCode key_hash; | ||
1191 | replay_key_hash (rep.fragment_id, rep.message_id, rep.fragment_offset, | ||
1192 | rep.flags, &key_hash); | ||
1193 | GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, chn, | ||
1194 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
1195 | |||
1196 | client_send_random (&chn->group_pub_hash, &rep.header); | ||
1197 | } | ||
1198 | |||
1199 | |||
1200 | static int | ||
1201 | check_cadet_replay_response (void *cls, | ||
1202 | const struct MulticastReplayResponseMessage *res) | ||
1203 | { | ||
1204 | struct Channel *chn = cls; | ||
1205 | if (NULL == chn) | ||
1206 | { | ||
1207 | GNUNET_break (0); | ||
1208 | return GNUNET_SYSERR; | ||
1209 | } | ||
1210 | return GNUNET_OK; | ||
1211 | } | ||
1212 | |||
1213 | |||
1214 | /** | ||
1215 | * Incoming multicast replay response from CADET. | ||
1216 | */ | ||
1217 | static void | ||
1218 | handle_cadet_replay_response (void *cls, | ||
1219 | const struct MulticastReplayResponseMessage *res) | ||
1220 | { | ||
1221 | struct Channel *chn = cls; | ||
1222 | GNUNET_CADET_receive_done (chn->channel); | ||
1223 | |||
1224 | /* @todo FIXME: got replay error response, send request to other members */ | ||
1225 | } | ||
1226 | |||
1227 | |||
914 | static void | 1228 | static void |
915 | group_set_cadet_port_hash (struct Group *grp) | 1229 | group_set_cadet_port_hash (struct Group *grp) |
916 | { | 1230 | { |
@@ -925,6 +1239,78 @@ group_set_cadet_port_hash (struct Group *grp) | |||
925 | } | 1239 | } |
926 | 1240 | ||
927 | 1241 | ||
1242 | |||
1243 | /** | ||
1244 | * Create new outgoing CADET channel. | ||
1245 | * | ||
1246 | * @param peer | ||
1247 | * Peer to connect to. | ||
1248 | * @param group_pub_key | ||
1249 | * Public key of group the channel belongs to. | ||
1250 | * @param group_pub_hash | ||
1251 | * Hash of @a group_pub_key. | ||
1252 | * | ||
1253 | * @return Channel. | ||
1254 | */ | ||
1255 | static struct Channel * | ||
1256 | cadet_channel_create (struct Group *grp, struct GNUNET_PeerIdentity *peer) | ||
1257 | { | ||
1258 | struct Channel *chn = GNUNET_malloc (sizeof (*chn)); | ||
1259 | chn->group = grp; | ||
1260 | chn->group_pub_key = grp->pub_key; | ||
1261 | chn->group_pub_hash = grp->pub_key_hash; | ||
1262 | chn->peer = *peer; | ||
1263 | chn->direction = DIR_OUTGOING; | ||
1264 | chn->is_connected = GNUNET_NO; | ||
1265 | chn->join_status = JOIN_WAITING; | ||
1266 | |||
1267 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | ||
1268 | GNUNET_MQ_hd_var_size (cadet_message, | ||
1269 | GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, | ||
1270 | struct GNUNET_MULTICAST_MessageHeader, | ||
1271 | chn), | ||
1272 | |||
1273 | GNUNET_MQ_hd_var_size (cadet_join_decision, | ||
1274 | GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION, | ||
1275 | struct MulticastJoinDecisionMessageHeader, | ||
1276 | chn), | ||
1277 | |||
1278 | GNUNET_MQ_hd_var_size (cadet_replay_request, | ||
1279 | GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, | ||
1280 | struct MulticastReplayRequestMessage, | ||
1281 | chn), | ||
1282 | |||
1283 | GNUNET_MQ_hd_var_size (cadet_replay_response, | ||
1284 | GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE, | ||
1285 | struct MulticastReplayResponseMessage, | ||
1286 | chn), | ||
1287 | |||
1288 | GNUNET_MQ_handler_end () | ||
1289 | }; | ||
1290 | |||
1291 | chn->channel = GNUNET_CADET_channel_creatE (cadet, chn, &chn->peer, | ||
1292 | &grp->cadet_port_hash, | ||
1293 | GNUNET_CADET_OPTION_RELIABLE, | ||
1294 | cadet_notify_window_change, | ||
1295 | cadet_notify_disconnect, | ||
1296 | cadet_handlers); | ||
1297 | GNUNET_CONTAINER_multihashmap_put (channels_out, &chn->group_pub_hash, chn, | ||
1298 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
1299 | return chn; | ||
1300 | } | ||
1301 | |||
1302 | |||
1303 | /** | ||
1304 | * Destroy outgoing CADET channel. | ||
1305 | */ | ||
1306 | static void | ||
1307 | cadet_channel_destroy (struct Channel *chn) | ||
1308 | { | ||
1309 | GNUNET_CADET_channel_destroy (chn->channel); | ||
1310 | GNUNET_CONTAINER_multihashmap_remove_all (channels_out, &chn->group_pub_hash); | ||
1311 | GNUNET_free (chn); | ||
1312 | } | ||
1313 | |||
928 | /** | 1314 | /** |
929 | * Handle a connecting client starting an origin. | 1315 | * Handle a connecting client starting an origin. |
930 | */ | 1316 | */ |
@@ -961,8 +1347,44 @@ handle_client_origin_start (void *cls, | |||
961 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 1347 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
962 | 1348 | ||
963 | group_set_cadet_port_hash (grp); | 1349 | group_set_cadet_port_hash (grp); |
964 | orig->cadet_port = GNUNET_CADET_open_port (cadet, &grp->cadet_port_hash, | 1350 | |
965 | cadet_notify_channel_new, NULL); | 1351 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
1352 | GNUNET_MQ_hd_var_size (cadet_message, | ||
1353 | GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, | ||
1354 | struct GNUNET_MULTICAST_MessageHeader, | ||
1355 | grp), | ||
1356 | |||
1357 | GNUNET_MQ_hd_var_size (cadet_request, | ||
1358 | GNUNET_MESSAGE_TYPE_MULTICAST_REQUEST, | ||
1359 | struct GNUNET_MULTICAST_RequestHeader, | ||
1360 | grp), | ||
1361 | |||
1362 | GNUNET_MQ_hd_var_size (cadet_join_request, | ||
1363 | GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST, | ||
1364 | struct MulticastJoinRequestMessage, | ||
1365 | grp), | ||
1366 | |||
1367 | GNUNET_MQ_hd_var_size (cadet_replay_request, | ||
1368 | GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, | ||
1369 | struct MulticastReplayRequestMessage, | ||
1370 | grp), | ||
1371 | |||
1372 | GNUNET_MQ_hd_var_size (cadet_replay_response, | ||
1373 | GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE, | ||
1374 | struct MulticastReplayResponseMessage, | ||
1375 | grp), | ||
1376 | |||
1377 | GNUNET_MQ_handler_end () | ||
1378 | }; | ||
1379 | |||
1380 | |||
1381 | orig->cadet_port = GNUNET_CADET_open_porT (cadet, | ||
1382 | &grp->cadet_port_hash, | ||
1383 | cadet_notify_connect, | ||
1384 | NULL, | ||
1385 | cadet_notify_window_change, | ||
1386 | cadet_notify_disconnect, | ||
1387 | cadet_handlers); | ||
966 | } | 1388 | } |
967 | else | 1389 | else |
968 | { | 1390 | { |
@@ -1544,278 +1966,6 @@ handle_client_replay_response (void *cls, | |||
1544 | 1966 | ||
1545 | 1967 | ||
1546 | /** | 1968 | /** |
1547 | * Incoming join request message from CADET. | ||
1548 | */ | ||
1549 | int | ||
1550 | cadet_recv_join_request (void *cls, | ||
1551 | struct GNUNET_CADET_Channel *channel, | ||
1552 | void **ctx, | ||
1553 | const struct GNUNET_MessageHeader *m) | ||
1554 | { | ||
1555 | GNUNET_CADET_receive_done(channel); | ||
1556 | const struct MulticastJoinRequestMessage * | ||
1557 | req = (const struct MulticastJoinRequestMessage *) m; | ||
1558 | uint16_t size = ntohs (m->size); | ||
1559 | if (size < sizeof (*req)) | ||
1560 | { | ||
1561 | GNUNET_break_op (0); | ||
1562 | return GNUNET_SYSERR; | ||
1563 | } | ||
1564 | if (NULL != *ctx) | ||
1565 | { | ||
1566 | GNUNET_break_op (0); | ||
1567 | return GNUNET_SYSERR; | ||
1568 | } | ||
1569 | if (ntohl (req->purpose.size) != (size | ||
1570 | - sizeof (req->header) | ||
1571 | - sizeof (req->reserved) | ||
1572 | - sizeof (req->signature))) | ||
1573 | { | ||
1574 | GNUNET_break_op (0); | ||
1575 | return GNUNET_SYSERR; | ||
1576 | } | ||
1577 | if (GNUNET_OK != | ||
1578 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST, | ||
1579 | &req->purpose, &req->signature, | ||
1580 | &req->member_pub_key)) | ||
1581 | { | ||
1582 | GNUNET_break_op (0); | ||
1583 | return GNUNET_SYSERR; | ||
1584 | } | ||
1585 | |||
1586 | struct GNUNET_HashCode group_pub_hash; | ||
1587 | GNUNET_CRYPTO_hash (&req->group_pub_key, sizeof (req->group_pub_key), &group_pub_hash); | ||
1588 | |||
1589 | struct Channel *chn = GNUNET_malloc (sizeof *chn); | ||
1590 | chn->channel = channel; | ||
1591 | chn->group_pub_key = req->group_pub_key; | ||
1592 | chn->group_pub_hash = group_pub_hash; | ||
1593 | chn->member_pub_key = req->member_pub_key; | ||
1594 | chn->peer = req->peer; | ||
1595 | chn->join_status = JOIN_WAITING; | ||
1596 | GNUNET_CONTAINER_multihashmap_put (channels_in, &chn->group_pub_hash, chn, | ||
1597 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
1598 | *ctx = chn; | ||
1599 | |||
1600 | client_send_all (&group_pub_hash, m); | ||
1601 | return GNUNET_OK; | ||
1602 | } | ||
1603 | |||
1604 | |||
1605 | /** | ||
1606 | * Incoming join decision message from CADET. | ||
1607 | */ | ||
1608 | int | ||
1609 | cadet_recv_join_decision (void *cls, | ||
1610 | struct GNUNET_CADET_Channel *channel, | ||
1611 | void **ctx, | ||
1612 | const struct GNUNET_MessageHeader *m) | ||
1613 | { | ||
1614 | GNUNET_CADET_receive_done (channel); | ||
1615 | const struct MulticastJoinDecisionMessageHeader * | ||
1616 | hdcsn = (const struct MulticastJoinDecisionMessageHeader *) m; | ||
1617 | const struct MulticastJoinDecisionMessage * | ||
1618 | dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1]; | ||
1619 | uint16_t size = ntohs (m->size); | ||
1620 | if (size < sizeof (struct MulticastJoinDecisionMessageHeader) + | ||
1621 | sizeof (struct MulticastJoinDecisionMessage)) | ||
1622 | { | ||
1623 | GNUNET_break_op (0); | ||
1624 | return GNUNET_SYSERR; | ||
1625 | } | ||
1626 | struct Channel *chn = *ctx; | ||
1627 | if (NULL == chn) | ||
1628 | { | ||
1629 | GNUNET_break_op (0); | ||
1630 | return GNUNET_SYSERR; | ||
1631 | } | ||
1632 | if (NULL == chn->group || GNUNET_NO != chn->group->is_origin) | ||
1633 | { | ||
1634 | GNUNET_break_op (0); | ||
1635 | return GNUNET_SYSERR; | ||
1636 | } | ||
1637 | switch (chn->join_status) | ||
1638 | { | ||
1639 | case JOIN_REFUSED: | ||
1640 | return GNUNET_SYSERR; | ||
1641 | |||
1642 | case JOIN_ADMITTED: | ||
1643 | return GNUNET_OK; | ||
1644 | |||
1645 | case JOIN_NOT_ASKED: | ||
1646 | case JOIN_WAITING: | ||
1647 | break; | ||
1648 | } | ||
1649 | |||
1650 | // FIXME: do we need to copy chn->peer or compare it with hdcsn->peer? | ||
1651 | struct Member *mem = (struct Member *) chn->group; | ||
1652 | client_send_join_decision (mem, hdcsn); | ||
1653 | if (GNUNET_YES == ntohl (dcsn->is_admitted)) | ||
1654 | { | ||
1655 | chn->join_status = JOIN_ADMITTED; | ||
1656 | return GNUNET_OK; | ||
1657 | } | ||
1658 | else | ||
1659 | { | ||
1660 | chn->join_status = JOIN_REFUSED; | ||
1661 | return GNUNET_SYSERR; | ||
1662 | } | ||
1663 | } | ||
1664 | |||
1665 | /** | ||
1666 | * Incoming multicast message from CADET. | ||
1667 | */ | ||
1668 | int | ||
1669 | cadet_recv_message (void *cls, | ||
1670 | struct GNUNET_CADET_Channel *channel, | ||
1671 | void **ctx, | ||
1672 | const struct GNUNET_MessageHeader *m) | ||
1673 | { | ||
1674 | GNUNET_CADET_receive_done(channel); | ||
1675 | const struct GNUNET_MULTICAST_MessageHeader * | ||
1676 | msg = (const struct GNUNET_MULTICAST_MessageHeader *) m; | ||
1677 | uint16_t size = ntohs (m->size); | ||
1678 | if (size < sizeof (*msg)) | ||
1679 | { | ||
1680 | GNUNET_break_op (0); | ||
1681 | return GNUNET_SYSERR; | ||
1682 | } | ||
1683 | struct Channel *chn = *ctx; | ||
1684 | if (NULL == chn) | ||
1685 | { | ||
1686 | GNUNET_break_op (0); | ||
1687 | return GNUNET_SYSERR; | ||
1688 | } | ||
1689 | if (ntohl (msg->purpose.size) != (size | ||
1690 | - sizeof (msg->header) | ||
1691 | - sizeof (msg->hop_counter) | ||
1692 | - sizeof (msg->signature))) | ||
1693 | { | ||
1694 | GNUNET_break_op (0); | ||
1695 | return GNUNET_SYSERR; | ||
1696 | } | ||
1697 | if (GNUNET_OK != | ||
1698 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_MULTICAST_MESSAGE, | ||
1699 | &msg->purpose, &msg->signature, | ||
1700 | &chn->group_pub_key)) | ||
1701 | { | ||
1702 | GNUNET_break_op (0); | ||
1703 | return GNUNET_SYSERR; | ||
1704 | } | ||
1705 | |||
1706 | client_send_all (&chn->group_pub_hash, m); | ||
1707 | return GNUNET_OK; | ||
1708 | } | ||
1709 | |||
1710 | |||
1711 | /** | ||
1712 | * Incoming multicast request message from CADET. | ||
1713 | */ | ||
1714 | int | ||
1715 | cadet_recv_request (void *cls, | ||
1716 | struct GNUNET_CADET_Channel *channel, | ||
1717 | void **ctx, | ||
1718 | const struct GNUNET_MessageHeader *m) | ||
1719 | { | ||
1720 | GNUNET_CADET_receive_done(channel); | ||
1721 | const struct GNUNET_MULTICAST_RequestHeader * | ||
1722 | req = (const struct GNUNET_MULTICAST_RequestHeader *) m; | ||
1723 | uint16_t size = ntohs (m->size); | ||
1724 | if (size < sizeof (*req)) | ||
1725 | { | ||
1726 | GNUNET_break_op (0); | ||
1727 | return GNUNET_SYSERR; | ||
1728 | } | ||
1729 | struct Channel *chn = *ctx; | ||
1730 | if (NULL == chn) | ||
1731 | { | ||
1732 | GNUNET_break_op (0); | ||
1733 | return GNUNET_SYSERR; | ||
1734 | } | ||
1735 | if (ntohl (req->purpose.size) != (size | ||
1736 | - sizeof (req->header) | ||
1737 | - sizeof (req->member_pub_key) | ||
1738 | - sizeof (req->signature))) | ||
1739 | { | ||
1740 | GNUNET_break_op (0); | ||
1741 | return GNUNET_SYSERR; | ||
1742 | } | ||
1743 | if (GNUNET_OK != | ||
1744 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST, | ||
1745 | &req->purpose, &req->signature, | ||
1746 | &req->member_pub_key)) | ||
1747 | { | ||
1748 | GNUNET_break_op (0); | ||
1749 | return GNUNET_SYSERR; | ||
1750 | } | ||
1751 | |||
1752 | client_send_origin (&chn->group_pub_hash, m); | ||
1753 | return GNUNET_OK; | ||
1754 | } | ||
1755 | |||
1756 | |||
1757 | /** | ||
1758 | * Incoming multicast replay request from CADET. | ||
1759 | */ | ||
1760 | int | ||
1761 | cadet_recv_replay_request (void *cls, | ||
1762 | struct GNUNET_CADET_Channel *channel, | ||
1763 | void **ctx, | ||
1764 | const struct GNUNET_MessageHeader *m) | ||
1765 | { | ||
1766 | GNUNET_CADET_receive_done(channel); | ||
1767 | struct MulticastReplayRequestMessage rep; | ||
1768 | uint16_t size = ntohs (m->size); | ||
1769 | if (size < sizeof (rep)) | ||
1770 | { | ||
1771 | GNUNET_break_op (0); | ||
1772 | return GNUNET_SYSERR; | ||
1773 | } | ||
1774 | struct Channel *chn = *ctx; | ||
1775 | |||
1776 | GNUNET_memcpy (&rep, m, sizeof (rep)); | ||
1777 | GNUNET_memcpy (&rep.member_pub_key, &chn->member_pub_key, sizeof (chn->member_pub_key)); | ||
1778 | |||
1779 | struct GNUNET_CONTAINER_MultiHashMap * | ||
1780 | grp_replay_req = GNUNET_CONTAINER_multihashmap_get (replay_req_cadet, | ||
1781 | &chn->group->pub_key_hash); | ||
1782 | if (NULL == grp_replay_req) | ||
1783 | { | ||
1784 | grp_replay_req = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | ||
1785 | GNUNET_CONTAINER_multihashmap_put (replay_req_cadet, | ||
1786 | &chn->group->pub_key_hash, grp_replay_req, | ||
1787 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
1788 | } | ||
1789 | struct GNUNET_HashCode key_hash; | ||
1790 | replay_key_hash (rep.fragment_id, rep.message_id, rep.fragment_offset, | ||
1791 | rep.flags, &key_hash); | ||
1792 | GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, chn, | ||
1793 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
1794 | |||
1795 | client_send_random (&chn->group_pub_hash, &rep.header); | ||
1796 | return GNUNET_OK; | ||
1797 | } | ||
1798 | |||
1799 | |||
1800 | /** | ||
1801 | * Incoming multicast replay response from CADET. | ||
1802 | */ | ||
1803 | int | ||
1804 | cadet_recv_replay_response (void *cls, | ||
1805 | struct GNUNET_CADET_Channel *channel, | ||
1806 | void **ctx, | ||
1807 | const struct GNUNET_MessageHeader *m) | ||
1808 | { | ||
1809 | GNUNET_CADET_receive_done(channel); | ||
1810 | //struct Channel *chn = *ctx; | ||
1811 | |||
1812 | /* @todo FIXME: got replay error response, send request to other members */ | ||
1813 | |||
1814 | return GNUNET_OK; | ||
1815 | } | ||
1816 | |||
1817 | |||
1818 | /** | ||
1819 | * A new client connected. | 1969 | * A new client connected. |
1820 | * | 1970 | * |
1821 | * @param cls NULL | 1971 | * @param cls NULL |
@@ -1899,32 +2049,6 @@ client_notify_disconnect (void *cls, | |||
1899 | 2049 | ||
1900 | 2050 | ||
1901 | /** | 2051 | /** |
1902 | * Message handlers for CADET. | ||
1903 | */ | ||
1904 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | ||
1905 | { cadet_recv_join_request, | ||
1906 | GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST, 0 }, | ||
1907 | |||
1908 | { cadet_recv_join_decision, | ||
1909 | GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION, 0 }, | ||
1910 | |||
1911 | { cadet_recv_message, | ||
1912 | GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, 0 }, | ||
1913 | |||
1914 | { cadet_recv_request, | ||
1915 | GNUNET_MESSAGE_TYPE_MULTICAST_REQUEST, 0 }, | ||
1916 | |||
1917 | { cadet_recv_replay_request, | ||
1918 | GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 0 }, | ||
1919 | |||
1920 | { cadet_recv_replay_response, | ||
1921 | GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE, 0 }, | ||
1922 | |||
1923 | { NULL, 0, 0 } | ||
1924 | }; | ||
1925 | |||
1926 | |||
1927 | /** | ||
1928 | * Service started. | 2052 | * Service started. |
1929 | * | 2053 | * |
1930 | * @param cls closure | 2054 | * @param cls closure |
@@ -1949,9 +2073,8 @@ run (void *cls, | |||
1949 | replay_req_cadet = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | 2073 | replay_req_cadet = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); |
1950 | replay_req_client = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | 2074 | replay_req_client = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); |
1951 | 2075 | ||
1952 | cadet = GNUNET_CADET_connect (cfg, NULL, | 2076 | cadet = GNUNET_CADET_connecT (cfg); |
1953 | cadet_notify_channel_end, | 2077 | |
1954 | cadet_handlers); | ||
1955 | GNUNET_assert (NULL != cadet); | 2078 | GNUNET_assert (NULL != cadet); |
1956 | 2079 | ||
1957 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 2080 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c index bb3ae447c..1b76737f4 100644 --- a/src/multicast/test_multicast_multipeer.c +++ b/src/multicast/test_multicast_multipeer.c | |||
@@ -35,7 +35,7 @@ | |||
35 | 35 | ||
36 | #define NUM_PEERS 2 | 36 | #define NUM_PEERS 2 |
37 | 37 | ||
38 | static struct GNUNET_TESTBED_Operation *op0; | 38 | static struct GNUNET_TESTBED_Operation *op0; |
39 | static struct GNUNET_TESTBED_Operation *op1; | 39 | static struct GNUNET_TESTBED_Operation *op1; |
40 | static struct GNUNET_TESTBED_Operation *pi_op0; | 40 | static struct GNUNET_TESTBED_Operation *pi_op0; |
41 | static struct GNUNET_TESTBED_Operation *pi_op1; | 41 | static struct GNUNET_TESTBED_Operation *pi_op1; |
@@ -115,19 +115,19 @@ timeout_task (void *cls) | |||
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | static void | 118 | static void |
119 | member_join_request (void *cls, | 119 | member_join_request (void *cls, |
120 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, | 120 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, |
121 | const struct GNUNET_MessageHeader *join_msg, | 121 | const struct GNUNET_MessageHeader *join_msg, |
122 | struct GNUNET_MULTICAST_JoinHandle *jh) | 122 | struct GNUNET_MULTICAST_JoinHandle *jh) |
123 | { | 123 | { |
124 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 124 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
125 | "Member sent a join request.\n"); | 125 | "Member sent a join request.\n"); |
126 | 126 | ||
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | static void | 130 | static void |
131 | member_join_decision (void *cls, | 131 | member_join_decision (void *cls, |
132 | int is_admitted, | 132 | int is_admitted, |
133 | const struct GNUNET_PeerIdentity *peer, | 133 | const struct GNUNET_PeerIdentity *peer, |
@@ -135,49 +135,49 @@ member_join_decision (void *cls, | |||
135 | const struct GNUNET_PeerIdentity *relays, | 135 | const struct GNUNET_PeerIdentity *relays, |
136 | const struct GNUNET_MessageHeader *join_msg) | 136 | const struct GNUNET_MessageHeader *join_msg) |
137 | { | 137 | { |
138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
139 | "Member received a decision from origin: %s\n", (GNUNET_YES == is_admitted)?"accepted":"rejected"); | 139 | "Member received a decision from origin: %s\n", (GNUNET_YES == is_admitted)?"accepted":"rejected"); |
140 | 140 | ||
141 | result = GNUNET_OK; | 141 | result = GNUNET_OK; |
142 | GNUNET_SCHEDULER_shutdown (); | 142 | GNUNET_SCHEDULER_shutdown (); |
143 | } | 143 | } |
144 | 144 | ||
145 | static void | 145 | static void |
146 | member_replay_frag () | 146 | member_replay_frag () |
147 | { | 147 | { |
148 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 148 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
149 | "member replay frag...\n"); | 149 | "member replay frag...\n"); |
150 | } | 150 | } |
151 | 151 | ||
152 | static void | 152 | static void |
153 | member_replay_msg () | 153 | member_replay_msg () |
154 | { | 154 | { |
155 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 155 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
156 | "member replay msg...\n"); | 156 | "member replay msg...\n"); |
157 | } | 157 | } |
158 | 158 | ||
159 | static void | 159 | static void |
160 | member_message () | 160 | member_message () |
161 | { | 161 | { |
162 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
163 | "member message...\n"); | 163 | "member message...\n"); |
164 | } | 164 | } |
165 | 165 | ||
166 | static void | 166 | static void |
167 | origin_join_request (void *cls, | 167 | origin_join_request (void *cls, |
168 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, | 168 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, |
169 | const struct GNUNET_MessageHeader *join_msg, | 169 | const struct GNUNET_MessageHeader *join_msg, |
170 | struct GNUNET_MULTICAST_JoinHandle *jh) | 170 | struct GNUNET_MULTICAST_JoinHandle *jh) |
171 | { | 171 | { |
172 | struct GNUNET_MessageHeader *join_resp; | 172 | struct GNUNET_MessageHeader *join_resp; |
173 | 173 | ||
174 | uint8_t data_size = ntohs (join_msg->size); | 174 | uint8_t data_size = ntohs (join_msg->size); |
175 | 175 | ||
176 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 176 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
177 | "Dizzy: Mh, got a join request...\n"); | 177 | "Dizzy: Mh, got a join request...\n"); |
178 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 178 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
179 | "'%s'\n", (char *)&join_msg[1]); | 179 | "'%s'\n", (char *)&join_msg[1]); |
180 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 180 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
181 | "Dizzy: Oh, it's Bird! Let's get him in.\n"); | 181 | "Dizzy: Oh, it's Bird! Let's get him in.\n"); |
182 | 182 | ||
183 | char data[] = "Hi, Bird. Come in!"; | 183 | char data[] = "Hi, Bird. Come in!"; |
@@ -196,7 +196,7 @@ origin_join_request (void *cls, | |||
196 | result = GNUNET_OK; | 196 | result = GNUNET_OK; |
197 | } | 197 | } |
198 | 198 | ||
199 | static void | 199 | static void |
200 | origin_replay_frag (void *cls, | 200 | origin_replay_frag (void *cls, |
201 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, | 201 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, |
202 | uint64_t fragment_id, | 202 | uint64_t fragment_id, |
@@ -206,15 +206,15 @@ origin_replay_frag (void *cls, | |||
206 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay fraq msg\n"); | 206 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay fraq msg\n"); |
207 | } | 207 | } |
208 | 208 | ||
209 | static void | 209 | static void |
210 | origin_replay_msg (void *cls, | 210 | origin_replay_msg (void *cls, |
211 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, | 211 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, |
212 | uint64_t message_id, | 212 | uint64_t message_id, |
213 | uint64_t fragment_offset, | 213 | uint64_t fragment_offset, |
214 | uint64_t flags, | 214 | uint64_t flags, |
215 | struct GNUNET_MULTICAST_ReplayHandle *rh) | 215 | struct GNUNET_MULTICAST_ReplayHandle *rh) |
216 | { | 216 | { |
217 | 217 | ||
218 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n"); | 218 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n"); |
219 | } | 219 | } |
220 | 220 | ||
@@ -223,12 +223,12 @@ origin_request (void *cls, | |||
223 | const struct GNUNET_MULTICAST_RequestHeader *req) | 223 | const struct GNUNET_MULTICAST_RequestHeader *req) |
224 | { | 224 | { |
225 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin request msg\n"); | 225 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin request msg\n"); |
226 | 226 | ||
227 | } | 227 | } |
228 | 228 | ||
229 | static void | 229 | static void |
230 | origin_message (void *cls, | 230 | origin_message (void *cls, |
231 | const struct GNUNET_MULTICAST_MessageHeader *msg) | 231 | const struct GNUNET_MULTICAST_MessageHeader *msg) |
232 | { | 232 | { |
233 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); | 233 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); |
234 | } | 234 | } |
@@ -240,11 +240,11 @@ service_connect1 (void *cls, | |||
240 | void *ca_result, | 240 | void *ca_result, |
241 | const char *emsg) | 241 | const char *emsg) |
242 | { | 242 | { |
243 | member = ca_result; | 243 | member = ca_result; |
244 | 244 | ||
245 | if (NULL != member) | 245 | if (NULL != member) |
246 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to multicast service of member\n"); | 246 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to multicast service of member\n"); |
247 | else | 247 | else |
248 | result = GNUNET_SYSERR; | 248 | result = GNUNET_SYSERR; |
249 | } | 249 | } |
250 | 250 | ||
@@ -264,21 +264,21 @@ multicast_ca1 (void *cls, | |||
264 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 264 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
265 | { | 265 | { |
266 | struct GNUNET_MessageHeader *join_msg; | 266 | struct GNUNET_MessageHeader *join_msg; |
267 | 267 | ||
268 | // Get members keys | 268 | // Get members keys |
269 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); | 269 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); |
270 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); | 270 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); |
271 | 271 | ||
272 | char data[] = "Whut's up, Dizzy!"; | 272 | char data[] = "Whut's up, Dizzy!"; |
273 | uint8_t data_size = strlen (data) + 1; | 273 | uint8_t data_size = strlen (data) + 1; |
274 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); | 274 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); |
275 | join_msg->size = htons (sizeof (join_msg) + data_size); | 275 | join_msg->size = htons (sizeof (join_msg) + data_size); |
276 | join_msg->type = htons (123); | 276 | join_msg->type = htons (123); |
277 | GNUNET_memcpy (&join_msg[1], data, data_size); | 277 | GNUNET_memcpy (&join_msg[1], data, data_size); |
278 | 278 | ||
279 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 279 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
280 | "Members tries to join multicast group\n"); | 280 | "Members tries to join multicast group\n"); |
281 | 281 | ||
282 | return GNUNET_MULTICAST_member_join (cfg, | 282 | return GNUNET_MULTICAST_member_join (cfg, |
283 | &group_pub_key, | 283 | &group_pub_key, |
284 | member_key, | 284 | member_key, |
@@ -301,13 +301,13 @@ peer_information_cb (void *cls, | |||
301 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 301 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
302 | const char *emsg) | 302 | const char *emsg) |
303 | { | 303 | { |
304 | int i = (int) cls; | 304 | int i = (int) (long) cls; |
305 | 305 | ||
306 | if (NULL == pinfo) { | 306 | if (NULL == pinfo) { |
307 | result = GNUNET_SYSERR; | 307 | result = GNUNET_SYSERR; |
308 | GNUNET_SCHEDULER_shutdown (); | 308 | GNUNET_SCHEDULER_shutdown (); |
309 | } | 309 | } |
310 | 310 | ||
311 | peer_id[i] = pinfo->result.id; | 311 | peer_id[i] = pinfo->result.id; |
312 | 312 | ||
313 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 313 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -376,13 +376,13 @@ service_connect0 (void *cls, | |||
376 | * Function run when service multicast has started and is providing us | 376 | * Function run when service multicast has started and is providing us |
377 | * with a configuration file. | 377 | * with a configuration file. |
378 | */ | 378 | */ |
379 | static void * | 379 | static void * |
380 | multicast_ca0 (void *cls, | 380 | multicast_ca0 (void *cls, |
381 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 381 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
382 | { | 382 | { |
383 | group_key = GNUNET_CRYPTO_eddsa_key_create (); | 383 | group_key = GNUNET_CRYPTO_eddsa_key_create (); |
384 | GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key); | 384 | GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key); |
385 | 385 | ||
386 | return GNUNET_MULTICAST_origin_start (cfg, | 386 | return GNUNET_MULTICAST_origin_start (cfg, |
387 | group_key, | 387 | group_key, |
388 | 0, | 388 | 0, |
@@ -433,7 +433,7 @@ testbed_master (void *cls, | |||
433 | topology (FIXME) */ | 433 | topology (FIXME) */ |
434 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 434 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
435 | "Connected to testbed_master()\n"); | 435 | "Connected to testbed_master()\n"); |
436 | 436 | ||
437 | peers = p; | 437 | peers = p; |
438 | 438 | ||
439 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 439 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -451,7 +451,7 @@ testbed_master (void *cls, | |||
451 | NULL); /* closure for the above two callbacks */ | 451 | NULL); /* closure for the above two callbacks */ |
452 | 452 | ||
453 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ | 453 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ |
454 | 454 | ||
455 | /* Schedule the shutdown task with a delay of a few Seconds */ | 455 | /* Schedule the shutdown task with a delay of a few Seconds */ |
456 | timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 40), | 456 | timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 40), |
457 | &timeout_task, NULL); | 457 | &timeout_task, NULL); |