Integer type name change.
[silc.git] / apps / silcd / server.h
1 /*
2
3   server.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2001 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20
21 #ifndef SERVER_H
22 #define SERVER_H
23
24 /* Forward declaration for SILC Server object. The actual object is
25    defined in internal header file for server routines. I want to keep
26    the object private hence this declaration. */
27 typedef struct SilcServerStruct *SilcServer;
28
29 /* Forward declaration of backup server context */
30 typedef struct SilcServerBackupStruct *SilcServerBackup;
31
32 /* Callback function that is called after the key exchange and connection
33    authentication protocols has been completed with a remote router. The
34    `server_entry' is the remote router entry. */
35 typedef void (*SilcServerConnectRouterCallback)(SilcServer server,
36                                                 SilcServerEntry server_entry,
37                                                 void *context);
38
39 /* Connection structure used when connection to remote */
40 typedef struct {
41   SilcSocketConnection sock;
42
43   /* Remote host name and port */
44   char *remote_host;
45   int remote_port;
46   bool backup;
47   char *backup_replace_ip;
48   int backup_replace_port;
49   bool no_reconnect;
50
51   /* Connection configuration (maybe NULL), and connection params */
52   void *conn;
53   void *param;
54
55   /* Current connection retry info */
56   SilcUInt32 retry_count;
57   SilcUInt32 retry_timeout;
58
59   /* Back pointer to server */
60   SilcServer server;
61
62   SilcServerConnectRouterCallback callback;
63   void *callback_context;
64 } *SilcServerConnection;
65
66 /* General definitions */
67
68 /* SILC port */
69 #define SILC_PORT 768;
70
71 /* Server and router. Used internally by the code. */
72 #define SILC_SERVER 0
73 #define SILC_ROUTER 1
74 #define SILC_BACKUP_ROUTER 2
75
76 /* Default parameter values */
77
78 /* Connection retry timeout. We implement exponential backoff algorithm
79    in connection retry. The interval of timeout grows when retry count
80    grows. */
81 #define SILC_SERVER_RETRY_COUNT        7         /* Max retry count */
82 #define SILC_SERVER_RETRY_MULTIPLIER   2         /* Interval growth */
83 #define SILC_SERVER_RETRY_RANDOMIZER   2         /* timeout += rnd % 2 */
84 #define SILC_SERVER_RETRY_INTERVAL_MIN 10        /* Min retry timeout */
85 #define SILC_SERVER_RETRY_INTERVAL_MAX 600       /* Max generated timeout */
86
87 #define SILC_SERVER_KEEPALIVE          300       /* Heartbeat interval */
88 #define SILC_SERVER_CHANNEL_REKEY      3600      /* Channel rekey interval */
89 #define SILC_SERVER_REKEY              3600      /* Session rekey interval */
90 #define SILC_SERVER_SKE_TIMEOUT        60        /* SKE timeout */
91 #define SILC_SERVER_CONNAUTH_TIMEOUT   60        /* CONN_AUTH timeout */
92 #define SILC_SERVER_MAX_CONNECTIONS    1000      /* Max connections */
93 #define SILC_SERVER_MAX_CONNECTIONS_SINGLE 1000  /* Max connections per host */
94
95 /* Macros */
96
97 /* This macro is used to send notify messages with formatted string. The
98    string is formatted with arguments and the formatted string is sent as
99    argument. */
100 #define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt)        \
101 do {                                                            \
102   char *__fmt__ = silc_format fmt;                              \
103   silc_server_send_notify(server, sock, FALSE,                  \
104                           type, 1, __fmt__, strlen(__fmt__));   \
105   silc_free(__fmt__);                                           \
106 } while(0);
107
108 /* Check whether rekey protocol is active */
109 #define SILC_SERVER_IS_REKEY(sock)                                      \
110   (sock->protocol && sock->protocol->protocol &&                        \
111    sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)
112
113 /* Prototypes */
114 int silc_server_alloc(SilcServer *new_server);
115 void silc_server_free(SilcServer server);
116 int silc_server_init(SilcServer server);
117 void silc_server_daemonise(SilcServer server);
118 void silc_server_drop(SilcServer server);
119 void silc_server_run(SilcServer server);
120 void silc_server_stop(SilcServer server);
121 void silc_server_start_key_exchange(SilcServer server,
122                                     SilcServerConnection sconn,
123                                     int sock);
124 bool silc_server_packet_parse(SilcPacketParserContext *parser_context,
125                               void *context);
126 void silc_server_packet_parse_type(SilcServer server, 
127                                    SilcSocketConnection sock,
128                                    SilcPacketContext *packet);
129 void silc_server_create_connection(SilcServer server,
130                                    const char *remote_host, SilcUInt32 port);
131 void silc_server_close_connection(SilcServer server,
132                                   SilcSocketConnection sock);
133 void silc_server_free_client_data(SilcServer server, 
134                                   SilcSocketConnection sock,
135                                   SilcClientEntry client, 
136                                   int notify,
137                                   const char *signoff);
138 void silc_server_free_sock_user_data(SilcServer server, 
139                                      SilcSocketConnection sock,
140                                      const char *signoff_message);
141 void silc_server_remove_from_channels(SilcServer server, 
142                                       SilcSocketConnection sock,
143                                       SilcClientEntry client,
144                                       int notify,
145                                       char *signoff_message,
146                                       int keygen);
147 int silc_server_remove_from_one_channel(SilcServer server, 
148                                         SilcSocketConnection sock,
149                                         SilcChannelEntry channel,
150                                         SilcClientEntry client,
151                                         int notify);
152 void silc_server_disconnect_remote(SilcServer server,
153                                    SilcSocketConnection sock,
154                                    const char *fmt, ...);
155 SilcChannelEntry silc_server_create_new_channel(SilcServer server, 
156                                                 SilcServerID *router_id,
157                                                 char *cipher, 
158                                                 char *hmac,
159                                                 char *channel_name,
160                                                 int broadcast);
161 SilcChannelEntry 
162 silc_server_create_new_channel_with_id(SilcServer server, 
163                                        char *cipher, 
164                                        char *hmac,
165                                        char *channel_name,
166                                        SilcChannelID *channel_id,
167                                        int broadcast);
168 bool silc_server_create_channel_key(SilcServer server, 
169                                     SilcChannelEntry channel,
170                                     SilcUInt32 key_len);
171 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
172                                               SilcBuffer key_payload,
173                                               SilcChannelEntry channel);
174 void silc_server_perform_heartbeat(SilcSocketConnection sock,
175                                    void *hb_context);
176 void silc_server_announce_get_channel_topic(SilcServer server,
177                                             SilcChannelEntry channel,
178                                             SilcBuffer *topic);
179 void silc_server_announce_get_channel_users(SilcServer server,
180                                             SilcChannelEntry channel,
181                                             SilcBuffer *channel_users,
182                                             SilcBuffer *channel_users_modes);
183 void silc_server_announce_get_channels(SilcServer server,
184                                        SilcIDList id_list,
185                                        SilcBuffer *channels,
186                                        SilcBuffer *channel_users,
187                                        SilcBuffer **channel_users_modes,
188                                        SilcUInt32 *channel_users_modes_c,
189                                        SilcBuffer **channel_topics,
190                                        SilcChannelID ***channel_ids,
191                                        unsigned long creation_time);
192 void silc_server_announce_servers(SilcServer server, bool global,
193                                   unsigned long creation_time,
194                                   SilcSocketConnection remote);
195 void silc_server_announce_clients(SilcServer server,
196                                   unsigned long creation_time,
197                                   SilcSocketConnection remote);
198 void silc_server_announce_channels(SilcServer server,
199                                    unsigned long creation_time,
200                                    SilcSocketConnection remote);
201 void silc_server_get_users_on_channel(SilcServer server,
202                                       SilcChannelEntry channel,
203                                       SilcBuffer *user_list,
204                                       SilcBuffer *mode_list,
205                                       SilcUInt32 *user_count);
206 void silc_server_save_users_on_channel(SilcServer server,
207                                        SilcSocketConnection sock,
208                                        SilcChannelEntry channel,
209                                        SilcClientID *noadd,
210                                        SilcBuffer user_list,
211                                        SilcBuffer mode_list,
212                                        SilcUInt32 user_count);
213 SilcSocketConnection silc_server_get_client_route(SilcServer server,
214                                                   unsigned char *id_data,
215                                                   SilcUInt32 id_len,
216                                                   SilcClientID *client_id,
217                                                   SilcIDListData *idata);
218 SilcBuffer silc_server_get_client_channel_list(SilcServer server,
219                                                SilcClientEntry client);
220 SilcClientEntry silc_server_get_client_resolve(SilcServer server,
221                                                SilcClientID *client_id,
222                                                bool *resolved);
223
224 #endif