aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-10-06 17:38:50 +0000
committerBart Polot <bart@net.in.tum.de>2011-10-06 17:38:50 +0000
commit7639188c0a248382968c1f1015687eb7b37b59b8 (patch)
tree483f3cafcb9e33866e1201b10b4eca38b56d84f9 /src/mesh
parent3647df0bbd6bd27866ee63e5b9020776e9a7ce01 (diff)
downloadgnunet-7639188c0a248382968c1f1015687eb7b37b59b8.tar.gz
gnunet-7639188c0a248382968c1f1015687eb7b37b59b8.zip
Stop all DHT get requests before disconnecting
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c22
-rw-r--r--src/mesh/test_mesh_small.conf4
-rw-r--r--src/mesh/test_mesh_small_unicast.c90
3 files changed, 104 insertions, 12 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index f30661abe..ba0244881 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -1187,6 +1187,9 @@ tunnel_destroy (struct MeshTunnel *t)
1187 /* TODO cancel core transmit ready in case it was active */ 1187 /* TODO cancel core transmit ready in case it was active */
1188 } 1188 }
1189 tree_destroy(t->tree); 1189 tree_destroy(t->tree);
1190 if (NULL != t->dht_get_type)
1191 GNUNET_DHT_get_stop(t->dht_get_type);
1192 t->dht_get_type = NULL;
1190 GNUNET_free (t); 1193 GNUNET_free (t);
1191 return r; 1194 return r;
1192} 1195}
@@ -3240,6 +3243,24 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
3240/******************************************************************************/ 3243/******************************************************************************/
3241 3244
3242/** 3245/**
3246 * Iterator over hash map entries.
3247 *
3248 * @param cls closure
3249 * @param key current key code
3250 * @param value value in the hash map
3251 * @return GNUNET_YES if we should continue to
3252 * iterate,
3253 * GNUNET_NO if not.
3254 */
3255int
3256shutdown_tunnel (void *cls, const GNUNET_HashCode * key, void *value)
3257{
3258 struct MeshTunnel *t = value;
3259 tunnel_destroy(t);
3260 return GNUNET_YES;
3261}
3262
3263/**
3243 * Task run during shutdown. 3264 * Task run during shutdown.
3244 * 3265 *
3245 * @param cls unused 3266 * @param cls unused
@@ -3255,6 +3276,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3255 GNUNET_CORE_disconnect (core_handle); 3276 GNUNET_CORE_disconnect (core_handle);
3256 core_handle = NULL; 3277 core_handle = NULL;
3257 } 3278 }
3279 GNUNET_CONTAINER_multihashmap_iterate(tunnels, &shutdown_tunnel, NULL);
3258 if (dht_handle != NULL) 3280 if (dht_handle != NULL)
3259 { 3281 {
3260 GNUNET_DHT_disconnect (dht_handle); 3282 GNUNET_DHT_disconnect (dht_handle);
diff --git a/src/mesh/test_mesh_small.conf b/src/mesh/test_mesh_small.conf
index 98def94c0..580a36f88 100644
--- a/src/mesh/test_mesh_small.conf
+++ b/src/mesh/test_mesh_small.conf
@@ -49,6 +49,10 @@ PORT = 10004
49[mesh] 49[mesh]
50PORT = 10005 50PORT = 10005
51DEBUG=YES 51DEBUG=YES
52ACCEPT_FROM = 127.0.0.1;
53HOSTNAME = localhost
54# PREFIX = valgrind --leak-check=full
55# PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args
52 56
53[testing] 57[testing]
54NUM_PEERS = 16 58NUM_PEERS = 16
diff --git a/src/mesh/test_mesh_small_unicast.c b/src/mesh/test_mesh_small_unicast.c
index 92e5d078b..f53b837de 100644
--- a/src/mesh/test_mesh_small_unicast.c
+++ b/src/mesh/test_mesh_small_unicast.c
@@ -122,15 +122,17 @@ static char *topology_file;
122 122
123static char *data_filename; 123static char *data_filename;
124 124
125struct GNUNET_TESTING_Daemon *d1; 125static struct GNUNET_TESTING_Daemon *d1;
126 126
127struct GNUNET_TESTING_Daemon *d2; 127static struct GNUNET_TESTING_Daemon *d2;
128 128
129struct GNUNET_MESH_Handle *h1; 129static struct GNUNET_MESH_Handle *h1;
130 130
131struct GNUNET_MESH_Handle *h2; 131static struct GNUNET_MESH_Handle *h2;
132 132
133struct GNUNET_MESH_Tunnel *t; 133static struct GNUNET_MESH_Tunnel *t;
134
135static uint16_t mesh_peers[16];
134 136
135/** 137/**
136 * Check whether peers successfully shut down. 138 * Check whether peers successfully shut down.
@@ -289,6 +291,53 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
289 291
290 292
291/** 293/**
294 * Prototype of a callback function indicating that two peers
295 * are currently connected.
296 *
297 * @param cls closure
298 * @param first peer id for first daemon
299 * @param second peer id for the second daemon
300 * @param distance distance between the connected peers
301 * @param emsg error message (NULL on success)
302 */
303void
304topo_cb (void *cls,
305 const struct GNUNET_PeerIdentity* first,
306 const struct GNUNET_PeerIdentity* second,
307 const char *emsg)
308{
309 GNUNET_PEER_Id p1;
310 GNUNET_PEER_Id p2;
311 struct GNUNET_PeerIdentity id;
312
313 GNUNET_PEER_resolve(1, &id);
314 p1 = GNUNET_PEER_search(first);
315 if (p1 == 1)
316 {
317 p2 = GNUNET_PEER_search(second);
318 GNUNET_assert(p2 < num_peers);
319 if (0 == p2) return;
320 mesh_peers[p2]++;
321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
322 "test: %s IS a neighbor\n",
323 GNUNET_i2s(second));
324 return;
325 }
326 p1 = GNUNET_PEER_search(second);
327 if (p1 == 1)
328 {
329 p2 = GNUNET_PEER_search(first);
330 GNUNET_assert(p2 < num_peers);
331 if (0 == p2) return;
332 mesh_peers[p2]++;
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "test: %s IS a neighbor\n",
335 GNUNET_i2s(first));
336 return;
337 }
338}
339
340/**
292 * connect_mesh_service: connect to the mesh service of one of the peers 341 * connect_mesh_service: connect to the mesh service of one of the peers
293 * 342 *
294 */ 343 */
@@ -296,20 +345,26 @@ static void
296connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 345connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
297{ 346{
298 GNUNET_MESH_ApplicationType app; 347 GNUNET_MESH_ApplicationType app;
348 unsigned int i;
299 349
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n"); 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n");
301 351
302 d1 = GNUNET_TESTING_daemon_get (pg, 1); 352 for (i = 1; i < num_peers; i++)
303 d2 = GNUNET_TESTING_daemon_get (pg, 3); 353 if (mesh_peers[i] == 0)
354 break;
355 GNUNET_assert (i < num_peers);
356 d2 = GNUNET_TESTING_daemon_get (pg, i);
304 app = (GNUNET_MESH_ApplicationType) 0; 357 app = (GNUNET_MESH_ApplicationType) 0;
305 358
306#if VERBOSE 359#if VERBOSE
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
308 "test: connecting to mesh service of peer %s\n", 361 "test: connecting to mesh service of peer %s (%u)\n",
309 GNUNET_i2s (&d1->id)); 362 GNUNET_i2s (&d1->id),
363 mesh_peers[0]);
310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
311 "test: connecting to mesh service of peer %s\n", 365 "test: connecting to mesh service of peer %s (%u)\n",
312 GNUNET_i2s (&d2->id)); 366 GNUNET_i2s (&d2->id),
367 i);
313#endif 368#endif
314 h1 = GNUNET_MESH_connect (d1->cfg, 369 h1 = GNUNET_MESH_connect (d1->cfg,
315 10, 370 10,
@@ -352,6 +407,7 @@ peergroup_ready (void *cls, const char *emsg)
352{ 407{
353 char *buf; 408 char *buf;
354 int buf_len; 409 int buf_len;
410 unsigned int i;
355 411
356 if (emsg != NULL) 412 if (emsg != NULL)
357 { 413 {
@@ -382,10 +438,20 @@ peergroup_ready (void *cls, const char *emsg)
382 GNUNET_free (buf); 438 GNUNET_free (buf);
383 } 439 }
384 peers_running = GNUNET_TESTING_daemons_running (pg); 440 peers_running = GNUNET_TESTING_daemons_running (pg);
441 for (i = 0; i < num_peers; i++)
442 {
443 d1 = GNUNET_TESTING_daemon_get (pg, i);
444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
445 "test: %u: %s\n",
446 GNUNET_PEER_intern(&d1->id),
447 GNUNET_i2s (&d1->id));
448 mesh_peers[i] = 0;
449 }
450 GNUNET_TESTING_get_topology(pg, &topo_cb, NULL);
385 451
386 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( 452 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
387 GNUNET_TIME_UNIT_SECONDS, 453 GNUNET_TIME_UNIT_SECONDS,
388 2), 454 4),
389 &connect_mesh_service, 455 &connect_mesh_service,
390 NULL); 456 NULL);
391 disconnect_task = 457 disconnect_task =