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;
41 } *SilcServerChannelRekey;
43 /* Generic rekey context for connections */
45 /* Current sending encryption key, provided for re-key. The `pfs'
46 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
47 unsigned char *send_enc_key;
55 /* ID List Entry status type and all the types. */
56 typedef uint8 SilcIDListStatus;
57 #define SILC_IDLIST_STATUS_NONE 0x00 /* No status */
58 #define SILC_IDLIST_STATUS_REGISTERED 0x01 /* Entry is registered */
59 #define SILC_IDLIST_STATUS_RESOLVED 0x02 /* Entry info is resolved */
60 #define SILC_IDLIST_STATUS_RESOLVING 0x04 /* Entry is being resolved
61 with WHOIS or IDENTIFY */
64 Generic ID list data structure.
66 This structure is included in all ID list entries and it includes data
67 pointers that are common to all ID entries. This structure is always
68 defined to the first field in the ID entries and is used to explicitly
69 type cast to this type without first explicitly casting to correct ID
70 entry type. Hence, the ID list entry is type casted to this type to
71 get this data from the ID entry (which is usually opaque pointer).
73 Note that some of the fields may be NULL.
77 /* Send and receive symmetric keys */
79 SilcCipher receive_key;
82 SilcServerRekey rekey;
84 /* Hash selected in the SKE protocol, NULL if not needed at all */
89 SilcHmac hmac_receive;
92 SilcPublicKey public_key;
94 long last_receive; /* Time last received data */
95 long last_sent; /* Time last sent data */
97 SilcIDListStatus status; /* Status mask of the entry */
98 } *SilcIDListData, SilcIDListDataStruct;
101 SILC Server entry object.
103 This entry holds information about servers in SILC network. However,
104 contents of this entry is highly dependent of what kind of server we are
105 (normal server or router server) and whether the entry is used as a local
106 list or a global list. These factors dictates the contents of this entry.
108 This entry is defined as follows:
110 Server type List type Contents
111 =======================================================================
112 server local list Server itself
113 server global list NULL
114 router local list All servers is the cell
115 router global list All servers in the SILC network
117 Following short description of the fields:
119 SilcIDListDataStruct data
121 Generic data structure to hold data common to all ID entries.
125 Logical name of the server. There is no limit of the length of the
126 server name. This is usually the same name as defined in DNS.
130 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
135 ID of the server. This includes all the relevant information about
136 the server SILC will ever need. These are also the informations
137 that is broadcasted between servers and routers in the SILC network.
142 Server info (from INFO command) saved temporarily and motd (from
143 MOTD command) saved temporarily.
145 SilcServerEntry router
147 This is a pointer back to the server list. This is the router server
148 where this server is connected to. If this is the router itself and
149 it doesn't have a route this is NULL.
152 SilcCipher receive_key
154 Data sending and receiving keys.
158 A pointer, usually, to the socket list for fast referencing to
159 the data used in connection with this server. This may be anything
160 but as just said, this is usually pointer to the socket connection
164 struct SilcServerEntryStruct {
165 /* Generic data structure. DO NOT add anything before this! */
166 SilcIDListDataStruct data;
174 /* Pointer to the router */
175 SilcServerEntry router;
177 /* Connection data */
182 SILC Channel Client entry structure.
184 This entry used only by the SilcChannelEntry object and it holds
185 information about current clients (ie. users) on channel. Following
186 short description of the fields:
188 SilcClientEntry client
190 Pointer to the client list. This is the client currently on channel.
194 Client's current mode on the channel.
196 SilcChannelEntry channel
198 Back pointer back to channel. As this structure is also used by
199 SilcClientEntry we have this here for fast access to the channel when
200 used by SilcClientEntry.
203 typedef struct SilcChannelClientEntryStruct {
204 SilcClientEntry client;
206 SilcChannelEntry channel;
207 } *SilcChannelClientEntry;
210 SILC Client entry object.
212 This entry holds information about connected clients ie. users in the SILC
213 network. The contents of this entrt is depended on whether we are normal
214 server or router server and whether the list is a local or global list.
216 This entry is defined as follows:
218 Server type List type Contents
219 =======================================================================
220 server local list All clients in server
221 server global list NULL
222 router local list All clients in cell
223 router global list All clients in SILC
225 Following short description of the fields:
227 SilcIDListDataStruct data
229 Generic data structure to hold data common to all ID entries.
231 unsigned char *nickname
233 The nickname of the client.
237 The name of the server where the client is from. MAy be NULL.
241 Client's usename. This is defined in the following manner:
243 Server type List type Contents
244 ====================================================
245 server local list User's name
246 router local list NULL
247 router global list NULL
249 Router doesn't hold this information since it is not vital data
250 for the router. If this information is needed by the client it is
251 fetched when it is needed.
255 Information about user. This is free information and can be virtually
256 anything. This is defined in following manner:
258 Server type List type Contents
259 ====================================================
260 server local list User's information
261 router local list NULL
262 router global list NULL
264 Router doesn't hold this information since it is not vital data
265 for the router. If this information is needed by the client it is
266 fetched when it is needed.
270 ID of the client. This includes all the information SILC will ever
271 need. Notice that no nickname of the user is saved anywhere. This is
272 beacuse of SilcClientID includes 88 bit hash value of the user's
273 nickname which can be used to track down specific user by their
274 nickname. Nickname is not relevant information that would need to be
279 Client's mode. Client maybe for example server operator or
280 router operator (SILC operator).
284 Time of last time client executed command. We are strict and will
285 not allow any command to be exeucted more than once in about
286 2 seconds. This is result of normal time().
290 Counter to check command bursts. By default, up to 5 commands
291 are allowed before limiting the execution. See command flags
294 SilcServerEntry router
296 This is a pointer to the server list. This is the router server whose
297 cell this client is coming from. This is used to route messages to
300 SilcHashTable channels;
302 All the channels this client has joined. The context saved in the
303 hash table shares memory with the channel entrys `user_list' hash
308 A pointer, usually, to the socket list for fast referencing to
309 the data used in connection with this client. This may be anything
310 but as just said, this is usually pointer to the socket connection
313 uint16 resolve_cmd_ident
315 Command identifier for the entry when the entry's data.status
316 is SILC_IDLIST_STATUS_RESOLVING. If this entry is asked to be
317 resolved when the status is set then the resolver may attach to
318 this command identifier and handle the process after the resolving
322 struct SilcClientEntryStruct {
323 /* Generic data structure. DO NOT add anything before this! */
324 SilcIDListDataStruct data;
326 unsigned char *nickname;
336 /* Pointer to the router */
337 SilcServerEntry router;
339 /* All channels this client has joined */
340 SilcHashTable channels;
342 /* Connection data */
345 /* data.status is RESOLVING and this includes the resolving command
347 uint16 resolve_cmd_ident;
351 SILC Channel entry object.
353 This entry holds information about channels in SILC network. The contents
354 of this entry is depended on whether we are normal server or router server
355 and whether the list is a local or global list.
357 This entry is defined as follows:
359 Server type List type Contents
360 =======================================================================
361 server local list All channels in server
362 server global list NULL
363 router local list All channels in cell
364 router global list All channels in SILC
366 Following short description of the fields:
370 Logical name of the channel.
374 Current mode of the channel. See lib/silccore/silcchannel.h for
379 ID of the channel. This includes all the information SILC will ever
384 Boolean value to tell whether there are users outside this server
385 on this channel. This is set to TRUE if router sends message to
386 the server that there are users outside your server on your
387 channel as well. This way server knows that messages needs to be
388 sent to the router for further routing. If this is a normal
389 server and this channel is not created on this server this field
390 is always TRUE. If this server is a router this field is ignored.
394 Current topic of the channel.
398 Default cipher of the channel. If this is NULL then server picks
399 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
403 Default hmac of the channel. If this is NULL then server picks
404 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
406 SilcPublicKey founder_key
407 SilcAuthMethod founder_method
408 unsigned char *founder_passwd
409 uint32 founder_passwd_len
411 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
412 the founder's public key, authentication method and the password
413 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
414 then the `founder_passwd' is NULL.
416 SilcHashTable user_list
418 All users joined on this channel. Note that the context saved to
419 this entry shares memory with the client entrys `channels' hash
422 SilcServerEntry router
424 This is a pointer to the server list. This is the router server
425 whose cell this channel belongs to. This is used to route messages
428 SilcCipher channel_key
430 The key of the channel (the cipher actually).
435 Raw key data of the channel key.
437 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
439 Current initial vector. Initial vector is received always along
440 with the channel packet. By default this is filled with NULL.
446 SilcServerChannelRekey rekey
448 Channel key re-key context.
451 struct SilcChannelEntryStruct {
460 SilcPublicKey founder_key;
461 SilcAuthMethod founder_method;
462 unsigned char *founder_passwd;
463 uint32 founder_passwd_len;
466 unsigned char *passphrase;
470 /* All users on this channel */
471 SilcHashTable user_list;
473 /* Pointer to the router */
474 SilcServerEntry router;
477 SilcCipher channel_key;
480 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
483 SilcServerChannelRekey rekey;
489 As for remainder these lists are defined as follows:
491 Entry list (cache) Server type List type Contents
492 =======================================================================
493 servers server local list Server itself
494 servers server global list NULL
495 servers router local list All servers in cell
496 servers router global list All servers in SILC
498 clients server local list All clients in server
499 clients server global list NULL
500 clients router local list All clients in cell
501 clients router global list All clients in SILC
503 channels server local list All channels in server
504 channels server global list NULL
505 channels router local list All channels in cell
506 channels router global list All channels in SILC
508 As seen on the list normal server never defines a global list. This is
509 because of normal server don't know anything about anything global data,
510 they get it from the router if and when they need it. Routers, on the
511 other hand, always define local and global lists because routers really
512 know all the relevant data in the SILC network.
514 This object is used as local and global list by the server/router.
515 Above table shows how this is defined on different conditions.
517 This object holds pointers to the ID cache system. Every ID cache entry
518 has a specific context pointer to allocated entry (server, client or
522 typedef struct SilcIDListStruct {
525 SilcIDCache channels;
529 ID Entry for Unknown connections.
531 This is used during authentication phases where we still don't know
532 what kind of connection remote connection is, hence, we will use this
533 structure instead until we know what type of connection remote end is.
535 This is not in any list. This is always individually allocated and
540 /* Generic data structure. DO NOT add anything before this! */
541 SilcIDListDataStruct data;
545 void silc_idlist_add_data(void *entry, SilcIDListData idata);
546 void silc_idlist_del_data(void *entry);
547 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
549 silc_idlist_add_server(SilcIDList id_list,
550 char *server_name, int server_type,
551 SilcServerID *id, SilcServerEntry router,
554 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
555 bool registered, SilcIDCacheEntry *ret_entry);
557 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
558 bool registered, SilcIDCacheEntry *ret_entry);
560 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
561 int port, bool registered,
562 SilcIDCacheEntry *ret_entry);
564 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
565 SilcServerID *new_id);
566 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
568 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
569 char *userinfo, SilcClientID *id,
570 SilcServerEntry router, void *connection);
571 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
572 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
574 SilcClientEntry **clients,
575 uint32 *clients_count);
576 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
578 SilcClientEntry **clients,
579 uint32 *clients_count);
581 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
582 bool registered, SilcIDCacheEntry *ret_entry);
584 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
585 SilcClientID *new_id);
586 void silc_idlist_client_destructor(SilcIDCache cache,
587 SilcIDCacheEntry entry);
589 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
590 SilcChannelID *id, SilcServerEntry router,
591 SilcCipher channel_key, SilcHmac hmac);
592 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
594 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
595 SilcIDCacheEntry *ret_entry);
597 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
598 SilcIDCacheEntry *ret_entry);
600 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
601 SilcChannelID *new_id);
603 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
604 uint32 *channels_count);