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 #define SILC_SERVER_MAX_CONNECTIONS 10000
31 /* General definitions */
34 #define SILC_PORT 768;
36 /* Server and router. Used internally by the code. */
40 /* Connection retry timeout. We implement exponential backoff algorithm
41 in connection retry. The interval of timeuot grows when retry count
43 #define SILC_SERVER_RETRY_COUNT 4 /* Max retry count */
44 #define SILC_SERVER_RETRY_MULTIPLIER 7 / 4 /* Interval growth */
45 #define SILC_SERVER_RETRY_RANDOMIZER 2 /* timeout += rnd % 2 */
46 #define SILC_SERVER_RETRY_INTERVAL_MIN 10 /* Min retry timeout */
47 #define SILC_SERVER_RETRY_INTERVAL_MAX 600 /* Max generated timeout */
52 Structure to hold various default parameters for server that can be
53 given before running the server.
58 uint32 retry_interval_min;
59 uint32 retry_interval_min_usec;
60 uint32 retry_interval_max;
61 char retry_keep_trying;
63 uint32 protocol_timeout;
64 uint32 protocol_timeout_usec;
66 char require_reverse_mapping;
71 /* This macro is used to send notify messages with formatted string. The
72 string is formatted with arguments and the formatted string is sent as
74 #define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt) \
76 char *__fmt__ = silc_format fmt; \
77 silc_server_send_notify(server, sock, FALSE, \
78 type, 1, __fmt__, strlen(__fmt__)); \
82 /* Check whether rekey protocol is active */
83 #define SILC_SERVER_IS_REKEY(sock) \
84 (sock->protocol && sock->protocol->protocol && \
85 sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)
88 int silc_server_alloc(SilcServer *new_server);
89 void silc_server_free(SilcServer server);
90 int silc_server_init(SilcServer server);
91 void silc_server_daemonise(SilcServer server);
92 void silc_server_run(SilcServer server);
93 void silc_server_stop(SilcServer server);
94 void silc_server_packet_parse(SilcPacketParserContext *parser_context);
95 void silc_server_packet_parse_type(SilcServer server,
96 SilcSocketConnection sock,
97 SilcPacketContext *packet);
98 void silc_server_create_connection(SilcServer server,
99 char *remote_host, uint32 port);
100 void silc_server_close_connection(SilcServer server,
101 SilcSocketConnection sock);
102 void silc_server_free_client_data(SilcServer server,
103 SilcSocketConnection sock,
104 SilcClientEntry client,
107 void silc_server_free_sock_user_data(SilcServer server,
108 SilcSocketConnection sock);
109 int silc_server_channel_has_global(SilcChannelEntry channel);
110 int silc_server_channel_has_local(SilcChannelEntry channel);
111 int silc_server_remove_clients_by_server(SilcServer server,
112 SilcServerEntry entry,
114 void silc_server_remove_from_channels(SilcServer server,
115 SilcSocketConnection sock,
116 SilcClientEntry client,
118 char *signoff_message,
120 int silc_server_remove_from_one_channel(SilcServer server,
121 SilcSocketConnection sock,
122 SilcChannelEntry channel,
123 SilcClientEntry client,
125 int silc_server_client_on_channel(SilcClientEntry client,
126 SilcChannelEntry channel);
127 void silc_server_disconnect_remote(SilcServer server,
128 SilcSocketConnection sock,
129 const char *fmt, ...);
130 SilcChannelEntry silc_server_create_new_channel(SilcServer server,
131 SilcServerID *router_id,
137 silc_server_create_new_channel_with_id(SilcServer server,
141 SilcChannelID *channel_id,
143 void silc_server_create_channel_key(SilcServer server,
144 SilcChannelEntry channel,
146 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
147 SilcBuffer key_payload,
148 SilcChannelEntry channel);
149 void silc_server_perform_heartbeat(SilcSocketConnection sock,
151 void silc_server_announce_get_channel_users(SilcServer server,
152 SilcChannelEntry channel,
153 SilcBuffer *channel_users,
154 SilcBuffer *channel_users_modes);
155 void silc_server_announce_get_channels(SilcServer server,
157 SilcBuffer *channels,
158 SilcBuffer *channel_users,
159 SilcBuffer **channel_users_modes,
160 uint32 *channel_users_modes_c,
161 SilcChannelID ***channel_ids);
162 void silc_server_announce_servers(SilcServer server);
163 void silc_server_announce_clients(SilcServer server);
164 void silc_server_announce_channels(SilcServer server);
165 void silc_server_get_users_on_channel(SilcServer server,
166 SilcChannelEntry channel,
167 SilcBuffer *user_list,
168 SilcBuffer *mode_list,
170 void silc_server_save_users_on_channel(SilcServer server,
171 SilcSocketConnection sock,
172 SilcChannelEntry channel,
174 SilcBuffer user_list,
175 SilcBuffer mode_list,
177 SilcSocketConnection silc_server_get_client_route(SilcServer server,
178 unsigned char *id_data,
180 SilcClientID *client_id,
181 SilcIDListData *idata);
182 SilcBuffer silc_server_get_client_channel_list(SilcServer server,
183 SilcClientEntry client);
184 SilcClientEntry silc_server_get_client_resolve(SilcServer server,
185 SilcClientID *client_id);