From a968abb33dc0ecdb572601b39f223d7e79f41860 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Fri, 25 Jan 2002 18:04:45 +0000 Subject: [PATCH] updates. --- CHANGES | 13 ++++++ TODO | 2 + apps/irssi/docs/help/in/sconnect.in | 5 +- apps/silcd/command.c | 45 +++++++++++++++--- apps/silcd/packet_receive.c | 71 ++++++++++++++++++++++------- apps/silcd/server.c | 15 +++--- apps/silcd/server.h | 6 +-- apps/silcd/server_internal.h | 10 ++++ apps/silcd/server_util.c | 20 +++++--- 9 files changed, 149 insertions(+), 38 deletions(-) diff --git a/CHANGES b/CHANGES index 0d6761e4..f843b00b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,16 @@ +Fri Jan 25 19:12:36 EET 2002 Pekka Riikonen + + * Added server & router operator statistics updating. Affected + file silcd/packet_receive.c and silcd/command.c. + + * Fixed the SERVER_SIGNOFF notify handling on normal server + not to save the history information for clients. Same was + fixed earlier in remove_clients_by_server function, but not + here. Affected file silcd/packet_receive.c. + + * Raised the default connection-retry count from 4 to 7 in + server. Affected file silcd/server.h. + Tue Jan 22 18:19:36 EET 2002 Pekka Riikonen * Removed assert()'s from the lib/silcclient/client_keyagr.c. diff --git a/TODO b/TODO index b8f2c9ec..2a2da686 100644 --- a/TODO +++ b/TODO @@ -81,6 +81,8 @@ TODO/bugs In SILC Server o IP address fields in configuration file should accept mask format as well, IP/MASK, and not just plain IP. + o Lots of statistics updating is missing around the server. + o If client's public key is saved in the server (and doing public key authentication) then the hostname and the username information could be taken from the public key. Should be a configuration option! diff --git a/apps/irssi/docs/help/in/sconnect.in b/apps/irssi/docs/help/in/sconnect.in index 0d2137ba..f77c5d3d 100644 --- a/apps/irssi/docs/help/in/sconnect.in +++ b/apps/irssi/docs/help/in/sconnect.in @@ -2,7 +2,10 @@ @SYNTAX:sconnect@ Operator command. Makes an server to connect to another -server or router. +server or router. The is the hostname or IP +addres of the server. + +Example: /SCONNECT silc.silcnet.org 706 See also: OPER, SILCOPER, CLOSE, SHUTDOWN diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 11e93037..d413a946 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -2657,6 +2657,7 @@ SILC_SERVER_CMD_FUNC(kill) SilcClientID *client_id; unsigned char *tmp, *comment; uint32 tmp_len, tmp_len2; + bool local; SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_KILL, cmd, 1, 2); @@ -2694,9 +2695,11 @@ SILC_SERVER_CMD_FUNC(kill) /* Get the client entry */ remote_client = silc_idlist_find_client_by_id(server->local_list, client_id, TRUE, NULL); + local = TRUE; if (!remote_client) { remote_client = silc_idlist_find_client_by_id(server->global_list, client_id, TRUE, NULL); + local = FALSE; if (!remote_client) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_KILL, SILC_STATUS_ERR_NO_SUCH_CLIENT_ID); @@ -2750,9 +2753,17 @@ SILC_SERVER_CMD_FUNC(kill) silc_server_free_client_data(server, sock, remote_client, FALSE, NULL); silc_server_close_connection(server, sock); } else { + /* Update statistics */ + if (remote_client->connection) + server->stat.my_clients--; + if (server->server_type == SILC_ROUTER) + server->stat.cell_clients--; + SILC_OPER_STATS_UPDATE(remote_client, server, SILC_UMODE_SERVER_OPERATOR); + SILC_OPER_STATS_UPDATE(remote_client, router, SILC_UMODE_ROUTER_OPERATOR); + /* Remove remote client */ - if (!silc_idlist_del_client(server->global_list, remote_client)) - silc_idlist_del_client(server->local_list, remote_client); + silc_idlist_del_client(local ? server->local_list : + server->global_list, remote_client); } out: @@ -3640,9 +3651,14 @@ SILC_SERVER_CMD_FUNC(umode) goto out; } } else { - if (client->mode & SILC_UMODE_SERVER_OPERATOR) - /* Remove the server operator rights */ + /* Remove the server operator rights */ + if (client->mode & SILC_UMODE_SERVER_OPERATOR) { client->mode &= ~SILC_UMODE_SERVER_OPERATOR; + if (client->connection) + server->stat.my_server_ops--; + if (server->server_type == SILC_ROUTER) + server->stat.server_ops--; + } } if (mask & SILC_UMODE_ROUTER_OPERATOR) { @@ -3653,9 +3669,14 @@ SILC_SERVER_CMD_FUNC(umode) goto out; } } else { - if (client->mode & SILC_UMODE_ROUTER_OPERATOR) - /* Remove the router operator rights */ + /* Remove the router operator rights */ + if (client->mode & SILC_UMODE_ROUTER_OPERATOR) { client->mode &= ~SILC_UMODE_ROUTER_OPERATOR; + if (client->connection) + server->stat.my_router_ops--; + if (server->server_type == SILC_ROUTER) + server->stat.router_ops--; + } } if (mask & SILC_UMODE_GONE) { @@ -4590,6 +4611,12 @@ SILC_SERVER_CMD_FUNC(oper) /* Client is now server operator */ client->mode |= SILC_UMODE_SERVER_OPERATOR; + /* Update statistics */ + if (client->connection) + server->stat.my_server_ops++; + if (server->server_type == SILC_ROUTER) + server->stat.server_ops++; + /* Send UMODE change to primary router */ if (!server->standalone) silc_server_send_notify_umode(server, server->router->connection, TRUE, @@ -4668,6 +4695,12 @@ SILC_SERVER_CMD_FUNC(silcoper) /* Client is now router operator */ client->mode |= SILC_UMODE_ROUTER_OPERATOR; + /* Update statistics */ + if (client->connection) + server->stat.my_router_ops++; + if (server->server_type == SILC_ROUTER) + server->stat.router_ops++; + /* Send UMODE change to primary router */ if (!server->standalone) silc_server_send_notify_umode(server, server->router->connection, TRUE, diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index a4bedaef..85b1a1b2 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -324,14 +324,18 @@ void silc_server_notify(SilcServer server, if (tmp_len > 128) tmp = NULL; + /* Update statistics */ + server->stat.clients--; + if (server->server_type == SILC_ROUTER) + server->stat.cell_clients--; + SILC_OPER_STATS_UPDATE(client, server, SILC_UMODE_SERVER_OPERATOR); + SILC_OPER_STATS_UPDATE(client, router, SILC_UMODE_ROUTER_OPERATOR); + /* Remove the client from all channels. */ silc_server_remove_from_channels(server, NULL, client, TRUE, tmp, FALSE); client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED; cache->expire = SILC_ID_CACHE_EXPIRE_DEF; - server->stat.clients--; - if (server->server_type == SILC_ROUTER) - server->stat.cell_clients--; break; case SILC_NOTIFY_TYPE_TOPIC_SET: @@ -849,6 +853,7 @@ void silc_server_notify(SilcServer server, if (server->server_type != SILC_ROUTER && silc_argument_get_arg_num(args) > 1) { int i; + bool local; for (i = 1; i < silc_argument_get_arg_num(args); i++) { /* Get Client ID */ @@ -862,9 +867,11 @@ void silc_server_notify(SilcServer server, /* Get client entry */ client = silc_idlist_find_client_by_id(server->global_list, client_id, TRUE, &cache); + local = TRUE; if (!client) { client = silc_idlist_find_client_by_id(server->local_list, client_id, TRUE, &cache); + local = FALSE; if (!client) { silc_free(client_id); continue; @@ -872,15 +879,20 @@ void silc_server_notify(SilcServer server, } silc_free(client_id); - /* Remove the client from all channels. */ - silc_server_remove_from_channels(server, NULL, client, - TRUE, NULL, FALSE); - - client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED; - cache->expire = SILC_ID_CACHE_EXPIRE_DEF; + /* Update statistics */ server->stat.clients--; if (server->server_type == SILC_ROUTER) server->stat.cell_clients--; + SILC_OPER_STATS_UPDATE(client, server, SILC_UMODE_SERVER_OPERATOR); + SILC_OPER_STATS_UPDATE(client, router, SILC_UMODE_ROUTER_OPERATOR); + + /* Remove the client from all channels. */ + silc_server_remove_from_channels(server, NULL, client, + TRUE, NULL, FALSE); + + /* Remove the client */ + silc_idlist_del_client(local ? server->local_list : + server->global_list, client); } } @@ -1025,7 +1037,7 @@ void silc_server_notify(SilcServer server, */ SILC_LOG_DEBUG(("UMODE_CHANGE notify")); - + /* Get client ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -1051,9 +1063,33 @@ void silc_server_notify(SilcServer server, tmp = silc_argument_get_arg_type(args, 2, &tmp_len); if (!tmp) goto out; + SILC_GET32_MSB(mode, tmp); + +#define SILC_UMODE_STATS_UPDATE(oper, mod) \ +do { \ + if (client->mode & (mod)) { \ + if (!(mode & (mod))) { \ + if (client->connection) \ + server->stat.my_ ## oper ## _ops--; \ + if (server->server_type == SILC_ROUTER) \ + server->stat. oper ## _ops--; \ + } \ + } else { \ + if (mode & (mod)) { \ + if (client->connection) \ + server->stat.my_ ## oper ## _ops++; \ + if (server->server_type == SILC_ROUTER) \ + server->stat. oper ## _ops++; \ + } \ + } \ +} while(0) + + /* Update statistics */ + SILC_UMODE_STATS_UPDATE(server, SILC_UMODE_SERVER_OPERATOR); + SILC_UMODE_STATS_UPDATE(router, SILC_UMODE_ROUTER_OPERATOR); /* Save the mode */ - SILC_GET32_MSB(client->mode, tmp); + client->mode = mode; break; @@ -1121,7 +1157,6 @@ void silc_server_notify(SilcServer server, } } } - break; /* Ignore rest of the notify types for now */ @@ -1673,10 +1708,14 @@ SilcClientEntry silc_server_new_client(SilcServer server, 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)); + ("There are %d server operators and %d router " + "operators online", + server->stat.server_ops, + server->stat.router_ops)); + SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE, + ("I have %d operators online", + server->stat.my_router_ops + + server->stat.my_server_ops)); } else { SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE, ("I have %d clients and %d channels formed", diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 64c837a1..50945385 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -2351,6 +2351,14 @@ void silc_server_free_client_data(SilcServer server, silc_server_remove_from_channels(server, NULL, client, FALSE, NULL, FALSE); + /* Update statistics */ + server->stat.my_clients--; + server->stat.clients--; + if (server->server_type == SILC_ROUTER) + server->stat.cell_clients--; + SILC_OPER_STATS_UPDATE(client, server, SILC_UMODE_SERVER_OPERATOR); + SILC_OPER_STATS_UPDATE(client, router, SILC_UMODE_ROUTER_OPERATOR); + /* We will not delete the client entry right away. We will take it into history (for WHOWAS command) for 5 minutes */ i->server = server; @@ -2362,12 +2370,7 @@ void silc_server_free_client_data(SilcServer server, client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED; client->router = NULL; client->connection = NULL; - - /* Free the client entry and everything in it */ - server->stat.my_clients--; - server->stat.clients--; - if (server->server_type == SILC_ROUTER) - server->stat.cell_clients--; + client->mode = 0; } /* Frees user_data pointer from socket connection object. This also sends diff --git a/apps/silcd/server.h b/apps/silcd/server.h index 6590f602..012d1edf 100644 --- a/apps/silcd/server.h +++ b/apps/silcd/server.h @@ -42,10 +42,10 @@ typedef struct SilcServerBackupStruct *SilcServerBackup; #define SILC_BACKUP_ROUTER 2 /* Connection retry timeout. We implement exponential backoff algorithm - in connection retry. The interval of timeuot grows when retry count + in connection retry. The interval of timeout grows when retry count grows. */ -#define SILC_SERVER_RETRY_COUNT 4 /* Max retry count */ -#define SILC_SERVER_RETRY_MULTIPLIER 7 / 4 /* Interval growth */ +#define SILC_SERVER_RETRY_COUNT 7 /* Max retry count */ +#define SILC_SERVER_RETRY_MULTIPLIER 2 /* Interval growth */ #define SILC_SERVER_RETRY_RANDOMIZER 2 /* timeout += rnd % 2 */ #define SILC_SERVER_RETRY_INTERVAL_MIN 10 /* Min retry timeout */ #define SILC_SERVER_RETRY_INTERVAL_MAX 600 /* Max generated timeout */ diff --git a/apps/silcd/server_internal.h b/apps/silcd/server_internal.h index 8001cf38..e50340b8 100644 --- a/apps/silcd/server_internal.h +++ b/apps/silcd/server_internal.h @@ -173,6 +173,16 @@ do { \ silc_schedule_set_listen_fd((s), (fd), (SILC_TASK_READ | SILC_TASK_WRITE)); \ } while(0) +#define SILC_OPER_STATS_UPDATE(c, type, mod) \ +do { \ + if ((c)->mode & (mod)) { \ + if ((c)->connection) \ + server->stat.my_ ## type ## _ops--; \ + if (server->server_type == SILC_ROUTER) \ + server->stat. type ## _ops--; \ + } \ +} while(0) + /* Prototypes */ SILC_TASK_CALLBACK_GLOBAL(silc_server_rekey_final); diff --git a/apps/silcd/server_util.c b/apps/silcd/server_util.c index c41c8bcf..88e6afa6 100644 --- a/apps/silcd/server_util.c +++ b/apps/silcd/server_util.c @@ -210,6 +210,13 @@ bool silc_server_remove_clients_by_server(SilcServer server, silc_buffer_free(idp); } + /* Update statistics */ + server->stat.clients--; + if (server->server_type == SILC_ROUTER) + server->stat.cell_clients--; + SILC_OPER_STATS_UPDATE(client, server, SILC_UMODE_SERVER_OPERATOR); + SILC_OPER_STATS_UPDATE(client, router, SILC_UMODE_ROUTER_OPERATOR); + /* Remove the client entry */ silc_server_remove_clients_channels(server, NULL, client, channels); if (!server_signoff) { @@ -218,9 +225,6 @@ bool silc_server_remove_clients_by_server(SilcServer server, } else { silc_idlist_del_client(server->local_list, client); } - server->stat.clients--; - if (server->server_type == SILC_ROUTER) - server->stat.cell_clients--; if (!silc_idcache_list_next(list, &id_cache)) break; @@ -270,6 +274,13 @@ bool silc_server_remove_clients_by_server(SilcServer server, silc_buffer_free(idp); } + /* Update statistics */ + server->stat.clients--; + if (server->server_type == SILC_ROUTER) + server->stat.cell_clients--; + SILC_OPER_STATS_UPDATE(client, server, SILC_UMODE_SERVER_OPERATOR); + SILC_OPER_STATS_UPDATE(client, router, SILC_UMODE_ROUTER_OPERATOR); + /* Remove the client entry */ silc_server_remove_clients_channels(server, NULL, client, channels); if (!server_signoff) { @@ -278,9 +289,6 @@ bool silc_server_remove_clients_by_server(SilcServer server, } else { silc_idlist_del_client(server->global_list, client); } - server->stat.clients--; - if (server->server_type == SILC_ROUTER) - server->stat.cell_clients--; if (!silc_idcache_list_next(list, &id_cache)) break; -- 2.24.0