diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-04-15 17:01:01 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-04-15 17:01:01 +0000 |
commit | da9d531e17773916c4c6ffdc1a055fe9e0a6c74f (patch) | |
tree | e257eacd9eef19a853821d1c3a72bdde8140135a /src/dht | |
parent | b9e53953acedad90fcc54c8245da5a9a29969fc4 (diff) | |
download | gnunet-da9d531e17773916c4c6ffdc1a055fe9e0a6c74f.tar.gz gnunet-da9d531e17773916c4c6ffdc1a055fe9e0a6c74f.zip |
Removing current_trail_index, current_destination_type where not required.
Cleaning up handle_get, handle_put, handle_trail code.
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-xdht_clients.c | 33 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_datacache.c | 18 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_datacache.h | 1 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 1759 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.h | 216 |
5 files changed, 907 insertions, 1120 deletions
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c index b2803afd9..6761dd96b 100644 --- a/src/dht/gnunet-service-xdht_clients.c +++ b/src/dht/gnunet-service-xdht_clients.c | |||
@@ -845,12 +845,14 @@ transmit_request (struct ClientQueryRecord *cqr) | |||
845 | cqr->seen_replies_count); | 845 | cqr->seen_replies_count); |
846 | 846 | ||
847 | /* FIXME: Here I am passing NULL for parameters check if its correct or | 847 | /* FIXME: Here I am passing NULL for parameters check if its correct or |
848 | not. */ | 848 | not. Here I don't want address to be const just the value how do I do it? */ |
849 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | 849 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); |
850 | GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication, | 850 | struct GNUNET_PeerIdentity *my_identity; |
851 | 0 /* hop count */ ,NULL, 0, | 851 | my_identity = GDS_NEIGHBOURS_get_my_id (); |
852 | &cqr->key, NULL, NULL, NULL, 0); | 852 | GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options, |
853 | 853 | cqr->replication, my_identity, my_identity, NULL, | |
854 | 0, 0, NULL); | ||
855 | |||
854 | /* exponential back-off for retries. | 856 | /* exponential back-off for retries. |
855 | * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */ | 857 | * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */ |
856 | cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency); | 858 | cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency); |
@@ -947,21 +949,22 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, | |||
947 | 949 | ||
948 | /* FIXME: Is it correct to pass NULL for current destination and current | 950 | /* FIXME: Is it correct to pass NULL for current destination and current |
949 | source. */ | 951 | source. */ |
950 | GDS_NEIGHBOURS_handle_put (ntohl (put_msg->type), ntohl (put_msg->options), | 952 | struct GNUNET_PeerIdentity *my_identity; |
951 | ntohl (put_msg->desired_replication_level), | 953 | my_identity = GDS_NEIGHBOURS_get_my_id(); |
952 | GNUNET_TIME_absolute_ntoh (put_msg->expiration), | 954 | GDS_NEIGHBOURS_send_put (&put_msg->key, &put_msg[1], |
953 | 0 /* hop count */ , | 955 | size - sizeof (struct GNUNET_DHT_ClientPutMessage), |
954 | &put_msg->key, 0, NULL, &put_msg[1], | 956 | ntohl (put_msg->type), ntohl (put_msg->options), |
955 | size - | 957 | ntohl (put_msg->desired_replication_level), |
956 | sizeof (struct GNUNET_DHT_ClientPutMessage), | 958 | GNUNET_TIME_absolute_ntoh (put_msg->expiration), |
957 | NULL, NULL, 0, NULL); | 959 | my_identity, my_identity, NULL, 0, 0, NULL); |
960 | |||
958 | 961 | ||
959 | GDS_CLIENTS_process_put (ntohl (put_msg->options), | 962 | GDS_CLIENTS_process_put (ntohl (put_msg->options), |
960 | ntohl (put_msg->type), | 963 | ntohl (put_msg->type), |
961 | 0, | 964 | 0, |
962 | ntohl (put_msg->desired_replication_level), | 965 | ntohl (put_msg->desired_replication_level), |
963 | 1, | 966 | 1, |
964 | GDS_NEIGHBOURS_get_id(), | 967 | GDS_NEIGHBOURS_get_my_id(), |
965 | GNUNET_TIME_absolute_ntoh (put_msg->expiration), | 968 | GNUNET_TIME_absolute_ntoh (put_msg->expiration), |
966 | &put_msg->key, | 969 | &put_msg->key, |
967 | &put_msg[1], | 970 | &put_msg[1], |
@@ -1040,7 +1043,7 @@ handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client, | |||
1040 | 0, | 1043 | 0, |
1041 | ntohl (get->desired_replication_level), | 1044 | ntohl (get->desired_replication_level), |
1042 | 1, | 1045 | 1, |
1043 | GDS_NEIGHBOURS_get_id(), | 1046 | GDS_NEIGHBOURS_get_my_id(), |
1044 | &get->key); | 1047 | &get->key); |
1045 | /* start remote requests */ | 1048 | /* start remote requests */ |
1046 | if (GNUNET_SCHEDULER_NO_TASK != retry_task) | 1049 | if (GNUNET_SCHEDULER_NO_TASK != retry_task) |
diff --git a/src/dht/gnunet-service-xdht_datacache.c b/src/dht/gnunet-service-xdht_datacache.c index 3af22e791..dd6810f45 100644 --- a/src/dht/gnunet-service-xdht_datacache.c +++ b/src/dht/gnunet-service-xdht_datacache.c | |||
@@ -148,27 +148,22 @@ struct GetRequestContext | |||
148 | enum GNUNET_BLOCK_EvaluationResult eval; | 148 | enum GNUNET_BLOCK_EvaluationResult eval; |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * | 151 | * Peeer which has the data for the key. |
152 | */ | 152 | */ |
153 | struct GNUNET_PeerIdentity source_peer; | 153 | struct GNUNET_PeerIdentity source_peer; |
154 | 154 | ||
155 | /** | 155 | /** |
156 | * | 156 | * Next hop to forward the get result to. |
157 | */ | ||
158 | unsigned int current_trail_index; | ||
159 | |||
160 | /** | ||
161 | * | ||
162 | */ | 157 | */ |
163 | struct GNUNET_PeerIdentity next_hop; | 158 | struct GNUNET_PeerIdentity next_hop; |
164 | 159 | ||
165 | /** | 160 | /** |
166 | * Head of trail to reach this finger. | 161 | * Head of get path. |
167 | */ | 162 | */ |
168 | struct GetPath *head; | 163 | struct GetPath *head; |
169 | 164 | ||
170 | /** | 165 | /** |
171 | * Tail of trail to reach this finger. | 166 | * Tail of get path. |
172 | */ | 167 | */ |
173 | struct GetPath *tail; | 168 | struct GetPath *tail; |
174 | /* get_path */ | 169 | /* get_path */ |
@@ -230,7 +225,7 @@ datacache_get_iterator (void *cls, | |||
230 | } | 225 | } |
231 | GDS_NEIGHBOURS_send_get_result (exp, key, put_path_length, put_path, | 226 | GDS_NEIGHBOURS_send_get_result (exp, key, put_path_length, put_path, |
232 | type, size, data, get_path, ctx->get_path_length, | 227 | type, size, data, get_path, ctx->get_path_length, |
233 | ctx->current_trail_index, &(ctx->next_hop), | 228 | &(ctx->next_hop), |
234 | &(ctx->source_peer)); | 229 | &(ctx->source_peer)); |
235 | 230 | ||
236 | /* forward to other peers */ | 231 | /* forward to other peers */ |
@@ -295,7 +290,6 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key, | |||
295 | uint32_t reply_bf_mutator, | 290 | uint32_t reply_bf_mutator, |
296 | uint32_t get_path_length, | 291 | uint32_t get_path_length, |
297 | struct GNUNET_PeerIdentity *get_path, | 292 | struct GNUNET_PeerIdentity *get_path, |
298 | unsigned int current_trail_index, | ||
299 | struct GNUNET_PeerIdentity *next_hop, | 293 | struct GNUNET_PeerIdentity *next_hop, |
300 | struct GNUNET_PeerIdentity *source_peer) | 294 | struct GNUNET_PeerIdentity *source_peer) |
301 | { | 295 | { |
@@ -316,7 +310,7 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key, | |||
316 | ctx.get_path_length = get_path_length; | 310 | ctx.get_path_length = get_path_length; |
317 | if (next_hop != NULL) | 311 | if (next_hop != NULL) |
318 | memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity)); | 312 | memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity)); |
319 | ctx.current_trail_index = current_trail_index; | 313 | |
320 | /* FIXME: add the get path into ctx and then call gds_neighbours_handle_get*/ | 314 | /* FIXME: add the get path into ctx and then call gds_neighbours_handle_get*/ |
321 | int i = 0; | 315 | int i = 0; |
322 | while (i < get_path_length) | 316 | while (i < get_path_length) |
diff --git a/src/dht/gnunet-service-xdht_datacache.h b/src/dht/gnunet-service-xdht_datacache.h index 9b147612f..a13d2b7b9 100644 --- a/src/dht/gnunet-service-xdht_datacache.h +++ b/src/dht/gnunet-service-xdht_datacache.h | |||
@@ -70,7 +70,6 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key, | |||
70 | uint32_t reply_bf_mutator, | 70 | uint32_t reply_bf_mutator, |
71 | uint32_t get_path_length, | 71 | uint32_t get_path_length, |
72 | struct GNUNET_PeerIdentity *get_path, | 72 | struct GNUNET_PeerIdentity *get_path, |
73 | unsigned int current_trail_index, | ||
74 | struct GNUNET_PeerIdentity *next_hop, | 73 | struct GNUNET_PeerIdentity *next_hop, |
75 | struct GNUNET_PeerIdentity *source_peer); | 74 | struct GNUNET_PeerIdentity *source_peer); |
76 | 75 | ||
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 7913b619b..70aa47108 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 | (C) 2009-2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2009-2014 Christian Grothoff (and other contributing authors) |
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 |
@@ -80,14 +80,10 @@ | |||
80 | #define MAXIMUM_PENDING_PER_FRIEND 64 | 80 | #define MAXIMUM_PENDING_PER_FRIEND 64 |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * How long at least to wait before sending another find finger trail request. | 83 | * How long at least to wait before sending another find finger trail request, |
84 | * at most we wait twice this long. | ||
84 | */ | 85 | */ |
85 | #define DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 86 | #define DHT_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
86 | |||
87 | /** | ||
88 | * How long at most to wait before sending another find finger trail request. | ||
89 | */ | ||
90 | #define DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10) | ||
91 | 87 | ||
92 | /** | 88 | /** |
93 | * How long at most to wait for transmission of a GET request to another peer? | 89 | * How long at most to wait for transmission of a GET request to another peer? |
@@ -147,11 +143,6 @@ struct PeerPutMessage | |||
147 | */ | 143 | */ |
148 | struct GNUNET_PeerIdentity current_source; | 144 | struct GNUNET_PeerIdentity current_source; |
149 | 145 | ||
150 | /** | ||
151 | * current_destination type. | ||
152 | */ | ||
153 | enum current_destination_type current_destination_type; | ||
154 | |||
155 | /** | 146 | /** |
156 | * When does the content expire? | 147 | * When does the content expire? |
157 | */ | 148 | */ |
@@ -191,11 +182,6 @@ struct PeerGetResultMessage | |||
191 | struct GNUNET_PeerIdentity source_peer; | 182 | struct GNUNET_PeerIdentity source_peer; |
192 | 183 | ||
193 | /** | 184 | /** |
194 | * Current index in get path. | ||
195 | */ | ||
196 | unsigned int current_path_index; | ||
197 | |||
198 | /** | ||
199 | * Number of peers recorded in the outgoing path from source to the | 185 | * Number of peers recorded in the outgoing path from source to the |
200 | * stored location of this message. | 186 | * stored location of this message. |
201 | */ | 187 | */ |
@@ -269,12 +255,7 @@ struct PeerGetMessage | |||
269 | * Source for which current_destination is the finger. | 255 | * Source for which current_destination is the finger. |
270 | */ | 256 | */ |
271 | struct GNUNET_PeerIdentity current_source; | 257 | struct GNUNET_PeerIdentity current_source; |
272 | 258 | ||
273 | /** | ||
274 | * Type of current destination | ||
275 | */ | ||
276 | enum current_destination_type current_dest_type; | ||
277 | |||
278 | /** | 259 | /** |
279 | * The key we are looking for. | 260 | * The key we are looking for. |
280 | */ | 261 | */ |
@@ -286,6 +267,7 @@ struct PeerGetMessage | |||
286 | 267 | ||
287 | 268 | ||
288 | /** | 269 | /** |
270 | * FIXME: Check the alignment in all the struct | ||
289 | * P2P Trail setup message | 271 | * P2P Trail setup message |
290 | */ | 272 | */ |
291 | struct PeerTrailSetupMessage | 273 | struct PeerTrailSetupMessage |
@@ -295,21 +277,16 @@ struct PeerTrailSetupMessage | |||
295 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP | 277 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP |
296 | */ | 278 | */ |
297 | struct GNUNET_MessageHeader header; | 279 | struct GNUNET_MessageHeader header; |
298 | 280 | ||
299 | /** | ||
300 | * Source peer which wants to setup the trail to one of its finger. | ||
301 | */ | ||
302 | struct GNUNET_PeerIdentity source_peer; | ||
303 | |||
304 | /** | 281 | /** |
305 | * Successor of this finger value will be our finger peer. | 282 | * Successor of this finger value will be our finger peer. |
306 | */ | 283 | */ |
307 | uint64_t destination_finger; | 284 | uint64_t destination_finger; |
308 | 285 | ||
309 | /** | 286 | /** |
310 | * Peer which gets this message can be either an intermediate finger or friend. | 287 | * Source peer which wants to setup the trail to one of its finger. |
311 | */ | 288 | */ |
312 | enum current_destination_type current_destination_type; | 289 | struct GNUNET_PeerIdentity source_peer; |
313 | 290 | ||
314 | /** | 291 | /** |
315 | * Peer to which this packet is forwarded. | 292 | * Peer to which this packet is forwarded. |
@@ -324,12 +301,12 @@ struct PeerTrailSetupMessage | |||
324 | struct GNUNET_PeerIdentity current_source; | 301 | struct GNUNET_PeerIdentity current_source; |
325 | 302 | ||
326 | /** | 303 | /** |
327 | * Index into finger peer map. | 304 | * Index into finger peer map, in NBO. |
328 | */ | 305 | */ |
329 | unsigned int finger_map_index; | 306 | uint32_t finger_map_index; |
330 | 307 | ||
331 | /** | 308 | /** |
332 | * Number of entries in trail list. | 309 | * Number of entries in trail list, in NBO. |
333 | */ | 310 | */ |
334 | uint32_t trail_length GNUNET_PACKED; | 311 | uint32_t trail_length GNUNET_PACKED; |
335 | 312 | ||
@@ -356,16 +333,11 @@ struct PeerTrailSetupResultMessage | |||
356 | * Peer which was looking for the trail to finger. | 333 | * Peer which was looking for the trail to finger. |
357 | */ | 334 | */ |
358 | struct GNUNET_PeerIdentity destination_peer; | 335 | struct GNUNET_PeerIdentity destination_peer; |
359 | |||
360 | /** | ||
361 | * Trail index which points to next destination to send this message. | ||
362 | */ | ||
363 | unsigned int current_index; | ||
364 | 336 | ||
365 | /** | 337 | /** |
366 | * Index into finger peer map | 338 | * Index into finger peer map |
367 | */ | 339 | */ |
368 | unsigned int finger_map_index; | 340 | uint32_t finger_map_index; |
369 | 341 | ||
370 | /** | 342 | /** |
371 | * Number of entries in trail list. | 343 | * Number of entries in trail list. |
@@ -438,12 +410,6 @@ struct PeerVerifySuccessorMessage | |||
438 | * Total number of peers in trail to current successor. | 410 | * Total number of peers in trail to current successor. |
439 | */ | 411 | */ |
440 | unsigned int trail_length; | 412 | unsigned int trail_length; |
441 | |||
442 | /** | ||
443 | * Trail index which points to next destination to send this message. | ||
444 | */ | ||
445 | unsigned int current_trail_index; | ||
446 | |||
447 | }; | 413 | }; |
448 | 414 | ||
449 | 415 | ||
@@ -480,13 +446,7 @@ struct PeerVerifySuccessorResultMessage | |||
480 | * If source_successor is destination peer, then trail is from destination_peer | 446 | * If source_successor is destination peer, then trail is from destination_peer |
481 | * to source_successor. | 447 | * to source_successor. |
482 | */ | 448 | */ |
483 | unsigned int trail_length; | 449 | unsigned int trail_length; |
484 | |||
485 | /** | ||
486 | * Trail index which points to next destination to send this message. | ||
487 | */ | ||
488 | unsigned int current_index; | ||
489 | |||
490 | }; | 450 | }; |
491 | 451 | ||
492 | /** | 452 | /** |
@@ -513,12 +473,6 @@ struct PeerNotifyNewSuccessorMessage | |||
513 | * Number of peers in trail from source_peer to new successor. | 473 | * Number of peers in trail from source_peer to new successor. |
514 | */ | 474 | */ |
515 | unsigned int trail_length; | 475 | unsigned int trail_length; |
516 | |||
517 | /** | ||
518 | * Trail index which points to next destination to send this message. | ||
519 | */ | ||
520 | unsigned int current_index; | ||
521 | |||
522 | }; | 476 | }; |
523 | 477 | ||
524 | 478 | ||
@@ -653,6 +607,13 @@ struct FingerInfo | |||
653 | 607 | ||
654 | }; | 608 | }; |
655 | 609 | ||
610 | enum current_destination_type | ||
611 | { | ||
612 | FRIEND, | ||
613 | FINGER, | ||
614 | VALUE, | ||
615 | MY_ID | ||
616 | }; | ||
656 | 617 | ||
657 | /** | 618 | /** |
658 | * FIXME: Think of a better name. | 619 | * FIXME: Think of a better name. |
@@ -738,11 +699,25 @@ static struct GNUNET_CONTAINER_MultiPeerMap *failed_trail_list; | |||
738 | static struct GNUNET_CORE_Handle *core_api; | 699 | static struct GNUNET_CORE_Handle *core_api; |
739 | 700 | ||
740 | /** | 701 | /** |
741 | * FIXME: Is it safe to assume its initialized to 0 by default. | 702 | * Finger map index for predecessor entry in finger peermap. |
703 | */ | ||
704 | #define PREDECESSOR_FINGER_ID 64 | ||
705 | |||
706 | /** | ||
742 | * The current finger index that we have found trail to. | 707 | * The current finger index that we have found trail to. |
743 | */ | 708 | */ |
744 | static unsigned int current_finger_index; | 709 | static unsigned int current_finger_index; |
745 | 710 | ||
711 | /** | ||
712 | * Iterate over trail and search your index location in the array. | ||
713 | * @param trail Trail which contains list of peers. | ||
714 | * @return Index in the array. | ||
715 | */ | ||
716 | static int | ||
717 | search_my_location (struct GNUNET_PeerIdentity *trail) | ||
718 | { | ||
719 | return 0; | ||
720 | } | ||
746 | 721 | ||
747 | /** | 722 | /** |
748 | * Called when core is ready to send a message we asked for | 723 | * Called when core is ready to send a message we asked for |
@@ -847,29 +822,35 @@ process_friend_queue (struct FriendInfo *peer) | |||
847 | } | 822 | } |
848 | 823 | ||
849 | 824 | ||
850 | /**FIXME: add better comment for current_source which shows its relation | 825 | /** |
851 | * with current_destination. | 826 | * FIXME: In this function using const, does it affect only here right? not in |
827 | * the struct P2PTrailSetupMessage as their fields are not defined as const. | ||
828 | * Also, I changed current_destination and current_source from const to not, | ||
829 | * because when we make a call from handle_dht_p2p_trail_setup, then we are | ||
830 | * passing struct for current_destination and not current_source, as we are writing | ||
831 | * to these variables and we can not decalre them as const. | ||
852 | * Construct a trail message and forward it to a friend. | 832 | * Construct a trail message and forward it to a friend. |
853 | * @param source_peer Peer which wants to set up the trail to one of its finger. | 833 | * @param source_peer Peer which wants to set up the trail to one of its finger. |
854 | * @param destination_finger Value whose successor we are searching the network. | 834 | * @param destination_finger Peer identity closest to this value will be |
855 | * @param current_destination Peer which gets this message. | 835 | * @a source_peer's finger. |
856 | * @param current_source Peer for which current_destination is its finger. | 836 | * @param current_destination Finger of the @a current_source, for which among |
857 | * @param target_friend Current friend to which this message should be forwarded. | 837 | * its friends, its own identity and all fingers, this |
858 | * @param trail_length Numbers of peers in the trail. | 838 | * finger is the closest to the @a destination_finger |
859 | * @param trail_peer_list peers this request has traversed so far | 839 | * @param current_source Peer for which @a current_destination is its finger. |
840 | * @param target_friend Friend to which this message should be forwarded. | ||
841 | * @param trail_length Numbers of peers in the trail found so far. | ||
842 | * @param trail_peer_list Peers this request has traversed so far | ||
860 | * @param finger_map_index Index in finger peer map | 843 | * @param finger_map_index Index in finger peer map |
861 | * @param type Type of current destination can be either FRIEND or FINGER | ||
862 | */ | 844 | */ |
863 | void | 845 | void |
864 | GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity *source_peer, | 846 | GDS_NEIGHBOURS_send_trail_setup (const struct GNUNET_PeerIdentity *source_peer, |
865 | uint64_t destination_finger, | 847 | uint64_t destination_finger, |
866 | struct GNUNET_PeerIdentity *current_destination, | 848 | struct GNUNET_PeerIdentity *current_destination, |
867 | struct GNUNET_PeerIdentity *current_source, | 849 | struct GNUNET_PeerIdentity *current_source, |
868 | struct FriendInfo *target_friend, | 850 | struct FriendInfo *target_friend, |
869 | unsigned int trail_length, | 851 | unsigned int trail_length, |
870 | struct GNUNET_PeerIdentity *trail_peer_list, | 852 | const struct GNUNET_PeerIdentity *trail_peer_list, |
871 | unsigned int finger_map_index, | 853 | unsigned int finger_map_index) |
872 | enum current_destination_type type) | ||
873 | { | 854 | { |
874 | struct P2PPendingMessage *pending; | 855 | struct P2PPendingMessage *pending; |
875 | struct PeerTrailSetupMessage *tsm; | 856 | struct PeerTrailSetupMessage *tsm; |
@@ -887,27 +868,29 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity *source_peer, | |||
887 | 868 | ||
888 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | 869 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) |
889 | { | 870 | { |
871 | /* SUPU: Its important to have such statistics as you need to keep track of | ||
872 | the packets lost due to full queue. */ | ||
890 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 873 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
891 | 1, GNUNET_NO); | 874 | 1, GNUNET_NO); |
892 | } | 875 | } |
893 | 876 | ||
894 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 877 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
895 | pending->importance = 0; /* FIXME */ | ||
896 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 878 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
897 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; | 879 | tsm = (struct PeerTrailSetupMessage *) &pending[1]; |
898 | pending->msg = &tsm->header; | 880 | pending->msg = &tsm->header; |
899 | tsm->header.size = htons (msize); | 881 | tsm->header.size = htons (msize); |
900 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); | 882 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); |
883 | /* FIXME: understand where you need to use memcpy or direct assignment. */ | ||
901 | memcpy (&(tsm->destination_finger), &destination_finger, sizeof (uint64_t)); | 884 | memcpy (&(tsm->destination_finger), &destination_finger, sizeof (uint64_t)); |
902 | memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | 885 | memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); |
903 | memcpy (&(tsm->current_destination), current_destination, sizeof (struct GNUNET_PeerIdentity)); | 886 | memcpy (&(tsm->current_destination), current_destination, sizeof (struct GNUNET_PeerIdentity)); |
904 | /* FIXME: Is it correct to use NULL here for comparison? */ | 887 | memcpy (&(tsm->current_source), current_source, sizeof (struct GNUNET_PeerIdentity)); |
905 | if (current_source != NULL) | ||
906 | memcpy (&(tsm->current_source), current_source, sizeof (struct GNUNET_PeerIdentity)); | ||
907 | tsm->current_destination_type = htonl (type); | ||
908 | tsm->trail_length = htonl (trail_length); | 888 | tsm->trail_length = htonl (trail_length); |
909 | tsm->finger_map_index = htonl (finger_map_index); | 889 | tsm->finger_map_index = htonl (finger_map_index); |
910 | 890 | ||
891 | /* SUPU: here i guess its okay to have it as NULL as it is added at the end of | ||
892 | the struct but in case of current_destination and current_source, it is part | ||
893 | of the struct. thats why the confusion. */ | ||
911 | if (trail_peer_list != NULL) | 894 | if (trail_peer_list != NULL) |
912 | { | 895 | { |
913 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; | 896 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; |
@@ -928,7 +911,6 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity *source_peer, | |||
928 | * @param target_friend Friend to which this message should be forwarded. | 911 | * @param target_friend Friend to which this message should be forwarded. |
929 | * @param trail_length Numbers of peers in the trail. | 912 | * @param trail_length Numbers of peers in the trail. |
930 | * @param trail_peer_list Peers which are part of the trail from source to destination. | 913 | * @param trail_peer_list Peers which are part of the trail from source to destination. |
931 | * @param current_trail_index Index at which sender of this message is located. | ||
932 | * @param finger_map_index Index in finger peer map | 914 | * @param finger_map_index Index in finger peer map |
933 | */ | 915 | */ |
934 | void | 916 | void |
@@ -937,7 +919,6 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity *destination_ | |||
937 | struct FriendInfo *target_friend, | 919 | struct FriendInfo *target_friend, |
938 | unsigned int trail_length, | 920 | unsigned int trail_length, |
939 | struct GNUNET_PeerIdentity *trail_peer_list, | 921 | struct GNUNET_PeerIdentity *trail_peer_list, |
940 | unsigned int current_trail_index, | ||
941 | unsigned int finger_map_index) | 922 | unsigned int finger_map_index) |
942 | { | 923 | { |
943 | struct P2PPendingMessage *pending; | 924 | struct P2PPendingMessage *pending; |
@@ -970,7 +951,6 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity *destination_ | |||
970 | memcpy (&(tsrm->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity)); | 951 | memcpy (&(tsrm->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity)); |
971 | memcpy (&(tsrm->finger_identity), source_finger, sizeof (struct GNUNET_PeerIdentity)); | 952 | memcpy (&(tsrm->finger_identity), source_finger, sizeof (struct GNUNET_PeerIdentity)); |
972 | tsrm->trail_length = htonl (trail_length); | 953 | tsrm->trail_length = htonl (trail_length); |
973 | tsrm->current_index = htonl (current_trail_index); | ||
974 | tsrm->finger_map_index = htonl (finger_map_index); | 954 | tsrm->finger_map_index = htonl (finger_map_index); |
975 | peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; | 955 | peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; |
976 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 956 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
@@ -989,15 +969,12 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity *destination_ | |||
989 | * @param target_friend Friend to which this message should be forwarded. | 969 | * @param target_friend Friend to which this message should be forwarded. |
990 | * @param trail_peer_list Peer which are part of trail from source to destination | 970 | * @param trail_peer_list Peer which are part of trail from source to destination |
991 | * @param trail_length Number of peers in the trail list. | 971 | * @param trail_length Number of peers in the trail list. |
992 | * @param current_trail_index Index in the trial list at which receiving peer should | ||
993 | * read the next element. | ||
994 | */ | 972 | */ |
995 | void GDS_NEIGHBOURS_send_verify_successor(struct GNUNET_PeerIdentity *source_peer, | 973 | void GDS_NEIGHBOURS_send_verify_successor(struct GNUNET_PeerIdentity *source_peer, |
996 | struct GNUNET_PeerIdentity *successor, | 974 | struct GNUNET_PeerIdentity *successor, |
997 | struct FriendInfo *target_friend, | 975 | struct FriendInfo *target_friend, |
998 | struct GNUNET_PeerIdentity *trail_peer_list, | 976 | struct GNUNET_PeerIdentity *trail_peer_list, |
999 | unsigned int trail_length, | 977 | unsigned int trail_length) |
1000 | unsigned int current_trail_index) | ||
1001 | { | 978 | { |
1002 | struct PeerVerifySuccessorMessage *vsm; | 979 | struct PeerVerifySuccessorMessage *vsm; |
1003 | struct P2PPendingMessage *pending; | 980 | struct P2PPendingMessage *pending; |
@@ -1029,7 +1006,6 @@ void GDS_NEIGHBOURS_send_verify_successor(struct GNUNET_PeerIdentity *source_pee | |||
1029 | memcpy (&(vsm->successor), successor, sizeof (struct GNUNET_PeerIdentity)); | 1006 | memcpy (&(vsm->successor), successor, sizeof (struct GNUNET_PeerIdentity)); |
1030 | memcpy (&(vsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | 1007 | memcpy (&(vsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); |
1031 | vsm->trail_length = htonl (trail_length); | 1008 | vsm->trail_length = htonl (trail_length); |
1032 | vsm->current_trail_index = htonl (current_trail_index); | ||
1033 | peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; | 1009 | peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; |
1034 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1010 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
1035 | 1011 | ||
@@ -1049,16 +1025,13 @@ void GDS_NEIGHBOURS_send_verify_successor(struct GNUNET_PeerIdentity *source_pee | |||
1049 | * @param target_friend Friend to which this message should be forwarded. | 1025 | * @param target_friend Friend to which this message should be forwarded. |
1050 | * @param trail_peer_list Peers which are part of trail from source to destination | 1026 | * @param trail_peer_list Peers which are part of trail from source to destination |
1051 | * @param trail_length Number of peers in the trail list. | 1027 | * @param trail_length Number of peers in the trail list. |
1052 | * @param current_trail_index Index in the trial list at which receiving peer should | ||
1053 | * get the next element. | ||
1054 | */ | 1028 | */ |
1055 | void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *destination_peer, | 1029 | void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *destination_peer, |
1056 | struct GNUNET_PeerIdentity *source_successor, | 1030 | struct GNUNET_PeerIdentity *source_successor, |
1057 | struct GNUNET_PeerIdentity *my_predecessor, | 1031 | struct GNUNET_PeerIdentity *my_predecessor, |
1058 | struct FriendInfo *target_friend, | 1032 | struct FriendInfo *target_friend, |
1059 | struct GNUNET_PeerIdentity *trail_peer_list, | 1033 | struct GNUNET_PeerIdentity *trail_peer_list, |
1060 | unsigned int trail_length, | 1034 | unsigned int trail_length) |
1061 | unsigned int current_trail_index) | ||
1062 | { | 1035 | { |
1063 | struct PeerVerifySuccessorResultMessage *vsmr; | 1036 | struct PeerVerifySuccessorResultMessage *vsmr; |
1064 | struct P2PPendingMessage *pending; | 1037 | struct P2PPendingMessage *pending; |
@@ -1091,9 +1064,7 @@ void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *de | |||
1091 | memcpy (&(vsmr->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity)); | 1064 | memcpy (&(vsmr->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity)); |
1092 | memcpy (&(vsmr->source_successor), source_successor, sizeof (struct GNUNET_PeerIdentity)); | 1065 | memcpy (&(vsmr->source_successor), source_successor, sizeof (struct GNUNET_PeerIdentity)); |
1093 | memcpy (&(vsmr->my_predecessor), my_predecessor, sizeof (struct GNUNET_PeerIdentity)); | 1066 | memcpy (&(vsmr->my_predecessor), my_predecessor, sizeof (struct GNUNET_PeerIdentity)); |
1094 | vsmr->trail_length = htonl (trail_length); | 1067 | vsmr->trail_length = htonl (trail_length); |
1095 | vsmr->current_index = htonl (current_trail_index); | ||
1096 | |||
1097 | peer_list = (struct GNUNET_PeerIdentity *) &vsmr[1]; | 1068 | peer_list = (struct GNUNET_PeerIdentity *) &vsmr[1]; |
1098 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1069 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
1099 | 1070 | ||
@@ -1110,7 +1081,6 @@ void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *de | |||
1110 | * @param destination_peer Peer which is the new destination. | 1081 | * @param destination_peer Peer which is the new destination. |
1111 | * @param target_friend Next friend to pass this message to. | 1082 | * @param target_friend Next friend to pass this message to. |
1112 | * @param peer_list List of peers in the trail to reach to destination_peer. | 1083 | * @param peer_list List of peers in the trail to reach to destination_peer. |
1113 | * @param current_trail_index Index of peer_list for next target friend position. | ||
1114 | * @param trail_length Total number of peers in peer list | 1084 | * @param trail_length Total number of peers in peer list |
1115 | */ | 1085 | */ |
1116 | void | 1086 | void |
@@ -1118,8 +1088,7 @@ GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity *source_pee | |||
1118 | struct GNUNET_PeerIdentity *destination_peer, | 1088 | struct GNUNET_PeerIdentity *destination_peer, |
1119 | struct FriendInfo *target_friend, | 1089 | struct FriendInfo *target_friend, |
1120 | struct GNUNET_PeerIdentity *trail_peer_list, | 1090 | struct GNUNET_PeerIdentity *trail_peer_list, |
1121 | unsigned int trail_length, | 1091 | unsigned int trail_length) |
1122 | unsigned int current_trail_index) | ||
1123 | { | 1092 | { |
1124 | struct PeerNotifyNewSuccessorMessage *nsm; | 1093 | struct PeerNotifyNewSuccessorMessage *nsm; |
1125 | struct P2PPendingMessage *pending; | 1094 | struct P2PPendingMessage *pending; |
@@ -1151,7 +1120,6 @@ GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity *source_pee | |||
1151 | memcpy (&(nsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | 1120 | memcpy (&(nsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); |
1152 | memcpy (&(nsm->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity)); | 1121 | memcpy (&(nsm->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity)); |
1153 | nsm->trail_length = htonl (trail_length); | 1122 | nsm->trail_length = htonl (trail_length); |
1154 | nsm->current_index = htonl (current_trail_index); | ||
1155 | 1123 | ||
1156 | peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; | 1124 | peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; |
1157 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1125 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
@@ -1187,6 +1155,13 @@ select_random_friend (struct GNUNET_PeerIdentity *congested_peer) | |||
1187 | index = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, current_size); | 1155 | index = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, current_size); |
1188 | iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); | 1156 | iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); |
1189 | 1157 | ||
1158 | if (GNUNET_CONTAINER_multipeermap_size (friend_peermap) == 0) | ||
1159 | { | ||
1160 | /* FIXME: It may happen that there is not friend in friend peermap but | ||
1161 | as this task has already been started it failed.*/ | ||
1162 | GNUNET_break(0); | ||
1163 | return NULL; | ||
1164 | } | ||
1190 | while(j < (*index)) | 1165 | while(j < (*index)) |
1191 | { | 1166 | { |
1192 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (iter,NULL,NULL)) | 1167 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (iter,NULL,NULL)) |
@@ -1216,21 +1191,19 @@ select_random_friend (struct GNUNET_PeerIdentity *congested_peer) | |||
1216 | 1191 | ||
1217 | 1192 | ||
1218 | /** | 1193 | /** |
1194 | * FIMXE: pass current_finger_index as argument. | ||
1219 | * Compute finger_identity to which we want to setup the trail | 1195 | * Compute finger_identity to which we want to setup the trail |
1220 | * @return finger_identity | 1196 | * @return finger_identity |
1221 | */ | 1197 | */ |
1222 | static uint64_t * | 1198 | static uint64_t |
1223 | compute_finger_identity() | 1199 | compute_finger_identity() |
1224 | { | 1200 | { |
1225 | uint64_t my_id64 ; | 1201 | uint64_t my_id64 ; |
1226 | uint64_t *finger_identity64; | 1202 | |
1227 | |||
1228 | finger_identity64 = GNUNET_malloc (sizeof (uint64_t)); | ||
1229 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); | 1203 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); |
1204 | my_id64 = GNUNET_ntohll (my_id64); | ||
1230 | /*FIXME: Do we need a mod finger = ((my_id + pow(2, finger_index)) mod (pow (2, MAX_FINGERS))*/ | 1205 | /*FIXME: Do we need a mod finger = ((my_id + pow(2, finger_index)) mod (pow (2, MAX_FINGERS))*/ |
1231 | *finger_identity64 = (my_id64 + (unsigned long) pow (2,current_finger_index)); | 1206 | return (my_id64 + (unsigned long) pow (2, current_finger_index)); |
1232 | |||
1233 | return finger_identity64; | ||
1234 | } | 1207 | } |
1235 | 1208 | ||
1236 | 1209 | ||
@@ -1238,18 +1211,14 @@ compute_finger_identity() | |||
1238 | * Compute immediate predecessor identity in the network. | 1211 | * Compute immediate predecessor identity in the network. |
1239 | * @return peer identity of immediate predecessor. | 1212 | * @return peer identity of immediate predecessor. |
1240 | */ | 1213 | */ |
1241 | static uint64_t * | 1214 | static uint64_t |
1242 | compute_predecessor_identity() | 1215 | compute_predecessor_identity() |
1243 | { | 1216 | { |
1244 | uint64_t my_id ; | 1217 | uint64_t my_id64; |
1245 | uint64_t *predecessor; | 1218 | |
1246 | 1219 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); | |
1247 | predecessor = GNUNET_malloc (sizeof (uint64_t)); | 1220 | my_id64 = GNUNET_ntohll (my_id64); |
1248 | memcpy (&my_id, &my_identity, sizeof (uint64_t)); | 1221 | return (my_id64 -1); |
1249 | /* FIXME: Do we need to use mod pow(2, MAX_FINGERS) here? */ | ||
1250 | *predecessor = (my_id -1); | ||
1251 | |||
1252 | return predecessor; | ||
1253 | } | 1222 | } |
1254 | 1223 | ||
1255 | 1224 | ||
@@ -1269,7 +1238,6 @@ send_verify_successor_message (void *cls, | |||
1269 | struct FriendInfo *target_friend; | 1238 | struct FriendInfo *target_friend; |
1270 | struct GNUNET_PeerIdentity *next_hop; | 1239 | struct GNUNET_PeerIdentity *next_hop; |
1271 | struct GNUNET_PeerIdentity *peer_list; | 1240 | struct GNUNET_PeerIdentity *peer_list; |
1272 | unsigned int finger_trail_current_index; | ||
1273 | struct FingerInfo *finger; | 1241 | struct FingerInfo *finger; |
1274 | unsigned int finger_index; | 1242 | unsigned int finger_index; |
1275 | unsigned int i; | 1243 | unsigned int i; |
@@ -1308,25 +1276,20 @@ send_verify_successor_message (void *cls, | |||
1308 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1276 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
1309 | memcpy (next_hop, &peer_list[0], sizeof (struct GNUNET_PeerIdentity)); | 1277 | memcpy (next_hop, &peer_list[0], sizeof (struct GNUNET_PeerIdentity)); |
1310 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 1278 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
1311 | finger_trail_current_index = 0; | 1279 | |
1312 | |||
1313 | |||
1314 | GDS_NEIGHBOURS_send_verify_successor (&my_identity, | 1280 | GDS_NEIGHBOURS_send_verify_successor (&my_identity, |
1315 | &(finger->finger_identity), | 1281 | &(finger->finger_identity), |
1316 | target_friend, | 1282 | target_friend, |
1317 | peer_list, | 1283 | peer_list, |
1318 | finger->trail_length, | 1284 | finger->trail_length); |
1319 | finger_trail_current_index); | ||
1320 | 1285 | ||
1321 | 1286 | ||
1322 | /* FIXME: Use a random value so that this message is send not at the same | 1287 | /* FIXME: Understand what this function is actually doing here. */ |
1323 | interval as send_find_finger_trail_message. */ | ||
1324 | send_new_request: | 1288 | send_new_request: |
1325 | next_send_time.rel_value_us = | 1289 | next_send_time.rel_value_us = |
1326 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | 1290 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + |
1327 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1291 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1328 | DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us / | 1292 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us); |
1329 | (current_finger_index + 50)); | ||
1330 | 1293 | ||
1331 | verify_successor = | 1294 | verify_successor = |
1332 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_verify_successor_message, | 1295 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_verify_successor_message, |
@@ -1335,8 +1298,19 @@ send_verify_successor_message (void *cls, | |||
1335 | 1298 | ||
1336 | 1299 | ||
1337 | /** | 1300 | /** |
1338 | * Task to send a find finger trail message. We attempt to find trail | 1301 | * FIXME - the main logic of handling the finger map index has changed. |
1339 | * to our fingers, successor and predecessor in the network. | 1302 | * first we start with finger index = 64, that index is reserved for the |
1303 | * predecessor always. Then we start going backwards, finger_index = 63 to 0 | ||
1304 | * and once its 0 we again go back to 64. now, when you start looking for the finger | ||
1305 | * then your successor is always the finger with lowest finger index. in finger_table_add | ||
1306 | * whenever you do an entry you check for predecessor , if the new finger identity | ||
1307 | * is greater than existing one, then that should be your predecessor. In case of | ||
1308 | * other fingers also, if the new entry is smaller than existing one. If yes | ||
1309 | * then that is correct finger for that finger index. Also, the lowest finger index and | ||
1310 | * its corresponding finger identity is your successor. | ||
1311 | * | ||
1312 | * Choose a random friend and start looking for the trail to reach to | ||
1313 | * finger identity through this random friend. | ||
1340 | * | 1314 | * |
1341 | * @param cls closure for this task | 1315 | * @param cls closure for this task |
1342 | * @param tc the context under which the task is running | 1316 | * @param tc the context under which the task is running |
@@ -1347,168 +1321,51 @@ send_find_finger_trail_message (void *cls, | |||
1347 | { | 1321 | { |
1348 | struct FriendInfo *target_friend; | 1322 | struct FriendInfo *target_friend; |
1349 | struct GNUNET_TIME_Relative next_send_time; | 1323 | struct GNUNET_TIME_Relative next_send_time; |
1350 | uint64_t *finger_identity; | 1324 | uint64_t finger_identity; |
1351 | unsigned int finger_map_index; | 1325 | unsigned int finger_map_index; |
1352 | 1326 | ||
1353 | if (1 == current_finger_index) | 1327 | /* FIXME: understand how does this scheduling of processes take place? */ |
1354 | { | ||
1355 | finger_identity = compute_predecessor_identity(); | ||
1356 | goto select_friend; | ||
1357 | } | ||
1358 | else | ||
1359 | { | ||
1360 | finger_identity = compute_finger_identity(); | ||
1361 | } | ||
1362 | |||
1363 | select_friend: | ||
1364 | target_friend = select_random_friend (NULL); | ||
1365 | |||
1366 | finger_map_index = current_finger_index; | ||
1367 | current_finger_index = ( current_finger_index + 1) % MAX_FINGERS; | ||
1368 | |||
1369 | if(NULL != target_friend) | ||
1370 | { | ||
1371 | /* FIXME: Here I am passing NULL for current source, is it correct? | ||
1372 | also, we set the current source only if current_destination_type | ||
1373 | is finger. */ | ||
1374 | GDS_NEIGHBOURS_send_trail_setup (&my_identity, *finger_identity, &(target_friend->id), | ||
1375 | NULL, target_friend, 0, NULL, finger_map_index, FRIEND); | ||
1376 | } | ||
1377 | |||
1378 | /* FIXME: How to decide the correct interval? */ | ||
1379 | next_send_time.rel_value_us = | 1328 | next_send_time.rel_value_us = |
1380 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | 1329 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + |
1381 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1330 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1382 | DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us / | 1331 | DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us); |
1383 | (current_finger_index + 10)); | 1332 | /* FIXME: here we are just adding the process to the scheduling list. only |
1384 | 1333 | when this function is executed, it may get scheduled. */ | |
1385 | find_finger_trail_task = | 1334 | find_finger_trail_task = |
1386 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message, | 1335 | GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message, |
1387 | NULL); | 1336 | NULL); |
1388 | } | 1337 | target_friend = select_random_friend (NULL); |
1389 | 1338 | ||
1390 | 1339 | if (NULL == target_friend) | |
1391 | /** | 1340 | { |
1392 | * Method called whenever a peer connects. | 1341 | /* SUPU: Here we can get NULL in the case there is no friend in the peer map |
1393 | * | 1342 | or all of the friends have reached their threshold. The first case should ideally |
1394 | * @param cls closure | 1343 | never happen because in handle_core_disconnect we have already canceled the task |
1395 | * @param peer_identity peer identity this notification is about | 1344 | but it may happen if we already started the process and we reached here and |
1396 | */ | 1345 | we cancelled the next task. So, it can return NULL in that case also. Should |
1397 | static void | 1346 | we handle both cases in same way or not? */ |
1398 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | ||
1399 | { | ||
1400 | struct FriendInfo *friend; | ||
1401 | |||
1402 | /* Check for connect to self message */ | ||
1403 | if (0 == memcmp (&my_identity, peer_identity, sizeof (struct GNUNET_PeerIdentity))) | ||
1404 | return; | ||
1405 | |||
1406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to %s\n", GNUNET_i2s (peer_identity)); | ||
1407 | |||
1408 | /* If peer already exists in our friend_peermap, then exit. */ | ||
1409 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap, peer_identity)) | ||
1410 | { | ||
1411 | GNUNET_break (0); | ||
1412 | return; | 1347 | return; |
1413 | } | 1348 | } |
1414 | |||
1415 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), 1, | ||
1416 | GNUNET_NO); | ||
1417 | |||
1418 | friend = GNUNET_new (struct FriendInfo); | ||
1419 | friend->id = *peer_identity; | ||
1420 | |||
1421 | GNUNET_assert (GNUNET_OK == | ||
1422 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, | ||
1423 | peer_identity, friend, | ||
1424 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1425 | |||
1426 | /* got a first connection, good time to start with FIND FINGER TRAIL requests... */ | ||
1427 | if (1 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)) | ||
1428 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); | ||
1429 | } | ||
1430 | |||
1431 | |||
1432 | /** | ||
1433 | * Method called whenever a peer disconnects. | ||
1434 | * | ||
1435 | * @param cls closure | ||
1436 | * @param peer peer identity this notification is about | ||
1437 | */ | ||
1438 | static void | ||
1439 | handle_core_disconnect (void *cls, | ||
1440 | const struct GNUNET_PeerIdentity *peer) | ||
1441 | { | ||
1442 | struct FriendInfo *remove_friend; | ||
1443 | struct FingerInfo *remove_finger; | ||
1444 | struct GNUNET_PeerIdentity key_ret; | ||
1445 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | ||
1446 | struct TrailPeerList *iterator; | ||
1447 | struct GNUNET_PeerIdentity *finger_identity; | ||
1448 | int finger_index; | ||
1449 | |||
1450 | /* Check for self message. */ | ||
1451 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | ||
1452 | return; | ||
1453 | |||
1454 | /* Search for peer to remove in your friend_peermap. */ | ||
1455 | remove_friend = | ||
1456 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); | ||
1457 | 1349 | ||
1458 | if (NULL == remove_friend) | 1350 | /* FIXME: start with current_finger_index = 64, */ |
1351 | if (PREDECESSOR_FINGER_ID == current_finger_index) | ||
1459 | { | 1352 | { |
1460 | GNUNET_break (0); | 1353 | /* FIXME: Where do we set the value back to PREDECESSR_FINGER_ID? Only |
1461 | return; | 1354 | when current_finger_index = 0, do we set it back to PREDECESSOR_FINGER_ID, |
1355 | in finger_table_add? Or is there any other possible condition, where we | ||
1356 | may need to set it to PREDECESSOR_FINGER_ID*/ | ||
1357 | finger_identity = compute_predecessor_identity(); | ||
1462 | } | 1358 | } |
1463 | 1359 | else | |
1464 | iterator = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1465 | finger_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
1466 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | ||
1467 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | ||
1468 | { | 1360 | { |
1469 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (finger_iter, &key_ret, | 1361 | finger_identity = compute_finger_identity(); |
1470 | (const void **)&remove_finger)) | ||
1471 | { | ||
1472 | iterator = remove_finger->head->next; | ||
1473 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(iterator->peer), &(remove_friend->id))) | ||
1474 | { | ||
1475 | memcpy (finger_identity, &(remove_finger->finger_identity), sizeof (struct GNUNET_PeerIdentity)); | ||
1476 | GNUNET_assert (GNUNET_YES == | ||
1477 | GNUNET_CONTAINER_multipeermap_remove (finger_peermap, | ||
1478 | finger_identity, | ||
1479 | remove_finger)); | ||
1480 | } | ||
1481 | } | ||
1482 | } | 1362 | } |
1363 | finger_map_index = current_finger_index; | ||
1483 | 1364 | ||
1484 | /* Remove the friend from friend_peermap. */ | 1365 | /* FIXME: verify if its correct to set current_destination and current_source |
1485 | GNUNET_assert (GNUNET_YES == | 1366 | as my identity. */ |
1486 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, | 1367 | GDS_NEIGHBOURS_send_trail_setup (&my_identity, finger_identity, &(target_friend->id), |
1487 | peer, | 1368 | &(target_friend->id), target_friend, 0, NULL, finger_map_index); |
1488 | remove_friend)); | ||
1489 | } | ||
1490 | |||
1491 | |||
1492 | /** | ||
1493 | * To be called on core init/fail. | ||
1494 | * | ||
1495 | * @param cls service closure | ||
1496 | * @param identity the public identity of this peer | ||
1497 | */ | ||
1498 | static void | ||
1499 | core_init (void *cls, | ||
1500 | const struct GNUNET_PeerIdentity *identity) | ||
1501 | { | ||
1502 | my_identity = *identity; | ||
1503 | |||
1504 | /* SUPU TEST CODE */ | ||
1505 | struct GNUNET_PeerIdentity *print_peer; | ||
1506 | print_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
1507 | memcpy (print_peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
1508 | FPRINTF (stderr,_("\nSUPU %s, %s, %d,my_identity = %s"), | ||
1509 | __FILE__, __func__,__LINE__, GNUNET_i2s (print_peer)); | ||
1510 | /* SUPU TEST CODE ENDS */ | ||
1511 | |||
1512 | } | 1369 | } |
1513 | 1370 | ||
1514 | 1371 | ||
@@ -1547,6 +1404,7 @@ invert_trail_list (struct GNUNET_PeerIdentity *destination_peer, | |||
1547 | } | 1404 | } |
1548 | 1405 | ||
1549 | 1406 | ||
1407 | #if 0 | ||
1550 | /** | 1408 | /** |
1551 | * | 1409 | * |
1552 | * @param existing_finger | 1410 | * @param existing_finger |
@@ -1562,7 +1420,7 @@ compare_finger_identity (struct GNUNET_PeerIdentity *existing_finger, | |||
1562 | (existing_finger == new_finger) ? 0 : -1; | 1420 | (existing_finger == new_finger) ? 0 : -1; |
1563 | return ret; | 1421 | return ret; |
1564 | } | 1422 | } |
1565 | 1423 | #endif | |
1566 | 1424 | ||
1567 | /** | 1425 | /** |
1568 | * FIXME: Not sure of the logic to find the correct predecessor | 1426 | * FIXME: Not sure of the logic to find the correct predecessor |
@@ -1573,18 +1431,18 @@ compare_finger_identity (struct GNUNET_PeerIdentity *existing_finger, | |||
1573 | * @return | 1431 | * @return |
1574 | */ | 1432 | */ |
1575 | static int | 1433 | static int |
1576 | compare_predecessor(struct GNUNET_PeerIdentity *existing_predecessor, | 1434 | compare_predecessor(struct GNUNET_PeerIdentity *peer) |
1577 | struct GNUNET_PeerIdentity *new_predecessor) | ||
1578 | { | 1435 | { |
1579 | int ret; | 1436 | /* FIXME: here you should first check if you already have an entry in the |
1580 | ret = (existing_predecessor < new_predecessor) ? 1 : | 1437 | finger peer map for finger index = 64, if yes then compare it with peer |
1581 | (existing_predecessor == new_predecessor) ? 0 : -1; | 1438 | if not then just add the peer. */ |
1582 | return ret; | 1439 | return 0; |
1583 | } | 1440 | } |
1584 | 1441 | ||
1585 | 1442 | ||
1586 | 1443 | /*FIXME: Here you need to set the correct value of finger_map_index, | |
1587 | /* | 1444 | * in case it is 0, then you set it back to 64, and in case it is x, |
1445 | * then you set it back to x-1. current_finger_index = ( current_finger_index - 1) % MAX_FINGERS | ||
1588 | * Add an entry in finger table. | 1446 | * Add an entry in finger table. |
1589 | * @param finger_identity Peer identity of finger | 1447 | * @param finger_identity Peer identity of finger |
1590 | * @param finger_trail Trail to reach the finger | 1448 | * @param finger_trail Trail to reach the finger |
@@ -1598,15 +1456,16 @@ void finger_table_add (struct GNUNET_PeerIdentity *finger_identity, | |||
1598 | unsigned int finger_map_index) | 1456 | unsigned int finger_map_index) |
1599 | { | 1457 | { |
1600 | struct FingerInfo *new_finger_entry; | 1458 | struct FingerInfo *new_finger_entry; |
1601 | struct GNUNET_PeerIdentity key_ret; | 1459 | //struct GNUNET_PeerIdentity key_ret; |
1602 | int i; | 1460 | int i; |
1603 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | 1461 | //struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; |
1604 | struct FingerInfo *existing_finger; | 1462 | //struct FingerInfo *existing_finger; |
1605 | int finger_index; | 1463 | //int finger_index; |
1606 | 1464 | ||
1607 | /* SUPU Here we trying to check if we already have an entry. If yes then we | 1465 | /* SUPU Here we trying to check if we already have an entry. If yes then we |
1608 | can keep two trails for redundant routing. if they are different then we | 1466 | can keep two trails for redundant routing. if they are different then we |
1609 | need to choose the closest one. and remove the other one. */ | 1467 | need to choose the closest one. and remove the other one. */ |
1468 | #if 0 | ||
1610 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | 1469 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); |
1611 | 1470 | ||
1612 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | 1471 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) |
@@ -1673,6 +1532,7 @@ void finger_table_add (struct GNUNET_PeerIdentity *finger_identity, | |||
1673 | } | 1532 | } |
1674 | 1533 | ||
1675 | add_new_entry: | 1534 | add_new_entry: |
1535 | #endif | ||
1676 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | 1536 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); |
1677 | memcpy (&(new_finger_entry->finger_identity), finger_identity, sizeof (struct GNUNET_PeerIdentity)); | 1537 | memcpy (&(new_finger_entry->finger_identity), finger_identity, sizeof (struct GNUNET_PeerIdentity)); |
1678 | new_finger_entry->finger_map_index = finger_map_index; | 1538 | new_finger_entry->finger_map_index = finger_map_index; |
@@ -1787,16 +1647,18 @@ find_closest_successor(struct Sorting_List *all_known_peers, uint64_t value, | |||
1787 | 1647 | ||
1788 | 1648 | ||
1789 | /** | 1649 | /** |
1650 | * here you should set the current source instead of destination type. | ||
1790 | * Find closest successor for the value. | 1651 | * Find closest successor for the value. |
1791 | * @param value Value for which we are looking for successor | 1652 | * @param value Value for which we are looking for successor |
1792 | * @param current_destination NULL if my_identity is successor else finger/friend | 1653 | * FIXME: pass the correct value for current_destination |
1793 | * identity | 1654 | * @param[out] current_destination set to the end of the finger to traverse next |
1794 | * @param type Next destination type | 1655 | * @param type Next destination type |
1795 | * @return Peer identity of next destination i.e. successor of value. | 1656 | * @return Peer identity of next hop, NULL if we are the |
1657 | * ultimate destination | ||
1796 | */ | 1658 | */ |
1797 | static struct GNUNET_PeerIdentity * | 1659 | static struct GNUNET_PeerIdentity * |
1798 | find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination, | 1660 | find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination, |
1799 | enum current_destination_type *type) | 1661 | struct GNUNET_PeerIdentity *current_source) |
1800 | { | 1662 | { |
1801 | struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; | 1663 | struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; |
1802 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | 1664 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; |
@@ -1869,12 +1731,10 @@ find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination, | |||
1869 | 1731 | ||
1870 | if (successor->type == MY_ID) | 1732 | if (successor->type == MY_ID) |
1871 | { | 1733 | { |
1872 | *type = MY_ID; | ||
1873 | return NULL; | 1734 | return NULL; |
1874 | } | 1735 | } |
1875 | else if (successor->type == FRIEND) | 1736 | else if (successor->type == FRIEND) |
1876 | { | 1737 | { |
1877 | *type = FRIEND; | ||
1878 | struct FriendInfo *target_friend; | 1738 | struct FriendInfo *target_friend; |
1879 | target_friend = (struct FriendInfo *)successor->data; | 1739 | target_friend = (struct FriendInfo *)successor->data; |
1880 | memcpy (current_destination, &(target_friend->id), sizeof (struct GNUNET_PeerIdentity)); | 1740 | memcpy (current_destination, &(target_friend->id), sizeof (struct GNUNET_PeerIdentity)); |
@@ -1882,7 +1742,6 @@ find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination, | |||
1882 | } | 1742 | } |
1883 | else if (successor->type == FINGER) | 1743 | else if (successor->type == FINGER) |
1884 | { | 1744 | { |
1885 | *type = FINGER; | ||
1886 | struct GNUNET_PeerIdentity *next_hop; | 1745 | struct GNUNET_PeerIdentity *next_hop; |
1887 | struct FingerInfo *finger; | 1746 | struct FingerInfo *finger; |
1888 | struct TrailPeerList *iterator; | 1747 | struct TrailPeerList *iterator; |
@@ -1892,57 +1751,63 @@ find_successor (uint64_t value, struct GNUNET_PeerIdentity *current_destination, | |||
1892 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1751 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
1893 | memcpy (next_hop, &(iterator->peer), sizeof (struct GNUNET_PeerIdentity)); | 1752 | memcpy (next_hop, &(iterator->peer), sizeof (struct GNUNET_PeerIdentity)); |
1894 | memcpy (current_destination, &(finger->finger_identity), sizeof (struct GNUNET_PeerIdentity)); | 1753 | memcpy (current_destination, &(finger->finger_identity), sizeof (struct GNUNET_PeerIdentity)); |
1754 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
1895 | return next_hop; | 1755 | return next_hop; |
1896 | } | 1756 | } |
1897 | else | 1757 | else |
1898 | { | 1758 | { |
1899 | type = NULL; | 1759 | GNUNET_assert (0); |
1900 | return NULL; | 1760 | return NULL; |
1901 | } | 1761 | } |
1902 | } | 1762 | } |
1903 | 1763 | ||
1904 | 1764 | ||
1905 | /** | 1765 | /** FIXME: by default I keep current_source, and destination as my own id. |
1906 | * Send a get message to selected target friend. If target friend in NULL, | 1766 | * in case we find a finger then we update current_source in the |
1907 | * then search for a target friend. | 1767 | * find_successor message. |
1908 | * @param block_type type of the block | 1768 | * Construct a Put message and send it to target_peer. |
1909 | * @param options routing options | 1769 | * @param key Key for the content |
1910 | * @param desired_replication_level desired replication count | 1770 | * @param data Content to store |
1911 | * @param hop_count how many hops did this request traverse so far? | 1771 | * @param data_size Size of content @a data in bytes |
1912 | * @param get_peer_path Peer list to reach to final destination which contains the data. | 1772 | * @param block_type Type of the block |
1913 | * @param get_path_length Total numbers of peer in @a get_path | 1773 | * @param options Routing options |
1914 | * @param key Key key for the content | 1774 | * @param desired_replication_level Desired replication count |
1915 | * @param target_peer Next peer to forward the message to. | 1775 | * @param expiration_time When does the content expire |
1916 | * @param current_destination Peer which will get this message. | 1776 | * @param current_destination |
1917 | * @param current_source Peer for @a current_destination is the finger. | 1777 | * @param current_source |
1918 | * @param current_dest_type Type of current destination can be either FRIEND or FINGER | 1778 | * @param target_peer Peer to which this message will be forwarded. |
1779 | * @param hop_count Number of hops traversed so far. | ||
1780 | * @param put_path_length Total number of peers in @a put_path | ||
1781 | * @param put_path Number of peers traversed so far | ||
1919 | */ | 1782 | */ |
1920 | void | 1783 | void |
1921 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type block_type, | 1784 | GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, |
1922 | enum GNUNET_DHT_RouteOption options, | 1785 | const void *data, size_t data_size, |
1923 | uint32_t desired_replication_level, | 1786 | enum GNUNET_BLOCK_Type block_type, |
1924 | uint32_t hop_count, | 1787 | enum GNUNET_DHT_RouteOption options, |
1925 | struct GNUNET_PeerIdentity *get_peer_path, | 1788 | uint32_t desired_replication_level, |
1926 | unsigned int get_path_length, | 1789 | struct GNUNET_TIME_Absolute expiration_time, |
1927 | struct GNUNET_HashCode *key, | 1790 | struct GNUNET_PeerIdentity *current_destination, |
1928 | struct GNUNET_PeerIdentity *target_peer, | 1791 | struct GNUNET_PeerIdentity *current_source, |
1929 | struct GNUNET_PeerIdentity *current_destination, | 1792 | struct GNUNET_PeerIdentity *target_peer, |
1930 | struct GNUNET_PeerIdentity *current_source, | 1793 | uint32_t hop_count, |
1931 | enum current_destination_type current_dest_type) | 1794 | uint32_t put_path_length, |
1795 | struct GNUNET_PeerIdentity *put_path) | ||
1932 | { | 1796 | { |
1933 | struct PeerGetMessage *get_request; | 1797 | struct PeerPutMessage *ppm; |
1934 | struct P2PPendingMessage *pending; | 1798 | struct P2PPendingMessage *pending; |
1935 | struct GNUNET_PeerIdentity *get_path; | ||
1936 | struct FriendInfo *target_friend; | 1799 | struct FriendInfo *target_friend; |
1937 | struct GNUNET_PeerIdentity *next_hop; | 1800 | struct GNUNET_PeerIdentity *pp; |
1938 | struct GNUNET_PeerIdentity *current_dest; | ||
1939 | enum current_destination_type dest_type; | ||
1940 | uint64_t key_value; | ||
1941 | size_t msize; | 1801 | size_t msize; |
1942 | 1802 | ||
1943 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | 1803 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + |
1944 | msize = sizeof (struct PeerGetMessage) + | 1804 | sizeof (struct PeerPutMessage); |
1945 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 1805 | |
1806 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
1807 | { | ||
1808 | put_path_length = 0; | ||
1809 | msize = data_size + sizeof (struct PeerPutMessage); | ||
1810 | } | ||
1946 | 1811 | ||
1947 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1812 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1948 | { | 1813 | { |
@@ -1950,150 +1815,91 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type block_type, | |||
1950 | return; | 1815 | return; |
1951 | } | 1816 | } |
1952 | 1817 | ||
1953 | memcpy (&key_value, key, sizeof (uint64_t)); | 1818 | /* This is the first call made from clients file. So, we should search for the |
1954 | 1819 | target_friend. */ | |
1955 | if (NULL == target_peer) | 1820 | if (NULL == target_peer) |
1956 | { | 1821 | { |
1957 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | 1822 | uint64_t key_value; |
1958 | current_dest = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1823 | struct GNUNET_PeerIdentity *next_hop; |
1959 | dest_type = MY_ID; | ||
1960 | next_hop = find_successor (key_value, current_dest, &dest_type); | ||
1961 | 1824 | ||
1962 | if (dest_type == MY_ID) | 1825 | memcpy (&key_value, key, sizeof (uint64_t)); |
1826 | next_hop = find_successor (key_value, current_destination, current_source); | ||
1827 | if (NULL == next_hop) /* I am the destination do datacache_put */ | ||
1963 | { | 1828 | { |
1964 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | 1829 | GDS_DATACACHE_handle_put (expiration_time, key, put_path_length, put_path, |
1965 | get_path = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1830 | block_type, data_size, data); |
1966 | memcpy (get_path, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
1967 | get_path_length = 1; | ||
1968 | GDS_DATACACHE_handle_get (key,block_type, NULL, 0, | ||
1969 | NULL, 0, get_path_length, get_path, 0, NULL,&my_identity); | ||
1970 | return; | 1831 | return; |
1971 | } | 1832 | } |
1972 | else | 1833 | else |
1973 | { | 1834 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
1974 | if (dest_type == FINGER) | ||
1975 | { | ||
1976 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
1977 | } | ||
1978 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | ||
1979 | } | ||
1980 | current_dest_type = dest_type; | ||
1981 | |||
1982 | } | 1835 | } |
1983 | else | ||
1984 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer); | ||
1985 | 1836 | ||
1986 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1837 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1987 | pending->importance = 0; /* FIXME */ | 1838 | pending->timeout = expiration_time; |
1988 | get_request = (struct PeerGetMessage *) &pending[1]; | 1839 | ppm = (struct PeerPutMessage *) &pending[1]; |
1989 | pending->msg = &get_request->header; | 1840 | pending->msg = &ppm->header; |
1990 | get_request->header.size = htons (msize); | 1841 | ppm->header.size = htons (msize); |
1991 | get_request->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); | 1842 | ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); |
1992 | get_request->get_path_length = htonl (get_path_length); | 1843 | ppm->options = htonl (options); |
1993 | get_request->key = *key; | 1844 | ppm->block_type = htonl (block_type); |
1994 | if (current_destination != NULL) | 1845 | ppm->hop_count = htonl (hop_count + 1); |
1995 | memcpy (&(get_request->current_destination), current_destination, sizeof (struct GNUNET_PeerIdentity)); | 1846 | ppm->desired_replication_level = htonl (desired_replication_level); |
1996 | else | 1847 | ppm->put_path_length = htonl (put_path_length); |
1997 | memcpy (&(get_request->current_destination), current_dest, sizeof (struct GNUNET_PeerIdentity)); | 1848 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
1998 | /* FIXME: Is this comparison correct? */ | 1849 | ppm->key = *key; |
1999 | if (current_source != NULL) | 1850 | ppm->current_destination = *current_destination; |
2000 | memcpy (&(get_request->current_source), current_source, sizeof (struct GNUNET_PeerIdentity)); | 1851 | ppm->current_source = *current_source; |
2001 | get_request->current_dest_type = htonl (current_dest_type); | 1852 | |
2002 | get_path = (struct GNUNET_PeerIdentity *) &get_request[1]; | 1853 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; |
2003 | if (get_path_length > 0) | 1854 | if (put_path_length != 0) |
2004 | memcpy (get_path, get_peer_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 1855 | { |
1856 | memcpy (pp, put_path, | ||
1857 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); | ||
1858 | } | ||
1859 | memcpy (&pp[put_path_length], data, data_size); | ||
2005 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 1860 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
2006 | target_friend->pending_count++; | 1861 | target_friend->pending_count++; |
2007 | process_friend_queue (target_friend); | 1862 | process_friend_queue (target_friend); |
2008 | |||
2009 | } | 1863 | } |
2010 | 1864 | ||
2011 | 1865 | ||
2012 | /** | ||
2013 | * FIXME: Here you should update the fields of struct PeerGetResultMessage. | ||
2014 | * At the end of this message you should add the data and get path and send | ||
2015 | * to the original requesting client. and there you should call GDS_CLIENT_handle_reply | ||
2016 | * with correct parameter. | ||
2017 | * @param expiration | ||
2018 | * @param key | ||
2019 | * @param get_path_length | ||
2020 | * @param get_path | ||
2021 | * @param put_path_length | ||
2022 | * @param put_path | ||
2023 | * @param type | ||
2024 | * @param data_size | ||
2025 | * @param data | ||
2026 | */ | ||
2027 | void | ||
2028 | GDS_NEIGHBOURS_datacache_get (struct GNUNET_TIME_Absolute expiration, | ||
2029 | const struct GNUNET_HashCode *key, | ||
2030 | unsigned int get_path_length, | ||
2031 | const struct GNUNET_PeerIdentity *get_path, | ||
2032 | unsigned int put_path_length, | ||
2033 | const struct GNUNET_PeerIdentity *put_path, | ||
2034 | enum GNUNET_BLOCK_Type type, size_t data_size, | ||
2035 | const void *data) | ||
2036 | { | ||
2037 | /* Here you don't have the get path and get path length. you should call | ||
2038 | some function get those values and update the message and send them. */ | ||
2039 | } | ||
2040 | |||
2041 | 1866 | ||
2042 | /** | 1867 | /** FIXME: by default I keep current_source, and destination as my own id. |
2043 | * TODO: In case of put, you add the peer in the peer list in handle_dht_p2p_put. | 1868 | * in case we find a finger then we update current_source in the |
2044 | * Verify that the addition is correct and we are adding peers correctly and incrementing | 1869 | * find_successor message. |
2045 | * the trail length correctly. | 1870 | * Construct a Get message and send it to target_peer. |
2046 | * Handle a put request from client file. If I am the final destination, | 1871 | * @param key Key for the content |
2047 | * do a put else forward the message to next peer. | 1872 | * @param block_type Type of the block |
2048 | * @param block_type type of the block | 1873 | * @param options Routing options |
2049 | * @param options routing options | 1874 | * @param desired_replication_level Desired replication count |
2050 | * @param desired_replication_level desired replication count, 0 for current | 1875 | * @param expiration_time When does the content expire |
2051 | * implementation of X-Vine. | 1876 | * @param current_destination |
2052 | * @param expiration_time when does the content expire | 1877 | * @param current_source |
2053 | * @param hop_count how many hops has this message traversed so far | 1878 | * @param target_peer Peer to which this message will be forwarded. |
2054 | * @param key key for the content | 1879 | * @param hop_count Number of hops traversed so far. |
2055 | * @param put_path_length number of entries in @a put_path | 1880 | * @param put_path_length Total number of peers in @a put_path |
2056 | * @param put_path peers this request has traversed so far (if tracked) | 1881 | * @param put_path Number of peers traversed so far |
2057 | * @param data payload to store | ||
2058 | * @param data_size number of bytes in @a data | ||
2059 | * @param current_destination intermediate destination of the packet. | ||
2060 | * @param current_source source for which @a current_destination is destination. | ||
2061 | * @param dest_type type of @a current_destination. | ||
2062 | * @param target_peer_id Next peer to forward the message to. | ||
2063 | */ | 1882 | */ |
2064 | void | 1883 | void |
2065 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type block_type, | 1884 | GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, |
2066 | enum GNUNET_DHT_RouteOption options, | 1885 | enum GNUNET_BLOCK_Type block_type, |
2067 | uint32_t desired_replication_level, | 1886 | enum GNUNET_DHT_RouteOption options, |
2068 | struct GNUNET_TIME_Absolute expiration_time, | 1887 | uint32_t desired_replication_level, |
2069 | uint32_t hop_count, | 1888 | struct GNUNET_PeerIdentity *current_destination, |
2070 | const struct GNUNET_HashCode *key, | 1889 | struct GNUNET_PeerIdentity *current_source, |
2071 | unsigned int put_path_length, | 1890 | struct GNUNET_PeerIdentity *target_peer, |
2072 | struct GNUNET_PeerIdentity *put_path, | 1891 | uint32_t hop_count, |
2073 | const void *data, size_t data_size, | 1892 | uint32_t get_path_length, |
2074 | struct GNUNET_PeerIdentity *current_destination, | 1893 | struct GNUNET_PeerIdentity *get_path) |
2075 | struct GNUNET_PeerIdentity *current_source, | ||
2076 | enum current_destination_type dest_type, | ||
2077 | struct GNUNET_PeerIdentity *target_peer) | ||
2078 | { | 1894 | { |
2079 | struct PeerPutMessage *ppm; | 1895 | struct PeerGetMessage *pgm; |
2080 | struct P2PPendingMessage *pending; | 1896 | struct P2PPendingMessage *pending; |
2081 | struct FriendInfo *target_friend; | 1897 | struct FriendInfo *target_friend; |
2082 | struct GNUNET_PeerIdentity *pp; | 1898 | struct GNUNET_PeerIdentity *gp; |
2083 | struct GNUNET_PeerIdentity *next_hop; | ||
2084 | struct GNUNET_PeerIdentity *current_dest; | ||
2085 | enum current_destination_type curr_dest_type; | ||
2086 | size_t msize; | 1899 | size_t msize; |
2087 | uint64_t key_value; | ||
2088 | 1900 | ||
2089 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + | 1901 | msize = sizeof (struct PeerGetMessage) + |
2090 | sizeof (struct PeerPutMessage); | 1902 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2091 | |||
2092 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
2093 | { | ||
2094 | put_path_length = 0; | ||
2095 | msize = data_size + sizeof (struct PeerPutMessage); | ||
2096 | } | ||
2097 | 1903 | ||
2098 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1904 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
2099 | { | 1905 | { |
@@ -2101,79 +1907,39 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type block_type, | |||
2101 | return; | 1907 | return; |
2102 | } | 1908 | } |
2103 | 1909 | ||
2104 | memcpy (&key_value, key, sizeof (uint64_t)); | 1910 | if (NULL == target_peer) |
2105 | |||
2106 | if (target_peer == NULL) | ||
2107 | { | 1911 | { |
2108 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | 1912 | /* This is the first call from client file, we need to search for next_hop*/ |
2109 | curr_dest_type = MY_ID; | 1913 | struct GNUNET_PeerIdentity *next_hop; |
2110 | current_dest = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1914 | uint64_t key_value; |
2111 | next_hop = find_successor (key_value, current_dest, &curr_dest_type); | 1915 | |
2112 | if (curr_dest_type == MY_ID) | 1916 | memcpy (&key_value, key, sizeof (struct GNUNET_PeerIdentity)); |
1917 | next_hop = find_successor (key_value, current_destination, current_source); | ||
1918 | if (NULL == next_hop) /* I am the destination do datacache_put */ | ||
2113 | { | 1919 | { |
2114 | /* FIXME: Choose one place to do datacache_put. I am doing put only if its | 1920 | GDS_DATACACHE_handle_get (key,block_type, NULL, 0, |
2115 | destination so I will do no put operation | 1921 | NULL, 0, 1, &my_identity, NULL,&my_identity); |
2116 | in the client file.*/ | ||
2117 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
2118 | GDS_DATACACHE_handle_put (expiration_time, key, put_path_length, put_path, | ||
2119 | block_type, data_size, data); | ||
2120 | return; | ||
2121 | } | 1922 | } |
2122 | else | 1923 | else |
2123 | { | 1924 | { |
2124 | /* Find the friend corresponding to next_hop */ | ||
2125 | if (curr_dest_type == FINGER) | ||
2126 | { | ||
2127 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
2128 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2129 | } | ||
2130 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 1925 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2131 | } | 1926 | } |
2132 | dest_type = curr_dest_type; | ||
2133 | } | 1927 | } |
2134 | else | ||
2135 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer); | ||
2136 | 1928 | ||
2137 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 1929 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
2138 | pending->importance = 0; /* FIXME */ | 1930 | pending->importance = 0; /* FIXME */ |
2139 | pending->timeout = expiration_time; | 1931 | pgm = (struct PeerGetMessage *) &pending[1]; |
2140 | ppm = (struct PeerPutMessage *) &pending[1]; | 1932 | pending->msg = &pgm->header; |
2141 | pending->msg = &ppm->header; | 1933 | pgm->header.size = htons (msize); |
2142 | ppm->header.size = htons (msize); | 1934 | pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); |
2143 | ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); | 1935 | pgm->get_path_length = htonl (get_path_length); |
2144 | ppm->options = htonl (options); | 1936 | pgm->key = *key; |
2145 | ppm->block_type = htonl (block_type); | 1937 | pgm->current_destination = *current_destination; |
2146 | ppm->hop_count = htonl (hop_count + 1); | 1938 | pgm->current_source = *current_source; |
2147 | ppm->desired_replication_level = htonl (desired_replication_level); | 1939 | pgm->hop_count = htonl (hop_count + 1); |
2148 | ppm->put_path_length = htonl (put_path_length); | 1940 | |
2149 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); | 1941 | gp = (struct GNUNET_PeerIdentity *) &pgm[1]; |
2150 | ppm->current_destination_type = dest_type; | 1942 | memcpy (gp, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2151 | /* FIXME: Here I am checking if we have a value in current_source then only copy. | ||
2152 | I am not sure if this checking is correct or not. */ | ||
2153 | if (current_source != NULL) | ||
2154 | { | ||
2155 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
2156 | memcpy (&(ppm->current_source), current_source, sizeof (struct GNUNET_PeerIdentity)); | ||
2157 | } | ||
2158 | else | ||
2159 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
2160 | if (current_destination != NULL) | ||
2161 | memcpy (&(ppm->current_destination), current_destination, sizeof (struct GNUNET_PeerIdentity)); | ||
2162 | else | ||
2163 | memcpy (&(ppm->current_destination), current_dest, sizeof (struct GNUNET_PeerIdentity)); | ||
2164 | ppm->current_destination_type = htonl (dest_type); | ||
2165 | ppm->key = *key; | ||
2166 | |||
2167 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; | ||
2168 | /* FIXME: Is this comparison correct? Do we need this comparison. What happens | ||
2169 | in the case put_path_length is 0 and put_path is NULL, then at run time | ||
2170 | memcpy will fail. And I am not sure if comparing NULL is correct or not. */ | ||
2171 | if (put_path_length != 0) | ||
2172 | { | ||
2173 | memcpy (pp, put_path, | ||
2174 | sizeof (struct GNUNET_PeerIdentity) * put_path_length); | ||
2175 | } | ||
2176 | memcpy (&pp[put_path_length], data, data_size); | ||
2177 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 1943 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
2178 | target_friend->pending_count++; | 1944 | target_friend->pending_count++; |
2179 | process_friend_queue (target_friend); | 1945 | process_friend_queue (target_friend); |
@@ -2181,18 +1947,18 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type block_type, | |||
2181 | 1947 | ||
2182 | 1948 | ||
2183 | /** | 1949 | /** |
2184 | * Send get result back to requesting client. | 1950 | * Send the get result to requesting client. |
2185 | * @param expiration when will the reply expire | 1951 | * @param expiration When will this result expire? |
2186 | * @param key the query this reply is for | 1952 | * @param key Key of the requested data. |
2187 | * @param get_path_length number of peers in @a get_path | 1953 | * @param put_path_length Number of peers in @a put_path |
2188 | * @param get_path path the reply took on get | 1954 | * @param put_path Path taken to put the data at its stored location. |
2189 | * @param put_path_length number of peers in @a put_path | 1955 | * @param type Block type |
2190 | * @param put_path path the reply took on put | 1956 | * @param data_size Size of the @a data |
2191 | * @param type type of the reply | 1957 | * @param data Payload to store |
2192 | * @param data_size number of bytes in @a data | 1958 | * @param get_path Path taken to reach to the location of the key. |
2193 | * @param data application payload data | 1959 | * @param get_path_length Number of peers in @a get_path |
2194 | * @param get_path | 1960 | * @param next_hop Next peer to forward the message to. |
2195 | * @param get_path_length | 1961 | * @param source_peer Peer which has the data for the key. |
2196 | */ | 1962 | */ |
2197 | void | 1963 | void |
2198 | GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | 1964 | GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, |
@@ -2203,7 +1969,6 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | |||
2203 | const void *data, | 1969 | const void *data, |
2204 | struct GNUNET_PeerIdentity *get_path, | 1970 | struct GNUNET_PeerIdentity *get_path, |
2205 | unsigned int get_path_length, | 1971 | unsigned int get_path_length, |
2206 | unsigned int current_path_index, | ||
2207 | struct GNUNET_PeerIdentity *next_hop, | 1972 | struct GNUNET_PeerIdentity *next_hop, |
2208 | struct GNUNET_PeerIdentity *source_peer) | 1973 | struct GNUNET_PeerIdentity *source_peer) |
2209 | { | 1974 | { |
@@ -2212,6 +1977,7 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | |||
2212 | struct GNUNET_PeerIdentity *pp; | 1977 | struct GNUNET_PeerIdentity *pp; |
2213 | struct P2PPendingMessage *pending; | 1978 | struct P2PPendingMessage *pending; |
2214 | struct FriendInfo *target_friend; | 1979 | struct FriendInfo *target_friend; |
1980 | int current_path_index; | ||
2215 | size_t msize; | 1981 | size_t msize; |
2216 | 1982 | ||
2217 | msize = get_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + | 1983 | msize = get_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + |
@@ -2223,7 +1989,8 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | |||
2223 | return; | 1989 | return; |
2224 | } | 1990 | } |
2225 | 1991 | ||
2226 | if (current_path_index == 0) | 1992 | current_path_index = search_my_location(get_path); |
1993 | if (0 == current_path_index) | ||
2227 | { | 1994 | { |
2228 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | 1995 | FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); |
2229 | GDS_CLIENTS_handle_reply (expiration, key, get_path_length, get_path, put_path_length, | 1996 | GDS_CLIENTS_handle_reply (expiration, key, get_path_length, get_path, put_path_length, |
@@ -2236,7 +2003,6 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | |||
2236 | pending->msg = &get_result->header; | 2003 | pending->msg = &get_result->header; |
2237 | get_result->header.size = htons (msize); | 2004 | get_result->header.size = htons (msize); |
2238 | get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT); | 2005 | get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT); |
2239 | get_result->current_path_index = current_path_index; | ||
2240 | get_result->key = *key; | 2006 | get_result->key = *key; |
2241 | memcpy (&(get_result->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | 2007 | memcpy (&(get_result->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); |
2242 | get_result->expiration_time = expiration; | 2008 | get_result->expiration_time = expiration; |
@@ -2257,117 +2023,78 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | |||
2257 | 2023 | ||
2258 | 2024 | ||
2259 | /** | 2025 | /** |
2260 | * | 2026 | * Send tral rejection message |
2261 | * @param cls | 2027 | * @param source_peer Source peer which wants to set up the trail. |
2262 | * @param peer | 2028 | * @param finger_identity Finger identity to which it want to setup the trail. |
2263 | * @param message | 2029 | * @param congested_peer Peer which has send trail rejection message |
2264 | * @return | 2030 | * @param next_hop Peer to which this message should be forwarded. |
2031 | * @param finger_map_index | ||
2032 | * @param trail_peer_list | ||
2033 | * @param trail_length | ||
2265 | */ | 2034 | */ |
2266 | static int | 2035 | void |
2267 | handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | 2036 | GDS_NEIGHBOURS_send_trail_rejection_message(struct GNUNET_PeerIdentity *source_peer, |
2268 | const struct GNUNET_MessageHeader *message) | 2037 | uint64_t finger_identity, |
2038 | struct GNUNET_PeerIdentity *congested_peer, | ||
2039 | const struct GNUNET_PeerIdentity *next_hop, | ||
2040 | unsigned int finger_map_index, | ||
2041 | struct GNUNET_PeerIdentity *trail_peer_list, | ||
2042 | unsigned int trail_length) | ||
2269 | { | 2043 | { |
2270 | /* If you are the source, go back to the client file and there search for | 2044 | struct PeerTrailRejectionMessage *trail_rejection; |
2271 | the requesting client and send back the result. */ | 2045 | struct GNUNET_PeerIdentity *trail_list; |
2272 | struct PeerGetResultMessage *get_result; | 2046 | struct P2PPendingMessage *pending; |
2273 | struct GNUNET_PeerIdentity *get_path; | 2047 | struct FriendInfo *target_friend; |
2274 | struct GNUNET_PeerIdentity *put_path; | ||
2275 | void *payload; | ||
2276 | size_t payload_size; | ||
2277 | size_t msize; | 2048 | size_t msize; |
2278 | unsigned int getlen; | ||
2279 | unsigned int putlen; | ||
2280 | int current_path_index; | ||
2281 | |||
2282 | msize = ntohs (message->size); | ||
2283 | if (msize < sizeof (struct PeerGetResultMessage)) | ||
2284 | { | ||
2285 | GNUNET_break_op (0); | ||
2286 | return GNUNET_YES; | ||
2287 | } | ||
2288 | |||
2289 | get_result = (struct PeerGetResultMessage *)message; | ||
2290 | getlen = ntohl (get_result->get_path_length); | ||
2291 | putlen = ntohl (get_result->put_path_length); | ||
2292 | 2049 | ||
2293 | if ((msize < | 2050 | msize = sizeof (struct PeerTrailRejectionMessage); |
2294 | sizeof (struct PeerGetResultMessage) + | ||
2295 | getlen * sizeof (struct GNUNET_PeerIdentity) + | ||
2296 | putlen * sizeof (struct GNUNET_PeerIdentity)) || | ||
2297 | (getlen > | ||
2298 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity) || | ||
2299 | (putlen > | ||
2300 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))) | ||
2301 | { | ||
2302 | GNUNET_break_op (0); | ||
2303 | return GNUNET_YES; | ||
2304 | } | ||
2305 | 2051 | ||
2306 | get_path = (struct GNUNET_PeerIdentity *) &get_result[1]; | 2052 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
2307 | payload = &get_path[getlen]; | 2053 | pending->importance = 0; /* FIXME */ |
2308 | payload_size = msize - (sizeof (struct PeerGetResultMessage) + | 2054 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
2309 | getlen * sizeof (struct GNUNET_PeerIdentity)); | 2055 | trail_rejection = (struct PeerTrailRejectionMessage *) &pending[1]; |
2310 | /* FIXME: Check if its correct or not. */ | 2056 | pending->msg = &trail_rejection->header; |
2311 | if (putlen > 0) | 2057 | trail_rejection->header.size = htons (msize); |
2312 | put_path = &get_path[1]; | 2058 | trail_rejection->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); |
2059 | memcpy (&(trail_rejection->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | ||
2060 | memcpy (&(trail_rejection->congested_peer), congested_peer, sizeof (struct GNUNET_PeerIdentity)); | ||
2061 | memcpy (&(trail_rejection->finger_identity), &finger_identity, sizeof (uint64_t)); | ||
2062 | trail_rejection->finger_map_index = htonl(finger_map_index); | ||
2063 | trail_rejection->trail_length = htonl (trail_length); | ||
2313 | 2064 | ||
2314 | current_path_index = ntohl (get_result->current_path_index); | 2065 | trail_list = (struct GNUNET_PeerIdentity *)&trail_rejection[1]; |
2315 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_path[0])))) | 2066 | memcpy (trail_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
2316 | { | ||
2317 | //GDS_CLIENTS_process_get_result(); | ||
2318 | GDS_CLIENTS_handle_reply (get_result->expiration_time, &(get_result->key), | ||
2319 | getlen, get_path, putlen, | ||
2320 | put_path, get_result->type, payload_size, payload); | ||
2321 | return GNUNET_YES; | ||
2322 | } | ||
2323 | else | ||
2324 | { | ||
2325 | struct GNUNET_PeerIdentity *next_hop; | ||
2326 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2327 | if (current_path_index != 0) | ||
2328 | current_path_index--; | ||
2329 | memcpy (next_hop, &get_path[current_path_index], sizeof (struct GNUNET_PeerIdentity)); | ||
2330 | 2067 | ||
2331 | GDS_NEIGHBOURS_send_get_result (get_result->expiration_time, &(get_result->key), | 2068 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2332 | putlen, put_path, | 2069 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); |
2333 | get_result->type, payload_size,payload, | 2070 | target_friend->pending_count++; |
2334 | get_path, getlen,current_path_index, | 2071 | process_friend_queue (target_friend); |
2335 | next_hop, &(get_result->source_peer)); | ||
2336 | return GNUNET_YES; | ||
2337 | } | ||
2338 | return GNUNET_SYSERR; | ||
2339 | } | 2072 | } |
2340 | 2073 | ||
2341 | 2074 | ||
2342 | /** | 2075 | /** |
2343 | * FIXME: Can refactor the code where we are setting the current source and | 2076 | * |
2344 | * current_dest_type | 2077 | * @param cls |
2345 | * Core handler for p2p put requests. | 2078 | * @param peer |
2346 | * | 2079 | * @param message |
2347 | * @param cls closure | 2080 | * @return |
2348 | * @param peer sender of the request | ||
2349 | * @param message message | ||
2350 | * @param peer peer identity this notification is about | ||
2351 | * @return #GNUNET_OK to keep the connection open, | ||
2352 | * #GNUNET_SYSERR to close it (signal serious error) | ||
2353 | */ | 2081 | */ |
2354 | static int | 2082 | static int |
2355 | handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | 2083 | handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, |
2356 | const struct GNUNET_MessageHeader *message) | 2084 | const struct GNUNET_MessageHeader *message) |
2357 | { | 2085 | { |
2358 | struct PeerPutMessage *put; | 2086 | struct PeerPutMessage *put; |
2359 | struct GNUNET_PeerIdentity *put_path; | 2087 | struct GNUNET_PeerIdentity *put_path; |
2088 | struct GNUNET_HashCode test_key; | ||
2360 | enum GNUNET_DHT_RouteOption options; | 2089 | enum GNUNET_DHT_RouteOption options; |
2361 | enum current_destination_type current_dst_type; | 2090 | struct GNUNET_PeerIdentity current_destination; |
2362 | struct GNUNET_PeerIdentity *current_destination; | 2091 | struct GNUNET_PeerIdentity current_source; |
2363 | struct GNUNET_PeerIdentity *current_source; | ||
2364 | struct GNUNET_PeerIdentity *next_hop; | 2092 | struct GNUNET_PeerIdentity *next_hop; |
2365 | struct GNUNET_HashCode test_key; | ||
2366 | uint64_t key_value; | ||
2367 | void *payload; | 2093 | void *payload; |
2368 | size_t payload_size; | ||
2369 | size_t msize; | 2094 | size_t msize; |
2370 | uint32_t putlen; | 2095 | uint32_t putlen; |
2096 | size_t payload_size; | ||
2097 | uint64_t key_value; | ||
2371 | 2098 | ||
2372 | msize = ntohs (message->size); | 2099 | msize = ntohs (message->size); |
2373 | if (msize < sizeof (struct PeerPutMessage)) | 2100 | if (msize < sizeof (struct PeerPutMessage)) |
@@ -2389,6 +2116,8 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2389 | return GNUNET_YES; | 2116 | return GNUNET_YES; |
2390 | } | 2117 | } |
2391 | 2118 | ||
2119 | current_destination = put->current_destination; | ||
2120 | current_source = put->current_source; | ||
2392 | put_path = (struct GNUNET_PeerIdentity *) &put[1]; | 2121 | put_path = (struct GNUNET_PeerIdentity *) &put[1]; |
2393 | payload = &put_path[putlen]; | 2122 | payload = &put_path[putlen]; |
2394 | options = ntohl (put->options); | 2123 | options = ntohl (put->options); |
@@ -2418,7 +2147,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2418 | break; | 2147 | break; |
2419 | } | 2148 | } |
2420 | 2149 | ||
2421 | if (ntohl (put->block_type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ | 2150 | if (ntohl (put->block_type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ |
2422 | { | 2151 | { |
2423 | switch (GNUNET_BLOCK_evaluate (GDS_block_context, | 2152 | switch (GNUNET_BLOCK_evaluate (GDS_block_context, |
2424 | ntohl (put->block_type), | 2153 | ntohl (put->block_type), |
@@ -2443,8 +2172,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2443 | } | 2172 | } |
2444 | } | 2173 | } |
2445 | 2174 | ||
2446 | struct GNUNET_PeerIdentity pp[putlen + 1]; | 2175 | struct GNUNET_PeerIdentity pp[putlen + 1]; |
2447 | |||
2448 | /* extend 'put path' by sender */ | 2176 | /* extend 'put path' by sender */ |
2449 | /* FIXME: Check what are we doing here? */ | 2177 | /* FIXME: Check what are we doing here? */ |
2450 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 2178 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) |
@@ -2456,51 +2184,30 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2456 | else | 2184 | else |
2457 | putlen = 0; | 2185 | putlen = 0; |
2458 | 2186 | ||
2459 | current_destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2187 | memcpy (&key_value, &(put->key), sizeof (uint64_t)); |
2460 | memcpy (current_destination, &(put->current_destination), sizeof (struct GNUNET_PeerIdentity)); | 2188 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_destination, &my_identity))) |
2461 | current_dst_type = ntohl (put->current_destination_type); | 2189 | { |
2462 | memcpy (&key_value, &(put->key), sizeof (uint64_t)); | 2190 | next_hop = GDS_ROUTING_search (¤t_source, ¤t_destination, peer); |
2463 | current_source = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2191 | if (next_hop == NULL) |
2464 | if (current_dst_type == FRIEND) | ||
2465 | { | ||
2466 | next_hop = find_successor (key_value, current_destination, ¤t_dst_type); | ||
2467 | if (current_dst_type == FINGER) | ||
2468 | { | ||
2469 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2470 | } | ||
2471 | else | ||
2472 | current_source = NULL; | ||
2473 | } | ||
2474 | else if (current_dst_type == FINGER) | ||
2475 | { | ||
2476 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_destination)) | ||
2477 | { | ||
2478 | next_hop = find_successor (key_value, current_destination, ¤t_dst_type); | ||
2479 | if (current_dst_type == FINGER) | ||
2480 | { | ||
2481 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2482 | } | ||
2483 | else | ||
2484 | current_source = NULL; | ||
2485 | } | ||
2486 | else | ||
2487 | { | 2192 | { |
2488 | next_hop = GDS_ROUTING_search (&(put->current_source), current_destination, peer); | 2193 | /* refer to handle_dht_p2p_trail_setup. */ |
2489 | memcpy (current_source, &(put->current_source), sizeof (struct GNUNET_PeerIdentity)); | ||
2490 | current_dst_type = FINGER; | ||
2491 | } | 2194 | } |
2492 | } | 2195 | } |
2196 | else | ||
2197 | { | ||
2198 | next_hop = find_successor (key_value, ¤t_destination, ¤t_source); | ||
2199 | } | ||
2493 | 2200 | ||
2494 | if (current_dst_type == MY_ID) | 2201 | if (NULL == next_hop) /* I am the final destination */ |
2495 | { | 2202 | { |
2496 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), | 2203 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), |
2497 | &(put->key),putlen, pp, ntohl (put->block_type), | 2204 | &(put->key),putlen, pp, ntohl (put->block_type), |
2498 | payload_size, payload); | 2205 | payload_size, payload); |
2499 | return GNUNET_YES; | 2206 | return GNUNET_YES; |
2500 | } | 2207 | } |
2501 | else | 2208 | else |
2502 | { | 2209 | { |
2503 | GDS_CLIENTS_process_put (options, | 2210 | GDS_CLIENTS_process_put (options, |
2504 | ntohl (put->block_type), | 2211 | ntohl (put->block_type), |
2505 | ntohl (put->hop_count), | 2212 | ntohl (put->hop_count), |
2506 | ntohl (put->desired_replication_level), | 2213 | ntohl (put->desired_replication_level), |
@@ -2510,14 +2217,15 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2510 | payload, | 2217 | payload, |
2511 | payload_size); | 2218 | payload_size); |
2512 | 2219 | ||
2513 | GDS_NEIGHBOURS_handle_put (ntohl (put->block_type),ntohl (put->options), | 2220 | GDS_NEIGHBOURS_send_put (&put->key, payload, payload_size, |
2514 | ntohl (put->desired_replication_level), | 2221 | ntohl (put->block_type),ntohl (put->options), |
2515 | GNUNET_TIME_absolute_ntoh (put->expiration_time), | 2222 | ntohl (put->desired_replication_level), |
2516 | ntohl (put->hop_count),&put->key, putlen, | 2223 | GNUNET_TIME_absolute_ntoh (put->expiration_time), |
2517 | pp, payload, payload_size, | 2224 | ¤t_destination, ¤t_source, next_hop, |
2518 | current_destination, current_source,current_dst_type, next_hop); | 2225 | ntohl (put->hop_count), putlen, pp); |
2226 | |||
2519 | return GNUNET_YES; | 2227 | return GNUNET_YES; |
2520 | } | 2228 | } |
2521 | return GNUNET_SYSERR; | 2229 | return GNUNET_SYSERR; |
2522 | } | 2230 | } |
2523 | 2231 | ||
@@ -2536,15 +2244,13 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2536 | const struct GNUNET_MessageHeader *message) | 2244 | const struct GNUNET_MessageHeader *message) |
2537 | { | 2245 | { |
2538 | struct PeerGetMessage *get; | 2246 | struct PeerGetMessage *get; |
2539 | struct GNUNET_PeerIdentity *current_destination; | ||
2540 | uint64_t key_value; | ||
2541 | enum current_destination_type current_dest_type; | ||
2542 | struct GNUNET_PeerIdentity *next_hop; | ||
2543 | struct GNUNET_PeerIdentity *get_path; | 2247 | struct GNUNET_PeerIdentity *get_path; |
2544 | enum GNUNET_BLOCK_Type block_type; | 2248 | struct GNUNET_PeerIdentity current_destination; |
2545 | enum GNUNET_DHT_RouteOption options; | 2249 | struct GNUNET_PeerIdentity current_source; |
2250 | struct GNUNET_PeerIdentity *next_hop; | ||
2251 | uint32_t get_length; | ||
2252 | uint64_t key_value; | ||
2546 | size_t msize; | 2253 | size_t msize; |
2547 | unsigned int get_length; | ||
2548 | 2254 | ||
2549 | msize = ntohs (message->size); | 2255 | msize = ntohs (message->size); |
2550 | if (msize < sizeof (struct PeerGetMessage)) | 2256 | if (msize < sizeof (struct PeerGetMessage)) |
@@ -2556,6 +2262,8 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2556 | get = (struct PeerGetMessage *)message; | 2262 | get = (struct PeerGetMessage *)message; |
2557 | get_length = ntohl (get->get_path_length); | 2263 | get_length = ntohl (get->get_path_length); |
2558 | get_path = (struct GNUNET_PeerIdentity *)&get[1]; | 2264 | get_path = (struct GNUNET_PeerIdentity *)&get[1]; |
2265 | current_destination = get->current_destination; | ||
2266 | current_source = get->current_source; | ||
2559 | 2267 | ||
2560 | if ((msize < | 2268 | if ((msize < |
2561 | sizeof (struct PeerGetMessage) + | 2269 | sizeof (struct PeerGetMessage) + |
@@ -2567,52 +2275,29 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2567 | return GNUNET_YES; | 2275 | return GNUNET_YES; |
2568 | } | 2276 | } |
2569 | 2277 | ||
2570 | current_destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2571 | memcpy (current_destination, &(get->current_destination), sizeof (struct GNUNET_PeerIdentity)); | ||
2572 | memcpy (&key_value, &(get->key), sizeof (uint64_t)); | ||
2573 | current_dest_type = ntohl (get->current_dest_type); | ||
2574 | block_type = ntohl (get->block_type); | ||
2575 | options = ntohl (get->options); | ||
2576 | struct GNUNET_PeerIdentity *current_source; | ||
2577 | current_source = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2578 | |||
2579 | if (current_dest_type == FRIEND) | ||
2580 | { | ||
2581 | next_hop = find_successor (key_value, current_destination, ¤t_dest_type); | ||
2582 | if (current_dest_type == FINGER) | ||
2583 | { | ||
2584 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2585 | } | ||
2586 | else | ||
2587 | current_source = NULL; | ||
2588 | } | ||
2589 | else if (current_dest_type == FINGER) | ||
2590 | { | ||
2591 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, current_destination)) | ||
2592 | { | ||
2593 | next_hop = find_successor (key_value, current_destination, ¤t_dest_type); | ||
2594 | if (current_dest_type == FINGER) | ||
2595 | { | ||
2596 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2597 | } | ||
2598 | else | ||
2599 | current_source = NULL; | ||
2600 | } | ||
2601 | else | ||
2602 | { | ||
2603 | next_hop = GDS_ROUTING_search (&(get->current_source), current_destination, peer); | ||
2604 | current_dest_type = FINGER; | ||
2605 | } | ||
2606 | } | ||
2607 | |||
2608 | /* Add sender to get path */ | 2278 | /* Add sender to get path */ |
2609 | struct GNUNET_PeerIdentity gp[get_length + 1]; | 2279 | struct GNUNET_PeerIdentity gp[get_length + 1]; |
2610 | memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); | 2280 | memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); |
2611 | gp[get_length + 1] = *peer; | 2281 | gp[get_length + 1] = *peer; |
2612 | get_length = get_length + 1; | 2282 | get_length = get_length + 1; |
2613 | 2283 | ||
2614 | if (current_dest_type == MY_ID) | 2284 | memcpy (&key_value, &(get->key), sizeof (uint64_t)); |
2285 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_destination, &my_identity))) | ||
2286 | { | ||
2287 | next_hop = GDS_ROUTING_search (¤t_source, ¤t_destination, peer); | ||
2288 | if (next_hop == NULL) | ||
2289 | { | ||
2290 | /* refer to handle_dht_p2p_trail_setup. */ | ||
2291 | } | ||
2292 | } | ||
2293 | else | ||
2294 | { | ||
2295 | next_hop = find_successor (key_value, ¤t_destination, ¤t_source); | ||
2296 | } | ||
2297 | |||
2298 | if (NULL == next_hop) | ||
2615 | { | 2299 | { |
2300 | /* FIXME: Try to make this code also short and remove useless variables. */ | ||
2616 | struct GNUNET_PeerIdentity final_get_path[get_length+1]; | 2301 | struct GNUNET_PeerIdentity final_get_path[get_length+1]; |
2617 | memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); | 2302 | memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); |
2618 | memcpy (&final_get_path[get_length+1], &my_identity, sizeof (struct GNUNET_PeerIdentity)); | 2303 | memcpy (&final_get_path[get_length+1], &my_identity, sizeof (struct GNUNET_PeerIdentity)); |
@@ -2621,18 +2306,16 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2621 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2306 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2622 | memcpy (next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity)); | 2307 | memcpy (next_hop, &final_get_path[get_length-2], sizeof (struct GNUNET_PeerIdentity)); |
2623 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, | 2308 | GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0, |
2624 | get_length, final_get_path,get_length - 1,next_hop, &my_identity); | 2309 | get_length, final_get_path,next_hop, &my_identity); |
2625 | 2310 | ||
2626 | return GNUNET_YES; | 2311 | return GNUNET_YES; |
2627 | } | 2312 | } |
2628 | else | 2313 | else |
2629 | { | 2314 | { |
2630 | GDS_NEIGHBOURS_handle_get (block_type, options, get->desired_replication_level, | 2315 | GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options, |
2631 | get->hop_count, gp, | 2316 | get->desired_replication_level,¤t_destination, |
2632 | get_length, &(get->key),next_hop, | 2317 | ¤t_source, next_hop, 0, |
2633 | current_destination, &(get->current_source),current_dest_type); | 2318 | get_length, gp); |
2634 | |||
2635 | return GNUNET_YES; | ||
2636 | } | 2319 | } |
2637 | return GNUNET_SYSERR; | 2320 | return GNUNET_SYSERR; |
2638 | } | 2321 | } |
@@ -2640,52 +2323,87 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2640 | 2323 | ||
2641 | 2324 | ||
2642 | /** | 2325 | /** |
2643 | * Send tral rejection message | 2326 | * Core handler for get result |
2644 | * @param source_peer Source peer which wants to set up the trail. | 2327 | * @param cls closure |
2645 | * @param finger_identity Finger identity to which it want to setup the trail. | 2328 | * @param peer sender of the request |
2646 | * @param congested_peer Peer which has send trail rejection message | 2329 | * @param message message |
2647 | * @param next_hop Peer to which this message should be forwarded. | 2330 | * @return #GNUNET_OK to keep the connection open, |
2648 | * @param finger_map_index | 2331 | * #GNUNET_SYSERR to close it (signal serious error) |
2649 | * @param trail_peer_list | ||
2650 | * @param trail_length | ||
2651 | */ | 2332 | */ |
2652 | void | 2333 | static int |
2653 | GDS_NEIGHBOURS_send_trail_rejection_message(struct GNUNET_PeerIdentity *source_peer, | 2334 | handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, |
2654 | uint64_t finger_identity, | 2335 | const struct GNUNET_MessageHeader *message) |
2655 | struct GNUNET_PeerIdentity *congested_peer, | ||
2656 | const struct GNUNET_PeerIdentity *next_hop, | ||
2657 | unsigned int finger_map_index, | ||
2658 | struct GNUNET_PeerIdentity *trail_peer_list, | ||
2659 | unsigned int trail_length) | ||
2660 | { | 2336 | { |
2661 | struct PeerTrailRejectionMessage *trail_rejection; | 2337 | /* If you are the source, go back to the client file and there search for |
2662 | struct GNUNET_PeerIdentity *trail_list; | 2338 | the requesting client and send back the result. */ |
2663 | struct P2PPendingMessage *pending; | 2339 | struct PeerGetResultMessage *get_result; |
2664 | struct FriendInfo *target_friend; | 2340 | struct GNUNET_PeerIdentity *get_path; |
2341 | struct GNUNET_PeerIdentity *put_path; | ||
2342 | void *payload; | ||
2343 | size_t payload_size; | ||
2665 | size_t msize; | 2344 | size_t msize; |
2345 | unsigned int getlen; | ||
2346 | unsigned int putlen; | ||
2347 | int current_path_index; | ||
2666 | 2348 | ||
2667 | msize = sizeof (struct PeerTrailRejectionMessage); | 2349 | msize = ntohs (message->size); |
2350 | if (msize < sizeof (struct PeerGetResultMessage)) | ||
2351 | { | ||
2352 | GNUNET_break_op (0); | ||
2353 | return GNUNET_YES; | ||
2354 | } | ||
2668 | 2355 | ||
2669 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 2356 | get_result = (struct PeerGetResultMessage *)message; |
2670 | pending->importance = 0; /* FIXME */ | 2357 | getlen = ntohl (get_result->get_path_length); |
2671 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 2358 | putlen = ntohl (get_result->put_path_length); |
2672 | trail_rejection = (struct PeerTrailRejectionMessage *) &pending[1]; | ||
2673 | pending->msg = &trail_rejection->header; | ||
2674 | trail_rejection->header.size = htons (msize); | ||
2675 | trail_rejection->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); | ||
2676 | memcpy (&(trail_rejection->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | ||
2677 | memcpy (&(trail_rejection->congested_peer), congested_peer, sizeof (struct GNUNET_PeerIdentity)); | ||
2678 | memcpy (&(trail_rejection->finger_identity), &finger_identity, sizeof (uint64_t)); | ||
2679 | trail_rejection->finger_map_index = htonl(finger_map_index); | ||
2680 | trail_rejection->trail_length = htonl (trail_length); | ||
2681 | 2359 | ||
2682 | trail_list = (struct GNUNET_PeerIdentity *)&trail_rejection[1]; | 2360 | if ((msize < |
2683 | memcpy (trail_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 2361 | sizeof (struct PeerGetResultMessage) + |
2362 | getlen * sizeof (struct GNUNET_PeerIdentity) + | ||
2363 | putlen * sizeof (struct GNUNET_PeerIdentity)) || | ||
2364 | (getlen > | ||
2365 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity) || | ||
2366 | (putlen > | ||
2367 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))) | ||
2368 | { | ||
2369 | GNUNET_break_op (0); | ||
2370 | return GNUNET_YES; | ||
2371 | } | ||
2684 | 2372 | ||
2685 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2373 | get_path = (struct GNUNET_PeerIdentity *) &get_result[1]; |
2686 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | 2374 | payload = &get_path[getlen]; |
2687 | target_friend->pending_count++; | 2375 | payload_size = msize - (sizeof (struct PeerGetResultMessage) + |
2688 | process_friend_queue (target_friend); | 2376 | getlen * sizeof (struct GNUNET_PeerIdentity)); |
2377 | /* FIXME: Check if its correct or not. */ | ||
2378 | if (putlen > 0) | ||
2379 | put_path = &get_path[1]; | ||
2380 | |||
2381 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_path[0])))) | ||
2382 | { | ||
2383 | //GDS_CLIENTS_process_get_result(); | ||
2384 | GDS_CLIENTS_handle_reply (get_result->expiration_time, &(get_result->key), | ||
2385 | getlen, get_path, putlen, | ||
2386 | put_path, get_result->type, payload_size, payload); | ||
2387 | return GNUNET_YES; | ||
2388 | } | ||
2389 | else | ||
2390 | { | ||
2391 | struct GNUNET_PeerIdentity *next_hop; | ||
2392 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2393 | current_path_index = search_my_location (get_path); | ||
2394 | /* FIXME: First check if you are adding yourself to the get path or not. | ||
2395 | if yes then don't check if current_path_index == 0, if not then check | ||
2396 | and next_hop == source_peer. */ | ||
2397 | memcpy (next_hop, &get_path[current_path_index - 1], sizeof (struct GNUNET_PeerIdentity)); | ||
2398 | |||
2399 | GDS_NEIGHBOURS_send_get_result (get_result->expiration_time, &(get_result->key), | ||
2400 | putlen, put_path, | ||
2401 | get_result->type, payload_size,payload, | ||
2402 | get_path, getlen, | ||
2403 | next_hop, &(get_result->source_peer)); | ||
2404 | return GNUNET_YES; | ||
2405 | } | ||
2406 | return GNUNET_SYSERR; | ||
2689 | } | 2407 | } |
2690 | 2408 | ||
2691 | 2409 | ||
@@ -2694,25 +2412,25 @@ GDS_NEIGHBOURS_send_trail_rejection_message(struct GNUNET_PeerIdentity *source_p | |||
2694 | * @param cls closure | 2412 | * @param cls closure |
2695 | * @param message message | 2413 | * @param message message |
2696 | * @param peer peer identity this notification is about | 2414 | * @param peer peer identity this notification is about |
2697 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 2415 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
2698 | */ | 2416 | */ |
2699 | static int | 2417 | static int |
2700 | handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | 2418 | handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, |
2701 | const struct GNUNET_MessageHeader *message) | 2419 | const struct GNUNET_MessageHeader *message) |
2702 | { | 2420 | { |
2703 | struct PeerTrailSetupMessage *trail_setup; | 2421 | const struct PeerTrailSetupMessage *trail_setup; |
2704 | struct GNUNET_PeerIdentity *next_hop; | 2422 | struct GNUNET_PeerIdentity current_destination; |
2705 | struct FriendInfo *target_friend; | 2423 | struct GNUNET_PeerIdentity current_source; |
2706 | struct GNUNET_PeerIdentity *current_destination; | 2424 | struct GNUNET_PeerIdentity source; |
2425 | struct GNUNET_PeerIdentity *next_hop; | ||
2426 | struct GNUNET_PeerIdentity next_peer; | ||
2707 | struct GNUNET_PeerIdentity *trail_peer_list; | 2427 | struct GNUNET_PeerIdentity *trail_peer_list; |
2708 | enum current_destination_type current_dest_type; | 2428 | struct FriendInfo *target_friend; |
2709 | struct GNUNET_PeerIdentity *next_peer; | ||
2710 | unsigned int trail_length; | ||
2711 | uint32_t current_trail_index; | ||
2712 | unsigned int finger_map_index; | ||
2713 | uint64_t destination_finger_value; | 2429 | uint64_t destination_finger_value; |
2430 | uint32_t trail_length; | ||
2431 | uint32_t finger_map_index; | ||
2714 | size_t msize; | 2432 | size_t msize; |
2715 | 2433 | ||
2716 | msize = ntohs (message->size); | 2434 | msize = ntohs (message->size); |
2717 | if (msize < sizeof (struct PeerTrailSetupMessage)) | 2435 | if (msize < sizeof (struct PeerTrailSetupMessage)) |
2718 | { | 2436 | { |
@@ -2720,7 +2438,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2720 | return GNUNET_YES; | 2438 | return GNUNET_YES; |
2721 | } | 2439 | } |
2722 | 2440 | ||
2723 | trail_setup = (struct PeerTrailSetupMessage *) message; | 2441 | trail_setup = (const struct PeerTrailSetupMessage *) message; |
2724 | trail_length = ntohl (trail_setup->trail_length); | 2442 | trail_length = ntohl (trail_setup->trail_length); |
2725 | 2443 | ||
2726 | if ((msize < sizeof (struct PeerTrailSetupMessage) + | 2444 | if ((msize < sizeof (struct PeerTrailSetupMessage) + |
@@ -2732,122 +2450,79 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2732 | return GNUNET_YES; | 2450 | return GNUNET_YES; |
2733 | } | 2451 | } |
2734 | 2452 | ||
2735 | current_dest_type = ntohl (trail_setup->current_destination_type); | ||
2736 | finger_map_index = ntohl (trail_setup->finger_map_index); | ||
2737 | trail_peer_list = (struct GNUNET_PeerIdentity *)&trail_setup[1]; | 2453 | trail_peer_list = (struct GNUNET_PeerIdentity *)&trail_setup[1]; |
2738 | destination_finger_value = trail_setup->destination_finger; | 2454 | current_destination = trail_setup->current_destination; |
2739 | current_destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2455 | current_source = trail_setup->current_source; |
2740 | memcpy (current_destination, &(trail_setup->current_destination), sizeof (struct GNUNET_PeerIdentity)); | 2456 | source = trail_setup->source_peer; |
2741 | 2457 | finger_map_index = ntohl (trail_setup->finger_map_index); | |
2742 | /* TODO: | 2458 | destination_finger_value = ntohl (trail_setup->destination_finger); |
2743 | each peer maintains a list of trail fail list. there it stores an entry with | 2459 | |
2744 | source, finger identity it was trying, hop which rejected. it again call | 2460 | /* Check if you are part of the trail or current destination, and accordingly |
2745 | select_random_friend but does not consider me. and starts trail setup | 2461 | * find the next peer to send the message to. */ |
2746 | again. */ | 2462 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (¤t_destination, &my_identity))) |
2747 | if (GDS_ROUTING_size() > 1) | ||
2748 | { | ||
2749 | /* Setup the trail rejection message and send the message to peer. */ | ||
2750 | /* FIXME: you need to pass the trail, trail length and finger map index. */ | ||
2751 | GDS_NEIGHBOURS_send_trail_rejection_message (&(trail_setup->source_peer), | ||
2752 | trail_setup->destination_finger, | ||
2753 | &my_identity, peer, finger_map_index, | ||
2754 | trail_peer_list, trail_length); | ||
2755 | } | ||
2756 | /* Find the next hop to send the packet to. */ | ||
2757 | if (current_dest_type == FRIEND) | ||
2758 | { | ||
2759 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination), | ||
2760 | &my_identity))) | ||
2761 | { | ||
2762 | next_hop = find_successor (destination_finger_value, current_destination, &(current_dest_type)); | ||
2763 | } | ||
2764 | else | ||
2765 | return GNUNET_SYSERR; | ||
2766 | } | ||
2767 | else if (current_dest_type == FINGER) | ||
2768 | { | 2463 | { |
2769 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination), | 2464 | next_hop = GDS_ROUTING_search (¤t_source, ¤t_destination, peer); |
2770 | &my_identity))) | 2465 | /* OPTIMIZATION: do find_successor also and get a better path if possible. */ |
2771 | { | 2466 | if (next_hop == NULL) |
2772 | next_hop = GDS_ROUTING_search (&(trail_setup->current_source), | ||
2773 | &(trail_setup->current_destination), peer); | ||
2774 | /* As an optimization, find the successor from the find successor and | ||
2775 | compare both the ids to find the closest peer. */ | ||
2776 | } | ||
2777 | else | ||
2778 | { | 2467 | { |
2779 | next_hop = find_successor (destination_finger_value, current_destination, &(current_dest_type)); | 2468 | /* FIXME next_hop to NULL, |
2469 | * 1. statistics update, drop the message. | ||
2470 | 2. complain to sender with new message: trail lost */ | ||
2471 | return GNUNET_OK; | ||
2780 | } | 2472 | } |
2781 | } | 2473 | } |
2782 | 2474 | else | |
2783 | /* Add yourself to the trail list and increment the trail length. */ | ||
2784 | struct GNUNET_PeerIdentity *peer_list; | ||
2785 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length + 1)); | ||
2786 | if ( trail_length > 0) | ||
2787 | { | 2475 | { |
2788 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 2476 | next_hop = find_successor (destination_finger_value, ¤t_destination, ¤t_source); |
2789 | } | 2477 | } |
2790 | memcpy (&peer_list[trail_length], &my_identity, sizeof (struct GNUNET_PeerIdentity)); | 2478 | |
2479 | /* Now add yourself to the trail. */ | ||
2480 | struct GNUNET_PeerIdentity peer_list[trail_length + 1]; | ||
2481 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
2482 | peer_list[trail_length] = my_identity; | ||
2791 | trail_length++; | 2483 | trail_length++; |
2792 | 2484 | ||
2793 | if (current_dest_type == MY_ID || | 2485 | /* Check next_hop type and make the judgment what to do next. */ |
2794 | (0 == GNUNET_CRYPTO_cmp_peer_identity(next_hop, &(trail_setup->source_peer)))) | 2486 | if (NULL == next_hop) /* This means I am the final destination */ |
2795 | { | 2487 | { |
2796 | struct GNUNET_PeerIdentity *source_peer; | 2488 | if (trail_length == 1) |
2797 | source_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2798 | memcpy (source_peer, &(trail_setup->source_peer), sizeof (struct GNUNET_PeerIdentity)); | ||
2799 | |||
2800 | current_trail_index = trail_length - 1; | ||
2801 | next_peer= GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2802 | if (current_trail_index == 0) | ||
2803 | { | 2489 | { |
2804 | memcpy (next_peer, &(trail_setup->source_peer), sizeof (struct GNUNET_PeerIdentity)); | 2490 | memcpy (&next_peer, &source, sizeof (struct GNUNET_PeerIdentity)); |
2805 | } | 2491 | } |
2806 | else | 2492 | else |
2807 | { | 2493 | { |
2808 | memcpy (next_peer, &trail_peer_list[current_trail_index-1], sizeof (struct GNUNET_PeerIdentity)); | 2494 | memcpy (&next_peer, &trail_peer_list[trail_length-2], sizeof (struct GNUNET_PeerIdentity)); |
2809 | } | 2495 | } |
2810 | 2496 | ||
2811 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); | 2497 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_peer); |
2812 | GNUNET_free (next_peer); | 2498 | |
2813 | 2499 | /* FIXME: URGENT change it to handle the change in current_finger_index. | |
2814 | if (0 == trail_setup->finger_map_index) | 2500 | compare to your own predecessor */ |
2501 | if (compare_predecessor (&source) /* ! HAVE A PREDECESSOR || (source_peer closer than existing PREDECESOR) */) | ||
2815 | { | 2502 | { |
2816 | struct GNUNET_PeerIdentity *new_trail_list; | 2503 | struct GNUNET_PeerIdentity *new_trail_list; |
2817 | new_trail_list = invert_trail_list (source_peer, peer_list, trail_length); | 2504 | new_trail_list = invert_trail_list (&source, peer_list, trail_length); |
2818 | finger_table_add (source_peer, new_trail_list, trail_length, 1); | 2505 | finger_table_add (&source, new_trail_list, trail_length, PREDECESSOR_FINGER_ID); |
2819 | } | 2506 | } |
2820 | 2507 | ||
2821 | GDS_NEIGHBOURS_send_trail_setup_result (&(trail_setup->source_peer), | 2508 | GDS_NEIGHBOURS_send_trail_setup_result (&source, |
2822 | &(my_identity), | 2509 | &(my_identity), |
2823 | target_friend, trail_length, | 2510 | target_friend, trail_length, |
2824 | peer_list, current_trail_index, | 2511 | peer_list, |
2825 | finger_map_index); | 2512 | finger_map_index); |
2826 | 2513 | ||
2827 | return GNUNET_YES; | 2514 | return GNUNET_YES; |
2828 | } | 2515 | } |
2829 | else | 2516 | else |
2830 | { | 2517 | { |
2831 | struct GNUNET_PeerIdentity *current_source; | ||
2832 | current_source = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2833 | if (current_dest_type == FINGER) | ||
2834 | { | ||
2835 | memcpy (current_source, &my_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2836 | } | ||
2837 | else | ||
2838 | current_source = NULL; | ||
2839 | |||
2840 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2518 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2841 | /* FiXME: Is it correct to use null value for current source. */ | 2519 | GDS_NEIGHBOURS_send_trail_setup (&source, |
2842 | GDS_NEIGHBOURS_send_trail_setup (&(trail_setup->source_peer), | 2520 | destination_finger_value, |
2843 | trail_setup->destination_finger, | 2521 | ¤t_destination, ¤t_source, |
2844 | current_destination,current_source, | ||
2845 | target_friend, trail_length, peer_list, | 2522 | target_friend, trail_length, peer_list, |
2846 | finger_map_index, current_dest_type); | 2523 | finger_map_index); |
2847 | 2524 | return GNUNET_YES; | |
2848 | return GNUNET_YES; | ||
2849 | } | 2525 | } |
2850 | |||
2851 | return GNUNET_SYSERR; | 2526 | return GNUNET_SYSERR; |
2852 | } | 2527 | } |
2853 | 2528 | ||
@@ -2892,7 +2567,6 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2892 | return GNUNET_YES; | 2567 | return GNUNET_YES; |
2893 | } | 2568 | } |
2894 | 2569 | ||
2895 | current_trail_index = ntohl (trail_result->current_index); | ||
2896 | finger_map_index = ntohl (trail_result->finger_map_index); | 2570 | finger_map_index = ntohl (trail_result->finger_map_index); |
2897 | 2571 | ||
2898 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1]; | 2572 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1]; |
@@ -2909,7 +2583,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2909 | else | 2583 | else |
2910 | { | 2584 | { |
2911 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2585 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2912 | 2586 | current_trail_index = search_my_location (trail_peer_list); | |
2913 | current_trail_index = current_trail_index - 1; | 2587 | current_trail_index = current_trail_index - 1; |
2914 | if (current_trail_index == 0) | 2588 | if (current_trail_index == 0) |
2915 | { | 2589 | { |
@@ -2920,7 +2594,6 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2920 | memcpy (next_hop, &(trail_peer_list[current_trail_index-1]),sizeof (struct GNUNET_PeerIdentity)); | 2594 | memcpy (next_hop, &(trail_peer_list[current_trail_index-1]),sizeof (struct GNUNET_PeerIdentity)); |
2921 | } | 2595 | } |
2922 | 2596 | ||
2923 | |||
2924 | /* If trail length = 2, it means that destination and source peer are friends | 2597 | /* If trail length = 2, it means that destination and source peer are friends |
2925 | Then don't add an entry. */ | 2598 | Then don't add an entry. */ |
2926 | if (trail_length != 2) | 2599 | if (trail_length != 2) |
@@ -2932,7 +2605,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2932 | GDS_NEIGHBOURS_send_trail_setup_result (&(trail_result->destination_peer), | 2605 | GDS_NEIGHBOURS_send_trail_setup_result (&(trail_result->destination_peer), |
2933 | &(trail_result->finger_identity), | 2606 | &(trail_result->finger_identity), |
2934 | target_friend, trail_length, | 2607 | target_friend, trail_length, |
2935 | trail_peer_list,current_trail_index, | 2608 | trail_peer_list, |
2936 | finger_map_index); | 2609 | finger_map_index); |
2937 | return GNUNET_YES; | 2610 | return GNUNET_YES; |
2938 | } | 2611 | } |
@@ -2990,7 +2663,6 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2990 | struct GNUNET_PeerIdentity *next_hop; | 2663 | struct GNUNET_PeerIdentity *next_hop; |
2991 | struct GNUNET_PeerIdentity *source_peer; | 2664 | struct GNUNET_PeerIdentity *source_peer; |
2992 | unsigned int trail_length; | 2665 | unsigned int trail_length; |
2993 | unsigned int current_trail_index; | ||
2994 | size_t msize; | 2666 | size_t msize; |
2995 | 2667 | ||
2996 | msize = ntohs (message->size); | 2668 | msize = ntohs (message->size); |
@@ -3011,7 +2683,6 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
3011 | return GNUNET_YES; | 2683 | return GNUNET_YES; |
3012 | } | 2684 | } |
3013 | 2685 | ||
3014 | current_trail_index = ntohl (vsm->current_trail_index); | ||
3015 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; | 2686 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; |
3016 | source_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2687 | source_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
3017 | memcpy (source_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity)); | 2688 | memcpy (source_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity)); |
@@ -3021,12 +2692,14 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
3021 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor),&my_identity))) | 2692 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor),&my_identity))) |
3022 | { | 2693 | { |
3023 | struct FingerInfo *my_predecessor; | 2694 | struct FingerInfo *my_predecessor; |
3024 | current_trail_index = trail_length - 1; | 2695 | if (trail_length == 1) |
3025 | if (current_trail_index == 0) | ||
3026 | memcpy (next_hop, source_peer, sizeof (struct GNUNET_PeerIdentity)); | 2696 | memcpy (next_hop, source_peer, sizeof (struct GNUNET_PeerIdentity)); |
3027 | else | 2697 | else |
2698 | { | ||
2699 | int current_trail_index; | ||
2700 | current_trail_index = search_my_location (trail_peer_list); | ||
3028 | memcpy (next_hop, &trail_peer_list[current_trail_index-1], sizeof (struct GNUNET_PeerIdentity)); | 2701 | memcpy (next_hop, &trail_peer_list[current_trail_index-1], sizeof (struct GNUNET_PeerIdentity)); |
3029 | 2702 | } | |
3030 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2703 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
3031 | GNUNET_free (next_hop); | 2704 | GNUNET_free (next_hop); |
3032 | 2705 | ||
@@ -3039,8 +2712,7 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
3039 | &(my_predecessor->finger_identity), | 2712 | &(my_predecessor->finger_identity), |
3040 | target_friend, | 2713 | target_friend, |
3041 | trail_peer_list, | 2714 | trail_peer_list, |
3042 | trail_length, | 2715 | trail_length); |
3043 | current_trail_index); | ||
3044 | } | 2716 | } |
3045 | else | 2717 | else |
3046 | { | 2718 | { |
@@ -3067,169 +2739,165 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
3067 | &(my_predecessor->finger_identity), | 2739 | &(my_predecessor->finger_identity), |
3068 | target_friend, | 2740 | target_friend, |
3069 | new_successor_trail, | 2741 | new_successor_trail, |
3070 | new_trail_length, | 2742 | new_trail_length); |
3071 | current_trail_index); | ||
3072 | } | 2743 | } |
3073 | 2744 | ||
3074 | } | 2745 | } |
3075 | else | 2746 | else |
3076 | { | 2747 | { |
3077 | current_trail_index = current_trail_index + 1; | 2748 | unsigned int current_trail_index; |
2749 | current_trail_index = search_my_location (trail_peer_list); | ||
3078 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 2750 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
3079 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2751 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
3080 | GNUNET_free (next_hop); | 2752 | GNUNET_free (next_hop); |
3081 | 2753 | ||
3082 | GDS_NEIGHBOURS_send_verify_successor (source_peer, &(vsm->successor),target_friend, | 2754 | GDS_NEIGHBOURS_send_verify_successor (source_peer, &(vsm->successor),target_friend, |
3083 | trail_peer_list, trail_length, current_trail_index); | 2755 | trail_peer_list, trail_length); |
3084 | } | 2756 | } |
3085 | return GNUNET_YES; | 2757 | return GNUNET_YES; |
3086 | } | 2758 | } |
3087 | 2759 | ||
3088 | 2760 | ||
3089 | /** | 2761 | /** |
3090 | * Core handle for p2p notify new successor messages. | 2762 | * Core handle for p2p verify successor result messages. |
3091 | * @param cls closure | 2763 | * @param cls closure |
3092 | * @param message message | 2764 | * @param message message |
3093 | * @param peer peer identity this notification is about | 2765 | * @param peer peer identity this notification is about |
3094 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 2766 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
3095 | */ | 2767 | */ |
3096 | static int | 2768 | static int |
3097 | handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer, | 2769 | handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdentity *peer, |
3098 | const struct GNUNET_MessageHeader *message) | 2770 | const struct GNUNET_MessageHeader *message) |
3099 | { | 2771 | { |
3100 | struct PeerNotifyNewSuccessorMessage *nsm; | 2772 | struct PeerVerifySuccessorResultMessage *vsrm; |
2773 | struct FriendInfo *target_friend; | ||
3101 | struct GNUNET_PeerIdentity *trail_peer_list; | 2774 | struct GNUNET_PeerIdentity *trail_peer_list; |
2775 | struct GNUNET_PeerIdentity *next_hop; | ||
2776 | unsigned int trail_length; | ||
3102 | unsigned int current_trail_index; | 2777 | unsigned int current_trail_index; |
3103 | size_t msize; | 2778 | size_t msize; |
3104 | unsigned int trail_length; | ||
3105 | 2779 | ||
3106 | msize = ntohs (message->size); | 2780 | msize = ntohs (message->size); |
3107 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) | 2781 | if (msize < sizeof (struct PeerVerifySuccessorResultMessage)) |
3108 | { | 2782 | { |
3109 | GNUNET_break_op (0); | 2783 | GNUNET_break_op (0); |
3110 | return GNUNET_YES; | 2784 | return GNUNET_YES; |
3111 | } | 2785 | } |
3112 | 2786 | ||
3113 | nsm = (struct PeerNotifyNewSuccessorMessage *) message; | 2787 | vsrm = (struct PeerVerifySuccessorResultMessage *) message; |
3114 | trail_length = ntohl (nsm->trail_length); | 2788 | trail_length = ntohl (vsrm->trail_length); |
3115 | 2789 | ||
3116 | if ((msize < sizeof (struct PeerNotifyNewSuccessorMessage) + | 2790 | if ((msize < |
3117 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || | 2791 | sizeof (struct PeerVerifySuccessorResultMessage) + |
3118 | (trail_length > | 2792 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || |
2793 | (trail_length > | ||
3119 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | 2794 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) |
3120 | { | 2795 | { |
3121 | GNUNET_break_op (0); | 2796 | GNUNET_break_op (0); |
3122 | return GNUNET_YES; | 2797 | return GNUNET_YES; |
3123 | } | 2798 | } |
3124 | 2799 | ||
3125 | current_trail_index = ntohl (nsm->current_index); | 2800 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsrm[1]; |
3126 | trail_peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; | 2801 | |
3127 | 2802 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->destination_peer), &(my_identity)))) | |
3128 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer), &my_identity))) | ||
3129 | { | 2803 | { |
3130 | struct GNUNET_PeerIdentity *new_trail; | 2804 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->my_predecessor), &(my_identity)))) |
3131 | new_trail = invert_trail_list (&(nsm->source_peer), trail_peer_list, trail_length); | 2805 | { |
3132 | finger_table_add (&(nsm->source_peer), new_trail, trail_length, 1); | 2806 | finger_table_add (&(vsrm->my_predecessor), trail_peer_list, trail_length, 0); |
3133 | return GNUNET_YES; | 2807 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2808 | memcpy (next_hop, &trail_peer_list[0], sizeof (struct GNUNET_PeerIdentity)); | ||
2809 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | ||
2810 | GNUNET_free (next_hop); | ||
2811 | |||
2812 | GDS_NEIGHBOURS_send_notify_new_successor (&my_identity, &(vsrm->my_predecessor), | ||
2813 | target_friend, trail_peer_list, | ||
2814 | trail_length); | ||
2815 | } | ||
3134 | } | 2816 | } |
3135 | else | 2817 | else |
3136 | { | 2818 | { |
3137 | struct FriendInfo *target_friend; | ||
3138 | struct GNUNET_PeerIdentity *next_hop; | ||
3139 | |||
3140 | target_friend = GNUNET_malloc (sizeof (struct FriendInfo)); | ||
3141 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2819 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
3142 | 2820 | current_trail_index = search_my_location (trail_peer_list); | |
3143 | current_trail_index = current_trail_index + 1; | 2821 | if (current_trail_index == 1) |
3144 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 2822 | memcpy (next_hop, &(vsrm->destination_peer), sizeof (struct GNUNET_PeerIdentity)); |
2823 | else | ||
2824 | memcpy (next_hop, &trail_peer_list[current_trail_index-1], sizeof (struct GNUNET_PeerIdentity)); | ||
3145 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2825 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
3146 | GNUNET_free (next_hop); | 2826 | GNUNET_free (next_hop); |
3147 | 2827 | ||
3148 | GDS_NEIGHBOURS_send_notify_new_successor (&(nsm->source_peer), | 2828 | GDS_NEIGHBOURS_send_verify_successor_result (&(vsrm->destination_peer), |
3149 | &(nsm->destination_peer), | 2829 | &(vsrm->source_successor), |
3150 | target_friend, trail_peer_list, | 2830 | &(vsrm->my_predecessor), |
3151 | trail_length, current_trail_index); | 2831 | target_friend, |
2832 | trail_peer_list, | ||
2833 | trail_length); | ||
3152 | } | 2834 | } |
3153 | return GNUNET_YES; | 2835 | return GNUNET_YES; |
3154 | } | 2836 | } |
3155 | 2837 | ||
3156 | 2838 | ||
3157 | /** | 2839 | /** |
3158 | * Core handle for p2p verify successor result messages. | 2840 | * Core handle for p2p notify new successor messages. |
3159 | * @param cls closure | 2841 | * @param cls closure |
3160 | * @param message message | 2842 | * @param message message |
3161 | * @param peer peer identity this notification is about | 2843 | * @param peer peer identity this notification is about |
3162 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 2844 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
3163 | */ | 2845 | */ |
3164 | static int | 2846 | static int |
3165 | handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdentity *peer, | 2847 | handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer, |
3166 | const struct GNUNET_MessageHeader *message) | 2848 | const struct GNUNET_MessageHeader *message) |
3167 | { | 2849 | { |
3168 | struct PeerVerifySuccessorResultMessage *vsrm; | 2850 | struct PeerNotifyNewSuccessorMessage *nsm; |
3169 | struct FriendInfo *target_friend; | ||
3170 | struct GNUNET_PeerIdentity *trail_peer_list; | 2851 | struct GNUNET_PeerIdentity *trail_peer_list; |
3171 | struct GNUNET_PeerIdentity *next_hop; | ||
3172 | unsigned int trail_length; | ||
3173 | unsigned int current_trail_index; | 2852 | unsigned int current_trail_index; |
3174 | size_t msize; | 2853 | size_t msize; |
2854 | unsigned int trail_length; | ||
3175 | 2855 | ||
3176 | msize = ntohs (message->size); | 2856 | msize = ntohs (message->size); |
3177 | if (msize < sizeof (struct PeerVerifySuccessorResultMessage)) | 2857 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) |
3178 | { | 2858 | { |
3179 | GNUNET_break_op (0); | 2859 | GNUNET_break_op (0); |
3180 | return GNUNET_YES; | 2860 | return GNUNET_YES; |
3181 | } | 2861 | } |
3182 | 2862 | ||
3183 | vsrm = (struct PeerVerifySuccessorResultMessage *) message; | 2863 | nsm = (struct PeerNotifyNewSuccessorMessage *) message; |
3184 | trail_length = ntohl (vsrm->trail_length); | 2864 | trail_length = ntohl (nsm->trail_length); |
3185 | 2865 | ||
3186 | if ((msize < | 2866 | if ((msize < sizeof (struct PeerNotifyNewSuccessorMessage) + |
3187 | sizeof (struct PeerVerifySuccessorResultMessage) + | 2867 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || |
3188 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || | 2868 | (trail_length > |
3189 | (trail_length > | ||
3190 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | 2869 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) |
3191 | { | 2870 | { |
3192 | GNUNET_break_op (0); | 2871 | GNUNET_break_op (0); |
3193 | return GNUNET_YES; | 2872 | return GNUNET_YES; |
3194 | } | 2873 | } |
3195 | 2874 | ||
3196 | current_trail_index = ntohl (vsrm->current_index); | 2875 | trail_peer_list = (struct GNUNET_PeerIdentity *) &nsm[1]; |
3197 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsrm[1]; | 2876 | |
3198 | 2877 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer), &my_identity))) | |
3199 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->destination_peer), &(my_identity)))) | ||
3200 | { | 2878 | { |
3201 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->my_predecessor), &(my_identity)))) | 2879 | struct GNUNET_PeerIdentity *new_trail; |
3202 | { | 2880 | new_trail = invert_trail_list (&(nsm->source_peer), trail_peer_list, trail_length); |
3203 | finger_table_add (&(vsrm->my_predecessor), trail_peer_list, trail_length, 0); | 2881 | finger_table_add (&(nsm->source_peer), new_trail, trail_length, 1); |
3204 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2882 | return GNUNET_YES; |
3205 | memcpy (next_hop, &trail_peer_list[0], sizeof (struct GNUNET_PeerIdentity)); | ||
3206 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | ||
3207 | current_trail_index = 0; | ||
3208 | GNUNET_free (next_hop); | ||
3209 | |||
3210 | GDS_NEIGHBOURS_send_notify_new_successor (&my_identity, &(vsrm->my_predecessor), | ||
3211 | target_friend, trail_peer_list, | ||
3212 | trail_length, current_trail_index); | ||
3213 | } | ||
3214 | } | 2883 | } |
3215 | else | 2884 | else |
3216 | { | 2885 | { |
2886 | struct FriendInfo *target_friend; | ||
2887 | struct GNUNET_PeerIdentity *next_hop; | ||
2888 | |||
2889 | target_friend = GNUNET_malloc (sizeof (struct FriendInfo)); | ||
3217 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2890 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
3218 | current_trail_index = current_trail_index - 1; | 2891 | |
3219 | if (current_trail_index == 0) | 2892 | current_trail_index = search_my_location (trail_peer_list); |
3220 | memcpy (next_hop, &(vsrm->destination_peer), sizeof (struct GNUNET_PeerIdentity)); | 2893 | memcpy (next_hop, &trail_peer_list[current_trail_index+1], sizeof (struct GNUNET_PeerIdentity)); |
3221 | else | ||
3222 | memcpy (next_hop, &trail_peer_list[current_trail_index-1], sizeof (struct GNUNET_PeerIdentity)); | ||
3223 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2894 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
3224 | GNUNET_free (next_hop); | 2895 | GNUNET_free (next_hop); |
3225 | 2896 | ||
3226 | GDS_NEIGHBOURS_send_verify_successor_result (&(vsrm->destination_peer), | 2897 | GDS_NEIGHBOURS_send_notify_new_successor (&(nsm->source_peer), |
3227 | &(vsrm->source_successor), | 2898 | &(nsm->destination_peer), |
3228 | &(vsrm->my_predecessor), | 2899 | target_friend, trail_peer_list, |
3229 | target_friend, | 2900 | trail_length); |
3230 | trail_peer_list, | ||
3231 | trail_length, | ||
3232 | current_trail_index); | ||
3233 | } | 2901 | } |
3234 | return GNUNET_YES; | 2902 | return GNUNET_YES; |
3235 | } | 2903 | } |
@@ -3278,32 +2946,186 @@ int handle_dht_p2p_trail_rejection(void *cls, const struct GNUNET_PeerIdentity * | |||
3278 | 2946 | ||
3279 | if(NULL != target_friend) | 2947 | if(NULL != target_friend) |
3280 | { | 2948 | { |
3281 | /* FIXME: Here I am passing NULL for current source, is it correct? | ||
3282 | also, we set the current source only if current_destination_type | ||
3283 | is finger. */ | ||
3284 | GDS_NEIGHBOURS_send_trail_setup (&(trail_fail->source_peer), | 2949 | GDS_NEIGHBOURS_send_trail_setup (&(trail_fail->source_peer), |
3285 | trail_fail->destination_finger_value, | 2950 | trail_fail->destination_finger_value, |
3286 | &(target_friend->id), | 2951 | &(target_friend->id), |
3287 | NULL, target_friend, ntohl (trail_rejection->trail_length), | 2952 | NULL, target_friend, ntohl (trail_rejection->trail_length), |
3288 | trail_peer_list, | 2953 | trail_peer_list, |
3289 | finger_map_index, FRIEND); | 2954 | finger_map_index); |
3290 | return GNUNET_YES; | 2955 | return GNUNET_YES; |
3291 | } | 2956 | } |
3292 | return GNUNET_SYSERR; | 2957 | return GNUNET_SYSERR; |
3293 | } | 2958 | } |
3294 | 2959 | ||
2960 | #if 0 | ||
2961 | /** | ||
2962 | * | ||
2963 | * @param cls | ||
2964 | * @param key | ||
2965 | * @param value | ||
2966 | * @return | ||
2967 | */ | ||
2968 | static int | ||
2969 | remove_matching_finger (void *cls, | ||
2970 | const struct GNUNET_PeerIdentity *key, | ||
2971 | void *value) | ||
2972 | { | ||
2973 | struct FingerInfo *remove_finger = value; | ||
2974 | const struct GNUNET_PeerIdentity *disconnected_peer = cls; | ||
2975 | |||
2976 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&remove_finger->head->peer, disconnected_peer)) | ||
2977 | { | ||
2978 | GNUNET_assert (GNUNET_YES == | ||
2979 | GNUNET_CONTAINER_multipeermap_remove (finger_peermap, | ||
2980 | key, | ||
2981 | remove_finger)); | ||
2982 | /* FIXME: free_finger(remove_finger); Call this function at finger_table_add, | ||
2983 | *when you replace an existing entry */ | ||
2984 | } | ||
2985 | return GNUNET_YES; | ||
2986 | } | ||
2987 | #endif | ||
2988 | |||
2989 | /** | ||
2990 | * Method called whenever a peer disconnects. | ||
2991 | * | ||
2992 | * @param cls closure | ||
2993 | * @param peer peer identity this notification is about | ||
2994 | */ | ||
2995 | static void | ||
2996 | handle_core_disconnect (void *cls, | ||
2997 | const struct GNUNET_PeerIdentity *peer) | ||
2998 | { | ||
2999 | #if 0 | ||
3000 | struct FriendInfo *remove_friend; | ||
3001 | //struct FingerInfo *remove_finger; | ||
3002 | // struct GNUNET_PeerIdentity key_ret; | ||
3003 | //struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | ||
3004 | //struct TrailPeerList *iterator; | ||
3005 | //struct GNUNET_PeerIdentity *finger_identity; | ||
3006 | //int finger_index; | ||
3007 | |||
3008 | /* Check for self message. */ | ||
3009 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | ||
3010 | return; | ||
3011 | |||
3012 | /* Search for peer to remove in your friend_peermap. */ | ||
3013 | remove_friend = | ||
3014 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); | ||
3015 | |||
3016 | if (NULL == remove_friend) | ||
3017 | { | ||
3018 | GNUNET_break (0); | ||
3019 | return; | ||
3020 | } | ||
3021 | //FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__); | ||
3022 | |||
3023 | GNUNET_CONTAINER_multipeermap_iterate (finger_peermap, | ||
3024 | &remove_matching_finger, peer); | ||
3025 | /* Remove the friend from friend_peermap. */ | ||
3026 | GNUNET_assert (GNUNET_YES == | ||
3027 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, | ||
3028 | peer, | ||
3029 | remove_friend)); | ||
3030 | |||
3031 | if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) | ||
3032 | return; | ||
3033 | |||
3034 | if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task) | ||
3035 | { | ||
3036 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); | ||
3037 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; | ||
3038 | } | ||
3039 | else | ||
3040 | GNUNET_break (0); | ||
3041 | |||
3042 | if (GNUNET_SCHEDULER_NO_TASK != verify_successor) | ||
3043 | { | ||
3044 | GNUNET_SCHEDULER_cancel (verify_successor); | ||
3045 | verify_successor = GNUNET_SCHEDULER_NO_TASK; | ||
3046 | } | ||
3047 | /* FIXME: garbage collect routing table, and notify the failed trails about | ||
3048 | trail lost. | ||
3049 | */ | ||
3050 | #endif | ||
3051 | } | ||
3052 | |||
3053 | |||
3054 | /** | ||
3055 | * Method called whenever a peer connects. | ||
3056 | * | ||
3057 | * @param cls closure | ||
3058 | * @param peer_identity peer identity this notification is about | ||
3059 | */ | ||
3060 | static void | ||
3061 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | ||
3062 | { | ||
3063 | struct FriendInfo *friend; | ||
3064 | |||
3065 | /* Check for connect to self message */ | ||
3066 | if (0 == memcmp (&my_identity, peer_identity, sizeof (struct GNUNET_PeerIdentity))) | ||
3067 | return; | ||
3068 | |||
3069 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to %s\n", GNUNET_i2s (peer_identity)); | ||
3070 | |||
3071 | /* If peer already exists in our friend_peermap, then exit. */ | ||
3072 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (friend_peermap, peer_identity)) | ||
3073 | { | ||
3074 | GNUNET_break (0); | ||
3075 | return; | ||
3076 | } | ||
3077 | /* FIXME: Use statistics at places where you think such a conditions are very | ||
3078 | rare. Then use statistics to make sure that it is indeed rare but if not | ||
3079 | rare then hanlde it differently.*/ | ||
3080 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), 1, | ||
3081 | GNUNET_NO); | ||
3082 | |||
3083 | friend = GNUNET_new (struct FriendInfo); | ||
3084 | friend->id = *peer_identity; | ||
3085 | |||
3086 | GNUNET_assert (GNUNET_OK == | ||
3087 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, | ||
3088 | peer_identity, friend, | ||
3089 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
3090 | |||
3091 | /* got a first connection, good time to start with FIND FINGER TRAIL requests... */ | ||
3092 | if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) | ||
3093 | find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL); | ||
3094 | } | ||
3095 | |||
3096 | |||
3097 | /** | ||
3098 | * To be called on core init/fail. | ||
3099 | * | ||
3100 | * @param cls service closure | ||
3101 | * @param identity the public identity of this peer | ||
3102 | */ | ||
3103 | static void | ||
3104 | core_init (void *cls, | ||
3105 | const struct GNUNET_PeerIdentity *identity) | ||
3106 | { | ||
3107 | my_identity = *identity; | ||
3108 | |||
3109 | /* SUPU TEST CODE */ | ||
3110 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
3111 | _("\nSUPU %s, %s, %d,my_identity = %s"), | ||
3112 | __FILE__, __func__, __LINE__, GNUNET_i2s (&my_identity)); | ||
3113 | /* SUPU TEST CODE ENDS */ | ||
3114 | |||
3115 | } | ||
3116 | |||
3295 | 3117 | ||
3296 | /** | 3118 | /** |
3297 | * Initialize neighbours subsystem. | 3119 | * Initialize neighbours subsystem. |
3298 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 3120 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
3299 | */ | 3121 | */ |
3300 | int | 3122 | int |
3301 | GDS_NEIGHBOURS_init() | 3123 | GDS_NEIGHBOURS_init() |
3302 | { | 3124 | { |
3303 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { | 3125 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { |
3304 | {&handle_dht_p2p_get, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, 0}, | ||
3305 | {&handle_dht_p2p_get_result, GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT, 0}, | ||
3306 | {&handle_dht_p2p_put, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, 0}, | 3126 | {&handle_dht_p2p_put, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, 0}, |
3127 | {&handle_dht_p2p_get, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, 0}, | ||
3128 | {&handle_dht_p2p_get_result, GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT, 0}, | ||
3307 | {&handle_dht_p2p_trail_setup, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP, 0}, | 3129 | {&handle_dht_p2p_trail_setup, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP, 0}, |
3308 | {&handle_dht_p2p_trail_setup_result, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT, 0}, | 3130 | {&handle_dht_p2p_trail_setup_result, GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT, 0}, |
3309 | {&handle_dht_p2p_verify_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR, 0}, | 3131 | {&handle_dht_p2p_verify_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR, 0}, |
@@ -3319,11 +3141,16 @@ GDS_NEIGHBOURS_init() | |||
3319 | GNUNET_NO, core_handlers); | 3141 | GNUNET_NO, core_handlers); |
3320 | if (NULL == core_api) | 3142 | if (NULL == core_api) |
3321 | return GNUNET_SYSERR; | 3143 | return GNUNET_SYSERR; |
3322 | 3144 | ||
3145 | /* Initialize the current index in the finger map. */ | ||
3146 | current_finger_index = PREDECESSOR_FINGER_ID; | ||
3147 | |||
3323 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | 3148 | friend_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); |
3324 | finger_peermap = GNUNET_CONTAINER_multipeermap_create (MAX_FINGERS, GNUNET_NO); | 3149 | finger_peermap = GNUNET_CONTAINER_multipeermap_create (MAX_FINGERS * 4/3, GNUNET_NO); |
3325 | /* FIXME: Not sure if this value is correct for this data structure. */ | 3150 | /* FIXME: Not sure if this value is correct for this data structure. also |
3326 | failed_trail_list = GNUNET_CONTAINER_multipeermap_create (LINK_THRESHOLD, GNUNET_NO); | 3151 | * not sure if we actually need any such data structure. Once done with other functions, |
3152 | * will revisit this part. */ | ||
3153 | failed_trail_list = GNUNET_CONTAINER_multipeermap_create (LINK_THRESHOLD * 4/3, GNUNET_NO); | ||
3327 | return GNUNET_OK; | 3154 | return GNUNET_OK; |
3328 | } | 3155 | } |
3329 | 3156 | ||
@@ -3348,28 +3175,38 @@ GDS_NEIGHBOURS_done () | |||
3348 | GNUNET_CONTAINER_multipeermap_destroy (finger_peermap); | 3175 | GNUNET_CONTAINER_multipeermap_destroy (finger_peermap); |
3349 | finger_peermap = NULL; | 3176 | finger_peermap = NULL; |
3350 | 3177 | ||
3178 | /* FIXME: Here I have added GNUNET_break(0) as ideally if friend_peermap | ||
3179 | is already zero, then we really don't need to cancel it again. If this | ||
3180 | condition happens it mean we might have missed some corner case. */ | ||
3351 | if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task) | 3181 | if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task) |
3352 | { | 3182 | { |
3183 | GNUNET_break (0); | ||
3353 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); | 3184 | GNUNET_SCHEDULER_cancel (find_finger_trail_task); |
3354 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; | 3185 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; |
3355 | } | 3186 | } |
3356 | 3187 | ||
3188 | /* FIXME: when do you cancel verify successor irrespective of this part | ||
3189 | of code. If no where else, then there should not be GNUNET_break (0) as it | ||
3190 | is right to call it here. Also, leave it here for time being and in case | ||
3191 | you always encounter this break, it means it is nor required. remove it then. */ | ||
3357 | if (GNUNET_SCHEDULER_NO_TASK != verify_successor) | 3192 | if (GNUNET_SCHEDULER_NO_TASK != verify_successor) |
3358 | { | 3193 | { |
3194 | GNUNET_break (0); | ||
3359 | GNUNET_SCHEDULER_cancel (verify_successor); | 3195 | GNUNET_SCHEDULER_cancel (verify_successor); |
3360 | verify_successor = GNUNET_SCHEDULER_NO_TASK; | 3196 | verify_successor = GNUNET_SCHEDULER_NO_TASK; |
3361 | } | 3197 | } |
3362 | |||
3363 | } | 3198 | } |
3364 | 3199 | ||
3365 | 3200 | ||
3366 | /** | 3201 | /** |
3367 | * Get the ID of the local node. | 3202 | * FIXME: I want to remove const but at the moment its giving error |
3203 | * in client file. | ||
3204 | * Get my identity | ||
3368 | * | 3205 | * |
3369 | * @return identity of the local node | 3206 | * @return my identity |
3370 | */ | 3207 | */ |
3371 | struct GNUNET_PeerIdentity * | 3208 | struct GNUNET_PeerIdentity * |
3372 | GDS_NEIGHBOURS_get_id () | 3209 | GDS_NEIGHBOURS_get_my_id (void) |
3373 | { | 3210 | { |
3374 | return &my_identity; | 3211 | return &my_identity; |
3375 | } | 3212 | } |
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h index 9ca2906ea..5f7aa422d 100644 --- a/src/dht/gnunet-service-xdht_neighbours.h +++ b/src/dht/gnunet-service-xdht_neighbours.h | |||
@@ -21,120 +21,100 @@ | |||
21 | /** | 21 | /** |
22 | * @file dht/gnunet-service-xdht_neighbours.h | 22 | * @file dht/gnunet-service-xdht_neighbours.h |
23 | * @brief GNUnet DHT routing code | 23 | * @brief GNUnet DHT routing code |
24 | * @author Christian Grothoff | 24 | * @author Supriti Singh |
25 | * @author Nathan Evans | ||
26 | */ | 25 | */ |
26 | |||
27 | #ifndef GNUNET_SERVICE_XDHT_NEIGHBOURS_H | 27 | #ifndef GNUNET_SERVICE_XDHT_NEIGHBOURS_H |
28 | #define GNUNET_SERVICE_XDHT_NEIGHBOURS_H | 28 | #define GNUNET_SERVICE_XDHT_NEIGHBOURS_H |
29 | 29 | ||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_block_lib.h" | 31 | #include "gnunet_block_lib.h" |
32 | #include "gnunet_dht_service.h" | 32 | #include "gnunet_xdht_service.h" |
33 | 33 | ||
34 | /** | 34 | |
35 | * FIXME: Change the comment to explain about usage of this in find successor. | 35 | /** FIXME: by default I keep current_source, and destination as my own id. |
36 | * Field in trail setup message to understand if the message is sent to an | 36 | * in case we find a finger then we update current_source in the |
37 | * intermediate finger, friend or me. | 37 | * find_successor message. |
38 | */ | 38 | * Construct a Put message and send it to target_peer. |
39 | enum current_destination_type /* FIXME: enum GSX_CurrentDestinationType */ | 39 | * @param key Key for the content |
40 | { | 40 | * @param data Content to store |
41 | /** | 41 | * @param data_size Size of content @a data in bytes |
42 | * Look in friend AND finger tables for a trail to the key. | 42 | * @param block_type Type of the block |
43 | */ | 43 | * @param options Routing options |
44 | /* FIXME: GSX_CDT_ */ FRIEND, | 44 | * @param desired_replication_level Desired replication count |
45 | 45 | * @param expiration_time When does the content expire | |
46 | /** | 46 | * @param current_destination |
47 | * Look in the routing table to follow a trail to reach to the | 47 | * @param current_source |
48 | * destination. It is also allowed (but currently not implemented) | 48 | * @param target_peer Peer to which this message will be forwarded. |
49 | * to look into friend/finger tables for a better trail to the key | 49 | * @param hop_count Number of hops traversed so far. |
50 | * and (if one is found) 'abort' the current trail and switch to | 50 | * @param put_path_length Total number of peers in @a put_path |
51 | * the better one. | 51 | * @param put_path Number of peers traversed so far |
52 | */ | ||
53 | FINGER, | ||
54 | |||
55 | /** | ||
56 | * "Returned" if the origin is the closest peer to the destination; | ||
57 | * Must not be passed to "GDS_NEIGHBOURS_handle_put". | ||
58 | */ | ||
59 | MY_ID, | ||
60 | |||
61 | /** | ||
62 | * FIXME. | ||
63 | */ | ||
64 | VALUE | ||
65 | }; | ||
66 | |||
67 | /** | ||
68 | * Perform a PUT operation. Forwards the given request to other | ||
69 | * peers. Does not store the data locally. Does not give the | ||
70 | * data to local clients. May do nothing if this is the only | ||
71 | * peer in the network (or if we are the closest peer in the | ||
72 | * network). | ||
73 | * | ||
74 | * @param type type of the block | ||
75 | * @param options routing options | ||
76 | * @param desired_replication_level desired replication count | ||
77 | * @param expiration_time when does the content expire | ||
78 | * @param hop_count how many hops has this message traversed so far | ||
79 | * @param key key for the content | ||
80 | * @param put_path_length number of entries in @a put_path | ||
81 | * @param put_path peers this request has traversed so far (if tracked) | ||
82 | * @param data payload to store | ||
83 | * @param data_size number of bytes in @a data | ||
84 | */ | 52 | */ |
85 | void | 53 | void |
86 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | 54 | GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key, |
87 | enum GNUNET_DHT_RouteOption options, | 55 | const void *data, size_t data_size, |
88 | uint32_t desired_replication_level, | 56 | enum GNUNET_BLOCK_Type block_type, |
89 | struct GNUNET_TIME_Absolute expiration_time, | 57 | enum GNUNET_DHT_RouteOption options, |
90 | uint32_t hop_count, | 58 | uint32_t desired_replication_level, |
91 | const struct GNUNET_HashCode * key, | 59 | struct GNUNET_TIME_Absolute expiration_time, |
92 | unsigned int put_path_length, | 60 | struct GNUNET_PeerIdentity *current_destination, |
93 | struct GNUNET_PeerIdentity *put_path, | 61 | struct GNUNET_PeerIdentity *current_source, |
94 | const void *data, size_t data_size, | 62 | struct GNUNET_PeerIdentity *target_peer, |
95 | struct GNUNET_PeerIdentity *current_destination, | 63 | uint32_t hop_count, |
96 | struct GNUNET_PeerIdentity *current_source, | 64 | uint32_t put_path_length, |
97 | enum current_destination_type dest_type, | 65 | struct GNUNET_PeerIdentity *put_path); |
98 | struct GNUNET_PeerIdentity *target_peer_id); | 66 | |
99 | 67 | ||
100 | 68 | /** FIXME: by default I keep current_source, and destination as my own id. | |
101 | /** | 69 | * in case we find a finger then we update current_source in the |
102 | * | 70 | * find_successor message. |
103 | * @param source_peer | 71 | * Construct a Get message and send it to target_peer. |
104 | * @param get_path | 72 | * @param key Key for the content |
105 | * @param get_path_length | 73 | * @param data Content to store |
106 | * @param key | 74 | * @param data_size Size of content @a data in bytes |
75 | * @param block_type Type of the block | ||
76 | * @param options Routing options | ||
77 | * @param desired_replication_level Desired replication count | ||
78 | * @param expiration_time When does the content expire | ||
79 | * @param current_destination | ||
80 | * @param current_source | ||
81 | * @param target_peer Peer to which this message will be forwarded. | ||
82 | * @param hop_count Number of hops traversed so far. | ||
83 | * @param put_path_length Total number of peers in @a put_path | ||
84 | * @param put_path Number of peers traversed so far | ||
107 | */ | 85 | */ |
108 | void | 86 | void |
109 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type block_type, | 87 | GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, |
110 | enum GNUNET_DHT_RouteOption options, | 88 | enum GNUNET_BLOCK_Type block_type, |
111 | uint32_t desired_replication_level, | 89 | enum GNUNET_DHT_RouteOption options, |
112 | uint32_t hop_count, | 90 | uint32_t desired_replication_level, |
113 | struct GNUNET_PeerIdentity *get_peer_path, | 91 | struct GNUNET_PeerIdentity *current_destination, |
114 | unsigned int get_path_length, | 92 | struct GNUNET_PeerIdentity *current_source, |
115 | struct GNUNET_HashCode *key, | 93 | struct GNUNET_PeerIdentity *target_peer, |
116 | struct GNUNET_PeerIdentity *target_peer, | 94 | uint32_t hop_count, |
117 | struct GNUNET_PeerIdentity *current_destination, | 95 | uint32_t get_path_length, |
118 | struct GNUNET_PeerIdentity *current_source, | 96 | struct GNUNET_PeerIdentity *get_path); |
119 | enum current_destination_type current_dest_type); | ||
120 | 97 | ||
121 | 98 | ||
122 | /** | 99 | /** |
123 | * FIXME: I am removing source peer as the first element in the trail | 100 | * Send the get result to requesting client. |
124 | * is source identity. | 101 | * @param expiration When will this result expire? |
125 | * Send get result back to requesting client. | 102 | * @param key Key of the requested data. |
126 | * @param expiration when will the reply expire | 103 | * @param put_path_length Number of peers in @a put_path |
127 | * @param key the query this reply is for | 104 | * @param put_path Path taken to put the data at its stored location. |
128 | * @param get_path_length number of peers in @a get_path | 105 | * @param type Block type |
129 | * @param get_path path the reply took on get | 106 | * @param data_size Size of the @a data |
130 | * @param put_path_length number of peers in @a put_path | 107 | * @param data Payload to store |
131 | * @param put_path path the reply took on put | 108 | * @param get_path Path taken to reach to the location of the key. |
132 | * @param type type of the reply | 109 | * @param get_path_length Number of peers in @a get_path |
133 | * @param data_size number of bytes in @a data | 110 | * @param current_get_path_index Index in get_path |
134 | * @param data application payload data | 111 | * @param next_hop Next peer to forward the message to. |
135 | * @param get_path | 112 | * @param source_peer Peer which has the data for the key. |
136 | * @param get_path_length | ||
137 | */ | 113 | */ |
114 | /* FIXME: Remove redundant arguments | ||
115 | * 1.remove get_path_index from message and just look up into the get path | ||
116 | for your location and get the next peer. | ||
117 | * 2. Remove next_hop, source_peer */ | ||
138 | void | 118 | void |
139 | GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | 119 | GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, |
140 | const struct GNUNET_HashCode *key, | 120 | const struct GNUNET_HashCode *key, |
@@ -144,40 +124,14 @@ GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration, | |||
144 | const void *data, | 124 | const void *data, |
145 | struct GNUNET_PeerIdentity *get_path, | 125 | struct GNUNET_PeerIdentity *get_path, |
146 | unsigned int get_path_length, | 126 | unsigned int get_path_length, |
147 | unsigned int current_trail_index, | ||
148 | struct GNUNET_PeerIdentity *next_hop, | 127 | struct GNUNET_PeerIdentity *next_hop, |
149 | struct GNUNET_PeerIdentity *source_peer); | 128 | struct GNUNET_PeerIdentity *source_peer); |
150 | 129 | ||
151 | /** | 130 | /** |
152 | * FIXME: Here you should update the fields of struct PeerGetResultMessage. | ||
153 | * At the end of this message you should add the data and get path and send | ||
154 | * to the original requesting client. and there you should call GDS_CLIENT_handle_reply | ||
155 | * with correct parameter. | ||
156 | * @param expiration | ||
157 | * @param key | ||
158 | * @param get_path_length | ||
159 | * @param get_path | ||
160 | * @param put_path_length | ||
161 | * @param put_path | ||
162 | * @param type | ||
163 | * @param data_size | ||
164 | * @param data | ||
165 | */ | ||
166 | void | ||
167 | GDS_NEIGHBOURS_datacache_get (struct GNUNET_TIME_Absolute expiration, | ||
168 | const struct GNUNET_HashCode *key, | ||
169 | unsigned int get_path_length, | ||
170 | const struct GNUNET_PeerIdentity *get_path, | ||
171 | unsigned int put_path_length, | ||
172 | const struct GNUNET_PeerIdentity *put_path, | ||
173 | enum GNUNET_BLOCK_Type type, size_t data_size, | ||
174 | const void *data); | ||
175 | |||
176 | |||
177 | /** | ||
178 | * Initialize neighbours subsystem. | 131 | * Initialize neighbours subsystem. |
179 | * | 132 | * |
180 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 133 | * @return #GNUNET_OK on success, |
134 | * #GNUNET_SYSERR on error | ||
181 | */ | 135 | */ |
182 | int | 136 | int |
183 | GDS_NEIGHBOURS_init (void); | 137 | GDS_NEIGHBOURS_init (void); |
@@ -191,12 +145,12 @@ GDS_NEIGHBOURS_done (void); | |||
191 | 145 | ||
192 | 146 | ||
193 | /** | 147 | /** |
194 | * Get the ID of the local node. | 148 | * Get my identity |
195 | * | 149 | * |
196 | * @return identity of the local node | 150 | * @return my identity |
197 | */ | 151 | */ |
198 | struct GNUNET_PeerIdentity * | 152 | struct GNUNET_PeerIdentity * |
199 | GDS_NEIGHBOURS_get_id (); | 153 | GDS_NEIGHBOURS_get_my_id (void); |
200 | 154 | ||
201 | 155 | ||
202 | #endif | 156 | #endif |