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 #define SILC_SERVER_MAX_CONNECTIONS 1000
34 /* General definitions */
37 #define SILC_PORT 768;
39 /* Server and router. Used internally by the code. */
42 #define SILC_BACKUP_ROUTER 2
44 /* Connection retry timeout. We implement exponential backoff algorithm
45 in connection retry. The interval of timeuot grows when retry count
47 #define SILC_SERVER_RETRY_COUNT 4 /* Max retry count */
48 #define SILC_SERVER_RETRY_MULTIPLIER 7 / 4 /* Interval growth */
49 #define SILC_SERVER_RETRY_RANDOMIZER 2 /* timeout += rnd % 2 */
50 #define SILC_SERVER_RETRY_INTERVAL_MIN 10 /* Min retry timeout */
51 #define SILC_SERVER_RETRY_INTERVAL_MAX 600 /* Max generated timeout */
56 Structure to hold various default parameters for server that can be
57 given before running the server.
62 uint32 retry_interval_min;
63 uint32 retry_interval_min_usec;
64 uint32 retry_interval_max;
65 char retry_keep_trying;
67 uint32 protocol_timeout;
68 uint32 protocol_timeout_usec;
70 char require_reverse_mapping;
73 /* Callback function that is called after the key exchange and connection
74 authentication protocols has been completed with a remote router. The
75 `server_entry' is the remote router entry. */
76 typedef void (*SilcServerConnectRouterCallback)(SilcServer server,
77 SilcServerEntry server_entry,
81 SilcSocketConnection sock;
83 /* Remote host name and port */
87 char *backup_replace_ip;
88 int backup_replace_port;
90 /* Current connection retry info */
94 /* Back pointer to server */
97 SilcServerConnectRouterCallback callback;
98 void *callback_context;
99 } *SilcServerConnection;
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 /* Check whether rekey protocol is active */
115 #define SILC_SERVER_IS_REKEY(sock) \
116 (sock->protocol && sock->protocol->protocol && \
117 sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)
120 int silc_server_alloc(SilcServer *new_server);
121 void silc_server_free(SilcServer server);
122 int silc_server_init(SilcServer server);
123 void silc_server_daemonise(SilcServer server);
124 void silc_server_run(SilcServer server);
125 void silc_server_stop(SilcServer server);
126 void silc_server_start_key_exchange(SilcServer server,
127 SilcServerConnection sconn,
129 void silc_server_packet_parse(SilcPacketParserContext *parser_context);
130 void silc_server_packet_parse_type(SilcServer server,
131 SilcSocketConnection sock,
132 SilcPacketContext *packet);
133 void silc_server_create_connection(SilcServer server,
134 char *remote_host, uint32 port);
135 void silc_server_close_connection(SilcServer server,
136 SilcSocketConnection sock);
137 void silc_server_free_client_data(SilcServer server,
138 SilcSocketConnection sock,
139 SilcClientEntry client,
142 void silc_server_free_sock_user_data(SilcServer server,
143 SilcSocketConnection sock);
144 void silc_server_remove_from_channels(SilcServer server,
145 SilcSocketConnection sock,
146 SilcClientEntry client,
148 char *signoff_message,
150 int silc_server_remove_from_one_channel(SilcServer server,
151 SilcSocketConnection sock,
152 SilcChannelEntry channel,
153 SilcClientEntry client,
155 void silc_server_disconnect_remote(SilcServer server,
156 SilcSocketConnection sock,
157 const char *fmt, ...);
158 SilcChannelEntry silc_server_create_new_channel(SilcServer server,
159 SilcServerID *router_id,
165 silc_server_create_new_channel_with_id(SilcServer server,
169 SilcChannelID *channel_id,
171 bool silc_server_create_channel_key(SilcServer server,
172 SilcChannelEntry channel,
174 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
175 SilcBuffer key_payload,
176 SilcChannelEntry channel);
177 void silc_server_perform_heartbeat(SilcSocketConnection sock,
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 uint32 *channel_users_modes_c,
189 SilcChannelID ***channel_ids,
190 unsigned long creation_time);
191 void silc_server_announce_servers(SilcServer server, bool global,
192 unsigned long creation_time,
193 SilcSocketConnection remote);
194 void silc_server_announce_clients(SilcServer server,
195 unsigned long creation_time,
196 SilcSocketConnection remote);
197 void silc_server_announce_channels(SilcServer server,
198 unsigned long creation_time,
199 SilcSocketConnection remote);
200 void silc_server_get_users_on_channel(SilcServer server,
201 SilcChannelEntry channel,
202 SilcBuffer *user_list,
203 SilcBuffer *mode_list,
205 void silc_server_save_users_on_channel(SilcServer server,
206 SilcSocketConnection sock,
207 SilcChannelEntry channel,
209 SilcBuffer user_list,
210 SilcBuffer mode_list,
212 SilcSocketConnection silc_server_get_client_route(SilcServer server,
213 unsigned char *id_data,
215 SilcClientID *client_id,
216 SilcIDListData *idata);
217 SilcBuffer silc_server_get_client_channel_list(SilcServer server,
218 SilcClientEntry client);
219 SilcClientEntry silc_server_get_client_resolve(SilcServer server,
220 SilcClientID *client_id);