diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-05-28 14:50:21 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-05-28 14:50:21 +0000 |
commit | 7eaca78577175efa02a194244be3471c847502b0 (patch) | |
tree | f8ff191df80fe2bfd56ef527fefb3e3f66ed3db1 | |
parent | ee7019c65d09225e211e43434ab0537682205254 (diff) | |
download | gnunet-7eaca78577175efa02a194244be3471c847502b0.tar.gz gnunet-7eaca78577175efa02a194244be3471c847502b0.zip |
Adapting verify successor code to use trail id
Linear lookup in find_successor()
Typo fix in comment of trail compression
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 964 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_routing.c | 2 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 2 |
3 files changed, 704 insertions, 264 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 3aac5ad59..1df5a49a2 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -80,6 +80,11 @@ | |||
80 | #define PUT_GET_REQUEST 65 | 80 | #define PUT_GET_REQUEST 65 |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Maximum number of trails that can go through a friend. | ||
84 | */ | ||
85 | #define TRAIL_THROUGH_FRIEND_THRESHOLD 64 | ||
86 | |||
87 | /** | ||
83 | * Finger map index for predecessor entry in finger peermap. | 88 | * Finger map index for predecessor entry in finger peermap. |
84 | */ | 89 | */ |
85 | #define PREDECESSOR_FINGER_ID 64 | 90 | #define PREDECESSOR_FINGER_ID 64 |
@@ -174,10 +179,13 @@ struct PeerTrailSetupResultMessage | |||
174 | * Identifier of the trail. | 179 | * Identifier of the trail. |
175 | */ | 180 | */ |
176 | struct GNUNET_HashCode trail_id; | 181 | struct GNUNET_HashCode trail_id; |
177 | /* Trail from destination_peer to finger_identity */ | ||
178 | 182 | ||
183 | /* Trail from destination_peer to finger_identity */ | ||
179 | }; | 184 | }; |
180 | 185 | ||
186 | /** | ||
187 | * P2P Verify Successor Message. | ||
188 | */ | ||
181 | struct PeerVerifySuccessorMessage | 189 | struct PeerVerifySuccessorMessage |
182 | { | 190 | { |
183 | /** | 191 | /** |
@@ -199,8 +207,18 @@ struct PeerVerifySuccessorMessage | |||
199 | * Identifier of trail to reach from source_peer to successor. | 207 | * Identifier of trail to reach from source_peer to successor. |
200 | */ | 208 | */ |
201 | struct GNUNET_HashCode trail_id; | 209 | struct GNUNET_HashCode trail_id; |
210 | |||
211 | /** | ||
212 | * Total number of peers to reach from source to successor. | ||
213 | */ | ||
214 | unsigned int trail_length; | ||
215 | |||
216 | /* Trail. */ | ||
202 | }; | 217 | }; |
203 | 218 | ||
219 | /** | ||
220 | * P2P Verify Successor Result Message | ||
221 | */ | ||
204 | struct PeerVerifySuccessorResultMessage | 222 | struct PeerVerifySuccessorResultMessage |
205 | { | 223 | { |
206 | /** | 224 | /** |
@@ -228,7 +246,11 @@ struct PeerVerifySuccessorResultMessage | |||
228 | */ | 246 | */ |
229 | struct GNUNET_HashCode trail_id; | 247 | struct GNUNET_HashCode trail_id; |
230 | 248 | ||
249 | /** | ||
250 | * Direction in which we are looking at the trail. | ||
251 | */ | ||
231 | enum GDS_ROUTING_trail_direction trail_direction; | 252 | enum GDS_ROUTING_trail_direction trail_direction; |
253 | |||
232 | /** | 254 | /** |
233 | * Total number of peers in trail from source_successor to my_predecessor | 255 | * Total number of peers in trail from source_successor to my_predecessor |
234 | * if my_predecessor is not same as destination_peer. | 256 | * if my_predecessor is not same as destination_peer. |
@@ -239,6 +261,9 @@ struct PeerVerifySuccessorResultMessage | |||
239 | * my_predecessor != destination_peer*/ | 261 | * my_predecessor != destination_peer*/ |
240 | }; | 262 | }; |
241 | 263 | ||
264 | /** | ||
265 | * P2P Notify New Successor Message. | ||
266 | */ | ||
242 | struct PeerNotifyNewSuccessorMessage | 267 | struct PeerNotifyNewSuccessorMessage |
243 | { | 268 | { |
244 | /** | 269 | /** |
@@ -256,15 +281,21 @@ struct PeerNotifyNewSuccessorMessage | |||
256 | */ | 281 | */ |
257 | struct GNUNET_PeerIdentity destination_peer; | 282 | struct GNUNET_PeerIdentity destination_peer; |
258 | 283 | ||
284 | /** | ||
285 | * Total number of peers in trail from source_peer to destination_peer | ||
286 | */ | ||
259 | unsigned int trail_length; | 287 | unsigned int trail_length; |
260 | 288 | ||
289 | /** | ||
290 | * Unique identifier of the trail. | ||
291 | */ | ||
261 | struct GNUNET_HashCode trail_id; | 292 | struct GNUNET_HashCode trail_id; |
262 | 293 | ||
263 | /* Trail. */ | 294 | /* Trail. */ |
264 | }; | 295 | }; |
265 | 296 | ||
266 | /** | 297 | /** |
267 | * Trail compressiong message. | 298 | * P2P Trail Compression Message. |
268 | */ | 299 | */ |
269 | struct PeerTrailCompressionMessage | 300 | struct PeerTrailCompressionMessage |
270 | { | 301 | { |
@@ -296,8 +327,9 @@ struct PeerTrailCompressionMessage | |||
296 | struct GNUNET_HashCode trail_id; | 327 | struct GNUNET_HashCode trail_id; |
297 | }; | 328 | }; |
298 | 329 | ||
330 | |||
299 | /** | 331 | /** |
300 | * Trail Tear Down message. | 332 | * P2P Trail Tear Down message. |
301 | */ | 333 | */ |
302 | struct PeerTrailTearDownMessage | 334 | struct PeerTrailTearDownMessage |
303 | { | 335 | { |
@@ -307,8 +339,9 @@ struct PeerTrailTearDownMessage | |||
307 | struct GNUNET_MessageHeader header; | 339 | struct GNUNET_MessageHeader header; |
308 | }; | 340 | }; |
309 | 341 | ||
342 | |||
310 | /** | 343 | /** |
311 | * Trail Rejection Message. | 344 | * P2P Trail Rejection Message. |
312 | */ | 345 | */ |
313 | struct PeerTrailRejectionMessage | 346 | struct PeerTrailRejectionMessage |
314 | { | 347 | { |
@@ -356,6 +389,39 @@ struct PeerTrailRejectionMessage | |||
356 | * to congested peer.*/ | 389 | * to congested peer.*/ |
357 | }; | 390 | }; |
358 | 391 | ||
392 | /** | ||
393 | * P2P Add Trail Message. | ||
394 | */ | ||
395 | struct PeerAddTrailMessage | ||
396 | { | ||
397 | /** | ||
398 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_ADD_TRAIL | ||
399 | */ | ||
400 | struct GNUNET_MessageHeader header; | ||
401 | |||
402 | /** | ||
403 | * Source peer of the routing trail. | ||
404 | */ | ||
405 | struct GNUNET_PeerIdentity source_peer; | ||
406 | |||
407 | /** | ||
408 | * Destination peer of the routing trail. | ||
409 | */ | ||
410 | struct GNUNET_PeerIdentity destination_peer; | ||
411 | |||
412 | /** | ||
413 | * Total number of peers from source peer to destination peer. | ||
414 | */ | ||
415 | unsigned int trail_length; | ||
416 | |||
417 | /** | ||
418 | * Unique identifier of the trail. | ||
419 | */ | ||
420 | struct GNUNET_HashCode trail_id; | ||
421 | |||
422 | /* Trail from source peer to destination peer. */ | ||
423 | }; | ||
424 | |||
359 | GNUNET_NETWORK_STRUCT_END | 425 | GNUNET_NETWORK_STRUCT_END |
360 | 426 | ||
361 | /** | 427 | /** |
@@ -487,7 +553,6 @@ struct TrailList | |||
487 | unsigned int first_friend_trail_count; | 553 | unsigned int first_friend_trail_count; |
488 | }; | 554 | }; |
489 | 555 | ||
490 | |||
491 | /** | 556 | /** |
492 | * An entry in finger_hashmap. | 557 | * An entry in finger_hashmap. |
493 | */ | 558 | */ |
@@ -514,6 +579,53 @@ struct FingerInfo | |||
514 | struct TrailList trail_list[MAXIMUM_TRAILS_PER_FINGER]; | 579 | struct TrailList trail_list[MAXIMUM_TRAILS_PER_FINGER]; |
515 | }; | 580 | }; |
516 | 581 | ||
582 | /** | ||
583 | * Data structure to keep track of closest peer seen so far in find_successor() | ||
584 | */ | ||
585 | struct Closest_Peer | ||
586 | { | ||
587 | /** | ||
588 | * 64 bit value of the peer | ||
589 | */ | ||
590 | uint64_t value; | ||
591 | |||
592 | /** | ||
593 | * Trail id to reach to peer. | ||
594 | */ | ||
595 | struct GNUNET_HashCode trail_id; | ||
596 | |||
597 | /** | ||
598 | * First hop, NULL in case of friend and my_identity | ||
599 | */ | ||
600 | struct GNUNET_PeerIdentity next_hop; | ||
601 | |||
602 | /** | ||
603 | * Next destination. In case of friend and my_identity , it is same as next_hop | ||
604 | * In case of finger it is finger identity. | ||
605 | */ | ||
606 | struct GNUNET_PeerIdentity next_destination; | ||
607 | }; | ||
608 | |||
609 | /** | ||
610 | * Data structure to store the trail chosen to reach to finger. | ||
611 | */ | ||
612 | struct Correct_Trail | ||
613 | { | ||
614 | /** | ||
615 | * First friend in the trail to reach finger. | ||
616 | */ | ||
617 | struct FriendInfo friend; | ||
618 | |||
619 | /** | ||
620 | * Identifier of this trail. | ||
621 | */ | ||
622 | struct GNUNET_HashCode trail_id; | ||
623 | |||
624 | /** | ||
625 | * Total number of peers in this trail. | ||
626 | */ | ||
627 | unsigned int trail_length; | ||
628 | }; | ||
517 | 629 | ||
518 | /** | 630 | /** |
519 | * Task that sends FIND FINGER TRAIL requests. This task is started when we have | 631 | * Task that sends FIND FINGER TRAIL requests. This task is started when we have |
@@ -728,13 +840,13 @@ GDS_NEIGHBOURS_send_trail_setup (const struct GNUNET_PeerIdentity source_peer, | |||
728 | 840 | ||
729 | /** | 841 | /** |
730 | * Construct a trail setup result message and forward it to target friend. | 842 | * Construct a trail setup result message and forward it to target friend. |
731 | * @param destination_peer | 843 | * @param destination_peer Peer which will get the trail to one of its finger. |
732 | * @param source_finger | 844 | * @param source_finger Peer to which the trail has been setup to. |
733 | * @param target_friend | 845 | * @param target_friend Friend to which this message should be forwarded. |
734 | * @param trail_length | 846 | * @param trail_length Numbers of peers in the trail. |
735 | * @param trail_peer_list | 847 | * @param trail_peer_list Peers which are part of the trail from source to destination. |
736 | * @param finger_map_index | 848 | * @param finger_map_index Index in finger peer map |
737 | * @param trail_id | 849 | * @param trail_id Unique identifier of the trail. |
738 | */ | 850 | */ |
739 | void | 851 | void |
740 | GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity destination_peer, | 852 | GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity destination_peer, |
@@ -865,16 +977,21 @@ GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer, | |||
865 | * @param source_peer Peer which wants to verify its successor. | 977 | * @param source_peer Peer which wants to verify its successor. |
866 | * @param successor Peer which is @a source_peer's current successor. | 978 | * @param successor Peer which is @a source_peer's current successor. |
867 | * @param trail_id Identifier of trail to reach successor. | 979 | * @param trail_id Identifier of trail to reach successor. |
980 | * @param trail Trail to reach from source_peer to successor | ||
981 | * @param trail_length Total number of peers in @a trail. | ||
868 | * @param target_friend Message send to this friend. | 982 | * @param target_friend Message send to this friend. |
869 | */ | 983 | */ |
870 | void | 984 | void |
871 | GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_peer, | 985 | GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_peer, |
872 | struct GNUNET_PeerIdentity successor, | 986 | struct GNUNET_PeerIdentity successor, |
873 | const struct GNUNET_HashCode trail_id, | 987 | const struct GNUNET_HashCode trail_id, |
988 | struct GNUNET_PeerIdentity *trail, | ||
989 | unsigned int trail_length, | ||
874 | struct FriendInfo *target_friend) | 990 | struct FriendInfo *target_friend) |
875 | { | 991 | { |
876 | struct PeerVerifySuccessorMessage *vsm; | 992 | struct PeerVerifySuccessorMessage *vsm; |
877 | struct P2PPendingMessage *pending; | 993 | struct P2PPendingMessage *pending; |
994 | struct GNUNET_PeerIdentity *peer_list; | ||
878 | size_t msize; | 995 | size_t msize; |
879 | 996 | ||
880 | msize = sizeof (struct PeerVerifySuccessorMessage); | 997 | msize = sizeof (struct PeerVerifySuccessorMessage); |
@@ -900,6 +1017,13 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_ | |||
900 | vsm->source_peer = source_peer; | 1017 | vsm->source_peer = source_peer; |
901 | vsm->successor = successor; | 1018 | vsm->successor = successor; |
902 | vsm->trail_id = trail_id; | 1019 | vsm->trail_id = trail_id; |
1020 | vsm->trail_length = htonl (trail_length); | ||
1021 | |||
1022 | if (trail_length > 0) | ||
1023 | { | ||
1024 | peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; | ||
1025 | memcpy (peer_list, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
1026 | } | ||
903 | 1027 | ||
904 | /* Send the message to chosen friend. */ | 1028 | /* Send the message to chosen friend. */ |
905 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 1029 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
@@ -909,7 +1033,7 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_ | |||
909 | 1033 | ||
910 | 1034 | ||
911 | /** | 1035 | /** |
912 | * | 1036 | * Construct a trail teardown message and send it to target_friend |
913 | * @param source_peer | 1037 | * @param source_peer |
914 | * @param destination_peer | 1038 | * @param destination_peer |
915 | * @param trail_id | 1039 | * @param trail_id |
@@ -928,7 +1052,7 @@ GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_PeerIdentity source_peer, | |||
928 | 1052 | ||
929 | 1053 | ||
930 | /** | 1054 | /** |
931 | * | 1055 | * Construct a verify successor message and send it to target_friend |
932 | * @param destination_peer | 1056 | * @param destination_peer |
933 | * @param source_successor | 1057 | * @param source_successor |
934 | * @param succ_predecessor | 1058 | * @param succ_predecessor |
@@ -993,7 +1117,7 @@ GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity destinat | |||
993 | 1117 | ||
994 | 1118 | ||
995 | /** | 1119 | /** |
996 | * | 1120 | * Construct a notify new successor message and send it to target_friend |
997 | * @param source_peer | 1121 | * @param source_peer |
998 | * @param new_successor | 1122 | * @param new_successor |
999 | * @param new_successor_trail | 1123 | * @param new_successor_trail |
@@ -1054,7 +1178,70 @@ GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity source_peer | |||
1054 | 1178 | ||
1055 | 1179 | ||
1056 | /** | 1180 | /** |
1057 | * Send a trail compression message to target_friend. | 1181 | * Construct an add_trail message and send it to target_friend |
1182 | * @param source_peer Source of the trail. | ||
1183 | * @param destination_peer Destination of the trail. | ||
1184 | * @param trail_id Unique identifer of the trail | ||
1185 | * @param trail Trail from @a source_peer to @a destination_peer | ||
1186 | * @param trail_length Total number of peers in @a trail. | ||
1187 | * @param target_friend Next peer to get this message. | ||
1188 | */ | ||
1189 | void | ||
1190 | GDS_NEIGHBOURS_send_add_trail (struct GNUNET_PeerIdentity source_peer, | ||
1191 | struct GNUNET_PeerIdentity destination_peer, | ||
1192 | struct GNUNET_HashCode trail_id, | ||
1193 | struct GNUNET_PeerIdentity *trail, | ||
1194 | unsigned int trail_length, | ||
1195 | struct FriendInfo *target_friend) | ||
1196 | { | ||
1197 | struct PeerAddTrailMessage *adm; | ||
1198 | struct GNUNET_PeerIdentity *peer_list; | ||
1199 | struct P2PPendingMessage *pending; | ||
1200 | size_t msize; | ||
1201 | |||
1202 | msize = sizeof (struct PeerAddTrailMessage) + | ||
1203 | (trail_length * sizeof(struct GNUNET_PeerIdentity)); | ||
1204 | |||
1205 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
1206 | { | ||
1207 | GNUNET_break (0); | ||
1208 | return; | ||
1209 | } | ||
1210 | |||
1211 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1212 | { | ||
1213 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | ||
1214 | 1, GNUNET_NO); | ||
1215 | } | ||
1216 | |||
1217 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | ||
1218 | pending->importance = 0; /* FIXME */ | ||
1219 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | ||
1220 | adm = (struct PeerAddTrailMessage *) &pending[1]; | ||
1221 | pending->msg = &adm->header; | ||
1222 | adm->header.size = htons (msize); | ||
1223 | adm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_ADD_TRAIL); | ||
1224 | adm->source_peer = source_peer; | ||
1225 | adm->destination_peer = destination_peer; | ||
1226 | adm->trail_length = htonl (trail_length); | ||
1227 | adm->trail_id = trail_id; | ||
1228 | |||
1229 | if (trail_length > 0) | ||
1230 | { | ||
1231 | peer_list = (struct GNUNET_PeerIdentity *)&adm[1]; | ||
1232 | memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * trail_length); | ||
1233 | } | ||
1234 | |||
1235 | /* Send the message to chosen friend. */ | ||
1236 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | ||
1237 | target_friend->pending_count++; | ||
1238 | process_friend_queue (target_friend); | ||
1239 | |||
1240 | } | ||
1241 | |||
1242 | |||
1243 | /** | ||
1244 | * Construct a trail compression message and send it to target_friend. | ||
1058 | * @param source_peer Source of the trail. | 1245 | * @param source_peer Source of the trail. |
1059 | * @param destination_finger Destination of trail. | 1246 | * @param destination_finger Destination of trail. |
1060 | * @param trail_id Unique identifier of trail. | 1247 | * @param trail_id Unique identifier of trail. |
@@ -1105,99 +1292,6 @@ GDS_NEIGHBOURS_send_trail_compression (struct GNUNET_PeerIdentity source_peer, | |||
1105 | 1292 | ||
1106 | } | 1293 | } |
1107 | 1294 | ||
1108 | /** | ||
1109 | * Construct a Put message and send it to target_peer. | ||
1110 | * @param key Key for the content | ||
1111 | * @param block_type Type of the block | ||
1112 | * @param options Routing options | ||
1113 | * @param desired_replication_level Desired replication count | ||
1114 | * @param current_destination Next current destination which will get this message. | ||
1115 | * @param current_source Source for @a current_destination | ||
1116 | * @param target_peer Peer to which this message will be forwarded. | ||
1117 | * @param hop_count Number of hops traversed so far. | ||
1118 | * @param put_path_length Total number of peers in @a put_path | ||
1119 | * @param put_path Number of peers traversed so far | ||
1120 | * @param expiration_time When does the content expire | ||
1121 | * @param data Content to store | ||
1122 | * @param data_size Size of content @a data in bytes | ||
1123 | */ | ||
1124 | void | ||
1125 | GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | ||
1126 | enum GNUNET_BLOCK_Type block_type, | ||
1127 | enum GNUNET_DHT_RouteOption options, | ||
1128 | uint32_t desired_replication_level, | ||
1129 | struct GNUNET_PeerIdentity current_destination, | ||
1130 | struct GNUNET_PeerIdentity current_source, | ||
1131 | struct GNUNET_PeerIdentity *target_peer, | ||
1132 | uint32_t hop_count, | ||
1133 | uint32_t put_path_length, | ||
1134 | struct GNUNET_PeerIdentity *put_path, | ||
1135 | struct GNUNET_TIME_Absolute expiration_time, | ||
1136 | const void *data, size_t data_size) | ||
1137 | { | ||
1138 | |||
1139 | } | ||
1140 | |||
1141 | /** | ||
1142 | * Construct a Get message and send it to target_peer. | ||
1143 | * @param key Key for the content | ||
1144 | * @param block_type Type of the block | ||
1145 | * @param options Routing options | ||
1146 | * @param desired_replication_level Desired replication count | ||
1147 | * @param current_destination Next current destination which will get this message. | ||
1148 | * @param current_source Source for @a current_destination | ||
1149 | * @param target_peer Peer to which this message will be forwarded. | ||
1150 | * @param hop_count Number of hops traversed so far. | ||
1151 | * @param data Content to store | ||
1152 | * @param data_size Size of content @a data in bytes | ||
1153 | * @param get_path_length Total number of peers in @a get_path | ||
1154 | * @param get_path Number of peers traversed so far | ||
1155 | */ | ||
1156 | void | ||
1157 | GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | ||
1158 | enum GNUNET_BLOCK_Type block_type, | ||
1159 | enum GNUNET_DHT_RouteOption options, | ||
1160 | uint32_t desired_replication_level, | ||
1161 | struct GNUNET_PeerIdentity current_destination, | ||
1162 | struct GNUNET_PeerIdentity current_source, | ||
1163 | struct GNUNET_PeerIdentity *target_peer, | ||
1164 | uint32_t hop_count, | ||
1165 | uint32_t get_path_length, | ||
1166 | struct GNUNET_PeerIdentity *get_path) | ||
1167 | { | ||
1168 | |||
1169 | } | ||
1170 | |||
1171 | |||
1172 | /** | ||
1173 | * Send the get result to requesting client. | ||
1174 | * @param key Key of the requested data. | ||
1175 | * @param type Block type | ||
1176 | * @param target_peer Next peer to forward the message to. | ||
1177 | * @param source_peer Peer which has the data for the key. | ||
1178 | * @param put_path_length Number of peers in @a put_path | ||
1179 | * @param put_path Path taken to put the data at its stored location. | ||
1180 | * @param get_path_length Number of peers in @a get_path | ||
1181 | * @param get_path Path taken to reach to the location of the key. | ||
1182 | * @param expiration When will this result expire? | ||
1183 | * @param data Payload to store | ||
1184 | * @param data_size Size of the @a data | ||
1185 | */ | ||
1186 | void | ||
1187 | GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | ||
1188 | enum GNUNET_BLOCK_Type type, | ||
1189 | struct GNUNET_PeerIdentity *target_peer, | ||
1190 | struct GNUNET_PeerIdentity *source_peer, | ||
1191 | unsigned int put_path_length, | ||
1192 | const struct GNUNET_PeerIdentity *put_path, | ||
1193 | unsigned int get_path_length, | ||
1194 | struct GNUNET_PeerIdentity *get_path, | ||
1195 | struct GNUNET_TIME_Absolute expiration, | ||
1196 | const void *data, size_t data_size) | ||
1197 | { | ||
1198 | |||
1199 | } | ||
1200 | |||
1201 | 1295 | ||
1202 | /** | 1296 | /** |
1203 | * Seach my location in trail. | 1297 | * Seach my location in trail. |
@@ -1222,27 +1316,63 @@ search_my_index (const struct GNUNET_PeerIdentity *trail, | |||
1222 | 1316 | ||
1223 | 1317 | ||
1224 | /** | 1318 | /** |
1225 | * Find the successor for destination_finger_value among my_identity, all my | 1319 | * Iterate over the list of all the trails to reach Finger. In case the first |
1226 | * friend and all my fingers. Don't consider friends/ fingers with first friend in | 1320 | * friend to reach the finger has crossed the trail threshold or is congested, |
1227 | * the trail which are congested or have crossed the threshold. | 1321 | * then don't select it. In case there multiple available good trails to reach |
1228 | * @param destination_finger_value Peer closest to this value will be the next successor. | 1322 | * to Finger, choose the one with shortest trail length. |
1229 | * @param next_destination [out] Updated to friend identity in case a friend is | 1323 | * @param finger Finger |
1230 | * successor, updated to first friend to reach to finger | 1324 | * @return struct Correct_Trail which contains the first friend , trail id |
1231 | * in case finger is the destination. | 1325 | * and trail length. NULL in case none of the trails are free. |
1232 | * @param new_intermediate_trail_id [out] In case we finger is the @a next_destination, | ||
1233 | * then we updated the field with trail id to reach | ||
1234 | * to that finger. | ||
1235 | * @param finger_map_index Index in finger peermap for which we are looking for a finger. | ||
1236 | * @return | ||
1237 | */ | 1326 | */ |
1238 | static struct GNUNET_PeerIdentity * | 1327 | static struct Correct_Trail * |
1239 | find_successor (uint64_t destination_finger_value, | 1328 | select_trail_to_finger (struct FingerInfo *finger) |
1240 | struct GNUNET_PeerIdentity *next_destination, | ||
1241 | struct GNUNET_HashCode *new_intermediate_trail_id, | ||
1242 | unsigned int finger_map_index) | ||
1243 | { | 1329 | { |
1244 | /* FIXME; IMPLEMENT*/ | 1330 | struct FriendInfo *friend; |
1245 | return NULL; | 1331 | struct TrailList *iterator; |
1332 | struct Correct_Trail *finger_trail; | ||
1333 | int i; | ||
1334 | |||
1335 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger->finger_identity, | ||
1336 | &my_identity)) | ||
1337 | return NULL; | ||
1338 | |||
1339 | finger_trail = GNUNET_new (struct Correct_Trail); | ||
1340 | |||
1341 | for (i = 0; i < finger->trails_count; i++) | ||
1342 | { | ||
1343 | iterator = &finger->trail_list[i]; | ||
1344 | if (iterator->trail_length > 0) | ||
1345 | { | ||
1346 | friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
1347 | &iterator->trail_head->peer); | ||
1348 | } | ||
1349 | else | ||
1350 | { | ||
1351 | friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
1352 | &finger->finger_identity); | ||
1353 | } | ||
1354 | |||
1355 | if ((friend->trails_count < TRAIL_THROUGH_FRIEND_THRESHOLD)|| | ||
1356 | ((0 == GNUNET_TIME_absolute_get_remaining (friend->congestion_duration).rel_value_us))) | ||
1357 | { | ||
1358 | if (iterator->trail_length == 0) | ||
1359 | { | ||
1360 | finger_trail->friend = *friend; | ||
1361 | //finger_trail->trail_id = 0; | ||
1362 | finger_trail->trail_length = 0; | ||
1363 | return finger_trail; | ||
1364 | } | ||
1365 | |||
1366 | if (finger_trail->trail_length > iterator->trail_length) | ||
1367 | { | ||
1368 | finger_trail->friend = *friend; | ||
1369 | finger_trail->trail_id = iterator->trail_id; | ||
1370 | finger_trail->trail_length = iterator->trail_length; | ||
1371 | } | ||
1372 | } | ||
1373 | } | ||
1374 | |||
1375 | return finger_trail; | ||
1246 | } | 1376 | } |
1247 | 1377 | ||
1248 | 1378 | ||
@@ -1340,6 +1470,188 @@ select_closest_peer (struct GNUNET_PeerIdentity *peer1, | |||
1340 | } | 1470 | } |
1341 | 1471 | ||
1342 | 1472 | ||
1473 | /** | ||
1474 | * Find the successor for destination_finger_value among my_identity, all my | ||
1475 | * friend and all my fingers. Don't consider friends/ fingers with first friend in | ||
1476 | * the trail which are congested or have crossed the threshold. | ||
1477 | * @param destination_finger_value Peer closest to this value will be the next successor. | ||
1478 | * @param next_destination [out] Updated to friend identity in case a friend is | ||
1479 | * successor, updated to first friend to reach to finger | ||
1480 | * in case finger is the destination. | ||
1481 | * @param new_intermediate_trail_id [out] In case we finger is the @a next_destination, | ||
1482 | * then we updated the field with trail id to reach | ||
1483 | * to that finger. | ||
1484 | * @param finger_map_index Index in finger peermap for which we are looking for a finger. | ||
1485 | * @return | ||
1486 | */ | ||
1487 | static struct GNUNET_PeerIdentity * | ||
1488 | find_successor (uint64_t destination_finger_value, | ||
1489 | struct GNUNET_PeerIdentity *next_destination, | ||
1490 | struct GNUNET_HashCode *new_intermediate_trail_id, | ||
1491 | unsigned int finger_map_index) | ||
1492 | { | ||
1493 | struct Closest_Peer *successor; | ||
1494 | struct GNUNET_PeerIdentity *next_hop; | ||
1495 | struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; | ||
1496 | struct GNUNET_CONTAINER_MultiHashMap32Iterator *finger_iter; | ||
1497 | struct GNUNET_PeerIdentity *closest_peer; | ||
1498 | struct Correct_Trail *finger_trail; | ||
1499 | struct FriendInfo *friend; | ||
1500 | struct FingerInfo *finger; | ||
1501 | int i; | ||
1502 | |||
1503 | successor = GNUNET_new (struct Closest_Peer); | ||
1504 | memcpy (&successor->value, &my_identity, sizeof (uint64_t)); | ||
1505 | //successor->trail_id = 0; | ||
1506 | successor->next_hop = my_identity; | ||
1507 | successor->next_destination = my_identity; | ||
1508 | |||
1509 | friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); | ||
1510 | for (i= 0; i < GNUNET_CONTAINER_multipeermap_size (friend_peermap); i++) | ||
1511 | { | ||
1512 | GNUNET_assert (GNUNET_YES == | ||
1513 | GNUNET_CONTAINER_multipeermap_iterator_next (friend_iter, NULL, | ||
1514 | (const void **)&friend)); | ||
1515 | if ((friend->trails_count > TRAIL_THROUGH_FRIEND_THRESHOLD)|| | ||
1516 | (0 != GNUNET_TIME_absolute_get_remaining (friend->congestion_duration).rel_value_us)) | ||
1517 | continue; | ||
1518 | |||
1519 | closest_peer = select_closest_peer (&my_identity, &friend->id, | ||
1520 | destination_finger_value, | ||
1521 | finger_map_index); | ||
1522 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer, &friend->id)) | ||
1523 | { | ||
1524 | memcpy (&successor->value, &friend->id, sizeof (uint64_t)); | ||
1525 | //successor->trail_id = 0; | ||
1526 | successor->next_hop = friend->id; | ||
1527 | successor->next_destination = friend->id; | ||
1528 | } | ||
1529 | } | ||
1530 | |||
1531 | finger_iter = GNUNET_CONTAINER_multihashmap32_iterator_create (finger_hashmap); | ||
1532 | for (i = 0; i < GNUNET_CONTAINER_multihashmap32_size (finger_hashmap); i++) | ||
1533 | { | ||
1534 | GNUNET_assert (GNUNET_YES == | ||
1535 | GNUNET_CONTAINER_multihashmap32_iterator_next (finger_iter, NULL, | ||
1536 | (void *)&finger)); | ||
1537 | finger_trail = select_trail_to_finger (finger); | ||
1538 | if (NULL == finger_trail) | ||
1539 | continue; | ||
1540 | |||
1541 | closest_peer = select_closest_peer (&my_identity, | ||
1542 | &finger->finger_identity, | ||
1543 | destination_finger_value, | ||
1544 | finger_map_index); | ||
1545 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (closest_peer, | ||
1546 | &finger->finger_identity)) | ||
1547 | { | ||
1548 | memcpy (&successor->value, &finger->finger_identity, sizeof (uint64_t)); | ||
1549 | successor->trail_id = finger_trail->trail_id; | ||
1550 | successor->next_hop = finger_trail->friend.id; | ||
1551 | successor->next_destination = finger->finger_identity; | ||
1552 | } | ||
1553 | } | ||
1554 | |||
1555 | next_destination = &successor->next_destination; | ||
1556 | new_intermediate_trail_id = &successor->trail_id; | ||
1557 | next_hop = &successor->next_hop; | ||
1558 | |||
1559 | return next_hop; | ||
1560 | } | ||
1561 | |||
1562 | /** | ||
1563 | * Construct a Put message and send it to target_peer. | ||
1564 | * @param key Key for the content | ||
1565 | * @param block_type Type of the block | ||
1566 | * @param options Routing options | ||
1567 | * @param desired_replication_level Desired replication count | ||
1568 | * @param current_destination Next current destination which will get this message. | ||
1569 | * @param current_source Source for @a current_destination | ||
1570 | * @param target_peer Peer to which this message will be forwarded. | ||
1571 | * @param hop_count Number of hops traversed so far. | ||
1572 | * @param put_path_length Total number of peers in @a put_path | ||
1573 | * @param put_path Number of peers traversed so far | ||
1574 | * @param expiration_time When does the content expire | ||
1575 | * @param data Content to store | ||
1576 | * @param data_size Size of content @a data in bytes | ||
1577 | */ | ||
1578 | void | ||
1579 | GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, | ||
1580 | enum GNUNET_BLOCK_Type block_type, | ||
1581 | enum GNUNET_DHT_RouteOption options, | ||
1582 | uint32_t desired_replication_level, | ||
1583 | struct GNUNET_PeerIdentity current_destination, | ||
1584 | struct GNUNET_PeerIdentity current_source, | ||
1585 | struct GNUNET_PeerIdentity *target_peer, | ||
1586 | uint32_t hop_count, | ||
1587 | uint32_t put_path_length, | ||
1588 | struct GNUNET_PeerIdentity *put_path, | ||
1589 | struct GNUNET_TIME_Absolute expiration_time, | ||
1590 | const void *data, size_t data_size) | ||
1591 | { | ||
1592 | |||
1593 | } | ||
1594 | |||
1595 | /** | ||
1596 | * Construct a Get message and send it to target_peer. | ||
1597 | * @param key Key for the content | ||
1598 | * @param block_type Type of the block | ||
1599 | * @param options Routing options | ||
1600 | * @param desired_replication_level Desired replication count | ||
1601 | * @param current_destination Next current destination which will get this message. | ||
1602 | * @param current_source Source for @a current_destination | ||
1603 | * @param target_peer Peer to which this message will be forwarded. | ||
1604 | * @param hop_count Number of hops traversed so far. | ||
1605 | * @param data Content to store | ||
1606 | * @param data_size Size of content @a data in bytes | ||
1607 | * @param get_path_length Total number of peers in @a get_path | ||
1608 | * @param get_path Number of peers traversed so far | ||
1609 | */ | ||
1610 | void | ||
1611 | GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | ||
1612 | enum GNUNET_BLOCK_Type block_type, | ||
1613 | enum GNUNET_DHT_RouteOption options, | ||
1614 | uint32_t desired_replication_level, | ||
1615 | struct GNUNET_PeerIdentity current_destination, | ||
1616 | struct GNUNET_PeerIdentity current_source, | ||
1617 | struct GNUNET_PeerIdentity *target_peer, | ||
1618 | uint32_t hop_count, | ||
1619 | uint32_t get_path_length, | ||
1620 | struct GNUNET_PeerIdentity *get_path) | ||
1621 | { | ||
1622 | |||
1623 | } | ||
1624 | |||
1625 | |||
1626 | /** | ||
1627 | * Send the get result to requesting client. | ||
1628 | * @param key Key of the requested data. | ||
1629 | * @param type Block type | ||
1630 | * @param target_peer Next peer to forward the message to. | ||
1631 | * @param source_peer Peer which has the data for the key. | ||
1632 | * @param put_path_length Number of peers in @a put_path | ||
1633 | * @param put_path Path taken to put the data at its stored location. | ||
1634 | * @param get_path_length Number of peers in @a get_path | ||
1635 | * @param get_path Path taken to reach to the location of the key. | ||
1636 | * @param expiration When will this result expire? | ||
1637 | * @param data Payload to store | ||
1638 | * @param data_size Size of the @a data | ||
1639 | */ | ||
1640 | void | ||
1641 | GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | ||
1642 | enum GNUNET_BLOCK_Type type, | ||
1643 | struct GNUNET_PeerIdentity *target_peer, | ||
1644 | struct GNUNET_PeerIdentity *source_peer, | ||
1645 | unsigned int put_path_length, | ||
1646 | const struct GNUNET_PeerIdentity *put_path, | ||
1647 | unsigned int get_path_length, | ||
1648 | struct GNUNET_PeerIdentity *get_path, | ||
1649 | struct GNUNET_TIME_Absolute expiration, | ||
1650 | const void *data, size_t data_size) | ||
1651 | { | ||
1652 | |||
1653 | } | ||
1654 | |||
1343 | 1655 | ||
1344 | /** | 1656 | /** |
1345 | * Randomly choose one of your friends (which is not congested and have not crossed | 1657 | * Randomly choose one of your friends (which is not congested and have not crossed |
@@ -1441,6 +1753,7 @@ send_find_finger_trail_message (void *cls, | |||
1441 | struct FriendInfo *target_friend; | 1753 | struct FriendInfo *target_friend; |
1442 | struct GNUNET_TIME_Relative next_send_time; | 1754 | struct GNUNET_TIME_Relative next_send_time; |
1443 | struct GNUNET_HashCode trail_id; | 1755 | struct GNUNET_HashCode trail_id; |
1756 | uint64_t trail_id_value; | ||
1444 | struct GNUNET_HashCode intermediate_trail_id; | 1757 | struct GNUNET_HashCode intermediate_trail_id; |
1445 | unsigned int finger_map_index; | 1758 | unsigned int finger_map_index; |
1446 | uint64_t finger_identity; | 1759 | uint64_t finger_identity; |
@@ -1470,10 +1783,8 @@ send_find_finger_trail_message (void *cls, | |||
1470 | 1783 | ||
1471 | finger_map_index = current_search_finger_index; | 1784 | finger_map_index = current_search_finger_index; |
1472 | 1785 | ||
1473 | /* FIXME: Find the correct function to generate a random trail id which is of | 1786 | trail_id_value = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); |
1474 | * type struct GNUNET_HashCode. */ | 1787 | memcpy (&trail_id, &trail_id_value, sizeof (struct GNUNET_HashCode)); |
1475 | //trail_id = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
1476 | |||
1477 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_identity, | 1788 | GDS_NEIGHBOURS_send_trail_setup (my_identity, finger_identity, |
1478 | target_friend->id, target_friend, 0, NULL, | 1789 | target_friend->id, target_friend, 0, NULL, |
1479 | finger_map_index, trail_id, intermediate_trail_id); | 1790 | finger_map_index, trail_id, intermediate_trail_id); |
@@ -1907,14 +2218,17 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
1907 | return 0; | 2218 | return 0; |
1908 | } | 2219 | } |
1909 | 2220 | ||
1910 | if (GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)) | 2221 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)) |
1911 | { | 2222 | { |
1912 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2223 | if (trail_length > 0) |
2224 | { | ||
2225 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
1913 | &trail[0]); | 2226 | &trail[0]); |
1914 | GDS_NEIGHBOURS_send_trail_compression (my_identity, finger_identity, | 2227 | GDS_NEIGHBOURS_send_trail_compression (my_identity, finger_identity, |
1915 | trail_id, finger_identity, | 2228 | trail_id, finger_identity, |
1916 | target_friend); | 2229 | target_friend); |
1917 | trail = NULL; | 2230 | trail = NULL; |
2231 | } | ||
1918 | return 0; | 2232 | return 0; |
1919 | } | 2233 | } |
1920 | 2234 | ||
@@ -1958,21 +2272,43 @@ send_verify_successor_message (struct FingerInfo *successor) | |||
1958 | struct GNUNET_HashCode trail_id; | 2272 | struct GNUNET_HashCode trail_id; |
1959 | struct GNUNET_PeerIdentity next_hop; | 2273 | struct GNUNET_PeerIdentity next_hop; |
1960 | struct FriendInfo *target_friend; | 2274 | struct FriendInfo *target_friend; |
2275 | struct GNUNET_PeerIdentity *trail; | ||
2276 | unsigned int trail_length; | ||
1961 | int i; | 2277 | int i; |
2278 | int j; | ||
1962 | 2279 | ||
1963 | for (i = 0; i < successor->trails_count; i++) | 2280 | for (i = 0; i < successor->trails_count; i++) |
1964 | { | 2281 | { |
1965 | trail_list_iterator = &successor->trail_list[i]; | 2282 | trail_list_iterator = &successor->trail_list[i]; |
2283 | |||
1966 | if (trail_list_iterator->trail_length > 0) | 2284 | if (trail_list_iterator->trail_length > 0) |
2285 | { | ||
2286 | trail_length = trail_list_iterator->trail_length; | ||
2287 | j = 0; | ||
2288 | trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * | ||
2289 | trail_length); | ||
2290 | struct Trail *element; | ||
2291 | element = trail_list_iterator->trail_head; | ||
2292 | while ( j < trail_length) | ||
2293 | { | ||
2294 | trail[j] = element->peer; | ||
2295 | element = element->next; | ||
2296 | j++; | ||
2297 | } | ||
1967 | next_hop = trail_list_iterator->trail_head->peer; | 2298 | next_hop = trail_list_iterator->trail_head->peer; |
2299 | } | ||
1968 | else | 2300 | else |
2301 | { | ||
2302 | trail = NULL; | ||
2303 | trail_length = 0; | ||
1969 | next_hop = successor->finger_identity; | 2304 | next_hop = successor->finger_identity; |
1970 | 2305 | } | |
1971 | trail_id = trail_list_iterator->trail_id; | 2306 | trail_id = trail_list_iterator->trail_id; |
1972 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); | 2307 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); |
1973 | GDS_NEIGHBOURS_send_verify_successor_message (my_identity, | 2308 | GDS_NEIGHBOURS_send_verify_successor_message (my_identity, |
1974 | successor->finger_identity, | 2309 | successor->finger_identity, |
1975 | trail_id, target_friend); | 2310 | trail_id, trail, trail_length, |
2311 | target_friend); | ||
1976 | } | 2312 | } |
1977 | } | 2313 | } |
1978 | 2314 | ||
@@ -2007,8 +2343,6 @@ finger_table_add (struct GNUNET_PeerIdentity new_finger_identity, | |||
2007 | scan_and_compress_trail (new_finger_identity, new_finger_trail, | 2343 | scan_and_compress_trail (new_finger_identity, new_finger_trail, |
2008 | new_finger_trail_length, new_finger_trail_id); | 2344 | new_finger_trail_length, new_finger_trail_id); |
2009 | 2345 | ||
2010 | successor = GNUNET_CONTAINER_multihashmap32_get (finger_hashmap, | ||
2011 | finger_map_index); | ||
2012 | existing_finger = GNUNET_CONTAINER_multihashmap32_get (finger_hashmap, | 2346 | existing_finger = GNUNET_CONTAINER_multihashmap32_get (finger_hashmap, |
2013 | finger_map_index); | 2347 | finger_map_index); |
2014 | 2348 | ||
@@ -2026,6 +2360,8 @@ finger_table_add (struct GNUNET_PeerIdentity new_finger_identity, | |||
2026 | new_entry_added = GNUNET_YES; | 2360 | new_entry_added = GNUNET_YES; |
2027 | } | 2361 | } |
2028 | 2362 | ||
2363 | successor = GNUNET_CONTAINER_multihashmap32_get (finger_hashmap, | ||
2364 | finger_map_index); | ||
2029 | if (0 == finger_map_index) | 2365 | if (0 == finger_map_index) |
2030 | { | 2366 | { |
2031 | current_search_finger_index = PREDECESSOR_FINGER_ID; | 2367 | current_search_finger_index = PREDECESSOR_FINGER_ID; |
@@ -2301,6 +2637,121 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2301 | 2637 | ||
2302 | 2638 | ||
2303 | /** | 2639 | /** |
2640 | * Invert the trail. | ||
2641 | * @param trail Trail to be inverted | ||
2642 | * @param trail_length Total number of peers in the trail. | ||
2643 | * @return Updated trail | ||
2644 | */ | ||
2645 | static struct GNUNET_PeerIdentity * | ||
2646 | invert_trail (struct GNUNET_PeerIdentity *trail, | ||
2647 | unsigned int trail_length) | ||
2648 | { | ||
2649 | int i; | ||
2650 | int j; | ||
2651 | struct GNUNET_PeerIdentity *inverted_trail; | ||
2652 | |||
2653 | inverted_trail = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity) * | ||
2654 | trail_length); | ||
2655 | i = 0; | ||
2656 | j = trail_length - 1; | ||
2657 | while (i < trail_length) | ||
2658 | { | ||
2659 | inverted_trail[i] = trail[j]; | ||
2660 | i++; | ||
2661 | j--; | ||
2662 | } | ||
2663 | return inverted_trail; | ||
2664 | } | ||
2665 | |||
2666 | |||
2667 | /** | ||
2668 | * Check if the new finger can be our predecessor. If yes then update predecessor | ||
2669 | * | ||
2670 | * @param new_finger | ||
2671 | * @param new_finger_trail | ||
2672 | * @param new_finger_trail_length | ||
2673 | * @return | ||
2674 | */ | ||
2675 | static int | ||
2676 | is_new_entry_correct_predecessor (struct FingerInfo *my_predecessor, | ||
2677 | struct GNUNET_PeerIdentity new_finger, | ||
2678 | struct GNUNET_PeerIdentity *new_finger_trail, | ||
2679 | unsigned int new_finger_trail_length) | ||
2680 | { | ||
2681 | struct GNUNET_PeerIdentity *updated_trail; | ||
2682 | struct GNUNET_HashCode new_trail_id; | ||
2683 | |||
2684 | updated_trail = invert_trail (new_finger_trail, new_finger_trail_length); | ||
2685 | if (GNUNET_YES == is_new_finger_closest (my_predecessor, new_finger, | ||
2686 | new_finger_trail, | ||
2687 | new_finger_trail_length, | ||
2688 | new_trail_id, PREDECESSOR_FINGER_ID)) | ||
2689 | { | ||
2690 | add_new_entry (new_finger, updated_trail, new_finger_trail_length, | ||
2691 | new_trail_id, PREDECESSOR_FINGER_ID); | ||
2692 | /* FIXME: check where you send add trail message */ | ||
2693 | return GNUNET_YES; | ||
2694 | } | ||
2695 | return GNUNET_NO; | ||
2696 | } | ||
2697 | |||
2698 | /** | ||
2699 | * In case the source peer of verify successor message is not my successor, | ||
2700 | * then construct a trail from source peer to my current predecessor. | ||
2701 | * @param my_predecessor my current predecessor. | ||
2702 | * @param current_trail Trail from source to me. | ||
2703 | * @param current_trail_length Total number of peers in @a current_trail | ||
2704 | * @param new_trail_length [out] Total number of peers in updated trail. | ||
2705 | * @return Updated trail from source peer to my_predecessor. | ||
2706 | */ | ||
2707 | static struct GNUNET_PeerIdentity * | ||
2708 | trail_source_to_my_predecessor (struct FingerInfo *my_predecessor, | ||
2709 | struct GNUNET_PeerIdentity *current_trail, | ||
2710 | unsigned int current_trail_length, | ||
2711 | unsigned int *new_trail_length) | ||
2712 | { | ||
2713 | struct GNUNET_PeerIdentity *new_trail; | ||
2714 | struct TrailList *trail_list_iterator; | ||
2715 | struct Trail *trail_iterator; | ||
2716 | unsigned int i; | ||
2717 | unsigned int j; | ||
2718 | unsigned int shortest_trail_length = 0; | ||
2719 | unsigned int trail_index = 0; | ||
2720 | |||
2721 | for (i = 0; i < my_predecessor->trails_count; i++) | ||
2722 | { | ||
2723 | trail_list_iterator = &my_predecessor->trail_list[i]; | ||
2724 | if (trail_list_iterator->trail_length > shortest_trail_length) | ||
2725 | continue; | ||
2726 | shortest_trail_length = trail_list_iterator->trail_length; | ||
2727 | trail_index = i; | ||
2728 | } | ||
2729 | |||
2730 | *new_trail_length = current_trail_length + shortest_trail_length + 1; | ||
2731 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * | ||
2732 | *new_trail_length); | ||
2733 | memcpy (new_trail, current_trail, | ||
2734 | current_trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
2735 | new_trail[current_trail_length + 1] = my_identity; | ||
2736 | |||
2737 | i = 0; | ||
2738 | j = current_trail_length + 1; | ||
2739 | trail_list_iterator = &my_predecessor->trail_list[trail_index]; | ||
2740 | trail_iterator = trail_list_iterator->trail_head; | ||
2741 | while ( i < shortest_trail_length) | ||
2742 | { | ||
2743 | new_trail[j] = trail_iterator->peer; | ||
2744 | j++; | ||
2745 | i++; | ||
2746 | trail_iterator = trail_iterator->next; | ||
2747 | } | ||
2748 | |||
2749 | *new_trail_length = j; | ||
2750 | return new_trail; | ||
2751 | } | ||
2752 | |||
2753 | |||
2754 | /** | ||
2304 | * Core handle for p2p verify successor messages. | 2755 | * Core handle for p2p verify successor messages. |
2305 | * @param cls closure | 2756 | * @param cls closure |
2306 | * @param message message | 2757 | * @param message message |
@@ -2316,10 +2767,12 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2316 | struct GNUNET_PeerIdentity source_peer; | 2767 | struct GNUNET_PeerIdentity source_peer; |
2317 | struct GNUNET_PeerIdentity *next_hop; | 2768 | struct GNUNET_PeerIdentity *next_hop; |
2318 | struct FriendInfo *target_friend; | 2769 | struct FriendInfo *target_friend; |
2319 | //struct FingerInfo *my_predecessor; | ||
2320 | //struct GNUNET_PeerIdentity *my_predecessor_trail; | ||
2321 | //unsigned int my_predecessor_trail_length; | ||
2322 | struct GNUNET_HashCode trail_id; | 2770 | struct GNUNET_HashCode trail_id; |
2771 | struct FingerInfo *my_predecessor; | ||
2772 | struct GNUNET_PeerIdentity *trail; | ||
2773 | struct GNUNET_PeerIdentity *new_trail; | ||
2774 | unsigned int trail_length; | ||
2775 | unsigned int new_trail_length; | ||
2323 | size_t msize; | 2776 | size_t msize; |
2324 | 2777 | ||
2325 | msize = ntohs (message->size); | 2778 | msize = ntohs (message->size); |
@@ -2330,50 +2783,68 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2330 | } | 2783 | } |
2331 | 2784 | ||
2332 | vsm = (struct PeerVerifySuccessorMessage *) message; | 2785 | vsm = (struct PeerVerifySuccessorMessage *) message; |
2786 | trail_length = ntohl (vsm->trail_length); | ||
2787 | if ((msize != sizeof (struct PeerVerifySuccessorMessage) + | ||
2788 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || | ||
2789 | (trail_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | ||
2790 | { | ||
2791 | GNUNET_break_op (0); | ||
2792 | return GNUNET_YES; | ||
2793 | } | ||
2794 | trail = (struct GNUNET_PeerIdentity *)&vsm[1]; | ||
2333 | source_peer = vsm->source_peer; | 2795 | source_peer = vsm->source_peer; |
2334 | successor = vsm->successor; | 2796 | successor = vsm->successor; |
2335 | trail_id = vsm->trail_id; | 2797 | trail_id = vsm->trail_id; |
2336 | 2798 | ||
2337 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity))) | 2799 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity))) |
2338 | { | 2800 | { |
2339 | GNUNET_assert (NULL != (next_hop = | 2801 | next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST); |
2340 | GDS_ROUTING_get_next_hop (trail_id, | 2802 | if (NULL == next_hop) |
2341 | GDS_ROUTING_SRC_TO_DEST))); | 2803 | { |
2804 | GNUNET_break (0); | ||
2805 | return GNUNET_SYSERR; | ||
2806 | } | ||
2342 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2807 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2343 | GDS_NEIGHBOURS_send_verify_successor_message (source_peer, successor, | 2808 | GDS_NEIGHBOURS_send_verify_successor_message (source_peer, successor, |
2344 | trail_id, target_friend); | 2809 | trail_id, trail, trail_length, |
2810 | target_friend); | ||
2345 | return GNUNET_OK; | 2811 | return GNUNET_OK; |
2346 | } | 2812 | } |
2347 | #if 0 | ||
2348 | my_predecessor = GNUNET_CONTAINER_multihashmap32_get (finger_hashmap, | ||
2349 | PREDECESSOR_FINGER_ID); | ||
2350 | if (NULL == my_predecessor) /* FIXME: not sure how to handle this case */ | ||
2351 | return GNUNET_OK; | ||
2352 | 2813 | ||
2353 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&source_peer, | 2814 | my_predecessor = GNUNET_CONTAINER_multihashmap32_get (finger_hashmap, |
2354 | &(my_predecessor->finger_identity)))) | 2815 | PREDECESSOR_FINGER_ID); |
2816 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); | ||
2817 | if (GNUNET_NO == is_new_entry_correct_predecessor (my_predecessor, source_peer, | ||
2818 | trail, trail_length)) | ||
2355 | { | 2819 | { |
2356 | my_predecessor_trail = NULL; | 2820 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&source_peer, |
2357 | my_predecessor_trail_length = 0; | 2821 | &my_predecessor->finger_identity)) |
2822 | { | ||
2823 | new_trail = trail_source_to_my_predecessor (my_predecessor, trail, | ||
2824 | trail_length, &new_trail_length); | ||
2825 | } | ||
2358 | } | 2826 | } |
2359 | else | 2827 | else |
2360 | { | 2828 | { |
2361 | /* FIXME: copy from my_predecessor trail. now we may have multiple routes | 2829 | my_predecessor = GNUNET_CONTAINER_multihashmap32_get (finger_hashmap, |
2362 | choose the one with shortest length and send that one. */ | 2830 | PREDECESSOR_FINGER_ID); |
2831 | GDS_NEIGHBOURS_send_add_trail (my_predecessor->finger_identity, | ||
2832 | source_peer, trail_id, | ||
2833 | trail, trail_length, | ||
2834 | target_friend); | ||
2835 | new_trail_length = trail_length; | ||
2836 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * | ||
2837 | new_trail_length); | ||
2838 | memcpy (new_trail, trail, sizeof (struct GNUNET_PeerIdentity) * | ||
2839 | trail_length); | ||
2363 | } | 2840 | } |
2364 | 2841 | ||
2365 | /* Here you are sending the result back along the trail through which the source | ||
2366 | peer send the message to you. now you have to specify the direction such | ||
2367 | that the trail id is used but now prev_hop is next_hop. */ | ||
2368 | |||
2369 | GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity, | 2842 | GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity, |
2370 | my_predecessor->finger_identity, | 2843 | my_predecessor->finger_identity, |
2371 | trail_id, | 2844 | trail_id, new_trail, |
2372 | my_predecessor_trail, | 2845 | new_trail_length, |
2373 | my_predecessor_trail_length, | ||
2374 | GDS_ROUTING_DEST_TO_SRC, | 2846 | GDS_ROUTING_DEST_TO_SRC, |
2375 | target_friend); | 2847 | target_friend); |
2376 | #endif | ||
2377 | return GNUNET_OK; | 2848 | return GNUNET_OK; |
2378 | } | 2849 | } |
2379 | 2850 | ||
@@ -2392,8 +2863,8 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2392 | struct PeerVerifySuccessorResultMessage *vsrm; | 2863 | struct PeerVerifySuccessorResultMessage *vsrm; |
2393 | enum GDS_ROUTING_trail_direction trail_direction; | 2864 | enum GDS_ROUTING_trail_direction trail_direction; |
2394 | struct GNUNET_HashCode trail_id; | 2865 | struct GNUNET_HashCode trail_id; |
2395 | unsigned int successor_current_predecessor_trail_length; | 2866 | unsigned int new_trail_length; |
2396 | struct GNUNET_PeerIdentity *successor_current_predecessor_trail; | 2867 | struct GNUNET_PeerIdentity *new_trail; |
2397 | struct GNUNET_PeerIdentity destination_peer; | 2868 | struct GNUNET_PeerIdentity destination_peer; |
2398 | struct GNUNET_PeerIdentity my_new_successor; | 2869 | struct GNUNET_PeerIdentity my_new_successor; |
2399 | struct GNUNET_PeerIdentity *next_hop; | 2870 | struct GNUNET_PeerIdentity *next_hop; |
@@ -2407,161 +2878,130 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2407 | return GNUNET_YES; | 2878 | return GNUNET_YES; |
2408 | } | 2879 | } |
2409 | vsrm = (struct PeerVerifySuccessorResultMessage *) message; | 2880 | vsrm = (struct PeerVerifySuccessorResultMessage *) message; |
2410 | successor_current_predecessor_trail_length = ntohl (vsrm->trail_length); | 2881 | new_trail_length = ntohl (vsrm->trail_length); |
2411 | trail_direction = ntohl (vsrm->trail_direction); | 2882 | trail_direction = ntohl (vsrm->trail_direction); |
2412 | trail_id = vsrm->trail_id; | 2883 | trail_id = vsrm->trail_id; |
2413 | 2884 | ||
2414 | if ((msize != | 2885 | if ((msize != |
2415 | sizeof (struct PeerVerifySuccessorResultMessage) + | 2886 | sizeof (struct PeerVerifySuccessorResultMessage) + |
2416 | successor_current_predecessor_trail_length * | 2887 | new_trail_length * |
2417 | sizeof (struct GNUNET_PeerIdentity)) || | 2888 | sizeof (struct GNUNET_PeerIdentity)) || |
2418 | (successor_current_predecessor_trail_length > | 2889 | (new_trail_length > |
2419 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | 2890 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) |
2420 | { | 2891 | { |
2421 | GNUNET_break_op (0); | 2892 | GNUNET_break_op (0); |
2422 | return GNUNET_YES; | 2893 | return GNUNET_YES; |
2423 | } | 2894 | } |
2424 | 2895 | ||
2425 | successor_current_predecessor_trail = (struct GNUNET_PeerIdentity *) &vsrm[1]; | 2896 | new_trail = (struct GNUNET_PeerIdentity *) &vsrm[1]; |
2426 | destination_peer = vsrm->destination_peer; | 2897 | destination_peer = vsrm->destination_peer; |
2427 | my_new_successor = vsrm->my_predecessor; | 2898 | my_new_successor = vsrm->my_predecessor; |
2428 | 2899 | ||
2429 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&destination_peer, &my_identity))) | 2900 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&destination_peer, &my_identity))) |
2430 | { | 2901 | { |
2431 | 2902 | struct GNUNET_HashCode new_finger_trail_id; | |
2903 | if (GNUNET_YES == finger_table_add (my_new_successor, | ||
2904 | new_trail, | ||
2905 | new_trail_length, | ||
2906 | PREDECESSOR_FINGER_ID, new_finger_trail_id)) | ||
2907 | { | ||
2908 | if (new_trail_length > 0) | ||
2909 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2910 | &new_trail[0]); | ||
2911 | else | ||
2912 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2913 | peer); | ||
2914 | GDS_NEIGHBOURS_send_notify_new_successor (my_identity, my_new_successor, | ||
2915 | new_trail, | ||
2916 | new_trail_length, | ||
2917 | new_finger_trail_id, target_friend); | ||
2918 | } | ||
2919 | return GNUNET_OK; | ||
2432 | } | 2920 | } |
2433 | 2921 | ||
2434 | next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction); | 2922 | GNUNET_assert (NULL != (next_hop = |
2923 | GDS_ROUTING_get_next_hop (trail_id, trail_direction))); | ||
2435 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2924 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2436 | GDS_NEIGHBOURS_send_verify_successor_result (destination_peer, | 2925 | GDS_NEIGHBOURS_send_verify_successor_result (destination_peer, |
2437 | vsrm->source_successor, | 2926 | vsrm->source_successor, |
2438 | my_new_successor, trail_id, | 2927 | my_new_successor, trail_id, |
2439 | successor_current_predecessor_trail, | 2928 | new_trail, |
2440 | successor_current_predecessor_trail_length, | 2929 | new_trail_length, |
2441 | trail_direction, target_friend); | 2930 | trail_direction, target_friend); |
2442 | return GNUNET_OK; | 2931 | return GNUNET_OK; |
2443 | } | 2932 | } |
2444 | 2933 | ||
2445 | 2934 | ||
2446 | #if 0 | ||
2447 | /** | 2935 | /** |
2448 | * Adapt it to use trail list array. | 2936 | * Here we need to pass the whole trail to reach to new successor as we |
2449 | * Core handle for p2p verify successor result messages. | 2937 | don't have that stored in our routing table. while passing through each |
2938 | peer we will have to add an entry. also when you are the destination and | ||
2939 | if you have added it back as pred, then you also need to add the trail in | ||
2940 | your own finger table and send add trail message to add this trail. you | ||
2941 | shoudl generate a new trail id. although they are same trails but you have | ||
2942 | to ahve different trail id. | ||
2943 | * Core handle for p2p notify new successor messages. | ||
2450 | * @param cls closure | 2944 | * @param cls closure |
2451 | * @param message message | 2945 | * @param message message |
2452 | * @param peer peer identity this notification is about | 2946 | * @param peer peer identity this notification is about |
2453 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 2947 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
2454 | */ | 2948 | */ |
2455 | static int | 2949 | static int |
2456 | handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdentity *peer, | 2950 | handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer, |
2457 | const struct GNUNET_MessageHeader *message) | 2951 | const struct GNUNET_MessageHeader *message) |
2458 | { | 2952 | { |
2459 | 2953 | struct PeerNotifyNewSuccessorMessage *nsm; | |
2460 | const struct PeerVerifySuccessorResultMessage *vsrm; | ||
2461 | unsigned int trail_length; | ||
2462 | struct GNUNET_HashCode trail_id; | ||
2463 | struct GNUNET_PeerIdentity *trail; | 2954 | struct GNUNET_PeerIdentity *trail; |
2955 | struct GNUNET_PeerIdentity source; | ||
2956 | struct GNUNET_PeerIdentity destination; | ||
2464 | struct FriendInfo *target_friend; | 2957 | struct FriendInfo *target_friend; |
2465 | struct GNUNET_PeerIdentity *next_hop; | 2958 | //struct GNUNET_HashCode trail_id; |
2466 | struct GNUNET_PeerIdentity destination_peer; | ||
2467 | struct GNUNET_PeerIdentity my_new_successor; | ||
2468 | struct FingerInfo *current_successor; | ||
2469 | struct GNUNET_HashCode old_successor_trail_id; | ||
2470 | size_t msize; | 2959 | size_t msize; |
2960 | uint32_t trail_length; | ||
2471 | 2961 | ||
2472 | msize = ntohs (message->size); | 2962 | msize = ntohs (message->size); |
2473 | if (msize < sizeof (struct PeerVerifySuccessorResultMessage)) | 2963 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) |
2474 | { | 2964 | { |
2475 | GNUNET_break_op (0); | 2965 | GNUNET_break_op (0); |
2476 | return GNUNET_YES; | 2966 | return GNUNET_YES; |
2477 | } | 2967 | } |
2478 | vsrm = (const struct PeerVerifySuccessorResultMessage *) message; | 2968 | nsm = (struct PeerNotifyNewSuccessorMessage *) message; |
2479 | trail_length = ntohl (vsrm->trail_length); | 2969 | trail_length = ntohl (nsm->trail_length); |
2480 | trail_id = vsrm->trail_id; | ||
2481 | 2970 | ||
2482 | if ((msize < | 2971 | if ((msize < sizeof (struct PeerNotifyNewSuccessorMessage) + |
2483 | sizeof (struct PeerVerifySuccessorResultMessage) + | 2972 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || |
2484 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || | 2973 | (trail_length > |
2485 | (trail_length > | ||
2486 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | 2974 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) |
2487 | { | 2975 | { |
2488 | GNUNET_break_op (0); | 2976 | GNUNET_break_op (0); |
2489 | return GNUNET_YES; | 2977 | return GNUNET_YES; |
2490 | } | 2978 | } |
2491 | 2979 | ||
2492 | trail = (struct GNUNET_PeerIdentity *) &vsrm[1]; | 2980 | trail = (struct GNUNET_PeerIdentity *) &nsm[1]; |
2493 | destination_peer = vsrm->destination_peer; | 2981 | source = nsm->source_peer; |
2494 | my_new_successor = vsrm->my_predecessor; | 2982 | destination = nsm->destination_peer; |
2495 | 2983 | //trail_id = nsm->trail_id; | |
2496 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&destination_peer, &my_identity))) | 2984 | #if 0 |
2985 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination)) | ||
2497 | { | 2986 | { |
2498 | unsigned int *new_trail_length; | 2987 | struct GNUNET_HashCode new_trail_id; |
2499 | struct GNUNET_PeerIdentity *new_trail; | 2988 | struct FingerInfo *my_predecessor; |
2500 | struct GNUNET_HashCode new_finger_trail_id; | 2989 | if (GNUNET_YES == is_new_entry_correct_predecessor (my_predecessor, |
2501 | 2990 | source, trail, | |
2502 | /* FIXME: generate a new_finger_trail_id */ | 2991 | trail_length)) |
2503 | current_successor = GNUNET_CONTAINER_multihashmap32_get (finger_hashmap, 0); | ||
2504 | old_successor_trail_id = current_successor->head->trail_id; | ||
2505 | target_friend = | ||
2506 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
2507 | &(current_successor->head->head->peer)); | ||
2508 | |||
2509 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_new_successor, | ||
2510 | ¤t_successor->finger_identity)) | ||
2511 | { | 2992 | { |
2512 | *new_trail_length = 0; | 2993 | GDS_NEIGHBOURS_send_add_trail (my_identity, source, new_trail_id, |
2513 | new_trail = update_trail_to_new_predecessor (current_successor, | 2994 | trail, trail_length, target_friend); |
2514 | trail_length, trail, | ||
2515 | new_trail_length); | ||
2516 | |||
2517 | if (GNUNET_OK == finger_table_add (&my_new_successor, new_trail, | ||
2518 | new_trail_length , 0, new_finger_trail_id)) | ||
2519 | { | ||
2520 | /*FIXME: | ||
2521 | *Here you should send a trail teardown message for old trail id | ||
2522 | and trail add for new trail. */ | ||
2523 | } | ||
2524 | GDS_NEIGHBOURS_send_notify_new_successor (my_identity, my_new_successor, | ||
2525 | new_trail, new_trail_length, | ||
2526 | new_finger_trail_id, target_friend); | ||
2527 | } | 2995 | } |
2528 | } | 2996 | } |
2529 | 2997 | ||
2530 | next_hop = GDS_ROUTING_get_next_hop (trail_id); | 2998 | //GDS_ROUTING_add (new_trail_id, peer, next_hop); |
2531 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | ||
2532 | GDS_NEIGHBOURS_send_verify_successor_result (vsrm->destination_peer, | ||
2533 | vsrm->source_successor, | ||
2534 | vsrm->my_predecessor, | ||
2535 | vsrm->trail_id, trail, | ||
2536 | |||
2537 | return GNUNET_OK; | ||
2538 | } | ||
2539 | trail_length, target_friend); | ||
2540 | #endif | 2999 | #endif |
2541 | |||
2542 | |||
2543 | /** | ||
2544 | * Core handle for p2p notify new successor messages. | ||
2545 | * @param cls closure | ||
2546 | * @param message message | ||
2547 | * @param peer peer identity this notification is about | ||
2548 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
2549 | */ | ||
2550 | static int | ||
2551 | handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer, | ||
2552 | const struct GNUNET_MessageHeader *message) | ||
2553 | { | ||
2554 | /* Here we need to pass the whole trail to reach to new successor as we | ||
2555 | don't have that stored in our routing table. while passing through each | ||
2556 | peer we will have to add an entry. also when you are the destination and | ||
2557 | if you have added it back as pred, then you also need to add the trail in | ||
2558 | your own finger table and send add trail message to add this trail. you | ||
2559 | shoudl generate a new trail id. although they are same trails but you have | ||
2560 | to ahve different trail id. */ | ||
2561 | return GNUNET_OK; | 3000 | return GNUNET_OK; |
2562 | } | 3001 | } |
2563 | 3002 | ||
2564 | 3003 | ||
3004 | |||
2565 | /** | 3005 | /** |
2566 | * FIXME: Here you should keep the trail id with you. | 3006 | * FIXME: Here you should keep the trail id with you. |
2567 | * Core handler for P2P trail rejection message | 3007 | * Core handler for P2P trail rejection message |
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c index ad7c9a276..531848842 100644 --- a/src/dht/gnunet-service-xdht_routing.c +++ b/src/dht/gnunet-service-xdht_routing.c | |||
@@ -100,7 +100,7 @@ GDS_ROUTING_get_next_hop (const struct GNUNET_HashCode trail_id, | |||
100 | struct RoutingTrail *trail; | 100 | struct RoutingTrail *trail; |
101 | 101 | ||
102 | trail = GNUNET_CONTAINER_multihashmap_get (routing_table, &trail_id); | 102 | trail = GNUNET_CONTAINER_multihashmap_get (routing_table, &trail_id); |
103 | 103 | ||
104 | if (NULL == trail) | 104 | if (NULL == trail) |
105 | return NULL; | 105 | return NULL; |
106 | 106 | ||
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 5a698a8d4..b03efe3f4 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -656,7 +656,7 @@ extern "C" | |||
656 | #define GNUNET_MESSAGE_TYPE_DHT_P2P_ADD_TRAIL 165 | 656 | #define GNUNET_MESSAGE_TYPE_DHT_P2P_ADD_TRAIL 165 |
657 | 657 | ||
658 | /** | 658 | /** |
659 | * Trail compessiong message. | 659 | * Trail compression message. |
660 | */ | 660 | */ |
661 | #define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_COMPRESSION 166 | 661 | #define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_COMPRESSION 166 |
662 | /******************************************************************************* | 662 | /******************************************************************************* |