update.
[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   unsigned long my_clients;       /* Locally connected clients */
29   unsigned long my_servers;       /* Locally connected servers */
30   unsigned long my_routers;       /* Locally connected routers */
31   unsigned long my_channels;      /* Locally created channels */
32   unsigned long my_chanclients;   /* Local clients on local channels */
33   unsigned long my_aways;         /* Local clients away (XXX) */
34   unsigned long my_server_ops;    /* Local server operators */
35   unsigned long my_router_ops;    /* Local router operators */
36
37   /* Global stats (mainly for router) */
38   unsigned long cell_clients;     /* All clients in cell */
39   unsigned long cell_servers;     /* All servers in cell */
40   unsigned long cell_channels;    /* All channels in cell */
41   unsigned long cell_chanclients; /* All clients on cell's channels */
42   unsigned long clients;          /* All clients */
43   unsigned long servers;          /* All servers */
44   unsigned long routers;          /* All routers */
45   unsigned long channels;         /* All channels */
46   unsigned long chanclients;      /* All clients on channels */
47   unsigned long server_ops;       /* All server operators */
48   unsigned long router_ops;       /* All router operators */
49
50   /* General */
51   unsigned long conn_attempts;    /* Connection attempts */
52   unsigned long conn_failures;    /* Connection failure */
53   unsigned long auth_attempts;    /* Authentication attempts */
54   unsigned long auth_failures;    /* Authentication failures */
55   unsigned long packets_sent;     /* Sent packets */
56   unsigned long packets_received; /* Received packets */
57 } SilcServerStatistics;
58
59 typedef struct {
60   void *id_entry;
61   SilcSocketConnection sock;
62
63   /* Remote host name and port */
64   char *remote_host;
65   int remote_port;
66   
67   /* Current connection retry info */
68   unsigned int retry_count;
69   unsigned int retry_timeout;
70
71   /* Back pointer to server */
72   SilcServer server;
73 } *SilcServerConnection;
74
75 /* 
76    SILC Server Object.
77
78 */
79 struct SilcServerStruct {
80   char *server_name;
81   int server_type;
82   int sock;
83   int standalone;
84   int listenning;
85   SilcServerID *id;
86   unsigned char *id_string;
87   unsigned int id_string_len;
88   SilcIdType id_type;
89
90   /* Current command identifier, 0 not used */
91   unsigned short cmd_ident;
92
93   /* Server's own ID entry. */
94   SilcServerEntry id_entry;
95
96   /* Back pointer to the primary router of this server. */
97   SilcServerEntry router;
98
99   /* SILC server task queues */
100   SilcTaskQueue io_queue;
101   SilcTaskQueue timeout_queue;
102   SilcTaskQueue generic_queue;
103
104   /* ID lists. */
105   SilcIDList local_list;
106   SilcIDList global_list;
107
108   /* Table of connected sockets */
109   SilcSocketConnection *sockets;
110
111   /* Server keys */
112   SilcCipher send_key;
113   SilcCipher receive_key;
114   SilcCipher none_cipher;
115
116   /* Server public key */
117   SilcPKCS pkcs;
118   SilcPublicKey public_key;
119   SilcPrivateKey private_key;
120
121   /* Hash objects for general hashing */
122   SilcHash md5hash;
123   SilcHash sha1hash;
124
125   /* HMAC objects for MAC's. */
126   SilcHmac md5hmac;
127   SilcHmac sha1hmac;
128
129   /* Configuration object */
130   SilcServerConfig config;
131
132   /* Random pool */
133   SilcRng rng;
134
135   /* Server statistics */
136   SilcServerStatistics stat;
137
138   /* Pending command queue */
139   SilcDList pending_commands;
140
141   /* Default parameteres for server */
142   SilcServerParams params;
143
144 #ifdef SILC_SIM
145   /* SIM (SILC Module) list */
146   SilcDList sim;
147 #endif
148 };
149
150 /* Server's heartbeat context */
151 typedef struct {
152   SilcServer server;
153 } *SilcServerHBContext;
154
155 /* Macros */
156
157 /* Registers generic task for file descriptor for reading from network and
158    writing to network. As being generic task the actual task is allocated 
159    only once and after that the same task applies to all registered fd's. */
160 #define SILC_REGISTER_CONNECTION_FOR_IO(fd)                             \
161 do {                                                                    \
162   SilcTask tmptask = silc_task_register(server->generic_queue, (fd),    \
163                                         silc_server_packet_process,     \
164                                         context, 0, 0,                  \
165                                         SILC_TASK_GENERIC,              \
166                                         SILC_TASK_PRI_NORMAL);          \
167   silc_task_set_iotype(tmptask, SILC_TASK_WRITE);                       \
168 } while(0)
169
170 #define SILC_SET_CONNECTION_FOR_INPUT(fd)                               \
171 do {                                                                    \
172   silc_schedule_set_listen_fd((fd), (1L << SILC_TASK_READ));            \
173 } while(0)
174      
175 #define SILC_SET_CONNECTION_FOR_OUTPUT(fd)                              \
176 do {                                                                    \
177   silc_schedule_set_listen_fd((fd), ((1L << SILC_TASK_READ) |           \
178                                      (1L << SILC_TASK_WRITE)));         \
179 } while(0)
180
181 /* Prototypes */
182
183 #endif