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 */
66 #define SILC_IDLIST_STATUS_LOCAL 0x20 /* Entry locally connected */
69 Generic ID list data structure.
71 This structure is included in all ID list entries and it includes data
72 pointers that are common to all ID entries. This structure is always
73 defined to the first field in the ID entries and is used to explicitly
74 type cast to this type without first explicitly casting to correct ID
75 entry type. Hence, the ID list entry is type casted to this type to
76 get this data from the ID entry (which is usually opaque pointer).
78 Note that some of the fields may be NULL.
82 /* Send and receive symmetric keys */
84 SilcCipher receive_key;
88 SilcHmac hmac_receive;
90 /* Packet sequence numbers */
92 SilcUInt32 psn_receive;
94 /* Hash selected in the SKE protocol, NULL if not needed at all */
98 SilcPublicKey public_key;
99 unsigned char fingerprint[20];
102 SilcServerRekey rekey;
104 long last_receive; /* Time last received data */
105 long last_sent; /* Time last sent data */
107 unsigned long created; /* Time when entry was created */
109 SilcIDListStatus status; /* Status mask of the entry */
110 } *SilcIDListData, SilcIDListDataStruct;
113 SILC Server entry object.
115 This entry holds information about servers in SILC network. However,
116 contents of this entry is highly dependent of what kind of server we are
117 (normal server or router server) and whether the entry is used as a local
118 list or a global list. These factors dictates the contents of this entry.
120 This entry is defined as follows:
122 Server type List type Contents
123 =======================================================================
124 server local list Server itself
125 server global list NULL
126 router local list All servers is the cell
127 router global list All servers in the SILC network
129 Following short description of the fields:
131 SilcIDListDataStruct data
133 Generic data structure to hold data common to all ID entries.
137 Logical name of the server. There is no limit of the length of the
138 server name. This is usually the same name as defined in DNS.
140 SilcUInt8 server_type
142 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
147 ID of the server. This includes all the relevant information about
148 the server SILC will ever need. These are also the informations
149 that is broadcasted between servers and routers in the SILC network.
154 Server info (from INFO command) saved temporarily and motd (from
155 MOTD command) saved temporarily.
157 SilcServerEntry router
159 This is a pointer back to the server list. This is the router server
160 where this server is connected to. If this is the router itself and
161 it doesn't have a route this is NULL.
164 SilcCipher receive_key
166 Data sending and receiving keys.
170 A pointer, usually, to the socket list for fast referencing to
171 the data used in connection with this server. This may be anything
172 but as just said, this is usually pointer to the socket connection
176 struct SilcServerEntryStruct {
177 /* Generic data structure. DO NOT add anything before this! */
178 SilcIDListDataStruct data;
181 SilcUInt8 server_type;
186 /* Pointer to the router */
187 SilcServerEntry router;
189 /* Connection data */
194 SILC Channel Client entry structure.
196 This entry used only by the SilcChannelEntry object and it holds
197 information about current clients (ie. users) on channel. Following
198 short description of the fields:
200 SilcClientEntry client
202 Pointer to the client list. This is the client currently on channel.
206 Client's current mode on the channel.
208 SilcChannelEntry channel
210 Back pointer back to channel. As this structure is also used by
211 SilcClientEntry we have this here for fast access to the channel when
212 used by SilcClientEntry.
215 typedef struct SilcChannelClientEntryStruct {
216 SilcClientEntry client;
218 SilcChannelEntry channel;
219 } *SilcChannelClientEntry;
222 SILC Client entry object.
224 This entry holds information about connected clients ie. users in the SILC
225 network. The contents of this entrt is depended on whether we are normal
226 server or router server and whether the list is a local or global list.
228 This entry is defined as follows:
230 Server type List type Contents
231 =======================================================================
232 server local list All clients in server
233 server global list NULL
234 router local list All clients in cell
235 router global list All clients in SILC
237 Following short description of the fields:
239 SilcIDListDataStruct data
241 Generic data structure to hold data common to all ID entries.
243 unsigned char *nickname
245 The nickname of the client.
249 The name of the server where the client is from. MAy be NULL.
253 Client's usename. This is defined in the following manner:
255 Server type List type Contents
256 ====================================================
257 server local list User's name
258 router local list NULL
259 router global list NULL
261 Router doesn't hold this information since it is not vital data
262 for the router. If this information is needed by the client it is
263 fetched when it is needed.
267 Information about user. This is free information and can be virtually
268 anything. This is defined in following manner:
270 Server type List type Contents
271 ====================================================
272 server local list User's information
273 router local list NULL
274 router global list NULL
276 Router doesn't hold this information since it is not vital data
277 for the router. If this information is needed by the client it is
278 fetched when it is needed.
282 ID of the client. This includes all the information SILC will ever
283 need. Notice that no nickname of the user is saved anywhere. This is
284 beacuse of SilcClientID includes 88 bit hash value of the user's
285 nickname which can be used to track down specific user by their
286 nickname. Nickname is not relevant information that would need to be
291 Client's mode. Client maybe for example server operator or
292 router operator (SILC operator).
296 Time of last time client executed command. We are strict and will
297 not allow any command to be exeucted more than once in about
298 2 seconds. This is result of normal time().
300 SilcUInt8 fast_command
302 Counter to check command bursts. By default, up to 5 commands
303 are allowed before limiting the execution. See command flags
306 SilcServerEntry router
308 This is a pointer to the server list. This is the router server whose
309 cell this client is coming from. This is used to route messages to
312 SilcHashTable channels;
314 All the channels this client has joined. The context saved in the
315 hash table shares memory with the channel entrys `user_list' hash
320 A pointer, usually, to the socket list for fast referencing to
321 the data used in connection with this client. This may be anything
322 but as just said, this is usually pointer to the socket connection
325 SilcUInt16 resolve_cmd_ident
327 Command identifier for the entry when the entry's data.status
328 is SILC_IDLIST_STATUS_RESOLVING. If this entry is asked to be
329 resolved when the status is set then the resolver may attach to
330 this command identifier and handle the process after the resolving
334 struct SilcClientEntryStruct {
335 /* Generic data structure. DO NOT add anything before this! */
336 SilcIDListDataStruct data;
338 unsigned char *nickname;
346 SilcUInt8 fast_command;
348 /* Pointer to the router */
349 SilcServerEntry router;
351 /* All channels this client has joined */
352 SilcHashTable channels;
354 /* Connection data */
357 /* data.status is RESOLVING and this includes the resolving command
359 SilcUInt16 resolve_cmd_ident;
363 SILC Channel entry object.
365 This entry holds information about channels in SILC network. The contents
366 of this entry is depended on whether we are normal server or router server
367 and whether the list is a local or global list.
369 This entry is defined as follows:
371 Server type List type Contents
372 =======================================================================
373 server local list All channels in server
374 server global list NULL
375 router local list All channels in cell
376 router global list All channels in SILC
378 Following short description of the fields:
382 Logical name of the channel.
386 Current mode of the channel. See lib/silccore/silcchannel.h for
391 ID of the channel. This includes all the information SILC will ever
396 Boolean value to tell whether there are users outside this server
397 on this channel. This is set to TRUE if router sends message to
398 the server that there are users outside your server on your
399 channel as well. This way server knows that messages needs to be
400 sent to the router for further routing. If this is a normal
401 server and this channel is not created on this server this field
402 is always TRUE. If this server is a router this field is ignored.
406 Current topic of the channel.
410 Default cipher of the channel. If this is NULL then server picks
411 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
415 Default hmac of the channel. If this is NULL then server picks
416 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
418 SilcPublicKey founder_key
420 If the SILC_CMODE_FOUNDER_AUTH has been set then this will include
421 the founder's public key. When the mode and this key is set the
422 channel is also permanent channel and cannot be destroyed.
424 SilcHashTable user_list
426 All users joined on this channel. Note that the context saved to
427 this entry shares memory with the client entrys `channels' hash
430 SilcServerEntry router
432 This is a pointer to the server list. This is the router server
433 whose cell this channel belongs to. This is used to route messages
436 SilcCipher channel_key
438 The key of the channel (the cipher actually).
443 Raw key data of the channel key.
445 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
447 Current initial vector. Initial vector is received always along
448 with the channel packet. By default this is filled with NULL.
454 SilcServerChannelRekey rekey
456 Channel key re-key context.
459 struct SilcChannelEntryStruct {
466 SilcPublicKey founder_key;
468 SilcUInt32 user_limit;
469 unsigned char *passphrase;
473 /* All users on this channel */
474 SilcHashTable user_list;
475 SilcUInt32 user_count;
477 /* Pointer to the router */
478 SilcServerEntry router;
481 SilcCipher channel_key;
486 SilcServerChannelRekey rekey;
487 unsigned long created;
490 unsigned int global_users : 1;
491 unsigned int disabled : 1;
492 unsigned int users_resolved : 1;
498 As for remainder these lists are defined as follows:
500 Entry list (cache) Server type List type Contents
501 =======================================================================
502 servers server local list Server itself
503 servers server global list NULL
504 servers router local list All servers in cell
505 servers router global list All servers in SILC
507 clients server local list All clients in server
508 clients server global list NULL
509 clients router local list All clients in cell
510 clients router global list All clients in SILC
512 channels server local list All channels in server
513 channels server global list NULL
514 channels router local list All channels in cell
515 channels router global list All channels in SILC
517 As seen on the list normal server never defines a global list. This is
518 because of normal server don't know anything about anything global data,
519 they get it from the router if and when they need it. Routers, on the
520 other hand, always define local and global lists because routers really
521 know all the relevant data in the SILC network.
523 This object is used as local and global list by the server/router.
524 Above table shows how this is defined on different conditions.
526 This object holds pointers to the ID cache system. Every ID cache entry
527 has a specific context pointer to allocated entry (server, client or
531 typedef struct SilcIDListStruct {
534 SilcIDCache channels;
538 ID Entry for Unknown connections.
540 This is used during authentication phases where we still don't know
541 what kind of connection remote connection is, hence, we will use this
542 structure instead until we know what type of connection remote end is.
544 This is not in any list. This is always individually allocated and
549 /* Generic data structure. DO NOT add anything before this! */
550 SilcIDListDataStruct data;
554 void silc_idlist_add_data(void *entry, SilcIDListData idata);
555 void silc_idlist_del_data(void *entry);
556 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
558 silc_idlist_add_server(SilcIDList id_list,
559 char *server_name, int server_type,
560 SilcServerID *id, SilcServerEntry router,
563 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
564 bool registered, SilcIDCacheEntry *ret_entry);
566 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
567 bool registered, SilcIDCacheEntry *ret_entry);
569 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
570 int port, bool registered,
571 SilcIDCacheEntry *ret_entry);
573 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
574 SilcServerID *new_id);
575 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
577 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
578 char *userinfo, SilcClientID *id,
579 SilcServerEntry router, void *connection,
581 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
582 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
584 SilcClientEntry **clients,
585 SilcUInt32 *clients_count);
586 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
588 SilcClientEntry **clients,
589 SilcUInt32 *clients_count);
591 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
592 bool registered, SilcIDCacheEntry *ret_entry);
594 silc_idlist_replace_client_id(SilcServer server,
595 SilcIDList id_list, SilcClientID *old_id,
596 SilcClientID *new_id, const char *nickname);
597 void silc_idlist_client_destructor(SilcIDCache cache,
598 SilcIDCacheEntry entry);
600 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
601 SilcChannelID *id, SilcServerEntry router,
602 SilcCipher channel_key, SilcHmac hmac,
604 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
606 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
607 SilcIDCacheEntry *ret_entry);
609 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
610 SilcIDCacheEntry *ret_entry);
612 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
613 SilcChannelID *new_id);
615 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
616 SilcUInt32 *channels_count);