Fixed socket connection counting. Added checks for not adding
authorPekka Riikonen <priikone@silcnet.org>
Fri, 28 Jun 2002 11:56:32 +0000 (11:56 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 28 Jun 2002 11:56:32 +0000 (11:56 +0000)
unregistered client to channels at any point.  Assert that
client is not joined to any channels when client is freed.

CHANGES
apps/silcd/idlist.c
apps/silcd/packet_receive.c
apps/silcd/server.c
apps/silcd/server_util.c

diff --git a/CHANGES b/CHANGES
index 9d0dd713dbc2db3a1d41f5e1624721502657d51d..39385ebec058f2816b7dfa053795bb66330cc940 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,15 @@ Fri Jun 28 11:53:25 CEST 2002 Pekka Riikonen <priikone@silcnet.org>
        * Do not set to wait for backup in rehash of the server.
          Affected file silcd/server.c.
 
+       * Do not check listener sockets when counting how many
+         socket connections we have.  Affected file is
+         silcd/server_util.c.
+
+       * Do not announce disconnected clients that are remaining
+         in history (for WHOWAS).  This is because SIGNOFF notify
+         for these has been sent earlier already.  Affected file
+         silcd/server.c.
+
 Thu Jun 27 20:07:27 EEST 2002 Pekka Riikonen <priikone@silcnet.org>
 
        * Buffer overflow with CUMODE command's mode->mode character
index 7ecb033cd298cfe1207579a596cb976a8c18c384..deae122dbc23af2326be56f64ecc7b7746b220cc 100644 (file)
@@ -368,6 +368,8 @@ int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry)
     if (!silc_idcache_del_by_context(id_list->clients, entry))
       return FALSE;
 
+    assert(!silc_hash_table_count(entry->channels));
+
     /* Free data */
     silc_free(entry->nickname);
     silc_free(entry->servername);
index c721c1038cb293d74000dd6d880fc68cacad2f4a..b2b04a4234a4c5be07768697b98a27b8c509c708 100644 (file)
@@ -3606,7 +3606,8 @@ void silc_server_resume_client(SilcServer server,
       server->stat.cell_clients--;
     silc_server_remove_from_channels(server, NULL, client, FALSE, NULL, FALSE);
     silc_server_del_from_watcher_list(server, client);
-    silc_idlist_del_client(server->local_list, client);
+    if (!silc_idlist_del_client(server->local_list, client))
+      silc_idlist_del_client(server->global_list, client);
     client = detached_client;
 
     /* If the ID is not based in our ID then change it */
index 1f0decd988d48674127eafcbbc12c97aba04cb7d..63e3a609231a6dac52298a1cb4620a959b2b04ac 100644 (file)
@@ -2872,6 +2872,8 @@ SILC_TASK_CALLBACK(silc_server_free_client_data_timeout)
 {
   FreeClientInternal i = (FreeClientInternal)context;
 
+  assert(!silc_hash_table_count(i->client->channels));
+
   silc_idlist_del_data(i->client);
   silc_idcache_purge_by_context(i->server->local_list->clients, i->client);
   silc_free(i);
@@ -2945,6 +2947,7 @@ void silc_server_free_client_data(SilcServer server,
                         (void *)i, 300, 0,
                         SILC_TASK_TIMEOUT, SILC_TASK_PRI_LOW);
   client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
+  client->data.status &= ~SILC_IDLIST_STATUS_LOCAL;
   client->mode = 0;
   client->router = NULL;
   client->connection = NULL;
@@ -3932,6 +3935,12 @@ static void silc_server_announce_get_clients(SilcServer server,
            break;
          continue;
        }
+       if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED) &&
+           !client->connection && !client->router && !SILC_IS_LOCAL(client)) {
+         if (!silc_idcache_list_next(list, &id_cache))
+           break;
+         continue;
+       }
 
        idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
 
@@ -4531,6 +4540,12 @@ void silc_server_save_users_on_channel(SilcServer server,
 
     silc_free(client_id);
 
+    if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED)) {
+      SILC_LOG_ERROR(("Attempting to add unregistered client to channel ",
+                     "%s", channel->channel_name));
+      continue;
+    }
+
     if (!silc_server_client_on_channel(client, channel, &chl)) {
       /* Client was not on the channel, add it. */
       chl = silc_calloc(1, sizeof(*chl));
@@ -4568,7 +4583,8 @@ void silc_server_save_user_channels(SilcServer server,
   char *name;
   int i = 0;
 
-  if (!channels ||!channels_user_modes)
+  if (!channels || !channels_user_modes ||
+      !(client->data.status & SILC_IDLIST_STATUS_REGISTERED))
     goto out;
   
   ch = silc_channel_payload_parse_list(channels->data, channels->len);
index 183819318d3a9a52fc295315aa3dc57517731586..4e1b2cb8f43b3c4b19ec6a4db53821dadf322449 100644 (file)
@@ -1038,7 +1038,8 @@ SilcUInt32 silc_server_num_sockets_by_ip(SilcServer server, const char *ip,
   int i, count;
 
   for (i = 0, count = 0; i < server->config->param.connections_max; i++) {
-    if (server->sockets[i] && !strcmp(server->sockets[i]->ip, ip) &&
+    if (server->sockets[i] && !SILC_IS_LISTENER(server->sockets[i]) &&
+       !strcmp(server->sockets[i]->ip, ip) &&
        server->sockets[i]->type == type)
       count++;
   }
@@ -1062,7 +1063,7 @@ SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server,
     return 0;
 
   for (i = 0, count = 0; i < server->config->param.connections_max; i++) {
-    if (server->sockets[i] && 
+    if (server->sockets[i] && !SILC_IS_LISTENER(server->sockets[i]) &&
        ((ip && !strcmp(server->sockets[i]->ip, ip)) ||
         (hostname && !strcmp(server->sockets[i]->hostname, hostname))) &&
        server->sockets[i]->port == port &&