diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-05-30 10:51:55 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-05-30 10:51:55 +0000 |
commit | fd1c80797d6136587fa12bb14c88307156c45171 (patch) | |
tree | f283a3df9b3f87b999c181b793ab664ab16575b3 /src/dht/gnunet-service-xdht_neighbours.c | |
parent | 9955561e1b204ccf23fbf841f409bd3ef79be88c (diff) | |
download | gnunet-fd1c80797d6136587fa12bb14c88307156c45171.tar.gz gnunet-fd1c80797d6136587fa12bb14c88307156c45171.zip |
-Adapting trail teardown and add trail messages for trail id.
Diffstat (limited to 'src/dht/gnunet-service-xdht_neighbours.c')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 229 |
1 files changed, 202 insertions, 27 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 61a818cd3..549b122ac 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -337,6 +337,26 @@ struct PeerTrailTearDownMessage | |||
337 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_TEARDOWN | 337 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_TEARDOWN |
338 | */ | 338 | */ |
339 | struct GNUNET_MessageHeader header; | 339 | struct GNUNET_MessageHeader header; |
340 | |||
341 | /** | ||
342 | * Source peer of the trail. | ||
343 | */ | ||
344 | struct GNUNET_PeerIdentity source_peer; | ||
345 | |||
346 | /** | ||
347 | * Destination peer of the trail. | ||
348 | */ | ||
349 | struct GNUNET_PeerIdentity destination_peer; | ||
350 | |||
351 | /** | ||
352 | * Unique identifier of the trail. | ||
353 | */ | ||
354 | struct GNUNET_HashCode TRAIL_ID; | ||
355 | |||
356 | /** | ||
357 | * Direction of trail. | ||
358 | */ | ||
359 | enum GDS_ROUTING_trail_direction trail_direction; | ||
340 | }; | 360 | }; |
341 | 361 | ||
342 | 362 | ||
@@ -1034,11 +1054,11 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_ | |||
1034 | 1054 | ||
1035 | /** | 1055 | /** |
1036 | * Construct a trail teardown message and send it to target_friend | 1056 | * Construct a trail teardown message and send it to target_friend |
1037 | * @param source_peer | 1057 | * @param source_peer Source of the trail. |
1038 | * @param destination_peer | 1058 | * @param destination_peer Destination of the trail. |
1039 | * @param trail_id | 1059 | * @param trail_id Unique identifier of the trail. |
1040 | * @param trail_direction | 1060 | * @param trail_direction Direction of trail. |
1041 | * @param target_friend | 1061 | * @param target_friend Friend to get this message. |
1042 | */ | 1062 | */ |
1043 | void | 1063 | void |
1044 | GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_PeerIdentity source_peer, | 1064 | GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_PeerIdentity source_peer, |
@@ -1047,7 +1067,40 @@ GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_PeerIdentity source_peer, | |||
1047 | enum GDS_ROUTING_trail_direction trail_direction, | 1067 | enum GDS_ROUTING_trail_direction trail_direction, |
1048 | struct FriendInfo *target_friend) | 1068 | struct FriendInfo *target_friend) |
1049 | { | 1069 | { |
1070 | struct PeerTrailTearDownMessage *ttdm; | ||
1071 | struct P2PPendingMessage *pending; | ||
1072 | size_t msize; | ||
1073 | |||
1074 | msize = sizeof (struct PeerTrailTearDownMessage); | ||
1075 | |||
1076 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
1077 | { | ||
1078 | GNUNET_break (0); | ||
1079 | return; | ||
1080 | } | ||
1050 | 1081 | ||
1082 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1083 | { | ||
1084 | GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), | ||
1085 | 1, GNUNET_NO); | ||
1086 | } | ||
1087 | |||
1088 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | ||
1089 | pending->importance = 0; /* FIXME */ | ||
1090 | pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); | ||
1091 | ttdm = (struct PeerTrailTearDownMessage *) &pending[1]; | ||
1092 | pending->msg = &ttdm->header; | ||
1093 | ttdm->header.size = htons (msize); | ||
1094 | ttdm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_TEARDOWN); | ||
1095 | ttdm->source_peer = source_peer; | ||
1096 | ttdm->destination_peer = destination_peer; | ||
1097 | ttdm->TRAIL_ID = trail_id; | ||
1098 | ttdm->trail_direction = htonl (trail_direction); | ||
1099 | |||
1100 | /* Send the message to chosen friend. */ | ||
1101 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | ||
1102 | target_friend->pending_count++; | ||
1103 | process_friend_queue (target_friend); | ||
1051 | } | 1104 | } |
1052 | 1105 | ||
1053 | 1106 | ||
@@ -2625,7 +2678,7 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
2625 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->destination_peer), | 2678 | if (0 != (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->destination_peer), |
2626 | &(trail_result->finger_identity)))) | 2679 | &(trail_result->finger_identity)))) |
2627 | { | 2680 | { |
2628 | GDS_ROUTING_add (trail_id, &next_hop, peer); | 2681 | GDS_ROUTING_add (trail_id, next_hop, *peer); |
2629 | } | 2682 | } |
2630 | 2683 | ||
2631 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); | 2684 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); |
@@ -2850,6 +2903,10 @@ handle_dht_p2p_verify_successor(void *cls, const struct GNUNET_PeerIdentity *pee | |||
2850 | 2903 | ||
2851 | 2904 | ||
2852 | /** | 2905 | /** |
2906 | * FIXME: I will keep the logic to remove the old trail to reach from me to | ||
2907 | * my old successor here and move adding a new trail from me to new successor to notify | ||
2908 | * new successor. And in case if the new successor also take it as predecessor | ||
2909 | * then call add_trail. | ||
2853 | * Core handle for p2p verify successor result messages. | 2910 | * Core handle for p2p verify successor result messages. |
2854 | * @param cls closure | 2911 | * @param cls closure |
2855 | * @param message message | 2912 | * @param message message |
@@ -2867,6 +2924,7 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2867 | struct GNUNET_PeerIdentity *new_trail; | 2924 | struct GNUNET_PeerIdentity *new_trail; |
2868 | struct GNUNET_PeerIdentity destination_peer; | 2925 | struct GNUNET_PeerIdentity destination_peer; |
2869 | struct GNUNET_PeerIdentity my_new_successor; | 2926 | struct GNUNET_PeerIdentity my_new_successor; |
2927 | struct GNUNET_PeerIdentity old_successor; | ||
2870 | struct GNUNET_PeerIdentity *next_hop; | 2928 | struct GNUNET_PeerIdentity *next_hop; |
2871 | struct FriendInfo *target_friend; | 2929 | struct FriendInfo *target_friend; |
2872 | size_t msize; | 2930 | size_t msize; |
@@ -2896,10 +2954,12 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2896 | new_trail = (struct GNUNET_PeerIdentity *) &vsrm[1]; | 2954 | new_trail = (struct GNUNET_PeerIdentity *) &vsrm[1]; |
2897 | destination_peer = vsrm->destination_peer; | 2955 | destination_peer = vsrm->destination_peer; |
2898 | my_new_successor = vsrm->my_predecessor; | 2956 | my_new_successor = vsrm->my_predecessor; |
2957 | old_successor = vsrm->source_successor; | ||
2899 | 2958 | ||
2900 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&destination_peer, &my_identity))) | 2959 | if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&destination_peer, &my_identity))) |
2901 | { | 2960 | { |
2902 | struct GNUNET_HashCode new_finger_trail_id; | 2961 | struct GNUNET_HashCode new_finger_trail_id; |
2962 | /* FIXME: generate a new trail id. */ | ||
2903 | if (GNUNET_YES == finger_table_add (my_new_successor, | 2963 | if (GNUNET_YES == finger_table_add (my_new_successor, |
2904 | new_trail, | 2964 | new_trail, |
2905 | new_trail_length, | 2965 | new_trail_length, |
@@ -2911,6 +2971,8 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2911 | else | 2971 | else |
2912 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 2972 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
2913 | peer); | 2973 | peer); |
2974 | GDS_NEIGHBOURS_send_trail_teardown (my_identity, old_successor, trail_id, | ||
2975 | GDS_ROUTING_SRC_TO_DEST, target_friend); | ||
2914 | GDS_NEIGHBOURS_send_notify_new_successor (my_identity, my_new_successor, | 2976 | GDS_NEIGHBOURS_send_notify_new_successor (my_identity, my_new_successor, |
2915 | new_trail, | 2977 | new_trail, |
2916 | new_trail_length, | 2978 | new_trail_length, |
@@ -2931,15 +2993,8 @@ handle_dht_p2p_verify_successor_result(void *cls, const struct GNUNET_PeerIdenti | |||
2931 | return GNUNET_OK; | 2993 | return GNUNET_OK; |
2932 | } | 2994 | } |
2933 | 2995 | ||
2934 | 2996 | ||
2935 | /** | 2997 | /* |
2936 | * Here we need to pass the whole trail to reach to new successor as we | ||
2937 | don't have that stored in our routing table. while passing through each | ||
2938 | peer we will have to add an entry. also when you are the destination and | ||
2939 | if you have added it back as pred, then you also need to add the trail in | ||
2940 | your own finger table and send add trail message to add this trail. you | ||
2941 | shoudl generate a new trail id. although they are same trails but you have | ||
2942 | to ahve different trail id. | ||
2943 | * Core handle for p2p notify new successor messages. | 2998 | * Core handle for p2p notify new successor messages. |
2944 | * @param cls closure | 2999 | * @param cls closure |
2945 | * @param message message | 3000 | * @param message message |
@@ -2950,22 +3005,24 @@ static int | |||
2950 | handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer, | 3005 | handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity *peer, |
2951 | const struct GNUNET_MessageHeader *message) | 3006 | const struct GNUNET_MessageHeader *message) |
2952 | { | 3007 | { |
2953 | #if 0 | ||
2954 | struct PeerNotifyNewSuccessorMessage *nsm; | 3008 | struct PeerNotifyNewSuccessorMessage *nsm; |
2955 | struct GNUNET_PeerIdentity *trail; | 3009 | struct GNUNET_PeerIdentity *trail; |
2956 | struct GNUNET_PeerIdentity source; | 3010 | struct GNUNET_PeerIdentity source; |
2957 | struct GNUNET_PeerIdentity destination; | 3011 | struct GNUNET_PeerIdentity destination; |
2958 | struct FriendInfo *target_friend; | 3012 | struct FriendInfo *target_friend; |
2959 | //struct GNUNET_HashCode trail_id; | 3013 | struct GNUNET_HashCode trail_id; |
3014 | unsigned int my_index; | ||
3015 | struct GNUNET_PeerIdentity next_hop; | ||
2960 | size_t msize; | 3016 | size_t msize; |
2961 | uint32_t trail_length; | 3017 | uint32_t trail_length; |
2962 | 3018 | ||
2963 | msize = ntohs (message->size); | 3019 | msize = ntohs (message->size); |
2964 | if (msize < sizeof (struct PeerNotifyNewSuccessorMessage)) | 3020 | if (msize != sizeof (struct PeerNotifyNewSuccessorMessage)) |
2965 | { | 3021 | { |
2966 | GNUNET_break_op (0); | 3022 | GNUNET_break_op (0); |
2967 | return GNUNET_YES; | 3023 | return GNUNET_YES; |
2968 | } | 3024 | } |
3025 | |||
2969 | nsm = (struct PeerNotifyNewSuccessorMessage *) message; | 3026 | nsm = (struct PeerNotifyNewSuccessorMessage *) message; |
2970 | trail_length = ntohl (nsm->trail_length); | 3027 | trail_length = ntohl (nsm->trail_length); |
2971 | 3028 | ||
@@ -2981,26 +3038,48 @@ handle_dht_p2p_notify_new_successor(void *cls, const struct GNUNET_PeerIdentity | |||
2981 | trail = (struct GNUNET_PeerIdentity *) &nsm[1]; | 3038 | trail = (struct GNUNET_PeerIdentity *) &nsm[1]; |
2982 | source = nsm->source_peer; | 3039 | source = nsm->source_peer; |
2983 | destination = nsm->destination_peer; | 3040 | destination = nsm->destination_peer; |
2984 | //trail_id = nsm->trail_id; | 3041 | trail_id = nsm->trail_id; |
2985 | 3042 | ||
2986 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination)) | 3043 | if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &destination)) |
2987 | { | 3044 | { |
2988 | struct GNUNET_HashCode new_trail_id; | 3045 | struct GNUNET_HashCode new_trail_id; |
2989 | struct FingerInfo *my_predecessor; | 3046 | struct FingerInfo *my_predecessor; |
3047 | |||
3048 | my_predecessor = | ||
3049 | GNUNET_CONTAINER_multihashmap32_get (finger_hashmap, | ||
3050 | PREDECESSOR_FINGER_ID); | ||
3051 | /* FIXME: get new_trail_id*/ | ||
3052 | |||
2990 | if (GNUNET_YES == is_new_entry_correct_predecessor (my_predecessor, | 3053 | if (GNUNET_YES == is_new_entry_correct_predecessor (my_predecessor, |
2991 | source, trail, | 3054 | source, trail, |
2992 | trail_length)) | 3055 | trail_length)) |
2993 | { | 3056 | { |
3057 | |||
3058 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
3059 | peer); | ||
2994 | GDS_NEIGHBOURS_send_add_trail (my_identity, source, new_trail_id, | 3060 | GDS_NEIGHBOURS_send_add_trail (my_identity, source, new_trail_id, |
2995 | trail, trail_length, target_friend); | 3061 | trail, trail_length, target_friend); |
3062 | return GNUNET_OK; | ||
2996 | } | 3063 | } |
2997 | } | 3064 | } |
2998 | 3065 | ||
2999 | //GDS_ROUTING_add (new_trail_id, peer, next_hop); | 3066 | my_index = search_my_index (trail, trail_length); |
3000 | #endif | 3067 | if (GNUNET_SYSERR == my_index) |
3068 | { | ||
3069 | GNUNET_break_op (0); | ||
3070 | return GNUNET_SYSERR; | ||
3071 | } | ||
3072 | if (trail_length == my_index) | ||
3073 | next_hop = destination; | ||
3074 | else | ||
3075 | next_hop = trail[my_index + 1]; | ||
3076 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, *peer, next_hop)); | ||
3077 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); | ||
3078 | GDS_NEIGHBOURS_send_notify_new_successor (source, destination, trail, | ||
3079 | trail_length, | ||
3080 | trail_id, target_friend); | ||
3001 | return GNUNET_OK; | 3081 | return GNUNET_OK; |
3002 | } | 3082 | } |
3003 | |||
3004 | 3083 | ||
3005 | 3084 | ||
3006 | /** | 3085 | /** |
@@ -3203,12 +3282,52 @@ static int | |||
3203 | handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer, | 3282 | handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer, |
3204 | const struct GNUNET_MessageHeader *message) | 3283 | const struct GNUNET_MessageHeader *message) |
3205 | { | 3284 | { |
3285 | struct PeerTrailTearDownMessage *trail_teardown; | ||
3286 | struct GNUNET_HashCode trail_id; | ||
3287 | enum GDS_ROUTING_trail_direction trail_direction; | ||
3288 | size_t msize; | ||
3289 | |||
3290 | msize = ntohs (message->size); | ||
3291 | if (msize != sizeof (struct PeerTrailTearDownMessage)) | ||
3292 | { | ||
3293 | GNUNET_break_op (0); | ||
3294 | return GNUNET_OK; | ||
3295 | } | ||
3296 | |||
3297 | trail_teardown = (struct PeerTrailTearDownMessage *) message; | ||
3298 | trail_direction = ntohl (trail_teardown->trail_direction); | ||
3299 | trail_id = trail_teardown->TRAIL_ID; | ||
3300 | |||
3301 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | ||
3302 | &trail_teardown->destination_peer)) | ||
3303 | { | ||
3304 | struct GNUNET_PeerIdentity *next_hop; | ||
3305 | struct FriendInfo *target_friend; | ||
3306 | |||
3307 | next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction); | ||
3308 | if (NULL == next_hop) | ||
3309 | { | ||
3310 | GNUNET_break (0); | ||
3311 | return GNUNET_SYSERR; | ||
3312 | } | ||
3313 | |||
3314 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
3315 | next_hop); | ||
3316 | GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id)); | ||
3317 | GDS_NEIGHBOURS_send_trail_teardown (trail_teardown->source_peer, | ||
3318 | trail_teardown->destination_peer, | ||
3319 | trail_id, trail_direction, | ||
3320 | target_friend); | ||
3321 | } | ||
3206 | return GNUNET_OK; | 3322 | return GNUNET_OK; |
3207 | } | 3323 | } |
3208 | 3324 | ||
3209 | 3325 | ||
3210 | /** | 3326 | /** |
3211 | * TRAIL ID and each peer should add an entry in the routing table. | 3327 | * Fixme: this function is called only in case in notify new successor, the new |
3328 | * successor wants to add the source of the peer as its predecessor. Identify | ||
3329 | * if there is any other use case where it is required and if yes then adapt the | ||
3330 | * code for it. | ||
3212 | * Core handle for p2p add trail message. | 3331 | * Core handle for p2p add trail message. |
3213 | * @param cls closure | 3332 | * @param cls closure |
3214 | * @param message message | 3333 | * @param message message |
@@ -3219,7 +3338,63 @@ static int | |||
3219 | handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | 3338 | handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, |
3220 | const struct GNUNET_MessageHeader *message) | 3339 | const struct GNUNET_MessageHeader *message) |
3221 | { | 3340 | { |
3222 | return GNUNET_OK; | 3341 | struct PeerAddTrailMessage *add_trail; |
3342 | struct GNUNET_PeerIdentity *trail; | ||
3343 | struct GNUNET_HashCode trail_id; | ||
3344 | struct GNUNET_PeerIdentity destination_peer; | ||
3345 | struct GNUNET_PeerIdentity source_peer; | ||
3346 | struct GNUNET_PeerIdentity next_hop; | ||
3347 | unsigned int trail_length; | ||
3348 | unsigned int my_index; | ||
3349 | size_t msize; | ||
3350 | |||
3351 | msize = ntohs (message->size); | ||
3352 | if (msize != sizeof (struct PeerAddTrailMessage)) | ||
3353 | { | ||
3354 | GNUNET_break_op (0); | ||
3355 | return GNUNET_OK; | ||
3356 | } | ||
3357 | |||
3358 | add_trail = (struct PeerAddTrailMessage *) message; | ||
3359 | trail_length = ntohl (add_trail->trail_length); | ||
3360 | |||
3361 | if ((msize < sizeof (struct PeerAddTrailMessage) + | ||
3362 | trail_length * sizeof (struct GNUNET_PeerIdentity)) || | ||
3363 | (trail_length > | ||
3364 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) | ||
3365 | { | ||
3366 | GNUNET_break_op (0); | ||
3367 | return GNUNET_OK; | ||
3368 | } | ||
3369 | |||
3370 | trail = (struct GNUNET_PeerIdentity *)&add_trail[1]; | ||
3371 | destination_peer = add_trail->destination_peer; | ||
3372 | source_peer = add_trail->source_peer; | ||
3373 | trail_id = add_trail->trail_id; | ||
3374 | |||
3375 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, | ||
3376 | &destination_peer)) | ||
3377 | { | ||
3378 | struct FriendInfo *target_friend; | ||
3379 | |||
3380 | my_index = search_my_index (trail, trail_length); | ||
3381 | if (GNUNET_SYSERR == my_index) | ||
3382 | { | ||
3383 | GNUNET_break_op (0); | ||
3384 | return GNUNET_SYSERR; | ||
3385 | } | ||
3386 | |||
3387 | if (0 == my_index) | ||
3388 | next_hop = source_peer; | ||
3389 | else | ||
3390 | next_hop = trail[trail_length - 1]; | ||
3391 | |||
3392 | GNUNET_assert (GNUNET_OK == GDS_ROUTING_add (trail_id, next_hop, *peer)); | ||
3393 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); | ||
3394 | GDS_NEIGHBOURS_send_add_trail (source_peer, destination_peer, trail_id, | ||
3395 | trail, trail_length, target_friend); | ||
3396 | } | ||
3397 | return GNUNET_OK; | ||
3223 | } | 3398 | } |
3224 | 3399 | ||
3225 | 3400 | ||