5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2001 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;
29 /* Context for holding cache information to periodically purge
37 Generic ID list data structure.
39 This structure is included in all ID list entries and it includes data
40 pointers that are common to all ID entries. This structure is always
41 defined to the first field in the ID entries and is used to explicitly
42 cast to this type without first explicitly casting to correct ID entry
43 type. Hence, the ID list entry is casted to this type to get this data
44 from the ID entry (which is usually opaque pointer).
46 Note that some of the fields may be NULL.
50 /* Send and receive symmetric keys */
52 SilcCipher receive_key;
54 /* Hash selected in the SKE protocol, NULL if not needed at all */
57 /* HMAC and raw key data */
59 unsigned char *hmac_key;
60 unsigned int hmac_key_len;
62 /* PKCS and public key */
64 SilcPublicKey public_key;
66 long last_receive; /* Time last received data */
67 long last_sent; /* Time last sent data */
68 unsigned char registered; /* Boolean whether connection is registered */
69 } *SilcIDListData, SilcIDListDataStruct;
72 SILC Server entry object.
74 This entry holds information about servers in SILC network. However,
75 contents of this entry is highly dependent of what kind of server we are
76 (normal server or router server) and whether the entry is used as a local
77 list or a global list. These factors dictates the contents of this entry.
79 This entry is defined as follows:
81 Server type List type Contents
82 =======================================================================
83 server local list Server itself
84 server global list NULL
85 router local list All servers is the cell
86 router global list All servers in the SILC network
88 Following short description of the fields:
90 SilcIDListDataStruct data
92 Generic data structure to hold data common to all ID entries.
96 Logical name of the server. There is no limit of the length of the
97 server name. This is usually the same name as defined in DNS.
101 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
106 ID of the server. This includes all the relevant information about
107 the server SILC will ever need. These are also the informations
108 that is broadcasted between servers and routers in the SILC network.
113 Server info (from INFO command) saved temporarily and motd (from
114 MOTD command) saved temporarily.
116 SilcServerEntry router
118 This is a pointer back to the server list. This is the router server
119 where this server is connected to. If this is the router itself and
120 it doesn't have a route this is NULL.
123 SilcCipher receive_key
125 Data sending and receiving keys.
129 A pointer, usually, to the socket list for fast referencing to
130 the data used in connection with this server. This may be anything
131 but as just said, this is usually pointer to the socket connection
135 struct SilcServerEntryStruct {
136 /* Generic data structure. DO NOT add anything before this! */
137 SilcIDListDataStruct data;
145 /* Pointer to the router */
146 SilcServerEntry router;
148 /* Connection data */
153 SILC Channel Client entry structure.
155 This entry used only by the SilcChannelEntry object and it holds
156 information about current clients (ie. users) on channel. Following
157 short description of the fields:
159 SilcClientEntry client
161 Pointer to the client list. This is the client currently on channel.
165 Client's current mode on the channel.
167 SilcChannelEntry channel
169 Back pointer back to channel. As this structure is also used by
170 SilcClientEntry we have this here for fast access to the channel when
171 used by SilcClientEntry.
173 struct SilcChannelClientEntryStruct *client_list
174 struct SilcChannelClientEntryStruct *channel_list
176 List member pointers. This structure is used by channel entry and
177 client entry thus we must have separate list member pointers for
178 them since we are using same entry for both lists (the entry is not
179 duplicated). SilcList requires this.
182 typedef struct SilcChannelClientEntryStruct {
183 SilcClientEntry client;
185 SilcChannelEntry channel;
186 struct SilcChannelClientEntryStruct *client_list;
187 struct SilcChannelClientEntryStruct *channel_list;
188 } *SilcChannelClientEntry;
191 SILC Client entry object.
193 This entry holds information about connected clients ie. users in the SILC
194 network. The contents of this entrt is depended on whether we are normal
195 server or router server and whether the list is a local or global list.
197 This entry is defined as follows:
199 Server type List type Contents
200 =======================================================================
201 server local list All clients in server
202 server global list NULL
203 router local list All clients in cell
204 router global list All clients in SILC
206 Following short description of the fields:
208 SilcIDListDataStruct data
210 Generic data structure to hold data common to all ID entries.
214 Client's (meaning user's) real name. This is defined in following
217 Server type List type Contents
218 ====================================================
219 server local list User's name
220 router local list NULL
221 router global list NULL
223 Router doesn't hold this information since it is not vital data
224 for the router. If this information is needed by the client it is
225 fetched when it is needed.
229 Information about user. This is free information and can be virtually
230 anything. This is defined in following manner:
232 Server type List type Contents
233 ====================================================
234 server local list User's information
235 router local list NULL
236 router global list NULL
238 Router doesn't hold this information since it is not vital data
239 for the router. If this information is needed by the client it is
240 fetched when it is needed.
244 ID of the client. This includes all the information SILC will ever
245 need. Notice that no nickname of the user is saved anywhere. This is
246 beacuse of SilcClientID includes 88 bit hash value of the user's
247 nickname which can be used to track down specific user by their
248 nickname. Nickname is not relevant information that would need to be
253 Client's mode. Client maybe for example server operator or
254 router operator (SILC operator).
258 Time of last time client executed command. We are strict and will
259 not allow any command to be exeucted more than once in about
260 2 seconds. This is result of normal time().
264 Counter to check command bursts. By default, up to 5 commands
265 are allowed before limiting the execution. See command flags
268 SilcServerEntry router
270 This is a pointer to the server list. This is the router server whose
271 cell this client is coming from. This is used to route messages to
276 List of channels this client has joined.
280 A pointer, usually, to the socket list for fast referencing to
281 the data used in connection with this client. This may be anything
282 but as just said, this is usually pointer to the socket connection
286 struct SilcClientEntryStruct {
287 /* Generic data structure. DO NOT add anything before this! */
288 SilcIDListDataStruct data;
290 unsigned char *nickname;
299 /* Pointer to the router */
300 SilcServerEntry router;
302 /* List of channels client has joined to */
305 /* Connection data */
310 SILC Channel entry object.
312 This entry holds information about channels in SILC network. The contents
313 of this entry is depended on whether we are normal server or router server
314 and whether the list is a local or global list.
316 This entry is defined as follows:
318 Server type List type Contents
319 =======================================================================
320 server local list All channels in server
321 server global list NULL
322 router local list All channels in cell
323 router global list All channels in SILC
325 Following short description of the fields:
329 Logical name of the channel.
333 Current mode of the channel. See lib/silccore/silcchannel.h for
338 ID of the channel. This includes all the information SILC will ever
343 Boolean value to tell whether there are users outside this server
344 on this channel. This is set to TRUE if router sends message to
345 the server that there are users outside your server on your
346 channel as well. This way server knows that messages needs to be
347 sent to the router for further routing. If this is a normal
348 server and this channel is not created on this server this field
349 is always TRUE. If this server is a router this field is ignored.
353 Current topic of the channel.
357 Default cipher of the channel. If this is NULL then server picks
358 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
360 SilcServerEntry router
362 This is a pointer to the server list. This is the router server
363 whose cell this channel belongs to. This is used to route messages
366 SilcCipher channel_key
368 The key of the channel (the cipher actually).
373 Raw key data of the channel key.
375 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
377 Current initial vector. Initial vector is received always along
378 with the channel packet. By default this is filled with NULL.
385 struct SilcChannelEntryStruct {
393 /* Data that is related to different channel modes. */
395 unsigned int user_limit;
396 unsigned char *passphrase;
397 unsigned char *ban_list;
398 unsigned char *invite_list;
399 unsigned char *cipher;
400 unsigned int key_len;
403 /* List of users on channel */
406 /* Pointer to the router */
407 SilcServerEntry router;
410 SilcCipher channel_key;
412 unsigned int key_len;
413 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
420 As for remainder these lists are defined as follows:
422 Entry list (cache) Server type List type Contents
423 =======================================================================
424 servers server local list Server itself
425 servers server global list NULL
426 servers router local list All servers in cell
427 servers router global list All servers in SILC
429 clients server local list All clients in server
430 clients server global list NULL
431 clients router local list All clients in cell
432 clients router global list All clients in SILC
434 channels server local list All channels in server
435 channels server global list NULL
436 channels router local list All channels in cell
437 channels router global list All channels in SILC
439 As seen on the list normal server never defines a global list. This is
440 because of normal server don't know anything about anything global data,
441 they get it from the router if and when they need it. Routers, on the
442 other hand, always define local and global lists because routers really
443 know all the relevant data in the SILC network.
445 This object is used as local and global list by the server/router.
446 Above table shows how this is defined on different conditions.
448 This object holds pointers to the ID cache system. Every ID cache entry
449 has a specific context pointer to allocated entry (server, client or
453 typedef struct SilcIDListStruct {
456 SilcIDCache channels;
460 ID Entry for Unknown connections.
462 This is used during authentication phases where we still don't know
463 what kind of connection remote connection is, hence, we will use this
464 structure instead until we know what type of connection remote end is.
466 This is not in any list. This is always individually allocated and
471 /* Generic data structure. DO NOT add anything before this! */
472 SilcIDListDataStruct data;
476 void silc_idlist_add_data(void *entry, SilcIDListData idata);
477 void silc_idlist_del_data(void *entry);
478 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
480 silc_idlist_add_server(SilcIDList id_list,
481 char *server_name, int server_type,
482 SilcServerID *id, SilcServerEntry router,
485 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
486 SilcIDCacheEntry *ret_entry);
488 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
489 SilcIDCacheEntry *ret_entry);
491 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
492 int port, SilcIDCacheEntry *ret_entry);
494 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
495 SilcServerID *new_id);
496 void silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
498 silc_idlist_add_client(SilcIDList id_list, unsigned char *nickname,
499 unsigned int nickname_len, char *username,
500 char *userinfo, SilcClientID *id,
501 SilcServerEntry router, void *connection);
502 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
504 silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
505 char *server, unsigned int *clients_count);
507 silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
509 unsigned int *clients_count);
511 silc_idlist_find_client_by_nickname(SilcIDList id_list, char *nickname,
513 SilcIDCacheEntry *ret_entry);
515 silc_idlist_find_client_by_hash(SilcIDList id_list, char *nickname,
516 SilcHash md5hash, SilcIDCacheEntry *ret_entry);
518 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
519 SilcIDCacheEntry *ret_entry);
521 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
522 SilcClientID *new_id);
523 void silc_idlist_client_destructor(SilcIDCache cache,
524 SilcIDCacheEntry entry);
526 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
527 SilcChannelID *id, SilcServerEntry router,
528 SilcCipher channel_key, SilcHmac hmac);
529 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
531 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
532 SilcIDCacheEntry *ret_entry);
534 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
535 SilcIDCacheEntry *ret_entry);
537 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
538 SilcChannelID *new_id);
540 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
541 unsigned int *channels_count);