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 */
65 #define SILC_IDLIST_STATUS_RESUMED 0x10 /* Entry is resumed */
68 Generic ID list data structure.
70 This structure is included in all ID list entries and it includes data
71 pointers that are common to all ID entries. This structure is always
72 defined to the first field in the ID entries and is used to explicitly
73 type cast to this type without first explicitly casting to correct ID
74 entry type. Hence, the ID list entry is type casted to this type to
75 get this data from the ID entry (which is usually opaque pointer).
77 Note that some of the fields may be NULL.
81 /* Send and receive symmetric keys */
83 SilcCipher receive_key;
87 SilcHmac hmac_receive;
89 /* Packet sequence numbers */
91 SilcUInt32 psn_receive;
93 /* Hash selected in the SKE protocol, NULL if not needed at all */
97 SilcPublicKey public_key;
98 unsigned char fingerprint[20];
101 SilcServerRekey rekey;
103 long last_receive; /* Time last received data */
104 long last_sent; /* Time last sent data */
106 unsigned long created; /* Time when entry was created */
108 SilcIDListStatus status; /* Status mask of the entry */
109 } *SilcIDListData, SilcIDListDataStruct;
112 SILC Server entry object.
114 This entry holds information about servers in SILC network. However,
115 contents of this entry is highly dependent of what kind of server we are
116 (normal server or router server) and whether the entry is used as a local
117 list or a global list. These factors dictates the contents of this entry.
119 This entry is defined as follows:
121 Server type List type Contents
122 =======================================================================
123 server local list Server itself
124 server global list NULL
125 router local list All servers is the cell
126 router global list All servers in the SILC network
128 Following short description of the fields:
130 SilcIDListDataStruct data
132 Generic data structure to hold data common to all ID entries.
136 Logical name of the server. There is no limit of the length of the
137 server name. This is usually the same name as defined in DNS.
139 SilcUInt8 server_type
141 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
146 ID of the server. This includes all the relevant information about
147 the server SILC will ever need. These are also the informations
148 that is broadcasted between servers and routers in the SILC network.
153 Server info (from INFO command) saved temporarily and motd (from
154 MOTD command) saved temporarily.
156 SilcServerEntry router
158 This is a pointer back to the server list. This is the router server
159 where this server is connected to. If this is the router itself and
160 it doesn't have a route this is NULL.
163 SilcCipher receive_key
165 Data sending and receiving keys.
169 A pointer, usually, to the socket list for fast referencing to
170 the data used in connection with this server. This may be anything
171 but as just said, this is usually pointer to the socket connection
175 struct SilcServerEntryStruct {
176 /* Generic data structure. DO NOT add anything before this! */
177 SilcIDListDataStruct data;
180 SilcUInt8 server_type;
185 /* Pointer to the router */
186 SilcServerEntry router;
188 /* Connection data */
193 SILC Channel Client entry structure.
195 This entry used only by the SilcChannelEntry object and it holds
196 information about current clients (ie. users) on channel. Following
197 short description of the fields:
199 SilcClientEntry client
201 Pointer to the client list. This is the client currently on channel.
205 Client's current mode on the channel.
207 SilcChannelEntry channel
209 Back pointer back to channel. As this structure is also used by
210 SilcClientEntry we have this here for fast access to the channel when
211 used by SilcClientEntry.
214 typedef struct SilcChannelClientEntryStruct {
215 SilcClientEntry client;
217 SilcChannelEntry channel;
218 } *SilcChannelClientEntry;
221 SILC Client entry object.
223 This entry holds information about connected clients ie. users in the SILC
224 network. The contents of this entrt is depended on whether we are normal
225 server or router server and whether the list is a local or global list.
227 This entry is defined as follows:
229 Server type List type Contents
230 =======================================================================
231 server local list All clients in server
232 server global list NULL
233 router local list All clients in cell
234 router global list All clients in SILC
236 Following short description of the fields:
238 SilcIDListDataStruct data
240 Generic data structure to hold data common to all ID entries.
242 unsigned char *nickname
244 The nickname of the client.
248 The name of the server where the client is from. MAy be NULL.
252 Client's usename. This is defined in the following manner:
254 Server type List type Contents
255 ====================================================
256 server local list User's name
257 router local list NULL
258 router global list NULL
260 Router doesn't hold this information since it is not vital data
261 for the router. If this information is needed by the client it is
262 fetched when it is needed.
266 Information about user. This is free information and can be virtually
267 anything. This is defined in following manner:
269 Server type List type Contents
270 ====================================================
271 server local list User's information
272 router local list NULL
273 router global list NULL
275 Router doesn't hold this information since it is not vital data
276 for the router. If this information is needed by the client it is
277 fetched when it is needed.
281 ID of the client. This includes all the information SILC will ever
282 need. Notice that no nickname of the user is saved anywhere. This is
283 beacuse of SilcClientID includes 88 bit hash value of the user's
284 nickname which can be used to track down specific user by their
285 nickname. Nickname is not relevant information that would need to be
290 Client's mode. Client maybe for example server operator or
291 router operator (SILC operator).
295 Time of last time client executed command. We are strict and will
296 not allow any command to be exeucted more than once in about
297 2 seconds. This is result of normal time().
299 SilcUInt8 fast_command
301 Counter to check command bursts. By default, up to 5 commands
302 are allowed before limiting the execution. See command flags
305 SilcServerEntry router
307 This is a pointer to the server list. This is the router server whose
308 cell this client is coming from. This is used to route messages to
311 SilcHashTable channels;
313 All the channels this client has joined. The context saved in the
314 hash table shares memory with the channel entrys `user_list' hash
319 A pointer, usually, to the socket list for fast referencing to
320 the data used in connection with this client. This may be anything
321 but as just said, this is usually pointer to the socket connection
324 SilcUInt16 resolve_cmd_ident
326 Command identifier for the entry when the entry's data.status
327 is SILC_IDLIST_STATUS_RESOLVING. If this entry is asked to be
328 resolved when the status is set then the resolver may attach to
329 this command identifier and handle the process after the resolving
333 struct SilcClientEntryStruct {
334 /* Generic data structure. DO NOT add anything before this! */
335 SilcIDListDataStruct data;
337 unsigned char *nickname;
345 SilcUInt8 fast_command;
347 /* Pointer to the router */
348 SilcServerEntry router;
350 /* All channels this client has joined */
351 SilcHashTable channels;
353 /* Connection data */
356 /* data.status is RESOLVING and this includes the resolving command
358 SilcUInt16 resolve_cmd_ident;
362 SILC Channel entry object.
364 This entry holds information about channels in SILC network. The contents
365 of this entry is depended on whether we are normal server or router server
366 and whether the list is a local or global list.
368 This entry is defined as follows:
370 Server type List type Contents
371 =======================================================================
372 server local list All channels in server
373 server global list NULL
374 router local list All channels in cell
375 router global list All channels in SILC
377 Following short description of the fields:
381 Logical name of the channel.
385 Current mode of the channel. See lib/silccore/silcchannel.h for
390 ID of the channel. This includes all the information SILC will ever
395 Boolean value to tell whether there are users outside this server
396 on this channel. This is set to TRUE if router sends message to
397 the server that there are users outside your server on your
398 channel as well. This way server knows that messages needs to be
399 sent to the router for further routing. If this is a normal
400 server and this channel is not created on this server this field
401 is always TRUE. If this server is a router this field is ignored.
405 Current topic of the channel.
409 Default cipher of the channel. If this is NULL then server picks
410 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
414 Default hmac of the channel. If this is NULL then server picks
415 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
417 SilcPublicKey founder_key
418 SilcAuthMethod founder_method
419 unsigned char *founder_passwd
420 SilcUInt32 founder_passwd_len
422 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
423 the founder's public key, authentication method and the password
424 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
425 then the `founder_passwd' is NULL.
427 SilcHashTable user_list
429 All users joined on this channel. Note that the context saved to
430 this entry shares memory with the client entrys `channels' hash
433 SilcServerEntry router
435 This is a pointer to the server list. This is the router server
436 whose cell this channel belongs to. This is used to route messages
439 SilcCipher channel_key
441 The key of the channel (the cipher actually).
446 Raw key data of the channel key.
448 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
450 Current initial vector. Initial vector is received always along
451 with the channel packet. By default this is filled with NULL.
457 SilcServerChannelRekey rekey
459 Channel key re-key context.
462 struct SilcChannelEntryStruct {
471 SilcPublicKey founder_key;
472 SilcAuthMethod founder_method;
473 unsigned char *founder_passwd;
474 SilcUInt32 founder_passwd_len;
476 SilcUInt32 user_limit;
477 unsigned char *passphrase;
481 /* All users on this channel */
482 SilcHashTable user_list;
483 SilcUInt32 user_count;
485 /* Pointer to the router */
486 SilcServerEntry router;
489 SilcCipher channel_key;
492 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
495 SilcServerChannelRekey rekey;
497 unsigned long created;
505 As for remainder these lists are defined as follows:
507 Entry list (cache) Server type List type Contents
508 =======================================================================
509 servers server local list Server itself
510 servers server global list NULL
511 servers router local list All servers in cell
512 servers router global list All servers in SILC
514 clients server local list All clients in server
515 clients server global list NULL
516 clients router local list All clients in cell
517 clients router global list All clients in SILC
519 channels server local list All channels in server
520 channels server global list NULL
521 channels router local list All channels in cell
522 channels router global list All channels in SILC
524 As seen on the list normal server never defines a global list. This is
525 because of normal server don't know anything about anything global data,
526 they get it from the router if and when they need it. Routers, on the
527 other hand, always define local and global lists because routers really
528 know all the relevant data in the SILC network.
530 This object is used as local and global list by the server/router.
531 Above table shows how this is defined on different conditions.
533 This object holds pointers to the ID cache system. Every ID cache entry
534 has a specific context pointer to allocated entry (server, client or
538 typedef struct SilcIDListStruct {
541 SilcIDCache channels;
545 ID Entry for Unknown connections.
547 This is used during authentication phases where we still don't know
548 what kind of connection remote connection is, hence, we will use this
549 structure instead until we know what type of connection remote end is.
551 This is not in any list. This is always individually allocated and
556 /* Generic data structure. DO NOT add anything before this! */
557 SilcIDListDataStruct data;
561 void silc_idlist_add_data(void *entry, SilcIDListData idata);
562 void silc_idlist_del_data(void *entry);
563 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
565 silc_idlist_add_server(SilcIDList id_list,
566 char *server_name, int server_type,
567 SilcServerID *id, SilcServerEntry router,
570 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
571 bool registered, SilcIDCacheEntry *ret_entry);
573 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
574 bool registered, SilcIDCacheEntry *ret_entry);
576 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
577 int port, bool registered,
578 SilcIDCacheEntry *ret_entry);
580 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
581 SilcServerID *new_id);
582 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
584 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
585 char *userinfo, SilcClientID *id,
586 SilcServerEntry router, void *connection,
588 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
589 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
591 SilcClientEntry **clients,
592 SilcUInt32 *clients_count);
593 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
595 SilcClientEntry **clients,
596 SilcUInt32 *clients_count);
598 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
599 bool registered, SilcIDCacheEntry *ret_entry);
601 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
602 SilcClientID *new_id, const char *nickname);
603 void silc_idlist_client_destructor(SilcIDCache cache,
604 SilcIDCacheEntry entry);
606 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
607 SilcChannelID *id, SilcServerEntry router,
608 SilcCipher channel_key, SilcHmac hmac,
610 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
612 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
613 SilcIDCacheEntry *ret_entry);
615 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
616 SilcIDCacheEntry *ret_entry);
618 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
619 SilcChannelID *new_id);
621 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
622 SilcUInt32 *channels_count);