diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-03-24 12:28:30 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-03-24 12:28:30 +0000 |
commit | 6b9d1e71ad452c1c069a1def8328542215327e3e (patch) | |
tree | 8cf209de9bda3d72de89f6814e46a065ccf20581 /src/dht | |
parent | ad10090b45f61b52ed90775cd912400503647675 (diff) | |
download | gnunet-6b9d1e71ad452c1c069a1def8328542215327e3e.tar.gz gnunet-6b9d1e71ad452c1c069a1def8328542215327e3e.zip |
Merged update_successor and update_predecessor with finger table add
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/dht_api.c | 6 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 1031 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_routing.c | 17 |
3 files changed, 433 insertions, 621 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index f94d1f67a..0a35ba988 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -1136,14 +1136,14 @@ mark_put_message_gone (void *cls, | |||
1136 | */ | 1136 | */ |
1137 | struct GNUNET_DHT_PutHandle * | 1137 | struct GNUNET_DHT_PutHandle * |
1138 | GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | 1138 | GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, |
1139 | const struct GNUNET_HashCode * key, | 1139 | const struct GNUNET_HashCode * key, |
1140 | uint32_t desired_replication_level, | 1140 | uint32_t desired_replication_level, |
1141 | enum GNUNET_DHT_RouteOption options, | 1141 | enum GNUNET_DHT_RouteOption options, |
1142 | enum GNUNET_BLOCK_Type type, size_t size, | 1142 | enum GNUNET_BLOCK_Type type, size_t size, |
1143 | const void *data, | 1143 | const void *data, |
1144 | struct GNUNET_TIME_Absolute exp, | 1144 | struct GNUNET_TIME_Absolute exp, |
1145 | struct GNUNET_TIME_Relative timeout, | 1145 | struct GNUNET_TIME_Relative timeout, |
1146 | GNUNET_DHT_PutContinuation cont, | 1146 | GNUNET_DHT_PutContinuation cont, |
1147 | void *cont_cls) | 1147 | void *cont_cls) |
1148 | { | 1148 | { |
1149 | struct GNUNET_DHT_ClientPutMessage *put_msg; | 1149 | struct GNUNET_DHT_ClientPutMessage *put_msg; |
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index fb6e71f2e..607cf3b43 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -48,6 +48,11 @@ | |||
48 | #include <fenv.h> | 48 | #include <fenv.h> |
49 | #include "dht.h" | 49 | #include "dht.h" |
50 | 50 | ||
51 | /* TODO: | ||
52 | 1. Use a global array of all known peers in find_successor, Only when | ||
53 | a new peer is added in finger or friend peer map, then re calculate | ||
54 | the array. Or else use the old one. */ | ||
55 | |||
51 | /** | 56 | /** |
52 | * Maximum possible fingers of a peer. | 57 | * Maximum possible fingers of a peer. |
53 | */ | 58 | */ |
@@ -73,6 +78,7 @@ | |||
73 | */ | 78 | */ |
74 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) | 79 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) |
75 | 80 | ||
81 | |||
76 | GNUNET_NETWORK_STRUCT_BEGIN | 82 | GNUNET_NETWORK_STRUCT_BEGIN |
77 | 83 | ||
78 | /** | 84 | /** |
@@ -230,9 +236,9 @@ struct PeerGetMessage | |||
230 | 236 | ||
231 | 237 | ||
232 | /** | 238 | /** |
233 | * A destination can be either a friend, finger or me. | 239 | * FIXME: Change the comment to explain about usage of this in find successor. |
234 | * Used in trail setup to understand if the message is sent to an intermediate | 240 | * Field in trail setup message to understand if the message is sent to an |
235 | * finger or a friend. | 241 | * intermediate finger, friend or me. |
236 | */ | 242 | */ |
237 | enum current_destination_type | 243 | enum current_destination_type |
238 | { | 244 | { |
@@ -260,21 +266,11 @@ struct PeerTrailSetupMessage | |||
260 | struct GNUNET_PeerIdentity source_peer; | 266 | struct GNUNET_PeerIdentity source_peer; |
261 | 267 | ||
262 | /** | 268 | /** |
263 | * Finger id to which we want to set up the trail to. | 269 | * Successor of this finger value will be our finger peer. |
264 | */ | 270 | */ |
265 | uint64_t destination_finger; | 271 | uint64_t destination_finger; |
266 | 272 | ||
267 | /** | 273 | /** |
268 | * If set to 1, then we are looking for trail to our immediate successor. | ||
269 | */ | ||
270 | unsigned int successor_flag; | ||
271 | |||
272 | /** | ||
273 | * If set to 1, then we are looking for trail to our immediate predecessor. | ||
274 | */ | ||
275 | unsigned int predecessor_flag; | ||
276 | |||
277 | /** | ||
278 | * Peer which gets this message can be either an intermediate finger or friend. | 274 | * Peer which gets this message can be either an intermediate finger or friend. |
279 | */ | 275 | */ |
280 | enum current_destination_type current_destination_type; | 276 | enum current_destination_type current_destination_type; |
@@ -298,7 +294,7 @@ struct PeerTrailSetupMessage | |||
298 | 294 | ||
299 | 295 | ||
300 | /** | 296 | /** |
301 | * P2P Trail setup Result message | 297 | * P2P Trail Setup Result message |
302 | */ | 298 | */ |
303 | struct PeerTrailSetupResultMessage | 299 | struct PeerTrailSetupResultMessage |
304 | { | 300 | { |
@@ -311,7 +307,7 @@ struct PeerTrailSetupResultMessage | |||
311 | /** | 307 | /** |
312 | * Finger to which we have found the path. | 308 | * Finger to which we have found the path. |
313 | */ | 309 | */ |
314 | struct GNUNET_PeerIdentity finger; | 310 | struct GNUNET_PeerIdentity finger_identity; |
315 | 311 | ||
316 | /** | 312 | /** |
317 | * Peer which was looking for the trail to finger. | 313 | * Peer which was looking for the trail to finger. |
@@ -319,26 +315,11 @@ struct PeerTrailSetupResultMessage | |||
319 | struct GNUNET_PeerIdentity destination_peer; | 315 | struct GNUNET_PeerIdentity destination_peer; |
320 | 316 | ||
321 | /** | 317 | /** |
322 | * Peer to which this packet is forwarded next. | 318 | * Trail index which points to next destination to send this message. |
323 | */ | ||
324 | struct GNUNET_PeerIdentity current_destination; | ||
325 | |||
326 | /** | ||
327 | * Index at which peer list should be accessed. | ||
328 | */ | 319 | */ |
329 | unsigned int current_index; | 320 | unsigned int current_index; |
330 | 321 | ||
331 | /** | 322 | /** |
332 | * If set to 1, then this trail is the trail to our successor. | ||
333 | */ | ||
334 | unsigned int successor_flag; | ||
335 | |||
336 | /** | ||
337 | * If set to 1, then this trail is the trail to our predecessor. | ||
338 | */ | ||
339 | unsigned int predecessor_flag; | ||
340 | |||
341 | /** | ||
342 | * Index into finger peer map | 323 | * Index into finger peer map |
343 | */ | 324 | */ |
344 | unsigned int finger_map_index; | 325 | unsigned int finger_map_index; |
@@ -352,7 +333,7 @@ struct PeerTrailSetupResultMessage | |||
352 | 333 | ||
353 | 334 | ||
354 | /** | 335 | /** |
355 | * P2P verify successor message. | 336 | * P2P Verify Successor message. |
356 | */ | 337 | */ |
357 | struct PeerVerifySuccessorMessage | 338 | struct PeerVerifySuccessorMessage |
358 | { | 339 | { |
@@ -378,7 +359,7 @@ struct PeerVerifySuccessorMessage | |||
378 | unsigned int trail_length; | 359 | unsigned int trail_length; |
379 | 360 | ||
380 | /** | 361 | /** |
381 | * Index in trail which points to next destination to send this message. | 362 | * Trail index which points to next destination to send this message. |
382 | */ | 363 | */ |
383 | unsigned int current_trail_index; | 364 | unsigned int current_trail_index; |
384 | 365 | ||
@@ -386,7 +367,7 @@ struct PeerVerifySuccessorMessage | |||
386 | 367 | ||
387 | 368 | ||
388 | /** | 369 | /** |
389 | * P2P verify successor result message. | 370 | * P2P Verify Successor Result message. |
390 | */ | 371 | */ |
391 | struct PeerVerifySuccessorResultMessage | 372 | struct PeerVerifySuccessorResultMessage |
392 | { | 373 | { |
@@ -421,14 +402,14 @@ struct PeerVerifySuccessorResultMessage | |||
421 | unsigned int trail_length; | 402 | unsigned int trail_length; |
422 | 403 | ||
423 | /** | 404 | /** |
424 | * Index in trail which points to next destination to send this message. | 405 | * Trail index which points to next destination to send this message. |
425 | */ | 406 | */ |
426 | unsigned int current_index; | 407 | unsigned int current_index; |
427 | 408 | ||
428 | }; | 409 | }; |
429 | 410 | ||
430 | /** | 411 | /** |
431 | * P2P notify new successor message. | 412 | * P2P Notify New Successor message. |
432 | */ | 413 | */ |
433 | struct PeerNotifyNewSuccessorMessage | 414 | struct PeerNotifyNewSuccessorMessage |
434 | { | 415 | { |
@@ -453,7 +434,7 @@ struct PeerNotifyNewSuccessorMessage | |||
453 | unsigned int trail_length; | 434 | unsigned int trail_length; |
454 | 435 | ||
455 | /** | 436 | /** |
456 | * Index in trail which points to next destination to send this message. | 437 | * Trail index which points to next destination to send this message. |
457 | */ | 438 | */ |
458 | unsigned int current_index; | 439 | unsigned int current_index; |
459 | 440 | ||
@@ -498,9 +479,9 @@ struct P2PPendingMessage | |||
498 | }; | 479 | }; |
499 | 480 | ||
500 | 481 | ||
501 | /** | 482 | /** |
502 | * Linked List of peers which are part of trail to reach a particular Finger. | 483 | * Linked List of peers which are part of trail to reach a particular Finger. |
503 | */ | 484 | */ |
504 | struct TrailPeerList | 485 | struct TrailPeerList |
505 | { | 486 | { |
506 | /** | 487 | /** |
@@ -539,17 +520,17 @@ struct FriendInfo | |||
539 | /** | 520 | /** |
540 | * Head of pending messages to be sent to this friend. | 521 | * Head of pending messages to be sent to this friend. |
541 | */ | 522 | */ |
542 | struct P2PPendingMessage *head; | 523 | struct P2PPendingMessage *head; |
543 | 524 | ||
544 | /** | 525 | /** |
545 | * Tail of pending messages to be sent to this friend. | 526 | * Tail of pending messages to be sent to this friend. |
546 | */ | 527 | */ |
547 | struct P2PPendingMessage *tail; | 528 | struct P2PPendingMessage *tail; |
548 | 529 | ||
549 | /** | 530 | /** |
550 | * Core handle for sending messages to this friend. | 531 | * Core handle for sending messages to this friend. |
551 | */ | 532 | */ |
552 | struct GNUNET_CORE_TransmitHandle *th; | 533 | struct GNUNET_CORE_TransmitHandle *th; |
553 | 534 | ||
554 | }; | 535 | }; |
555 | 536 | ||
@@ -565,22 +546,12 @@ struct FingerInfo | |||
565 | struct GNUNET_PeerIdentity finger_identity; | 546 | struct GNUNET_PeerIdentity finger_identity; |
566 | 547 | ||
567 | /** | 548 | /** |
568 | * If 1, then this finger entry is my first finger(successor). | ||
569 | */ | ||
570 | unsigned int successor; | ||
571 | |||
572 | /** | ||
573 | * If 1, then this finger entry is my first predecessor. | ||
574 | */ | ||
575 | unsigned int predecessor; | ||
576 | |||
577 | /** | ||
578 | * Index in finger peer map | 549 | * Index in finger peer map |
579 | */ | 550 | */ |
580 | unsigned int finger_map_index; | 551 | unsigned int finger_map_index; |
581 | 552 | ||
582 | /** | 553 | /** |
583 | * Total number of entries in trail from me to finger. | 554 | * Total number of entries in trail from [me,finger] |
584 | */ | 555 | */ |
585 | unsigned int trail_length; | 556 | unsigned int trail_length; |
586 | 557 | ||
@@ -596,18 +567,26 @@ struct FingerInfo | |||
596 | 567 | ||
597 | }; | 568 | }; |
598 | 569 | ||
570 | |||
599 | /** | 571 | /** |
572 | * FIXME: Think of a better name. | ||
600 | * Data structure passed to sorting algorithm in find_successor. | 573 | * Data structure passed to sorting algorithm in find_successor. |
601 | */ | 574 | */ |
602 | struct Sorting_List | 575 | struct Sorting_List |
603 | { | 576 | { |
604 | /* 64 bit value of peer identity */ | 577 | /** |
578 | * 64 bit value of peer identity | ||
579 | */ | ||
605 | uint64_t peer_id; | 580 | uint64_t peer_id; |
606 | 581 | ||
607 | /* Type : MY_ID, FINGER, FINGER */ | 582 | /** |
583 | * Type : MY_ID, FINGER, FINGER, Value | ||
584 | */ | ||
608 | enum current_destination_type type; | 585 | enum current_destination_type type; |
609 | 586 | ||
610 | /* Pointer to original data structure linked to peer id. */ | 587 | /** |
588 | * Pointer to original data structure linked to peer id. | ||
589 | */ | ||
611 | void *data; | 590 | void *data; |
612 | }; | 591 | }; |
613 | 592 | ||
@@ -619,7 +598,7 @@ static GNUNET_SCHEDULER_TaskIdentifier find_finger_trail_task; | |||
619 | 598 | ||
620 | /** | 599 | /** |
621 | * | 600 | * |
622 | * Task that periodically checks for who is my successor. | 601 | * Task that periodically verifies my successor. |
623 | */ | 602 | */ |
624 | static GNUNET_SCHEDULER_TaskIdentifier verify_successor; | 603 | static GNUNET_SCHEDULER_TaskIdentifier verify_successor; |
625 | 604 | ||
@@ -659,7 +638,7 @@ static unsigned int current_finger_index; | |||
659 | * Called when core is ready to send a message we asked for | 638 | * Called when core is ready to send a message we asked for |
660 | * out to the destination. | 639 | * out to the destination. |
661 | * | 640 | * |
662 | * @param cls the 'struct PeerInfo' of the target peer | 641 | * @param cls the 'struct FriendInfo' of the target friend |
663 | * @param size number of bytes available in buf | 642 | * @param size number of bytes available in buf |
664 | * @param buf where the callee should write the message | 643 | * @param buf where the callee should write the message |
665 | * @return number of bytes written to buf | 644 | * @return number of bytes written to buf |
@@ -759,25 +738,25 @@ process_friend_queue (struct FriendInfo *peer) | |||
759 | 738 | ||
760 | 739 | ||
761 | /** | 740 | /** |
762 | * Setup the trail message and forward it to a friend. | 741 | * Construct a trail message and forward it to a friend. |
763 | * @param source_peer Peer which wants to set up the trail to one of its finger. | 742 | * @param source_peer Peer which wants to set up the trail to one of its finger. |
764 | * @param destination_finger Peer to which we want to set up the trail to. | 743 | * @param destination_finger Value whose successor we are searching the network. |
744 | * @param current_destination Peer which gets this message. | ||
765 | * @param target_friend Current friend to which this message should be forwarded. | 745 | * @param target_friend Current friend to which this message should be forwarded. |
766 | * @param trail_length Numbers of peers in the trail. | 746 | * @param trail_length Numbers of peers in the trail. |
767 | * @param trail_peer_list peers this request has traversed so far | 747 | * @param trail_peer_list peers this request has traversed so far |
768 | * @param successor_flag If 1 then we are looking for trail to our successor. | 748 | * @param finger_map_index Index in finger peer map |
769 | * @param predecessor_flag If 1, then we are looking for trail to our predecessor. | 749 | * @param type Type of current destination can be either FRIEND or FINGER |
770 | * @param current_finger_index Finger index in finger peer map | ||
771 | */ | 750 | */ |
772 | void | 751 | void |
773 | GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity *source_peer, | 752 | GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity *source_peer, |
774 | uint64_t destination_finger, | 753 | uint64_t destination_finger, |
775 | struct FriendInfo *target_friend, | 754 | struct GNUNET_PeerIdentity *current_destination, |
776 | unsigned int trail_length, | 755 | struct FriendInfo *target_friend, |
777 | struct GNUNET_PeerIdentity *trail_peer_list, | 756 | unsigned int trail_length, |
778 | unsigned int successor_flag, | 757 | struct GNUNET_PeerIdentity *trail_peer_list, |
779 | unsigned int predecessor_flag, | 758 | unsigned int finger_map_index, |
780 | unsigned int current_finger_index) | 759 | enum current_destination_type type) |
781 | { | 760 | { |
782 | struct P2PPendingMessage *pending; | 761 | struct P2PPendingMessage *pending; |
783 | struct PeerTrailSetupMessage *tsm; | 762 | struct PeerTrailSetupMessage *tsm; |
@@ -808,26 +787,10 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity *source_peer, | |||
808 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); | 787 | tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); |
809 | memcpy (&(tsm->destination_finger), &destination_finger, sizeof (uint64_t)); | 788 | memcpy (&(tsm->destination_finger), &destination_finger, sizeof (uint64_t)); |
810 | memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); | 789 | memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); |
811 | memcpy (&(tsm->current_destination), &(target_friend->id), | 790 | memcpy (&(tsm->current_destination), current_destination, sizeof (struct GNUNET_PeerIdentity)); |
812 | sizeof (struct GNUNET_PeerIdentity)); | 791 | tsm->current_destination_type = htonl (type); |
813 | tsm->current_destination_type = htonl (FRIEND); | ||
814 | tsm->trail_length = htonl (trail_length); | 792 | tsm->trail_length = htonl (trail_length); |
815 | tsm->finger_map_index = htonl (current_finger_index); | 793 | tsm->finger_map_index = htonl (finger_map_index); |
816 | if(1 == successor_flag) | ||
817 | { | ||
818 | tsm->successor_flag = htonl(1); | ||
819 | tsm->predecessor_flag = htonl (0); | ||
820 | } | ||
821 | else if (1 == predecessor_flag) | ||
822 | { | ||
823 | tsm->predecessor_flag = htonl(1); | ||
824 | tsm->successor_flag = htonl(0); | ||
825 | } | ||
826 | else | ||
827 | { | ||
828 | tsm->successor_flag = htonl(0); | ||
829 | tsm->predecessor_flag = htonl(0); | ||
830 | } | ||
831 | 794 | ||
832 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; | 795 | peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; |
833 | memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); | 796 | memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); |
@@ -839,27 +802,24 @@ GDS_NEIGHBOURS_send_trail_setup (struct GNUNET_PeerIdentity *source_peer, | |||
839 | 802 | ||
840 | 803 | ||
841 | /** | 804 | /** |
842 | * Handle a tail setup result message. | 805 | * Construct a trail setup result message and forward it to a friend. |
843 | * @param destination_peer Peer which will get the trail to one of its finger. | 806 | * @param destination_peer Peer which will get the trail to one of its finger. |
844 | * @param source_finger Peer to which the trail has been setup to. | 807 | * @param source_finger Peer to which the trail has been setup to. |
845 | * @param target_friend Friend to which this message should be forwarded. | 808 | * @param target_friend Friend to which this message should be forwarded. |
846 | * @param trail_length Numbers of peers in the trail. | 809 | * @param trail_length Numbers of peers in the trail. |
847 | * @param trail_peer_list Peers which are part of the trail from source to destination. | 810 | * @param trail_peer_list Peers which are part of the trail from source to destination. |
848 | * @param current_trail_index Index in trail_peer_list. | 811 | * @param current_trail_index Index in the trial list at which receiving peer should |
849 | * @param successor_flag If 1, then this is the trail to our successor. | 812 | * read the next element. |
850 | * @param predecessor_flag If 1, then this is the trail to our predecessor. | 813 | * @param finger_map_index Index in finger peer map |
851 | * @param finger_map_index Finger index in finger peer map | ||
852 | */ | 814 | */ |
853 | void | 815 | void |
854 | GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity *destination_peer, | 816 | GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity *destination_peer, |
855 | struct GNUNET_PeerIdentity *source_finger, | 817 | struct GNUNET_PeerIdentity *source_finger, |
856 | struct FriendInfo *target_friend, | 818 | struct FriendInfo *target_friend, |
857 | unsigned int trail_length, | 819 | unsigned int trail_length, |
858 | struct GNUNET_PeerIdentity *trail_peer_list, | 820 | struct GNUNET_PeerIdentity *trail_peer_list, |
859 | unsigned int current_trail_index, | 821 | unsigned int current_trail_index, |
860 | unsigned int successor_flag, | 822 | unsigned int finger_map_index) |
861 | unsigned int predecessor_flag, | ||
862 | unsigned int finger_map_index) | ||
863 | { | 823 | { |
864 | struct P2PPendingMessage *pending; | 824 | struct P2PPendingMessage *pending; |
865 | struct PeerTrailSetupResultMessage *tsrm; | 825 | struct PeerTrailSetupResultMessage *tsrm; |
@@ -888,13 +848,10 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity *destination_ | |||
888 | pending->msg = &tsrm->header; | 848 | pending->msg = &tsrm->header; |
889 | tsrm->header.size = htons (msize); | 849 | tsrm->header.size = htons (msize); |
890 | tsrm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT); | 850 | tsrm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT); |
891 | memcpy (&(tsrm->current_destination), &(target_friend->id), sizeof (struct GNUNET_PeerIdentity)); | ||
892 | memcpy (&(tsrm->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity)); | 851 | memcpy (&(tsrm->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity)); |
893 | memcpy (&(tsrm->finger), source_finger, sizeof (struct GNUNET_PeerIdentity)); | 852 | memcpy (&(tsrm->finger_identity), source_finger, sizeof (struct GNUNET_PeerIdentity)); |
894 | tsrm->trail_length = htonl (trail_length); | 853 | tsrm->trail_length = htonl (trail_length); |
895 | tsrm->current_index = htonl (current_trail_index); | 854 | tsrm->current_index = htonl (current_trail_index); |
896 | tsrm->successor_flag = htonl (successor_flag); | ||
897 | tsrm->predecessor_flag = htonl (predecessor_flag); | ||
898 | tsrm->finger_map_index = htonl (finger_map_index); | 855 | tsrm->finger_map_index = htonl (finger_map_index); |
899 | peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; | 856 | peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; |
900 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 857 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
@@ -914,14 +871,14 @@ GDS_NEIGHBOURS_send_trail_setup_result (struct GNUNET_PeerIdentity *destination_ | |||
914 | * @param trail_peer_list Peer which are part of trail from source to destination | 871 | * @param trail_peer_list Peer which are part of trail from source to destination |
915 | * @param trail_length Number of peers in the trail list. | 872 | * @param trail_length Number of peers in the trail list. |
916 | * @param current_trail_index Index in the trial list at which receiving peer should | 873 | * @param current_trail_index Index in the trial list at which receiving peer should |
917 | * get the next element. | 874 | * read the next element. |
918 | */ | 875 | */ |
919 | void GDS_NEIGHBOURS_send_verify_successor(struct GNUNET_PeerIdentity *source_peer, | 876 | void GDS_NEIGHBOURS_send_verify_successor(struct GNUNET_PeerIdentity *source_peer, |
920 | struct GNUNET_PeerIdentity *successor, | 877 | struct GNUNET_PeerIdentity *successor, |
921 | struct FriendInfo *target_friend, | 878 | struct FriendInfo *target_friend, |
922 | struct GNUNET_PeerIdentity *trail_peer_list, | 879 | struct GNUNET_PeerIdentity *trail_peer_list, |
923 | unsigned int trail_length, | 880 | unsigned int trail_length, |
924 | unsigned int current_trail_index) | 881 | unsigned int current_trail_index) |
925 | { | 882 | { |
926 | struct PeerVerifySuccessorMessage *vsm; | 883 | struct PeerVerifySuccessorMessage *vsm; |
927 | struct P2PPendingMessage *pending; | 884 | struct P2PPendingMessage *pending; |
@@ -969,20 +926,20 @@ void GDS_NEIGHBOURS_send_verify_successor(struct GNUNET_PeerIdentity *source_pee | |||
969 | * Construct a PeerVerifySuccessorResult message and send it to friend. | 926 | * Construct a PeerVerifySuccessorResult message and send it to friend. |
970 | * @param destination_peer Peer which sent verify successor message | 927 | * @param destination_peer Peer which sent verify successor message |
971 | * @param source_successor Peer to which verify successor message was sent. | 928 | * @param source_successor Peer to which verify successor message was sent. |
972 | * @param my_predecessor source_successor predecessor. | 929 | * @param my_predecessor source_successor's predecessor. |
973 | * @param target_friend Friend to which this message should be forwarded. | 930 | * @param target_friend Friend to which this message should be forwarded. |
974 | * @param trail_peer_list Peer which are part of trail from source to destination | 931 | * @param trail_peer_list Peers which are part of trail from source to destination |
975 | * @param trail_length Number of peers in the trail list. | 932 | * @param trail_length Number of peers in the trail list. |
976 | * @param current_trail_index Index in the trial list at which receiving peer should | 933 | * @param current_trail_index Index in the trial list at which receiving peer should |
977 | * get the next element. | 934 | * get the next element. |
978 | */ | 935 | */ |
979 | void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *destination_peer, | 936 | void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *destination_peer, |
980 | struct GNUNET_PeerIdentity *source_successor, | 937 | struct GNUNET_PeerIdentity *source_successor, |
981 | struct GNUNET_PeerIdentity *my_predecessor, | 938 | struct GNUNET_PeerIdentity *my_predecessor, |
982 | struct FriendInfo *target_friend, | 939 | struct FriendInfo *target_friend, |
983 | struct GNUNET_PeerIdentity *trail_peer_list, | 940 | struct GNUNET_PeerIdentity *trail_peer_list, |
984 | unsigned int trail_length, | 941 | unsigned int trail_length, |
985 | unsigned int current_trail_index) | 942 | unsigned int current_trail_index) |
986 | { | 943 | { |
987 | struct PeerVerifySuccessorResultMessage *vsmr; | 944 | struct PeerVerifySuccessorResultMessage *vsmr; |
988 | struct P2PPendingMessage *pending; | 945 | struct P2PPendingMessage *pending; |
@@ -1004,7 +961,7 @@ void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *de | |||
1004 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | 961 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), |
1005 | 1, GNUNET_NO); | 962 | 1, GNUNET_NO); |
1006 | } | 963 | } |
1007 | 964 | ||
1008 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | 965 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); |
1009 | pending->importance = 0; /* FIXME */ | 966 | pending->importance = 0; /* FIXME */ |
1010 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | 967 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); |
@@ -1039,11 +996,11 @@ void GDS_NEIGHBOURS_send_verify_successor_result (struct GNUNET_PeerIdentity *de | |||
1039 | */ | 996 | */ |
1040 | void | 997 | void |
1041 | GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity *source_peer, | 998 | GDS_NEIGHBOURS_send_notify_new_successor (struct GNUNET_PeerIdentity *source_peer, |
1042 | struct GNUNET_PeerIdentity *destination_peer, | 999 | struct GNUNET_PeerIdentity *destination_peer, |
1043 | struct FriendInfo *target_friend, | 1000 | struct FriendInfo *target_friend, |
1044 | struct GNUNET_PeerIdentity *trail_peer_list, | 1001 | struct GNUNET_PeerIdentity *trail_peer_list, |
1045 | unsigned int trail_length, | 1002 | unsigned int trail_length, |
1046 | unsigned int current_trail_index) | 1003 | unsigned int current_trail_index) |
1047 | { | 1004 | { |
1048 | struct PeerNotifyNewSuccessorMessage *nsm; | 1005 | struct PeerNotifyNewSuccessorMessage *nsm; |
1049 | struct P2PPendingMessage *pending; | 1006 | struct P2PPendingMessage *pending; |
@@ -1170,7 +1127,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
1170 | waiting for a confirmation So, once we got the request, we use the key and | 1127 | waiting for a confirmation So, once we got the request, we use the key and |
1171 | try to find the closest successor, but in this case when we reach to the | 1128 | try to find the closest successor, but in this case when we reach to the |
1172 | closest successor in handle_dht_p2p_put, then just do datacache_put. As the calling | 1129 | closest successor in handle_dht_p2p_put, then just do datacache_put. As the calling |
1173 | function does not need any confirmation, we don't need the result back. */ | 1130 | function does not need any confirmation, we don't need the result back. */ |
1174 | } | 1131 | } |
1175 | 1132 | ||
1176 | 1133 | ||
@@ -1206,6 +1163,7 @@ select_random_friend() | |||
1206 | else | 1163 | else |
1207 | return NULL; | 1164 | return NULL; |
1208 | } | 1165 | } |
1166 | |||
1209 | 1167 | ||
1210 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (iter,&key_ret,(const void **)&friend)) | 1168 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (iter,&key_ret,(const void **)&friend)) |
1211 | { | 1169 | { |
@@ -1223,14 +1181,15 @@ select_random_friend() | |||
1223 | static uint64_t * | 1181 | static uint64_t * |
1224 | compute_finger_identity() | 1182 | compute_finger_identity() |
1225 | { | 1183 | { |
1226 | uint64_t *my_id64 ; | 1184 | uint64_t my_id64 ; |
1227 | uint64_t *finger_identity64; | 1185 | uint64_t *finger_identity64; |
1228 | 1186 | ||
1229 | my_id64 = GNUNET_malloc (sizeof (uint64_t)); | ||
1230 | finger_identity64 = GNUNET_malloc (sizeof (uint64_t)); | 1187 | finger_identity64 = GNUNET_malloc (sizeof (uint64_t)); |
1231 | 1188 | ||
1232 | memcpy (my_id64, &(my_identity.public_key.q_y), sizeof (uint64_t)); | 1189 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); |
1233 | *finger_identity64 = fmod ((*my_id64 + pow (2,current_finger_index)),( (pow (2,MAX_FINGERS)))); | 1190 | |
1191 | /*FIXME: Do we need a mod finger = ((my_id + pow(2, finger_index)) mod (pow (2, MAX_FINGERS))*/ | ||
1192 | *finger_identity64 = (my_id64 + (unsigned long) pow (2,current_finger_index)); | ||
1234 | 1193 | ||
1235 | return finger_identity64; | 1194 | return finger_identity64; |
1236 | } | 1195 | } |
@@ -1243,23 +1202,19 @@ compute_finger_identity() | |||
1243 | static uint64_t * | 1202 | static uint64_t * |
1244 | compute_predecessor_identity() | 1203 | compute_predecessor_identity() |
1245 | { | 1204 | { |
1246 | uint64_t *my_id ; | 1205 | uint64_t my_id ; |
1247 | uint64_t *predecessor; | 1206 | uint64_t *predecessor; |
1248 | 1207 | ||
1249 | my_id = GNUNET_malloc (sizeof (uint64_t)); | ||
1250 | predecessor = GNUNET_malloc (sizeof (uint64_t)); | 1208 | predecessor = GNUNET_malloc (sizeof (uint64_t)); |
1251 | 1209 | memcpy (&my_id, &my_identity, sizeof (uint64_t)); | |
1252 | memcpy (my_id, &(my_identity.public_key.q_y), sizeof (uint64_t)); | 1210 | /* FIXME: Do we need to use mod pow(2, MAX_FINGERS) here? */ |
1253 | *predecessor = fmod ((*my_id -1), (pow (2,MAX_FINGERS))); | 1211 | *predecessor = (my_id -1); |
1254 | 1212 | ||
1255 | return predecessor; | 1213 | return predecessor; |
1256 | } | 1214 | } |
1257 | 1215 | ||
1258 | 1216 | ||
1259 | /** | 1217 | /** |
1260 | * SUPU: You should pass the trail index from where next peer should read. read | ||
1261 | * position should be set and after you read you should update the read position | ||
1262 | * for next peer in the trail list. | ||
1263 | * Periodically ping your successor to ask its current predecessor | 1218 | * Periodically ping your successor to ask its current predecessor |
1264 | * | 1219 | * |
1265 | * @param cls closure for this task | 1220 | * @param cls closure for this task |
@@ -1279,22 +1234,27 @@ send_verify_successor_message (void *cls, | |||
1279 | struct FingerInfo *finger; | 1234 | struct FingerInfo *finger; |
1280 | unsigned int finger_index; | 1235 | unsigned int finger_index; |
1281 | unsigned int i; | 1236 | unsigned int i; |
1282 | 1237 | int flag = 0; | |
1283 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | 1238 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); |
1284 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | 1239 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) |
1285 | { | 1240 | { |
1286 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (finger_iter, &key_ret, | 1241 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (finger_iter, &key_ret, |
1287 | (const void **)&finger)) | 1242 | (const void **)&finger)) |
1288 | { | 1243 | { |
1289 | if (1 == finger->successor) | 1244 | if (0 == finger->finger_map_index) |
1245 | { | ||
1246 | flag = 1; | ||
1290 | break; | 1247 | break; |
1248 | } | ||
1291 | } | 1249 | } |
1292 | } | 1250 | } |
1293 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | 1251 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); |
1294 | 1252 | ||
1253 | if( flag == 0) | ||
1254 | goto send_new_request; | ||
1255 | |||
1295 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * finger->trail_length); | 1256 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * finger->trail_length); |
1296 | 1257 | ||
1297 | /* Iterate over your linked list of trail and copy it into peer_list. */ | ||
1298 | struct TrailPeerList *iterate; | 1258 | struct TrailPeerList *iterate; |
1299 | iterate = finger->head; | 1259 | iterate = finger->head; |
1300 | i = 0; | 1260 | i = 0; |
@@ -1305,24 +1265,22 @@ send_verify_successor_message (void *cls, | |||
1305 | i++; | 1265 | i++; |
1306 | } | 1266 | } |
1307 | 1267 | ||
1308 | /* element stored at location 0 is my own identity. element stored at location 1 | 1268 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
1309 | is the next hop. */ | 1269 | memcpy (next_hop, &peer_list[1], sizeof (struct GNUNET_PeerIdentity)); |
1310 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
1311 | memcpy (next_hop, &peer_list[1], sizeof (struct GNUNET_PeerIdentity)); | ||
1312 | /* Find the friend corresponding to this next hop. */ | ||
1313 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 1270 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
1314 | finger_trail_current_index = 2; | 1271 | finger_trail_current_index = 2; |
1315 | 1272 | ||
1316 | GDS_NEIGHBOURS_send_verify_successor (&my_identity, | 1273 | GDS_NEIGHBOURS_send_verify_successor (&my_identity, |
1317 | &(finger->finger_identity), | 1274 | &(finger->finger_identity), |
1318 | target_friend, | 1275 | target_friend, |
1319 | peer_list, | 1276 | peer_list, |
1320 | finger->trail_length, | 1277 | finger->trail_length, |
1321 | finger_trail_current_index); | 1278 | finger_trail_current_index); |
1322 | 1279 | ||
1323 | 1280 | ||
1324 | /* FIXME: Use a random value so that this message is send not at the same | 1281 | /* FIXME: Use a random value so that this message is send not at the same |
1325 | interval as send_find_finger_trail_message. */ | 1282 | interval as send_find_finger_trail_message. */ |
1283 | send_new_request: | ||
1326 | next_send_time.rel_value_us = | 1284 | next_send_time.rel_value_us = |
1327 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + | 1285 | DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL.rel_value_us + |
1328 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1286 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
@@ -1349,21 +1307,14 @@ send_find_finger_trail_message (void *cls, | |||
1349 | struct FriendInfo *target_friend; | 1307 | struct FriendInfo *target_friend; |
1350 | struct GNUNET_TIME_Relative next_send_time; | 1308 | struct GNUNET_TIME_Relative next_send_time; |
1351 | struct GNUNET_PeerIdentity *peer_list; | 1309 | struct GNUNET_PeerIdentity *peer_list; |
1352 | unsigned int successor_flag; | ||
1353 | unsigned int predecessor_flag; | ||
1354 | uint64_t *finger_identity; | 1310 | uint64_t *finger_identity; |
1355 | unsigned int finger_index; | 1311 | unsigned int finger_map_index; |
1356 | |||
1357 | /* Initialize flag values */ | ||
1358 | predecessor_flag = 0; | ||
1359 | successor_flag = 0; | ||
1360 | 1312 | ||
1361 | if (1 == current_finger_index) | 1313 | if (1 == current_finger_index) |
1362 | { | 1314 | { |
1363 | /* We have started the process to find the successor. We should search | 1315 | /* We have started the process to find the successor. We should search |
1364 | for our predecessor. */ | 1316 | for our predecessor. */ |
1365 | finger_identity = compute_predecessor_identity(); | 1317 | finger_identity = compute_predecessor_identity(); |
1366 | predecessor_flag = 1; | ||
1367 | goto select_friend; | 1318 | goto select_friend; |
1368 | } | 1319 | } |
1369 | else | 1320 | else |
@@ -1371,18 +1322,13 @@ send_find_finger_trail_message (void *cls, | |||
1371 | finger_identity = compute_finger_identity(); | 1322 | finger_identity = compute_finger_identity(); |
1372 | } | 1323 | } |
1373 | 1324 | ||
1374 | if(0 == current_finger_index) | ||
1375 | { | ||
1376 | /* We are searching for our successor in the network. */ | ||
1377 | successor_flag = 1; | ||
1378 | } | ||
1379 | |||
1380 | select_friend: | 1325 | select_friend: |
1381 | finger_index = current_finger_index; | ||
1382 | current_finger_index = ( current_finger_index + 1) % MAX_FINGERS; | ||
1383 | |||
1384 | target_friend = select_random_friend(); | 1326 | target_friend = select_random_friend(); |
1385 | 1327 | ||
1328 | |||
1329 | finger_map_index = current_finger_index; | ||
1330 | current_finger_index = ( current_finger_index + 1) % MAX_FINGERS; | ||
1331 | |||
1386 | /* We found a friend.*/ | 1332 | /* We found a friend.*/ |
1387 | if(NULL != target_friend) | 1333 | if(NULL != target_friend) |
1388 | { | 1334 | { |
@@ -1391,12 +1337,10 @@ send_find_finger_trail_message (void *cls, | |||
1391 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | 1337 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); |
1392 | memcpy (&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); | 1338 | memcpy (&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); |
1393 | memcpy (&peer_list[1], &(target_friend->id), sizeof (struct GNUNET_PeerIdentity)); | 1339 | memcpy (&peer_list[1], &(target_friend->id), sizeof (struct GNUNET_PeerIdentity)); |
1394 | 1340 | ||
1395 | /* TODO send trail setup */ | 1341 | GDS_NEIGHBOURS_send_trail_setup (&my_identity, *finger_identity, &(target_friend->id), |
1396 | GDS_NEIGHBOURS_send_trail_setup (&my_identity, *finger_identity, | 1342 | target_friend, trail_length, peer_list, |
1397 | target_friend, trail_length, peer_list, | 1343 | finger_map_index, FRIEND); |
1398 | successor_flag, predecessor_flag, | ||
1399 | finger_index); | ||
1400 | } | 1344 | } |
1401 | 1345 | ||
1402 | /* FIXME: Should we be using current_finger_index to generate random interval.*/ | 1346 | /* FIXME: Should we be using current_finger_index to generate random interval.*/ |
@@ -1439,7 +1383,6 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity) | |||
1439 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), 1, | 1383 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# peers connected"), 1, |
1440 | GNUNET_NO); | 1384 | GNUNET_NO); |
1441 | 1385 | ||
1442 | |||
1443 | friend = GNUNET_new (struct FriendInfo); | 1386 | friend = GNUNET_new (struct FriendInfo); |
1444 | friend->id = *peer_identity; | 1387 | friend->id = *peer_identity; |
1445 | 1388 | ||
@@ -1465,12 +1408,18 @@ handle_core_disconnect (void *cls, | |||
1465 | const struct GNUNET_PeerIdentity *peer) | 1408 | const struct GNUNET_PeerIdentity *peer) |
1466 | { | 1409 | { |
1467 | struct FriendInfo *remove_friend; | 1410 | struct FriendInfo *remove_friend; |
1411 | struct FingerInfo *remove_finger; | ||
1412 | struct GNUNET_PeerIdentity key_ret; | ||
1413 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | ||
1414 | struct TrailPeerList *iterator; | ||
1415 | struct GNUNET_PeerIdentity *finger_identity; | ||
1416 | int finger_index; | ||
1468 | 1417 | ||
1469 | /* Check for self message. */ | 1418 | /* Check for self message. */ |
1470 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | 1419 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
1471 | return; | 1420 | return; |
1472 | 1421 | ||
1473 | /* Search for peer to remove in your friend_peermap. */ | 1422 | /* Search for peer to remove in your friend_peermap. */ |
1474 | remove_friend = | 1423 | remove_friend = |
1475 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); | 1424 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); |
1476 | 1425 | ||
@@ -1480,21 +1429,31 @@ handle_core_disconnect (void *cls, | |||
1480 | return; | 1429 | return; |
1481 | } | 1430 | } |
1482 | 1431 | ||
1432 | iterator = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1433 | finger_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
1434 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | ||
1435 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | ||
1436 | { | ||
1437 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (finger_iter, &key_ret, | ||
1438 | (const void **)&remove_finger)) | ||
1439 | { | ||
1440 | iterator = remove_finger->head->next; | ||
1441 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(iterator->peer), &(remove_friend->id))) | ||
1442 | { | ||
1443 | memcpy (finger_identity, &(remove_finger->finger_identity), sizeof (struct GNUNET_PeerIdentity)); | ||
1444 | GNUNET_assert (GNUNET_YES == | ||
1445 | GNUNET_CONTAINER_multipeermap_remove (finger_peermap, | ||
1446 | finger_identity, | ||
1447 | remove_finger)); | ||
1448 | } | ||
1449 | } | ||
1450 | } | ||
1451 | |||
1483 | /* Remove the friend from friend_peermap. */ | 1452 | /* Remove the friend from friend_peermap. */ |
1484 | GNUNET_assert (GNUNET_YES == | 1453 | GNUNET_assert (GNUNET_YES == |
1485 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, | 1454 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, |
1486 | peer, | 1455 | peer, |
1487 | remove_friend)); | 1456 | remove_friend)); |
1488 | |||
1489 | /* If the peer is removed then all the trail which goes through this | ||
1490 | peer also becomes invalid. */ | ||
1491 | /* FIXME: Iterate over finger peermap, get the trail index and find all the | ||
1492 | finger whose trail's first peer was this peer. and remove them from finger | ||
1493 | peermap. Assumption that in send_find_finger_trail we will eventually reach | ||
1494 | to this finger and we will setup up the new trail. | ||
1495 | So, we need a threshold on number of trail thats can go through a node | ||
1496 | so that if that nodes go away then also our system is up and runnning. | ||
1497 | Where can we specify that threshold.*/ | ||
1498 | } | 1457 | } |
1499 | 1458 | ||
1500 | 1459 | ||
@@ -1509,6 +1468,7 @@ core_init (void *cls, | |||
1509 | const struct GNUNET_PeerIdentity *identity) | 1468 | const struct GNUNET_PeerIdentity *identity) |
1510 | { | 1469 | { |
1511 | my_identity = *identity; | 1470 | my_identity = *identity; |
1471 | |||
1512 | } | 1472 | } |
1513 | 1473 | ||
1514 | 1474 | ||
@@ -1565,8 +1525,13 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1565 | return 0; | 1525 | return 0; |
1566 | } | 1526 | } |
1567 | 1527 | ||
1528 | |||
1568 | /** | 1529 | /** |
1569 | * FIXME: For redundant routing, we may start looking for different | 1530 | * FIXME: When we add a successor or predecessor should we check the entry in |
1531 | * finger map index. If we don't replace the old entry then should we notify | ||
1532 | * peer which think it is our predecessor or successor. Or will send verify | ||
1533 | * successor message will handle this case on its own. | ||
1534 | * * FIXME: For redundant routing, we may start looking for different | ||
1570 | * paths to reach to same finger. So, in send_find_finger, we are starting | 1535 | * paths to reach to same finger. So, in send_find_finger, we are starting |
1571 | * the search for trail to a finger, even if we already have found trail to | 1536 | * the search for trail to a finger, even if we already have found trail to |
1572 | * reach to it. There are several reasons for doing so | 1537 | * reach to it. There are several reasons for doing so |
@@ -1576,174 +1541,74 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1576 | * 3. As I don't know how keys are distributed and how put/get will react | 1541 | * 3. As I don't know how keys are distributed and how put/get will react |
1577 | * because of this, I have to think further before implementing it. | 1542 | * because of this, I have to think further before implementing it. |
1578 | * Add an entry in finger table. | 1543 | * Add an entry in finger table. |
1579 | * @param finger Finger to be added to finger table | 1544 | * Add an entry into finger table |
1580 | * @param peer_list peers this request has traversed so far | 1545 | * @param finger_identity Peer identity of finger |
1581 | * @param trail_length Numbers of peers in the trail. | 1546 | * @param finger_trail Trail to reach the finger |
1547 | * @param trail_length Number of peers in the trail. | ||
1548 | * @param finger_map_index Index in finger peer map. | ||
1582 | */ | 1549 | */ |
1583 | static | 1550 | static |
1584 | void finger_table_add (struct GNUNET_PeerIdentity *finger, | 1551 | void finger_table_add (struct GNUNET_PeerIdentity *finger_identity, |
1585 | struct GNUNET_PeerIdentity *peer_list, | 1552 | struct GNUNET_PeerIdentity *finger_trail, |
1586 | unsigned int trail_length, | 1553 | unsigned int trail_length, |
1587 | unsigned int successor_flag, | ||
1588 | unsigned int predecessor_flag, | ||
1589 | unsigned int finger_map_index) | 1554 | unsigned int finger_map_index) |
1590 | { | 1555 | { |
1591 | struct FingerInfo *new_finger_entry; | 1556 | struct FingerInfo *new_finger_entry; |
1592 | unsigned int i = 0; | ||
1593 | /** SUPU: when we add an entry then we should look if | ||
1594 | * we already have an entry for that index. If yes, then | ||
1595 | * 1) if both the finger identity are same, and same first friend, then choose | ||
1596 | * the one with shorter trail length. | ||
1597 | * 2) if the finger identity is different, then keep the one which is closest.*/ | ||
1598 | |||
1599 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (finger_peermap, finger)) | ||
1600 | { | ||
1601 | exit(0); | ||
1602 | #if 0 | ||
1603 | /* Optimization. For the moment we just ignore and do nothing.*/ | ||
1604 | /* We already have an entry for this finger. */ | ||
1605 | struct GNUNET_PeerIdentity *first_friend; | ||
1606 | struct FingerInfo *exisiting_finger_entry; | ||
1607 | |||
1608 | struct TrailPeerList *iterator; | ||
1609 | iterator = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1610 | exisiting_finger_entry = GNUNET_CONTAINER_multipeermap_get(finger_peermap, finger); | ||
1611 | iterator = exisiting_finger_entry->head; | ||
1612 | memcpy (first_friend, &(iterator->peer), sizeof(struct GNUNET_PeerIdentity)); | ||
1613 | |||
1614 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(first_friend, finger)) | ||
1615 | { | ||
1616 | |||
1617 | } | ||
1618 | #endif | ||
1619 | } | ||
1620 | |||
1621 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | ||
1622 | memcpy (&(new_finger_entry->finger_identity), finger, sizeof (struct GNUNET_PeerIdentity)); | ||
1623 | |||
1624 | |||
1625 | /* Insert elements of peer_list into TrailPeerList. */ | ||
1626 | i = 0; | ||
1627 | while (i < trail_length) | ||
1628 | { | ||
1629 | struct TrailPeerList *element; | ||
1630 | element = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
1631 | element->next = NULL; | ||
1632 | element->prev = NULL; | ||
1633 | |||
1634 | memcpy (&(element->peer), &peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
1635 | GNUNET_CONTAINER_DLL_insert_tail(new_finger_entry->head, new_finger_entry->tail, element); | ||
1636 | i++; | ||
1637 | } | ||
1638 | |||
1639 | |||
1640 | new_finger_entry->successor = successor_flag; | ||
1641 | new_finger_entry->predecessor = predecessor_flag; | ||
1642 | new_finger_entry->finger_map_index = finger_map_index; | ||
1643 | new_finger_entry->trail_length = trail_length; | ||
1644 | |||
1645 | |||
1646 | GNUNET_assert (GNUNET_OK == | ||
1647 | GNUNET_CONTAINER_multipeermap_put (finger_peermap, | ||
1648 | &(new_finger_entry->finger_identity), | ||
1649 | new_finger_entry, | ||
1650 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1651 | |||
1652 | /*FIXME: Is it really a good time to call verify successor message. */ | ||
1653 | if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap)) | ||
1654 | { | ||
1655 | verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); | ||
1656 | } | ||
1657 | } | ||
1658 | |||
1659 | |||
1660 | /** | ||
1661 | * FIXME: Also copy the trail list in reverse direction that is the path to | ||
1662 | * reach to your predecessor. | ||
1663 | * Replace your predecessor with new predecessor. | ||
1664 | * @param predecessor My new predecessor | ||
1665 | * @param peer_list Trail list to reach to my new predecessor | ||
1666 | * @param trail_length Number of peers in the trail. | ||
1667 | */ | ||
1668 | static void | ||
1669 | update_predecessor (struct GNUNET_PeerIdentity *predecessor, | ||
1670 | struct GNUNET_PeerIdentity *peer_list, | ||
1671 | unsigned int trail_length) | ||
1672 | { | ||
1673 | struct GNUNET_PeerIdentity *trail_peer_list; | ||
1674 | struct FingerInfo *new_finger_entry; | ||
1675 | struct FingerInfo *finger; | ||
1676 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | 1557 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; |
1677 | struct GNUNET_PeerIdentity key_ret; | 1558 | struct GNUNET_PeerIdentity key_ret; |
1559 | struct FingerInfo *existing_finger; | ||
1678 | int finger_index; | 1560 | int finger_index; |
1679 | int i; | 1561 | int i; |
1680 | int j; | ||
1681 | int flag = 0; | ||
1682 | 1562 | ||
1683 | /* Check if you already have a predecessor. Then remove it and add the new | 1563 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); |
1684 | entry. */ | 1564 | |
1685 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | ||
1686 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | 1565 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) |
1687 | { | 1566 | { |
1688 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (finger_iter, &key_ret, | 1567 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (finger_iter, &key_ret, |
1689 | (const void **)&finger)) | 1568 | (const void **)&existing_finger)) |
1690 | { | 1569 | { |
1691 | if (1 == finger->predecessor) | 1570 | /* If we already have an entry at the finger map index. */ |
1692 | { | 1571 | if ((finger_map_index == existing_finger->finger_map_index)) |
1693 | flag = 1; | ||
1694 | break; | ||
1695 | } | ||
1696 | } | ||
1697 | } | ||
1698 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | ||
1699 | /* check if you come out of the loop or because of the conditoin*/ | ||
1700 | if (flag == 0) | ||
1701 | { | ||
1702 | goto add_new_predecessor; | ||
1703 | } | ||
1704 | else | ||
1705 | { | ||
1706 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(finger_peermap, &(finger->finger_identity))) | ||
1707 | { | ||
1708 | /* compare peer ids of new finger and old finger if they are same don't remove and exit | ||
1709 | if different then remove and exit. */ | ||
1710 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&(finger->finger_identity), predecessor)) | ||
1711 | { | ||
1712 | //goto do_nothing; | ||
1713 | exit(0); | ||
1714 | } | ||
1715 | else | ||
1716 | { | 1572 | { |
1717 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(finger_peermap, &(finger->finger_identity), finger)) | 1573 | /* Check if the finger entry are same. */ |
1574 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&(existing_finger->finger_identity),finger_identity)) | ||
1718 | { | 1575 | { |
1719 | goto add_new_predecessor; | 1576 | /* Compare the trail length. */ |
1577 | if ((trail_length == existing_finger->trail_length)|| | ||
1578 | (trail_length > existing_finger->trail_length)) | ||
1579 | { | ||
1580 | return; | ||
1581 | } | ||
1582 | else if (trail_length < existing_finger->trail_length) | ||
1583 | { | ||
1584 | /* FIXME: As an optimization, when you add limit on trail length | ||
1585 | going through a particular friend, then check if the friend to | ||
1586 | reach the two trails are same or not. If not then choose one | ||
1587 | whose threshold value has not yet reached. Also, think about | ||
1588 | redundant routing, where you want to keep multiple paths | ||
1589 | to reach to the same finger. In that case you should allow multiple | ||
1590 | entries with same finger identity. */ | ||
1591 | if ( GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (finger_peermap, | ||
1592 | &(existing_finger->finger_identity), | ||
1593 | existing_finger)) | ||
1594 | { | ||
1595 | goto add_new_entry; | ||
1596 | } | ||
1597 | } | ||
1720 | } | 1598 | } |
1721 | else | 1599 | else |
1722 | //goto do_nothing; | 1600 | { |
1723 | exit(0); | 1601 | /* FIXME: Here you are if you got different finger identity then one |
1602 | you already have at that index. Then you should choose the | ||
1603 | one which is closest. */ | ||
1604 | } | ||
1724 | } | 1605 | } |
1725 | } | 1606 | } |
1726 | } | 1607 | } |
1727 | 1608 | ||
1728 | add_new_predecessor: | 1609 | add_new_entry: |
1729 | i = trail_length - 1; | ||
1730 | j = 0; | ||
1731 | trail_peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * | ||
1732 | trail_length); | ||
1733 | while (i > 0) | ||
1734 | { | ||
1735 | memcpy( &trail_peer_list[j], &peer_list[i], sizeof (struct GNUNET_PeerIdentity)); | ||
1736 | i--; | ||
1737 | j++; | ||
1738 | } | ||
1739 | memcpy (&trail_peer_list[j], &peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
1740 | |||
1741 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | 1610 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); |
1742 | memcpy (&(new_finger_entry->finger_identity), predecessor, sizeof (struct GNUNET_PeerIdentity)); | 1611 | memcpy (&(new_finger_entry->finger_identity), finger_identity, sizeof (struct GNUNET_PeerIdentity)); |
1743 | new_finger_entry->finger_map_index = 1; | ||
1744 | new_finger_entry->predecessor = 1; | ||
1745 | new_finger_entry->successor = 0; | ||
1746 | new_finger_entry->trail_length = trail_length; | ||
1747 | 1612 | ||
1748 | i = 0; | 1613 | i = 0; |
1749 | while (i < trail_length) | 1614 | while (i < trail_length) |
@@ -1753,12 +1618,29 @@ update_predecessor (struct GNUNET_PeerIdentity *predecessor, | |||
1753 | element->next = NULL; | 1618 | element->next = NULL; |
1754 | element->prev = NULL; | 1619 | element->prev = NULL; |
1755 | 1620 | ||
1756 | memcpy (&(element->peer), &trail_peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | 1621 | memcpy (&(element->peer), &finger_trail[i], sizeof(struct GNUNET_PeerIdentity)); |
1757 | GNUNET_CONTAINER_DLL_insert_tail(new_finger_entry->head, new_finger_entry->tail, element); | 1622 | GNUNET_CONTAINER_DLL_insert_tail(new_finger_entry->head, new_finger_entry->tail, element); |
1758 | i++; | 1623 | i++; |
1759 | } | 1624 | } |
1625 | |||
1626 | new_finger_entry->finger_map_index = finger_map_index; | ||
1627 | new_finger_entry->trail_length = trail_length; | ||
1628 | |||
1629 | /* FIXME: Here we are keeping multiple hashmap option so that there are | ||
1630 | multiple routes to reach to same finger, redundant routing. */ | ||
1631 | GNUNET_assert (GNUNET_OK == | ||
1632 | GNUNET_CONTAINER_multipeermap_put (finger_peermap, | ||
1633 | &(new_finger_entry->finger_identity), | ||
1634 | new_finger_entry, | ||
1635 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
1636 | |||
1637 | if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap) | ||
1638 | && (new_finger_entry->finger_map_index!= 1)) | ||
1639 | { | ||
1640 | verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); | ||
1641 | } | ||
1760 | } | 1642 | } |
1761 | 1643 | ||
1762 | 1644 | ||
1763 | /** | 1645 | /** |
1764 | * Compare two peer identities. | 1646 | * Compare two peer identities. |
@@ -1783,14 +1665,14 @@ compare_peer_id (const void *p1, const void *p2) | |||
1783 | 1665 | ||
1784 | 1666 | ||
1785 | /** | 1667 | /** |
1786 | * Returns the previous element of value in all_known_peers. | 1668 | * Return the previous element of value in all_known_peers. |
1787 | * @param all_known_peers list of all the peers | 1669 | * @param all_known_peers list of all the peers |
1788 | * @param value value we have to search in the all_known_peers. | 1670 | * @param value value we have to search in the all_known_peers. |
1789 | * @return | 1671 | * @return |
1790 | */ | 1672 | */ |
1791 | static struct Sorting_List * | 1673 | static struct Sorting_List * |
1792 | find_closest_successor(struct Sorting_List *all_known_peers, uint64_t value, | 1674 | find_closest_successor(struct Sorting_List *all_known_peers, uint64_t value, |
1793 | unsigned int size) | 1675 | unsigned int size) |
1794 | { | 1676 | { |
1795 | int first; | 1677 | int first; |
1796 | int last; | 1678 | int last; |
@@ -1832,7 +1714,7 @@ find_closest_successor(struct Sorting_List *all_known_peers, uint64_t value, | |||
1832 | * Find closest successor for the value. | 1714 | * Find closest successor for the value. |
1833 | * @param value Value for which we are looking for successor | 1715 | * @param value Value for which we are looking for successor |
1834 | * @param current_destination NULL if my_identity is successor else finger/friend | 1716 | * @param current_destination NULL if my_identity is successor else finger/friend |
1835 | * identity | 1717 | * identity |
1836 | * @param type Next destination type | 1718 | * @param type Next destination type |
1837 | * @return Peer identity of next destination i.e. successor of value. | 1719 | * @return Peer identity of next destination i.e. successor of value. |
1838 | */ | 1720 | */ |
@@ -1908,7 +1790,7 @@ find_successor(uint64_t value, struct GNUNET_PeerIdentity *current_destination, | |||
1908 | 1790 | ||
1909 | /* search value in all_known_peers array. */ | 1791 | /* search value in all_known_peers array. */ |
1910 | successor = find_closest_successor (all_known_peers, value, size); | 1792 | successor = find_closest_successor (all_known_peers, value, size); |
1911 | 1793 | ||
1912 | if (successor->type == MY_ID) | 1794 | if (successor->type == MY_ID) |
1913 | { | 1795 | { |
1914 | *type = MY_ID; | 1796 | *type = MY_ID; |
@@ -1944,9 +1826,7 @@ find_successor(uint64_t value, struct GNUNET_PeerIdentity *current_destination, | |||
1944 | } | 1826 | } |
1945 | 1827 | ||
1946 | 1828 | ||
1947 | /** | 1829 | /** |
1948 | * SUPU: The first element in the trail setup message is your identity. | ||
1949 | * in this function you should increment the trail length. | ||
1950 | * Handle a PeerTrailSetupMessage. | 1830 | * Handle a PeerTrailSetupMessage. |
1951 | * @param cls closure | 1831 | * @param cls closure |
1952 | * @param message message | 1832 | * @param message message |
@@ -1955,23 +1835,20 @@ find_successor(uint64_t value, struct GNUNET_PeerIdentity *current_destination, | |||
1955 | */ | 1835 | */ |
1956 | static int | 1836 | static int |
1957 | handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | 1837 | handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, |
1958 | const struct GNUNET_MessageHeader *message) | 1838 | const struct GNUNET_MessageHeader *message) |
1959 | { | 1839 | { |
1960 | struct PeerTrailSetupMessage *trail_setup; | 1840 | struct PeerTrailSetupMessage *trail_setup; |
1961 | struct GNUNET_PeerIdentity *next_hop; | 1841 | struct GNUNET_PeerIdentity *next_hop; |
1962 | struct FriendInfo *target_friend; | 1842 | struct FriendInfo *target_friend; |
1963 | size_t msize; | 1843 | struct GNUNET_PeerIdentity *current_destination; |
1964 | uint32_t trail_length; | 1844 | struct GNUNET_PeerIdentity *next_peer; |
1845 | struct GNUNET_PeerIdentity *trail_peer_list; | ||
1965 | enum current_destination_type peer_type; | 1846 | enum current_destination_type peer_type; |
1966 | struct GNUNET_PeerIdentity *trail_peer_list; | 1847 | unsigned int trail_length; |
1967 | uint32_t current_trail_index; | 1848 | uint32_t current_trail_index; |
1968 | unsigned int finger_map_index; | 1849 | unsigned int finger_map_index; |
1969 | struct GNUNET_PeerIdentity *next_peer; | 1850 | uint64_t finger_value; |
1970 | unsigned int successor_flag; | 1851 | size_t msize; |
1971 | unsigned int predecessor_flag; | ||
1972 | uint64_t value; | ||
1973 | struct GNUNET_PeerIdentity *current_destination; | ||
1974 | current_destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
1975 | 1852 | ||
1976 | /* parse and validate message. */ | 1853 | /* parse and validate message. */ |
1977 | msize = ntohs (message->size); | 1854 | msize = ntohs (message->size); |
@@ -1981,41 +1858,32 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1981 | return GNUNET_YES; | 1858 | return GNUNET_YES; |
1982 | } | 1859 | } |
1983 | 1860 | ||
1984 | |||
1985 | trail_setup = (struct PeerTrailSetupMessage *) message; | 1861 | trail_setup = (struct PeerTrailSetupMessage *) message; |
1986 | trail_length = ntohl (trail_setup->trail_length); | 1862 | trail_length = ntohl (trail_setup->trail_length); |
1987 | peer_type = ntohl (trail_setup->current_destination_type); | ||
1988 | finger_map_index = ntohl (trail_setup->finger_map_index); | ||
1989 | successor_flag = ntohl (trail_setup->successor_flag); | ||
1990 | predecessor_flag = ntohl (trail_setup->predecessor_flag); | ||
1991 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_setup[1]; | ||
1992 | value = trail_setup->destination_finger; | ||
1993 | 1863 | ||
1994 | if ((msize < | 1864 | if ((msize < |
1995 | sizeof (struct PeerTrailSetupMessage) + | 1865 | sizeof (struct PeerTrailSetupMessage) + |
1996 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || | 1866 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || |
1997 | (trail_length > | 1867 | (trail_length > |
1998 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | 1868 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) |
1999 | { | 1869 | { |
2000 | GNUNET_break_op (0); | 1870 | GNUNET_break_op (0); |
2001 | return GNUNET_YES; | 1871 | return GNUNET_YES; |
2002 | } | 1872 | } |
2003 | 1873 | ||
2004 | GNUNET_STATISTICS_update (GDS_stats, | 1874 | peer_type = ntohl (trail_setup->current_destination_type); |
2005 | gettext_noop ("# TRAIL SETUP requests received"), 1, | 1875 | finger_map_index = ntohl (trail_setup->finger_map_index); |
2006 | GNUNET_NO); | 1876 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_setup[1]; |
2007 | GNUNET_STATISTICS_update (GDS_stats, | 1877 | finger_value = trail_setup->destination_finger; |
2008 | gettext_noop ("# TRAIL SETUP bytes received"), msize, | 1878 | current_destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2009 | GNUNET_NO); | 1879 | memcpy (current_destination, &(trail_setup->current_destination), sizeof (struct GNUNET_PeerIdentity)); |
2010 | 1880 | ||
2011 | if (peer_type == FRIEND) | 1881 | if (peer_type == FRIEND) |
2012 | { | 1882 | { |
2013 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination), | 1883 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination), |
2014 | &my_identity))) | 1884 | &my_identity))) |
2015 | { | 1885 | { |
2016 | next_hop = find_successor (value, | 1886 | next_hop = find_successor (finger_value, current_destination, &(peer_type)); |
2017 | current_destination, | ||
2018 | &(peer_type)); | ||
2019 | } | 1887 | } |
2020 | else | 1888 | else |
2021 | return GNUNET_SYSERR; | 1889 | return GNUNET_SYSERR; |
@@ -2050,20 +1918,16 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2050 | else | 1918 | else |
2051 | { | 1919 | { |
2052 | /* I am the current_destination finger */ | 1920 | /* I am the current_destination finger */ |
2053 | next_hop = find_successor (value, | 1921 | next_hop = find_successor (finger_value, current_destination, &(peer_type)); |
2054 | current_destination, &(peer_type)); | ||
2055 | } | 1922 | } |
2056 | } | 1923 | } |
2057 | 1924 | ||
2058 | /* If you are the next hop, then you are the final destination */ | 1925 | /* If you are the next hop, then you are the final destination */ |
2059 | if (peer_type == MY_ID) | 1926 | if (peer_type == MY_ID) |
2060 | { | 1927 | { |
2061 | /*SUPU: | 1928 | struct GNUNET_PeerIdentity *source; |
2062 | 1. You were the destination of this message which means you were already added | 1929 | source = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2063 | in the peer list by previous calling function. | 1930 | memcpy (source, &(trail_setup->source_peer), sizeof (struct GNUNET_PeerIdentity)); |
2064 | 2. current_trail_index should point to the trail element at which the peer | ||
2065 | which receives this message should look for the next peer to forward the packet | ||
2066 | to. */ | ||
2067 | current_trail_index = trail_length - 2; | 1931 | current_trail_index = trail_length - 2; |
2068 | next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 1932 | next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2069 | memcpy (next_peer, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 1933 | memcpy (next_peer, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
@@ -2073,25 +1937,42 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2073 | if(current_trail_index != 0) | 1937 | if(current_trail_index != 0) |
2074 | current_trail_index = current_trail_index - 1; | 1938 | current_trail_index = current_trail_index - 1; |
2075 | 1939 | ||
2076 | update_predecessor (&(trail_setup->source_peer), trail_peer_list, trail_length ); | 1940 | if (0 == trail_setup->finger_map_index) |
1941 | { | ||
1942 | struct GNUNET_PeerIdentity *new_trail; | ||
1943 | int i; | ||
1944 | int j; | ||
1945 | |||
1946 | i = trail_length - 1; | ||
1947 | j = 0; | ||
1948 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * | ||
1949 | trail_length); | ||
1950 | while (i > 0) | ||
1951 | { | ||
1952 | memcpy( &new_trail[j], &trail_peer_list[i], sizeof (struct GNUNET_PeerIdentity)); | ||
1953 | i--; | ||
1954 | j++; | ||
1955 | } | ||
1956 | memcpy (&new_trail[j], &trail_peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
1957 | finger_table_add (source, new_trail, trail_length, 1); | ||
1958 | } | ||
1959 | |||
2077 | GDS_NEIGHBOURS_send_trail_setup_result (&(trail_setup->source_peer), | 1960 | GDS_NEIGHBOURS_send_trail_setup_result (&(trail_setup->source_peer), |
2078 | &(my_identity), | 1961 | &(my_identity), |
2079 | target_friend, trail_length, | 1962 | target_friend, trail_length, |
2080 | trail_peer_list, current_trail_index, | 1963 | trail_peer_list, current_trail_index, |
2081 | successor_flag, | 1964 | finger_map_index); |
2082 | predecessor_flag, | ||
2083 | finger_map_index); | ||
2084 | 1965 | ||
2085 | return GNUNET_YES; | 1966 | return GNUNET_YES; |
2086 | } | 1967 | } |
2087 | 1968 | ||
2088 | /* Add next hop to list of peers. */ | 1969 | /* Add next hop to list of peers. */ |
2089 | struct GNUNET_PeerIdentity *peer_list; | 1970 | struct GNUNET_PeerIdentity *peer_list; |
2090 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length + 1)); | 1971 | peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length + 1)); |
2091 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); | 1972 | memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); |
2092 | memcpy (&peer_list[trail_length], next_hop, sizeof (struct GNUNET_PeerIdentity)); | 1973 | memcpy (&peer_list[trail_length], next_hop, sizeof (struct GNUNET_PeerIdentity)); |
2093 | trail_length++; | 1974 | trail_length++; |
2094 | 1975 | ||
2095 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 1976 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2096 | 1977 | ||
2097 | if(peer_type == FINGER) | 1978 | if(peer_type == FINGER) |
@@ -2102,12 +1983,9 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2102 | } | 1983 | } |
2103 | 1984 | ||
2104 | GDS_NEIGHBOURS_send_trail_setup (&(trail_setup->source_peer), | 1985 | GDS_NEIGHBOURS_send_trail_setup (&(trail_setup->source_peer), |
2105 | trail_setup->destination_finger, | 1986 | trail_setup->destination_finger, |
2106 | target_friend, | 1987 | current_destination, target_friend, trail_length, |
2107 | trail_setup->trail_length, | 1988 | peer_list, finger_map_index, peer_type); |
2108 | peer_list,trail_setup->successor_flag, | ||
2109 | trail_setup->predecessor_flag, | ||
2110 | finger_map_index); | ||
2111 | 1989 | ||
2112 | return GNUNET_YES; | 1990 | return GNUNET_YES; |
2113 | } | 1991 | } |
@@ -2122,21 +2000,19 @@ return GNUNET_YES; | |||
2122 | */ | 2000 | */ |
2123 | static int | 2001 | static int |
2124 | handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *peer, | 2002 | handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *peer, |
2125 | const struct GNUNET_MessageHeader *message) | 2003 | const struct GNUNET_MessageHeader *message) |
2126 | { | 2004 | { |
2127 | struct PeerTrailSetupResultMessage *trail_result; | 2005 | struct PeerTrailSetupResultMessage *trail_result; |
2128 | size_t msize; | ||
2129 | unsigned int trail_length; | ||
2130 | struct GNUNET_PeerIdentity *trail_peer_list; | 2006 | struct GNUNET_PeerIdentity *trail_peer_list; |
2131 | unsigned int current_trail_index; | ||
2132 | struct GNUNET_PeerIdentity *next_peer; | 2007 | struct GNUNET_PeerIdentity *next_peer; |
2133 | struct FriendInfo *target_friend; | 2008 | struct FriendInfo *target_friend; |
2009 | unsigned int current_trail_index; | ||
2134 | unsigned int finger_map_index; | 2010 | unsigned int finger_map_index; |
2135 | unsigned int successor_flag; | 2011 | unsigned int trail_length; |
2136 | unsigned int predecessor_flag; | 2012 | size_t msize; |
2137 | 2013 | ||
2138 | msize = ntohs (message->size); | 2014 | msize = ntohs (message->size); |
2139 | if (msize < sizeof (struct PeerTrailSetupMessage)) | 2015 | if (msize < sizeof (struct PeerTrailSetupResultMessage)) |
2140 | { | 2016 | { |
2141 | GNUNET_break_op (0); | 2017 | GNUNET_break_op (0); |
2142 | return GNUNET_YES; | 2018 | return GNUNET_YES; |
@@ -2156,19 +2032,14 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2156 | } | 2032 | } |
2157 | 2033 | ||
2158 | current_trail_index = ntohl (trail_result->current_index); | 2034 | current_trail_index = ntohl (trail_result->current_index); |
2159 | successor_flag = ntohl (trail_result->successor_flag); | ||
2160 | predecessor_flag = ntohl (trail_result->predecessor_flag); | ||
2161 | finger_map_index = ntohl (trail_result->finger_map_index); | 2035 | finger_map_index = ntohl (trail_result->finger_map_index); |
2162 | 2036 | ||
2163 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1]; | 2037 | trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1]; |
2164 | 2038 | ||
2165 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->current_destination), | 2039 | if ( 0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->destination_peer), |
2166 | &my_identity))) | ||
2167 | { | ||
2168 | if ( 0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->destination_peer), | ||
2169 | &my_identity))) | 2040 | &my_identity))) |
2170 | { | 2041 | { |
2171 | #if 0 | 2042 | #if 0 |
2172 | /* SUPU: Here I have removed myself from the trail before storing it in | 2043 | /* SUPU: Here I have removed myself from the trail before storing it in |
2173 | th finger table - to save space, but in case of verify successor result | 2044 | th finger table - to save space, but in case of verify successor result |
2174 | the result trail does not contain me, and I will never get the message back. | 2045 | the result trail does not contain me, and I will never get the message back. |
@@ -2185,47 +2056,40 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2185 | i--; | 2056 | i--; |
2186 | } | 2057 | } |
2187 | trail_length = trail_length -1 ; SUPU: As you removed yourself from the trail.*/ | 2058 | trail_length = trail_length -1 ; SUPU: As you removed yourself from the trail.*/ |
2188 | #endif | 2059 | #endif |
2189 | 2060 | ||
2190 | finger_table_add (&(trail_result->finger), trail_peer_list, trail_length, | 2061 | finger_table_add (&(trail_result->finger_identity), trail_peer_list, trail_length, |
2191 | successor_flag, predecessor_flag, | 2062 | finger_map_index); |
2192 | finger_map_index); | ||
2193 | 2063 | ||
2194 | return GNUNET_YES; | 2064 | return GNUNET_YES; |
2195 | } | 2065 | } |
2196 | else | 2066 | else |
2197 | { | 2067 | { |
2198 | next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2068 | next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2199 | memcpy (next_peer, &(trail_peer_list[current_trail_index]), | 2069 | memcpy (next_peer, &(trail_peer_list[current_trail_index]), |
2200 | sizeof (struct GNUNET_PeerIdentity)); | 2070 | sizeof (struct GNUNET_PeerIdentity)); |
2201 | /* SUPU: here current trail index will always be greater than 0. | 2071 | /* SUPU: here current trail index will always be greater than 0. |
2202 | so no need for this check here. trail index = 0, contains the final | 2072 | so no need for this check here. trail index = 0, contains the final |
2203 | destination, and if we are in this loop we have not yet reached the | 2073 | destination, and if we are in this loop we have not yet reached the |
2204 | final destination. */ | 2074 | final destination. */ |
2205 | current_trail_index = current_trail_index - 1; | 2075 | current_trail_index = current_trail_index - 1; |
2206 | 2076 | ||
2207 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); | 2077 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); |
2208 | GNUNET_free (next_peer); | 2078 | GNUNET_free (next_peer); |
2209 | 2079 | ||
2210 | GDS_NEIGHBOURS_send_trail_setup_result (&(trail_result->destination_peer), | 2080 | GDS_NEIGHBOURS_send_trail_setup_result (&(trail_result->destination_peer), |
2211 | &(trail_result->finger), | 2081 | &(trail_result->finger_identity), |
2212 | target_friend, trail_length, | 2082 | target_friend, trail_length, |
2213 | trail_peer_list,current_trail_index, | 2083 | trail_peer_list,current_trail_index, |
2214 | trail_result->successor_flag, | 2084 | finger_map_index); |
2215 | trail_result->predecessor_flag, | ||
2216 | finger_map_index); | ||
2217 | return GNUNET_YES; | 2085 | return GNUNET_YES; |
2218 | } | 2086 | } |
2219 | } | 2087 | |
2220 | else | 2088 | return GNUNET_SYSERR; |
2221 | return GNUNET_SYSERR; | ||
2222 | } | 2089 | } |
2223 | 2090 | ||
2224 | 2091 | ||
2225 | /** | 2092 | /** |
2226 | * SUPU: In this function you don't do anything with trail length | ||
2227 | * You increment the current trail index so that you find the correct | ||
2228 | * peer to send the packet forward. | ||
2229 | * Core handle for p2p verify successor messages. | 2093 | * Core handle for p2p verify successor messages. |
2230 | * @param cls closure | 2094 | * @param cls closure |
2231 | * @param message message | 2095 | * @param message message |
@@ -2237,13 +2101,14 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2237 | const struct GNUNET_MessageHeader *message) | 2101 | const struct GNUNET_MessageHeader *message) |
2238 | { | 2102 | { |
2239 | struct PeerVerifySuccessorMessage *vsm; | 2103 | struct PeerVerifySuccessorMessage *vsm; |
2240 | size_t msize; | ||
2241 | unsigned int trail_length; | ||
2242 | struct GNUNET_PeerIdentity *trail_peer_list; | 2104 | struct GNUNET_PeerIdentity *trail_peer_list; |
2243 | unsigned int current_trail_index; | ||
2244 | struct FriendInfo *target_friend; | 2105 | struct FriendInfo *target_friend; |
2245 | struct GNUNET_PeerIdentity *next_hop; | 2106 | struct GNUNET_PeerIdentity *next_hop; |
2246 | 2107 | struct GNUNET_PeerIdentity *source_peer; | |
2108 | unsigned int trail_length; | ||
2109 | unsigned int current_trail_index; | ||
2110 | size_t msize; | ||
2111 | |||
2247 | msize = ntohs (message->size); | 2112 | msize = ntohs (message->size); |
2248 | if (msize < sizeof (struct PeerVerifySuccessorMessage)) | 2113 | if (msize < sizeof (struct PeerVerifySuccessorMessage)) |
2249 | { | 2114 | { |
@@ -2266,8 +2131,12 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2266 | 2131 | ||
2267 | current_trail_index = ntohl (vsm->current_trail_index); | 2132 | current_trail_index = ntohl (vsm->current_trail_index); |
2268 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; | 2133 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; |
2134 | source_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2135 | memcpy (source_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity)); | ||
2269 | 2136 | ||
2270 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2137 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2138 | |||
2139 | /* SUPU: If I am the destination. */ | ||
2271 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor), | 2140 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor), |
2272 | &my_identity))) | 2141 | &my_identity))) |
2273 | { | 2142 | { |
@@ -2284,14 +2153,16 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2284 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next | 2153 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next |
2285 | (finger_iter,&key_ret,(const void **)&my_predecessor)) | 2154 | (finger_iter,&key_ret,(const void **)&my_predecessor)) |
2286 | { | 2155 | { |
2287 | if(1 == my_predecessor->predecessor) | 2156 | if(1 == my_predecessor->finger_map_index) |
2288 | break; | 2157 | { |
2158 | break; | ||
2159 | } | ||
2289 | } | 2160 | } |
2290 | } | 2161 | } |
2291 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | 2162 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); |
2292 | 2163 | ||
2293 | destination_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2164 | destination_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2294 | memcpy (destination_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity)); | 2165 | memcpy (destination_peer, source_peer, sizeof (struct GNUNET_PeerIdentity)); |
2295 | current_trail_index = trail_length - 2; | 2166 | current_trail_index = trail_length - 2; |
2296 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 2167 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
2297 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2168 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
@@ -2300,13 +2171,51 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2300 | if (current_trail_index != 0) | 2171 | if (current_trail_index != 0) |
2301 | current_trail_index = current_trail_index - 1; | 2172 | current_trail_index = current_trail_index - 1; |
2302 | 2173 | ||
2174 | /*SUPU: Remove this later*/ | ||
2175 | struct GNUNET_PeerIdentity *predecessor; | ||
2176 | predecessor = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
2177 | if (NULL == my_predecessor) | ||
2178 | { | ||
2179 | /* FIXME: Ideally my_predecessor should not be NULL. If some one sent | ||
2180 | me a request to verify it I am the successor or not, then I would have | ||
2181 | added that peer to my_predecessor list. Check trail setup and see if | ||
2182 | you are adding predecessor when you get the request for successor. */ | ||
2183 | #if 0 | ||
2184 | update_predecessor (source_peer, trail_peer_list, trail_length); | ||
2185 | |||
2186 | GDS_NEIGHBOURS_send_verify_successor_result (destination_peer, | ||
2187 | &(my_identity), | ||
2188 | source_peer, | ||
2189 | target_friend, | ||
2190 | trail_peer_list, | ||
2191 | trail_length, | ||
2192 | current_trail_index); | ||
2193 | #endif | ||
2194 | } | ||
2195 | else | ||
2196 | { | ||
2197 | /* FIXME: some times my_predecssor->finger_identity has no valid value. | ||
2198 | Check why?*/ | ||
2199 | memcpy (predecessor, &(my_predecessor->finger_identity), sizeof (struct GNUNET_PeerIdentity)); | ||
2200 | } | ||
2303 | 2201 | ||
2304 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->source_peer), | 2202 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (source_peer, |
2305 | &(my_predecessor->finger_identity)))) | 2203 | &(my_predecessor->finger_identity)))) |
2306 | { | 2204 | { |
2205 | /* SUPU: If source peer is my predecessor .*/ | ||
2206 | GDS_NEIGHBOURS_send_verify_successor_result (destination_peer, | ||
2207 | &(my_identity), | ||
2208 | &(my_predecessor->finger_identity), | ||
2209 | target_friend, | ||
2210 | trail_peer_list, | ||
2211 | trail_length, | ||
2212 | current_trail_index); | ||
2213 | } | ||
2214 | else | ||
2215 | { | ||
2307 | struct GNUNET_PeerIdentity *new_successor_trail; | 2216 | struct GNUNET_PeerIdentity *new_successor_trail; |
2308 | unsigned int new_trail_length; | 2217 | int new_trail_length; |
2309 | unsigned int i; | 2218 | int i; |
2310 | 2219 | ||
2311 | new_trail_length = trail_length + my_predecessor->trail_length - 1; | 2220 | new_trail_length = trail_length + my_predecessor->trail_length - 1; |
2312 | new_successor_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) | 2221 | new_successor_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) |
@@ -2318,6 +2227,7 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2318 | 2227 | ||
2319 | /* Copy the trail from me to my predecessor excluding me. */ | 2228 | /* Copy the trail from me to my predecessor excluding me. */ |
2320 | struct TrailPeerList *iterator; | 2229 | struct TrailPeerList *iterator; |
2230 | iterator = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
2321 | iterator = my_predecessor->head->next; | 2231 | iterator = my_predecessor->head->next; |
2322 | i = trail_length; | 2232 | i = trail_length; |
2323 | while (i < new_trail_length) | 2233 | while (i < new_trail_length) |
@@ -2328,131 +2238,32 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2328 | } | 2238 | } |
2329 | 2239 | ||
2330 | GDS_NEIGHBOURS_send_verify_successor_result (destination_peer, | 2240 | GDS_NEIGHBOURS_send_verify_successor_result (destination_peer, |
2331 | &(my_identity), | 2241 | &(my_identity), |
2332 | &(my_predecessor->finger_identity), | 2242 | &(my_predecessor->finger_identity), |
2333 | target_friend, | 2243 | target_friend, |
2334 | new_successor_trail, | 2244 | new_successor_trail, |
2335 | new_trail_length, | 2245 | new_trail_length, |
2336 | current_trail_index); | 2246 | current_trail_index); |
2337 | } | 2247 | } |
2338 | |||
2339 | GDS_NEIGHBOURS_send_verify_successor_result (destination_peer, | ||
2340 | &(my_identity), | ||
2341 | &(my_predecessor->finger_identity), | ||
2342 | target_friend, | ||
2343 | trail_peer_list, | ||
2344 | trail_length, | ||
2345 | current_trail_index); | ||
2346 | 2248 | ||
2347 | } | 2249 | } |
2348 | else | 2250 | else |
2349 | { | 2251 | { |
2252 | /* If I am not the destination. */ | ||
2350 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 2253 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
2351 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2254 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2352 | GNUNET_free (next_hop); | 2255 | GNUNET_free (next_hop); |
2353 | 2256 | ||
2354 | current_trail_index = current_trail_index + 1; | 2257 | current_trail_index = current_trail_index + 1; |
2355 | 2258 | ||
2356 | GDS_NEIGHBOURS_send_verify_successor(&(vsm->source_peer), | 2259 | GDS_NEIGHBOURS_send_verify_successor(source_peer, &(vsm->successor),target_friend, |
2357 | &(vsm->successor), | 2260 | trail_peer_list, trail_length, current_trail_index); |
2358 | target_friend, | ||
2359 | trail_peer_list, | ||
2360 | trail_length, | ||
2361 | current_trail_index); | ||
2362 | } | 2261 | } |
2363 | return GNUNET_YES; | 2262 | return GNUNET_YES; |
2364 | } | 2263 | } |
2365 | 2264 | ||
2366 | 2265 | ||
2367 | /** | 2266 | /** |
2368 | * Update successor field in finger table with new successor. | ||
2369 | * @param successor New successor which is the predecessor my old successor. | ||
2370 | * @param peer_list Trail list to reach to new successor = trail to reach old | ||
2371 | * successor + trail to reach to new successor from that old successor. | ||
2372 | * @param trail_length Number of peers to reach to the new successor. | ||
2373 | */ | ||
2374 | static void | ||
2375 | update_successor (struct GNUNET_PeerIdentity *successor_identity, | ||
2376 | struct GNUNET_PeerIdentity *peer_list, | ||
2377 | unsigned int trail_length) | ||
2378 | { | ||
2379 | struct FingerInfo *new_finger_entry; | ||
2380 | unsigned int i; | ||
2381 | struct FingerInfo *finger; | ||
2382 | struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; | ||
2383 | struct GNUNET_PeerIdentity key_ret; | ||
2384 | int finger_index; | ||
2385 | int flag = 0; | ||
2386 | |||
2387 | /* Check if you already have a predecessor. Then remove it and add the new | ||
2388 | entry. */ | ||
2389 | finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); | ||
2390 | for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) | ||
2391 | { | ||
2392 | if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (finger_iter, &key_ret, | ||
2393 | (const void **)&finger)) | ||
2394 | { | ||
2395 | if (1 == finger->successor) | ||
2396 | { | ||
2397 | flag = 1; | ||
2398 | break; | ||
2399 | } | ||
2400 | } | ||
2401 | } | ||
2402 | GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter); | ||
2403 | /* check if you come out of the loop or because of the conditoin*/ | ||
2404 | if (flag == 0) | ||
2405 | { | ||
2406 | goto add_new_successor; | ||
2407 | } | ||
2408 | else | ||
2409 | { | ||
2410 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(finger_peermap, &(finger->finger_identity))) | ||
2411 | { | ||
2412 | /* compare peer ids of new finger and old finger if they are same don't remove and exit | ||
2413 | if different then remove and exit. */ | ||
2414 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&(finger->finger_identity), successor_identity)) | ||
2415 | { | ||
2416 | //goto do_nothing; | ||
2417 | exit(0); | ||
2418 | } | ||
2419 | else | ||
2420 | { | ||
2421 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(finger_peermap, &(finger->finger_identity), finger)) | ||
2422 | { | ||
2423 | goto add_new_successor; | ||
2424 | } | ||
2425 | else | ||
2426 | //goto do_nothing; | ||
2427 | exit(0); | ||
2428 | } | ||
2429 | } | ||
2430 | } | ||
2431 | |||
2432 | add_new_successor: | ||
2433 | new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo)); | ||
2434 | new_finger_entry->predecessor = 0; | ||
2435 | new_finger_entry->successor = 1; | ||
2436 | new_finger_entry->trail_length = trail_length; | ||
2437 | new_finger_entry->finger_map_index = 0; | ||
2438 | memcpy (&(new_finger_entry->finger_identity), successor_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
2439 | |||
2440 | i = 0; | ||
2441 | while (i < trail_length) | ||
2442 | { | ||
2443 | struct TrailPeerList *element; | ||
2444 | element = GNUNET_malloc (sizeof (struct TrailPeerList)); | ||
2445 | element->next = NULL; | ||
2446 | element->prev = NULL; | ||
2447 | |||
2448 | memcpy (&(element->peer), &peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
2449 | GNUNET_CONTAINER_DLL_insert_tail(new_finger_entry->head, new_finger_entry->tail, element); | ||
2450 | i++; | ||
2451 | } | ||
2452 | } | ||
2453 | |||
2454 | |||
2455 | /** | ||
2456 | * Core handle for p2p notify new successor messages. | 2267 | * Core handle for p2p notify new successor messages. |
2457 | * @param cls closure | 2268 | * @param cls closure |
2458 | * @param message message | 2269 | * @param message message |
@@ -2464,11 +2275,11 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity | |||
2464 | const struct GNUNET_MessageHeader *message) | 2275 | const struct GNUNET_MessageHeader *message) |
2465 | { | 2276 | { |
2466 | struct PeerNotifyNewSuccessorMessage *nsm; | 2277 | struct PeerNotifyNewSuccessorMessage *nsm; |
2467 | size_t msize; | ||
2468 | unsigned int trail_length; | ||
2469 | struct GNUNET_PeerIdentity *trail_peer_list; | 2278 | struct GNUNET_PeerIdentity *trail_peer_list; |
2470 | unsigned int current_trail_index; | 2279 | unsigned int current_trail_index; |
2471 | 2280 | size_t msize; | |
2281 | unsigned int trail_length; | ||
2282 | |||
2472 | msize = ntohs (message->size); | 2283 | msize = ntohs (message->size); |
2473 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) | 2284 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) |
2474 | { | 2285 | { |
@@ -2495,9 +2306,23 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity | |||
2495 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer), | 2306 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer), |
2496 | &my_identity))) | 2307 | &my_identity))) |
2497 | { | 2308 | { |
2498 | update_predecessor (&(nsm->source_peer), | 2309 | struct GNUNET_PeerIdentity *new_trail; |
2499 | trail_peer_list, | 2310 | int i; |
2500 | trail_length); | 2311 | int j; |
2312 | |||
2313 | i = trail_length - 1; | ||
2314 | j = 0; | ||
2315 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * | ||
2316 | trail_length); | ||
2317 | while (i > 0) | ||
2318 | { | ||
2319 | memcpy( &new_trail[j], &trail_peer_list[i], sizeof (struct GNUNET_PeerIdentity)); | ||
2320 | i--; | ||
2321 | j++; | ||
2322 | } | ||
2323 | memcpy (&new_trail[j], &trail_peer_list[i], sizeof(struct GNUNET_PeerIdentity)); | ||
2324 | finger_table_add (&(nsm->source_peer), new_trail, trail_length, 1); | ||
2325 | |||
2501 | return GNUNET_YES; | 2326 | return GNUNET_YES; |
2502 | } | 2327 | } |
2503 | else | 2328 | else |
@@ -2507,16 +2332,14 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity | |||
2507 | struct GNUNET_PeerIdentity *next_hop; | 2332 | struct GNUNET_PeerIdentity *next_hop; |
2508 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2333 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2509 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 2334 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
2510 | |||
2511 | |||
2512 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2335 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2513 | GNUNET_free (next_hop); | 2336 | GNUNET_free (next_hop); |
2514 | current_trail_index = current_trail_index + 1; | 2337 | current_trail_index = current_trail_index + 1; |
2515 | 2338 | ||
2516 | GDS_NEIGHBOURS_send_notify_new_successor (&(nsm->source_peer), | 2339 | GDS_NEIGHBOURS_send_notify_new_successor (&(nsm->source_peer), |
2517 | &(nsm->destination_peer), | 2340 | &(nsm->destination_peer), |
2518 | target_friend, trail_peer_list, trail_length, | 2341 | target_friend, trail_peer_list, |
2519 | current_trail_index); | 2342 | trail_length, current_trail_index); |
2520 | } | 2343 | } |
2521 | return GNUNET_YES; | 2344 | return GNUNET_YES; |
2522 | } | 2345 | } |
@@ -2534,12 +2357,12 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2534 | const struct GNUNET_MessageHeader *message) | 2357 | const struct GNUNET_MessageHeader *message) |
2535 | { | 2358 | { |
2536 | struct PeerVerifySuccessorResultMessage *vsrm; | 2359 | struct PeerVerifySuccessorResultMessage *vsrm; |
2537 | size_t msize; | ||
2538 | struct FriendInfo *target_friend; | 2360 | struct FriendInfo *target_friend; |
2539 | unsigned int current_trail_index; | ||
2540 | struct GNUNET_PeerIdentity *trail_peer_list; | 2361 | struct GNUNET_PeerIdentity *trail_peer_list; |
2541 | struct GNUNET_PeerIdentity *next_hop; | 2362 | struct GNUNET_PeerIdentity *next_hop; |
2542 | unsigned int trail_length; | 2363 | unsigned int trail_length; |
2364 | unsigned int current_trail_index; | ||
2365 | size_t msize; | ||
2543 | 2366 | ||
2544 | msize = ntohs (message->size); | 2367 | msize = ntohs (message->size); |
2545 | if (msize < sizeof (struct PeerVerifySuccessorResultMessage)) | 2368 | if (msize < sizeof (struct PeerVerifySuccessorResultMessage)) |
@@ -2548,12 +2371,8 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2548 | return GNUNET_YES; | 2371 | return GNUNET_YES; |
2549 | } | 2372 | } |
2550 | 2373 | ||
2551 | /* Again in the function you have the whole trail to reach to the destination. */ | ||
2552 | vsrm = (struct PeerVerifySuccessorResultMessage *) message; | 2374 | vsrm = (struct PeerVerifySuccessorResultMessage *) message; |
2553 | current_trail_index = ntohl (vsrm->current_index); | ||
2554 | trail_length = ntohl (vsrm->trail_length); | 2375 | trail_length = ntohl (vsrm->trail_length); |
2555 | |||
2556 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsrm[1]; | ||
2557 | 2376 | ||
2558 | if ((msize < | 2377 | if ((msize < |
2559 | sizeof (struct PeerVerifySuccessorResultMessage) + | 2378 | sizeof (struct PeerVerifySuccessorResultMessage) + |
@@ -2565,14 +2384,16 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2565 | return GNUNET_YES; | 2384 | return GNUNET_YES; |
2566 | } | 2385 | } |
2567 | 2386 | ||
2387 | current_trail_index = ntohl (vsrm->current_index); | ||
2388 | trail_peer_list = (struct GNUNET_PeerIdentity *) &vsrm[1]; | ||
2389 | |||
2568 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->destination_peer), | 2390 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->destination_peer), |
2569 | &(my_identity)))) | 2391 | &(my_identity)))) |
2570 | { | 2392 | { |
2571 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->my_predecessor), | 2393 | if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->my_predecessor), |
2572 | &(my_identity)))) | 2394 | &(my_identity)))) |
2573 | { | 2395 | { |
2574 | update_successor (&(vsrm->my_predecessor), trail_peer_list, trail_length); | 2396 | finger_table_add (&(vsrm->my_predecessor), trail_peer_list, trail_length, 0); |
2575 | |||
2576 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2397 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2577 | memcpy (next_hop, &trail_peer_list[1], sizeof (struct GNUNET_PeerIdentity)); | 2398 | memcpy (next_hop, &trail_peer_list[1], sizeof (struct GNUNET_PeerIdentity)); |
2578 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2399 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
@@ -2580,26 +2401,25 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2580 | GNUNET_free (next_hop); | 2401 | GNUNET_free (next_hop); |
2581 | 2402 | ||
2582 | GDS_NEIGHBOURS_send_notify_new_successor (&my_identity, &(vsrm->my_predecessor), | 2403 | GDS_NEIGHBOURS_send_notify_new_successor (&my_identity, &(vsrm->my_predecessor), |
2583 | target_friend, trail_peer_list, | 2404 | target_friend, trail_peer_list, |
2584 | trail_length, current_trail_index); | 2405 | trail_length, current_trail_index); |
2585 | } | 2406 | } |
2586 | } | 2407 | } |
2587 | else | 2408 | else |
2588 | { | 2409 | { |
2589 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 2410 | next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
2590 | |||
2591 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); | 2411 | memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); |
2592 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); | 2412 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); |
2593 | GNUNET_free (next_hop); | 2413 | GNUNET_free (next_hop); |
2594 | current_trail_index = current_trail_index - 1; | 2414 | current_trail_index = current_trail_index - 1; |
2595 | 2415 | ||
2596 | GDS_NEIGHBOURS_send_verify_successor_result (&(vsrm->destination_peer), | 2416 | GDS_NEIGHBOURS_send_verify_successor_result (&(vsrm->destination_peer), |
2597 | &(vsrm->source_successor), | 2417 | &(vsrm->source_successor), |
2598 | &(vsrm->my_predecessor), | 2418 | &(vsrm->my_predecessor), |
2599 | target_friend, | 2419 | target_friend, |
2600 | trail_peer_list, | 2420 | trail_peer_list, |
2601 | trail_length, | 2421 | trail_length, |
2602 | current_trail_index); | 2422 | current_trail_index); |
2603 | } | 2423 | } |
2604 | return GNUNET_YES; | 2424 | return GNUNET_YES; |
2605 | } | 2425 | } |
@@ -2622,8 +2442,8 @@ GDS_NEIGHBOURS_init() | |||
2622 | {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_NEW_SUCCESSOR, 0}, | 2442 | {&handle_dht_p2p_notify_new_successor, GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_NEW_SUCCESSOR, 0}, |
2623 | {NULL, 0, 0} | 2443 | {NULL, 0, 0} |
2624 | }; | 2444 | }; |
2625 | 2445 | ||
2626 | 2446 | ||
2627 | /*TODO: What is ATS? Why do we need it? */ | 2447 | /*TODO: What is ATS? Why do we need it? */ |
2628 | atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); | 2448 | atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); |
2629 | core_api = | 2449 | core_api = |
@@ -2654,19 +2474,11 @@ GDS_NEIGHBOURS_done () | |||
2654 | GNUNET_ATS_performance_done (atsAPI); | 2474 | GNUNET_ATS_performance_done (atsAPI); |
2655 | atsAPI = NULL; | 2475 | atsAPI = NULL; |
2656 | 2476 | ||
2657 | /* FIXME: In case of friends, every time we are disconnected from a friend | ||
2658 | we remove it from friend table. So, this assertion works for friend. | ||
2659 | But in case of finger_peermap, we never remove any entry from our | ||
2660 | finger peermap. So, either when we remove the friend from friend peermap,then | ||
2661 | I remove all the finger for which that friend was the first trail and leave | ||
2662 | it on send_find_finger_trail to eventually find path to that finger. In that | ||
2663 | case may be assertion for finger peermap will also succed. Or else if | ||
2664 | peermap are not empty check it and empty it and then destroy because | ||
2665 | multipeermpa_destroy does not free individual entries. */ | ||
2666 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)); | 2477 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)); |
2667 | GNUNET_CONTAINER_multipeermap_destroy (friend_peermap); | 2478 | GNUNET_CONTAINER_multipeermap_destroy (friend_peermap); |
2668 | friend_peermap = NULL; | 2479 | friend_peermap = NULL; |
2669 | 2480 | ||
2481 | |||
2670 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (finger_peermap)); | 2482 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (finger_peermap)); |
2671 | GNUNET_CONTAINER_multipeermap_destroy (finger_peermap); | 2483 | GNUNET_CONTAINER_multipeermap_destroy (finger_peermap); |
2672 | finger_peermap = NULL; | 2484 | finger_peermap = NULL; |
@@ -2677,6 +2489,7 @@ GDS_NEIGHBOURS_done () | |||
2677 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; | 2489 | find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK; |
2678 | } | 2490 | } |
2679 | 2491 | ||
2492 | |||
2680 | if (GNUNET_SCHEDULER_NO_TASK != verify_successor) | 2493 | if (GNUNET_SCHEDULER_NO_TASK != verify_successor) |
2681 | { | 2494 | { |
2682 | GNUNET_SCHEDULER_cancel (verify_successor); | 2495 | GNUNET_SCHEDULER_cancel (verify_successor); |
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c index 5830dc9f8..d8912b54b 100644 --- a/src/dht/gnunet-service-xdht_routing.c +++ b/src/dht/gnunet-service-xdht_routing.c | |||
@@ -52,17 +52,17 @@ struct RoutingTrail | |||
52 | /** | 52 | /** |
53 | * Source peer . | 53 | * Source peer . |
54 | */ | 54 | */ |
55 | struct GNUNET_PeerIdentity *source; | 55 | struct GNUNET_PeerIdentity source; |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Destination peer. | 58 | * Destination peer. |
59 | */ | 59 | */ |
60 | struct GNUNET_PeerIdentity *destination; | 60 | struct GNUNET_PeerIdentity destination; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * The peer to which this request should be passed to. | 63 | * The peer to which this request should be passed to. |
64 | */ | 64 | */ |
65 | struct GNUNET_PeerIdentity *next_hop; | 65 | struct GNUNET_PeerIdentity next_hop; |
66 | 66 | ||
67 | }; | 67 | }; |
68 | 68 | ||
@@ -91,17 +91,16 @@ GDS_ROUTING_add (struct GNUNET_PeerIdentity *source, | |||
91 | 91 | ||
92 | /* If dest is already present in the routing table, then exit.*/ | 92 | /* If dest is already present in the routing table, then exit.*/ |
93 | if (GNUNET_YES == | 93 | if (GNUNET_YES == |
94 | GNUNET_CONTAINER_multipeermap_contains (routing_table, | 94 | GNUNET_CONTAINER_multipeermap_contains (routing_table, dest)) |
95 | dest)) | ||
96 | { | 95 | { |
97 | GNUNET_break (0); | 96 | GNUNET_break (0); |
98 | return; | 97 | return; |
99 | } | 98 | } |
100 | 99 | ||
101 | new_routing_entry = GNUNET_malloc (sizeof (struct RoutingTrail)); | 100 | new_routing_entry = GNUNET_malloc (sizeof (struct RoutingTrail)); |
102 | new_routing_entry->source = source; | 101 | memcpy (&(new_routing_entry->source) , source, sizeof (struct GNUNET_PeerIdentity)); |
103 | new_routing_entry->next_hop = next_hop; | 102 | memcpy (&(new_routing_entry->next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity)); |
104 | new_routing_entry->destination = dest; | 103 | memcpy (&(new_routing_entry->destination), dest, sizeof (struct GNUNET_PeerIdentity)); |
105 | 104 | ||
106 | GNUNET_assert (GNUNET_OK == | 105 | GNUNET_assert (GNUNET_OK == |
107 | GNUNET_CONTAINER_multipeermap_put (routing_table, | 106 | GNUNET_CONTAINER_multipeermap_put (routing_table, |
@@ -124,7 +123,7 @@ GDS_ROUTING_search(struct GNUNET_PeerIdentity *source_peer, | |||
124 | if(trail == NULL) | 123 | if(trail == NULL) |
125 | return NULL; | 124 | return NULL; |
126 | 125 | ||
127 | return trail->next_hop; | 126 | return &(trail->next_hop); |
128 | } | 127 | } |
129 | 128 | ||
130 | 129 | ||