aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-07-25 09:45:59 +0000
committerBart Polot <bart@net.in.tum.de>2012-07-25 09:45:59 +0000
commit90da8ec92541c5a645ada39ba524198f131ce6e5 (patch)
tree05487caacbb077dcb8a1ad57687e97ff756011fc
parent276328cd16b253961dc140eff2ed994d62d16661 (diff)
downloadgnunet-90da8ec92541c5a645ada39ba524198f131ce6e5.tar.gz
gnunet-90da8ec92541c5a645ada39ba524198f131ce6e5.zip
- add tunnel and queue accounting
-rw-r--r--src/mesh/gnunet-service-mesh.c54
-rw-r--r--src/mesh/mesh.conf.in2
2 files changed, 54 insertions, 2 deletions
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;
687static struct GNUNET_TIME_Relative connect_timeout; 687static struct GNUNET_TIME_Relative connect_timeout;
688static long long unsigned int default_ttl; 688static long long unsigned int default_ttl;
689static long long unsigned int dht_replication_level; 689static long long unsigned int dht_replication_level;
690 690static long long unsigned int max_tunnels;
691static long long unsigned int max_msgs_queue;
691 692
692/** 693/**
693 * DLL with all the clients, head. 694 * DLL with all the clients, head.
@@ -705,6 +706,11 @@ static struct MeshClient *clients_tail;
705static struct GNUNET_CONTAINER_MultiHashMap *tunnels; 706static struct GNUNET_CONTAINER_MultiHashMap *tunnels;
706 707
707/** 708/**
709 * Number of tunnels known.
710 */
711static unsigned long long n_tunnels;
712
713/**
708 * Tunnels incoming, indexed by MESH_TunnelNumber 714 * Tunnels incoming, indexed by MESH_TunnelNumber
709 * (which is greater than GNUNET_MESH_LOCAL_TUNNEL_ID_SERV). 715 * (which is greater than GNUNET_MESH_LOCAL_TUNNEL_ID_SERV).
710 */ 716 */
@@ -3329,6 +3335,9 @@ tunnel_destroy (struct MeshTunnel *t)
3329 if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task) 3335 if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task)
3330 GNUNET_SCHEDULER_cancel (t->path_refresh_task); 3336 GNUNET_SCHEDULER_cancel (t->path_refresh_task);
3331 3337
3338 n_tunnels--;
3339 GNUNET_STATISTICS_update (stats, "# tunnels", -1, GNUNET_NO);
3340 GNUNET_assert (0 <= n_tunnels);
3332 GNUNET_free (t); 3341 GNUNET_free (t);
3333 return r; 3342 return r;
3334} 3343}
@@ -3342,6 +3351,7 @@ tunnel_destroy (struct MeshTunnel *t)
3342 * @param client Clients that owns the tunnel, NULL for foreign tunnels. 3351 * @param client Clients that owns the tunnel, NULL for foreign tunnels.
3343 * @param local Tunnel Number for the tunnel, for the client point of view. 3352 * @param local Tunnel Number for the tunnel, for the client point of view.
3344 * 3353 *
3354 * @return A new initialized tunnel. NULL on error.
3345 */ 3355 */
3346static struct MeshTunnel * 3356static struct MeshTunnel *
3347tunnel_new (GNUNET_PEER_Id owner, 3357tunnel_new (GNUNET_PEER_Id owner,
@@ -3351,15 +3361,20 @@ tunnel_new (GNUNET_PEER_Id owner,
3351{ 3361{
3352 struct MeshTunnel *t; 3362 struct MeshTunnel *t;
3353 struct GNUNET_HashCode hash; 3363 struct GNUNET_HashCode hash;
3364
3365 if (n_tunnels >= max_tunnels && NULL == client)
3366 return NULL;
3354 3367
3355 t = GNUNET_malloc (sizeof (struct MeshTunnel)); 3368 t = GNUNET_malloc (sizeof (struct MeshTunnel));
3356 t->id.oid = owner; 3369 t->id.oid = owner;
3357 t->id.tid = tid; 3370 t->id.tid = tid;
3358 t->queue_max = 1000; // FIXME API parameter 3371 t->queue_max = (max_msgs_queue / max_tunnels) + 1;
3359 t->tree = tree_new (owner); 3372 t->tree = tree_new (owner);
3360 t->owner = client; 3373 t->owner = client;
3361 t->local_tid = local; 3374 t->local_tid = local;
3362 t->children_fc = GNUNET_CONTAINER_multihashmap_create (8); 3375 t->children_fc = GNUNET_CONTAINER_multihashmap_create (8);
3376 n_tunnels++;
3377 GNUNET_STATISTICS_update (stats, "# tunnels", 1, GNUNET_NO);
3363 3378
3364 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); 3379 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
3365 if (GNUNET_OK != 3380 if (GNUNET_OK !=
@@ -3901,6 +3916,11 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
3901 3916
3902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating tunnel\n"); 3917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating tunnel\n");
3903 t = tunnel_new (GNUNET_PEER_intern (pi), tid, NULL, 0); 3918 t = tunnel_new (GNUNET_PEER_intern (pi), tid, NULL, 0);
3919 if (NULL == t)
3920 {
3921 // FIXME notify failure
3922 return GNUNET_OK;
3923 }
3904 opt = ntohl (msg->opt); 3924 opt = ntohl (msg->opt);
3905 t->speed_min = (0 != (opt & MESH_TUNNEL_OPT_SPEED_MIN)) ? 3925 t->speed_min = (0 != (opt & MESH_TUNNEL_OPT_SPEED_MIN)) ?
3906 GNUNET_YES : GNUNET_NO; 3926 GNUNET_YES : GNUNET_NO;
@@ -5331,6 +5351,12 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
5331 while (NULL != tunnel_get_by_pi (myid, next_tid)) 5351 while (NULL != tunnel_get_by_pi (myid, next_tid))
5332 next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; 5352 next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
5333 t = tunnel_new (myid, next_tid++, c, ntohl (t_msg->tunnel_id)); 5353 t = tunnel_new (myid, next_tid++, c, ntohl (t_msg->tunnel_id));
5354 if (NULL == t)
5355 {
5356 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tunnel creation failed.\n");
5357 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
5358 return;
5359 }
5334 next_tid = next_tid & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; 5360 next_tid = next_tid & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
5335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n", 5361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n",
5336 GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid); 5362 GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid);
@@ -6623,6 +6649,30 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
6623 } 6649 }
6624 6650
6625 if (GNUNET_OK != 6651 if (GNUNET_OK !=
6652 GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_MSGS_QUEUE",
6653 &max_msgs_queue))
6654 {
6655 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6656 _
6657 ("Mesh service is lacking key configuration settings (%s). Exiting.\n"),
6658 "max msgs queue");
6659 GNUNET_SCHEDULER_shutdown ();
6660 return;
6661 }
6662
6663 if (GNUNET_OK !=
6664 GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_TUNNELS",
6665 &max_tunnels))
6666 {
6667 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6668 _
6669 ("Mesh service is lacking key configuration settings (%s). Exiting.\n"),
6670 "max tunnels");
6671 GNUNET_SCHEDULER_shutdown ();
6672 return;
6673 }
6674
6675 if (GNUNET_OK !=
6626 GNUNET_CONFIGURATION_get_value_number (c, "MESH", "DEFAULT_TTL", 6676 GNUNET_CONFIGURATION_get_value_number (c, "MESH", "DEFAULT_TTL",
6627 &default_ttl)) 6677 &default_ttl))
6628 { 6678 {
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
17CONNECT_TIMEOUT = 30 s 17CONNECT_TIMEOUT = 30 s
18DEFAULT_TTL = 64 18DEFAULT_TTL = 64
19DHT_REPLICATION_LEVEL = 10 19DHT_REPLICATION_LEVEL = 10
20MAX_TUNNELS = 1000
21MAX_MSGS_QUEUE = 10000