+/**
+ * Core handler for P2P notify successor message
+ * @param cls closure
+ * @param message message
+ * @param peer peer identity this notification is about
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ */
+static int
+handle_dht_p2p_notify_succ_confirmation (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message)
+{
+ const struct PeerNotifyConfirmationMessage *notify_confirmation;
+ enum GDS_ROUTING_trail_direction trail_direction;
+ struct GNUNET_HashCode trail_id;
+ struct FriendInfo *target_friend;
+ struct GNUNET_PeerIdentity *next_hop;
+ size_t msize;
+
+ msize = ntohs (message->size);
+
+ if (msize != sizeof (struct PeerNotifyConfirmationMessage))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_OK;
+ }
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop
+ ("# Bytes received from other peers"), msize,
+ GNUNET_NO);
+
+ notify_confirmation = (const struct PeerNotifyConfirmationMessage *) message;
+ trail_direction = ntohl (notify_confirmation->trail_direction);
+ trail_id = notify_confirmation->trail_id;
+
+ next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction);
+ if (NULL == next_hop)
+ {
+ /* The source of notify new successor, might have found even a better
+ successor. In that case it send a trail teardown message, and hence,
+ the next hop is NULL. */
+ //Fixme: Add some print to confirm the above theory.
+ return GNUNET_OK;
+ }
+
+ /* I peer which sent the notify successor message to the successor. */
+ if (0 == GNUNET_CRYPTO_cmp_peer_identity (next_hop, &my_identity))
+ {
+ /*
+ * Schedule another round of verify sucessor with your current successor
+ * which may or may not be source of this message. This message is used
+ * only to ensure that we have a path setup to reach to our successor.
+ */
+
+ // TODO: cancel schedule of notify_successor_retry_task
+ if (send_notify_new_successor_retry_task != NULL)
+ {
+ struct SendNotifyContext *notify_ctx;
+ notify_ctx = GNUNET_SCHEDULER_cancel(send_notify_new_successor_retry_task);
+ GNUNET_free (notify_ctx->successor_trail);
+ GNUNET_free (notify_ctx);
+ send_notify_new_successor_retry_task = NULL;
+ }
+ if (send_verify_successor_task == NULL)
+ {
+ verify_successor_next_send_time.rel_value_us =
+ DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us +
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us);
+ send_verify_successor_task =
+ GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time,
+ &send_verify_successor_message,
+ NULL);
+ }
+ }
+ else
+ {
+ target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
+ if (NULL == target_friend)
+ {
+ DEBUG ("\n friend not found, line number = %d",__LINE__);
+ return GNUNET_SYSERR;
+ }
+ GDS_NEIGHBOURS_send_notify_succcessor_confirmation (trail_id,
+ GDS_ROUTING_DEST_TO_SRC,
+ target_friend);
+ }
+ return GNUNET_OK;
+}
+
+