aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/gnunet-service-cadet.c')
-rw-r--r--src/cadet/gnunet-service-cadet.c85
1 files changed, 63 insertions, 22 deletions
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c
index 20e4c363e..4568d2733 100644
--- a/src/cadet/gnunet-service-cadet.c
+++ b/src/cadet/gnunet-service-cadet.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2013, 2017 GNUnet e.V. 3 Copyright (C) 2001-2013, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
@@ -763,6 +761,7 @@ handle_local_data (void *cls,
763 buf, 761 buf,
764 payload_size)) 762 payload_size))
765 { 763 {
764 GNUNET_break (0);
766 GNUNET_SERVICE_client_drop (c->client); 765 GNUNET_SERVICE_client_drop (c->client);
767 return; 766 return;
768 } 767 }
@@ -823,7 +822,7 @@ get_all_peers_iterator (void *cls,
823 struct GNUNET_CADET_LocalInfoPeer *msg; 822 struct GNUNET_CADET_LocalInfoPeer *msg;
824 823
825 env = GNUNET_MQ_msg (msg, 824 env = GNUNET_MQ_msg (msg,
826 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); 825 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS);
827 msg->destination = *peer; 826 msg->destination = *peer;
828 msg->paths = htons (GCP_count_paths (p)); 827 msg->paths = htons (GCP_count_paths (p));
829 msg->tunnel = htons (NULL != GCP_get_tunnel (p, 828 msg->tunnel = htons (NULL != GCP_get_tunnel (p,
@@ -875,14 +874,14 @@ path_info_iterator (void *cls,
875{ 874{
876 struct GNUNET_MQ_Handle *mq = cls; 875 struct GNUNET_MQ_Handle *mq = cls;
877 struct GNUNET_MQ_Envelope *env; 876 struct GNUNET_MQ_Envelope *env;
878 struct GNUNET_MessageHeader *resp; 877 struct GNUNET_CADET_LocalInfoPeer *resp;
879 struct GNUNET_PeerIdentity *id; 878 struct GNUNET_PeerIdentity *id;
880 uint16_t path_size; 879 uint16_t path_size;
881 unsigned int i; 880 unsigned int i;
882 unsigned int path_length; 881 unsigned int path_length;
883 882
884 path_length = GCPP_get_length (path); 883 path_length = GCPP_get_length (path);
885 path_size = sizeof (struct GNUNET_PeerIdentity) * (path_length - 1); 884 path_size = sizeof (struct GNUNET_PeerIdentity) * path_length;
886 if (sizeof (*resp) + path_size > UINT16_MAX) 885 if (sizeof (*resp) + path_size > UINT16_MAX)
887 { 886 {
888 LOG (GNUNET_ERROR_TYPE_WARNING, 887 LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -893,19 +892,57 @@ path_info_iterator (void *cls,
893 env = GNUNET_MQ_msg_extra (resp, 892 env = GNUNET_MQ_msg_extra (resp,
894 path_size, 893 path_size,
895 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); 894 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER);
895
896
897 resp->offset = htons(off);
898 resp->finished_with_paths = htons(0);
899
896 id = (struct GNUNET_PeerIdentity *) &resp[1]; 900 id = (struct GNUNET_PeerIdentity *) &resp[1];
897 901
898 /* Don't copy first peer. First peer is always the local one. Last 902 /* Don't copy first peer. First peer is always the local one. Last
899 * peer is always the destination (leave as 0, EOL). 903 * peer is always the destination (leave as 0, EOL).
900 */ 904 */
901 for (i = 0; i < off; i++) 905 for (i = 0; i <= off; i++)
902 id[i] = *GCP_get_id (GCPP_get_peer_at_offset (path, 906 id[i] = *GCP_get_id (GCPP_get_peer_at_offset (path,
903 i + 1)); 907 i));
904 GNUNET_MQ_send (mq, 908 GNUNET_MQ_send (mq,
905 env); 909 env);
906 return GNUNET_YES; 910 return GNUNET_YES;
907} 911}
908 912
913/**
914 * Getting summary information about the number of paths and if a tunnel exists,
915 * and the indirect paths to a peer, if there are ones.
916 *
917 * @param cls Closure ().
918 * @param peer Peer ID (tunnel remote peer).
919 * @param value Peer info.
920 * @return #GNUNET_YES, to keep iterating.
921 */
922static void
923get_peer_info (void *cls,
924 const struct GNUNET_PeerIdentity *peer,
925 struct CadetPeer *p)
926{
927 struct CadetClient *c = cls;
928 struct GNUNET_MQ_Envelope *env;
929 struct GNUNET_CADET_LocalInfoPeer *msg;
930
931 env = GNUNET_MQ_msg (msg,
932 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER);
933 msg->offset = htons(0);
934 msg->destination = *peer;
935 msg->paths = htons (GCP_count_paths (p));
936 msg->tunnel = htons (NULL != GCP_get_tunnel (p,
937 GNUNET_NO));
938 msg->finished_with_paths = htons(0);
939 GNUNET_MQ_send (c->mq,
940 env);
941 GCP_iterate_indirect_paths (p,
942 &path_info_iterator,
943 c->mq);
944}
945
909 946
910/** 947/**
911 * Handler for client's SHOW_PEER request. 948 * Handler for client's SHOW_PEER request.
@@ -920,19 +957,23 @@ handle_show_peer (void *cls,
920 struct CadetClient *c = cls; 957 struct CadetClient *c = cls;
921 struct CadetPeer *p; 958 struct CadetPeer *p;
922 struct GNUNET_MQ_Envelope *env; 959 struct GNUNET_MQ_Envelope *env;
923 struct GNUNET_MessageHeader *resp; 960 struct GNUNET_CADET_LocalInfoPeer *resp;
924 961
925 p = GCP_get (&msg->peer, 962 p = GCP_get (&msg->peer,
926 GNUNET_NO); 963 GNUNET_NO);
927 if (NULL != p) 964 if (NULL != p){
928 GCP_iterate_paths (p, 965 get_peer_info(c, &(msg->peer), p);
929 &path_info_iterator, 966 }
930 c->mq); 967
931 /* Send message with 0/0 to indicate the end */ 968
932 env = GNUNET_MQ_msg (resp, 969 env = GNUNET_MQ_msg (resp,
933 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER_END); 970 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER);
971 resp->finished_with_paths = htons(1);
972 resp->destination = msg->peer;
973
934 GNUNET_MQ_send (c->mq, 974 GNUNET_MQ_send (c->mq,
935 env); 975 env);
976
936 GNUNET_SERVICE_client_continue (c->client); 977 GNUNET_SERVICE_client_continue (c->client);
937} 978}
938 979