5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2002 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.
21 #ifndef SERVER_INTERNAL_H
22 #define SERVER_INTERNAL_H
24 /* Server statistics structure. This holds various statistics about
27 /* Local stats (server and router) */
28 SilcUInt32 my_clients; /* Locally connected clients */
29 SilcUInt32 my_servers; /* Locally connected servers */
30 SilcUInt32 my_routers; /* Locally connected routers */
31 SilcUInt32 my_channels; /* Locally created channels */
32 SilcUInt32 my_chanclients; /* Local clients on local channels */
33 SilcUInt32 my_aways; /* Local clients away (gone) */
34 SilcUInt32 my_detached; /* Local clients detached */
35 SilcUInt32 my_server_ops; /* Local server operators */
36 SilcUInt32 my_router_ops; /* Local router operators */
38 /* Global stats (mainly for router) */
39 SilcUInt32 cell_clients; /* All clients in cell */
40 SilcUInt32 cell_servers; /* All servers in cell */
41 SilcUInt32 cell_channels; /* All channels in cell */
42 SilcUInt32 cell_chanclients; /* All clients on cell's channels */
43 SilcUInt32 clients; /* All clients */
44 SilcUInt32 servers; /* All servers */
45 SilcUInt32 routers; /* All routers */
46 SilcUInt32 channels; /* All channels */
47 SilcUInt32 chanclients; /* All clients on channels */
48 SilcUInt32 aways; /* All clients away (gone) */
49 SilcUInt32 detached; /* All clients detached */
50 SilcUInt32 server_ops; /* All server operators */
51 SilcUInt32 router_ops; /* All router operators */
54 SilcUInt32 conn_attempts; /* Connection attempts */
55 SilcUInt32 conn_failures; /* Connection failure */
56 SilcUInt32 auth_attempts; /* Authentication attempts */
57 SilcUInt32 auth_failures; /* Authentication failures */
58 SilcUInt32 packets_sent; /* Sent packets */
59 SilcUInt32 packets_received; /* Received packets */
60 } SilcServerStatistics;
66 struct SilcServerStruct {
71 unsigned char *id_string;
72 SilcUInt32 id_string_len;
76 bool standalone; /* TRUE if server is standalone, and
77 does not have connection to network. */
78 bool listenning; /* TRUE if server is listenning for
79 incoming connections. */
81 SilcServerEntry id_entry; /* Server's own ID entry */
82 SilcServerEntry router; /* Pointer to the primary router */
83 unsigned long router_connect; /* Time when router was connected */
84 SilcServerBackup backup; /* Backup routers */
85 bool backup_router; /* TRUE if this is backup router */
86 bool backup_primary; /* TRUE if we've switched our primary
87 router to a backup router. */
88 SilcServerConnection router_conn; /* non-NULL when connecting to the
89 primary router, and NULL otherwise. */
91 /* Current command identifier, 0 not used */
94 /* SILC server scheduler */
95 SilcSchedule schedule;
98 SilcIDList local_list;
99 SilcIDList global_list;
100 SilcHashTable watcher_list;
102 /* Table of connected sockets */
103 SilcSocketConnection *sockets;
105 /* Server public key */
107 SilcPublicKey public_key;
108 SilcPrivateKey private_key;
110 /* Hash objects for general hashing */
114 /* HMAC objects for MAC's. */
118 /* Configuration object */
119 SilcServerConfig config;
120 SilcServerConfigRef config_ref;
126 /* Server statistics */
127 SilcServerStatistics stat;
129 /* Pending command queue */
130 SilcDList pending_commands;
133 /* SIM (SILC Module) list */
138 /* Server's heartbeat context */
141 } *SilcServerHBContext;
143 /* Failure context. This is allocated when failure packet is received.
144 Failure packets are processed with timeout and data is saved in this
148 SilcSocketConnection sock;
150 } *SilcServerFailureContext;
154 /* Registers generic task for file descriptor for reading from network and
155 writing to network. As being generic task the actual task is allocated
156 only once and after that the same task applies to all registered fd's. */
157 #define SILC_REGISTER_CONNECTION_FOR_IO(fd) \
159 silc_schedule_task_add(server->schedule, (fd), \
160 silc_server_packet_process, \
163 SILC_TASK_PRI_NORMAL); \
166 #define SILC_SET_CONNECTION_FOR_INPUT(s, fd) \
168 silc_schedule_set_listen_fd((s), (fd), SILC_TASK_READ); \
171 #define SILC_SET_CONNECTION_FOR_OUTPUT(s, fd) \
173 silc_schedule_set_listen_fd((s), (fd), (SILC_TASK_READ | SILC_TASK_WRITE)); \
176 #define SILC_OPER_STATS_UPDATE(c, type, mod) \
178 if ((c)->mode & (mod)) { \
179 if ((c)->connection) \
180 server->stat.my_ ## type ## _ops--; \
181 if (server->server_type == SILC_ROUTER) \
182 server->stat. type ## _ops--; \
183 (c)->mode &= ~(mod); \
187 #define SILC_UMODE_STATS_UPDATE(oper, mod) \
189 if (client->mode & (mod)) { \
190 if (!(mode & (mod))) { \
191 if (client->connection) \
192 server->stat.my_ ## oper ## _ops--; \
193 if (server->server_type == SILC_ROUTER) \
194 server->stat. oper ## _ops--; \
197 if (mode & (mod)) { \
198 if (client->connection) \
199 server->stat.my_ ## oper ## _ops++; \
200 if (server->server_type == SILC_ROUTER) \
201 server->stat. oper ## _ops++; \
206 #define SILC_GET_SKE_FLAGS(x, p) \
208 if ((x)->param && (x)->param->key_exchange_pfs) \
209 (p)->flags |= SILC_SKE_SP_FLAG_PFS; \
210 if (!(x)->publickeys) \
211 (p)->flags |= SILC_SKE_SP_FLAG_MUTUAL; \
215 SILC_TASK_CALLBACK_GLOBAL(silc_server_rekey_final);
216 void silc_server_watcher_list_destroy(void *key, void *context,