updates.
[silc.git] / apps / silcd / server.h
1 /*
2
3   server.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2001 Pekka Riikonen
8
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.
13   
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.
18
19 */
20
21 #ifndef SERVER_H
22 #define SERVER_H
23
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;
28
29 #define SILC_SERVER_MAX_CONNECTIONS 10000
30
31 /* General definitions */
32
33 /* SILC port */
34 #define SILC_PORT 768;
35
36 /* Server and router. Used internally by the code. */
37 #define SILC_SERVER 0
38 #define SILC_ROUTER 1
39
40 /* Connection retry timeout. We implement exponential backoff algorithm
41    in connection retry. The interval of timeuot grows when retry count
42    grows. */
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 */
48
49 /* 
50    Silc Server Params.
51
52    Structure to hold various default parameters for server that can be
53    given before running the server. 
54
55 */
56 typedef struct {
57   unsigned int retry_count;
58   unsigned long retry_interval_min;
59   unsigned long retry_interval_min_usec;
60   unsigned long retry_interval_max;
61   char retry_keep_trying;
62
63   unsigned long protocol_timeout;
64   unsigned long protocol_timeout_usec;
65
66   char require_reverse_mapping;
67 } *SilcServerParams;
68
69 /* Macros */
70
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
73    argument. */
74 #define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt)        \
75 do {                                                            \
76   char *__fmt__ = silc_format fmt;                              \
77   silc_server_send_notify(server, sock, FALSE,                  \
78                           type, 1, __fmt__, strlen(__fmt__));   \
79   silc_free(__fmt__);                                           \
80 } while(0);
81
82 /* Prototypes */
83 int silc_server_alloc(SilcServer *new_server);
84 void silc_server_free(SilcServer server);
85 int silc_server_init(SilcServer server);
86 void silc_server_daemonise(SilcServer server);
87 void silc_server_run(SilcServer server);
88 void silc_server_stop(SilcServer server);
89 void silc_server_packet_parse(SilcPacketParserContext *parser_context);
90 void silc_server_packet_parse_type(SilcServer server, 
91                                    SilcSocketConnection sock,
92                                    SilcPacketContext *packet);
93 void silc_server_create_connection(SilcServer server,
94                                    char *remote_host, unsigned int port);
95 void silc_server_close_connection(SilcServer server,
96                                   SilcSocketConnection sock);
97 void silc_server_free_client_data(SilcServer server, 
98                                   SilcSocketConnection sock,
99                                   SilcClientEntry client, 
100                                   int notify,
101                                   char *signoff);
102 void silc_server_free_sock_user_data(SilcServer server, 
103                                      SilcSocketConnection sock);
104 int silc_server_channel_has_global(SilcChannelEntry channel);
105 int silc_server_channel_has_local(SilcChannelEntry channel);
106 int silc_server_remove_clients_by_server(SilcServer server, 
107                                          SilcServerEntry entry,
108                                          int server_signoff);
109 void silc_server_remove_from_channels(SilcServer server, 
110                                       SilcSocketConnection sock,
111                                       SilcClientEntry client,
112                                       int notify,
113                                       char *signoff_message,
114                                       int keygen);
115 int silc_server_remove_from_one_channel(SilcServer server, 
116                                         SilcSocketConnection sock,
117                                         SilcChannelEntry channel,
118                                         SilcClientEntry client,
119                                         int notify);
120 int silc_server_client_on_channel(SilcClientEntry client,
121                                   SilcChannelEntry channel);
122 void silc_server_disconnect_remote(SilcServer server,
123                                    SilcSocketConnection sock,
124                                    const char *fmt, ...);
125 SilcChannelEntry silc_server_create_new_channel(SilcServer server, 
126                                                 SilcServerID *router_id,
127                                                 char *cipher, 
128                                                 char *hmac,
129                                                 char *channel_name,
130                                                 int broadcast);
131 SilcChannelEntry 
132 silc_server_create_new_channel_with_id(SilcServer server, 
133                                        char *cipher, 
134                                        char *hmac,
135                                        char *channel_name,
136                                        SilcChannelID *channel_id,
137                                        int broadcast);
138 void silc_server_create_channel_key(SilcServer server, 
139                                     SilcChannelEntry channel,
140                                     unsigned int key_len);
141 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
142                                               SilcBuffer key_payload,
143                                               SilcChannelEntry channel);
144 void silc_server_perform_heartbeat(SilcSocketConnection sock,
145                                    void *hb_context);
146 void silc_server_announce_get_channel_users(SilcServer server,
147                                             SilcChannelEntry channel,
148                                             SilcBuffer *channel_users);
149 void silc_server_announce_get_channels(SilcServer server,
150                                        SilcIDList id_list,
151                                        SilcBuffer *channels,
152                                        SilcBuffer *channel_users);
153 void silc_server_announce_servers(SilcServer server);
154 void silc_server_announce_clients(SilcServer server);
155 void silc_server_announce_channels(SilcServer server);
156 void silc_server_get_users_on_channel(SilcServer server,
157                                       SilcChannelEntry channel,
158                                       SilcBuffer *user_list,
159                                       SilcBuffer *mode_list,
160                                       unsigned int *user_count);
161 void silc_server_save_users_on_channel(SilcServer server,
162                                        SilcSocketConnection sock,
163                                        SilcChannelEntry channel,
164                                        SilcClientID *noadd,
165                                        SilcBuffer user_list,
166                                        SilcBuffer mode_list,
167                                        unsigned int user_count);
168 SilcSocketConnection silc_server_get_client_route(SilcServer server,
169                                                   unsigned char *id_data,
170                                                   unsigned int id_len,
171                                                   SilcClientID *client_id,
172                                                   SilcIDListData *idata);
173 SilcBuffer silc_server_get_client_channel_list(SilcServer server,
174                                                SilcClientEntry client);
175 SilcClientEntry silc_server_get_client_resolve(SilcServer server,
176                                                SilcClientID *client_id);
177
178 #endif