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 */
89 #define SILC_SERVER_CH_JOIN_LIMIT 50 /* Default join limit */
93 /* This macro is used to send notify messages with formatted string. The
94 string is formatted with arguments and the formatted string is sent as
96 #define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt) \
98 char *__fmt__ = silc_format fmt; \
99 silc_server_send_notify(server, sock, FALSE, \
100 type, 1, __fmt__, strlen(__fmt__)); \
101 silc_free(__fmt__); \
104 /* Send notify to operators */
105 #define SILC_SERVER_SEND_OPERS(server, route, local, type, fmt) \
107 char *__fmt__ = silc_format fmt; \
108 silc_server_send_opers_notify(server, route, local, \
109 type, 1, __fmt__, strlen(__fmt__)); \
110 silc_free(__fmt__); \
113 /* Check whether rekey protocol is active */
114 #define SILC_SERVER_IS_REKEY(sock) \
115 (sock->protocol && sock->protocol->protocol && \
116 sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)
118 /* Check whether backup resuming protocol is active */
119 #define SILC_SERVER_IS_BACKUP(sock) \
120 (sock->protocol && sock->protocol->protocol && \
121 sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_BACKUP)
123 /* Output a message to stderr or to the appropriate log facility wether
124 we are in the background or not. */
125 #define SILC_SERVER_LOG_INFO(fmt) \
126 silc_server_stderr(SILC_LOG_INFO, silc_format fmt)
127 #define SILC_SERVER_LOG_WARNING(fmt) \
128 silc_server_stderr(SILC_LOG_WARNING, silc_format fmt)
129 #define SILC_SERVER_LOG_ERROR(fmt) \
130 silc_server_stderr(SILC_LOG_ERROR, silc_format fmt)
131 #define SILC_SERVER_LOG_FATAL(fmt) \
132 silc_server_stderr(SILC_LOG_WARNING, silc_format fmt)
135 int silc_server_alloc(SilcServer *new_server);
136 void silc_server_free(SilcServer server);
137 bool silc_server_init(SilcServer server);
138 bool silc_server_rehash(SilcServer server);
139 void silc_server_run(SilcServer server);
140 void silc_server_stop(SilcServer server);
141 void silc_server_start_key_exchange(SilcServer server,
142 SilcServerConnection sconn,
144 bool silc_server_packet_parse(SilcPacketParserContext *parser_context,
146 void silc_server_packet_parse_type(SilcServer server,
147 SilcSocketConnection sock,
148 SilcPacketContext *packet);
149 void silc_server_create_connection(SilcServer server,
150 const char *remote_host, SilcUInt32 port);
151 void silc_server_close_connection(SilcServer server,
152 SilcSocketConnection sock);
153 void silc_server_free_client_data(SilcServer server,
154 SilcSocketConnection sock,
155 SilcClientEntry client,
157 const char *signoff);
158 void silc_server_free_sock_user_data(SilcServer server,
159 SilcSocketConnection sock,
160 const char *signoff_message);
161 void silc_server_remove_from_channels(SilcServer server,
162 SilcSocketConnection sock,
163 SilcClientEntry client,
165 const char *signoff_message,
166 bool keygen, bool killed);
167 bool silc_server_remove_from_one_channel(SilcServer server,
168 SilcSocketConnection sock,
169 SilcChannelEntry channel,
170 SilcClientEntry client,
172 void silc_server_disconnect_remote(SilcServer server,
173 SilcSocketConnection sock,
174 SilcStatus status, ...);
175 SilcChannelEntry silc_server_create_new_channel(SilcServer server,
176 SilcServerID *router_id,
182 silc_server_create_new_channel_with_id(SilcServer server,
186 SilcChannelID *channel_id,
188 bool silc_server_create_channel_key(SilcServer server,
189 SilcChannelEntry channel,
191 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
192 SilcBuffer key_payload,
193 SilcChannelEntry channel);
194 void silc_server_perform_heartbeat(SilcSocketConnection sock,
196 void silc_server_announce_get_channel_topic(SilcServer server,
197 SilcChannelEntry channel,
199 void silc_server_announce_get_channel_users(SilcServer server,
200 SilcChannelEntry channel,
201 SilcBuffer *channel_modes,
202 SilcBuffer *channel_users,
203 SilcBuffer *channel_users_modes);
204 void silc_server_announce_get_channels(SilcServer server,
206 SilcBuffer *channels,
207 SilcBuffer **channel_modes,
208 SilcBuffer *channel_users,
209 SilcBuffer **channel_users_modes,
210 SilcUInt32 *channel_users_modes_c,
211 SilcBuffer **channel_topics,
212 SilcBuffer **channel_invites,
213 SilcBuffer **channel_bans,
214 SilcChannelID ***channel_ids,
215 unsigned long creation_time);
216 void silc_server_announce_servers(SilcServer server, bool global,
217 unsigned long creation_time,
218 SilcSocketConnection remote);
219 void silc_server_announce_clients(SilcServer server,
220 unsigned long creation_time,
221 SilcSocketConnection remote);
222 void silc_server_announce_channels(SilcServer server,
223 unsigned long creation_time,
224 SilcSocketConnection remote);
225 void silc_server_announce_watches(SilcServer server,
226 SilcSocketConnection remote);
227 bool silc_server_get_users_on_channel(SilcServer server,
228 SilcChannelEntry channel,
229 SilcBuffer *user_list,
230 SilcBuffer *mode_list,
231 SilcUInt32 *user_count);
232 void silc_server_save_users_on_channel(SilcServer server,
233 SilcSocketConnection sock,
234 SilcChannelEntry channel,
236 SilcBuffer user_list,
237 SilcBuffer mode_list,
238 SilcUInt32 user_count);
239 void silc_server_save_user_channels(SilcServer server,
240 SilcSocketConnection sock,
241 SilcClientEntry client,
243 SilcBuffer channels_user_modes);
245 silc_server_get_client_route(SilcServer server,
246 unsigned char *id_data,
248 SilcClientID *client_id,
249 SilcIDListData *idata,
250 SilcClientEntry *client_entry);
251 SilcBuffer silc_server_get_client_channel_list(SilcServer server,
252 SilcClientEntry client,
255 SilcBuffer *user_mode_list);
256 void silc_server_stderr(SilcLogType type, char *message);