Added support to retry when connecting.
[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 - 2000 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 /* XXX TODO */
27 typedef struct {
28
29 } SilcServerStatistics;
30
31 typedef struct {
32   void *id_entry;
33   SilcSocketConnection sock;
34
35   /* Remote host name and port */
36   char *remote_host;
37   int remote_port;
38   
39   /* Current connection retry info */
40   unsigned int retry_count;
41   unsigned int retry_timeout;
42
43   /* Back pointer to server */
44   SilcServer server;
45 } *SilcServerConnection;
46
47 /* 
48    SILC Server Object.
49
50 */
51 struct SilcServerStruct {
52   char *server_name;
53   int server_type;
54   int sock;
55   int standalone;
56   int listenning;
57   SilcServerID *id;
58   SilcIdType id_type;
59   SilcServerEntry id_entry;
60
61   /* SILC server task queues */
62   SilcTaskQueue io_queue;
63   SilcTaskQueue timeout_queue;
64   SilcTaskQueue generic_queue;
65
66   /* ID lists. */
67   SilcIDList local_list;
68   SilcIDList global_list;
69
70   /* Table of connected sockets */
71   SilcSocketConnection *sockets;
72
73   /* Server keys */
74   SilcCipher send_key;
75   SilcCipher receive_key;
76   SilcCipher none_cipher;
77
78   /* Server public key */
79   SilcPKCS pkcs;
80   SilcPublicKey public_key;
81   SilcPrivateKey private_key;
82
83   /* Hash objects for general hashing */
84   SilcHash md5hash;
85   SilcHash sha1hash;
86
87   /* HMAC objects for MAC's. */
88   SilcHmac md5hmac;
89   SilcHmac sha1hmac;
90
91   /* Configuration object */
92   SilcConfigServer config;
93
94   /* Random pool */
95   SilcRng rng;
96
97   /* Server statistics */
98   SilcServerStatistics stats;
99
100   /* Default parameteres for server */
101   SilcServerParams params;
102
103 #ifdef SILC_SIM
104   /* SIM (SILC Module) list */
105   SilcDList sim;
106 #endif
107 };
108
109 /* Macros */
110
111 /* Registers generic task for file descriptor for reading from network and
112    writing to network. As being generic task the actual task is allocated 
113    only once and after that the same task applies to all registered fd's. */
114 #define SILC_REGISTER_CONNECTION_FOR_IO(fd)                             \
115 do {                                                                    \
116   SilcTask tmptask = silc_task_register(server->generic_queue, (fd),    \
117                                         silc_server_packet_process,     \
118                                         context, 0, 0,                  \
119                                         SILC_TASK_GENERIC,              \
120                                         SILC_TASK_PRI_NORMAL);          \
121   silc_task_set_iotype(tmptask, SILC_TASK_WRITE);                       \
122 } while(0)
123
124 #define SILC_SET_CONNECTION_FOR_INPUT(fd)                               \
125 do {                                                                    \
126   silc_schedule_set_listen_fd((fd), (1L << SILC_TASK_READ));            \
127 } while(0)
128      
129 #define SILC_SET_CONNECTION_FOR_OUTPUT(fd)                              \
130 do {                                                                    \
131   silc_schedule_set_listen_fd((fd), ((1L << SILC_TASK_READ) |           \
132                                      (1L << SILC_TASK_WRITE)));         \
133 } while(0)
134
135 /* Prototypes */
136
137 #endif