diff options
author | t3sserakt <t3ss@posteo.de> | 2018-06-25 23:46:01 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2018-06-25 23:46:01 +0200 |
commit | 1aac0fdeaa4af2c7b14b81f0a90f0465b9c681f4 (patch) | |
tree | c965610083cc4079d812b9c78165995177d78fb2 /src | |
parent | 23644d2ef3a3c0299b681e68a7122bc5becff322 (diff) | |
download | gnunet-1aac0fdeaa4af2c7b14b81f0a90f0465b9c681f4.tar.gz gnunet-1aac0fdeaa4af2c7b14b81f0a90f0465b9c681f4.zip |
bug 5228: made gnunet-cadet -p work as intended
Diffstat (limited to 'src')
-rw-r--r-- | src/cadet/cadet.h | 10 | ||||
-rw-r--r-- | src/cadet/cadet_api.c | 22 | ||||
-rw-r--r-- | src/cadet/gnunet-cadet.c | 52 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet.c | 64 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet_paths.c | 2 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet_peer.c | 35 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet_peer.h | 13 | ||||
-rw-r--r-- | src/include/gnunet_cadet_service.h | 4 |
8 files changed, 160 insertions, 42 deletions
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h index 69be4e537..bac4bc49d 100644 --- a/src/cadet/cadet.h +++ b/src/cadet/cadet.h | |||
@@ -258,6 +258,11 @@ struct GNUNET_CADET_LocalInfoPeer | |||
258 | * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS | 258 | * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS |
259 | */ | 259 | */ |
260 | struct GNUNET_MessageHeader header; | 260 | struct GNUNET_MessageHeader header; |
261 | |||
262 | /** | ||
263 | * Offset the peer has in the path this message is about. | ||
264 | */ | ||
265 | uint16_t offset GNUNET_PACKED; | ||
261 | 266 | ||
262 | /** | 267 | /** |
263 | * Number of paths. | 268 | * Number of paths. |
@@ -268,6 +273,11 @@ struct GNUNET_CADET_LocalInfoPeer | |||
268 | * Do we have a tunnel toward this peer? | 273 | * Do we have a tunnel toward this peer? |
269 | */ | 274 | */ |
270 | int16_t tunnel GNUNET_PACKED; | 275 | int16_t tunnel GNUNET_PACKED; |
276 | |||
277 | /** | ||
278 | * We are finished with the paths. | ||
279 | */ | ||
280 | uint16_t finished_with_paths; | ||
271 | 281 | ||
272 | /** | 282 | /** |
273 | * ID of the peer (can be local peer). | 283 | * ID of the peer (can be local peer). |
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index 91054cd4f..b019424f9 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c | |||
@@ -898,7 +898,6 @@ check_get_peer (void *cls, | |||
898 | const struct GNUNET_PeerIdentity *paths_array; | 898 | const struct GNUNET_PeerIdentity *paths_array; |
899 | size_t esize; | 899 | size_t esize; |
900 | unsigned int epaths; | 900 | unsigned int epaths; |
901 | unsigned int paths; | ||
902 | unsigned int peers; | 901 | unsigned int peers; |
903 | 902 | ||
904 | esize = ntohs (message->header.size); | 903 | esize = ntohs (message->header.size); |
@@ -915,17 +914,7 @@ check_get_peer (void *cls, | |||
915 | peers = (esize - msize) / sizeof (struct GNUNET_PeerIdentity); | 914 | peers = (esize - msize) / sizeof (struct GNUNET_PeerIdentity); |
916 | epaths = ntohs (message->paths); | 915 | epaths = ntohs (message->paths); |
917 | paths_array = (const struct GNUNET_PeerIdentity *) &message[1]; | 916 | paths_array = (const struct GNUNET_PeerIdentity *) &message[1]; |
918 | paths = 0; | 917 | |
919 | for (unsigned int i = 0; i < peers; i++) | ||
920 | if (0 == memcmp (&paths_array[i], | ||
921 | &message->destination, | ||
922 | sizeof (struct GNUNET_PeerIdentity))) | ||
923 | paths++; | ||
924 | if (paths != epaths) | ||
925 | { | ||
926 | GNUNET_break (0); | ||
927 | return GNUNET_SYSERR; | ||
928 | } | ||
929 | return GNUNET_OK; | 918 | return GNUNET_OK; |
930 | } | 919 | } |
931 | 920 | ||
@@ -949,6 +938,11 @@ handle_get_peer (void *cls, | |||
949 | 938 | ||
950 | if (NULL == h->info_cb.peer_cb) | 939 | if (NULL == h->info_cb.peer_cb) |
951 | return; | 940 | return; |
941 | |||
942 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
943 | "number of paths %u\n", | ||
944 | ntohs (message->paths)); | ||
945 | |||
952 | paths = ntohs (message->paths); | 946 | paths = ntohs (message->paths); |
953 | paths_array = (const struct GNUNET_PeerIdentity *) &message[1]; | 947 | paths_array = (const struct GNUNET_PeerIdentity *) &message[1]; |
954 | peers = (ntohs (message->header.size) - sizeof (*message)) | 948 | peers = (ntohs (message->header.size) - sizeof (*message)) |
@@ -978,7 +972,9 @@ handle_get_peer (void *cls, | |||
978 | (int) ntohs (message->tunnel), | 972 | (int) ntohs (message->tunnel), |
979 | neighbor, | 973 | neighbor, |
980 | paths, | 974 | paths, |
981 | paths_array); | 975 | paths_array, |
976 | (int) ntohs (message->offset), | ||
977 | (int) ntohs (message->finished_with_paths)); | ||
982 | } | 978 | } |
983 | 979 | ||
984 | 980 | ||
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index ed297196e..67cebf02b 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c | |||
@@ -530,34 +530,48 @@ peer_callback (void *cls, | |||
530 | int tunnel, | 530 | int tunnel, |
531 | int neighbor, | 531 | int neighbor, |
532 | unsigned int n_paths, | 532 | unsigned int n_paths, |
533 | const struct GNUNET_PeerIdentity *paths) | 533 | const struct GNUNET_PeerIdentity *paths, |
534 | int offset, | ||
535 | int finished_with_paths) | ||
534 | { | 536 | { |
535 | unsigned int i; | 537 | unsigned int i; |
536 | const struct GNUNET_PeerIdentity *p; | 538 | const struct GNUNET_PeerIdentity *p; |
537 | 539 | ||
538 | FPRINTF (stdout, | 540 | |
539 | "%s [TUNNEL: %s, NEIGHBOR: %s, PATHS: %u]\n", | 541 | if (GNUNET_YES == finished_with_paths) |
540 | GNUNET_i2s_full (peer), | ||
541 | tunnel ? "Y" : "N", | ||
542 | neighbor ? "Y" : "N", | ||
543 | n_paths); | ||
544 | p = paths; | ||
545 | for (i = 0; i < n_paths && NULL != p;) | ||
546 | { | 542 | { |
543 | GNUNET_SCHEDULER_shutdown(); | ||
544 | return; | ||
545 | } | ||
546 | |||
547 | if (offset == 0){ | ||
548 | FPRINTF (stdout, | ||
549 | "%s [TUNNEL: %s, NEIGHBOR: %s, PATHS: %u]\n", | ||
550 | GNUNET_i2s_full (peer), | ||
551 | tunnel ? "Y" : "N", | ||
552 | neighbor ? "Y" : "N", | ||
553 | n_paths); | ||
554 | }else{ | ||
555 | p = paths; | ||
547 | FPRINTF (stdout, | 556 | FPRINTF (stdout, |
548 | "%s ", | 557 | "Path with offset %u: ", |
549 | GNUNET_i2s (p)); | 558 | offset); |
550 | if (0 == memcmp (p, | 559 | for (i = 0; i < offset && NULL != p;) |
551 | peer, | ||
552 | sizeof (*p))) | ||
553 | { | 560 | { |
554 | FPRINTF (stdout, "\n"); | 561 | FPRINTF (stdout, |
555 | i++; | 562 | "%s ", |
563 | GNUNET_i2s (p)); | ||
564 | i++; | ||
565 | p++; | ||
556 | } | 566 | } |
557 | p++; | 567 | |
568 | FPRINTF (stdout, | ||
569 | "\n"); | ||
570 | |||
558 | } | 571 | } |
572 | |||
559 | 573 | ||
560 | GNUNET_SCHEDULER_shutdown(); | 574 | |
561 | } | 575 | } |
562 | 576 | ||
563 | 577 | ||
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c index 38037e92f..dd693731f 100644 --- a/src/cadet/gnunet-service-cadet.c +++ b/src/cadet/gnunet-service-cadet.c | |||
@@ -822,7 +822,7 @@ get_all_peers_iterator (void *cls, | |||
822 | struct GNUNET_CADET_LocalInfoPeer *msg; | 822 | struct GNUNET_CADET_LocalInfoPeer *msg; |
823 | 823 | ||
824 | env = GNUNET_MQ_msg (msg, | 824 | env = GNUNET_MQ_msg (msg, |
825 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); | 825 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); |
826 | msg->destination = *peer; | 826 | msg->destination = *peer; |
827 | msg->paths = htons (GCP_count_paths (p)); | 827 | msg->paths = htons (GCP_count_paths (p)); |
828 | msg->tunnel = htons (NULL != GCP_get_tunnel (p, | 828 | msg->tunnel = htons (NULL != GCP_get_tunnel (p, |
@@ -892,6 +892,11 @@ path_info_iterator (void *cls, | |||
892 | env = GNUNET_MQ_msg_extra (resp, | 892 | env = GNUNET_MQ_msg_extra (resp, |
893 | path_size, | 893 | path_size, |
894 | 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 | |||
895 | id = (struct GNUNET_PeerIdentity *) &resp[1]; | 900 | id = (struct GNUNET_PeerIdentity *) &resp[1]; |
896 | 901 | ||
897 | /* 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 |
@@ -905,6 +910,45 @@ path_info_iterator (void *cls, | |||
905 | return GNUNET_YES; | 910 | return GNUNET_YES; |
906 | } | 911 | } |
907 | 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 | */ | ||
922 | static void | ||
923 | get_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 | |||
932 | env = GNUNET_MQ_msg (msg, | ||
933 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); | ||
934 | |||
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 | |||
942 | GNUNET_MQ_send (c->mq, | ||
943 | env); | ||
944 | |||
945 | GCP_iterate_indirect_paths(p, | ||
946 | &path_info_iterator, | ||
947 | c->mq); | ||
948 | |||
949 | } | ||
950 | |||
951 | |||
908 | 952 | ||
909 | /** | 953 | /** |
910 | * Handler for client's SHOW_PEER request. | 954 | * Handler for client's SHOW_PEER request. |
@@ -919,19 +963,23 @@ handle_show_peer (void *cls, | |||
919 | struct CadetClient *c = cls; | 963 | struct CadetClient *c = cls; |
920 | struct CadetPeer *p; | 964 | struct CadetPeer *p; |
921 | struct GNUNET_MQ_Envelope *env; | 965 | struct GNUNET_MQ_Envelope *env; |
922 | struct GNUNET_MessageHeader *resp; | 966 | struct GNUNET_CADET_LocalInfoPeer *resp; |
923 | 967 | ||
924 | p = GCP_get (&msg->peer, | 968 | p = GCP_get (&msg->peer, |
925 | GNUNET_NO); | 969 | GNUNET_NO); |
926 | if (NULL != p) | 970 | if (NULL != p){ |
927 | GCP_iterate_paths (p, | 971 | get_peer_info(c, &(msg->peer), p); |
928 | &path_info_iterator, | 972 | } |
929 | c->mq); | 973 | |
930 | /* Send message with 0/0 to indicate the end */ | 974 | |
931 | env = GNUNET_MQ_msg (resp, | 975 | env = GNUNET_MQ_msg (resp, |
932 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER_END); | 976 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); |
977 | resp->finished_with_paths = htons(1); | ||
978 | resp->destination = msg->peer; | ||
979 | |||
933 | GNUNET_MQ_send (c->mq, | 980 | GNUNET_MQ_send (c->mq, |
934 | env); | 981 | env); |
982 | |||
935 | GNUNET_SERVICE_client_continue (c->client); | 983 | GNUNET_SERVICE_client_continue (c->client); |
936 | } | 984 | } |
937 | 985 | ||
diff --git a/src/cadet/gnunet-service-cadet_paths.c b/src/cadet/gnunet-service-cadet_paths.c index e77d54e55..593617ff6 100644 --- a/src/cadet/gnunet-service-cadet_paths.c +++ b/src/cadet/gnunet-service-cadet_paths.c | |||
@@ -17,7 +17,7 @@ | |||
17 | */ | 17 | */ |
18 | /** | 18 | /** |
19 | * @file cadet/gnunet-service-cadet_paths.c | 19 | * @file cadet/gnunet-service-cadet_paths.c |
20 | * @brief Information we track per path. | 20 | * @brief Information we track per path. |
21 | * @author Bartlomiej Polot | 21 | * @author Bartlomiej Polot |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
23 | */ | 23 | */ |
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index 9cd1f5229..8e536e376 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c | |||
@@ -1235,6 +1235,41 @@ GCP_iterate_paths (struct CadetPeer *cp, | |||
1235 | return ret; | 1235 | return ret; |
1236 | } | 1236 | } |
1237 | 1237 | ||
1238 | /** | ||
1239 | * Iterate over the paths to a peer without direct link. | ||
1240 | * | ||
1241 | * @param cp Peer to get path info. | ||
1242 | * @param callback Function to call for every path. | ||
1243 | * @param callback_cls Closure for @a callback. | ||
1244 | * @return Number of iterated paths. | ||
1245 | */ | ||
1246 | unsigned int | ||
1247 | GCP_iterate_indirect_paths (struct CadetPeer *cp, | ||
1248 | GCP_PathIterator callback, | ||
1249 | void *callback_cls) | ||
1250 | { | ||
1251 | unsigned int ret = 0; | ||
1252 | |||
1253 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1254 | "Iterating over paths to peer %s without direct link\n", | ||
1255 | GCP_2s (cp)); | ||
1256 | for (unsigned int i=1;i<cp->path_dll_length;i++) | ||
1257 | { | ||
1258 | for (struct CadetPeerPathEntry *pe = cp->path_heads[i]; | ||
1259 | NULL != pe; | ||
1260 | pe = pe->next) | ||
1261 | { | ||
1262 | ret++; | ||
1263 | if (GNUNET_NO == | ||
1264 | callback (callback_cls, | ||
1265 | pe->path, | ||
1266 | i)) | ||
1267 | return ret; | ||
1268 | } | ||
1269 | } | ||
1270 | return ret; | ||
1271 | } | ||
1272 | |||
1238 | 1273 | ||
1239 | /** | 1274 | /** |
1240 | * Iterate over the paths to @a cp where | 1275 | * Iterate over the paths to @a cp where |
diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h index 2357a293d..3b8b31b9a 100644 --- a/src/cadet/gnunet-service-cadet_peer.h +++ b/src/cadet/gnunet-service-cadet_peer.h | |||
@@ -139,6 +139,19 @@ GCP_iterate_paths (struct CadetPeer *cp, | |||
139 | GCP_PathIterator callback, | 139 | GCP_PathIterator callback, |
140 | void *callback_cls); | 140 | void *callback_cls); |
141 | 141 | ||
142 | /** | ||
143 | * Iterate over the paths to a peer without direct link. | ||
144 | * | ||
145 | * @param cp Peer to get path info. | ||
146 | * @param callback Function to call for every path. | ||
147 | * @param callback_cls Closure for @a callback. | ||
148 | * @return Number of iterated paths. | ||
149 | */ | ||
150 | unsigned int | ||
151 | GCP_iterate_indirect_paths (struct CadetPeer *cp, | ||
152 | GCP_PathIterator callback, | ||
153 | void *callback_cls); | ||
154 | |||
142 | 155 | ||
143 | /** | 156 | /** |
144 | * Iterate over the paths to @a peer where | 157 | * Iterate over the paths to @a peer where |
diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h index 4f35a3f1f..552763055 100644 --- a/src/include/gnunet_cadet_service.h +++ b/src/include/gnunet_cadet_service.h | |||
@@ -425,7 +425,9 @@ typedef void | |||
425 | int tunnel, | 425 | int tunnel, |
426 | int neighbor, | 426 | int neighbor, |
427 | unsigned int n_paths, | 427 | unsigned int n_paths, |
428 | const struct GNUNET_PeerIdentity *paths); | 428 | const struct GNUNET_PeerIdentity *paths, |
429 | int offset, | ||
430 | int finished_with_paths); | ||
429 | 431 | ||
430 | 432 | ||
431 | /** | 433 | /** |