updates.
[silc.git] / apps / silcd / server.h
index 3a041fc63712446b7fefef3ef5bc7cb23d70b380..495bd263dc29bfefce379995039d488bb8994019 100644 (file)
    the object private hence this declaration. */
 typedef struct SilcServerStruct *SilcServer;
 
-#define SILC_SERVER_MAX_CONNECTIONS 10000
+/* Forward declaration of backup server context */
+typedef struct SilcServerBackupStruct *SilcServerBackup;
+
+#define SILC_SERVER_MAX_CONNECTIONS 1000
 
 /* General definitions */
 
+/* SILC port */
+#define SILC_PORT 768;
+
 /* Server and router. Used internally by the code. */
 #define SILC_SERVER 0
 #define SILC_ROUTER 1
+#define SILC_BACKUP_ROUTER 2
 
 /* Connection retry timeout. We implement exponential backoff algorithm
    in connection retry. The interval of timeuot grows when retry count
@@ -51,30 +58,62 @@ typedef struct SilcServerStruct *SilcServer;
 
 */
 typedef struct {
-  unsigned int retry_count;
-  unsigned long retry_interval_min;
-  unsigned long retry_interval_min_usec;
-  unsigned long retry_interval_max;
+  uint32 retry_count;
+  uint32 retry_interval_min;
+  uint32 retry_interval_min_usec;
+  uint32 retry_interval_max;
   char retry_keep_trying;
 
-  unsigned long protocol_timeout;
-  unsigned long protocol_timeout_usec;
+  uint32 protocol_timeout;
+  uint32 protocol_timeout_usec;
 
   char require_reverse_mapping;
 } *SilcServerParams;
 
+/* Callback function that is called after the key exchange and connection
+   authentication protocols has been completed with a remote router. The
+   `server_entry' is the remote router entry. */
+typedef void (*SilcServerConnectRouterCallback)(SilcServer server,
+                                               SilcServerEntry server_entry,
+                                               void *context);
+
+typedef struct {
+  SilcSocketConnection sock;
+
+  /* Remote host name and port */
+  char *remote_host;
+  int remote_port;
+  bool backup;
+  
+  /* Current connection retry info */
+  uint32 retry_count;
+  uint32 retry_timeout;
+
+  /* Back pointer to server */
+  SilcServer server;
+
+  SilcServerConnectRouterCallback callback;
+  void *callback_context;
+} *SilcServerConnection;
+
 /* Macros */
 
 /* This macro is used to send notify messages with formatted string. The
    string is formatted with arguments and the formatted string is sent as
    argument. */
-#define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt)                   \
-do {                                                                       \
-  char *__fmt__ = silc_format fmt;                                         \
-  silc_server_send_notify(server, sock, type, 1, __fmt__, strlen(__fmt__)); \
-  silc_free(__fmt__);                                                      \
+#define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt)       \
+do {                                                           \
+  char *__fmt__ = silc_format fmt;                             \
+  silc_server_send_notify(server, sock, FALSE,                         \
+                         type, 1, __fmt__, strlen(__fmt__));   \
+  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)
+
 /* Prototypes */
 int silc_server_alloc(SilcServer *new_server);
 void silc_server_free(SilcServer server);
@@ -82,42 +121,97 @@ int silc_server_init(SilcServer server);
 void silc_server_daemonise(SilcServer server);
 void silc_server_run(SilcServer server);
 void silc_server_stop(SilcServer server);
+void silc_server_start_key_exchange(SilcServer server,
+                                   SilcServerConnection sconn,
+                                   int sock);
 void silc_server_packet_parse(SilcPacketParserContext *parser_context);
 void silc_server_packet_parse_type(SilcServer server, 
                                   SilcSocketConnection sock,
                                   SilcPacketContext *packet);
+void silc_server_create_connection(SilcServer server,
+                                  char *remote_host, uint32 port);
 void silc_server_close_connection(SilcServer server,
                                  SilcSocketConnection sock);
+void silc_server_free_client_data(SilcServer server, 
+                                 SilcSocketConnection sock,
+                                 SilcClientEntry client, 
+                                 int notify,
+                                 char *signoff);
 void silc_server_free_sock_user_data(SilcServer server, 
                                     SilcSocketConnection sock);
-int silc_server_channel_has_global(SilcChannelEntry channel);
-int silc_server_channel_has_local(SilcChannelEntry channel);
-int silc_server_remove_clients_by_server(SilcServer server, 
-                                        SilcServerEntry entry);
 void silc_server_remove_from_channels(SilcServer server, 
                                      SilcSocketConnection sock,
-                                     SilcClientEntry client);
+                                     SilcClientEntry client,
+                                     int notify,
+                                     char *signoff_message,
+                                     int keygen);
 int silc_server_remove_from_one_channel(SilcServer server, 
                                        SilcSocketConnection sock,
                                        SilcChannelEntry channel,
                                        SilcClientEntry client,
                                        int notify);
-int silc_server_client_on_channel(SilcClientEntry client,
-                                 SilcChannelEntry channel);
 void silc_server_disconnect_remote(SilcServer server,
                                   SilcSocketConnection sock,
                                   const char *fmt, ...);
 SilcChannelEntry silc_server_create_new_channel(SilcServer server, 
                                                SilcServerID *router_id,
                                                char *cipher, 
-                                               char *channel_name);
-void silc_server_create_channel_key(SilcServer server, 
+                                               char *hmac,
+                                               char *channel_name,
+                                               int broadcast);
+SilcChannelEntry 
+silc_server_create_new_channel_with_id(SilcServer server, 
+                                      char *cipher, 
+                                      char *hmac,
+                                      char *channel_name,
+                                      SilcChannelID *channel_id,
+                                      int broadcast);
+bool silc_server_create_channel_key(SilcServer server, 
                                    SilcChannelEntry channel,
-                                   unsigned int key_len);
+                                   uint32 key_len);
 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
                                              SilcBuffer key_payload,
                                              SilcChannelEntry channel);
 void silc_server_perform_heartbeat(SilcSocketConnection sock,
                                   void *hb_context);
+void silc_server_announce_get_channel_users(SilcServer server,
+                                           SilcChannelEntry channel,
+                                           SilcBuffer *channel_users,
+                                           SilcBuffer *channel_users_modes);
+void silc_server_announce_get_channels(SilcServer server,
+                                      SilcIDList id_list,
+                                      SilcBuffer *channels,
+                                      SilcBuffer *channel_users,
+                                      SilcBuffer **channel_users_modes,
+                                      uint32 *channel_users_modes_c,
+                                      SilcChannelID ***channel_ids,
+                                      unsigned long creation_time);
+void silc_server_announce_servers(SilcServer server, bool global,
+                                 unsigned long creation_time);
+void silc_server_announce_clients(SilcServer server,
+                                 unsigned long creationg_time);
+void silc_server_announce_channels(SilcServer server,
+                                  unsigned long creationg_time);
+void silc_server_get_users_on_channel(SilcServer server,
+                                     SilcChannelEntry channel,
+                                     SilcBuffer *user_list,
+                                     SilcBuffer *mode_list,
+                                     uint32 *user_count);
+void silc_server_save_users_on_channel(SilcServer server,
+                                      SilcSocketConnection sock,
+                                      SilcChannelEntry channel,
+                                      SilcClientID *noadd,
+                                      SilcBuffer user_list,
+                                      SilcBuffer mode_list,
+                                      uint32 user_count);
+SilcSocketConnection silc_server_get_client_route(SilcServer server,
+                                                 unsigned char *id_data,
+                                                 uint32 id_len,
+                                                 SilcClientID *client_id,
+                                                 SilcIDListData *idata);
+SilcBuffer silc_server_get_client_channel_list(SilcServer server,
+                                              SilcClientEntry client);
+SilcClientEntry silc_server_get_client_resolve(SilcServer server,
+                                              SilcClientID *client_id);
 
 #endif