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. */
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 /* Back pointer to server */
56 SilcServerConnectRouterCallback callback;
57 void *callback_context;
58 } *SilcServerConnection;
60 /* General definitions */
63 #define SILC_PORT 768;
65 /* Server and router. Used internally by the code. */
68 #define SILC_BACKUP_ROUTER 2
70 /* Default parameter values */
72 /* Connection retry timeout. We implement exponential backoff algorithm
73 in connection retry. The interval of timeout grows when retry count
75 #define SILC_SERVER_RETRY_COUNT 7 /* Max retry count */
76 #define SILC_SERVER_RETRY_MULTIPLIER 2 /* Interval growth */
77 #define SILC_SERVER_RETRY_RANDOMIZER 2 /* timeout += rnd % 2 */
78 #define SILC_SERVER_RETRY_INTERVAL_MIN 10 /* Min retry timeout */
79 #define SILC_SERVER_RETRY_INTERVAL_MAX 600 /* Max generated timeout */
81 #define SILC_SERVER_KEEPALIVE 300 /* Heartbeat interval */
82 #define SILC_SERVER_CHANNEL_REKEY 3600 /* Channel rekey interval */
83 #define SILC_SERVER_REKEY 3600 /* Session rekey interval */
84 #define SILC_SERVER_SKE_TIMEOUT 60 /* SKE timeout */
85 #define SILC_SERVER_CONNAUTH_TIMEOUT 60 /* CONN_AUTH timeout */
86 #define SILC_SERVER_MAX_CONNECTIONS 1000 /* Max connections */
87 #define SILC_SERVER_MAX_CONNECTIONS_SINGLE 1000 /* Max connections per host */
88 #define SILC_SERVER_LOG_FLUSH_DELAY 300 /* Default log flush delay */
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 /* Check whether rekey protocol is active */
104 #define SILC_SERVER_IS_REKEY(sock) \
105 (sock->protocol && sock->protocol->protocol && \
106 sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)
108 /* Output an error message wether to stderr or LOG_ERROR if we are in the
110 #define SILC_SERVER_LOG_ERROR(fmt) silc_server_stderr(silc_format fmt)
113 int silc_server_alloc(SilcServer *new_server);
114 void silc_server_free(SilcServer server);
115 bool silc_server_init(SilcServer server);
116 bool silc_server_rehash(SilcServer server);
117 void silc_server_run(SilcServer server);
118 void silc_server_stop(SilcServer server);
119 void silc_server_start_key_exchange(SilcServer server,
120 SilcServerConnection sconn,
122 bool silc_server_packet_parse(SilcPacketParserContext *parser_context,
124 void silc_server_packet_parse_type(SilcServer server,
125 SilcSocketConnection sock,
126 SilcPacketContext *packet);
127 void silc_server_create_connection(SilcServer server,
128 const char *remote_host, SilcUInt32 port);
129 void silc_server_close_connection(SilcServer server,
130 SilcSocketConnection sock);
131 void silc_server_free_client_data(SilcServer server,
132 SilcSocketConnection sock,
133 SilcClientEntry client,
135 const char *signoff);
136 void silc_server_free_sock_user_data(SilcServer server,
137 SilcSocketConnection sock,
138 const char *signoff_message);
139 void silc_server_remove_from_channels(SilcServer server,
140 SilcSocketConnection sock,
141 SilcClientEntry client,
143 char *signoff_message,
145 int silc_server_remove_from_one_channel(SilcServer server,
146 SilcSocketConnection sock,
147 SilcChannelEntry channel,
148 SilcClientEntry client,
150 void silc_server_disconnect_remote(SilcServer server,
151 SilcSocketConnection sock,
152 const char *fmt, ...);
153 SilcChannelEntry silc_server_create_new_channel(SilcServer server,
154 SilcServerID *router_id,
160 silc_server_create_new_channel_with_id(SilcServer server,
164 SilcChannelID *channel_id,
166 bool silc_server_create_channel_key(SilcServer server,
167 SilcChannelEntry channel,
169 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
170 SilcBuffer key_payload,
171 SilcChannelEntry channel);
172 void silc_server_perform_heartbeat(SilcSocketConnection sock,
174 void silc_server_announce_get_channel_topic(SilcServer server,
175 SilcChannelEntry channel,
177 void silc_server_announce_get_channel_users(SilcServer server,
178 SilcChannelEntry channel,
179 SilcBuffer *channel_users,
180 SilcBuffer *channel_users_modes);
181 void silc_server_announce_get_channels(SilcServer server,
183 SilcBuffer *channels,
184 SilcBuffer *channel_users,
185 SilcBuffer **channel_users_modes,
186 SilcUInt32 *channel_users_modes_c,
187 SilcBuffer **channel_topics,
188 SilcChannelID ***channel_ids,
189 unsigned long creation_time);
190 void silc_server_announce_servers(SilcServer server, bool global,
191 unsigned long creation_time,
192 SilcSocketConnection remote);
193 void silc_server_announce_clients(SilcServer server,
194 unsigned long creation_time,
195 SilcSocketConnection remote);
196 void silc_server_announce_channels(SilcServer server,
197 unsigned long creation_time,
198 SilcSocketConnection remote);
199 void silc_server_get_users_on_channel(SilcServer server,
200 SilcChannelEntry channel,
201 SilcBuffer *user_list,
202 SilcBuffer *mode_list,
203 SilcUInt32 *user_count);
204 void silc_server_save_users_on_channel(SilcServer server,
205 SilcSocketConnection sock,
206 SilcChannelEntry channel,
208 SilcBuffer user_list,
209 SilcBuffer mode_list,
210 SilcUInt32 user_count);
212 silc_server_get_client_route(SilcServer server,
213 unsigned char *id_data,
215 SilcClientID *client_id,
216 SilcIDListData *idata,
217 SilcClientEntry *client_entry);
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,
223 void silc_server_stderr(char *message);