5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2002 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; either version 2 of the License, or
12 (at your option) any later version.
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.
24 /* Forward declaration of backup server context */
25 typedef struct SilcServerBackupStruct *SilcServerBackup;
27 /* Callback function that is called after the key exchange and connection
28 authentication protocols has been completed with a remote router. The
29 `server_entry' is the remote router entry or NULL on error. */
30 typedef void (*SilcServerConnectRouterCallback)(SilcServer server,
31 SilcServerEntry server_entry,
34 /* Connection structure used when connection to remote */
36 SilcSocketConnection sock;
38 /* Remote host name and port */
42 char *backup_replace_ip;
43 int backup_replace_port;
46 /* Connection configuration (maybe NULL) */
47 SilcServerConfigRef conn;
49 /* Current connection retry info */
50 SilcUInt32 retry_count;
51 SilcUInt32 retry_timeout;
53 SilcServerConnectRouterCallback callback;
54 void *callback_context;
55 } *SilcServerConnection;
57 /* General definitions */
62 /* Server and router. Used internally by the code. */
65 #define SILC_BACKUP_ROUTER 2
67 /* Default parameter values */
69 /* Connection retry timeout. We implement exponential backoff algorithm
70 in connection retry. The interval of timeout grows when retry count
72 #define SILC_SERVER_RETRY_COUNT 7 /* Max retry count */
73 #define SILC_SERVER_RETRY_MULTIPLIER 2 /* Interval growth */
74 #define SILC_SERVER_RETRY_RANDOMIZER 2 /* timeout += rnd % 2 */
75 #define SILC_SERVER_RETRY_INTERVAL_MIN 10 /* Min retry timeout */
76 #define SILC_SERVER_RETRY_INTERVAL_MAX 600 /* Max generated timeout */
78 #define SILC_SERVER_KEEPALIVE 300 /* Heartbeat interval */
79 #define SILC_SERVER_CHANNEL_REKEY 3600 /* Channel rekey interval */
80 #define SILC_SERVER_REKEY 3600 /* Session rekey interval */
81 #define SILC_SERVER_SKE_TIMEOUT 60 /* SKE timeout */
82 #define SILC_SERVER_CONNAUTH_TIMEOUT 60 /* CONN_AUTH timeout */
83 #define SILC_SERVER_MAX_CONNECTIONS 1000 /* Max connections */
84 #define SILC_SERVER_MAX_CONNECTIONS_SINGLE 1000 /* Max connections per host */
85 #define SILC_SERVER_LOG_FLUSH_DELAY 300 /* Default log flush delay */
86 #define SILC_SERVER_QOS_RATE_LIMIT 10 /* Default QoS rate limit */
87 #define SILC_SERVER_QOS_BYTES_LIMIT 2048 /* Default QoS bytes limit */
88 #define SILC_SERVER_QOS_LIMIT_SEC 0 /* Default QoS limit sec */
89 #define SILC_SERVER_QOS_LIMIT_USEC 500000 /* Default QoS limit usec */
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 /* Output an error message wether to stderr or LOG_ERROR if we are in the
120 #define SILC_SERVER_LOG_ERROR(fmt) silc_server_stderr(silc_format fmt)
123 int silc_server_alloc(SilcServer *new_server);
124 void silc_server_free(SilcServer server);
125 bool silc_server_init(SilcServer server);
126 bool silc_server_rehash(SilcServer server);
127 void silc_server_run(SilcServer server);
128 void silc_server_stop(SilcServer server);
129 void silc_server_start_key_exchange(SilcServer server,
130 SilcServerConnection sconn,
132 bool silc_server_packet_parse(SilcPacketParserContext *parser_context,
134 void silc_server_packet_parse_type(SilcServer server,
135 SilcSocketConnection sock,
136 SilcPacketContext *packet);
137 void silc_server_create_connection(SilcServer server,
138 const char *remote_host, SilcUInt32 port);
139 void silc_server_close_connection(SilcServer server,
140 SilcSocketConnection sock);
141 void silc_server_free_client_data(SilcServer server,
142 SilcSocketConnection sock,
143 SilcClientEntry client,
145 const char *signoff);
146 void silc_server_free_sock_user_data(SilcServer server,
147 SilcSocketConnection sock,
148 const char *signoff_message);
149 void silc_server_remove_from_channels(SilcServer server,
150 SilcSocketConnection sock,
151 SilcClientEntry client,
153 const char *signoff_message,
155 bool silc_server_remove_from_one_channel(SilcServer server,
156 SilcSocketConnection sock,
157 SilcChannelEntry channel,
158 SilcClientEntry client,
160 void silc_server_disconnect_remote(SilcServer server,
161 SilcSocketConnection sock,
162 SilcStatus status, ...);
163 SilcChannelEntry silc_server_create_new_channel(SilcServer server,
164 SilcServerID *router_id,
170 silc_server_create_new_channel_with_id(SilcServer server,
174 SilcChannelID *channel_id,
176 bool silc_server_create_channel_key(SilcServer server,
177 SilcChannelEntry channel,
179 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
180 SilcBuffer key_payload,
181 SilcChannelEntry channel);
182 void silc_server_perform_heartbeat(SilcSocketConnection sock,
184 void silc_server_announce_get_channel_topic(SilcServer server,
185 SilcChannelEntry channel,
187 void silc_server_announce_get_channel_users(SilcServer server,
188 SilcChannelEntry channel,
189 SilcBuffer *channel_modes,
190 SilcBuffer *channel_users,
191 SilcBuffer *channel_users_modes);
192 void silc_server_announce_get_channels(SilcServer server,
194 SilcBuffer *channels,
195 SilcBuffer **channel_modes,
196 SilcBuffer *channel_users,
197 SilcBuffer **channel_users_modes,
198 SilcUInt32 *channel_users_modes_c,
199 SilcBuffer **channel_topics,
200 SilcChannelID ***channel_ids,
201 unsigned long creation_time);
202 void silc_server_announce_servers(SilcServer server, bool global,
203 unsigned long creation_time,
204 SilcSocketConnection remote);
205 void silc_server_announce_clients(SilcServer server,
206 unsigned long creation_time,
207 SilcSocketConnection remote);
208 void silc_server_announce_channels(SilcServer server,
209 unsigned long creation_time,
210 SilcSocketConnection remote);
211 bool silc_server_get_users_on_channel(SilcServer server,
212 SilcChannelEntry channel,
213 SilcBuffer *user_list,
214 SilcBuffer *mode_list,
215 SilcUInt32 *user_count);
216 void silc_server_save_users_on_channel(SilcServer server,
217 SilcSocketConnection sock,
218 SilcChannelEntry channel,
220 SilcBuffer user_list,
221 SilcBuffer mode_list,
222 SilcUInt32 user_count);
223 void silc_server_save_user_channels(SilcServer server,
224 SilcSocketConnection sock,
225 SilcClientEntry client,
227 SilcBuffer channels_user_modes);
229 silc_server_get_client_route(SilcServer server,
230 unsigned char *id_data,
232 SilcClientID *client_id,
233 SilcIDListData *idata,
234 SilcClientEntry *client_entry);
235 SilcBuffer silc_server_get_client_channel_list(SilcServer server,
236 SilcClientEntry client,
239 SilcBuffer *user_mode_list);
240 void silc_server_stderr(char *message);