aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-06-19 22:31:03 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-06-19 22:31:03 +0000
commit43e731e418561ac45f923212dd8bba7c8d4a3cb4 (patch)
treea5a83aef9eb4ca8a9b877058e2bd49e2fc7052f2 /src
parent52ac9153ac1af25700c5302e0b1f28e76714043a (diff)
downloadgnunet-43e731e418561ac45f923212dd8bba7c8d4a3cb4.tar.gz
gnunet-43e731e418561ac45f923212dd8bba7c8d4a3cb4.zip
- Initializing head, tail in datacache struct get_context
- Static analysis bug fixes - Other minor fixes
Diffstat (limited to 'src')
-rw-r--r--src/dht/gnunet-service-xdht_clients.c1
-rw-r--r--src/dht/gnunet-service-xdht_datacache.c20
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c341
3 files changed, 205 insertions, 157 deletions
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c
index 59fbd6f17..b9cfd6dda 100644
--- a/src/dht/gnunet-service-xdht_clients.c
+++ b/src/dht/gnunet-service-xdht_clients.c
@@ -850,7 +850,6 @@ transmit_request (struct ClientQueryRecord *cqr)
850 GNUNET_h2s (&cqr->key), 850 GNUNET_h2s (&cqr->key),
851 cqr->replication, 851 cqr->replication,
852 cqr->seen_replies_count); 852 cqr->seen_replies_count);
853
854 GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options, 853 GDS_NEIGHBOURS_send_get (&cqr->key, cqr->type, cqr->msg_options,
855 cqr->replication, NULL, NULL , NULL, 854 cqr->replication, NULL, NULL , NULL,
856 0, 0, NULL); 855 0, 0, NULL);
diff --git a/src/dht/gnunet-service-xdht_datacache.c b/src/dht/gnunet-service-xdht_datacache.c
index a1c42528e..5f35f088b 100644
--- a/src/dht/gnunet-service-xdht_datacache.c
+++ b/src/dht/gnunet-service-xdht_datacache.c
@@ -166,6 +166,7 @@ struct GetRequestContext
166 * Tail of get path. 166 * Tail of get path.
167 */ 167 */
168 struct GetPath *tail; 168 struct GetPath *tail;
169
169 /* get_path */ 170 /* get_path */
170}; 171};
171 172
@@ -213,16 +214,18 @@ datacache_get_iterator (void *cls,
213 ("# Good RESULTS found in datacache"), 1, 214 ("# Good RESULTS found in datacache"), 1,
214 GNUNET_NO); 215 GNUNET_NO);
215 struct GNUNET_PeerIdentity *get_path; 216 struct GNUNET_PeerIdentity *get_path;
216 get_path = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 217 get_path = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) *
218 ctx->get_path_length);
217 struct GetPath *iterator; 219 struct GetPath *iterator;
218 iterator = ctx->head; 220 iterator = ctx->head;
219 int i = 0; 221 int i = 0;
220 while (i < ctx->get_path_length) 222 while (i < ctx->get_path_length)
221 { 223 {
222 memcpy (&get_path[i], &(iterator->peer), sizeof (struct GNUNET_PeerIdentity)); 224 get_path[i] = iterator->peer;
223 i++; 225 i++;
224 iterator = iterator->next; 226 iterator = iterator->next;
225 } 227 }
228
226 GDS_NEIGHBOURS_send_get_result (key,type, &(ctx->next_hop),&(ctx->source_peer), 229 GDS_NEIGHBOURS_send_get_result (key,type, &(ctx->next_hop),&(ctx->source_peer),
227 put_path_length, put_path, ctx->get_path_length, 230 put_path_length, put_path, ctx->get_path_length,
228 get_path, exp, data, size ); 231 get_path, exp, data, size );
@@ -304,23 +307,22 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key,
304 ctx.reply_bf = reply_bf; 307 ctx.reply_bf = reply_bf;
305 ctx.reply_bf_mutator = reply_bf_mutator; 308 ctx.reply_bf_mutator = reply_bf_mutator;
306 ctx.get_path_length = get_path_length; 309 ctx.get_path_length = get_path_length;
307 ctx.head = NULL; 310
308 ctx.tail = NULL;
309 if (next_hop != NULL) 311 if (next_hop != NULL)
310 memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity)); 312 memcpy (&(ctx.next_hop), next_hop, sizeof (struct GNUNET_PeerIdentity));
311 313
312 int i = 0; 314 unsigned int i = 0;
313 315 ctx.head = NULL;
316 ctx.tail = NULL;
314 if (get_path != NULL) 317 if (get_path != NULL)
315 { 318 {
316 while (i < get_path_length) 319 while (i < get_path_length)
317 { 320 {
318 struct GetPath *element; 321 struct GetPath *element;
319 element = GNUNET_malloc (sizeof (struct GetPath)); 322 element = GNUNET_new (struct GetPath);
320 element->next = NULL; 323 element->next = NULL;
321 element->prev = NULL; 324 element->prev = NULL;
322 325 element->peer = get_path[i];
323 memcpy (&(element->peer), &get_path[i], sizeof(struct GNUNET_PeerIdentity));
324 GNUNET_CONTAINER_DLL_insert (ctx.head, ctx.tail, element); 326 GNUNET_CONTAINER_DLL_insert (ctx.head, ctx.tail, element);
325 i++; 327 i++;
326 } 328 }
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 2e6a3f69d..a0b1c378f 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -50,22 +50,9 @@
50 * recover in case of peer failure. We can do it in Chord way. In R5N, the key 50 * recover in case of peer failure. We can do it in Chord way. In R5N, the key
51 * is hashed and then data is stored according to the key value generated after 51 * is hashed and then data is stored according to the key value generated after
52 * hashing. 52 * hashing.
53 * 2. Now souce and destination of a trail also stores the trail entries for 53 * 2. We will keep an entry in routing table even if its a friend for the moment.
54 * which they are end point. Make these changes in case of gds_routing_add() 54 * Because I am not sure if there is a case where it will not work.
55 * 3. Should we append xvine in message which are of xvine dht? 55 * Trail id we can keep but actually there is no trail.
56 * 4. make sure you are adding trail for end point of trail everywhere.
57 * 5. Should we increment the trail count of a friend which is a finger.
58 *
59 * 8. Check everywhere if the peer from which you got the message is correct or
60 * not.
61 * 9. if finger is a friend then don't add any entry in routing table of the
62 * end points.
63 * frued
64 * Important
65 * Should we add an entry in our routing table if I am the immediate friend
66 * and finger also. Yes add it at the moment later we can remove it if it does
67 * not look correct. In notify new successor we add a new trail irrespective
68 * that the trail is destination or not.
69 */ 56 */
70 57
71/** 58/**
@@ -103,7 +90,7 @@
103/** 90/**
104 * Maximum number of trails stored per finger. 91 * Maximum number of trails stored per finger.
105 */ 92 */
106#define MAXIMUM_TRAILS_PER_FINGER 2 93#define MAXIMUM_TRAILS_PER_FINGER 1
107 94
108/** 95/**
109 * Finger map index for predecessor entry in finger table. 96 * Finger map index for predecessor entry in finger table.
@@ -112,12 +99,11 @@
112 99
113/** 100/**
114 * Wrap around in peer identity circle. 101 * Wrap around in peer identity circle.
115 * FIXME: not used anywhere, should be used in
116 * find_successor() while comparing two peers.
117 */ 102 */
118#define PEER_IDENTITES_WRAP_AROUND pow(2, 64) - 1 103#define PEER_IDENTITES_WRAP_AROUND pow(2, 64) - 1
119 104
120/** 105/**
106 * FIXME: Its use only at 3 places check if you can remove it.
121 * To check if a finger is predecessor or not. 107 * To check if a finger is predecessor or not.
122 */ 108 */
123enum GDS_NEIGHBOURS_finger_type 109enum GDS_NEIGHBOURS_finger_type
@@ -751,6 +737,11 @@ struct Trail
751 * Length of trail pointed 737 * Length of trail pointed
752 */ 738 */
753 unsigned int trail_length; 739 unsigned int trail_length;
740
741 /**
742 * Is there a valid trail entry.
743 */
744 unsigned int is_present;
754}; 745};
755 746
756/** 747/**
@@ -1226,7 +1217,7 @@ GDS_NEIGHBOURS_send_trail_rejection (struct GNUNET_PeerIdentity source_peer,
1226void 1217void
1227GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_peer, 1218GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_peer,
1228 struct GNUNET_PeerIdentity successor, 1219 struct GNUNET_PeerIdentity successor,
1229 const struct GNUNET_HashCode *trail_id, 1220 struct GNUNET_HashCode trail_id,
1230 struct GNUNET_PeerIdentity *trail, 1221 struct GNUNET_PeerIdentity *trail,
1231 unsigned int trail_length, 1222 unsigned int trail_length,
1232 struct FriendInfo *target_friend) 1223 struct FriendInfo *target_friend)
@@ -1258,10 +1249,7 @@ GDS_NEIGHBOURS_send_verify_successor_message (struct GNUNET_PeerIdentity source_
1258 vsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR); 1249 vsm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR);
1259 vsm->source_peer = source_peer; 1250 vsm->source_peer = source_peer;
1260 vsm->successor = successor; 1251 vsm->successor = successor;
1261 if (NULL == trail_id) 1252 vsm->trail_id = trail_id;
1262 memset (&vsm->trail_id, 0, sizeof (vsm->trail_id));
1263 else
1264 vsm->trail_id = *trail_id;
1265 1253
1266 if (trail_length > 0) 1254 if (trail_length > 0)
1267 { 1255 {
@@ -1686,7 +1674,6 @@ select_closest_finger (struct GNUNET_PeerIdentity *peer1,
1686 1674
1687 memcpy (&peer1_value, peer1, sizeof (uint64_t)); 1675 memcpy (&peer1_value, peer1, sizeof (uint64_t));
1688 memcpy (&peer2_value, peer2, sizeof (uint64_t)); 1676 memcpy (&peer2_value, peer2, sizeof (uint64_t));
1689
1690 if (peer1_value == value) 1677 if (peer1_value == value)
1691 { 1678 {
1692 return peer1; 1679 return peer1;
@@ -1844,12 +1831,12 @@ compare_finger_and_current_successor (struct Closest_Peer *current_closest_peer)
1844{ 1831{
1845 struct FingerInfo *finger; 1832 struct FingerInfo *finger;
1846 struct FriendInfo *friend; 1833 struct FriendInfo *friend;
1847 struct Selected_Finger_Trail *finger_trail;
1848 struct GNUNET_PeerIdentity *closest_peer; 1834 struct GNUNET_PeerIdentity *closest_peer;
1849 int i; 1835 int i;
1850 1836
1851 for (i = 0; i < MAX_FINGERS; i++) 1837 for (i = 0; i < MAX_FINGERS; i++)
1852 { 1838 {
1839 struct Selected_Finger_Trail *finger_trail;
1853 finger = &finger_table[i]; 1840 finger = &finger_table[i];
1854 1841
1855 if (GNUNET_NO == finger->is_present) 1842 if (GNUNET_NO == finger->is_present)
@@ -2009,7 +1996,7 @@ find_successor (uint64_t destination_finger_value,
2009{ 1996{
2010 struct Closest_Peer *current_closest_peer; 1997 struct Closest_Peer *current_closest_peer;
2011 struct GNUNET_PeerIdentity *next_hop; 1998 struct GNUNET_PeerIdentity *next_hop;
2012 1999
2013 /* Initialize current_successor to my_identity. */ 2000 /* Initialize current_successor to my_identity. */
2014 current_closest_peer = init_current_successor (my_identity, 2001 current_closest_peer = init_current_successor (my_identity,
2015 destination_finger_value, 2002 destination_finger_value,
@@ -2070,6 +2057,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2070 struct P2PPendingMessage *pending; 2057 struct P2PPendingMessage *pending;
2071 struct FriendInfo *target_friend; 2058 struct FriendInfo *target_friend;
2072 struct GNUNET_PeerIdentity *pp; 2059 struct GNUNET_PeerIdentity *pp;
2060 struct GNUNET_PeerIdentity *local_best_known_dest;
2073 size_t msize; 2061 size_t msize;
2074 2062
2075 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + 2063 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size +
@@ -2095,9 +2083,11 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2095 struct GNUNET_PeerIdentity *next_hop; 2083 struct GNUNET_PeerIdentity *next_hop;
2096 2084
2097 memcpy (&key_value, key, sizeof (uint64_t)); 2085 memcpy (&key_value, key, sizeof (uint64_t));
2098 next_hop = find_successor (key_value, best_known_dest, 2086 local_best_known_dest = GNUNET_new (struct GNUNET_PeerIdentity);
2087
2088 next_hop = find_successor (key_value, local_best_known_dest,
2099 intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); 2089 intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR);
2100 if (0 == GNUNET_CRYPTO_cmp_peer_identity(next_hop, &my_identity)) 2090 if (0 == GNUNET_CRYPTO_cmp_peer_identity (local_best_known_dest, &my_identity))
2101 { 2091 {
2102 /* I am the destination but we have already done datacache_put in client file. */ 2092 /* I am the destination but we have already done datacache_put in client file. */
2103 return; 2093 return;
@@ -2105,7 +2095,10 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2105 else 2095 else
2106 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 2096 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2107 } 2097 }
2108 2098 else
2099 {
2100 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer);
2101 }
2109 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2102 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
2110 pending->timeout = expiration_time; 2103 pending->timeout = expiration_time;
2111 ppm = (struct PeerPutMessage *) &pending[1]; 2104 ppm = (struct PeerPutMessage *) &pending[1];
@@ -2118,7 +2111,10 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2118 ppm->desired_replication_level = htonl (desired_replication_level); 2111 ppm->desired_replication_level = htonl (desired_replication_level);
2119 ppm->put_path_length = htonl (put_path_length); 2112 ppm->put_path_length = htonl (put_path_length);
2120 ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); 2113 ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
2121 ppm->best_known_destination = *best_known_dest; 2114 if (NULL == best_known_dest)
2115 ppm->best_known_destination = *local_best_known_dest;
2116 else
2117 ppm->best_known_destination = *best_known_dest;
2122 ppm->key = *key; 2118 ppm->key = *key;
2123 if (NULL == intermediate_trail_id) 2119 if (NULL == intermediate_trail_id)
2124 memset (&ppm->intermediate_trail_id, 0, sizeof (ppm->intermediate_trail_id)); 2120 memset (&ppm->intermediate_trail_id, 0, sizeof (ppm->intermediate_trail_id));
@@ -2131,8 +2127,6 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2131 sizeof (struct GNUNET_PeerIdentity) * put_path_length); 2127 sizeof (struct GNUNET_PeerIdentity) * put_path_length);
2132 } 2128 }
2133 memcpy (&pp[put_path_length], data, data_size); 2129 memcpy (&pp[put_path_length], data, data_size);
2134 if (NULL == target_friend)
2135 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer);
2136 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 2130 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
2137 target_friend->pending_count++; 2131 target_friend->pending_count++;
2138 process_friend_queue (target_friend); 2132 process_friend_queue (target_friend);
@@ -2170,6 +2164,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2170 struct PeerGetMessage *pgm; 2164 struct PeerGetMessage *pgm;
2171 struct P2PPendingMessage *pending; 2165 struct P2PPendingMessage *pending;
2172 struct FriendInfo *target_friend; 2166 struct FriendInfo *target_friend;
2167 struct GNUNET_PeerIdentity *local_best_known_dest;
2173 struct GNUNET_PeerIdentity *gp; 2168 struct GNUNET_PeerIdentity *gp;
2174 size_t msize; 2169 size_t msize;
2175 2170
@@ -2189,11 +2184,11 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2189 2184
2190 memcpy (&key_value, key, sizeof (uint64_t)); 2185 memcpy (&key_value, key, sizeof (uint64_t));
2191 // FIXME: endianess of key_value!? 2186 // FIXME: endianess of key_value!?
2192 /* FIXME: Here you should use enum GDS_NEIGHBOURS_FINGER_TYPE in place of 0. */ 2187 local_best_known_dest = GNUNET_new (struct GNUNET_PeerIdentity);
2193 next_hop = find_successor (key_value, best_known_dest, 2188 next_hop = find_successor (key_value, local_best_known_dest,
2194 intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); 2189 intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR);
2195 2190
2196 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity,next_hop)) 2191 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity,next_hop))
2197 { 2192 {
2198 GDS_DATACACHE_handle_get (key,block_type, NULL, 0, 2193 GDS_DATACACHE_handle_get (key,block_type, NULL, 0,
2199 NULL, 0, 1, &my_identity, NULL,&my_identity); 2194 NULL, 0, 1, &my_identity, NULL,&my_identity);
@@ -2204,6 +2199,10 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2204 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop); 2199 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
2205 } 2200 }
2206 } 2201 }
2202 else
2203 {
2204 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer);
2205 }
2207 2206
2208 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2207 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
2209 pending->importance = 0; /* FIXME */ 2208 pending->importance = 0; /* FIXME */
@@ -2213,8 +2212,15 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2213 pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); 2212 pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET);
2214 pgm->get_path_length = htonl (get_path_length); 2213 pgm->get_path_length = htonl (get_path_length);
2215 pgm->key = *key; 2214 pgm->key = *key;
2216 pgm->best_known_destination = *best_known_dest; 2215 if (NULL != best_known_dest)
2217 pgm->intermediate_trail_id = *intermediate_trail_id; 2216 pgm->best_known_destination = *best_known_dest;
2217 else
2218 pgm->best_known_destination = *local_best_known_dest;
2219
2220 if (NULL == intermediate_trail_id)
2221 memset (&pgm->intermediate_trail_id, 0, sizeof (pgm->intermediate_trail_id));
2222 else
2223 pgm->intermediate_trail_id = *intermediate_trail_id;
2218 pgm->hop_count = htonl (hop_count + 1); 2224 pgm->hop_count = htonl (hop_count + 1);
2219 2225
2220 if (get_path != 0) 2226 if (get_path != 0)
@@ -2222,8 +2228,6 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2222 gp = (struct GNUNET_PeerIdentity *) &pgm[1]; 2228 gp = (struct GNUNET_PeerIdentity *) &pgm[1];
2223 memcpy (gp, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); 2229 memcpy (gp, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity));
2224 } 2230 }
2225 if (NULL == target_friend)
2226 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer);
2227 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); 2231 GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
2228 target_friend->pending_count++; 2232 target_friend->pending_count++;
2229 process_friend_queue (target_friend); 2233 process_friend_queue (target_friend);
@@ -2263,7 +2267,7 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key,
2263 struct FriendInfo *target_friend; 2267 struct FriendInfo *target_friend;
2264 int current_path_index; 2268 int current_path_index;
2265 size_t msize; 2269 size_t msize;
2266 2270
2267 msize = get_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + 2271 msize = get_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size +
2268 sizeof (struct PeerPutMessage); 2272 sizeof (struct PeerPutMessage);
2269 2273
@@ -2445,7 +2449,7 @@ send_find_finger_trail_message (void *cls,
2445 { 2449 {
2446 return; 2450 return;
2447 } 2451 }
2448 2452
2449 finger_id_value = compute_finger_identity_value (current_search_finger_index); 2453 finger_id_value = compute_finger_identity_value (current_search_finger_index);
2450 if (PREDECESSOR_FINGER_ID == current_search_finger_index) 2454 if (PREDECESSOR_FINGER_ID == current_search_finger_index)
2451 is_predecessor = 1; 2455 is_predecessor = 1;
@@ -2700,6 +2704,8 @@ free_trail (struct Trail *trail)
2700 trail_element); 2704 trail_element);
2701 GNUNET_free_non_null (trail_element); 2705 GNUNET_free_non_null (trail_element);
2702 } 2706 }
2707 trail->trail_head = NULL;
2708 trail->trail_tail = NULL;
2703} 2709}
2704 2710
2705 2711
@@ -2716,6 +2722,9 @@ free_finger (struct FingerInfo *finger, unsigned int finger_table_index)
2716 for (i = 0; i < finger->trails_count; i++) 2722 for (i = 0; i < finger->trails_count; i++)
2717 { 2723 {
2718 trail = &finger->trail_list[i]; 2724 trail = &finger->trail_list[i];
2725 if (GNUNET_NO == trail->is_present)
2726 continue;
2727
2719 if (trail->trail_length > 0) 2728 if (trail->trail_length > 0)
2720 free_trail (trail); 2729 free_trail (trail);
2721 } 2730 }
@@ -2726,8 +2735,13 @@ free_finger (struct FingerInfo *finger, unsigned int finger_table_index)
2726 2735
2727 2736
2728/** 2737/**
2738 * FIXME: ensure that you are not adding any trail to reach to a friend which
2739 * is a finger. Also decide on should you increment trails count of a friend
2740 * which is also a finger.
2729 * Add a new entry in finger table at finger_table_index. 2741 * Add a new entry in finger table at finger_table_index.
2730 * In case finger identity is me or a friend, then don't add a trail. 2742 * In case finger identity is me or a friend, then don't add a trail. NOTE
2743 * trail length to reach to a finger can be 0 only if the finger is a friend
2744 * or my identity.
2731 * In case a finger is a friend, then increment the trails count of the friend. 2745 * In case a finger is a friend, then increment the trails count of the friend.
2732 * @param finger_identity Peer Identity of new finger 2746 * @param finger_identity Peer Identity of new finger
2733 * @param finger_trail Trail to reach from me to finger (excluding both end points). 2747 * @param finger_trail Trail to reach from me to finger (excluding both end points).
@@ -2752,48 +2766,47 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
2752 new_entry->finger_table_index = finger_table_index; 2766 new_entry->finger_table_index = finger_table_index;
2753 new_entry->is_present = GNUNET_YES; 2767 new_entry->is_present = GNUNET_YES;
2754 2768
2755 /* Finger is not my identity. */ 2769 /* If the new entry is my own identity or a friend. */
2756 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) 2770 if ((0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) ||
2771 (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)))
2757 { 2772 {
2758 if (finger_trail_length == 0) 2773 new_entry->trails_count = 0;
2759 { 2774 finger_table[finger_table_index] = *new_entry;
2760 first_trail_hop = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2775 return;
2761 &finger_identity); 2776 }
2762 first_trail_hop->trails_count++; 2777
2763 finger_table[finger_table_index] = *new_entry; 2778 /* finger trail length can be 0 only in case if finger is my identity or
2764 return; 2779 finger is friend. We should never reach here. */
2765 } 2780 GNUNET_assert (finger_trail_length > 0);
2766 2781
2767 /* PRINT TRAIL remove*/ 2782 GNUNET_assert (NULL !=
2768 2783 (first_trail_hop =
2769 GNUNET_assert(NULL !=
2770 (first_trail_hop =
2771 GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2784 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2772 &finger_trail[0]))); 2785 &finger_trail[0])));
2773 new_entry->trails_count = 1; 2786 new_entry->trails_count = 1;
2774 first_trail_hop->trails_count++; 2787 first_trail_hop->trails_count++;
2775 2788
2776 /* Copy the finger trail into trail. */ 2789 /* Copy the finger trail into trail. */
2777 trail = GNUNET_new (struct Trail); 2790 trail = GNUNET_new (struct Trail);
2778 while (i < finger_trail_length) 2791 while (i < finger_trail_length)
2779 { 2792 {
2780 struct Trail_Element *element = GNUNET_new (struct Trail_Element); 2793 struct Trail_Element *element = GNUNET_new (struct Trail_Element);
2781
2782 element->next = NULL;
2783 element->prev = NULL;
2784 element->peer = finger_trail[i];
2785 GNUNET_CONTAINER_DLL_insert_tail (trail->trail_head,
2786 trail->trail_tail,
2787 element);
2788 i++;
2789 }
2790 /* Add trail to trail list. */
2791 new_entry->trail_list[0].trail_head = trail->trail_head;
2792 new_entry->trail_list[0].trail_tail = trail->trail_tail;
2793 new_entry->trail_list[0].trail_length = finger_trail_length;
2794 new_entry->trail_list[0].trail_id = trail_id;
2795 }
2796 2794
2795 element->next = NULL;
2796 element->prev = NULL;
2797 element->peer = finger_trail[i];
2798 GNUNET_CONTAINER_DLL_insert_tail (trail->trail_head,
2799 trail->trail_tail,
2800 element);
2801 i++;
2802 }
2803
2804 /* Add trail to trail list. */
2805 new_entry->trail_list[0].trail_head = trail->trail_head;
2806 new_entry->trail_list[0].trail_tail = trail->trail_tail;
2807 new_entry->trail_list[0].trail_length = finger_trail_length;
2808 new_entry->trail_list[0].trail_id = trail_id;
2809 new_entry->trail_list[0].is_present = GNUNET_YES;
2797 finger_table[finger_table_index] = *new_entry; 2810 finger_table[finger_table_index] = *new_entry;
2798 return; 2811 return;
2799} 2812}
@@ -2883,7 +2896,6 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity,
2883 2896
2884 /* If we found no other friend except the first hop, return the original 2897 /* If we found no other friend except the first hop, return the original
2885 trail back.*/ 2898 trail back.*/
2886
2887 new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); 2899 new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length);
2888 *new_trail_length = trail_length; 2900 *new_trail_length = trail_length;
2889 memcpy (new_trail, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); 2901 memcpy (new_trail, trail, trail_length * sizeof (struct GNUNET_PeerIdentity));
@@ -2892,69 +2904,91 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity,
2892 2904
2893 2905
2894/** 2906/**
2895 * FIXME: Ensure that we add trail in succession in the trail list. 2907 * Send verify successor message to your current successor over the shortest
2896 * There are no free spots within the trail list. 2908 * trail.
2897 * Send verify successor message to your successor on all trails to reach 2909 * @param successor Current successor.
2898 * the successor.
2899 * @param successor My current successor
2900 */ 2910 */
2901static void 2911static void
2902send_verify_successor_message (struct FingerInfo *successor) 2912send_verify_successor_message (struct FingerInfo *successor)
2903{ 2913{
2904 struct Trail *trail_list_iterator; 2914 /*
2905 struct GNUNET_HashCode *trail_id; 2915 * FIXME: should we send a verify successor message across all the trails
2906 struct GNUNET_PeerIdentity next_hop; 2916 * in case we send through all friends. It complicates the logic, don't
2917 * do it at the moment. Write it as optimization and do it later.
2918 * 1. Here we can have 3 types of fingers
2919 * --> my own identity
2920 * Assumption that the calling function will not send request for
2921 * such successor. Move the logic here.
2922 * --> friend is a finger
2923 * Need to verify if we keep the trails count for a friend. In case of
2924 * friend there is no trail to reach to that friend, so
2925 * 1. no entry in routing table
2926 * 2. no trail id
2927 * 3. no trails count
2928 * 4. but do we increment the count of trails through the friend?
2929 * Trails count is used only to keep a limit on number of trails
2930 * that a friend should be part of. No need to increment the trails
2931 * count for a friend which is a finegr also. so, if finger = friend
2932 * then don't increment the trails count. But if the same friend
2933 * is the first friend to reach to some other finger then increment
2934 * the trails count. Not sure if this design is correct need to verify
2935 * again.
2936 * --> real finger
2937 */
2907 struct FriendInfo *target_friend; 2938 struct FriendInfo *target_friend;
2908 struct GNUNET_PeerIdentity *trail; 2939 struct GNUNET_HashCode trail_id;
2909 unsigned int trail_length;
2910 int i; 2940 int i;
2911 int j; 2941
2912
2913 /* If successor is a friend. */ 2942 /* If successor is a friend. */
2914 if (successor->trails_count == 0) 2943 if (successor->trails_count == 0)
2915 { 2944 {
2916 struct FriendInfo *target_friend;
2917 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, 2945 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2918 &successor->finger_identity); 2946 &successor->finger_identity);
2947 memset ((void *)&trail_id, 0 , sizeof (trail_id));
2919 GDS_NEIGHBOURS_send_verify_successor_message (my_identity, 2948 GDS_NEIGHBOURS_send_verify_successor_message (my_identity,
2920 successor->finger_identity, 2949 successor->finger_identity,
2921 NULL, NULL, 0, 2950 trail_id, NULL, 0,
2922 target_friend); 2951 target_friend);
2952 return;
2923 } 2953 }
2924 2954
2925 trail_id = GNUNET_new (struct GNUNET_HashCode);
2926
2927 for (i = 0; i < successor->trails_count; i++) 2955 for (i = 0; i < successor->trails_count; i++)
2928 { 2956 {
2929 trail_list_iterator = &successor->trail_list[i]; 2957 struct Trail *trail;
2930 GNUNET_assert (NULL != trail_list_iterator->trail_head); 2958 struct Trail_Element *element;
2931 2959 unsigned int trail_length;
2932 if (trail_list_iterator->trail_length > 0) 2960 int j;
2933 { 2961
2934 struct Trail_Element *element; 2962 trail = &successor->trail_list[i];
2935 2963
2936 trail_length = trail_list_iterator->trail_length; 2964 /* No trail stored at this index. */
2937 trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) 2965 if (GNUNET_YES == trail->is_present)
2938 * trail_length); 2966 continue;
2939 element = trail_list_iterator->trail_head; 2967
2940 for (j = 0; j < trail_length; j++, element = element->next) 2968 /* Only in case of a friend we can have no trail. We have already handled
2941 trail[j] = element->peer; 2969 * that case. So, now we should never have any such trail. */
2942 next_hop = trail_list_iterator->trail_head->peer; 2970 GNUNET_assert (trail->trail_length > 0);
2943 } 2971 trail_id = trail->trail_id;
2944 else 2972 trail_length = trail->trail_length;
2973
2974 /* Copy the trail into peer list. */
2975 element = trail->trail_head;
2976 struct GNUNET_PeerIdentity peer_list[trail_length];
2977 while (j < trail_length)
2945 { 2978 {
2946 trail = NULL; 2979 peer_list[j] = element->peer;
2947 trail_length = 0; 2980 element = element->next;
2948 next_hop = successor->finger_identity; 2981 j++;
2949 } 2982 }
2950 *trail_id = trail_list_iterator->trail_id; 2983
2951 GNUNET_assert (NULL != (target_friend = 2984 GNUNET_assert (NULL != (target_friend =
2952 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop))); 2985 GNUNET_CONTAINER_multipeermap_get (friend_peermap,
2953 2986 &peer_list[0])));
2954 GDS_NEIGHBOURS_send_verify_successor_message (my_identity, 2987 GDS_NEIGHBOURS_send_verify_successor_message (my_identity,
2955 successor->finger_identity, 2988 successor->finger_identity,
2956 trail_id, trail, trail_length, 2989 trail_id, peer_list, trail_length,
2957 target_friend); 2990 target_friend);
2991
2958 } 2992 }
2959} 2993}
2960 2994
@@ -3005,7 +3039,7 @@ update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity,
3005 * @return finger_table_index Value between 0 <= finger_table_index <= 64 3039 * @return finger_table_index Value between 0 <= finger_table_index <= 64
3006 * -1, if no valid finger_table_index is found. 3040 * -1, if no valid finger_table_index is found.
3007 */ 3041 */
3008static int 3042static unsigned int
3009get_finger_table_index (uint64_t ultimate_destination_finger_value, 3043get_finger_table_index (uint64_t ultimate_destination_finger_value,
3010 unsigned int is_predecessor) 3044 unsigned int is_predecessor)
3011{ 3045{
@@ -3146,8 +3180,8 @@ test_finger_table_print()
3146 } 3180 }
3147 } 3181 }
3148} 3182}
3149
3150#endif 3183#endif
3184
3151/** 3185/**
3152 * Check if there is already an entry in finger_table at finger_table_index. 3186 * Check if there is already an entry in finger_table at finger_table_index.
3153 * We get the finger_table_index from 64bit finger value we got from the network. 3187 * We get the finger_table_index from 64bit finger value we got from the network.
@@ -3158,8 +3192,8 @@ test_finger_table_print()
3158 * finger. 3192 * finger.
3159 * -- If the new finger is closest, remove the existing entry, send trail 3193 * -- If the new finger is closest, remove the existing entry, send trail
3160 * teardown message across all the trails to reach the existing entry. 3194 * teardown message across all the trails to reach the existing entry.
3161 * Add the trail. 3195 * Add the new finger.
3162 * -- If new and existing finger are different, and existing finger is same 3196 * -- If new and existing finger are different, and existing finger is closest
3163 * then do nothing. 3197 * then do nothing.
3164 * -- Update current_search_finger_index. 3198 * -- Update current_search_finger_index.
3165 * @param finger_identity Peer Identity of new finger 3199 * @param finger_identity Peer Identity of new finger
@@ -3191,11 +3225,12 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3191 finger_table_index = get_finger_table_index (finger_value, is_predecessor); 3225 finger_table_index = get_finger_table_index (finger_value, is_predecessor);
3192 3226
3193 /* Invalid finger_table_index. */ 3227 /* Invalid finger_table_index. */
3194 if ((finger_table_index > PREDECESSOR_FINGER_ID) || (finger_table_index < 0)) 3228 if ((finger_table_index > PREDECESSOR_FINGER_ID))
3195 { 3229 {
3196 GNUNET_break_op (0); 3230 GNUNET_break_op (0);
3197 return; 3231 return;
3198 } 3232 }
3233
3199 updated_finger_trail_length = finger_trail_length; 3234 updated_finger_trail_length = finger_trail_length;
3200 updated_trail = 3235 updated_trail =
3201 scan_and_compress_trail (finger_identity, finger_trail, 3236 scan_and_compress_trail (finger_identity, finger_trail,
@@ -3204,7 +3239,9 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3204 3239
3205 /* If the new entry is same as successor then don't add it in finger table, 3240 /* If the new entry is same as successor then don't add it in finger table,
3206 reset the current search finger index and exit. */ 3241 reset the current search finger index and exit. */
3207 if ((0 != finger_table_index) && (PREDECESSOR_FINGER_ID != finger_table_index)) 3242 if ((0 != finger_table_index) &&
3243 (PREDECESSOR_FINGER_ID != finger_table_index) &&
3244 (finger_table_index == current_search_finger_index))
3208 { 3245 {
3209 successor = &finger_table[0]; 3246 successor = &finger_table[0];
3210 GNUNET_assert (GNUNET_YES == successor->is_present); 3247 GNUNET_assert (GNUNET_YES == successor->is_present);
@@ -3390,7 +3427,6 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3390 } 3427 }
3391 else 3428 else
3392 { 3429 {
3393 /*FIXME: Here you should use enum GDS_NEIGHBOURS_FINGER_TYPE in place of 0. */
3394 next_hop = find_successor (key_value, &best_known_dest, 3430 next_hop = find_successor (key_value, &best_known_dest,
3395 &intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); 3431 &intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR);
3396 } 3432 }
@@ -3481,7 +3517,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3481 GNUNET_break_op (0); 3517 GNUNET_break_op (0);
3482 return GNUNET_YES; 3518 return GNUNET_YES;
3483 } 3519 }
3484 3520
3485 /* Add sender to get path */ 3521 /* Add sender to get path */
3486 struct GNUNET_PeerIdentity gp[get_length + 1]; 3522 struct GNUNET_PeerIdentity gp[get_length + 1];
3487 memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity)); 3523 memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity));
@@ -3496,7 +3532,6 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3496 } 3532 }
3497 else 3533 else
3498 { 3534 {
3499 /*FIXME: Here you should use enum GDS_NEIGHBOURS_FINGER_TYPE in place of 0. */
3500 next_hop = find_successor (key_value, &best_known_dest, 3535 next_hop = find_successor (key_value, &best_known_dest,
3501 &intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR); 3536 &intermediate_trail_id, GDS_FINGER_TYPE_NON_PREDECESSOR);
3502 } 3537 }
@@ -3804,6 +3839,8 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer,
3804 is_predecessor, trail_id, 3839 is_predecessor, trail_id,
3805 &new_intermediate_trail_id); 3840 &new_intermediate_trail_id);
3806 } 3841 }
3842 GNUNET_free (local_best_known_dest);
3843 GNUNET_free (next_hop_towards_local_best_known_dest);
3807 return GNUNET_OK; 3844 return GNUNET_OK;
3808} 3845}
3809 3846
@@ -4002,7 +4039,7 @@ invert_trail (const struct GNUNET_PeerIdentity *trail,
4002 int i; 4039 int i;
4003 int j; 4040 int j;
4004 struct GNUNET_PeerIdentity *inverted_trail; 4041 struct GNUNET_PeerIdentity *inverted_trail;
4005 4042
4006 inverted_trail = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity) * 4043 inverted_trail = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity) *
4007 trail_length); 4044 trail_length);
4008 i = 0; 4045 i = 0;
@@ -4244,7 +4281,7 @@ handle_dht_p2p_verify_successor(void *cls,
4244 const struct GNUNET_MessageHeader *message) 4281 const struct GNUNET_MessageHeader *message)
4245{ 4282{
4246 const struct PeerVerifySuccessorMessage *vsm; 4283 const struct PeerVerifySuccessorMessage *vsm;
4247 const struct GNUNET_HashCode *trail_id; 4284 struct GNUNET_HashCode trail_id;
4248 struct GNUNET_PeerIdentity successor; 4285 struct GNUNET_PeerIdentity successor;
4249 struct GNUNET_PeerIdentity source_peer; 4286 struct GNUNET_PeerIdentity source_peer;
4250 struct GNUNET_PeerIdentity *trail; 4287 struct GNUNET_PeerIdentity *trail;
@@ -4277,9 +4314,7 @@ handle_dht_p2p_verify_successor(void *cls,
4277 return GNUNET_OK; 4314 return GNUNET_OK;
4278 } 4315 }
4279 4316
4280 4317 trail_id = vsm->trail_id;
4281 trail_id = GNUNET_new (struct GNUNET_HashCode);
4282 trail_id = &vsm->trail_id;
4283 source_peer = vsm->source_peer; 4318 source_peer = vsm->source_peer;
4284 successor = vsm->successor; 4319 successor = vsm->successor;
4285 trail = (struct GNUNET_PeerIdentity *)&vsm[1]; 4320 trail = (struct GNUNET_PeerIdentity *)&vsm[1];
@@ -4294,7 +4329,7 @@ handle_dht_p2p_verify_successor(void *cls,
4294 * the trail. */ 4329 * the trail. */
4295 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity))) 4330 if(0 != (GNUNET_CRYPTO_cmp_peer_identity (&successor, &my_identity)))
4296 { 4331 {
4297 next_hop = GDS_ROUTING_get_next_hop (*trail_id, GDS_ROUTING_SRC_TO_DEST); 4332 next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST);
4298 if (NULL == next_hop) 4333 if (NULL == next_hop)
4299 { 4334 {
4300 GNUNET_break (0); 4335 GNUNET_break (0);
@@ -4342,7 +4377,7 @@ handle_dht_p2p_verify_successor(void *cls,
4342 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer); 4377 target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer);
4343 GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity, 4378 GDS_NEIGHBOURS_send_verify_successor_result (source_peer, my_identity,
4344 current_predecessor->finger_identity, 4379 current_predecessor->finger_identity,
4345 *trail_id, trail_to_predecessor, 4380 trail_id, trail_to_predecessor,
4346 trail_to_predecessor_length, 4381 trail_to_predecessor_length,
4347 GDS_ROUTING_DEST_TO_SRC, 4382 GDS_ROUTING_DEST_TO_SRC,
4348 target_friend); 4383 target_friend);
@@ -4760,6 +4795,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
4760 my_identity, is_predecessor, 4795 my_identity, is_predecessor,
4761 new_trail,new_trail_length,trail_id, 4796 new_trail,new_trail_length,trail_id,
4762 target_friend, CONGESTION_TIMEOUT); 4797 target_friend, CONGESTION_TIMEOUT);
4798 GNUNET_free (new_trail);
4763 return GNUNET_OK; 4799 return GNUNET_OK;
4764 } 4800 }
4765 4801
@@ -4812,6 +4848,7 @@ handle_dht_p2p_trail_setup_rejection (void *cls,
4812 is_predecessor, trail_id, 4848 is_predecessor, trail_id,
4813 &new_intermediate_trail_id); 4849 &new_intermediate_trail_id);
4814 } 4850 }
4851 GNUNET_free (next_hop);
4815 return GNUNET_OK; 4852 return GNUNET_OK;
4816} 4853}
4817 4854
@@ -4934,6 +4971,7 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer
4934 4971
4935 /* If not final destination, then send a trail teardown message to next hop.*/ 4972 /* If not final destination, then send a trail teardown message to next hop.*/
4936 GDS_NEIGHBOURS_send_trail_teardown (trail_id, trail_direction, next_hop); 4973 GDS_NEIGHBOURS_send_trail_teardown (trail_id, trail_direction, next_hop);
4974 GNUNET_free (next_hop);
4937 return GNUNET_OK; 4975 return GNUNET_OK;
4938} 4976}
4939 4977
@@ -5023,7 +5061,7 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer,
5023 5061
5024 5062
5025/** 5063/**
5026 * Send trail teardown and free the trail of the finger for which the first 5064 * Send trail teardown and free the finger trail in which the first
5027 * friend to reach to a finger is disconnected_friend 5065 * friend to reach to a finger is disconnected_friend
5028 * @param disconnected_friend PeerIdentity of friend which got disconnected 5066 * @param disconnected_friend PeerIdentity of friend which got disconnected
5029 * @param remove_finger Finger whose trail we need to check if it has 5067 * @param remove_finger Finger whose trail we need to check if it has
@@ -5036,7 +5074,6 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5036 struct FingerInfo *remove_finger) 5074 struct FingerInfo *remove_finger)
5037{ 5075{
5038 unsigned int matching_trails_count; 5076 unsigned int matching_trails_count;
5039 struct Trail *trail;
5040 int i; 5077 int i;
5041 5078
5042 /* Number of trails with disconnected_friend as the first hop in the trail 5079 /* Number of trails with disconnected_friend as the first hop in the trail
@@ -5046,8 +5083,12 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5046 /* Iterate over all the trails of finger. */ 5083 /* Iterate over all the trails of finger. */
5047 for (i = 0; i < remove_finger->trails_count; i++) 5084 for (i = 0; i < remove_finger->trails_count; i++)
5048 { 5085 {
5086 struct Trail *trail;
5049 trail = &remove_finger->trail_list[i]; 5087 trail = &remove_finger->trail_list[i];
5050 5088
5089 if (GNUNET_NO == trail->is_present)
5090 continue;
5091
5051 /* First friend to reach to finger is disconnected_peer. */ 5092 /* First friend to reach to finger is disconnected_peer. */
5052 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail->trail_head->peer, 5093 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&trail->trail_head->peer,
5053 disconnected_friend)) 5094 disconnected_friend))
@@ -5064,12 +5105,13 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5064 5105
5065/** 5106/**
5066 * Iterate over finger_table entries. 5107 * Iterate over finger_table entries.
5067 * 0. Ignore finger which is my_identity. 5108 * 0. Ignore finger which is my_identity or if no valid entry present at
5109 * that finger index.
5068 * 1. If disconnected_friend is a finger, then free that entry. Don't send trail 5110 * 1. If disconnected_friend is a finger, then free that entry. Don't send trail
5069 * teardown message, as there is no trail to reach to a finger which is a friend. 5111 * teardown message, as there is no trail to reach to a finger which is a friend.
5070 * 2. Check if disconnected_friend peer is the first friend in the trail to reach to a finger. 5112 * 2. Check if disconnected_friend is the first friend in the trail to reach to a finger.
5071 * 2.1 Send trail teardown message across all the trails in which disconnected 5113 * 2.1 Send trail teardown message across all the trails in which disconnected
5072 * peer is the first friend in the trail. If disconnected_friend peer is the 5114 * friend is the first friend in the trail. If disconnected_friend is the
5073 * first friend in all the trails to reach finger, then remove the finger. 5115 * first friend in all the trails to reach finger, then remove the finger.
5074 * @param disconnected_friend Peer identity of friend which got disconnected. 5116 * @param disconnected_friend Peer identity of friend which got disconnected.
5075 */ 5117 */
@@ -5094,7 +5136,7 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_friend)
5094 &my_identity)) 5136 &my_identity))
5095 continue; 5137 continue;
5096 5138
5097 /* Is finger same as disconnected friend? */ 5139 /* Is disconnected friend a finger? */
5098 if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend, 5140 if (0 == GNUNET_CRYPTO_cmp_peer_identity (disconnected_friend,
5099 &remove_finger->finger_identity)) 5141 &remove_finger->finger_identity))
5100 { 5142 {
@@ -5110,7 +5152,7 @@ remove_matching_fingers (const struct GNUNET_PeerIdentity *disconnected_friend)
5110 removed_trails_count = remove_matching_trails (disconnected_friend, 5152 removed_trails_count = remove_matching_trails (disconnected_friend,
5111 remove_finger); 5153 remove_finger);
5112 5154
5113 /* All the finger trails has disconnected_friend as the first friend, 5155 /* All the finger trails had disconnected_friend as the first friend,
5114 * so free the finger. */ 5156 * so free the finger. */
5115 if (removed_trails_count == remove_finger->trails_count) 5157 if (removed_trails_count == remove_finger->trails_count)
5116 { 5158 {
@@ -5143,7 +5185,9 @@ handle_core_disconnect (void *cls,
5143 /* Remove fingers with peer as first friend or if peer is a finger. */ 5185 /* Remove fingers with peer as first friend or if peer is a finger. */
5144 remove_matching_fingers (peer); 5186 remove_matching_fingers (peer);
5145 5187
5146 /* Remove any trail from routing table of which peer is a part of. */ 5188 /* Remove any trail from routing table of which peer is a part of. This function
5189 * internally sends a trail teardown message in the direction of which
5190 * disconnected peer is not part of. */
5147 GDS_ROUTING_remove_trail_by_peer (peer); 5191 GDS_ROUTING_remove_trail_by_peer (peer);
5148 5192
5149 /* Remove peer from friend_peermap. */ 5193 /* Remove peer from friend_peermap. */
@@ -5151,6 +5195,7 @@ handle_core_disconnect (void *cls,
5151 GNUNET_CONTAINER_multipeermap_remove (friend_peermap, 5195 GNUNET_CONTAINER_multipeermap_remove (friend_peermap,
5152 peer, 5196 peer,
5153 remove_friend)); 5197 remove_friend));
5198
5154 if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap)) 5199 if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap))
5155 return; 5200 return;
5156 5201
@@ -5223,10 +5268,8 @@ core_init (void *cls,
5223 my_identity = *identity; 5268 my_identity = *identity;
5224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5225 "my_indentity = %s\n",GNUNET_i2s(&my_identity)); 5270 "my_indentity = %s\n",GNUNET_i2s(&my_identity));
5226#if 0
5227 FPRINTF (stderr,_("\nSUPU %s, %s, %d, my_identity = %s"), 5271 FPRINTF (stderr,_("\nSUPU %s, %s, %d, my_identity = %s"),
5228 __FILE__, __func__,__LINE__, GNUNET_i2s (&my_identity)); 5272 __FILE__, __func__,__LINE__, GNUNET_i2s (&my_identity));
5229#endif
5230} 5273}
5231 5274
5232 5275
@@ -5237,11 +5280,15 @@ static void
5237finger_table_init () 5280finger_table_init ()
5238{ 5281{
5239 int i; 5282 int i;
5283 int j;
5240 5284
5241 for(i = 0; i < MAX_FINGERS; i++) 5285 for(i = 0; i < MAX_FINGERS; i++)
5242 { 5286 {
5243 finger_table[i].is_present = GNUNET_NO; 5287 finger_table[i].is_present = GNUNET_NO;
5288 for (j = 0; j < MAXIMUM_TRAILS_PER_FINGER; j++)
5289 finger_table[i].trail_list[j].is_present = GNUNET_NO;
5244 memset ((void *)&finger_table[i], 0, sizeof (finger_table[i])); 5290 memset ((void *)&finger_table[i], 0, sizeof (finger_table[i]));
5291
5245 } 5292 }
5246} 5293}
5247 5294