Added silc_server_remove_clients_by_server.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 15 Feb 2001 12:24:50 +0000 (12:24 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 15 Feb 2001 12:24:50 +0000 (12:24 +0000)
CHANGES
apps/silcd/server.c
apps/silcd/server.h
apps/silcd/testi2.conf

diff --git a/CHANGES b/CHANGES
index 2657723ced7fcf900afd814f4ed356fc1bde2d4d..b9c7fdddbed1951075da91424c55ebd451381e71 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,12 @@
+Thu Feb 15 14:24:32 EET 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+       * Added new function silc_server_remove_clients_by_server to
+         remove all client entries from ID list when the server connection
+         is lost.  In this case it is also important to invalidate all
+         client entires as they hold the invalid server entry.  This
+         fixes fatal bug when server has lost connection and will reconnect
+         again.
+
 Wed Feb 14 16:03:25 EET 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Made some sanity checks to silc_server_daemonise like to check
index 05cba0894a9f485b120f7b1e9dac1c62c79e0de3..6fd86d7d6b27f499c7437ff8bb209cf1e5c26667 100644 (file)
@@ -1821,6 +1821,18 @@ void silc_server_free_sock_user_data(SilcServer server,
                                   FALSE : TRUE, user_data->id, 
                                   SILC_ID_CLIENT_LEN, SILC_ID_CLIENT);
 
+      /* Then also free all client entries that this server owns as
+        they will become invalid now as well. */
+      silc_server_remove_clients_by_server(server, user_data);
+
+      /* If this was our primary router connection then we're lost to
+        the outside world. */
+      if (server->server_type == SILC_SERVER && server->router == user_data) {
+       server->id_entry->router = NULL;
+       server->router = NULL;
+       server->standalone = TRUE;
+      }
+
       /* Free the server entry */
       silc_idlist_del_data(user_data);
       silc_idlist_del_server(server->local_list, user_data);
@@ -1843,6 +1855,70 @@ void silc_server_free_sock_user_data(SilcServer server,
   sock->user_data = NULL;
 }
 
+/* This function is used to remove all client entries by the server `entry'.
+   This is called when the connection is lost to the server. In this case
+   we must invalidate all the client entries owned by the server `entry'. */
+
+int silc_server_remove_clients_by_server(SilcServer server, 
+                                        SilcServerEntry entry)
+{
+  SilcIDCacheList list = NULL;
+  SilcIDCacheEntry id_cache = NULL;
+  SilcClientEntry client = NULL;
+
+  if (silc_idcache_find_by_id(server->local_list->clients, 
+                             SILC_ID_CACHE_ANY, SILC_ID_CLIENT, &list)) {
+
+    if (silc_idcache_list_first(list, &id_cache)) {
+      while (id_cache) {
+       client = (SilcClientEntry)id_cache->context;
+       
+       if (client->router != entry) {
+         if (!silc_idcache_list_next(list, &id_cache))
+           break;
+         else
+           continue;
+       }
+
+       /* Remove the client entry */
+       silc_server_remove_from_channels(server, NULL, client);
+       silc_idlist_del_client(server->local_list, client);
+
+       if (!silc_idcache_list_next(list, &id_cache))
+         break;
+      }
+    }
+    silc_idcache_list_free(list);
+  }
+  
+  if (silc_idcache_find_by_id(server->global_list->clients, 
+                             SILC_ID_CACHE_ANY, SILC_ID_CLIENT, &list)) {
+
+    if (silc_idcache_list_first(list, &id_cache)) {
+      while (id_cache) {
+       client = (SilcClientEntry)id_cache->context;
+       
+       if (client->router != entry) {
+         if (!silc_idcache_list_next(list, &id_cache))
+           break;
+         else
+           continue;
+       }
+
+       /* Remove the client entry */
+       silc_server_remove_from_channels(server, NULL, client);
+       silc_idlist_del_client(server->global_list, client);
+
+       if (!silc_idcache_list_next(list, &id_cache))
+         break;
+      }
+    }
+    silc_idcache_list_free(list);
+  }
+  
+  return TRUE;
+}
+
 /* Checks whether given channel has global users.  If it does this returns
    TRUE and FALSE if there is only locally connected clients on the channel. */
 
index 24cb37c64352b231d7be87cfa3c402c75b50406e..c6d27d75b59cacded60525c1e484f514e9b45272 100644 (file)
@@ -92,6 +92,8 @@ void silc_server_free_sock_user_data(SilcServer server,
                                     SilcSocketConnection sock);
 int silc_server_channel_has_global(SilcChannelEntry channel);
 int silc_server_channel_has_local(SilcChannelEntry channel);
+int silc_server_remove_clients_by_server(SilcServer server, 
+                                        SilcServerEntry entry);
 void silc_server_remove_from_channels(SilcServer server, 
                                      SilcSocketConnection sock,
                                      SilcClientEntry client);
index f6818db19560df19b7e1d4cfdf9addf7d93a4395..fe6247a1d0a8b9ff75a693d83810e3924412a3a0 100644 (file)
@@ -19,10 +19,10 @@ nobody:nobody
 Mun huone:Mun servo:Pekka Riikonen:priikone@poseidon.pspt.fi
 
 [ServerInfo]
-lassi.kuo.fi.ssh.com:212.146.8.245:Kuopio, Finland:1334
+lassi.kuo.fi.ssh.com:10.2.1.7:Kuopio, Finland:1334
 
 [ListenPort]
-212.146.8.245:212.146.8.245:1334
+10.2.1.7:10.2.1.7:1334
 
 [Logging]
 infologfile:silcd2.log:10000
@@ -43,9 +43,10 @@ errorlogfile:silcd2.log:10000
 [AdminConnection]
 
 [ServerConnection]
-212.146.8.245:passwd:priikone:1333:1:1
+10.2.1.7:passwd:priikone:1333:1:1
 
 [RouterConnection]
+10.2.1.7:passwd:priikone:1335:1:1:0
 
 [DenyConnection]
 [RedirectClient]