aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-07-13 01:20:42 +0000
committerBart Polot <bart@net.in.tum.de>2013-07-13 01:20:42 +0000
commit9babf324cd30822e8099dece229503ebc466e11b (patch)
tree08b7351bb25f01fe3116b5b43db08a0f255e30e9
parent1d53ec8da14a39e436cbddebba9cd92537870b6a (diff)
downloadgnunet-9babf324cd30822e8099dece229503ebc466e11b.tar.gz
gnunet-9babf324cd30822e8099dece229503ebc466e11b.zip
Add context to a client immediately after connection. Otherwise calling SERVER_get_client_context on a client that never sent an initial message (and didn't have a chance to receive something via SERVER_set_client_context) causes an assertion failure in server.c:355. This happens when the client can connect to the service on multiple protocols, one of the connections will be immediately closed (see bug for ghost client disconnects)
-rw-r--r--src/mesh/gnunet-service-mesh.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 7504fa223..169d3ce63 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -4395,6 +4395,24 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
4395 4395
4396 4396
4397/** 4397/**
4398 * Handler for client connection.
4399 *
4400 * @param cls Closure (unused).
4401 * @param client Client handler.
4402 */
4403static void
4404handle_local_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
4405{
4406 struct MeshClient *c;
4407
4408 c = GNUNET_malloc (sizeof (struct MeshClient));
4409 c->handle = client;
4410 GNUNET_SERVER_client_keep (client);
4411 GNUNET_SERVER_client_set_user_context (client, c);
4412}
4413
4414
4415/**
4398 * Handler for client disconnection 4416 * Handler for client disconnection
4399 * 4417 *
4400 * @param cls closure 4418 * @param cls closure
@@ -4476,14 +4494,11 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
4476 } 4494 }
4477 size /= sizeof (uint32_t); 4495 size /= sizeof (uint32_t);
4478 4496
4479 /* Create new client structure */ 4497 /* Initialize new client structure */
4480 c = GNUNET_malloc (sizeof (struct MeshClient)); 4498 c = GNUNET_SERVER_client_get_user_context (client, struct MeshClient);
4481 c->id = next_client_id++; /* overflow not important: just for debug */ 4499 c->id = next_client_id++; /* overflow not important: just for debug */
4482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client id %u\n", c->id); 4500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client id %u\n", c->id);
4483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u ports\n", size); 4501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u ports\n", size);
4484 c->handle = client;
4485 GNUNET_SERVER_client_keep (client);
4486 GNUNET_SERVER_client_set_user_context (client, c);
4487 if (size > 0) 4502 if (size > 0)
4488 { 4503 {
4489 uint32_t u32; 4504 uint32_t u32;
@@ -5113,6 +5128,8 @@ static void
5113server_init (void) 5128server_init (void)
5114{ 5129{
5115 GNUNET_SERVER_add_handlers (server_handle, client_handlers); 5130 GNUNET_SERVER_add_handlers (server_handle, client_handlers);
5131 GNUNET_SERVER_connect_notify (server_handle,
5132 &handle_local_client_connect, NULL);
5116 GNUNET_SERVER_disconnect_notify (server_handle, 5133 GNUNET_SERVER_disconnect_notify (server_handle,
5117 &handle_local_client_disconnect, NULL); 5134 &handle_local_client_disconnect, NULL);
5118 nc = GNUNET_SERVER_notification_context_create (server_handle, 1); 5135 nc = GNUNET_SERVER_notification_context_create (server_handle, 1);