updates. New data types.
[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 typedef struct {
60   SilcSocketConnection sock;
61
62   /* Remote host name and port */
63   char *remote_host;
64   int remote_port;
65   
66   /* Current connection retry info */
67   uint32 retry_count;
68   uint32 retry_timeout;
69
70   /* Back pointer to server */
71   SilcServer server;
72 } *SilcServerConnection;
73
74 /* 
75    SILC Server Object.
76
77 */
78 struct SilcServerStruct {
79   char *server_name;
80   int server_type;
81   int sock;
82   int standalone;
83   int listenning;
84   SilcServerID *id;
85   unsigned char *id_string;
86   uint32 id_string_len;
87   SilcIdType id_type;
88
89   /* Current command identifier, 0 not used */
90   uint16 cmd_ident;
91
92   /* Server's own ID entry. */
93   SilcServerEntry id_entry;
94
95   /* Back pointer to the primary router of this server. */
96   SilcServerEntry router;
97
98   /* SILC server task queues */
99   SilcTaskQueue io_queue;
100   SilcTaskQueue timeout_queue;
101   SilcTaskQueue generic_queue;
102
103   /* ID lists. */
104   SilcIDList local_list;
105   SilcIDList global_list;
106
107   /* Table of connected sockets */
108   SilcSocketConnection *sockets;
109
110   /* Server keys */
111   SilcCipher send_key;
112   SilcCipher receive_key;
113   SilcCipher none_cipher;
114
115   /* Server public key */
116   SilcPKCS pkcs;
117   SilcPublicKey public_key;
118   SilcPrivateKey private_key;
119
120   /* Hash objects for general hashing */
121   SilcHash md5hash;
122   SilcHash sha1hash;
123
124   /* HMAC objects for MAC's. */
125   SilcHmac md5hmac;
126   SilcHmac sha1hmac;
127
128   /* Configuration object */
129   SilcServerConfig config;
130
131   /* Random pool */
132   SilcRng rng;
133
134   /* Server statistics */
135   SilcServerStatistics stat;
136
137   /* Pending command queue */
138   SilcDList pending_commands;
139
140   /* Default parameteres for server */
141   SilcServerParams params;
142
143 #ifdef SILC_SIM
144   /* SIM (SILC Module) list */
145   SilcDList sim;
146 #endif
147 };
148
149 /* Server's heartbeat context */
150 typedef struct {
151   SilcServer server;
152 } *SilcServerHBContext;
153
154 /* Failure context. This is allocated when failure packet is received.
155    Failure packets are processed with timeout and data is saved in this
156    structure. */
157 typedef struct {
158   SilcServer server;
159   SilcSocketConnection sock;
160   uint32 failure;
161 } *SilcServerFailureContext;
162
163 /* Macros */
164
165 /* Registers generic task for file descriptor for reading from network and
166    writing to network. As being generic task the actual task is allocated 
167    only once and after that the same task applies to all registered fd's. */
168 #define SILC_REGISTER_CONNECTION_FOR_IO(fd)                             \
169 do {                                                                    \
170   SilcTask tmptask = silc_task_register(server->generic_queue, (fd),    \
171                                         silc_server_packet_process,     \
172                                         context, 0, 0,                  \
173                                         SILC_TASK_GENERIC,              \
174                                         SILC_TASK_PRI_NORMAL);          \
175   silc_task_set_iotype(tmptask, SILC_TASK_WRITE);                       \
176 } while(0)
177
178 #define SILC_SET_CONNECTION_FOR_INPUT(fd)                               \
179 do {                                                                    \
180   silc_schedule_set_listen_fd((fd), (1L << SILC_TASK_READ));            \
181 } while(0)
182      
183 #define SILC_SET_CONNECTION_FOR_OUTPUT(fd)                              \
184 do {                                                                    \
185   silc_schedule_set_listen_fd((fd), ((1L << SILC_TASK_READ) |           \
186                                      (1L << SILC_TASK_WRITE)));         \
187 } while(0)
188
189 /* Prototypes */
190
191 #endif