+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
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,
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();
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);
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;
}
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;
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);
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
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
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);
got_err:
silc_free(tmp->host);
- silc_free(tmp->version);
CONFIG_FREE_AUTH(tmp);
silc_free(tmp);
config->tmp = NULL;
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);
got_err:
silc_free(tmp->host);
- silc_free(tmp->version);
silc_free(tmp->backup_replace_ip);
CONFIG_FREE_AUTH(tmp);
silc_free(tmp);
{ "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 }
{ "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 },
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)
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);
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);
unsigned char *passphrase;
SilcUInt32 passphrase_len;
SilcHashTable publickeys;
- char *version;
SilcServerConfigConnParams *param;
bool backup_router;
struct SilcServerConfigServerStruct *next;
SilcUInt32 passphrase_len;
SilcHashTable publickeys;
SilcUInt16 port;
- char *version;
SilcServerConfigConnParams *param;
bool initiator;
bool backup_router;
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);
/* 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();