5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2005, 2007 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 declarations */
24 typedef struct SilcServerEntryStruct *SilcServerEntry;
25 typedef struct SilcClientEntryStruct *SilcClientEntry;
26 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
27 typedef struct SilcServerBackupStruct *SilcServerBackup;
28 typedef struct SilcIDListDataObject *SilcIDListData, SilcIDListDataStruct;
29 typedef struct SilcIDListStruct *SilcIDList;
31 /* Callback function that is called after the key exchange and connection
32 authentication protocols has been completed with a remote router. The
33 `server_entry' is the remote router entry or NULL on error. */
34 typedef void (*SilcServerConnectCallback)(SilcServer server,
35 SilcServerEntry server_entry,
38 /* Connection structure used when connection to remote */
39 typedef struct SilcServerConnectionStruct {
42 SilcPacketStream sock;
43 SilcAsyncOperation op;
44 SilcServerConfigRef conn;
49 char *backup_replace_ip;
50 int backup_replace_port;
52 /* Current connection retry info */
53 SilcUInt32 retry_count;
54 SilcUInt32 retry_timeout;
55 SilcServerConnectCallback callback;
56 void *callback_context;
59 unsigned int backup : 1; /* Set when backup router connection */
60 unsigned int backup_resuming : 1; /* Set when running resuming protocol */
61 unsigned int no_reconnect : 1; /* Set when to not reconnect */
62 unsigned int no_conf : 1; /* Set when connecting without pre-
64 } *SilcServerConnection;
66 /* General definitions */
71 /* Server and router. Used internally by the code. */
74 #define SILC_BACKUP_ROUTER 2
76 /* Default parameter values */
78 /* Connection retry timeout. We implement exponential backoff algorithm
79 in connection retry. The interval of timeout grows when retry count
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 */
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 #define SILC_SERVER_LOG_FLUSH_DELAY 300 /* Default log flush delay */
95 #define SILC_SERVER_QOS_RATE_LIMIT 10 /* Default QoS rate limit */
96 #define SILC_SERVER_QOS_BYTES_LIMIT 2048 /* Default QoS bytes limit */
97 #define SILC_SERVER_QOS_LIMIT_SEC 0 /* Default QoS limit sec */
98 #define SILC_SERVER_QOS_LIMIT_USEC 500000 /* Default QoS limit usec */
99 #define SILC_SERVER_CH_JOIN_LIMIT 50 /* Default join limit */
103 /* This macro is used to send notify messages with formatted string. The
104 string is formatted with arguments and the formatted string is sent as
106 #define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt) \
108 char *__fmt__ = silc_format fmt; \
109 silc_server_send_notify(server, sock, FALSE, \
110 type, 1, __fmt__, strlen(__fmt__)); \
111 silc_free(__fmt__); \
114 /* Send notify to operators */
115 #define SILC_SERVER_SEND_OPERS(server, route, local, type, fmt) \
117 char *__fmt__ = silc_format fmt; \
118 silc_server_send_opers_notify(server, route, local, \
119 type, 1, __fmt__, strlen(__fmt__)); \
120 silc_free(__fmt__); \
123 /* Check whether rekey protocol is active */
124 #define SILC_SERVER_IS_REKEY(sock) \
125 (sock->protocol && sock->protocol->protocol && \
126 sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)
128 /* Output a message to stderr or to the appropriate log facility wether
129 we are in the background or not. */
130 #define SILC_SERVER_LOG_INFO(fmt) \
131 silc_server_stderr(SILC_LOG_INFO, silc_format fmt)
132 #define SILC_SERVER_LOG_WARNING(fmt) \
133 silc_server_stderr(SILC_LOG_WARNING, silc_format fmt)
134 #define SILC_SERVER_LOG_ERROR(fmt) \
135 silc_server_stderr(SILC_LOG_ERROR, silc_format fmt)
136 #define SILC_SERVER_LOG_FATAL(fmt) \
137 silc_server_stderr(SILC_LOG_WARNING, silc_format fmt)
140 SilcBool silc_server_alloc(SilcServer *new_server);
141 void silc_server_free(SilcServer server);
142 SilcBool silc_server_init(SilcServer server);
143 SilcBool silc_server_rehash(SilcServer server);
144 void silc_server_run(SilcServer server);
145 void silc_server_stop(SilcServer server);
146 void silc_server_start_key_exchange(SilcServerConnection sconn);
147 void silc_server_create_connection(SilcServer server,
149 const char *remote_host, SilcUInt32 port,
150 SilcServerConnectCallback callback,
152 void silc_server_close_connection(SilcServer server,
153 SilcPacketStream sock);
154 void silc_server_free_client_data(SilcServer server,
155 SilcPacketStream sock,
156 SilcClientEntry client,
158 const char *signoff);
159 void silc_server_free_sock_user_data(SilcServer server,
160 SilcPacketStream sock,
161 const char *signoff_message);
162 void silc_server_remove_from_channels(SilcServer server,
163 SilcPacketStream sock,
164 SilcClientEntry client,
166 const char *signoff_message,
167 SilcBool keygen, bool killed);
168 SilcBool silc_server_remove_from_one_channel(SilcServer server,
169 SilcPacketStream sock,
170 SilcChannelEntry channel,
171 SilcClientEntry client,
173 void silc_server_disconnect_remote(SilcServer server,
174 SilcPacketStream sock,
175 SilcStatus status, ...);
176 SilcChannelEntry silc_server_create_new_channel(SilcServer server,
177 SilcServerID *router_id,
183 silc_server_create_new_channel_with_id(SilcServer server,
187 SilcChannelID *channel_id,
189 SilcBool silc_server_create_channel_key(SilcServer server,
190 SilcChannelEntry channel,
192 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
193 SilcBuffer key_payload,
194 SilcChannelEntry channel);
195 void silc_server_perform_heartbeat(SilcPacketStream sock,
197 void silc_server_announce_get_channel_topic(SilcServer server,
198 SilcChannelEntry channel,
200 void silc_server_announce_get_channel_users(SilcServer server,
201 SilcChannelEntry channel,
202 SilcBuffer *channel_modes,
203 SilcBuffer *channel_users,
204 SilcBuffer *channel_users_modes);
205 void silc_server_announce_get_channels(SilcServer server,
207 SilcBuffer *channels,
208 SilcBuffer **channel_modes,
209 SilcBuffer *channel_users,
210 SilcBuffer **channel_users_modes,
211 SilcUInt32 *channel_users_modes_c,
212 SilcBuffer **channel_topics,
213 SilcBuffer **channel_invites,
214 SilcBuffer **channel_bans,
215 SilcChannelID ***channel_ids,
216 unsigned long creation_time);
217 void silc_server_announce_servers(SilcServer server, SilcBool global,
218 unsigned long creation_time,
219 SilcPacketStream remote);
220 void silc_server_announce_clients(SilcServer server,
221 unsigned long creation_time,
222 SilcPacketStream remote);
223 void silc_server_announce_channels(SilcServer server,
224 unsigned long creation_time,
225 SilcPacketStream remote);
226 void silc_server_announce_watches(SilcServer server,
227 SilcPacketStream remote);
228 SilcBool silc_server_get_users_on_channel(SilcServer server,
229 SilcChannelEntry channel,
230 SilcBuffer *user_list,
231 SilcBuffer *mode_list,
232 SilcUInt32 *user_count);
233 void silc_server_save_users_on_channel(SilcServer server,
234 SilcPacketStream sock,
235 SilcChannelEntry channel,
237 SilcBuffer user_list,
238 SilcBuffer mode_list,
239 SilcUInt32 user_count);
240 void silc_server_save_user_channels(SilcServer server,
241 SilcPacketStream sock,
242 SilcClientEntry client,
244 SilcBuffer channels_user_modes);
246 silc_server_get_client_route(SilcServer server,
247 unsigned char *id_data,
249 SilcClientID *client_id,
250 SilcIDListData *idata,
251 SilcClientEntry *client_entry);
252 SilcBuffer silc_server_get_client_channel_list(SilcServer server,
253 SilcClientEntry client,
254 SilcBool get_private,
256 SilcBuffer *user_mode_list);
257 void silc_server_stderr(SilcLogType type, char *message);
258 void silc_server_http_init(SilcServer server);
259 void silc_server_http_uninit(SilcServer server);