Ported backup router protocol.
sizeof(serv));
channel_name = parsed;
- /* If server name is not specified but local channels is FALSE then the
- channel will be global, based on our router name. */
- if (!serv[0] && !server->config->local_channels) {
- if (!server->standalone) {
- silc_snprintf(serv, sizeof(serv), server->router->server_name);
- } else {
+ if (server->config->dynamic_server) {
+ /* If server name is not specified but local channels is FALSE then the
+ channel will be global, based on our router name. */
+ if (!serv[0] && !server->config->local_channels) {
+ if (!server->standalone) {
+ silc_snprintf(serv, sizeof(serv), server->router->server_name);
+ } else {
+ SilcServerConfigRouter *router;
+ router = silc_server_config_get_primary_router(server);
+ if (router) {
+ /* Create connection to primary router */
+ SILC_LOG_DEBUG(("Create dynamic connection to primary router %s:%d",
+ router->host, router->port));
+ silc_server_create_connection(server, FALSE, TRUE,
+ router->host, router->port,
+ silc_server_command_join_connected,
+ cmd);
+ return;
+ }
+ }
+ }
+
+ /* If server name is ours, ignore it. */
+ if (serv[0] && silc_utf8_strcasecmp(serv, server->server_name))
+ memset(serv, 0, sizeof(serv));
+
+ /* Create connection */
+ if (serv[0] && server->standalone) {
SilcServerConfigRouter *router;
router = silc_server_config_get_primary_router(server);
if (router) {
}
}
- /* If server name is ours, ignore it. */
- if (serv[0] && silc_utf8_strcasecmp(serv, server->server_name))
- memset(serv, 0, sizeof(serv));
-
- /* Create connection */
- if (serv[0] && server->standalone) {
- SilcServerConfigRouter *router;
- router = silc_server_config_get_primary_router(server);
- if (router) {
- /* Create connection to primary router */
- SILC_LOG_DEBUG(("Create dynamic connection to primary router %s:%d",
- router->host, router->port));
- silc_server_create_connection(server, FALSE, TRUE,
- router->host, router->port,
- silc_server_command_join_connected, cmd);
- return;
- }
- }
-
/* Check for valid channel name. This is cached, the original is saved
in the channel context. */
channel_namec = silc_channel_name_check(channel_name, strlen(channel_name),
/* Connection data */
void *connection;
+
+ void *backup_proto;
+ unsigned int backup : 1; /* Set when executing backup protocol */
};
/*
server->backup_noswitch = (status == SILC_STATUS_OK ? FALSE : TRUE);
/* If backup disconnected then mark that resuming will not be allowed */
-#if 0
if (server->server_type == SILC_ROUTER && !server->backup_router &&
- sock->type == SILC_CONN_SERVER && sock->user_data) {
- SilcServerEntry server_entry = sock->user_data;
+ idata->conn_type == SILC_CONN_SERVER) {
+ SilcServerEntry server_entry = (SilcServerEntry)idata;
if (server_entry->server_type == SILC_BACKUP_ROUTER)
server->backup_closed = TRUE;
}
/* Handle the disconnection from our end too */
- if (sock->user_data && SILC_IS_LOCAL(sock->user_data))
+ if (SILC_IS_LOCAL(idata))
silc_server_free_sock_user_data(server, sock, NULL);
- SILC_SET_DISCONNECTING(sock);
silc_server_close_connection(server, sock);
server->backup_noswitch = FALSE;
-#endif
}
break;
router resuming protocol. */
if (packet->flags & SILC_PACKET_FLAG_LIST)
break;
-#if 0
silc_server_backup_resume_router(server, sock, packet);
-#endif
break;
default:
SilcBool silc_server_init_secondary(SilcServer server)
{
- return TRUE;
-#if 0
- int sock = 0;
- SilcPacketStream newsocket = NULL;
SilcServerConfigServerInfoInterface *interface;
+ SilcNetListener listener;
for (interface = server->config->server_info->secondary; interface;
- interface = interface->next, sock++) {
-
- if (!silc_server_listen(server,
- interface->server_ip, interface->port, &sock_list[sock]))
- goto err;
-
- /* Set socket to non-blocking mode */
- silc_net_set_socket_nonblock(sock_list[sock]);
-
- /* Add ourselves also to the socket table. The entry allocated above
- is sent as argument for fast referencing in the future. */
- silc_socket_alloc(sock_list[sock],
- SILC_CONN_SERVER, NULL, &newsocket);
- server->sockets[sock_list[sock]] = newsocket;
- SILC_SET_LISTENER(newsocket);
-
- /* Perform name and address lookups to resolve the listenning address
- and port. */
- if (!silc_net_check_local_by_sock(sock_list[sock], &newsocket->hostname,
- &newsocket->ip)) {
- if ((server->config->require_reverse_lookup && !newsocket->hostname) ||
- !newsocket->ip) {
- SILC_LOG_ERROR(("IP/DNS lookup failed for local host %s",
- newsocket->hostname ? newsocket->hostname :
- newsocket->ip ? newsocket->ip : ""));
- server->stat.conn_failures++;
- goto err;
- }
- if (!newsocket->hostname)
- newsocket->hostname = strdup(newsocket->ip);
- }
- newsocket->port = silc_net_get_local_port(sock);
-
- newsocket->user_data = (void *)server->id_entry;
- silc_schedule_task_add(server->schedule, sock_list[sock],
- silc_server_accept_new_connection,
- (void *)server, 0, 0,
- SILC_TASK_FD,
- SILC_TASK_PRI_NORMAL);
+ interface = interface->next) {
+ listener = silc_server_listen(server, interface->server_ip,
+ interface->port);
+ if (!listener)
+ return FALSE;
+ silc_dlist_add(server->listeners, listener);
}
return TRUE;
-
- err:
- do silc_net_close_server(sock_list[sock--]); while (sock >= 0);
-#endif /* 0 */
- return FALSE;
}
/* Initializes the entire SILC server. This is called always before running
server->config->server_info->primary->port);
if (!listener)
goto err;
-
silc_dlist_add(server->listeners, listener);
/* Create a Server ID for the server. */
}
}
-#if 0
- /* Register the ID Cache purge task. This periodically purges the ID cache
- and removes the expired cache entries. */
-
- /* Clients local list */
- server->purge_i = purge = silc_calloc(1, sizeof(*purge));
- purge->cache = server->local_list->clients;
- purge->timeout = 600;
- silc_schedule_task_add_timeout(server->schedule, silc_idlist_purge,
- (void *)purge, purge->timeout, 0);
-
- /* Clients global list */
- server->purge_g = purge = silc_calloc(1, sizeof(*purge));
- purge->cache = server->global_list->clients;
- purge->timeout = 300;
- silc_schedule_task_add_timeout(server->schedule, silc_idlist_purge,
- (void *)purge, purge->timeout, 0);
-#endif /Ã* 0 */
-
/* If we are normal server we'll retrieve network statisticial information
once in a while from the router. */
if (server->server_type != SILC_ROUTER)
return FALSE;
}
-#if 0
/* Task callback to close a socket connection after rehash */
SILC_TASK_CALLBACK(silc_server_rehash_close_connection)
{
- SilcServer server = context;
- SilcPacketStream sock = server->sockets[fd];
+ SilcServer server = app_context;
+ SilcPacketStream sock = context;
+ SilcIDListData idata = silc_packet_get_context(sock);
+ const char *hostname;
+ SilcUInt16 port;
- if (!sock)
- return;
+ silc_socket_stream_get_info(silc_packet_stream_get_stream(sock),
+ NULL, &hostname, NULL, &port);
SILC_LOG_INFO(("Connection %s:%d [%s] is unconfigured",
- sock->hostname, sock->port,
- (sock->type == SILC_CONN_UNKNOWN ? "Unknown" :
- sock->type == SILC_CONN_CLIENT ? "Client" :
- sock->type == SILC_CONN_SERVER ? "Server" :
- "Router")));
+ hostname, port, SILC_CONNTYPE_STRING(idata->conn_type)));
silc_schedule_task_del_by_context(server->schedule, sock);
silc_server_disconnect_remote(server, sock,
SILC_STATUS_ERR_BANNED_FROM_SERVER,
"This connection is removed from "
"configuration");
- if (sock->user_data)
- silc_server_free_sock_user_data(server, sock, NULL);
+ silc_server_free_sock_user_data(server, sock, NULL);
}
-#endif /* 0 */
/* This function basically reads the config file again and switches the config
object pointed by the server object. After that, we have to fix various
SilcBool silc_server_rehash(SilcServer server)
{
-#if 0
SilcServerConfig newconfig;
SILC_LOG_INFO(("Rehashing server"));
return FALSE;
}
- /* Reinit scheduler if necessary */
- if (newconfig->param.connections_max > server->config->param.connections_max)
- if (!silc_schedule_reinit(server->schedule,
- newconfig->param.connections_max))
- return FALSE;
-
/* Fix the server_name field */
if (strcmp(server->server_name, newconfig->server_info->server_name)) {
silc_free(server->server_name);
/* Update the idcache list with a fresh pointer */
silc_free(server->id_entry->server_name);
server->id_entry->server_name = strdup(server->server_name);
- if (!silc_idcache_del_by_context(server->local_list->servers,
- server->id_entry))
- return FALSE;
- if (!silc_idcache_add(server->local_list->servers,
- strdup(server->id_entry->server_name),
- server->id_entry->id, server->id_entry, 0, NULL))
- return FALSE;
+ silc_idcache_update_by_context(server->local_list->servers,
+ server->id_entry, NULL,
+ strdup(server->id_entry->server_name),
+ TRUE);
}
/* Set logging */
server->private_key = newconfig->server_info->private_key;
newconfig->server_info->public_key = NULL;
newconfig->server_info->private_key = NULL;
-
- /* Allocate PKCS context for local public and private keys */
- silc_pkcs_free(server->pkcs);
- if (!silc_pkcs_alloc(server->public_key->name, &server->pkcs))
- return FALSE;
- silc_pkcs_public_key_set(server->pkcs, server->public_key);
- silc_pkcs_private_key_set(server->pkcs, server->private_key);
}
/* Check for unconfigured server and router connections and close
SilcPacketStream sock;
sock = silc_server_find_socket_by_host(server, SILC_CONN_ROUTER,
ptr->host, ptr->port);
- if (sock && !SILC_IS_LISTENER(sock))
- silc_schedule_task_add(server->schedule, sock->sock,
- silc_server_rehash_close_connection,
- server, 0, 1, SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
+ if (sock)
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_rehash_close_connection,
+ sock, 0, 1);
}
}
}
SilcPacketStream sock;
sock = silc_server_find_socket_by_host(server, SILC_CONN_SERVER,
ptr->host, 0);
- if (sock && !SILC_IS_LISTENER(sock))
- silc_schedule_task_add(server->schedule, sock->sock,
- silc_server_rehash_close_connection,
- server, 0, 1, SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
+ if (sock)
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_rehash_close_connection,
+ sock, 0, 1);
}
}
}
sock = silc_server_find_socket_by_host(server, SILC_CONN_CLIENT,
ptr->host, 0);
if (sock)
- silc_schedule_task_add(server->schedule, sock->sock,
- silc_server_rehash_close_connection,
- server, 0, 1, SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_rehash_close_connection,
+ sock, 0, 1);
}
}
}
#endif /* SILC_DEBUG */
SILC_LOG_DEBUG(("Server rehashed"));
-#endif /* 0 */
return TRUE;
}
unsigned char id[32];
SilcUInt32 id_len;
SilcID remote_id;
+ const char *ip;
SILC_LOG_DEBUG(("Connection authentication completed"));
silc_server_announce_channels(server, 0, SILC_PRIMARY_ROUTE(server));
}
-#if 0
/* If we are backup router then this primary router is whom we are
backing up. */
- if (server->server_type == SILC_BACKUP_ROUTER)
- silc_server_backup_add(server, server->id_entry, sock->ip,
+ if (server->server_type == SILC_BACKUP_ROUTER) {
+ silc_socket_stream_get_info(silc_packet_stream_get_stream(sconn->
+ sock),
+ NULL, NULL, &ip, NULL);
+ silc_server_backup_add(server, server->id_entry, ip,
sconn->remote_port, TRUE);
-#endif /* 0 */
+ }
} else {
/* We already have primary router. Disconnect this connection */
SILC_LOG_DEBUG(("We already have primary router, disconnect"));
silc_schedule_task_add_timeout(server->schedule, silc_server_do_rekey,
sconn->sock, sconn->rekey_timeout, 0);
-#if 0
- /* Perform keepalive. */
- silc_socket_set_heartbeat(sock, param->keepalive_secs, server,
- silc_server_perform_heartbeat,
- server->schedule);
-#endif /* 0 */
-
/* Set the entry as packet stream context */
silc_packet_set_context(sconn->sock, id_entry);
if (sconn && sconn->callback)
(*sconn->callback)(server, id_entry, sconn->callback_context);
-#if 0
/* Free the temporary connection data context */
if (sconn) {
silc_server_config_unref(&sconn->conn);
}
if (sconn == server->router_conn)
server->router_conn = NULL;
-#endif /* 0 */
silc_free(entry);
}
silc_net_is_ip(ptr->host) ?
ptr->host : NULL,
silc_net_is_ip(ptr->host) ?
- NULL : ptr->host, ptr->port)) {
+ NULL : ptr->host, ptr->port,
+ SILC_CONN_ROUTER)) {
SILC_LOG_DEBUG(("We are already connected to %s:%d",
ptr->host, ptr->port));
if (!sock)
continue;
server->backup_noswitch = TRUE;
-#if 0
- if (sock->user_data)
- silc_server_free_sock_user_data(server, sock, NULL);
+ silc_server_free_sock_user_data(server, sock, NULL);
silc_server_disconnect_remote(server, sock, 0, NULL);
-#endif /* 0 */
server->backup_noswitch = FALSE;
SILC_LOG_DEBUG(("Reconnecting to primary router"));
} else {
SilcServerConfigConnParams *param = &server->config->param;
SilcServerConnection sconn;
void *id_entry;
- const char *hostname;
+ const char *hostname, *ip;
SilcUInt16 port;
entry->op = NULL;
silc_socket_stream_get_info(silc_packet_stream_get_stream(sock),
- NULL, &hostname, NULL, &port);
+ NULL, &hostname, &ip, &port);
if (success == FALSE) {
/* Authentication failed */
/* If we are primary router and we have backup router configured
but it has not connected to use yet, do not accept any other
connection. */
-#if 0
if (server->wait_backup && server->server_type == SILC_ROUTER &&
!server->backup_router && !backup_router) {
SilcServerConfigRouter *router;
goto out;
}
}
-#endif /* 0 */
SILC_LOG_DEBUG(("Remote host is %s",
entry->data.conn_type == SILC_CONN_SERVER ?
/* Connection has been fully established now. Everything is ok. */
SILC_LOG_DEBUG(("New connection %p authenticated", sconn));
-#if 0
- /* Perform keepalive. */
- if (param->keepalive_secs)
- silc_socket_set_heartbeat(sock, param->keepalive_secs, server,
- silc_server_perform_heartbeat,
- server->schedule);
-#endif
-
/* Perform Quality of Service */
if (param->qos)
silc_socket_stream_set_qos(silc_packet_stream_get_stream(sock),
const char *signoff_message)
{
SilcIDListData idata = silc_packet_get_context(sock);
+ const char *ip;
+ SilcUInt16 port;
SILC_LOG_DEBUG(("Start"));
if (server->server_shutdown || server->backup_noswitch)
backup_router = NULL;
+ silc_socket_stream_get_info(silc_packet_stream_get_stream(sock),
+ NULL, NULL, &ip, &port);
+
/* If this was our primary router connection then we're lost to
the outside world. */
if (server->router == user_data) {
/* We stop here to take a breath */
sleep(2);
-#if 0
if (server->backup_router) {
server->server_type = SILC_ROUTER;
/* We'll need to constantly try to reconnect to the primary
router so that we'll see when it comes back online. */
- silc_server_backup_reconnect(server, sock->ip, sock->port,
+ silc_server_create_connection(server, FALSE, FALSE, ip, port,
silc_server_backup_connected,
NULL);
}
-#endif /* 0 */
/* Mark this connection as replaced */
silc_server_backup_replaced_add(server, user_data->id,
silc_free(__fmt__); \
} while(0)
-/* Check whether rekey protocol is active */
-#define SILC_SERVER_IS_REKEY(sock) \
- (sock->protocol && sock->protocol->protocol && \
- sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)
-
/* Output a message to stderr or to the appropriate log facility wether
we are in the background or not. */
#define SILC_SERVER_LOG_INFO(fmt) \
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2001 - 2005, 2007 Pekka Riikonen
+ Copyright (C) 2001 - 2007 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "server_internal.h"
SILC_TASK_CALLBACK(silc_server_protocol_backup_done);
-SILC_TASK_CALLBACK(silc_server_backup_connect_to_router);
SILC_TASK_CALLBACK(silc_server_backup_announce_watches);
static void silc_server_backup_connect_primary(SilcServer server,
SilcUInt32 sessions_count;
SilcUInt32 initiator_restart;
long start;
+ int state;
unsigned int responder : 1;
unsigned int received_failure : 1;
unsigned int timeout : 1;
SilcPacket packet)
{
SilcIDListData idata = silc_packet_get_context(sock);
+ SilcServerEntry router = (SilcServerEntry)idata;
SilcUInt8 type, session;
SilcServerBackupProtocolContext ctx;
int i, ret;
return;
}
-
/* Start the resuming protocol if requested. */
if (type == SILC_SERVER_BACKUP_START) {
/* We have received a start for resuming protocol. We are either
proto_ctx->session = session;
proto_ctx->start = time(0);
silc_packet_stream_ref(sock);
+ router->backup = TRUE;
+ router->backup_proto = proto_ctx;
SILC_LOG_DEBUG(("Starting backup resuming protocol as responder"));
SILC_LOG_INFO(("Starting backup resuming protocol"));
return;
}
-#if 0
/* Activate the shared protocol context for this socket connection
if necessary */
if (type == SILC_SERVER_BACKUP_RESUMED &&
- idata->conn_type == SILC_CONN_ROUTER && !sock->protocol &&
+ idata->conn_type == SILC_CONN_ROUTER && !router->backup &&
idata->status & SILC_IDLIST_STATUS_DISABLED) {
- SilcServerEntry backup_router;
-
- if (silc_server_backup_replaced_get(server, ((SilcServerEntry)idata)->id,
- &backup_router)) {
- SilcPacketStream bsock =
- (SilcSocketConnection)backup_router->connection;
- if (bsock->protocol && bsock->protocol->protocol &&
- bsock->protocol->protocol->type == SILC_PROTOCOL_SERVER_BACKUP) {
- sock->protocol = bsock->protocol;
- ctx = sock->protocol->context;
- if (ctx->sock)
- silc_socket_free(ctx->sock); /* unref */
- ctx->sock = silc_socket_dup(sock);
- }
- }
+ if (silc_server_backup_replaced_get(server, router->id, NULL))
+ router->backup = TRUE;
}
-
/* Call the resuming protocol if the protocol is active. */
- if (SILC_SERVER_IS_BACKUP(sock)) {
- ctx = sock->protocol->context;
+ if (router->backup) {
+ ctx = router->backup_proto;
ctx->type = type;
for (i = 0; i < ctx->sessions_count; i++) {
if (session == ctx->sessions[i].session) {
ctx->session = session;
- silc_protocol_execute(sock->protocol, server->schedule, 0, 0);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_protocol_backup,
+ ctx, 0, 1);
silc_packet_free(packet);
return;
}
/* If RESUMED received the session ID is zero, execute the protocol. */
if (type == SILC_SERVER_BACKUP_RESUMED) {
- silc_protocol_execute(sock->protocol, server->schedule, 0, 0);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_protocol_backup,
+ ctx, 0, 1);
silc_packet_free(packet);
return;
}
silc_packet_free(packet);
return;
}
-#endif /* 0 */
silc_packet_free(packet);
}
SilcServerBackupProtocolContext proto_ctx =
(SilcServerBackupProtocolContext)context;
SilcServer server = proto_ctx->server;
- SilcPacketStream sock = proto_ctx->sock;
SILC_LOG_DEBUG(("Starting backup resuming protocol as initiator"));
SILC_LOG_INFO(("Starting backup resuming protocol"));
/* Try again */
silc_schedule_task_add_timeout(server->schedule,
silc_server_backup_connected_again,
- context, 0, 0);
+ context, 0, 1);
return;
}
SilcServerEntry server_entry,
void *context)
{
-#if 0
SilcPacketStream backup_router = context;
+ SilcIDListData idata = silc_packet_get_context(backup_router);
+ SilcServerEntry router = (SilcServerEntry)idata;
SilcServerBackupProtocolContext ctx;
SilcPacketStream sock;
- SilcIDListData idata;
unsigned char data[2];
if (!server_entry) {
/* Unref */
silc_packet_stream_unref(backup_router);
- if (!backup_router->protocol)
+ if (!router->backup)
return;
if (!server_entry->connection)
return;
- ctx = (SilcServerBackupProtocolContext)backup_router->protocol->context;
- sock = (SilcSocketConnection)server_entry->connection;
+ ctx = router->backup_proto;
+ sock = server_entry->connection;
idata = (SilcIDListData)server_entry;
SILC_LOG_DEBUG(("Sending CONNECTED packet (session %d)", ctx->session));
data[0] = SILC_SERVER_BACKUP_CONNECTED;
data[1] = ctx->session;
silc_server_packet_send(server, backup_router,
- SILC_PACKET_RESUME_ROUTER, 0, data, 2, FALSE);
+ SILC_PACKET_RESUME_ROUTER, 0, data, 2);
/* The primary connection is disabled until it sends the RESUMED packet
to us. */
the primary router connection since it will send the subsequent
packets in this protocol. We don't talk with backup router
anymore. */
- sock->protocol = backup_router->protocol;
- if (ctx->sock)
- silc_socket_free(ctx->sock); /* unref */
- ctx->sock = silc_socket_dup(server_entry->connection);
- backup_router->protocol = NULL;
-#endif /* 0 */x
+ server_entry->backup = TRUE;
+ server_entry->backup_proto = ctx;
+ router->backup = FALSE;
+ router->backup_proto = NULL;
}
/* Timeout callback used by the backup router to send the ENDING packet
SILC_TASK_CALLBACK(silc_server_backup_send_resumed)
{
-#if 0
SilcServerBackupProtocolContext ctx = context;
SilcServer server = ctx->server;
unsigned char data[2];
SILC_LOG_DEBUG(("Start"));
for (i = 0; i < ctx->sessions_count; i++)
- if (ctx->sessions[i].server_entry == ctx->sock->user_data)
+ if (ctx->sessions[i].server_entry == silc_packet_get_context(ctx->sock))
ctx->session = ctx->sessions[i].session;
/* We've received all the CONNECTED packets and now we'll send the
data, sizeof(data));
/* The protocol will go to END state. */
- protocol->state = SILC_PROTOCOL_STATE_END;
-#endif /* 0 */
+ ctx->state = 250;
}
/* Backup resuming protocol. This protocol is executed when the primary
SILC_TASK_CALLBACK(silc_server_protocol_backup)
{
-#if 0
SilcServerBackupProtocolContext ctx = context;
SilcServer server = ctx->server;
- SilcServerEntry server_entry;
+ SilcServerEntry server_entry = NULL;
SilcPacketStream sock = NULL;
unsigned char data[2];
+ SilcDList list;
int i;
- if (protocol->state == SILC_PROTOCOL_STATE_UNKNOWN)
- protocol->state = SILC_PROTOCOL_STATE_START;
+ if (!ctx->state)
+ ctx->state = 1;
- switch(protocol->state) {
- case SILC_PROTOCOL_STATE_START:
+ switch(ctx->state) {
+ case 1:
if (ctx->responder == FALSE) {
/*
* Initiator (backup router)
packet will indicate to the primary router that it has been replaced
by us. For normal servers it means that we will be resigning as
being primary router shortly. */
- for (i = 0; i < server->config->param.connections_max; i++) {
- sock = server->sockets[i];
- if (!sock || !sock->user_data ||
- sock->user_data == server->id_entry ||
- (sock->type != SILC_CONN_ROUTER &&
- sock->type != SILC_CONN_SERVER))
+ list = silc_packet_engine_get_streams(server->packet_engine);
+ if (!list)
+ return;
+
+ silc_dlist_start(list);
+ while ((sock = silc_dlist_get(list))) {
+ server_entry = silc_packet_get_context(sock);
+
+ if (!server_entry || server_entry == server->id_entry ||
+ (server_entry->data.conn_type != SILC_CONN_ROUTER &&
+ server_entry->data.conn_type != SILC_CONN_SERVER))
continue;
- server_entry = sock->user_data;
if (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)
continue;
server_entry->server_name, ctx->sessions_count));
/* This connection is performing this protocol too now */
- sock->protocol = protocol;
+ server_entry->backup = TRUE;
+ server_entry->backup_proto = ctx;
data[0] = SILC_SERVER_BACKUP_START;
data[1] = ctx->sessions_count;
silc_server_packet_send(server, sock, SILC_PACKET_RESUME_ROUTER, 0,
- data, sizeof(data), FALSE);
+ data, sizeof(data));
ctx->sessions_count++;
}
+ silc_packet_engine_free_streams_list(list);
/* Announce data to the new primary to be. */
silc_server_announce_servers(server, TRUE, 0, ctx->sock);
silc_server_announce_clients(server, 0, ctx->sock);
silc_server_announce_channels(server, 0, ctx->sock);
- protocol->state++;
+ ctx->state++;
} else {
/*
SILC_CONN_ROUTER)) {
SILC_LOG_DEBUG(("Received START (session %d), reconnect to router",
ctx->session));
+ silc_packet_stream_ref(ctx->sock);
silc_server_create_connection(server, FALSE, FALSE,
primary->host, primary->port,
silc_server_backup_connect_primary,
- silc_socket_dup(ctx->sock));
+ ctx->sock);
} else {
/* Nowhere to connect just return the CONNECTED packet */
SILC_LOG_DEBUG(("Received START (session %d), send CONNECTED back",
data[1] = ctx->session;
silc_server_packet_send(server, ctx->sock,
SILC_PACKET_RESUME_ROUTER, 0,
- data, sizeof(data), FALSE);
+ data, sizeof(data));
}
/* Add this resuming session */
if (server->server_type == SILC_ROUTER &&
(!server->router ||
server->router->data.status & SILC_IDLIST_STATUS_DISABLED))
- protocol->state++;
+ ctx->state++;
else
- protocol->state = SILC_PROTOCOL_STATE_END;
+ ctx->state = 250;
}
break;
/* The ENDING is sent with timeout, and then we continue to the
END state in the protocol. */
- silc_schedule_task_add(server->schedule, 0,
- silc_server_backup_send_resumed,
- protocol, 1, 0, SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_backup_send_resumed,
+ ctx, 1, 0);
return;
} else {
/* Switch announced informations to our primary router of using the
backup router. */
silc_server_local_servers_toggle_enabled(server, TRUE);
- silc_server_update_servers_by_server(server, ctx->sock->user_data,
- server->router);
- silc_server_update_clients_by_server(server, ctx->sock->user_data,
+ silc_server_update_servers_by_server(server,
+ silc_packet_get_context(ctx->sock),
+ server->router);
+ silc_server_update_clients_by_server(server,
+ silc_packet_get_context(ctx->sock),
server->router, TRUE);
/* We as primary router now must send RESUMED packets to all servers
and routers so that they know we are back. For backup router we
send the packet last so that we give the backup as much time as
possible to deal with message routing at this critical moment. */
- for (i = 0; i < server->config->param.connections_max; i++) {
- sock = server->sockets[i];
- if (!sock || !sock->user_data ||
- sock->user_data == server->id_entry ||
- (sock->type != SILC_CONN_ROUTER &&
- sock->type != SILC_CONN_SERVER))
+ list = silc_packet_engine_get_streams(server->packet_engine);
+ if (!list)
+ return;
+
+ silc_dlist_start(list);
+ while ((sock = silc_dlist_get(list))) {
+ server_entry = silc_packet_get_context(sock);
+
+ if (!server_entry || server_entry == server->id_entry ||
+ (server_entry->data.conn_type != SILC_CONN_ROUTER &&
+ server_entry->data.conn_type != SILC_CONN_SERVER))
continue;
/* Send to backup last */
continue;
send_to_backup:
- server_entry = sock->user_data;
server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
SILC_LOG_DEBUG(("Sending RESUMED to %s", server_entry->server_name));
SILC_LOG_INFO(("Sending RESUMED to %s", server_entry->server_name));
/* This connection is performing this protocol too now */
- sock->protocol = protocol;
+ server_entry->backup = TRUE;
+ server_entry->backup_proto = ctx;
data[0] = SILC_SERVER_BACKUP_RESUMED;
data[1] = 0;
silc_server_packet_send(server, sock, SILC_PACKET_RESUME_ROUTER, 0,
- data, sizeof(data), FALSE);
+ data, sizeof(data));
}
+ silc_packet_engine_free_streams_list(list);
/* Now send the same packet to backup */
if (sock != ctx->sock) {
server->wait_backup = FALSE;
/* Announce WATCH list a little later */
- silc_schedule_task_add(server->schedule, 0,
- silc_server_backup_announce_watches,
- silc_socket_dup(ctx->sock), 4, 0,
- SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
+ silc_packet_stream_ref(ctx->sock);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_backup_announce_watches,
+ ctx->sock, 4, 0);
/* For us this is the end of this protocol. */
- if (protocol->final_callback)
- silc_protocol_execute_final(protocol, server->schedule);
- else
- silc_protocol_free(protocol);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_protocol_backup_done,
+ ctx->sock, 0, 1);
}
break;
- case SILC_PROTOCOL_STATE_END:
+ case 250:
{
/*
* Responder (backup router, servers, and remote router)
server->server_type = SILC_BACKUP_ROUTER;
/* We have now new primary router. All traffic goes there from now on. */
- router = ctx->sock->user_data;
+ router = silc_packet_get_context(ctx->sock);
if (silc_server_backup_replaced_get(server, router->id,
&backup_router)) {
server->router->server_name));
/* Protocol has ended, call the final callback */
- if (protocol->final_callback)
- silc_protocol_execute_final(protocol, server->schedule);
- else
- silc_protocol_free(protocol);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_protocol_backup_done,
+ ctx->sock, 0, 1);
}
break;
- case SILC_PROTOCOL_STATE_ERROR:
+ case 251:
/* Protocol has ended, call the final callback */
- if (protocol->final_callback)
- silc_protocol_execute_final(protocol, server->schedule);
- else
- silc_protocol_free(protocol);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_protocol_backup_done,
+ ctx->sock, 0, 1);
break;
- case SILC_PROTOCOL_STATE_FAILURE:
+ case 252:
/* Protocol has ended, call the final callback */
SILC_LOG_ERROR(("Error during backup resume: received Failure"));
ctx->received_failure = TRUE;
- if (protocol->final_callback)
- silc_protocol_execute_final(protocol, server->schedule);
- else
- silc_protocol_free(protocol);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_protocol_backup_done,
+ ctx->sock, 0, 1);
break;
- case SILC_PROTOCOL_STATE_UNKNOWN:
+ default:
break;
}
-#endif /* 0 */
}
/* Final resuming protocol completion callback */
SILC_TASK_CALLBACK(silc_server_protocol_backup_done)
{
-#if 0
SilcServerBackupProtocolContext ctx = context;
SilcServer server = ctx->server;
+ SilcDList list;
SilcServerEntry server_entry;
SilcPacketStream sock;
SilcBool error;
int i;
- silc_schedule_task_del_by_context(server->schedule, protocol);
+ silc_schedule_task_del_by_context(server->schedule, ctx);
error = ctx->error;
- if (error) {
+ if (error)
SILC_LOG_ERROR(("Error occurred during backup router resuming protcool"));
- if (server->server_type == SILC_SERVER)
- silc_schedule_task_del_by_callback(server->schedule,
- silc_server_backup_connect_to_router);
- }
if (server->server_shutdown)
return;
/* Remove this protocol from all server entries that has it */
- for (i = 0; i < server->config->param.connections_max; i++) {
- sock = server->sockets[i];
- if (!sock || !sock->user_data ||
- (sock->type != SILC_CONN_ROUTER &&
- sock->type != SILC_CONN_SERVER))
- continue;
+ list = silc_packet_engine_get_streams(server->packet_engine);
+ if (!list)
+ return;
- server_entry = sock->user_data;
+ silc_dlist_start(list);
+ while ((sock = silc_dlist_get(list))) {
+ server_entry = silc_packet_get_context(sock);
+ if (!server_entry)
+ continue;
- /* The SilcProtocol context was shared between all connections, clear
- it from all connections. */
- if (sock->protocol == protocol) {
- sock->protocol = NULL;
+ if (server_entry->data.conn_type != SILC_CONN_ROUTER &&
+ server_entry->data.conn_type != SILC_CONN_SERVER)
+ continue;
+ if (server_entry->backup_proto == ctx) {
if (error) {
if (server->server_type == SILC_SERVER &&
/* Backup router */
if (SILC_PRIMARY_ROUTE(server) == sock && server->backup_router) {
if (ctx->sock == sock) {
- silc_socket_free(sock); /* unref */
+ silc_packet_stream_unref(sock);
ctx->sock = NULL;
}
/* Restart the protocol. */
proto_ctx = silc_calloc(1, sizeof(*proto_ctx));
proto_ctx->server = server;
- proto_ctx->sock = silc_socket_dup(sock);
+ proto_ctx->sock = sock;
proto_ctx->responder = FALSE;
proto_ctx->type = SILC_SERVER_BACKUP_START;
proto_ctx->start = time(0);
proto_ctx->initiator_restart = ctx->initiator_restart + 1;
/* Start through scheduler */
- silc_schedule_task_add(server->schedule, 0,
- silc_server_backup_connected_later,
- proto_ctx, 5, 0,
- SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_backup_connected_later,
+ proto_ctx, 5, 0);
} else {
/* If failure was received, switch back to normal backup router.
For some reason primary wouldn't accept that we were supposed
silc_server_local_servers_toggle_enabled(server, FALSE);
server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
silc_server_update_servers_by_server(server, server->id_entry,
- sock->user_data);
+ silc_packet_get_context(sock));
silc_server_update_clients_by_server(server, NULL,
- sock->user_data, TRUE);
+ silc_packet_get_context(sock),
+ TRUE);
/* Announce our clients and channels to the router */
silc_server_announce_clients(server, 0, sock);
silc_server_announce_channels(server, 0, sock);
/* Announce WATCH list a little later */
- silc_schedule_task_add(server->schedule, 0,
- silc_server_backup_announce_watches,
- silc_socket_dup(sock), 5, 0,
- SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_backup_announce_watches,
+ sock, 5, 0);
}
continue;
server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
}
}
+ silc_packet_engine_free_streams_list(list);
if (!error) {
SILC_LOG_INFO(("Backup resuming protocol ended successfully"));
silc_server_announce_channels(server, 0, server->router->connection);
/* Announce WATCH list a little later */
- silc_schedule_task_add(server->schedule, 0,
- silc_server_backup_announce_watches,
- silc_socket_dup(server->router->connection), 4, 0,
- SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_backup_announce_watches,
+ server->router->connection, 4, 0);
}
} else {
/* Error */
FALSE);
/* Check couple of times same START_USE just in case. */
- silc_schedule_task_add(server->schedule, 0,
- silc_server_backup_check_status,
- silc_socket_dup(server->router->connection),
- 5, 1, SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
- silc_schedule_task_add(server->schedule, 0,
- silc_server_backup_check_status,
- silc_socket_dup(server->router->connection),
- 20, 1, SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
- silc_schedule_task_add(server->schedule, 0,
- silc_server_backup_check_status,
- silc_socket_dup(server->router->connection),
- 60, 1, SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_backup_check_status,
+ server->router->connection,
+ 5, 1);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_backup_check_status,
+ server->router->connection,
+ 20, 1);
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_backup_check_status,
+ server->router->connection,
+ 60, 1);
}
}
}
- if (ctx->sock && ctx->sock->protocol)
- ctx->sock->protocol = NULL;
if (ctx->sock)
- silc_socket_free(ctx->sock); /* unref */
- silc_protocol_free(protocol);
+ silc_packet_stream_unref(ctx->sock);
silc_free(ctx->sessions);
silc_free(ctx);
-#endif /* 0 */
}
SILC_TASK_CALLBACK(silc_server_backup_announce_watches)
{
-#if 0
SilcPacketStream sock = context;
SilcServer server = app_context;
- if (sock->users > 1)
+ if (silc_packet_stream_is_valid(sock))
silc_server_announce_watches(server, sock);
- silc_socket_free(sock);
-#endif /* 0 */
+ silc_packet_stream_unref(sock);
}
/* Pending command queue */
SilcDList pending_commands;
- /* Purge context for disconnected clients */
- SilcIDListPurge purge_i;
- SilcIDListPurge purge_g;
-
unsigned int server_type : 2; /* Server type (server.h) */
unsigned int standalone : 1; /* Set if server is standalone, and
does not have connection to network. */
if (!server_entry) {
/* Connecting failed */
+ SilcConnectionType type = (server->server_type == SILC_ROUTER ?
+ SILC_CONN_SERVER : SILC_CONN_ROUTER);
if (query->dynamic_prim /* && @serv != prim.host.name */ &&
!silc_server_num_sockets_by_remote(server, query->nick_server,
- query->nick_server, 706)) {
+ query->nick_server, 706, type)) {
/* Connection attempt to primary router failed, now try to the one
specified in nick@server. */
silc_server_create_connection(server, FALSE, TRUE, query->nick_server,
/* Check if router sent error reply */
if (cmdr && !silc_command_get_status(cmdr->payload, NULL, NULL)) {
SilcBuffer buffer;
+ SilcConnectionType type = (server->server_type == SILC_ROUTER ?
+ SILC_CONN_SERVER : SILC_CONN_ROUTER);
/* If this was nick@server query, retry to @serv if the primary router
returned error. */
if (query->nick_server[0] && !query->dynamic_retry &&
!silc_server_num_sockets_by_remote(server, query->nick_server,
- query->nick_server, 1334)) {
+ query->nick_server, 1334, type)) {
SILC_LOG_DEBUG(("Retry query by connecting to %s:%d",
query->nick_server, 706));
silc_server_create_connection(server, FALSE, TRUE, query->nick_server,
/* If primary router is specified, use that. Otherwise connect
to the server in nick@server string. */
SilcServerConfigRouter *router;
+ SilcConnectionType type = (server->server_type == SILC_ROUTER ?
+ SILC_CONN_SERVER : SILC_CONN_ROUTER);
router = silc_server_config_get_primary_router(server);
if (router && server->standalone) {
} else if (!silc_server_num_sockets_by_remote(server,
query->nick_server,
query->nick_server,
- 706)) {
+ 706, type)) {
/* Create connection and handle the query after connection */
SILC_LOG_DEBUG(("Create dynamic connection to %s:%d",
query->nick_server, 706));
SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server,
const char *ip,
const char *hostname,
- SilcUInt16 port)
+ SilcUInt16 port,
+ SilcConnectionType type)
{
SilcServerConnection conn;
+ SilcIDListData idata;
+ SilcConnectionType t = SILC_CONN_UNKNOWN;
int count = 0;
if (!ip && !hostname)
silc_dlist_start(server->conns);
while ((conn = silc_dlist_get(server->conns))) {
+ if (conn->sock) {
+ idata = silc_packet_get_context(conn->sock);
+ if (idata)
+ t = idata->conn_type;
+ }
if (((ip && !strcmp(conn->remote_host, ip)) ||
(hostname && !strcmp(conn->remote_host, hostname))) &&
- conn->remote_port == port)
+ conn->remote_port == port && t == type)
count++;
}
SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server,
const char *ip,
const char *hostname,
- SilcUInt16 port);
+ SilcUInt16 port,
+ SilcConnectionType type);
/* Get public key by key usage and key context. */
SilcPublicKey silc_server_get_public_key(SilcServer server,
SilcPublicKey public_key;
SilcSKR skr = *auth_data;
SilcSKRFind find;
- SilcSKRStatus status;
+ SilcSKRStatus status = SILC_SKR_NOT_FOUND;
if (!silc_pkcs_load_public_key(p, &public_key)) {
SILC_SERVER_LOG_ERROR(("Error while parsing config file: "
find = silc_skr_find_alloc();
silc_skr_find_set_public_key(find, public_key);
silc_skr_find_set_usage(find, usage);
- silc_skr_find_set_context(find, key_context ? key_context : (void *)usage);
+ if (!key_context)
+ silc_skr_find_set_context(find, SILC_32_TO_PTR(usage));
silc_skr_find(skr, NULL, find, my_find_callback, &status);
- if (status == SILC_SKR_ALREADY_EXIST) {
+ if (status == SILC_SKR_OK) {
+ /* Already added, ignore error */
silc_pkcs_public_key_free(public_key);
- SILC_SERVER_LOG_WARNING(("Warning: public key file \"%s\" already "
- "configured, ignoring this key", p));
- return TRUE; /* non fatal error */
+ return TRUE;
}
/* Add the public key to repository */
- if (silc_skr_add_public_key(skr, public_key, usage,
- key_context ? key_context : (void *)usage,
- NULL) != SILC_SKR_OK) {
+ status = silc_skr_add_public_key(skr, public_key, usage,
+ key_context ? key_context :
+ (void *)usage, NULL);
+ if (status != SILC_SKR_OK) {
SILC_SERVER_LOG_ERROR(("Error while adding public key \"%s\"", p));
return FALSE;
}
SilcUInt16 port;
SilcSocket sock;
SilcIDListData idata = silc_packet_get_context(s);
- if (!silc_socket_stream_get_info(silc_packet_stream_get_stream(s),
+ if (!silc_socket_stream_get_info(silc_packet_stream_get_stream(s),
&sock, &hostname, &ip, &port))
continue;
fprintf(fdd, " %d: host %s ip %s port %d type %d\n",
{ 15, "*silcd*,*serverid*,silc_server_*,*idlist*" },
/* All from silcd/ and basic stuff from libs */
- { 20, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcauth*,*silcske*" },
+ { 20, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcconauth*,*silcske*" },
/* All from silcd/ and more stuff from libs */
- { 25, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcauth*,"
+ { 25, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcconauth*,"
"*silcpacket*,*ske*,*silcrng*" },
/* All from silcd/ and even more stuff from libs */
- { 30, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcauth*,"
+ { 30, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcconauth*,"
"*silcpacket*,*ske*,*silcrng*,*command*,*channel*,*private*,*notify*" },
/* All from silcd/ and even more stuff from libs + all from silccore */
- { 35, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcauth*,"
+ { 35, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcconauth*,"
"*silcpacket*,*ske*,*silcrng*,*command*,*channel*,*private*,*notify*"
"*silcid*,*argument*" },
/* All from silcd/, all from silccore, silccrypt and silcmath */
- { 40, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcauth*,"
+ { 40, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcconauth*,"
"*silcpacket*,*ske*,*silcrng*,*command*,*channel*,*private*,*notify*"
"*silcid*,*argument*,*pkcs*,*hmac*,*hash*,*cipher*,silc_math*" },
/* All from silcd/, all from silccore, silccrypt and silcmath + stuff
from silcutil */
- { 45, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcauth*,"
+ { 45, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcconauth*,"
"*silcpacket*,*ske*,*silcrng*,*command*,*channel*,*private*,*notify*"
"*silcid*,*argument*,*pkcs*,*hmac*,*hash*,*cipher*,silc_math*,*sim*"
"*sockconn*" },
/* All from silcd/, all from silccore, silccrypt and silcmath + more stuff
from silcutil */
- { 50, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcauth*,"
+ { 50, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcconauth*,"
"*silcpacket*,*ske*,*silcrng*,*command*,*channel*,*private*,*notify*"
"*silcid*,*argument*,*pkcs*,*hmac*,*hash*,*cipher*,silc_math*,*sim*"
"*sockconn*,*net*" },
/* All from silcd/, all from silccore, silccrypt and silcmath + more stuff
from silcutil */
- { 55, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcauth*,"
+ { 55, "*silcd*,*serverid*,silc_server_*,*idlist*,*silcconauth*,"
"*silcpacket*,*ske*,*silcrng*,*command*,*channel*,*private*,*notify*"
"*silcid*,*argument*,*pkcs*,*hmac*,*hash*,*cipher*,silc_math*,*sim*"
"*sockconn*,*net*,*log*,*config*" },