aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-10-05 11:26:53 +0000
committerBart Polot <bart@net.in.tum.de>2011-10-05 11:26:53 +0000
commit6ee0cc926dfa4d3055c481227bc3da9282a5a863 (patch)
tree34d471cc55ad073cca5a23274f9933fc061d6a15
parent4a2288ffe56da35d9fb0e564f207f33c56fc841a (diff)
downloadgnunet-6ee0cc926dfa4d3055c481227bc3da9282a5a863.tar.gz
gnunet-6ee0cc926dfa4d3055c481227bc3da9282a5a863.zip
Moved dht get handles for types into tunnel handlers, added tasks to restart dht gets periodically
-rw-r--r--src/mesh/gnunet-service-mesh.c76
1 files changed, 43 insertions, 33 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 645b5470a..3de96341e 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -62,6 +62,9 @@
62 GNUNET_TIME_UNIT_SECONDS,\ 62 GNUNET_TIME_UNIT_SECONDS,\
63 10) 63 10)
64 64
65#define GET_RESTART_TIME GNUNET_TIME_relative_multiply(\
66 GNUNET_TIME_UNIT_SECONDS,\
67 5)
65 68
66/******************************************************************************/ 69/******************************************************************************/
67/************************ DATA STRUCTURES ****************************/ 70/************************ DATA STRUCTURES ****************************/
@@ -286,6 +289,16 @@ struct MeshTunnel
286 */ 289 */
287 struct MeshTunnelTree *tree; 290 struct MeshTunnelTree *tree;
288 291
292 /**
293 * Used to search peers offering a service
294 */
295 struct GNUNET_DHT_GetHandle *dht_get_type;
296
297 /**
298 * Task to reissue the DHT get request for a type
299 */
300 GNUNET_SCHEDULER_TaskIdentifier dht_get_type_task;
301
289 /** 302 /**
290 * Task to keep the used paths alive 303 * Task to keep the used paths alive
291 */ 304 */
@@ -346,16 +359,6 @@ struct MeshClient
346 */ 359 */
347 struct GNUNET_CONTAINER_MultiHashMap *types; 360 struct GNUNET_CONTAINER_MultiHashMap *types;
348 361
349 /**
350 * Used to search peers offering a service
351 */
352 struct GNUNET_DHT_GetHandle *dht_get_type;
353
354 /**
355 * Task to reissue the DHT get request for a type
356 */
357 GNUNET_SCHEDULER_TaskIdentifier dht_get_type_task;
358
359#if MESH_DEBUG 362#if MESH_DEBUG
360 /** 363 /**
361 * ID of the client, for debug messages 364 * ID of the client, for debug messages
@@ -1200,9 +1203,15 @@ tunnel_destroy (struct MeshTunnel *t)
1200static int 1203static int
1201tunnel_destroy_iterator (void *cls, const GNUNET_HashCode * key, void *value) 1204tunnel_destroy_iterator (void *cls, const GNUNET_HashCode * key, void *value)
1202{ 1205{
1206 struct MeshTunnel *t = value;
1203 int r; 1207 int r;
1204 1208
1205 r = tunnel_destroy ((struct MeshTunnel *) value); 1209 if (NULL != t->dht_get_type)
1210 {
1211 GNUNET_SCHEDULER_cancel (t->dht_get_type_task);
1212 GNUNET_DHT_get_stop (t->dht_get_type);
1213 }
1214 r = tunnel_destroy (t);
1206 return r; 1215 return r;
1207} 1216}
1208 1217
@@ -2264,8 +2273,8 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
2264 return; 2273 return;
2265 } 2274 }
2266 GNUNET_assert (NULL != t->client); 2275 GNUNET_assert (NULL != t->client);
2267 GNUNET_DHT_get_stop (t->client->dht_get_type); /* FIXME move to task? */ 2276 GNUNET_DHT_get_stop (t->dht_get_type); /* FIXME move to task? */
2268 t->client->dht_get_type = NULL; 2277 t->dht_get_type = NULL;
2269 peer_info = peer_info_get (pi); 2278 peer_info = peer_info_get (pi);
2270 GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey, peer_info, 2279 GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey, peer_info,
2271 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 2280 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
@@ -2346,7 +2355,7 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
2346 2355
2347 2356
2348/** 2357/**
2349 * Task run during shutdown. 2358 * Task to restart the DHT get search for a peer offering a type.
2350 * 2359 *
2351 * @param cls unused 2360 * @param cls unused
2352 * @param tc unused 2361 * @param tc unused
@@ -2354,7 +2363,20 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
2354static void 2363static void
2355dht_get_type_restart (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 2364dht_get_type_restart (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2356{ 2365{
2366 struct MeshTunnel *t = cls;
2367 GNUNET_HashCode hash;
2357 2368
2369 if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason)
2370 return;
2371 GNUNET_DHT_get_stop(t->dht_get_type);
2372 /* FIXME: calculate hash */
2373 t->dht_get_type = GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
2374 GNUNET_BLOCK_TYPE_TEST, &hash, 10U,
2375 GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0,
2376 &dht_get_type_handler, t);
2377 t->dht_get_type_task = GNUNET_SCHEDULER_add_delayed(GET_RESTART_TIME,
2378 &dht_get_type_restart,
2379 t);
2358} 2380}
2359 2381
2360/******************************************************************************/ 2382/******************************************************************************/
@@ -2410,11 +2432,6 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
2410 } 2432 }
2411 if (NULL != c->types) 2433 if (NULL != c->types)
2412 GNUNET_CONTAINER_multihashmap_destroy (c->types); 2434 GNUNET_CONTAINER_multihashmap_destroy (c->types);
2413 if (NULL != c->dht_get_type)
2414 {
2415 GNUNET_SCHEDULER_cancel (c->dht_get_type_task);
2416 GNUNET_DHT_get_stop (c->dht_get_type);
2417 }
2418 GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c); 2435 GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c);
2419 next = c->next; 2436 next = c->next;
2420 GNUNET_free (c); 2437 GNUNET_free (c);
@@ -2923,21 +2940,21 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2923 return; 2940 return;
2924 } 2941 }
2925 /* Ok, lets find a peer offering the service */ 2942 /* Ok, lets find a peer offering the service */
2926 if (c->dht_get_type) 2943 if (t->dht_get_type)
2927 { 2944 {
2928 GNUNET_SCHEDULER_cancel (c->dht_get_type_task); 2945 GNUNET_SCHEDULER_cancel (t->dht_get_type_task);
2929 GNUNET_DHT_get_stop (c->dht_get_type); 2946 GNUNET_DHT_get_stop (t->dht_get_type);
2930 } 2947 }
2931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n", 2948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n",
2932 GNUNET_h2s_full (&hash)); 2949 GNUNET_h2s_full (&hash));
2933 c->dht_get_type = 2950 t->dht_get_type =
2934 GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, 2951 GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
2935 GNUNET_BLOCK_TYPE_TEST, &hash, 10U, 2952 GNUNET_BLOCK_TYPE_TEST, &hash, 10U,
2936 GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, 2953 GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0,
2937 &dht_get_type_handler, t); 2954 &dht_get_type_handler, t);
2938 c->dht_get_type_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 2955 t->dht_get_type_task = GNUNET_SCHEDULER_add_delayed(GET_RESTART_TIME,
2939 &dht_get_type_restart, 2956 &dht_get_type_restart,
2940 NULL); 2957 t);
2941 2958
2942 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2959 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2943 return; 2960 return;
@@ -3253,9 +3270,8 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
3253static void 3270static void
3254shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 3271shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3255{ 3272{
3256 struct MeshClient *c;
3257
3258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shutting down\n"); 3273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shutting down\n");
3274 /* TODO: destroy tunnels? */
3259 if (core_handle != NULL) 3275 if (core_handle != NULL)
3260 { 3276 {
3261 GNUNET_CORE_disconnect (core_handle); 3277 GNUNET_CORE_disconnect (core_handle);
@@ -3263,12 +3279,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3263 } 3279 }
3264 if (dht_handle != NULL) 3280 if (dht_handle != NULL)
3265 { 3281 {
3266 for (c = clients; NULL != c; c = c->next)
3267 if (NULL != c->dht_get_type)
3268 {
3269 GNUNET_SCHEDULER_cancel(c->dht_get_type_task);
3270 GNUNET_DHT_get_stop (c->dht_get_type);
3271 }
3272 GNUNET_DHT_disconnect (dht_handle); 3282 GNUNET_DHT_disconnect (dht_handle);
3273 dht_handle = NULL; 3283 dht_handle = NULL;
3274 } 3284 }