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
33 SilcSchedule schedule;
36 /* Channel key re-key context. */
39 SilcChannelEntry channel;
42 } *SilcServerChannelRekey;
44 /* Generic rekey context for connections */
46 /* Current sending encryption key, provided for re-key. The `pfs'
47 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
48 unsigned char *send_enc_key;
56 /* ID List Entry status type and all the types. */
57 typedef uint8 SilcIDListStatus;
58 #define SILC_IDLIST_STATUS_NONE 0x00 /* No status */
59 #define SILC_IDLIST_STATUS_REGISTERED 0x01 /* Entry is registered */
60 #define SILC_IDLIST_STATUS_RESOLVED 0x02 /* Entry info is resolved */
61 #define SILC_IDLIST_STATUS_RESOLVING 0x04 /* Entry is being resolved
62 with WHOIS or IDENTIFY */
63 #define SILC_IDLIST_STATUS_DISABLED 0x08 /* Entry is disabled */
66 Generic ID list data structure.
68 This structure is included in all ID list entries and it includes data
69 pointers that are common to all ID entries. This structure is always
70 defined to the first field in the ID entries and is used to explicitly
71 type cast to this type without first explicitly casting to correct ID
72 entry type. Hence, the ID list entry is type casted to this type to
73 get this data from the ID entry (which is usually opaque pointer).
75 Note that some of the fields may be NULL.
79 /* Send and receive symmetric keys */
81 SilcCipher receive_key;
84 SilcServerRekey rekey;
86 /* Hash selected in the SKE protocol, NULL if not needed at all */
91 SilcHmac hmac_receive;
94 SilcPublicKey public_key;
96 long last_receive; /* Time last received data */
97 long last_sent; /* Time last sent data */
99 unsigned long created; /* Time when entry was created */
101 SilcIDListStatus status; /* Status mask of the entry */
102 } *SilcIDListData, SilcIDListDataStruct;
105 SILC Server entry object.
107 This entry holds information about servers in SILC network. However,
108 contents of this entry is highly dependent of what kind of server we are
109 (normal server or router server) and whether the entry is used as a local
110 list or a global list. These factors dictates the contents of this entry.
112 This entry is defined as follows:
114 Server type List type Contents
115 =======================================================================
116 server local list Server itself
117 server global list NULL
118 router local list All servers is the cell
119 router global list All servers in the SILC network
121 Following short description of the fields:
123 SilcIDListDataStruct data
125 Generic data structure to hold data common to all ID entries.
129 Logical name of the server. There is no limit of the length of the
130 server name. This is usually the same name as defined in DNS.
134 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
139 ID of the server. This includes all the relevant information about
140 the server SILC will ever need. These are also the informations
141 that is broadcasted between servers and routers in the SILC network.
146 Server info (from INFO command) saved temporarily and motd (from
147 MOTD command) saved temporarily.
149 SilcServerEntry router
151 This is a pointer back to the server list. This is the router server
152 where this server is connected to. If this is the router itself and
153 it doesn't have a route this is NULL.
156 SilcCipher receive_key
158 Data sending and receiving keys.
162 A pointer, usually, to the socket list for fast referencing to
163 the data used in connection with this server. This may be anything
164 but as just said, this is usually pointer to the socket connection
168 struct SilcServerEntryStruct {
169 /* Generic data structure. DO NOT add anything before this! */
170 SilcIDListDataStruct data;
178 /* Pointer to the router */
179 SilcServerEntry router;
181 /* Connection data */
186 SILC Channel Client entry structure.
188 This entry used only by the SilcChannelEntry object and it holds
189 information about current clients (ie. users) on channel. Following
190 short description of the fields:
192 SilcClientEntry client
194 Pointer to the client list. This is the client currently on channel.
198 Client's current mode on the channel.
200 SilcChannelEntry channel
202 Back pointer back to channel. As this structure is also used by
203 SilcClientEntry we have this here for fast access to the channel when
204 used by SilcClientEntry.
207 typedef struct SilcChannelClientEntryStruct {
208 SilcClientEntry client;
210 SilcChannelEntry channel;
211 } *SilcChannelClientEntry;
214 SILC Client entry object.
216 This entry holds information about connected clients ie. users in the SILC
217 network. The contents of this entrt is depended on whether we are normal
218 server or router server and whether the list is a local or global list.
220 This entry is defined as follows:
222 Server type List type Contents
223 =======================================================================
224 server local list All clients in server
225 server global list NULL
226 router local list All clients in cell
227 router global list All clients in SILC
229 Following short description of the fields:
231 SilcIDListDataStruct data
233 Generic data structure to hold data common to all ID entries.
235 unsigned char *nickname
237 The nickname of the client.
241 The name of the server where the client is from. MAy be NULL.
245 Client's usename. This is defined in the following manner:
247 Server type List type Contents
248 ====================================================
249 server local list User's name
250 router local list NULL
251 router global list NULL
253 Router doesn't hold this information since it is not vital data
254 for the router. If this information is needed by the client it is
255 fetched when it is needed.
259 Information about user. This is free information and can be virtually
260 anything. This is defined in following manner:
262 Server type List type Contents
263 ====================================================
264 server local list User's information
265 router local list NULL
266 router global list NULL
268 Router doesn't hold this information since it is not vital data
269 for the router. If this information is needed by the client it is
270 fetched when it is needed.
274 ID of the client. This includes all the information SILC will ever
275 need. Notice that no nickname of the user is saved anywhere. This is
276 beacuse of SilcClientID includes 88 bit hash value of the user's
277 nickname which can be used to track down specific user by their
278 nickname. Nickname is not relevant information that would need to be
283 Client's mode. Client maybe for example server operator or
284 router operator (SILC operator).
288 Time of last time client executed command. We are strict and will
289 not allow any command to be exeucted more than once in about
290 2 seconds. This is result of normal time().
294 Counter to check command bursts. By default, up to 5 commands
295 are allowed before limiting the execution. See command flags
298 SilcServerEntry router
300 This is a pointer to the server list. This is the router server whose
301 cell this client is coming from. This is used to route messages to
304 SilcHashTable channels;
306 All the channels this client has joined. The context saved in the
307 hash table shares memory with the channel entrys `user_list' hash
312 A pointer, usually, to the socket list for fast referencing to
313 the data used in connection with this client. This may be anything
314 but as just said, this is usually pointer to the socket connection
317 uint16 resolve_cmd_ident
319 Command identifier for the entry when the entry's data.status
320 is SILC_IDLIST_STATUS_RESOLVING. If this entry is asked to be
321 resolved when the status is set then the resolver may attach to
322 this command identifier and handle the process after the resolving
326 struct SilcClientEntryStruct {
327 /* Generic data structure. DO NOT add anything before this! */
328 SilcIDListDataStruct data;
330 unsigned char *nickname;
340 /* Pointer to the router */
341 SilcServerEntry router;
343 /* All channels this client has joined */
344 SilcHashTable channels;
346 /* Connection data */
349 /* data.status is RESOLVING and this includes the resolving command
351 uint16 resolve_cmd_ident;
355 SILC Channel entry object.
357 This entry holds information about channels in SILC network. The contents
358 of this entry is depended on whether we are normal server or router server
359 and whether the list is a local or global list.
361 This entry is defined as follows:
363 Server type List type Contents
364 =======================================================================
365 server local list All channels in server
366 server global list NULL
367 router local list All channels in cell
368 router global list All channels in SILC
370 Following short description of the fields:
374 Logical name of the channel.
378 Current mode of the channel. See lib/silccore/silcchannel.h for
383 ID of the channel. This includes all the information SILC will ever
388 Boolean value to tell whether there are users outside this server
389 on this channel. This is set to TRUE if router sends message to
390 the server that there are users outside your server on your
391 channel as well. This way server knows that messages needs to be
392 sent to the router for further routing. If this is a normal
393 server and this channel is not created on this server this field
394 is always TRUE. If this server is a router this field is ignored.
398 Current topic of the channel.
402 Default cipher of the channel. If this is NULL then server picks
403 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
407 Default hmac of the channel. If this is NULL then server picks
408 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
410 SilcPublicKey founder_key
411 SilcAuthMethod founder_method
412 unsigned char *founder_passwd
413 uint32 founder_passwd_len
415 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
416 the founder's public key, authentication method and the password
417 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
418 then the `founder_passwd' is NULL.
420 SilcHashTable user_list
422 All users joined on this channel. Note that the context saved to
423 this entry shares memory with the client entrys `channels' hash
426 SilcServerEntry router
428 This is a pointer to the server list. This is the router server
429 whose cell this channel belongs to. This is used to route messages
432 SilcCipher channel_key
434 The key of the channel (the cipher actually).
439 Raw key data of the channel key.
441 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
443 Current initial vector. Initial vector is received always along
444 with the channel packet. By default this is filled with NULL.
450 SilcServerChannelRekey rekey
452 Channel key re-key context.
455 struct SilcChannelEntryStruct {
464 SilcPublicKey founder_key;
465 SilcAuthMethod founder_method;
466 unsigned char *founder_passwd;
467 uint32 founder_passwd_len;
470 unsigned char *passphrase;
474 /* All users on this channel */
475 SilcHashTable user_list;
477 /* Pointer to the router */
478 SilcServerEntry router;
481 SilcCipher channel_key;
484 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
487 SilcServerChannelRekey rekey;
489 unsigned long created;
495 As for remainder these lists are defined as follows:
497 Entry list (cache) Server type List type Contents
498 =======================================================================
499 servers server local list Server itself
500 servers server global list NULL
501 servers router local list All servers in cell
502 servers router global list All servers in SILC
504 clients server local list All clients in server
505 clients server global list NULL
506 clients router local list All clients in cell
507 clients router global list All clients in SILC
509 channels server local list All channels in server
510 channels server global list NULL
511 channels router local list All channels in cell
512 channels router global list All channels in SILC
514 As seen on the list normal server never defines a global list. This is
515 because of normal server don't know anything about anything global data,
516 they get it from the router if and when they need it. Routers, on the
517 other hand, always define local and global lists because routers really
518 know all the relevant data in the SILC network.
520 This object is used as local and global list by the server/router.
521 Above table shows how this is defined on different conditions.
523 This object holds pointers to the ID cache system. Every ID cache entry
524 has a specific context pointer to allocated entry (server, client or
528 typedef struct SilcIDListStruct {
531 SilcIDCache channels;
535 ID Entry for Unknown connections.
537 This is used during authentication phases where we still don't know
538 what kind of connection remote connection is, hence, we will use this
539 structure instead until we know what type of connection remote end is.
541 This is not in any list. This is always individually allocated and
546 /* Generic data structure. DO NOT add anything before this! */
547 SilcIDListDataStruct data;
551 void silc_idlist_add_data(void *entry, SilcIDListData idata);
552 void silc_idlist_del_data(void *entry);
553 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
555 silc_idlist_add_server(SilcIDList id_list,
556 char *server_name, int server_type,
557 SilcServerID *id, SilcServerEntry router,
560 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
561 bool registered, SilcIDCacheEntry *ret_entry);
563 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
564 bool registered, SilcIDCacheEntry *ret_entry);
566 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
567 int port, bool registered,
568 SilcIDCacheEntry *ret_entry);
570 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
571 SilcServerID *new_id);
572 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
574 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
575 char *userinfo, SilcClientID *id,
576 SilcServerEntry router, void *connection);
577 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
578 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
580 SilcClientEntry **clients,
581 uint32 *clients_count);
582 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
584 SilcClientEntry **clients,
585 uint32 *clients_count);
587 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
588 bool registered, SilcIDCacheEntry *ret_entry);
590 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
591 SilcClientID *new_id);
592 void silc_idlist_client_destructor(SilcIDCache cache,
593 SilcIDCacheEntry entry);
595 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
596 SilcChannelID *id, SilcServerEntry router,
597 SilcCipher channel_key, SilcHmac hmac);
598 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
600 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
601 SilcIDCacheEntry *ret_entry);
603 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
604 SilcIDCacheEntry *ret_entry);
606 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
607 SilcChannelID *new_id);
609 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
610 uint32 *channels_count);