5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 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.
24 /* Forward declarations */
25 typedef struct SilcServerEntryStruct *SilcServerEntry;
26 typedef struct SilcClientEntryStruct *SilcClientEntry;
27 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
30 SILC Server entry object.
32 This entry holds information about servers in SILC network. However,
33 contents of this entry is highly dependent of what kind of server we are
34 (normal server or router server) and whether the entry is used as a local
35 list or a global list. These factors dictates the contents of this entry.
37 This entry is defined as follows:
39 Server type List type Contents
40 =======================================================================
41 server local list Server itself
42 server global list NULL
43 router local list All servers is the cell
44 router global list All servers in the SILC network
46 Following short description of the fields:
50 Logical name of the server. There is no limit of the length of the
51 server name. This is usually the same name as defined in DNS.
55 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
60 ID of the server. This includes all the relevant information about
61 the server SILC will ever need. These are also the informations
62 that is broadcasted between servers and routers in the SILC network.
66 Time when data was received from the server last time.
68 SilcServerEntry router
70 This is a pointer back to the server list. This is the router server
71 where this server is connected to. If this is the router itself and
72 it doesn't have a route this is NULL.
75 SilcCipher receive_key
77 Data sending and receiving keys.
81 A pointer, usually, to the socket list for fast referencing to
82 the data used in connection with this server. This may be anything
83 but as just said, this is usually pointer to the socket connection
87 struct SilcServerEntryStruct {
93 /* TRUE when server is registered to server */
96 /* Pointer to the router */
97 SilcServerEntry router;
101 SilcCipher receive_key;
103 SilcPublicKey public_key;
105 unsigned char *hmac_key;
106 unsigned int hmac_key_len;
108 /* Connection data */
113 SILC Channel Client entry structure.
115 This entry used only by the SilcChannelEntry object and it holds
116 information about current clients (ie. users) on channel. Following
117 short description of the fields:
119 SilcClientEntry client
121 Pointer to the client list. This is the client currently on channel.
125 Client's current mode on the channel.
127 SilcChannelEntry channel
129 Back pointer back to channel. As this structure is also used by
130 SilcClientEntry we have this here for fast access to the channel when
131 used by SilcClientEntry.
133 struct SilcChannelClientEntryStruct *client_list
134 struct SilcChannelClientEntryStruct *channel_list
136 List member pointers. This structure is used by channel entry and
137 client entry thus we must have separate list member pointers for
138 them since we are using same entry for both lists (the entry is not
139 duplicated). SilcList requires this.
142 typedef struct SilcChannelClientEntryStruct {
143 SilcClientEntry client;
145 SilcChannelEntry channel;
146 struct SilcChannelClientEntryStruct *client_list;
147 struct SilcChannelClientEntryStruct *channel_list;
148 } *SilcChannelClientEntry;
151 SILC Client entry object.
153 This entry holds information about connected clients ie. users in the SILC
154 network. The contents of this entrt is depended on whether we are normal
155 server or router server and whether the list is a local or global list.
157 This entry is defined as follows:
159 Server type List type Contents
160 =======================================================================
161 server local list All clients in server
162 server global list NULL
163 router local list All clients in cell
164 router global list All clients in SILC
166 Following short description of the fields:
170 Client's (meaning user's) real name. This is defined in following
173 Server type List type Contents
174 ====================================================
175 server local list User's name
176 router local list NULL
177 router global list NULL
179 Router doesn't hold this information since it is not vital data
180 for the router. If this information is needed by the client it is
181 fetched when it is needed.
185 Information about user. This is free information and can be virtually
186 anything. This is defined in following manner:
188 Server type List type Contents
189 ====================================================
190 server local list User's information
191 router local list NULL
192 router global list NULL
194 Router doesn't hold this information since it is not vital data
195 for the router. If this information is needed by the client it is
196 fetched when it is needed.
200 ID of the client. This includes all the information SILC will ever
201 need. Notice that no nickname of the user is saved anywhere. This is
202 beacuse of SilcClientID includes 88 bit hash value of the user's
203 nickname which can be used to track down specific user by their
204 nickname. Nickname is not relevant information that would need to be
209 Client's mode. Client maybe for example server operator or
210 router operator (SILC operator).
214 Time of last time data was received from the client. This is
215 result of normal time().
219 Time of last time client executed command. We are strict and will
220 not allow any command to be exeucted more than once in about
221 2 seconds. This is result of normal time().
225 Boolean value to indicate whether this client has registered itself
226 to the server. After KE and authentication protocols has been
227 successfully completed will client become registered.
229 SilcServerEntry router
231 This is a pointer to the server list. This is the router server whose
232 cell this client is coming from. This is used to route messages to
235 SilcCipher session_key
237 The actual session key established by key exchange protcol between
238 connecting parties. This is used for both encryption and decryption.
242 PKCS of the client. This maybe NULL.
246 MAC key used to compute MAC's for packets.
250 A pointer, usually, to the socket list for fast referencing to
251 the data used in connection with this client. This may be anything
252 but as just said, this is usually pointer to the socket connection
256 struct SilcClientEntryStruct {
263 /* Time of last accesses of the client */
267 /* TRUE when client is registered to server */
270 /* Pointer to the router */
271 SilcServerEntry router;
273 /* List of channels client has joined to */
278 SilcCipher receive_key;
281 SilcPublicKey public_key;
283 /* Connection data */
288 SILC Channel entry object.
290 This entry holds information about channels in SILC network. The contents
291 of this entry is depended on whether we are normal server or router server
292 and whether the list is a local or global list.
294 This entry is defined as follows:
296 Server type List type Contents
297 =======================================================================
298 server local list All channels in server
299 server global list NULL
300 router local list All channels in cell
301 router global list All channels in SILC
303 Following short description of the fields:
307 Logical name of the channel.
311 Current mode of the channel. See lib/silccore/silcchannel.h for
316 ID of the channel. This includes all the information SILC will ever
321 Boolean value to tell whether there are users outside this server
322 on this channel. This is set to TRUE if router sends message to
323 the server that there are users outside your server on your
324 channel as well. This way server knows that messages needs to be
325 sent to the router for further routing. If this is a normal
326 server and this channel is not created on this server this field
327 is always TRUE. If this server is a router this field is ignored.
331 Current topic of the channel.
335 Default cipher of the channel. If this is NULL then server picks
336 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
338 SilcServerEntry router
340 This is a pointer to the server list. This is the router server
341 whose cell this channel belongs to. This is used to route messages
344 SilcCipher channel_key
346 The key of the channel (the cipher actually).
351 Raw key data of the channel key.
353 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
355 Current initial vector. Initial vector is received always along
356 with the channel packet. By default this is filled with NULL.
359 struct SilcChannelEntryStruct {
367 /* Data that is related to different channel modes. */
369 unsigned int user_limit;
370 unsigned char *passphrase;
371 unsigned char *ban_list;
372 unsigned char *invite_list;
373 unsigned char *cipher;
374 unsigned int key_len;
377 /* List of users on channel */
380 /* Pointer to the router */
381 SilcServerEntry router;
384 SilcCipher channel_key;
386 unsigned int key_len;
387 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
393 As for remainder these lists are defined as follows:
395 Entry list (cache) Server type List type Contents
396 =======================================================================
397 servers server local list Server itself
398 servers server global list NULL
399 servers router local list All servers in cell
400 servers router global list All servers in SILC
402 clients server local list All clients in server
403 clients server global list NULL
404 clients router local list All clients in cell
405 clients router global list All clients in SILC
407 channels server local list All channels in server
408 channels server global list NULL
409 channels router local list All channels in cell
410 channels router global list All channels in SILC
412 As seen on the list normal server never defines a global list. This is
413 because of normal server don't know anything about anything global data,
414 they get it from the router if and when they need it. Routers, on the
415 other hand, always define local and global lists because routers really
416 know all the relevant data in the SILC network.
418 This object is used as local and global list by the server/router.
419 Above table shows how this is defined on different conditions.
421 This object holds pointers to the ID cache system. Every ID cache entry
422 has a specific context pointer to allocated entry (server, client or
426 typedef struct SilcIDListStruct {
429 SilcIDCache channels;
433 Temporary ID Entry object.
435 This is used during authentication phases where we still don't know
436 what kind of connection remote connection is, hence, we will use this
437 structure instead until we know what type of connection remote end is.
439 This is not in any list. This is always individually allocated and
445 SilcCipher receive_key;
447 SilcPublicKey public_key;
450 unsigned char *hmac_key;
451 unsigned int hmac_key_len;
458 silc_idlist_add_server(SilcIDList id_list,
459 char *server_name, int server_type,
460 SilcServerID *id, SilcServerEntry router,
461 SilcCipher send_key, SilcCipher receive_key,
462 SilcPKCS pkcs, SilcHmac hmac,
463 SilcPublicKey public_key, void *connection);
465 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id);
467 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
468 SilcServerID *new_id);
470 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
471 char *userinfo, SilcClientID *id,
472 SilcServerEntry router,
473 SilcCipher send_key, SilcCipher receive_key,
474 SilcPKCS pkcs, SilcHmac hmac,
475 SilcPublicKey public_key, void *connection);
476 void silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
478 silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
479 char *server, unsigned int *clients_count);
481 silc_idlist_find_client_by_nickname(SilcIDList id_list, char *nickname,
484 silc_idlist_find_client_by_hash(SilcIDList id_list, char *nickname,
487 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id);
489 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
490 SilcClientID *new_id);
492 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
493 SilcChannelID *id, SilcServerEntry router,
494 SilcCipher channel_key);
495 void silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
497 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name);
499 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id);