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 */
59 /* Back pointer to server */
62 SilcServerConnectRouterCallback callback;
63 void *callback_context;
64 } *SilcServerConnection;
66 #define SILC_SERVER_MAX_CONNECTIONS 1000
68 /* General definitions */
71 #define SILC_PORT 768;
73 /* Server and router. Used internally by the code. */
76 #define SILC_BACKUP_ROUTER 2
78 /* Default parameter values */
80 /* Connection retry timeout. We implement exponential backoff algorithm
81 in connection retry. The interval of timeout grows when retry count
83 #define SILC_SERVER_RETRY_COUNT 7 /* Max retry count */
84 #define SILC_SERVER_RETRY_MULTIPLIER 2 /* Interval growth */
85 #define SILC_SERVER_RETRY_RANDOMIZER 2 /* timeout += rnd % 2 */
86 #define SILC_SERVER_RETRY_INTERVAL_MIN 10 /* Min retry timeout */
87 #define SILC_SERVER_RETRY_INTERVAL_MAX 600 /* Max generated timeout */
89 #define SILC_SERVER_KEEPALIVE 300 /* Heartbeat interval */
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 /* Check whether rekey protocol is active */
105 #define SILC_SERVER_IS_REKEY(sock) \
106 (sock->protocol && sock->protocol->protocol && \
107 sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)
110 int silc_server_alloc(SilcServer *new_server);
111 void silc_server_free(SilcServer server);
112 int silc_server_init(SilcServer server);
113 void silc_server_daemonise(SilcServer server);
114 void silc_server_drop(SilcServer server);
115 void silc_server_run(SilcServer server);
116 void silc_server_stop(SilcServer server);
117 void silc_server_start_key_exchange(SilcServer server,
118 SilcServerConnection sconn,
120 bool silc_server_packet_parse(SilcPacketParserContext *parser_context,
122 void silc_server_packet_parse_type(SilcServer server,
123 SilcSocketConnection sock,
124 SilcPacketContext *packet);
125 void silc_server_create_connection(SilcServer server,
126 const char *remote_host, uint32 port);
127 void silc_server_close_connection(SilcServer server,
128 SilcSocketConnection sock);
129 void silc_server_free_client_data(SilcServer server,
130 SilcSocketConnection sock,
131 SilcClientEntry client,
133 const char *signoff);
134 void silc_server_free_sock_user_data(SilcServer server,
135 SilcSocketConnection sock,
136 const char *signoff_message);
137 void silc_server_remove_from_channels(SilcServer server,
138 SilcSocketConnection sock,
139 SilcClientEntry client,
141 char *signoff_message,
143 int silc_server_remove_from_one_channel(SilcServer server,
144 SilcSocketConnection sock,
145 SilcChannelEntry channel,
146 SilcClientEntry client,
148 void silc_server_disconnect_remote(SilcServer server,
149 SilcSocketConnection sock,
150 const char *fmt, ...);
151 SilcChannelEntry silc_server_create_new_channel(SilcServer server,
152 SilcServerID *router_id,
158 silc_server_create_new_channel_with_id(SilcServer server,
162 SilcChannelID *channel_id,
164 bool silc_server_create_channel_key(SilcServer server,
165 SilcChannelEntry channel,
167 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
168 SilcBuffer key_payload,
169 SilcChannelEntry channel);
170 void silc_server_perform_heartbeat(SilcSocketConnection sock,
172 void silc_server_announce_get_channel_topic(SilcServer server,
173 SilcChannelEntry channel,
175 void silc_server_announce_get_channel_users(SilcServer server,
176 SilcChannelEntry channel,
177 SilcBuffer *channel_users,
178 SilcBuffer *channel_users_modes);
179 void silc_server_announce_get_channels(SilcServer server,
181 SilcBuffer *channels,
182 SilcBuffer *channel_users,
183 SilcBuffer **channel_users_modes,
184 uint32 *channel_users_modes_c,
185 SilcBuffer **channel_topics,
186 SilcChannelID ***channel_ids,
187 unsigned long creation_time);
188 void silc_server_announce_servers(SilcServer server, bool global,
189 unsigned long creation_time,
190 SilcSocketConnection remote);
191 void silc_server_announce_clients(SilcServer server,
192 unsigned long creation_time,
193 SilcSocketConnection remote);
194 void silc_server_announce_channels(SilcServer server,
195 unsigned long creation_time,
196 SilcSocketConnection remote);
197 void silc_server_get_users_on_channel(SilcServer server,
198 SilcChannelEntry channel,
199 SilcBuffer *user_list,
200 SilcBuffer *mode_list,
202 void silc_server_save_users_on_channel(SilcServer server,
203 SilcSocketConnection sock,
204 SilcChannelEntry channel,
206 SilcBuffer user_list,
207 SilcBuffer mode_list,
209 SilcSocketConnection silc_server_get_client_route(SilcServer server,
210 unsigned char *id_data,
212 SilcClientID *client_id,
213 SilcIDListData *idata);
214 SilcBuffer silc_server_get_client_channel_list(SilcServer server,
215 SilcClientEntry client);
216 SilcClientEntry silc_server_get_client_resolve(SilcServer server,
217 SilcClientID *client_id,