SILC_TASK_CALLBACK(silc_server_rehash_close_connection);
SILC_TASK_CALLBACK(silc_server_connect_to_router_retry);
SILC_TASK_CALLBACK(silc_server_connect_router);
-SILC_TASK_CALLBACK(silc_server_connect_to_router);
SILC_TASK_CALLBACK(silc_server_connect_to_router_second);
SILC_TASK_CALLBACK(silc_server_connect_to_router_final);
SILC_TASK_CALLBACK(silc_server_accept_new_connection);
server to do authentication and key exchange with our router - called
from schedule. */
-SILC_TASK_CALLBACK(silc_server_connect_to_router)
+SILC_TASK_CALLBACK_GLOBAL(silc_server_connect_to_router)
{
SilcServer server = (SilcServer)context;
SilcServerConnection sconn;
else
silc_server_free_sock_user_data(server, sock, NULL);
} else if (server->router_conn && server->router_conn->sock == sock &&
- !server->router && server->standalone)
+ !server->router && server->standalone)
silc_schedule_task_add(server->schedule, 0,
silc_server_connect_to_router,
server, 1, 0,
if (!sock->user_data) {
/* If any protocol is active cancel its execution. It will call
the final callback which will finalize the disconnection. */
- if (sock->protocol) {
+ if (sock->protocol && sock->protocol->protocol &&
+ sock->protocol->protocol->type != SILC_PROTOCOL_SERVER_BACKUP) {
SILC_LOG_DEBUG(("Cancelling protocol, calling final callback"));
silc_protocol_cancel(sock->protocol, server->schedule);
sock->protocol->state = SILC_PROTOCOL_STATE_ERROR;
}
/* If any protocol is active cancel its execution */
- if (sock->protocol) {
+ if (sock->protocol && sock->protocol->protocol &&
+ sock->protocol->protocol->type != SILC_PROTOCOL_SERVER_BACKUP) {
SILC_LOG_DEBUG(("Cancelling protocol, calling final callback"));
silc_protocol_cancel(sock->protocol, server->schedule);
sock->protocol->state = SILC_PROTOCOL_STATE_ERROR;
/* If we have protocol active we must assure that we call the protocol's
final callback so that all the memory is freed. */
- if (sock->protocol) {
+ if (sock->protocol && sock->protocol->protocol &&
+ sock->protocol->protocol->type != SILC_PROTOCOL_SERVER_BACKUP) {
protocol = sock->protocol->protocol->type;
silc_protocol_cancel(sock->protocol, server->schedule);
sock->protocol->state = SILC_PROTOCOL_STATE_ERROR;
}
}
+SILC_TASK_CALLBACK(silc_server_backup_timeout)
+{
+ SilcProtocol protocol = context;
+ SilcServer server = app_context;
+
+ SILC_LOG_INFO(("Timeout occurred during backup resuming protocol"));
+ silc_protocol_cancel(protocol, server->schedule);
+ protocol->state = SILC_PROTOCOL_STATE_ERROR;
+ silc_protocol_execute_final(protocol, server->schedule);
+}
+
/* Processes incoming RESUME_ROUTER packet. This can give the packet
for processing to the protocol handler or allocate new protocol if
start command is received. */
&sock->protocol, proto_ctx,
silc_server_protocol_backup_done);
silc_protocol_execute(sock->protocol, server->schedule, 0, 0);
+ silc_schedule_task_add(server->schedule, sock->sock,
+ silc_server_backup_timeout,
+ sock->protocol, 30, 0, SILC_TASK_TIMEOUT,
+ SILC_TASK_PRI_NORMAL);
}
}
&sock->protocol, proto_ctx,
silc_server_protocol_backup_done);
silc_protocol_execute(sock->protocol, server->schedule, 0, 0);
+
+ silc_schedule_task_add(server->schedule, sock->sock,
+ silc_server_backup_timeout,
+ sock->protocol, 30, 0, SILC_TASK_TIMEOUT,
+ SILC_TASK_PRI_NORMAL);
}
/* Called when we've established connection back to our primary router
SilcIDCacheList list;
SilcIDCacheEntry id_cache;
+ silc_schedule_task_del_by_context(server->schedule, protocol);
+
if (protocol->state == SILC_PROTOCOL_STATE_ERROR ||
protocol->state == SILC_PROTOCOL_STATE_FAILURE) {
SILC_LOG_ERROR(("Error occurred during backup router resuming protcool"));
if (sock->protocol == protocol) {
sock->protocol = NULL;
+ /* Backup closes connection and reconnects if error occurred */
+ if (SILC_PRIMARY_ROUTE(server) == sock && server->backup_router) {
+ if (protocol->state == SILC_PROTOCOL_STATE_ERROR ||
+ protocol->state == SILC_PROTOCOL_STATE_FAILURE) {
+ server->backup_noswitch = TRUE;
+ server->server_type = SILC_BACKUP_ROUTER;
+
+ if (sock->user_data)
+ silc_server_free_sock_user_data(server, sock, NULL);
+ silc_server_close_connection(server, sock);
+
+ silc_schedule_task_add(server->schedule, 0,
+ silc_server_connect_to_router,
+ server, 1, 0,
+ SILC_TASK_TIMEOUT,
+ SILC_TASK_PRI_NORMAL);
+
+ if (!silc_idcache_list_next(list, &id_cache))
+ break;
+ continue;
+ }
+ }
+
if (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)
server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
}
if (sock->protocol == protocol) {
sock->protocol = NULL;
+ /* Backup closes connection and reconnects if error occurred */
+ if (SILC_PRIMARY_ROUTE(server) == sock && server->backup_router) {
+ if (protocol->state == SILC_PROTOCOL_STATE_ERROR ||
+ protocol->state == SILC_PROTOCOL_STATE_FAILURE) {
+ server->backup_noswitch = TRUE;
+ server->server_type = SILC_BACKUP_ROUTER;
+
+ if (sock->user_data)
+ silc_server_free_sock_user_data(server, sock, NULL);
+ silc_server_close_connection(server, sock);
+
+ silc_schedule_task_add(server->schedule, 0,
+ silc_server_connect_to_router,
+ server, 1, 0,
+ SILC_TASK_TIMEOUT,
+ SILC_TASK_PRI_NORMAL);
+
+ if (!silc_idcache_list_next(list, &id_cache))
+ break;
+ continue;
+ }
+ }
+
if (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)
server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
}
silc_idcache_list_free(list);
}
- SILC_LOG_INFO(("Backup resuming protocol ended successfully"));
+ if (protocol->state != SILC_PROTOCOL_STATE_ERROR &&
+ protocol->state != SILC_PROTOCOL_STATE_FAILURE)
+ SILC_LOG_INFO(("Backup resuming protocol ended successfully"));
if (ctx->sock->protocol)
ctx->sock->protocol = NULL;