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
419 If the SILC_CMODE_FOUNDER_AUTH has been set then this will include
420 the founder's public key. When the mode and this key is set the
421 channel is also permanent channel and cannot be destroyed.
423 SilcHashTable user_list
425 All users joined on this channel. Note that the context saved to
426 this entry shares memory with the client entrys `channels' hash
429 SilcServerEntry router
431 This is a pointer to the server list. This is the router server
432 whose cell this channel belongs to. This is used to route messages
435 SilcCipher channel_key
437 The key of the channel (the cipher actually).
442 Raw key data of the channel key.
444 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
446 Current initial vector. Initial vector is received always along
447 with the channel packet. By default this is filled with NULL.
453 SilcServerChannelRekey rekey
455 Channel key re-key context.
458 struct SilcChannelEntryStruct {
465 SilcPublicKey founder_key;
467 SilcUInt32 user_limit;
468 unsigned char *passphrase;
472 /* All users on this channel */
473 SilcHashTable user_list;
474 SilcUInt32 user_count;
476 /* Pointer to the router */
477 SilcServerEntry router;
480 SilcCipher channel_key;
485 SilcServerChannelRekey rekey;
486 unsigned long created;
489 unsigned int global_users : 1;
490 unsigned int disabled : 1;
491 unsigned int users_resolved : 1;
497 As for remainder these lists are defined as follows:
499 Entry list (cache) Server type List type Contents
500 =======================================================================
501 servers server local list Server itself
502 servers server global list NULL
503 servers router local list All servers in cell
504 servers router global list All servers in SILC
506 clients server local list All clients in server
507 clients server global list NULL
508 clients router local list All clients in cell
509 clients router global list All clients in SILC
511 channels server local list All channels in server
512 channels server global list NULL
513 channels router local list All channels in cell
514 channels router global list All channels in SILC
516 As seen on the list normal server never defines a global list. This is
517 because of normal server don't know anything about anything global data,
518 they get it from the router if and when they need it. Routers, on the
519 other hand, always define local and global lists because routers really
520 know all the relevant data in the SILC network.
522 This object is used as local and global list by the server/router.
523 Above table shows how this is defined on different conditions.
525 This object holds pointers to the ID cache system. Every ID cache entry
526 has a specific context pointer to allocated entry (server, client or
530 typedef struct SilcIDListStruct {
533 SilcIDCache channels;
537 ID Entry for Unknown connections.
539 This is used during authentication phases where we still don't know
540 what kind of connection remote connection is, hence, we will use this
541 structure instead until we know what type of connection remote end is.
543 This is not in any list. This is always individually allocated and
548 /* Generic data structure. DO NOT add anything before this! */
549 SilcIDListDataStruct data;
553 void silc_idlist_add_data(void *entry, SilcIDListData idata);
554 void silc_idlist_del_data(void *entry);
555 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
557 silc_idlist_add_server(SilcIDList id_list,
558 char *server_name, int server_type,
559 SilcServerID *id, SilcServerEntry router,
562 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
563 bool registered, SilcIDCacheEntry *ret_entry);
565 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
566 bool registered, SilcIDCacheEntry *ret_entry);
568 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
569 int port, bool registered,
570 SilcIDCacheEntry *ret_entry);
572 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
573 SilcServerID *new_id);
574 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
576 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
577 char *userinfo, SilcClientID *id,
578 SilcServerEntry router, void *connection,
580 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
581 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
583 SilcClientEntry **clients,
584 SilcUInt32 *clients_count);
585 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
587 SilcClientEntry **clients,
588 SilcUInt32 *clients_count);
590 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
591 bool registered, SilcIDCacheEntry *ret_entry);
593 silc_idlist_replace_client_id(SilcServer server,
594 SilcIDList id_list, SilcClientID *old_id,
595 SilcClientID *new_id, const char *nickname);
596 void silc_idlist_client_destructor(SilcIDCache cache,
597 SilcIDCacheEntry entry);
599 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
600 SilcChannelID *id, SilcServerEntry router,
601 SilcCipher channel_key, SilcHmac hmac,
603 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
605 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
606 SilcIDCacheEntry *ret_entry);
608 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
609 SilcIDCacheEntry *ret_entry);
611 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
612 SilcChannelID *new_id);
614 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
615 SilcUInt32 *channels_count);