More Toolkit porint for SILC Server 1.1.
authorPekka Riikonen <priikone@silcnet.org>
Sun, 1 Jul 2007 16:06:56 +0000 (16:06 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 1 Jul 2007 16:06:56 +0000 (16:06 +0000)
CHANGES
apps/silcd/command.c
apps/silcd/idlist.c
apps/silcd/packet_receive.c
apps/silcd/server.c
apps/silcd/server_backup.c
apps/silcd/server_util.c
apps/silcd/serverconfig.c
apps/silcd/silcd.c

diff --git a/CHANGES b/CHANGES
index 6aba7dfceb3bd058a2c8b0ee5124fbf17de04bfd..c772f64760a77dfc74109967323f3654182e7b7c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,9 @@ Sun Jul  1 12:40:06 EEST 2007  Pekka Riikonen <priikone@silcnet.org>
          Affected files are lib/silccore/silcnotify.c and
          silcargument.c.
 
+       * Fixed SILC_PACKET_FLAG_LONG_PAD bitmask value.  Affected
+         file lib/silccore/silcpacket.h.
+
 Sat Jun 30 21:48:08 EEST 2007  Pekka Riikonen <priikone@silcnet.org>
 
        * Set the destination ID to packet stream as SKE responder
index 49e436bf4bcee6304d549c96cd36583087abc057..12b5ce26236161276a37e780c79a47e9cfa6d1b1 100644 (file)
@@ -2465,10 +2465,22 @@ SILC_SERVER_CMD_FUNC(join)
          channel = silc_server_create_new_channel(server, server->id, cipher,
                                                   hmac, channel_name, TRUE);
          if (!channel) {
-           silc_server_command_send_status_data(
-                                 cmd, SILC_COMMAND_JOIN,
-                                 SILC_STATUS_ERR_UNKNOWN_ALGORITHM,
-                                 0, 2, cipher, strlen(cipher));
+           if (cipher) {
+             silc_server_command_send_status_data(
+                               cmd, SILC_COMMAND_JOIN,
+                               SILC_STATUS_ERR_UNKNOWN_ALGORITHM,
+                               0, 2, cipher, strlen(cipher));
+           } else if (hmac) {
+             silc_server_command_send_status_data(
+                               cmd, SILC_COMMAND_JOIN,
+                               SILC_STATUS_ERR_UNKNOWN_ALGORITHM,
+                               0, 2, hmac, strlen(hmac));
+           } else {
+             silc_server_command_send_status_reply(
+                               cmd, SILC_COMMAND_JOIN,
+                               SILC_STATUS_ERR_RESOURCE_LIMIT,
+                               0);
+           }
            goto out;
          }
 
@@ -2524,10 +2536,22 @@ SILC_SERVER_CMD_FUNC(join)
          channel = silc_server_create_new_channel(server, server->id, cipher,
                                                   hmac, channel_name, TRUE);
          if (!channel) {
-           silc_server_command_send_status_data(
-                                      cmd, SILC_COMMAND_JOIN,
-                                      SILC_STATUS_ERR_UNKNOWN_ALGORITHM, 0,
-                                      2, cipher, strlen(cipher));
+           if (cipher) {
+             silc_server_command_send_status_data(
+                                     cmd, SILC_COMMAND_JOIN,
+                                     SILC_STATUS_ERR_UNKNOWN_ALGORITHM,
+                                     0, 2, cipher, strlen(cipher));
+           } else if (hmac) {
+             silc_server_command_send_status_data(
+                                     cmd, SILC_COMMAND_JOIN,
+                                     SILC_STATUS_ERR_UNKNOWN_ALGORITHM,
+                                     0, 2, hmac, strlen(hmac));
+           } else {
+             silc_server_command_send_status_reply(
+                                     cmd, SILC_COMMAND_JOIN,
+                                     SILC_STATUS_ERR_RESOURCE_LIMIT,
+                                     0);
+           }
            goto out;
          }
 
@@ -2557,10 +2581,22 @@ SILC_SERVER_CMD_FUNC(join)
        channel = silc_server_create_new_channel(server, server->id, cipher,
                                                 hmac, channel_name, TRUE);
        if (!channel) {
-         silc_server_command_send_status_data(
-                                      cmd, SILC_COMMAND_JOIN,
-                                      SILC_STATUS_ERR_UNKNOWN_ALGORITHM, 0,
-                                      2, cipher, strlen(cipher));
+         if (cipher) {
+           silc_server_command_send_status_data(
+                                     cmd, SILC_COMMAND_JOIN,
+                                     SILC_STATUS_ERR_UNKNOWN_ALGORITHM,
+                                     0, 2, cipher, strlen(cipher));
+         } else if (hmac) {
+           silc_server_command_send_status_data(
+                                     cmd, SILC_COMMAND_JOIN,
+                                     SILC_STATUS_ERR_UNKNOWN_ALGORITHM,
+                                     0, 2, hmac, strlen(hmac));
+         } else {
+           silc_server_command_send_status_reply(
+                                     cmd, SILC_COMMAND_JOIN,
+                                     SILC_STATUS_ERR_RESOURCE_LIMIT,
+                                     0);
+         }
          goto out;
        }
 
@@ -4464,7 +4500,7 @@ SILC_SERVER_CMD_FUNC(silcoper)
   username = silc_identifier_check(username, tmp_len, SILC_STRING_UTF8, 128,
                                   &tmp_len);
   if (!username) {
-    silc_server_command_send_status_reply(cmd, SILC_COMMAND_OPER,
+    silc_server_command_send_status_reply(cmd, SILC_COMMAND_SILCOPER,
                                          SILC_STATUS_ERR_BAD_USERNAME,
                                          0);
     goto out;
@@ -4513,7 +4549,7 @@ SILC_SERVER_CMD_FUNC(silcoper)
   }
   if (!result) {
     /* Authentication failed */
-    silc_server_command_send_status_reply(cmd, SILC_COMMAND_OPER,
+    silc_server_command_send_status_reply(cmd, SILC_COMMAND_SILCOPER,
                                          SILC_STATUS_ERR_AUTH_FAILED, 0);
     goto out;
   }
index a29ba9fb1f9a1817e182917437ef706ab71f511b..e302b6e6bf3ddfed204cdd7fee49e633c4dff14e 100644 (file)
@@ -558,18 +558,17 @@ silc_idlist_replace_client_id(SilcServer server,
 
   client = (SilcClientEntry)id_cache->context;
 
-  /* Remove the old entry and add a new one */
-
-  if (!silc_idcache_del_by_context(id_list->clients, client, server))
-    return NULL;
-
   /* Check if anyone is watching old nickname */
   if (server->server_type == SILC_ROUTER)
     silc_server_check_watcher_list(server, client, nickname,
                                   SILC_NOTIFY_TYPE_NICK_CHANGE);
 
+  /* Replace */
+  if (!silc_idcache_update(id_list->clients, id_cache, new_id, nicknamec,
+                          TRUE))
+    return NULL;
+
   silc_free(client->nickname);
-  *client->id = *new_id;
   client->nickname = nickname ? strdup(nickname) : NULL;
 
   /* Check if anyone is watching new nickname */
@@ -577,10 +576,6 @@ silc_idlist_replace_client_id(SilcServer server,
     silc_server_check_watcher_list(server, client, nickname,
                                   SILC_NOTIFY_TYPE_NICK_CHANGE);
 
-  if (!silc_idcache_add(id_list->clients, nicknamec, client->id,
-                       client))
-    return NULL;
-
   SILC_LOG_DEBUG(("Replaced"));
 
   return client;
index 04eeb0d32938ec5eb2c9c8cdf9714a295a0ff408..9b990ff8d5fb587bec5a973171ec2e7400e9fd1d 100644 (file)
@@ -46,8 +46,17 @@ static void silc_server_notify_process(SilcServer server,
   SilcUInt32 tmp_len, tmp2_len;
   SilcBool local, ret;
 
-  if (idata->conn_type == SILC_CONN_CLIENT ||
-      packet->src_id_type != SILC_ID_SERVER || !packet->dst_id) {
+  if (idata->conn_type == SILC_CONN_CLIENT) {
+    SILC_LOG_DEBUG(("Notify received from client, drop it"));
+    return;
+  }
+
+  if (packet->src_id_type != SILC_ID_SERVER){
+    SILC_LOG_DEBUG(("Bad notify packet received"));
+    return;
+  }
+
+  if (!packet->dst_id) {
     SILC_LOG_DEBUG(("Bad notify packet received"));
     return;
   }
@@ -69,8 +78,10 @@ static void silc_server_notify_process(SilcServer server,
 
   /* Parse the Notify Payload */
   payload = silc_notify_payload_parse(buffer->data, silc_buffer_len(buffer));
-  if (!payload)
+  if (!payload) {
+    SILC_LOG_DEBUG(("Marlformed notify payload"));
     return;
+  }
 
   /* If we are router and this packet is not already broadcast packet
      we will broadcast it. The sending socket really cannot be router or
@@ -84,8 +95,10 @@ static void silc_server_notify_process(SilcServer server,
       /* Packet is destined to channel */
       if (!silc_id_str2id(packet->dst_id, packet->dst_id_len,
                          packet->dst_id_type, &channel_id,
-                         sizeof(channel_id)))
+                         sizeof(channel_id))) {
+       SILC_LOG_DEBUG(("Malformed destination ID in notify packet"));
        goto out;
+      }
 
       silc_server_packet_send_dest(server, SILC_PRIMARY_ROUTE(server),
                                   packet->type, packet->flags |
@@ -112,8 +125,10 @@ static void silc_server_notify_process(SilcServer server,
 
   type = silc_notify_get_type(payload);
   args = silc_notify_get_args(payload);
-  if (!args)
+  if (!args) {
+    SILC_LOG_DEBUG(("Notify doesn't have any arguments, drop it"));
     goto out;
+  }
 
   switch(type) {
   case SILC_NOTIFY_TYPE_JOIN:
@@ -133,7 +148,8 @@ static void silc_server_notify_process(SilcServer server,
       channel = silc_idlist_find_channel_by_id(server->local_list,
                                               SILC_ID_GET_ID(id), NULL);
       if (!channel) {
-       SILC_LOG_DEBUG(("Notify for unknown channel"));
+       SILC_LOG_DEBUG(("Notify for unknown channel %s",
+                       silc_id_render(SILC_ID_GET_ID(id), SILC_ID_CHANNEL)));
        goto out;
       }
     }
@@ -251,7 +267,8 @@ static void silc_server_notify_process(SilcServer server,
       channel = silc_idlist_find_channel_by_id(server->local_list,
                                               &channel_id, NULL);
       if (!channel) {
-       SILC_LOG_DEBUG(("Notify for unknown channel"));
+       SILC_LOG_DEBUG(("Notify for unknown channel %s",
+                       silc_id_render(&channel_id, SILC_ID_CHANNEL)));
        goto out;
       }
     }
@@ -383,7 +400,8 @@ static void silc_server_notify_process(SilcServer server,
       channel = silc_idlist_find_channel_by_id(server->local_list,
                                               &channel_id, NULL);
       if (!channel) {
-       SILC_LOG_DEBUG(("Notify for unknown channel"));
+       SILC_LOG_DEBUG(("Notify for unknown channel %s",
+                       silc_id_render(&channel_id, SILC_ID_CHANNEL)));
        goto out;
       }
     }
@@ -503,7 +521,8 @@ static void silc_server_notify_process(SilcServer server,
       channel = silc_idlist_find_channel_by_id(server->local_list,
                                               &channel_id, NULL);
       if (!channel) {
-       SILC_LOG_DEBUG(("Notify for unknown channel"));
+       SILC_LOG_DEBUG(("Notify for unknown channel %s",
+                       silc_id_render(&channel_id, SILC_ID_CHANNEL)));
        goto out;
       }
     }
@@ -823,7 +842,8 @@ static void silc_server_notify_process(SilcServer server,
        channel = silc_idlist_find_channel_by_id(server->local_list,
                                                 &channel_id, NULL);
        if (!channel) {
-         SILC_LOG_DEBUG(("Notify for unknown channel"));
+         SILC_LOG_DEBUG(("Notify for unknown channel %s",
+                         silc_id_render(&channel_id, SILC_ID_CHANNEL)));
          goto out;
        }
       }
@@ -1010,7 +1030,8 @@ static void silc_server_notify_process(SilcServer server,
       channel = silc_idlist_find_channel_by_id(server->local_list,
                                               SILC_ID_GET_ID(id), NULL);
       if (!channel) {
-       SILC_LOG_DEBUG(("Notify for unknown channel"));
+       SILC_LOG_DEBUG(("Notify for unknown channel %s",
+                       silc_id_render(SILC_ID_GET_ID(id), SILC_ID_CHANNEL)));
        goto out;
       }
     }
@@ -1079,7 +1100,8 @@ static void silc_server_notify_process(SilcServer server,
       channel = silc_idlist_find_channel_by_id(server->global_list,
                                               SILC_ID_GET_ID(id), NULL);
       if (!channel) {
-       SILC_LOG_DEBUG(("Notify for unknown channel"));
+       SILC_LOG_DEBUG(("Notify for unknown channel %s",
+                       silc_id_render(SILC_ID_GET_ID(id), SILC_ID_CHANNEL)));
        goto out;
       }
     }
@@ -1208,12 +1230,12 @@ static void silc_server_notify_process(SilcServer server,
 
            /* Get client entry */
            client = silc_idlist_find_client_by_id(server->global_list,
-                                                  SILC_ID_GET_ID(id),
+                                                  SILC_ID_GET_ID(id2),
                                                   TRUE, &cache);
            local = FALSE;
            if (!client) {
              client = silc_idlist_find_client_by_id(server->local_list,
-                                                    SILC_ID_GET_ID(id),
+                                                    SILC_ID_GET_ID(id2),
                                                     TRUE, &cache);
              local = TRUE;
              if (!client)
@@ -1304,7 +1326,8 @@ static void silc_server_notify_process(SilcServer server,
       channel = silc_idlist_find_channel_by_id(server->local_list,
                                               &channel_id, NULL);
       if (!channel) {
-       SILC_LOG_DEBUG(("Notify for unknown channel"));
+       SILC_LOG_DEBUG(("Notify for unknown channel %s",
+                       silc_id_render(SILC_ID_GET_ID(id), SILC_ID_CHANNEL)));
        goto out;
       }
     }
@@ -1564,7 +1587,8 @@ static void silc_server_notify_process(SilcServer server,
       channel = silc_idlist_find_channel_by_id(server->local_list,
                                               SILC_ID_GET_ID(id), NULL);
       if (!channel) {
-       SILC_LOG_DEBUG(("Notify for unknown channel"));
+       SILC_LOG_DEBUG(("Notify for unknown channel %s",
+                       silc_id_render(SILC_ID_GET_ID(id), SILC_ID_CHANNEL)));
        goto out;
       }
     }
@@ -1652,6 +1676,7 @@ static void silc_server_notify_process(SilcServer server,
     break;
 
   default:
+    SILC_LOG_DEBUG(("Unsupported notify %d", type));
     break;
   }
 
@@ -2717,7 +2742,8 @@ static void silc_server_new_id_real(SilcServer server,
       /* As a router we keep information of all global information in our
         global list. Cell wide information however is kept in the local
         list. */
-      entry = silc_idlist_add_server(id_list, NULL, 0, &id, router,
+      entry = silc_idlist_add_server(id_list, NULL, 0,
+                                    silc_id_dup(&id, SILC_ID_SERVER), router,
                                     router_sock);
       if (!entry) {
        SILC_LOG_ERROR(("Could not add new server to the ID Cache"));
@@ -2959,9 +2985,12 @@ static void silc_server_new_channel_process(SilcServer server,
       }
 
       /* Create the channel with the provided Channel ID */
-      channel = silc_server_create_new_channel_with_id(server, NULL, NULL,
-                                                      channel_name,
-                                                      &channel_id, FALSE);
+      channel =
+       silc_server_create_new_channel_with_id(
+                                    server, NULL, NULL,
+                                    channel_name,
+                                    silc_id_dup(&channel_id, SILC_ID_CHANNEL),
+                                    FALSE);
       if (!channel) {
        silc_channel_payload_free(payload);
        return;
index 2b0f291ce3f3635302824fef557187d39d3fe978..46fccfc085d68ca3bb47b682dd69c7026be39a14 100644 (file)
@@ -24,6 +24,7 @@
 
 SILC_TASK_CALLBACK(silc_server_get_stats);
 SILC_TASK_CALLBACK(silc_server_connect_router);
+SILC_TASK_CALLBACK(silc_server_connect_to_router_retry);
 SILC_TASK_CALLBACK(silc_server_do_rekey);
 SILC_TASK_CALLBACK(silc_server_purge_expired_clients);
 static void silc_server_accept_new_connection(SilcNetStatus status,
@@ -876,12 +877,16 @@ SilcBool silc_server_init(SilcServer server)
      the ID list. */
   id_entry =
     silc_idlist_add_server(server->local_list, strdup(server->server_name),
-                          server->server_type, server->id, NULL, NULL);
+                          server->server_type,
+                          silc_id_dup(server->id, SILC_ID_SERVER),
+                          NULL, NULL);
   if (!id_entry) {
     SILC_LOG_ERROR(("Could not add local server to cache"));
     goto err;
   }
   id_entry->data.status |= SILC_IDLIST_STATUS_REGISTERED;
+  id_entry->data.conn_type = (server->server_type == SILC_SERVER ?
+                             SILC_CONN_SERVER : SILC_CONN_ROUTER);
   server->id_entry = id_entry;
 
   /* Create secondary TCP listeners */
@@ -1205,7 +1210,7 @@ void silc_server_stop(SilcServer server)
       silc_server_free_sock_user_data(server, ps,
                                      "Server is shutting down");
     }
-    silc_dlist_uninit(list);
+    silc_packet_engine_free_streams_list(list);
   }
 
   /* We are not connected to network anymore */
@@ -1217,6 +1222,12 @@ void silc_server_stop(SilcServer server)
 
   silc_server_http_uninit(server);
 
+  /* Cancel any possible retry timeouts */
+  silc_schedule_task_del_by_callback(server->schedule,
+                                    silc_server_connect_router);
+  silc_schedule_task_del_by_callback(server->schedule,
+                                    silc_server_connect_to_router_retry);
+
   silc_schedule_stop(server->schedule);
 
   SILC_LOG_DEBUG(("Server stopped"));
@@ -1331,6 +1342,7 @@ silc_server_ke_auth_compl(SilcConnAuth connauth, SilcBool success,
                                  SILC_STATUS_ERR_AUTH_FAILED, NULL);
     if (sconn->callback)
       (*sconn->callback)(server, NULL, sconn->callback_context);
+    silc_server_connection_free(sconn);
     return;
   }
 
@@ -1468,6 +1480,7 @@ silc_server_ke_auth_compl(SilcConnAuth connauth, SilcBool success,
          silc_server_backup_add(server, server->id_entry, ip,
                                 sconn->remote_port, TRUE);
        }
+#if 0
       } else {
        /* We already have primary router.  Disconnect this connection */
        SILC_LOG_DEBUG(("We already have primary router, disconnect"));
@@ -1479,6 +1492,7 @@ silc_server_ke_auth_compl(SilcConnAuth connauth, SilcBool success,
        silc_server_connection_free(sconn);
        silc_free(entry);
        return;
+#endif /* 0 */
       }
     } else {
       /* Add this server to be our backup router */
@@ -1520,13 +1534,6 @@ silc_server_ke_auth_compl(SilcConnAuth connauth, SilcBool success,
   if (sconn && sconn->callback)
     (*sconn->callback)(server, id_entry, sconn->callback_context);
 
-  /* Free the temporary connection data context */
-  if (sconn) {
-    silc_server_config_unref(&sconn->conn);
-    silc_free(sconn->remote_host);
-    silc_free(sconn->backup_replace_ip);
-    silc_free(sconn);
-  }
   if (sconn == server->router_conn)
     server->router_conn = NULL;
 
@@ -1625,10 +1632,12 @@ static void silc_server_ke_completed(SilcSKE ske, SilcSKEStatus status,
     }
   }
 
+  entry->data.rekey = rekey;
+
   /* Start connection authentication */
   sconn->op =
-    silc_connauth_initiator(connauth, server->server_type == SILC_ROUTER ?
-                           SILC_CONN_ROUTER : SILC_CONN_SERVER, auth_meth,
+    silc_connauth_initiator(connauth, server->server_type == SILC_SERVER ?
+                           SILC_CONN_SERVER : SILC_CONN_ROUTER, auth_meth,
                            auth_data, auth_data_len,
                            silc_server_ke_auth_compl, sconn);
 }
@@ -1800,6 +1809,7 @@ static void silc_server_connection_established(SilcNetStatus status,
       silc_schedule_task_add_timeout(sconn->server->schedule,
                                     silc_server_connect_to_router_retry,
                                     sconn, 1, 0);
+      silc_dlist_del(server->conns, sconn);
     } else {
       if (sconn->callback)
        (*sconn->callback)(server, NULL, sconn->callback_context);
@@ -1883,7 +1893,6 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router)
                   "normal server" : server->server_type == SILC_ROUTER ?
                   "router" : "backup router/normal server")));
 
-  /* XXX */
   if (!server->config->routers) {
     /* There wasn't a configured router, we will continue but we don't
        have a connection to outside world.  We will be standalone server. */
@@ -1892,6 +1901,12 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router)
     return;
   }
 
+  /* Cancel any possible retry timeouts */
+  silc_schedule_task_del_by_callback(server->schedule,
+                                    silc_server_connect_router);
+  silc_schedule_task_del_by_callback(server->schedule,
+                                    silc_server_connect_to_router_retry);
+
   /* Create the connections to all our routes */
   for (ptr = server->config->routers; ptr; ptr = ptr->next) {
 
@@ -1947,6 +1962,7 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router)
     sconn = silc_calloc(1, sizeof(*sconn));
     if (!sconn)
       continue;
+    sconn->server = server;
     sconn->remote_host = strdup(ptr->host);
     sconn->remote_port = ptr->port;
     sconn->backup = ptr->backup_router;
@@ -1957,7 +1973,6 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router)
 
     SILC_LOG_DEBUG(("Created connection %p", sconn));
 
-    /* XXX */
     if (!server->router_conn && !sconn->backup)
       server->router_conn = sconn;
 
@@ -2359,9 +2374,11 @@ silc_server_accept_auth_compl(SilcConnAuth connauth, SilcBool success,
       if (entry->data.conn_type == SILC_CONN_SERVER) {
        server->stat.my_servers++;
        server->stat.servers++;
+       SILC_LOG_DEBUG(("my_servers %d", server->stat.my_servers));
       } else {
        server->stat.my_routers++;
        server->stat.routers++;
+       SILC_LOG_DEBUG(("my_routers %d", server->stat.my_routers));
       }
 
       /* Check whether this connection is to be our primary router connection
@@ -2696,8 +2713,8 @@ SILC_TASK_CALLBACK(silc_server_do_rekey)
                  SILC_CONNTYPE_STRING(idata->conn_type)));
 
   /* Allocate SKE */
-  ske = silc_ske_alloc(server->rng, server->schedule, server->repository,
-                      server->public_key, server->private_key, sock);
+  ske = silc_ske_alloc(server->rng, server->schedule, NULL,
+                      server->public_key, NULL, sock);
   if (!ske)
     return;
 
@@ -2749,8 +2766,8 @@ static void silc_server_rekey(SilcServer server, SilcPacketStream sock,
                  SILC_CONNTYPE_STRING(idata->conn_type)));
 
   /* Allocate SKE */
-  ske = silc_ske_alloc(server->rng, server->schedule, server->repository,
-                      server->public_key, server->private_key, sock);
+  ske = silc_ske_alloc(server->rng, server->schedule, NULL,
+                      server->public_key, NULL, sock);
   if (!ske) {
     silc_packet_free(packet);
     return;
@@ -3114,22 +3131,26 @@ void silc_server_free_sock_user_data(SilcServer server,
       if (idata->sconn)
        silc_server_connection_free(idata->sconn);
 
-      /* Free the server entry */
-      silc_server_backup_del(server, user_data);
-      silc_server_backup_replaced_del(server, user_data);
-      silc_idlist_del_data(user_data);
-      if (!silc_idlist_del_server(server->local_list, user_data))
-       silc_idlist_del_server(server->global_list, user_data);
+      /* Statistics */
       if (idata->conn_type == SILC_CONN_SERVER) {
        server->stat.my_servers--;
        server->stat.servers--;
-      } else {
+       SILC_LOG_DEBUG(("my_servers %d", server->stat.my_servers));
+      } else if (idata->conn_type == SILC_CONN_ROUTER) {
        server->stat.my_routers--;
        server->stat.routers--;
+       SILC_LOG_DEBUG(("my_routers %d", server->stat.my_routers));
       }
       if (server->server_type == SILC_ROUTER)
        server->stat.cell_servers--;
 
+      /* Free the server entry */
+      silc_server_backup_del(server, user_data);
+      silc_server_backup_replaced_del(server, user_data);
+      silc_idlist_del_data(user_data);
+      if (!silc_idlist_del_server(server->local_list, user_data))
+       silc_idlist_del_server(server->global_list, user_data);
+
       if (backup_router && backup_router != server->id_entry) {
        /* Announce all of our stuff that was created about 5 minutes ago.
           The backup router knows all the other stuff already. */
@@ -3936,6 +3957,9 @@ static void silc_server_announce_get_clients(SilcServer server,
       if (!client->connection && !client->router)
        continue;
 
+      SILC_LOG_DEBUG(("Announce Client ID %s",
+                     silc_id_render(client->id, SILC_ID_CLIENT)));
+
       idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
 
       *clients = silc_buffer_realloc(*clients,
@@ -4163,6 +4187,9 @@ void silc_server_announce_get_channel_users(SilcServer server,
   while (silc_hash_table_get(&htl, NULL, (void *)&chl)) {
     clidp = silc_id_payload_encode(chl->client->id, SILC_ID_CLIENT);
 
+    SILC_LOG_DEBUG(("JOIN Client %s", silc_id_render(chl->client->id,
+                                                    SILC_ID_CLIENT)));
+
     /* JOIN Notify */
     tmp = silc_server_announce_encode_notify(SILC_NOTIFY_TYPE_JOIN, 2,
                                             clidp->data,
@@ -4256,6 +4283,9 @@ void silc_server_announce_get_channels(SilcServer server,
       else
        announce = TRUE;
 
+      SILC_LOG_DEBUG(("Announce Channel ID %s",
+                     silc_id_render(channel->id, SILC_ID_CHANNEL)));
+
       silc_id_id2str(channel->id, SILC_ID_CHANNEL, cid, sizeof(cid), &id_len);
       name_len = strlen(channel->channel_name);
 
@@ -4560,10 +4590,10 @@ void silc_server_announce_watches(SilcServer server,
 /* Assembles user list and users mode list from the `channel'. */
 
 SilcBool silc_server_get_users_on_channel(SilcServer server,
-                                     SilcChannelEntry channel,
-                                     SilcBuffer *user_list,
-                                     SilcBuffer *mode_list,
-                                     SilcUInt32 *user_count)
+                                         SilcChannelEntry channel,
+                                         SilcBuffer *user_list,
+                                         SilcBuffer *mode_list,
+                                         SilcUInt32 *user_count)
 {
   SilcChannelClientEntry chl;
   SilcHashTableList htl;
index d0ae1065b3595e2d513c651afd9e94adce7133cf..e460c95d720022afabf2d277f2459eb8a3dcca2e 100644 (file)
@@ -108,7 +108,8 @@ void silc_server_backup_add(SilcServer server, SilcServerEntry backup_server,
   }
 
   SILC_LOG_DEBUG(("Backup router %s will replace %s",
-                 backup_server->data.sconn->remote_host, ip, port));
+                 backup_server->data.sconn ?
+                 backup_server->data.sconn->remote_host : "(me)", ip));
 
   for (i = 0; i < server->backup->servers_count; i++) {
     if (!server->backup->servers[i].server) {
@@ -551,10 +552,10 @@ void silc_server_backup_ping_reply(void *context, void *reply)
     /* The primary is not down, refuse to serve the server as primary */
     SILC_LOG_DEBUG(("PING received, primary is up"));
     silc_server_backup_send_start_use(pc->server, pc->sock, TRUE);
+    silc_packet_free(pc->packet);
   }
 
   silc_packet_stream_unref(pc->sock);
-  silc_packet_free(pc->packet);
   silc_free(pc);
 }
 
@@ -811,7 +812,7 @@ void silc_server_backup_connected(SilcServer server,
     /* Try again */
     silc_schedule_task_add_timeout(server->schedule,
                                   silc_server_backup_connected_again,
-                                  context, 0, 1);
+                                  context, 5, 0);
     return;
   }
 
@@ -1159,7 +1160,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup)
        if (sock == ctx->sock)
          continue;
 
-      send_to_backup:
+       server_entry = silc_packet_get_context(sock);
        server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
 
        SILC_LOG_DEBUG(("Sending RESUMED to %s", server_entry->server_name));
@@ -1174,14 +1175,27 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup)
        silc_server_packet_send(server, sock, SILC_PACKET_RESUME_ROUTER, 0,
                                data, sizeof(data));
       }
-      silc_packet_engine_free_streams_list(list);
 
       /* Now send the same packet to backup */
       if (sock != ctx->sock) {
        sleep(1);
        sock = ctx->sock;
-       goto send_to_backup;
+       server_entry = silc_packet_get_context(sock);
+       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 */
+       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));
       }
+      silc_packet_engine_free_streams_list(list);
 
       /* We are now resumed and are back as primary router in the cell. */
       SILC_LOG_INFO(("We are now the primary router of our cell again"));
@@ -1196,7 +1210,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup)
       /* For us this is the end of this protocol. */
       silc_schedule_task_add_timeout(server->schedule,
                                     silc_server_protocol_backup_done,
-                                    ctx->sock, 0, 1);
+                                    ctx, 0, 1);
     }
     break;
 
@@ -1262,7 +1276,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup)
       /* Protocol has ended, call the final callback */
       silc_schedule_task_add_timeout(server->schedule,
                                     silc_server_protocol_backup_done,
-                                    ctx->sock, 0, 1);
+                                    ctx, 0, 1);
     }
     break;
 
@@ -1270,7 +1284,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup)
     /* Protocol has ended, call the final callback */
     silc_schedule_task_add_timeout(server->schedule,
                                   silc_server_protocol_backup_done,
-                                  ctx->sock, 0, 1);
+                                  ctx, 0, 1);
     break;
 
   case 252:
@@ -1279,7 +1293,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup)
     ctx->received_failure = TRUE;
     silc_schedule_task_add_timeout(server->schedule,
                                   silc_server_protocol_backup_done,
-                                  ctx->sock, 0, 1);
+                                  ctx, 0, 1);
     break;
 
   default:
@@ -1445,8 +1459,10 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup_done)
 
   if (ctx->sock) {
     SilcServerEntry r = silc_packet_get_context(ctx->sock);
-    r->backup = FALSE;
-    r->backup_proto = NULL;
+    if (r) {
+      r->backup = FALSE;
+      r->backup_proto = NULL;
+    }
     silc_packet_stream_unref(ctx->sock);
   }
   silc_free(ctx->sessions);
index 084628cb7affdd65cc50889d0aa982a153ffa0d9..19ea23e67821e2efb77f6fe817ce5bc773890ed3 100644 (file)
@@ -162,17 +162,15 @@ SilcBool silc_server_remove_clients_by_server(SilcServer server,
 
   if (server_signoff) {
     idp = silc_id_payload_encode(entry->id, SILC_ID_SERVER);
-    if (idp) {
-      argv = silc_realloc(argv, sizeof(*argv) * (argc + 1));
-      argv_lens = silc_realloc(argv_lens,  sizeof(*argv_lens) * (argc + 1));
-      argv_types = silc_realloc(argv_types, sizeof(*argv_types) * (argc + 1));
-      argv[argc] = silc_calloc(silc_buffer_len(idp), sizeof(*argv[0]));
-      memcpy(argv[argc], idp->data, silc_buffer_len(idp));
-      argv_lens[argc] = silc_buffer_len(idp);
-      argv_types[argc] = argc + 1;
-      argc++;
-      silc_buffer_free(idp);
-    }
+    argv = silc_realloc(argv, sizeof(*argv) * (argc + 1));
+    argv_lens = silc_realloc(argv_lens,  sizeof(*argv_lens) * (argc + 1));
+    argv_types = silc_realloc(argv_types, sizeof(*argv_types) * (argc + 1));
+    argv[argc] = silc_calloc(silc_buffer_len(idp), sizeof(*argv[0]));
+    memcpy(argv[argc], idp->data, silc_buffer_len(idp));
+    argv_lens[argc] = silc_buffer_len(idp);
+    argv_types[argc] = argc + 1;
+    argc++;
+    silc_buffer_free(idp);
   }
 
   if (silc_idcache_get_all(server->local_list->clients, &list)) {
@@ -415,10 +413,8 @@ silc_server_update_clients_by_real_server(SilcServer server,
           since the server is local. */
        if (!local) {
          SILC_LOG_DEBUG(("Moving client to local list"));
-         silc_idcache_add(server->local_list->clients, client_cache->name,
-                          client_cache->id, client_cache->context);
-         silc_idcache_del_by_context(server->global_list->clients, client,
-                                     NULL);
+         silc_idcache_move(server->global_list->clients,
+                           server->local_list->clients, client_cache);
        }
        server_entry = server_entry->router;
       } else {
@@ -427,20 +423,16 @@ silc_server_update_clients_by_real_server(SilcServer server,
           since the server is local. */
        if (server_entry->server_type != SILC_BACKUP_ROUTER && !local) {
          SILC_LOG_DEBUG(("Moving client to local list"));
-         silc_idcache_add(server->local_list->clients, client_cache->name,
-                          client_cache->id, client_cache->context);
-         silc_idcache_del_by_context(server->global_list->clients, client,
-                                     NULL);
+         silc_idcache_move(server->global_list->clients,
+                           server->local_list->clients, client_cache);
 
        } else if (server->server_type == SILC_BACKUP_ROUTER && local) {
          /* If we are backup router and this client is on local list, we
             must move it to global list, as it is not currently local to
             us (we are not primary). */
          SILC_LOG_DEBUG(("Moving client to global list"));
-         silc_idcache_add(server->global_list->clients, client_cache->name,
-                          client_cache->id, client_cache->context);
-         silc_idcache_del_by_context(server->local_list->clients, client,
-                                     NULL);
+         silc_idcache_move(server->local_list->clients,
+                           server->global_list->clients, client_cache);
        }
       }
 
@@ -467,10 +459,8 @@ silc_server_update_clients_by_real_server(SilcServer server,
           since the server is global. */
        if (local) {
          SILC_LOG_DEBUG(("Moving client to global list"));
-         silc_idcache_add(server->global_list->clients, client_cache->name,
-                          client_cache->id, client_cache->context);
-         silc_idcache_del_by_context(server->local_list->clients, client,
-                                     NULL);
+         silc_idcache_move(server->local_list->clients,
+                           server->global_list->clients, client_cache);
        }
        server_entry = server_entry->router;
       } else {
@@ -479,10 +469,8 @@ silc_server_update_clients_by_real_server(SilcServer server,
           since the server is global. */
        if (server_entry->server_type != SILC_BACKUP_ROUTER && local) {
          SILC_LOG_DEBUG(("Moving client to global list"));
-         silc_idcache_add(server->global_list->clients, client_cache->name,
-                          client_cache->id, client_cache->context);
-         silc_idcache_del_by_context(server->local_list->clients, client,
-                                     NULL);
+         silc_idcache_move(server->local_list->clients,
+                           server->global_list->clients, client_cache);
        }
       }
       return server_entry;
@@ -1067,6 +1055,8 @@ SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server,
   if (!ip && !hostname)
     return 0;
 
+  SILC_LOG_DEBUG(("Num connections %d", silc_dlist_count(server->conns)));
+
   silc_dlist_start(server->conns);
   while ((conn = silc_dlist_get(server->conns))) {
     if (conn->sock) {
@@ -1233,6 +1223,7 @@ SilcBool silc_server_connection_allowed(SilcServer server,
                  global->connections_max_per_host);
 
   if (max_hosts && conn_number >= max_hosts) {
+    SILC_LOG_DEBUG(("Server is full, %d >= %d", conn_number, max_hosts));
     SILC_LOG_INFO(("Server is full, closing %s (%s) connection",
                   hostname, ip));
     silc_server_disconnect_remote(server, sock,
@@ -1242,6 +1233,8 @@ SilcBool silc_server_connection_allowed(SilcServer server,
   }
 
   if (num_sockets >= max_per_host) {
+    SILC_LOG_DEBUG(("Too many connections, %d >= %d", num_sockets,
+                   max_per_host));
     SILC_LOG_INFO(("Too many connections from %s (%s), closing connection",
                   hostname, ip));
     silc_server_disconnect_remote(server, sock,
@@ -1997,7 +1990,7 @@ void silc_server_create_connections(SilcServer server)
   silc_schedule_task_del_by_callback(server->schedule,
                                     silc_server_connect_to_router);
   silc_schedule_task_add_timeout(server->schedule,
-                                silc_server_connect_to_router, server, 0, 1);
+                                silc_server_connect_to_router, server, 1, 0);
 }
 
 static void
index 99b9abaed40bab190d9b1b06f5cb77d6d416efec..fca40453051f1d019c50179d965f34e013a8dc01 100644 (file)
@@ -1415,6 +1415,24 @@ static SilcBool silc_server_config_check(SilcServerConfig config)
     ret = FALSE;
   }
 
+  if (!config->server_info->public_key ||
+      !config->server_info->private_key) {
+    SILC_SERVER_LOG_ERROR(("\nError: Server keypair is missing"));
+    ret = FALSE;
+  }
+
+  if (!config->server_info->primary) {
+    SILC_SERVER_LOG_ERROR(("\nError: Missing mandatory block `Primary' "
+                          "in `ServerInfo'"));
+    ret = FALSE;
+  }
+
+  if (!config->server_info->primary->server_ip) {
+    SILC_SERVER_LOG_ERROR(("\nError: Missing mandatory field `Ip' "
+                          "in `Primary' in `ServerInfo'"));
+    ret = FALSE;
+  }
+
   /* RouterConnection sanity checks */
 
   if (config->routers && config->routers->backup_router == TRUE &&
@@ -1424,15 +1442,6 @@ static SilcBool silc_server_config_check(SilcServerConfig config)
         "connection. You have marked it incorrectly as backup router."));
     ret = FALSE;
   }
-#if 0
-  if (config->routers && config->routers->initiator == FALSE &&
-      config->routers->backup_router == FALSE) {
-    SILC_SERVER_LOG_ERROR((
-         "\nError: First RouterConnection block must be primary router "
-        "connection and it must be marked as Initiator."));
-    ret = FALSE;
-  }
-#endif
   if (config->routers && config->routers->backup_router == TRUE &&
       !config->servers && !config->routers->next) {
     SILC_SERVER_LOG_ERROR((
index 0a5c9fc6a0249d00ca33277d5a1ab549f3298322..14e3657f968d6fd64e6fdbb4b09caf8f00ea215a 100644 (file)
@@ -673,8 +673,9 @@ int main(int argc, char **argv)
     silc_pkcs_register_default();
     silc_hash_register_default();
     silc_hmac_register_default();
-    silc_create_key_pair(opt_pkcs, opt_bits, pubfile, prvfile,
-                        opt_identifier, "", NULL, NULL, FALSE);
+    if (!silc_create_key_pair(opt_pkcs, opt_bits, pubfile, prvfile,
+                             opt_identifier, "", NULL, NULL, FALSE))
+      exit(1);
     exit(0);
   }