aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-10-05 12:38:43 +0000
committerBart Polot <bart@net.in.tum.de>2011-10-05 12:38:43 +0000
commit71806bdede28c426d2c0723facc1c66d222d5bc7 (patch)
tree12012eb36330f2e9d6795b296117c8fefdcbcff0 /src/mesh/gnunet-service-mesh.c
parenteb5fcd956d0c4513d736e8f029f42aa3850768af (diff)
downloadgnunet-71806bdede28c426d2c0723facc1c66d222d5bc7.tar.gz
gnunet-71806bdede28c426d2c0723facc1c66d222d5bc7.zip
Added periodic restart to all DHT get queries
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r--src/mesh/gnunet-service-mesh.c94
1 files changed, 76 insertions, 18 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 3de96341e..323be7dd3 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -289,6 +289,11 @@ struct MeshTunnel
289 */ 289 */
290 struct MeshTunnelTree *tree; 290 struct MeshTunnelTree *tree;
291 291
292 /**
293 * Application type we are looking for in this tunnel
294 */
295 GNUNET_MESH_ApplicationType type;
296
292 /** 297 /**
293 * Used to search peers offering a service 298 * Used to search peers offering a service
294 */ 299 */
@@ -610,11 +615,21 @@ static void
610dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, 615dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
611 const GNUNET_HashCode * key, 616 const GNUNET_HashCode * key,
612 const struct GNUNET_PeerIdentity *get_path, 617 const struct GNUNET_PeerIdentity *get_path,
613 unsigned int get_path_length, 618 unsigned int get_path_length,
614 const struct GNUNET_PeerIdentity *put_path, 619 const struct GNUNET_PeerIdentity *put_path,
615 unsigned int put_path_length, 620 unsigned int put_path_length,
616 enum GNUNET_BLOCK_Type type, size_t size, const void *data); 621 enum GNUNET_BLOCK_Type type, size_t size, const void *data);
617 622
623/**
624 * Task to restart the DHT get search for a peer.
625 *
626 * @param cls unused
627 * @param tc unused
628 */
629static void
630dht_get_restart (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
631
632
618 633
619/******************************************************************************/ 634/******************************************************************************/
620/****************** GENERAL HELPER FUNCTIONS ************************/ 635/****************** GENERAL HELPER FUNCTIONS ************************/
@@ -786,6 +801,9 @@ path_remove_from_peer (struct MeshPeerInfo *peer,
786 0, /* xquery bits */ 801 0, /* xquery bits */
787 &dht_get_id_handler, 802 &dht_get_id_handler,
788 (void *) path_info); 803 (void *) path_info);
804 peer_d->dhtget_task = GNUNET_SCHEDULER_add_delayed(GET_RESTART_TIME,
805 &dht_get_restart,
806 path_info);
789 } 807 }
790 } 808 }
791} 809}
@@ -2175,22 +2193,16 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
2175 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2193 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2176 "MESH: Got results from DHT for %s\n", 2194 "MESH: Got results from DHT for %s\n",
2177 GNUNET_h2s_full(&pi.hashPubKey)); 2195 GNUNET_h2s_full(&pi.hashPubKey));
2196 GNUNET_SCHEDULER_cancel(path_info->peer->dhtget_task);
2197 GNUNET_DHT_get_stop(path_info->peer->dhtget);
2198 path_info->peer->dhtget = NULL;
2178 if (NULL == get_path || NULL == put_path) 2199 if (NULL == get_path || NULL == put_path)
2179 { 2200 {
2180 if (NULL == path_info->peer->path_head) 2201 if (NULL == path_info->peer->path_head)
2181 { 2202 {
2182 // Find ourselves some alternate initial path to the destination: retry 2203 // Find ourselves some alternate initial path to the destination: retry
2183 GNUNET_DHT_get_stop (path_info->peer->dhtget); 2204 path_info->peer->dhtget_task = GNUNET_SCHEDULER_add_now (&dht_get_restart,
2184 path_info->peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ 2205 path_info);
2185 GNUNET_TIME_UNIT_SECONDS, /* timeout */
2186 GNUNET_BLOCK_TYPE_TEST, /* type */
2187 &pi.hashPubKey, /*key to search */
2188 4, /* replication level */
2189 GNUNET_DHT_RO_RECORD_ROUTE,
2190 NULL, /* xquery */
2191 0, /* xquery bits */
2192 &dht_get_id_handler,
2193 (void *) path_info);
2194 return; 2206 return;
2195 } 2207 }
2196 } 2208 }
@@ -2238,6 +2250,44 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
2238 2250
2239 2251
2240/** 2252/**
2253 * Task to restart the DHT get search for a peer.
2254 *
2255 * @param cls unused
2256 * @param tc unused
2257 */
2258static void
2259dht_get_restart (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2260{
2261 struct MeshPathInfo *path = cls;
2262 struct MeshPeerInfo *peer = path->peer;
2263 struct GNUNET_PeerIdentity id;
2264
2265 if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason)
2266 return;
2267 GNUNET_PEER_resolve(peer->id, &id);
2268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2269 "MESH: restarting DHT get for id %s [%u]\n",
2270 GNUNET_i2s (&id),
2271 peer->id);
2272 if (NULL != peer->dhtget)
2273 GNUNET_DHT_get_stop(peer->dhtget);
2274 peer->dhtget = GNUNET_DHT_get_start (dht_handle,
2275 GNUNET_TIME_UNIT_FOREVER_REL,
2276 GNUNET_BLOCK_TYPE_TEST,
2277 &id.hashPubKey,
2278 10U,
2279 GNUNET_DHT_RO_RECORD_ROUTE,
2280 NULL,
2281 0,
2282 &dht_get_id_handler,
2283 path);
2284 peer->dhtget_task = GNUNET_SCHEDULER_add_delayed (GET_RESTART_TIME,
2285 &dht_get_restart,
2286 path);
2287}
2288
2289
2290/**
2241 * Function to process paths received for a new peer addition. The recorded 2291 * Function to process paths received for a new peer addition. The recorded
2242 * paths form the initial tunnel, which can be optimized later. 2292 * paths form the initial tunnel, which can be optimized later.
2243 * Called on each result obtained for the DHT search. 2293 * Called on each result obtained for the DHT search.
@@ -2303,6 +2353,9 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
2303 dht_get_id_handler, 2353 dht_get_id_handler,
2304 /* callback */ 2354 /* callback */
2305 path_info); /* closure */ 2355 path_info); /* closure */
2356 peer_info->dhtget_task = GNUNET_SCHEDULER_add_delayed (GET_RESTART_TIME,
2357 &dht_get_restart,
2358 path_info);
2306 return; 2359 return;
2307 } 2360 }
2308 2361
@@ -2368,8 +2421,11 @@ dht_get_type_restart (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2368 2421
2369 if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason) 2422 if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason)
2370 return; 2423 return;
2424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2425 "MESH: restarting DHT get for type %u\n",
2426 t->type);
2371 GNUNET_DHT_get_stop(t->dht_get_type); 2427 GNUNET_DHT_get_stop(t->dht_get_type);
2372 /* FIXME: calculate hash */ 2428 GNUNET_CRYPTO_hash (&t->type, sizeof (GNUNET_MESH_ApplicationType), &hash);
2373 t->dht_get_type = GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, 2429 t->dht_get_type = GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
2374 GNUNET_BLOCK_TYPE_TEST, &hash, 10U, 2430 GNUNET_BLOCK_TYPE_TEST, &hash, 10U,
2375 GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, 2431 GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0,
@@ -2763,6 +2819,9 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
2763 0, /* xquery bits */ 2819 0, /* xquery bits */
2764 &dht_get_id_handler, 2820 &dht_get_id_handler,
2765 (void *) path_info); 2821 (void *) path_info);
2822 peer_info->dhtget_task = GNUNET_SCHEDULER_add_delayed (GET_RESTART_TIME,
2823 &dht_get_restart,
2824 path_info);
2766 } 2825 }
2767 else if (NULL != peer_info->path_head) 2826 else if (NULL != peer_info->path_head)
2768 { 2827 {
@@ -2878,7 +2937,6 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2878 struct MeshClient *c; 2937 struct MeshClient *c;
2879 struct MeshTunnel *t; 2938 struct MeshTunnel *t;
2880 GNUNET_HashCode hash; 2939 GNUNET_HashCode hash;
2881 GNUNET_MESH_ApplicationType type;
2882 MESH_TunnelNumber tid; 2940 MESH_TunnelNumber tid;
2883 2941
2884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got connect by type request\n"); 2942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got connect by type request\n");
@@ -2919,9 +2977,9 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2919 } 2977 }
2920 2978
2921 /* Do WE have the service? */ 2979 /* Do WE have the service? */
2922 type = ntohl (connect_msg->type); 2980 t->type = ntohl (connect_msg->type);
2923 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type requested: %u\n", type); 2981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type requested: %u\n", t->type);
2924 GNUNET_CRYPTO_hash (&type, sizeof (GNUNET_MESH_ApplicationType), &hash); 2982 GNUNET_CRYPTO_hash (&t->type, sizeof (GNUNET_MESH_ApplicationType), &hash);
2925 if (GNUNET_CONTAINER_multihashmap_contains (applications, &hash) == 2983 if (GNUNET_CONTAINER_multihashmap_contains (applications, &hash) ==
2926 GNUNET_YES) 2984 GNUNET_YES)
2927 { 2985 {