CONNECT, CLOSE and SHUTDOWN commands.
[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 /* Server and router. Used internally by the code. */
34 #define SILC_SERVER 0
35 #define SILC_ROUTER 1
36
37 /* Connection retry timeout. We implement exponential backoff algorithm
38    in connection retry. The interval of timeuot grows when retry count
39    grows. */
40 #define SILC_SERVER_RETRY_COUNT        4         /* Max retry count */
41 #define SILC_SERVER_RETRY_MULTIPLIER   7 / 4     /* Interval growth */
42 #define SILC_SERVER_RETRY_RANDOMIZER   2         /* timeout += rnd % 2 */
43 #define SILC_SERVER_RETRY_INTERVAL_MIN 10        /* Min retry timeout */
44 #define SILC_SERVER_RETRY_INTERVAL_MAX 600       /* Max generated timeout */
45
46 /* 
47    Silc Server Params.
48
49    Structure to hold various default parameters for server that can be
50    given before running the server. 
51
52 */
53 typedef struct {
54   unsigned int retry_count;
55   unsigned long retry_interval_min;
56   unsigned long retry_interval_min_usec;
57   unsigned long retry_interval_max;
58   char retry_keep_trying;
59
60   unsigned long protocol_timeout;
61   unsigned long protocol_timeout_usec;
62
63   char require_reverse_mapping;
64 } *SilcServerParams;
65
66 /* Macros */
67
68 /* This macro is used to send notify messages with formatted string. The
69    string is formatted with arguments and the formatted string is sent as
70    argument. */
71 #define SILC_SERVER_SEND_NOTIFY(server, sock, type, fmt)        \
72 do {                                                            \
73   char *__fmt__ = silc_format fmt;                              \
74   silc_server_send_notify(server, sock, FALSE,                  \
75                           type, 1, __fmt__, strlen(__fmt__));   \
76   silc_free(__fmt__);                                           \
77 } while(0);
78
79 /* Prototypes */
80 int silc_server_alloc(SilcServer *new_server);
81 void silc_server_free(SilcServer server);
82 int silc_server_init(SilcServer server);
83 void silc_server_daemonise(SilcServer server);
84 void silc_server_run(SilcServer server);
85 void silc_server_stop(SilcServer server);
86 void silc_server_packet_parse(SilcPacketParserContext *parser_context);
87 void silc_server_packet_parse_type(SilcServer server, 
88                                    SilcSocketConnection sock,
89                                    SilcPacketContext *packet);
90 void silc_server_create_connection(SilcServer server,
91                                    char *remote_host, unsigned int port);
92 void silc_server_close_connection(SilcServer server,
93                                   SilcSocketConnection sock);
94 void silc_server_free_client_data(SilcServer server, 
95                                   SilcSocketConnection sock,
96                                   SilcClientEntry user_data, char *signoff);
97 void silc_server_free_sock_user_data(SilcServer server, 
98                                      SilcSocketConnection sock);
99 int silc_server_channel_has_global(SilcChannelEntry channel);
100 int silc_server_channel_has_local(SilcChannelEntry channel);
101 int silc_server_remove_clients_by_server(SilcServer server, 
102                                          SilcServerEntry entry);
103 void silc_server_remove_from_channels(SilcServer server, 
104                                       SilcSocketConnection sock,
105                                       SilcClientEntry client,
106                                       char *signoff_message);
107 int silc_server_remove_from_one_channel(SilcServer server, 
108                                         SilcSocketConnection sock,
109                                         SilcChannelEntry channel,
110                                         SilcClientEntry client,
111                                         int notify);
112 int silc_server_client_on_channel(SilcClientEntry client,
113                                   SilcChannelEntry channel);
114 void silc_server_disconnect_remote(SilcServer server,
115                                    SilcSocketConnection sock,
116                                    const char *fmt, ...);
117 SilcChannelEntry silc_server_create_new_channel(SilcServer server, 
118                                                 SilcServerID *router_id,
119                                                 char *cipher, 
120                                                 char *channel_name,
121                                                 int broadcast);
122 SilcChannelEntry 
123 silc_server_create_new_channel_with_id(SilcServer server, 
124                                        char *cipher, 
125                                        char *channel_name,
126                                        SilcChannelID *channel_id,
127                                        int broadcast);
128 void silc_server_create_channel_key(SilcServer server, 
129                                     SilcChannelEntry channel,
130                                     unsigned int key_len);
131 SilcChannelEntry silc_server_save_channel_key(SilcServer server,
132                                               SilcBuffer key_payload,
133                                               SilcChannelEntry channel);
134 void silc_server_perform_heartbeat(SilcSocketConnection sock,
135                                    void *hb_context);
136 void silc_server_announce_servers(SilcServer server);
137 void silc_server_announce_clients(SilcServer server);
138 void silc_server_announce_channels(SilcServer server);
139
140 #endif