aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-03-11 13:57:15 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-03-11 13:57:15 +0000
commit4c40fdfde27964814a749f64f581203cc6b669e4 (patch)
treec85f61ae0e7760d010e5c2f95b6d18e4cf9f965f /src/dht
parentdaa28fbf0d1d7a0b8fcca4a711f4db10822ef0bf (diff)
downloadgnunet-4c40fdfde27964814a749f64f581203cc6b669e4.tar.gz
gnunet-4c40fdfde27964814a749f64f581203cc6b669e4.zip
- verify successor result
- notify new successor
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c1193
-rw-r--r--src/dht/gnunet-service-xdht_routing.c22
2 files changed, 796 insertions, 419 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index b0eb08fd1..d9f073cd6 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -48,36 +48,8 @@
48#include <fenv.h> 48#include <fenv.h>
49#include "dht.h" 49#include "dht.h"
50 50
51
52/* FIXME:
53 * 1. do we need some mechanism to check if we already have found trail to
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
62 * when we are in trail seutp result part. each peer in the trail check if any of
63 * the corresponding peers is its friend list. Then it can shortcut the path.
64 * 4. As we start looking for finger from i = 0, using this parameter to
65 * generate random value does not look smart in send_find_finger_trail_message.
66 * 6. Need to add a new task, fix fingers. For node join/leave, we need to
67 * upgrade our finger table periodically. So, we should call fix_fingers
68 * and change our finger table.
69 * 7. Should we look for fingers one by one in send_find_finger_trail_setup
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.
75 */
76
77
78/** 51/**
79 * Maximum possible fingers of a peer. 52 * Maximum possible fingers of a peer.
80 * FIXME: Should it be 64 as we are doing all the operation on 64 bit numbers now?
81 */ 53 */
82#define MAX_FINGERS 64 54#define MAX_FINGERS 64
83 55
@@ -97,19 +69,11 @@
97#define DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10) 69#define DHT_MAXIMUM_FIND_FINGER_TRAIL_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10)
98 70
99/** 71/**
100 * FIXME: Currently used in GDS_NEIGHBOURS_handle_trail_setup.
101 * I have just copied it from gnunet-service-dht_neighbours. Will it work here?
102 * How long at most to wait for transmission of a GET request to another peer? 72 * How long at most to wait for transmission of a GET request to another peer?
103 */ 73 */
104#define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) 74#define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
105 75
106GNUNET_NETWORK_STRUCT_BEGIN 76GNUNET_NETWORK_STRUCT_BEGIN
107
108/* FIXME:
109 * 1) Bloomfilter is not required for X-Vine.
110 * Keep the field now but remove it when implementing PUT/GET.
111 * 2) also, check the field of put/get/result if all are required for
112 * x-vine or not. */
113 77
114/** 78/**
115 * P2P PUT message 79 * P2P PUT message
@@ -266,25 +230,20 @@ struct PeerGetMessage
266 230
267 231
268/** 232/**
269 * A destination can be either a friend or finger. 233 * A destination can be either a friend, finger or me.
234 * Used in trail setup to understand if the message is sent to an intermediate
235 * finger or a friend.
270 */ 236 */
271enum current_destination_type 237enum current_destination_type
272{ 238{
273
274 /* Friend */
275 FRIEND , 239 FRIEND ,
276
277 /* Finger */
278 FINGER , 240 FINGER ,
279
280 /* My own identity */
281 MY_ID 241 MY_ID
282}; 242};
283 243
284 244
285/** 245/**
286 * P2P Trail setup message 246 * P2P Trail setup message
287 * TODO: Take reference from put_path and get_path to understand how to use size of trail list.
288 */ 247 */
289struct PeerTrailSetupMessage 248struct PeerTrailSetupMessage
290{ 249{
@@ -295,20 +254,11 @@ struct PeerTrailSetupMessage
295 struct GNUNET_MessageHeader header; 254 struct GNUNET_MessageHeader header;
296 255
297 /** 256 /**
298 * Source peer which wants to find trail to one of its finger. 257 * Source peer which wants to setup the trail to one of its finger.
299 */ 258 */
300 struct GNUNET_PeerIdentity source_peer; 259 struct GNUNET_PeerIdentity source_peer;
301 260
302 /** 261 /**
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?
305 * As we are not sending any hello messages to this destination
306 * finger, we are only searching for it, we can just send 64 bit.
307 * Finger id to which we want to set up the trail to.
308 *
309 struct GNUNET_PeerIdentity destination_finger; */
310
311 /**
312 * Finger id to which we want to set up the trail to. 262 * Finger id to which we want to set up the trail to.
313 */ 263 */
314 uint64_t destination_finger; 264 uint64_t destination_finger;
@@ -324,19 +274,76 @@ struct PeerTrailSetupMessage
324 unsigned int predecessor_flag; 274 unsigned int predecessor_flag;
325 275
326 /** 276 /**
327 * If the message is forwarded to finger or friend. 277 * Peer which gets this message can be either an intermediate finger or friend.
328 */ 278 */
329 enum current_destination_type current_destination_type; 279 enum current_destination_type current_destination_type;
330 280
331 /** 281 /**
332 * This field contains the peer to which this packet is forwarded. 282 * Peer to which this packet is forwarded.
333 */ 283 */
334 struct GNUNET_PeerIdentity current_destination; 284 struct GNUNET_PeerIdentity current_destination;
335 285
286 /**
287 * Index into finger peer map.
288 */
289 unsigned int finger_map_index;
290
291 /**
292 * Number of entries in trail list.
293 */
294 uint32_t trail_length GNUNET_PACKED;
295
296};
297
298
299/**
300 * P2P Trail setup Result message
301 */
302struct PeerTrailSetupResultMessage
303{
304
305 /**
306 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_RESULT_SETUP
307 */
308 struct GNUNET_MessageHeader header;
309
310 /**
311 * Finger to which we have found the path.
312 */
313 struct GNUNET_PeerIdentity finger;
314
315 /**
316 * Peer which was looking for the trail to finger.
317 */
318 struct GNUNET_PeerIdentity destination_peer;
319
320 /**
321 * Peer to which this packet is forwarded next.
322 */
323 struct GNUNET_PeerIdentity current_destination;
324
325 /**
326 * Index at which peer list should be accessed.
327 */
328 unsigned int current_index;
329
330 /**
331 * If set to 1, then this trail is the trail to our successor.
332 */
333 unsigned int successor_flag;
334
335 /**
336 * If set to 1, then this trail is the trail to our predecessor.
337 */
338 unsigned int predecessor_flag;
339
340 /**
341 * Index into finger peer map
342 */
343 unsigned int finger_map_index;
344
336 /** 345 /**
337 * Number of entries in trail list. 346 * Number of entries in trail list.
338 * FIXME: Is this data type correct?
339 * FIMXE: Is usage of GNUNET_PACKED correct?
340 */ 347 */
341 uint32_t trail_length GNUNET_PACKED; 348 uint32_t trail_length GNUNET_PACKED;
342 349
@@ -360,25 +367,25 @@ struct PeerVerifySuccessorMessage
360 struct GNUNET_PeerIdentity source_peer; 367 struct GNUNET_PeerIdentity source_peer;
361 368
362 /** 369 /**
363 * Identity of our current successor. 370 * My current successor.
364 */ 371 */
365 struct GNUNET_PeerIdentity successor; 372 struct GNUNET_PeerIdentity successor;
366 373
367 /** 374 /**
368 * Total number of peers in trail. 375 * Total number of peers in trail to current successor.
369 */ 376 */
370 unsigned int trail_length; 377 unsigned int trail_length;
371 378
372 /** 379 /**
373 * The current index in trail for next destination to send this message to. 380 * Index in trail which points to next destination to send this message.
374 */ 381 */
375 unsigned int current_index; 382 unsigned int current_trail_index;
376 383
377}; 384};
378 385
379 386
380/** 387/**
381 * 388 * P2P verify successor result message.
382 */ 389 */
383struct PeerVerifySuccessorResultMessage 390struct PeerVerifySuccessorResultMessage
384{ 391{
@@ -389,12 +396,12 @@ struct PeerVerifySuccessorResultMessage
389 struct GNUNET_MessageHeader header; 396 struct GNUNET_MessageHeader header;
390 397
391 /** 398 /**
392 * Destination peer which send the request to verify its successor. 399 * Destination peer which sent the request to verify its successor.
393 */ 400 */
394 struct GNUNET_PeerIdentity destination_peer; 401 struct GNUNET_PeerIdentity destination_peer;
395 402
396 /** 403 /**
397 * Identity of successor to which PeerVerifySuccessorMessage was sent. 404 * Successor to which PeerVerifySuccessorMessage was sent.
398 */ 405 */
399 struct GNUNET_PeerIdentity source_successor; 406 struct GNUNET_PeerIdentity source_successor;
400 407
@@ -404,78 +411,54 @@ struct PeerVerifySuccessorResultMessage
404 struct GNUNET_PeerIdentity my_predecessor; 411 struct GNUNET_PeerIdentity my_predecessor;
405 412
406 /** 413 /**
407 * Total number of peers in trail. 414 * Total number of peers in trail.
415 * If source_successor is not destination peer, then trail is from destination_peer
416 * to my_predecessor.
417 * If source_successor is destination peer, then trail is from destination_peer
418 * to source_successor.
408 */ 419 */
409 unsigned int trail_length; 420 unsigned int trail_length;
410 421
411 /** 422 /**
412 * The current index in trail for next destination to send this message to. 423 * Index in trail which points to next destination to send this message.
413 */ 424 */
414 unsigned int current_index; 425 unsigned int current_index;
415 426
416}; 427};
417 428
418/** 429/**
419 * 430 * P2P notify new successor message.
420 */ 431 */
421struct PeerNotifyNewSuccessorMessage 432struct PeerNotifyNewSuccessorMessage
422{ 433{
423
424};
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.
429 * P2P Trail setup Result message
430 */
431struct PeerTrailSetupResultMessage
432{
433
434 /** 434 /**
435 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_RESULT_SETUP 435 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_NEW_SUCCESSOR
436 */ 436 */
437 struct GNUNET_MessageHeader header; 437 struct GNUNET_MessageHeader header;
438 438
439 /** 439 /**
440 * Finger to which we have found the path. 440 * Source peer which wants to notify its new successor.
441 */
442 struct GNUNET_PeerIdentity finger;
443
444 /**
445 * Peer which was looking for the trail to finger.
446 */
447 struct GNUNET_PeerIdentity destination_peer;
448
449 /**
450 * This field contains the peer to which this packet is forwarded.
451 */ 441 */
452 struct GNUNET_PeerIdentity current_destination; 442 struct GNUNET_PeerIdentity source_peer;
453
454 /**
455 * FIXME: Temporary field used to remember at which index we should read
456 * to get our next peer.
457 */
458 unsigned int current_index;
459 443
460 /** 444 /**
461 * If set to 1, then this trail is the trail to succcessor of our finger. 445 * New successor identity.
462 */ 446 */
463 unsigned int successor_flag; 447 struct GNUNET_PeerIdentity destination_peer;
464 448
465 /** 449 /**
466 * If set to 1, then this trail is the trail to predecessor of our finger. 450 * Number of peers in trail from source_peer to new successor.
467 */ 451 */
468 unsigned int predecessor_flag; 452 unsigned int trail_length;
469 453
470 /** 454 /**
471 * Number of entries in trail list. 455 * Index in trail which points to next destination to send this message.
472 * FIXME: Is this data type correct?
473 * FIXME: Is usage of GNUNET_PACKED correct?
474 */ 456 */
475 uint32_t trail_length GNUNET_PACKED; 457 unsigned int current_index;
476 458
477}; 459};
478 460
461
479GNUNET_NETWORK_STRUCT_END 462GNUNET_NETWORK_STRUCT_END
480 463
481 464
@@ -520,13 +503,13 @@ struct P2PPendingMessage
520struct TrailPeerList 503struct TrailPeerList
521{ 504{
522 /** 505 /**
523 * Pointer to next item in the list 506 * Pointer to next item in the list
524 */ 507 */
525 struct TrailPeerList *next; 508 struct TrailPeerList *next;
526 509
527 /** 510 /**
528 * Pointer to previous item in the list 511 * Pointer to previous item in the list
529 */ 512 */
530 struct TrailPeerList *prev; 513 struct TrailPeerList *prev;
531 514
532 /** 515 /**
@@ -537,35 +520,33 @@ struct TrailPeerList
537}; 520};
538 521
539 522
540/** FIXME: 523/**
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.
543 * Entry in friend_peermap. 524 * Entry in friend_peermap.
544 */ 525 */
545struct FriendInfo 526struct FriendInfo
546{ 527{
547 /** 528 /**
548 * What is the identity of the peer? 529 * Friend Identity
549 */ 530 */
550 struct GNUNET_PeerIdentity id; 531 struct GNUNET_PeerIdentity id;
551 532
552 /** 533 /**
553 * Count of outstanding messages for peer. 534 * Count of outstanding messages for this friend.
554 */ 535 */
555 unsigned int pending_count; 536 unsigned int pending_count;
556 537
557 /** 538 /**
558 * Head of pending messages to be sent to this peer. 539 * Head of pending messages to be sent to this friend.
559 */ 540 */
560 struct P2PPendingMessage *head; 541 struct P2PPendingMessage *head;
561 542
562 /** 543 /**
563 * Tail of pending messages to be sent to this peer. 544 * Tail of pending messages to be sent to this friend.
564 */ 545 */
565 struct P2PPendingMessage *tail; 546 struct P2PPendingMessage *tail;
566 547
567 /** 548 /**
568 * Core handle for sending messages to this peer. 549 * Core handle for sending messages to this friend.
569 */ 550 */
570 struct GNUNET_CORE_TransmitHandle *th; 551 struct GNUNET_CORE_TransmitHandle *th;
571 552
@@ -573,13 +554,6 @@ struct FriendInfo
573 554
574 555
575/** 556/**
576 * FIXME: We can also use an enum to say if its pred/suc/finger
577 * FIXME: As in chord , where we store the actual finger identity we were looking
578 * for and the real id which we got as successor. If we want to store like that
579 * then we will need to add a new field and search actual peer id.
580 * FIXME: Should we use another PeerIdentity which is smaller
581 * than 256 bits while storing.
582 * Predcessor is needed in case of node join/fail.
583 * Entry in finger_peermap. 557 * Entry in finger_peermap.
584 */ 558 */
585struct FingerInfo 559struct FingerInfo
@@ -590,17 +564,22 @@ struct FingerInfo
590 struct GNUNET_PeerIdentity finger_identity; 564 struct GNUNET_PeerIdentity finger_identity;
591 565
592 /** 566 /**
593 * If 1, then this finger entry is first finger /successor of the peer. 567 * If 1, then this finger entry is my first finger(successor).
594 */ 568 */
595 unsigned int successor; 569 unsigned int successor;
596 570
597 /** 571 /**
598 * If 1, then this finger entry is first predecessor of the peer. 572 * If 1, then this finger entry is my first predecessor.
599 */ 573 */
600 unsigned int predecessor; 574 unsigned int predecessor;
601 575
602 /** 576 /**
603 * Total number of entries in trail. 577 * Index in finger peer map
578 */
579 unsigned int finger_map_index;
580
581 /**
582 * Total number of entries in trail from me to finger.
604 */ 583 */
605 unsigned int trail_length; 584 unsigned int trail_length;
606 585
@@ -619,7 +598,7 @@ static GNUNET_SCHEDULER_TaskIdentifier find_finger_trail_task;
619 598
620/** 599/**
621 * 600 *
622 * Task that periodically checks for the immediate successor. 601 * Task that periodically checks for who is my successor.
623 */ 602 */
624static GNUNET_SCHEDULER_TaskIdentifier verify_successor; 603static GNUNET_SCHEDULER_TaskIdentifier verify_successor;
625 604
@@ -639,7 +618,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *friend_peermap;
639static struct GNUNET_CONTAINER_MultiPeerMap *finger_peermap; 618static struct GNUNET_CONTAINER_MultiPeerMap *finger_peermap;
640 619
641/** 620/**
642 * TODO: Ask whats the use of ATS.
643 * Handle to ATS. 621 * Handle to ATS.
644 */ 622 */
645static struct GNUNET_ATS_PerformanceHandle *atsAPI; 623static struct GNUNET_ATS_PerformanceHandle *atsAPI;
@@ -760,27 +738,25 @@ process_friend_queue (struct FriendInfo *peer)
760 738
761 739
762/** 740/**
763 * SUPU:
764 * We add the next destination i.e. friend to which we are sending the packet
765 * to our peer list in the calling function and we also increment trail_length
766 * in calling function i.e. send_find_finger_trail and handle_dht_p2p_trail_setup.
767 * Here we only copy the whole trail into our peer_list.
768 * Setup the trail message and forward it to a friend. 741 * Setup the trail message and forward it to a friend.
769 * @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.
770 * @param destination_finger Peer to which we want to set up the trail to. 743 * @param destination_finger Peer to which we want to set up the trail to.
771 * @param current_destination Current peer to which this message should be forwarded. 744 * @param target_friend Current friend to which this message should be forwarded.
772 * @param trail_length Numbers of peers in the trail. 745 * @param trail_length Numbers of peers in the trail.
773 * @param trail_peer_list peers this request has traversed so far 746 * @param trail_peer_list peers this request has traversed so far
774 * @param successor_flag If 1 then we are looking for trail to our successor. 747 * @param successor_flag If 1 then we are looking for trail to our successor.
748 * @param predecessor_flag If 1, then we are looking for trail to our predecessor.
749 * @param current_finger_index Finger index in finger peer map
775 */ 750 */
776void 751void
777GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer, 752GDS_NEIGHBOURS_handle_trail_setup (struct GNUNET_PeerIdentity *source_peer,
778 uint64_t *destination_finger, 753 uint64_t *destination_finger,
779 struct FriendInfo *current_destination, 754 struct FriendInfo *target_friend,
780 unsigned int trail_length, 755 unsigned int trail_length,
781 struct GNUNET_PeerIdentity *trail_peer_list, 756 struct GNUNET_PeerIdentity *trail_peer_list,
782 unsigned int successor_flag, 757 unsigned int successor_flag,
783 unsigned int predecessor_flag) 758 unsigned int predecessor_flag,
759 unsigned int current_finger_index)
784{ 760{
785 struct P2PPendingMessage *pending; 761 struct P2PPendingMessage *pending;
786 struct PeerTrailSetupMessage *tsm; 762 struct PeerTrailSetupMessage *tsm;
@@ -796,7 +772,7 @@ GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer,
796 return; 772 return;
797 } 773 }
798 774
799 if (current_destination->pending_count >= MAXIMUM_PENDING_PER_FRIEND) 775 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
800 { 776 {
801 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 777 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
802 1, GNUNET_NO); 778 1, GNUNET_NO);
@@ -811,44 +787,60 @@ GDS_NEIGHBOURS_handle_trail_setup(struct GNUNET_PeerIdentity *source_peer,
811 tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP); 787 tsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP);
812 memcpy (&(tsm->destination_finger), destination_finger, sizeof (uint64_t)); 788 memcpy (&(tsm->destination_finger), destination_finger, sizeof (uint64_t));
813 memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); 789 memcpy (&(tsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity));
814 memcpy (&(tsm->current_destination),&(current_destination->id), 790 memcpy (&(tsm->current_destination), &(target_friend->id),
815 sizeof (struct GNUNET_PeerIdentity)); 791 sizeof (struct GNUNET_PeerIdentity));
816 tsm->current_destination_type = htonl(FRIEND); 792 tsm->current_destination_type = htonl (FRIEND);
817 tsm->trail_length = htonl(trail_length); 793 tsm->trail_length = htonl (trail_length);
818 if(successor_flag == 1) 794 tsm->finger_map_index = htonl (current_finger_index);
795 if(1 == successor_flag)
796 {
819 tsm->successor_flag = 1; 797 tsm->successor_flag = 1;
820 if(predecessor_flag == 1) 798 tsm->predecessor_flag = 0;
799 }
800 else if (1 == predecessor_flag)
801 {
821 tsm->predecessor_flag = 1; 802 tsm->predecessor_flag = 1;
803 tsm->successor_flag = 0;
804 }
805 else
806 {
807 tsm->successor_flag = 0;
808 tsm->predecessor_flag = 0;
809 }
822 810
823 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length);
824 peer_list = (struct GNUNET_PeerIdentity *) &tsm[1]; 811 peer_list = (struct GNUNET_PeerIdentity *) &tsm[1];
812 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length);
825 memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity)); 813 memcpy (peer_list, trail_peer_list, trail_length * sizeof(struct GNUNET_PeerIdentity));
826 814
827 GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending); 815 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
828 current_destination->pending_count++; 816 target_friend->pending_count++;
829 process_friend_queue (current_destination); 817 process_friend_queue (target_friend);
830 818
831} 819}
832 820
833/**FIXME: As we are having a fixed list of trail peer list we can just 821
834 * store inside the message instead of attaching it all the time. 822/**
835 * Handle a tail setup result message. 823 * Handle a tail setup result message.
836 * @param destination_peer Peer which will get the trail to one of its finger. 824 * @param destination_peer Peer which will get the trail to one of its finger.
837 * @param source_finger Peer to which the trail has been setup to. 825 * @param source_finger Peer to which the trail has been setup to.
838 * @param current_destination Current peer to which this message should be forwarded. 826 * @param target_friend Friend to which this message should be forwarded.
839 * @param trail_length Numbers of peers in the trail. 827 * @param trail_length Numbers of peers in the trail.
840 * @param trail_peer_list peers this request has traversed so far 828 * @param trail_peer_list Peers which are part of the trail from source to destination.
841 * @param current_trail_index Index in trail_peer_list. 829 * @param current_trail_index Index in trail_peer_list.
830 * @param successor_flag If 1, then this is the trail to our successor.
831 * @param predecessor_flag If 1, then this is the trail to our predecessor.
832 * @param finger_map_index Finger index in finger peer map
842 */ 833 */
843void 834void
844GDS_NEIGHBOURS_handle_trail_setup_result (struct GNUNET_PeerIdentity *destination_peer, 835GDS_NEIGHBOURS_handle_trail_setup_result (struct GNUNET_PeerIdentity *destination_peer,
845 struct GNUNET_PeerIdentity *source_finger, 836 struct GNUNET_PeerIdentity *source_finger,
846 struct FriendInfo *current_destination, 837 struct FriendInfo *target_friend,
847 unsigned int trail_length, 838 unsigned int trail_length,
848 const struct GNUNET_PeerIdentity *trail_peer_list, 839 struct GNUNET_PeerIdentity *trail_peer_list,
849 unsigned int current_trail_index, 840 unsigned int current_trail_index,
850 unsigned int successor_flag, 841 unsigned int successor_flag,
851 unsigned int predecessor_flag) 842 unsigned int predecessor_flag,
843 unsigned int finger_map_index)
852{ 844{
853 struct P2PPendingMessage *pending; 845 struct P2PPendingMessage *pending;
854 struct PeerTrailSetupResultMessage *tsrm; 846 struct PeerTrailSetupResultMessage *tsrm;
@@ -864,47 +856,50 @@ GDS_NEIGHBOURS_handle_trail_setup_result (struct GNUNET_PeerIdentity *destinatio
864 return; 856 return;
865 } 857 }
866 858
867 if (current_destination->pending_count >= MAXIMUM_PENDING_PER_FRIEND) 859 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
868 { 860 {
869 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 861 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
870 1, GNUNET_NO); 862 1, GNUNET_NO);
871 } 863 }
872 864
873 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 865 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
874 pending->importance = 0; /* FIXME */ 866 pending->importance = 0;
875 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); 867 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
876 tsrm = (struct PeerTrailSetupResultMessage *) &pending[1]; 868 tsrm = (struct PeerTrailSetupResultMessage *) &pending[1];
877 pending->msg = &tsrm->header; 869 pending->msg = &tsrm->header;
878 tsrm->header.size = htons (msize); 870 tsrm->header.size = htons (msize);
879 tsrm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT); 871 tsrm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT);
880 memcpy (&(tsrm->current_destination), &(current_destination->id), sizeof(struct GNUNET_PeerIdentity)); 872 memcpy (&(tsrm->current_destination), &(target_friend->id), sizeof (struct GNUNET_PeerIdentity));
881 memcpy (&(tsrm->destination_peer), destination_peer, sizeof(struct GNUNET_PeerIdentity)); 873 memcpy (&(tsrm->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity));
882 memcpy (&(tsrm->finger), source_finger, sizeof(struct GNUNET_PeerIdentity)); 874 memcpy (&(tsrm->finger), source_finger, sizeof (struct GNUNET_PeerIdentity));
883 tsrm->trail_length = htonl (trail_length); 875 tsrm->trail_length = htonl (trail_length);
884 tsrm->current_index = htonl (current_trail_index); 876 tsrm->current_index = htonl (current_trail_index);
885 tsrm->successor_flag = htonl (successor_flag); 877 tsrm->successor_flag = htonl (successor_flag);
886 tsrm->predecessor_flag = htonl (predecessor_flag); 878 tsrm->predecessor_flag = htonl (predecessor_flag);
879 tsrm->finger_map_index = htonl (finger_map_index);
887 peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1]; 880 peer_list = (struct GNUNET_PeerIdentity *) &tsrm[1];
888 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); 881 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
889 882
890 /* Send the message to chosen friend. */ 883 /* Send the message to chosen friend. */
891 GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending); 884 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
892 current_destination->pending_count++; 885 target_friend->pending_count++;
893 process_friend_queue (current_destination); 886 process_friend_queue (target_friend);
894} 887}
895 888
896 889
897/**FIXME: Calling function should provide the current destination 890/**
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.
901 * This function is called from send_verify_successor_message funciton
902 * and handle_dht_p2p_verify_successor.
903 * Construct a PeerVerifySuccessor message and send it to friend. 891 * Construct a PeerVerifySuccessor message and send it to friend.
892 * @param source_peer Peer which wants to verify its successor
893 * @param successor Peer which is our current successor
894 * @param target_friend Friend to which this message should be forwarded.
895 * @param trail_peer_list Peer which are part of trail from source to destination
896 * @param trail_length Number of peers in the trail list.
897 * @param current_trail_index Index in the trial list at which receiving peer should
898 * get the next element.
904 */ 899 */
905void GDS_NEIGUBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_peer, 900void GDS_NEIGUBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_peer,
906 struct GNUNET_PeerIdentity *successor, 901 struct GNUNET_PeerIdentity *successor,
907 struct FriendInfo *current_destination, 902 struct FriendInfo *target_friend,
908 struct GNUNET_PeerIdentity *trail_peer_list, 903 struct GNUNET_PeerIdentity *trail_peer_list,
909 unsigned int trail_length, 904 unsigned int trail_length,
910 unsigned int current_trail_index) 905 unsigned int current_trail_index)
@@ -915,7 +910,7 @@ void GDS_NEIGUBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_p
915 size_t msize; 910 size_t msize;
916 911
917 msize = sizeof (struct PeerVerifySuccessorMessage) + 912 msize = sizeof (struct PeerVerifySuccessorMessage) +
918 (trail_length * sizeof(struct GNUNET_PeerIdentity)); 913 (trail_length * sizeof (struct GNUNET_PeerIdentity));
919 914
920 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 915 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
921 { 916 {
@@ -923,7 +918,7 @@ void GDS_NEIGUBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_p
923 return; 918 return;
924 } 919 }
925 920
926 if (current_destination->pending_count >= MAXIMUM_PENDING_PER_FRIEND) 921 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
927 { 922 {
928 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 923 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
929 1, GNUNET_NO); 924 1, GNUNET_NO);
@@ -939,45 +934,38 @@ void GDS_NEIGUBOURS_handle_verify_successor(struct GNUNET_PeerIdentity *source_p
939 memcpy (&(vsm->successor), successor, sizeof (struct GNUNET_PeerIdentity)); 934 memcpy (&(vsm->successor), successor, sizeof (struct GNUNET_PeerIdentity));
940 memcpy (&(vsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity)); 935 memcpy (&(vsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity));
941 vsm->trail_length = htonl (trail_length); 936 vsm->trail_length = htonl (trail_length);
942 vsm->current_index = htonl (current_trail_index); 937 vsm->current_trail_index = htonl (current_trail_index);
943 938
944 peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; 939 peer_list = (struct GNUNET_PeerIdentity *) &vsm[1];
945 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); 940 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
946 941
947 /* Send the message to chosen friend. */ 942 /* Send the message to chosen friend. */
948 GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending); 943 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
949 current_destination->pending_count++; 944 target_friend->pending_count++;
950 process_friend_queue (current_destination); 945 process_friend_queue (target_friend);
951 946
952} 947}
953 948
954 949
955/**FIXME: 950/**
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
965 * Construct a PeerVerifySuccessorResult message and send it to friend. 951 * Construct a PeerVerifySuccessorResult message and send it to friend.
952 * @param destination_peer Peer which sent verify successor message
953 * @param source_successor Peer to which verify successor message was sent.
954 * @param my_predecessor source_successor predecessor.
955 * @param target_friend Friend to which this message should be forwarded.
956 * @param trail_peer_list Peer which are part of trail from source to destination
957 * @param trail_length Number of peers in the trail list.
958 * @param current_trail_index Index in the trial list at which receiving peer should
959 * get the next element.
966 */ 960 */
967void GDS_NEIGHBOURS_handle_verify_successor_result(struct GNUNET_PeerIdentity *destination_peer, 961void GDS_NEIGHBOURS_handle_verify_successor_result (struct GNUNET_PeerIdentity *destination_peer,
968 struct GNUNET_PeerIdentity *source_successor, 962 struct GNUNET_PeerIdentity *source_successor,
969 struct GNUNET_PeerIdentity *my_predecessor, 963 struct GNUNET_PeerIdentity *my_predecessor,
970 struct FriendInfo *current_destination, 964 struct FriendInfo *target_friend,
971 struct GNUNET_PeerIdentity *trail_peer_list, 965 struct GNUNET_PeerIdentity *trail_peer_list,
972 unsigned int trail_length, 966 unsigned int trail_length,
973 unsigned int current_trail_index) 967 unsigned int current_trail_index)
974{ 968{
975 /* In this funciton, you receive
976 1. successor
977 2. trial to reach that successor
978 3. trail_length.
979 4. current trail index --> this gives the next_hop on whose pending queue you should
980 add the message. */
981 struct PeerVerifySuccessorResultMessage *vsmr; 969 struct PeerVerifySuccessorResultMessage *vsmr;
982 struct P2PPendingMessage *pending; 970 struct P2PPendingMessage *pending;
983 struct GNUNET_PeerIdentity *peer_list; 971 struct GNUNET_PeerIdentity *peer_list;
@@ -992,7 +980,7 @@ void GDS_NEIGHBOURS_handle_verify_successor_result(struct GNUNET_PeerIdentity *d
992 return; 980 return;
993 } 981 }
994 982
995 if (current_destination->pending_count >= MAXIMUM_PENDING_PER_FRIEND) 983 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
996 { 984 {
997 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 985 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
998 1, GNUNET_NO); 986 1, GNUNET_NO);
@@ -1015,18 +1003,68 @@ void GDS_NEIGHBOURS_handle_verify_successor_result(struct GNUNET_PeerIdentity *d
1015 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); 1003 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
1016 1004
1017 /* Send the message to chosen friend. */ 1005 /* Send the message to chosen friend. */
1018 GNUNET_CONTAINER_DLL_insert_tail (current_destination->head, current_destination->tail, pending); 1006 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
1019 current_destination->pending_count++; 1007 target_friend->pending_count++;
1020 process_friend_queue (current_destination); 1008 process_friend_queue (target_friend);
1021} 1009}
1022 1010
1023 1011
1024/** 1012/**
1025 * Construct a PeerNotifyNewSuccessor message and send it to friend. 1013 * Construct a PeerNotifyNewSuccessor message and send it to friend.
1014 * @param source_peer Peer which is sending notify message to its new successor.
1015 * @param destination_peer Peer which is the new destination.
1016 * @param target_friend Next friend to pass this message to.
1017 * @param peer_list List of peers in the trail to reach to destination_peer.
1018 * @param current_trail_index Index of peer_list for next target friend position.
1019 * @param trail_length Total number of peers in peer list
1026 */ 1020 */
1027void GDS_NEIGHBOURS_handle_notify_new_successor() 1021void
1022GDS_NEIGHBOURS_notify_new_successor (struct GNUNET_PeerIdentity *source_peer,
1023 struct GNUNET_PeerIdentity *destination_peer,
1024 struct FriendInfo *target_friend,
1025 struct GNUNET_PeerIdentity *trail_peer_list,
1026 unsigned int trail_length,
1027 unsigned int current_trail_index)
1028{ 1028{
1029 struct PeerNotifyNewSuccessorMessage *nsm;
1030 struct P2PPendingMessage *pending;
1031 struct GNUNET_PeerIdentity *peer_list;
1032 size_t msize;
1033
1034 msize = sizeof (struct PeerNotifyNewSuccessorMessage) +
1035 (trail_length * sizeof(struct GNUNET_PeerIdentity));
1029 1036
1037 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1038 {
1039 GNUNET_break (0);
1040 return;
1041 }
1042
1043 if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
1044 {
1045 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"),
1046 1, GNUNET_NO);
1047 }
1048
1049 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1050 pending->importance = 0; /* FIXME */
1051 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
1052 nsm = (struct PeerNotifyNewSuccessorMessage *) &pending[1];
1053 pending->msg = &nsm->header;
1054 nsm->header.size = htons (msize);
1055 nsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_NEW_SUCCESSOR);
1056 memcpy (&(nsm->source_peer), source_peer, sizeof (struct GNUNET_PeerIdentity));
1057 memcpy (&(nsm->destination_peer), destination_peer, sizeof (struct GNUNET_PeerIdentity));
1058 nsm->trail_length = htonl (trail_length);
1059 nsm->current_index = htonl (current_trail_index);
1060
1061 peer_list = (struct GNUNET_PeerIdentity *) &nsm[1];
1062 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
1063
1064 /* Send the message to chosen friend. */
1065 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
1066 target_friend->pending_count++;
1067 process_friend_queue (target_friend);
1030} 1068}
1031 1069
1032 1070
@@ -1173,6 +1211,16 @@ compute_finger_identity()
1173 my_id64 = GNUNET_malloc (sizeof (uint64_t)); 1211 my_id64 = GNUNET_malloc (sizeof (uint64_t));
1174 finger_identity64 = GNUNET_malloc (sizeof (uint64_t)); 1212 finger_identity64 = GNUNET_malloc (sizeof (uint64_t));
1175 1213
1214 /* Check if for current_finger_index you already have an entry in finger table.
1215 If yes it means you should try to find the trail for finger identifier
1216 corresponding to next current_finger_index. */
1217 /*FIXME: Create an iterator, read all the elements of finger_peermap one by one
1218 and if finger_index == current_finger_index, then (
1219 current_finger_index = current_finger_index + 1) % MAX_FINGERS. We can either
1220 return NULL or just restart the process to find finger. When we remove the
1221 friend in handle_core_disconnect, then we also remove the entry from finger
1222 * peermap. Thats why there can be gap in our logic. ;*/
1223
1176 memcpy (my_id64, &(my_identity.public_key.q_y), sizeof (uint64_t)); 1224 memcpy (my_id64, &(my_identity.public_key.q_y), sizeof (uint64_t));
1177 *finger_identity64 = fmod ((*my_id64 + pow (2,current_finger_index)),( (pow (2,MAX_FINGERS)))); 1225 *finger_identity64 = fmod ((*my_id64 + pow (2,current_finger_index)),( (pow (2,MAX_FINGERS))));
1178 1226
@@ -1202,63 +1250,86 @@ find_predecessor()
1202 1250
1203 1251
1204/** 1252/**
1253 * FIXME: At the moment no one is calling this function.
1254 * Need to find the correct place to call this function.
1255 *
1256 */
1257#if 0
1258static void
1259fix_fingers()
1260{
1261 /*
1262 * 1. Choose a random finger index using GNUNET_CRYPTO_random.
1263 * 2. call find_successor for that finger. now here you have to send
1264 * what value how do you remember which index you used. so its important
1265 * to have finger index in finger table.
1266 *
1267 */
1268}
1269#endif
1270
1271
1272/**
1273 * SUPU: You should pass the trail index from where next peer should read. read
1274 * position should be set and after you read you should update the read position
1275 * for next peer in the trail list.
1205 * Periodically ping your successor to ask its current predecessor 1276 * Periodically ping your successor to ask its current predecessor
1206 * 1277 *
1207 * @param cls closure for this task 1278 * @param cls closure for this task
1208 * @param tc the context under which the task is running 1279 * @param tc the context under which the task is running
1209 */ 1280 */
1210static void 1281static void
1211send_verify_successor_message(void *cls, 1282send_verify_successor_message (void *cls,
1212 const struct GNUNET_SCHEDULER_TaskContext *tc ) 1283 const struct GNUNET_SCHEDULER_TaskContext *tc )
1213{ 1284{
1214 struct GNUNET_TIME_Relative next_send_time; 1285 struct GNUNET_TIME_Relative next_send_time;
1215 struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; 1286 struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter;
1216 struct GNUNET_PeerIdentity key_ret; 1287 struct GNUNET_PeerIdentity key_ret;
1217 struct FriendInfo *current_destination; 1288 struct FriendInfo *target_friend;
1289 struct GNUNET_PeerIdentity *next_hop;
1218 struct GNUNET_PeerIdentity *finger_trail; 1290 struct GNUNET_PeerIdentity *finger_trail;
1219 unsigned int finger_trail_length; 1291 unsigned int finger_trail_length;
1220 unsigned int finger_trail_current_index; 1292 unsigned int finger_trail_current_index;
1221 struct FingerInfo *finger; 1293 struct FingerInfo *finger;
1222 unsigned int finger_index; 1294 unsigned int finger_index;
1223 1295
1224 /* Iterate over your finger peermap to find the element with successor field set.
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); 1296 finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap);
1228 for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) 1297 for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++)
1229 { 1298 {
1230 /* FIXME: I don't think we are actually iterating. 1299 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next (finger_iter, &key_ret,
1231 Read about how to iterate over the multi peer map. */ 1300 (const void **)&finger))
1232 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger))
1233 { 1301 {
1234 if(1 == finger->successor) 1302 if (1 == finger->successor)
1235 break; /* FIXME: Do I come out of inner if or outer for */ 1303 break;
1236 } 1304 }
1237 } 1305 }
1238 1306
1239 /* FIXME: Is this copy correct? */ 1307 GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter);
1308
1240 finger_trail = GNUNET_malloc ((finger->trail_length * 1309 finger_trail = GNUNET_malloc ((finger->trail_length *
1241 sizeof (struct GNUNET_PeerIdentity))); 1310 sizeof (struct GNUNET_PeerIdentity)));
1242 current_destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 1311 target_friend = GNUNET_malloc (sizeof (struct FriendInfo));
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, 1312 memcpy (finger_trail, finger->trail_peer_list,
1247 (finger->trail_length * sizeof (struct GNUNET_PeerIdentity))); 1313 (finger->trail_length * sizeof (struct GNUNET_PeerIdentity)));
1248 finger_trail_length = finger->trail_length; 1314 finger_trail_length = finger->trail_length;
1249 finger_trail_current_index = 1; 1315 /* FIXME: Here I am the first element in the trail to reach to any finger.
1250 memcpy (current_destination, &finger_trail[1], 1316 So, our first target friend is situated at trail index = 1 and target friend
1317 should read from finger_Trial_current_index. Check in the function that
1318 finger_trail_current_index < trail_length.*/
1319 finger_trail_current_index = 2;
1320 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1321 memcpy (next_hop, &finger_trail[1],
1251 sizeof (struct GNUNET_PeerIdentity)); 1322 sizeof (struct GNUNET_PeerIdentity));
1252 1323
1253 /* FIXME: current_destination should be friend not gnunet_peeridentity. 1324 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
1254 Search over your friend_peermap to find the friend corresponding to 1325 GNUNET_free (next_hop);
1255 current_destination. */ 1326
1256 GDS_NEIGUBOURS_handle_verify_successor (&my_identity, 1327 GDS_NEIGUBOURS_handle_verify_successor (&my_identity,
1257 &(finger->finger_identity), 1328 &(finger->finger_identity),
1258 current_destination, 1329 target_friend,
1259 finger_trail, 1330 finger_trail,
1260 finger_trail_length, 1331 finger_trail_length,
1261 finger_trail_current_index); 1332 finger_trail_current_index);
1262 1333
1263 1334
1264 /* FIXME: Use a random value so that this message is send not at the same 1335 /* FIXME: Use a random value so that this message is send not at the same
@@ -1277,21 +1348,25 @@ send_verify_successor_message(void *cls,
1277 1348
1278/** 1349/**
1279 * Task to send a find finger trail message. We attempt to find trail 1350 * Task to send a find finger trail message. We attempt to find trail
1280 * to our finger and successor in the network. 1351 * to our fingers, successor and predecessor in the network.
1281 * 1352 *
1282 * @param cls closure for this task 1353 * @param cls closure for this task
1283 * @param tc the context under which the task is running 1354 * @param tc the context under which the task is running
1284 */ 1355 */
1285static void 1356static void
1286send_find_finger_trail_message (void *cls, 1357send_find_finger_trail_message (void *cls,
1287 const struct GNUNET_SCHEDULER_TaskContext *tc) 1358 const struct GNUNET_SCHEDULER_TaskContext *tc)
1288{ 1359{
1289 struct FriendInfo *friend; 1360 struct FriendInfo *target_friend;
1290 struct GNUNET_TIME_Relative next_send_time; 1361 struct GNUNET_TIME_Relative next_send_time;
1291 struct GNUNET_PeerIdentity *peer_list; 1362 struct GNUNET_PeerIdentity *peer_list;
1292 unsigned int successor_flag; 1363 unsigned int successor_flag;
1293 unsigned int predecessor_flag; 1364 unsigned int predecessor_flag;
1294 uint64_t *finger_identity; 1365 uint64_t *finger_identity;
1366 unsigned int finger_index;
1367
1368 predecessor_flag = 0;
1369 successor_flag = 0;
1295 1370
1296 if (1 == current_finger_index) 1371 if (1 == current_finger_index)
1297 { 1372 {
@@ -1300,7 +1375,7 @@ send_find_finger_trail_message (void *cls,
1300 finger_identity = find_predecessor(); 1375 finger_identity = find_predecessor();
1301 1376
1302 /* FIXME: There is no case in find_predecessor which returns NULL. It can 1377 /* 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 1378 return NULL, only if we already have found a trail to predecessor. is it
1304 required or not need to check.*/ 1379 required or not need to check.*/
1305 if(NULL == finger_identity) 1380 if(NULL == finger_identity)
1306 { 1381 {
@@ -1308,12 +1383,18 @@ send_find_finger_trail_message (void *cls,
1308 goto new_find_finger_trail_request; 1383 goto new_find_finger_trail_request;
1309 } 1384 }
1310 predecessor_flag = 1; 1385 predecessor_flag = 1;
1311 goto choose_friend; 1386 goto select_friend;
1312 } 1387 }
1313 else 1388 else
1314 { 1389 {
1315 finger_identity = compute_finger_identity(); 1390 finger_identity = compute_finger_identity();
1316 1391
1392 /* Here again we can get NULL, only if we already have an entry for that
1393 index value in our finger peer map. That will be checked in compute_finger_identity
1394 Also, it may be beneficial to keep checking for the new trail and only when
1395 adding the entry into finger table, we check if the new route is shorter
1396 or else we may want to keep more than one route (redundant routing). There can be
1397 no case when it return NULL. */
1317 if(finger_identity == NULL) 1398 if(finger_identity == NULL)
1318 { 1399 {
1319 goto new_find_finger_trail_request; 1400 goto new_find_finger_trail_request;
@@ -1326,24 +1407,27 @@ send_find_finger_trail_message (void *cls,
1326 successor_flag = 1; 1407 successor_flag = 1;
1327 } 1408 }
1328 1409
1329 choose_friend: 1410 select_friend:
1330 current_finger_index = current_finger_index + 1; 1411 finger_index = current_finger_index;
1331 friend = GNUNET_malloc (sizeof (struct FriendInfo)); 1412 current_finger_index = ( current_finger_index + 1) % MAX_FINGERS;
1332 friend = select_random_friend(); 1413
1414 target_friend = select_random_friend();
1333 1415
1334 /* We found a friend.*/ 1416 /* We found a friend.*/
1335 if(NULL != friend) 1417 if(NULL != target_friend)
1336 { 1418 {
1337 /*SUPU: Here you are adding yourself to peer list so that trail result 1419 /*SUPU: Here you are adding yourself to peer list so that trail result
1338 reaches back to you. */ 1420 reaches back to you. Highest trail index = trail_length - 1; */
1339 unsigned int trail_length = 2; 1421 unsigned int trail_length = 2;
1340 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); 1422 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length);
1341 memcpy (&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity)); 1423 memcpy (&peer_list[0], &(my_identity), sizeof (struct GNUNET_PeerIdentity));
1342 memcpy (&peer_list[1], &(friend->id), sizeof (struct GNUNET_PeerIdentity)); 1424 memcpy (&peer_list[1], &(target_friend->id), sizeof (struct GNUNET_PeerIdentity));
1343 1425
1426 /* FIXME: Here why are you sending the current_finger_index ? */
1344 GDS_NEIGHBOURS_handle_trail_setup (&my_identity, finger_identity, 1427 GDS_NEIGHBOURS_handle_trail_setup (&my_identity, finger_identity,
1345 friend, trail_length, peer_list, 1428 target_friend, trail_length, peer_list,
1346 successor_flag, predecessor_flag); 1429 successor_flag, predecessor_flag,
1430 finger_index);
1347 } 1431 }
1348 1432
1349 /* FIXME: Should we be using current_finger_index to generate random interval.*/ 1433 /* FIXME: Should we be using current_finger_index to generate random interval.*/
@@ -1408,7 +1492,6 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
1408 1492
1409 1493
1410/** 1494/**
1411 * FIXME: Implement after testing finger/friend table setup.
1412 * Method called whenever a peer disconnects. 1495 * Method called whenever a peer disconnects.
1413 * 1496 *
1414 * @param cls closure 1497 * @param cls closure
@@ -1418,17 +1501,37 @@ static void
1418handle_core_disconnect (void *cls, 1501handle_core_disconnect (void *cls,
1419 const struct GNUNET_PeerIdentity *peer) 1502 const struct GNUNET_PeerIdentity *peer)
1420{ 1503{
1421 /** 1504 struct FriendInfo *remove_friend;
1422 * 1. remove the friend from the friend map. 1505
1423 * 2. remove the trail for the fingers for which this peer was the first hop. 1506 /* Check for self message. */
1424 * 3. start send_find_finger_trail for these fingers to find a new trail 1507 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
1425 * in the network. 1508 return;
1426 * 4. Also when a node gets disconnected, how should we update pointers of its 1509
1427 * immediate successor and predecessor in the network ? 1510 /* Search for peer to remove in your friend_peermap. */
1428 * 5. Also how do we distribute the keys in the network? 1511 remove_friend =
1429 * 6. Here is case where we started put operation but a peer got disconnected and 1512 GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer);
1430 we removed the entry from the table. How to handle such a case. 1513
1431 */ 1514 if (NULL == remove_friend)
1515 {
1516 GNUNET_break (0);
1517 return;
1518 }
1519
1520 /* Remove the friend from friend_peermap. */
1521 GNUNET_assert (GNUNET_YES ==
1522 GNUNET_CONTAINER_multipeermap_remove (friend_peermap,
1523 peer,
1524 remove_friend));
1525
1526 /* If the peer is removed then all the trail which goes through this
1527 peer also becomes invalid. */
1528 /* FIXME: Iterate over finger peermap, get the trail index and find all the
1529 finger whose trail's first peer was this peer. and remove them from finger
1530 peermap. Assumption that in send_find_finger_trail we will eventually reach
1531 to this finger and we will setup up the new trail.
1532 So, we need a threshold on number of trail thats can go through a node
1533 so that if that nodes go away then also our system is up and runnning.
1534 Where can we specify that threshold.*/
1432} 1535}
1433 1536
1434 1537
@@ -1621,6 +1724,10 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination,
1621 } 1724 }
1622 } 1725 }
1623 1726
1727 /* FIXME: If this is correct. */
1728 GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter);
1729 GNUNET_CONTAINER_multipeermap_iterator_destroy (friend_iter);
1730
1624 qsort (all_known_peers, size, sizeof (struct GNUNET_PeerIdentity), &compare_peer_id); 1731 qsort (all_known_peers, size, sizeof (struct GNUNET_PeerIdentity), &compare_peer_id);
1625 1732
1626 /* search value in all_known_peers array. */ 1733 /* search value in all_known_peers array. */
@@ -1649,16 +1756,36 @@ find_successor(uint64_t *value, struct GNUNET_PeerIdentity *current_destination,
1649 struct FingerInfo *successor_finger; 1756 struct FingerInfo *successor_finger;
1650 struct GNUNET_PeerIdentity *next_hop; 1757 struct GNUNET_PeerIdentity *next_hop;
1651 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 1758 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1652 successor_finger = GNUNET_malloc (sizeof (struct FingerInfo));
1653 successor_finger = GNUNET_CONTAINER_multipeermap_get (finger_peermap, successor); 1759 successor_finger = GNUNET_CONTAINER_multipeermap_get (finger_peermap, successor);
1654 memcpy (next_hop, &(successor_finger->trail_peer_list[0]), sizeof (struct GNUNET_PeerIdentity)); 1760 memcpy (next_hop, &(successor_finger->trail_peer_list[0]), sizeof (struct GNUNET_PeerIdentity));
1761 GNUNET_free (next_hop);
1655 return next_hop; 1762 return next_hop;
1656 } 1763 }
1657 return NULL; 1764 return NULL;
1658} 1765}
1659 1766
1660 1767
1768#if 0
1661/** 1769/**
1770 * Compare two peer id's and find the closest peer id for value.
1771 * @param peer1 some peer id
1772 * @param peer2 some peer id
1773 * @param value value to which one of the peer id should be closest.
1774 * @return
1775 */
1776static struct GNUNET_PeerIdentity *
1777find_closest_destination (struct GNUNET_PeerIdentity *peer1,
1778 struct GNUNET_PeerIdentity *peer2,
1779 uint64_t *value)
1780{
1781 /* Compare value with peer1 and peer2 and find the closest peer to this value.*/
1782 return NULL;
1783}
1784#endif
1785
1786/**
1787 * SUPU: The first element in the trail setup message is your identity.
1788 * in this function you should increment the trail length.
1662 * Handle a PeerTrailSetupMessage. 1789 * Handle a PeerTrailSetupMessage.
1663 * @param cls closure 1790 * @param cls closure
1664 * @param message message 1791 * @param message message
@@ -1677,9 +1804,9 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1677 enum current_destination_type peer_type; 1804 enum current_destination_type peer_type;
1678 struct GNUNET_PeerIdentity *trail_peer_list; 1805 struct GNUNET_PeerIdentity *trail_peer_list;
1679 uint32_t current_trail_index; 1806 uint32_t current_trail_index;
1807 unsigned int finger_map_index;
1680 struct GNUNET_PeerIdentity *next_peer; 1808 struct GNUNET_PeerIdentity *next_peer;
1681 1809
1682
1683 /* parse and validate message. */ 1810 /* parse and validate message. */
1684 msize = ntohs (message->size); 1811 msize = ntohs (message->size);
1685 if (msize < sizeof (struct PeerTrailSetupMessage)) 1812 if (msize < sizeof (struct PeerTrailSetupMessage))
@@ -1692,6 +1819,7 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1692 trail_length = ntohl (trail_setup->trail_length); 1819 trail_length = ntohl (trail_setup->trail_length);
1693 peer_type = ntohl (trail_setup->current_destination_type); 1820 peer_type = ntohl (trail_setup->current_destination_type);
1694 trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_setup[1]; 1821 trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_setup[1];
1822 finger_map_index = ntohl (trail_setup->finger_map_index);
1695 1823
1696 if ((msize < 1824 if ((msize <
1697 sizeof (struct PeerTrailSetupMessage) + 1825 sizeof (struct PeerTrailSetupMessage) +
@@ -1700,10 +1828,9 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1700 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) 1828 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
1701 { 1829 {
1702 GNUNET_break_op (0); 1830 GNUNET_break_op (0);
1703 return GNUNET_YES; /*TODO: Why do we send GNUNET_YES here? */ 1831 return GNUNET_YES;
1704 } 1832 }
1705 1833
1706
1707 GNUNET_STATISTICS_update (GDS_stats, 1834 GNUNET_STATISTICS_update (GDS_stats,
1708 gettext_noop ("# TRAIL SETUP requests received"), 1, 1835 gettext_noop ("# TRAIL SETUP requests received"), 1,
1709 GNUNET_NO); 1836 GNUNET_NO);
@@ -1711,78 +1838,84 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1711 gettext_noop ("# TRAIL SETUP bytes received"), msize, 1838 gettext_noop ("# TRAIL SETUP bytes received"), msize,
1712 GNUNET_NO); 1839 GNUNET_NO);
1713 1840
1714 if(peer_type == FRIEND) 1841 if (peer_type == FRIEND)
1715 { 1842 {
1716 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination), 1843 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination),
1717 &my_identity))) 1844 &my_identity)))
1718 { 1845 {
1719 next_hop = find_successor (&(trail_setup->destination_finger), 1846 next_hop = find_successor (&(trail_setup->destination_finger),
1720 &(trail_setup->current_destination), 1847 &(trail_setup->current_destination),
1721 &(peer_type)); 1848 &(peer_type));
1722 } 1849 }
1723 else 1850 else
1724 return GNUNET_SYSERR; /*TODO: Should we handle this case differently? */ 1851 return GNUNET_SYSERR;
1725 } 1852 }
1726 else if(peer_type == FINGER) 1853 else if (peer_type == FINGER)
1727 { 1854 {
1728 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination), 1855 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_setup->current_destination),
1729 &my_identity))) 1856 &my_identity)))
1730 { 1857 {
1731 /* I am part of trail.
1732 SUPU: So, I should ask for next hop to reach the current_destination which is the finger
1733 for which this packet has been sent. */
1734 next_hop = GDS_ROUTING_search (&(trail_setup->source_peer), 1858 next_hop = GDS_ROUTING_search (&(trail_setup->source_peer),
1735 &(trail_setup->current_destination)); 1859 &(trail_setup->current_destination));
1736 1860
1737 /*TODO: 1861 #if 0
1738 call find_successor and compare the two peer ids 1862 /* This is an optimization. Uncomment when basic code is running first. */
1739 and choose whichever is closest to the destination finger. */ 1863 /* I am part of trail.*/
1864 struct GNUNET_PeerIdentity *next_peer_routing_table;
1865 next_peer_routing_table = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1866 next_peer_routing_table = GDS_ROUTING_search (&(trail_setup->source_peer),
1867 &(trail_setup->current_destination));
1868
1869 struct GNUNET_PeerIdentity *next_peer_find_successor;
1870 next_peer_find_successor = find_successor (&(trail_setup->destination_finger),
1871 &(trail_setup->current_destination),
1872 &(peer_type));
1873
1874 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1875 next_hop = find_closest_destination (next_peer_routing_table,
1876 next_peer_find_successor,
1877 &(trail_setup->destination_finger) );
1878 #endif
1740 } 1879 }
1741 else 1880 else
1742 { 1881 {
1743 /* I am the current_destination finger 1882 /* I am the current_destination finger */
1744 FIXME: Why are we sending current_destination to find_successor.
1745 In this case, is it safe to assume current_Destination = my_identity.
1746 I guess we are sending current_destination so that we update it with new
1747 current_destination, if could either me, friend or finger.*/
1748 next_hop = find_successor (&(trail_setup->destination_finger), 1883 next_hop = find_successor (&(trail_setup->destination_finger),
1749 &(trail_setup->current_destination),&(peer_type)); 1884 &(trail_setup->current_destination), &(peer_type));
1750 } 1885 }
1751 } 1886 }
1752 1887
1753 /* If you are the next hop */ 1888 /* If you are the next hop, then you are the final destination */
1754 if(peer_type == MY_ID) 1889 if (peer_type == MY_ID)
1755 { 1890 {
1756 /* FIXME: Verify if its allowed here to definer peer_list and define it 1891 /*SUPU:
1757 again in the next block below? */ 1892 1. You were the destination of this message which means you were already added
1758 struct GNUNET_PeerIdentity *peer_list; 1893 in the peer list by previous calling function.
1759 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length)); 1894 2. current_trail_index should point to the trail element at which the peer
1760 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); 1895 which receives this message should look for the next peer to forward the packet
1761 current_trail_index = trail_length - 2; 1896 to. */
1762 next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); //FIXME: Do we need to allocate the memory? 1897 current_trail_index = trail_length - 2;
1763 memcpy (next_peer, &peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity));
1764 1898
1765 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); 1899 next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1766 1900 memcpy (next_peer, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity));
1767 /* FIXME: It does not find a friend. Could be possible error in find_successor 1901 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer);
1768 function. Change the logic in find_successor and change it again. */ 1902 GNUNET_free (next_peer);
1769 1903
1770 /* FIXME: Here as destination_finger is 64 bit instead of struct 1904 if(current_trail_index != 0)
1771 GNUNET_PeerIdentity, but you need destination_peer id. If you calling the 1905 current_trail_index = current_trail_index - 1;
1772 function handle_Trail_setup_result from here, it means you are the 1906
1773 destination. So, you can send your own identity. */ 1907 GDS_NEIGHBOURS_handle_trail_setup_result (&(trail_setup->source_peer),
1774 GDS_NEIGHBOURS_handle_trail_setup_result (&(trail_setup->source_peer), 1908 &(my_identity),
1775 &(my_identity), 1909 target_friend, trail_length,
1776 target_friend, trail_length, 1910 trail_peer_list, current_trail_index,
1777 peer_list,current_trail_index, 1911 trail_setup->successor_flag,
1778 trail_setup->successor_flag, 1912 trail_setup->predecessor_flag,
1779 trail_setup->predecessor_flag); 1913 finger_map_index);
1780 1914
1781 return GNUNET_YES; 1915 return GNUNET_YES;
1782 } 1916 }
1783 1917
1784 /* Add next_hop to list of peers that trail setup message have traversed so far 1918 /* Add next hop to list of peers. */
1785 and increment trail length. */
1786 struct GNUNET_PeerIdentity *peer_list; 1919 struct GNUNET_PeerIdentity *peer_list;
1787 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length + 1)); 1920 peer_list = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length + 1));
1788 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity)); 1921 memcpy (peer_list, trail_peer_list, trail_length * sizeof (struct GNUNET_PeerIdentity));
@@ -1803,33 +1936,44 @@ handle_dht_p2p_trail_setup(void *cls, const struct GNUNET_PeerIdentity *peer,
1803 target_friend, 1936 target_friend,
1804 trail_setup->trail_length, 1937 trail_setup->trail_length,
1805 peer_list,trail_setup->successor_flag, 1938 peer_list,trail_setup->successor_flag,
1806 trail_setup->predecessor_flag); 1939 trail_setup->predecessor_flag,
1940 finger_map_index);
1807return GNUNET_YES; 1941return GNUNET_YES;
1808} 1942}
1809 1943
1810 1944
1811/** 1945/**
1946 * FIXME: For redundant routing, we may start looking for different
1947 * paths to reach to same finger. So, in send_find_finger, we are starting
1948 * the search for trail to a finger, even if we already have found trail to
1949 * reach to it. There are several reasons for doing so
1950 * 1. We may reach to a closer successor than we have at the moment. So, we
1951 * should keep looking for the successor.
1952 * 2. We may reach to the same successor but through a shorter path.
1953 * 3. As I don't know how keys are distributed and how put/get will react
1954 * because of this, I have to think further before implementing it.
1812 * Add an entry in finger table. 1955 * Add an entry in finger table.
1813 * @param finger Finger to be added to finger table 1956 * @param finger Finger to be added to finger table
1814 * @param peer_list peers this request has traversed so far 1957 * @param peer_list peers this request has traversed so far
1815 * @param trail_length Numbers of peers in the trail. 1958 * @param trail_length Numbers of peers in the trail.
1816 */ 1959 */
1817static 1960static
1818void finger_table_add(struct GNUNET_PeerIdentity *finger, 1961void finger_table_add (struct GNUNET_PeerIdentity *finger,
1819 const struct GNUNET_PeerIdentity *peer_list, 1962 struct GNUNET_PeerIdentity *peer_list,
1820 unsigned int trail_length, 1963 unsigned int trail_length,
1821 unsigned int successor_flag, 1964 unsigned int successor_flag,
1822 unsigned int predecessor_flag) 1965 unsigned int predecessor_flag,
1966 unsigned int finger_map_index)
1823{ 1967{
1824 /*FIXME: okay so there are two fields. one we should remember what finger 1968 struct FingerInfo *new_finger_entry;
1825 identity we were looking for and what successor id we got. */ 1969
1826 struct FingerInfo *finger_entry; 1970 new_finger_entry = GNUNET_malloc (sizeof (struct FingerInfo));
1827 finger_entry = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 1971 memcpy (&(new_finger_entry->finger_identity), finger, sizeof (struct GNUNET_PeerIdentity));
1828 memcpy (&(finger_entry->finger_identity), finger, sizeof (struct GNUNET_PeerIdentity)); 1972 memcpy (&(new_finger_entry->trail_peer_list), peer_list,
1829 memcpy (&(finger_entry->trail_peer_list), peer_list,
1830 sizeof (struct GNUNET_PeerIdentity)* trail_length); 1973 sizeof (struct GNUNET_PeerIdentity)* trail_length);
1831 finger_entry->successor = successor_flag; 1974 new_finger_entry->successor = successor_flag;
1832 finger_entry->predecessor = predecessor_flag; 1975 new_finger_entry->predecessor = predecessor_flag;
1976 new_finger_entry->finger_map_index = finger_map_index;
1833 1977
1834 /*FIXME: Is it really a good time to call verify successor message. */ 1978 /*FIXME: Is it really a good time to call verify successor message. */
1835 if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap)) 1979 if (1 == GNUNET_CONTAINER_multipeermap_size (finger_peermap))
@@ -1850,11 +1994,12 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
1850{ 1994{
1851 struct PeerTrailSetupResultMessage *trail_result; 1995 struct PeerTrailSetupResultMessage *trail_result;
1852 size_t msize; 1996 size_t msize;
1853 uint32_t trail_length; 1997 unsigned int trail_length;
1854 const struct GNUNET_PeerIdentity *trail_peer_list; 1998 struct GNUNET_PeerIdentity *trail_peer_list;
1855 uint32_t current_trail_index; 1999 unsigned int current_trail_index;
1856 struct GNUNET_PeerIdentity *next_peer; 2000 struct GNUNET_PeerIdentity *next_peer;
1857 struct FriendInfo *target_friend; 2001 struct FriendInfo *target_friend;
2002 unsigned int finger_map_index;
1858 2003
1859 msize = ntohs (message->size); 2004 msize = ntohs (message->size);
1860 if (msize < sizeof (struct PeerTrailSetupMessage)) 2005 if (msize < sizeof (struct PeerTrailSetupMessage))
@@ -1867,44 +2012,70 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
1867 trail_length = ntohl (trail_result->trail_length); 2012 trail_length = ntohl (trail_result->trail_length);
1868 current_trail_index = ntohl (trail_result->current_index); 2013 current_trail_index = ntohl (trail_result->current_index);
1869 trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1]; 2014 trail_peer_list = (struct GNUNET_PeerIdentity *) &trail_result[1];
2015 finger_map_index = ntohl (trail_result->finger_map_index);
1870 2016
1871 if ((msize < 2017 if ((msize <
1872 sizeof (struct PeerTrailSetupResultMessage) + 2018 sizeof (struct PeerTrailSetupResultMessage) +
1873 trail_length * sizeof (struct GNUNET_PeerIdentity)) || 2019 trail_length * sizeof (struct GNUNET_PeerIdentity)) ||
1874 (trail_length > 2020 (trail_length >
1875 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) 2021 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
1876 { 2022 {
1877 GNUNET_break_op (0); 2023 GNUNET_break_op (0);
1878 return GNUNET_YES; 2024 return GNUNET_YES;
1879 } 2025 }
1880 2026
1881 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->current_destination), 2027 if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->current_destination),
1882 &my_identity))) 2028 &my_identity)))
1883 { 2029 {
1884 /* Am I the destination? */ 2030 if ( 0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->destination_peer),
1885 if( 0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->destination_peer), 2031 &my_identity)))
1886 &my_identity)))
1887 { 2032 {
1888 finger_table_add (&(trail_result->finger), trail_peer_list,trail_length, 2033 #if 0
1889 trail_result->successor_flag, trail_result->predecessor_flag); 2034 /* SUPU: Here I have removed myself from the trail before storing it in
2035 th finger table - to save space, but in case of verify successor result
2036 the result trail does not contain me, and I will never get the message back.
2037 So, keeping myself in the trail list. Think of better solution.*/
2038 struct GNUNET_PeerIdentity *finger_trail;
2039 finger_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (trail_length - 1));
2040
2041 /* Copy the whole trail_peer_list except the first element into trail */
2042 unsigned int i;
2043 i = trail_length - 1;
2044 while (i > 0)
2045 {
2046 memcpy (&finger_trail[i], &trail_peer_list[i], sizeof (struct GNUNET_PeerIdentity));
2047 i--;
2048 }
2049 trail_length = trail_length -1 ; /* SUPU: As you removed yourself from the trail.*/
2050 #endif
2051
2052 finger_table_add (&(trail_result->finger), trail_peer_list, trail_length,
2053 trail_result->successor_flag, trail_result->predecessor_flag,
2054 trail_result->finger_map_index);
1890 2055
1891 return GNUNET_YES; 2056 return GNUNET_YES;
1892 } 2057 }
1893 else 2058 else
1894 { 2059 {
1895 next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 2060 next_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1896 current_trail_index = current_trail_index - 1; 2061 memcpy (next_peer, &(trail_peer_list[current_trail_index]),
1897 memcpy (next_peer, &(trail_peer_list[trail_length-1]),
1898 sizeof (struct GNUNET_PeerIdentity)); 2062 sizeof (struct GNUNET_PeerIdentity));
2063 /* SUPU: here current trail index will always be greater than 0.
2064 so no need for this check here. trail index = 0, contains the final
2065 destination, and if we are in this loop we have not yet reached the
2066 final destination. */
2067 current_trail_index = current_trail_index - 1;
1899 2068
1900 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer); 2069 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_peer);
1901 2070 GNUNET_free (next_peer);
1902 GDS_NEIGHBOURS_handle_trail_setup_result(&(trail_result->destination_peer), 2071
1903 &(trail_result->finger), 2072 GDS_NEIGHBOURS_handle_trail_setup_result (&(trail_result->destination_peer),
1904 target_friend, trail_length, 2073 &(trail_result->finger),
1905 trail_peer_list,current_trail_index, 2074 target_friend, trail_length,
1906 trail_result->successor_flag, 2075 trail_peer_list,current_trail_index,
1907 trail_result->predecessor_flag); 2076 trail_result->successor_flag,
2077 trail_result->predecessor_flag,
2078 finger_map_index);
1908 return GNUNET_YES; 2079 return GNUNET_YES;
1909 } 2080 }
1910 } 2081 }
@@ -1914,7 +2085,10 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
1914 2085
1915 2086
1916/** 2087/**
1917 * Core handle for p2p trail construction result messages. 2088 * SUPU: In this function you don't do anything with trail length
2089 * You increment the current trail index so that you find the correct
2090 * peer to send the packet forward.
2091 * Core handle for p2p verify successor messages.
1918 * @param cls closure 2092 * @param cls closure
1919 * @param message message 2093 * @param message message
1920 * @param peer peer identity this notification is about 2094 * @param peer peer identity this notification is about
@@ -1924,26 +2098,15 @@ static int
1924handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *peer, 2098handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *peer,
1925 const struct GNUNET_MessageHeader *message) 2099 const struct GNUNET_MessageHeader *message)
1926{ 2100{
1927 /*
1928 * In this function you have received the message verify successor,
1929 * Now, either you are the destination or just part of the trail.
1930 * As we already know the whole path find out the next destination
1931 * and pass the packet forward.
1932 * If you are the final destination, check who is your predecessor.
1933 * and send your predecessor back to calling function. call GDS_NEIGHBOURS_handle_verify_successor
1934 * FIXME: Should we have a different handler function for it.
1935 */
1936 struct PeerVerifySuccessorMessage *vsm; 2101 struct PeerVerifySuccessorMessage *vsm;
1937 size_t msize; 2102 size_t msize;
1938 unsigned int trail_length; 2103 unsigned int trail_length;
1939
1940 /* Uncomment after initialization
1941 struct GNUNET_PeerIdentity *trail_peer_list; 2104 struct GNUNET_PeerIdentity *trail_peer_list;
1942 unsigned int current_trail_index; 2105 unsigned int current_trail_index;
1943 struct GNUNET_PeerIdentity *next_peer;
1944 struct FriendInfo *target_friend; 2106 struct FriendInfo *target_friend;
1945 */ 2107 struct GNUNET_PeerIdentity *next_hop;
1946 msize = ntohs (message->size); 2108
2109 msize = ntohs (message->size);
1947 if (msize < sizeof (struct PeerVerifySuccessorMessage)) 2110 if (msize < sizeof (struct PeerVerifySuccessorMessage))
1948 { 2111 {
1949 GNUNET_break_op (0); 2112 GNUNET_break_op (0);
@@ -1952,9 +2115,10 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee
1952 2115
1953 vsm = (struct PeerVerifySuccessorMessage *) message; 2116 vsm = (struct PeerVerifySuccessorMessage *) message;
1954 trail_length = ntohl (vsm->trail_length); 2117 trail_length = ntohl (vsm->trail_length);
1955 //current_trail_index = ntohl (vsm->current_index); 2118 current_trail_index = ntohl (vsm->current_trail_index);
1956 2119
1957 //trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1]; 2120 trail_peer_list = (struct GNUNET_PeerIdentity *) &vsm[1];
2121
1958 if ((msize < 2122 if ((msize <
1959 sizeof (struct PeerVerifySuccessorMessage) + 2123 sizeof (struct PeerVerifySuccessorMessage) +
1960 trail_length * sizeof (struct GNUNET_PeerIdentity)) || 2124 trail_length * sizeof (struct GNUNET_PeerIdentity)) ||
@@ -1965,66 +2129,165 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee
1965 return GNUNET_YES; 2129 return GNUNET_YES;
1966 } 2130 }
1967 2131
2132 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
2133
1968 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor), 2134 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor),
1969 &my_identity))) 2135 &my_identity)))
1970 { 2136 {
1971 /* You are the successor for which this message has been sent. */ 2137 /* I am the successor, check who is my predecessor. If my predecessor is not
1972 /* Search over your finger peer map to find the predecessor and then call 2138 same as source peer then update the trail and send back to calling function.
1973 GDS_NEIGHBOURS_handle_verify_successor_result with correct parameters. */ 2139 */
1974 struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter; 2140 struct GNUNET_CONTAINER_MultiPeerMapIterator *finger_iter;
1975 struct GNUNET_PeerIdentity key_ret; 2141 struct GNUNET_PeerIdentity key_ret;
1976 unsigned int finger_index; 2142 unsigned int finger_index;
1977 struct FingerInfo *finger; 2143 struct FingerInfo *my_predecessor;
1978 struct GNUNET_PeerIdentity *destination_peer; 2144 struct GNUNET_PeerIdentity *destination_peer;
1979 2145
2146 /* Iterate over finger peer map and extract your predecessor. */
1980 finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap); 2147 finger_iter = GNUNET_CONTAINER_multipeermap_iterator_create (finger_peermap);
1981 for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++) 2148 for (finger_index = 0; finger_index < GNUNET_CONTAINER_multipeermap_size (finger_peermap); finger_index++)
1982 { 2149 {
1983 /* FIXME: I don't think we are actually iterating. 2150 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next
1984 Read about how to iterate over the multi peer map. */ 2151 (finger_iter,&key_ret,(const void **)&my_predecessor))
1985 if(GNUNET_YES == GNUNET_CONTAINER_multipeermap_iterator_next(finger_iter,&key_ret,(const void **)&finger))
1986 { 2152 {
1987 if(1 == finger->predecessor) 2153 if(1 == my_predecessor->predecessor)
1988 break; /* FIXME: Do I come out of inner if or outer for */ 2154 break;
1989 } 2155 }
1990 } 2156 }
1991 2157
2158 GNUNET_CONTAINER_multipeermap_iterator_destroy (finger_iter);
2159
1992 destination_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 2160 destination_peer = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1993 memcpy (destination_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity)); 2161 memcpy (destination_peer, &(vsm->source_peer), sizeof (struct GNUNET_PeerIdentity));
2162 current_trail_index = trail_length - 2; /*SUPU: I am the last element in the trail.*/
2163 memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity));
2164 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2165 GNUNET_free (next_hop);
2166
2167 current_trail_index = current_trail_index - 1;
2168
2169 /* FIXME: Here we should check if our predecessor is source peer or not.
2170 If not then, we can send an updated trail that goes through us. Instead of
2171 looking for a new trail to reach to the new successor, source peer
2172 can just use this trail. It may not be an optimal route. */
2173 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->source_peer),
2174 &(my_predecessor->finger_identity))))
2175 {
2176 /*If we have a new predecessor, then create a new trail to reach from
2177 vsm source peer to this new successor of source peer. */
2178 struct GNUNET_PeerIdentity *new_successor_trail;
2179 unsigned int my_predecessor_trail_length;
2180 unsigned int new_trail_length;
2181 unsigned int i;
2182
2183 /* SUPU:my_predecessor_trail will not contain my identity. But the trail
2184 that I got from the requesting peer will contain my identity. */
2185 my_predecessor_trail_length = my_predecessor->trail_length;
2186 new_trail_length = trail_length + my_predecessor_trail_length;
2187
2188 new_successor_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)
2189 * new_trail_length);
2190 memcpy (new_successor_trail, trail_peer_list,
2191 trail_length * sizeof (struct GNUNET_PeerIdentity));
2192
2193 i = trail_length;
2194 while (i < new_trail_length)
2195 {
2196 memcpy (&new_successor_trail[i],&(my_predecessor->trail_peer_list[i]),
2197 sizeof (struct GNUNET_PeerIdentity));
2198 i++;
2199 }
2200
2201
2202 GDS_NEIGHBOURS_handle_verify_successor_result (destination_peer,
2203 &(my_identity),
2204 &(my_predecessor->finger_identity),
2205 target_friend,
2206 new_successor_trail,
2207 new_trail_length,
2208 current_trail_index);
2209 }
1994 2210
1995 /*SUPU: Initialize all the fields. */ 2211 GDS_NEIGHBOURS_handle_verify_successor_result (destination_peer,
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), 2212 &(my_identity),
2003 &(finger->finger_identity), 2213 &(my_predecessor->finger_identity),
2004 target_friend, 2214 target_friend,
2005 trail_peer_list, 2215 trail_peer_list,
2006 trail_length, 2216 trail_length,
2007 current_trail_index); */ 2217 current_trail_index);
2218
2008 } 2219 }
2009 else 2220 else
2010 { 2221 {
2011 /* FIXME: Initialize all the parameters to 2222 memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity));
2012 * this function. Read the element at current_trail_index + 1 2223 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2013 and call GDS_NEIGHBOURS_handle_verify_successor with correct parameters. */ 2224 GNUNET_free (next_hop);
2014 /* FIXME: Uncomment after initializing the fields. 2225
2015 * GDS_NEIGUBOURS_handle_verify_successor(&(vsm->source_peer), 2226 current_trail_index = current_trail_index + 1;
2227
2228 GDS_NEIGUBOURS_handle_verify_successor(&(vsm->source_peer),
2016 &(vsm->successor), 2229 &(vsm->successor),
2017 target_friend, 2230 target_friend,
2018 trail_peer_list, 2231 trail_peer_list,
2019 trail_length, 2232 trail_length,
2020 current_trail_index); */ 2233 current_trail_index);
2021 } 2234 }
2022 return GNUNET_YES; 2235 return GNUNET_YES;
2023} 2236}
2024 2237
2025 2238
2026/** 2239/**
2027 * Core handle for p2p trail construction result messages. 2240 * Update successor field in finger table with new successor.
2241 * @param successor New successor which is the predecessor my old successor.
2242 * @param peer_list Trail list to reach to new successor = trail to reach old
2243 * successor + trail to reach to new successor from that old successor.
2244 * @param trail_length Number of peers to reach to the new successor.
2245 */
2246static void
2247update_successor (struct GNUNET_PeerIdentity *successor,
2248 struct GNUNET_PeerIdentity *peer_list,
2249 unsigned int trail_length)
2250{
2251 /* FIXME: Here you can call fix_fingers. */
2252
2253}
2254
2255
2256/**
2257 * FIXME: Also copy the trail list in reverse direction that is the path to
2258 * reach to your predecessor.
2259 * Replace your predecessor with new predecessor.
2260 * @param predecessor My new predecessor
2261 * @param peer_list Trail list to reach to my new predecessor
2262 * @param trail_length Number of peers in the trail.
2263 */
2264static void
2265update_predecessor (struct GNUNET_PeerIdentity *predecessor,
2266 struct GNUNET_PeerIdentity *peer_list,
2267 unsigned int trail_length)
2268{
2269 /* In this function, you should first read the whole peer_list in
2270 * opposite direction and copy in into trail_peer field of finger entry.
2271 * also search for pervious predecessor and change the predecessor flag to 0.
2272 * add the entry into finger table with predecessor flag = 1.
2273 */
2274 unsigned int successor_flag;
2275 unsigned int predecessor_flag;
2276 unsigned int finger_index;
2277
2278 successor_flag = 0;
2279 predecessor_flag = 1;
2280 finger_index = 1;
2281 /* FIXME: Assumption that predecessor is always stored at current_finger_index = 1.*/
2282 finger_table_add (predecessor, peer_list, trail_length, successor_flag,
2283 predecessor_flag, finger_index);
2284
2285 /* FIXME: Here you should call fix_Fingers. */
2286}
2287
2288
2289/**
2290 * Core handle for p2p notify new successor messages.
2028 * @param cls closure 2291 * @param cls closure
2029 * @param message message 2292 * @param message message
2030 * @param peer peer identity this notification is about 2293 * @param peer peer identity this notification is about
@@ -2034,18 +2297,66 @@ static int
2034handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer, 2297handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer,
2035 const struct GNUNET_MessageHeader *message) 2298 const struct GNUNET_MessageHeader *message)
2036{ 2299{
2037 /* 2300 struct PeerNotifyNewSuccessorMessage *nsm;
2038 * So, if you are the destination you should update your 2301 size_t msize;
2039 * predecessor field with peer id of source peer of this message. 2302 unsigned int trail_length;
2040 * If you are not the destination peer, then just check your routing 2303 struct GNUNET_PeerIdentity *trail_peer_list;
2041 * table and pass on the message. 2304 unsigned int current_trail_index;
2042 */ 2305
2306 msize = ntohs (message->size);
2307 if (msize < sizeof (struct PeerNotifyNewSuccessorMessage))
2308 {
2309 GNUNET_break_op (0);
2310 return GNUNET_YES;
2311 }
2312
2313 /* Again in the function you have the whole trail to reach to the destination. */
2314 nsm = (struct PeerNotifyNewSuccessorMessage *) message;
2315 current_trail_index = ntohl (nsm->current_index);
2316 trail_length = ntohl (nsm->trail_length);
2317
2318 trail_peer_list = (struct GNUNET_PeerIdentity *) &nsm[1];
2319
2320 if ((msize <
2321 sizeof (struct PeerNotifyNewSuccessorMessage) +
2322 trail_length * sizeof (struct GNUNET_PeerIdentity)) ||
2323 (trail_length >
2324 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
2325 {
2326 GNUNET_break_op (0);
2327 return GNUNET_YES;
2328 }
2329
2330 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(nsm->destination_peer),
2331 &my_identity)))
2332 {
2333 update_predecessor (&(nsm->source_peer),
2334 trail_peer_list,
2335 trail_length);
2336 return GNUNET_YES;
2337 }
2338 else
2339 {
2340 struct FriendInfo *target_friend;
2341 target_friend = GNUNET_malloc (sizeof (struct FriendInfo));
2342 struct GNUNET_PeerIdentity *next_hop;
2343 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
2344 memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity));
2345 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2346 GNUNET_free (next_hop);
2347 current_trail_index = current_trail_index + 1;
2348
2349 GDS_NEIGHBOURS_notify_new_successor (&(nsm->source_peer),
2350 &(nsm->destination_peer),
2351 target_friend, trail_peer_list, trail_length,
2352 current_trail_index);
2353 }
2043 return GNUNET_YES; 2354 return GNUNET_YES;
2044} 2355}
2045 2356
2046 2357
2047/** 2358/**
2048 * Core handle for p2p trail construction result messages. 2359 * Core handle for p2p verify successor result messages.
2049 * @param cls closure 2360 * @param cls closure
2050 * @param message message 2361 * @param message message
2051 * @param peer peer identity this notification is about 2362 * @param peer peer identity this notification is about
@@ -2055,15 +2366,78 @@ static int
2055handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdentity *peer, 2366handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdentity *peer,
2056 const struct GNUNET_MessageHeader *message) 2367 const struct GNUNET_MessageHeader *message)
2057{ 2368{
2058 /* 2369 struct PeerVerifySuccessorResultMessage *vsrm;
2059 * In this function you have received the message verify successor result, 2370 size_t msize;
2060 If you are not the destination, just pass this message forward 2371 struct FriendInfo *target_friend;
2061 * if you are destination, 2372 unsigned int current_trail_index;
2062 * then check if immediate predecessor of this peer is you or someone else. 2373 struct GNUNET_PeerIdentity *trail_peer_list;
2063 * If its you, then don't do anything. 2374 struct GNUNET_PeerIdentity *next_hop;
2064 * If its some one else, then call notify method to let your new successor 2375 unsigned int trail_length;
2065 * know that you are its predecessor. 2376
2066 */ 2377 msize = ntohs (message->size);
2378 if (msize < sizeof (struct PeerVerifySuccessorResultMessage))
2379 {
2380 GNUNET_break_op (0);
2381 return GNUNET_YES;
2382 }
2383
2384 /* Again in the function you have the whole trail to reach to the destination. */
2385 vsrm = (struct PeerVerifySuccessorResultMessage *) message;
2386 current_trail_index = ntohl (vsrm->current_index);
2387 trail_length = ntohl (vsrm->trail_length);
2388
2389 trail_peer_list = (struct GNUNET_PeerIdentity *) &vsrm[1];
2390
2391 if ((msize <
2392 sizeof (struct PeerVerifySuccessorResultMessage) +
2393 trail_length * sizeof (struct GNUNET_PeerIdentity)) ||
2394 (trail_length >
2395 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
2396 {
2397 GNUNET_break_op (0);
2398 return GNUNET_YES;
2399 }
2400
2401 if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->destination_peer),
2402 &(my_identity))))
2403 {
2404
2405 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&(vsrm->my_predecessor),
2406 &(my_identity))))
2407 {
2408 update_successor (&(vsrm->my_predecessor), trail_peer_list, trail_length);
2409
2410 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
2411 /* FIXME: Assuming that I am also in trail list and I am the first peer. */
2412 memcpy (next_hop, &trail_peer_list[1], sizeof (struct GNUNET_PeerIdentity));
2413 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2414 GNUNET_free (next_hop);
2415
2416 GDS_NEIGHBOURS_notify_new_successor (&my_identity, &(vsrm->my_predecessor),
2417 target_friend, trail_peer_list,
2418 trail_length, current_trail_index);
2419 }
2420 }
2421 else
2422 {
2423 /* Read the peer trail list and find out the next destination to forward this
2424 packet to. */
2425 next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
2426
2427 /* FIXME: Assuming that I am also in trail list and I am the first peer. */
2428 memcpy (next_hop, &trail_peer_list[current_trail_index], sizeof (struct GNUNET_PeerIdentity));
2429 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2430 GNUNET_free (next_hop);
2431 current_trail_index = current_trail_index - 1;
2432
2433 GDS_NEIGHBOURS_handle_verify_successor_result (&(vsrm->destination_peer),
2434 &(vsrm->source_successor),
2435 &(vsrm->my_predecessor),
2436 target_friend,
2437 trail_peer_list,
2438 trail_length,
2439 current_trail_index);
2440 }
2067 return GNUNET_YES; 2441 return GNUNET_YES;
2068} 2442}
2069 2443
@@ -2116,8 +2490,15 @@ GDS_NEIGHBOURS_done ()
2116 GNUNET_ATS_performance_done (atsAPI); 2490 GNUNET_ATS_performance_done (atsAPI);
2117 atsAPI = NULL; 2491 atsAPI = NULL;
2118 2492
2119 /* FIXME: Once handle_core_disconnect is implemented, both below assertion should not 2493 /* FIXME: In case of friends, every time we are disconnected from a friend
2120 fail. */ 2494 we remove it from friend table. So, this assertion works for friend.
2495 But in case of finger_peermap, we never remove any entry from our
2496 finger peermap. So, either when we remove the friend from friend peermap,then
2497 I remove all the finger for which that friend was the first trail and leave
2498 it on send_find_finger_trail to eventually find path to that finger. In that
2499 case may be assertion for finger peermap will also succed. Or else if
2500 peermap are not empty check it and empty it and then destroy because
2501 multipeermpa_destroy does not free individual entries. */
2121 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)); 2502 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap));
2122 GNUNET_CONTAINER_multipeermap_destroy (friend_peermap); 2503 GNUNET_CONTAINER_multipeermap_destroy (friend_peermap);
2123 friend_peermap = NULL; 2504 friend_peermap = NULL;
diff --git a/src/dht/gnunet-service-xdht_routing.c b/src/dht/gnunet-service-xdht_routing.c
index 13f0d3e77..5830dc9f8 100644
--- a/src/dht/gnunet-service-xdht_routing.c
+++ b/src/dht/gnunet-service-xdht_routing.c
@@ -44,6 +44,7 @@
44 44
45 45
46/** 46/**
47 * FIXME: Do we need a field prev_hop
47 * Routing table entry . 48 * Routing table entry .
48 */ 49 */
49struct RoutingTrail 50struct RoutingTrail
@@ -59,11 +60,6 @@ struct RoutingTrail
59 struct GNUNET_PeerIdentity *destination; 60 struct GNUNET_PeerIdentity *destination;
60 61
61 /** 62 /**
62 * The peer this request was received from.
63 */
64 struct GNUNET_PeerIdentity *previous_hop;
65
66 /**
67 * The peer to which this request should be passed to. 63 * The peer to which this request should be passed to.
68 */ 64 */
69 struct GNUNET_PeerIdentity *next_hop; 65 struct GNUNET_PeerIdentity *next_hop;
@@ -93,11 +89,6 @@ GDS_ROUTING_add (struct GNUNET_PeerIdentity *source,
93{ 89{
94 struct RoutingTrail *new_routing_entry; 90 struct RoutingTrail *new_routing_entry;
95 91
96 new_routing_entry = GNUNET_malloc (sizeof (struct RoutingTrail));
97 new_routing_entry->source = source;
98 new_routing_entry->next_hop = next_hop;
99 new_routing_entry->destination = dest;
100
101 /* If dest is already present in the routing table, then exit.*/ 92 /* If dest is already present in the routing table, then exit.*/
102 if (GNUNET_YES == 93 if (GNUNET_YES ==
103 GNUNET_CONTAINER_multipeermap_contains (routing_table, 94 GNUNET_CONTAINER_multipeermap_contains (routing_table,
@@ -106,11 +97,16 @@ GDS_ROUTING_add (struct GNUNET_PeerIdentity *source,
106 GNUNET_break (0); 97 GNUNET_break (0);
107 return; 98 return;
108 } 99 }
109 100
101 new_routing_entry = GNUNET_malloc (sizeof (struct RoutingTrail));
102 new_routing_entry->source = source;
103 new_routing_entry->next_hop = next_hop;
104 new_routing_entry->destination = dest;
105
110 GNUNET_assert (GNUNET_OK == 106 GNUNET_assert (GNUNET_OK ==
111 GNUNET_CONTAINER_multipeermap_put (routing_table, 107 GNUNET_CONTAINER_multipeermap_put (routing_table,
112 dest, new_routing_entry, 108 dest, new_routing_entry,
113 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 109 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
114} 110}
115 111
116 112