diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-08-01 22:56:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-08-01 22:56:32 +0000 |
commit | 22be4f71e12c7f2eacafe03d94d4d1c86bc72f0a (patch) | |
tree | 9bbaf4db61f8a862476ccb79a88ad6dfed6ef91e | |
parent | 3d3cedf2e2c41883771cc2170b761840ac26b869 (diff) | |
download | gnunet-22be4f71e12c7f2eacafe03d94d4d1c86bc72f0a.tar.gz gnunet-22be4f71e12c7f2eacafe03d94d4d1c86bc72f0a.zip |
-adapting xdht and wdht to new core MQ API
-rw-r--r-- | src/dht/gnunet-service-wdht_clients.c | 23 | ||||
-rw-r--r-- | src/dht/gnunet-service-wdht_neighbours.c | 267 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_clients.c | 23 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 3286 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.h | 12 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_routing.c | 74 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_routing.h | 27 | ||||
-rw-r--r-- | src/dv/gnunet-service-dv.c | 366 | ||||
-rw-r--r-- | src/util/mq.c | 4 |
9 files changed, 2047 insertions, 2035 deletions
diff --git a/src/dht/gnunet-service-wdht_clients.c b/src/dht/gnunet-service-wdht_clients.c index 2d9730b08..2abeea661 100644 --- a/src/dht/gnunet-service-wdht_clients.c +++ b/src/dht/gnunet-service-wdht_clients.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2011 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2011, 2016 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 |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -653,7 +653,8 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, | |||
653 | _("Could not pass reply to client, message too big!\n")); | 653 | _("Could not pass reply to client, message too big!\n")); |
654 | return; | 654 | return; |
655 | } | 655 | } |
656 | DEBUG("reply FOR DATA_SIZE = %lu\n",msize); | 656 | DEBUG ("reply FOR DATA_SIZE = %u\n", |
657 | (unsigned int) msize); | ||
657 | pm = GNUNET_malloc (msize + sizeof (struct PendingMessage)); | 658 | pm = GNUNET_malloc (msize + sizeof (struct PendingMessage)); |
658 | reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; | 659 | reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; |
659 | pm->msg = &reply->header; | 660 | pm->msg = &reply->header; |
@@ -666,17 +667,23 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, | |||
666 | reply->expiration = GNUNET_TIME_absolute_hton (expiration); | 667 | reply->expiration = GNUNET_TIME_absolute_hton (expiration); |
667 | reply->key = *key; | 668 | reply->key = *key; |
668 | paths = (struct GNUNET_PeerIdentity *) &reply[1]; | 669 | paths = (struct GNUNET_PeerIdentity *) &reply[1]; |
669 | GNUNET_memcpy (paths, put_path, | 670 | GNUNET_memcpy (paths, |
670 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); | 671 | put_path, |
671 | GNUNET_memcpy (&paths[put_path_length], get_path, | 672 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); |
672 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); | 673 | GNUNET_memcpy (&paths[put_path_length], |
673 | GNUNET_memcpy (&paths[get_path_length + put_path_length], data, data_size); | 674 | get_path, |
675 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); | ||
676 | GNUNET_memcpy (&paths[get_path_length + put_path_length], | ||
677 | data, | ||
678 | data_size); | ||
674 | frc.do_copy = GNUNET_NO; | 679 | frc.do_copy = GNUNET_NO; |
675 | frc.pm = pm; | 680 | frc.pm = pm; |
676 | frc.data = data; | 681 | frc.data = data; |
677 | frc.data_size = data_size; | 682 | frc.data_size = data_size; |
678 | frc.type = type; | 683 | frc.type = type; |
679 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply, | 684 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, |
685 | key, | ||
686 | &forward_reply, | ||
680 | &frc); | 687 | &frc); |
681 | if (GNUNET_NO == frc.do_copy) | 688 | if (GNUNET_NO == frc.do_copy) |
682 | { | 689 | { |
diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c index 6f5b93c7c..1d5fd67c0 100644 --- a/src/dht/gnunet-service-wdht_neighbours.c +++ b/src/dht/gnunet-service-wdht_neighbours.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2015 GNUnet e.V. | 3 | Copyright (C) 2009-2016 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 |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -164,7 +164,7 @@ struct FriendInfo | |||
164 | /** | 164 | /** |
165 | * Friend Identity | 165 | * Friend Identity |
166 | */ | 166 | */ |
167 | struct GNUNET_PeerIdentity id; | 167 | const struct GNUNET_PeerIdentity *id; |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * | 170 | * |
@@ -840,28 +840,19 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id, | |||
840 | * | 840 | * |
841 | * @param cls closure | 841 | * @param cls closure |
842 | * @param peer peer identity this notification is about | 842 | * @param peer peer identity this notification is about |
843 | * @param internal_cls our `struct FriendInfo` for @a peer | ||
843 | */ | 844 | */ |
844 | static void | 845 | static void |
845 | handle_core_disconnect (void *cls, | 846 | handle_core_disconnect (void *cls, |
846 | const struct GNUNET_PeerIdentity *peer) | 847 | const struct GNUNET_PeerIdentity *peer, |
848 | void *internal_cls) | ||
847 | { | 849 | { |
848 | struct FriendInfo *remove_friend; | 850 | struct FriendInfo *remove_friend = internal_cls; |
849 | struct Trail *t; | 851 | struct Trail *t; |
850 | 852 | ||
851 | /* If disconnected to own identity, then return. */ | 853 | /* If disconnected to own identity, then return. */ |
852 | if (0 == memcmp (&my_identity, | 854 | if (NULL == remove_friend) |
853 | peer, | ||
854 | sizeof (struct GNUNET_PeerIdentity))) | ||
855 | return; | 855 | return; |
856 | |||
857 | if (NULL == (remove_friend = | ||
858 | GNUNET_CONTAINER_multipeermap_get (friends_peermap, | ||
859 | peer))) | ||
860 | { | ||
861 | GNUNET_break (0); | ||
862 | return; | ||
863 | } | ||
864 | |||
865 | GNUNET_assert (GNUNET_YES == | 856 | GNUNET_assert (GNUNET_YES == |
866 | GNUNET_CONTAINER_multipeermap_remove (friends_peermap, | 857 | GNUNET_CONTAINER_multipeermap_remove (friends_peermap, |
867 | peer, | 858 | peer, |
@@ -874,10 +865,8 @@ handle_core_disconnect (void *cls, | |||
874 | delete_trail (t, | 865 | delete_trail (t, |
875 | GNUNET_NO, | 866 | GNUNET_NO, |
876 | GNUNET_YES); | 867 | GNUNET_YES); |
877 | GNUNET_MQ_destroy (remove_friend->mq); | ||
878 | GNUNET_free (remove_friend); | 868 | GNUNET_free (remove_friend); |
879 | if (0 == | 869 | if (0 == GNUNET_CONTAINER_multipeermap_size (friends_peermap)) |
880 | GNUNET_CONTAINER_multipeermap_size (friends_peermap)) | ||
881 | { | 870 | { |
882 | GNUNET_SCHEDULER_cancel (random_walk_task); | 871 | GNUNET_SCHEDULER_cancel (random_walk_task); |
883 | random_walk_task = NULL; | 872 | random_walk_task = NULL; |
@@ -1056,10 +1045,13 @@ do_random_walk (void *cls) | |||
1056 | * | 1045 | * |
1057 | * @param cls closure | 1046 | * @param cls closure |
1058 | * @param peer_identity peer identity this notification is about | 1047 | * @param peer_identity peer identity this notification is about |
1048 | * @param mq message queue for transmission to @a peer_identity | ||
1049 | * @return the `struct FriendInfo` for the @a peer_identity, NULL for us | ||
1059 | */ | 1050 | */ |
1060 | static void | 1051 | static void * |
1061 | handle_core_connect (void *cls, | 1052 | handle_core_connect (void *cls, |
1062 | const struct GNUNET_PeerIdentity *peer_identity) | 1053 | const struct GNUNET_PeerIdentity *peer_identity, |
1054 | struct GNUNET_MQ_Handle *mq) | ||
1063 | { | 1055 | { |
1064 | struct FriendInfo *friend; | 1056 | struct FriendInfo *friend; |
1065 | 1057 | ||
@@ -1067,21 +1059,11 @@ handle_core_connect (void *cls, | |||
1067 | if (0 == memcmp (&my_identity, | 1059 | if (0 == memcmp (&my_identity, |
1068 | peer_identity, | 1060 | peer_identity, |
1069 | sizeof (struct GNUNET_PeerIdentity))) | 1061 | sizeof (struct GNUNET_PeerIdentity))) |
1070 | return; | 1062 | return NULL; |
1071 | |||
1072 | /* If peer already exists in our friend_peermap, then exit. */ | ||
1073 | if (GNUNET_YES == | ||
1074 | GNUNET_CONTAINER_multipeermap_contains (friends_peermap, | ||
1075 | peer_identity)) | ||
1076 | { | ||
1077 | GNUNET_break (0); | ||
1078 | return; | ||
1079 | } | ||
1080 | 1063 | ||
1081 | friend = GNUNET_new (struct FriendInfo); | 1064 | friend = GNUNET_new (struct FriendInfo); |
1082 | friend->id = *peer_identity; | 1065 | friend->id = peer_identity; |
1083 | friend->mq = GNUNET_CORE_mq_create (core_api, | 1066 | friend->mq = mq; |
1084 | peer_identity); | ||
1085 | GNUNET_assert (GNUNET_OK == | 1067 | GNUNET_assert (GNUNET_OK == |
1086 | GNUNET_CONTAINER_multipeermap_put (friends_peermap, | 1068 | GNUNET_CONTAINER_multipeermap_put (friends_peermap, |
1087 | peer_identity, | 1069 | peer_identity, |
@@ -1093,6 +1075,7 @@ handle_core_connect (void *cls, | |||
1093 | random_walk_task = GNUNET_SCHEDULER_add_now (&do_random_walk, | 1075 | random_walk_task = GNUNET_SCHEDULER_add_now (&do_random_walk, |
1094 | NULL); | 1076 | NULL); |
1095 | } | 1077 | } |
1078 | return friend; | ||
1096 | } | 1079 | } |
1097 | 1080 | ||
1098 | 1081 | ||
@@ -1114,30 +1097,23 @@ core_init (void *cls, | |||
1114 | * Handle a `struct RandomWalkMessage` from a | 1097 | * Handle a `struct RandomWalkMessage` from a |
1115 | * #GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK message. | 1098 | * #GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK message. |
1116 | * | 1099 | * |
1117 | * @param cls closure (NULL) | 1100 | * @param cls the `struct FriendInfo` for the sender |
1118 | * @param peer sender identity | 1101 | * @param m the setup message |
1119 | * @param message the setup message | ||
1120 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1121 | */ | 1102 | */ |
1122 | static int | 1103 | static void |
1123 | handle_dht_p2p_random_walk (void *cls, | 1104 | handle_dht_p2p_random_walk (void *cls, |
1124 | const struct GNUNET_PeerIdentity *peer, | 1105 | const struct RandomWalkMessage *m) |
1125 | const struct GNUNET_MessageHeader *message) | ||
1126 | { | 1106 | { |
1127 | const struct RandomWalkMessage *m; | 1107 | struct FriendInfo *pred = cls; |
1128 | struct Trail *t; | 1108 | struct Trail *t; |
1129 | struct FriendInfo *pred; | ||
1130 | uint16_t layer; | 1109 | uint16_t layer; |
1131 | 1110 | ||
1132 | m = (const struct RandomWalkMessage *) message; | ||
1133 | layer = ntohs (m->layer); | 1111 | layer = ntohs (m->layer); |
1134 | if (layer > NUMBER_LAYERED_ID) | 1112 | if (layer > NUMBER_LAYERED_ID) |
1135 | { | 1113 | { |
1136 | GNUNET_break_op (0); | 1114 | GNUNET_break_op (0); |
1137 | return GNUNET_SYSERR; | 1115 | return; |
1138 | } | 1116 | } |
1139 | pred = GNUNET_CONTAINER_multipeermap_get (friends_peermap, | ||
1140 | peer); | ||
1141 | t = GNUNET_new (struct Trail); | 1117 | t = GNUNET_new (struct Trail); |
1142 | t->pred_id = m->trail_id; | 1118 | t->pred_id = m->trail_id; |
1143 | t->pred = pred; | 1119 | t->pred = pred; |
@@ -1149,7 +1125,7 @@ handle_dht_p2p_random_walk (void *cls, | |||
1149 | { | 1125 | { |
1150 | GNUNET_break_op (0); | 1126 | GNUNET_break_op (0); |
1151 | GNUNET_free (t); | 1127 | GNUNET_free (t); |
1152 | return GNUNET_SYSERR; | 1128 | return; |
1153 | } | 1129 | } |
1154 | GNUNET_CONTAINER_MDLL_insert (pred, | 1130 | GNUNET_CONTAINER_MDLL_insert (pred, |
1155 | pred->pred_head, | 1131 | pred->pred_head, |
@@ -1225,7 +1201,7 @@ handle_dht_p2p_random_walk (void *cls, | |||
1225 | pred->pred_tail, | 1201 | pred->pred_tail, |
1226 | t); | 1202 | t); |
1227 | GNUNET_free (t); | 1203 | GNUNET_free (t); |
1228 | return GNUNET_OK; | 1204 | return; |
1229 | } | 1205 | } |
1230 | GNUNET_CONTAINER_MDLL_insert (succ, | 1206 | GNUNET_CONTAINER_MDLL_insert (succ, |
1231 | succ->succ_head, | 1207 | succ->succ_head, |
@@ -1239,36 +1215,30 @@ handle_dht_p2p_random_walk (void *cls, | |||
1239 | GNUNET_MQ_send (succ->mq, | 1215 | GNUNET_MQ_send (succ->mq, |
1240 | env); | 1216 | env); |
1241 | } | 1217 | } |
1242 | return GNUNET_OK; | ||
1243 | } | 1218 | } |
1244 | 1219 | ||
1245 | 1220 | ||
1246 | /** | 1221 | /** |
1247 | * Handle a `struct RandomWalkResponseMessage`. | 1222 | * Handle a `struct RandomWalkResponseMessage`. |
1248 | * | 1223 | * |
1249 | * @param cls closure (NULL) | 1224 | * @param cls closure |
1250 | * @param peer sender identity | 1225 | * @param rwrm the setup response message |
1251 | * @param message the setup response message | ||
1252 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1253 | */ | 1226 | */ |
1254 | static int | 1227 | static void |
1255 | handle_dht_p2p_random_walk_response (void *cls, | 1228 | handle_dht_p2p_random_walk_response (void *cls, |
1256 | const struct GNUNET_PeerIdentity *peer, | 1229 | const struct RandomWalkResponseMessage *rwrm) |
1257 | const struct GNUNET_MessageHeader *message) | 1230 | { |
1258 | { | ||
1259 | const struct RandomWalkResponseMessage *rwrm; | ||
1260 | struct Trail *trail; | 1231 | struct Trail *trail; |
1261 | struct FriendInfo *pred; | 1232 | struct FriendInfo *pred; |
1262 | struct FingerTable *ft; | 1233 | struct FingerTable *ft; |
1263 | struct Finger *finger; | 1234 | struct Finger *finger; |
1264 | 1235 | ||
1265 | rwrm = (const struct RandomWalkResponseMessage *) message; | ||
1266 | trail = GNUNET_CONTAINER_multihashmap_get (trail_map, | 1236 | trail = GNUNET_CONTAINER_multihashmap_get (trail_map, |
1267 | &rwrm->trail_id); | 1237 | &rwrm->trail_id); |
1268 | if (NULL == trail) | 1238 | if (NULL == trail) |
1269 | { | 1239 | { |
1270 | /* TODO: log/statistics: we didn't find the trail (can happen) */ | 1240 | /* TODO: log/statistics: we didn't find the trail (can happen) */ |
1271 | return GNUNET_OK; | 1241 | return; |
1272 | } | 1242 | } |
1273 | if (NULL != (pred = trail->pred)) | 1243 | if (NULL != (pred = trail->pred)) |
1274 | { | 1244 | { |
@@ -1283,7 +1253,7 @@ handle_dht_p2p_random_walk_response (void *cls, | |||
1283 | rwrm2->trail_id = trail->pred_id; | 1253 | rwrm2->trail_id = trail->pred_id; |
1284 | GNUNET_MQ_send (pred->mq, | 1254 | GNUNET_MQ_send (pred->mq, |
1285 | env); | 1255 | env); |
1286 | return GNUNET_OK; | 1256 | return; |
1287 | } | 1257 | } |
1288 | /* We are the first hop, complete finger */ | 1258 | /* We are the first hop, complete finger */ |
1289 | if (NULL == (ft = trail->ft)) | 1259 | if (NULL == (ft = trail->ft)) |
@@ -1293,7 +1263,7 @@ handle_dht_p2p_random_walk_response (void *cls, | |||
1293 | delete_trail (trail, | 1263 | delete_trail (trail, |
1294 | GNUNET_NO, | 1264 | GNUNET_NO, |
1295 | GNUNET_YES); | 1265 | GNUNET_YES); |
1296 | return GNUNET_OK; | 1266 | return; |
1297 | } | 1267 | } |
1298 | if (NULL == (finger = ft->fingers[trail->finger_off])) | 1268 | if (NULL == (finger = ft->fingers[trail->finger_off])) |
1299 | { | 1269 | { |
@@ -1302,7 +1272,7 @@ handle_dht_p2p_random_walk_response (void *cls, | |||
1302 | delete_trail (trail, | 1272 | delete_trail (trail, |
1303 | GNUNET_NO, | 1273 | GNUNET_NO, |
1304 | GNUNET_YES); | 1274 | GNUNET_YES); |
1305 | return GNUNET_OK; | 1275 | return; |
1306 | } | 1276 | } |
1307 | 1277 | ||
1308 | 1278 | ||
@@ -1316,39 +1286,33 @@ handle_dht_p2p_random_walk_response (void *cls, | |||
1316 | */ | 1286 | */ |
1317 | /* FIXME: add the value in db structure 1.a */ | 1287 | /* FIXME: add the value in db structure 1.a */ |
1318 | 1288 | ||
1319 | return GNUNET_OK; | ||
1320 | } | 1289 | } |
1321 | 1290 | ||
1322 | 1291 | ||
1323 | /** | 1292 | /** |
1324 | * Handle a `struct TrailDestroyMessage`. | 1293 | * Handle a `struct TrailDestroyMessage`. |
1325 | * | 1294 | * |
1326 | * @param cls closure (NULL) | 1295 | * @param cls closure |
1327 | * @param peer sender identity | 1296 | * @param tdm the trail destroy message |
1328 | * @param message the finger destroy message | ||
1329 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1330 | */ | 1297 | */ |
1331 | static int | 1298 | static void |
1332 | handle_dht_p2p_trail_destroy (void *cls, | 1299 | handle_dht_p2p_trail_destroy (void *cls, |
1333 | const struct GNUNET_PeerIdentity *peer, | 1300 | const struct TrailDestroyMessage *tdm) |
1334 | const struct GNUNET_MessageHeader *message) | 1301 | { |
1335 | { | 1302 | struct FriendInfo *sender = cls; |
1336 | const struct TrailDestroyMessage *tdm; | ||
1337 | struct Trail *trail; | 1303 | struct Trail *trail; |
1338 | 1304 | ||
1339 | tdm = (const struct TrailDestroyMessage *) message; | ||
1340 | trail = GNUNET_CONTAINER_multihashmap_get (trail_map, | 1305 | trail = GNUNET_CONTAINER_multihashmap_get (trail_map, |
1341 | &tdm->trail_id); | 1306 | &tdm->trail_id); |
1342 | delete_trail (trail, | 1307 | delete_trail (trail, |
1343 | ( (NULL != trail->succ) && | 1308 | ( (NULL != trail->succ) && |
1344 | (0 == memcmp (peer, | 1309 | (0 == memcmp (sender->id, |
1345 | &trail->succ->id, | 1310 | &trail->succ->id, |
1346 | sizeof (struct GNUNET_PeerIdentity))) ), | 1311 | sizeof (struct GNUNET_PeerIdentity))) ), |
1347 | ( (NULL != trail->pred) && | 1312 | ( (NULL != trail->pred) && |
1348 | (0 == memcmp (peer, | 1313 | (0 == memcmp (sender->id, |
1349 | &trail->pred->id, | 1314 | &trail->pred->id, |
1350 | sizeof (struct GNUNET_PeerIdentity))) )); | 1315 | sizeof (struct GNUNET_PeerIdentity))) )); |
1351 | return GNUNET_OK; | ||
1352 | } | 1316 | } |
1353 | 1317 | ||
1354 | 1318 | ||
@@ -1399,10 +1363,12 @@ handle_dht_p2p_peer_get (void *cls, | |||
1399 | unsigned int trail_path_length, | 1363 | unsigned int trail_path_length, |
1400 | const struct GNUNET_MessageHeader *message) | 1364 | const struct GNUNET_MessageHeader *message) |
1401 | { | 1365 | { |
1366 | #if 0 | ||
1402 | const struct PeerGetMessage *pgm; | 1367 | const struct PeerGetMessage *pgm; |
1403 | 1368 | ||
1404 | // FIXME: note: never called like this, message embedded with trail route! | 1369 | // FIXME: note: never called like this, message embedded with trail route! |
1405 | pgm = (const struct PeerGetMessage *) message; | 1370 | pgm = (const struct PeerGetMessage *) message; |
1371 | #endif | ||
1406 | // -> lookup in datacache (figure out way to remember trail!) | 1372 | // -> lookup in datacache (figure out way to remember trail!) |
1407 | /* | 1373 | /* |
1408 | * steps : | 1374 | * steps : |
@@ -1434,9 +1400,11 @@ handle_dht_p2p_peer_get_result (void *cls, | |||
1434 | unsigned int trail_path_length, | 1400 | unsigned int trail_path_length, |
1435 | const struct GNUNET_MessageHeader *message) | 1401 | const struct GNUNET_MessageHeader *message) |
1436 | { | 1402 | { |
1403 | #if 0 | ||
1437 | const struct PeerGetResultMessage *pgrm; | 1404 | const struct PeerGetResultMessage *pgrm; |
1438 | 1405 | ||
1439 | pgrm = (const struct PeerGetResultMessage *) message; | 1406 | pgrm = (const struct PeerGetResultMessage *) message; |
1407 | #endif | ||
1440 | // pretty much: parse, & pass to client (there is some call for that...) | 1408 | // pretty much: parse, & pass to client (there is some call for that...) |
1441 | 1409 | ||
1442 | #if 0 | 1410 | #if 0 |
@@ -1474,9 +1442,11 @@ handle_dht_p2p_peer_put (void *cls, | |||
1474 | unsigned int trail_path_length, | 1442 | unsigned int trail_path_length, |
1475 | const struct GNUNET_MessageHeader *message) | 1443 | const struct GNUNET_MessageHeader *message) |
1476 | { | 1444 | { |
1445 | #if 0 | ||
1477 | const struct PeerGetResultMessage *pgrm; | 1446 | const struct PeerGetResultMessage *pgrm; |
1478 | 1447 | ||
1479 | pgrm = (const struct PeerGetResultMessage *) message; | 1448 | pgrm = (const struct PeerGetResultMessage *) message; |
1449 | #endif | ||
1480 | // parse & store in datacache, this is in response to us asking for successors. | 1450 | // parse & store in datacache, this is in response to us asking for successors. |
1481 | /* | 1451 | /* |
1482 | * steps : | 1452 | * steps : |
@@ -1550,17 +1520,53 @@ struct TrailHandler | |||
1550 | 1520 | ||
1551 | 1521 | ||
1552 | /** | 1522 | /** |
1553 | * Handle a `struct TrailRouteMessage`. | 1523 | * Check that a `struct TrailRouteMessage` is well-formed. |
1554 | * | 1524 | * |
1555 | * @param cls closure (NULL) | 1525 | * @param cls closure |
1556 | * @param peer sender identity | 1526 | * @param trm the finger destroy message |
1557 | * @param message the finger destroy message | ||
1558 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1527 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1559 | */ | 1528 | */ |
1560 | static int | 1529 | static int |
1530 | check_dht_p2p_trail_route (void *cls, | ||
1531 | const struct TrailRouteMessage *trm) | ||
1532 | { | ||
1533 | const struct GNUNET_PeerIdentity *path; | ||
1534 | uint16_t path_length; | ||
1535 | const struct GNUNET_MessageHeader *payload; | ||
1536 | size_t msize; | ||
1537 | |||
1538 | msize = ntohs (trm->header.size); | ||
1539 | path_length = ntohs (trm->path_length); | ||
1540 | if (msize < sizeof (struct TrailRouteMessage) + | ||
1541 | path_length * sizeof (struct GNUNET_PeerIdentity) + | ||
1542 | sizeof (struct GNUNET_MessageHeader) ) | ||
1543 | { | ||
1544 | GNUNET_break_op (0); | ||
1545 | return GNUNET_SYSERR; | ||
1546 | } | ||
1547 | path = (const struct GNUNET_PeerIdentity *) &trm[1]; | ||
1548 | payload = (const struct GNUNET_MessageHeader *) &path[path_length]; | ||
1549 | if (msize != (ntohs (payload->size) + | ||
1550 | sizeof (struct TrailRouteMessage) + | ||
1551 | path_length * sizeof (struct GNUNET_PeerIdentity))) | ||
1552 | { | ||
1553 | GNUNET_break_op (0); | ||
1554 | return GNUNET_SYSERR; | ||
1555 | } | ||
1556 | /* FIXME: verify payload is OK!? */ | ||
1557 | return GNUNET_OK; | ||
1558 | } | ||
1559 | |||
1560 | |||
1561 | /** | ||
1562 | * Handle a `struct TrailRouteMessage`. | ||
1563 | * | ||
1564 | * @param cls closure | ||
1565 | * @param trm the finger destroy message | ||
1566 | */ | ||
1567 | static void | ||
1561 | handle_dht_p2p_trail_route (void *cls, | 1568 | handle_dht_p2p_trail_route (void *cls, |
1562 | const struct GNUNET_PeerIdentity *peer, | 1569 | const struct TrailRouteMessage *trm) |
1563 | const struct GNUNET_MessageHeader *message) | ||
1564 | { | 1570 | { |
1565 | static const struct TrailHandler handlers[] = { | 1571 | static const struct TrailHandler handlers[] = { |
1566 | { &handle_dht_p2p_successor_find, NULL, | 1572 | { &handle_dht_p2p_successor_find, NULL, |
@@ -1577,46 +1583,22 @@ handle_dht_p2p_trail_route (void *cls, | |||
1577 | 0 }, | 1583 | 0 }, |
1578 | { NULL, NULL, 0, 0 } | 1584 | { NULL, NULL, 0, 0 } |
1579 | }; | 1585 | }; |
1586 | struct FriendInfo *sender = cls; | ||
1580 | unsigned int i; | 1587 | unsigned int i; |
1581 | const struct TrailRouteMessage *trm; | ||
1582 | const struct GNUNET_PeerIdentity *path; | 1588 | const struct GNUNET_PeerIdentity *path; |
1583 | uint16_t path_length; | 1589 | uint16_t path_length; |
1584 | const struct GNUNET_MessageHeader *payload; | 1590 | const struct GNUNET_MessageHeader *payload; |
1585 | const struct TrailHandler *th; | 1591 | const struct TrailHandler *th; |
1586 | struct Trail *trail; | 1592 | struct Trail *trail; |
1587 | size_t msize; | ||
1588 | 1593 | ||
1589 | /* Parse and check message is well-formed */ | ||
1590 | msize = ntohs (message->size); | ||
1591 | if (msize < sizeof (struct TrailRouteMessage)) | ||
1592 | { | ||
1593 | GNUNET_break_op (0); | ||
1594 | return GNUNET_YES; | ||
1595 | } | ||
1596 | trm = (const struct TrailRouteMessage *) message; | ||
1597 | path_length = ntohs (trm->path_length); | 1594 | path_length = ntohs (trm->path_length); |
1598 | if (msize < sizeof (struct TrailRouteMessage) + | ||
1599 | path_length * sizeof (struct GNUNET_PeerIdentity) + | ||
1600 | sizeof (struct GNUNET_MessageHeader) ) | ||
1601 | { | ||
1602 | GNUNET_break_op (0); | ||
1603 | return GNUNET_YES; | ||
1604 | } | ||
1605 | path = (const struct GNUNET_PeerIdentity *) &trm[1]; | 1595 | path = (const struct GNUNET_PeerIdentity *) &trm[1]; |
1606 | payload = (const struct GNUNET_MessageHeader *) &path[path_length]; | 1596 | payload = (const struct GNUNET_MessageHeader *) &path[path_length]; |
1607 | if (msize != (ntohs (payload->size) + | ||
1608 | sizeof (struct TrailRouteMessage) + | ||
1609 | path_length * sizeof (struct GNUNET_PeerIdentity))) | ||
1610 | { | ||
1611 | GNUNET_break_op (0); | ||
1612 | return GNUNET_YES; | ||
1613 | } | ||
1614 | |||
1615 | /* Is this message for us? */ | 1597 | /* Is this message for us? */ |
1616 | trail = GNUNET_CONTAINER_multihashmap_get (trail_map, | 1598 | trail = GNUNET_CONTAINER_multihashmap_get (trail_map, |
1617 | &trm->trail_id); | 1599 | &trm->trail_id); |
1618 | if ( (NULL != trail->pred) && | 1600 | if ( (NULL != trail->pred) && |
1619 | (0 == memcmp (peer, | 1601 | (0 == memcmp (sender->id, |
1620 | &trail->pred->id, | 1602 | &trail->pred->id, |
1621 | sizeof (struct GNUNET_PeerIdentity))) ) | 1603 | sizeof (struct GNUNET_PeerIdentity))) ) |
1622 | { | 1604 | { |
@@ -1626,18 +1608,18 @@ handle_dht_p2p_trail_route (void *cls, | |||
1626 | forward_message_on_trail (trail->succ, | 1608 | forward_message_on_trail (trail->succ, |
1627 | &trail->succ_id, | 1609 | &trail->succ_id, |
1628 | ntohs (trm->record_path), | 1610 | ntohs (trm->record_path), |
1629 | peer, | 1611 | sender->id, |
1630 | path, | 1612 | path, |
1631 | path_length, | 1613 | path_length, |
1632 | payload); | 1614 | payload); |
1633 | return GNUNET_OK; | 1615 | return; |
1634 | } | 1616 | } |
1635 | } | 1617 | } |
1636 | else | 1618 | else |
1637 | { | 1619 | { |
1638 | /* forward to 'predecessor' */ | 1620 | /* forward to 'predecessor' */ |
1639 | GNUNET_break_op ( (NULL != trail->succ) && | 1621 | GNUNET_break_op ( (NULL != trail->succ) && |
1640 | (0 == memcmp (peer, | 1622 | (0 == memcmp (sender->id, |
1641 | &trail->succ->id, | 1623 | &trail->succ->id, |
1642 | sizeof (struct GNUNET_PeerIdentity))) ); | 1624 | sizeof (struct GNUNET_PeerIdentity))) ); |
1643 | if (NULL != trail->pred) | 1625 | if (NULL != trail->pred) |
@@ -1645,11 +1627,11 @@ handle_dht_p2p_trail_route (void *cls, | |||
1645 | forward_message_on_trail (trail->pred, | 1627 | forward_message_on_trail (trail->pred, |
1646 | &trail->pred_id, | 1628 | &trail->pred_id, |
1647 | ntohs (trm->record_path), | 1629 | ntohs (trm->record_path), |
1648 | peer, | 1630 | sender->id, |
1649 | path, | 1631 | path, |
1650 | path_length, | 1632 | path_length, |
1651 | payload); | 1633 | payload); |
1652 | return GNUNET_OK; | 1634 | return; |
1653 | } | 1635 | } |
1654 | } | 1636 | } |
1655 | 1637 | ||
@@ -1673,7 +1655,6 @@ handle_dht_p2p_trail_route (void *cls, | |||
1673 | } | 1655 | } |
1674 | } | 1656 | } |
1675 | GNUNET_break_op (NULL != th); | 1657 | GNUNET_break_op (NULL != th); |
1676 | return GNUNET_OK; | ||
1677 | } | 1658 | } |
1678 | 1659 | ||
1679 | 1660 | ||
@@ -1685,35 +1666,37 @@ handle_dht_p2p_trail_route (void *cls, | |||
1685 | int | 1666 | int |
1686 | GDS_NEIGHBOURS_init (void) | 1667 | GDS_NEIGHBOURS_init (void) |
1687 | { | 1668 | { |
1688 | static const struct GNUNET_CORE_MessageHandler core_handlers[] = { | 1669 | GNUNET_MQ_hd_fixed_size (dht_p2p_random_walk, |
1689 | { &handle_dht_p2p_random_walk, | 1670 | GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK, |
1690 | GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK, | 1671 | struct RandomWalkMessage); |
1691 | sizeof (struct RandomWalkMessage) }, | 1672 | GNUNET_MQ_hd_fixed_size (dht_p2p_random_walk_response, |
1692 | { &handle_dht_p2p_random_walk_response, | 1673 | GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK_RESPONSE, |
1693 | GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK_RESPONSE, | 1674 | struct RandomWalkResponseMessage); |
1694 | sizeof (struct RandomWalkResponseMessage) }, | 1675 | GNUNET_MQ_hd_fixed_size (dht_p2p_trail_destroy, |
1695 | { &handle_dht_p2p_trail_destroy, | 1676 | GNUNET_MESSAGE_TYPE_WDHT_TRAIL_DESTROY, |
1696 | GNUNET_MESSAGE_TYPE_WDHT_TRAIL_DESTROY, | 1677 | struct TrailDestroyMessage); |
1697 | sizeof (struct TrailDestroyMessage) }, | 1678 | GNUNET_MQ_hd_var_size (dht_p2p_trail_route, |
1698 | { &handle_dht_p2p_trail_route, | 1679 | GNUNET_MESSAGE_TYPE_WDHT_TRAIL_ROUTE, |
1699 | GNUNET_MESSAGE_TYPE_WDHT_TRAIL_ROUTE, | 1680 | struct TrailRouteMessage); |
1700 | 0}, | 1681 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
1701 | {NULL, 0, 0} | 1682 | make_dht_p2p_random_walk_handler (NULL), |
1683 | make_dht_p2p_random_walk_response_handler (NULL), | ||
1684 | make_dht_p2p_trail_destroy_handler (NULL), | ||
1685 | make_dht_p2p_trail_route_handler (NULL), | ||
1686 | GNUNET_MQ_handler_end () | ||
1702 | }; | 1687 | }; |
1703 | 1688 | ||
1704 | core_api = | 1689 | core_api = GNUNET_CORE_connecT (GDS_cfg, NULL, |
1705 | GNUNET_CORE_connect (GDS_cfg, NULL, | 1690 | &core_init, |
1706 | &core_init, | 1691 | &handle_core_connect, |
1707 | &handle_core_connect, | 1692 | &handle_core_disconnect, |
1708 | &handle_core_disconnect, | 1693 | core_handlers); |
1709 | NULL, GNUNET_NO, | ||
1710 | NULL, GNUNET_NO, | ||
1711 | core_handlers); | ||
1712 | |||
1713 | if (NULL == core_api) | 1694 | if (NULL == core_api) |
1714 | return GNUNET_SYSERR; | 1695 | return GNUNET_SYSERR; |
1715 | friends_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | 1696 | friends_peermap = GNUNET_CONTAINER_multipeermap_create (256, |
1716 | trail_map = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES); | 1697 | GNUNET_NO); |
1698 | trail_map = GNUNET_CONTAINER_multihashmap_create (1024, | ||
1699 | GNUNET_YES); | ||
1717 | trail_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1700 | trail_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1718 | return GNUNET_OK; | 1701 | return GNUNET_OK; |
1719 | } | 1702 | } |
@@ -1727,7 +1710,7 @@ GDS_NEIGHBOURS_done (void) | |||
1727 | { | 1710 | { |
1728 | if (NULL == core_api) | 1711 | if (NULL == core_api) |
1729 | return; | 1712 | return; |
1730 | GNUNET_CORE_disconnect (core_api); | 1713 | GNUNET_CORE_disconnecT (core_api); |
1731 | core_api = NULL; | 1714 | core_api = NULL; |
1732 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friends_peermap)); | 1715 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friends_peermap)); |
1733 | GNUNET_CONTAINER_multipeermap_destroy (friends_peermap); | 1716 | GNUNET_CONTAINER_multipeermap_destroy (friends_peermap); |
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c index 9e489b6d9..3185243b7 100644 --- a/src/dht/gnunet-service-xdht_clients.c +++ b/src/dht/gnunet-service-xdht_clients.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2011 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2011, 2016 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 |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -651,7 +651,8 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, | |||
651 | _("Could not pass reply to client, message too big!\n")); | 651 | _("Could not pass reply to client, message too big!\n")); |
652 | return; | 652 | return; |
653 | } | 653 | } |
654 | DEBUG("reply FOR DATA_SIZE = %lu\n",msize); | 654 | DEBUG ("reply FOR DATA_SIZE = %u\n", |
655 | (unsigned int) msize); | ||
655 | pm = GNUNET_malloc (msize + sizeof (struct PendingMessage)); | 656 | pm = GNUNET_malloc (msize + sizeof (struct PendingMessage)); |
656 | reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; | 657 | reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; |
657 | pm->msg = &reply->header; | 658 | pm->msg = &reply->header; |
@@ -664,17 +665,23 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, | |||
664 | reply->expiration = GNUNET_TIME_absolute_hton (expiration); | 665 | reply->expiration = GNUNET_TIME_absolute_hton (expiration); |
665 | reply->key = *key; | 666 | reply->key = *key; |
666 | paths = (struct GNUNET_PeerIdentity *) &reply[1]; | 667 | paths = (struct GNUNET_PeerIdentity *) &reply[1]; |
667 | GNUNET_memcpy (paths, put_path, | 668 | GNUNET_memcpy (paths, |
668 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); | 669 | put_path, |
669 | GNUNET_memcpy (&paths[put_path_length], get_path, | 670 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); |
670 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); | 671 | GNUNET_memcpy (&paths[put_path_length], |
671 | GNUNET_memcpy (&paths[get_path_length + put_path_length], data, data_size); | 672 | get_path, |
673 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); | ||
674 | GNUNET_memcpy (&paths[get_path_length + put_path_length], | ||
675 | data, | ||
676 | data_size); | ||
672 | frc.do_copy = GNUNET_NO; | 677 | frc.do_copy = GNUNET_NO; |
673 | frc.pm = pm; | 678 | frc.pm = pm; |
674 | frc.data = data; | 679 | frc.data = data; |
675 | frc.data_size = data_size; | 680 | frc.data_size = data_size; |
676 | frc.type = type; | 681 | frc.type = type; |
677 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply, | 682 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, |
683 | key, | ||
684 | &forward_reply, | ||
678 | &frc); | 685 | &frc); |
679 | if (GNUNET_NO == frc.do_copy) | 686 | if (GNUNET_NO == frc.do_copy) |
680 | { | 687 | { |
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index b5c17361b..7bfc11918 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2014 GNUnet e.V. | 3 | Copyright (C) 2009-2014, 2016 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 |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -22,6 +22,7 @@ | |||
22 | * @file dht/gnunet-service-xdht_neighbours.c | 22 | * @file dht/gnunet-service-xdht_neighbours.c |
23 | * @brief GNUnet DHT service's finger and friend table management code | 23 | * @brief GNUnet DHT service's finger and friend table management code |
24 | * @author Supriti Singh | 24 | * @author Supriti Singh |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | 27 | ||
27 | #include "platform.h" | 28 | #include "platform.h" |
@@ -381,7 +382,7 @@ struct PeerTrailSetupResultMessage | |||
381 | /** | 382 | /** |
382 | * Value to which finger_identity is the closest peer. | 383 | * Value to which finger_identity is the closest peer. |
383 | */ | 384 | */ |
384 | uint64_t ulitmate_destination_finger_value; | 385 | uint64_t ultimate_destination_finger_value; |
385 | 386 | ||
386 | /** | 387 | /** |
387 | * Identifier of the trail from querying peer to finger_identity, NOT | 388 | * Identifier of the trail from querying peer to finger_identity, NOT |
@@ -625,39 +626,6 @@ struct PeerAddTrailMessage | |||
625 | 626 | ||
626 | GNUNET_NETWORK_STRUCT_END | 627 | GNUNET_NETWORK_STRUCT_END |
627 | 628 | ||
628 | /** | ||
629 | * Linked list of messages to send to a particular other peer. | ||
630 | */ | ||
631 | struct P2PPendingMessage | ||
632 | { | ||
633 | /** | ||
634 | * Pointer to next item in the list | ||
635 | */ | ||
636 | struct P2PPendingMessage *next; | ||
637 | |||
638 | /** | ||
639 | * Pointer to previous item in the list | ||
640 | */ | ||
641 | struct P2PPendingMessage *prev; | ||
642 | |||
643 | /** | ||
644 | * Message importance level. FIXME: used? useful? | ||
645 | */ | ||
646 | unsigned int importance; | ||
647 | |||
648 | /** | ||
649 | * When does this message time out? | ||
650 | */ | ||
651 | struct GNUNET_TIME_Absolute timeout; | ||
652 | |||
653 | /** | ||
654 | * Actual message to be sent, allocated at the end of the struct: | ||
655 | * // msg = (cast) &pm[1]; | ||
656 | * // GNUNET_memcpy (&pm[1], data, len); | ||
657 | */ | ||
658 | const struct GNUNET_MessageHeader *msg; | ||
659 | |||
660 | }; | ||
661 | 629 | ||
662 | /** | 630 | /** |
663 | * Entry in friend_peermap. | 631 | * Entry in friend_peermap. |
@@ -667,7 +635,7 @@ struct FriendInfo | |||
667 | /** | 635 | /** |
668 | * Friend Identity | 636 | * Friend Identity |
669 | */ | 637 | */ |
670 | struct GNUNET_PeerIdentity id; | 638 | const struct GNUNET_PeerIdentity *id; |
671 | 639 | ||
672 | /** | 640 | /** |
673 | * Number of trails for which this friend is the first hop or if the friend | 641 | * Number of trails for which this friend is the first hop or if the friend |
@@ -676,31 +644,14 @@ struct FriendInfo | |||
676 | unsigned int trails_count; | 644 | unsigned int trails_count; |
677 | 645 | ||
678 | /** | 646 | /** |
679 | * Count of outstanding messages for this friend. | ||
680 | */ | ||
681 | unsigned int pending_count; | ||
682 | |||
683 | /** | ||
684 | * In case not 0, then amount of time for which this friend is congested. | 647 | * In case not 0, then amount of time for which this friend is congested. |
685 | */ | 648 | */ |
686 | struct GNUNET_TIME_Absolute congestion_timestamp; | 649 | struct GNUNET_TIME_Absolute congestion_timestamp; |
687 | 650 | ||
688 | |||
689 | // TODO : Change name of head and tail to pending_messages_list_head and so. | ||
690 | /** | 651 | /** |
691 | * Head of pending messages to be sent to this friend. | 652 | * Handle for sending messages to this friend. |
692 | */ | 653 | */ |
693 | struct P2PPendingMessage *head; | 654 | struct GNUNET_MQ_Handle *mq; |
694 | |||
695 | /** | ||
696 | * Tail of pending messages to be sent to this friend. | ||
697 | */ | ||
698 | struct P2PPendingMessage *tail; | ||
699 | |||
700 | /** | ||
701 | * Core handle for sending messages to this friend. | ||
702 | */ | ||
703 | struct GNUNET_CORE_TransmitHandle *th; | ||
704 | 655 | ||
705 | }; | 656 | }; |
706 | 657 | ||
@@ -853,25 +804,25 @@ struct VerifySuccessorContext | |||
853 | * Task that sends FIND FINGER TRAIL requests. This task is started when we have | 804 | * Task that sends FIND FINGER TRAIL requests. This task is started when we have |
854 | * get our first friend. | 805 | * get our first friend. |
855 | */ | 806 | */ |
856 | static struct GNUNET_SCHEDULER_Task * find_finger_trail_task; | 807 | static struct GNUNET_SCHEDULER_Task *find_finger_trail_task; |
857 | 808 | ||
858 | /** | 809 | /** |
859 | * Task that sends verify successor message. This task is started when we get | 810 | * Task that sends verify successor message. This task is started when we get |
860 | * our successor for the first time. | 811 | * our successor for the first time. |
861 | */ | 812 | */ |
862 | static struct GNUNET_SCHEDULER_Task * send_verify_successor_task; | 813 | static struct GNUNET_SCHEDULER_Task *send_verify_successor_task; |
863 | 814 | ||
864 | /** | 815 | /** |
865 | * Task that sends verify successor message. This task is started when we get | 816 | * Task that sends verify successor message. This task is started when we get |
866 | * our successor for the first time. | 817 | * our successor for the first time. |
867 | */ | 818 | */ |
868 | static struct GNUNET_SCHEDULER_Task * send_verify_successor_retry_task; | 819 | static struct GNUNET_SCHEDULER_Task *send_verify_successor_retry_task; |
869 | 820 | ||
870 | /** | 821 | /** |
871 | * Task that sends verify successor message. This task is started when we get | 822 | * Task that sends verify successor message. This task is started when we get |
872 | * our successor for the first time. | 823 | * our successor for the first time. |
873 | */ | 824 | */ |
874 | static struct GNUNET_SCHEDULER_Task * send_notify_new_successor_retry_task; | 825 | static struct GNUNET_SCHEDULER_Task *send_notify_new_successor_retry_task; |
875 | 826 | ||
876 | /** | 827 | /** |
877 | * Identity of this peer. | 828 | * Identity of this peer. |
@@ -894,11 +845,6 @@ static struct FingerInfo finger_table [MAX_FINGERS]; | |||
894 | static struct GNUNET_CORE_Handle *core_api; | 845 | static struct GNUNET_CORE_Handle *core_api; |
895 | 846 | ||
896 | /** | 847 | /** |
897 | * Handle for the statistics service. | ||
898 | */ | ||
899 | //extern struct GNUNET_STATISTICS_Handle *GDS_stats; | ||
900 | |||
901 | /** | ||
902 | * The current finger index that we have want to find trail to. We start the | 848 | * The current finger index that we have want to find trail to. We start the |
903 | * search with value = 0, i.e. successor and then go to PREDCESSOR_FINGER_ID | 849 | * search with value = 0, i.e. successor and then go to PREDCESSOR_FINGER_ID |
904 | * and decrement it. For any index 63 <= index < 0, if finger is same as successor, | 850 | * and decrement it. For any index 63 <= index < 0, if finger is same as successor, |
@@ -953,117 +899,11 @@ static unsigned int successor_times; | |||
953 | * Number of rounds for which we should search for finger. | 899 | * Number of rounds for which we should search for finger. |
954 | */ | 900 | */ |
955 | static unsigned int fingers_round_count; | 901 | static unsigned int fingers_round_count; |
956 | /** | ||
957 | * Called when core is ready to send a message we asked for | ||
958 | * out to the destination. | ||
959 | * | ||
960 | * @param cls the 'struct FriendInfo' of the target friend | ||
961 | * @param size number of bytes available in buf | ||
962 | * @param buf where the callee should write the message | ||
963 | * @return number of bytes written to buf | ||
964 | */ | ||
965 | static size_t | ||
966 | core_transmit_notify (void *cls, size_t size, void *buf) | ||
967 | { | ||
968 | struct FriendInfo *peer = cls; | ||
969 | char *cbuf = buf; | ||
970 | struct P2PPendingMessage *pending; | ||
971 | size_t off; | ||
972 | size_t msize; | ||
973 | |||
974 | peer->th = NULL; | ||
975 | while ( (NULL != (pending = peer->head)) && | ||
976 | (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us) ) | ||
977 | { | ||
978 | GNUNET_STATISTICS_update (GDS_stats, | ||
979 | gettext_noop | ||
980 | ("# Messages dropped (CORE timeout)"), | ||
981 | 1, | ||
982 | GNUNET_NO); | ||
983 | peer->pending_count--; | ||
984 | GNUNET_CONTAINER_DLL_remove (peer->head, | ||
985 | peer->tail, | ||
986 | pending); | ||
987 | GNUNET_free (pending); | ||
988 | } | ||
989 | if (NULL == pending) | ||
990 | { | ||
991 | /* no messages pending */ | ||
992 | return 0; | ||
993 | } | ||
994 | if (NULL == buf) | ||
995 | { | ||
996 | peer->th = | ||
997 | GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO, | ||
998 | GNUNET_CORE_PRIO_BEST_EFFORT, | ||
999 | GNUNET_TIME_absolute_get_remaining | ||
1000 | (pending->timeout), &peer->id, | ||
1001 | ntohs (pending->msg->size), | ||
1002 | &core_transmit_notify, peer); | ||
1003 | GNUNET_break (NULL != peer->th); | ||
1004 | return 0; | ||
1005 | } | ||
1006 | off = 0; | ||
1007 | while ((NULL != (pending = peer->head)) && | ||
1008 | (size - off >= (msize = ntohs (pending->msg->size)))) | ||
1009 | { | ||
1010 | GNUNET_STATISTICS_update (GDS_stats, | ||
1011 | gettext_noop | ||
1012 | ("# Bytes transmitted to other peers"), | ||
1013 | msize, | ||
1014 | GNUNET_NO); | ||
1015 | GNUNET_memcpy (&cbuf[off], pending->msg, msize); | ||
1016 | off += msize; | ||
1017 | peer->pending_count--; | ||
1018 | GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); | ||
1019 | GNUNET_free (pending); | ||
1020 | } | ||
1021 | if (peer->head != NULL) | ||
1022 | { | ||
1023 | peer->th = | ||
1024 | GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO, | ||
1025 | GNUNET_CORE_PRIO_BEST_EFFORT, | ||
1026 | GNUNET_TIME_absolute_get_remaining | ||
1027 | (pending->timeout), &peer->id, msize, | ||
1028 | &core_transmit_notify, peer); | ||
1029 | GNUNET_break (NULL != peer->th); | ||
1030 | } | ||
1031 | return off; | ||
1032 | } | ||
1033 | 902 | ||
1034 | 903 | ||
1035 | /** | 904 | /** |
1036 | * Transmit all messages in the friend's message queue. | 905 | * Construct a trail setup message and forward it to @a target_friend |
1037 | * | 906 | * |
1038 | * @param peer message queue to process | ||
1039 | */ | ||
1040 | static void | ||
1041 | process_friend_queue (struct FriendInfo *peer) | ||
1042 | { | ||
1043 | struct P2PPendingMessage *pending; | ||
1044 | |||
1045 | if (NULL == (pending = peer->head)) | ||
1046 | { | ||
1047 | return; | ||
1048 | } | ||
1049 | if (NULL != peer->th) | ||
1050 | { | ||
1051 | return; | ||
1052 | } | ||
1053 | |||
1054 | peer->th = | ||
1055 | GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO, | ||
1056 | pending->importance, | ||
1057 | GNUNET_TIME_absolute_get_remaining | ||
1058 | (pending->timeout), &peer->id, | ||
1059 | ntohs (pending->msg->size), | ||
1060 | &core_transmit_notify, peer); | ||
1061 | GNUNET_break (NULL != peer->th); | ||
1062 | } | ||
1063 | |||
1064 | |||
1065 | /** | ||
1066 | * Construct a trail setup message and forward it to target_friend | ||
1067 | * @param source_peer Peer which wants to setup the trail | 907 | * @param source_peer Peer which wants to setup the trail |
1068 | * @param ultimate_destination_finger_value Peer identity closest to this value | 908 | * @param ultimate_destination_finger_value Peer identity closest to this value |
1069 | * will be finger to @a source_peer | 909 | * will be finger to @a source_peer |
@@ -1079,63 +919,56 @@ process_friend_queue (struct FriendInfo *peer) | |||
1079 | * best_known_destination when its a finger. If not | 919 | * best_known_destination when its a finger. If not |
1080 | * used then set to 0. | 920 | * used then set to 0. |
1081 | */ | 921 | */ |
1082 | void | 922 | static void |
1083 | GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer, | 923 | GDS_NEIGHBOURS_send_trail_setup (const struct GNUNET_PeerIdentity *source_peer, |
1084 | uint64_t ultimate_destination_finger_value, | 924 | uint64_t ultimate_destination_finger_value, |
1085 | struct GNUNET_PeerIdentity best_known_destination, | 925 | const struct GNUNET_PeerIdentity *best_known_destination, |
1086 | struct FriendInfo *target_friend, | 926 | const struct FriendInfo *target_friend, |
1087 | unsigned int trail_length, | 927 | unsigned int trail_length, |
1088 | const struct GNUNET_PeerIdentity *trail_peer_list, | 928 | const struct GNUNET_PeerIdentity *trail_peer_list, |
1089 | unsigned int is_predecessor, | 929 | unsigned int is_predecessor, |
1090 | struct GNUNET_HashCode trail_id, | 930 | const struct GNUNET_HashCode *trail_id, |
1091 | struct GNUNET_HashCode intermediate_trail_id) | 931 | const struct GNUNET_HashCode *intermediate_trail_id) |
1092 | { | 932 | { |
1093 | struct P2PPendingMessage *pending; | 933 | struct GNUNET_MQ_Envelope *env; |
1094 | struct PeerTrailSetupMessage *tsm; | 934 | struct PeerTrailSetupMessage *tsm; |
1095 | struct GNUNET_PeerIdentity *peer_list; | ||
1096 | size_t msize; | 935 | size_t msize; |
1097 | 936 | ||
1098 | msize = sizeof (struct PeerTrailSetupMessage) + | 937 | msize = trail_length * sizeof (struct GNUNET_PeerIdentity); |
1099 | (trail_length * sizeof (struct GNUNET_PeerIdentity)); | 938 | if (msize + sizeof (struct PeerTrailSetupMessage) |
1100 | 939 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | |
1101 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
1102 | { | 940 | { |
1103 | GNUNET_break (0); | 941 | GNUNET_break (0); |
1104 | return; | 942 | return; |
1105 | } | 943 | } |
1106 | 944 | if (GNUNET_MQ_get_length (target_friend->mq) >= MAXIMUM_PENDING_PER_FRIEND) | |
1107 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1108 | { | 945 | { |
1109 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 946 | GNUNET_STATISTICS_update (GDS_stats, |
1110 | 1, GNUNET_NO); | 947 | gettext_noop ("# P2P messages dropped due to full queue"), |
948 | 1, | ||
949 | GNUNET_NO); | ||
950 | return; | ||
1111 | } | 951 | } |
1112 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 952 | env = GNUNET_MQ_msg_extra (tsm, |
1113 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 953 | msize, |
1114 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; | 954 | GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP); |
1115 | pending->msg = &(tsm->header); | ||
1116 | tsm->header.size = htons (msize); | ||
1117 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP); | ||
1118 | tsm->final_destination_finger_value = GNUNET_htonll (ultimate_destination_finger_value); | 955 | tsm->final_destination_finger_value = GNUNET_htonll (ultimate_destination_finger_value); |
1119 | tsm->source_peer = source_peer; | 956 | tsm->source_peer = *source_peer; |
1120 | tsm->best_known_destination = best_known_destination; | 957 | tsm->best_known_destination = *best_known_destination; |
1121 | tsm->is_predecessor = htonl (is_predecessor); | 958 | tsm->is_predecessor = htonl (is_predecessor); |
1122 | tsm->trail_id = trail_id; | 959 | tsm->trail_id = *trail_id; |
1123 | tsm->intermediate_trail_id = intermediate_trail_id; | 960 | tsm->intermediate_trail_id = *intermediate_trail_id; |
1124 | 961 | GNUNET_memcpy (&tsm[1], | |
1125 | if (trail_length > 0) | 962 | trail_peer_list, |
1126 | { | 963 | msize); |
1127 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; | 964 | GNUNET_MQ_send (target_friend->mq, |
1128 | GNUNET_memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); | 965 | env); |
1129 | } | ||
1130 | |||
1131 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | ||
1132 | target_friend->pending_count++; | ||
1133 | process_friend_queue (target_friend); | ||
1134 | } | 966 | } |
1135 | 967 | ||
1136 | 968 | ||
1137 | /** | 969 | /** |
1138 | * Construct a trail setup result message and forward it to target friend. | 970 | * Construct a trail setup result message and forward it to @a target_friend. |
971 | * | ||
1139 | * @param querying_peer Peer which sent the trail setup request and should get | 972 | * @param querying_peer Peer which sent the trail setup request and should get |
1140 | * the result back. | 973 | * the result back. |
1141 | * @param Finger Peer to which the trail has been setup to. | 974 | * @param Finger Peer to which the trail has been setup to. |
@@ -1148,106 +981,87 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity source_peer, | |||
1148 | * peer. | 981 | * peer. |
1149 | * @param trail_id Unique identifier of the trail. | 982 | * @param trail_id Unique identifier of the trail. |
1150 | */ | 983 | */ |
1151 | void | 984 | static void |
1152 | GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity querying_peer, | 985 | GDS_NEIGHBOURS_send_trail_setup_result (const struct GNUNET_PeerIdentity *querying_peer, |
1153 | struct GNUNET_PeerIdentity finger, | 986 | const struct GNUNET_PeerIdentity *finger, |
1154 | struct FriendInfo *target_friend, | 987 | struct FriendInfo *target_friend, |
1155 | unsigned int trail_length, | 988 | unsigned int trail_length, |
1156 | const struct GNUNET_PeerIdentity *trail_peer_list, | 989 | const struct GNUNET_PeerIdentity *trail_peer_list, |
1157 | unsigned int is_predecessor, | 990 | unsigned int is_predecessor, |
1158 | uint64_t ultimate_destination_finger_value, | 991 | uint64_t ultimate_destination_finger_value, |
1159 | struct GNUNET_HashCode trail_id) | 992 | const struct GNUNET_HashCode *trail_id) |
1160 | { | 993 | { |
1161 | struct P2PPendingMessage *pending; | 994 | struct GNUNET_MQ_Envelope *env; |
1162 | struct PeerTrailSetupResultMessage *tsrm; | 995 | struct PeerTrailSetupResultMessage *tsrm; |
1163 | struct GNUNET_PeerIdentity *peer_list; | ||
1164 | size_t msize; | 996 | size_t msize; |
1165 | 997 | ||
1166 | msize = sizeof (struct PeerTrailSetupResultMessage) + | 998 | msize = trail_length * sizeof (struct GNUNET_PeerIdentity); |
1167 | (trail_length * sizeof (struct GNUNET_PeerIdentity)); | 999 | if (msize + sizeof (struct PeerTrailSetupResultMessage) |
1168 | 1000 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | |
1169 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
1170 | { | 1001 | { |
1171 | GNUNET_break (0); | 1002 | GNUNET_break (0); |
1172 | return; | 1003 | return; |
1173 | } | 1004 | } |
1174 | 1005 | if (GNUNET_MQ_get_length (target_friend->mq) >= MAXIMUM_PENDING_PER_FRIEND) | |
1175 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1176 | { | 1006 | { |
1177 | GNUNET_STATISTICS_update (GDS_stats, | 1007 | GNUNET_STATISTICS_update (GDS_stats, |
1178 | gettext_noop ("# P2P messages dropped due to full queue"), | 1008 | gettext_noop ("# P2P messages dropped due to full queue"), |
1179 | 1, GNUNET_NO); | 1009 | 1, |
1180 | } | 1010 | GNUNET_NO); |
1181 | 1011 | return; | |
1182 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1012 | } |
1183 | pending->importance = 0; | 1013 | env = GNUNET_MQ_msg_extra (tsrm, |
1184 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 1014 | msize, |
1185 | tsrm = (struct PeerTrailSetupResultMessage *) &pending[1]; | 1015 | GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_RESULT); |
1186 | pending->msg = &tsrm->header; | 1016 | tsrm->querying_peer = *querying_peer; |
1187 | tsrm->header.size = htons (msize); | 1017 | tsrm->finger_identity = *finger; |
1188 | tsrm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_RESULT); | ||
1189 | tsrm->querying_peer = querying_peer; | ||
1190 | tsrm->finger_identity = finger; | ||
1191 | tsrm->is_predecessor = htonl (is_predecessor); | 1018 | tsrm->is_predecessor = htonl (is_predecessor); |
1192 | tsrm->trail_id = trail_id; | 1019 | tsrm->trail_id = *trail_id; |
1193 | tsrm->ulitmate_destination_finger_value = | 1020 | tsrm->ultimate_destination_finger_value |
1194 | GNUNET_htonll (ultimate_destination_finger_value); | 1021 | = GNUNET_htonll (ultimate_destination_finger_value); |
1195 | peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; | 1022 | GNUNET_memcpy (&tsrm[1], |
1196 | GNUNET_memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1023 | trail_peer_list, |
1197 | 1024 | msize); | |
1198 | /* Send the message to chosen friend. */ | 1025 | GNUNET_MQ_send (target_friend->mq, |
1199 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 1026 | env); |
1200 | target_friend->pending_count++; | ||
1201 | process_friend_queue (target_friend); | ||
1202 | } | 1027 | } |
1203 | 1028 | ||
1029 | |||
1204 | /** | 1030 | /** |
1205 | * Send notify successor confirmation message. | 1031 | * Send notify successor confirmation message. |
1032 | * | ||
1206 | * @param trail_id Unique Identifier of the trail. | 1033 | * @param trail_id Unique Identifier of the trail. |
1207 | * @param trail_direction Destination to Source. | 1034 | * @param trail_direction Destination to Source. |
1208 | * @param target_friend Friend to get this message next. | 1035 | * @param target_friend Friend to get this message next. |
1209 | */ | 1036 | */ |
1210 | void | 1037 | static void |
1211 | GDS_NEIGHBOURS_send_notify_succcessor_confirmation (struct GNUNET_HashCode trail_id, | 1038 | GDS_NEIGHBOURS_send_notify_succcessor_confirmation (const struct GNUNET_HashCode *trail_id, |
1212 | unsigned int trail_direction, | 1039 | unsigned int trail_direction, |
1213 | struct FriendInfo *target_friend) | 1040 | struct FriendInfo *target_friend) |
1214 | { | 1041 | { |
1215 | struct PeerNotifyConfirmationMessage *ncm; | 1042 | struct PeerNotifyConfirmationMessage *ncm; |
1216 | struct P2PPendingMessage *pending; | 1043 | struct GNUNET_MQ_Envelope *env; |
1217 | size_t msize; | ||
1218 | 1044 | ||
1219 | msize = sizeof (struct PeerNotifyConfirmationMessage); | 1045 | if (GNUNET_MQ_get_length (target_friend->mq) >= MAXIMUM_PENDING_PER_FRIEND) |
1220 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
1221 | { | 1046 | { |
1222 | GNUNET_break (0); | 1047 | GNUNET_STATISTICS_update (GDS_stats, |
1048 | gettext_noop ("# P2P messages dropped due to full queue"), | ||
1049 | 1, | ||
1050 | GNUNET_NO); | ||
1223 | return; | 1051 | return; |
1224 | } | 1052 | } |
1225 | 1053 | env = GNUNET_MQ_msg (ncm, | |
1226 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | 1054 | GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION); |
1227 | { | 1055 | ncm->trail_id = *trail_id; |
1228 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | ||
1229 | 1, GNUNET_NO); | ||
1230 | } | ||
1231 | |||
1232 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | ||
1233 | pending->importance = 0; /* FIXME */ | ||
1234 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | ||
1235 | ncm = (struct PeerNotifyConfirmationMessage *) &pending[1]; | ||
1236 | pending->msg = &ncm->header; | ||
1237 | ncm->header.size = htons (msize); | ||
1238 | ncm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION); | ||
1239 | ncm->trail_id = trail_id; | ||
1240 | ncm->trail_direction = htonl (trail_direction); | 1056 | ncm->trail_direction = htonl (trail_direction); |
1241 | 1057 | GNUNET_MQ_send (target_friend->mq, | |
1242 | /* Send the message to chosen friend. */ | 1058 | env); |
1243 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | ||
1244 | target_friend->pending_count++; | ||
1245 | process_friend_queue (target_friend); | ||
1246 | } | 1059 | } |
1247 | 1060 | ||
1248 | 1061 | ||
1249 | /** | 1062 | /** |
1250 | * Send trail rejection message to target friend | 1063 | * Send trail rejection message to @a target_friend |
1064 | * | ||
1251 | * @param source_peer Peer which is trying to setup the trail. | 1065 | * @param source_peer Peer which is trying to setup the trail. |
1252 | * @param ultimate_destination_finger_value Peer closest to this value will be | 1066 | * @param ultimate_destination_finger_value Peer closest to this value will be |
1253 | * @a source_peer's finger | 1067 | * @a source_peer's finger |
@@ -1262,62 +1076,51 @@ GDS_NEIGHBOURS_send_notify_succcessor_confirmation (struct GNUNET_HashCode trail | |||
1262 | * @param congestion_timeout Duration given by congested peer as an estimate of | 1076 | * @param congestion_timeout Duration given by congested peer as an estimate of |
1263 | * how long it may remain congested. | 1077 | * how long it may remain congested. |
1264 | */ | 1078 | */ |
1265 | void | 1079 | static void |
1266 | GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer, | 1080 | GDS_NEIGHBOURS_send_trail_rejection (const struct GNUNET_PeerIdentity *source_peer, |
1267 | uint64_t ultimate_destination_finger_value, | 1081 | uint64_t ultimate_destination_finger_value, |
1268 | struct GNUNET_PeerIdentity congested_peer, | 1082 | const struct GNUNET_PeerIdentity *congested_peer, |
1269 | unsigned int is_predecessor, | 1083 | unsigned int is_predecessor, |
1270 | const struct GNUNET_PeerIdentity *trail_peer_list, | 1084 | const struct GNUNET_PeerIdentity *trail_peer_list, |
1271 | unsigned int trail_length, | 1085 | unsigned int trail_length, |
1272 | struct GNUNET_HashCode trail_id, | 1086 | const struct GNUNET_HashCode *trail_id, |
1273 | struct FriendInfo *target_friend, | 1087 | struct FriendInfo *target_friend, |
1274 | const struct GNUNET_TIME_Relative congestion_timeout) | 1088 | const struct GNUNET_TIME_Relative congestion_timeout) |
1275 | { | 1089 | { |
1276 | struct PeerTrailRejectionMessage *trm; | 1090 | struct PeerTrailRejectionMessage *trm; |
1277 | struct P2PPendingMessage *pending; | 1091 | struct GNUNET_MQ_Envelope *env; |
1278 | struct GNUNET_PeerIdentity *peer_list; | ||
1279 | size_t msize; | 1092 | size_t msize; |
1280 | 1093 | ||
1281 | msize = sizeof (struct PeerTrailRejectionMessage) + | 1094 | msize = trail_length * sizeof (struct GNUNET_PeerIdentity); |
1282 | (trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1095 | if (msize + sizeof (struct PeerTrailRejectionMessage) |
1283 | 1096 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | |
1284 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
1285 | { | 1097 | { |
1286 | GNUNET_break (0); | 1098 | GNUNET_break (0); |
1287 | return; | 1099 | return; |
1288 | } | 1100 | } |
1289 | 1101 | if (GNUNET_MQ_get_length (target_friend->mq) >= MAXIMUM_PENDING_PER_FRIEND) | |
1290 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1291 | { | 1102 | { |
1292 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1103 | GNUNET_STATISTICS_update (GDS_stats, |
1293 | 1, GNUNET_NO); | 1104 | gettext_noop ("# P2P messages dropped due to full queue"), |
1105 | 1, | ||
1106 | GNUNET_NO); | ||
1107 | return; | ||
1294 | } | 1108 | } |
1295 | 1109 | env = GNUNET_MQ_msg_extra (trm, | |
1296 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1110 | msize, |
1297 | pending->importance = 0; | 1111 | GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_REJECTION); |
1298 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 1112 | trm->source_peer = *source_peer; |
1299 | trm = (struct PeerTrailRejectionMessage *)&pending[1]; | 1113 | trm->congested_peer = *congested_peer; |
1300 | pending->msg = &trm->header; | ||
1301 | trm->header.size = htons (msize); | ||
1302 | trm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_REJECTION); | ||
1303 | trm->source_peer = source_peer; | ||
1304 | trm->congested_peer = congested_peer; | ||
1305 | trm->congestion_time = congestion_timeout; | 1114 | trm->congestion_time = congestion_timeout; |
1306 | trm->is_predecessor = htonl (is_predecessor); | 1115 | trm->is_predecessor = htonl (is_predecessor); |
1307 | trm->trail_id = trail_id; | 1116 | trm->trail_id = *trail_id; |
1308 | trm->ultimate_destination_finger_value = | 1117 | trm->ultimate_destination_finger_value |
1309 | GNUNET_htonll (ultimate_destination_finger_value); | 1118 | = GNUNET_htonll (ultimate_destination_finger_value); |
1310 | 1119 | GNUNET_memcpy (&trm[1], | |
1311 | peer_list = (struct GNUNET_PeerIdentity *) &trm[1]; | 1120 | trail_peer_list, |
1312 | if (trail_length > 0) | 1121 | msize); |
1313 | { | 1122 | GNUNET_MQ_send (target_friend->mq, |
1314 | GNUNET_memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1123 | env); |
1315 | } | ||
1316 | |||
1317 | /* Send the message to chosen friend. */ | ||
1318 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | ||
1319 | target_friend->pending_count++; | ||
1320 | process_friend_queue (target_friend); | ||
1321 | } | 1124 | } |
1322 | 1125 | ||
1323 | 1126 | ||
@@ -1332,57 +1135,49 @@ GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer, | |||
1332 | * @param trail_length Total number of peers in @a trail. | 1135 | * @param trail_length Total number of peers in @a trail. |
1333 | * @param target_friend Next friend to get this message. | 1136 | * @param target_friend Next friend to get this message. |
1334 | */ | 1137 | */ |
1335 | void | 1138 | static void |
1336 | GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_peer, | 1139 | GDS_NEIGHBOURS_send_verify_successor_message (const struct GNUNET_PeerIdentity *source_peer, |
1337 | struct GNUNET_PeerIdentity successor, | 1140 | const struct GNUNET_PeerIdentity *successor, |
1338 | struct GNUNET_HashCode trail_id, | 1141 | const struct GNUNET_HashCode *trail_id, |
1339 | struct GNUNET_PeerIdentity *trail, | 1142 | struct GNUNET_PeerIdentity *trail, |
1340 | unsigned int trail_length, | 1143 | unsigned int trail_length, |
1341 | struct FriendInfo *target_friend) | 1144 | struct FriendInfo *target_friend) |
1342 | { | 1145 | { |
1343 | struct PeerVerifySuccessorMessage *vsm; | 1146 | struct PeerVerifySuccessorMessage *vsm; |
1344 | struct P2PPendingMessage *pending; | 1147 | struct GNUNET_MQ_Envelope *env; |
1345 | struct GNUNET_PeerIdentity *peer_list; | ||
1346 | size_t msize; | 1148 | size_t msize; |
1347 | 1149 | ||
1348 | msize = sizeof (struct PeerVerifySuccessorMessage) + | 1150 | msize = trail_length * sizeof (struct GNUNET_PeerIdentity); |
1349 | (trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1151 | if (msize + sizeof (*vsm) >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
1350 | |||
1351 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
1352 | { | 1152 | { |
1353 | GNUNET_break (0); | 1153 | GNUNET_break (0); |
1354 | return; | 1154 | return; |
1355 | } | 1155 | } |
1356 | 1156 | if (GNUNET_MQ_get_length (target_friend->mq) >= MAXIMUM_PENDING_PER_FRIEND) | |
1357 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1358 | { | 1157 | { |
1359 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1158 | GNUNET_STATISTICS_update (GDS_stats, |
1360 | 1, GNUNET_NO); | 1159 | gettext_noop ("# P2P messages dropped due to full queue"), |
1160 | 1, | ||
1161 | GNUNET_NO); | ||
1162 | return; | ||
1361 | } | 1163 | } |
1362 | 1164 | env = GNUNET_MQ_msg_extra (vsm, | |
1363 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1165 | msize, |
1364 | pending->importance = 0; /* FIXME */ | 1166 | GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR); |
1365 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 1167 | vsm->source_peer = *source_peer; |
1366 | vsm = (struct PeerVerifySuccessorMessage *) &pending[1]; | 1168 | vsm->successor = *successor; |
1367 | pending->msg = &vsm->header; | 1169 | vsm->trail_id = *trail_id; |
1368 | vsm->header.size = htons (msize); | 1170 | GNUNET_memcpy (&vsm[1], |
1369 | vsm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR); | 1171 | trail, |
1370 | vsm->source_peer = source_peer; | 1172 | msize); |
1371 | vsm->successor = successor; | 1173 | GNUNET_MQ_send (target_friend->mq, |
1372 | vsm->trail_id = trail_id; | 1174 | env); |
1373 | peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; | ||
1374 | GNUNET_memcpy (peer_list, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
1375 | |||
1376 | /* Send the message to chosen friend. */ | ||
1377 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | ||
1378 | target_friend->pending_count++; | ||
1379 | process_friend_queue (target_friend); | ||
1380 | } | 1175 | } |
1381 | 1176 | ||
1382 | 1177 | ||
1383 | /** | 1178 | /** |
1384 | * FIXME: In every function we pass target friend except for this one. | 1179 | * FIXME: In every function we pass target friend except for this one. |
1385 | * so, either change everything or this one. also, should se just store | 1180 | * so, either change everything or this one. also, should we just store |
1386 | * the pointer to friend in routing table rather than gnunet_peeridentity. | 1181 | * the pointer to friend in routing table rather than gnunet_peeridentity. |
1387 | * if yes then we should keep friend info in.h andmake lot of changes. | 1182 | * if yes then we should keep friend info in.h andmake lot of changes. |
1388 | * Construct a trail teardown message and forward it to target friend. | 1183 | * Construct a trail teardown message and forward it to target friend. |
@@ -1397,50 +1192,37 @@ GDS_NEIGHBOURS_send_trail_teardown (const struct GNUNET_HashCode *trail_id, | |||
1397 | const struct GNUNET_PeerIdentity *peer) | 1192 | const struct GNUNET_PeerIdentity *peer) |
1398 | { | 1193 | { |
1399 | struct PeerTrailTearDownMessage *ttdm; | 1194 | struct PeerTrailTearDownMessage *ttdm; |
1400 | struct P2PPendingMessage *pending; | 1195 | struct GNUNET_MQ_Envelope *env; |
1401 | struct FriendInfo *target_friend; | 1196 | struct FriendInfo *target_friend; |
1402 | size_t msize; | ||
1403 | |||
1404 | msize = sizeof (struct PeerTrailTearDownMessage); | ||
1405 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
1406 | { | ||
1407 | GNUNET_break (0); | ||
1408 | return; | ||
1409 | } | ||
1410 | 1197 | ||
1411 | if (NULL == (target_friend = | 1198 | if (NULL == (target_friend = |
1412 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))) | 1199 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
1200 | peer))) | ||
1413 | { | 1201 | { |
1414 | /* FIXME: In what case friend can be null. ?*/ | 1202 | /* FIXME: In what case friend can be null. ?*/ |
1415 | GNUNET_break (0); | 1203 | GNUNET_break (0); |
1416 | return; | 1204 | return; |
1417 | } | 1205 | } |
1418 | 1206 | if (GNUNET_MQ_get_length (target_friend->mq) >= MAXIMUM_PENDING_PER_FRIEND) | |
1419 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1420 | { | 1207 | { |
1421 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1208 | GNUNET_STATISTICS_update (GDS_stats, |
1422 | 1, GNUNET_NO); | 1209 | gettext_noop ("# P2P messages dropped due to full queue"), |
1210 | 1, | ||
1211 | GNUNET_NO); | ||
1212 | return; | ||
1423 | } | 1213 | } |
1424 | 1214 | env = GNUNET_MQ_msg (ttdm, | |
1425 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1215 | GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN); |
1426 | pending->importance = 0; /* FIXME */ | ||
1427 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | ||
1428 | ttdm = (struct PeerTrailTearDownMessage *) &pending[1]; | ||
1429 | pending->msg = &ttdm->header; | ||
1430 | ttdm->header.size = htons (msize); | ||
1431 | ttdm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN); | ||
1432 | ttdm->trail_id = *trail_id; | 1216 | ttdm->trail_id = *trail_id; |
1433 | ttdm->trail_direction = htonl (trail_direction); | 1217 | ttdm->trail_direction = htonl (trail_direction); |
1434 | 1218 | GNUNET_MQ_send (target_friend->mq, | |
1435 | /* Send the message to chosen friend. */ | 1219 | env); |
1436 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | ||
1437 | target_friend->pending_count++; | ||
1438 | process_friend_queue (target_friend); | ||
1439 | } | 1220 | } |
1440 | 1221 | ||
1441 | 1222 | ||
1442 | /** | 1223 | /** |
1443 | * Construct a verify successor result message and send it to target_friend | 1224 | * Construct a verify successor result message and send it to target_friend |
1225 | * | ||
1444 | * @param querying_peer Peer which sent the verify successor message. | 1226 | * @param querying_peer Peer which sent the verify successor message. |
1445 | * @param source_successor Current_successor of @a querying_peer. | 1227 | * @param source_successor Current_successor of @a querying_peer. |
1446 | * @param current_predecessor Current predecessor of @a successor. Could be same | 1228 | * @param current_predecessor Current predecessor of @a successor. Could be same |
@@ -1454,55 +1236,48 @@ GDS_NEIGHBOURS_send_trail_teardown (const struct GNUNET_HashCode *trail_id, | |||
1454 | * case we are sending result from @a successor to @a querying_peer. | 1236 | * case we are sending result from @a successor to @a querying_peer. |
1455 | * @param target_friend Next friend to get this message. | 1237 | * @param target_friend Next friend to get this message. |
1456 | */ | 1238 | */ |
1457 | void | 1239 | static void |
1458 | GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity querying_peer, | 1240 | GDS_NEIGHBOURS_send_verify_successor_result (const struct GNUNET_PeerIdentity *querying_peer, |
1459 | struct GNUNET_PeerIdentity current_successor, | 1241 | const struct GNUNET_PeerIdentity *current_successor, |
1460 | struct GNUNET_PeerIdentity probable_successor, | 1242 | const struct GNUNET_PeerIdentity *probable_successor, |
1461 | struct GNUNET_HashCode trail_id, | 1243 | const struct GNUNET_HashCode *trail_id, |
1462 | const struct GNUNET_PeerIdentity *trail, | 1244 | const struct GNUNET_PeerIdentity *trail, |
1463 | unsigned int trail_length, | 1245 | unsigned int trail_length, |
1464 | enum GDS_ROUTING_trail_direction trail_direction, | 1246 | enum GDS_ROUTING_trail_direction trail_direction, |
1465 | struct FriendInfo *target_friend) | 1247 | struct FriendInfo *target_friend) |
1466 | { | 1248 | { |
1467 | struct PeerVerifySuccessorResultMessage *vsmr; | 1249 | struct PeerVerifySuccessorResultMessage *vsmr; |
1468 | struct P2PPendingMessage *pending; | 1250 | struct GNUNET_MQ_Envelope *env; |
1469 | struct GNUNET_PeerIdentity *peer_list; | ||
1470 | size_t msize; | 1251 | size_t msize; |
1471 | 1252 | ||
1472 | msize = sizeof (struct PeerVerifySuccessorResultMessage) + | 1253 | msize = trail_length * sizeof(struct GNUNET_PeerIdentity); |
1473 | (trail_length * sizeof(struct GNUNET_PeerIdentity)); | 1254 | if (msize + sizeof (struct PeerVerifySuccessorResultMessage) |
1474 | 1255 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | |
1475 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
1476 | { | 1256 | { |
1477 | GNUNET_break (0); | 1257 | GNUNET_break (0); |
1478 | return; | 1258 | return; |
1479 | } | 1259 | } |
1480 | 1260 | if (GNUNET_MQ_get_length (target_friend->mq) >= MAXIMUM_PENDING_PER_FRIEND) | |
1481 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1482 | { | 1261 | { |
1483 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1262 | GNUNET_STATISTICS_update (GDS_stats, |
1484 | 1, GNUNET_NO); | 1263 | gettext_noop ("# P2P messages dropped due to full queue"), |
1264 | 1, | ||
1265 | GNUNET_NO); | ||
1266 | return; | ||
1485 | } | 1267 | } |
1486 | 1268 | env = GNUNET_MQ_msg_extra (vsmr, | |
1487 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1269 | msize, |
1488 | pending->importance = 0; /* FIXME */ | 1270 | GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR_RESULT); |
1489 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 1271 | vsmr->querying_peer = *querying_peer; |
1490 | vsmr = (struct PeerVerifySuccessorResultMessage *) &pending[1]; | 1272 | vsmr->current_successor = *current_successor; |
1491 | pending->msg = &vsmr->header; | 1273 | vsmr->probable_successor = *probable_successor; |
1492 | vsmr->header.size = htons (msize); | ||
1493 | vsmr->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR_RESULT); | ||
1494 | vsmr->querying_peer = querying_peer; | ||
1495 | vsmr->current_successor = current_successor; | ||
1496 | vsmr->probable_successor = probable_successor; | ||
1497 | vsmr->trail_direction = htonl (trail_direction); | 1274 | vsmr->trail_direction = htonl (trail_direction); |
1498 | vsmr->trail_id = trail_id; | 1275 | vsmr->trail_id = *trail_id; |
1499 | peer_list = (struct GNUNET_PeerIdentity *) &vsmr[1]; | 1276 | GNUNET_memcpy (&vsmr[1], |
1500 | GNUNET_memcpy (peer_list, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1277 | trail, |
1501 | 1278 | msize); | |
1502 | /* Send the message to chosen friend. */ | 1279 | GNUNET_MQ_send (target_friend->mq, |
1503 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 1280 | env); |
1504 | target_friend->pending_count++; | ||
1505 | process_friend_queue (target_friend); | ||
1506 | } | 1281 | } |
1507 | 1282 | ||
1508 | 1283 | ||
@@ -1518,57 +1293,50 @@ GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity querying | |||
1518 | * @param successor_trail_id Unique identifier of @a new_successor_trail. | 1293 | * @param successor_trail_id Unique identifier of @a new_successor_trail. |
1519 | * @param target_friend Next friend to get this message. | 1294 | * @param target_friend Next friend to get this message. |
1520 | */ | 1295 | */ |
1521 | void | 1296 | static void |
1522 | GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity source_peer, | 1297 | GDS_NEIGHBOURS_send_notify_new_successor (const struct GNUNET_PeerIdentity *source_peer, |
1523 | struct GNUNET_PeerIdentity successor, | 1298 | const struct GNUNET_PeerIdentity *successor, |
1524 | const struct GNUNET_PeerIdentity *successor_trail, | 1299 | const struct GNUNET_PeerIdentity *successor_trail, |
1525 | unsigned int successor_trail_length, | 1300 | unsigned int successor_trail_length, |
1526 | struct GNUNET_HashCode succesor_trail_id, | 1301 | const struct GNUNET_HashCode *succesor_trail_id, |
1527 | struct FriendInfo *target_friend) | 1302 | struct FriendInfo *target_friend) |
1528 | { | 1303 | { |
1529 | struct PeerNotifyNewSuccessorMessage *nsm; | 1304 | struct PeerNotifyNewSuccessorMessage *nsm; |
1530 | struct P2PPendingMessage *pending; | 1305 | struct GNUNET_MQ_Envelope *env; |
1531 | struct GNUNET_PeerIdentity *peer_list; | ||
1532 | size_t msize; | 1306 | size_t msize; |
1533 | 1307 | ||
1534 | msize = sizeof (struct PeerNotifyNewSuccessorMessage) + | 1308 | msize = successor_trail_length * sizeof(struct GNUNET_PeerIdentity); |
1535 | (successor_trail_length * sizeof(struct GNUNET_PeerIdentity)); | 1309 | if (msize + sizeof (struct PeerNotifyNewSuccessorMessage) |
1536 | 1310 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | |
1537 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
1538 | { | 1311 | { |
1539 | GNUNET_break (0); | 1312 | GNUNET_break (0); |
1540 | return; | 1313 | return; |
1541 | } | 1314 | } |
1542 | 1315 | if (GNUNET_MQ_get_length (target_friend->mq) >= MAXIMUM_PENDING_PER_FRIEND) | |
1543 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1544 | { | 1316 | { |
1545 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1317 | GNUNET_STATISTICS_update (GDS_stats, |
1546 | 1, GNUNET_NO); | 1318 | gettext_noop ("# P2P messages dropped due to full queue"), |
1319 | 1, | ||
1320 | GNUNET_NO); | ||
1321 | return; | ||
1547 | } | 1322 | } |
1548 | 1323 | env = GNUNET_MQ_msg_extra (nsm, | |
1549 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1324 | msize, |
1550 | pending->importance = 0; /* FIXME */ | 1325 | GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_NEW_SUCCESSOR); |
1551 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 1326 | nsm->new_successor = *successor; |
1552 | nsm = (struct PeerNotifyNewSuccessorMessage *) &pending[1]; | 1327 | nsm->source_peer = *source_peer; |
1553 | pending->msg = &nsm->header; | 1328 | nsm->trail_id = *succesor_trail_id; |
1554 | nsm->header.size = htons (msize); | 1329 | GNUNET_memcpy (&nsm[1], |
1555 | nsm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_NEW_SUCCESSOR); | 1330 | successor_trail, |
1556 | nsm->new_successor = successor; | 1331 | msize); |
1557 | nsm->source_peer = source_peer; | 1332 | GNUNET_MQ_send (target_friend->mq, |
1558 | nsm->trail_id = succesor_trail_id; | 1333 | env); |
1559 | peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; | ||
1560 | GNUNET_memcpy (peer_list, successor_trail, | ||
1561 | successor_trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
1562 | |||
1563 | /* Send the message to chosen friend. */ | ||
1564 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | ||
1565 | target_friend->pending_count++; | ||
1566 | process_friend_queue (target_friend); | ||
1567 | } | 1334 | } |
1568 | 1335 | ||
1569 | 1336 | ||
1570 | /** | 1337 | /** |
1571 | * Construct an add_trail message and send it to target_friend | 1338 | * Construct an add_trail message and send it to target_friend |
1339 | * | ||
1572 | * @param source_peer Source of the trail. | 1340 | * @param source_peer Source of the trail. |
1573 | * @param destination_peer Destination of the trail. | 1341 | * @param destination_peer Destination of the trail. |
1574 | * @param trail_id Unique identifier of the trail from | 1342 | * @param trail_id Unique identifier of the trail from |
@@ -1578,58 +1346,51 @@ GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity source_peer | |||
1578 | * @param trail_length Total number of peers in @a trail. | 1346 | * @param trail_length Total number of peers in @a trail. |
1579 | * @param target_friend Next friend to get this message. | 1347 | * @param target_friend Next friend to get this message. |
1580 | */ | 1348 | */ |
1581 | void | 1349 | static void |
1582 | GDS_NEIGHBOURS_send_add_trail (struct GNUNET_PeerIdentity source_peer, | 1350 | GDS_NEIGHBOURS_send_add_trail (const struct GNUNET_PeerIdentity *source_peer, |
1583 | struct GNUNET_PeerIdentity destination_peer, | 1351 | const struct GNUNET_PeerIdentity *destination_peer, |
1584 | struct GNUNET_HashCode trail_id, | 1352 | const struct GNUNET_HashCode *trail_id, |
1585 | const struct GNUNET_PeerIdentity *trail, | 1353 | const struct GNUNET_PeerIdentity *trail, |
1586 | unsigned int trail_length, | 1354 | unsigned int trail_length, |
1587 | struct FriendInfo *target_friend) | 1355 | struct FriendInfo *target_friend) |
1588 | { | 1356 | { |
1589 | struct PeerAddTrailMessage *adm; | 1357 | struct PeerAddTrailMessage *adm; |
1590 | struct GNUNET_PeerIdentity *peer_list; | 1358 | struct GNUNET_MQ_Envelope *env; |
1591 | struct P2PPendingMessage *pending; | ||
1592 | size_t msize; | 1359 | size_t msize; |
1593 | 1360 | ||
1594 | msize = sizeof (struct PeerAddTrailMessage) + | 1361 | msize = trail_length * sizeof(struct GNUNET_PeerIdentity); |
1595 | (trail_length * sizeof(struct GNUNET_PeerIdentity)); | 1362 | if (msize + sizeof (struct PeerAddTrailMessage) |
1596 | 1363 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | |
1597 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
1598 | { | 1364 | { |
1599 | GNUNET_break (0); | 1365 | GNUNET_break (0); |
1600 | return; | 1366 | return; |
1601 | } | 1367 | } |
1602 | 1368 | if (GNUNET_MQ_get_length (target_friend->mq) >= MAXIMUM_PENDING_PER_FRIEND) | |
1603 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1604 | { | 1369 | { |
1605 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 1370 | GNUNET_STATISTICS_update (GDS_stats, |
1606 | 1, GNUNET_NO); | 1371 | gettext_noop ("# P2P messages dropped due to full queue"), |
1372 | 1, | ||
1373 | GNUNET_NO); | ||
1374 | return; | ||
1607 | } | 1375 | } |
1608 | 1376 | env = GNUNET_MQ_msg_extra (adm, | |
1609 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1377 | msize, |
1610 | pending->importance = 0; /* FIXME */ | 1378 | GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL); |
1611 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 1379 | adm->source_peer = *source_peer; |
1612 | adm = (struct PeerAddTrailMessage *) &pending[1]; | 1380 | adm->destination_peer = *destination_peer; |
1613 | pending->msg = &adm->header; | 1381 | adm->trail_id = *trail_id; |
1614 | adm->header.size = htons (msize); | 1382 | GNUNET_memcpy (&adm[1], |
1615 | adm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL); | 1383 | trail, |
1616 | adm->source_peer = source_peer; | 1384 | msize); |
1617 | adm->destination_peer = destination_peer; | 1385 | GNUNET_MQ_send (target_friend->mq, |
1618 | adm->trail_id = trail_id; | 1386 | env); |
1619 | peer_list = (struct GNUNET_PeerIdentity *)&adm[1]; | ||
1620 | GNUNET_memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * trail_length); | ||
1621 | |||
1622 | /* Send the message to chosen friend. */ | ||
1623 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | ||
1624 | target_friend->pending_count++; | ||
1625 | process_friend_queue (target_friend); | ||
1626 | |||
1627 | } | 1387 | } |
1628 | 1388 | ||
1629 | 1389 | ||
1630 | /** | 1390 | /** |
1631 | * Search my location in trail. In case I am present more than once in the | 1391 | * Search my location in trail. In case I am present more than once in the |
1632 | * trail (can happen during trail setup), then return my lowest index. | 1392 | * trail (can happen during trail setup), then return my lowest index. |
1393 | * | ||
1633 | * @param trail List of peers | 1394 | * @param trail List of peers |
1634 | * @return my_index if found | 1395 | * @return my_index if found |
1635 | * trail_length + 1 if an entry is present twice, It is an error. | 1396 | * trail_length + 1 if an entry is present twice, It is an error. |
@@ -1660,8 +1421,7 @@ search_my_index (const struct GNUNET_PeerIdentity *trail, | |||
1660 | 1421 | ||
1661 | if (1 == flag) | 1422 | if (1 == flag) |
1662 | return index_seen; | 1423 | return index_seen; |
1663 | else | 1424 | return -1; |
1664 | return -1; | ||
1665 | } | 1425 | } |
1666 | 1426 | ||
1667 | 1427 | ||
@@ -1679,19 +1439,19 @@ is_friend_congested (struct FriendInfo *friend) | |||
1679 | ((0 == GNUNET_TIME_absolute_get_remaining | 1439 | ((0 == GNUNET_TIME_absolute_get_remaining |
1680 | (friend->congestion_timestamp).rel_value_us))) | 1440 | (friend->congestion_timestamp).rel_value_us))) |
1681 | return GNUNET_NO; | 1441 | return GNUNET_NO; |
1682 | else | 1442 | return GNUNET_YES; |
1683 | return GNUNET_YES; | ||
1684 | } | 1443 | } |
1685 | 1444 | ||
1686 | 1445 | ||
1687 | /** | 1446 | /** |
1688 | * Select closest finger to value. | 1447 | * Select closest finger to value. |
1448 | * | ||
1689 | * @param peer1 First peer | 1449 | * @param peer1 First peer |
1690 | * @param peer2 Second peer | 1450 | * @param peer2 Second peer |
1691 | * @param value Value to be compare | 1451 | * @param value Value to be compare |
1692 | * @return Closest peer | 1452 | * @return Closest peer |
1693 | */ | 1453 | */ |
1694 | static struct GNUNET_PeerIdentity | 1454 | static const struct GNUNET_PeerIdentity * |
1695 | select_closest_finger (const struct GNUNET_PeerIdentity *peer1, | 1455 | select_closest_finger (const struct GNUNET_PeerIdentity *peer1, |
1696 | const struct GNUNET_PeerIdentity *peer2, | 1456 | const struct GNUNET_PeerIdentity *peer2, |
1697 | uint64_t value) | 1457 | uint64_t value) |
@@ -1706,49 +1466,50 @@ select_closest_finger (const struct GNUNET_PeerIdentity *peer1, | |||
1706 | 1466 | ||
1707 | if (peer1_value == value) | 1467 | if (peer1_value == value) |
1708 | { | 1468 | { |
1709 | return *peer1; | 1469 | return peer1; |
1710 | } | 1470 | } |
1711 | 1471 | ||
1712 | if (peer2_value == value) | 1472 | if (peer2_value == value) |
1713 | { | 1473 | { |
1714 | return *peer2; | 1474 | return peer2; |
1715 | } | 1475 | } |
1716 | 1476 | ||
1717 | if (value < peer1_value && peer1_value < peer2_value) | 1477 | if (value < peer1_value && peer1_value < peer2_value) |
1718 | { | 1478 | { |
1719 | return *peer1; | 1479 | return peer1; |
1720 | } | 1480 | } |
1721 | else if (value < peer2_value && peer2_value < peer1_value) | 1481 | else if (value < peer2_value && peer2_value < peer1_value) |
1722 | { | 1482 | { |
1723 | return *peer2; | 1483 | return peer2; |
1724 | } | 1484 | } |
1725 | else if (peer1_value < value && value < peer2_value) | 1485 | else if (peer1_value < value && value < peer2_value) |
1726 | { | 1486 | { |
1727 | return *peer2; | 1487 | return peer2; |
1728 | } | 1488 | } |
1729 | else if (peer2_value < value && value < peer1_value) | 1489 | else if (peer2_value < value && value < peer1_value) |
1730 | { | 1490 | { |
1731 | return *peer1; | 1491 | return peer1; |
1732 | } | 1492 | } |
1733 | else if (peer1_value < peer2_value && peer2_value < value) | 1493 | else if (peer1_value < peer2_value && peer2_value < value) |
1734 | { | 1494 | { |
1735 | return *peer1; | 1495 | return peer1; |
1736 | } | 1496 | } |
1737 | else // if (peer2_value < peer1_value && peer1_value < value) | 1497 | else // if (peer2_value < peer1_value && peer1_value < value) |
1738 | { | 1498 | { |
1739 | return *peer2; | 1499 | return peer2; |
1740 | } | 1500 | } |
1741 | } | 1501 | } |
1742 | 1502 | ||
1743 | 1503 | ||
1744 | /** | 1504 | /** |
1745 | * Select closest predecessor to value. | 1505 | * Select closest predecessor to value. |
1506 | * | ||
1746 | * @param peer1 First peer | 1507 | * @param peer1 First peer |
1747 | * @param peer2 Second peer | 1508 | * @param peer2 Second peer |
1748 | * @param value Value to be compare | 1509 | * @param value Value to be compare |
1749 | * @return Peer which precedes value in the network. | 1510 | * @return Peer which precedes value in the network. |
1750 | */ | 1511 | */ |
1751 | static struct GNUNET_PeerIdentity | 1512 | static const struct GNUNET_PeerIdentity * |
1752 | select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1, | 1513 | select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1, |
1753 | const struct GNUNET_PeerIdentity *peer2, | 1514 | const struct GNUNET_PeerIdentity *peer2, |
1754 | uint64_t value) | 1515 | uint64_t value) |
@@ -1763,37 +1524,37 @@ select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1, | |||
1763 | 1524 | ||
1764 | if (peer1_value == value) | 1525 | if (peer1_value == value) |
1765 | { | 1526 | { |
1766 | return *peer1; | 1527 | return peer1; |
1767 | } | 1528 | } |
1768 | 1529 | ||
1769 | if (peer2_value == value) | 1530 | if (peer2_value == value) |
1770 | { | 1531 | { |
1771 | return *peer2; | 1532 | return peer2; |
1772 | } | 1533 | } |
1773 | 1534 | ||
1774 | if (value < peer1_value && peer1_value < peer2_value) | 1535 | if (value < peer1_value && peer1_value < peer2_value) |
1775 | { | 1536 | { |
1776 | return *peer2; | 1537 | return peer2; |
1777 | } | 1538 | } |
1778 | else if (value < peer2_value && peer2_value < peer1_value) | 1539 | else if (value < peer2_value && peer2_value < peer1_value) |
1779 | { | 1540 | { |
1780 | return *peer1; | 1541 | return peer1; |
1781 | } | 1542 | } |
1782 | else if (peer1_value < value && value < peer2_value) | 1543 | else if (peer1_value < value && value < peer2_value) |
1783 | { | 1544 | { |
1784 | return *peer1; | 1545 | return peer1; |
1785 | } | 1546 | } |
1786 | else if (peer2_value < value && value < peer1_value) | 1547 | else if (peer2_value < value && value < peer1_value) |
1787 | { | 1548 | { |
1788 | return *peer2; | 1549 | return peer2; |
1789 | } | 1550 | } |
1790 | else if (peer1_value < peer2_value && peer2_value < value) | 1551 | else if (peer1_value < peer2_value && peer2_value < value) |
1791 | { | 1552 | { |
1792 | return *peer2; | 1553 | return peer2; |
1793 | } | 1554 | } |
1794 | else // if (peer2_value < peer1_value && peer1_value < value) | 1555 | else // if (peer2_value < peer1_value && peer1_value < value) |
1795 | { | 1556 | { |
1796 | return *peer1; | 1557 | return peer1; |
1797 | } | 1558 | } |
1798 | } | 1559 | } |
1799 | 1560 | ||
@@ -1906,7 +1667,7 @@ test_finger_table_print() | |||
1906 | * @param is_predecessor Is value a predecessor or any other finger. | 1667 | * @param is_predecessor Is value a predecessor or any other finger. |
1907 | * @return Closest peer among two peers. | 1668 | * @return Closest peer among two peers. |
1908 | */ | 1669 | */ |
1909 | static struct GNUNET_PeerIdentity | 1670 | static const struct GNUNET_PeerIdentity * |
1910 | select_closest_peer (const struct GNUNET_PeerIdentity *peer1, | 1671 | select_closest_peer (const struct GNUNET_PeerIdentity *peer1, |
1911 | const struct GNUNET_PeerIdentity *peer2, | 1672 | const struct GNUNET_PeerIdentity *peer2, |
1912 | uint64_t value, | 1673 | uint64_t value, |
@@ -1982,7 +1743,7 @@ static void | |||
1982 | compare_finger_and_current_closest_peer (struct Closest_Peer *current_closest_peer) | 1743 | compare_finger_and_current_closest_peer (struct Closest_Peer *current_closest_peer) |
1983 | { | 1744 | { |
1984 | struct FingerInfo *finger; | 1745 | struct FingerInfo *finger; |
1985 | struct GNUNET_PeerIdentity closest_peer; | 1746 | const struct GNUNET_PeerIdentity *closest_peer; |
1986 | struct Trail *finger_trail; | 1747 | struct Trail *finger_trail; |
1987 | int i; | 1748 | int i; |
1988 | 1749 | ||
@@ -2015,7 +1776,8 @@ compare_finger_and_current_closest_peer (struct Closest_Peer *current_closest_pe | |||
2015 | current_closest_peer->destination_finger_value, | 1776 | current_closest_peer->destination_finger_value, |
2016 | current_closest_peer->is_predecessor); | 1777 | current_closest_peer->is_predecessor); |
2017 | 1778 | ||
2018 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&finger->finger_identity, &closest_peer)) | 1779 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&finger->finger_identity, |
1780 | closest_peer)) | ||
2019 | { | 1781 | { |
2020 | /* Choose one of the trail to reach to finger. */ | 1782 | /* Choose one of the trail to reach to finger. */ |
2021 | finger_trail = select_finger_trail (finger); | 1783 | finger_trail = select_finger_trail (finger); |
@@ -2024,7 +1786,7 @@ compare_finger_and_current_closest_peer (struct Closest_Peer *current_closest_pe | |||
2024 | if (NULL == finger_trail) | 1786 | if (NULL == finger_trail) |
2025 | continue; | 1787 | continue; |
2026 | 1788 | ||
2027 | current_closest_peer->best_known_destination = closest_peer; | 1789 | current_closest_peer->best_known_destination = *closest_peer; |
2028 | current_closest_peer->next_hop = finger_trail->trail_head->peer; | 1790 | current_closest_peer->next_hop = finger_trail->trail_head->peer; |
2029 | current_closest_peer->trail_id = finger_trail->trail_id; | 1791 | current_closest_peer->trail_id = finger_trail->trail_id; |
2030 | current_closest_peer->finger_table_index = i; | 1792 | current_closest_peer->finger_table_index = i; |
@@ -2040,6 +1802,7 @@ compare_finger_and_current_closest_peer (struct Closest_Peer *current_closest_pe | |||
2040 | * If friend is not congested and has not crossed trail threshold, then check | 1802 | * If friend is not congested and has not crossed trail threshold, then check |
2041 | * if friend peer identity is closer to final_destination_finger_value than | 1803 | * if friend peer identity is closer to final_destination_finger_value than |
2042 | * current_successor. If yes then update current_successor. | 1804 | * current_successor. If yes then update current_successor. |
1805 | * | ||
2043 | * @param cls closure | 1806 | * @param cls closure |
2044 | * @param key current public key | 1807 | * @param key current public key |
2045 | * @param value struct Closest_Peer | 1808 | * @param value struct Closest_Peer |
@@ -2053,32 +1816,32 @@ compare_friend_and_current_closest_peer (void *cls, | |||
2053 | { | 1816 | { |
2054 | struct FriendInfo *friend = value; | 1817 | struct FriendInfo *friend = value; |
2055 | struct Closest_Peer *current_closest_peer = cls; | 1818 | struct Closest_Peer *current_closest_peer = cls; |
2056 | struct GNUNET_PeerIdentity closest_peer; | 1819 | const struct GNUNET_PeerIdentity *closest_peer; |
2057 | 1820 | ||
2058 | /* Friend is either congested or has crossed threshold. */ | 1821 | /* Friend is either congested or has crossed threshold. */ |
2059 | if (GNUNET_YES == is_friend_congested (friend)) | 1822 | if (GNUNET_YES == is_friend_congested (friend)) |
2060 | return GNUNET_YES; | 1823 | return GNUNET_YES; |
2061 | 1824 | ||
2062 | /* If current_closest_peer and friend identity are same, then do nothing.*/ | 1825 | /* If current_closest_peer and friend identity are same, then do nothing.*/ |
2063 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&friend->id, | 1826 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (friend->id, |
2064 | ¤t_closest_peer->best_known_destination)) | 1827 | ¤t_closest_peer->best_known_destination)) |
2065 | { | 1828 | { |
2066 | GNUNET_break (0); | 1829 | GNUNET_break (0); |
2067 | return GNUNET_YES; | 1830 | return GNUNET_YES; |
2068 | } | 1831 | } |
2069 | 1832 | ||
2070 | closest_peer = select_closest_peer (&friend->id, | 1833 | closest_peer = select_closest_peer (friend->id, |
2071 | ¤t_closest_peer->best_known_destination, | 1834 | ¤t_closest_peer->best_known_destination, |
2072 | current_closest_peer->destination_finger_value, | 1835 | current_closest_peer->destination_finger_value, |
2073 | current_closest_peer->is_predecessor); | 1836 | current_closest_peer->is_predecessor); |
2074 | 1837 | ||
2075 | /* Is friend the closest successor? */ | 1838 | /* Is friend the closest successor? */ |
2076 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&friend->id, &closest_peer)) | 1839 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (friend->id, |
1840 | closest_peer)) | ||
2077 | { | 1841 | { |
2078 | current_closest_peer->best_known_destination = friend->id; | 1842 | current_closest_peer->best_known_destination = *friend->id; |
2079 | current_closest_peer->next_hop = friend->id; | 1843 | current_closest_peer->next_hop = *friend->id; |
2080 | } | 1844 | } |
2081 | |||
2082 | return GNUNET_YES; | 1845 | return GNUNET_YES; |
2083 | } | 1846 | } |
2084 | 1847 | ||
@@ -2090,12 +1853,14 @@ compare_friend_and_current_closest_peer (void *cls, | |||
2090 | */ | 1853 | */ |
2091 | static struct Closest_Peer | 1854 | static struct Closest_Peer |
2092 | init_closest_peer (struct GNUNET_PeerIdentity my_identity, | 1855 | init_closest_peer (struct GNUNET_PeerIdentity my_identity, |
2093 | uint64_t destination_finger_value, | 1856 | uint64_t destination_finger_value, |
2094 | unsigned int is_predecessor) | 1857 | unsigned int is_predecessor) |
2095 | { | 1858 | { |
2096 | struct Closest_Peer current_closest_peer; | 1859 | struct Closest_Peer current_closest_peer; |
2097 | 1860 | ||
2098 | memset (¤t_closest_peer.trail_id, 0, sizeof(struct GNUNET_HashCode)); | 1861 | memset (¤t_closest_peer.trail_id, |
1862 | 0, | ||
1863 | sizeof(struct GNUNET_HashCode)); | ||
2099 | current_closest_peer.destination_finger_value = destination_finger_value; | 1864 | current_closest_peer.destination_finger_value = destination_finger_value; |
2100 | current_closest_peer.is_predecessor = is_predecessor; | 1865 | current_closest_peer.is_predecessor = is_predecessor; |
2101 | current_closest_peer.next_hop = my_identity; | 1866 | current_closest_peer.next_hop = my_identity; |
@@ -2174,35 +1939,32 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2174 | const void *data, size_t data_size) | 1939 | const void *data, size_t data_size) |
2175 | { | 1940 | { |
2176 | struct PeerPutMessage *ppm; | 1941 | struct PeerPutMessage *ppm; |
2177 | struct P2PPendingMessage *pending; | 1942 | struct GNUNET_MQ_Envelope *env; |
2178 | struct FriendInfo *target_friend; | 1943 | struct FriendInfo *target_friend; |
2179 | struct GNUNET_PeerIdentity *pp; | 1944 | struct GNUNET_PeerIdentity *pp; |
2180 | size_t msize; | 1945 | size_t msize; |
2181 | 1946 | ||
2182 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + | 1947 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size; |
2183 | sizeof (struct PeerPutMessage); | 1948 | if (msize + sizeof (struct PeerPutMessage) |
2184 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | 1949 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
2185 | { | 1950 | { |
2186 | put_path_length = 0; | 1951 | put_path_length = 0; |
2187 | msize = data_size + sizeof (struct PeerPutMessage); | 1952 | msize = data_size; |
2188 | } | 1953 | } |
2189 | 1954 | if (msize + sizeof (struct PeerPutMessage) | |
2190 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | 1955 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
2191 | { | 1956 | { |
2192 | DEBUG("msize = %lu\n",msize); | ||
2193 | GNUNET_break (0); | 1957 | GNUNET_break (0); |
2194 | return; | 1958 | return; |
2195 | } | 1959 | } |
2196 | 1960 | ||
2197 | GNUNET_assert (NULL != | 1961 | GNUNET_assert (NULL != |
2198 | (target_friend = | 1962 | (target_friend = |
2199 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); | 1963 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2200 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1964 | target_peer))); |
2201 | pending->timeout = expiration_time; | 1965 | env = GNUNET_MQ_msg_extra (ppm, |
2202 | ppm = (struct PeerPutMessage *) &pending[1]; | 1966 | msize, |
2203 | pending->msg = &ppm->header; | 1967 | GNUNET_MESSAGE_TYPE_XDHT_P2P_PUT); |
2204 | ppm->header.size = htons (msize); | ||
2205 | ppm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_PUT); | ||
2206 | ppm->options = htonl (options); | 1968 | ppm->options = htonl (options); |
2207 | ppm->block_type = htonl (block_type); | 1969 | ppm->block_type = htonl (block_type); |
2208 | ppm->hop_count = htonl (hop_count + 1); | 1970 | ppm->hop_count = htonl (hop_count + 1); |
@@ -2211,23 +1973,22 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | |||
2211 | ppm->best_known_destination = best_known_dest; | 1973 | ppm->best_known_destination = best_known_dest; |
2212 | ppm->intermediate_trail_id = intermediate_trail_id; | 1974 | ppm->intermediate_trail_id = intermediate_trail_id; |
2213 | ppm->key = *key; | 1975 | ppm->key = *key; |
2214 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; | ||
2215 | ppm->put_path_length = htonl (put_path_length); | 1976 | ppm->put_path_length = htonl (put_path_length); |
2216 | if(put_path_length > 0) | 1977 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; |
2217 | { | 1978 | GNUNET_memcpy (pp, |
2218 | GNUNET_memcpy (pp, put_path, | 1979 | put_path, |
2219 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); | 1980 | put_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2220 | } | 1981 | GNUNET_memcpy (&pp[put_path_length], |
2221 | GNUNET_memcpy (&pp[put_path_length], data, data_size); | 1982 | data, |
2222 | GNUNET_assert (NULL != target_friend); | 1983 | data_size); |
2223 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 1984 | GNUNET_MQ_send (target_friend->mq, |
2224 | target_friend->pending_count++; | 1985 | env); |
2225 | process_friend_queue (target_friend); | ||
2226 | } | 1986 | } |
2227 | 1987 | ||
2228 | 1988 | ||
2229 | /** | 1989 | /** |
2230 | * Handle the put request from the client. | 1990 | * Handle the put request from the client. |
1991 | * | ||
2231 | * @param key Key for the content | 1992 | * @param key Key for the content |
2232 | * @param block_type Type of the block | 1993 | * @param block_type Type of the block |
2233 | * @param options Routing options | 1994 | * @param options Routing options |
@@ -2242,7 +2003,8 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, | |||
2242 | enum GNUNET_DHT_RouteOption options, | 2003 | enum GNUNET_DHT_RouteOption options, |
2243 | uint32_t desired_replication_level, | 2004 | uint32_t desired_replication_level, |
2244 | struct GNUNET_TIME_Absolute expiration_time, | 2005 | struct GNUNET_TIME_Absolute expiration_time, |
2245 | const void *data, size_t data_size) | 2006 | const void *data, |
2007 | size_t data_size) | ||
2246 | { | 2008 | { |
2247 | struct GNUNET_PeerIdentity best_known_dest; | 2009 | struct GNUNET_PeerIdentity best_known_dest; |
2248 | struct GNUNET_HashCode intermediate_trail_id; | 2010 | struct GNUNET_HashCode intermediate_trail_id; |
@@ -2250,7 +2012,9 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, | |||
2250 | uint64_t key_value; | 2012 | uint64_t key_value; |
2251 | struct Closest_Peer successor; | 2013 | struct Closest_Peer successor; |
2252 | 2014 | ||
2253 | GNUNET_memcpy (&key_value, key, sizeof (uint64_t)); | 2015 | GNUNET_memcpy (&key_value, |
2016 | key, | ||
2017 | sizeof (uint64_t)); | ||
2254 | key_value = GNUNET_ntohll (key_value); | 2018 | key_value = GNUNET_ntohll (key_value); |
2255 | successor = find_local_best_known_next_hop (key_value, | 2019 | successor = find_local_best_known_next_hop (key_value, |
2256 | GDS_FINGER_TYPE_NON_PREDECESSOR); | 2020 | GDS_FINGER_TYPE_NON_PREDECESSOR); |
@@ -2258,28 +2022,52 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, | |||
2258 | next_hop = successor.next_hop; | 2022 | next_hop = successor.next_hop; |
2259 | intermediate_trail_id = successor.trail_id; | 2023 | intermediate_trail_id = successor.trail_id; |
2260 | 2024 | ||
2261 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity)) | 2025 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, |
2026 | &my_identity)) | ||
2262 | { | 2027 | { |
2263 | DEBUG("\n PUT_REQUEST_SUCCESSFUL for key = %s",GNUNET_h2s(key)); | 2028 | DEBUG("\n PUT_REQUEST_SUCCESSFUL for key = %s", |
2029 | GNUNET_h2s(key)); | ||
2264 | /* I am the destination. */ | 2030 | /* I am the destination. */ |
2265 | GDS_DATACACHE_handle_put (expiration_time, key, 0, NULL, | 2031 | GDS_DATACACHE_handle_put (expiration_time, |
2266 | block_type,data_size,data); | 2032 | key, |
2267 | GDS_CLIENTS_process_put (options, block_type, 0, | 2033 | 0, |
2034 | NULL, | ||
2035 | block_type, | ||
2036 | data_size, | ||
2037 | data); | ||
2038 | GDS_CLIENTS_process_put (options, | ||
2039 | block_type, | ||
2040 | 0, | ||
2268 | ntohl (desired_replication_level), | 2041 | ntohl (desired_replication_level), |
2269 | 1, &my_identity, expiration_time, //FIXME: GNUNETnthoh something on expiration time. | 2042 | 1, |
2270 | key, data, data_size); | 2043 | &my_identity, |
2044 | expiration_time, | ||
2045 | key, | ||
2046 | data, | ||
2047 | data_size); | ||
2271 | return; | 2048 | return; |
2272 | } | 2049 | } |
2273 | /* In case we are sending the request to a finger, then send across all of its | 2050 | /* In case we are sending the request to a finger, then send across all of its |
2274 | trail.*/ | 2051 | trail.*/ |
2275 | GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level, | 2052 | GDS_NEIGHBOURS_send_put (key, |
2276 | best_known_dest, intermediate_trail_id, &next_hop, | 2053 | block_type, |
2277 | 0, 1, &my_identity, expiration_time, | 2054 | options, |
2278 | data, data_size); | 2055 | desired_replication_level, |
2056 | best_known_dest, | ||
2057 | intermediate_trail_id, | ||
2058 | &next_hop, | ||
2059 | 0, | ||
2060 | 1, | ||
2061 | &my_identity, | ||
2062 | expiration_time, | ||
2063 | data, | ||
2064 | data_size); | ||
2279 | } | 2065 | } |
2280 | 2066 | ||
2067 | |||
2281 | /** | 2068 | /** |
2282 | * Construct a Get message and send it to target_peer. | 2069 | * Construct a Get message and send it to target_peer. |
2070 | * | ||
2283 | * @param key Key for the content | 2071 | * @param key Key for the content |
2284 | * @param block_type Type of the block | 2072 | * @param block_type Type of the block |
2285 | * @param options Routing options | 2073 | * @param options Routing options |
@@ -2300,50 +2088,43 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2300 | enum GNUNET_BLOCK_Type block_type, | 2088 | enum GNUNET_BLOCK_Type block_type, |
2301 | enum GNUNET_DHT_RouteOption options, | 2089 | enum GNUNET_DHT_RouteOption options, |
2302 | uint32_t desired_replication_level, | 2090 | uint32_t desired_replication_level, |
2303 | struct GNUNET_PeerIdentity best_known_dest, | 2091 | const struct GNUNET_PeerIdentity *best_known_dest, |
2304 | struct GNUNET_HashCode intermediate_trail_id, | 2092 | const struct GNUNET_HashCode *intermediate_trail_id, |
2305 | struct GNUNET_PeerIdentity *target_peer, | 2093 | const struct GNUNET_PeerIdentity *target_peer, |
2306 | uint32_t hop_count, | 2094 | uint32_t hop_count, |
2307 | uint32_t get_path_length, | 2095 | uint32_t get_path_length, |
2308 | struct GNUNET_PeerIdentity *get_path) | 2096 | const struct GNUNET_PeerIdentity *get_path) |
2309 | { | 2097 | { |
2310 | struct PeerGetMessage *pgm; | 2098 | struct PeerGetMessage *pgm; |
2311 | struct P2PPendingMessage *pending; | 2099 | struct GNUNET_MQ_Envelope *env; |
2312 | struct FriendInfo *target_friend; | 2100 | struct FriendInfo *target_friend; |
2313 | struct GNUNET_PeerIdentity *gp; | ||
2314 | size_t msize; | 2101 | size_t msize; |
2315 | 2102 | ||
2316 | msize = sizeof (struct PeerGetMessage) + | 2103 | msize = get_path_length * sizeof (struct GNUNET_PeerIdentity); |
2317 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2104 | if (msize + sizeof (struct PeerGetMessage) |
2318 | 2105 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | |
2319 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
2320 | { | 2106 | { |
2321 | GNUNET_break (0); | 2107 | GNUNET_break (0); |
2322 | return; | 2108 | return; |
2323 | } | 2109 | } |
2324 | GNUNET_assert (NULL != | 2110 | GNUNET_assert (NULL != |
2325 | (target_friend = | 2111 | (target_friend = |
2326 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); | 2112 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2327 | 2113 | target_peer))); | |
2328 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 2114 | env = GNUNET_MQ_msg_extra (pgm, |
2329 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 2115 | msize, |
2330 | pending->importance = 0; /* FIXME */ | 2116 | GNUNET_MESSAGE_TYPE_XDHT_P2P_GET); |
2331 | pgm = (struct PeerGetMessage *) &pending[1]; | ||
2332 | pending->msg = &pgm->header; | ||
2333 | pgm->header.size = htons (msize); | ||
2334 | pgm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_GET); | ||
2335 | pgm->get_path_length = htonl (get_path_length); | 2117 | pgm->get_path_length = htonl (get_path_length); |
2336 | pgm->best_known_destination = best_known_dest; | 2118 | pgm->best_known_destination = *best_known_dest; |
2337 | pgm->key = *key; | 2119 | pgm->key = *key; |
2338 | pgm->intermediate_trail_id = intermediate_trail_id; | 2120 | pgm->intermediate_trail_id = *intermediate_trail_id; |
2339 | pgm->hop_count = htonl (hop_count + 1); | 2121 | pgm->hop_count = htonl (hop_count + 1); |
2340 | pgm->get_path_length = htonl (get_path_length); | 2122 | pgm->get_path_length = htonl (get_path_length); |
2341 | gp = (struct GNUNET_PeerIdentity *) &pgm[1]; | 2123 | GNUNET_memcpy (&pgm[1], |
2342 | GNUNET_memcpy (gp, get_path, | 2124 | get_path, |
2343 | sizeof (struct GNUNET_PeerIdentity) * get_path_length); | 2125 | msize); |
2344 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 2126 | GNUNET_MQ_send (target_friend->mq, |
2345 | target_friend->pending_count++; | 2127 | env); |
2346 | process_friend_queue (target_friend); | ||
2347 | } | 2128 | } |
2348 | 2129 | ||
2349 | 2130 | ||
@@ -2351,28 +2132,29 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2351 | * Handle the get request from the client file. If I am destination do | 2132 | * Handle the get request from the client file. If I am destination do |
2352 | * datacache put and return. Else find the target friend and forward message | 2133 | * datacache put and return. Else find the target friend and forward message |
2353 | * to it. | 2134 | * to it. |
2135 | * | ||
2354 | * @param key Key for the content | 2136 | * @param key Key for the content |
2355 | * @param block_type Type of the block | 2137 | * @param block_type Type of the block |
2356 | * @param options Routing options | 2138 | * @param options Routing options |
2357 | * @param desired_replication_level Desired replication count | 2139 | * @param desired_replication_level Desired replication count |
2358 | */ | 2140 | */ |
2359 | void | 2141 | void |
2360 | GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key, | 2142 | GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key, |
2361 | enum GNUNET_BLOCK_Type block_type, | 2143 | enum GNUNET_BLOCK_Type block_type, |
2362 | enum GNUNET_DHT_RouteOption options, | 2144 | enum GNUNET_DHT_RouteOption options, |
2363 | uint32_t desired_replication_level) | 2145 | uint32_t desired_replication_level) |
2364 | { | 2146 | { |
2365 | struct Closest_Peer successor; | 2147 | struct Closest_Peer successor; |
2366 | struct GNUNET_PeerIdentity best_known_dest; | 2148 | struct GNUNET_PeerIdentity best_known_dest; |
2367 | struct GNUNET_HashCode intermediate_trail_id; | 2149 | struct GNUNET_HashCode intermediate_trail_id; |
2368 | uint64_t key_value; | 2150 | uint64_t key_value; |
2369 | 2151 | ||
2370 | GNUNET_memcpy (&key_value, key, sizeof (uint64_t)); | 2152 | GNUNET_memcpy (&key_value, |
2153 | key, | ||
2154 | sizeof (uint64_t)); | ||
2371 | key_value = GNUNET_ntohll (key_value); | 2155 | key_value = GNUNET_ntohll (key_value); |
2372 | |||
2373 | successor = find_local_best_known_next_hop (key_value, | 2156 | successor = find_local_best_known_next_hop (key_value, |
2374 | GDS_FINGER_TYPE_NON_PREDECESSOR); | 2157 | GDS_FINGER_TYPE_NON_PREDECESSOR); |
2375 | |||
2376 | best_known_dest = successor.best_known_destination; | 2158 | best_known_dest = successor.best_known_destination; |
2377 | intermediate_trail_id = successor.trail_id; | 2159 | intermediate_trail_id = successor.trail_id; |
2378 | 2160 | ||
@@ -2380,14 +2162,29 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key, | |||
2380 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | 2162 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
2381 | &best_known_dest)) | 2163 | &best_known_dest)) |
2382 | { | 2164 | { |
2383 | GDS_DATACACHE_handle_get (key,block_type, NULL, 0, | 2165 | GDS_DATACACHE_handle_get (key, |
2384 | NULL, 0, 1, &my_identity, NULL,&my_identity); | 2166 | block_type, |
2167 | NULL, | ||
2168 | 0, | ||
2169 | NULL, | ||
2170 | 0, | ||
2171 | 1, | ||
2172 | &my_identity, | ||
2173 | NULL, | ||
2174 | &my_identity); | ||
2385 | return; | 2175 | return; |
2386 | } | 2176 | } |
2387 | 2177 | ||
2388 | GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level, | 2178 | GDS_NEIGHBOURS_send_get (key, |
2389 | best_known_dest,intermediate_trail_id, &successor.next_hop, | 2179 | block_type, |
2390 | 0, 1, &my_identity); | 2180 | options, |
2181 | desired_replication_level, | ||
2182 | &best_known_dest, | ||
2183 | &intermediate_trail_id, | ||
2184 | &successor.next_hop, | ||
2185 | 0, | ||
2186 | 1, | ||
2187 | &my_identity); | ||
2391 | } | 2188 | } |
2392 | 2189 | ||
2393 | 2190 | ||
@@ -2420,30 +2217,30 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2420 | { | 2217 | { |
2421 | struct PeerGetResultMessage *get_result; | 2218 | struct PeerGetResultMessage *get_result; |
2422 | struct GNUNET_PeerIdentity *paths; | 2219 | struct GNUNET_PeerIdentity *paths; |
2423 | struct P2PPendingMessage *pending; | 2220 | struct GNUNET_MQ_Envelope *env; |
2424 | struct FriendInfo *target_friend; | 2221 | struct FriendInfo *target_friend; |
2425 | int current_path_index; | 2222 | int current_path_index; |
2426 | size_t msize; | 2223 | size_t msize; |
2427 | 2224 | ||
2428 | msize = (put_path_length + get_path_length )* sizeof (struct GNUNET_PeerIdentity) + | 2225 | msize = (put_path_length + get_path_length) * sizeof (struct GNUNET_PeerIdentity) + |
2429 | data_size + | 2226 | data_size; |
2430 | sizeof (struct PeerGetResultMessage); | 2227 | if (msize + sizeof (struct PeerGetResultMessage) |
2431 | 2228 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | |
2432 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
2433 | { | 2229 | { |
2434 | put_path_length = 0; | 2230 | put_path_length = 0; |
2435 | msize = msize - put_path_length * sizeof (struct GNUNET_PeerIdentity); | 2231 | msize = data_size; |
2436 | } | 2232 | } |
2437 | 2233 | if (msize + sizeof (struct PeerGetResultMessage) | |
2438 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | 2234 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
2439 | { | 2235 | { |
2440 | GNUNET_break(0); | 2236 | GNUNET_break(0); |
2441 | return; | 2237 | return; |
2442 | } | 2238 | } |
2443 | current_path_index = 0; | 2239 | current_path_index = 0; |
2444 | if(get_path_length > 0) | 2240 | if (get_path_length > 0) |
2445 | { | 2241 | { |
2446 | current_path_index = search_my_index(get_path, get_path_length); | 2242 | current_path_index = search_my_index (get_path, |
2243 | get_path_length); | ||
2447 | if (-1 == current_path_index) | 2244 | if (-1 == current_path_index) |
2448 | { | 2245 | { |
2449 | GNUNET_break (0); | 2246 | GNUNET_break (0); |
@@ -2458,39 +2255,45 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2458 | } | 2255 | } |
2459 | if (0 == current_path_index) | 2256 | if (0 == current_path_index) |
2460 | { | 2257 | { |
2461 | DEBUG ("GET_RESULT TO CLIENT KEY = %s, Peer = %s",GNUNET_h2s(key),GNUNET_i2s(&my_identity)); | 2258 | DEBUG ("GET_RESULT TO CLIENT KEY = %s, Peer = %s", |
2462 | GDS_CLIENTS_handle_reply (expiration, key, get_path_length, | 2259 | GNUNET_h2s(key), |
2463 | get_path, put_path_length, | 2260 | GNUNET_i2s(&my_identity)); |
2464 | put_path, type, data_size, data); | 2261 | GDS_CLIENTS_handle_reply (expiration, |
2262 | key, | ||
2263 | get_path_length, | ||
2264 | get_path, | ||
2265 | put_path_length, | ||
2266 | put_path, | ||
2267 | type, | ||
2268 | data_size, | ||
2269 | data); | ||
2465 | return; | 2270 | return; |
2466 | } | 2271 | } |
2467 | 2272 | env = GNUNET_MQ_msg_extra (get_result, | |
2468 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 2273 | msize, |
2469 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | 2274 | GNUNET_MESSAGE_TYPE_XDHT_P2P_GET_RESULT); |
2470 | pending->importance = 0; | ||
2471 | get_result = (struct PeerGetResultMessage *)&pending[1]; | ||
2472 | pending->msg = &get_result->header; | ||
2473 | get_result->header.size = htons (msize); | ||
2474 | get_result->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_GET_RESULT); | ||
2475 | get_result->key = *key; | 2275 | get_result->key = *key; |
2476 | get_result->querying_peer = *source_peer; | 2276 | get_result->querying_peer = *source_peer; |
2477 | get_result->expiration_time = GNUNET_TIME_absolute_hton (expiration); | 2277 | get_result->expiration_time = GNUNET_TIME_absolute_hton (expiration); |
2478 | get_result->get_path_length = htonl (get_path_length); | 2278 | get_result->get_path_length = htonl (get_path_length); |
2479 | get_result->put_path_length = htonl (put_path_length); | 2279 | get_result->put_path_length = htonl (put_path_length); |
2480 | paths = (struct GNUNET_PeerIdentity *)&get_result[1]; | 2280 | paths = (struct GNUNET_PeerIdentity *)&get_result[1]; |
2481 | GNUNET_memcpy (paths, put_path, | 2281 | GNUNET_memcpy (paths, |
2482 | put_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2282 | put_path, |
2483 | GNUNET_memcpy (&paths[put_path_length], get_path, | 2283 | put_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2484 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2284 | GNUNET_memcpy (&paths[put_path_length], |
2485 | GNUNET_memcpy (&paths[put_path_length + get_path_length], data, data_size); | 2285 | get_path, |
2286 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); | ||
2287 | GNUNET_memcpy (&paths[put_path_length + get_path_length], | ||
2288 | data, | ||
2289 | data_size); | ||
2486 | 2290 | ||
2487 | GNUNET_assert (NULL != | 2291 | GNUNET_assert (NULL != |
2488 | (target_friend = | 2292 | (target_friend = |
2489 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2293 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2490 | &get_path[current_path_index - 1]))); | 2294 | &get_path[current_path_index - 1]))); |
2491 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 2295 | GNUNET_MQ_send (target_friend->mq, |
2492 | target_friend->pending_count++; | 2296 | env); |
2493 | process_friend_queue (target_friend); | ||
2494 | } | 2297 | } |
2495 | 2298 | ||
2496 | 2299 | ||
@@ -2559,10 +2362,11 @@ select_random_friend () | |||
2559 | 2362 | ||
2560 | /** | 2363 | /** |
2561 | * Compute 64 bit value of finger_identity corresponding to a finger index using | 2364 | * Compute 64 bit value of finger_identity corresponding to a finger index using |
2562 | * chord formula. | 2365 | * Chord formula. |
2563 | * For all fingers, n.finger[i] = n + pow (2,i), | 2366 | * For all fingers, n.finger[i] = n + pow (2,i), |
2564 | * For predecessor, n.finger[PREDECESSOR_FINGER_ID] = n - 1, where | 2367 | * For predecessor, n.finger[PREDECESSOR_FINGER_ID] = n - 1, where |
2565 | * n = my_identity, i = finger_index, n.finger[i] = 64 bit finger value | 2368 | * n = my_identity, i = finger_index, n.finger[i] = 64 bit finger value |
2369 | * | ||
2566 | * @param finger_index Index corresponding to which we calculate 64 bit value. | 2370 | * @param finger_index Index corresponding to which we calculate 64 bit value. |
2567 | * @return 64 bit value. | 2371 | * @return 64 bit value. |
2568 | */ | 2372 | */ |
@@ -2571,21 +2375,20 @@ compute_finger_identity_value (unsigned int finger_index) | |||
2571 | { | 2375 | { |
2572 | uint64_t my_id64; | 2376 | uint64_t my_id64; |
2573 | 2377 | ||
2574 | GNUNET_memcpy (&my_id64, &my_identity, sizeof (uint64_t)); | 2378 | GNUNET_memcpy (&my_id64, |
2379 | &my_identity, | ||
2380 | sizeof (uint64_t)); | ||
2575 | my_id64 = GNUNET_ntohll (my_id64); | 2381 | my_id64 = GNUNET_ntohll (my_id64); |
2576 | 2382 | ||
2577 | /* Are we looking for immediate predecessor? */ | 2383 | /* Are we looking for immediate predecessor? */ |
2578 | if (PREDECESSOR_FINGER_ID == finger_index) | 2384 | if (PREDECESSOR_FINGER_ID == finger_index) |
2579 | return (my_id64 - 1); | 2385 | return (my_id64 - 1); |
2580 | else | 2386 | uint64_t add = (uint64_t)1 << finger_index; |
2581 | { | 2387 | return (my_id64 + add); |
2582 | uint64_t add = (uint64_t)1 << finger_index; | ||
2583 | return (my_id64 + add); | ||
2584 | } | ||
2585 | } | 2388 | } |
2586 | 2389 | ||
2587 | 2390 | ||
2588 | /* | 2391 | /** |
2589 | * Choose a random friend. Calculate the next finger identity to search,from | 2392 | * Choose a random friend. Calculate the next finger identity to search,from |
2590 | * current_search_finger_index. Start looking for the trail to reach to | 2393 | * current_search_finger_index. Start looking for the trail to reach to |
2591 | * finger identity through this random friend. | 2394 | * finger identity through this random friend. |
@@ -2619,9 +2422,7 @@ send_find_finger_trail_message (void *cls) | |||
2619 | 2422 | ||
2620 | target_friend = select_random_friend (); | 2423 | target_friend = select_random_friend (); |
2621 | if (NULL == target_friend) | 2424 | if (NULL == target_friend) |
2622 | { | ||
2623 | return; | 2425 | return; |
2624 | } | ||
2625 | 2426 | ||
2626 | finger_id_value = compute_finger_identity_value (current_search_finger_index); | 2427 | finger_id_value = compute_finger_identity_value (current_search_finger_index); |
2627 | if (PREDECESSOR_FINGER_ID == current_search_finger_index) | 2428 | if (PREDECESSOR_FINGER_ID == current_search_finger_index) |
@@ -2629,12 +2430,19 @@ send_find_finger_trail_message (void *cls) | |||
2629 | 2430 | ||
2630 | /* Generate a unique trail id for trail we are trying to setup. */ | 2431 | /* Generate a unique trail id for trail we are trying to setup. */ |
2631 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, | 2432 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, |
2632 | &trail_id, sizeof (trail_id)); | 2433 | &trail_id, |
2633 | memset(&intermediate_trail_id, 0, sizeof (struct GNUNET_HashCode)); | 2434 | sizeof (trail_id)); |
2634 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_id_value, | 2435 | memset (&intermediate_trail_id, |
2635 | target_friend->id, target_friend, 0, NULL, | 2436 | 0, |
2636 | is_predecessor, trail_id, | 2437 | sizeof (struct GNUNET_HashCode)); |
2637 | intermediate_trail_id); | 2438 | GDS_NEIGHBOURS_send_trail_setup (&my_identity, |
2439 | finger_id_value, | ||
2440 | target_friend->id, | ||
2441 | target_friend, | ||
2442 | 0, NULL, | ||
2443 | is_predecessor, | ||
2444 | &trail_id, | ||
2445 | &intermediate_trail_id); | ||
2638 | } | 2446 | } |
2639 | 2447 | ||
2640 | 2448 | ||
@@ -2660,13 +2468,13 @@ static void | |||
2660 | select_and_replace_trail (struct FingerInfo *finger, | 2468 | select_and_replace_trail (struct FingerInfo *finger, |
2661 | const struct GNUNET_PeerIdentity *new_trail, | 2469 | const struct GNUNET_PeerIdentity *new_trail, |
2662 | unsigned int new_trail_length, | 2470 | unsigned int new_trail_length, |
2663 | struct GNUNET_HashCode new_trail_id) | 2471 | const struct GNUNET_HashCode *new_trail_id) |
2664 | { | 2472 | { |
2665 | struct Trail *current_trail; | 2473 | struct Trail *current_trail; |
2666 | unsigned int largest_trail_length; | 2474 | unsigned int largest_trail_length; |
2667 | unsigned int largest_trail_index; | 2475 | unsigned int largest_trail_index; |
2668 | struct Trail_Element *trail_element; | 2476 | struct Trail_Element *trail_element; |
2669 | struct GNUNET_PeerIdentity *next_hop; | 2477 | const struct GNUNET_PeerIdentity *next_hop; |
2670 | unsigned int i; | 2478 | unsigned int i; |
2671 | 2479 | ||
2672 | largest_trail_length = new_trail_length; | 2480 | largest_trail_length = new_trail_length; |
@@ -2688,9 +2496,10 @@ select_and_replace_trail (struct FingerInfo *finger, | |||
2688 | /* New trail is not better than existing ones. Send trail teardown. */ | 2496 | /* New trail is not better than existing ones. Send trail teardown. */ |
2689 | if (largest_trail_index == (MAXIMUM_TRAILS_PER_FINGER + 1)) | 2497 | if (largest_trail_index == (MAXIMUM_TRAILS_PER_FINGER + 1)) |
2690 | { | 2498 | { |
2691 | next_hop = GDS_ROUTING_get_next_hop (new_trail_id, GDS_ROUTING_SRC_TO_DEST); | 2499 | next_hop = GDS_ROUTING_get_next_hop (new_trail_id, |
2500 | GDS_ROUTING_SRC_TO_DEST); | ||
2692 | GDS_ROUTING_remove_trail (new_trail_id); | 2501 | GDS_ROUTING_remove_trail (new_trail_id); |
2693 | GDS_NEIGHBOURS_send_trail_teardown (&new_trail_id, | 2502 | GDS_NEIGHBOURS_send_trail_teardown (new_trail_id, |
2694 | GDS_ROUTING_SRC_TO_DEST, | 2503 | GDS_ROUTING_SRC_TO_DEST, |
2695 | next_hop); | 2504 | next_hop); |
2696 | return; | 2505 | return; |
@@ -2698,8 +2507,9 @@ select_and_replace_trail (struct FingerInfo *finger, | |||
2698 | 2507 | ||
2699 | /* Send trail teardown message across the replaced trail. */ | 2508 | /* Send trail teardown message across the replaced trail. */ |
2700 | struct Trail *replace_trail = &finger->trail_list[largest_trail_index]; | 2509 | struct Trail *replace_trail = &finger->trail_list[largest_trail_index]; |
2701 | next_hop = GDS_ROUTING_get_next_hop (replace_trail->trail_id, GDS_ROUTING_SRC_TO_DEST); | 2510 | next_hop = GDS_ROUTING_get_next_hop (&replace_trail->trail_id, |
2702 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (replace_trail->trail_id)); | 2511 | GDS_ROUTING_SRC_TO_DEST); |
2512 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (&replace_trail->trail_id)); | ||
2703 | GDS_NEIGHBOURS_send_trail_teardown (&replace_trail->trail_id, | 2513 | GDS_NEIGHBOURS_send_trail_teardown (&replace_trail->trail_id, |
2704 | GDS_ROUTING_SRC_TO_DEST, | 2514 | GDS_ROUTING_SRC_TO_DEST, |
2705 | next_hop); | 2515 | next_hop); |
@@ -2708,14 +2518,15 @@ select_and_replace_trail (struct FingerInfo *finger, | |||
2708 | while (NULL != (trail_element = replace_trail->trail_head)) | 2518 | while (NULL != (trail_element = replace_trail->trail_head)) |
2709 | { | 2519 | { |
2710 | GNUNET_CONTAINER_DLL_remove (replace_trail->trail_head, | 2520 | GNUNET_CONTAINER_DLL_remove (replace_trail->trail_head, |
2711 | replace_trail->trail_tail, trail_element); | 2521 | replace_trail->trail_tail, |
2522 | trail_element); | ||
2712 | GNUNET_free_non_null (trail_element); | 2523 | GNUNET_free_non_null (trail_element); |
2713 | } | 2524 | } |
2714 | 2525 | ||
2715 | /* Add new trial at that location. */ | 2526 | /* Add new trial at that location. */ |
2716 | replace_trail->is_present = GNUNET_YES; | 2527 | replace_trail->is_present = GNUNET_YES; |
2717 | replace_trail->trail_length = new_trail_length; | 2528 | replace_trail->trail_length = new_trail_length; |
2718 | replace_trail->trail_id = new_trail_id; | 2529 | replace_trail->trail_id = *new_trail_id; |
2719 | 2530 | ||
2720 | for (i = 0; i < new_trail_length; i++) | 2531 | for (i = 0; i < new_trail_length; i++) |
2721 | { | 2532 | { |
@@ -2778,6 +2589,7 @@ is_new_trail_unique (struct FingerInfo *existing_finger, | |||
2778 | return GNUNET_NO; | 2589 | return GNUNET_NO; |
2779 | } | 2590 | } |
2780 | 2591 | ||
2592 | |||
2781 | /** | 2593 | /** |
2782 | * FIXME; In case of multiple trails, we may have a case where a trail from in | 2594 | * FIXME; In case of multiple trails, we may have a case where a trail from in |
2783 | * between has been removed, then we should try to find a free slot , not simply | 2595 | * between has been removed, then we should try to find a free slot , not simply |
@@ -2792,14 +2604,15 @@ static void | |||
2792 | add_new_trail (struct FingerInfo *existing_finger, | 2604 | add_new_trail (struct FingerInfo *existing_finger, |
2793 | const struct GNUNET_PeerIdentity *new_trail, | 2605 | const struct GNUNET_PeerIdentity *new_trail, |
2794 | unsigned int new_trail_length, | 2606 | unsigned int new_trail_length, |
2795 | struct GNUNET_HashCode new_trail_id) | 2607 | const struct GNUNET_HashCode *new_trail_id) |
2796 | { | 2608 | { |
2797 | struct FriendInfo *friend; | 2609 | struct FriendInfo *friend; |
2798 | struct Trail *trail; | 2610 | struct Trail *trail; |
2799 | unsigned int i; | 2611 | unsigned int i; |
2800 | int free_slot = -1; | 2612 | int free_slot = -1; |
2801 | 2613 | ||
2802 | if (GNUNET_NO == is_new_trail_unique (existing_finger, new_trail, | 2614 | if (GNUNET_NO == is_new_trail_unique (existing_finger, |
2615 | new_trail, | ||
2803 | new_trail_length)) | 2616 | new_trail_length)) |
2804 | return; | 2617 | return; |
2805 | 2618 | ||
@@ -2817,7 +2630,7 @@ add_new_trail (struct FingerInfo *existing_finger, | |||
2817 | 2630 | ||
2818 | trail = &existing_finger->trail_list[free_slot]; | 2631 | trail = &existing_finger->trail_list[free_slot]; |
2819 | GNUNET_assert (GNUNET_NO == trail->is_present); | 2632 | GNUNET_assert (GNUNET_NO == trail->is_present); |
2820 | trail->trail_id = new_trail_id; | 2633 | trail->trail_id = *new_trail_id; |
2821 | trail->trail_length = new_trail_length; | 2634 | trail->trail_length = new_trail_length; |
2822 | existing_finger->trails_count++; | 2635 | existing_finger->trails_count++; |
2823 | trail->is_present = GNUNET_YES; | 2636 | trail->is_present = GNUNET_YES; |
@@ -2847,7 +2660,7 @@ add_new_trail (struct FingerInfo *existing_finger, | |||
2847 | existing_finger->trail_list[free_slot].trail_head = trail->trail_head; | 2660 | existing_finger->trail_list[free_slot].trail_head = trail->trail_head; |
2848 | existing_finger->trail_list[free_slot].trail_tail = trail->trail_tail; | 2661 | existing_finger->trail_list[free_slot].trail_tail = trail->trail_tail; |
2849 | existing_finger->trail_list[free_slot].trail_length = new_trail_length; | 2662 | existing_finger->trail_list[free_slot].trail_length = new_trail_length; |
2850 | existing_finger->trail_list[free_slot].trail_id = new_trail_id; | 2663 | existing_finger->trail_list[free_slot].trail_id = *new_trail_id; |
2851 | existing_finger->trail_list[free_slot].is_present = GNUNET_YES; | 2664 | existing_finger->trail_list[free_slot].is_present = GNUNET_YES; |
2852 | } | 2665 | } |
2853 | 2666 | ||
@@ -2867,21 +2680,22 @@ static void | |||
2867 | add_new_trail (struct FingerInfo *existing_finger, | 2680 | add_new_trail (struct FingerInfo *existing_finger, |
2868 | const struct GNUNET_PeerIdentity *new_trail, | 2681 | const struct GNUNET_PeerIdentity *new_trail, |
2869 | unsigned int new_trail_length, | 2682 | unsigned int new_trail_length, |
2870 | struct GNUNET_HashCode new_trail_id) | 2683 | const struct GNUNET_HashCode *new_trail_id) |
2871 | { | 2684 | { |
2872 | struct Trail *trail; | 2685 | struct Trail *trail; |
2873 | struct FriendInfo *first_friend; | 2686 | struct FriendInfo *first_friend; |
2874 | int i; | 2687 | int i; |
2875 | int index; | 2688 | int index; |
2876 | 2689 | ||
2877 | if (GNUNET_NO == is_new_trail_unique (existing_finger, new_trail, | 2690 | if (GNUNET_NO == is_new_trail_unique (existing_finger, |
2691 | new_trail, | ||
2878 | new_trail_length)) | 2692 | new_trail_length)) |
2879 | return; | 2693 | return; |
2880 | 2694 | ||
2881 | index = existing_finger->trails_count; | 2695 | index = existing_finger->trails_count; |
2882 | trail = &existing_finger->trail_list[index]; | 2696 | trail = &existing_finger->trail_list[index]; |
2883 | GNUNET_assert (GNUNET_NO == trail->is_present); | 2697 | GNUNET_assert (GNUNET_NO == trail->is_present); |
2884 | trail->trail_id = new_trail_id; | 2698 | trail->trail_id = *new_trail_id; |
2885 | trail->trail_length = new_trail_length; | 2699 | trail->trail_length = new_trail_length; |
2886 | existing_finger->trails_count++; | 2700 | existing_finger->trails_count++; |
2887 | trail->is_present = GNUNET_YES; | 2701 | trail->is_present = GNUNET_YES; |
@@ -2909,7 +2723,7 @@ add_new_trail (struct FingerInfo *existing_finger, | |||
2909 | existing_finger->trail_list[index].trail_head = trail->trail_head; | 2723 | existing_finger->trail_list[index].trail_head = trail->trail_head; |
2910 | existing_finger->trail_list[index].trail_tail = trail->trail_tail; | 2724 | existing_finger->trail_list[index].trail_tail = trail->trail_tail; |
2911 | existing_finger->trail_list[index].trail_length = new_trail_length; | 2725 | existing_finger->trail_list[index].trail_length = new_trail_length; |
2912 | existing_finger->trail_list[index].trail_id = new_trail_id; | 2726 | existing_finger->trail_list[index].trail_id = *new_trail_id; |
2913 | existing_finger->trail_list[index].is_present = GNUNET_YES; | 2727 | existing_finger->trail_list[index].is_present = GNUNET_YES; |
2914 | } | 2728 | } |
2915 | #endif | 2729 | #endif |
@@ -2927,9 +2741,9 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2927 | struct Trail *trail) | 2741 | struct Trail *trail) |
2928 | { | 2742 | { |
2929 | struct FriendInfo *friend; | 2743 | struct FriendInfo *friend; |
2930 | struct GNUNET_PeerIdentity *next_hop; | 2744 | const struct GNUNET_PeerIdentity *next_hop; |
2931 | 2745 | ||
2932 | next_hop = GDS_ROUTING_get_next_hop (trail->trail_id, | 2746 | next_hop = GDS_ROUTING_get_next_hop (&trail->trail_id, |
2933 | GDS_ROUTING_SRC_TO_DEST); | 2747 | GDS_ROUTING_SRC_TO_DEST); |
2934 | if (NULL == next_hop) | 2748 | if (NULL == next_hop) |
2935 | { | 2749 | { |
@@ -2955,21 +2769,29 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2955 | if(NULL == friend) | 2769 | if(NULL == friend) |
2956 | { | 2770 | { |
2957 | DEBUG ("\n LINE NO: = %d, Friend not found for trail id %s of peer %s trail length = %d", | 2771 | DEBUG ("\n LINE NO: = %d, Friend not found for trail id %s of peer %s trail length = %d", |
2958 | __LINE__,GNUNET_h2s(&trail->trail_id), GNUNET_i2s(&my_identity),trail->trail_length); | 2772 | __LINE__, |
2773 | GNUNET_h2s (&trail->trail_id), | ||
2774 | GNUNET_i2s(&my_identity), | ||
2775 | trail->trail_length); | ||
2959 | return; | 2776 | return; |
2960 | } | 2777 | } |
2961 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (next_hop, &friend->id) | 2778 | if ( (0 != GNUNET_CRYPTO_cmp_peer_identity (next_hop, |
2962 | && (0 == trail->trail_length)) | 2779 | friend->id) ) && |
2780 | (0 == trail->trail_length)) | ||
2963 | { | 2781 | { |
2964 | DEBUG ("\n LINE NO: = %d, Friend not found for trail id %s of peer %s trail length = %d", | 2782 | DEBUG ("\n LINE NO: = %d, Friend not found for trail id %s of peer %s trail length = %d", |
2965 | __LINE__,GNUNET_h2s(&trail->trail_id), GNUNET_i2s(&my_identity),trail->trail_length); | 2783 | __LINE__, |
2784 | GNUNET_h2s (&trail->trail_id), | ||
2785 | GNUNET_i2s (&my_identity), | ||
2786 | trail->trail_length); | ||
2966 | return; | 2787 | return; |
2967 | } | 2788 | } |
2968 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id)); | 2789 | GNUNET_assert (GNUNET_YES == |
2790 | GDS_ROUTING_remove_trail (&trail->trail_id)); | ||
2969 | friend->trails_count--; | 2791 | friend->trails_count--; |
2970 | GDS_NEIGHBOURS_send_trail_teardown (&trail->trail_id, | 2792 | GDS_NEIGHBOURS_send_trail_teardown (&trail->trail_id, |
2971 | GDS_ROUTING_SRC_TO_DEST, | 2793 | GDS_ROUTING_SRC_TO_DEST, |
2972 | &friend->id); | 2794 | friend->id); |
2973 | } | 2795 | } |
2974 | 2796 | ||
2975 | 2797 | ||
@@ -2980,9 +2802,7 @@ send_trail_teardown (struct FingerInfo *finger, | |||
2980 | static void | 2802 | static void |
2981 | send_all_finger_trails_teardown (struct FingerInfo *finger) | 2803 | send_all_finger_trails_teardown (struct FingerInfo *finger) |
2982 | { | 2804 | { |
2983 | unsigned int i; | 2805 | for (unsigned int i = 0; i < finger->trails_count; i++) |
2984 | |||
2985 | for (i = 0; i < finger->trails_count; i++) | ||
2986 | { | 2806 | { |
2987 | struct Trail *trail; | 2807 | struct Trail *trail; |
2988 | 2808 | ||
@@ -3019,15 +2839,17 @@ free_trail (struct Trail *trail) | |||
3019 | 2839 | ||
3020 | /** | 2840 | /** |
3021 | * Free finger and its trail. | 2841 | * Free finger and its trail. |
2842 | * | ||
3022 | * @param finger Finger to be freed. | 2843 | * @param finger Finger to be freed. |
3023 | * @param finger_table_index Index at which finger is stored. | 2844 | * @param finger_table_index Index at which finger is stored. |
3024 | */ | 2845 | */ |
3025 | static void | 2846 | static void |
3026 | free_finger (struct FingerInfo *finger, unsigned int finger_table_index) | 2847 | free_finger (struct FingerInfo *finger, |
2848 | unsigned int finger_table_index) | ||
3027 | { | 2849 | { |
3028 | struct Trail *trail; | 2850 | struct Trail *trail; |
3029 | unsigned int i; | 2851 | |
3030 | for (i = 0; i < finger->trails_count; i++) | 2852 | for (unsigned int i = 0; i < finger->trails_count; i++) |
3031 | { | 2853 | { |
3032 | trail = &finger->trail_list[i]; | 2854 | trail = &finger->trail_list[i]; |
3033 | if (GNUNET_NO == trail->is_present) | 2855 | if (GNUNET_NO == trail->is_present) |
@@ -3039,7 +2861,9 @@ free_finger (struct FingerInfo *finger, unsigned int finger_table_index) | |||
3039 | } | 2861 | } |
3040 | 2862 | ||
3041 | finger->is_present = GNUNET_NO; | 2863 | finger->is_present = GNUNET_NO; |
3042 | memset ((void *)&finger_table[finger_table_index], 0, sizeof (finger_table[finger_table_index])); | 2864 | memset (&finger_table[finger_table_index], |
2865 | 0, | ||
2866 | sizeof (finger_table[finger_table_index])); | ||
3043 | } | 2867 | } |
3044 | 2868 | ||
3045 | 2869 | ||
@@ -3048,6 +2872,7 @@ free_finger (struct FingerInfo *finger, unsigned int finger_table_index) | |||
3048 | * In case I am my own finger, then we don't have a trail. In case of a friend, | 2872 | * In case I am my own finger, then we don't have a trail. In case of a friend, |
3049 | * we have a trail with unique id and '0' trail length. | 2873 | * we have a trail with unique id and '0' trail length. |
3050 | * In case a finger is a friend, then increment the trails count of the friend. | 2874 | * In case a finger is a friend, then increment the trails count of the friend. |
2875 | * | ||
3051 | * @param finger_identity Peer Identity of new finger | 2876 | * @param finger_identity Peer Identity of new finger |
3052 | * @param finger_trail Trail to reach from me to finger (excluding both end points). | 2877 | * @param finger_trail Trail to reach from me to finger (excluding both end points). |
3053 | * @param finger_trail_length Total number of peers in @a finger_trail. | 2878 | * @param finger_trail_length Total number of peers in @a finger_trail. |
@@ -3055,10 +2880,10 @@ free_finger (struct FingerInfo *finger, unsigned int finger_table_index) | |||
3055 | * @param finger_table_index Index in finger table. | 2880 | * @param finger_table_index Index in finger table. |
3056 | */ | 2881 | */ |
3057 | static void | 2882 | static void |
3058 | add_new_finger (struct GNUNET_PeerIdentity finger_identity, | 2883 | add_new_finger (const struct GNUNET_PeerIdentity *finger_identity, |
3059 | const struct GNUNET_PeerIdentity *finger_trail, | 2884 | const struct GNUNET_PeerIdentity *finger_trail, |
3060 | unsigned int finger_trail_length, | 2885 | unsigned int finger_trail_length, |
3061 | struct GNUNET_HashCode trail_id, | 2886 | const struct GNUNET_HashCode *trail_id, |
3062 | unsigned int finger_table_index) | 2887 | unsigned int finger_table_index) |
3063 | { | 2888 | { |
3064 | struct FingerInfo *new_entry; | 2889 | struct FingerInfo *new_entry; |
@@ -3067,13 +2892,13 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
3067 | unsigned int i; | 2892 | unsigned int i; |
3068 | 2893 | ||
3069 | new_entry = GNUNET_new (struct FingerInfo); | 2894 | new_entry = GNUNET_new (struct FingerInfo); |
3070 | new_entry->finger_identity = finger_identity; | 2895 | new_entry->finger_identity = *finger_identity; |
3071 | new_entry->finger_table_index = finger_table_index; | 2896 | new_entry->finger_table_index = finger_table_index; |
3072 | new_entry->is_present = GNUNET_YES; | 2897 | new_entry->is_present = GNUNET_YES; |
3073 | 2898 | ||
3074 | /* If the new entry is my own identity. */ | 2899 | /* If the new entry is my own identity. */ |
3075 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | 2900 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
3076 | &finger_identity)) | 2901 | finger_identity)) |
3077 | { | 2902 | { |
3078 | new_entry->trails_count = 0; | 2903 | new_entry->trails_count = 0; |
3079 | finger_table[finger_table_index] = *new_entry; | 2904 | finger_table[finger_table_index] = *new_entry; |
@@ -3084,7 +2909,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
3084 | /* Finger is a friend. */ | 2909 | /* Finger is a friend. */ |
3085 | if (0 == finger_trail_length) | 2910 | if (0 == finger_trail_length) |
3086 | { | 2911 | { |
3087 | new_entry->trail_list[0].trail_id = trail_id; | 2912 | new_entry->trail_list[0].trail_id = *trail_id; |
3088 | new_entry->trails_count = 1; | 2913 | new_entry->trails_count = 1; |
3089 | new_entry->trail_list[0].is_present = GNUNET_YES; | 2914 | new_entry->trail_list[0].is_present = GNUNET_YES; |
3090 | new_entry->trail_list[0].trail_length = 0; | 2915 | new_entry->trail_list[0].trail_length = 0; |
@@ -3093,8 +2918,8 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
3093 | finger_table[finger_table_index] = *new_entry; | 2918 | finger_table[finger_table_index] = *new_entry; |
3094 | GNUNET_assert (NULL != | 2919 | GNUNET_assert (NULL != |
3095 | (first_trail_hop = | 2920 | (first_trail_hop = |
3096 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2921 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3097 | &finger_identity))); | 2922 | finger_identity))); |
3098 | 2923 | ||
3099 | first_trail_hop->trails_count++; | 2924 | first_trail_hop->trails_count++; |
3100 | GNUNET_free (new_entry); | 2925 | GNUNET_free (new_entry); |
@@ -3102,9 +2927,9 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
3102 | } | 2927 | } |
3103 | 2928 | ||
3104 | GNUNET_assert (NULL != | 2929 | GNUNET_assert (NULL != |
3105 | (first_trail_hop = | 2930 | (first_trail_hop = |
3106 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2931 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3107 | &finger_trail[0]))); | 2932 | &finger_trail[0]))); |
3108 | new_entry->trails_count = 1; | 2933 | new_entry->trails_count = 1; |
3109 | first_trail_hop->trails_count++; | 2934 | first_trail_hop->trails_count++; |
3110 | /* Copy the finger trail into trail. */ | 2935 | /* Copy the finger trail into trail. */ |
@@ -3123,7 +2948,7 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity, | |||
3123 | 2948 | ||
3124 | /* Add trail to trail list. */ | 2949 | /* Add trail to trail list. */ |
3125 | trail->trail_length = finger_trail_length; | 2950 | trail->trail_length = finger_trail_length; |
3126 | trail->trail_id = trail_id; | 2951 | trail->trail_id = *trail_id; |
3127 | trail->is_present = GNUNET_YES; | 2952 | trail->is_present = GNUNET_YES; |
3128 | finger_table[finger_table_index] = *new_entry; | 2953 | finger_table[finger_table_index] = *new_entry; |
3129 | GNUNET_free (new_entry); | 2954 | GNUNET_free (new_entry); |
@@ -3141,7 +2966,6 @@ static void | |||
3141 | send_verify_successor_message (void *cls) | 2966 | send_verify_successor_message (void *cls) |
3142 | { | 2967 | { |
3143 | struct FriendInfo *target_friend; | 2968 | struct FriendInfo *target_friend; |
3144 | struct GNUNET_HashCode trail_id; | ||
3145 | struct Trail *trail; | 2969 | struct Trail *trail; |
3146 | struct Trail_Element *element; | 2970 | struct Trail_Element *element; |
3147 | unsigned int trail_length; | 2971 | unsigned int trail_length; |
@@ -3186,7 +3010,7 @@ send_verify_successor_message (void *cls) | |||
3186 | } | 3010 | } |
3187 | 3011 | ||
3188 | struct VerifySuccessorContext *ctx; | 3012 | struct VerifySuccessorContext *ctx; |
3189 | ctx = GNUNET_new(struct VerifySuccessorContext); | 3013 | ctx = GNUNET_new (struct VerifySuccessorContext); |
3190 | 3014 | ||
3191 | ctx->num_retries_scheduled++; | 3015 | ctx->num_retries_scheduled++; |
3192 | send_verify_successor_retry_task = | 3016 | send_verify_successor_retry_task = |
@@ -3211,7 +3035,7 @@ send_verify_successor_message (void *cls) | |||
3211 | for (i = 0; i < successor->trails_count; i++) | 3035 | for (i = 0; i < successor->trails_count; i++) |
3212 | { | 3036 | { |
3213 | trail = &successor->trail_list[i]; | 3037 | trail = &successor->trail_list[i]; |
3214 | if(GNUNET_YES == trail->is_present) | 3038 | if (GNUNET_YES == trail->is_present) |
3215 | break; | 3039 | break; |
3216 | } | 3040 | } |
3217 | 3041 | ||
@@ -3223,13 +3047,13 @@ send_verify_successor_message (void *cls) | |||
3223 | &successor->finger_identity)); | 3047 | &successor->finger_identity)); |
3224 | /* Trail stored at this index. */ | 3048 | /* Trail stored at this index. */ |
3225 | GNUNET_assert (GNUNET_YES == trail->is_present); | 3049 | GNUNET_assert (GNUNET_YES == trail->is_present); |
3226 | trail_id = trail->trail_id; | 3050 | if (NULL == GDS_ROUTING_get_next_hop (&trail->trail_id, |
3227 | if (NULL == GDS_ROUTING_get_next_hop(trail_id,GDS_ROUTING_SRC_TO_DEST)) | 3051 | GDS_ROUTING_SRC_TO_DEST)) |
3228 | { | 3052 | { |
3229 | DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line %u", | 3053 | DEBUG (" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line %u", |
3230 | GNUNET_i2s (&my_identity), | 3054 | GNUNET_i2s (&my_identity), |
3231 | GNUNET_h2s (&trail->trail_id), | 3055 | GNUNET_h2s (&trail->trail_id), |
3232 | __LINE__); | 3056 | __LINE__); |
3233 | GNUNET_break(0); | 3057 | GNUNET_break(0); |
3234 | return; | 3058 | return; |
3235 | } | 3059 | } |
@@ -3238,6 +3062,7 @@ send_verify_successor_message (void *cls) | |||
3238 | { | 3062 | { |
3239 | /* Copy the trail into peer list. */ | 3063 | /* Copy the trail into peer list. */ |
3240 | struct GNUNET_PeerIdentity peer_list[trail_length]; | 3064 | struct GNUNET_PeerIdentity peer_list[trail_length]; |
3065 | |||
3241 | element = trail->trail_head; | 3066 | element = trail->trail_head; |
3242 | for(i = 0; i < trail_length; i++) | 3067 | for(i = 0; i < trail_length; i++) |
3243 | { | 3068 | { |
@@ -3247,9 +3072,11 @@ send_verify_successor_message (void *cls) | |||
3247 | GNUNET_assert (NULL != (target_friend = | 3072 | GNUNET_assert (NULL != (target_friend = |
3248 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3073 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3249 | &peer_list[0]))); | 3074 | &peer_list[0]))); |
3250 | GDS_NEIGHBOURS_send_verify_successor_message (my_identity, | 3075 | GDS_NEIGHBOURS_send_verify_successor_message (&my_identity, |
3251 | successor->finger_identity, | 3076 | &successor->finger_identity, |
3252 | trail_id, peer_list, trail_length, | 3077 | &trail->trail_id, |
3078 | peer_list, | ||
3079 | trail_length, | ||
3253 | target_friend); | 3080 | target_friend); |
3254 | } | 3081 | } |
3255 | else | 3082 | else |
@@ -3257,9 +3084,11 @@ send_verify_successor_message (void *cls) | |||
3257 | GNUNET_assert (NULL != (target_friend = | 3084 | GNUNET_assert (NULL != (target_friend = |
3258 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 3085 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
3259 | &successor->finger_identity))); | 3086 | &successor->finger_identity))); |
3260 | GDS_NEIGHBOURS_send_verify_successor_message (my_identity, | 3087 | GDS_NEIGHBOURS_send_verify_successor_message (&my_identity, |
3261 | successor->finger_identity, | 3088 | &successor->finger_identity, |
3262 | trail_id, NULL, 0, | 3089 | &trail->trail_id, |
3090 | NULL, | ||
3091 | 0, | ||
3263 | target_friend); | 3092 | target_friend); |
3264 | } | 3093 | } |
3265 | } | 3094 | } |
@@ -3287,19 +3116,19 @@ update_current_search_finger_index (unsigned int finger_table_index) | |||
3287 | if (0 == current_search_finger_index) | 3116 | if (0 == current_search_finger_index) |
3288 | { | 3117 | { |
3289 | current_search_finger_index = PREDECESSOR_FINGER_ID; | 3118 | current_search_finger_index = PREDECESSOR_FINGER_ID; |
3290 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &successor->finger_identity)) | 3119 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
3120 | &successor->finger_identity)) | ||
3291 | { | 3121 | { |
3292 | if (NULL == send_verify_successor_task) | 3122 | if (NULL == send_verify_successor_task) |
3293 | { | 3123 | { |
3294 | send_verify_successor_task = | 3124 | send_verify_successor_task |
3295 | GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); | 3125 | = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, |
3126 | NULL); | ||
3296 | } | 3127 | } |
3297 | } | 3128 | } |
3298 | return; | 3129 | return; |
3299 | } | 3130 | } |
3300 | 3131 | current_search_finger_index--; | |
3301 | current_search_finger_index = current_search_finger_index - 1; | ||
3302 | return; | ||
3303 | } | 3132 | } |
3304 | 3133 | ||
3305 | 3134 | ||
@@ -3426,15 +3255,15 @@ remove_existing_finger (struct FingerInfo *existing_finger, | |||
3426 | * @param finger_trail_id Unique identifier of @finger_trail. | 3255 | * @param finger_trail_id Unique identifier of @finger_trail. |
3427 | */ | 3256 | */ |
3428 | static void | 3257 | static void |
3429 | finger_table_add (struct GNUNET_PeerIdentity finger_identity, | 3258 | finger_table_add (const struct GNUNET_PeerIdentity *finger_identity, |
3430 | const struct GNUNET_PeerIdentity *finger_trail, | 3259 | const struct GNUNET_PeerIdentity *finger_trail, |
3431 | unsigned int finger_trail_length, | 3260 | unsigned int finger_trail_length, |
3432 | unsigned int is_predecessor, | 3261 | unsigned int is_predecessor, |
3433 | uint64_t finger_value, | 3262 | uint64_t finger_value, |
3434 | struct GNUNET_HashCode finger_trail_id) | 3263 | const struct GNUNET_HashCode *finger_trail_id) |
3435 | { | 3264 | { |
3436 | struct FingerInfo *existing_finger; | 3265 | struct FingerInfo *existing_finger; |
3437 | struct GNUNET_PeerIdentity closest_peer; | 3266 | const struct GNUNET_PeerIdentity *closest_peer; |
3438 | struct FingerInfo *successor; | 3267 | struct FingerInfo *successor; |
3439 | unsigned int finger_table_index; | 3268 | unsigned int finger_table_index; |
3440 | 3269 | ||
@@ -3458,7 +3287,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3458 | GNUNET_break (0); //ASSERTION FAILS HERE. FIXME | 3287 | GNUNET_break (0); //ASSERTION FAILS HERE. FIXME |
3459 | return; | 3288 | return; |
3460 | } | 3289 | } |
3461 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | 3290 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (finger_identity, |
3462 | &successor->finger_identity)) | 3291 | &successor->finger_identity)) |
3463 | { | 3292 | { |
3464 | if (0 == fingers_round_count) | 3293 | if (0 == fingers_round_count) |
@@ -3479,7 +3308,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3479 | 3308 | ||
3480 | struct FingerInfo prev_finger; | 3309 | struct FingerInfo prev_finger; |
3481 | prev_finger = finger_table[finger_table_index - 1]; | 3310 | prev_finger = finger_table[finger_table_index - 1]; |
3482 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | 3311 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (finger_identity, |
3483 | &prev_finger.finger_identity)) | 3312 | &prev_finger.finger_identity)) |
3484 | { | 3313 | { |
3485 | current_search_finger_index--; | 3314 | current_search_finger_index--; |
@@ -3493,51 +3322,59 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3493 | /* No entry present in finger_table for given finger map index. */ | 3322 | /* No entry present in finger_table for given finger map index. */ |
3494 | if (GNUNET_NO == existing_finger->is_present) | 3323 | if (GNUNET_NO == existing_finger->is_present) |
3495 | { | 3324 | { |
3496 | /* Shorten the trail if possible. */ | 3325 | /* Shorten the trail if possible. */ |
3497 | add_new_finger (finger_identity, finger_trail, | 3326 | add_new_finger (finger_identity, |
3327 | finger_trail, | ||
3498 | finger_trail_length, | 3328 | finger_trail_length, |
3499 | finger_trail_id, finger_table_index); | 3329 | finger_trail_id, |
3330 | finger_table_index); | ||
3500 | update_current_search_finger_index (finger_table_index); | 3331 | update_current_search_finger_index (finger_table_index); |
3501 | return; | 3332 | return; |
3502 | } | 3333 | } |
3503 | 3334 | ||
3504 | /* If existing entry and finger identity are not same. */ | 3335 | /* If existing entry and finger identity are not same. */ |
3505 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), | 3336 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&existing_finger->finger_identity, |
3506 | &finger_identity)) | 3337 | finger_identity)) |
3507 | { | 3338 | { |
3508 | closest_peer = select_closest_peer (&existing_finger->finger_identity, | 3339 | closest_peer = select_closest_peer (&existing_finger->finger_identity, |
3509 | &finger_identity, | 3340 | finger_identity, |
3510 | finger_value, | 3341 | finger_value, |
3511 | is_predecessor); | 3342 | is_predecessor); |
3512 | 3343 | ||
3513 | /* If the new finger is the closest peer. */ | 3344 | /* If the new finger is the closest peer. */ |
3514 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &closest_peer)) | 3345 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (finger_identity, |
3346 | closest_peer)) | ||
3515 | { | 3347 | { |
3516 | remove_existing_finger (existing_finger, finger_table_index); | 3348 | remove_existing_finger (existing_finger, |
3517 | add_new_finger (finger_identity, finger_trail, finger_trail_length, | 3349 | finger_table_index); |
3518 | finger_trail_id, finger_table_index); | 3350 | add_new_finger (finger_identity, |
3351 | finger_trail, | ||
3352 | finger_trail_length, | ||
3353 | finger_trail_id, | ||
3354 | finger_table_index); | ||
3519 | } | 3355 | } |
3520 | else | 3356 | else |
3521 | { | 3357 | { |
3522 | /* Existing finger is the closest one. We need to send trail teardown | 3358 | /* Existing finger is the closest one. We need to send trail teardown |
3523 | across the trail setup in routing table of all the peers. */ | 3359 | across the trail setup in routing table of all the peers. */ |
3524 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &my_identity)) | 3360 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (finger_identity, |
3361 | &my_identity)) | ||
3525 | { | 3362 | { |
3526 | if (finger_trail_length > 0) | 3363 | if (finger_trail_length > 0) |
3527 | GDS_NEIGHBOURS_send_trail_teardown (&finger_trail_id, | 3364 | GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id, |
3528 | GDS_ROUTING_SRC_TO_DEST, | 3365 | GDS_ROUTING_SRC_TO_DEST, |
3529 | &finger_trail[0]); | 3366 | &finger_trail[0]); |
3530 | else | 3367 | else |
3531 | GDS_NEIGHBOURS_send_trail_teardown (&finger_trail_id, | 3368 | GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id, |
3532 | GDS_ROUTING_SRC_TO_DEST, | 3369 | GDS_ROUTING_SRC_TO_DEST, |
3533 | &finger_identity); | 3370 | finger_identity); |
3534 | } | 3371 | } |
3535 | } | 3372 | } |
3536 | } | 3373 | } |
3537 | else | 3374 | else |
3538 | { | 3375 | { |
3539 | /* If both new and existing entry are same as my_identity, then do nothing. */ | 3376 | /* If both new and existing entry are same as my_identity, then do nothing. */ |
3540 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity), | 3377 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&existing_finger->finger_identity, |
3541 | &my_identity)) | 3378 | &my_identity)) |
3542 | { | 3379 | { |
3543 | return; | 3380 | return; |
@@ -3545,11 +3382,15 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3545 | 3382 | ||
3546 | /* If there is space to store more trails. */ | 3383 | /* If there is space to store more trails. */ |
3547 | if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) | 3384 | if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) |
3548 | add_new_trail (existing_finger, finger_trail, | 3385 | add_new_trail (existing_finger, |
3549 | finger_trail_length, finger_trail_id); | 3386 | finger_trail, |
3387 | finger_trail_length, | ||
3388 | finger_trail_id); | ||
3550 | else | 3389 | else |
3551 | select_and_replace_trail (existing_finger, finger_trail, | 3390 | select_and_replace_trail (existing_finger, |
3552 | finger_trail_length, finger_trail_id); | 3391 | finger_trail, |
3392 | finger_trail_length, | ||
3393 | finger_trail_id); | ||
3553 | } | 3394 | } |
3554 | update_current_search_finger_index (finger_table_index); | 3395 | update_current_search_finger_index (finger_table_index); |
3555 | return; | 3396 | return; |
@@ -3557,55 +3398,66 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3557 | 3398 | ||
3558 | 3399 | ||
3559 | /** | 3400 | /** |
3560 | * Core handler for P2P put messages. | 3401 | * Verify validity of P2P put messages. |
3402 | * | ||
3561 | * @param cls closure | 3403 | * @param cls closure |
3562 | * @param peer sender of the request | 3404 | * @param put the message |
3563 | * @param message message | 3405 | * @return #GNUNET_OK if the message is well-formed |
3564 | * @return #GNUNET_OK to keep the connection open, | ||
3565 | * #GNUNET_SYSERR to close it (signal serious error) | ||
3566 | */ | 3406 | */ |
3567 | static int | 3407 | static int |
3568 | handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | 3408 | check_dht_p2p_put (void *cls, |
3569 | const struct GNUNET_MessageHeader *message) | 3409 | const struct PeerPutMessage *put) |
3570 | { | 3410 | { |
3571 | struct PeerPutMessage *put; | 3411 | size_t msize; |
3412 | uint32_t putlen; | ||
3413 | |||
3414 | msize = ntohs (put->header.size); | ||
3415 | putlen = ntohl (put->put_path_length); | ||
3416 | if ((msize < | ||
3417 | sizeof (struct PeerPutMessage) + | ||
3418 | putlen * sizeof (struct GNUNET_PeerIdentity)) || | ||
3419 | (putlen > | ||
3420 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | ||
3421 | { | ||
3422 | GNUNET_break_op (0); | ||
3423 | return GNUNET_SYSERR; | ||
3424 | } | ||
3425 | return GNUNET_OK; | ||
3426 | } | ||
3427 | |||
3428 | |||
3429 | /** | ||
3430 | * Core handler for P2P put messages. | ||
3431 | * | ||
3432 | * @param cls closure | ||
3433 | * @param put the message | ||
3434 | */ | ||
3435 | static void | ||
3436 | handle_dht_p2p_put (void *cls, | ||
3437 | const struct PeerPutMessage *put) | ||
3438 | { | ||
3572 | struct GNUNET_PeerIdentity *put_path; | 3439 | struct GNUNET_PeerIdentity *put_path; |
3573 | struct GNUNET_PeerIdentity current_best_known_dest; | 3440 | struct GNUNET_PeerIdentity current_best_known_dest; |
3574 | struct GNUNET_PeerIdentity best_known_dest; | 3441 | struct GNUNET_PeerIdentity best_known_dest; |
3575 | struct GNUNET_HashCode received_intermediate_trail_id; | 3442 | struct GNUNET_HashCode received_intermediate_trail_id; |
3576 | struct GNUNET_HashCode intermediate_trail_id; | 3443 | struct GNUNET_HashCode intermediate_trail_id; |
3577 | struct GNUNET_PeerIdentity next_hop; | 3444 | struct GNUNET_PeerIdentity next_hop; |
3578 | struct GNUNET_PeerIdentity *next_routing_hop; | 3445 | const struct GNUNET_PeerIdentity *next_routing_hop; |
3579 | enum GNUNET_DHT_RouteOption options; | 3446 | enum GNUNET_DHT_RouteOption options; |
3580 | struct GNUNET_HashCode test_key; | 3447 | struct GNUNET_HashCode test_key; |
3448 | struct Closest_Peer successor; | ||
3581 | void *payload; | 3449 | void *payload; |
3582 | size_t msize; | 3450 | size_t msize; |
3583 | uint32_t putlen; | 3451 | uint32_t putlen = ntohl (put->put_path_length); |
3452 | struct GNUNET_PeerIdentity pp[putlen + 1]; | ||
3584 | uint32_t hop_count; | 3453 | uint32_t hop_count; |
3585 | size_t payload_size; | 3454 | size_t payload_size; |
3586 | uint64_t key_value; | 3455 | uint64_t key_value; |
3587 | 3456 | ||
3588 | msize = ntohs (message->size); | 3457 | msize = ntohs (put->header.size); |
3589 | if (msize < sizeof (struct PeerPutMessage)) | ||
3590 | { | ||
3591 | GNUNET_break_op (0); | ||
3592 | return GNUNET_OK; | ||
3593 | } | ||
3594 | |||
3595 | put = (struct PeerPutMessage *) message; | ||
3596 | putlen = ntohl (put->put_path_length); | ||
3597 | if ((msize < | ||
3598 | sizeof (struct PeerPutMessage) + | ||
3599 | putlen * sizeof (struct GNUNET_PeerIdentity)) || | ||
3600 | (putlen > | ||
3601 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | ||
3602 | { | ||
3603 | GNUNET_break_op (0); | ||
3604 | return GNUNET_OK; | ||
3605 | } | ||
3606 | GNUNET_STATISTICS_update (GDS_stats, | 3458 | GNUNET_STATISTICS_update (GDS_stats, |
3607 | gettext_noop | 3459 | gettext_noop ("# Bytes received from other peers"), |
3608 | ("# Bytes received from other peers"), (int64_t) msize, | 3460 | (int64_t) msize, |
3609 | GNUNET_NO); | 3461 | GNUNET_NO); |
3610 | 3462 | ||
3611 | current_best_known_dest = put->best_known_destination; | 3463 | current_best_known_dest = put->best_known_destination; |
@@ -3617,30 +3469,36 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3617 | payload_size = msize - (sizeof (struct PeerPutMessage) + | 3469 | payload_size = msize - (sizeof (struct PeerPutMessage) + |
3618 | putlen * sizeof (struct GNUNET_PeerIdentity)); | 3470 | putlen * sizeof (struct GNUNET_PeerIdentity)); |
3619 | hop_count++; | 3471 | hop_count++; |
3620 | switch (GNUNET_BLOCK_get_key (GDS_block_context, ntohl (put->block_type), | 3472 | switch (GNUNET_BLOCK_get_key (GDS_block_context, |
3621 | payload, payload_size, &test_key)) | 3473 | ntohl (put->block_type), |
3474 | payload, | ||
3475 | payload_size, | ||
3476 | &test_key)) | ||
3622 | { | 3477 | { |
3623 | case GNUNET_YES: | 3478 | case GNUNET_YES: |
3624 | if (0 != memcmp (&test_key, &put->key, sizeof (struct GNUNET_HashCode))) | 3479 | if (0 != memcmp (&test_key, |
3480 | &put->key, | ||
3481 | sizeof (struct GNUNET_HashCode))) | ||
3625 | { | 3482 | { |
3626 | char *put_s = GNUNET_strdup (GNUNET_h2s_full (&put->key)); | 3483 | char *put_s = GNUNET_strdup (GNUNET_h2s_full (&put->key)); |
3627 | GNUNET_break_op (0); | 3484 | GNUNET_break_op (0); |
3628 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3485 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3629 | "PUT with key `%s' for block with key %s\n", | 3486 | "PUT with key `%s' for block with key %s\n", |
3630 | put_s, GNUNET_h2s_full (&test_key)); | 3487 | put_s, |
3488 | GNUNET_h2s_full (&test_key)); | ||
3631 | GNUNET_free (put_s); | 3489 | GNUNET_free (put_s); |
3632 | return GNUNET_OK; | 3490 | return; |
3633 | } | 3491 | } |
3634 | break; | 3492 | break; |
3635 | case GNUNET_NO: | 3493 | case GNUNET_NO: |
3636 | GNUNET_break_op (0); | 3494 | GNUNET_break_op (0); |
3637 | return GNUNET_OK; | 3495 | return; |
3638 | case GNUNET_SYSERR: | 3496 | case GNUNET_SYSERR: |
3639 | /* cannot verify, good luck */ | 3497 | /* cannot verify, good luck */ |
3640 | break; | 3498 | break; |
3641 | } | 3499 | } |
3642 | 3500 | ||
3643 | if (ntohl (put->block_type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ | 3501 | if (ntohl (put->block_type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ |
3644 | { | 3502 | { |
3645 | switch (GNUNET_BLOCK_evaluate (GDS_block_context, | 3503 | switch (GNUNET_BLOCK_evaluate (GDS_block_context, |
3646 | ntohl (put->block_type), | 3504 | ntohl (put->block_type), |
@@ -3648,7 +3506,8 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3648 | NULL, /* query */ | 3506 | NULL, /* query */ |
3649 | NULL, 0, /* bloom filer */ | 3507 | NULL, 0, /* bloom filer */ |
3650 | NULL, 0, /* xquery */ | 3508 | NULL, 0, /* xquery */ |
3651 | payload, payload_size)) | 3509 | payload, |
3510 | payload_size)) | ||
3652 | { | 3511 | { |
3653 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 3512 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
3654 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 3513 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
@@ -3662,7 +3521,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3662 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 3521 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
3663 | default: | 3522 | default: |
3664 | GNUNET_break_op (0); | 3523 | GNUNET_break_op (0); |
3665 | return GNUNET_OK; | 3524 | return; |
3666 | } | 3525 | } |
3667 | } | 3526 | } |
3668 | 3527 | ||
@@ -3670,7 +3529,8 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3670 | unsigned int i; | 3529 | unsigned int i; |
3671 | for (i = 0; i < putlen; i++) | 3530 | for (i = 0; i < putlen; i++) |
3672 | { | 3531 | { |
3673 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &put_path[i])) | 3532 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
3533 | &put_path[i])) | ||
3674 | { | 3534 | { |
3675 | putlen = i; | 3535 | putlen = i; |
3676 | break; | 3536 | break; |
@@ -3678,19 +3538,22 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3678 | } | 3538 | } |
3679 | 3539 | ||
3680 | /* Add yourself to the list. */ | 3540 | /* Add yourself to the list. */ |
3681 | struct GNUNET_PeerIdentity pp[putlen + 1]; | ||
3682 | //if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 3541 | //if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) |
3683 | if (1) | 3542 | if (1) |
3684 | { | 3543 | { |
3685 | GNUNET_memcpy (pp, put_path, putlen * sizeof (struct GNUNET_PeerIdentity)); | 3544 | GNUNET_memcpy (pp, |
3545 | put_path, | ||
3546 | putlen * sizeof (struct GNUNET_PeerIdentity)); | ||
3686 | pp[putlen] = my_identity; | 3547 | pp[putlen] = my_identity; |
3687 | putlen++; | 3548 | putlen++; |
3688 | } | 3549 | } |
3689 | else | 3550 | else |
3551 | { | ||
3690 | putlen = 0; | 3552 | putlen = 0; |
3691 | 3553 | } | |
3692 | GNUNET_memcpy (&key_value, &(put->key), sizeof (uint64_t)); | 3554 | GNUNET_memcpy (&key_value, |
3693 | struct Closest_Peer successor; | 3555 | &put->key, |
3556 | sizeof (uint64_t)); | ||
3694 | key_value = GNUNET_ntohll (key_value); | 3557 | key_value = GNUNET_ntohll (key_value); |
3695 | successor = find_local_best_known_next_hop (key_value, | 3558 | successor = find_local_best_known_next_hop (key_value, |
3696 | GDS_FINGER_TYPE_NON_PREDECESSOR); | 3559 | GDS_FINGER_TYPE_NON_PREDECESSOR); |
@@ -3698,9 +3561,10 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3698 | intermediate_trail_id = successor.trail_id; | 3561 | intermediate_trail_id = successor.trail_id; |
3699 | best_known_dest = successor.best_known_destination; | 3562 | best_known_dest = successor.best_known_destination; |
3700 | 3563 | ||
3701 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_best_known_dest, &my_identity))) | 3564 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_best_known_dest, |
3565 | &my_identity))) | ||
3702 | { | 3566 | { |
3703 | next_routing_hop = GDS_ROUTING_get_next_hop (received_intermediate_trail_id, | 3567 | next_routing_hop = GDS_ROUTING_get_next_hop (&received_intermediate_trail_id, |
3704 | GDS_ROUTING_SRC_TO_DEST); | 3568 | GDS_ROUTING_SRC_TO_DEST); |
3705 | if (NULL != next_routing_hop) | 3569 | if (NULL != next_routing_hop) |
3706 | { | 3570 | { |
@@ -3714,27 +3578,68 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3714 | ntohl (put->block_type), | 3578 | ntohl (put->block_type), |
3715 | hop_count, | 3579 | hop_count, |
3716 | ntohl (put->desired_replication_level), | 3580 | ntohl (put->desired_replication_level), |
3717 | putlen, pp, | 3581 | putlen, |
3582 | pp, | ||
3718 | GNUNET_TIME_absolute_ntoh (put->expiration_time), | 3583 | GNUNET_TIME_absolute_ntoh (put->expiration_time), |
3719 | &put->key, | 3584 | &put->key, |
3720 | payload, | 3585 | payload, |
3721 | payload_size); | 3586 | payload_size); |
3722 | 3587 | ||
3723 | /* I am the final destination */ | 3588 | /* I am the final destination */ |
3724 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &best_known_dest)) | 3589 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
3590 | &best_known_dest)) | ||
3725 | { | 3591 | { |
3726 | DEBUG("\n PUT_REQUEST_SUCCESSFUL for key = %s",GNUNET_h2s(&put->key)); | 3592 | DEBUG ("\n PUT_REQUEST_SUCCESSFUL for key = %s", |
3593 | GNUNET_h2s(&put->key)); | ||
3727 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), | 3594 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), |
3728 | &(put->key),putlen, pp, ntohl (put->block_type), | 3595 | &put->key, |
3729 | payload_size, payload); | 3596 | putlen, |
3597 | pp, | ||
3598 | ntohl (put->block_type), | ||
3599 | payload_size, | ||
3600 | payload); | ||
3730 | } | 3601 | } |
3731 | GDS_NEIGHBOURS_send_put (&put->key, | 3602 | GDS_NEIGHBOURS_send_put (&put->key, |
3732 | ntohl (put->block_type),ntohl (put->options), | 3603 | ntohl (put->block_type), |
3604 | ntohl (put->options), | ||
3733 | ntohl (put->desired_replication_level), | 3605 | ntohl (put->desired_replication_level), |
3734 | best_known_dest, intermediate_trail_id, &next_hop, | 3606 | best_known_dest, |
3735 | hop_count, putlen, pp, | 3607 | intermediate_trail_id, |
3608 | &next_hop, | ||
3609 | hop_count, | ||
3610 | putlen, | ||
3611 | pp, | ||
3736 | GNUNET_TIME_absolute_ntoh (put->expiration_time), | 3612 | GNUNET_TIME_absolute_ntoh (put->expiration_time), |
3737 | payload, payload_size); | 3613 | payload, |
3614 | payload_size); | ||
3615 | } | ||
3616 | |||
3617 | |||
3618 | /** | ||
3619 | * Check integrity of @a get message. | ||
3620 | * | ||
3621 | * @param cls closure | ||
3622 | * @param get the message | ||
3623 | * @return #GNUNET_OK if @a get is well-formed | ||
3624 | */ | ||
3625 | static int | ||
3626 | check_dht_p2p_get (void *cls, | ||
3627 | const struct PeerGetMessage *get) | ||
3628 | { | ||
3629 | uint32_t get_length; | ||
3630 | size_t msize; | ||
3631 | |||
3632 | msize = ntohs (get->header.size); | ||
3633 | get_length = ntohl (get->get_path_length); | ||
3634 | if ((msize < | ||
3635 | sizeof (struct PeerGetMessage) + | ||
3636 | get_length * sizeof (struct GNUNET_PeerIdentity)) || | ||
3637 | (get_length > | ||
3638 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | ||
3639 | { | ||
3640 | GNUNET_break_op (0); | ||
3641 | return GNUNET_SYSERR; | ||
3642 | } | ||
3738 | return GNUNET_OK; | 3643 | return GNUNET_OK; |
3739 | } | 3644 | } |
3740 | 3645 | ||
@@ -3745,16 +3650,12 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3745 | * Core handler for p2p get requests. | 3650 | * Core handler for p2p get requests. |
3746 | * | 3651 | * |
3747 | * @param cls closure | 3652 | * @param cls closure |
3748 | * @param peer sender of the request | 3653 | * @param get the message |
3749 | * @param message message | ||
3750 | * @return #GNUNET_OK to keep the connection open, | ||
3751 | * #GNUNET_SYSERR to close it (signal serious error) | ||
3752 | */ | 3654 | */ |
3753 | static int | 3655 | static void |
3754 | handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | 3656 | handle_dht_p2p_get (void *cls, |
3755 | const struct GNUNET_MessageHeader *message) | 3657 | const struct PeerGetMessage *get) |
3756 | { | 3658 | { |
3757 | const struct PeerGetMessage *get; | ||
3758 | const struct GNUNET_PeerIdentity *get_path; | 3659 | const struct GNUNET_PeerIdentity *get_path; |
3759 | struct GNUNET_PeerIdentity best_known_dest; | 3660 | struct GNUNET_PeerIdentity best_known_dest; |
3760 | struct GNUNET_PeerIdentity current_best_known_dest; | 3661 | struct GNUNET_PeerIdentity current_best_known_dest; |
@@ -3762,51 +3663,33 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3762 | struct GNUNET_HashCode received_intermediate_trail_id; | 3663 | struct GNUNET_HashCode received_intermediate_trail_id; |
3763 | struct Closest_Peer successor; | 3664 | struct Closest_Peer successor; |
3764 | struct GNUNET_PeerIdentity next_hop; | 3665 | struct GNUNET_PeerIdentity next_hop; |
3765 | struct GNUNET_PeerIdentity *next_routing_hop; | 3666 | const struct GNUNET_PeerIdentity *next_routing_hop; |
3766 | uint32_t get_length; | 3667 | uint32_t get_length; |
3767 | uint64_t key_value; | 3668 | uint64_t key_value; |
3768 | uint32_t hop_count; | 3669 | uint32_t hop_count; |
3769 | size_t msize; | 3670 | size_t msize; |
3770 | 3671 | ||
3771 | msize = ntohs (message->size); | 3672 | msize = ntohs (get->header.size); |
3772 | if (msize < sizeof (struct PeerGetMessage)) | ||
3773 | { | ||
3774 | GNUNET_break_op (0); | ||
3775 | return GNUNET_YES; | ||
3776 | } | ||
3777 | |||
3778 | get = (const struct PeerGetMessage *)message; | ||
3779 | get_length = ntohl (get->get_path_length); | 3673 | get_length = ntohl (get->get_path_length); |
3780 | if ((msize < | ||
3781 | sizeof (struct PeerGetMessage) + | ||
3782 | get_length * sizeof (struct GNUNET_PeerIdentity)) || | ||
3783 | (get_length > | ||
3784 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | ||
3785 | { | ||
3786 | GNUNET_break_op (0); | ||
3787 | return GNUNET_YES; | ||
3788 | } | ||
3789 | |||
3790 | current_best_known_dest = get->best_known_destination; | 3674 | current_best_known_dest = get->best_known_destination; |
3791 | received_intermediate_trail_id = get->intermediate_trail_id; | 3675 | received_intermediate_trail_id = get->intermediate_trail_id; |
3792 | get_path = (const struct GNUNET_PeerIdentity *)&get[1]; | 3676 | get_path = (const struct GNUNET_PeerIdentity *) &get[1]; |
3793 | hop_count = get->hop_count; | 3677 | hop_count = get->hop_count; |
3794 | hop_count++; | 3678 | hop_count++; |
3795 | |||
3796 | |||
3797 | GNUNET_STATISTICS_update (GDS_stats, | 3679 | GNUNET_STATISTICS_update (GDS_stats, |
3798 | gettext_noop | 3680 | gettext_noop ("# Bytes received from other peers"), |
3799 | ("# Bytes received from other peers"), msize, | 3681 | msize, |
3800 | GNUNET_NO); | 3682 | GNUNET_NO); |
3801 | 3683 | GNUNET_memcpy (&key_value, | |
3802 | GNUNET_memcpy (&key_value, &(get->key), sizeof (uint64_t)); | 3684 | &get->key, |
3685 | sizeof (uint64_t)); | ||
3803 | key_value = GNUNET_ntohll (key_value); | 3686 | key_value = GNUNET_ntohll (key_value); |
3804 | 3687 | ||
3805 | /* Check if you are already a part of get path. */ | 3688 | /* Check if you are already a part of get path. */ |
3806 | unsigned int i; | 3689 | for (unsigned int i = 0; i < get_length; i++) |
3807 | for (i = 0; i < get_length; i++) | ||
3808 | { | 3690 | { |
3809 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &get_path[i])) | 3691 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
3692 | &get_path[i])) | ||
3810 | { | 3693 | { |
3811 | get_length = i; | 3694 | get_length = i; |
3812 | break; | 3695 | break; |
@@ -3815,24 +3698,30 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3815 | 3698 | ||
3816 | /* Add yourself in the get path. */ | 3699 | /* Add yourself in the get path. */ |
3817 | struct GNUNET_PeerIdentity gp[get_length + 1]; | 3700 | struct GNUNET_PeerIdentity gp[get_length + 1]; |
3818 | GNUNET_memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); | 3701 | GNUNET_memcpy (gp, |
3702 | get_path, | ||
3703 | get_length * sizeof (struct GNUNET_PeerIdentity)); | ||
3819 | gp[get_length] = my_identity; | 3704 | gp[get_length] = my_identity; |
3820 | get_length = get_length + 1; | 3705 | get_length = get_length + 1; |
3821 | GDS_CLIENTS_process_get (get->options, get->block_type, hop_count, | 3706 | GDS_CLIENTS_process_get (get->options, |
3822 | get->desired_replication_level, get->get_path_length, | 3707 | get->block_type, |
3823 | gp, &get->key); | 3708 | hop_count, |
3709 | get->desired_replication_level, | ||
3710 | get->get_path_length, | ||
3711 | gp, | ||
3712 | &get->key); | ||
3824 | 3713 | ||
3825 | 3714 | ||
3826 | successor = find_local_best_known_next_hop (key_value, | 3715 | successor = find_local_best_known_next_hop (key_value, |
3827 | GDS_FINGER_TYPE_NON_PREDECESSOR); | 3716 | GDS_FINGER_TYPE_NON_PREDECESSOR); |
3828 | next_hop = successor.next_hop; | 3717 | next_hop = successor.next_hop; |
3829 | best_known_dest = successor.best_known_destination; | 3718 | best_known_dest = successor.best_known_destination; |
3830 | intermediate_trail_id = successor.trail_id; | 3719 | intermediate_trail_id = successor.trail_id; |
3831 | /* I am not the final destination. I am part of trail to reach final dest. */ | 3720 | /* I am not the final destination. I am part of trail to reach final dest. */ |
3832 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_best_known_dest, &my_identity))) | 3721 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_best_known_dest, &my_identity))) |
3833 | { | 3722 | { |
3834 | next_routing_hop = GDS_ROUTING_get_next_hop (received_intermediate_trail_id, | 3723 | next_routing_hop = GDS_ROUTING_get_next_hop (&received_intermediate_trail_id, |
3835 | GDS_ROUTING_SRC_TO_DEST); | 3724 | GDS_ROUTING_SRC_TO_DEST); |
3836 | if (NULL != next_routing_hop) | 3725 | if (NULL != next_routing_hop) |
3837 | { | 3726 | { |
3838 | next_hop = *next_routing_hop; | 3727 | next_hop = *next_routing_hop; |
@@ -3842,66 +3731,72 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3842 | } | 3731 | } |
3843 | 3732 | ||
3844 | /* I am the final destination. */ | 3733 | /* I am the final destination. */ |
3845 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest)) | 3734 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
3735 | &best_known_dest)) | ||
3846 | { | 3736 | { |
3847 | if (1 == get_length) | 3737 | if (1 == get_length) |
3848 | { | 3738 | { |
3849 | DEBUG("\n GET_REQUEST DONE for key = %s",GNUNET_h2s(&get->key)); | 3739 | DEBUG ("\n GET_REQUEST DONE for key = %s", |
3850 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, | 3740 | GNUNET_h2s(&get->key)); |
3851 | NULL, 0, 1, &my_identity, NULL,&my_identity); | 3741 | GDS_DATACACHE_handle_get (&get->key, |
3742 | get->block_type, /* FIXME: endianess? */ | ||
3743 | NULL, | ||
3744 | 0, | ||
3745 | NULL, | ||
3746 | 0, | ||
3747 | 1, | ||
3748 | &my_identity, | ||
3749 | NULL, | ||
3750 | &my_identity); | ||
3852 | } | 3751 | } |
3853 | else | 3752 | else |
3854 | { | 3753 | { |
3855 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, | 3754 | GDS_DATACACHE_handle_get (&get->key, |
3856 | get_length, gp, &gp[get_length - 2], | 3755 | get->block_type, /* FIXME: endianess? */ |
3756 | NULL, | ||
3757 | 0, | ||
3758 | NULL, | ||
3759 | 0, | ||
3760 | get_length, | ||
3761 | gp, | ||
3762 | &gp[get_length - 2], | ||
3857 | &my_identity); | 3763 | &my_identity); |
3858 | } | 3764 | } |
3859 | } | 3765 | } |
3860 | else | 3766 | else |
3861 | { | 3767 | { |
3862 | 3768 | GDS_NEIGHBOURS_send_get (&get->key, | |
3863 | GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options, | 3769 | get->block_type, /* FIXME: endianess? */ |
3864 | get->desired_replication_level, best_known_dest, | 3770 | get->options, |
3865 | intermediate_trail_id, &next_hop, hop_count, | 3771 | get->desired_replication_level, |
3866 | get_length, gp); | 3772 | &best_known_dest, |
3773 | &intermediate_trail_id, | ||
3774 | &next_hop, | ||
3775 | hop_count, | ||
3776 | get_length, | ||
3777 | gp); | ||
3867 | } | 3778 | } |
3868 | return GNUNET_YES; | ||
3869 | } | 3779 | } |
3870 | 3780 | ||
3871 | 3781 | ||
3872 | /** | 3782 | /** |
3873 | * Core handler for get result | 3783 | * Check validity of @a get_result message. |
3784 | * | ||
3874 | * @param cls closure | 3785 | * @param cls closure |
3875 | * @param peer sender of the request | 3786 | * @param get_result the message |
3876 | * @param message message | 3787 | * @return #GNUNET_OK if @a get_result is well-formed |
3877 | * @return #GNUNET_OK to keep the connection open, | ||
3878 | * #GNUNET_SYSERR to close it (signal serious error) | ||
3879 | */ | 3788 | */ |
3880 | static int | 3789 | static int |
3881 | handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | 3790 | check_dht_p2p_get_result (void *cls, |
3882 | const struct GNUNET_MessageHeader *message) | 3791 | const struct PeerGetResultMessage *get_result) |
3883 | { | 3792 | { |
3884 | const struct PeerGetResultMessage *get_result; | ||
3885 | const struct GNUNET_PeerIdentity *get_path; | ||
3886 | const struct GNUNET_PeerIdentity *put_path; | ||
3887 | const void *payload; | ||
3888 | size_t payload_size; | ||
3889 | size_t msize; | 3793 | size_t msize; |
3890 | unsigned int getlen; | 3794 | unsigned int getlen; |
3891 | unsigned int putlen; | 3795 | unsigned int putlen; |
3892 | int current_path_index; | ||
3893 | 3796 | ||
3894 | msize = ntohs (message->size); | 3797 | msize = ntohs (get_result->header.size); |
3895 | if (msize < sizeof (struct PeerGetResultMessage)) | ||
3896 | { | ||
3897 | GNUNET_break_op (0); | ||
3898 | return GNUNET_YES; | ||
3899 | } | ||
3900 | |||
3901 | get_result = (const struct PeerGetResultMessage *)message; | ||
3902 | getlen = ntohl (get_result->get_path_length); | 3798 | getlen = ntohl (get_result->get_path_length); |
3903 | putlen = ntohl (get_result->put_path_length); | 3799 | putlen = ntohl (get_result->put_path_length); |
3904 | |||
3905 | if ((msize < | 3800 | if ((msize < |
3906 | sizeof (struct PeerGetResultMessage) + | 3801 | sizeof (struct PeerGetResultMessage) + |
3907 | getlen * sizeof (struct GNUNET_PeerIdentity) + | 3802 | getlen * sizeof (struct GNUNET_PeerIdentity) + |
@@ -3912,52 +3807,85 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3912 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))) | 3807 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))) |
3913 | { | 3808 | { |
3914 | GNUNET_break_op (0); | 3809 | GNUNET_break_op (0); |
3915 | return GNUNET_YES; | 3810 | return GNUNET_SYSERR; |
3916 | } | 3811 | } |
3917 | DEBUG("GET_RESULT FOR DATA_SIZE = %lu\n",msize); | 3812 | return GNUNET_OK; |
3813 | } | ||
3814 | |||
3815 | |||
3816 | /** | ||
3817 | * Core handler for get result | ||
3818 | * | ||
3819 | * @param cls closure | ||
3820 | * @param get_result the message | ||
3821 | */ | ||
3822 | static void | ||
3823 | handle_dht_p2p_get_result (void *cls, | ||
3824 | const struct PeerGetResultMessage *get_result) | ||
3825 | { | ||
3826 | const struct GNUNET_PeerIdentity *get_path; | ||
3827 | const struct GNUNET_PeerIdentity *put_path; | ||
3828 | const void *payload; | ||
3829 | size_t payload_size; | ||
3830 | size_t msize; | ||
3831 | unsigned int getlen; | ||
3832 | unsigned int putlen; | ||
3833 | int current_path_index; | ||
3834 | |||
3835 | msize = ntohs (get_result->header.size); | ||
3836 | getlen = ntohl (get_result->get_path_length); | ||
3837 | putlen = ntohl (get_result->put_path_length); | ||
3838 | DEBUG ("GET_RESULT FOR DATA_SIZE = %u\n", | ||
3839 | (unsigned int) msize); | ||
3918 | GNUNET_STATISTICS_update (GDS_stats, | 3840 | GNUNET_STATISTICS_update (GDS_stats, |
3919 | gettext_noop | 3841 | gettext_noop ("# Bytes received from other peers"), |
3920 | ("# Bytes received from other peers"), msize, | 3842 | msize, |
3921 | GNUNET_NO); | 3843 | GNUNET_NO); |
3922 | |||
3923 | put_path = (const struct GNUNET_PeerIdentity *) &get_result[1]; | 3844 | put_path = (const struct GNUNET_PeerIdentity *) &get_result[1]; |
3924 | get_path = &put_path[putlen]; | 3845 | get_path = &put_path[putlen]; |
3925 | payload = (const void *) &get_path[getlen]; | 3846 | payload = (const void *) &get_path[getlen]; |
3926 | payload_size = msize - (sizeof (struct PeerGetResultMessage) + | 3847 | payload_size = msize - (sizeof (struct PeerGetResultMessage) + |
3927 | (getlen + putlen) * sizeof (struct GNUNET_PeerIdentity)); | 3848 | (getlen + putlen) * sizeof (struct GNUNET_PeerIdentity)); |
3928 | 3849 | ||
3929 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_path[0])))) | 3850 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
3851 | &get_path[0]))) | ||
3930 | { | 3852 | { |
3931 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (get_result->expiration_time), | 3853 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (get_result->expiration_time), |
3932 | &(get_result->key), | 3854 | &get_result->key, |
3933 | getlen, get_path, putlen, | 3855 | getlen, |
3934 | put_path, get_result->type, payload_size, payload); | 3856 | get_path, |
3935 | return GNUNET_YES; | 3857 | putlen, |
3858 | put_path, | ||
3859 | get_result->type, | ||
3860 | payload_size, | ||
3861 | payload); | ||
3862 | return; | ||
3936 | } | 3863 | } |
3937 | else | 3864 | current_path_index = search_my_index (get_path, |
3865 | getlen); | ||
3866 | if (-1 == current_path_index) | ||
3938 | { | 3867 | { |
3939 | current_path_index = search_my_index (get_path, getlen); | 3868 | DEBUG ("No entry found in get path.\n"); |
3940 | if (-1 == current_path_index ) | 3869 | GNUNET_break (0); |
3941 | { | 3870 | return; |
3942 | DEBUG ("No entry found in get path.\n"); | 3871 | } |
3943 | GNUNET_break (0); | 3872 | if ((getlen + 1) == current_path_index) |
3944 | return GNUNET_SYSERR; | 3873 | { |
3945 | } | 3874 | DEBUG("Present twice in get path. Not allowed. \n"); |
3946 | if((getlen + 1) == current_path_index) | 3875 | GNUNET_break (0); |
3947 | { | 3876 | return; |
3948 | DEBUG("Present twice in get path. Not allowed. \n"); | ||
3949 | GNUNET_break (0); | ||
3950 | return GNUNET_SYSERR; | ||
3951 | } | ||
3952 | GDS_NEIGHBOURS_send_get_result (&(get_result->key), get_result->type, | ||
3953 | &get_path[current_path_index - 1], | ||
3954 | &(get_result->querying_peer), putlen, put_path, | ||
3955 | getlen, get_path, | ||
3956 | GNUNET_TIME_absolute_ntoh (get_result->expiration_time), | ||
3957 | payload, payload_size); | ||
3958 | return GNUNET_YES; | ||
3959 | } | 3877 | } |
3960 | return GNUNET_SYSERR; | 3878 | GDS_NEIGHBOURS_send_get_result (&get_result->key, |
3879 | get_result->type, /* FIXME: endianess? */ | ||
3880 | &get_path[current_path_index - 1], | ||
3881 | &get_result->querying_peer, | ||
3882 | putlen, | ||
3883 | put_path, | ||
3884 | getlen, | ||
3885 | get_path, | ||
3886 | GNUNET_TIME_absolute_ntoh (get_result->expiration_time), | ||
3887 | payload, | ||
3888 | payload_size); | ||
3961 | } | 3889 | } |
3962 | 3890 | ||
3963 | 3891 | ||
@@ -3978,21 +3906,23 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3978 | */ | 3906 | */ |
3979 | static struct Closest_Peer | 3907 | static struct Closest_Peer |
3980 | get_local_best_known_next_hop (uint64_t final_dest_finger_val, | 3908 | get_local_best_known_next_hop (uint64_t final_dest_finger_val, |
3981 | struct GNUNET_HashCode intermediate_trail_id, | 3909 | const struct GNUNET_HashCode *intermediate_trail_id, |
3982 | unsigned int is_predecessor, | 3910 | unsigned int is_predecessor, |
3983 | struct GNUNET_PeerIdentity source, | 3911 | const struct GNUNET_PeerIdentity *source, |
3984 | struct GNUNET_PeerIdentity *current_dest) | 3912 | const struct GNUNET_PeerIdentity *current_dest) |
3985 | { | 3913 | { |
3986 | struct Closest_Peer peer; | 3914 | struct Closest_Peer peer; |
3987 | 3915 | ||
3988 | peer = find_local_best_known_next_hop (final_dest_finger_val, is_predecessor); | 3916 | peer = find_local_best_known_next_hop (final_dest_finger_val, |
3917 | is_predecessor); | ||
3989 | 3918 | ||
3990 | /* Am I just a part of a trail towards a finger (current_destination)? */ | 3919 | /* Am I just a part of a trail towards a finger (current_destination)? */ |
3991 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_dest) && | 3920 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
3921 | current_dest) && | ||
3992 | 0 != GNUNET_CRYPTO_cmp_peer_identity (&peer.best_known_destination, | 3922 | 0 != GNUNET_CRYPTO_cmp_peer_identity (&peer.best_known_destination, |
3993 | current_dest)) | 3923 | current_dest)) |
3994 | { | 3924 | { |
3995 | struct GNUNET_PeerIdentity closest_peer; | 3925 | const struct GNUNET_PeerIdentity *closest_peer; |
3996 | 3926 | ||
3997 | /* Select best successor among one found locally and current_destination | 3927 | /* Select best successor among one found locally and current_destination |
3998 | * that we got from network.*/ | 3928 | * that we got from network.*/ |
@@ -4002,9 +3932,10 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val, | |||
4002 | is_predecessor); | 3932 | is_predecessor); |
4003 | 3933 | ||
4004 | /* Is current dest (end point of the trail of which I am a part) closest_peer? */ | 3934 | /* Is current dest (end point of the trail of which I am a part) closest_peer? */ |
4005 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (current_dest, &closest_peer)) | 3935 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (current_dest, |
3936 | closest_peer)) | ||
4006 | { | 3937 | { |
4007 | struct GNUNET_PeerIdentity *next_hop; | 3938 | const struct GNUNET_PeerIdentity *next_hop; |
4008 | 3939 | ||
4009 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, | 3940 | next_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, |
4010 | GDS_ROUTING_SRC_TO_DEST); | 3941 | GDS_ROUTING_SRC_TO_DEST); |
@@ -4018,7 +3949,7 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val, | |||
4018 | { | 3949 | { |
4019 | peer.next_hop = *next_hop; | 3950 | peer.next_hop = *next_hop; |
4020 | peer.best_known_destination = *current_dest; | 3951 | peer.best_known_destination = *current_dest; |
4021 | peer.trail_id = intermediate_trail_id; | 3952 | peer.trail_id = *intermediate_trail_id; |
4022 | } | 3953 | } |
4023 | } | 3954 | } |
4024 | } | 3955 | } |
@@ -4026,18 +3957,41 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val, | |||
4026 | } | 3957 | } |
4027 | 3958 | ||
4028 | 3959 | ||
4029 | /* | 3960 | /** |
4030 | * Core handle for PeerTrailSetupMessage. | 3961 | * Check format of a PeerTrailSetupMessage. |
3962 | * | ||
4031 | * @param cls closure | 3963 | * @param cls closure |
4032 | * @param message message | 3964 | * @param trail_setup the message |
4033 | * @param peer peer identity this notification is about | 3965 | * @return #GNUNET_OK if @a trail_setup is well-formed |
4034 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
4035 | */ | 3966 | */ |
4036 | static int | 3967 | static int |
4037 | handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | 3968 | check_dht_p2p_trail_setup (void *cls, |
4038 | const struct GNUNET_MessageHeader *message) | 3969 | const struct PeerTrailSetupMessage *trail_setup) |
3970 | { | ||
3971 | size_t msize; | ||
3972 | |||
3973 | msize = ntohs (trail_setup->header.size); | ||
3974 | if ((msize - sizeof (struct PeerTrailSetupMessage)) % | ||
3975 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
3976 | { | ||
3977 | GNUNET_break_op (0); | ||
3978 | return GNUNET_SYSERR; | ||
3979 | } | ||
3980 | return GNUNET_OK; | ||
3981 | } | ||
3982 | |||
3983 | |||
3984 | /** | ||
3985 | * Core handle for PeerTrailSetupMessage. | ||
3986 | * | ||
3987 | * @param cls closure | ||
3988 | * @param trail_setup the message | ||
3989 | */ | ||
3990 | static void | ||
3991 | handle_dht_p2p_trail_setup (void *cls, | ||
3992 | const struct PeerTrailSetupMessage *trail_setup) | ||
4039 | { | 3993 | { |
4040 | const struct PeerTrailSetupMessage *trail_setup; | 3994 | struct FriendInfo *friend = cls; |
4041 | const struct GNUNET_PeerIdentity *trail_peer_list; | 3995 | const struct GNUNET_PeerIdentity *trail_peer_list; |
4042 | struct GNUNET_PeerIdentity current_dest; | 3996 | struct GNUNET_PeerIdentity current_dest; |
4043 | struct FriendInfo *target_friend; | 3997 | struct FriendInfo *target_friend; |
@@ -4050,55 +4004,44 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4050 | int i; | 4004 | int i; |
4051 | size_t msize; | 4005 | size_t msize; |
4052 | 4006 | ||
4053 | msize = ntohs (message->size); | 4007 | msize = ntohs (trail_setup->header.size); |
4054 | if (msize < sizeof (struct PeerTrailSetupMessage)) | ||
4055 | { | ||
4056 | GNUNET_break_op (0); | ||
4057 | return GNUNET_SYSERR; | ||
4058 | } | ||
4059 | |||
4060 | trail_setup = (const struct PeerTrailSetupMessage *) message; | ||
4061 | if ((msize - sizeof (struct PeerTrailSetupMessage)) % | ||
4062 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
4063 | { | ||
4064 | GNUNET_break_op (0); | ||
4065 | return GNUNET_OK; | ||
4066 | } | ||
4067 | trail_length = (msize - sizeof (struct PeerTrailSetupMessage))/ | 4008 | trail_length = (msize - sizeof (struct PeerTrailSetupMessage))/ |
4068 | sizeof (struct GNUNET_PeerIdentity); | 4009 | sizeof (struct GNUNET_PeerIdentity); |
4069 | |||
4070 | GNUNET_STATISTICS_update (GDS_stats, | 4010 | GNUNET_STATISTICS_update (GDS_stats, |
4071 | gettext_noop | 4011 | gettext_noop ("# Bytes received from other peers"), |
4072 | ("# Bytes received from other peers"), msize, | 4012 | msize, |
4073 | GNUNET_NO); | 4013 | GNUNET_NO); |
4074 | 4014 | trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_setup[1]; | |
4075 | trail_peer_list = (const struct GNUNET_PeerIdentity *)&trail_setup[1]; | ||
4076 | current_dest = trail_setup->best_known_destination; | 4015 | current_dest = trail_setup->best_known_destination; |
4077 | trail_id = trail_setup->trail_id; | 4016 | trail_id = trail_setup->trail_id; |
4078 | final_dest_finger_val = | 4017 | final_dest_finger_val |
4079 | GNUNET_ntohll (trail_setup->final_destination_finger_value); | 4018 | = GNUNET_ntohll (trail_setup->final_destination_finger_value); |
4080 | source = trail_setup->source_peer; | 4019 | source = trail_setup->source_peer; |
4081 | is_predecessor = ntohl (trail_setup->is_predecessor); | 4020 | is_predecessor = ntohl (trail_setup->is_predecessor); |
4082 | intermediate_trail_id = trail_setup->intermediate_trail_id; | 4021 | intermediate_trail_id = trail_setup->intermediate_trail_id; |
4083 | 4022 | ||
4084 | /* Did the friend insert its ID in the trail list? */ | 4023 | /* Did the friend insert its ID in the trail list? */ |
4085 | if (trail_length > 0 && | 4024 | if ( (trail_length > 0) && |
4086 | 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (struct GNUNET_PeerIdentity))) | 4025 | (0 != memcmp (&trail_peer_list[trail_length-1], |
4026 | friend->id, | ||
4027 | sizeof (struct GNUNET_PeerIdentity))) ) | ||
4087 | { | 4028 | { |
4088 | GNUNET_break_op (0); | 4029 | GNUNET_break_op (0); |
4089 | return GNUNET_SYSERR; | 4030 | return; |
4090 | } | 4031 | } |
4091 | 4032 | ||
4092 | /* If I was the source and got the message back, then set trail length to 0.*/ | 4033 | /* If I was the source and got the message back, then set trail length to 0.*/ |
4093 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) | 4034 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
4035 | &source)) | ||
4094 | { | 4036 | { |
4095 | trail_length = 0; | 4037 | trail_length = 0; |
4096 | } | 4038 | } |
4097 | 4039 | ||
4098 | /* Check if you are present in the trail seen so far? */ | 4040 | /* Check if you are present in the trail seen so far? */ |
4099 | for (i = 0; i < trail_length ; i++) | 4041 | for (i = 0; i < trail_length; i++) |
4100 | { | 4042 | { |
4101 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity)) | 4043 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[i], |
4044 | &my_identity)) | ||
4102 | { | 4045 | { |
4103 | /* We will add ourself later in code, if NOT destination. */ | 4046 | /* We will add ourself later in code, if NOT destination. */ |
4104 | trail_length = i; | 4047 | trail_length = i; |
@@ -4107,150 +4050,177 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4107 | } | 4050 | } |
4108 | 4051 | ||
4109 | /* Is my routing table full? */ | 4052 | /* Is my routing table full? */ |
4110 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) | 4053 | if (GNUNET_YES == GDS_ROUTING_threshold_reached ()) |
4111 | { | 4054 | { |
4112 | if (trail_length > 0) | 4055 | target_friend |
4113 | target_friend = | 4056 | = (trail_length > 0) |
4114 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4057 | ? GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4115 | &trail_peer_list[trail_length - 1]); | 4058 | &trail_peer_list[trail_length - 1]) |
4116 | else | 4059 | : GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4117 | target_friend = | 4060 | &source); |
4118 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4061 | if (NULL == target_friend) |
4119 | &source); | ||
4120 | if(NULL == target_friend) | ||
4121 | { | 4062 | { |
4122 | DEBUG ("\n friend not found"); | 4063 | DEBUG ("\n friend not found"); |
4123 | GNUNET_break(0); | 4064 | GNUNET_break(0); |
4124 | return GNUNET_OK; | 4065 | return; |
4125 | } | 4066 | } |
4126 | GDS_NEIGHBOURS_send_trail_rejection (source, final_dest_finger_val, | 4067 | GDS_NEIGHBOURS_send_trail_rejection (&source, |
4127 | my_identity, is_predecessor, | 4068 | final_dest_finger_val, |
4128 | trail_peer_list, trail_length, | 4069 | &my_identity, |
4129 | trail_id, target_friend, | 4070 | is_predecessor, |
4071 | trail_peer_list, | ||
4072 | trail_length, | ||
4073 | &trail_id, | ||
4074 | target_friend, | ||
4130 | CONGESTION_TIMEOUT); | 4075 | CONGESTION_TIMEOUT); |
4131 | return GNUNET_OK; | 4076 | return; |
4132 | } | 4077 | } |
4133 | 4078 | ||
4134 | /* Get the next hop to forward the trail setup request. */ | 4079 | /* Get the next hop to forward the trail setup request. */ |
4135 | struct Closest_Peer next_peer = | 4080 | struct Closest_Peer next_peer |
4136 | get_local_best_known_next_hop (final_dest_finger_val, | 4081 | = get_local_best_known_next_hop (final_dest_finger_val, |
4137 | intermediate_trail_id, | 4082 | &intermediate_trail_id, |
4138 | is_predecessor, | 4083 | is_predecessor, |
4139 | source, | 4084 | &source, |
4140 | ¤t_dest); | 4085 | ¤t_dest); |
4141 | 4086 | ||
4142 | /* Am I the final destination? */ | 4087 | /* Am I the final destination? */ |
4143 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&next_peer.best_known_destination, | 4088 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&next_peer.best_known_destination, |
4144 | &my_identity))) | 4089 | &my_identity)) |
4145 | { | 4090 | { |
4146 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&source, &my_identity)) | 4091 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&source, |
4092 | &my_identity)) | ||
4147 | { | 4093 | { |
4148 | finger_table_add (my_identity, NULL, 0, is_predecessor, | 4094 | finger_table_add (&my_identity, |
4149 | final_dest_finger_val, trail_id); | 4095 | NULL, |
4150 | return GNUNET_OK; | 4096 | 0, |
4097 | is_predecessor, | ||
4098 | final_dest_finger_val, | ||
4099 | &trail_id); | ||
4100 | return; | ||
4151 | } | 4101 | } |
4152 | 4102 | ||
4153 | if (trail_length > 0) | 4103 | target_friend |
4154 | target_friend = | 4104 | = (trail_length > 0) |
4155 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4105 | ? GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4156 | &trail_peer_list[trail_length-1]); | 4106 | &trail_peer_list[trail_length-1]) |
4157 | else | 4107 | : GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4158 | target_friend = | 4108 | &source); |
4159 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source); | ||
4160 | if (NULL == target_friend) | 4109 | if (NULL == target_friend) |
4161 | { | 4110 | { |
4162 | GNUNET_break_op (0); | 4111 | GNUNET_break_op (0); |
4163 | return GNUNET_SYSERR; | 4112 | return; |
4164 | } | 4113 | } |
4165 | GDS_ROUTING_add (trail_id, target_friend->id, my_identity); | 4114 | GDS_ROUTING_add (&trail_id, |
4166 | GDS_NEIGHBOURS_send_trail_setup_result (source, | 4115 | target_friend->id, |
4167 | my_identity, | 4116 | &my_identity); |
4168 | target_friend, trail_length, | 4117 | GDS_NEIGHBOURS_send_trail_setup_result (&source, |
4118 | &my_identity, | ||
4119 | target_friend, | ||
4120 | trail_length, | ||
4169 | trail_peer_list, | 4121 | trail_peer_list, |
4170 | is_predecessor, | 4122 | is_predecessor, |
4171 | final_dest_finger_val,trail_id); | 4123 | final_dest_finger_val, |
4124 | &trail_id); | ||
4125 | return; | ||
4172 | } | 4126 | } |
4173 | else /* I'm not the final destination. */ | 4127 | /* I'm not the final destination. */ |
4128 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
4129 | &next_peer.next_hop); | ||
4130 | if (NULL == target_friend) | ||
4174 | { | 4131 | { |
4175 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4132 | DEBUG ("\n target friend not found for peer = %s", |
4176 | &next_peer.next_hop); | 4133 | GNUNET_i2s(&next_peer.next_hop)); |
4177 | if(NULL == target_friend) | 4134 | GNUNET_break (0); |
4178 | { | 4135 | return; |
4179 | DEBUG ("\n target friend not found for peer = %s", GNUNET_i2s(&next_peer.next_hop)); | ||
4180 | GNUNET_break (0); | ||
4181 | return GNUNET_OK; | ||
4182 | } | ||
4183 | if (0 != GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) | ||
4184 | { | ||
4185 | /* Add yourself to list of peers. */ | ||
4186 | struct GNUNET_PeerIdentity peer_list[trail_length + 1]; | ||
4187 | |||
4188 | GNUNET_memcpy (peer_list, trail_peer_list, | ||
4189 | trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
4190 | peer_list[trail_length] = my_identity; | ||
4191 | GDS_NEIGHBOURS_send_trail_setup (source, | ||
4192 | final_dest_finger_val, | ||
4193 | next_peer.best_known_destination, | ||
4194 | target_friend, trail_length + 1, peer_list, | ||
4195 | is_predecessor, trail_id, | ||
4196 | next_peer.trail_id); | ||
4197 | } | ||
4198 | else | ||
4199 | GDS_NEIGHBOURS_send_trail_setup (source, | ||
4200 | final_dest_finger_val, | ||
4201 | next_peer.best_known_destination, | ||
4202 | target_friend, 0, NULL, | ||
4203 | is_predecessor, trail_id, | ||
4204 | next_peer.trail_id); | ||
4205 | } | 4136 | } |
4206 | return GNUNET_OK; | 4137 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
4138 | &source)) | ||
4139 | { | ||
4140 | /* Add yourself to list of peers. */ | ||
4141 | struct GNUNET_PeerIdentity peer_list[trail_length + 1]; | ||
4142 | |||
4143 | GNUNET_memcpy (peer_list, | ||
4144 | trail_peer_list, | ||
4145 | trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
4146 | peer_list[trail_length] = my_identity; | ||
4147 | GDS_NEIGHBOURS_send_trail_setup (&source, | ||
4148 | final_dest_finger_val, | ||
4149 | &next_peer.best_known_destination, | ||
4150 | target_friend, | ||
4151 | trail_length + 1, | ||
4152 | peer_list, | ||
4153 | is_predecessor, | ||
4154 | &trail_id, | ||
4155 | &next_peer.trail_id); | ||
4156 | return; | ||
4157 | } | ||
4158 | GDS_NEIGHBOURS_send_trail_setup (&source, | ||
4159 | final_dest_finger_val, | ||
4160 | &next_peer.best_known_destination, | ||
4161 | target_friend, | ||
4162 | 0, | ||
4163 | NULL, | ||
4164 | is_predecessor, | ||
4165 | &trail_id, | ||
4166 | &next_peer.trail_id); | ||
4207 | } | 4167 | } |
4208 | 4168 | ||
4209 | 4169 | ||
4210 | /** | 4170 | /** |
4211 | * Core handle for p2p trail setup result messages. | 4171 | * Validate format of trail setup result messages. |
4172 | * | ||
4212 | * @param closure | 4173 | * @param closure |
4213 | * @param message message | 4174 | * @param trail_result the message |
4214 | * @param peer sender of this message. | 4175 | * @return #GNUNET_OK if @a trail_result is well-formed |
4215 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
4216 | */ | 4176 | */ |
4217 | static int | 4177 | static int |
4218 | handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *peer, | 4178 | check_dht_p2p_trail_setup_result (void *cls, |
4219 | const struct GNUNET_MessageHeader *message) | 4179 | const struct PeerTrailSetupResultMessage *trail_result) |
4220 | { | 4180 | { |
4221 | const struct PeerTrailSetupResultMessage *trail_result; | 4181 | size_t msize; |
4182 | |||
4183 | msize = ntohs (trail_result->header.size); | ||
4184 | if ((msize - sizeof (struct PeerTrailSetupResultMessage)) % | ||
4185 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
4186 | { | ||
4187 | GNUNET_break_op (0); | ||
4188 | return GNUNET_SYSERR; | ||
4189 | } | ||
4190 | return GNUNET_OK; | ||
4191 | } | ||
4192 | |||
4193 | |||
4194 | /** | ||
4195 | * Core handle for p2p trail setup result messages. | ||
4196 | * | ||
4197 | * @param closure | ||
4198 | * @param trail_result the message | ||
4199 | */ | ||
4200 | static void | ||
4201 | handle_dht_p2p_trail_setup_result (void *cls, | ||
4202 | const struct PeerTrailSetupResultMessage *trail_result) | ||
4203 | { | ||
4204 | struct FriendInfo *friend = cls; | ||
4222 | const struct GNUNET_PeerIdentity *trail_peer_list; | 4205 | const struct GNUNET_PeerIdentity *trail_peer_list; |
4223 | struct GNUNET_PeerIdentity next_hop; | 4206 | struct GNUNET_PeerIdentity next_hop; |
4224 | struct FriendInfo *target_friend; | 4207 | struct FriendInfo *target_friend; |
4225 | struct GNUNET_PeerIdentity querying_peer; | 4208 | struct GNUNET_PeerIdentity querying_peer; |
4226 | struct GNUNET_PeerIdentity finger_identity; | 4209 | struct GNUNET_PeerIdentity finger_identity; |
4227 | uint32_t trail_length; | 4210 | uint32_t trail_length; |
4228 | uint64_t ulitmate_destination_finger_value; | 4211 | uint64_t ultimate_destination_finger_value; |
4229 | uint32_t is_predecessor; | 4212 | uint32_t is_predecessor; |
4230 | struct GNUNET_HashCode trail_id; | 4213 | struct GNUNET_HashCode trail_id; |
4231 | int my_index; | 4214 | int my_index; |
4232 | size_t msize; | 4215 | size_t msize; |
4233 | 4216 | ||
4234 | msize = ntohs (message->size); | 4217 | msize = ntohs (trail_result->header.size); |
4235 | if (msize < sizeof (struct PeerTrailSetupResultMessage)) | ||
4236 | { | ||
4237 | GNUNET_break_op (0); | ||
4238 | return GNUNET_YES; | ||
4239 | } | ||
4240 | |||
4241 | trail_result = (const struct PeerTrailSetupResultMessage *) message; | ||
4242 | if ((msize - sizeof (struct PeerTrailSetupResultMessage)) % | ||
4243 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
4244 | { | ||
4245 | GNUNET_break_op (0); | ||
4246 | return GNUNET_OK; | ||
4247 | } | ||
4248 | trail_length = (msize - sizeof (struct PeerTrailSetupResultMessage))/ | 4218 | trail_length = (msize - sizeof (struct PeerTrailSetupResultMessage))/ |
4249 | sizeof (struct GNUNET_PeerIdentity); | 4219 | sizeof (struct GNUNET_PeerIdentity); |
4250 | 4220 | ||
4251 | GNUNET_STATISTICS_update (GDS_stats, | 4221 | GNUNET_STATISTICS_update (GDS_stats, |
4252 | gettext_noop | 4222 | gettext_noop ("# Bytes received from other peers"), |
4253 | ("# Bytes received from other peers"), msize, | 4223 | msize, |
4254 | GNUNET_NO); | 4224 | GNUNET_NO); |
4255 | 4225 | ||
4256 | is_predecessor = ntohl (trail_result->is_predecessor); | 4226 | is_predecessor = ntohl (trail_result->is_predecessor); |
@@ -4258,89 +4228,103 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4258 | finger_identity = trail_result->finger_identity; | 4228 | finger_identity = trail_result->finger_identity; |
4259 | trail_id = trail_result->trail_id; | 4229 | trail_id = trail_result->trail_id; |
4260 | trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_result[1]; | 4230 | trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_result[1]; |
4261 | ulitmate_destination_finger_value = | 4231 | ultimate_destination_finger_value |
4262 | GNUNET_ntohll (trail_result->ulitmate_destination_finger_value); | 4232 | = GNUNET_ntohll (trail_result->ultimate_destination_finger_value); |
4263 | 4233 | ||
4264 | /* Am I the one who initiated the query? */ | 4234 | /* Am I the one who initiated the query? */ |
4265 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) | 4235 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, |
4236 | &my_identity))) | ||
4266 | { | 4237 | { |
4267 | /* Check that you got the message from the correct peer. */ | 4238 | /* Check that you got the message from the correct peer. */ |
4268 | if (trail_length > 0) | 4239 | if (trail_length > 0) |
4269 | { | 4240 | { |
4270 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[0], | 4241 | GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[0], |
4271 | peer)); | 4242 | friend->id)); |
4272 | } | 4243 | } |
4273 | else | 4244 | else |
4274 | { | 4245 | { |
4275 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | 4246 | GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, |
4276 | peer)); | 4247 | friend->id)); |
4277 | } | 4248 | } |
4278 | GDS_ROUTING_add (trail_id, my_identity, *peer); | 4249 | GDS_ROUTING_add (&trail_id, |
4279 | finger_table_add (finger_identity, trail_peer_list, trail_length, | 4250 | &my_identity, |
4280 | is_predecessor, ulitmate_destination_finger_value, trail_id); | 4251 | friend->id); |
4281 | return GNUNET_YES; | 4252 | finger_table_add (&finger_identity, |
4253 | trail_peer_list, | ||
4254 | trail_length, | ||
4255 | is_predecessor, | ||
4256 | ultimate_destination_finger_value, | ||
4257 | &trail_id); | ||
4258 | return; | ||
4282 | } | 4259 | } |
4283 | 4260 | ||
4284 | /* Get my location in the trail. */ | 4261 | /* Get my location in the trail. */ |
4285 | my_index = search_my_index (trail_peer_list, trail_length); | 4262 | my_index = search_my_index (trail_peer_list, |
4263 | trail_length); | ||
4286 | if (-1 == my_index) | 4264 | if (-1 == my_index) |
4287 | { | 4265 | { |
4288 | DEBUG ("Not found in trail\n"); | 4266 | DEBUG ("Not found in trail\n"); |
4289 | GNUNET_break_op(0); | 4267 | GNUNET_break_op(0); |
4290 | return GNUNET_SYSERR; | 4268 | return; |
4291 | } | 4269 | } |
4292 | //TODO; return -2. | 4270 | //TODO; return -2. |
4293 | if ((trail_length + 1) == my_index) | 4271 | if ((trail_length + 1) == my_index) |
4294 | { | 4272 | { |
4295 | DEBUG ("Found twice in trail.\n"); | 4273 | DEBUG ("Found twice in trail.\n"); |
4296 | GNUNET_break_op(0); | 4274 | GNUNET_break_op(0); |
4297 | return GNUNET_SYSERR; | 4275 | return; |
4298 | } | 4276 | } |
4299 | 4277 | ||
4300 | //TODO; Refactor code here and above to check if sender peer is correct | 4278 | //TODO; Refactor code here and above to check if sender peer is correct |
4301 | if (my_index == 0) | 4279 | if (my_index == 0) |
4302 | { | 4280 | { |
4303 | if(trail_length > 1) | 4281 | if (trail_length > 1) |
4304 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[1], | 4282 | GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[1], |
4305 | peer)); | 4283 | friend->id)); |
4306 | else | 4284 | else |
4307 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | 4285 | GNUNET_assert (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, |
4308 | peer)); | 4286 | friend->id)); |
4309 | next_hop = trail_result->querying_peer; | 4287 | next_hop = trail_result->querying_peer; |
4310 | } | 4288 | } |
4311 | else | 4289 | else |
4312 | { | 4290 | { |
4313 | if(my_index == trail_length - 1) | 4291 | if (my_index == trail_length - 1) |
4314 | { | 4292 | { |
4315 | GNUNET_assert(0 == | 4293 | GNUNET_assert (0 == |
4316 | GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | 4294 | GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, |
4317 | peer)); | 4295 | friend->id)); |
4318 | } | 4296 | } |
4319 | else | 4297 | else |
4320 | GNUNET_assert(0 == | 4298 | GNUNET_assert (0 == |
4321 | GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[my_index + 1], | 4299 | GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[my_index + 1], |
4322 | peer)); | 4300 | friend->id)); |
4323 | next_hop = trail_peer_list[my_index - 1]; | 4301 | next_hop = trail_peer_list[my_index - 1]; |
4324 | } | 4302 | } |
4325 | 4303 | ||
4326 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); | 4304 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4305 | &next_hop); | ||
4327 | if (NULL == target_friend) | 4306 | if (NULL == target_friend) |
4328 | { | 4307 | { |
4329 | GNUNET_break_op (0); | 4308 | GNUNET_break_op (0); |
4330 | return GNUNET_SYSERR; | 4309 | return; |
4331 | } | 4310 | } |
4332 | GDS_ROUTING_add (trail_id, next_hop, *peer); | 4311 | GDS_ROUTING_add (&trail_id, |
4333 | GDS_NEIGHBOURS_send_trail_setup_result (querying_peer, finger_identity, | 4312 | &next_hop, |
4334 | target_friend, trail_length, trail_peer_list, | 4313 | friend->id); |
4314 | GDS_NEIGHBOURS_send_trail_setup_result (&querying_peer, | ||
4315 | &finger_identity, | ||
4316 | target_friend, | ||
4317 | trail_length, | ||
4318 | trail_peer_list, | ||
4335 | is_predecessor, | 4319 | is_predecessor, |
4336 | ulitmate_destination_finger_value, | 4320 | ultimate_destination_finger_value, |
4337 | trail_id); | 4321 | &trail_id); |
4338 | return GNUNET_OK; | ||
4339 | } | 4322 | } |
4340 | 4323 | ||
4341 | 4324 | ||
4342 | /** | 4325 | /** |
4343 | * Invert the trail. | 4326 | * Invert the trail. |
4327 | * | ||
4344 | * @param trail Trail to be inverted | 4328 | * @param trail Trail to be inverted |
4345 | * @param trail_length Total number of peers in the trail. | 4329 | * @param trail_length Total number of peers in the trail. |
4346 | * @return Updated trail | 4330 | * @return Updated trail |
@@ -4353,8 +4337,8 @@ invert_trail (const struct GNUNET_PeerIdentity *trail, | |||
4353 | int j; | 4337 | int j; |
4354 | struct GNUNET_PeerIdentity *inverted_trail; | 4338 | struct GNUNET_PeerIdentity *inverted_trail; |
4355 | 4339 | ||
4356 | inverted_trail = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity) * | 4340 | inverted_trail = GNUNET_new_array (trail_length, |
4357 | trail_length); | 4341 | struct GNUNET_PeerIdentity); |
4358 | i = 0; | 4342 | i = 0; |
4359 | j = trail_length - 1; | 4343 | j = trail_length - 1; |
4360 | while (i < trail_length) | 4344 | while (i < trail_length) |
@@ -4364,14 +4348,16 @@ invert_trail (const struct GNUNET_PeerIdentity *trail, | |||
4364 | j--; | 4348 | j--; |
4365 | } | 4349 | } |
4366 | 4350 | ||
4367 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, | 4351 | GNUNET_assert (NULL != |
4368 | &inverted_trail[0])); | 4352 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4353 | &inverted_trail[0])); | ||
4369 | return inverted_trail; | 4354 | return inverted_trail; |
4370 | } | 4355 | } |
4371 | 4356 | ||
4372 | 4357 | ||
4373 | /** | 4358 | /** |
4374 | * Return the shortest trail among all the trails to reach to finger from me. | 4359 | * Return the shortest trail among all the trails to reach to finger from me. |
4360 | * | ||
4375 | * @param finger Finger | 4361 | * @param finger Finger |
4376 | * @param shortest_trail_length[out] Trail length of shortest trail from me | 4362 | * @param shortest_trail_length[out] Trail length of shortest trail from me |
4377 | * to @a finger | 4363 | * to @a finger |
@@ -4414,10 +4400,10 @@ get_shortest_trail (struct FingerInfo *finger, | |||
4414 | trail = &finger->trail_list[shortest_trail_index]; | 4400 | trail = &finger->trail_list[shortest_trail_index]; |
4415 | trail_element = trail->trail_head; | 4401 | trail_element = trail->trail_head; |
4416 | 4402 | ||
4417 | trail_list = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* | 4403 | trail_list = GNUNET_new_array (shortest_trail_length, |
4418 | shortest_trail_length); | 4404 | struct GNUNET_PeerIdentity); |
4419 | 4405 | ||
4420 | for(i = 0; i < shortest_trail_length; i++,trail_element = trail_element->next) | 4406 | for (i = 0; i < shortest_trail_length; i++,trail_element = trail_element->next) |
4421 | { | 4407 | { |
4422 | trail_list[i] = trail_element->peer; | 4408 | trail_list[i] = trail_element->peer; |
4423 | } | 4409 | } |
@@ -4430,20 +4416,21 @@ get_shortest_trail (struct FingerInfo *finger, | |||
4430 | 4416 | ||
4431 | 4417 | ||
4432 | /** | 4418 | /** |
4433 | * Check if trail_1 and trail_2 have any common element. If yes then join | 4419 | * Check if @a trail_1 and @a trail_2 have any common element. If yes then join |
4434 | * them at common element. trail_1 always preceeds trail_2 in joined trail. | 4420 | * them at common element. @a trail_1 always preceeds @a trail_2 in joined trail. |
4421 | * | ||
4435 | * @param trail_1 Trail from source to me, NOT including endpoints. | 4422 | * @param trail_1 Trail from source to me, NOT including endpoints. |
4436 | * @param trail_1_len Total number of peers @a trail_1 | 4423 | * @param trail_1_len Total number of peers @a trail_1 |
4437 | * @param trail_2 Trail from me to current predecessor, NOT including endpoints. | 4424 | * @param trail_2 Trail from me to current predecessor, NOT including endpoints. |
4438 | * @param trail_2_len Total number of peers @a trail_2 | 4425 | * @param trail_2_len Total number of peers @a trail_2 |
4439 | * @param joined_trail_len Total number of peers in combined trail of trail_1 | 4426 | * @param joined_trail_len Total number of peers in combined trail of @a trail_1 |
4440 | * trail_2. | 4427 | * @a trail_2. |
4441 | * @return Joined trail. | 4428 | * @return Joined trail. |
4442 | */ | 4429 | */ |
4443 | static struct GNUNET_PeerIdentity * | 4430 | static struct GNUNET_PeerIdentity * |
4444 | check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail_1, | 4431 | check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail_1, |
4445 | unsigned int trail_1_len, | 4432 | unsigned int trail_1_len, |
4446 | struct GNUNET_PeerIdentity *trail_2, | 4433 | const struct GNUNET_PeerIdentity *trail_2, |
4447 | unsigned int trail_2_len, | 4434 | unsigned int trail_2_len, |
4448 | unsigned int *joined_trail_len) | 4435 | unsigned int *joined_trail_len) |
4449 | { | 4436 | { |
@@ -4456,12 +4443,13 @@ check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail_1, | |||
4456 | { | 4443 | { |
4457 | for (j = 0; j < trail_2_len; j++) | 4444 | for (j = 0; j < trail_2_len; j++) |
4458 | { | 4445 | { |
4459 | if(0 != GNUNET_CRYPTO_cmp_peer_identity (&trail_1[i],&trail_2[j])) | 4446 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&trail_1[i], |
4447 | &trail_2[j])) | ||
4460 | continue; | 4448 | continue; |
4461 | 4449 | ||
4462 | *joined_trail_len = i + (trail_2_len - j); | 4450 | *joined_trail_len = i + (trail_2_len - j); |
4463 | joined_trail = GNUNET_malloc (*joined_trail_len * | 4451 | joined_trail = GNUNET_new_array (*joined_trail_len, |
4464 | sizeof(struct GNUNET_PeerIdentity)); | 4452 | struct GNUNET_PeerIdentity); |
4465 | 4453 | ||
4466 | 4454 | ||
4467 | /* Copy all the elements from 0 to i into joined_trail. */ | 4455 | /* Copy all the elements from 0 to i into joined_trail. */ |
@@ -4487,8 +4475,8 @@ check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail_1, | |||
4487 | 4475 | ||
4488 | /* Here you should join the trails. */ | 4476 | /* Here you should join the trails. */ |
4489 | *joined_trail_len = trail_1_len + trail_2_len + 1; | 4477 | *joined_trail_len = trail_1_len + trail_2_len + 1; |
4490 | joined_trail = GNUNET_malloc (*joined_trail_len * | 4478 | joined_trail = GNUNET_new_array (*joined_trail_len, |
4491 | sizeof(struct GNUNET_PeerIdentity)); | 4479 | struct GNUNET_PeerIdentity); |
4492 | 4480 | ||
4493 | 4481 | ||
4494 | for(i = 0; i < trail_1_len;i++) | 4482 | for(i = 0; i < trail_1_len;i++) |
@@ -4511,6 +4499,7 @@ check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail_1, | |||
4511 | /** | 4499 | /** |
4512 | * Return the trail from source to my current predecessor. Check if source | 4500 | * Return the trail from source to my current predecessor. Check if source |
4513 | * is already part of the this trail, if yes then return the shorten trail. | 4501 | * is already part of the this trail, if yes then return the shorten trail. |
4502 | * | ||
4514 | * @param current_trail Trail from source to me, NOT including the endpoints. | 4503 | * @param current_trail Trail from source to me, NOT including the endpoints. |
4515 | * @param current_trail_length Number of peers in @a current_trail. | 4504 | * @param current_trail_length Number of peers in @a current_trail. |
4516 | * @param trail_src_to_curr_pred_length[out] Number of peers in trail from | 4505 | * @param trail_src_to_curr_pred_length[out] Number of peers in trail from |
@@ -4547,8 +4536,8 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer, | |||
4547 | if(0 == i) | 4536 | if(0 == i) |
4548 | return NULL; | 4537 | return NULL; |
4549 | 4538 | ||
4550 | trail_src_to_curr_pred = GNUNET_malloc (*trail_src_to_curr_pred_length * | 4539 | trail_src_to_curr_pred = GNUNET_new_array (*trail_src_to_curr_pred_length, |
4551 | sizeof(struct GNUNET_PeerIdentity)); | 4540 | struct GNUNET_PeerIdentity); |
4552 | for (j = 0; j < i; j++) | 4541 | for (j = 0; j < i; j++) |
4553 | trail_src_to_curr_pred[j] = trail_src_to_me[j]; | 4542 | trail_src_to_curr_pred[j] = trail_src_to_me[j]; |
4554 | return trail_src_to_curr_pred; | 4543 | return trail_src_to_curr_pred; |
@@ -4578,8 +4567,9 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer, | |||
4578 | } | 4567 | } |
4579 | 4568 | ||
4580 | *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i; | 4569 | *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i; |
4581 | trail_src_to_curr_pred = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)* | 4570 | trail_src_to_curr_pred = GNUNET_new_array (*trail_src_to_curr_pred_length, |
4582 | *trail_src_to_curr_pred_length); | 4571 | struct GNUNET_PeerIdentity); |
4572 | |||
4583 | 4573 | ||
4584 | for (j = 0; j < *trail_src_to_curr_pred_length; i++,j++) | 4574 | for (j = 0; j < *trail_src_to_curr_pred_length; i++,j++) |
4585 | trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i]; | 4575 | trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i]; |
@@ -4603,13 +4593,14 @@ get_trail_src_to_curr_pred (struct GNUNET_PeerIdentity source_peer, | |||
4603 | * the trail to get the trail from me to finger, add an entry in your routing | 4593 | * the trail to get the trail from me to finger, add an entry in your routing |
4604 | * table, send add trail message to peers which are part of trail from me to | 4594 | * table, send add trail message to peers which are part of trail from me to |
4605 | * finger and add finger in finger table. | 4595 | * finger and add finger in finger table. |
4596 | * | ||
4606 | * @param finger | 4597 | * @param finger |
4607 | * @param trail | 4598 | * @param trail |
4608 | * @param trail_length | 4599 | * @param trail_length |
4609 | */ | 4600 | */ |
4610 | static void | 4601 | static void |
4611 | update_predecessor (struct GNUNET_PeerIdentity finger, | 4602 | update_predecessor (const struct GNUNET_PeerIdentity *finger, |
4612 | struct GNUNET_PeerIdentity *trail, | 4603 | const struct GNUNET_PeerIdentity *trail, |
4613 | unsigned int trail_length) | 4604 | unsigned int trail_length) |
4614 | { | 4605 | { |
4615 | struct GNUNET_HashCode trail_to_new_predecessor_id; | 4606 | struct GNUNET_HashCode trail_to_new_predecessor_id; |
@@ -4624,8 +4615,11 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4624 | if (0 == trail_length) | 4615 | if (0 == trail_length) |
4625 | { | 4616 | { |
4626 | trail_to_new_predecessor = NULL; | 4617 | trail_to_new_predecessor = NULL; |
4627 | GDS_ROUTING_add (trail_to_new_predecessor_id, my_identity, finger); | 4618 | GDS_ROUTING_add (&trail_to_new_predecessor_id, |
4628 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger); | 4619 | &my_identity, |
4620 | finger); | ||
4621 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
4622 | finger); | ||
4629 | if (NULL == target_friend) | 4623 | if (NULL == target_friend) |
4630 | { | 4624 | { |
4631 | GNUNET_break (0); | 4625 | GNUNET_break (0); |
@@ -4636,14 +4630,15 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4636 | { | 4630 | { |
4637 | /* Invert the trail to get the trail from me to finger, NOT including the | 4631 | /* Invert the trail to get the trail from me to finger, NOT including the |
4638 | endpoints.*/ | 4632 | endpoints.*/ |
4639 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, | 4633 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4640 | &trail[trail_length-1])); | 4634 | &trail[trail_length-1])); |
4641 | trail_to_new_predecessor = invert_trail (trail, trail_length); | 4635 | trail_to_new_predecessor = invert_trail (trail, |
4636 | trail_length); | ||
4642 | 4637 | ||
4643 | /* Add an entry in your routing table. */ | 4638 | /* Add an entry in your routing table. */ |
4644 | GDS_ROUTING_add (trail_to_new_predecessor_id, | 4639 | GDS_ROUTING_add (&trail_to_new_predecessor_id, |
4645 | my_identity, | 4640 | &my_identity, |
4646 | trail_to_new_predecessor[0]); | 4641 | &trail_to_new_predecessor[0]); |
4647 | 4642 | ||
4648 | GNUNET_assert (NULL != (target_friend = | 4643 | GNUNET_assert (NULL != (target_friend = |
4649 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4644 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
@@ -4652,20 +4647,23 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4652 | 4647 | ||
4653 | /* Add entry in routing table of all peers that are part of trail from me | 4648 | /* Add entry in routing table of all peers that are part of trail from me |
4654 | to finger, including finger. */ | 4649 | to finger, including finger. */ |
4655 | GDS_NEIGHBOURS_send_add_trail (my_identity, | 4650 | GDS_NEIGHBOURS_send_add_trail (&my_identity, |
4656 | finger, | 4651 | finger, |
4657 | trail_to_new_predecessor_id, | 4652 | &trail_to_new_predecessor_id, |
4658 | trail_to_new_predecessor, | 4653 | trail_to_new_predecessor, |
4659 | trail_length, | 4654 | trail_length, |
4660 | target_friend); | 4655 | target_friend); |
4661 | 4656 | ||
4662 | add_new_finger (finger, trail_to_new_predecessor, trail_length, | 4657 | add_new_finger (finger, |
4663 | trail_to_new_predecessor_id, PREDECESSOR_FINGER_ID); | 4658 | trail_to_new_predecessor, |
4664 | GNUNET_free_non_null(trail_to_new_predecessor); | 4659 | trail_length, |
4660 | &trail_to_new_predecessor_id, | ||
4661 | PREDECESSOR_FINGER_ID); | ||
4662 | GNUNET_free_non_null (trail_to_new_predecessor); | ||
4665 | } | 4663 | } |
4666 | 4664 | ||
4667 | 4665 | ||
4668 | /* | 4666 | /** |
4669 | * Check if you already have a predecessor. If not then add finger as your | 4667 | * Check if you already have a predecessor. If not then add finger as your |
4670 | * predecessor. If you have predecessor, then compare two peer identites. | 4668 | * predecessor. If you have predecessor, then compare two peer identites. |
4671 | * If finger is correct predecessor, then remove the old entry, add finger in | 4669 | * If finger is correct predecessor, then remove the old entry, add finger in |
@@ -4676,66 +4674,95 @@ update_predecessor (struct GNUNET_PeerIdentity finger, | |||
4676 | * @param trail_length Total number of peer in @a trail. | 4674 | * @param trail_length Total number of peer in @a trail. |
4677 | */ | 4675 | */ |
4678 | static void | 4676 | static void |
4679 | compare_and_update_predecessor (struct GNUNET_PeerIdentity finger, | 4677 | compare_and_update_predecessor (const struct GNUNET_PeerIdentity *finger, |
4680 | struct GNUNET_PeerIdentity *trail, | 4678 | const struct GNUNET_PeerIdentity *trail, |
4681 | unsigned int trail_length) | 4679 | unsigned int trail_length) |
4682 | { | 4680 | { |
4683 | struct FingerInfo *current_predecessor; | 4681 | struct FingerInfo *current_predecessor; |
4684 | struct GNUNET_PeerIdentity closest_peer; | 4682 | const struct GNUNET_PeerIdentity *closest_peer; |
4685 | uint64_t predecessor_value; | 4683 | uint64_t predecessor_value; |
4686 | unsigned int is_predecessor = 1; | 4684 | unsigned int is_predecessor = 1; |
4687 | 4685 | ||
4688 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; | 4686 | current_predecessor = &finger_table[PREDECESSOR_FINGER_ID]; |
4689 | GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger, &my_identity)); | 4687 | GNUNET_assert (0 != GNUNET_CRYPTO_cmp_peer_identity (finger, |
4688 | &my_identity)); | ||
4690 | 4689 | ||
4691 | /* No predecessor. Add finger as your predecessor. */ | 4690 | /* No predecessor. Add finger as your predecessor. */ |
4692 | if (GNUNET_NO == current_predecessor->is_present) | 4691 | if (GNUNET_NO == current_predecessor->is_present) |
4693 | { | 4692 | { |
4694 | update_predecessor (finger, trail, trail_length); | 4693 | update_predecessor (finger, |
4694 | trail, | ||
4695 | trail_length); | ||
4695 | return; | 4696 | return; |
4696 | } | 4697 | } |
4697 | 4698 | ||
4698 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (¤t_predecessor->finger_identity, | 4699 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (¤t_predecessor->finger_identity, |
4699 | &finger)) | 4700 | finger)) |
4700 | { | 4701 | { |
4701 | return; | 4702 | return; |
4702 | } | 4703 | } |
4703 | 4704 | ||
4704 | predecessor_value = compute_finger_identity_value (PREDECESSOR_FINGER_ID); | 4705 | predecessor_value = compute_finger_identity_value (PREDECESSOR_FINGER_ID); |
4705 | closest_peer = select_closest_peer (&finger, | 4706 | closest_peer = select_closest_peer (finger, |
4706 | ¤t_predecessor->finger_identity, | 4707 | ¤t_predecessor->finger_identity, |
4707 | predecessor_value, is_predecessor); | 4708 | predecessor_value, |
4709 | is_predecessor); | ||
4708 | 4710 | ||
4709 | /* Finger is the closest predecessor. Remove the existing one and add the new | 4711 | /* Finger is the closest predecessor. Remove the existing one and add the new |
4710 | one. */ | 4712 | one. */ |
4711 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&closest_peer, &finger)) | 4713 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer, |
4712 | { | 4714 | finger)) |
4713 | remove_existing_finger (current_predecessor, PREDECESSOR_FINGER_ID); | 4715 | { |
4714 | update_predecessor (finger, trail, trail_length); | 4716 | remove_existing_finger (current_predecessor, |
4717 | PREDECESSOR_FINGER_ID); | ||
4718 | update_predecessor (finger, | ||
4719 | trail, | ||
4720 | trail_length); | ||
4715 | return; | 4721 | return; |
4716 | } | 4722 | } |
4717 | return; | ||
4718 | } | 4723 | } |
4719 | 4724 | ||
4720 | 4725 | ||
4721 | /* | 4726 | /** |
4722 | * Core handle for p2p verify successor messages. | 4727 | * Check format of a p2p verify successor messages. |
4728 | * | ||
4723 | * @param cls closure | 4729 | * @param cls closure |
4724 | * @param message message | 4730 | * @param vsm the message |
4725 | * @param peer peer identity this notification is about | 4731 | * @return #GNUNET_OK if @a vsm is well-formed |
4726 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
4727 | */ | 4732 | */ |
4728 | static int | 4733 | static int |
4729 | handle_dht_p2p_verify_successor(void *cls, | 4734 | check_dht_p2p_verify_successor (void *cls, |
4730 | const struct GNUNET_PeerIdentity *peer, | 4735 | const struct PeerVerifySuccessorMessage *vsm) |
4731 | const struct GNUNET_MessageHeader *message) | 4736 | { |
4737 | size_t msize; | ||
4738 | |||
4739 | msize = ntohs (vsm->header.size); | ||
4740 | if ((msize - sizeof (struct PeerVerifySuccessorMessage)) % | ||
4741 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
4742 | { | ||
4743 | GNUNET_break_op (0); | ||
4744 | return GNUNET_SYSERR; | ||
4745 | } | ||
4746 | return GNUNET_OK; | ||
4747 | } | ||
4748 | |||
4749 | |||
4750 | /** | ||
4751 | * Core handle for p2p verify successor messages. | ||
4752 | * | ||
4753 | * @param cls closure | ||
4754 | * @param vsm the message | ||
4755 | */ | ||
4756 | static void | ||
4757 | handle_dht_p2p_verify_successor (void *cls, | ||
4758 | const struct PeerVerifySuccessorMessage *vsm) | ||
4732 | { | 4759 | { |
4733 | const struct PeerVerifySuccessorMessage *vsm; | 4760 | struct FriendInfo *friend = cls; |
4734 | struct GNUNET_HashCode trail_id; | 4761 | struct GNUNET_HashCode trail_id; |
4735 | struct GNUNET_PeerIdentity successor; | 4762 | struct GNUNET_PeerIdentity successor; |
4736 | struct GNUNET_PeerIdentity source_peer; | 4763 | struct GNUNET_PeerIdentity source_peer; |
4737 | struct GNUNET_PeerIdentity *trail; | 4764 | struct GNUNET_PeerIdentity *trail; |
4738 | struct GNUNET_PeerIdentity *next_hop; | 4765 | const struct GNUNET_PeerIdentity *next_hop; |
4739 | struct FingerInfo current_predecessor; | 4766 | struct FingerInfo current_predecessor; |
4740 | struct FriendInfo *target_friend; | 4767 | struct FriendInfo *target_friend; |
4741 | unsigned int trail_src_to_curr_pred_len = 0; | 4768 | unsigned int trail_src_to_curr_pred_len = 0; |
@@ -4743,27 +4770,12 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4743 | unsigned int trail_length; | 4770 | unsigned int trail_length; |
4744 | size_t msize; | 4771 | size_t msize; |
4745 | 4772 | ||
4746 | msize = ntohs (message->size); | 4773 | msize = ntohs (vsm->header.size); |
4747 | |||
4748 | if (msize < sizeof (struct PeerVerifySuccessorMessage)) | ||
4749 | { | ||
4750 | GNUNET_break_op (0); | ||
4751 | return GNUNET_YES; | ||
4752 | } | ||
4753 | |||
4754 | vsm = (const struct PeerVerifySuccessorMessage *) message; | ||
4755 | trail_length = (msize - sizeof (struct PeerVerifySuccessorMessage))/ | 4774 | trail_length = (msize - sizeof (struct PeerVerifySuccessorMessage))/ |
4756 | sizeof (struct GNUNET_PeerIdentity); | 4775 | sizeof (struct GNUNET_PeerIdentity); |
4757 | if ((msize - sizeof (struct PeerVerifySuccessorMessage)) % | ||
4758 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
4759 | { | ||
4760 | GNUNET_break_op (0); | ||
4761 | return GNUNET_OK; | ||
4762 | } | ||
4763 | |||
4764 | GNUNET_STATISTICS_update (GDS_stats, | 4776 | GNUNET_STATISTICS_update (GDS_stats, |
4765 | gettext_noop | 4777 | gettext_noop ("# Bytes received from other peers"), |
4766 | ("# Bytes received from other peers"), msize, | 4778 | msize, |
4767 | GNUNET_NO); | 4779 | GNUNET_NO); |
4768 | 4780 | ||
4769 | trail_id = vsm->trail_id; | 4781 | trail_id = vsm->trail_id; |
@@ -4773,53 +4785,55 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4773 | 4785 | ||
4774 | /* I am NOT the successor of source_peer. Pass the message to next_hop on | 4786 | /* I am NOT the successor of source_peer. Pass the message to next_hop on |
4775 | * the trail. */ | 4787 | * the trail. */ |
4776 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity))) | 4788 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, |
4789 | &my_identity))) | ||
4777 | { | 4790 | { |
4778 | next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST); | 4791 | next_hop = GDS_ROUTING_get_next_hop (&trail_id, |
4792 | GDS_ROUTING_SRC_TO_DEST); | ||
4779 | if (NULL == next_hop) | 4793 | if (NULL == next_hop) |
4780 | { | 4794 | return; |
4781 | return GNUNET_OK; | ||
4782 | } | ||
4783 | |||
4784 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | ||
4785 | 4795 | ||
4786 | if(NULL == target_friend) | 4796 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4797 | next_hop); | ||
4798 | if (NULL == target_friend) | ||
4787 | { | 4799 | { |
4788 | GNUNET_break_op(0); | 4800 | GNUNET_break_op(0); |
4789 | return GNUNET_OK; | 4801 | return; |
4790 | } | 4802 | } |
4791 | GDS_NEIGHBOURS_send_verify_successor_message (source_peer, successor, | 4803 | GDS_NEIGHBOURS_send_verify_successor_message (&source_peer, |
4792 | trail_id, trail, trail_length, | 4804 | &successor, |
4805 | &trail_id, | ||
4806 | trail, | ||
4807 | trail_length, | ||
4793 | target_friend); | 4808 | target_friend); |
4794 | return GNUNET_OK; | 4809 | return; |
4795 | } | 4810 | } |
4796 | 4811 | ||
4797 | /* I am the destination of this message. */ | 4812 | /* I am the destination of this message. */ |
4798 | |||
4799 | /* Check if the source_peer could be our predecessor and if yes then update | 4813 | /* Check if the source_peer could be our predecessor and if yes then update |
4800 | * it. */ | 4814 | * it. */ |
4801 | compare_and_update_predecessor (source_peer, trail, trail_length); | 4815 | compare_and_update_predecessor (&source_peer, |
4816 | trail, | ||
4817 | trail_length); | ||
4802 | current_predecessor = finger_table[PREDECESSOR_FINGER_ID]; | 4818 | current_predecessor = finger_table[PREDECESSOR_FINGER_ID]; |
4803 | 4819 | ||
4804 | /* Is source of this message NOT my predecessor. */ | 4820 | /* Is source of this message NOT my predecessor. */ |
4805 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_predecessor.finger_identity, | 4821 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_predecessor.finger_identity, |
4806 | &source_peer))) | 4822 | &source_peer))) |
4807 | { | 4823 | { |
4808 | trail_src_to_curr_pred = | 4824 | trail_src_to_curr_pred |
4809 | get_trail_src_to_curr_pred (source_peer, | 4825 | = get_trail_src_to_curr_pred (source_peer, |
4810 | trail, | 4826 | trail, |
4811 | trail_length, | 4827 | trail_length, |
4812 | &trail_src_to_curr_pred_len); | 4828 | &trail_src_to_curr_pred_len); |
4813 | } | 4829 | } |
4814 | else | 4830 | else |
4815 | { | 4831 | { |
4816 | trail_src_to_curr_pred_len = trail_length; | 4832 | trail_src_to_curr_pred_len = trail_length; |
4817 | unsigned int i; | 4833 | trail_src_to_curr_pred = GNUNET_new_array (trail_src_to_curr_pred_len, |
4818 | 4834 | struct GNUNET_PeerIdentity); | |
4819 | trail_src_to_curr_pred = | 4835 | |
4820 | GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity) | 4836 | for (unsigned int i = 0; i < trail_src_to_curr_pred_len; i++) |
4821 | *trail_src_to_curr_pred_len); | ||
4822 | for(i = 0; i < trail_src_to_curr_pred_len; i++) | ||
4823 | { | 4837 | { |
4824 | trail_src_to_curr_pred[i] = trail[i]; | 4838 | trail_src_to_curr_pred[i] = trail[i]; |
4825 | } | 4839 | } |
@@ -4827,21 +4841,24 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4827 | 4841 | ||
4828 | GNUNET_assert (NULL != | 4842 | GNUNET_assert (NULL != |
4829 | (target_friend = | 4843 | (target_friend = |
4830 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))); | 4844 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4831 | GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity, | 4845 | friend->id))); |
4832 | current_predecessor.finger_identity, | 4846 | GDS_NEIGHBOURS_send_verify_successor_result (&source_peer, |
4833 | trail_id, trail_src_to_curr_pred, | 4847 | &my_identity, |
4848 | ¤t_predecessor.finger_identity, | ||
4849 | &trail_id, | ||
4850 | trail_src_to_curr_pred, | ||
4834 | trail_src_to_curr_pred_len, | 4851 | trail_src_to_curr_pred_len, |
4835 | GDS_ROUTING_DEST_TO_SRC, | 4852 | GDS_ROUTING_DEST_TO_SRC, |
4836 | target_friend); | 4853 | target_friend); |
4837 | GNUNET_free_non_null(trail_src_to_curr_pred); | 4854 | GNUNET_free_non_null (trail_src_to_curr_pred); |
4838 | return GNUNET_OK; | ||
4839 | } | 4855 | } |
4840 | 4856 | ||
4841 | 4857 | ||
4842 | /** | 4858 | /** |
4843 | * If the trail from me to my probable successor contains a friend not | 4859 | * If the trail from me to my probable successor contains a friend not |
4844 | * at index 0, then we can shorten the trail. | 4860 | * at index 0, then we can shorten the trail. |
4861 | * | ||
4845 | * @param probable_successor Peer which is our probable successor | 4862 | * @param probable_successor Peer which is our probable successor |
4846 | * @param trail_me_to_probable_successor Peers in path from me to my probable | 4863 | * @param trail_me_to_probable_successor Peers in path from me to my probable |
4847 | * successor, NOT including the endpoints. | 4864 | * successor, NOT including the endpoints. |
@@ -4850,8 +4867,8 @@ handle_dht_p2p_verify_successor(void *cls, | |||
4850 | * @return Updated trail, if any friend found. | 4867 | * @return Updated trail, if any friend found. |
4851 | * Else the trail_me_to_probable_successor. | 4868 | * Else the trail_me_to_probable_successor. |
4852 | */ | 4869 | */ |
4853 | struct GNUNET_PeerIdentity * | 4870 | const struct GNUNET_PeerIdentity * |
4854 | check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, | 4871 | check_trail_me_to_probable_succ (const struct GNUNET_PeerIdentity *probable_successor, |
4855 | const struct GNUNET_PeerIdentity *trail_me_to_probable_successor, | 4872 | const struct GNUNET_PeerIdentity *trail_me_to_probable_successor, |
4856 | unsigned int trail_me_to_probable_successor_len, | 4873 | unsigned int trail_me_to_probable_successor_len, |
4857 | unsigned int *trail_to_new_successor_length) | 4874 | unsigned int *trail_to_new_successor_length) |
@@ -4862,7 +4879,7 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, | |||
4862 | 4879 | ||
4863 | /* Probable successor is a friend */ | 4880 | /* Probable successor is a friend */ |
4864 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4881 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4865 | &probable_successor)) | 4882 | probable_successor)) |
4866 | { | 4883 | { |
4867 | trail_to_new_successor = NULL; | 4884 | trail_to_new_successor = NULL; |
4868 | *trail_to_new_successor_length = 0; | 4885 | *trail_to_new_successor_length = 0; |
@@ -4870,7 +4887,7 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, | |||
4870 | } | 4887 | } |
4871 | 4888 | ||
4872 | /* Is there any friend of yours in this trail. */ | 4889 | /* Is there any friend of yours in this trail. */ |
4873 | if(trail_me_to_probable_successor_len > 1) | 4890 | if (trail_me_to_probable_successor_len > 1) |
4874 | { | 4891 | { |
4875 | for (i = trail_me_to_probable_successor_len - 1; i > 0; i--) | 4892 | for (i = trail_me_to_probable_successor_len - 1; i > 0; i--) |
4876 | { | 4893 | { |
@@ -4879,11 +4896,9 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, | |||
4879 | continue; | 4896 | continue; |
4880 | 4897 | ||
4881 | *trail_to_new_successor_length = (trail_me_to_probable_successor_len - i); | 4898 | *trail_to_new_successor_length = (trail_me_to_probable_successor_len - i); |
4882 | trail_to_new_successor = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity)* | 4899 | trail_to_new_successor = GNUNET_new_array (*trail_to_new_successor_length, |
4883 | *trail_to_new_successor_length); | 4900 | struct GNUNET_PeerIdentity); |
4884 | 4901 | for (j = 0; j < *trail_to_new_successor_length; i++,j++) | |
4885 | |||
4886 | for(j = 0; j < *trail_to_new_successor_length; i++,j++) | ||
4887 | { | 4902 | { |
4888 | trail_to_new_successor[j] = trail_me_to_probable_successor[i]; | 4903 | trail_to_new_successor[j] = trail_me_to_probable_successor[i]; |
4889 | } | 4904 | } |
@@ -4893,9 +4908,10 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor, | |||
4893 | } | 4908 | } |
4894 | 4909 | ||
4895 | *trail_to_new_successor_length = trail_me_to_probable_successor_len; | 4910 | *trail_to_new_successor_length = trail_me_to_probable_successor_len; |
4896 | return (struct GNUNET_PeerIdentity*)trail_me_to_probable_successor; | 4911 | return trail_me_to_probable_successor; |
4897 | } | 4912 | } |
4898 | 4913 | ||
4914 | |||
4899 | // TODO: Move up | 4915 | // TODO: Move up |
4900 | struct SendNotifyContext | 4916 | struct SendNotifyContext |
4901 | { | 4917 | { |
@@ -4929,25 +4945,26 @@ send_notify_new_successor (void *cls); | |||
4929 | * @param trail_length Total number of peers in @a trail. | 4945 | * @param trail_length Total number of peers in @a trail. |
4930 | */ | 4946 | */ |
4931 | static void | 4947 | static void |
4932 | compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ, | 4948 | compare_and_update_successor (const struct GNUNET_PeerIdentity *curr_succ, |
4933 | struct GNUNET_PeerIdentity probable_successor, | 4949 | const struct GNUNET_PeerIdentity *probable_successor, |
4934 | const struct GNUNET_PeerIdentity *trail, | 4950 | const struct GNUNET_PeerIdentity *trail, |
4935 | unsigned int trail_length) | 4951 | unsigned int trail_length) |
4936 | { | 4952 | { |
4937 | struct FingerInfo *current_successor; | 4953 | struct FingerInfo *current_successor; |
4938 | struct GNUNET_PeerIdentity closest_peer; | 4954 | const struct GNUNET_PeerIdentity *closest_peer; |
4939 | struct GNUNET_HashCode trail_id; | 4955 | struct GNUNET_HashCode trail_id; |
4940 | struct GNUNET_PeerIdentity *trail_me_to_probable_succ; | 4956 | const struct GNUNET_PeerIdentity *trail_me_to_probable_succ; |
4941 | struct FriendInfo *target_friend; | 4957 | struct FriendInfo *target_friend; |
4942 | unsigned int trail_me_to_probable_succ_len; | 4958 | unsigned int trail_me_to_probable_succ_len; |
4943 | unsigned int is_predecessor = 0; | 4959 | unsigned int is_predecessor = 0; |
4944 | uint64_t successor_value; | 4960 | uint64_t successor_value; |
4961 | struct SendNotifyContext *notify_ctx; | ||
4945 | 4962 | ||
4946 | current_successor = &finger_table[0]; | 4963 | current_successor = &finger_table[0]; |
4947 | successor_value = compute_finger_identity_value(0); | 4964 | successor_value = compute_finger_identity_value(0); |
4948 | 4965 | ||
4949 | /* If probable successor is same as current_successor, do nothing. */ | 4966 | /* If probable successor is same as current_successor, do nothing. */ |
4950 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (&probable_successor, | 4967 | if(0 == GNUNET_CRYPTO_cmp_peer_identity (probable_successor, |
4951 | ¤t_successor->finger_identity)) | 4968 | ¤t_successor->finger_identity)) |
4952 | { | 4969 | { |
4953 | if ((NULL != GDS_stats)) | 4970 | if ((NULL != GDS_stats)) |
@@ -4958,9 +4975,13 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ, | |||
4958 | uint64_t my_id; | 4975 | uint64_t my_id; |
4959 | GNUNET_memcpy (&my_id, &my_identity, sizeof(uint64_t)); | 4976 | GNUNET_memcpy (&my_id, &my_identity, sizeof(uint64_t)); |
4960 | my_id_str = GNUNET_strdup (GNUNET_i2s_full (&my_identity)); | 4977 | my_id_str = GNUNET_strdup (GNUNET_i2s_full (&my_identity)); |
4961 | GNUNET_memcpy(&succ, ¤t_successor->finger_identity, sizeof(uint64_t)); | 4978 | GNUNET_memcpy (&succ, |
4979 | ¤t_successor->finger_identity, | ||
4980 | sizeof(uint64_t)); | ||
4962 | succ = GNUNET_ntohll(succ); | 4981 | succ = GNUNET_ntohll(succ); |
4963 | GNUNET_asprintf (&key, "XDHT:%s:", my_id_str); | 4982 | GNUNET_asprintf (&key, |
4983 | "XDHT:%s:", | ||
4984 | my_id_str); | ||
4964 | GNUNET_free (my_id_str); | 4985 | GNUNET_free (my_id_str); |
4965 | 4986 | ||
4966 | GNUNET_STATISTICS_set (GDS_stats, key, succ, 0); | 4987 | GNUNET_STATISTICS_set (GDS_stats, key, succ, 0); |
@@ -4973,12 +4994,13 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ, | |||
4973 | NULL); | 4994 | NULL); |
4974 | return; | 4995 | return; |
4975 | } | 4996 | } |
4976 | closest_peer = select_closest_peer (&probable_successor, | 4997 | closest_peer = select_closest_peer (probable_successor, |
4977 | ¤t_successor->finger_identity, | 4998 | ¤t_successor->finger_identity, |
4978 | successor_value, is_predecessor); | 4999 | successor_value, |
5000 | is_predecessor); | ||
4979 | 5001 | ||
4980 | /* If the current_successor in the finger table is closest, then do nothing. */ | 5002 | /* If the current_successor in the finger table is closest, then do nothing. */ |
4981 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&closest_peer , | 5003 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer, |
4982 | ¤t_successor->finger_identity)) | 5004 | ¤t_successor->finger_identity)) |
4983 | { | 5005 | { |
4984 | //FIXME: Is this a good place to return the stats. | 5006 | //FIXME: Is this a good place to return the stats. |
@@ -5008,97 +5030,104 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ, | |||
5008 | 5030 | ||
5009 | if (send_verify_successor_task == NULL) | 5031 | if (send_verify_successor_task == NULL) |
5010 | send_verify_successor_task = | 5032 | send_verify_successor_task = |
5011 | GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time, | 5033 | GNUNET_SCHEDULER_add_delayed (verify_successor_next_send_time, |
5012 | &send_verify_successor_message, | 5034 | &send_verify_successor_message, |
5013 | NULL); | 5035 | NULL); |
5014 | return; | 5036 | return; |
5015 | } | 5037 | } |
5016 | 5038 | ||
5017 | /* Probable successor is the closest peer.*/ | 5039 | /* Probable successor is the closest peer.*/ |
5018 | if(trail_length > 0) | 5040 | if(trail_length > 0) |
5019 | { | 5041 | { |
5020 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, | 5042 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5021 | &trail[0])); | 5043 | &trail[0])); |
5022 | } | 5044 | } |
5023 | else | 5045 | else |
5024 | { | 5046 | { |
5025 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get(friend_peermap, | 5047 | GNUNET_assert(NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5026 | &probable_successor)); | 5048 | probable_successor)); |
5027 | } | 5049 | } |
5028 | 5050 | ||
5029 | trail_me_to_probable_succ_len = 0; | 5051 | trail_me_to_probable_succ_len = 0; |
5030 | trail_me_to_probable_succ = | 5052 | trail_me_to_probable_succ = check_trail_me_to_probable_succ (probable_successor, |
5031 | check_trail_me_to_probable_succ (probable_successor, | 5053 | trail, |
5032 | trail, trail_length, | 5054 | trail_length, |
5033 | &trail_me_to_probable_succ_len); | 5055 | &trail_me_to_probable_succ_len); |
5034 | 5056 | ||
5035 | /* Remove the existing successor. */ | 5057 | /* Remove the existing successor. */ |
5036 | remove_existing_finger (current_successor, 0); | 5058 | remove_existing_finger (current_successor, 0); |
5037 | /* Generate a new trail id to reach to your new successor. */ | 5059 | /* Generate a new trail id to reach to your new successor. */ |
5038 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, | 5060 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, |
5039 | &trail_id, sizeof (trail_id)); | 5061 | &trail_id, |
5062 | sizeof (trail_id)); | ||
5040 | 5063 | ||
5041 | if (trail_me_to_probable_succ_len > 0) | 5064 | if (trail_me_to_probable_succ_len > 0) |
5042 | { | 5065 | { |
5043 | GDS_ROUTING_add (trail_id, my_identity, trail_me_to_probable_succ[0]); | 5066 | GDS_ROUTING_add (&trail_id, |
5067 | &my_identity, | ||
5068 | &trail_me_to_probable_succ[0]); | ||
5044 | GNUNET_assert (NULL != | 5069 | GNUNET_assert (NULL != |
5045 | (target_friend = | 5070 | (target_friend = |
5046 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5071 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5047 | &trail_me_to_probable_succ[0]))); | 5072 | &trail_me_to_probable_succ[0]))); |
5048 | } | 5073 | } |
5049 | else | 5074 | else |
5050 | { | 5075 | { |
5051 | GDS_ROUTING_add (trail_id, my_identity, probable_successor); | 5076 | GDS_ROUTING_add (&trail_id, |
5077 | &my_identity, | ||
5078 | probable_successor); | ||
5052 | GNUNET_assert (NULL != | 5079 | GNUNET_assert (NULL != |
5053 | (target_friend = | 5080 | (target_friend = |
5054 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5081 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5055 | &probable_successor))); | 5082 | probable_successor))); |
5056 | } | 5083 | } |
5057 | 5084 | ||
5058 | add_new_finger (probable_successor, trail_me_to_probable_succ, | 5085 | add_new_finger (probable_successor, |
5059 | trail_me_to_probable_succ_len, trail_id, 0); | 5086 | trail_me_to_probable_succ, |
5060 | 5087 | trail_me_to_probable_succ_len, | |
5061 | struct SendNotifyContext *notify_ctx; | 5088 | &trail_id, |
5089 | 0); | ||
5062 | 5090 | ||
5063 | notify_ctx = GNUNET_new(struct SendNotifyContext); | 5091 | notify_ctx = GNUNET_new (struct SendNotifyContext); |
5064 | 5092 | ||
5065 | notify_ctx->source_peer = my_identity; | 5093 | notify_ctx->source_peer = my_identity; |
5066 | notify_ctx->successor = probable_successor; | 5094 | notify_ctx->successor = *probable_successor; |
5067 | notify_ctx->successor_trail = | 5095 | notify_ctx->successor_trail = GNUNET_new_array (trail_me_to_probable_succ_len, |
5068 | GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity) * trail_me_to_probable_succ_len); | 5096 | struct GNUNET_PeerIdentity); |
5069 | GNUNET_memcpy(notify_ctx->successor_trail, trail_me_to_probable_succ, | 5097 | GNUNET_memcpy (notify_ctx->successor_trail, |
5070 | sizeof(struct GNUNET_PeerIdentity) * trail_me_to_probable_succ_len); | 5098 | trail_me_to_probable_succ, |
5099 | sizeof(struct GNUNET_PeerIdentity) * trail_me_to_probable_succ_len); | ||
5071 | notify_ctx->successor_trail_length = trail_me_to_probable_succ_len; | 5100 | notify_ctx->successor_trail_length = trail_me_to_probable_succ_len; |
5072 | notify_ctx->succesor_trail_id = trail_id; | 5101 | notify_ctx->succesor_trail_id = trail_id; |
5073 | notify_ctx->target_friend = target_friend; | 5102 | notify_ctx->target_friend = target_friend; |
5074 | notify_ctx->num_retries_scheduled = 0; | 5103 | notify_ctx->num_retries_scheduled = 0; |
5075 | GNUNET_free_non_null (trail_me_to_probable_succ); | ||
5076 | 5104 | ||
5077 | // TODO: Check if we should verify before schedule if already scheduled. | 5105 | // TODO: Check if we should verify before schedule if already scheduled. |
5078 | GNUNET_SCHEDULER_add_now(&send_notify_new_successor, (void*)notify_ctx); | 5106 | GNUNET_SCHEDULER_add_now (&send_notify_new_successor, |
5107 | notify_ctx); | ||
5079 | } | 5108 | } |
5080 | 5109 | ||
5081 | 5110 | ||
5082 | |||
5083 | void | 5111 | void |
5084 | send_notify_new_successor (void *cls) | 5112 | send_notify_new_successor (void *cls) |
5085 | { | 5113 | { |
5086 | struct SendNotifyContext *ctx = cls; | 5114 | struct SendNotifyContext *ctx = cls; |
5087 | 5115 | ||
5088 | GDS_NEIGHBOURS_send_notify_new_successor (ctx->source_peer, | 5116 | GDS_NEIGHBOURS_send_notify_new_successor (&ctx->source_peer, |
5089 | ctx->successor, | 5117 | &ctx->successor, |
5090 | ctx->successor_trail, | 5118 | ctx->successor_trail, |
5091 | ctx->successor_trail_length, | 5119 | ctx->successor_trail_length, |
5092 | ctx->succesor_trail_id, | 5120 | &ctx->succesor_trail_id, |
5093 | ctx->target_friend); | 5121 | ctx->target_friend); |
5094 | 5122 | ||
5095 | if (0 == ctx->num_retries_scheduled && | 5123 | if ( (0 == ctx->num_retries_scheduled) && |
5096 | send_notify_new_successor_retry_task != NULL) | 5124 | (send_notify_new_successor_retry_task != NULL) ) |
5097 | { | 5125 | { |
5098 | // Result from previous notify successos hasn't arrived, so the retry task | 5126 | // Result from previous notify successos hasn't arrived, so the retry task |
5099 | // hasn't been cancelled! Already a new notify successor must be called. | 5127 | // hasn't been cancelled! Already a new notify successor must be called. |
5100 | // We will cancel the retry request. | 5128 | // We will cancel the retry request. |
5101 | struct SendNotifyContext *old_notify_ctx; | 5129 | struct SendNotifyContext *old_notify_ctx; |
5130 | |||
5102 | old_notify_ctx = GNUNET_SCHEDULER_cancel(send_notify_new_successor_retry_task); | 5131 | old_notify_ctx = GNUNET_SCHEDULER_cancel(send_notify_new_successor_retry_task); |
5103 | GNUNET_free (old_notify_ctx->successor_trail); | 5132 | GNUNET_free (old_notify_ctx->successor_trail); |
5104 | GNUNET_free (old_notify_ctx); | 5133 | GNUNET_free (old_notify_ctx); |
@@ -5106,28 +5135,51 @@ send_notify_new_successor (void *cls) | |||
5106 | } | 5135 | } |
5107 | 5136 | ||
5108 | ctx->num_retries_scheduled++; | 5137 | ctx->num_retries_scheduled++; |
5109 | send_notify_new_successor_retry_task = GNUNET_SCHEDULER_add_delayed(notify_successor_retry_time, | 5138 | send_notify_new_successor_retry_task |
5110 | &send_notify_new_successor, | 5139 | = GNUNET_SCHEDULER_add_delayed (notify_successor_retry_time, |
5111 | cls); | 5140 | &send_notify_new_successor, |
5141 | cls); | ||
5112 | } | 5142 | } |
5113 | 5143 | ||
5114 | /* | 5144 | |
5115 | * Core handle for p2p verify successor result messages. | 5145 | /** |
5146 | * Check integrity of verify successor result messages. | ||
5147 | * | ||
5116 | * @param cls closure | 5148 | * @param cls closure |
5117 | * @param message message | 5149 | * @param vsrm the message |
5118 | * @param peer peer identity this notification is about | 5150 | * @return #GNUNET_OK if @a vrsm is well-formed |
5119 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
5120 | */ | 5151 | */ |
5121 | static int | 5152 | static int |
5122 | handle_dht_p2p_verify_successor_result(void *cls, | 5153 | check_dht_p2p_verify_successor_result (void *cls, |
5123 | const struct GNUNET_PeerIdentity *peer, | 5154 | const struct PeerVerifySuccessorResultMessage *vsrm) |
5124 | const struct GNUNET_MessageHeader *message) | ||
5125 | { | 5155 | { |
5126 | const struct PeerVerifySuccessorResultMessage *vsrm; | 5156 | size_t msize; |
5157 | |||
5158 | msize = ntohs (vsrm->header.size); | ||
5159 | if ((msize - sizeof (struct PeerVerifySuccessorResultMessage)) % | ||
5160 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
5161 | { | ||
5162 | GNUNET_break_op (0); | ||
5163 | return GNUNET_SYSERR; | ||
5164 | } | ||
5165 | return GNUNET_OK; | ||
5166 | } | ||
5167 | |||
5168 | |||
5169 | /** | ||
5170 | * Core handle for p2p verify successor result messages. | ||
5171 | * | ||
5172 | * @param cls closure | ||
5173 | * @param vsrm the message | ||
5174 | */ | ||
5175 | static void | ||
5176 | handle_dht_p2p_verify_successor_result (void *cls, | ||
5177 | const struct PeerVerifySuccessorResultMessage *vsrm) | ||
5178 | { | ||
5127 | enum GDS_ROUTING_trail_direction trail_direction; | 5179 | enum GDS_ROUTING_trail_direction trail_direction; |
5128 | struct GNUNET_PeerIdentity querying_peer; | 5180 | struct GNUNET_PeerIdentity querying_peer; |
5129 | struct GNUNET_HashCode trail_id; | 5181 | struct GNUNET_HashCode trail_id; |
5130 | struct GNUNET_PeerIdentity *next_hop; | 5182 | const struct GNUNET_PeerIdentity *next_hop; |
5131 | struct FriendInfo *target_friend; | 5183 | struct FriendInfo *target_friend; |
5132 | struct GNUNET_PeerIdentity probable_successor; | 5184 | struct GNUNET_PeerIdentity probable_successor; |
5133 | struct GNUNET_PeerIdentity current_successor; | 5185 | struct GNUNET_PeerIdentity current_successor; |
@@ -5135,26 +5187,13 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
5135 | unsigned int trail_length; | 5187 | unsigned int trail_length; |
5136 | size_t msize; | 5188 | size_t msize; |
5137 | 5189 | ||
5138 | msize = ntohs (message->size); | 5190 | msize = ntohs (vsrm->header.size); |
5139 | if (msize < sizeof (struct PeerVerifySuccessorResultMessage)) | 5191 | trail_length = (msize - sizeof (struct PeerVerifySuccessorResultMessage)) |
5140 | { | 5192 | / sizeof (struct GNUNET_PeerIdentity); |
5141 | GNUNET_break_op (0); | ||
5142 | return GNUNET_YES; | ||
5143 | } | ||
5144 | |||
5145 | vsrm = (const struct PeerVerifySuccessorResultMessage *) message; | ||
5146 | if ((msize - sizeof (struct PeerVerifySuccessorResultMessage)) % | ||
5147 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
5148 | { | ||
5149 | GNUNET_break_op (0); | ||
5150 | return GNUNET_OK; | ||
5151 | } | ||
5152 | trail_length = (msize - sizeof (struct PeerVerifySuccessorResultMessage))/ | ||
5153 | sizeof (struct GNUNET_PeerIdentity); | ||
5154 | 5193 | ||
5155 | GNUNET_STATISTICS_update (GDS_stats, | 5194 | GNUNET_STATISTICS_update (GDS_stats, |
5156 | gettext_noop | 5195 | gettext_noop ("# Bytes received from other peers"), |
5157 | ("# Bytes received from other peers"), msize, | 5196 | msize, |
5158 | GNUNET_NO); | 5197 | GNUNET_NO); |
5159 | 5198 | ||
5160 | trail = (const struct GNUNET_PeerIdentity *) &vsrm[1]; | 5199 | trail = (const struct GNUNET_PeerIdentity *) &vsrm[1]; |
@@ -5164,25 +5203,30 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
5164 | probable_successor = vsrm->probable_successor; | 5203 | probable_successor = vsrm->probable_successor; |
5165 | current_successor = vsrm->current_successor; | 5204 | current_successor = vsrm->current_successor; |
5166 | 5205 | ||
5167 | /* I am the querying_peer. */ | 5206 | /* Am I the querying_peer? */ |
5168 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) | 5207 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, |
5208 | &my_identity))) | ||
5169 | { | 5209 | { |
5170 | /* Cancel Retry Task */ | 5210 | /* Cancel Retry Task */ |
5171 | if (NULL != send_verify_successor_retry_task) | 5211 | if (NULL != send_verify_successor_retry_task) |
5172 | { | 5212 | { |
5173 | struct VerifySuccessorContext *ctx; | 5213 | struct VerifySuccessorContext *ctx; |
5174 | ctx = GNUNET_SCHEDULER_cancel(send_verify_successor_retry_task); | 5214 | |
5175 | GNUNET_free(ctx); | 5215 | ctx = GNUNET_SCHEDULER_cancel (send_verify_successor_retry_task); |
5216 | GNUNET_free (ctx); | ||
5176 | send_verify_successor_retry_task = NULL; | 5217 | send_verify_successor_retry_task = NULL; |
5177 | } | 5218 | } |
5178 | compare_and_update_successor (current_successor, | 5219 | compare_and_update_successor (¤t_successor, |
5179 | probable_successor, trail, trail_length); | 5220 | &probable_successor, |
5180 | return GNUNET_OK; | 5221 | trail, |
5222 | trail_length); | ||
5223 | return; | ||
5181 | } | 5224 | } |
5182 | 5225 | ||
5183 | /*If you are not the querying peer then pass on the message */ | 5226 | /*If you are not the querying peer then pass on the message */ |
5184 | if(NULL == (next_hop = | 5227 | if(NULL == (next_hop = |
5185 | GDS_ROUTING_get_next_hop (trail_id, trail_direction))) | 5228 | GDS_ROUTING_get_next_hop (&trail_id, |
5229 | trail_direction))) | ||
5186 | { | 5230 | { |
5187 | /* Here it may happen that source peer has found a new successor, and removed | 5231 | /* Here it may happen that source peer has found a new successor, and removed |
5188 | the trail, Hence no entry found in the routing table. Fail silently.*/ | 5232 | the trail, Hence no entry found in the routing table. Fail silently.*/ |
@@ -5191,38 +5235,61 @@ handle_dht_p2p_verify_successor_result(void *cls, | |||
5191 | GNUNET_h2s (&trail_id), | 5235 | GNUNET_h2s (&trail_id), |
5192 | __LINE__); | 5236 | __LINE__); |
5193 | GNUNET_break_op(0); | 5237 | GNUNET_break_op(0); |
5194 | return GNUNET_OK; | 5238 | return; |
5195 | } | 5239 | } |
5196 | if (NULL == (target_friend = | 5240 | if (NULL == (target_friend = |
5197 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))) | 5241 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))) |
5198 | { | 5242 | { |
5199 | GNUNET_break_op(0); | 5243 | GNUNET_break_op(0); |
5200 | return GNUNET_OK; | 5244 | return; |
5201 | } | 5245 | } |
5202 | GDS_NEIGHBOURS_send_verify_successor_result (querying_peer, | 5246 | GDS_NEIGHBOURS_send_verify_successor_result (&querying_peer, |
5203 | vsrm->current_successor, | 5247 | &vsrm->current_successor, |
5204 | probable_successor, trail_id, | 5248 | &probable_successor, |
5249 | &trail_id, | ||
5205 | trail, | 5250 | trail, |
5206 | trail_length, | 5251 | trail_length, |
5207 | trail_direction, target_friend); | 5252 | trail_direction, |
5208 | return GNUNET_OK; | 5253 | target_friend); |
5209 | } | 5254 | } |
5210 | 5255 | ||
5211 | 5256 | ||
5212 | /* | 5257 | /** |
5213 | * Core handle for p2p notify new successor messages. | 5258 | * Check integrity of p2p notify new successor messages. |
5259 | * | ||
5214 | * @param cls closure | 5260 | * @param cls closure |
5215 | * @param message message | 5261 | * @param nsm the message |
5216 | * @param peer peer identity this notification is about | 5262 | * @return #GNUNET_OK if @a nsm is well-formed |
5217 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
5218 | */ | 5263 | */ |
5219 | static int | 5264 | static int |
5220 | handle_dht_p2p_notify_new_successor(void *cls, | 5265 | check_dht_p2p_notify_new_successor (void *cls, |
5221 | const struct GNUNET_PeerIdentity *peer, | 5266 | const struct PeerNotifyNewSuccessorMessage *nsm) |
5222 | const struct GNUNET_MessageHeader *message) | ||
5223 | { | 5267 | { |
5224 | const struct PeerNotifyNewSuccessorMessage *nsm; | 5268 | size_t msize; |
5225 | struct GNUNET_PeerIdentity *trail; | 5269 | |
5270 | msize = ntohs (nsm->header.size); | ||
5271 | if ((msize - sizeof (struct PeerNotifyNewSuccessorMessage)) % | ||
5272 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
5273 | { | ||
5274 | GNUNET_break_op (0); | ||
5275 | return GNUNET_SYSERR; | ||
5276 | } | ||
5277 | return GNUNET_OK; | ||
5278 | } | ||
5279 | |||
5280 | |||
5281 | /** | ||
5282 | * Core handle for p2p notify new successor messages. | ||
5283 | * | ||
5284 | * @param cls closure | ||
5285 | * @param nsm the message | ||
5286 | */ | ||
5287 | static void | ||
5288 | handle_dht_p2p_notify_new_successor (void *cls, | ||
5289 | const struct PeerNotifyNewSuccessorMessage *nsm) | ||
5290 | { | ||
5291 | struct FriendInfo *friend = cls; | ||
5292 | const struct GNUNET_PeerIdentity *trail; | ||
5226 | struct GNUNET_PeerIdentity source; | 5293 | struct GNUNET_PeerIdentity source; |
5227 | struct GNUNET_PeerIdentity new_successor; | 5294 | struct GNUNET_PeerIdentity new_successor; |
5228 | struct GNUNET_HashCode trail_id; | 5295 | struct GNUNET_HashCode trail_id; |
@@ -5232,47 +5299,39 @@ handle_dht_p2p_notify_new_successor(void *cls, | |||
5232 | size_t msize; | 5299 | size_t msize; |
5233 | uint32_t trail_length; | 5300 | uint32_t trail_length; |
5234 | 5301 | ||
5235 | msize = ntohs (message->size); | 5302 | msize = ntohs (nsm->header.size); |
5236 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) | ||
5237 | { | ||
5238 | GNUNET_break_op (0); | ||
5239 | return GNUNET_YES; | ||
5240 | } | ||
5241 | nsm = (const struct PeerNotifyNewSuccessorMessage *) message; | ||
5242 | if ((msize - sizeof (struct PeerNotifyNewSuccessorMessage)) % | ||
5243 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
5244 | { | ||
5245 | GNUNET_break_op (0); | ||
5246 | return GNUNET_OK; | ||
5247 | } | ||
5248 | trail_length = (msize - sizeof (struct PeerNotifyNewSuccessorMessage))/ | 5303 | trail_length = (msize - sizeof (struct PeerNotifyNewSuccessorMessage))/ |
5249 | sizeof (struct GNUNET_PeerIdentity); | 5304 | sizeof (struct GNUNET_PeerIdentity); |
5250 | GNUNET_STATISTICS_update (GDS_stats, | 5305 | GNUNET_STATISTICS_update (GDS_stats, |
5251 | gettext_noop | 5306 | gettext_noop ("# Bytes received from other peers"), |
5252 | ("# Bytes received from other peers"), msize, | 5307 | msize, |
5253 | GNUNET_NO); | 5308 | GNUNET_NO); |
5254 | 5309 | trail = (const struct GNUNET_PeerIdentity *) &nsm[1]; | |
5255 | trail = (struct GNUNET_PeerIdentity *) &nsm[1]; | 5310 | source = nsm->source_peer; |
5256 | source = nsm->source_peer; | ||
5257 | new_successor = nsm->new_successor; | 5311 | new_successor = nsm->new_successor; |
5258 | trail_id = nsm->trail_id; | 5312 | trail_id = nsm->trail_id; |
5259 | 5313 | ||
5260 | /* I am the new_successor to source_peer. */ | 5314 | /* I am the new_successor to source_peer. */ |
5261 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &new_successor)) | 5315 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
5316 | &new_successor)) | ||
5262 | { | 5317 | { |
5263 | if(trail_length > 0) | 5318 | if (trail_length > 0) |
5264 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail[trail_length - 1], | 5319 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&trail[trail_length - 1], |
5265 | peer)); | 5320 | friend->id)); |
5266 | else | 5321 | else |
5267 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity(&source, peer)); | 5322 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&source, |
5323 | friend->id)); | ||
5268 | 5324 | ||
5269 | compare_and_update_predecessor (source, trail, trail_length); | 5325 | compare_and_update_predecessor (&source, |
5270 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); | 5326 | trail, |
5327 | trail_length); | ||
5328 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
5329 | friend->id); | ||
5271 | GNUNET_assert (NULL != target_friend); | 5330 | GNUNET_assert (NULL != target_friend); |
5272 | GDS_NEIGHBOURS_send_notify_succcessor_confirmation (trail_id, | 5331 | GDS_NEIGHBOURS_send_notify_succcessor_confirmation (&trail_id, |
5273 | GDS_ROUTING_DEST_TO_SRC, | 5332 | GDS_ROUTING_DEST_TO_SRC, |
5274 | target_friend); | 5333 | target_friend); |
5275 | return GNUNET_OK; | 5334 | return; |
5276 | } | 5335 | } |
5277 | 5336 | ||
5278 | GNUNET_assert(trail_length > 0); | 5337 | GNUNET_assert(trail_length > 0); |
@@ -5282,82 +5341,74 @@ handle_dht_p2p_notify_new_successor(void *cls, | |||
5282 | { | 5341 | { |
5283 | DEBUG ("No entry found in trail\n"); | 5342 | DEBUG ("No entry found in trail\n"); |
5284 | GNUNET_break_op (0); | 5343 | GNUNET_break_op (0); |
5285 | return GNUNET_SYSERR; | 5344 | return; |
5286 | } | 5345 | } |
5287 | if((trail_length + 1) == my_index) | 5346 | if((trail_length + 1) == my_index) |
5288 | { | 5347 | { |
5289 | DEBUG ("Found twice in trail.\n"); | 5348 | DEBUG ("Found twice in trail.\n"); |
5290 | GNUNET_break_op (0); | 5349 | GNUNET_break_op (0); |
5291 | return GNUNET_SYSERR; | 5350 | return; |
5292 | } | 5351 | } |
5293 | if ((trail_length-1) == my_index) | 5352 | if ((trail_length-1) == my_index) |
5294 | next_hop = new_successor; | 5353 | next_hop = new_successor; |
5295 | else | 5354 | else |
5296 | next_hop = trail[my_index + 1]; | 5355 | next_hop = trail[my_index + 1]; |
5297 | 5356 | ||
5298 | GDS_ROUTING_add(trail_id, *peer, next_hop); | 5357 | GDS_ROUTING_add (&trail_id, |
5299 | target_friend = | 5358 | friend->id, |
5300 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); | 5359 | &next_hop); |
5360 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
5361 | &next_hop); | ||
5301 | if (NULL == target_friend) | 5362 | if (NULL == target_friend) |
5302 | { | 5363 | { |
5303 | GNUNET_break(0); | 5364 | GNUNET_break(0); |
5304 | return GNUNET_OK; | 5365 | return; |
5305 | } | 5366 | } |
5306 | GDS_NEIGHBOURS_send_notify_new_successor (source, new_successor, trail, | 5367 | GDS_NEIGHBOURS_send_notify_new_successor (&source, |
5368 | &new_successor, | ||
5369 | trail, | ||
5307 | trail_length, | 5370 | trail_length, |
5308 | trail_id, target_friend); | 5371 | &trail_id, |
5309 | return GNUNET_OK; | 5372 | target_friend); |
5310 | |||
5311 | } | 5373 | } |
5312 | 5374 | ||
5313 | 5375 | ||
5314 | /** | 5376 | /** |
5315 | * Core handler for P2P notify successor message | 5377 | * Core handler for P2P notify successor message |
5378 | * | ||
5316 | * @param cls closure | 5379 | * @param cls closure |
5317 | * @param message message | 5380 | * @param notify_confirmation the message |
5318 | * @param peer peer identity this notification is about | ||
5319 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
5320 | */ | 5381 | */ |
5321 | static int | 5382 | static void |
5322 | handle_dht_p2p_notify_succ_confirmation (void *cls, | 5383 | handle_dht_p2p_notify_succ_confirmation (void *cls, |
5323 | const struct GNUNET_PeerIdentity *peer, | 5384 | const struct PeerNotifyConfirmationMessage *notify_confirmation) |
5324 | const struct GNUNET_MessageHeader *message) | ||
5325 | { | 5385 | { |
5326 | const struct PeerNotifyConfirmationMessage *notify_confirmation; | ||
5327 | enum GDS_ROUTING_trail_direction trail_direction; | 5386 | enum GDS_ROUTING_trail_direction trail_direction; |
5328 | struct GNUNET_HashCode trail_id; | 5387 | struct GNUNET_HashCode trail_id; |
5329 | struct FriendInfo *target_friend; | 5388 | struct FriendInfo *target_friend; |
5330 | struct GNUNET_PeerIdentity *next_hop; | 5389 | const struct GNUNET_PeerIdentity *next_hop; |
5331 | size_t msize; | 5390 | |
5332 | |||
5333 | msize = ntohs (message->size); | ||
5334 | |||
5335 | if (msize != sizeof (struct PeerNotifyConfirmationMessage)) | ||
5336 | { | ||
5337 | GNUNET_break_op (0); | ||
5338 | return GNUNET_OK; | ||
5339 | } | ||
5340 | GNUNET_STATISTICS_update (GDS_stats, | 5391 | GNUNET_STATISTICS_update (GDS_stats, |
5341 | gettext_noop | 5392 | gettext_noop ("# Bytes received from other peers"), |
5342 | ("# Bytes received from other peers"), msize, | 5393 | ntohs (notify_confirmation->header.size), |
5343 | GNUNET_NO); | 5394 | GNUNET_NO); |
5344 | |||
5345 | notify_confirmation = (const struct PeerNotifyConfirmationMessage *) message; | ||
5346 | trail_direction = ntohl (notify_confirmation->trail_direction); | 5395 | trail_direction = ntohl (notify_confirmation->trail_direction); |
5347 | trail_id = notify_confirmation->trail_id; | 5396 | trail_id = notify_confirmation->trail_id; |
5348 | 5397 | ||
5349 | next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction); | 5398 | next_hop = GDS_ROUTING_get_next_hop (&trail_id, |
5399 | trail_direction); | ||
5350 | if (NULL == next_hop) | 5400 | if (NULL == next_hop) |
5351 | { | 5401 | { |
5352 | /* The source of notify new successor, might have found even a better | 5402 | /* The source of notify new successor, might have found even a better |
5353 | successor. In that case it send a trail teardown message, and hence, | 5403 | successor. In that case it send a trail teardown message, and hence, |
5354 | the next hop is NULL. */ | 5404 | the next hop is NULL. */ |
5355 | //Fixme: Add some print to confirm the above theory. | 5405 | //Fixme: Add some print to confirm the above theory. |
5356 | return GNUNET_OK; | 5406 | return; |
5357 | } | 5407 | } |
5358 | 5408 | ||
5359 | /* I peer which sent the notify successor message to the successor. */ | 5409 | /* I peer which sent the notify successor message to the successor. */ |
5360 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &my_identity)) | 5410 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, |
5411 | &my_identity)) | ||
5361 | { | 5412 | { |
5362 | /* | 5413 | /* |
5363 | * Schedule another round of verify sucessor with your current successor | 5414 | * Schedule another round of verify sucessor with your current successor |
@@ -5380,41 +5431,64 @@ handle_dht_p2p_notify_succ_confirmation (void *cls, | |||
5380 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us + | 5431 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us + |
5381 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 5432 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
5382 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us); | 5433 | DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us); |
5383 | send_verify_successor_task = | 5434 | send_verify_successor_task |
5384 | GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time, | 5435 | = GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time, |
5385 | &send_verify_successor_message, | 5436 | &send_verify_successor_message, |
5386 | NULL); | 5437 | NULL); |
5387 | } | 5438 | } |
5388 | } | 5439 | } |
5389 | else | 5440 | else |
5390 | { | 5441 | { |
5391 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 5442 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5443 | next_hop); | ||
5392 | if (NULL == target_friend) | 5444 | if (NULL == target_friend) |
5393 | { | 5445 | { |
5394 | DEBUG ("\n friend not found, line number = %d",__LINE__); | 5446 | DEBUG ("\n friend not found, line number = %d", |
5395 | return GNUNET_SYSERR; | 5447 | __LINE__); |
5448 | return; | ||
5396 | } | 5449 | } |
5397 | GDS_NEIGHBOURS_send_notify_succcessor_confirmation (trail_id, | 5450 | GDS_NEIGHBOURS_send_notify_succcessor_confirmation (&trail_id, |
5398 | GDS_ROUTING_DEST_TO_SRC, | 5451 | GDS_ROUTING_DEST_TO_SRC, |
5399 | target_friend); | 5452 | target_friend); |
5400 | } | 5453 | } |
5401 | return GNUNET_OK; | ||
5402 | } | 5454 | } |
5403 | 5455 | ||
5404 | 5456 | ||
5405 | /** | 5457 | /** |
5406 | * Core handler for P2P trail rejection message | 5458 | * Check integrity of P2P trail rejection message |
5459 | * | ||
5407 | * @param cls closure | 5460 | * @param cls closure |
5408 | * @param message message | 5461 | * @param trail_rejection the message |
5409 | * @param peer peer identity this notification is about | 5462 | * @return #GNUNET_OK if @a trail_rejection is well-formed |
5410 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
5411 | */ | 5463 | */ |
5412 | static int | 5464 | static int |
5413 | handle_dht_p2p_trail_setup_rejection (void *cls, | 5465 | check_dht_p2p_trail_setup_rejection (void *cls, |
5414 | const struct GNUNET_PeerIdentity *peer, | 5466 | const struct PeerTrailRejectionMessage *trail_rejection) |
5415 | const struct GNUNET_MessageHeader *message) | ||
5416 | { | 5467 | { |
5417 | const struct PeerTrailRejectionMessage *trail_rejection; | 5468 | size_t msize; |
5469 | |||
5470 | msize = ntohs (trail_rejection->header.size); | ||
5471 | if ((msize - sizeof (struct PeerTrailRejectionMessage)) % | ||
5472 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
5473 | { | ||
5474 | GNUNET_break_op (0); | ||
5475 | return GNUNET_SYSERR; | ||
5476 | } | ||
5477 | return GNUNET_OK; | ||
5478 | } | ||
5479 | |||
5480 | |||
5481 | /** | ||
5482 | * Core handler for P2P trail rejection message | ||
5483 | * | ||
5484 | * @param cls closure | ||
5485 | * @param trail_rejection the message | ||
5486 | */ | ||
5487 | static void | ||
5488 | handle_dht_p2p_trail_setup_rejection (void *cls, | ||
5489 | const struct PeerTrailRejectionMessage *trail_rejection) | ||
5490 | { | ||
5491 | struct FriendInfo *friend = cls; | ||
5418 | unsigned int trail_length; | 5492 | unsigned int trail_length; |
5419 | const struct GNUNET_PeerIdentity *trail_peer_list; | 5493 | const struct GNUNET_PeerIdentity *trail_peer_list; |
5420 | struct FriendInfo *target_friend; | 5494 | struct FriendInfo *target_friend; |
@@ -5424,93 +5498,93 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5424 | struct GNUNET_PeerIdentity source; | 5498 | struct GNUNET_PeerIdentity source; |
5425 | uint64_t ultimate_destination_finger_value; | 5499 | uint64_t ultimate_destination_finger_value; |
5426 | unsigned int is_predecessor; | 5500 | unsigned int is_predecessor; |
5501 | struct Closest_Peer successor; | ||
5427 | size_t msize; | 5502 | size_t msize; |
5428 | 5503 | ||
5429 | msize = ntohs (message->size); | 5504 | msize = ntohs (trail_rejection->header.size); |
5430 | if (msize < sizeof (struct PeerTrailRejectionMessage)) | ||
5431 | { | ||
5432 | GNUNET_break_op (0); | ||
5433 | return GNUNET_YES; | ||
5434 | } | ||
5435 | trail_rejection = (const struct PeerTrailRejectionMessage *) message; | ||
5436 | if ((msize - sizeof (struct PeerTrailRejectionMessage)) % | ||
5437 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
5438 | { | ||
5439 | GNUNET_break_op (0); | ||
5440 | return GNUNET_OK; | ||
5441 | } | ||
5442 | trail_length = (msize - sizeof (struct PeerTrailRejectionMessage))/ | 5505 | trail_length = (msize - sizeof (struct PeerTrailRejectionMessage))/ |
5443 | sizeof (struct GNUNET_PeerIdentity); | 5506 | sizeof (struct GNUNET_PeerIdentity); |
5444 | GNUNET_STATISTICS_update (GDS_stats, | 5507 | GNUNET_STATISTICS_update (GDS_stats, |
5445 | gettext_noop | 5508 | gettext_noop ("# Bytes received from other peers"), |
5446 | ("# Bytes received from other peers"), msize, | 5509 | msize, |
5447 | GNUNET_NO); | 5510 | GNUNET_NO); |
5448 | 5511 | ||
5449 | trail_peer_list = (const struct GNUNET_PeerIdentity *)&trail_rejection[1]; | 5512 | trail_peer_list = (const struct GNUNET_PeerIdentity *) &trail_rejection[1]; |
5450 | is_predecessor = ntohl (trail_rejection->is_predecessor); | 5513 | is_predecessor = ntohl (trail_rejection->is_predecessor); |
5451 | congestion_timeout = trail_rejection->congestion_time; | 5514 | congestion_timeout = trail_rejection->congestion_time; |
5452 | source = trail_rejection->source_peer; | 5515 | source = trail_rejection->source_peer; |
5453 | trail_id = trail_rejection->trail_id; | 5516 | trail_id = trail_rejection->trail_id; |
5454 | ultimate_destination_finger_value = | 5517 | ultimate_destination_finger_value |
5455 | GNUNET_ntohll (trail_rejection->ultimate_destination_finger_value); | 5518 | = GNUNET_ntohll (trail_rejection->ultimate_destination_finger_value); |
5456 | /* First set the congestion time of the friend that sent you this message. */ | 5519 | /* First set the congestion time of the friend that sent you this message. */ |
5457 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); | 5520 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5521 | friend->id); | ||
5458 | if (NULL == target_friend) | 5522 | if (NULL == target_friend) |
5459 | { | 5523 | { |
5460 | DEBUG ("\nLINE = %d ,No friend found.",__LINE__); | 5524 | DEBUG ("\nLINE = %d ,No friend found.",__LINE__); |
5461 | GNUNET_break(0); | 5525 | GNUNET_break(0); |
5462 | return GNUNET_OK; | 5526 | return; |
5463 | } | 5527 | } |
5464 | target_friend->congestion_timestamp = | 5528 | target_friend->congestion_timestamp |
5465 | GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), | 5529 | = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), |
5466 | congestion_timeout); | 5530 | congestion_timeout); |
5467 | 5531 | ||
5468 | /* I am the source peer which wants to setup the trail. Do nothing. | 5532 | /* I am the source peer which wants to setup the trail. Do nothing. |
5469 | * send_find_finger_trail_task is scheduled periodically.*/ | 5533 | * send_find_finger_trail_task is scheduled periodically.*/ |
5470 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &source))) | 5534 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &source))) |
5471 | return GNUNET_OK; | 5535 | return; |
5472 | 5536 | ||
5473 | /* If I am congested then pass this message to peer before me in trail. */ | 5537 | /* If I am congested then pass this message to peer before me in trail. */ |
5474 | if(GNUNET_YES == GDS_ROUTING_threshold_reached()) | 5538 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) |
5475 | { | 5539 | { |
5476 | /* First remove yourself from the trail. */ | 5540 | /* First remove yourself from the trail. */ |
5477 | unsigned int new_trail_length = trail_length - 1; | 5541 | unsigned int new_trail_length = trail_length - 1; |
5478 | struct GNUNET_PeerIdentity trail[new_trail_length]; | 5542 | struct GNUNET_PeerIdentity trail[new_trail_length]; |
5479 | 5543 | ||
5480 | GNUNET_memcpy (trail, trail_peer_list, new_trail_length * sizeof(struct GNUNET_PeerIdentity)); | 5544 | GNUNET_memcpy (trail, |
5545 | trail_peer_list, | ||
5546 | new_trail_length * sizeof(struct GNUNET_PeerIdentity)); | ||
5481 | if (0 == trail_length) | 5547 | if (0 == trail_length) |
5482 | next_peer = source; | 5548 | next_peer = source; |
5483 | else | 5549 | else |
5484 | next_peer = trail[new_trail_length-1]; | 5550 | next_peer = trail[new_trail_length-1]; |
5485 | 5551 | ||
5486 | target_friend = | 5552 | target_friend |
5487 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer); | 5553 | = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5554 | &next_peer); | ||
5488 | if (NULL == target_friend) | 5555 | if (NULL == target_friend) |
5489 | { | 5556 | { |
5490 | DEBUG ("\nLINE = %d ,No friend found.",__LINE__); | 5557 | DEBUG ("\nLINE = %d ,No friend found.", |
5558 | __LINE__); | ||
5491 | GNUNET_break(0); | 5559 | GNUNET_break(0); |
5492 | return GNUNET_OK; | 5560 | return; |
5493 | } | 5561 | } |
5494 | GDS_NEIGHBOURS_send_trail_rejection (source, | 5562 | GDS_NEIGHBOURS_send_trail_rejection (&source, |
5495 | ultimate_destination_finger_value, | 5563 | ultimate_destination_finger_value, |
5496 | my_identity, is_predecessor, | 5564 | &my_identity, |
5497 | trail, new_trail_length, trail_id, | 5565 | is_predecessor, |
5498 | target_friend, CONGESTION_TIMEOUT); | 5566 | trail, |
5499 | return GNUNET_OK; | 5567 | new_trail_length, |
5568 | &trail_id, | ||
5569 | target_friend, | ||
5570 | CONGESTION_TIMEOUT); | ||
5571 | return; | ||
5500 | } | 5572 | } |
5501 | 5573 | ||
5502 | struct Closest_Peer successor; | 5574 | successor = find_local_best_known_next_hop (ultimate_destination_finger_value, |
5503 | successor = find_local_best_known_next_hop (ultimate_destination_finger_value, is_predecessor); | 5575 | is_predecessor); |
5504 | 5576 | ||
5505 | /* Am I the final destination? */ | 5577 | /* Am I the final destination? */ |
5506 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination, | 5578 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination, |
5507 | &my_identity))) | 5579 | &my_identity)) |
5508 | { | 5580 | { |
5509 | /*Here you are already part of trail. Copy the trail removing yourself. */ | 5581 | /*Here you are already part of trail. Copy the trail removing yourself. */ |
5510 | unsigned int new_trail_length = trail_length - 1; | 5582 | unsigned int new_trail_length = trail_length - 1; |
5511 | struct GNUNET_PeerIdentity trail[new_trail_length]; | 5583 | struct GNUNET_PeerIdentity trail[new_trail_length]; |
5512 | 5584 | ||
5513 | GNUNET_memcpy (trail, trail_peer_list, new_trail_length * sizeof(struct GNUNET_PeerIdentity)); | 5585 | GNUNET_memcpy (trail, |
5586 | trail_peer_list, | ||
5587 | new_trail_length * sizeof(struct GNUNET_PeerIdentity)); | ||
5514 | 5588 | ||
5515 | if (0 == new_trail_length) | 5589 | if (0 == new_trail_length) |
5516 | next_peer = source; | 5590 | next_peer = source; |
@@ -5518,79 +5592,67 @@ handle_dht_p2p_trail_setup_rejection (void *cls, | |||
5518 | { | 5592 | { |
5519 | next_peer = trail[new_trail_length-1]; | 5593 | next_peer = trail[new_trail_length-1]; |
5520 | } | 5594 | } |
5521 | target_friend = | 5595 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5522 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer); | 5596 | &next_peer); |
5523 | 5597 | ||
5524 | if (NULL == target_friend) | 5598 | if (NULL == target_friend) |
5525 | { | 5599 | { |
5526 | DEBUG ("\nLINE = %d ,No friend found.",__LINE__); | 5600 | DEBUG ("\nLINE = %d ,No friend found.", |
5601 | __LINE__); | ||
5527 | GNUNET_break(0); | 5602 | GNUNET_break(0); |
5528 | return GNUNET_OK; | 5603 | return; |
5529 | } | 5604 | } |
5530 | GDS_NEIGHBOURS_send_trail_setup_result (source, | 5605 | GDS_NEIGHBOURS_send_trail_setup_result (&source, |
5531 | my_identity, | 5606 | &my_identity, |
5532 | target_friend, new_trail_length, | 5607 | target_friend, |
5608 | new_trail_length, | ||
5533 | trail, | 5609 | trail, |
5534 | is_predecessor, | 5610 | is_predecessor, |
5535 | ultimate_destination_finger_value, | 5611 | ultimate_destination_finger_value, |
5536 | trail_id); | 5612 | &trail_id); |
5613 | return; | ||
5537 | } | 5614 | } |
5538 | else | 5615 | /* Here I was already part of trail. So no need to add. */ |
5616 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
5617 | &successor.next_hop); | ||
5618 | if (NULL == target_friend) | ||
5539 | { | 5619 | { |
5540 | /* Here I was already part of trail. So no need to add. */ | 5620 | DEBUG ("\nLINE = %d ,No friend found.",__LINE__); |
5541 | target_friend = | 5621 | GNUNET_break (0); |
5542 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5622 | return; |
5543 | &successor.next_hop); | ||
5544 | if (NULL == target_friend) | ||
5545 | { | ||
5546 | DEBUG ("\nLINE = %d ,No friend found.",__LINE__); | ||
5547 | GNUNET_break(0); | ||
5548 | return GNUNET_OK; | ||
5549 | } | ||
5550 | |||
5551 | GDS_NEIGHBOURS_send_trail_setup (source, | ||
5552 | ultimate_destination_finger_value, | ||
5553 | successor.best_known_destination, | ||
5554 | target_friend, trail_length, trail_peer_list, | ||
5555 | is_predecessor, trail_id, | ||
5556 | successor.trail_id); | ||
5557 | } | 5623 | } |
5558 | return GNUNET_OK; | 5624 | GDS_NEIGHBOURS_send_trail_setup (&source, |
5625 | ultimate_destination_finger_value, | ||
5626 | &successor.best_known_destination, | ||
5627 | target_friend, | ||
5628 | trail_length, | ||
5629 | trail_peer_list, | ||
5630 | is_predecessor, | ||
5631 | &trail_id, | ||
5632 | &successor.trail_id); | ||
5559 | } | 5633 | } |
5560 | 5634 | ||
5561 | 5635 | ||
5562 | /** | 5636 | /** |
5563 | * Core handler for trail teardown message. | 5637 | * Core handler for trail teardown message. |
5638 | * | ||
5564 | * @param cls closure | 5639 | * @param cls closure |
5565 | * @param message message | 5640 | * @param trail_teardown the message |
5566 | * @param peer sender of this messsage. | ||
5567 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
5568 | */ | 5641 | */ |
5569 | static int | 5642 | static void |
5570 | handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer, | 5643 | handle_dht_p2p_trail_teardown (void *cls, |
5571 | const struct GNUNET_MessageHeader *message) | 5644 | const struct PeerTrailTearDownMessage *trail_teardown) |
5572 | { | 5645 | { |
5573 | const struct PeerTrailTearDownMessage *trail_teardown; | ||
5574 | enum GDS_ROUTING_trail_direction trail_direction; | 5646 | enum GDS_ROUTING_trail_direction trail_direction; |
5575 | struct GNUNET_HashCode trail_id; | 5647 | struct GNUNET_HashCode trail_id; |
5576 | struct GNUNET_PeerIdentity *next_hop; | 5648 | const struct GNUNET_PeerIdentity *next_hop; |
5577 | size_t msize; | 5649 | size_t msize; |
5578 | 5650 | ||
5579 | msize = ntohs (message->size); | 5651 | msize = ntohs (trail_teardown->header.size); |
5580 | |||
5581 | /* Here we pass only the trail id. */ | ||
5582 | if (msize != sizeof (struct PeerTrailTearDownMessage)) | ||
5583 | { | ||
5584 | GNUNET_break_op (0); | ||
5585 | return GNUNET_OK; | ||
5586 | } | ||
5587 | |||
5588 | GNUNET_STATISTICS_update (GDS_stats, | 5652 | GNUNET_STATISTICS_update (GDS_stats, |
5589 | gettext_noop | 5653 | gettext_noop ("# Bytes received from other peers"), |
5590 | ("# Bytes received from other peers"), msize, | 5654 | msize, |
5591 | GNUNET_NO); | 5655 | GNUNET_NO); |
5592 | |||
5593 | trail_teardown = (const struct PeerTrailTearDownMessage *) message; | ||
5594 | trail_direction = ntohl (trail_teardown->trail_direction); | 5656 | trail_direction = ntohl (trail_teardown->trail_direction); |
5595 | trail_id = trail_teardown->trail_id; | 5657 | trail_id = trail_teardown->trail_id; |
5596 | 5658 | ||
@@ -5598,55 +5660,80 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer | |||
5598 | /* Get the prev_hop for this trail by getting the next hop in opposite direction. */ | 5660 | /* Get the prev_hop for this trail by getting the next hop in opposite direction. */ |
5599 | #if 0 | 5661 | #if 0 |
5600 | GNUNET_assert (NULL != (prev_hop = | 5662 | GNUNET_assert (NULL != (prev_hop = |
5601 | GDS_ROUTING_get_next_hop (trail_id, !trail_direction))); | 5663 | GDS_ROUTING_get_next_hop (trail_id, ! trail_direction))); |
5602 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (prev_hop, peer)) | 5664 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (prev_hop, |
5665 | friend->id)) | ||
5603 | { | 5666 | { |
5604 | GNUNET_break (0); | 5667 | GNUNET_break (0); |
5605 | return GNUNET_SYSERR; | 5668 | return; |
5606 | } | 5669 | } |
5607 | #endif | 5670 | #endif |
5608 | 5671 | ||
5609 | next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction); | 5672 | next_hop = GDS_ROUTING_get_next_hop (&trail_id, |
5673 | trail_direction); | ||
5610 | if (NULL == next_hop) | 5674 | if (NULL == next_hop) |
5611 | { | 5675 | { |
5612 | DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line %u", | 5676 | DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line %u", |
5613 | GNUNET_i2s (&my_identity), | 5677 | GNUNET_i2s (&my_identity), |
5614 | GNUNET_h2s(&trail_id), | 5678 | GNUNET_h2s (&trail_id), |
5615 | __LINE__); | 5679 | __LINE__); |
5616 | GNUNET_break (0); | 5680 | GNUNET_break (0); |
5617 | return GNUNET_SYSERR; | 5681 | return; |
5618 | } | 5682 | } |
5619 | 5683 | ||
5620 | /* I am the next hop, which means I am the final destination. */ | 5684 | /* I am the next hop, which means I am the final destination. */ |
5621 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &my_identity)) | 5685 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &my_identity)) |
5622 | { | 5686 | { |
5623 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); | 5687 | GNUNET_assert (GNUNET_YES == |
5624 | return GNUNET_OK; | 5688 | GDS_ROUTING_remove_trail (&trail_id)); |
5689 | return; | ||
5625 | } | 5690 | } |
5626 | else | 5691 | /* If not final destination, then send a trail teardown message to next hop.*/ |
5692 | GNUNET_assert (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
5693 | next_hop)); | ||
5694 | GNUNET_assert (GNUNET_YES == | ||
5695 | GDS_ROUTING_remove_trail (&trail_id)); | ||
5696 | GDS_NEIGHBOURS_send_trail_teardown (&trail_id, | ||
5697 | trail_direction, | ||
5698 | next_hop); | ||
5699 | } | ||
5700 | |||
5701 | |||
5702 | /** | ||
5703 | * Check validity of p2p add trail message. | ||
5704 | * | ||
5705 | * @param cls closure | ||
5706 | * @param add_trail the message | ||
5707 | * @return #GNUNET_OK if @a add_trail is well-formed | ||
5708 | */ | ||
5709 | static int | ||
5710 | check_dht_p2p_add_trail (void *cls, | ||
5711 | const struct PeerAddTrailMessage *add_trail) | ||
5712 | { | ||
5713 | size_t msize; | ||
5714 | |||
5715 | msize = ntohs (add_trail->header.size); | ||
5716 | if ((msize - sizeof (struct PeerAddTrailMessage)) % | ||
5717 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
5627 | { | 5718 | { |
5628 | /* If not final destination, then send a trail teardown message to next hop.*/ | 5719 | GNUNET_break_op (0); |
5629 | GNUNET_assert (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop)); | 5720 | return GNUNET_SYSERR; |
5630 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); | ||
5631 | GDS_NEIGHBOURS_send_trail_teardown (&trail_id, trail_direction, next_hop); | ||
5632 | } | 5721 | } |
5633 | |||
5634 | return GNUNET_OK; | 5722 | return GNUNET_OK; |
5635 | } | 5723 | } |
5636 | 5724 | ||
5637 | 5725 | ||
5638 | /** | 5726 | /** |
5639 | * Core handle for p2p add trail message. | 5727 | * Core handle for p2p add trail message. |
5728 | * | ||
5640 | * @param cls closure | 5729 | * @param cls closure |
5641 | * @param message message | 5730 | * @param add_trail the message |
5642 | * @param peer peer identity this notification is about | ||
5643 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
5644 | */ | 5731 | */ |
5645 | static int | 5732 | static void |
5646 | handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | 5733 | handle_dht_p2p_add_trail (void *cls, |
5647 | const struct GNUNET_MessageHeader *message) | 5734 | const struct PeerAddTrailMessage *add_trail) |
5648 | { | 5735 | { |
5649 | const struct PeerAddTrailMessage *add_trail; | 5736 | struct FriendInfo *friend = cls; |
5650 | const struct GNUNET_PeerIdentity *trail; | 5737 | const struct GNUNET_PeerIdentity *trail; |
5651 | struct GNUNET_HashCode trail_id; | 5738 | struct GNUNET_HashCode trail_id; |
5652 | struct GNUNET_PeerIdentity destination_peer; | 5739 | struct GNUNET_PeerIdentity destination_peer; |
@@ -5656,38 +5743,25 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
5656 | unsigned int my_index; | 5743 | unsigned int my_index; |
5657 | size_t msize; | 5744 | size_t msize; |
5658 | 5745 | ||
5659 | msize = ntohs (message->size); | 5746 | msize = ntohs (add_trail->header.size); |
5660 | /* In this message we pass the whole trail from source to destination as we | 5747 | /* In this message we pass the whole trail from source to destination as we |
5661 | * are adding that trail.*/ | 5748 | * are adding that trail.*/ |
5662 | //FIXME: failed when run with 1000 pears. check why. | 5749 | //FIXME: failed when run with 1000 pears. check why. |
5663 | if (msize < sizeof (struct PeerAddTrailMessage)) | ||
5664 | { | ||
5665 | GNUNET_break_op (0); | ||
5666 | return GNUNET_OK; | ||
5667 | } | ||
5668 | |||
5669 | add_trail = (const struct PeerAddTrailMessage *) message; | ||
5670 | trail_length = (msize - sizeof (struct PeerAddTrailMessage))/ | 5750 | trail_length = (msize - sizeof (struct PeerAddTrailMessage))/ |
5671 | sizeof (struct GNUNET_PeerIdentity); | 5751 | sizeof (struct GNUNET_PeerIdentity); |
5672 | if ((msize - sizeof (struct PeerAddTrailMessage)) % | ||
5673 | sizeof (struct GNUNET_PeerIdentity) != 0) | ||
5674 | { | ||
5675 | GNUNET_break_op (0); | ||
5676 | return GNUNET_OK; | ||
5677 | } | ||
5678 | |||
5679 | GNUNET_STATISTICS_update (GDS_stats, | 5752 | GNUNET_STATISTICS_update (GDS_stats, |
5680 | gettext_noop | 5753 | gettext_noop ("# Bytes received from other peers"), |
5681 | ("# Bytes received from other peers"), msize, | 5754 | msize, |
5682 | GNUNET_NO); | 5755 | GNUNET_NO); |
5683 | 5756 | ||
5684 | trail = (const struct GNUNET_PeerIdentity *)&add_trail[1]; | 5757 | trail = (const struct GNUNET_PeerIdentity *) &add_trail[1]; |
5685 | destination_peer = add_trail->destination_peer; | 5758 | destination_peer = add_trail->destination_peer; |
5686 | source_peer = add_trail->source_peer; | 5759 | source_peer = add_trail->source_peer; |
5687 | trail_id = add_trail->trail_id; | 5760 | trail_id = add_trail->trail_id; |
5688 | 5761 | ||
5689 | /* I am not the destination of the trail. */ | 5762 | /* I am not the destination of the trail. */ |
5690 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination_peer)) | 5763 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, |
5764 | &destination_peer)) | ||
5691 | { | 5765 | { |
5692 | struct FriendInfo *target_friend; | 5766 | struct FriendInfo *target_friend; |
5693 | 5767 | ||
@@ -5696,13 +5770,13 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
5696 | if (-1 == my_index) | 5770 | if (-1 == my_index) |
5697 | { | 5771 | { |
5698 | GNUNET_break_op (0); | 5772 | GNUNET_break_op (0); |
5699 | return GNUNET_SYSERR; | 5773 | return; |
5700 | } | 5774 | } |
5701 | if((trail_length + 1) == my_index) | 5775 | if((trail_length + 1) == my_index) |
5702 | { | 5776 | { |
5703 | DEBUG ("Found twice in trail.\n"); | 5777 | DEBUG ("Found twice in trail.\n"); |
5704 | GNUNET_break_op (0); | 5778 | GNUNET_break_op (0); |
5705 | return GNUNET_SYSERR; | 5779 | return; |
5706 | } | 5780 | } |
5707 | if ((trail_length - 1) == my_index) | 5781 | if ((trail_length - 1) == my_index) |
5708 | { | 5782 | { |
@@ -5713,18 +5787,26 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
5713 | next_hop = trail[my_index + 1]; | 5787 | next_hop = trail[my_index + 1]; |
5714 | } | 5788 | } |
5715 | /* Add in your routing table. */ | 5789 | /* Add in your routing table. */ |
5716 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, next_hop)); | 5790 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (&trail_id, |
5791 | friend->id, | ||
5792 | &next_hop)); | ||
5717 | //GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer)); | 5793 | //GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer)); |
5718 | GNUNET_assert (NULL != | 5794 | GNUNET_assert (NULL != |
5719 | (target_friend = | 5795 | (target_friend = |
5720 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); | 5796 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5721 | GDS_NEIGHBOURS_send_add_trail (source_peer, destination_peer, trail_id, | 5797 | &next_hop))); |
5722 | trail, trail_length, target_friend); | 5798 | GDS_NEIGHBOURS_send_add_trail (&source_peer, |
5723 | return GNUNET_OK; | 5799 | &destination_peer, |
5800 | &trail_id, | ||
5801 | trail, | ||
5802 | trail_length, | ||
5803 | target_friend); | ||
5804 | return; | ||
5724 | } | 5805 | } |
5725 | /* I am the destination. Add an entry in routing table. */ | 5806 | /* I am the destination. Add an entry in routing table. */ |
5726 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, my_identity)); | 5807 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (&trail_id, |
5727 | return GNUNET_OK; | 5808 | friend->id, |
5809 | &my_identity)); | ||
5728 | } | 5810 | } |
5729 | 5811 | ||
5730 | 5812 | ||
@@ -5742,7 +5824,7 @@ static int | |||
5742 | remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend, | 5824 | remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend, |
5743 | struct FingerInfo *finger) | 5825 | struct FingerInfo *finger) |
5744 | { | 5826 | { |
5745 | struct GNUNET_PeerIdentity *next_hop; | 5827 | const struct GNUNET_PeerIdentity *next_hop; |
5746 | struct FriendInfo *remove_friend; | 5828 | struct FriendInfo *remove_friend; |
5747 | struct Trail *current_trail; | 5829 | struct Trail *current_trail; |
5748 | unsigned int matching_trails_count = 0; | 5830 | unsigned int matching_trails_count = 0; |
@@ -5763,7 +5845,7 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend, | |||
5763 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 5845 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
5764 | disconnected_friend); | 5846 | disconnected_friend); |
5765 | GNUNET_assert (NULL != remove_friend); | 5847 | GNUNET_assert (NULL != remove_friend); |
5766 | next_hop = GDS_ROUTING_get_next_hop (current_trail->trail_id, | 5848 | next_hop = GDS_ROUTING_get_next_hop (¤t_trail->trail_id, |
5767 | GDS_ROUTING_SRC_TO_DEST); | 5849 | GDS_ROUTING_SRC_TO_DEST); |
5768 | 5850 | ||
5769 | /* Here it may happen that as all the peers got disconnected, the entry in | 5851 | /* Here it may happen that as all the peers got disconnected, the entry in |
@@ -5774,7 +5856,8 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend, | |||
5774 | { | 5856 | { |
5775 | GNUNET_assert (0 == (GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend, | 5857 | GNUNET_assert (0 == (GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend, |
5776 | next_hop))); | 5858 | next_hop))); |
5777 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (current_trail->trail_id)); | 5859 | GNUNET_assert (GNUNET_YES == |
5860 | GDS_ROUTING_remove_trail (¤t_trail->trail_id)); | ||
5778 | } | 5861 | } |
5779 | matching_trails_count++; | 5862 | matching_trails_count++; |
5780 | free_trail (current_trail); | 5863 | free_trail (current_trail); |
@@ -5836,7 +5919,9 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
5836 | if (0 == current_finger->trails_count) | 5919 | if (0 == current_finger->trails_count) |
5837 | { | 5920 | { |
5838 | current_finger->is_present = GNUNET_NO; | 5921 | current_finger->is_present = GNUNET_NO; |
5839 | memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); | 5922 | memset (&finger_table[i], |
5923 | 0, | ||
5924 | sizeof (finger_table[i])); | ||
5840 | } | 5925 | } |
5841 | } | 5926 | } |
5842 | } | 5927 | } |
@@ -5847,61 +5932,32 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_peer) | |||
5847 | * | 5932 | * |
5848 | * @param cls closure | 5933 | * @param cls closure |
5849 | * @param peer peer identity this notification is about | 5934 | * @param peer peer identity this notification is about |
5935 | * @param internal_cls our `struct FriendInfo` for @a peer | ||
5850 | */ | 5936 | */ |
5851 | static void | 5937 | static void |
5852 | handle_core_disconnect (void *cls, | 5938 | handle_core_disconnect (void *cls, |
5853 | const struct GNUNET_PeerIdentity *peer) | 5939 | const struct GNUNET_PeerIdentity *peer, |
5940 | void *internal_cls) | ||
5854 | { | 5941 | { |
5855 | struct FriendInfo *remove_friend; | 5942 | struct FriendInfo *remove_friend = internal_cls; |
5856 | struct P2PPendingMessage *pos; | ||
5857 | unsigned int discarded; | ||
5858 | 5943 | ||
5859 | /* If disconnected to own identity, then return. */ | 5944 | /* If disconnected to own identity, then return. */ |
5860 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | 5945 | if (NULL == remove_friend) |
5861 | return; | 5946 | return; |
5862 | |||
5863 | if(NULL == (remove_friend = | ||
5864 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer))) | ||
5865 | { | ||
5866 | DEBUG("\n friend already disconnected."); | ||
5867 | return; | ||
5868 | } | ||
5869 | |||
5870 | remove_matching_fingers (peer); | 5947 | remove_matching_fingers (peer); |
5871 | GNUNET_assert (GNUNET_SYSERR != GDS_ROUTING_remove_trail_by_peer (peer)); | 5948 | GNUNET_assert (GNUNET_SYSERR != |
5949 | GDS_ROUTING_remove_trail_by_peer (peer)); | ||
5872 | GNUNET_assert (GNUNET_YES == | 5950 | GNUNET_assert (GNUNET_YES == |
5873 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, | 5951 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, |
5874 | peer, | 5952 | peer, |
5875 | remove_friend)); | 5953 | remove_friend)); |
5876 | |||
5877 | /* Remove all the messages queued in pending list of this peer is discarded.*/ | ||
5878 | if (remove_friend->th != NULL) | ||
5879 | { | ||
5880 | GNUNET_CORE_notify_transmit_ready_cancel(remove_friend->th); | ||
5881 | remove_friend->th = NULL; | ||
5882 | } | ||
5883 | |||
5884 | discarded = 0; | ||
5885 | while (NULL != (pos = remove_friend->head)) | ||
5886 | { | ||
5887 | GNUNET_CONTAINER_DLL_remove (remove_friend->head, remove_friend->tail, pos); | ||
5888 | discarded++; | ||
5889 | GNUNET_free (pos); | ||
5890 | } | ||
5891 | |||
5892 | GNUNET_STATISTICS_update (GDS_stats, | ||
5893 | gettext_noop | ||
5894 | ("# Queued messages discarded (peer disconnected)"), | ||
5895 | discarded, GNUNET_NO); | ||
5896 | //GNUNET_free (remove_friend); | ||
5897 | |||
5898 | if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) | 5954 | if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) |
5899 | return; | 5955 | return; |
5900 | 5956 | ||
5901 | if (NULL != find_finger_trail_task) | 5957 | if (NULL != find_finger_trail_task) |
5902 | { | 5958 | { |
5903 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); | 5959 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); |
5904 | find_finger_trail_task = NULL; | 5960 | find_finger_trail_task = NULL; |
5905 | } | 5961 | } |
5906 | else | 5962 | else |
5907 | GNUNET_break (0); | 5963 | GNUNET_break (0); |
@@ -5913,30 +5969,28 @@ handle_core_disconnect (void *cls, | |||
5913 | * | 5969 | * |
5914 | * @param cls closure | 5970 | * @param cls closure |
5915 | * @param peer_identity peer identity this notification is about | 5971 | * @param peer_identity peer identity this notification is about |
5972 | * @param mq message queue for sending data to @a peer | ||
5973 | * @return our `struct FriendInfo` for this peer | ||
5916 | */ | 5974 | */ |
5917 | static void | 5975 | static void * |
5918 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | 5976 | handle_core_connect (void *cls, |
5977 | const struct GNUNET_PeerIdentity *peer_identity, | ||
5978 | struct GNUNET_MQ_Handle *mq) | ||
5919 | { | 5979 | { |
5920 | struct FriendInfo *friend; | 5980 | struct FriendInfo *friend; |
5921 | 5981 | ||
5922 | /* Check for connect to self message */ | 5982 | /* Check for connect to self message */ |
5923 | if (0 == memcmp (&my_identity, peer_identity, sizeof (struct GNUNET_PeerIdentity))) | 5983 | if (0 == memcmp (&my_identity, |
5924 | return; | 5984 | peer_identity, |
5925 | 5985 | sizeof (struct GNUNET_PeerIdentity))) | |
5926 | /* If peer already exists in our friend_peermap, then exit. */ | 5986 | return NULL; |
5927 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap, | ||
5928 | peer_identity)) | ||
5929 | { | ||
5930 | GNUNET_break (0); | ||
5931 | return; | ||
5932 | } | ||
5933 | |||
5934 | friend = GNUNET_new (struct FriendInfo); | 5987 | friend = GNUNET_new (struct FriendInfo); |
5935 | friend->id = *peer_identity; | 5988 | friend->id = peer_identity; |
5936 | 5989 | friend->mq = mq; | |
5937 | GNUNET_assert (GNUNET_OK == | 5990 | GNUNET_assert (GNUNET_OK == |
5938 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, | 5991 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, |
5939 | peer_identity, friend, | 5992 | friend->id, |
5993 | friend, | ||
5940 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 5994 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
5941 | 5995 | ||
5942 | /* FIXME: now we are not making a distinction between fingers which are friends | 5996 | /* FIXME: now we are not making a distinction between fingers which are friends |
@@ -5946,8 +6000,11 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | |||
5946 | /* Got a first connection, good time to start with FIND FINGER TRAIL requests...*/ | 6000 | /* Got a first connection, good time to start with FIND FINGER TRAIL requests...*/ |
5947 | if (NULL == find_finger_trail_task) | 6001 | if (NULL == find_finger_trail_task) |
5948 | { | 6002 | { |
5949 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); | 6003 | find_finger_trail_task |
6004 | = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, | ||
6005 | NULL); | ||
5950 | } | 6006 | } |
6007 | return friend; | ||
5951 | } | 6008 | } |
5952 | 6009 | ||
5953 | 6010 | ||
@@ -5982,34 +6039,68 @@ finger_table_init () | |||
5982 | int | 6039 | int |
5983 | GDS_NEIGHBOURS_init (void) | 6040 | GDS_NEIGHBOURS_init (void) |
5984 | { | 6041 | { |
5985 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { | 6042 | GNUNET_MQ_hd_var_size (dht_p2p_put, |
5986 | {&handle_dht_p2p_put, GNUNET_MESSAGE_TYPE_XDHT_P2P_PUT, 0}, | 6043 | GNUNET_MESSAGE_TYPE_XDHT_P2P_PUT, |
5987 | {&handle_dht_p2p_get, GNUNET_MESSAGE_TYPE_XDHT_P2P_GET, 0}, | 6044 | struct PeerPutMessage); |
5988 | {&handle_dht_p2p_get_result, GNUNET_MESSAGE_TYPE_XDHT_P2P_GET_RESULT, 0}, | 6045 | GNUNET_MQ_hd_var_size (dht_p2p_get, |
5989 | {&handle_dht_p2p_trail_setup, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP, 0}, | 6046 | GNUNET_MESSAGE_TYPE_XDHT_P2P_GET, |
5990 | {&handle_dht_p2p_trail_setup_result, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_RESULT, 0}, | 6047 | struct PeerGetMessage); |
5991 | {&handle_dht_p2p_verify_successor, GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR, 0}, | 6048 | GNUNET_MQ_hd_var_size (dht_p2p_get_result, |
5992 | {&handle_dht_p2p_verify_successor_result, GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR_RESULT, 0}, | 6049 | GNUNET_MESSAGE_TYPE_XDHT_P2P_GET_RESULT, |
5993 | {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_NEW_SUCCESSOR, 0}, | 6050 | struct PeerGetResultMessage); |
5994 | {&handle_dht_p2p_trail_setup_rejection, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_REJECTION, 0}, | 6051 | GNUNET_MQ_hd_var_size (dht_p2p_trail_setup, |
5995 | {&handle_dht_p2p_trail_teardown, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN, | 6052 | GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP, |
5996 | sizeof (struct PeerTrailTearDownMessage)}, | 6053 | struct PeerTrailSetupMessage); |
5997 | {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0}, | 6054 | GNUNET_MQ_hd_var_size (dht_p2p_trail_setup_result, |
5998 | {&handle_dht_p2p_notify_succ_confirmation, GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION, | 6055 | GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_RESULT, |
5999 | sizeof (struct PeerNotifyConfirmationMessage)}, | 6056 | struct PeerTrailSetupResultMessage); |
6000 | {NULL, 0, 0} | 6057 | GNUNET_MQ_hd_var_size (dht_p2p_verify_successor, |
6058 | GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR, | ||
6059 | struct PeerVerifySuccessorMessage); | ||
6060 | GNUNET_MQ_hd_var_size (dht_p2p_verify_successor_result, | ||
6061 | GNUNET_MESSAGE_TYPE_XDHT_P2P_VERIFY_SUCCESSOR_RESULT, | ||
6062 | struct PeerVerifySuccessorResultMessage); | ||
6063 | GNUNET_MQ_hd_var_size (dht_p2p_notify_new_successor, | ||
6064 | GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_NEW_SUCCESSOR, | ||
6065 | struct PeerNotifyNewSuccessorMessage); | ||
6066 | GNUNET_MQ_hd_var_size (dht_p2p_trail_setup_rejection, | ||
6067 | GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_REJECTION, | ||
6068 | struct PeerTrailRejectionMessage); | ||
6069 | GNUNET_MQ_hd_fixed_size (dht_p2p_trail_teardown, | ||
6070 | GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN, | ||
6071 | struct PeerTrailTearDownMessage); | ||
6072 | GNUNET_MQ_hd_var_size (dht_p2p_add_trail, | ||
6073 | GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, | ||
6074 | struct PeerAddTrailMessage); | ||
6075 | GNUNET_MQ_hd_fixed_size (dht_p2p_notify_succ_confirmation, | ||
6076 | GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION, | ||
6077 | struct PeerNotifyConfirmationMessage); | ||
6078 | struct GNUNET_MQ_MessageHandler core_handlers[] = { | ||
6079 | make_dht_p2p_put_handler (NULL), | ||
6080 | make_dht_p2p_get_handler (NULL), | ||
6081 | make_dht_p2p_get_result_handler (NULL), | ||
6082 | make_dht_p2p_trail_setup_handler (NULL), | ||
6083 | make_dht_p2p_trail_setup_result_handler (NULL), | ||
6084 | make_dht_p2p_verify_successor_handler (NULL), | ||
6085 | make_dht_p2p_verify_successor_result_handler (NULL), | ||
6086 | make_dht_p2p_notify_new_successor_handler (NULL), | ||
6087 | make_dht_p2p_trail_setup_rejection_handler (NULL), | ||
6088 | make_dht_p2p_trail_teardown_handler (NULL), | ||
6089 | make_dht_p2p_add_trail_handler (NULL), | ||
6090 | make_dht_p2p_notify_succ_confirmation_handler (NULL), | ||
6091 | GNUNET_MQ_handler_end () | ||
6001 | }; | 6092 | }; |
6002 | 6093 | ||
6003 | core_api = | 6094 | core_api = GNUNET_CORE_connecT (GDS_cfg, |
6004 | GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect, | 6095 | NULL, |
6005 | &handle_core_disconnect, NULL, GNUNET_NO, NULL, | 6096 | &core_init, |
6006 | GNUNET_NO, core_handlers); | 6097 | &handle_core_connect, |
6007 | 6098 | &handle_core_disconnect, | |
6099 | core_handlers); | ||
6008 | if (NULL == core_api) | 6100 | if (NULL == core_api) |
6009 | return GNUNET_SYSERR; | 6101 | return GNUNET_SYSERR; |
6010 | 6102 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, | |
6011 | //TODO: check size of this peer map? | 6103 | GNUNET_YES); |
6012 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | ||
6013 | finger_table_init (); | 6104 | finger_table_init (); |
6014 | successor_times = 10; | 6105 | successor_times = 10; |
6015 | fingers_round_count = 5; | 6106 | fingers_round_count = 5; |
@@ -6033,7 +6124,6 @@ GDS_NEIGHBOURS_init (void) | |||
6033 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 6124 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
6034 | DHT_SEND_NOTIFY_SUCCESSOR_RETRY_INTERVAL.rel_value_us); | 6125 | DHT_SEND_NOTIFY_SUCCESSOR_RETRY_INTERVAL.rel_value_us); |
6035 | 6126 | ||
6036 | |||
6037 | return GNUNET_OK; | 6127 | return GNUNET_OK; |
6038 | } | 6128 | } |
6039 | 6129 | ||
@@ -6044,16 +6134,12 @@ GDS_NEIGHBOURS_init (void) | |||
6044 | static void | 6134 | static void |
6045 | delete_finger_table_entries() | 6135 | delete_finger_table_entries() |
6046 | { | 6136 | { |
6047 | unsigned int i; | 6137 | for (unsigned int i = 0; i < MAX_FINGERS; i++) |
6048 | unsigned int j; | ||
6049 | |||
6050 | for(i = 0; i < MAX_FINGERS; i++) | ||
6051 | { | 6138 | { |
6052 | if(GNUNET_YES == finger_table[i].is_present) | 6139 | if (GNUNET_YES != finger_table[i].is_present) |
6053 | { | 6140 | continue; |
6054 | for(j = 0; j < finger_table[i].trails_count; j++) | 6141 | for (unsigned int j = 0; j < finger_table[i].trails_count; j++) |
6055 | free_trail(&finger_table[i].trail_list[j]); | 6142 | free_trail(&finger_table[i].trail_list[j]); |
6056 | } | ||
6057 | } | 6143 | } |
6058 | } | 6144 | } |
6059 | 6145 | ||
@@ -6067,7 +6153,7 @@ GDS_NEIGHBOURS_done (void) | |||
6067 | if (NULL == core_api) | 6153 | if (NULL == core_api) |
6068 | return; | 6154 | return; |
6069 | 6155 | ||
6070 | GNUNET_CORE_disconnect (core_api); | 6156 | GNUNET_CORE_disconnecT (core_api); |
6071 | core_api = NULL; | 6157 | core_api = NULL; |
6072 | 6158 | ||
6073 | delete_finger_table_entries(); | 6159 | delete_finger_table_entries(); |
@@ -6086,19 +6172,19 @@ GDS_NEIGHBOURS_done (void) | |||
6086 | GNUNET_SCHEDULER_cancel (send_verify_successor_task); | 6172 | GNUNET_SCHEDULER_cancel (send_verify_successor_task); |
6087 | send_verify_successor_task = NULL; | 6173 | send_verify_successor_task = NULL; |
6088 | } | 6174 | } |
6089 | |||
6090 | if (NULL != send_verify_successor_retry_task) | 6175 | if (NULL != send_verify_successor_retry_task) |
6091 | { | 6176 | { |
6092 | struct VerifySuccessorContext *ctx; | 6177 | struct VerifySuccessorContext *ctx; |
6178 | |||
6093 | ctx = GNUNET_SCHEDULER_cancel (send_verify_successor_retry_task); | 6179 | ctx = GNUNET_SCHEDULER_cancel (send_verify_successor_retry_task); |
6094 | GNUNET_free(ctx); | 6180 | GNUNET_free (ctx); |
6095 | send_verify_successor_retry_task = NULL; | 6181 | send_verify_successor_retry_task = NULL; |
6096 | } | 6182 | } |
6097 | 6183 | if (NULL != send_notify_new_successor_retry_task) | |
6098 | if (send_notify_new_successor_retry_task != NULL) | ||
6099 | { | 6184 | { |
6100 | struct SendNotifyContext *notify_ctx; | 6185 | struct SendNotifyContext *notify_ctx; |
6101 | notify_ctx = GNUNET_SCHEDULER_cancel(send_notify_new_successor_retry_task); | 6186 | |
6187 | notify_ctx = GNUNET_SCHEDULER_cancel (send_notify_new_successor_retry_task); | ||
6102 | GNUNET_free (notify_ctx->successor_trail); | 6188 | GNUNET_free (notify_ctx->successor_trail); |
6103 | GNUNET_free (notify_ctx); | 6189 | GNUNET_free (notify_ctx); |
6104 | send_notify_new_successor_retry_task = NULL; | 6190 | send_notify_new_successor_retry_task = NULL; |
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h index 8a99254dd..1df45031d 100644 --- a/src/dht/gnunet-service-xdht_neighbours.h +++ b/src/dht/gnunet-service-xdht_neighbours.h | |||
@@ -60,10 +60,10 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, | |||
60 | * @param desired_replication_level Desired replication count | 60 | * @param desired_replication_level Desired replication count |
61 | */ | 61 | */ |
62 | void | 62 | void |
63 | GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key, | 63 | GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key, |
64 | enum GNUNET_BLOCK_Type block_type, | 64 | enum GNUNET_BLOCK_Type block_type, |
65 | enum GNUNET_DHT_RouteOption options, | 65 | enum GNUNET_DHT_RouteOption options, |
66 | uint32_t desired_replication_level); | 66 | uint32_t desired_replication_level); |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Send the get result to requesting client. | 69 | * Send the get result to requesting client. |
@@ -89,7 +89,9 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
89 | unsigned int get_path_length, | 89 | unsigned int get_path_length, |
90 | const struct GNUNET_PeerIdentity *get_path, | 90 | const struct GNUNET_PeerIdentity *get_path, |
91 | struct GNUNET_TIME_Absolute expiration, | 91 | struct GNUNET_TIME_Absolute expiration, |
92 | const void *data, size_t data_size); | 92 | const void *data, |
93 | size_t data_size); | ||
94 | |||
93 | 95 | ||
94 | /** | 96 | /** |
95 | * Construct a trail teardown message and forward it to target friend. | 97 | * Construct a trail teardown message and forward it to target friend. |
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c index d705a92a5..12b85eb7f 100644 --- a/src/dht/gnunet-service-xdht_routing.c +++ b/src/dht/gnunet-service-xdht_routing.c | |||
@@ -83,20 +83,21 @@ static struct GNUNET_CONTAINER_MultiHashMap *routing_table; | |||
83 | * #GNUNET_SYSERR in case no matching entry found in routing table. | 83 | * #GNUNET_SYSERR in case no matching entry found in routing table. |
84 | */ | 84 | */ |
85 | int | 85 | int |
86 | GDS_ROUTING_update_trail_prev_hop (const struct GNUNET_HashCode trail_id, | 86 | GDS_ROUTING_update_trail_prev_hop (const struct GNUNET_HashCode *trail_id, |
87 | struct GNUNET_PeerIdentity prev_hop) | 87 | const struct GNUNET_PeerIdentity *prev_hop) |
88 | { | 88 | { |
89 | struct RoutingTrail *trail; | 89 | struct RoutingTrail *trail; |
90 | 90 | ||
91 | trail = GNUNET_CONTAINER_multihashmap_get (routing_table, &trail_id); | 91 | trail = GNUNET_CONTAINER_multihashmap_get (routing_table, |
92 | trail_id); | ||
92 | 93 | ||
93 | if (NULL == trail) | 94 | if (NULL == trail) |
94 | return GNUNET_SYSERR; | 95 | return GNUNET_SYSERR; |
95 | 96 | trail->prev_hop = *prev_hop; | |
96 | trail->prev_hop = prev_hop; | ||
97 | return GNUNET_OK; | 97 | return GNUNET_OK; |
98 | } | 98 | } |
99 | 99 | ||
100 | |||
100 | /** | 101 | /** |
101 | * Update the next hop of the trail. Call made by trail compression where | 102 | * Update the next hop of the trail. Call made by trail compression where |
102 | * if you are source of the trail and now you have a new first friend, then | 103 | * if you are source of the trail and now you have a new first friend, then |
@@ -106,34 +107,35 @@ GDS_ROUTING_update_trail_prev_hop (const struct GNUNET_HashCode trail_id, | |||
106 | * #GNUNET_SYSERR in case no matching entry found in routing table. | 107 | * #GNUNET_SYSERR in case no matching entry found in routing table. |
107 | */ | 108 | */ |
108 | int | 109 | int |
109 | GDS_ROUTING_update_trail_next_hop (const struct GNUNET_HashCode trail_id, | 110 | GDS_ROUTING_update_trail_next_hop (const struct GNUNET_HashCode *trail_id, |
110 | struct GNUNET_PeerIdentity next_hop) | 111 | const struct GNUNET_PeerIdentity *next_hop) |
111 | { | 112 | { |
112 | struct RoutingTrail *trail; | 113 | struct RoutingTrail *trail; |
113 | 114 | ||
114 | trail = GNUNET_CONTAINER_multihashmap_get (routing_table, &trail_id); | 115 | trail = GNUNET_CONTAINER_multihashmap_get (routing_table, |
115 | 116 | trail_id); | |
116 | if (NULL == trail) | 117 | if (NULL == trail) |
117 | |||
118 | return GNUNET_SYSERR; | 118 | return GNUNET_SYSERR; |
119 | 119 | trail->next_hop = *next_hop; | |
120 | trail->next_hop = next_hop; | ||
121 | return GNUNET_OK; | 120 | return GNUNET_OK; |
122 | } | 121 | } |
123 | 122 | ||
123 | |||
124 | /** | 124 | /** |
125 | * Get the next hop for trail corresponding to trail_id | 125 | * Get the next hop for trail corresponding to trail_id |
126 | * | ||
126 | * @param trail_id Trail id to be searched. | 127 | * @param trail_id Trail id to be searched. |
127 | * @return Next_hop if found | 128 | * @return Next_hop if found |
128 | * NULL If next hop not found. | 129 | * NULL If next hop not found. |
129 | */ | 130 | */ |
130 | struct GNUNET_PeerIdentity * | 131 | const struct GNUNET_PeerIdentity * |
131 | GDS_ROUTING_get_next_hop (const struct GNUNET_HashCode trail_id, | 132 | GDS_ROUTING_get_next_hop (const struct GNUNET_HashCode *trail_id, |
132 | enum GDS_ROUTING_trail_direction trail_direction) | 133 | enum GDS_ROUTING_trail_direction trail_direction) |
133 | { | 134 | { |
134 | struct RoutingTrail *trail; | 135 | struct RoutingTrail *trail; |
135 | 136 | ||
136 | trail = GNUNET_CONTAINER_multihashmap_get (routing_table, &trail_id); | 137 | trail = GNUNET_CONTAINER_multihashmap_get (routing_table, |
138 | trail_id); | ||
137 | if (NULL == trail) | 139 | if (NULL == trail) |
138 | { | 140 | { |
139 | /* If a friend got disconnected and we removed all the entry from the | 141 | /* If a friend got disconnected and we removed all the entry from the |
@@ -145,9 +147,9 @@ GDS_ROUTING_get_next_hop (const struct GNUNET_HashCode trail_id, | |||
145 | switch (trail_direction) | 147 | switch (trail_direction) |
146 | { | 148 | { |
147 | case GDS_ROUTING_SRC_TO_DEST: | 149 | case GDS_ROUTING_SRC_TO_DEST: |
148 | return &(trail->next_hop); | 150 | return &trail->next_hop; |
149 | case GDS_ROUTING_DEST_TO_SRC: | 151 | case GDS_ROUTING_DEST_TO_SRC: |
150 | return &(trail->prev_hop); | 152 | return &trail->prev_hop; |
151 | } | 153 | } |
152 | return NULL; | 154 | return NULL; |
153 | } | 155 | } |
@@ -160,22 +162,23 @@ GDS_ROUTING_get_next_hop (const struct GNUNET_HashCode trail_id, | |||
160 | * #GNUNET_NO if entry not found. | 162 | * #GNUNET_NO if entry not found. |
161 | */ | 163 | */ |
162 | int | 164 | int |
163 | GDS_ROUTING_remove_trail (const struct GNUNET_HashCode remove_trail_id) | 165 | GDS_ROUTING_remove_trail (const struct GNUNET_HashCode *remove_trail_id) |
164 | { | 166 | { |
165 | struct RoutingTrail *remove_entry; | 167 | struct RoutingTrail *remove_entry; |
166 | 168 | ||
167 | remove_entry = GNUNET_CONTAINER_multihashmap_get (routing_table, &remove_trail_id); | 169 | remove_entry = GNUNET_CONTAINER_multihashmap_get (routing_table, |
170 | remove_trail_id); | ||
168 | if (NULL == remove_entry) | 171 | if (NULL == remove_entry) |
169 | return GNUNET_NO; | 172 | return GNUNET_NO; |
170 | 173 | ||
171 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (routing_table, | 174 | if (GNUNET_YES == |
172 | &remove_trail_id, | 175 | GNUNET_CONTAINER_multihashmap_remove (routing_table, |
173 | remove_entry)) | 176 | remove_trail_id, |
177 | remove_entry)) | ||
174 | { | 178 | { |
175 | GNUNET_free (remove_entry); | 179 | GNUNET_free (remove_entry); |
176 | return GNUNET_YES; | 180 | return GNUNET_YES; |
177 | } | 181 | } |
178 | |||
179 | return GNUNET_NO; | 182 | return GNUNET_NO; |
180 | } | 183 | } |
181 | 184 | ||
@@ -189,9 +192,10 @@ GDS_ROUTING_remove_trail (const struct GNUNET_HashCode remove_trail_id) | |||
189 | * @return #GNUNET_YES if we should continue to iterate, | 192 | * @return #GNUNET_YES if we should continue to iterate, |
190 | * #GNUNET_NO if not. | 193 | * #GNUNET_NO if not. |
191 | */ | 194 | */ |
192 | static int remove_matching_trails (void *cls, | 195 | static int |
193 | const struct GNUNET_HashCode *key, | 196 | remove_matching_trails (void *cls, |
194 | void *value) | 197 | const struct GNUNET_HashCode *key, |
198 | void *value) | ||
195 | { | 199 | { |
196 | struct RoutingTrail *remove_trail = value; | 200 | struct RoutingTrail *remove_trail = value; |
197 | struct GNUNET_PeerIdentity *disconnected_peer = cls; | 201 | struct GNUNET_PeerIdentity *disconnected_peer = cls; |
@@ -306,22 +310,22 @@ GDS_ROUTING_remove_trail_by_peer (const struct GNUNET_PeerIdentity *peer) | |||
306 | * but with different prev_hop/next_hop | 310 | * but with different prev_hop/next_hop |
307 | */ | 311 | */ |
308 | int | 312 | int |
309 | GDS_ROUTING_add (struct GNUNET_HashCode new_trail_id, | 313 | GDS_ROUTING_add (const struct GNUNET_HashCode *new_trail_id, |
310 | struct GNUNET_PeerIdentity prev_hop, | 314 | const struct GNUNET_PeerIdentity *prev_hop, |
311 | struct GNUNET_PeerIdentity next_hop) | 315 | const struct GNUNET_PeerIdentity *next_hop) |
312 | { | 316 | { |
313 | struct RoutingTrail *new_entry; | 317 | struct RoutingTrail *new_entry; |
314 | 318 | ||
315 | new_entry = GNUNET_new (struct RoutingTrail); | 319 | new_entry = GNUNET_new (struct RoutingTrail); |
316 | new_entry->trail_id = new_trail_id; | 320 | new_entry->trail_id = *new_trail_id; |
317 | new_entry->next_hop = next_hop; | 321 | new_entry->next_hop = *next_hop; |
318 | new_entry->prev_hop = prev_hop; | 322 | new_entry->prev_hop = *prev_hop; |
319 | |||
320 | 323 | ||
324 | // FIXME: this leaks memory if the put fails! | ||
321 | return GNUNET_CONTAINER_multihashmap_put (routing_table, | 325 | return GNUNET_CONTAINER_multihashmap_put (routing_table, |
322 | &new_trail_id, new_entry, | 326 | &new_entry->trail_id, |
327 | new_entry, | ||
323 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 328 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
324 | |||
325 | } | 329 | } |
326 | 330 | ||
327 | 331 | ||
diff --git a/src/dht/gnunet-service-xdht_routing.h b/src/dht/gnunet-service-xdht_routing.h index 958ff1a7c..69ab1ff78 100644 --- a/src/dht/gnunet-service-xdht_routing.h +++ b/src/dht/gnunet-service-xdht_routing.h | |||
@@ -49,8 +49,8 @@ enum GDS_ROUTING_trail_direction | |||
49 | * #GNUNET_SYSERR in case no matching entry found in routing table. | 49 | * #GNUNET_SYSERR in case no matching entry found in routing table. |
50 | */ | 50 | */ |
51 | int | 51 | int |
52 | GDS_ROUTING_update_trail_prev_hop (struct GNUNET_HashCode trail_id, | 52 | GDS_ROUTING_update_trail_prev_hop (const struct GNUNET_HashCode *trail_id, |
53 | struct GNUNET_PeerIdentity prev_hop); | 53 | const struct GNUNET_PeerIdentity *prev_hop); |
54 | 54 | ||
55 | 55 | ||
56 | /** | 56 | /** |
@@ -62,8 +62,8 @@ GDS_ROUTING_update_trail_prev_hop (struct GNUNET_HashCode trail_id, | |||
62 | * #GNUNET_SYSERR in case no matching entry found in routing table. | 62 | * #GNUNET_SYSERR in case no matching entry found in routing table. |
63 | */ | 63 | */ |
64 | int | 64 | int |
65 | GDS_ROUTING_update_trail_next_hop (const struct GNUNET_HashCode trail_id, | 65 | GDS_ROUTING_update_trail_next_hop (const struct GNUNET_HashCode *trail_id, |
66 | struct GNUNET_PeerIdentity next_hop); | 66 | const struct GNUNET_PeerIdentity *next_hop); |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Get the next hop for trail corresponding to trail_id | 69 | * Get the next hop for trail corresponding to trail_id |
@@ -71,25 +71,28 @@ GDS_ROUTING_update_trail_next_hop (const struct GNUNET_HashCode trail_id, | |||
71 | * @return Next_hop if found | 71 | * @return Next_hop if found |
72 | * NULL If next hop not found. | 72 | * NULL If next hop not found. |
73 | */ | 73 | */ |
74 | struct GNUNET_PeerIdentity * | 74 | const struct GNUNET_PeerIdentity * |
75 | GDS_ROUTING_get_next_hop (struct GNUNET_HashCode trail_id, | 75 | GDS_ROUTING_get_next_hop (const struct GNUNET_HashCode *trail_id, |
76 | enum GDS_ROUTING_trail_direction trail_direction); | 76 | enum GDS_ROUTING_trail_direction trail_direction); |
77 | 77 | ||
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Remove every trail where peer is either next_hop or prev_hop | 80 | * Remove every trail where peer is either next_hop or prev_hop |
81 | * @param peer Peer to be searched. | 81 | * @param peer Peer to be searched. |
82 | */ | 82 | */ |
83 | int | 83 | int |
84 | GDS_ROUTING_remove_trail_by_peer (const struct GNUNET_PeerIdentity *peer); | 84 | GDS_ROUTING_remove_trail_by_peer (const struct GNUNET_PeerIdentity *peer); |
85 | |||
86 | |||
85 | /** | 87 | /** |
86 | * Remove trail with trail_id | 88 | * Remove trail with trail_id |
89 | * | ||
87 | * @param trail_id Trail id to be removed | 90 | * @param trail_id Trail id to be removed |
88 | * @return #GNUNET_YES success | 91 | * @return #GNUNET_YES success |
89 | * #GNUNET_NO if entry not found. | 92 | * #GNUNET_NO if entry not found. |
90 | */ | 93 | */ |
91 | int | 94 | int |
92 | GDS_ROUTING_remove_trail (struct GNUNET_HashCode remove_trail_id); | 95 | GDS_ROUTING_remove_trail (const struct GNUNET_HashCode *remove_trail_id); |
93 | 96 | ||
94 | 97 | ||
95 | /** | 98 | /** |
@@ -102,9 +105,9 @@ GDS_ROUTING_remove_trail (struct GNUNET_HashCode remove_trail_id); | |||
102 | * but with different prev_hop/next_hop | 105 | * but with different prev_hop/next_hop |
103 | */ | 106 | */ |
104 | int | 107 | int |
105 | GDS_ROUTING_add (struct GNUNET_HashCode new_trail_id, | 108 | GDS_ROUTING_add (const struct GNUNET_HashCode *new_trail_id, |
106 | struct GNUNET_PeerIdentity prev_hop, | 109 | const struct GNUNET_PeerIdentity *prev_hop, |
107 | struct GNUNET_PeerIdentity next_hop); | 110 | const struct GNUNET_PeerIdentity *next_hop); |
108 | 111 | ||
109 | 112 | ||
110 | /** | 113 | /** |
@@ -135,4 +138,4 @@ GDS_ROUTING_init (void); | |||
135 | void | 138 | void |
136 | GDS_ROUTING_done (void); | 139 | GDS_ROUTING_done (void); |
137 | 140 | ||
138 | #endif \ No newline at end of file | 141 | #endif |
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 2827a17f2..3b79b474f 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013, 2016 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 |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -125,34 +125,6 @@ GNUNET_NETWORK_STRUCT_END | |||
125 | 125 | ||
126 | 126 | ||
127 | /** | 127 | /** |
128 | * Linked list of messages to send to clients. | ||
129 | */ | ||
130 | struct PendingMessage | ||
131 | { | ||
132 | /** | ||
133 | * Pointer to next item in the list | ||
134 | */ | ||
135 | struct PendingMessage *next; | ||
136 | |||
137 | /** | ||
138 | * Pointer to previous item in the list | ||
139 | */ | ||
140 | struct PendingMessage *prev; | ||
141 | |||
142 | /** | ||
143 | * Actual message to be sent, allocated after this struct. | ||
144 | */ | ||
145 | const struct GNUNET_MessageHeader *msg; | ||
146 | |||
147 | /** | ||
148 | * Next target for the message (a neighbour of ours). | ||
149 | */ | ||
150 | struct GNUNET_PeerIdentity next_target; | ||
151 | |||
152 | }; | ||
153 | |||
154 | |||
155 | /** | ||
156 | * Information about a direct neighbor (core-level, excluding | 128 | * Information about a direct neighbor (core-level, excluding |
157 | * DV-links, only DV-enabled peers). | 129 | * DV-links, only DV-enabled peers). |
158 | */ | 130 | */ |
@@ -162,7 +134,7 @@ struct DirectNeighbor | |||
162 | /** | 134 | /** |
163 | * Identity of the peer. | 135 | * Identity of the peer. |
164 | */ | 136 | */ |
165 | struct GNUNET_PeerIdentity peer; | 137 | const struct GNUNET_PeerIdentity *peer; |
166 | 138 | ||
167 | /** | 139 | /** |
168 | * Session ID we use whenever we create a set union with | 140 | * Session ID we use whenever we create a set union with |
@@ -173,19 +145,9 @@ struct DirectNeighbor | |||
173 | struct GNUNET_HashCode real_session_id; | 145 | struct GNUNET_HashCode real_session_id; |
174 | 146 | ||
175 | /** | 147 | /** |
176 | * Head of linked list of messages to send to this peer. | ||
177 | */ | ||
178 | struct PendingMessage *pm_head; | ||
179 | |||
180 | /** | ||
181 | * Tail of linked list of messages to send to this peer. | ||
182 | */ | ||
183 | struct PendingMessage *pm_tail; | ||
184 | |||
185 | /** | ||
186 | * Transmit handle to core service. | 148 | * Transmit handle to core service. |
187 | */ | 149 | */ |
188 | struct GNUNET_CORE_TransmitHandle *cth; | 150 | struct GNUNET_MQ_Handle *mq; |
189 | 151 | ||
190 | /** | 152 | /** |
191 | * Routing table of the neighbor, NULL if not yet established. | 153 | * Routing table of the neighbor, NULL if not yet established. |
@@ -240,11 +202,6 @@ struct DirectNeighbor | |||
240 | unsigned int consensus_insertion_distance; | 202 | unsigned int consensus_insertion_distance; |
241 | 203 | ||
242 | /** | 204 | /** |
243 | * Number of messages currently in the 'pm_XXXX'-DLL. | ||
244 | */ | ||
245 | unsigned int pm_queue_size; | ||
246 | |||
247 | /** | ||
248 | * Elements in consensus | 205 | * Elements in consensus |
249 | */ | 206 | */ |
250 | unsigned int consensus_elements; | 207 | unsigned int consensus_elements; |
@@ -381,7 +338,7 @@ static struct GNUNET_ATS_PerformanceHandle *ats; | |||
381 | /** | 338 | /** |
382 | * Task scheduled to refresh routes based on direct neighbours. | 339 | * Task scheduled to refresh routes based on direct neighbours. |
383 | */ | 340 | */ |
384 | static struct GNUNET_SCHEDULER_Task * rr_task; | 341 | static struct GNUNET_SCHEDULER_Task *rr_task; |
385 | 342 | ||
386 | /** | 343 | /** |
387 | * #GNUNET_YES if we are shutting down. | 344 | * #GNUNET_YES if we are shutting down. |
@@ -549,60 +506,6 @@ send_disconnect_to_plugin (const struct GNUNET_PeerIdentity *target) | |||
549 | 506 | ||
550 | 507 | ||
551 | /** | 508 | /** |
552 | * Function called to transfer a message to another peer | ||
553 | * via core. | ||
554 | * | ||
555 | * @param cls closure with the direct neighbor | ||
556 | * @param size number of bytes available in buf | ||
557 | * @param buf where the callee should write the message | ||
558 | * @return number of bytes written to buf | ||
559 | */ | ||
560 | static size_t | ||
561 | core_transmit_notify (void *cls, size_t size, void *buf) | ||
562 | { | ||
563 | struct DirectNeighbor *dn = cls; | ||
564 | char *cbuf = buf; | ||
565 | struct PendingMessage *pending; | ||
566 | size_t off; | ||
567 | size_t msize; | ||
568 | |||
569 | dn->cth = NULL; | ||
570 | if (NULL == buf) | ||
571 | { | ||
572 | /* client disconnected */ | ||
573 | return 0; | ||
574 | } | ||
575 | off = 0; | ||
576 | while ( (NULL != (pending = dn->pm_head)) && | ||
577 | (size >= off + (msize = ntohs (pending->msg->size)))) | ||
578 | { | ||
579 | dn->pm_queue_size--; | ||
580 | GNUNET_CONTAINER_DLL_remove (dn->pm_head, | ||
581 | dn->pm_tail, | ||
582 | pending); | ||
583 | GNUNET_memcpy (&cbuf[off], pending->msg, msize); | ||
584 | GNUNET_free (pending); | ||
585 | off += msize; | ||
586 | } | ||
587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
588 | "Transmitting total of %u bytes to %s\n", | ||
589 | (unsigned int) off, | ||
590 | GNUNET_i2s (&dn->peer)); | ||
591 | GNUNET_assert (NULL != core_api); | ||
592 | if (NULL != pending) | ||
593 | dn->cth = | ||
594 | GNUNET_CORE_notify_transmit_ready (core_api, | ||
595 | GNUNET_YES /* cork */, | ||
596 | GNUNET_CORE_PRIO_BEST_EFFORT, | ||
597 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
598 | &dn->peer, | ||
599 | msize, | ||
600 | &core_transmit_notify, dn); | ||
601 | return off; | ||
602 | } | ||
603 | |||
604 | |||
605 | /** | ||
606 | * Forward the given payload to the given target. | 509 | * Forward the given payload to the given target. |
607 | * | 510 | * |
608 | * @param target where to send the message | 511 | * @param target where to send the message |
@@ -618,11 +521,10 @@ forward_payload (struct DirectNeighbor *target, | |||
618 | const struct GNUNET_PeerIdentity *actual_target, | 521 | const struct GNUNET_PeerIdentity *actual_target, |
619 | const struct GNUNET_MessageHeader *payload) | 522 | const struct GNUNET_MessageHeader *payload) |
620 | { | 523 | { |
621 | struct PendingMessage *pm; | 524 | struct GNUNET_MQ_Envelope *env; |
622 | struct RouteMessage *rm; | 525 | struct RouteMessage *rm; |
623 | size_t msize; | ||
624 | 526 | ||
625 | if ( (target->pm_queue_size >= MAX_QUEUE_SIZE) && | 527 | if ( (GNUNET_MQ_get_length (target->mq) >= MAX_QUEUE_SIZE) && |
626 | (0 != memcmp (sender, | 528 | (0 != memcmp (sender, |
627 | &my_identity, | 529 | &my_identity, |
628 | sizeof (struct GNUNET_PeerIdentity))) ) | 530 | sizeof (struct GNUNET_PeerIdentity))) ) |
@@ -630,38 +532,24 @@ forward_payload (struct DirectNeighbor *target, | |||
630 | /* not _our_ client and queue is full, drop */ | 532 | /* not _our_ client and queue is full, drop */ |
631 | GNUNET_STATISTICS_update (stats, | 533 | GNUNET_STATISTICS_update (stats, |
632 | "# messages dropped", | 534 | "# messages dropped", |
633 | 1, GNUNET_NO); | 535 | 1, |
536 | GNUNET_NO); | ||
634 | return; | 537 | return; |
635 | } | 538 | } |
636 | msize = sizeof (struct RouteMessage) + ntohs (payload->size); | 539 | if (sizeof (struct RouteMessage) + ntohs (payload->size) |
637 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 540 | >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
638 | { | 541 | { |
639 | GNUNET_break (0); | 542 | GNUNET_break (0); |
640 | return; | 543 | return; |
641 | } | 544 | } |
642 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + msize); | 545 | env = GNUNET_MQ_msg_nested_mh (rm, |
643 | pm->next_target = target->peer; | 546 | GNUNET_MESSAGE_TYPE_DV_ROUTE, |
644 | pm->msg = (const struct GNUNET_MessageHeader *) &pm[1]; | 547 | payload); |
645 | rm = (struct RouteMessage *) &pm[1]; | ||
646 | rm->header.size = htons ((uint16_t) msize); | ||
647 | rm->header.type = htons (GNUNET_MESSAGE_TYPE_DV_ROUTE); | ||
648 | rm->distance = htonl (distance); | 548 | rm->distance = htonl (distance); |
649 | rm->target = *actual_target; | 549 | rm->target = *actual_target; |
650 | rm->sender = *sender; | 550 | rm->sender = *sender; |
651 | GNUNET_memcpy (&rm[1], payload, ntohs (payload->size)); | 551 | GNUNET_MQ_send (target->mq, |
652 | GNUNET_CONTAINER_DLL_insert_tail (target->pm_head, | 552 | env); |
653 | target->pm_tail, | ||
654 | pm); | ||
655 | target->pm_queue_size++; | ||
656 | GNUNET_assert (NULL != core_api); | ||
657 | if (NULL == target->cth) | ||
658 | target->cth = GNUNET_CORE_notify_transmit_ready (core_api, | ||
659 | GNUNET_YES /* cork */, | ||
660 | GNUNET_CORE_PRIO_BEST_EFFORT, | ||
661 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
662 | &target->peer, | ||
663 | msize, | ||
664 | &core_transmit_notify, target); | ||
665 | } | 553 | } |
666 | 554 | ||
667 | 555 | ||
@@ -790,7 +678,7 @@ build_set (void *cls) | |||
790 | /* we have added all elements to the set, run the operation */ | 678 | /* we have added all elements to the set, run the operation */ |
791 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
792 | "Finished building my SET for peer `%s' with %u elements, committing\n", | 680 | "Finished building my SET for peer `%s' with %u elements, committing\n", |
793 | GNUNET_i2s (&neighbor->peer), | 681 | GNUNET_i2s (neighbor->peer), |
794 | neighbor->consensus_elements); | 682 | neighbor->consensus_elements); |
795 | GNUNET_SET_commit (neighbor->set_op, | 683 | GNUNET_SET_commit (neighbor->set_op, |
796 | neighbor->my_set); | 684 | neighbor->my_set); |
@@ -809,8 +697,12 @@ build_set (void *cls) | |||
809 | 697 | ||
810 | /* Find next non-NULL entry */ | 698 | /* Find next non-NULL entry */ |
811 | neighbor->consensus_insertion_offset++; | 699 | neighbor->consensus_insertion_offset++; |
812 | if ( (0 != memcmp (&target->peer, &my_identity, sizeof (my_identity))) && | 700 | if ( (0 != memcmp (&target->peer, |
813 | (0 != memcmp (&target->peer, &neighbor->peer, sizeof (neighbor->peer))) ) | 701 | &my_identity, |
702 | sizeof (my_identity))) && | ||
703 | (0 != memcmp (&target->peer, | ||
704 | neighbor->peer, | ||
705 | sizeof (struct GNUNET_PeerIdentity))) ) | ||
814 | { | 706 | { |
815 | /* Add target if it is not the neighbor or this peer */ | 707 | /* Add target if it is not the neighbor or this peer */ |
816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -842,26 +734,26 @@ handle_direct_connect (struct DirectNeighbor *neighbor) | |||
842 | 734 | ||
843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
844 | "Direct connection to %s established, routing table exchange begins.\n", | 736 | "Direct connection to %s established, routing table exchange begins.\n", |
845 | GNUNET_i2s (&neighbor->peer)); | 737 | GNUNET_i2s (neighbor->peer)); |
846 | GNUNET_STATISTICS_update (stats, | 738 | GNUNET_STATISTICS_update (stats, |
847 | "# peers connected (1-hop)", | 739 | "# peers connected (1-hop)", |
848 | 1, GNUNET_NO); | 740 | 1, GNUNET_NO); |
849 | route = GNUNET_CONTAINER_multipeermap_get (all_routes, | 741 | route = GNUNET_CONTAINER_multipeermap_get (all_routes, |
850 | &neighbor->peer); | 742 | neighbor->peer); |
851 | if (NULL != route) | 743 | if (NULL != route) |
852 | { | 744 | { |
853 | GNUNET_assert (GNUNET_YES == | 745 | GNUNET_assert (GNUNET_YES == |
854 | GNUNET_CONTAINER_multipeermap_remove (all_routes, | 746 | GNUNET_CONTAINER_multipeermap_remove (all_routes, |
855 | &neighbor->peer, | 747 | neighbor->peer, |
856 | route)); | 748 | route)); |
857 | send_disconnect_to_plugin (&neighbor->peer); | 749 | send_disconnect_to_plugin (neighbor->peer); |
858 | release_route (route); | 750 | release_route (route); |
859 | GNUNET_free (route); | 751 | GNUNET_free (route); |
860 | } | 752 | } |
861 | 753 | ||
862 | neighbor->direct_route = GNUNET_new (struct Route); | 754 | neighbor->direct_route = GNUNET_new (struct Route); |
863 | neighbor->direct_route->next_hop = neighbor; | 755 | neighbor->direct_route->next_hop = neighbor; |
864 | neighbor->direct_route->target.peer = neighbor->peer; | 756 | neighbor->direct_route->target.peer = *neighbor->peer; |
865 | allocate_route (neighbor->direct_route, DIRECT_NEIGHBOR_COST); | 757 | allocate_route (neighbor->direct_route, DIRECT_NEIGHBOR_COST); |
866 | 758 | ||
867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -870,8 +762,12 @@ handle_direct_connect (struct DirectNeighbor *neighbor) | |||
870 | 762 | ||
871 | 763 | ||
872 | /* construct session ID seed as XOR of both peer's identities */ | 764 | /* construct session ID seed as XOR of both peer's identities */ |
873 | GNUNET_CRYPTO_hash (&my_identity, sizeof (my_identity), &h1); | 765 | GNUNET_CRYPTO_hash (&my_identity, |
874 | GNUNET_CRYPTO_hash (&neighbor->peer, sizeof (struct GNUNET_PeerIdentity), &h2); | 766 | sizeof (my_identity), |
767 | &h1); | ||
768 | GNUNET_CRYPTO_hash (neighbor->peer, | ||
769 | sizeof (struct GNUNET_PeerIdentity), | ||
770 | &h2); | ||
875 | GNUNET_CRYPTO_hash_xor (&h1, | 771 | GNUNET_CRYPTO_hash_xor (&h1, |
876 | &h2, | 772 | &h2, |
877 | &session_id); | 773 | &session_id); |
@@ -919,16 +815,21 @@ handle_direct_connect (struct DirectNeighbor *neighbor) | |||
919 | * | 815 | * |
920 | * @param cls closure | 816 | * @param cls closure |
921 | * @param peer peer identity this notification is about | 817 | * @param peer peer identity this notification is about |
818 | * @param mq message queue for sending data to @a peer | ||
819 | * @return our `struct DirectNeighbour` for this peer | ||
922 | */ | 820 | */ |
923 | static void | 821 | static void * |
924 | handle_core_connect (void *cls, | 822 | handle_core_connect (void *cls, |
925 | const struct GNUNET_PeerIdentity *peer) | 823 | const struct GNUNET_PeerIdentity *peer, |
824 | struct GNUNET_MQ_Handle *mq) | ||
926 | { | 825 | { |
927 | struct DirectNeighbor *neighbor; | 826 | struct DirectNeighbor *neighbor; |
928 | 827 | ||
929 | /* Check for connect to self message */ | 828 | /* Check for connect to self message */ |
930 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | 829 | if (0 == memcmp (&my_identity, |
931 | return; | 830 | peer, |
831 | sizeof (struct GNUNET_PeerIdentity))) | ||
832 | return NULL; | ||
932 | /* check if entry exists */ | 833 | /* check if entry exists */ |
933 | neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, | 834 | neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, |
934 | peer); | 835 | peer); |
@@ -942,23 +843,24 @@ handle_core_connect (void *cls, | |||
942 | GNUNET_i2s (peer), | 843 | GNUNET_i2s (peer), |
943 | (unsigned int) neighbor->distance); | 844 | (unsigned int) neighbor->distance); |
944 | if (DIRECT_NEIGHBOR_COST != neighbor->distance) | 845 | if (DIRECT_NEIGHBOR_COST != neighbor->distance) |
945 | return; | 846 | return NULL; |
946 | handle_direct_connect (neighbor); | 847 | handle_direct_connect (neighbor); |
947 | return; | 848 | return NULL; |
948 | } | 849 | } |
949 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
950 | "Core connected to %s (distance unknown)\n", | 851 | "Core connected to %s (distance unknown)\n", |
951 | GNUNET_i2s (peer)); | 852 | GNUNET_i2s (peer)); |
952 | neighbor = GNUNET_new (struct DirectNeighbor); | 853 | neighbor = GNUNET_new (struct DirectNeighbor); |
953 | neighbor->peer = *peer; | 854 | neighbor->peer = peer; |
954 | GNUNET_assert (GNUNET_YES == | 855 | GNUNET_assert (GNUNET_YES == |
955 | GNUNET_CONTAINER_multipeermap_put (direct_neighbors, | 856 | GNUNET_CONTAINER_multipeermap_put (direct_neighbors, |
956 | peer, | 857 | neighbor->peer, |
957 | neighbor, | 858 | neighbor, |
958 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 859 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
959 | neighbor->connected = GNUNET_YES; | 860 | neighbor->connected = GNUNET_YES; |
960 | neighbor->distance = 0; /* unknown */ | 861 | neighbor->distance = 0; /* unknown */ |
961 | neighbor->network = GNUNET_ATS_NET_UNSPECIFIED; | 862 | neighbor->network = GNUNET_ATS_NET_UNSPECIFIED; |
863 | return neighbor; | ||
962 | } | 864 | } |
963 | 865 | ||
964 | 866 | ||
@@ -1613,7 +1515,7 @@ listen_set_union (void *cls, | |||
1613 | return; /* why??? */ | 1515 | return; /* why??? */ |
1614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1615 | "Starting to create consensus with %s\n", | 1517 | "Starting to create consensus with %s\n", |
1616 | GNUNET_i2s (&neighbor->peer)); | 1518 | GNUNET_i2s (neighbor->peer)); |
1617 | if (NULL != neighbor->set_op) | 1519 | if (NULL != neighbor->set_op) |
1618 | { | 1520 | { |
1619 | GNUNET_SET_operation_cancel (neighbor->set_op); | 1521 | GNUNET_SET_operation_cancel (neighbor->set_op); |
@@ -1668,22 +1570,46 @@ initiate_set_union (void *cls) | |||
1668 | 1570 | ||
1669 | 1571 | ||
1670 | /** | 1572 | /** |
1573 | * Check that @a rm is well-formed. | ||
1574 | * | ||
1575 | * @param cls closure | ||
1576 | * @param rm the message | ||
1577 | * @return #GNUNET_OK if @a rm is well-formed. | ||
1578 | */ | ||
1579 | static int | ||
1580 | check_dv_route_message (void *cls, | ||
1581 | const struct RouteMessage *rm) | ||
1582 | { | ||
1583 | const struct GNUNET_MessageHeader *payload; | ||
1584 | |||
1585 | if (ntohs (rm->header.size) < sizeof (struct RouteMessage) + sizeof (struct GNUNET_MessageHeader)) | ||
1586 | { | ||
1587 | GNUNET_break_op (0); | ||
1588 | return GNUNET_SYSERR; | ||
1589 | } | ||
1590 | payload = (const struct GNUNET_MessageHeader *) &rm[1]; | ||
1591 | if (ntohs (rm->header.size) != sizeof (struct RouteMessage) + ntohs (payload->size)) | ||
1592 | { | ||
1593 | GNUNET_break_op (0); | ||
1594 | return GNUNET_SYSERR; | ||
1595 | } | ||
1596 | return GNUNET_OK; | ||
1597 | } | ||
1598 | |||
1599 | |||
1600 | /** | ||
1671 | * Core handler for DV data messages. Whatever this message | 1601 | * Core handler for DV data messages. Whatever this message |
1672 | * contains all we really have to do is rip it out of its | 1602 | * contains all we really have to do is rip it out of its |
1673 | * DV layering and give it to our pal the DV plugin to report | 1603 | * DV layering and give it to our pal the DV plugin to report |
1674 | * in with. | 1604 | * in with. |
1675 | * | 1605 | * |
1676 | * @param cls closure | 1606 | * @param cls closure |
1677 | * @param peer peer which sent the message (immediate sender) | 1607 | * @param rm the message |
1678 | * @param message the message | ||
1679 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the other peer violated the protocol | ||
1680 | */ | 1608 | */ |
1681 | static int | 1609 | static void |
1682 | handle_dv_route_message (void *cls, | 1610 | handle_dv_route_message (void *cls, |
1683 | const struct GNUNET_PeerIdentity *peer, | 1611 | const struct RouteMessage *rm) |
1684 | const struct GNUNET_MessageHeader *message) | ||
1685 | { | 1612 | { |
1686 | const struct RouteMessage *rm; | ||
1687 | const struct GNUNET_MessageHeader *payload; | 1613 | const struct GNUNET_MessageHeader *payload; |
1688 | struct Route *route; | 1614 | struct Route *route; |
1689 | struct DirectNeighbor *neighbor; | 1615 | struct DirectNeighbor *neighbor; |
@@ -1695,19 +1621,8 @@ handle_dv_route_message (void *cls, | |||
1695 | char prev[5]; | 1621 | char prev[5]; |
1696 | char dst[5]; | 1622 | char dst[5]; |
1697 | 1623 | ||
1698 | if (ntohs (message->size) < sizeof (struct RouteMessage) + sizeof (struct GNUNET_MessageHeader)) | ||
1699 | { | ||
1700 | GNUNET_break_op (0); | ||
1701 | return GNUNET_SYSERR; | ||
1702 | } | ||
1703 | rm = (const struct RouteMessage *) message; | ||
1704 | distance = ntohl (rm->distance); | 1624 | distance = ntohl (rm->distance); |
1705 | payload = (const struct GNUNET_MessageHeader *) &rm[1]; | 1625 | payload = (const struct GNUNET_MessageHeader *) &rm[1]; |
1706 | if (ntohs (message->size) != sizeof (struct RouteMessage) + ntohs (payload->size)) | ||
1707 | { | ||
1708 | GNUNET_break_op (0); | ||
1709 | return GNUNET_SYSERR; | ||
1710 | } | ||
1711 | strncpy (prev, GNUNET_i2s (peer), 4); | 1626 | strncpy (prev, GNUNET_i2s (peer), 4); |
1712 | strncpy (me, GNUNET_i2s (&my_identity), 4); | 1627 | strncpy (me, GNUNET_i2s (&my_identity), 4); |
1713 | strncpy (src, GNUNET_i2s (&rm->sender), 4); | 1628 | strncpy (src, GNUNET_i2s (&rm->sender), 4); |
@@ -1715,19 +1630,22 @@ handle_dv_route_message (void *cls, | |||
1715 | prev[4] = me[4] = src[4] = dst[4] = '\0'; | 1630 | prev[4] = me[4] = src[4] = dst[4] = '\0'; |
1716 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1631 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1717 | "Handling DV message with %u bytes payload of type %u from %s to %s routed by %s to me (%s @ hop %u)\n", | 1632 | "Handling DV message with %u bytes payload of type %u from %s to %s routed by %s to me (%s @ hop %u)\n", |
1718 | (unsigned int) (ntohs (message->size) - sizeof (struct RouteMessage)), | 1633 | (unsigned int) (ntohs (rm->header.size) - sizeof (struct RouteMessage)), |
1719 | ntohs (payload->type), | 1634 | ntohs (payload->type), |
1720 | src, dst, | 1635 | src, |
1721 | prev, me, | 1636 | dst, |
1637 | prev, | ||
1638 | me, | ||
1722 | (unsigned int) distance + 1); | 1639 | (unsigned int) distance + 1); |
1723 | 1640 | ||
1724 | if (0 == memcmp (&rm->target, | 1641 | if (0 == memcmp (&rm->target, |
1725 | &my_identity, | 1642 | &my_identity, |
1726 | sizeof (struct GNUNET_PeerIdentity))) | 1643 | sizeof (struct GNUNET_PeerIdentity))) |
1727 | { | 1644 | { |
1728 | if ((NULL | 1645 | if ((NULL != |
1729 | != (dn = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, | 1646 | (dn = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, |
1730 | &rm->sender))) && (DIRECT_NEIGHBOR_COST == dn->distance)) | 1647 | &rm->sender))) && |
1648 | (DIRECT_NEIGHBOR_COST == dn->distance)) | ||
1731 | { | 1649 | { |
1732 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1733 | "Discarding DV message, as %s is a direct neighbor\n", | 1651 | "Discarding DV message, as %s is a direct neighbor\n", |
@@ -1735,7 +1653,7 @@ handle_dv_route_message (void *cls, | |||
1735 | GNUNET_STATISTICS_update (stats, | 1653 | GNUNET_STATISTICS_update (stats, |
1736 | "# messages discarded (direct neighbor)", | 1654 | "# messages discarded (direct neighbor)", |
1737 | 1, GNUNET_NO); | 1655 | 1, GNUNET_NO); |
1738 | return GNUNET_OK; | 1656 | return; |
1739 | } | 1657 | } |
1740 | /* message is for me, check reverse route! */ | 1658 | /* message is for me, check reverse route! */ |
1741 | route = GNUNET_CONTAINER_multipeermap_get (all_routes, | 1659 | route = GNUNET_CONTAINER_multipeermap_get (all_routes, |
@@ -1749,7 +1667,7 @@ handle_dv_route_message (void *cls, | |||
1749 | if (NULL == neighbor) | 1667 | if (NULL == neighbor) |
1750 | { | 1668 | { |
1751 | GNUNET_break (0); | 1669 | GNUNET_break (0); |
1752 | return GNUNET_OK; | 1670 | return; |
1753 | } | 1671 | } |
1754 | target = GNUNET_new (struct Target); | 1672 | target = GNUNET_new (struct Target); |
1755 | target->peer = rm->sender; | 1673 | target->peer = rm->sender; |
@@ -1768,7 +1686,7 @@ handle_dv_route_message (void *cls, | |||
1768 | { | 1686 | { |
1769 | GNUNET_break_op (0); | 1687 | GNUNET_break_op (0); |
1770 | GNUNET_free (target); | 1688 | GNUNET_free (target); |
1771 | return GNUNET_OK; | 1689 | return; |
1772 | } | 1690 | } |
1773 | add_new_route (target, neighbor); | 1691 | add_new_route (target, neighbor); |
1774 | } | 1692 | } |
@@ -1779,7 +1697,7 @@ handle_dv_route_message (void *cls, | |||
1779 | send_data_to_plugin (payload, | 1697 | send_data_to_plugin (payload, |
1780 | &rm->sender, | 1698 | &rm->sender, |
1781 | 1 + distance); | 1699 | 1 + distance); |
1782 | return GNUNET_OK; | 1700 | return; |
1783 | } | 1701 | } |
1784 | if ( (NULL == GNUNET_CONTAINER_multipeermap_get (direct_neighbors, | 1702 | if ( (NULL == GNUNET_CONTAINER_multipeermap_get (direct_neighbors, |
1785 | &rm->sender)) && | 1703 | &rm->sender)) && |
@@ -1795,7 +1713,7 @@ handle_dv_route_message (void *cls, | |||
1795 | if (NULL == neighbor) | 1713 | if (NULL == neighbor) |
1796 | { | 1714 | { |
1797 | GNUNET_break (0); | 1715 | GNUNET_break (0); |
1798 | return GNUNET_OK; | 1716 | return; |
1799 | } | 1717 | } |
1800 | target = GNUNET_new (struct Target); | 1718 | target = GNUNET_new (struct Target); |
1801 | target->peer = rm->sender; | 1719 | target->peer = rm->sender; |
@@ -1810,7 +1728,7 @@ handle_dv_route_message (void *cls, | |||
1810 | { | 1728 | { |
1811 | GNUNET_break_op (0); | 1729 | GNUNET_break_op (0); |
1812 | GNUNET_free (target); | 1730 | GNUNET_free (target); |
1813 | return GNUNET_OK; | 1731 | return; |
1814 | } | 1732 | } |
1815 | add_new_route (target, neighbor); | 1733 | add_new_route (target, neighbor); |
1816 | } | 1734 | } |
@@ -1830,7 +1748,7 @@ handle_dv_route_message (void *cls, | |||
1830 | GNUNET_STATISTICS_update (stats, | 1748 | GNUNET_STATISTICS_update (stats, |
1831 | "# messages discarded (no route)", | 1749 | "# messages discarded (no route)", |
1832 | 1, GNUNET_NO); | 1750 | 1, GNUNET_NO); |
1833 | return GNUNET_OK; | 1751 | return; |
1834 | } | 1752 | } |
1835 | } | 1753 | } |
1836 | else | 1754 | else |
@@ -1839,13 +1757,12 @@ handle_dv_route_message (void *cls, | |||
1839 | } | 1757 | } |
1840 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1841 | "Forwarding message to %s\n", | 1759 | "Forwarding message to %s\n", |
1842 | GNUNET_i2s (&neighbor->peer)); | 1760 | GNUNET_i2s (neighbor->peer)); |
1843 | forward_payload (neighbor, | 1761 | forward_payload (neighbor, |
1844 | distance + 1, | 1762 | distance + 1, |
1845 | &rm->sender, | 1763 | &rm->sender, |
1846 | &rm->target, | 1764 | &rm->target, |
1847 | payload); | 1765 | payload); |
1848 | return GNUNET_OK; | ||
1849 | } | 1766 | } |
1850 | 1767 | ||
1851 | 1768 | ||
@@ -1918,20 +1835,10 @@ handle_dv_send_message (void *cls, | |||
1918 | static void | 1835 | static void |
1919 | cleanup_neighbor (struct DirectNeighbor *neighbor) | 1836 | cleanup_neighbor (struct DirectNeighbor *neighbor) |
1920 | { | 1837 | { |
1921 | struct PendingMessage *pending; | ||
1922 | |||
1923 | while (NULL != (pending = neighbor->pm_head)) | ||
1924 | { | ||
1925 | neighbor->pm_queue_size--; | ||
1926 | GNUNET_CONTAINER_DLL_remove (neighbor->pm_head, | ||
1927 | neighbor->pm_tail, | ||
1928 | pending); | ||
1929 | GNUNET_free (pending); | ||
1930 | } | ||
1931 | handle_direct_disconnect (neighbor); | 1838 | handle_direct_disconnect (neighbor); |
1932 | GNUNET_assert (GNUNET_YES == | 1839 | GNUNET_assert (GNUNET_YES == |
1933 | GNUNET_CONTAINER_multipeermap_remove (direct_neighbors, | 1840 | GNUNET_CONTAINER_multipeermap_remove (direct_neighbors, |
1934 | &neighbor->peer, | 1841 | neighbor->peer, |
1935 | neighbor)); | 1842 | neighbor)); |
1936 | GNUNET_free (neighbor); | 1843 | GNUNET_free (neighbor); |
1937 | } | 1844 | } |
@@ -1942,36 +1849,31 @@ cleanup_neighbor (struct DirectNeighbor *neighbor) | |||
1942 | * | 1849 | * |
1943 | * @param cls closure | 1850 | * @param cls closure |
1944 | * @param peer peer identity this notification is about | 1851 | * @param peer peer identity this notification is about |
1852 | * @param internal_cls the corresponding `struct DirectNeighbor` | ||
1945 | */ | 1853 | */ |
1946 | static void | 1854 | static void |
1947 | handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 1855 | handle_core_disconnect (void *cls, |
1856 | const struct GNUNET_PeerIdentity *peer, | ||
1857 | void *internal_cls) | ||
1948 | { | 1858 | { |
1949 | struct DirectNeighbor *neighbor; | 1859 | struct DirectNeighbor *neighbor = internal_cls; |
1950 | 1860 | ||
1951 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1861 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1952 | "Received core peer disconnect message for peer `%s'!\n", | 1862 | "Received core peer disconnect message for peer `%s'!\n", |
1953 | GNUNET_i2s (peer)); | 1863 | GNUNET_i2s (peer)); |
1954 | /* Check for disconnect from self message */ | 1864 | /* Check for disconnect from self message */ |
1955 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | ||
1956 | return; | ||
1957 | neighbor = | ||
1958 | GNUNET_CONTAINER_multipeermap_get (direct_neighbors, peer); | ||
1959 | if (NULL == neighbor) | 1865 | if (NULL == neighbor) |
1960 | { | ||
1961 | GNUNET_break (0); | ||
1962 | return; | 1866 | return; |
1963 | } | ||
1964 | GNUNET_break (GNUNET_YES == neighbor->connected); | 1867 | GNUNET_break (GNUNET_YES == neighbor->connected); |
1965 | neighbor->connected = GNUNET_NO; | 1868 | neighbor->connected = GNUNET_NO; |
1966 | if (DIRECT_NEIGHBOR_COST == neighbor->distance) | 1869 | if (DIRECT_NEIGHBOR_COST == neighbor->distance) |
1967 | { | 1870 | { |
1968 | |||
1969 | GNUNET_STATISTICS_update (stats, | 1871 | GNUNET_STATISTICS_update (stats, |
1970 | "# peers connected (1-hop)", | 1872 | "# peers connected (1-hop)", |
1971 | -1, GNUNET_NO); | 1873 | -1, |
1874 | GNUNET_NO); | ||
1972 | } | 1875 | } |
1973 | cleanup_neighbor (neighbor); | 1876 | cleanup_neighbor (neighbor); |
1974 | |||
1975 | if (GNUNET_YES == in_shutdown) | 1877 | if (GNUNET_YES == in_shutdown) |
1976 | return; | 1878 | return; |
1977 | schedule_refresh_routes (); | 1879 | schedule_refresh_routes (); |
@@ -2035,14 +1937,16 @@ shutdown_task (void *cls) | |||
2035 | 1937 | ||
2036 | in_shutdown = GNUNET_YES; | 1938 | in_shutdown = GNUNET_YES; |
2037 | GNUNET_assert (NULL != core_api); | 1939 | GNUNET_assert (NULL != core_api); |
2038 | GNUNET_CORE_disconnect (core_api); | 1940 | GNUNET_CORE_disconnecT (core_api); |
2039 | core_api = NULL; | 1941 | core_api = NULL; |
2040 | GNUNET_ATS_performance_done (ats); | 1942 | GNUNET_ATS_performance_done (ats); |
2041 | ats = NULL; | 1943 | ats = NULL; |
2042 | GNUNET_CONTAINER_multipeermap_iterate (direct_neighbors, | 1944 | GNUNET_CONTAINER_multipeermap_iterate (direct_neighbors, |
2043 | &free_direct_neighbors, NULL); | 1945 | &free_direct_neighbors, |
1946 | NULL); | ||
2044 | GNUNET_CONTAINER_multipeermap_iterate (all_routes, | 1947 | GNUNET_CONTAINER_multipeermap_iterate (all_routes, |
2045 | &free_route, NULL); | 1948 | &free_route, |
1949 | NULL); | ||
2046 | GNUNET_CONTAINER_multipeermap_destroy (direct_neighbors); | 1950 | GNUNET_CONTAINER_multipeermap_destroy (direct_neighbors); |
2047 | GNUNET_CONTAINER_multipeermap_destroy (all_routes); | 1951 | GNUNET_CONTAINER_multipeermap_destroy (all_routes); |
2048 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 1952 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
@@ -2103,7 +2007,8 @@ notify_client_about_route (void *cls, | |||
2103 | * @param message the actual message | 2007 | * @param message the actual message |
2104 | */ | 2008 | */ |
2105 | static void | 2009 | static void |
2106 | handle_start (void *cls, struct GNUNET_SERVER_Client *client, | 2010 | handle_start (void *cls, |
2011 | struct GNUNET_SERVER_Client *client, | ||
2107 | const struct GNUNET_MessageHeader *message) | 2012 | const struct GNUNET_MessageHeader *message) |
2108 | { | 2013 | { |
2109 | GNUNET_SERVER_notification_context_add (nc, client); | 2014 | GNUNET_SERVER_notification_context_add (nc, client); |
@@ -2139,12 +2044,16 @@ core_init (void *cls, | |||
2139 | * @param c configuration to use | 2044 | * @param c configuration to use |
2140 | */ | 2045 | */ |
2141 | static void | 2046 | static void |
2142 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 2047 | run (void *cls, |
2048 | struct GNUNET_SERVER_Handle *server, | ||
2143 | const struct GNUNET_CONFIGURATION_Handle *c) | 2049 | const struct GNUNET_CONFIGURATION_Handle *c) |
2144 | { | 2050 | { |
2145 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { | 2051 | GNUNET_MQ_hd_var_size (dv_route_message, |
2146 | {&handle_dv_route_message, GNUNET_MESSAGE_TYPE_DV_ROUTE, 0}, | 2052 | GNUNET_MESSAGE_TYPE_DV_ROUTE, |
2147 | {NULL, 0, 0} | 2053 | struct RouteMessage); |
2054 | struct GNUNET_MQ_MessageHandler core_handlers[] = { | ||
2055 | make_dv_route_message_handler (NULL), | ||
2056 | GNUNET_MQ_handler_end () | ||
2148 | }; | 2057 | }; |
2149 | static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { | 2058 | static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { |
2150 | {&handle_start, NULL, | 2059 | {&handle_start, NULL, |
@@ -2157,30 +2066,36 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
2157 | }; | 2066 | }; |
2158 | in_shutdown = GNUNET_NO; | 2067 | in_shutdown = GNUNET_NO; |
2159 | cfg = c; | 2068 | cfg = c; |
2160 | direct_neighbors = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); | 2069 | direct_neighbors = GNUNET_CONTAINER_multipeermap_create (128, |
2161 | all_routes = GNUNET_CONTAINER_multipeermap_create (65536, GNUNET_NO); | 2070 | GNUNET_NO); |
2162 | core_api = GNUNET_CORE_connect (cfg, NULL, | 2071 | all_routes = GNUNET_CONTAINER_multipeermap_create (65536, |
2072 | GNUNET_NO); | ||
2073 | core_api = GNUNET_CORE_connecT (cfg, | ||
2074 | NULL, | ||
2163 | &core_init, | 2075 | &core_init, |
2164 | &handle_core_connect, | 2076 | &handle_core_connect, |
2165 | &handle_core_disconnect, | 2077 | &handle_core_disconnect, |
2166 | NULL, GNUNET_NO, | ||
2167 | NULL, GNUNET_NO, | ||
2168 | core_handlers); | 2078 | core_handlers); |
2169 | 2079 | ||
2170 | if (NULL == core_api) | 2080 | if (NULL == core_api) |
2171 | return; | 2081 | return; |
2172 | ats = GNUNET_ATS_performance_init (cfg, &handle_ats_update, NULL); | 2082 | ats = GNUNET_ATS_performance_init (cfg, |
2083 | &handle_ats_update, | ||
2084 | NULL); | ||
2173 | if (NULL == ats) | 2085 | if (NULL == ats) |
2174 | { | 2086 | { |
2175 | GNUNET_CORE_disconnect (core_api); | 2087 | GNUNET_CORE_disconnecT (core_api); |
2176 | core_api = NULL; | 2088 | core_api = NULL; |
2177 | return; | 2089 | return; |
2178 | } | 2090 | } |
2179 | nc = GNUNET_SERVER_notification_context_create (server, | 2091 | nc = GNUNET_SERVER_notification_context_create (server, |
2180 | MAX_QUEUE_SIZE_PLUGIN); | 2092 | MAX_QUEUE_SIZE_PLUGIN); |
2181 | stats = GNUNET_STATISTICS_create ("dv", cfg); | 2093 | stats = GNUNET_STATISTICS_create ("dv", |
2182 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | 2094 | cfg); |
2183 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 2095 | GNUNET_SERVER_add_handlers (server, |
2096 | plugin_handlers); | ||
2097 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
2098 | NULL); | ||
2184 | } | 2099 | } |
2185 | 2100 | ||
2186 | 2101 | ||
@@ -2192,11 +2107,16 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
2192 | * @return 0 ok, 1 on error | 2107 | * @return 0 ok, 1 on error |
2193 | */ | 2108 | */ |
2194 | int | 2109 | int |
2195 | main (int argc, char *const *argv) | 2110 | main (int argc, |
2111 | char *const *argv) | ||
2196 | { | 2112 | { |
2197 | return (GNUNET_OK == | 2113 | return (GNUNET_OK == |
2198 | GNUNET_SERVICE_run (argc, argv, "dv", GNUNET_SERVICE_OPTION_NONE, | 2114 | GNUNET_SERVICE_run (argc, |
2199 | &run, NULL)) ? 0 : 1; | 2115 | argv, |
2116 | "dv", | ||
2117 | GNUNET_SERVICE_OPTION_NONE, | ||
2118 | &run, | ||
2119 | NULL)) ? 0 : 1; | ||
2200 | } | 2120 | } |
2201 | 2121 | ||
2202 | /* end of gnunet-service-dv.c */ | 2122 | /* end of gnunet-service-dv.c */ |
diff --git a/src/util/mq.c b/src/util/mq.c index a4ea5e39d..bea5eb304 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -632,8 +632,8 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp, | |||
632 | 632 | ||
633 | mqm = GNUNET_MQ_msg_ (mhp, size, type); | 633 | mqm = GNUNET_MQ_msg_ (mhp, size, type); |
634 | GNUNET_memcpy ((char *) mqm->mh + base_size, | 634 | GNUNET_memcpy ((char *) mqm->mh + base_size, |
635 | nested_mh, | 635 | nested_mh, |
636 | ntohs (nested_mh->size)); | 636 | ntohs (nested_mh->size)); |
637 | 637 | ||
638 | return mqm; | 638 | return mqm; |
639 | } | 639 | } |