- SILC_LOG_DEBUG(("Connection to router %s:%d established", sconn->remote_host,
- sconn->remote_port));
-
- /* Continue with key exchange protocol */
- silc_server_start_key_exchange(server, sconn, sock);
-}
-
-
-/* Timeout task callback to connect to remote router */
-
-SILC_TASK_CALLBACK(silc_server_backup_connect_to_router)
-{
- SilcServer server = app_context;
- SilcServerConnection sconn = (SilcServerConnection)context;
- int sock;
- const char *server_ip;
-
- SILC_LOG_DEBUG(("Connecting to router %s:%d", sconn->remote_host,
- sconn->remote_port));
-
- /* Connect to remote host */
- server_ip = server->config->server_info->primary == NULL ? NULL :
- server->config->server_info->primary->server_ip;
- sock = silc_net_create_connection_async(server_ip, sconn->remote_port,
- sconn->remote_host);
- if (sock < 0) {
- if (server->server_type == SILC_SERVER) {
- sconn->retry_count++;
- if (sconn->retry_count > 3) {
- silc_free(sconn->remote_host);
- silc_free(sconn);
- return;
- }
- }
- silc_schedule_task_add(server->schedule, 0,
- silc_server_backup_connect_to_router,
- context, 10, 0, SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);
- return;
- }
-
- /* wait for the connection to be established */
- silc_schedule_task_add(server->schedule, sock,
- silc_server_backup_connection_established,
- context, 0, 0, SILC_TASK_FD,
- SILC_TASK_PRI_NORMAL);
- silc_schedule_set_listen_fd(server->schedule, sock,
- SILC_TASK_WRITE, FALSE);
-}
-
-/* Constantly tries to reconnect to a primary router indicated by the
- `ip' and `port'. The `connected' callback will be called when the
- connection is created. */
-
-void silc_server_backup_reconnect(SilcServer server,
- const char *ip, SilcUInt16 port,
- SilcServerConnectRouterCallback callback,
- void *context)
-{
- SilcServerConnection sconn;
-
- SILC_LOG_INFO(("Attempting to reconnect to primary router"));
-
- sconn = silc_calloc(1, sizeof(*sconn));
- sconn->remote_host = strdup(ip);
- sconn->remote_port = port;
- sconn->callback = callback;
- sconn->callback_context = context;
- sconn->no_reconnect = TRUE;
- sconn->retry_count = 0;
- silc_schedule_task_add(server->schedule, 0,
- silc_server_backup_connect_to_router,
- sconn, 1, 0, SILC_TASK_TIMEOUT,
- SILC_TASK_PRI_NORMAL);