From: Pekka Riikonen Date: Thu, 15 Feb 2001 12:24:50 +0000 (+0000) Subject: Added silc_server_remove_clients_by_server. X-Git-Tag: SILC.0.1~220 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=439d7874f4cc9590a4a4e5d57f924c1b661a1485 Added silc_server_remove_clients_by_server. --- diff --git a/CHANGES b/CHANGES index 2657723c..b9c7fddd 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +Thu Feb 15 14:24:32 EET 2001 Pekka Riikonen + + * 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 * Made some sanity checks to silc_server_daemonise like to check diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 05cba089..6fd86d7d 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -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. */ diff --git a/apps/silcd/server.h b/apps/silcd/server.h index 24cb37c6..c6d27d75 100644 --- a/apps/silcd/server.h +++ b/apps/silcd/server.h @@ -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); diff --git a/apps/silcd/testi2.conf b/apps/silcd/testi2.conf index f6818db1..fe6247a1 100644 --- a/apps/silcd/testi2.conf +++ b/apps/silcd/testi2.conf @@ -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]