5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2002 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;
37 /* Channel key re-key context. */
40 SilcChannelEntry channel;
43 } *SilcServerChannelRekey;
45 /* Generic rekey context for connections */
47 /* Current sending encryption key, provided for re-key. The `pfs'
48 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
49 unsigned char *send_enc_key;
50 SilcUInt32 enc_key_len;
57 /* ID List Entry status type and all the types. */
58 typedef SilcUInt8 SilcIDListStatus;
59 #define SILC_IDLIST_STATUS_NONE 0x00 /* No status */
60 #define SILC_IDLIST_STATUS_REGISTERED 0x01 /* Entry is registered */
61 #define SILC_IDLIST_STATUS_RESOLVED 0x02 /* Entry info is resolved */
62 #define SILC_IDLIST_STATUS_RESOLVING 0x04 /* Entry is being resolved
63 with WHOIS or IDENTIFY */
64 #define SILC_IDLIST_STATUS_DISABLED 0x08 /* Entry is disabled */
67 Generic ID list data structure.
69 This structure is included in all ID list entries and it includes data
70 pointers that are common to all ID entries. This structure is always
71 defined to the first field in the ID entries and is used to explicitly
72 type cast to this type without first explicitly casting to correct ID
73 entry type. Hence, the ID list entry is type casted to this type to
74 get this data from the ID entry (which is usually opaque pointer).
76 Note that some of the fields may be NULL.
80 /* Send and receive symmetric keys */
82 SilcCipher receive_key;
86 SilcHmac hmac_receive;
88 /* Packet sequence numbers */
90 SilcUInt32 psn_receive;
92 /* Hash selected in the SKE protocol, NULL if not needed at all */
96 SilcPublicKey public_key;
97 unsigned char fingerprint[20];
100 SilcServerRekey rekey;
102 long last_receive; /* Time last received data */
103 long last_sent; /* Time last sent data */
105 unsigned long created; /* Time when entry was created */
107 SilcIDListStatus status; /* Status mask of the entry */
108 } *SilcIDListData, SilcIDListDataStruct;
111 SILC Server entry object.
113 This entry holds information about servers in SILC network. However,
114 contents of this entry is highly dependent of what kind of server we are
115 (normal server or router server) and whether the entry is used as a local
116 list or a global list. These factors dictates the contents of this entry.
118 This entry is defined as follows:
120 Server type List type Contents
121 =======================================================================
122 server local list Server itself
123 server global list NULL
124 router local list All servers is the cell
125 router global list All servers in the SILC network
127 Following short description of the fields:
129 SilcIDListDataStruct data
131 Generic data structure to hold data common to all ID entries.
135 Logical name of the server. There is no limit of the length of the
136 server name. This is usually the same name as defined in DNS.
138 SilcUInt8 server_type
140 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
145 ID of the server. This includes all the relevant information about
146 the server SILC will ever need. These are also the informations
147 that is broadcasted between servers and routers in the SILC network.
152 Server info (from INFO command) saved temporarily and motd (from
153 MOTD command) saved temporarily.
155 SilcServerEntry router
157 This is a pointer back to the server list. This is the router server
158 where this server is connected to. If this is the router itself and
159 it doesn't have a route this is NULL.
162 SilcCipher receive_key
164 Data sending and receiving keys.
168 A pointer, usually, to the socket list for fast referencing to
169 the data used in connection with this server. This may be anything
170 but as just said, this is usually pointer to the socket connection
174 struct SilcServerEntryStruct {
175 /* Generic data structure. DO NOT add anything before this! */
176 SilcIDListDataStruct data;
179 SilcUInt8 server_type;
184 /* Pointer to the router */
185 SilcServerEntry router;
187 /* Connection data */
192 SILC Channel Client entry structure.
194 This entry used only by the SilcChannelEntry object and it holds
195 information about current clients (ie. users) on channel. Following
196 short description of the fields:
198 SilcClientEntry client
200 Pointer to the client list. This is the client currently on channel.
204 Client's current mode on the channel.
206 SilcChannelEntry channel
208 Back pointer back to channel. As this structure is also used by
209 SilcClientEntry we have this here for fast access to the channel when
210 used by SilcClientEntry.
213 typedef struct SilcChannelClientEntryStruct {
214 SilcClientEntry client;
216 SilcChannelEntry channel;
217 } *SilcChannelClientEntry;
220 SILC Client entry object.
222 This entry holds information about connected clients ie. users in the SILC
223 network. The contents of this entrt is depended on whether we are normal
224 server or router server and whether the list is a local or global list.
226 This entry is defined as follows:
228 Server type List type Contents
229 =======================================================================
230 server local list All clients in server
231 server global list NULL
232 router local list All clients in cell
233 router global list All clients in SILC
235 Following short description of the fields:
237 SilcIDListDataStruct data
239 Generic data structure to hold data common to all ID entries.
241 unsigned char *nickname
243 The nickname of the client.
247 The name of the server where the client is from. MAy be NULL.
251 Client's usename. This is defined in the following manner:
253 Server type List type Contents
254 ====================================================
255 server local list User's name
256 router local list NULL
257 router global list NULL
259 Router doesn't hold this information since it is not vital data
260 for the router. If this information is needed by the client it is
261 fetched when it is needed.
265 Information about user. This is free information and can be virtually
266 anything. This is defined in following manner:
268 Server type List type Contents
269 ====================================================
270 server local list User's information
271 router local list NULL
272 router global list NULL
274 Router doesn't hold this information since it is not vital data
275 for the router. If this information is needed by the client it is
276 fetched when it is needed.
280 ID of the client. This includes all the information SILC will ever
281 need. Notice that no nickname of the user is saved anywhere. This is
282 beacuse of SilcClientID includes 88 bit hash value of the user's
283 nickname which can be used to track down specific user by their
284 nickname. Nickname is not relevant information that would need to be
289 Client's mode. Client maybe for example server operator or
290 router operator (SILC operator).
294 Time of last time client executed command. We are strict and will
295 not allow any command to be exeucted more than once in about
296 2 seconds. This is result of normal time().
298 SilcUInt8 fast_command
300 Counter to check command bursts. By default, up to 5 commands
301 are allowed before limiting the execution. See command flags
304 SilcServerEntry router
306 This is a pointer to the server list. This is the router server whose
307 cell this client is coming from. This is used to route messages to
310 SilcHashTable channels;
312 All the channels this client has joined. The context saved in the
313 hash table shares memory with the channel entrys `user_list' hash
318 A pointer, usually, to the socket list for fast referencing to
319 the data used in connection with this client. This may be anything
320 but as just said, this is usually pointer to the socket connection
323 SilcUInt16 resolve_cmd_ident
325 Command identifier for the entry when the entry's data.status
326 is SILC_IDLIST_STATUS_RESOLVING. If this entry is asked to be
327 resolved when the status is set then the resolver may attach to
328 this command identifier and handle the process after the resolving
332 struct SilcClientEntryStruct {
333 /* Generic data structure. DO NOT add anything before this! */
334 SilcIDListDataStruct data;
336 unsigned char *nickname;
344 SilcUInt8 fast_command;
346 /* Pointer to the router */
347 SilcServerEntry router;
349 /* All channels this client has joined */
350 SilcHashTable channels;
352 /* Connection data */
355 /* data.status is RESOLVING and this includes the resolving command
357 SilcUInt16 resolve_cmd_ident;
361 SILC Channel entry object.
363 This entry holds information about channels in SILC network. The contents
364 of this entry is depended on whether we are normal server or router server
365 and whether the list is a local or global list.
367 This entry is defined as follows:
369 Server type List type Contents
370 =======================================================================
371 server local list All channels in server
372 server global list NULL
373 router local list All channels in cell
374 router global list All channels in SILC
376 Following short description of the fields:
380 Logical name of the channel.
384 Current mode of the channel. See lib/silccore/silcchannel.h for
389 ID of the channel. This includes all the information SILC will ever
394 Boolean value to tell whether there are users outside this server
395 on this channel. This is set to TRUE if router sends message to
396 the server that there are users outside your server on your
397 channel as well. This way server knows that messages needs to be
398 sent to the router for further routing. If this is a normal
399 server and this channel is not created on this server this field
400 is always TRUE. If this server is a router this field is ignored.
404 Current topic of the channel.
408 Default cipher of the channel. If this is NULL then server picks
409 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
413 Default hmac of the channel. If this is NULL then server picks
414 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
416 SilcPublicKey founder_key
417 SilcAuthMethod founder_method
418 unsigned char *founder_passwd
419 SilcUInt32 founder_passwd_len
421 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
422 the founder's public key, authentication method and the password
423 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
424 then the `founder_passwd' is NULL.
426 SilcHashTable user_list
428 All users joined on this channel. Note that the context saved to
429 this entry shares memory with the client entrys `channels' hash
432 SilcServerEntry router
434 This is a pointer to the server list. This is the router server
435 whose cell this channel belongs to. This is used to route messages
438 SilcCipher channel_key
440 The key of the channel (the cipher actually).
445 Raw key data of the channel key.
447 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
449 Current initial vector. Initial vector is received always along
450 with the channel packet. By default this is filled with NULL.
456 SilcServerChannelRekey rekey
458 Channel key re-key context.
461 struct SilcChannelEntryStruct {
470 SilcPublicKey founder_key;
471 SilcAuthMethod founder_method;
472 unsigned char *founder_passwd;
473 SilcUInt32 founder_passwd_len;
475 SilcUInt32 user_limit;
476 unsigned char *passphrase;
480 /* All users on this channel */
481 SilcHashTable user_list;
482 SilcUInt32 user_count;
484 /* Pointer to the router */
485 SilcServerEntry router;
488 SilcCipher channel_key;
491 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
494 SilcServerChannelRekey rekey;
496 unsigned long created;
503 As for remainder these lists are defined as follows:
505 Entry list (cache) Server type List type Contents
506 =======================================================================
507 servers server local list Server itself
508 servers server global list NULL
509 servers router local list All servers in cell
510 servers router global list All servers in SILC
512 clients server local list All clients in server
513 clients server global list NULL
514 clients router local list All clients in cell
515 clients router global list All clients in SILC
517 channels server local list All channels in server
518 channels server global list NULL
519 channels router local list All channels in cell
520 channels router global list All channels in SILC
522 As seen on the list normal server never defines a global list. This is
523 because of normal server don't know anything about anything global data,
524 they get it from the router if and when they need it. Routers, on the
525 other hand, always define local and global lists because routers really
526 know all the relevant data in the SILC network.
528 This object is used as local and global list by the server/router.
529 Above table shows how this is defined on different conditions.
531 This object holds pointers to the ID cache system. Every ID cache entry
532 has a specific context pointer to allocated entry (server, client or
536 typedef struct SilcIDListStruct {
539 SilcIDCache channels;
543 ID Entry for Unknown connections.
545 This is used during authentication phases where we still don't know
546 what kind of connection remote connection is, hence, we will use this
547 structure instead until we know what type of connection remote end is.
549 This is not in any list. This is always individually allocated and
554 /* Generic data structure. DO NOT add anything before this! */
555 SilcIDListDataStruct data;
559 void silc_idlist_add_data(void *entry, SilcIDListData idata);
560 void silc_idlist_del_data(void *entry);
561 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
563 silc_idlist_add_server(SilcIDList id_list,
564 char *server_name, int server_type,
565 SilcServerID *id, SilcServerEntry router,
568 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
569 bool registered, SilcIDCacheEntry *ret_entry);
571 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
572 bool registered, SilcIDCacheEntry *ret_entry);
574 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
575 int port, bool registered,
576 SilcIDCacheEntry *ret_entry);
578 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
579 SilcServerID *new_id);
580 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
582 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
583 char *userinfo, SilcClientID *id,
584 SilcServerEntry router, void *connection,
586 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
587 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
589 SilcClientEntry **clients,
590 SilcUInt32 *clients_count);
591 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
593 SilcClientEntry **clients,
594 SilcUInt32 *clients_count);
596 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
597 bool registered, SilcIDCacheEntry *ret_entry);
599 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
600 SilcClientID *new_id, const char *nickname);
601 void silc_idlist_client_destructor(SilcIDCache cache,
602 SilcIDCacheEntry entry);
604 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
605 SilcChannelID *id, SilcServerEntry router,
606 SilcCipher channel_key, SilcHmac hmac,
608 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
610 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
611 SilcIDCacheEntry *ret_entry);
613 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
614 SilcIDCacheEntry *ret_entry);
616 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
617 SilcChannelID *new_id);
619 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
620 SilcUInt32 *channels_count);