diff options
-rw-r--r-- | src/cadet/cadet.h | 2 | ||||
-rw-r--r-- | src/cadet/cadet_api.c | 557 | ||||
-rw-r--r-- | src/cadet/test_cadet.c | 2 |
3 files changed, 293 insertions, 268 deletions
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h index 61388bb15..063711fd2 100644 --- a/src/cadet/cadet.h +++ b/src/cadet/cadet.h | |||
@@ -232,7 +232,7 @@ struct GNUNET_CADET_LocalInfoPeer | |||
232 | int16_t tunnel GNUNET_PACKED; | 232 | int16_t tunnel GNUNET_PACKED; |
233 | 233 | ||
234 | /** | 234 | /** |
235 | * ID of the destination of the tunnel (can be local peer). | 235 | * ID of the peer (can be local peer). |
236 | */ | 236 | */ |
237 | struct GNUNET_PeerIdentity destination; | 237 | struct GNUNET_PeerIdentity destination; |
238 | 238 | ||
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index a9793a7f8..660bcea3d 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c | |||
@@ -742,15 +742,15 @@ handle_local_ack (void *cls, | |||
742 | struct GNUNET_CADET_TransmitHandle *th; | 742 | struct GNUNET_CADET_TransmitHandle *th; |
743 | struct GNUNET_CADET_TransmitHandle *next; | 743 | struct GNUNET_CADET_TransmitHandle *next; |
744 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 744 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
745 | " pending data, sending %U bytes!\n", | 745 | " pending data, sending %u bytes!\n", |
746 | ch->packet_size); | 746 | ch->packet_size); |
747 | for (th = h->th_head; NULL != th; th = next) | 747 | for (th = h->th_head; NULL != th; th = next) |
748 | { | 748 | { |
749 | next = th->next; | 749 | next = th->next; |
750 | if (th->channel == ch) | 750 | if (th->channel == ch) |
751 | { | 751 | { |
752 | GNUNET_assert (NULL == th->request_data_task); | ||
752 | th->request_data_task = GNUNET_SCHEDULER_add_now (&request_data, th); | 753 | th->request_data_task = GNUNET_SCHEDULER_add_now (&request_data, th); |
753 | GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); | ||
754 | break; | 754 | break; |
755 | } | 755 | } |
756 | } | 756 | } |
@@ -802,100 +802,6 @@ handle_mq_error (void *cls, | |||
802 | } | 802 | } |
803 | 803 | ||
804 | 804 | ||
805 | /** | ||
806 | * Reconnect to the service, retransmit all infomation to try to restore the | ||
807 | * original state. | ||
808 | * | ||
809 | * @param h handle to the cadet | ||
810 | * | ||
811 | * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...) | ||
812 | */ | ||
813 | static int | ||
814 | do_reconnect (struct GNUNET_CADET_Handle *h) | ||
815 | { | ||
816 | GNUNET_MQ_hd_fixed_size (channel_created, | ||
817 | GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE, | ||
818 | struct GNUNET_CADET_ChannelCreateMessage); | ||
819 | GNUNET_MQ_hd_fixed_size (channel_destroy, | ||
820 | GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY, | ||
821 | struct GNUNET_CADET_ChannelDestroyMessage); | ||
822 | GNUNET_MQ_hd_var_size (local_data, | ||
823 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, | ||
824 | struct GNUNET_CADET_LocalData); | ||
825 | GNUNET_MQ_hd_fixed_size (local_ack, | ||
826 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, | ||
827 | struct GNUNET_CADET_LocalAck); | ||
828 | // FIXME | ||
829 | // GNUNET_MQ_hd_fixed_Y size (channel_destroyed, | ||
830 | // GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK, | ||
831 | // struct GNUNET_CADET_ChannelDestroyMessage); | ||
832 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
833 | make_channel_created_handler (h), | ||
834 | make_channel_destroy_handler (h), | ||
835 | make_local_data_handler (h), | ||
836 | make_local_ack_handler (h), | ||
837 | GNUNET_MQ_handler_end () | ||
838 | }; | ||
839 | |||
840 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET\n"); | ||
841 | |||
842 | GNUNET_assert (NULL == h->mq); | ||
843 | h->mq = GNUNET_CLIENT_connecT (h->cfg, | ||
844 | "cadet", | ||
845 | handlers, | ||
846 | &handle_mq_error, | ||
847 | h); | ||
848 | if (NULL == h->mq) | ||
849 | { | ||
850 | reconnect (h); | ||
851 | return GNUNET_NO; | ||
852 | } | ||
853 | else | ||
854 | { | ||
855 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; | ||
856 | } | ||
857 | return GNUNET_YES; | ||
858 | } | ||
859 | |||
860 | /** | ||
861 | * Reconnect callback: tries to reconnect again after a failer previous | ||
862 | * reconnecttion | ||
863 | * | ||
864 | * @param cls closure (cadet handle) | ||
865 | */ | ||
866 | static void | ||
867 | reconnect_cbk (void *cls) | ||
868 | { | ||
869 | struct GNUNET_CADET_Handle *h = cls; | ||
870 | |||
871 | h->reconnect_task = NULL; | ||
872 | do_reconnect (h); | ||
873 | } | ||
874 | |||
875 | |||
876 | /** | ||
877 | * Reconnect to the service, retransmit all infomation to try to restore the | ||
878 | * original state. | ||
879 | * | ||
880 | * @param h handle to the cadet | ||
881 | * | ||
882 | * @return #GNUNET_YES in case of sucess, #GNUNET_NO otherwise (service down...) | ||
883 | */ | ||
884 | static void | ||
885 | reconnect (struct GNUNET_CADET_Handle *h) | ||
886 | { | ||
887 | struct GNUNET_CADET_Channel *ch; | ||
888 | |||
889 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
890 | "Requested RECONNECT, destroying all channels\n"); | ||
891 | for (ch = h->channels_head; NULL != ch; ch = h->channels_head) | ||
892 | destroy_channel (ch, GNUNET_YES); | ||
893 | if (NULL == h->reconnect_task) | ||
894 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time, | ||
895 | &reconnect_cbk, h); | ||
896 | } | ||
897 | |||
898 | |||
899 | /* | 805 | /* |
900 | * Process a local reply about info on all channels, pass info to the user. | 806 | * Process a local reply about info on all channels, pass info to the user. |
901 | * | 807 | * |
@@ -983,36 +889,51 @@ reconnect (struct GNUNET_CADET_Handle *h) | |||
983 | 889 | ||
984 | 890 | ||
985 | /** | 891 | /** |
986 | * Process a local reply about info on all tunnels, pass info to the user. | 892 | * Check that message received from CADET service is well-formed. |
987 | * | 893 | * |
988 | * @param h Cadet handle. | 894 | * @param cls the `struct GNUNET_CADET_Handle` |
989 | * @param message Message itself. | 895 | * @param message the message we got |
896 | * @return #GNUNET_OK if the message is well-formed, | ||
897 | * #GNUNET_SYSERR otherwise | ||
990 | */ | 898 | */ |
991 | static void | 899 | static int |
992 | process_get_peers (struct GNUNET_CADET_Handle *h, | 900 | check_get_peers (void *cls, |
993 | const struct GNUNET_MessageHeader *message) | 901 | const struct GNUNET_CADET_LocalInfoPeer *message) |
994 | { | 902 | { |
995 | struct GNUNET_CADET_LocalInfoPeer *msg; | 903 | struct GNUNET_CADET_Handle *h = cls; |
996 | uint16_t size; | 904 | uint16_t size; |
997 | 905 | ||
998 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Peer messasge received\n"); | ||
999 | |||
1000 | if (NULL == h->info_cb.peers_cb) | 906 | if (NULL == h->info_cb.peers_cb) |
1001 | { | 907 | { |
1002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); | 908 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1003 | return; | 909 | " no handler for peesr monitor message!\n"); |
910 | return GNUNET_SYSERR; | ||
1004 | } | 911 | } |
1005 | 912 | ||
1006 | size = ntohs (message->size); | 913 | size = ntohs (message->header.size); |
1007 | if (sizeof (struct GNUNET_CADET_LocalInfoPeer) > size) | 914 | if (sizeof (struct GNUNET_CADET_LocalInfoPeer) > size) |
1008 | { | 915 | { |
1009 | h->info_cb.peers_cb (h->info_cls, NULL, -1, 0, 0); | 916 | h->info_cb.peers_cb (h->info_cls, NULL, -1, 0, 0); |
1010 | h->info_cb.peers_cb = NULL; | 917 | h->info_cb.peers_cb = NULL; |
1011 | h->info_cls = NULL; | 918 | h->info_cls = NULL; |
1012 | return; | 919 | return GNUNET_SYSERR; |
1013 | } | 920 | } |
1014 | 921 | ||
1015 | msg = (struct GNUNET_CADET_LocalInfoPeer *) message; | 922 | return GNUNET_OK; |
923 | } | ||
924 | |||
925 | |||
926 | /** | ||
927 | * Process a local reply about info on all tunnels, pass info to the user. | ||
928 | * | ||
929 | * @param cls Closure (Cadet handle). | ||
930 | * @param msg Message itself. | ||
931 | */ | ||
932 | static void | ||
933 | handle_get_peers (void *cls, | ||
934 | const struct GNUNET_CADET_LocalInfoPeer *msg) | ||
935 | { | ||
936 | struct GNUNET_CADET_Handle *h = cls; | ||
1016 | h->info_cb.peers_cb (h->info_cls, &msg->destination, | 937 | h->info_cb.peers_cb (h->info_cls, &msg->destination, |
1017 | (int) ntohs (msg->tunnel), | 938 | (int) ntohs (msg->tunnel), |
1018 | (unsigned int ) ntohs (msg->paths), | 939 | (unsigned int ) ntohs (msg->paths), |
@@ -1021,71 +942,59 @@ process_get_peers (struct GNUNET_CADET_Handle *h, | |||
1021 | 942 | ||
1022 | 943 | ||
1023 | /** | 944 | /** |
1024 | * Process a local peer info reply, pass info to the user. | 945 | * Check that message received from CADET service is well-formed. |
1025 | * | 946 | * |
1026 | * @param h Cadet handle. | 947 | * @param cls the `struct GNUNET_CADET_Handle` |
1027 | * @param message Message itself. | 948 | * @param message the message we got |
949 | * @return #GNUNET_OK if the message is well-formed, | ||
950 | * #GNUNET_SYSERR otherwise | ||
1028 | */ | 951 | */ |
1029 | static void | 952 | static int |
1030 | process_get_peer (struct GNUNET_CADET_Handle *h, | 953 | check_get_peer (void *cls, |
1031 | const struct GNUNET_MessageHeader *message) | 954 | const struct GNUNET_CADET_LocalInfoPeer *message) |
1032 | { | 955 | { |
1033 | struct GNUNET_CADET_LocalInfoPeer *msg; | 956 | struct GNUNET_CADET_Handle *h = cls; |
1034 | struct GNUNET_PeerIdentity *id; | 957 | const size_t msize = sizeof (struct GNUNET_CADET_LocalInfoPeer); |
958 | struct GNUNET_PeerIdentity *paths_array; | ||
959 | size_t esize; | ||
1035 | unsigned int epaths; | 960 | unsigned int epaths; |
1036 | unsigned int paths; | 961 | unsigned int paths; |
1037 | unsigned int path_length; | 962 | unsigned int peers; |
1038 | unsigned int i; | ||
1039 | int neighbor; | ||
1040 | size_t esize; | ||
1041 | size_t msize; | ||
1042 | 963 | ||
1043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Info Peer messasge received\n"); | ||
1044 | if (NULL == h->info_cb.peer_cb) | 964 | if (NULL == h->info_cb.peer_cb) |
1045 | { | 965 | { |
1046 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); | 966 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1047 | return; | 967 | " no handler for peer monitor message!\n"); |
968 | goto clean_cls; | ||
1048 | } | 969 | } |
1049 | 970 | ||
1050 | /* Verify message sanity */ | 971 | /* Verify message sanity */ |
1051 | msg = (struct GNUNET_CADET_LocalInfoPeer *) message; | 972 | esize = ntohs (message->header.size); |
1052 | esize = ntohs (message->size); | ||
1053 | msize = sizeof (struct GNUNET_CADET_LocalInfoPeer); | ||
1054 | if (esize < msize) | 973 | if (esize < msize) |
1055 | { | 974 | { |
1056 | GNUNET_break_op (0); | 975 | GNUNET_break_op (0); |
1057 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); | 976 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); |
1058 | goto clean_cls; | 977 | goto clean_cls; |
1059 | } | 978 | } |
1060 | epaths = (unsigned int) ntohs (msg->paths); | 979 | if (0 != ((esize - msize) % sizeof (struct GNUNET_PeerIdentity))) |
980 | { | ||
981 | GNUNET_break_op (0); | ||
982 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); | ||
983 | goto clean_cls; | ||
984 | |||
985 | } | ||
986 | peers = (esize - msize) / sizeof (struct GNUNET_PeerIdentity); | ||
987 | epaths = (unsigned int) ntohs (message->paths); | ||
988 | paths_array = (struct GNUNET_PeerIdentity *) &message[1]; | ||
1061 | paths = 0; | 989 | paths = 0; |
1062 | path_length = 0; | 990 | for (int i = 0; i < peers; i++) |
1063 | neighbor = GNUNET_NO; | ||
1064 | id = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
1065 | for (i = 0; msize < esize; i++) | ||
1066 | { | 991 | { |
1067 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (&id[i])); | 992 | if (0 == memcmp (&paths_array[i], &message->destination, |
1068 | msize += sizeof (struct GNUNET_PeerIdentity); | ||
1069 | path_length++; | ||
1070 | if (0 == memcmp (&id[i], &msg->destination, | ||
1071 | sizeof (struct GNUNET_PeerIdentity))) | 993 | sizeof (struct GNUNET_PeerIdentity))) |
1072 | { | 994 | { |
1073 | if (1 == path_length) | ||
1074 | neighbor = GNUNET_YES; | ||
1075 | path_length = 0; | ||
1076 | paths++; | 995 | paths++; |
1077 | } | 996 | } |
1078 | } | 997 | } |
1079 | if (msize != esize) | ||
1080 | { | ||
1081 | GNUNET_break_op (0); | ||
1082 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1083 | "m:%u, e: %u\n", | ||
1084 | (unsigned int) msize, | ||
1085 | (unsigned int) esize); | ||
1086 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); | ||
1087 | goto clean_cls; | ||
1088 | } | ||
1089 | if (paths != epaths) | 998 | if (paths != epaths) |
1090 | { | 999 | { |
1091 | GNUNET_break_op (0); | 1000 | GNUNET_break_op (0); |
@@ -1094,52 +1003,109 @@ process_get_peer (struct GNUNET_CADET_Handle *h, | |||
1094 | goto clean_cls; | 1003 | goto clean_cls; |
1095 | } | 1004 | } |
1096 | 1005 | ||
1097 | /* Call Callback with tunnel info. */ | 1006 | return GNUNET_OK; |
1098 | id = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
1099 | h->info_cb.peer_cb (h->info_cls, | ||
1100 | &msg->destination, | ||
1101 | (int) ntohs (msg->tunnel), | ||
1102 | neighbor, | ||
1103 | paths, | ||
1104 | id); | ||
1105 | 1007 | ||
1106 | clean_cls: | 1008 | clean_cls: |
1107 | h->info_cb.peer_cb = NULL; | 1009 | h->info_cb.peer_cb = NULL; |
1108 | h->info_cls = NULL; | 1010 | h->info_cls = NULL; |
1011 | return GNUNET_SYSERR; | ||
1109 | } | 1012 | } |
1110 | 1013 | ||
1111 | 1014 | ||
1112 | /** | 1015 | /** |
1113 | * Process a local reply about info on all tunnels, pass info to the user. | 1016 | * Process a local peer info reply, pass info to the user. |
1114 | * | 1017 | * |
1115 | * @param h Cadet handle. | 1018 | * @param cls Closure (Cadet handle). |
1116 | * @param message Message itself. | 1019 | * @param message Message itself. |
1117 | */ | 1020 | */ |
1118 | static void | 1021 | static void |
1119 | process_get_tunnels (struct GNUNET_CADET_Handle *h, | 1022 | handle_get_peer (void *cls, |
1120 | const struct GNUNET_MessageHeader *message) | 1023 | const struct GNUNET_CADET_LocalInfoPeer *message) |
1121 | { | 1024 | { |
1122 | struct GNUNET_CADET_LocalInfoTunnel *msg; | 1025 | struct GNUNET_CADET_Handle *h = cls; |
1123 | uint16_t size; | 1026 | struct GNUNET_PeerIdentity *paths_array; |
1027 | unsigned int paths; | ||
1028 | unsigned int path_length; | ||
1029 | int neighbor; | ||
1030 | unsigned int peers; | ||
1031 | |||
1032 | paths = (unsigned int) ntohs (message->paths); | ||
1033 | paths_array = (struct GNUNET_PeerIdentity *) &message[1]; | ||
1034 | peers = (ntohs (message->header.size) - sizeof (*message)) | ||
1035 | / sizeof (struct GNUNET_PeerIdentity); | ||
1036 | path_length = 0; | ||
1037 | neighbor = GNUNET_NO; | ||
1038 | |||
1039 | for (int i = 0; i < peers; i++) | ||
1040 | { | ||
1041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (&paths_array[i])); | ||
1042 | path_length++; | ||
1043 | if (0 == memcmp (&paths_array[i], &message->destination, | ||
1044 | sizeof (struct GNUNET_PeerIdentity))) | ||
1045 | { | ||
1046 | if (1 == path_length) | ||
1047 | neighbor = GNUNET_YES; | ||
1048 | path_length = 0; | ||
1049 | } | ||
1050 | } | ||
1051 | |||
1052 | /* Call Callback with tunnel info. */ | ||
1053 | paths_array = (struct GNUNET_PeerIdentity *) &message[1]; | ||
1054 | h->info_cb.peer_cb (h->info_cls, | ||
1055 | &message->destination, | ||
1056 | (int) ntohs (message->tunnel), | ||
1057 | neighbor, | ||
1058 | paths, | ||
1059 | paths_array); | ||
1060 | } | ||
1061 | |||
1124 | 1062 | ||
1125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnels messasge received\n"); | 1063 | /** |
1064 | * Check that message received from CADET service is well-formed. | ||
1065 | * | ||
1066 | * @param cls the `struct GNUNET_CADET_Handle` | ||
1067 | * @param msg the message we got | ||
1068 | * @return #GNUNET_OK if the message is well-formed, | ||
1069 | * #GNUNET_SYSERR otherwise | ||
1070 | */ | ||
1071 | static int | ||
1072 | check_get_tunnels (void *cls, | ||
1073 | const struct GNUNET_CADET_LocalInfoTunnel *msg) | ||
1074 | { | ||
1075 | struct GNUNET_CADET_Handle *h = cls; | ||
1076 | uint16_t size; | ||
1126 | 1077 | ||
1127 | if (NULL == h->info_cb.tunnels_cb) | 1078 | if (NULL == h->info_cb.tunnels_cb) |
1128 | { | 1079 | { |
1129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); | 1080 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1130 | return; | 1081 | " no handler for tunnels monitor message!\n"); |
1082 | return GNUNET_SYSERR; | ||
1131 | } | 1083 | } |
1132 | 1084 | ||
1133 | size = ntohs (message->size); | 1085 | size = ntohs (msg->header.size); |
1134 | if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) > size) | 1086 | if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) > size) |
1135 | { | 1087 | { |
1136 | h->info_cb.tunnels_cb (h->info_cls, NULL, 0, 0, 0, 0); | 1088 | h->info_cb.tunnels_cb (h->info_cls, NULL, 0, 0, 0, 0); |
1137 | h->info_cb.tunnels_cb = NULL; | 1089 | h->info_cb.tunnels_cb = NULL; |
1138 | h->info_cls = NULL; | 1090 | h->info_cls = NULL; |
1139 | return; | 1091 | return GNUNET_SYSERR; |
1140 | } | 1092 | } |
1093 | return GNUNET_OK; | ||
1094 | } | ||
1095 | |||
1096 | |||
1097 | /** | ||
1098 | * Process a local reply about info on all tunnels, pass info to the user. | ||
1099 | * | ||
1100 | * @param cls Closure (Cadet handle). | ||
1101 | * @param message Message itself. | ||
1102 | */ | ||
1103 | static void | ||
1104 | handle_get_tunnels (void *cls, | ||
1105 | const struct GNUNET_CADET_LocalInfoTunnel *msg) | ||
1106 | { | ||
1107 | struct GNUNET_CADET_Handle *h = cls; | ||
1141 | 1108 | ||
1142 | msg = (struct GNUNET_CADET_LocalInfoTunnel *) message; | ||
1143 | h->info_cb.tunnels_cb (h->info_cls, &msg->destination, | 1109 | h->info_cb.tunnels_cb (h->info_cls, &msg->destination, |
1144 | ntohl (msg->channels), ntohl (msg->connections), | 1110 | ntohl (msg->channels), ntohl (msg->connections), |
1145 | ntohs (msg->estate), ntohs (msg->cstate)); | 1111 | ntohs (msg->estate), ntohs (msg->cstate)); |
@@ -1148,33 +1114,32 @@ process_get_tunnels (struct GNUNET_CADET_Handle *h, | |||
1148 | 1114 | ||
1149 | 1115 | ||
1150 | /** | 1116 | /** |
1151 | * Process a local tunnel info reply, pass info to the user. | 1117 | * Check that message received from CADET service is well-formed. |
1152 | * | 1118 | * |
1153 | * @param h Cadet handle. | 1119 | * @param cls the `struct GNUNET_CADET_Handle` |
1154 | * @param message Message itself. | 1120 | * @param msg the message we got |
1121 | * @return #GNUNET_OK if the message is well-formed, | ||
1122 | * #GNUNET_SYSERR otherwise | ||
1155 | */ | 1123 | */ |
1156 | static void | 1124 | static int |
1157 | process_get_tunnel (struct GNUNET_CADET_Handle *h, | 1125 | check_get_tunnel (void *cls, |
1158 | const struct GNUNET_MessageHeader *message) | 1126 | const struct GNUNET_CADET_LocalInfoTunnel *msg) |
1159 | { | 1127 | { |
1160 | struct GNUNET_CADET_LocalInfoTunnel *msg; | 1128 | struct GNUNET_CADET_Handle *h = cls; |
1161 | size_t esize; | ||
1162 | size_t msize; | ||
1163 | unsigned int ch_n; | 1129 | unsigned int ch_n; |
1164 | unsigned int c_n; | 1130 | unsigned int c_n; |
1165 | struct GNUNET_CADET_Hash *conns; | 1131 | size_t esize; |
1166 | CADET_ChannelNumber *chns; | 1132 | size_t msize; |
1167 | 1133 | ||
1168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnel messasge received\n"); | ||
1169 | if (NULL == h->info_cb.tunnel_cb) | 1134 | if (NULL == h->info_cb.tunnel_cb) |
1170 | { | 1135 | { |
1171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); | 1136 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1172 | return; | 1137 | " no handler for tunnel monitor message!\n"); |
1138 | goto clean_cls; | ||
1173 | } | 1139 | } |
1174 | 1140 | ||
1175 | /* Verify message sanity */ | 1141 | /* Verify message sanity */ |
1176 | msg = (struct GNUNET_CADET_LocalInfoTunnel *) message; | 1142 | msize = ntohs (msg->header.size); |
1177 | msize = ntohs (message->size); | ||
1178 | esize = sizeof (struct GNUNET_CADET_LocalInfoTunnel); | 1143 | esize = sizeof (struct GNUNET_CADET_LocalInfoTunnel); |
1179 | if (esize > msize) | 1144 | if (esize > msize) |
1180 | { | 1145 | { |
@@ -1195,96 +1160,156 @@ process_get_tunnel (struct GNUNET_CADET_Handle *h, | |||
1195 | (unsigned int) esize, | 1160 | (unsigned int) esize, |
1196 | ch_n, | 1161 | ch_n, |
1197 | c_n); | 1162 | c_n); |
1198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1199 | "%u (%u ch, %u conn)\n", | ||
1200 | (unsigned int) sizeof (struct GNUNET_CADET_LocalInfoTunnel), | ||
1201 | (unsigned int) sizeof (CADET_ChannelNumber), | ||
1202 | (unsigned int) sizeof (struct GNUNET_HashCode)); | ||
1203 | h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0); | 1163 | h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0); |
1204 | goto clean_cls; | 1164 | goto clean_cls; |
1205 | } | 1165 | } |
1206 | 1166 | ||
1167 | return GNUNET_OK; | ||
1168 | |||
1169 | clean_cls: | ||
1170 | h->info_cb.tunnel_cb = NULL; | ||
1171 | h->info_cls = NULL; | ||
1172 | return GNUNET_SYSERR; | ||
1173 | } | ||
1174 | |||
1175 | |||
1176 | /** | ||
1177 | * Process a local tunnel info reply, pass info to the user. | ||
1178 | * | ||
1179 | * @param cls Closure (Cadet handle). | ||
1180 | * @param msg Message itself. | ||
1181 | */ | ||
1182 | static void | ||
1183 | handle_get_tunnel (void *cls, | ||
1184 | const struct GNUNET_CADET_LocalInfoTunnel *msg) | ||
1185 | { | ||
1186 | struct GNUNET_CADET_Handle *h = cls; | ||
1187 | unsigned int ch_n; | ||
1188 | unsigned int c_n; | ||
1189 | struct GNUNET_CADET_Hash *conns; | ||
1190 | CADET_ChannelNumber *chns; | ||
1191 | |||
1192 | ch_n = ntohl (msg->channels); | ||
1193 | c_n = ntohl (msg->connections); | ||
1194 | |||
1207 | /* Call Callback with tunnel info. */ | 1195 | /* Call Callback with tunnel info. */ |
1208 | conns = (struct GNUNET_CADET_Hash *) &msg[1]; | 1196 | conns = (struct GNUNET_CADET_Hash *) &msg[1]; |
1209 | chns = (CADET_ChannelNumber *) &conns[c_n]; | 1197 | chns = (CADET_ChannelNumber *) &conns[c_n]; |
1210 | h->info_cb.tunnel_cb (h->info_cls, &msg->destination, | 1198 | h->info_cb.tunnel_cb (h->info_cls, &msg->destination, |
1211 | ch_n, c_n, chns, conns, | 1199 | ch_n, c_n, chns, conns, |
1212 | ntohs (msg->estate), ntohs (msg->cstate)); | 1200 | ntohs (msg->estate), ntohs (msg->cstate)); |
1201 | } | ||
1213 | 1202 | ||
1214 | clean_cls: | 1203 | |
1215 | h->info_cb.tunnel_cb = NULL; | 1204 | |
1216 | h->info_cls = NULL; | 1205 | /** |
1206 | * Reconnect to the service, retransmit all infomation to try to restore the | ||
1207 | * original state. | ||
1208 | * | ||
1209 | * @param h handle to the cadet | ||
1210 | * | ||
1211 | * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...) | ||
1212 | */ | ||
1213 | static int | ||
1214 | do_reconnect (struct GNUNET_CADET_Handle *h) | ||
1215 | { | ||
1216 | GNUNET_MQ_hd_fixed_size (channel_created, | ||
1217 | GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE, | ||
1218 | struct GNUNET_CADET_ChannelCreateMessage); | ||
1219 | GNUNET_MQ_hd_fixed_size (channel_destroy, | ||
1220 | GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY, | ||
1221 | struct GNUNET_CADET_ChannelDestroyMessage); | ||
1222 | GNUNET_MQ_hd_var_size (local_data, | ||
1223 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, | ||
1224 | struct GNUNET_CADET_LocalData); | ||
1225 | GNUNET_MQ_hd_fixed_size (local_ack, | ||
1226 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, | ||
1227 | struct GNUNET_CADET_LocalAck); | ||
1228 | GNUNET_MQ_hd_var_size (get_peers, | ||
1229 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, | ||
1230 | struct GNUNET_CADET_LocalInfoPeer); | ||
1231 | GNUNET_MQ_hd_var_size (get_peer, | ||
1232 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER, | ||
1233 | struct GNUNET_CADET_LocalInfoPeer); | ||
1234 | GNUNET_MQ_hd_var_size (get_tunnels, | ||
1235 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, | ||
1236 | struct GNUNET_CADET_LocalInfoTunnel); | ||
1237 | GNUNET_MQ_hd_var_size (get_tunnel, | ||
1238 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, | ||
1239 | struct GNUNET_CADET_LocalInfoTunnel); | ||
1240 | // FIXME | ||
1241 | // GNUNET_MQ_hd_fixed_Y size (channel_destroyed, | ||
1242 | // GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK, | ||
1243 | // struct GNUNET_CADET_ChannelDestroyMessage); | ||
1244 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
1245 | make_channel_created_handler (h), | ||
1246 | make_channel_destroy_handler (h), | ||
1247 | make_local_data_handler (h), | ||
1248 | make_local_ack_handler (h), | ||
1249 | make_get_peers_handler (h), | ||
1250 | make_get_peer_handler (h), | ||
1251 | make_get_tunnels_handler (h), | ||
1252 | make_get_tunnel_handler (h), | ||
1253 | GNUNET_MQ_handler_end () | ||
1254 | }; | ||
1255 | |||
1256 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET\n"); | ||
1257 | |||
1258 | GNUNET_assert (NULL == h->mq); | ||
1259 | h->mq = GNUNET_CLIENT_connecT (h->cfg, | ||
1260 | "cadet", | ||
1261 | handlers, | ||
1262 | &handle_mq_error, | ||
1263 | h); | ||
1264 | if (NULL == h->mq) | ||
1265 | { | ||
1266 | reconnect (h); | ||
1267 | return GNUNET_NO; | ||
1268 | } | ||
1269 | else | ||
1270 | { | ||
1271 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; | ||
1272 | } | ||
1273 | return GNUNET_YES; | ||
1217 | } | 1274 | } |
1218 | 1275 | ||
1276 | /** | ||
1277 | * Reconnect callback: tries to reconnect again after a failer previous | ||
1278 | * reconnecttion | ||
1279 | * | ||
1280 | * @param cls closure (cadet handle) | ||
1281 | */ | ||
1282 | static void | ||
1283 | reconnect_cbk (void *cls) | ||
1284 | { | ||
1285 | struct GNUNET_CADET_Handle *h = cls; | ||
1219 | 1286 | ||
1220 | // FIXME: add monitor messages to mq | 1287 | h->reconnect_task = NULL; |
1221 | // static void | 1288 | do_reconnect (h); |
1222 | // msg_received (void *cls, const struct GNUNET_MessageHeader *msg) | 1289 | } |
1223 | // { | 1290 | |
1224 | // struct GNUNET_CADET_Handle *h = cls; | 1291 | |
1225 | // uint16_t type; | 1292 | /** |
1226 | // | 1293 | * Reconnect to the service, retransmit all infomation to try to restore the |
1227 | // if (msg == NULL) | 1294 | * original state. |
1228 | // { | 1295 | * |
1229 | // LOG (GNUNET_ERROR_TYPE_DEBUG, | 1296 | * @param h handle to the cadet |
1230 | // "Cadet service disconnected, reconnecting\n", h); | 1297 | * |
1231 | // reconnect (h); | 1298 | * @return #GNUNET_YES in case of sucess, #GNUNET_NO otherwise (service down...) |
1232 | // return; | 1299 | */ |
1233 | // } | 1300 | static void |
1234 | // type = ntohs (msg->type); | 1301 | reconnect (struct GNUNET_CADET_Handle *h) |
1235 | // LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); | 1302 | { |
1236 | // LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a message: %s\n", | 1303 | struct GNUNET_CADET_Channel *ch; |
1237 | // GC_m2s (type)); | 1304 | |
1238 | // switch (type) | 1305 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1239 | // { | 1306 | "Requested RECONNECT, destroying all channels\n"); |
1240 | // /* Notify of a new incoming channel */ | 1307 | for (ch = h->channels_head; NULL != ch; ch = h->channels_head) |
1241 | // case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE: | 1308 | destroy_channel (ch, GNUNET_YES); |
1242 | // // process_channel_created (h, | 1309 | if (NULL == h->reconnect_task) |
1243 | // // (struct GNUNET_CADET_ChannelCreateMessage *) msg); | 1310 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time, |
1244 | // break; | 1311 | &reconnect_cbk, h); |
1245 | // /* Notify of a channel disconnection */ | 1312 | } |
1246 | // case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY: /* TODO separate(gid problem)*/ | ||
1247 | // case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK: | ||
1248 | // // process_channel_destroy (h, | ||
1249 | // // (struct GNUNET_CADET_ChannelDestroyMessage *) msg); | ||
1250 | // break; | ||
1251 | // case GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA: | ||
1252 | // // process_incoming_data (h, msg); | ||
1253 | // break; | ||
1254 | // case GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK: | ||
1255 | // // process_ack (h, msg); | ||
1256 | // break; | ||
1257 | // // case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNELS: | ||
1258 | // // process_get_channels (h, msg); | ||
1259 | // // break; | ||
1260 | // // case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL: | ||
1261 | // // process_show_channel (h, msg); | ||
1262 | // // break; | ||
1263 | // case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS: | ||
1264 | // process_get_peers (h, msg); | ||
1265 | // break; | ||
1266 | // case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER: | ||
1267 | // process_get_peer (h, msg); | ||
1268 | // break; | ||
1269 | // case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS: | ||
1270 | // process_get_tunnels (h, msg); | ||
1271 | // break; | ||
1272 | // case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL: | ||
1273 | // process_get_tunnel (h, msg); | ||
1274 | // break; | ||
1275 | // // case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL: | ||
1276 | // // process_show_channel (h, msg); | ||
1277 | // // break; | ||
1278 | // default: | ||
1279 | // /* We shouldn't get any other packages, log and ignore */ | ||
1280 | // LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1281 | // "unsolicited message form service (type %s)\n", | ||
1282 | // GC_m2s (ntohs (msg->type))); | ||
1283 | // } | ||
1284 | // LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n"); | ||
1285 | // GNUNET_CLIENT_receive (h->client, &msg_received, h, | ||
1286 | // GNUNET_TIME_UNIT_FOREVER_REL); | ||
1287 | // } | ||
1288 | 1313 | ||
1289 | 1314 | ||
1290 | /******************************************************************************/ | 1315 | /******************************************************************************/ |
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index e2d3902e5..cf18b8a90 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c | |||
@@ -33,7 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * How many messages to send | 34 | * How many messages to send |
35 | */ | 35 | */ |
36 | #define TOTAL_PACKETS 5000 /* Cannot exceed 64k! */ | 36 | #define TOTAL_PACKETS 500 /* Cannot exceed 64k! */ |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * How long until we give up on connecting the peers? | 39 | * How long until we give up on connecting the peers? |