5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2001 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 for SILC Server object. The actual object is
25 defined in internal header file for server routines. I want to keep
26 the object private hence this declaration. */
27 typedef struct SilcServerStruct *SilcServer;
29 /* Forward declaration of backup server context */
30 typedef struct SilcServerBackupStruct *SilcServerBackup;
32 /* Callback function that is called after the key exchange and connection
33 authentication protocols has been completed with a remote router. The
34 `server_entry' is the remote router entry. */
35 typedef void (*SilcServerConnectRouterCallback)(SilcServer server,
36 SilcServerEntry server_entry,
39 /* Connection structure used when connection to remote */
41 SilcSocketConnection sock;
43 /* Remote host name and port */
47 char *backup_replace_ip;
48 int backup_replace_port;
51 /* Connection configuration (maybe NULL), and connection params */
55 /* Current connection retry info */
56 SilcUInt32 retry_count;
57 SilcUInt32 retry_timeout;
59 /* Back pointer to server */
62 SilcServerConnectRouterCallback callback;
63 void *callback_context;
64 } *SilcServerConnection;
66 /* General definitions */
69 #define SILC_PORT 768;
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 */
97 /* This macro is used to send notify messages with formatted string. The
98 string is formatted with arguments and the formatted string is sent as
100 #define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt) \
102 char *__fmt__ = silc_format fmt; \
103 silc_server_send_notify(server, sock, FALSE, \
104 type, 1, __fmt__, strlen(__fmt__)); \
105 silc_free(__fmt__); \
108 /* Check whether rekey protocol is active */
109 #define SILC_SERVER_IS_REKEY(sock) \
110 (sock->protocol && sock->protocol->protocol && \
111 sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)
114 int silc_server_alloc(SilcServer *new_server);
115 void silc_server_free(SilcServer server);
116 int silc_server_init(SilcServer server);
117 void silc_server_daemonise(SilcServer server);
118 void silc_server_drop(SilcServer server);
119 void silc_server_run(SilcServer server);
120 void silc_server_stop(SilcServer server);
121 void silc_server_start_key_exchange(SilcServer server,
122 SilcServerConnection sconn,
124 bool silc_server_packet_parse(SilcPacketParserContext *parser_context,
126 void silc_server_packet_parse_type(SilcServer server,
127 SilcSocketConnection sock,
128 SilcPacketContext *packet);
129 void silc_server_create_connection(SilcServer server,
130 const char *remote_host, SilcUInt32 port);
131 void silc_server_close_connection(SilcServer server,
132 SilcSocketConnection sock);
133 void silc_server_free_client_data(SilcServer server,
134 SilcSocketConnection sock,
135 SilcClientEntry client,
137 const char *signoff);
138 void silc_server_free_sock_user_data(SilcServer server,
139 SilcSocketConnection sock,
140 const char *signoff_message);
141 void silc_server_remove_from_channels(SilcServer server,
142 SilcSocketConnection sock,
143 SilcClientEntry client,
145 char *signoff_message,
147 int silc_server_remove_from_one_channel(SilcServer server,
148 SilcSocketConnection sock,
149 SilcChannelEntry channel,
150 SilcClientEntry client,
152 void silc_server_disconnect_remote(SilcServer server,
153 SilcSocketConnection sock,
154 const char *fmt, ...);
155 SilcChannelEntry silc_server_create_new_channel(SilcServer server,
156 SilcServerID *router_id,
162 silc_server_create_new_channel_with_id(SilcServer server,
166 SilcChannelID *channel_id,
168 bool silc_server_create_channel_key(SilcServer server,
169 SilcChannelEntry channel,
171 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
172 SilcBuffer key_payload,
173 SilcChannelEntry channel);
174 void silc_server_perform_heartbeat(SilcSocketConnection sock,
176 void silc_server_announce_get_channel_topic(SilcServer server,
177 SilcChannelEntry channel,
179 void silc_server_announce_get_channel_users(SilcServer server,
180 SilcChannelEntry channel,
181 SilcBuffer *channel_users,
182 SilcBuffer *channel_users_modes);
183 void silc_server_announce_get_channels(SilcServer server,
185 SilcBuffer *channels,
186 SilcBuffer *channel_users,
187 SilcBuffer **channel_users_modes,
188 SilcUInt32 *channel_users_modes_c,
189 SilcBuffer **channel_topics,
190 SilcChannelID ***channel_ids,
191 unsigned long creation_time);
192 void silc_server_announce_servers(SilcServer server, bool global,
193 unsigned long creation_time,
194 SilcSocketConnection remote);
195 void silc_server_announce_clients(SilcServer server,
196 unsigned long creation_time,
197 SilcSocketConnection remote);
198 void silc_server_announce_channels(SilcServer server,
199 unsigned long creation_time,
200 SilcSocketConnection remote);
201 void silc_server_get_users_on_channel(SilcServer server,
202 SilcChannelEntry channel,
203 SilcBuffer *user_list,
204 SilcBuffer *mode_list,
205 SilcUInt32 *user_count);
206 void silc_server_save_users_on_channel(SilcServer server,
207 SilcSocketConnection sock,
208 SilcChannelEntry channel,
210 SilcBuffer user_list,
211 SilcBuffer mode_list,
212 SilcUInt32 user_count);
213 SilcSocketConnection silc_server_get_client_route(SilcServer server,
214 unsigned char *id_data,
216 SilcClientID *client_id,
217 SilcIDListData *idata);
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,