- /* Initiator of the protocol. We are backup router */
-
- packet = silc_buffer_alloc(2);
- silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
-
- /* Send the START packet to primary router and normal servers. */
- if (silc_idcache_get_all(server->local_list->servers, &list)) {
- if (silc_idcache_list_first(list, &id_cache)) {
- while (id_cache) {
- server_entry = (SilcServerEntry)id_cache->context;
- if (!server_entry || (server_entry == server->id_entry) ||
- !server_entry->connection || !server_entry->data.send_key ||
- (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)) {
- if (!silc_idcache_list_next(list, &id_cache))
- break;
- else
- continue;
- }
-
- ctx->sessions = silc_realloc(ctx->sessions,
- sizeof(*ctx->sessions) *
- (ctx->sessions_count + 1));
- ctx->sessions[ctx->sessions_count].session = ctx->sessions_count;
- ctx->sessions[ctx->sessions_count].connected = FALSE;
- ctx->sessions[ctx->sessions_count].server_entry = server_entry;
-
- SILC_LOG_DEBUG(("Sending START to %s (session %d)",
- server_entry->server_name, ctx->sessions_count));
-
- /* This connection is performing this protocol too now */
- ((SilcSocketConnection)server_entry->connection)->protocol =
- protocol;
-
- if (server_entry->server_type == SILC_ROUTER)
- packet->data[0] = SILC_SERVER_BACKUP_START;
- else
- packet->data[0] = SILC_SERVER_BACKUP_START_GLOBAL;
- packet->data[1] = ctx->sessions_count;
- silc_server_packet_send(server, server_entry->connection,
- SILC_PACKET_RESUME_ROUTER, 0,
- packet->data, packet->len, FALSE);
- ctx->sessions_count++;
-
- if (!silc_idcache_list_next(list, &id_cache))
- break;
- }
- }
-
- silc_idcache_list_free(list);
- }
-
- if (silc_idcache_get_all(server->global_list->servers, &list)) {
- if (silc_idcache_list_first(list, &id_cache)) {
- while (id_cache) {
- server_entry = (SilcServerEntry)id_cache->context;
- if (!server_entry || (server_entry == server->id_entry) ||
- !server_entry->connection || !server_entry->data.send_key ||
- (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)) {
- if (!silc_idcache_list_next(list, &id_cache))
- break;
- else
- continue;
- }
-
- ctx->sessions = silc_realloc(ctx->sessions,
- sizeof(*ctx->sessions) *
- (ctx->sessions_count + 1));
- ctx->sessions[ctx->sessions_count].session = ctx->sessions_count;
- ctx->sessions[ctx->sessions_count].connected = FALSE;
- ctx->sessions[ctx->sessions_count].server_entry = server_entry;
-
- SILC_LOG_DEBUG(("Sending START to %s (session %d)",
- server_entry->server_name, ctx->sessions_count));
-
- /* This connection is performing this protocol too now */
- ((SilcSocketConnection)server_entry->connection)->protocol =
- protocol;
-
- if (server_entry->server_type == SILC_ROUTER)
- packet->data[0] = SILC_SERVER_BACKUP_START;
- else
- packet->data[0] = SILC_SERVER_BACKUP_START_GLOBAL;
- packet->data[1] = ctx->sessions_count;
- silc_server_packet_send(server, server_entry->connection,
- SILC_PACKET_RESUME_ROUTER, 0,
- packet->data, packet->len, FALSE);
- ctx->sessions_count++;
-
- if (!silc_idcache_list_next(list, &id_cache))
- break;
- }
- }
-
- silc_idcache_list_free(list);
+ /*
+ * Initiator (backup router)
+ */
+
+ /* Send the START packet to primary router and normal servers. The
+ 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. */
+ 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;
+
+ if (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)
+ continue;
+
+ ctx->sessions = silc_realloc(ctx->sessions,
+ sizeof(*ctx->sessions) *
+ (ctx->sessions_count + 1));
+ ctx->sessions[ctx->sessions_count].session = ctx->sessions_count;
+ ctx->sessions[ctx->sessions_count].connected = FALSE;
+ ctx->sessions[ctx->sessions_count].server_entry = server_entry;
+
+ SILC_LOG_DEBUG(("Sending START to %s (session %d)",
+ server_entry->server_name, ctx->sessions_count));
+ SILC_LOG_INFO(("Expecting CONNECTED from %s (session %d)",
+ server_entry->server_name, ctx->sessions_count));
+
+ /* This connection is performing this protocol too now */
+ 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));
+ ctx->sessions_count++;