Added statistics support
authorPekka Riikonen <priikone@silcnet.org>
Fri, 2 Feb 2001 21:04:25 +0000 (21:04 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 2 Feb 2001 21:04:25 +0000 (21:04 +0000)
CHANGES
apps/silcd/packet_receive.c
apps/silcd/server.c
apps/silcd/server_internal.h

diff --git a/CHANGES b/CHANGES
index a843a2a056d3a389ddec6bb0da3ea65337c1883c..f7d07e0d4eb4cc72dadf0349313db9738d8b07af 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -16,6 +16,11 @@ Fri Feb  2 11:42:56 EET 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
          that we are now re-sending.  Ignored if NULL.  Affected file
          silcd/packet_send.[ch].
 
+       * Added some server statistics support in sil/server_internal.h
+         SilcServerStatistics structure and around the server code.  Also
+         send some nice statistics information when client is connecting
+         to the client.
+
 Thu Feb  1 23:31:21 EET 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Fixed channel ID decoding in server's JOIN command reply in
index 3056be6d58500907bf128b8c4b7cb9d410cbcc50..343c9bd7ed0b0c1a454219eb308037c389208abd 100644 (file)
@@ -70,7 +70,6 @@ void silc_server_private_message(SilcServer server,
         we will send the packet to that server. */
       router = (SilcServerEntry)dst_sock->user_data;
       idata = (SilcIDListData)router;
-      //assert(client->router == server->id_entry);
 
       silc_server_send_private_message(server, dst_sock,
                                       idata->send_key,
@@ -456,6 +455,36 @@ SilcClientEntry silc_server_new_client(SilcServer server,
   SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
                          ("Welcome to the SILC Network %s@%s",
                           username, sock->hostname));
+  if (server->server_type == SILC_ROUTER) {
+    SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
+                           ("There are %d clients on %d servers in SILC "
+                            "Network", server->stat.clients,
+                            server->stat.servers));
+    SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
+                           ("There are %d clients on %d server in our cell",
+                            server->stat.cell_clients,
+                            server->stat.cell_servers));
+    SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
+                           ("I have %d clients, %d channels, %d servers and "
+                            "%d routers",
+                            server->stat.my_clients, 
+                            server->stat.my_channels,
+                            server->stat.my_servers,
+                            server->stat.my_routers));
+    SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
+                           ("%d server operators and %d router operators "
+                            "online",
+                            server->stat.my_server_ops,
+                            server->stat.my_router_ops));
+  } else {
+    SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
+                           ("I have %d clients and %d channels formed",
+                            server->stat.my_clients,
+                            server->stat.my_channels));
+    SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
+                           ("%d operators online",
+                            server->stat.my_server_ops));
+  }
   SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
                          ("Your host is %s, running version %s",
                           server->config->server_info->server_name,
@@ -599,27 +628,6 @@ void silc_server_new_id(SilcServer server, SilcSocketConnection sock,
                            buffer->data, buffer->len, FALSE);
   }
 
-#if 0
-  /* If the packet is originated from the one who sent it to us we know
-     that the ID belongs to our cell, unless the sender was router. */
-  tmpid = silc_id_str2id(packet->src_id, SILC_ID_SERVER);
-  tmpserver = (SilcServerEntry)sock->user_data;
-
-  if (!SILC_ID_SERVER_COMPARE(tmpid, tmpserver->id) &&
-      sock->type == SILC_SOCKET_TYPE_SERVER) {
-    id_list = server->local_list;
-    router_sock = sock;
-    router = sock->user_data;
-    /*    router = server->id_entry; */
-  } else {
-    id_list = server->global_list;
-    router_sock = (SilcSocketConnection)server->router->connection;
-    router = server->router;
-  }
-
-  silc_free(tmpid);
-#endif
-
   if (sock->type == SILC_SOCKET_TYPE_SERVER)
     id_list = server->local_list;
   else
@@ -651,6 +659,10 @@ void silc_server_new_id(SilcServer server, SilcSocketConnection sock,
                                     router, router_sock);
       entry->nickname = NULL;
 
+      if (sock->type == SILC_SOCKET_TYPE_SERVER)
+       server->stat.cell_clients++;
+      server->stat.clients++;
+
 #if 0
       /* XXX Adding two ID's with same IP number replaces the old entry thus
         gives wrong route. Thus, now disabled until figured out a better way
@@ -677,6 +689,10 @@ void silc_server_new_id(SilcServer server, SilcSocketConnection sock,
        list. Cell wide information however is kept in the local list. */
     silc_idlist_add_server(id_list, NULL, 0, id, router, router_sock);
 
+    if (sock->type == SILC_SOCKET_TYPE_SERVER)
+      server->stat.cell_servers++;
+    server->stat.servers++;
+
 #if 0
     /* Add route cache for this ID */
     silc_server_route_add(silc_server_route_hash(
@@ -825,6 +841,8 @@ void silc_server_new_channel(SilcServer server,
      router hence global channel. */
   silc_idlist_add_channel(server->global_list, channel_name, 0, channel_id, 
                          server->router->connection, NULL);
+
+  server->stat.channels++;
 }
 
 /* Received notify packet. Server can receive notify packets from router. 
@@ -1106,6 +1124,8 @@ void silc_server_new_channel_user(SilcServer server,
   silc_list_add(channel->user_list, chl);
   silc_list_add(client->channels, chl);
 
+  server->stat.chanclients++;
+
   /* Send JOIN notify to local clients on the channel. As we are router
      it is assured that this is sent only to our local clients and locally
      connected servers if needed. */
@@ -1183,6 +1203,7 @@ void silc_server_remove_id(SilcServer server,
 
       /* Remove the client entry */
       silc_idlist_del_client(id_list, (SilcClientEntry)id_entry);
+      server->stat.clients--;
 
       SILC_LOG_DEBUG(("Removed client id(%s) from [%s] %s",
                      silc_id_render(id, SILC_ID_CLIENT),
@@ -1196,6 +1217,7 @@ void silc_server_remove_id(SilcServer server,
                                             NULL);
     if (id_entry) {
       silc_idlist_del_server(id_list, (SilcServerEntry)id_entry);
+      server->stat.servers--;
 
       SILC_LOG_DEBUG(("Removed server id(%s) from [%s] %s",
                      silc_id_render(id, SILC_ID_SERVER),
@@ -1209,6 +1231,7 @@ void silc_server_remove_id(SilcServer server,
                                              NULL);
     if (id_entry) {
       silc_idlist_del_channel(id_list, (SilcChannelEntry)id_entry);
+      server->stat.channels--;
 
       SILC_LOG_DEBUG(("Removed channel id(%s) from [%s] %s",
                      silc_id_render(id, SILC_ID_CHANNEL),
index bbca2e02f9989e4a9fb79f42e8e9deed2a0b5259..4508c70f94d1b796c7619541ffca86cd214efe27 100644 (file)
@@ -772,9 +772,12 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection)
 
   SILC_LOG_DEBUG(("Accepting new connection"));
 
+  server->stat.conn_attempts++;
+
   sock = silc_net_accept_connection(server->sock);
   if (sock < 0) {
     SILC_LOG_ERROR(("Could not accept new connection: %s", strerror(errno)));
+    server->stat.conn_failures++;
     return;
   }
 
@@ -785,6 +788,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection)
       /*silc_server_send_notify("Server is full, trying to redirect..."); */
     } else {
       SILC_LOG_ERROR(("Refusing connection, server is full"));
+      server->stat.conn_failures++;
     }
     return;
   }
@@ -806,6 +810,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection)
   if ((server->params->require_reverse_mapping && !newsocket->hostname) ||
       !newsocket->ip) {
     SILC_LOG_ERROR(("IP/DNS lookup failed"));
+    server->stat.conn_failures++;
     return;
   }
   if (!newsocket->hostname)
@@ -826,6 +831,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection)
      protocol but will not start it yet. The connector will be the
      initiator of the protocol thus we will wait for initiation from 
      there before we start the protocol. */
+  server->stat.auth_attempts++;
   silc_protocol_alloc(SILC_PROTOCOL_SERVER_KEY_EXCHANGE, 
                      &newsocket->protocol, proto_ctx, 
                      silc_server_accept_new_connection_second);
@@ -881,6 +887,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_second)
       sock->protocol = NULL;
     silc_server_disconnect_remote(server, sock, "Server closed connection: "
                                  "Key exchange failed");
+    server->stat.auth_failures++;
     return;
   }
 
@@ -949,6 +956,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
       sock->protocol = NULL;
     silc_server_disconnect_remote(server, sock, "Server closed connection: "
                                  "Authentication failed");
+    server->stat.auth_failures++;
     return;
   }
 
@@ -973,6 +981,8 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
        break;
       }
 
+      server->stat.my_clients++;
+
       id_entry = (void *)client;
       break;
     }
@@ -1004,6 +1014,11 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
        break;
       }
 
+      if (sock->type == SILC_SOCKET_TYPE_SERVER)
+       server->stat.my_servers++;
+      else
+       server->stat.my_routers++;
+
       id_entry = (void *)new_server;
       
       /* There is connection to other server now, if it is router then
@@ -1066,6 +1081,8 @@ SILC_TASK_CALLBACK(silc_server_packet_process)
   /* Packet sending */
 
   if (type == SILC_TASK_WRITE) {
+    server->stat.packets_sent++;
+
     if (sock->outbuf->data - sock->outbuf->head)
       silc_buffer_push(sock->outbuf, sock->outbuf->data - sock->outbuf->head);
 
@@ -1122,6 +1139,8 @@ SILC_TASK_CALLBACK(silc_server_packet_process)
     return;
   }
 
+  server->stat.packets_received++;
+
   /* Get keys and stuff from ID entry */
   idata = (SilcIDListData)sock->user_data;
   if (idata) {
@@ -1570,7 +1589,6 @@ void silc_server_packet_parse_type(SilcServer server,
 void silc_server_close_connection(SilcServer server,
                                  SilcSocketConnection sock)
 {
-
   SILC_LOG_DEBUG(("Closing connection %d", sock->sock));
 
   /* We won't listen for this connection anymore */
@@ -1645,6 +1663,7 @@ void silc_server_free_sock_user_data(SilcServer server,
       /* Free the client entry and everything in it */
       silc_idlist_del_data(user_data);
       silc_idlist_del_client(server->local_list, user_data);
+      server->stat.my_clients--;
       break;
     }
   case SILC_SOCKET_TYPE_SERVER:
@@ -1662,6 +1681,7 @@ void silc_server_free_sock_user_data(SilcServer server,
       /* Free the server entry */
       silc_idlist_del_data(user_data);
       silc_idlist_del_server(server->local_list, user_data);
+      server->stat.my_servers--;
       break;
     }
   default:
@@ -1752,12 +1772,14 @@ void silc_server_remove_from_channels(SilcServer server,
                                           clidp->data, clidp->len);
       
       silc_idlist_del_channel(server->local_list, channel);
+      server->stat.my_channels--;
       continue;
     }
 
     /* Remove from list */
     silc_list_del(channel->user_list, chl);
     silc_free(chl);
+    server->stat.my_chanclients--;
 
     /* Send notify to channel about client leaving SILC and thus
        the entire channel. */
@@ -1813,12 +1835,14 @@ int silc_server_remove_from_one_channel(SilcServer server,
       
       silc_idlist_del_channel(server->local_list, channel);
       silc_buffer_free(clidp);
+      server->stat.my_channels--;
       return FALSE;
     }
 
     /* Remove from list */
     silc_list_del(channel->user_list, chl);
     silc_free(chl);
+    server->stat.my_chanclients--;
 
     /* If there is no global users on the channel anymore mark the channel
        as local channel. */
@@ -1832,6 +1856,7 @@ int silc_server_remove_from_one_channel(SilcServer server,
        !silc_server_channel_has_local(channel)) {
       silc_idlist_del_channel(server->local_list, channel);
       silc_buffer_free(clidp);
+      server->stat.my_channels--;
       return FALSE;
     }
 
@@ -1929,6 +1954,8 @@ SilcChannelEntry silc_server_create_new_channel(SilcServer server,
                                 channel_name, entry->id, SILC_ID_CHANNEL_LEN);
   }
 
+  server->stat.my_channels++;
+
   return entry;
 }
 
index bd1abf16c3321d62806807cb4eeb0044f007a095..37236c34e7ad806045675f36cefd52411e3aa088 100644 (file)
 
 /* Server statistics structure. This holds various statistics about
    various things. */
-/* XXX TODO */
 typedef struct {
-
+  /* Local stats (server and router) */
+  unsigned long my_clients;      /* Locally connected clients */
+  unsigned long my_servers;      /* Locally connected servers */
+  unsigned long my_routers;      /* Locally connected routers */
+  unsigned long my_channels;     /* Locally created channels */
+  unsigned long my_chanclients;          /* Local clients on local channels */
+  unsigned long my_aways;        /* Local clients away (XXX) */
+  unsigned long my_server_ops;   /* Local server operators */
+  unsigned long my_router_ops;   /* Local router operators */
+
+  /* Global stats (mainly for router) */
+  unsigned long cell_clients;    /* All clients in cell */
+  unsigned long cell_servers;    /* All servers in cell */
+  unsigned long cell_channels;   /* All channels in cell */
+  unsigned long cell_chanclients; /* All clients on cell's channels */
+  unsigned long clients;         /* All clients */
+  unsigned long servers;         /* All servers */
+  unsigned long routers;         /* All routers */
+  unsigned long channels;        /* All channels */
+  unsigned long chanclients;     /* All clients on channels */
+  unsigned long server_ops;      /* All server operators */
+  unsigned long router_ops;      /* All router operators */
+
+  /* General */
+  unsigned long conn_attempts;   /* Connection attempts */
+  unsigned long conn_failures;   /* Connection failure */
+  unsigned long auth_attempts;   /* Authentication attempts */
+  unsigned long auth_failures;   /* Authentication failures */
+  unsigned long packets_sent;    /* Sent packets */
+  unsigned long packets_received; /* Received packets */
 } SilcServerStatistics;
 
 typedef struct {
@@ -102,7 +130,7 @@ struct SilcServerStruct {
   SilcRng rng;
 
   /* Server statistics */
-  SilcServerStatistics stats;
+  SilcServerStatistics stat;
 
   /* Pending command queue */
   SilcDList pending_commands;