aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-xdht_neighbours.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-service-xdht_neighbours.c')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index dde456037..3d17a07fa 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -845,6 +845,16 @@ struct Closest_Peer
845 unsigned int finger_table_index; 845 unsigned int finger_table_index;
846}; 846};
847 847
848/**
849 * Context for send_verify_successor_task.
850 */
851struct VerifySuccessorContext
852{
853 /**
854 * Number of times this has been scheduled.
855 */
856 unsigned int num_retries_scheduled;
857};
848 858
849/** 859/**
850 * Task that sends FIND FINGER TRAIL requests. This task is started when we have 860 * Task that sends FIND FINGER TRAIL requests. This task is started when we have
@@ -3160,10 +3170,6 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
3160 return; 3170 return;
3161} 3171}
3162 3172
3163struct VerifySuccessorContext
3164{
3165 unsigned int num_retries_scheduled;
3166};
3167 3173
3168/** 3174/**
3169 * Periodic task to verify current successor. There can be multiple trails to reach 3175 * Periodic task to verify current successor. There can be multiple trails to reach
@@ -3174,7 +3180,7 @@ struct VerifySuccessorContext
3174 */ 3180 */
3175static void 3181static void
3176send_verify_successor_message (void *cls, 3182send_verify_successor_message (void *cls,
3177 const struct GNUNET_SCHEDULER_TaskContext *tc) 3183 const struct GNUNET_SCHEDULER_TaskContext *tc)
3178{ 3184{
3179 struct FriendInfo *target_friend; 3185 struct FriendInfo *target_friend;
3180 struct GNUNET_HashCode trail_id; 3186 struct GNUNET_HashCode trail_id;
@@ -3184,6 +3190,8 @@ send_verify_successor_message (void *cls,
3184 unsigned int i = 0; 3190 unsigned int i = 0;
3185 struct FingerInfo *successor; 3191 struct FingerInfo *successor;
3186 3192
3193 successor = &finger_table[0];
3194
3187 /* This task will be scheduled when the result for Verify Successor is received. */ 3195 /* This task will be scheduled when the result for Verify Successor is received. */
3188 send_verify_successor_task = GNUNET_SCHEDULER_NO_TASK; 3196 send_verify_successor_task = GNUNET_SCHEDULER_NO_TASK;
3189 3197
@@ -3194,13 +3202,29 @@ send_verify_successor_message (void *cls,
3194 */ 3202 */
3195 if (NULL == cls) 3203 if (NULL == cls)
3196 { 3204 {
3205 /* FIXME: Here we are scheduling a new verify successor task, as we
3206 got a new successor. But a send verify successor task may be in progress.
3207 1. We need to be sure that this is indeed a new successor. As this function
3208 is called even if we add a new trail to reach t old successor.
3209 2. Assuming the new successor is different, then verify successor message
3210 * to old successor may be following stages.
3211 * --> Waiting for verify successor result. Don't wait anymore. there is
3212 * no trail to reach from old successor to me, hence, routing
3213 * lookup will fail.
3214 * --> Waiting for notify confirmation. again don't wait for it. notify
3215 * confirmation will not succeded.
3216 */
3197 if (send_verify_successor_retry_task != GNUNET_SCHEDULER_NO_TASK) 3217 if (send_verify_successor_retry_task != GNUNET_SCHEDULER_NO_TASK)
3198 { 3218 {
3219 /* FIXME: Are we scheduling retry task as soon as we send verify message.
3220 If yes then here before making this task, first check if the message
3221 is for the same peer again. */
3199 struct VerifySuccessorContext *old_ctx = 3222 struct VerifySuccessorContext *old_ctx =
3200 GNUNET_SCHEDULER_cancel(send_verify_successor_retry_task); 3223 GNUNET_SCHEDULER_cancel(send_verify_successor_retry_task);
3201 /* old_ctx must not be NULL, as the retry task had been scheduled */ 3224 /* old_ctx must not be NULL, as the retry task had been scheduled */
3202 GNUNET_assert(NULL != old_ctx); 3225 GNUNET_assert(NULL != old_ctx);
3203 GNUNET_free(old_ctx); 3226 GNUNET_free(old_ctx);
3227 /* FIXME: Why don't we reset the task to NO_TASK here? */
3204 } 3228 }
3205 3229
3206 struct VerifySuccessorContext *ctx; 3230 struct VerifySuccessorContext *ctx;
@@ -3225,14 +3249,6 @@ send_verify_successor_message (void *cls,
3225 ctx); 3249 ctx);
3226 } 3250 }
3227 3251
3228 successor = &finger_table[0];
3229 /* We are waiting for a confirmation from the notify message and we have not
3230 * crossed the wait time, then return. */
3231// if ((1 == waiting_for_notify_confirmation)
3232// && (0 != GNUNET_TIME_absolute_get_remaining(successor->wait_notify_confirmation).rel_value_us))
3233// {
3234// return;
3235// }
3236 /* Among all the trails to reach to successor, select first one which is present.*/ 3252 /* Among all the trails to reach to successor, select first one which is present.*/
3237 for (i = 0; i < successor->trails_count; i++) 3253 for (i = 0; i < successor->trails_count; i++)
3238 { 3254 {
@@ -3737,14 +3753,12 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3737 3753
3738 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_best_known_dest, &my_identity))) 3754 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_best_known_dest, &my_identity)))
3739 { 3755 {
3740 next_routing_hop = GDS_ROUTING_get_next_hop (intermediate_trail_id, 3756 next_routing_hop = GDS_ROUTING_get_next_hop (received_intermediate_trail_id,
3741 GDS_ROUTING_SRC_TO_DEST); 3757 GDS_ROUTING_SRC_TO_DEST);
3742 if (NULL != next_routing_hop) 3758 if (NULL != next_routing_hop)
3743 { 3759 {
3744 next_hop = next_routing_hop; 3760 next_hop = next_routing_hop;
3745 intermediate_trail_id = received_intermediate_trail_id; 3761 intermediate_trail_id = received_intermediate_trail_id;
3746 FPRINTF (stderr,_("\nSUPU %s, %s, %d,intermediate_trail_id=%s"),__FILE__, __func__,__LINE__,GNUNET_h2s(&intermediate_trail_id));
3747
3748 best_known_dest = current_best_known_dest; 3762 best_known_dest = current_best_known_dest;
3749 } 3763 }
3750 } 3764 }
@@ -3881,7 +3895,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3881 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_best_known_dest, &my_identity))) 3895 if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&current_best_known_dest, &my_identity)))
3882 { 3896 {
3883 next_routing_hop = GDS_ROUTING_get_next_hop (received_intermediate_trail_id, 3897 next_routing_hop = GDS_ROUTING_get_next_hop (received_intermediate_trail_id,
3884 GDS_ROUTING_SRC_TO_DEST); 3898 GDS_ROUTING_SRC_TO_DEST);
3885 if (NULL != next_routing_hop) 3899 if (NULL != next_routing_hop)
3886 { 3900 {
3887 next_hop = next_routing_hop; 3901 next_hop = next_routing_hop;
@@ -5333,22 +5347,8 @@ handle_dht_p2p_notify_new_successor(void *cls,
5333 next_hop = new_successor; 5347 next_hop = new_successor;
5334 else 5348 else
5335 next_hop = trail[my_index + 1]; 5349 next_hop = trail[my_index + 1];
5336 /* Add an entry in routing table for trail from source to its new successor. */
5337 /* TODO : Verify the logic below
5338 * Removed th following error check because GNUNET_SYSERR is returned when
5339 * route with trail_id was already in the routing table. This can happen, when
5340 * notify_successor was being retried. This should not be an error, and should
5341 * be ignored.
5342 */
5343 GDS_ROUTING_add(trail_id, *peer, next_hop);
5344// if (GNUNET_SYSERR == GDS_ROUTING_add (trail_id, *peer, next_hop))
5345// {
5346//
5347// GNUNET_break(0);
5348// return GNUNET_OK;
5349//
5350// }
5351 5350
5351 GDS_ROUTING_add(trail_id, *peer, next_hop);
5352 target_friend = 5352 target_friend =
5353 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); 5353 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop);
5354 if (NULL == target_friend) 5354 if (NULL == target_friend)
@@ -5731,10 +5731,6 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
5731 source_peer = add_trail->source_peer; 5731 source_peer = add_trail->source_peer;
5732 trail_id = add_trail->trail_id; 5732 trail_id = add_trail->trail_id;
5733 5733
5734 //FIXME: add a check that sender peer is not malicious. Make it a generic
5735 // function so that it can be used in all other functions where we need the
5736 // same functionality.
5737
5738 /* I am not the destination of the trail. */ 5734 /* I am not the destination of the trail. */
5739 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination_peer)) 5735 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination_peer))
5740 { 5736 {
@@ -5762,7 +5758,8 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
5762 next_hop = trail[my_index + 1]; 5758 next_hop = trail[my_index + 1];
5763 } 5759 }
5764 /* Add in your routing table. */ 5760 /* Add in your routing table. */
5765 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer)); 5761 GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, next_hop));
5762 //GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer));
5766 GNUNET_assert (NULL != 5763 GNUNET_assert (NULL !=
5767 (target_friend = 5764 (target_friend =
5768 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); 5765 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop)));