diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet.c | 158 |
1 files changed, 20 insertions, 138 deletions
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c index ae5d48943..a62ce4cb0 100644 --- a/src/cadet/gnunet-service-cadet.c +++ b/src/cadet/gnunet-service-cadet.c | |||
@@ -821,7 +821,7 @@ get_all_peers_iterator (void *cls, | |||
821 | struct CadetClient *c = cls; | 821 | struct CadetClient *c = cls; |
822 | struct CadetPeer *p = value; | 822 | struct CadetPeer *p = value; |
823 | struct GNUNET_MQ_Envelope *env; | 823 | struct GNUNET_MQ_Envelope *env; |
824 | struct GNUNET_CADET_LocalInfoPeer *msg; | 824 | struct GNUNET_CADET_LocalInfoPeers *msg; |
825 | 825 | ||
826 | env = GNUNET_MQ_msg (msg, | 826 | env = GNUNET_MQ_msg (msg, |
827 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); | 827 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); |
@@ -829,6 +829,7 @@ get_all_peers_iterator (void *cls, | |||
829 | msg->paths = htons (GCP_count_paths (p)); | 829 | msg->paths = htons (GCP_count_paths (p)); |
830 | msg->tunnel = htons (NULL != GCP_get_tunnel (p, | 830 | msg->tunnel = htons (NULL != GCP_get_tunnel (p, |
831 | GNUNET_NO)); | 831 | GNUNET_NO)); |
832 | msg->best_path_length = htonl (0); // FIXME: get length of shortest known path! | ||
832 | GNUNET_MQ_send (c->mq, | 833 | GNUNET_MQ_send (c->mq, |
833 | env); | 834 | env); |
834 | return GNUNET_YES; | 835 | return GNUNET_YES; |
@@ -852,7 +853,7 @@ handle_get_peers (void *cls, | |||
852 | GCP_iterate_all (&get_all_peers_iterator, | 853 | GCP_iterate_all (&get_all_peers_iterator, |
853 | c); | 854 | c); |
854 | env = GNUNET_MQ_msg (reply, | 855 | env = GNUNET_MQ_msg (reply, |
855 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); | 856 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END); |
856 | GNUNET_MQ_send (c->mq, | 857 | GNUNET_MQ_send (c->mq, |
857 | env); | 858 | env); |
858 | GNUNET_SERVICE_client_continue (c->client); | 859 | GNUNET_SERVICE_client_continue (c->client); |
@@ -876,10 +877,9 @@ path_info_iterator (void *cls, | |||
876 | { | 877 | { |
877 | struct GNUNET_MQ_Handle *mq = cls; | 878 | struct GNUNET_MQ_Handle *mq = cls; |
878 | struct GNUNET_MQ_Envelope *env; | 879 | struct GNUNET_MQ_Envelope *env; |
879 | struct GNUNET_CADET_LocalInfoPeer *resp; | 880 | struct GNUNET_CADET_LocalInfoPath *resp; |
880 | struct GNUNET_PeerIdentity *id; | 881 | struct GNUNET_PeerIdentity *id; |
881 | uint16_t path_size; | 882 | size_t path_size; |
882 | unsigned int i; | ||
883 | unsigned int path_length; | 883 | unsigned int path_length; |
884 | 884 | ||
885 | path_length = GCPP_get_length (path); | 885 | path_length = GCPP_get_length (path); |
@@ -893,18 +893,13 @@ path_info_iterator (void *cls, | |||
893 | } | 893 | } |
894 | env = GNUNET_MQ_msg_extra (resp, | 894 | env = GNUNET_MQ_msg_extra (resp, |
895 | path_size, | 895 | path_size, |
896 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); | 896 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH); |
897 | |||
898 | |||
899 | resp->offset = htons(off); | ||
900 | resp->finished_with_paths = htons(0); | ||
901 | |||
902 | id = (struct GNUNET_PeerIdentity *) &resp[1]; | 897 | id = (struct GNUNET_PeerIdentity *) &resp[1]; |
903 | 898 | ||
904 | /* Don't copy first peer. First peer is always the local one. Last | 899 | /* Don't copy first peer. First peer is always the local one. Last |
905 | * peer is always the destination (leave as 0, EOL). | 900 | * peer is always the destination (leave as 0, EOL). |
906 | */ | 901 | */ |
907 | for (i = 0; i <= off; i++) | 902 | for (unsigned int i = 0; i <= off; i++) |
908 | id[i] = *GCP_get_id (GCPP_get_peer_at_offset (path, | 903 | id[i] = *GCP_get_id (GCPP_get_peer_at_offset (path, |
909 | i)); | 904 | i)); |
910 | GNUNET_MQ_send (mq, | 905 | GNUNET_MQ_send (mq, |
@@ -912,70 +907,32 @@ path_info_iterator (void *cls, | |||
912 | return GNUNET_YES; | 907 | return GNUNET_YES; |
913 | } | 908 | } |
914 | 909 | ||
915 | /** | ||
916 | * Getting summary information about the number of paths and if a tunnel exists, | ||
917 | * and the indirect paths to a peer, if there are ones. | ||
918 | * | ||
919 | * @param cls Closure (). | ||
920 | * @param peer Peer ID (tunnel remote peer). | ||
921 | * @param value Peer info. | ||
922 | * @return #GNUNET_YES, to keep iterating. | ||
923 | */ | ||
924 | static void | ||
925 | get_peer_info (void *cls, | ||
926 | const struct GNUNET_PeerIdentity *peer, | ||
927 | struct CadetPeer *p) | ||
928 | { | ||
929 | struct CadetClient *c = cls; | ||
930 | struct GNUNET_MQ_Envelope *env; | ||
931 | struct GNUNET_CADET_LocalInfoPeer *msg; | ||
932 | |||
933 | env = GNUNET_MQ_msg (msg, | ||
934 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); | ||
935 | msg->offset = htons(0); | ||
936 | msg->destination = *peer; | ||
937 | msg->paths = htons (GCP_count_paths (p)); | ||
938 | msg->tunnel = htons (NULL != GCP_get_tunnel (p, | ||
939 | GNUNET_NO)); | ||
940 | msg->finished_with_paths = htons(0); | ||
941 | GNUNET_MQ_send (c->mq, | ||
942 | env); | ||
943 | GCP_iterate_indirect_paths (p, | ||
944 | &path_info_iterator, | ||
945 | c->mq); | ||
946 | } | ||
947 | |||
948 | 910 | ||
949 | /** | 911 | /** |
950 | * Handler for client's SHOW_PEER request. | 912 | * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH request. |
951 | * | 913 | * |
952 | * @param cls Identification of the client. | 914 | * @param cls Identification of the client. |
953 | * @param msg The actual message. | 915 | * @param msg The actual message. |
954 | */ | 916 | */ |
955 | static void | 917 | static void |
956 | handle_show_peer (void *cls, | 918 | handle_show_path (void *cls, |
957 | const struct GNUNET_CADET_LocalInfo *msg) | 919 | const struct GNUNET_CADET_RequestPathInfoMessage *msg) |
958 | { | 920 | { |
959 | struct CadetClient *c = cls; | 921 | struct CadetClient *c = cls; |
960 | struct CadetPeer *p; | 922 | struct CadetPeer *p; |
961 | struct GNUNET_MQ_Envelope *env; | 923 | struct GNUNET_MQ_Envelope *env; |
962 | struct GNUNET_CADET_LocalInfoPeer *resp; | 924 | struct GNUNET_MessageHeader *resp; |
963 | 925 | ||
964 | p = GCP_get (&msg->peer, | 926 | p = GCP_get (&msg->peer, |
965 | GNUNET_NO); | 927 | GNUNET_NO); |
966 | if (NULL != p){ | 928 | if (NULL != p) |
967 | get_peer_info(c, &(msg->peer), p); | 929 | GCP_iterate_indirect_paths (p, |
968 | } | 930 | &path_info_iterator, |
969 | 931 | c->mq); | |
970 | |||
971 | env = GNUNET_MQ_msg (resp, | 932 | env = GNUNET_MQ_msg (resp, |
972 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); | 933 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END); |
973 | resp->finished_with_paths = htons(1); | ||
974 | resp->destination = msg->peer; | ||
975 | |||
976 | GNUNET_MQ_send (c->mq, | 934 | GNUNET_MQ_send (c->mq, |
977 | env); | 935 | env); |
978 | |||
979 | GNUNET_SERVICE_client_continue (c->client); | 936 | GNUNET_SERVICE_client_continue (c->client); |
980 | } | 937 | } |
981 | 938 | ||
@@ -1144,77 +1101,6 @@ handle_info_tunnel (void *cls, | |||
1144 | 1101 | ||
1145 | 1102 | ||
1146 | /** | 1103 | /** |
1147 | * Iterator over all peers to dump info for each peer. | ||
1148 | * | ||
1149 | * @param cls Closure (unused). | ||
1150 | * @param peer Peer ID (tunnel remote peer). | ||
1151 | * @param value Peer info. | ||
1152 | * | ||
1153 | * @return #GNUNET_YES, to keep iterating. | ||
1154 | */ | ||
1155 | static int | ||
1156 | show_peer_iterator (void *cls, | ||
1157 | const struct GNUNET_PeerIdentity *peer, | ||
1158 | void *value) | ||
1159 | { | ||
1160 | struct CadetPeer *p = value; | ||
1161 | struct CadetTunnel *t; | ||
1162 | |||
1163 | t = GCP_get_tunnel (p, | ||
1164 | GNUNET_NO); | ||
1165 | if (NULL != t) | ||
1166 | GCT_debug (t, | ||
1167 | GNUNET_ERROR_TYPE_ERROR); | ||
1168 | LOG (GNUNET_ERROR_TYPE_ERROR, "\n"); | ||
1169 | return GNUNET_YES; | ||
1170 | } | ||
1171 | |||
1172 | |||
1173 | /** | ||
1174 | * Handler for client's INFO_DUMP request. | ||
1175 | * | ||
1176 | * @param cls Identification of the client. | ||
1177 | * @param message The actual message. | ||
1178 | */ | ||
1179 | static void | ||
1180 | handle_info_dump (void *cls, | ||
1181 | const struct GNUNET_MessageHeader *message) | ||
1182 | { | ||
1183 | struct CadetClient *c = cls; | ||
1184 | |||
1185 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1186 | "Received dump info request from client %u\n", | ||
1187 | c->id); | ||
1188 | |||
1189 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1190 | "*************************** DUMP START ***************************\n"); | ||
1191 | for (struct CadetClient *ci = clients_head; | ||
1192 | NULL != ci; | ||
1193 | ci = ci->next) | ||
1194 | { | ||
1195 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1196 | "Client %u (%p), handle: %p, ports: %u, channels: %u\n", | ||
1197 | ci->id, | ||
1198 | ci, | ||
1199 | ci->client, | ||
1200 | (NULL != c->ports) | ||
1201 | ? GNUNET_CONTAINER_multihashmap_size (ci->ports) | ||
1202 | : 0, | ||
1203 | GNUNET_CONTAINER_multihashmap32_size (ci->channels)); | ||
1204 | } | ||
1205 | LOG (GNUNET_ERROR_TYPE_ERROR, "***************************\n"); | ||
1206 | GCP_iterate_all (&show_peer_iterator, | ||
1207 | NULL); | ||
1208 | |||
1209 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1210 | "**************************** DUMP END ****************************\n"); | ||
1211 | |||
1212 | GNUNET_SERVICE_client_continue (c->client); | ||
1213 | } | ||
1214 | |||
1215 | |||
1216 | |||
1217 | /** | ||
1218 | * Callback called when a client connects to the service. | 1104 | * Callback called when a client connects to the service. |
1219 | * | 1105 | * |
1220 | * @param cls closure for the service | 1106 | * @param cls closure for the service |
@@ -1541,12 +1427,12 @@ GNUNET_SERVICE_MAIN | |||
1541 | struct GNUNET_CADET_LocalAck, | 1427 | struct GNUNET_CADET_LocalAck, |
1542 | NULL), | 1428 | NULL), |
1543 | GNUNET_MQ_hd_fixed_size (get_peers, | 1429 | GNUNET_MQ_hd_fixed_size (get_peers, |
1544 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, | 1430 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS, |
1545 | struct GNUNET_MessageHeader, | 1431 | struct GNUNET_MessageHeader, |
1546 | NULL), | 1432 | NULL), |
1547 | GNUNET_MQ_hd_fixed_size (show_peer, | 1433 | GNUNET_MQ_hd_fixed_size (show_path, |
1548 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER, | 1434 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH, |
1549 | struct GNUNET_CADET_LocalInfo, | 1435 | struct GNUNET_CADET_RequestPathInfoMessage, |
1550 | NULL), | 1436 | NULL), |
1551 | GNUNET_MQ_hd_fixed_size (info_tunnels, | 1437 | GNUNET_MQ_hd_fixed_size (info_tunnels, |
1552 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, | 1438 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, |
@@ -1556,10 +1442,6 @@ GNUNET_SERVICE_MAIN | |||
1556 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, | 1442 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, |
1557 | struct GNUNET_CADET_LocalInfo, | 1443 | struct GNUNET_CADET_LocalInfo, |
1558 | NULL), | 1444 | NULL), |
1559 | GNUNET_MQ_hd_fixed_size (info_dump, | ||
1560 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP, | ||
1561 | struct GNUNET_MessageHeader, | ||
1562 | NULL), | ||
1563 | GNUNET_MQ_handler_end ()); | 1445 | GNUNET_MQ_handler_end ()); |
1564 | 1446 | ||
1565 | /* end of gnunet-service-cadet-new.c */ | 1447 | /* end of gnunet-service-cadet-new.c */ |