addition of silc.css
[silc.git] / apps / silcd / server_internal.h
1 /*
2
3   server_internal.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_INTERNAL_H
22 #define SERVER_INTERNAL_H
23
24 /* Server statistics structure. This holds various statistics about
25    various things. */
26 typedef struct {
27   /* Local stats (server and router) */
28   uint32 my_clients;              /* Locally connected clients */
29   uint32 my_servers;              /* Locally connected servers */
30   uint32 my_routers;              /* Locally connected routers */
31   uint32 my_channels;             /* Locally created channels */
32   uint32 my_chanclients;          /* Local clients on local channels */
33   uint32 my_aways;                /* Local clients away (XXX) */
34   uint32 my_server_ops;           /* Local server operators */
35   uint32 my_router_ops;           /* Local router operators */
36
37   /* Global stats (mainly for router) */
38   uint32 cell_clients;            /* All clients in cell */
39   uint32 cell_servers;            /* All servers in cell */
40   uint32 cell_channels;           /* All channels in cell */
41   uint32 cell_chanclients;        /* All clients on cell's channels */
42   uint32 clients;                 /* All clients */
43   uint32 servers;                 /* All servers */
44   uint32 routers;                 /* All routers */
45   uint32 channels;                /* All channels */
46   uint32 chanclients;             /* All clients on channels */
47   uint32 server_ops;              /* All server operators */
48   uint32 router_ops;              /* All router operators */
49
50   /* General */
51   uint32 conn_attempts;           /* Connection attempts */
52   uint32 conn_failures;           /* Connection failure */
53   uint32 auth_attempts;           /* Authentication attempts */
54   uint32 auth_failures;           /* Authentication failures */
55   uint32 packets_sent;            /* Sent packets */
56   uint32 packets_received;        /* Received packets */
57 } SilcServerStatistics;
58
59 /* 
60    SILC Server Object.
61
62 */
63 struct SilcServerStruct {
64   char *server_name;
65   int server_type;
66   int sock;
67   SilcServerID *id;
68   unsigned char *id_string;
69   uint32 id_string_len;
70   SilcIdType id_type;
71
72   bool standalone;                   /* TRUE if server is standalone, and
73                                         does not have connection to network. */
74   bool listenning;                   /* TRUE if server is listenning for
75                                         incoming connections. */
76   SilcServerEntry id_entry;          /* Server's own ID entry */
77   SilcServerEntry router;            /* Pointer to the primary router */
78   unsigned long router_connect;      /* Time when router was connected */
79   SilcServerBackup backup;           /* Backup routers */
80   bool backup_router;                /* TRUE if this is backup router */
81   bool backup_primary;               /* TRUE if we've switched our primary
82                                         router to a backup router. */
83
84   /* Current command identifier, 0 not used */
85   uint16 cmd_ident;
86
87   /* SILC server scheduler */
88   SilcSchedule schedule;
89
90   /* ID lists. */
91   SilcIDList local_list;
92   SilcIDList global_list;
93
94   /* Table of connected sockets */
95   SilcSocketConnection *sockets;
96
97   /* Server keys */
98   SilcCipher send_key;
99   SilcCipher receive_key;
100   SilcCipher none_cipher;
101
102   /* Server public key */
103   SilcPKCS pkcs;
104   SilcPublicKey public_key;
105   SilcPrivateKey private_key;
106
107   /* Hash objects for general hashing */
108   SilcHash md5hash;
109   SilcHash sha1hash;
110
111   /* HMAC objects for MAC's. */
112   SilcHmac md5hmac;
113   SilcHmac sha1hmac;
114
115   /* Configuration object */
116   SilcServerConfig config;
117
118   /* Random pool */
119   SilcRng rng;
120
121   /* Server statistics */
122   SilcServerStatistics stat;
123
124   /* Pending command queue */
125   SilcDList pending_commands;
126
127   /* Default parameteres for server */
128   SilcServerParams params;
129
130 #ifdef SILC_SIM
131   /* SIM (SILC Module) list */
132   SilcDList sim;
133 #endif
134 };
135
136 /* Server's heartbeat context */
137 typedef struct {
138   SilcServer server;
139 } *SilcServerHBContext;
140
141 /* Failure context. This is allocated when failure packet is received.
142    Failure packets are processed with timeout and data is saved in this
143    structure. */
144 typedef struct {
145   SilcServer server;
146   SilcSocketConnection sock;
147   uint32 failure;
148 } *SilcServerFailureContext;
149
150 /* Macros */
151
152 /* Registers generic task for file descriptor for reading from network and
153    writing to network. As being generic task the actual task is allocated 
154    only once and after that the same task applies to all registered fd's. */
155 #define SILC_REGISTER_CONNECTION_FOR_IO(fd)             \
156 do {                                                    \
157   silc_schedule_task_add(server->schedule, (fd),        \
158                          silc_server_packet_process,    \
159                          context, 0, 0,                 \
160                          SILC_TASK_GENERIC,             \
161                          SILC_TASK_PRI_NORMAL);         \
162 } while(0)
163
164 #define SILC_SET_CONNECTION_FOR_INPUT(s, fd)                    \
165 do {                                                            \
166   silc_schedule_set_listen_fd((s), (fd), SILC_TASK_READ);       \
167 } while(0)
168      
169 #define SILC_SET_CONNECTION_FOR_OUTPUT(s, fd)                                 \
170 do {                                                                          \
171   silc_schedule_set_listen_fd((s), (fd), (SILC_TASK_READ | SILC_TASK_WRITE)); \
172 } while(0)
173
174 /* Prototypes */
175 SILC_TASK_CALLBACK_GLOBAL(silc_server_rekey_final);
176
177 #endif