5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2005 Pekka Riikonen
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; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
23 /* Forward declaration of backup server context */
24 typedef struct SilcServerBackupStruct *SilcServerBackup;
26 /* Callback function that is called after the key exchange and connection
27 authentication protocols has been completed with a remote router. The
28 `server_entry' is the remote router entry or NULL on error. */
29 typedef void (*SilcServerConnectRouterCallback)(SilcServer server,
30 SilcServerEntry server_entry,
33 /* Connection structure used when connection to remote */
35 SilcSocketConnection sock;
37 /* Remote host name and port */
41 char *backup_replace_ip;
42 int backup_replace_port;
45 /* Connection configuration (maybe NULL) */
46 SilcServerConfigRef conn;
48 /* Current connection retry info */
49 SilcUInt32 retry_count;
50 SilcUInt32 retry_timeout;
52 SilcServerConnectRouterCallback callback;
53 void *callback_context;
54 } *SilcServerConnection;
56 /* General definitions */
61 /* Server and router. Used internally by the code. */
64 #define SILC_BACKUP_ROUTER 2
66 /* Default parameter values */
68 /* Connection retry timeout. We implement exponential backoff algorithm
69 in connection retry. The interval of timeout grows when retry count
71 #define SILC_SERVER_RETRY_COUNT 7 /* Max retry count */
72 #define SILC_SERVER_RETRY_MULTIPLIER 2 /* Interval growth */
73 #define SILC_SERVER_RETRY_RANDOMIZER 2 /* timeout += rnd % 2 */
74 #define SILC_SERVER_RETRY_INTERVAL_MIN 10 /* Min retry timeout */
75 #define SILC_SERVER_RETRY_INTERVAL_MAX 600 /* Max generated timeout */
77 #define SILC_SERVER_KEEPALIVE 300 /* Heartbeat interval */
78 #define SILC_SERVER_CHANNEL_REKEY 3600 /* Channel rekey interval */
79 #define SILC_SERVER_REKEY 3600 /* Session rekey interval */
80 #define SILC_SERVER_SKE_TIMEOUT 60 /* SKE timeout */
81 #define SILC_SERVER_CONNAUTH_TIMEOUT 60 /* CONN_AUTH timeout */
82 #define SILC_SERVER_MAX_CONNECTIONS 1000 /* Max connections */
83 #define SILC_SERVER_MAX_CONNECTIONS_SINGLE 1000 /* Max connections per host */
84 #define SILC_SERVER_LOG_FLUSH_DELAY 300 /* Default log flush delay */
85 #define SILC_SERVER_QOS_RATE_LIMIT 10 /* Default QoS rate limit */
86 #define SILC_SERVER_QOS_BYTES_LIMIT 2048 /* Default QoS bytes limit */
87 #define SILC_SERVER_QOS_LIMIT_SEC 0 /* Default QoS limit sec */
88 #define SILC_SERVER_QOS_LIMIT_USEC 500000 /* Default QoS limit usec */
92 /* This macro is used to send notify messages with formatted string. The
93 string is formatted with arguments and the formatted string is sent as
95 #define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt) \
97 char *__fmt__ = silc_format fmt; \
98 silc_server_send_notify(server, sock, FALSE, \
99 type, 1, __fmt__, strlen(__fmt__)); \
100 silc_free(__fmt__); \
103 /* Send notify to operators */
104 #define SILC_SERVER_SEND_OPERS(server, route, local, type, fmt) \
106 char *__fmt__ = silc_format fmt; \
107 silc_server_send_opers_notify(server, route, local, \
108 type, 1, __fmt__, strlen(__fmt__)); \
109 silc_free(__fmt__); \
112 /* Check whether rekey protocol is active */
113 #define SILC_SERVER_IS_REKEY(sock) \
114 (sock->protocol && sock->protocol->protocol && \
115 sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)
117 /* Check whether backup resuming protocol is active */
118 #define SILC_SERVER_IS_BACKUP(sock) \
119 (sock->protocol && sock->protocol->protocol && \
120 sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_BACKUP)
122 /* Output a message to stderr or to the appropriate log facility wether
123 we are in the background or not. */
124 #define SILC_SERVER_LOG_INFO(fmt) \
125 silc_server_stderr(SILC_LOG_INFO, silc_format fmt)
126 #define SILC_SERVER_LOG_WARNING(fmt) \
127 silc_server_stderr(SILC_LOG_WARNING, silc_format fmt)
128 #define SILC_SERVER_LOG_ERROR(fmt) \
129 silc_server_stderr(SILC_LOG_ERROR, silc_format fmt)
130 #define SILC_SERVER_LOG_FATAL(fmt) \
131 silc_server_stderr(SILC_LOG_WARNING, silc_format fmt)
134 int silc_server_alloc(SilcServer *new_server);
135 void silc_server_free(SilcServer server);
136 bool silc_server_init(SilcServer server);
137 bool silc_server_rehash(SilcServer server);
138 void silc_server_run(SilcServer server);
139 void silc_server_stop(SilcServer server);
140 void silc_server_start_key_exchange(SilcServer server,
141 SilcServerConnection sconn,
143 bool silc_server_packet_parse(SilcPacketParserContext *parser_context,
145 void silc_server_packet_parse_type(SilcServer server,
146 SilcSocketConnection sock,
147 SilcPacketContext *packet);
148 void silc_server_create_connection(SilcServer server,
149 const char *remote_host, SilcUInt32 port);
150 void silc_server_close_connection(SilcServer server,
151 SilcSocketConnection sock);
152 void silc_server_free_client_data(SilcServer server,
153 SilcSocketConnection sock,
154 SilcClientEntry client,
156 const char *signoff);
157 void silc_server_free_sock_user_data(SilcServer server,
158 SilcSocketConnection sock,
159 const char *signoff_message);
160 void silc_server_remove_from_channels(SilcServer server,
161 SilcSocketConnection sock,
162 SilcClientEntry client,
164 const char *signoff_message,
165 bool keygen, bool killed);
166 bool silc_server_remove_from_one_channel(SilcServer server,
167 SilcSocketConnection sock,
168 SilcChannelEntry channel,
169 SilcClientEntry client,
171 void silc_server_disconnect_remote(SilcServer server,
172 SilcSocketConnection sock,
173 SilcStatus status, ...);
174 SilcChannelEntry silc_server_create_new_channel(SilcServer server,
175 SilcServerID *router_id,
181 silc_server_create_new_channel_with_id(SilcServer server,
185 SilcChannelID *channel_id,
187 bool silc_server_create_channel_key(SilcServer server,
188 SilcChannelEntry channel,
190 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
191 SilcBuffer key_payload,
192 SilcChannelEntry channel);
193 void silc_server_perform_heartbeat(SilcSocketConnection sock,
195 void silc_server_announce_get_channel_topic(SilcServer server,
196 SilcChannelEntry channel,
198 void silc_server_announce_get_channel_users(SilcServer server,
199 SilcChannelEntry channel,
200 SilcBuffer *channel_modes,
201 SilcBuffer *channel_users,
202 SilcBuffer *channel_users_modes);
203 void silc_server_announce_get_channels(SilcServer server,
205 SilcBuffer *channels,
206 SilcBuffer **channel_modes,
207 SilcBuffer *channel_users,
208 SilcBuffer **channel_users_modes,
209 SilcUInt32 *channel_users_modes_c,
210 SilcBuffer **channel_topics,
211 SilcBuffer **channel_invites,
212 SilcBuffer **channel_bans,
213 SilcChannelID ***channel_ids,
214 unsigned long creation_time);
215 void silc_server_announce_servers(SilcServer server, bool global,
216 unsigned long creation_time,
217 SilcSocketConnection remote);
218 void silc_server_announce_clients(SilcServer server,
219 unsigned long creation_time,
220 SilcSocketConnection remote);
221 void silc_server_announce_channels(SilcServer server,
222 unsigned long creation_time,
223 SilcSocketConnection remote);
224 void silc_server_announce_watches(SilcServer server,
225 SilcSocketConnection remote);
226 bool silc_server_get_users_on_channel(SilcServer server,
227 SilcChannelEntry channel,
228 SilcBuffer *user_list,
229 SilcBuffer *mode_list,
230 SilcUInt32 *user_count);
231 void silc_server_save_users_on_channel(SilcServer server,
232 SilcSocketConnection sock,
233 SilcChannelEntry channel,
235 SilcBuffer user_list,
236 SilcBuffer mode_list,
237 SilcUInt32 user_count);
238 void silc_server_save_user_channels(SilcServer server,
239 SilcSocketConnection sock,
240 SilcClientEntry client,
242 SilcBuffer channels_user_modes);
244 silc_server_get_client_route(SilcServer server,
245 unsigned char *id_data,
247 SilcClientID *client_id,
248 SilcIDListData *idata,
249 SilcClientEntry *client_entry);
250 SilcBuffer silc_server_get_client_channel_list(SilcServer server,
251 SilcClientEntry client,
254 SilcBuffer *user_mode_list);
255 void silc_server_stderr(SilcLogType type, char *message);