aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-03-06 19:14:46 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-03-06 19:14:46 +0000
commit25ccd453b45a0f73008e414d6d4f8c34f6f8d779 (patch)
tree2591efb9e5f85d2e69eac13bba70322b0a76ef3e /src/dht
parentc3e0eb9e5cbc2a3212fb22e39c8fa4749fdee396 (diff)
downloadgnunet-25ccd453b45a0f73008e414d6d4f8c34f6f8d779.tar.gz
gnunet-25ccd453b45a0f73008e414d6d4f8c34f6f8d779.zip
- verify_successor
- 64 bit finger identifier - predecessor flag
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c737
1 files changed, 518 insertions, 219 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index cb1af96c3..b0eb08fd1 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -50,12 +50,17 @@
50 50
51 51
52/* FIXME: 52/* FIXME:
53 1. Add content and route replication later. 53 * 1. do we need some mechanism to check if we already have found trail to
54 *2. Algorithm to shorten the trail length - one possible solution could be 54 * our finger at a particular index. also real finger identifier that we
55 * were looking for and successor it that we got. and whats the benefit of sending
56 * 64 bit finger for searching? can we just send gnuent_peeridentity finger id
57 * and only in find_successor we give 64 bit.
58 * 2. Think of better names for variable especially for variables of type
59 * uint64_t
60 * 3. Add content and route replication later.
61 * 4. Algorithm to shorten the trail length - one possible solution could be
55 * when we are in trail seutp result part. each peer in the trail check if any of 62 * when we are in trail seutp result part. each peer in the trail check if any of
56 * the corresponding peers is its friend list. Then it can shortcut the path. 63 * the corresponding peers is its friend list. Then it can shortcut the path.
57 * But this will have O(n) run time at each peer, where n = trail_length.\
58 * or rather O(n)+O(n-1)+..O(1) =O(n).
59 * 4. As we start looking for finger from i = 0, using this parameter to 64 * 4. As we start looking for finger from i = 0, using this parameter to
60 * generate random value does not look smart in send_find_finger_trail_message. 65 * generate random value does not look smart in send_find_finger_trail_message.
61 * 6. Need to add a new task, fix fingers. For node join/leave, we need to 66 * 6. Need to add a new task, fix fingers. For node join/leave, we need to
@@ -63,6 +68,10 @@
63 * and change our finger table. 68 * and change our finger table.
64 * 7. Should we look for fingers one by one in send_find_finger_trail_setup 69 * 7. Should we look for fingers one by one in send_find_finger_trail_setup
65 * 8. Change the message is gnunet_protocols.h 70 * 8. Change the message is gnunet_protocols.h
71 * 9. Can we just send the whole peer list as array for verify successor
72 * and verify successor result instead of the way in which we send in peertrailmessage.
73 * 10. I have added a new field trail length in finger info. so in finger_table_add
74 * find this value to be added.
66 */ 75 */
67 76
68 77
@@ -80,12 +89,12 @@
80/** 89/**
81 * How long at least to wait before sending another find finger trail request. 90 * How long at least to wait before sending another find finger trail request.
82 */ 91 */
83#define DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 92#define DHT_MINIMUM_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
84 93
85/** 94/**
86 * How long at most to wait before sending another find finger trail request. 95 * How long at most to wait before sending another find finger trail request.
87 */ 96 */
88#define DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10) 97#define DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10)
89 98
90/** 99/**
91 * FIXME: Currently used in GDS_NEIGHBOURS_handle_trail_setup. 100 * FIXME: Currently used in GDS_NEIGHBOURS_handle_trail_setup.
@@ -261,6 +270,7 @@ struct PeerGetMessage
261 */ 270 */
262enum current_destination_type 271enum current_destination_type
263{ 272{
273
264 /* Friend */ 274 /* Friend */
265 FRIEND , 275 FRIEND ,
266 276
@@ -271,12 +281,14 @@ enum current_destination_type
271 MY_ID 281 MY_ID
272}; 282};
273 283
284
274/** 285/**
275 * P2P Trail setup message 286 * P2P Trail setup message
276 * TODO: Take reference from put_path and get_path to understand how to use size of trail list. 287 * TODO: Take reference from put_path and get_path to understand how to use size of trail list.
277 */ 288 */
278struct PeerTrailSetupMessage 289struct PeerTrailSetupMessage
279{ 290{
291
280 /** 292 /**
281 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP 293 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP
282 */ 294 */
@@ -288,6 +300,8 @@ struct PeerTrailSetupMessage
288 struct GNUNET_PeerIdentity source_peer; 300 struct GNUNET_PeerIdentity source_peer;
289 301
290 /** 302 /**
303 * FIXME: Do we need to store the real finger identifier we were searching
304 * for in our finger table. Whats the use of storing it if any?
291 * As we are not sending any hello messages to this destination 305 * As we are not sending any hello messages to this destination
292 * finger, we are only searching for it, we can just send 64 bit. 306 * finger, we are only searching for it, we can just send 64 bit.
293 * Finger id to which we want to set up the trail to. 307 * Finger id to which we want to set up the trail to.
@@ -305,6 +319,11 @@ struct PeerTrailSetupMessage
305 unsigned int successor_flag; 319 unsigned int successor_flag;
306 320
307 /** 321 /**
322 * If set to 1, then we are looking for trail to our immediate predecessor.
323 */
324 unsigned int predecessor_flag;
325
326 /**
308 * If the message is forwarded to finger or friend. 327 * If the message is forwarded to finger or friend.
309 */ 328 */
310 enum current_destination_type current_destination_type; 329 enum current_destination_type current_destination_type;
@@ -321,41 +340,97 @@ struct PeerTrailSetupMessage
321 */ 340 */
322 uint32_t trail_length GNUNET_PACKED; 341 uint32_t trail_length GNUNET_PACKED;
323 342
324 /* FIXME: Add this field later.
325 * The finger index in finger map.
326 unsigned int finger_index;*/
327
328}; 343};
329 344
345
330/** 346/**
331 * 347 * P2P verify successor message.
332 */ 348 */
333struct PeerVerifySuccessor 349struct PeerVerifySuccessorMessage
334{ 350{
335 351
352 /**
353 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR
354 */
355 struct GNUNET_MessageHeader header;
356
357 /**
358 * Source peer which wants to verify its successor.
359 */
360 struct GNUNET_PeerIdentity source_peer;
361
362 /**
363 * Identity of our current successor.
364 */
365 struct GNUNET_PeerIdentity successor;
366
367 /**
368 * Total number of peers in trail.
369 */
370 unsigned int trail_length;
371
372 /**
373 * The current index in trail for next destination to send this message to.
374 */
375 unsigned int current_index;
376
336}; 377};
337 378
338 379
339/** 380/**
340 * 381 *
341 */ 382 */
342struct PeerVerifySuccessorResult 383struct PeerVerifySuccessorResultMessage
343{ 384{
344 385
386 /**
387 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR_RESULT
388 */
389 struct GNUNET_MessageHeader header;
390
391 /**
392 * Destination peer which send the request to verify its successor.
393 */
394 struct GNUNET_PeerIdentity destination_peer;
395
396 /**
397 * Identity of successor to which PeerVerifySuccessorMessage was sent.
398 */
399 struct GNUNET_PeerIdentity source_successor;
400
401 /**
402 * source_successor's predecessor
403 */
404 struct GNUNET_PeerIdentity my_predecessor;
405
406 /**
407 * Total number of peers in trail.
408 */
409 unsigned int trail_length;
410
411 /**
412 * The current index in trail for next destination to send this message to.
413 */
414 unsigned int current_index;
415
345}; 416};
346 417
347/** 418/**
348 * 419 *
349 */ 420 */
350struct PeerNotifyNewSuccessor 421struct PeerNotifyNewSuccessorMessage
351{ 422{
352 423
353}; 424};
354/** 425
426
427/**FIXME: Here we can keep the whole list inside the message instead of attaching
428 * it all the time as the list remains constant all the time.
355 * P2P Trail setup Result message 429 * P2P Trail setup Result message
356 */ 430 */
357struct PeerTrailSetupResultMessage 431struct PeerTrailSetupResultMessage
358{ 432{
433
359 /** 434 /**
360 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_RESULT_SETUP 435 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_RESULT_SETUP
361 */ 436 */
@@ -388,6 +463,11 @@ struct PeerTrailSetupResultMessage
388 unsigned int successor_flag; 463 unsigned int successor_flag;
389 464
390 /** 465 /**
466 * If set to 1, then this trail is the trail to predecessor of our finger.
467 */
468 unsigned int predecessor_flag;
469
470 /**
391 * Number of entries in trail list. 471 * Number of entries in trail list.
392 * FIXME: Is this data type correct? 472 * FIXME: Is this data type correct?
393 * FIXME: Is usage of GNUNET_PACKED correct? 473 * FIXME: Is usage of GNUNET_PACKED correct?
@@ -457,7 +537,9 @@ struct TrailPeerList
457}; 537};
458 538
459 539
460/** 540/** FIXME:
541 * 1.Previously I have added the field successor and predecessor of a friend.
542 * But whats the use and is it even possible to have those values.
461 * Entry in friend_peermap. 543 * Entry in friend_peermap.
462 */ 544 */
463struct FriendInfo 545struct FriendInfo
@@ -473,16 +555,6 @@ struct FriendInfo
473 unsigned int pending_count; 555 unsigned int pending_count;
474 556
475 /** 557 /**
476 * Successor of this finger.
477 */
478 struct GNUNET_PeerIdentity successor_identity;
479
480 /**
481 * Predecessor of this finger.
482 */
483 struct GNUNET_PeerIdentity predecessor_identity;
484
485 /**
486 * Head of pending messages to be sent to this peer. 558 * Head of pending messages to be sent to this peer.
487 */ 559 */
488 struct P2PPendingMessage *head; 560 struct P2PPendingMessage *head;
@@ -493,7 +565,6 @@ struct FriendInfo
493 struct P2PPendingMessage *tail; 565 struct P2PPendingMessage *tail;
494 566
495 /** 567 /**
496 * TODO - How and where to use this?
497 * Core handle for sending messages to this peer. 568 * Core handle for sending messages to this peer.
498 */ 569 */
499 struct GNUNET_CORE_TransmitHandle *th; 570 struct GNUNET_CORE_TransmitHandle *th;
@@ -502,17 +573,12 @@ struct FriendInfo
502 573
503 574
504/** 575/**
576 * FIXME: We can also use an enum to say if its pred/suc/finger
505 * FIXME: As in chord , where we store the actual finger identity we were looking 577 * FIXME: As in chord , where we store the actual finger identity we were looking
506 * for and the real id which we got as successor. If we want to store like that 578 * for and the real id which we got as successor. If we want to store like that
507 * then we will need to add a new field and search actual peer id. 579 * then we will need to add a new field and search actual peer id.
508 * FIXME: Should we use another PeerIdentity which is smaller 580 * FIXME: Should we use another PeerIdentity which is smaller
509 * than 256 bits while storing. 581 * than 256 bits while storing.
510 * SUPU
511 * finger_identity is the actual finger that we were looking for.
512 * successor is the peer id which is our finger in place of finger_identity
513 * that we were actually looking for. It may happen that finger_identity
514 * was not in the network and we found the successor closest to that
515 * finger_identity.
516 * Predcessor is needed in case of node join/fail. 582 * Predcessor is needed in case of node join/fail.
517 * Entry in finger_peermap. 583 * Entry in finger_peermap.
518 */ 584 */
@@ -527,24 +593,31 @@ struct FingerInfo
527 * If 1, then this finger entry is first finger /successor of the peer. 593 * If 1, then this finger entry is first finger /successor of the peer.
528 */ 594 */
529 unsigned int successor; 595 unsigned int successor;
596
530 /** 597 /**
531 * List of peers in the trail. 598 * If 1, then this finger entry is first predecessor of the peer.
532 */ 599 */
533 const struct GNUNET_PeerIdentity *trail_peer_list; 600 unsigned int predecessor;
601
602 /**
603 * Total number of entries in trail.
604 */
605 unsigned int trail_length;
606
607 /**
608 * List of peers in the trail to reach this finger.
609 */
610 struct GNUNET_PeerIdentity *trail_peer_list;
611
534}; 612};
535 613
614
536/** 615/**
537 * Task that sends FIND FINGER TRAIL requests. 616 * Task that sends FIND FINGER TRAIL requests.
538 */ 617 */
539static GNUNET_SCHEDULER_TaskIdentifier find_finger_trail_task; 618static GNUNET_SCHEDULER_TaskIdentifier find_finger_trail_task;
540 619
541/** 620/**
542 * FIXME: As we should check for our immediate successor
543 * in case of node join/fail, the immediate successor will change.
544 * Hence we define a process which will be scheduled in regular interval.
545 * But you should schedule this process once you have found your successor.
546 * so, in finger_table_add_entry, when finger_peermap is size 1 then start
547 * this task, and periodically call it within it self like find_finger_trail_setup
548 * 621 *
549 * Task that periodically checks for the immediate successor. 622 * Task that periodically checks for the immediate successor.
550 */ 623 */
@@ -556,12 +629,6 @@ static GNUNET_SCHEDULER_TaskIdentifier verify_successor;
556static struct GNUNET_PeerIdentity my_identity; 629static struct GNUNET_PeerIdentity my_identity;
557 630
558/** 631/**
559 * FIXME: Not used anywhere in the code yet.
560 * Hash of the identity of this peer.
561 */
562static struct GNUNET_HashCode my_identity_hash;
563
564/**
565 * Hash map of all the friends of a peer 632 * Hash map of all the friends of a peer
566 */ 633 */
567static struct GNUNET_CONTAINER_MultiPeerMap *friend_peermap; 634static struct GNUNET_CONTAINER_MultiPeerMap *friend_peermap;
@@ -583,6 +650,7 @@ static struct GNUNET_ATS_PerformanceHandle *atsAPI;
583static struct GNUNET_CORE_Handle *core_api; 650static struct GNUNET_CORE_Handle *core_api;
584 651
585/** 652/**
653 * FIXME: Is it safe to assume its initialized to 0 by default.
586 * The current finger index that we have found trail to. 654 * The current finger index that we have found trail to.
587 */ 655 */
588static unsigned int current_finger_index; 656static unsigned int current_finger_index;
@@ -711,15 +779,16 @@ GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer,
711 struct FriendInfo *current_destination, 779 struct FriendInfo *current_destination,
712 unsigned int trail_length, 780 unsigned int trail_length,
713 struct GNUNET_PeerIdentity *trail_peer_list, 781 struct GNUNET_PeerIdentity *trail_peer_list,
714 unsigned int successor_flag) 782 unsigned int successor_flag,
783 unsigned int predecessor_flag)
715{ 784{
716 struct P2PPendingMessage *pending; 785 struct P2PPendingMessage *pending;
717 struct PeerTrailSetupMessage *tsm; 786 struct PeerTrailSetupMessage *tsm;
718 struct GNUNET_PeerIdentity *peer_list; 787 struct GNUNET_PeerIdentity *peer_list;
719 size_t msize; 788 size_t msize;
720 789
721 msize = sizeof(struct PeerTrailSetupMessage) + 790 msize = sizeof (struct PeerTrailSetupMessage) +
722 (trail_length * sizeof(struct GNUNET_PeerIdentity)); 791 (trail_length * sizeof (struct GNUNET_PeerIdentity));
723 792
724 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 793 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
725 { 794 {
@@ -740,16 +809,20 @@ GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer,
740 pending->msg = &tsm->header; 809 pending->msg = &tsm->header;
741 tsm->header.size = htons (msize); 810 tsm->header.size = htons (msize);
742 tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); 811 tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP);
743 memcpy(&(tsm->destination_finger), destination_finger, sizeof (uint64_t)); //FIXME: Is this copy correct? 812 memcpy (&(tsm->destination_finger), destination_finger, sizeof (uint64_t));
744 memcpy(&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); 813 memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity));
745 memcpy(&(tsm->current_destination),&(current_destination->id), sizeof (struct GNUNET_PeerIdentity)); 814 memcpy (&(tsm->current_destination),&(current_destination->id),
815 sizeof (struct GNUNET_PeerIdentity));
746 tsm->current_destination_type = htonl(FRIEND); 816 tsm->current_destination_type = htonl(FRIEND);
747 tsm->trail_length = htonl(trail_length); 817 tsm->trail_length = htonl(trail_length);
748 if(successor_flag == 1) 818 if(successor_flag == 1)
749 tsm->successor_flag = 1; 819 tsm->successor_flag = 1;
820 if(predecessor_flag == 1)
821 tsm->predecessor_flag = 1;
822
750 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); 823 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length);
751 peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; 824 peer_list = (struct GNUNET_PeerIdentity *) &tsm[1];
752 memcpy(peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); 825 memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity));
753 826
754 GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending); 827 GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending);
755 current_destination->pending_count++; 828 current_destination->pending_count++;
@@ -757,7 +830,8 @@ GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer,
757 830
758} 831}
759 832
760/** 833/**FIXME: As we are having a fixed list of trail peer list we can just
834 * store inside the message instead of attaching it all the time.
761 * Handle a tail setup result message. 835 * Handle a tail setup result message.
762 * @param destination_peer Peer which will get the trail to one of its finger. 836 * @param destination_peer Peer which will get the trail to one of its finger.
763 * @param source_finger Peer to which the trail has been setup to. 837 * @param source_finger Peer to which the trail has been setup to.
@@ -767,21 +841,22 @@ GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer,
767 * @param current_trail_index Index in trail_peer_list. 841 * @param current_trail_index Index in trail_peer_list.
768 */ 842 */
769void 843void
770GDS_NEIGHBOURS_handle_trail_setup_result(struct GNUNET_PeerIdentity *destination_peer, 844GDS_NEIGHBOURS_handle_trail_setup_result (struct GNUNET_PeerIdentity *destination_peer,
771 struct GNUNET_PeerIdentity *source_finger, 845 struct GNUNET_PeerIdentity *source_finger,
772 struct FriendInfo *current_destination, 846 struct FriendInfo *current_destination,
773 unsigned int trail_length, 847 unsigned int trail_length,
774 const struct GNUNET_PeerIdentity *trail_peer_list, 848 const struct GNUNET_PeerIdentity *trail_peer_list,
775 unsigned int current_trial_index, 849 unsigned int current_trail_index,
776 unsigned int successor_flag) 850 unsigned int successor_flag,
851 unsigned int predecessor_flag)
777{ 852{
778 struct P2PPendingMessage *pending; 853 struct P2PPendingMessage *pending;
779 struct PeerTrailSetupResultMessage *tsrm; 854 struct PeerTrailSetupResultMessage *tsrm;
780 struct GNUNET_PeerIdentity *peer_list; 855 struct GNUNET_PeerIdentity *peer_list;
781 size_t msize; 856 size_t msize;
782 857
783 msize = sizeof(struct PeerTrailSetupMessage) + 858 msize = sizeof (struct PeerTrailSetupResultMessage) +
784 (trail_length * sizeof(struct GNUNET_PeerIdentity)); 859 (trail_length * sizeof (struct GNUNET_PeerIdentity));
785 860
786 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 861 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
787 { 862 {
@@ -802,14 +877,15 @@ GDS_NEIGHBOURS_handle_trail_setup_result(struct GNUNET_PeerIdentity *destination
802 pending->msg = &tsrm->header; 877 pending->msg = &tsrm->header;
803 tsrm->header.size = htons (msize); 878 tsrm->header.size = htons (msize);
804 tsrm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT); 879 tsrm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT);
805 memcpy(&(tsrm->current_destination), &(current_destination->id), sizeof(struct GNUNET_PeerIdentity)); 880 memcpy (&(tsrm->current_destination), &(current_destination->id), sizeof(struct GNUNET_PeerIdentity));
806 memcpy(&(tsrm->destination_peer), destination_peer, sizeof(struct GNUNET_PeerIdentity)); 881 memcpy (&(tsrm->destination_peer), destination_peer, sizeof(struct GNUNET_PeerIdentity));
807 memcpy(&(tsrm->finger), source_finger, sizeof(struct GNUNET_PeerIdentity)); 882 memcpy (&(tsrm->finger), source_finger, sizeof(struct GNUNET_PeerIdentity));
808 tsrm->trail_length = htonl(trail_length); 883 tsrm->trail_length = htonl (trail_length);
809 tsrm->current_index = htonl(current_trial_index); 884 tsrm->current_index = htonl (current_trail_index);
810 tsrm->successor_flag = htonl(successor_flag); 885 tsrm->successor_flag = htonl (successor_flag);
886 tsrm->predecessor_flag = htonl (predecessor_flag);
811 peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; 887 peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1];
812 memcpy(peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); 888 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
813 889
814 /* Send the message to chosen friend. */ 890 /* Send the message to chosen friend. */
815 GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending); 891 GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending);
@@ -818,27 +894,83 @@ GDS_NEIGHBOURS_handle_trail_setup_result(struct GNUNET_PeerIdentity *destination
818} 894}
819 895
820 896
821/** 897/**FIXME: Calling function should provide the current destination
898 * and also should compute the new current_trail_index. Also you should add
899 * yourself to the list of peers and increment the length correctly. its
900 * responsibility of send_verify_successor_message and handle_verify_succesor_message.
822 * This function is called from send_verify_successor_message funciton 901 * This function is called from send_verify_successor_message funciton
823 * and handle_dht_p2p_verify_successor. 902 * and handle_dht_p2p_verify_successor.
824 * Construct a PeerVerifySuccessor message and send it to friend. 903 * Construct a PeerVerifySuccessor message and send it to friend.
825 */ 904 */
826void GDS_NEIGUBOURS_handle_verify_successor() 905void GDS_NEIGUBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_peer,
906 struct GNUNET_PeerIdentity *successor,
907 struct FriendInfo *current_destination,
908 struct GNUNET_PeerIdentity *trail_peer_list,
909 unsigned int trail_length,
910 unsigned int current_trail_index)
827{ 911{
828 /* In this funciton, you receive 912 struct PeerVerifySuccessorMessage *vsm;
829 1. successor 913 struct P2PPendingMessage *pending;
830 2. trial to reach that successor 914 struct GNUNET_PeerIdentity *peer_list;
831 3. trail_length. 915 size_t msize;
832 4. current trail index --> this gives the next_hop on whose pending queue you should 916
833 add the message. */ 917 msize = sizeof (struct PeerVerifySuccessorMessage) +
918 (trail_length * sizeof(struct GNUNET_PeerIdentity));
919
920 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
921 {
922 GNUNET_break (0);
923 return;
924 }
925
926 if (current_destination->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
927 {
928 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
929 1, GNUNET_NO);
930 }
931
932 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
933 pending->importance = 0; /* FIXME */
934 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
935 vsm = (struct PeerVerifySuccessorMessage *) &pending[1];
936 pending->msg = &vsm->header;
937 vsm->header.size = htons (msize);
938 vsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR);
939 memcpy (&(vsm->successor), successor, sizeof (struct GNUNET_PeerIdentity));
940 memcpy (&(vsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity));
941 vsm->trail_length = htonl (trail_length);
942 vsm->current_index = htonl (current_trail_index);
943
944 peer_list = (struct GNUNET_PeerIdentity *) &vsm[1];
945 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
946
947 /* Send the message to chosen friend. */
948 GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending);
949 current_destination->pending_count++;
950 process_friend_queue (current_destination);
951
834} 952}
835 953
836 954
837/** 955/**FIXME:
838 * this function will be called by destination successor. 956 * 1. In this function we don't want the trail. so instead of maintaing the trail
957 * length and current_trail_index, we can just remove all the elements form trail list
958 * and current_destination = last element of trail list.
959 * 1. Responsiblity of calling function to provide new current destination.
960 * and correct current_trail_index.
961 * this function will be called by destination successor. and each peer
962 * which is in the trail to reach to the peer. as successor changed destination
963 * peer may have replaced the entry in its finger table. so you have to use the
964 * trial provided by source peer and so you should have source id in peerverifysuccessor
839 * Construct a PeerVerifySuccessorResult message and send it to friend. 965 * Construct a PeerVerifySuccessorResult message and send it to friend.
840 */ 966 */
841void GDS_NEIGHBOURS_handle_verify_successor_result() 967void GDS_NEIGHBOURS_handle_verify_successor_result(struct GNUNET_PeerIdentity *destination_peer,
968 struct GNUNET_PeerIdentity *source_successor,
969 struct GNUNET_PeerIdentity *my_predecessor,
970 struct FriendInfo *current_destination,
971 struct GNUNET_PeerIdentity *trail_peer_list,
972 unsigned int trail_length,
973 unsigned int current_trail_index)
842{ 974{
843 /* In this funciton, you receive 975 /* In this funciton, you receive
844 1. successor 976 1. successor
@@ -846,6 +978,46 @@ void GDS_NEIGHBOURS_handle_verify_successor_result()
846 3. trail_length. 978 3. trail_length.
847 4. current trail index --> this gives the next_hop on whose pending queue you should 979 4. current trail index --> this gives the next_hop on whose pending queue you should
848 add the message. */ 980 add the message. */
981 struct PeerVerifySuccessorResultMessage *vsmr;
982 struct P2PPendingMessage *pending;
983 struct GNUNET_PeerIdentity *peer_list;
984 size_t msize;
985
986 msize = sizeof (struct PeerVerifySuccessorResultMessage) +
987 (trail_length * sizeof(struct GNUNET_PeerIdentity));
988
989 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
990 {
991 GNUNET_break (0);
992 return;
993 }
994
995 if (current_destination->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
996 {
997 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
998 1, GNUNET_NO);
999 }
1000
1001 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1002 pending->importance = 0; /* FIXME */
1003 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
1004 vsmr = (struct PeerVerifySuccessorResultMessage *) &pending[1];
1005 pending->msg = &vsmr->header;
1006 vsmr->header.size = htons (msize);
1007 vsmr->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR_RESULT);
1008 memcpy (&(vsmr->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity));
1009 memcpy (&(vsmr->source_successor), source_successor, sizeof (struct GNUNET_PeerIdentity));
1010 memcpy (&(vsmr->my_predecessor), my_predecessor, sizeof (struct GNUNET_PeerIdentity));
1011 vsmr->trail_length = htonl (trail_length);
1012 vsmr->current_index = htonl (current_trail_index);
1013
1014 peer_list = (struct GNUNET_PeerIdentity *) &vsmr[1];
1015 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
1016
1017 /* Send the message to chosen friend. */
1018 GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending);
1019 current_destination->pending_count++;
1020 process_friend_queue (current_destination);
849} 1021}
850 1022
851 1023
@@ -954,18 +1126,18 @@ select_random_friend()
954 struct GNUNET_PeerIdentity key_ret; 1126 struct GNUNET_PeerIdentity key_ret;
955 struct FriendInfo *friend; 1127 struct FriendInfo *friend;
956 1128
957 current_size = GNUNET_CONTAINER_multipeermap_size(friend_peermap); 1129 current_size = GNUNET_CONTAINER_multipeermap_size (friend_peermap);
958 1130
959 /* Element stored at this index in friend_peermap should be selected friend. */ 1131 /* Element stored at this index in friend_peermap should be selected friend. */
960 index = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, current_size); 1132 index = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, current_size);
961 1133
962 /* Create an iterator for friend_peermap. */ 1134 /* Create an iterator for friend_peermap. */
963 iter = GNUNET_CONTAINER_multipeermap_iterator_create(friend_peermap); 1135 iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap);
964 1136
965 /* Set the position of iterator to index. */ 1137 /* Set the position of iterator to index. */
966 while(j < (*index)) 1138 while(j < (*index))
967 { 1139 {
968 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(iter,NULL,NULL)) 1140 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (iter,NULL,NULL))
969 { 1141 {
970 /* FIXME: I don't think we are actually incrementing iter. iter is always 1142 /* FIXME: I don't think we are actually incrementing iter. iter is always
971 pointing to the same element. */ 1143 pointing to the same element. */
@@ -975,7 +1147,7 @@ select_random_friend()
975 return NULL; 1147 return NULL;
976 } 1148 }
977 1149
978 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(iter,&key_ret,(const void **)&friend)) 1150 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (iter,&key_ret,(const void **)&friend))
979 { 1151 {
980 return friend; 1152 return friend;
981 } 1153 }
@@ -1001,7 +1173,7 @@ compute_finger_identity()
1001 my_id64 = GNUNET_malloc (sizeof (uint64_t)); 1173 my_id64 = GNUNET_malloc (sizeof (uint64_t));
1002 finger_identity64 = GNUNET_malloc (sizeof (uint64_t)); 1174 finger_identity64 = GNUNET_malloc (sizeof (uint64_t));
1003 1175
1004 memcpy(my_id64, &(my_identity.public_key.q_y), sizeof (uint64_t)); 1176 memcpy (my_id64, &(my_identity.public_key.q_y), sizeof (uint64_t));
1005 *finger_identity64 = fmod ((*my_id64 + pow (2,current_finger_index)),( (pow (2,MAX_FINGERS)))); 1177 *finger_identity64 = fmod ((*my_id64 + pow (2,current_finger_index)),( (pow (2,MAX_FINGERS))));
1006 1178
1007 return finger_identity64; 1179 return finger_identity64;
@@ -1009,32 +1181,28 @@ compute_finger_identity()
1009 1181
1010 1182
1011/** 1183/**
1012 * TODO: Implement after testing friend/finger map.
1013 * TODO: Handle the case when we already have a trail to our predecessor in
1014 * the network.
1015 * This function will be needed when we are handling node joins/fails
1016 * to maintain correct pointer to our predecessor and successor in the network.
1017 * Find immediate predecessor in the network. 1184 * Find immediate predecessor in the network.
1018 * @param me my own identity 1185 * @param me my own identity
1019 * @return peer identity of immediate predecessor. 1186 * @return peer identity of immediate predecessor.
1020 */ 1187 */
1021static uint64_t * 1188static uint64_t *
1022find_immediate_predecessor() 1189find_predecessor()
1023{ 1190{
1024 /* Using your own peer identity, calculate your predecessor 1191 uint64_t *my_id ;
1025 * in the network. Try to setup path to this predecessor using 1192 uint64_t *predecessor;
1026 * the same logic as used for other fingers. 1193
1027 * If we already have a trail to our predecessor then send NULL and 1194 my_id = GNUNET_malloc (sizeof (uint64_t));
1028 * calling function should be able to handle that case. 1195 predecessor = GNUNET_malloc (sizeof (uint64_t));
1029 */ 1196
1030 /* FIXME: O could be a valid peer id, return something else. */ 1197 memcpy (my_id, &(my_identity.public_key.q_y), sizeof (uint64_t));
1031 return 0; 1198 *predecessor = fmod ((*my_id -1), (pow (2,MAX_FINGERS)));
1199
1200 return predecessor;
1032} 1201}
1033 1202
1034 1203
1035/** 1204/**
1036 * Periodically verify your own immediate successor and 1205 * Periodically ping your successor to ask its current predecessor
1037 * tell your successor about yourself.
1038 * 1206 *
1039 * @param cls closure for this task 1207 * @param cls closure for this task
1040 * @param tc the context under which the task is running 1208 * @param tc the context under which the task is running
@@ -1043,33 +1211,55 @@ static void
1043send_verify_successor_message(void *cls, 1211send_verify_successor_message(void *cls,
1044 const struct GNUNET_SCHEDULER_TaskContext *tc ) 1212 const struct GNUNET_SCHEDULER_TaskContext *tc )
1045{ 1213{
1046 /*
1047 * FIXME:
1048 * Should we have a new message type
1049 * 1. like who is your predecessor.
1050 * 2. notify
1051 In this function
1052 1. ask your immediate successor ( its stored in your finger table with
1053 field that notes that its immediate successor) who is its predecessor.
1054 2. Then after getting the reply, check if its you.
1055 3. If not then update the new successor and your successor
1056 and notify the new successor that you are its new predecessor.
1057 */
1058
1059 /* okay so you first need to construct a messsage that you want to send
1060 to your "successor". but here you should just call another function which
1061 will construct the message and send it to first friend in the trial to
1062 reach our successor. */
1063 struct GNUNET_TIME_Relative next_send_time; 1214 struct GNUNET_TIME_Relative next_send_time;
1064 //struct GNUNET_PeerIdentity *successor; 1215 struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter;
1065 //struct FingerInfo *finger; 1216 struct GNUNET_PeerIdentity key_ret;
1217 struct FriendInfo *current_destination;
1218 struct GNUNET_PeerIdentity *finger_trail;
1219 unsigned int finger_trail_length;
1220 unsigned int finger_trail_current_index;
1221 struct FingerInfo *finger;
1222 unsigned int finger_index;
1066 1223
1067 /* Iterate over your finger peermap to find the element with successor field set. 1224 /* Iterate over your finger peermap to find the element with successor field set.
1068 That field is your successor. */ 1225 That field is your successor. */
1226 /* FIXME: Again if the iteration is correct or not? */
1227 finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap);
1228 for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++)
1229 {
1230 /* FIXME: I don't think we are actually iterating.
1231 Read about how to iterate over the multi peer map. */
1232 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger))
1233 {
1234 if(1 == finger->successor)
1235 break; /* FIXME: Do I come out of inner if or outer for */
1236 }
1237 }
1238
1239 /* FIXME: Is this copy correct? */
1240 finger_trail = GNUNET_malloc ((finger->trail_length *
1241 sizeof (struct GNUNET_PeerIdentity)));
1242 current_destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1243
1244 /* FIXME: Should we add ourself to peer list . When we get the result back
1245 then we should have to be in the list so that message reaches to us. */
1246 memcpy (finger_trail, finger->trail_peer_list,
1247 (finger->trail_length * sizeof (struct GNUNET_PeerIdentity)));
1248 finger_trail_length = finger->trail_length;
1249 finger_trail_current_index = 1;
1250 memcpy (current_destination, &finger_trail[1],
1251 sizeof (struct GNUNET_PeerIdentity));
1252
1253 /* FIXME: current_destination should be friend not gnunet_peeridentity.
1254 Search over your friend_peermap to find the friend corresponding to
1255 current_destination. */
1256 GDS_NEIGUBOURS_handle_verify_successor (&my_identity,
1257 &(finger->finger_identity),
1258 current_destination,
1259 finger_trail,
1260 finger_trail_length,
1261 finger_trail_current_index);
1069 1262
1070 /* In this function you should send your successor id, trail to reach that successor,
1071 trail_length, current_trial_index. */
1072 GDS_NEIGUBOURS_handle_verify_successor();
1073 1263
1074 /* FIXME: Use a random value so that this message is send not at the same 1264 /* FIXME: Use a random value so that this message is send not at the same
1075 interval as send_find_finger_trail_message. */ 1265 interval as send_find_finger_trail_message. */
@@ -1098,28 +1288,27 @@ send_find_finger_trail_message (void *cls,
1098{ 1288{
1099 struct FriendInfo *friend; 1289 struct FriendInfo *friend;
1100 struct GNUNET_TIME_Relative next_send_time; 1290 struct GNUNET_TIME_Relative next_send_time;
1101 uint64_t *finger_identity; /* FIXME: Better variable name */
1102 struct GNUNET_PeerIdentity *peer_list; 1291 struct GNUNET_PeerIdentity *peer_list;
1103 unsigned int successor_flag; /* set to 1 if we are looking for first finger/ 1292 unsigned int successor_flag;
1104 our succcessor, else 0. */ 1293 unsigned int predecessor_flag;
1105 1294 uint64_t *finger_identity;
1106 /* We already have found trail to each of our possible fingers in the network. */ 1295
1107 if (GNUNET_CONTAINER_multipeermap_size (finger_peermap) == MAX_FINGERS) 1296 if (1 == current_finger_index)
1108 { 1297 {
1109 /* FIXME: I call find_immediate_predecessor when I have found trail to 1298 /* We have started the process to find the successor. We should search
1110 * all the possible fingers in the network. But we need to find immediate 1299 for our predecessor. */
1111 * predecessor when there is a node failure/join. It may happen before. 1300 finger_identity = find_predecessor();
1112 * Think of a better strategy to decide when to call this function.
1113 * We can find trail to our immediate predecessor in the network.
1114 * I think its better to call this after we have trail to our successor set up.
1115 */
1116 finger_identity = find_immediate_predecessor();
1117 1301
1302 /* FIXME: There is no case in find_predecessor which returns NULL. It can
1303 return NULL, only if we already have found a trial to predecessor. is it
1304 required or not need to check.*/
1118 if(NULL == finger_identity) 1305 if(NULL == finger_identity)
1119 { 1306 {
1120 /* We already have a trail to reach to immediate predecessor. */ 1307 /* We already have a trail to reach to immediate predecessor. */
1121 goto new_find_finger_trail_request; 1308 goto new_find_finger_trail_request;
1122 } 1309 }
1310 predecessor_flag = 1;
1311 goto choose_friend;
1123 } 1312 }
1124 else 1313 else
1125 { 1314 {
@@ -1136,18 +1325,25 @@ send_find_finger_trail_message (void *cls,
1136 /* We are searching for our successor in the network. */ 1325 /* We are searching for our successor in the network. */
1137 successor_flag = 1; 1326 successor_flag = 1;
1138 } 1327 }
1328
1329 choose_friend:
1330 current_finger_index = current_finger_index + 1;
1139 friend = GNUNET_malloc (sizeof (struct FriendInfo)); 1331 friend = GNUNET_malloc (sizeof (struct FriendInfo));
1140 friend = select_random_friend(); 1332 friend = select_random_friend();
1141 1333
1142 /* We found a friend.*/ 1334 /* We found a friend.*/
1143 if(NULL != friend) 1335 if(NULL != friend)
1144 { 1336 {
1337 /*SUPU: Here you are adding yourself to peer list so that trail result
1338 reaches back to you. */
1145 unsigned int trail_length = 2; 1339 unsigned int trail_length = 2;
1146 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); 1340 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length);
1147 memcpy(&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); 1341 memcpy (&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity));
1148 memcpy(&peer_list[1], &(friend->id), sizeof (struct GNUNET_PeerIdentity)); 1342 memcpy (&peer_list[1], &(friend->id), sizeof (struct GNUNET_PeerIdentity));
1149 GDS_NEIGHBOURS_handle_trail_setup(&my_identity, finger_identity, 1343
1150 friend, trail_length, peer_list,successor_flag); 1344 GDS_NEIGHBOURS_handle_trail_setup (&my_identity, finger_identity,
1345 friend, trail_length, peer_list,
1346 successor_flag, predecessor_flag);
1151 } 1347 }
1152 1348
1153 /* FIXME: Should we be using current_finger_index to generate random interval.*/ 1349 /* FIXME: Should we be using current_finger_index to generate random interval.*/
@@ -1247,10 +1443,6 @@ core_init (void *cls,
1247 const struct GNUNET_PeerIdentity *identity) 1443 const struct GNUNET_PeerIdentity *identity)
1248{ 1444{
1249 my_identity = *identity; 1445 my_identity = *identity;
1250 GNUNET_CRYPTO_hash (identity,
1251 sizeof (struct GNUNET_PeerIdentity),
1252 &my_identity_hash);
1253
1254} 1446}
1255 1447
1256 1448
@@ -1307,19 +1499,20 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1307 return 0; 1499 return 0;
1308} 1500}
1309 1501
1502
1310/** 1503/**
1311 * Compare two peer identities. Used with qsort or bsearch. 1504 * Compare two peer identities.
1312 * 1505 * @param p1 Peer identity
1313 * @param p1 Some peer identity. 1506 * @param p2 Peer identity
1314 * @param p2 Some peer identity. 1507 * @return 1 if p1 > p2, -1 if p1 < p2 and 0 if p1 == p2.
1315 * @return 1 if p1 > p2, -1 if p1 < p2 and 0 if p1 == p2.
1316 */ 1508 */
1317static int 1509static int
1318peer_id_cmp (const void *p1, const void *p2) 1510compare_peer_id (const void *p1, const void *p2)
1319{ 1511{
1320 return memcmp (p1, p2, sizeof (uint64_t)); 1512 return memcmp (p1, p2, sizeof (uint64_t));
1321} 1513}
1322 1514
1515
1323/** 1516/**
1324 * Returns the previous element of value in all_known_peers. 1517 * Returns the previous element of value in all_known_peers.
1325 * @param all_known_peers list of all the peers 1518 * @param all_known_peers list of all the peers
@@ -1343,11 +1536,11 @@ binary_search(struct GNUNET_PeerIdentity *all_known_peers, uint64_t *value,
1343 while(first <= last) 1536 while(first <= last)
1344 { 1537 {
1345 /* all_known_peers[middle] > value*/ 1538 /* all_known_peers[middle] > value*/
1346 if(0 > peer_id_cmp(&all_known_peers[middle], &value)) 1539 if(0 > compare_peer_id(&all_known_peers[middle], &value))
1347 { 1540 {
1348 first = middle + 1; 1541 first = middle + 1;
1349 } 1542 }
1350 else if(0 == peer_id_cmp(&all_known_peers[middle], &value)) 1543 else if(0 == compare_peer_id(&all_known_peers[middle], &value))
1351 { 1544 {
1352 if(middle == 0) 1545 if(middle == 0)
1353 { 1546 {
@@ -1367,7 +1560,6 @@ binary_search(struct GNUNET_PeerIdentity *all_known_peers, uint64_t *value,
1367} 1560}
1368 1561
1369 1562
1370
1371/** 1563/**
1372 * Find closest successor for the value. 1564 * Find closest successor for the value.
1373 * @param value Value for which we are looking for successor 1565 * @param value Value for which we are looking for successor
@@ -1380,16 +1572,6 @@ static struct GNUNET_PeerIdentity *
1380find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination, 1572find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination,
1381 enum current_destination_type *type) 1573 enum current_destination_type *type)
1382{ 1574{
1383 /* 1. Create an array and copy all the peer identites from finger_peermap,
1384 friend_peermap, your own identity and value you are searching.
1385 2. Sort the array.
1386 3. Do a binary search on array to find the location of your value.
1387 4. previous element of the value is your successor.
1388 5. search for the successor in friend/finger/my_identity .
1389 6. if my_identity, then return NULL and set type to my_identity
1390 7. if friend, then return friend->id and set type to friend.
1391 8. if finger, then set current_destination = finger and return the first
1392 element from the trail list of finger as next_hop. */
1393 struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter; 1575 struct GNUNET_CONTAINER_MultiPeerMapIterator *friend_iter;
1394 struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; 1576 struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter;
1395 struct GNUNET_PeerIdentity key_ret; 1577 struct GNUNET_PeerIdentity key_ret;
@@ -1409,9 +1591,9 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination,
1409 all_known_peers = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * size); 1591 all_known_peers = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * size);
1410 1592
1411 j = 0; 1593 j = 0;
1412 memcpy(&all_known_peers[j], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); 1594 memcpy (&all_known_peers[j], &(my_identity), sizeof (struct GNUNET_PeerIdentity));
1413 j++; 1595 j++;
1414 memcpy(&all_known_peers[j], value, sizeof(struct GNUNET_PeerIdentity)); 1596 memcpy (&all_known_peers[j], value, sizeof(struct GNUNET_PeerIdentity));
1415 1597
1416 /* Iterate over friend peermap and copy all the elements into array. */ 1598 /* Iterate over friend peermap and copy all the elements into array. */
1417 friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap); 1599 friend_iter = GNUNET_CONTAINER_multipeermap_iterator_create (friend_peermap);
@@ -1421,7 +1603,7 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination,
1421 Read about how to iterate over the multipeermap. */ 1603 Read about how to iterate over the multipeermap. */
1422 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(friend_iter,&key_ret,(const void **)&friend)) 1604 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(friend_iter,&key_ret,(const void **)&friend))
1423 { 1605 {
1424 memcpy(&all_known_peers[j], &(friend->id), sizeof (struct GNUNET_PeerIdentity)); 1606 memcpy (&all_known_peers[j], &(friend->id), sizeof (struct GNUNET_PeerIdentity));
1425 j++; 1607 j++;
1426 } 1608 }
1427 } 1609 }
@@ -1434,15 +1616,15 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination,
1434 Read about how to iterate over the multi peer map. */ 1616 Read about how to iterate over the multi peer map. */
1435 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger)) 1617 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger))
1436 { 1618 {
1437 memcpy(&all_known_peers[j], &(finger->finger_identity), sizeof (struct GNUNET_PeerIdentity)); 1619 memcpy (&all_known_peers[j], &(finger->finger_identity), sizeof (struct GNUNET_PeerIdentity));
1438 j++; 1620 j++;
1439 } 1621 }
1440 } 1622 }
1441 1623
1442 qsort(all_known_peers, size, sizeof (struct GNUNET_PeerIdentity), &peer_id_cmp); 1624 qsort (all_known_peers, size, sizeof (struct GNUNET_PeerIdentity), &compare_peer_id);
1443 1625
1444 /* search value in all_known_peers array. */ 1626 /* search value in all_known_peers array. */
1445 successor = binary_search(all_known_peers, value, size); 1627 successor = binary_search (all_known_peers, value, size);
1446 1628
1447 /* compare successor with my_identity, finger and friend */ 1629 /* compare successor with my_identity, finger and friend */
1448 if(0 == GNUNET_CRYPTO_cmp_peer_identity(&(my_identity), successor)) 1630 if(0 == GNUNET_CRYPTO_cmp_peer_identity(&(my_identity), successor))
@@ -1454,22 +1636,22 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination,
1454 successor)) 1636 successor))
1455 { 1637 {
1456 *type = FRIEND; 1638 *type = FRIEND;
1457 memcpy(current_destination, successor, sizeof (struct GNUNET_PeerIdentity)); 1639 memcpy (current_destination, successor, sizeof (struct GNUNET_PeerIdentity));
1458 return successor; 1640 return successor;
1459 } 1641 }
1460 else if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (finger_peermap, 1642 else if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (finger_peermap,
1461 successor)) 1643 successor))
1462 { 1644 {
1463 *type = FINGER; 1645 *type = FINGER;
1464 memcpy(current_destination, successor, sizeof (struct GNUNET_PeerIdentity)); 1646 memcpy (current_destination, successor, sizeof (struct GNUNET_PeerIdentity));
1465 /* get the corresponding finger for succcesor and read the first element from 1647 /* get the corresponding finger for succcesor and read the first element from
1466 the trail list and return that element. */ 1648 the trail list and return that element. */
1467 struct FingerInfo *successor_finger; 1649 struct FingerInfo *successor_finger;
1468 struct GNUNET_PeerIdentity *next_hop; 1650 struct GNUNET_PeerIdentity *next_hop;
1469 next_hop = GNUNET_malloc(sizeof (struct GNUNET_PeerIdentity)); 1651 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1470 successor_finger = GNUNET_malloc (sizeof (struct FingerInfo)); 1652 successor_finger = GNUNET_malloc (sizeof (struct FingerInfo));
1471 successor_finger = GNUNET_CONTAINER_multipeermap_get (finger_peermap, successor); 1653 successor_finger = GNUNET_CONTAINER_multipeermap_get (finger_peermap, successor);
1472 memcpy(next_hop, &(successor_finger->trail_peer_list[0]), sizeof (struct GNUNET_PeerIdentity)); 1654 memcpy (next_hop, &(successor_finger->trail_peer_list[0]), sizeof (struct GNUNET_PeerIdentity));
1473 return next_hop; 1655 return next_hop;
1474 } 1656 }
1475 return NULL; 1657 return NULL;
@@ -1531,21 +1713,26 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1531 1713
1532 if(peer_type == FRIEND) 1714 if(peer_type == FRIEND)
1533 { 1715 {
1534 if(0 == (GNUNET_CRYPTO_cmp_peer_identity(&(trail_setup->current_destination),&my_identity))) 1716 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination),
1717 &my_identity)))
1535 { 1718 {
1536 next_hop = find_successor(&(trail_setup->destination_finger),&(trail_setup->current_destination),&(peer_type)); 1719 next_hop = find_successor (&(trail_setup->destination_finger),
1720 &(trail_setup->current_destination),
1721 &(peer_type));
1537 } 1722 }
1538 else 1723 else
1539 return GNUNET_SYSERR; /*TODO: Should we handle this case differently? */ 1724 return GNUNET_SYSERR; /*TODO: Should we handle this case differently? */
1540 } 1725 }
1541 else if(peer_type == FINGER) 1726 else if(peer_type == FINGER)
1542 { 1727 {
1543 if(0 != (GNUNET_CRYPTO_cmp_peer_identity(&(trail_setup->current_destination),&my_identity))) 1728 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination),
1729 &my_identity)))
1544 { 1730 {
1545 /* I am part of trail. 1731 /* I am part of trail.
1546 SUPU: So, I should ask for next hop to reach the current_destination which is the finger 1732 SUPU: So, I should ask for next hop to reach the current_destination which is the finger
1547 for which this packet has been sent. */ 1733 for which this packet has been sent. */
1548 next_hop = GDS_ROUTING_search(&(trail_setup->source_peer),&(trail_setup->current_destination)); 1734 next_hop = GDS_ROUTING_search (&(trail_setup->source_peer),
1735 &(trail_setup->current_destination));
1549 1736
1550 /*TODO: 1737 /*TODO:
1551 call find_successor and compare the two peer ids 1738 call find_successor and compare the two peer ids
@@ -1558,7 +1745,8 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1558 In this case, is it safe to assume current_Destination = my_identity. 1745 In this case, is it safe to assume current_Destination = my_identity.
1559 I guess we are sending current_destination so that we update it with new 1746 I guess we are sending current_destination so that we update it with new
1560 current_destination, if could either me, friend or finger.*/ 1747 current_destination, if could either me, friend or finger.*/
1561 next_hop = find_successor(&(trail_setup->destination_finger),&(trail_setup->current_destination),&(peer_type)); 1748 next_hop = find_successor (&(trail_setup->destination_finger),
1749 &(trail_setup->current_destination),&(peer_type));
1562 } 1750 }
1563 } 1751 }
1564 1752
@@ -1569,10 +1757,10 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1569 again in the next block below? */ 1757 again in the next block below? */
1570 struct GNUNET_PeerIdentity *peer_list; 1758 struct GNUNET_PeerIdentity *peer_list;
1571 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length)); 1759 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length));
1572 memcpy(peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); 1760 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
1573 current_trail_index = trail_length - 2; 1761 current_trail_index = trail_length - 2;
1574 next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); //FIXME: Do we need to allocate the memory? 1762 next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); //FIXME: Do we need to allocate the memory?
1575 memcpy(next_peer, &peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity)); 1763 memcpy (next_peer, &peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity));
1576 1764
1577 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); 1765 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer);
1578 1766
@@ -1583,11 +1771,12 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1583 GNUNET_PeerIdentity, but you need destination_peer id. If you calling the 1771 GNUNET_PeerIdentity, but you need destination_peer id. If you calling the
1584 function handle_Trail_setup_result from here, it means you are the 1772 function handle_Trail_setup_result from here, it means you are the
1585 destination. So, you can send your own identity. */ 1773 destination. So, you can send your own identity. */
1586 GDS_NEIGHBOURS_handle_trail_setup_result(&(trail_setup->source_peer), 1774 GDS_NEIGHBOURS_handle_trail_setup_result (&(trail_setup->source_peer),
1587 &(my_identity), 1775 &(my_identity),
1588 target_friend, trail_length, 1776 target_friend, trail_length,
1589 peer_list,current_trail_index, 1777 peer_list,current_trail_index,
1590 trail_setup->successor_flag); 1778 trail_setup->successor_flag,
1779 trail_setup->predecessor_flag);
1591 1780
1592 return GNUNET_YES; 1781 return GNUNET_YES;
1593 } 1782 }
@@ -1596,31 +1785,30 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1596 and increment trail length. */ 1785 and increment trail length. */
1597 struct GNUNET_PeerIdentity *peer_list; 1786 struct GNUNET_PeerIdentity *peer_list;
1598 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length + 1)); 1787 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length + 1));
1599 memcpy(peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); 1788 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
1600 memcpy(&peer_list[trail_length], next_hop, sizeof (struct GNUNET_PeerIdentity)); 1789 memcpy (&peer_list[trail_length], next_hop, sizeof (struct GNUNET_PeerIdentity));
1601 trail_length++; 1790 trail_length++;
1602 1791
1603 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 1792 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
1604 1793
1605 if(peer_type == FINGER) 1794 if(peer_type == FINGER)
1606 { 1795 {
1607 GDS_ROUTING_add(&(trail_setup->source_peer),&(trail_setup->current_destination),next_hop); 1796 GDS_ROUTING_add (&(trail_setup->source_peer),
1797 &(trail_setup->current_destination),
1798 next_hop);
1608 } 1799 }
1609 1800
1610 GDS_NEIGHBOURS_handle_trail_setup(&(trail_setup->source_peer), 1801 GDS_NEIGHBOURS_handle_trail_setup (&(trail_setup->source_peer),
1611 &(trail_setup->destination_finger), 1802 &(trail_setup->destination_finger),
1612 target_friend, 1803 target_friend,
1613 trail_setup->trail_length, 1804 trail_setup->trail_length,
1614 peer_list,trail_setup->successor_flag); 1805 peer_list,trail_setup->successor_flag,
1806 trail_setup->predecessor_flag);
1615return GNUNET_YES; 1807return GNUNET_YES;
1616} 1808}
1617 1809
1618 1810
1619/** 1811/**
1620 * FIXME : Add interval field.
1621 * When adding successor or predeccsor, update a field to
1622 * specify that this entry is not a finger but immediate
1623 * successor or predeccesor.
1624 * Add an entry in finger table. 1812 * Add an entry in finger table.
1625 * @param finger Finger to be added to finger table 1813 * @param finger Finger to be added to finger table
1626 * @param peer_list peers this request has traversed so far 1814 * @param peer_list peers this request has traversed so far
@@ -1630,16 +1818,20 @@ static
1630void finger_table_add(struct GNUNET_PeerIdentity *finger, 1818void finger_table_add(struct GNUNET_PeerIdentity *finger,
1631 const struct GNUNET_PeerIdentity *peer_list, 1819 const struct GNUNET_PeerIdentity *peer_list,
1632 unsigned int trail_length, 1820 unsigned int trail_length,
1633 unsigned int successor_flag) 1821 unsigned int successor_flag,
1822 unsigned int predecessor_flag)
1634{ 1823{
1635 /*FIXME: okay so there are two fields. one we should remember what finger 1824 /*FIXME: okay so there are two fields. one we should remember what finger
1636 identity we were looking for and what successor id we got. */ 1825 identity we were looking for and what successor id we got. */
1637 struct FingerInfo *finger_entry; 1826 struct FingerInfo *finger_entry;
1638 finger_entry = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 1827 finger_entry = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1639 memcpy(&(finger_entry->finger_identity), finger, sizeof(struct GNUNET_PeerIdentity)); 1828 memcpy (&(finger_entry->finger_identity), finger, sizeof (struct GNUNET_PeerIdentity));
1640 memcpy(&(finger_entry->trail_peer_list), peer_list, sizeof(struct GNUNET_PeerIdentity) 1829 memcpy (&(finger_entry->trail_peer_list), peer_list,
1641 * trail_length); 1830 sizeof (struct GNUNET_PeerIdentity)* trail_length);
1642 finger_entry->successor = successor_flag; 1831 finger_entry->successor = successor_flag;
1832 finger_entry->predecessor = predecessor_flag;
1833
1834 /*FIXME: Is it really a good time to call verify successor message. */
1643 if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap)) 1835 if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap))
1644 verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL); 1836 verify_successor = GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL);
1645} 1837}
@@ -1673,7 +1865,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
1673 1865
1674 trail_result = (struct PeerTrailSetupResultMessage *) message; 1866 trail_result = (struct PeerTrailSetupResultMessage *) message;
1675 trail_length = ntohl (trail_result->trail_length); 1867 trail_length = ntohl (trail_result->trail_length);
1676 current_trail_index = ntohl(trail_result->current_index); 1868 current_trail_index = ntohl (trail_result->current_index);
1677 trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1]; 1869 trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1];
1678 1870
1679 if ((msize < 1871 if ((msize <
@@ -1686,26 +1878,33 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
1686 return GNUNET_YES; 1878 return GNUNET_YES;
1687 } 1879 }
1688 1880
1689 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->current_destination), &my_identity))) 1881 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->current_destination),
1882 &my_identity)))
1690 { 1883 {
1691 /* Am I the destination? */ 1884 /* Am I the destination? */
1692 if( 0 == (GNUNET_CRYPTO_cmp_peer_identity(&(trail_result->destination_peer), &my_identity))) 1885 if( 0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->destination_peer),
1886 &my_identity)))
1693 { 1887 {
1694 finger_table_add(&(trail_result->finger), trail_peer_list,trail_length,trail_result->successor_flag); 1888 finger_table_add (&(trail_result->finger), trail_peer_list,trail_length,
1889 trail_result->successor_flag, trail_result->predecessor_flag);
1890
1695 return GNUNET_YES; 1891 return GNUNET_YES;
1696 } 1892 }
1697 else 1893 else
1698 { 1894 {
1699 next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 1895 next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1700 current_trail_index = current_trail_index - 1; 1896 current_trail_index = current_trail_index - 1;
1701 memcpy(next_peer, &(trail_peer_list[trail_length-1]), sizeof (struct GNUNET_PeerIdentity)); 1897 memcpy (next_peer, &(trail_peer_list[trail_length-1]),
1898 sizeof (struct GNUNET_PeerIdentity));
1899
1702 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); 1900 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer);
1703 1901
1704 GDS_NEIGHBOURS_handle_trail_setup_result(&(trail_result->destination_peer), 1902 GDS_NEIGHBOURS_handle_trail_setup_result(&(trail_result->destination_peer),
1705 &(trail_result->finger), 1903 &(trail_result->finger),
1706 target_friend, trail_length, 1904 target_friend, trail_length,
1707 trail_peer_list,current_trail_index, 1905 trail_peer_list,current_trail_index,
1708 trail_result->successor_flag); 1906 trail_result->successor_flag,
1907 trail_result->predecessor_flag);
1709 return GNUNET_YES; 1908 return GNUNET_YES;
1710 } 1909 }
1711 } 1910 }
@@ -1715,11 +1914,15 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
1715 1914
1716 1915
1717/** 1916/**
1718 * Core handle for p2p verify successor messages. 1917 * Core handle for p2p trail construction result messages.
1918 * @param cls closure
1919 * @param message message
1920 * @param peer peer identity this notification is about
1719 * @return GNUNET_OK on success, GNUNET_SYSERR on error 1921 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1720 */ 1922 */
1721static int 1923static int
1722handle_dht_p2p_verify_successor() 1924handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *peer,
1925 const struct GNUNET_MessageHeader *message)
1723{ 1926{
1724 /* 1927 /*
1725 * In this function you have received the message verify successor, 1928 * In this function you have received the message verify successor,
@@ -1727,18 +1930,109 @@ handle_dht_p2p_verify_successor()
1727 * As we already know the whole path find out the next destination 1930 * As we already know the whole path find out the next destination
1728 * and pass the packet forward. 1931 * and pass the packet forward.
1729 * If you are the final destination, check who is your predecessor. 1932 * If you are the final destination, check who is your predecessor.
1730 * and send your predecessor back to calling function. 1933 * and send your predecessor back to calling function. call GDS_NEIGHBOURS_handle_verify_successor
1731 * FIXME: Should we have a different handler function for it. 1934 * FIXME: Should we have a different handler function for it.
1732 */ 1935 */
1936 struct PeerVerifySuccessorMessage *vsm;
1937 size_t msize;
1938 unsigned int trail_length;
1939
1940 /* Uncomment after initialization
1941 struct GNUNET_PeerIdentity *trail_peer_list;
1942 unsigned int current_trail_index;
1943 struct GNUNET_PeerIdentity *next_peer;
1944 struct FriendInfo *target_friend;
1945 */
1946 msize = ntohs (message->size);
1947 if (msize < sizeof (struct PeerVerifySuccessorMessage))
1948 {
1949 GNUNET_break_op (0);
1950 return GNUNET_YES;
1951 }
1952
1953 vsm = (struct PeerVerifySuccessorMessage *) message;
1954 trail_length = ntohl (vsm->trail_length);
1955 //current_trail_index = ntohl (vsm->current_index);
1956
1957 //trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1];
1958 if ((msize <
1959 sizeof (struct PeerVerifySuccessorMessage) +
1960 trail_length * sizeof (struct GNUNET_PeerIdentity)) ||
1961 (trail_length >
1962 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
1963 {
1964 GNUNET_break_op (0);
1965 return GNUNET_YES;
1966 }
1967
1968 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor),
1969 &my_identity)))
1970 {
1971 /* You are the successor for which this message has been sent. */
1972 /* Search over your finger peer map to find the predecessor and then call
1973 GDS_NEIGHBOURS_handle_verify_successor_result with correct parameters. */
1974 struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter;
1975 struct GNUNET_PeerIdentity key_ret;
1976 unsigned int finger_index;
1977 struct FingerInfo *finger;
1978 struct GNUNET_PeerIdentity *destination_peer;
1979
1980 finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap);
1981 for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++)
1982 {
1983 /* FIXME: I don't think we are actually iterating.
1984 Read about how to iterate over the multi peer map. */
1985 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger))
1986 {
1987 if(1 == finger->predecessor)
1988 break; /* FIXME: Do I come out of inner if or outer for */
1989 }
1990 }
1991
1992 destination_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1993 memcpy (destination_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity));
1994
1995 /*SUPU: Initialize all the fields. */
1996 /* FIXME: Initialize all the parameters of this function.
1997 Also, target_friend in this case is the peer id which is last in the trail.
1998 check if destination peer is in peer list or not. To check you will have to
1999 check the trail_setup and how we are adding the peer in there. */
2000 /* FIXME: Uncomment after initializing the fields
2001 * GDS_NEIGHBOURS_handle_verify_successor_result (destination_peer,
2002 &(my_identity),
2003 &(finger->finger_identity),
2004 target_friend,
2005 trail_peer_list,
2006 trail_length,
2007 current_trail_index); */
2008 }
2009 else
2010 {
2011 /* FIXME: Initialize all the parameters to
2012 * this function. Read the element at current_trail_index + 1
2013 and call GDS_NEIGHBOURS_handle_verify_successor with correct parameters. */
2014 /* FIXME: Uncomment after initializing the fields.
2015 * GDS_NEIGUBOURS_handle_verify_successor(&(vsm->source_peer),
2016 &(vsm->successor),
2017 target_friend,
2018 trail_peer_list,
2019 trail_length,
2020 current_trail_index); */
2021 }
1733 return GNUNET_YES; 2022 return GNUNET_YES;
1734} 2023}
1735 2024
2025
1736/** 2026/**
1737 * Core handle for p2p notify successor messages. 2027 * Core handle for p2p trail construction result messages.
2028 * @param cls closure
2029 * @param message message
2030 * @param peer peer identity this notification is about
1738 * @return GNUNET_OK on success, GNUNET_SYSERR on error 2031 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1739 */ 2032 */
1740static int 2033static int
1741handle_dht_p2p_notify_new_successor() 2034handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer,
2035 const struct GNUNET_MessageHeader *message)
1742{ 2036{
1743 /* 2037 /*
1744 * So, if you are the destination you should update your 2038 * So, if you are the destination you should update your
@@ -1749,12 +2043,17 @@ handle_dht_p2p_notify_new_successor()
1749 return GNUNET_YES; 2043 return GNUNET_YES;
1750} 2044}
1751 2045
2046
1752/** 2047/**
1753 * Core handle for p2p verify successor result messages. 2048 * Core handle for p2p trail construction result messages.
2049 * @param cls closure
2050 * @param message message
2051 * @param peer peer identity this notification is about
1754 * @return GNUNET_OK on success, GNUNET_SYSERR on error 2052 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1755 */ 2053 */
1756static int 2054static int
1757handle_dht_p2p_verify_successor_result() 2055handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdentity *peer,
2056 const struct GNUNET_MessageHeader *message)
1758{ 2057{
1759 /* 2058 /*
1760 * In this function you have received the message verify successor result, 2059 * In this function you have received the message verify successor result,