updates.
authorPekka Riikonen <priikone@silcnet.org>
Fri, 29 Mar 2002 08:45:36 +0000 (08:45 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 29 Mar 2002 08:45:36 +0000 (08:45 +0000)
CHANGES
apps/silcd/server.c
apps/silcd/server_util.c
apps/silcd/server_util.h
apps/silcd/serverconfig.c
apps/silcd/serverconfig.h
apps/silcd/silcd.c

diff --git a/CHANGES b/CHANGES
index e0bf64910fee99603bcfa1b156d015e2350ad3ec..ff8dfd07c32374b625dffcad80c06444738e2fe7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+Fri Mar 29 10:41:07 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * And yet again reverted back the config thing since Johnny
+         screwed it up.  Affected file silcd/serverconfig.[ch], server.c,
+         and silcd.c.
+
 Fri Mar 29 03:26:12 CET 2002 Johnny Mnemonic <johnny@themnemonic.org>
 
        * Added preliminary checking during config parsing for a valid
index c00c3ea94495435f9d70e17a5745a6e706bbba80..5a0a9ebd5d39e778ae0e7a237fe73a2679d246f4 100644 (file)
@@ -282,7 +282,7 @@ bool silc_server_init(SilcServer server)
      timeout. It expires as soon as the caller calls silc_server_run. This
      task performs authentication protocol and key exchange with our
      primary router. */
-  silc_schedule_task_add(server->schedule, sock,
+  silc_schedule_task_add(server->schedule, 0,
                         silc_server_connect_to_router,
                         (void *)server, 0, 1,
                         SILC_TASK_TIMEOUT,
@@ -356,15 +356,10 @@ bool silc_server_init(SilcServer server)
 bool silc_server_rehash(SilcServer server)
 {
   SilcServerConfig newconfig;
+  SilcUInt32 max_conns;
 
   SILC_LOG_INFO(("Rehashing server"));
 
-  /* Our old config is gone now. We'll unreference our reference made in
-     silc_server_init and then destroy it since we are destroying it
-     underneath the application (layer which called silc_server_init). */
-  silc_server_config_unref(&server->config_ref);
-  silc_server_config_destroy(server->config);
-
   /* Reset the logging system */
   silc_log_quick = TRUE;
   silc_log_flush_all();
@@ -376,10 +371,23 @@ bool silc_server_rehash(SilcServer server)
     return FALSE;
   }
 
+  max_conns = server->config->param.connections_max;
+
+  /* Our old config is gone now. We'll unreference our reference made in
+     silc_server_init and then destroy it since we are destroying it
+     underneath the application (layer which called silc_server_init). */
+  silc_server_config_unref(&server->config_ref);
+  silc_server_config_destroy(server->config);
+
   /* Take new config context */
   server->config = newconfig;
   silc_server_config_ref(&server->config_ref, server->config, server->config);
 
+  /* Reinit scheduler if necessary */
+  if (server->config->param.connections_max > max_conns)
+    silc_schedule_reinit(server->schedule, 
+                        server->config->param.connections_max);
+
   /* Fix the server_name field */
   if (strcmp(server->server_name, newconfig->server_info->server_name)) {
     silc_free(server->server_name);
@@ -416,6 +424,31 @@ bool silc_server_rehash(SilcServer server)
     silc_pkcs_private_key_set(server->pkcs, server->private_key);
   }
 
+  /* Go through all configured routers after rehash */
+  silc_schedule_task_add(server->schedule, 0,
+                        silc_server_connect_to_router,
+                        (void *)server, 0, 1,
+                        SILC_TASK_TIMEOUT,
+                        SILC_TASK_PRI_NORMAL);
+
+  /* Check whether our router status has changed */
+  if (server->config->servers) {
+    SilcServerConfigServer *ptr = server->config->servers;
+
+    server->server_type = SILC_ROUTER;
+    while (ptr) {
+      if (ptr->backup_router) {
+       server->server_type = SILC_BACKUP_ROUTER;
+       server->backup_router = TRUE;
+       server->id_entry->server_type = SILC_BACKUP_ROUTER;
+       break;
+      }
+      ptr = ptr->next;
+    }
+  }
+
+  SILC_LOG_DEBUG(("Server rehashed"));
+
   return TRUE;
 }
 
@@ -662,6 +695,17 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router)
                    ptr->host, ptr->port));
 
     if (ptr->initiator) {
+      /* Check whether we are connected to this host already */
+      if (silc_server_num_sockets_by_remote(server, 
+                                           silc_net_is_ip(ptr->host) ?
+                                           ptr->host : NULL,
+                                           silc_net_is_ip(ptr->host) ?
+                                           NULL : ptr->host, ptr->port,
+                                           SILC_SOCKET_TYPE_ROUTER)) {
+       SILC_LOG_DEBUG(("We are already connected to this router"));
+       continue;
+      }
+
       /* Allocate connection object for hold connection specific stuff. */
       sconn = silc_calloc(1, sizeof(*sconn));
       sconn->server = server;
@@ -676,7 +720,7 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router)
       if (!server->router_conn && !sconn->backup)
        server->router_conn = sconn;
 
-      silc_schedule_task_add(server->schedule, fd,
+      silc_schedule_task_add(server->schedule, 0,
                             silc_server_connect_router,
                             (void *)sconn, 0, 1, SILC_TASK_TIMEOUT,
                             SILC_TASK_PRI_NORMAL);
index cad3223a67a16a8e91cf01c2d28ca448066ead8c..abc20ce67563c52f1b014ac41952322fb3e283bc 100644 (file)
@@ -809,6 +809,33 @@ SilcUInt32 silc_server_num_sockets_by_ip(SilcServer server, const char *ip,
   return count;
 }
 
+/* Find number of sockets by IP address indicated by remote host, indicatd
+   by `ip' or `hostname', `port', and `type'.  Returns 0 if socket connections
+   does not exist. If `ip' is provided then `hostname' is ignored. */
+
+SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server, 
+                                            const char *ip,
+                                            const char *hostname,
+                                            SilcUInt16 port,
+                                            SilcSocketType type)
+{
+  int i, count;
+
+  if (!ip && !hostname)
+    return 0;
+
+  for (i = 0, count = 0; i < server->config->param.connections_max; i++) {
+    if (server->sockets[i] && 
+       ((ip && !strcmp(server->sockets[i]->ip, ip)) ||
+        (hostname && !strcmp(server->sockets[i]->hostname, hostname))) &&
+       server->sockets[i]->port == port &&
+       server->sockets[i]->type == type)
+      count++;
+  }
+
+  return count;
+}
+
 /* Finds locally cached public key by the public key received in the SKE. 
    If we have it locally cached then we trust it and will use it in the
    authentication protocol.  Returns the locally cached public key or NULL
index 8300a4b57b997fab3b248610d8517f302291fd46..ebb4b4fc113515b2241b38bc8a8716f0bfe13c1b 100644 (file)
@@ -87,6 +87,15 @@ char *silc_server_name_modify_bad(const char *name, SilcUInt32 name_len);
 SilcUInt32 silc_server_num_sockets_by_ip(SilcServer server, const char *ip,
                                         SilcSocketType type);
 
+/* Find number of sockets by IP address indicated by remote host, indicatd
+   by `ip' or `hostname', `port', and `type'.  Returns 0 if socket connections
+   does not exist. If `ip' is provided then `hostname' is ignored. */
+SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server, 
+                                            const char *ip,
+                                            const char *hostname,
+                                            SilcUInt16 port,
+                                            SilcSocketType type);
+
 /* Finds locally cached public key by the public key received in the SKE. 
    If we have it locally cached then we trust it and will use it in the
    authentication protocol.  Returns the locally cached public key or NULL
index 0b31048af5093fcc86a32b7cb33f9196555426de..b4c264b34d9472bce2211e1dd1c81c73042352ac 100644 (file)
@@ -884,10 +884,6 @@ SILC_CONFIG_CALLBACK(fetch_server)
       goto got_err;
     }
   }
-  else if (!strcmp(name, "versionid")) {
-    CONFIG_IS_DOUBLE(tmp->version);
-    tmp->version = strdup((char *) val);
-  }
   else if (!strcmp(name, "params")) {
     CONFIG_IS_DOUBLE(tmp->param);
     tmp->param = my_find_param(config, (char *) val, line);
@@ -906,7 +902,6 @@ SILC_CONFIG_CALLBACK(fetch_server)
 
  got_err:
   silc_free(tmp->host);
-  silc_free(tmp->version);
   CONFIG_FREE_AUTH(tmp);
   silc_free(tmp);
   config->tmp = NULL;
@@ -966,10 +961,6 @@ SILC_CONFIG_CALLBACK(fetch_router)
       goto got_err;
     }
   }
-  else if (!strcmp(name, "versionid")) {
-    CONFIG_IS_DOUBLE(tmp->version);
-    tmp->version = strdup((char *) val);
-  }
   else if (!strcmp(name, "params")) {
     CONFIG_IS_DOUBLE(tmp->param);
     tmp->param = my_find_param(config, (char *) val, line);
@@ -1004,7 +995,6 @@ SILC_CONFIG_CALLBACK(fetch_router)
 
  got_err:
   silc_free(tmp->host);
-  silc_free(tmp->version);
   silc_free(tmp->backup_replace_ip);
   CONFIG_FREE_AUTH(tmp);
   silc_free(tmp);
@@ -1144,7 +1134,6 @@ static const SilcConfigTable table_serverconn[] = {
   { "host",            SILC_CONFIG_ARG_STRE,   fetch_server,   NULL },
   { "passphrase",      SILC_CONFIG_ARG_STR,    fetch_server,   NULL },
   { "publickey",       SILC_CONFIG_ARG_STR,    fetch_server,   NULL },
-  { "versionid",       SILC_CONFIG_ARG_STR,    fetch_server,   NULL },
   { "params",          SILC_CONFIG_ARG_STR,    fetch_server,   NULL },
   { "backup",          SILC_CONFIG_ARG_TOGGLE, fetch_server,   NULL },
   { 0, 0, 0, 0 }
@@ -1155,7 +1144,6 @@ static const SilcConfigTable table_routerconn[] = {
   { "port",            SILC_CONFIG_ARG_INT,    fetch_router,   NULL },
   { "passphrase",      SILC_CONFIG_ARG_STR,    fetch_router,   NULL },
   { "publickey",       SILC_CONFIG_ARG_STR,    fetch_router,   NULL },
-  { "versionid",       SILC_CONFIG_ARG_STR,    fetch_router,   NULL },
   { "params",          SILC_CONFIG_ARG_STR,    fetch_router,   NULL },
   { "initiator",       SILC_CONFIG_ARG_TOGGLE, fetch_router,   NULL },
   { "backuphost",      SILC_CONFIG_ARG_STRE,   fetch_router,   NULL },
@@ -1310,7 +1298,11 @@ void silc_server_config_destroy(SilcServerConfig config)
 
   SILC_LOG_DEBUG(("Freeing config context"));
 
+  /* Destroy general config stuff */
   silc_free(config->module_path);
+  silc_free(config->param.version_protocol);
+  silc_free(config->param.version_software);
+  silc_free(config->param.version_software_vendor);
 
   /* Destroy Logging channels */
   if (config->logging_info)
@@ -1361,8 +1353,15 @@ void silc_server_config_destroy(SilcServerConfig config)
     silc_free(di->name);
     silc_free(di);
   }
-  SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigClient,
-                                 config->clients)
+  SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigConnParams,
+                                  config->conn_params)
+    silc_free(di->name);
+    silc_free(di->version_protocol);
+    silc_free(di->version_software);
+    silc_free(di->version_software_vendor);
+    silc_free(di);
+  }
+  SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigClient, config->clients)
     silc_free(di->host);
     CONFIG_FREE_AUTH(di);
     silc_free(di);
@@ -1382,14 +1381,12 @@ void silc_server_config_destroy(SilcServerConfig config)
   SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigServer,
                                  config->servers)
     silc_free(di->host);
-    silc_free(di->version);
     CONFIG_FREE_AUTH(di);
     silc_free(di);
   }
   SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigRouter,
                                  config->routers)
     silc_free(di->host);
-    silc_free(di->version);
     silc_free(di->backup_replace_ip);
     CONFIG_FREE_AUTH(di);
     silc_free(di);
index cd5e2201be09a62a512316dd2cb2b0c8a7f22d1c..4d79063d8954bbd5b38faa2cabd00cd047b13ed3 100644 (file)
@@ -122,7 +122,6 @@ typedef struct SilcServerConfigServerStruct {
   unsigned char *passphrase;
   SilcUInt32 passphrase_len;
   SilcHashTable publickeys;
-  char *version;
   SilcServerConfigConnParams *param;
   bool backup_router;
   struct SilcServerConfigServerStruct *next;
@@ -135,7 +134,6 @@ typedef struct SilcServerConfigRouterStruct {
   SilcUInt32 passphrase_len;
   SilcHashTable publickeys;
   SilcUInt16 port;
-  char *version;
   SilcServerConfigConnParams *param;
   bool initiator;
   bool backup_router;
index 2ad30724bd57726764feafc8d12f5c32130f82c7..82d29d7a44767154f713a9aa028d594e7a2bee91 100644 (file)
@@ -381,9 +381,6 @@ int main(int argc, char **argv)
   if (silcd->config == NULL)
     goto fail;
   silcd->config_file = silcd_config_file;
-  /* Since silc_server_config_alloc returns an unreferenced config object
-     we must immediately increment it. */
-  silc_server_config_ref(&silcd->config_ref, silcd->config, silcd->config);
 
   /* Check for another silcd running */
   silc_server_checkpid(silcd);
@@ -428,6 +425,7 @@ int main(int argc, char **argv)
   /* Stop the server and free it. */
   silc_server_stop(silcd);
   silc_server_free(silcd);
+  silc_server_config_destroy(silcd->config);
 
   /* Flush the logging system */
   silc_log_flush_all();