From: Bart Polot Date: Wed, 25 Jul 2012 09:45:59 +0000 (+0000) Subject: - add tunnel and queue accounting X-Git-Tag: initial-import-from-subversion-38251~12341 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=90da8ec92541c5a645ada39ba524198f131ce6e5;p=oweals%2Fgnunet.git - add tunnel and queue accounting --- diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 1f9a7736b..ffdbb0f86 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -687,7 +687,8 @@ static struct GNUNET_TIME_Relative unacknowledged_wait_time; static struct GNUNET_TIME_Relative connect_timeout; static long long unsigned int default_ttl; static long long unsigned int dht_replication_level; - +static long long unsigned int max_tunnels; +static long long unsigned int max_msgs_queue; /** * DLL with all the clients, head. @@ -704,6 +705,11 @@ static struct MeshClient *clients_tail; */ static struct GNUNET_CONTAINER_MultiHashMap *tunnels; +/** + * Number of tunnels known. + */ +static unsigned long long n_tunnels; + /** * Tunnels incoming, indexed by MESH_TunnelNumber * (which is greater than GNUNET_MESH_LOCAL_TUNNEL_ID_SERV). @@ -3329,6 +3335,9 @@ tunnel_destroy (struct MeshTunnel *t) if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task) GNUNET_SCHEDULER_cancel (t->path_refresh_task); + n_tunnels--; + GNUNET_STATISTICS_update (stats, "# tunnels", -1, GNUNET_NO); + GNUNET_assert (0 <= n_tunnels); GNUNET_free (t); return r; } @@ -3342,6 +3351,7 @@ tunnel_destroy (struct MeshTunnel *t) * @param client Clients that owns the tunnel, NULL for foreign tunnels. * @param local Tunnel Number for the tunnel, for the client point of view. * + * @return A new initialized tunnel. NULL on error. */ static struct MeshTunnel * tunnel_new (GNUNET_PEER_Id owner, @@ -3351,15 +3361,20 @@ tunnel_new (GNUNET_PEER_Id owner, { struct MeshTunnel *t; struct GNUNET_HashCode hash; + + if (n_tunnels >= max_tunnels && NULL == client) + return NULL; t = GNUNET_malloc (sizeof (struct MeshTunnel)); t->id.oid = owner; t->id.tid = tid; - t->queue_max = 1000; // FIXME API parameter + t->queue_max = (max_msgs_queue / max_tunnels) + 1; t->tree = tree_new (owner); t->owner = client; t->local_tid = local; t->children_fc = GNUNET_CONTAINER_multihashmap_create (8); + n_tunnels++; + GNUNET_STATISTICS_update (stats, "# tunnels", 1, GNUNET_NO); GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); if (GNUNET_OK != @@ -3901,6 +3916,11 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating tunnel\n"); t = tunnel_new (GNUNET_PEER_intern (pi), tid, NULL, 0); + if (NULL == t) + { + // FIXME notify failure + return GNUNET_OK; + } opt = ntohl (msg->opt); t->speed_min = (0 != (opt & MESH_TUNNEL_OPT_SPEED_MIN)) ? GNUNET_YES : GNUNET_NO; @@ -5331,6 +5351,12 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, while (NULL != tunnel_get_by_pi (myid, next_tid)) next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; t = tunnel_new (myid, next_tid++, c, ntohl (t_msg->tunnel_id)); + if (NULL == t) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tunnel creation failed.\n"); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } next_tid = next_tid & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n", GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid); @@ -6622,6 +6648,30 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, return; } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_MSGS_QUEUE", + &max_msgs_queue)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ + ("Mesh service is lacking key configuration settings (%s). Exiting.\n"), + "max msgs queue"); + GNUNET_SCHEDULER_shutdown (); + return; + } + + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_TUNNELS", + &max_tunnels)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ + ("Mesh service is lacking key configuration settings (%s). Exiting.\n"), + "max tunnels"); + GNUNET_SCHEDULER_shutdown (); + return; + } + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, "MESH", "DEFAULT_TTL", &default_ttl)) diff --git a/src/mesh/mesh.conf.in b/src/mesh/mesh.conf.in index 6aa8b4fac..83b45c786 100644 --- a/src/mesh/mesh.conf.in +++ b/src/mesh/mesh.conf.in @@ -17,3 +17,5 @@ UNACKNOWLEDGED_WAIT = 2 s CONNECT_TIMEOUT = 30 s DEFAULT_TTL = 64 DHT_REPLICATION_LEVEL = 10 +MAX_TUNNELS = 1000 +MAX_MSGS_QUEUE = 10000