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;
42 } *SilcServerChannelRekey;
44 /* Generic rekey context for connections */
46 /* Current sending encryption key, provided for re-key. The `pfs'
47 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
48 unsigned char *send_enc_key;
56 /* ID List Entry status type and all the types. */
57 typedef uint8 SilcIDListStatus;
58 #define SILC_IDLIST_STATUS_NONE 0x00 /* No status */
59 #define SILC_IDLIST_STATUS_REGISTERED 0x01 /* Entry is registered */
60 #define SILC_IDLIST_STATUS_RESOLVED 0x02 /* Entry info is resolved */
61 #define SILC_IDLIST_STATUS_RESOLVING 0x04 /* Entry is being resolved
62 with WHOIS or IDENTIFY */
65 Generic ID list data structure.
67 This structure is included in all ID list entries and it includes data
68 pointers that are common to all ID entries. This structure is always
69 defined to the first field in the ID entries and is used to explicitly
70 type cast to this type without first explicitly casting to correct ID
71 entry type. Hence, the ID list entry is type casted to this type to
72 get this data from the ID entry (which is usually opaque pointer).
74 Note that some of the fields may be NULL.
78 /* Send and receive symmetric keys */
80 SilcCipher receive_key;
83 SilcServerRekey rekey;
85 /* Hash selected in the SKE protocol, NULL if not needed at all */
90 SilcHmac hmac_receive;
93 SilcPublicKey public_key;
95 long last_receive; /* Time last received data */
96 long last_sent; /* Time last sent data */
98 SilcIDListStatus status; /* Status mask of the entry */
99 } *SilcIDListData, SilcIDListDataStruct;
102 SILC Server entry object.
104 This entry holds information about servers in SILC network. However,
105 contents of this entry is highly dependent of what kind of server we are
106 (normal server or router server) and whether the entry is used as a local
107 list or a global list. These factors dictates the contents of this entry.
109 This entry is defined as follows:
111 Server type List type Contents
112 =======================================================================
113 server local list Server itself
114 server global list NULL
115 router local list All servers is the cell
116 router global list All servers in the SILC network
118 Following short description of the fields:
120 SilcIDListDataStruct data
122 Generic data structure to hold data common to all ID entries.
126 Logical name of the server. There is no limit of the length of the
127 server name. This is usually the same name as defined in DNS.
131 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
136 ID of the server. This includes all the relevant information about
137 the server SILC will ever need. These are also the informations
138 that is broadcasted between servers and routers in the SILC network.
143 Server info (from INFO command) saved temporarily and motd (from
144 MOTD command) saved temporarily.
146 SilcServerEntry router
148 This is a pointer back to the server list. This is the router server
149 where this server is connected to. If this is the router itself and
150 it doesn't have a route this is NULL.
153 SilcCipher receive_key
155 Data sending and receiving keys.
159 A pointer, usually, to the socket list for fast referencing to
160 the data used in connection with this server. This may be anything
161 but as just said, this is usually pointer to the socket connection
165 struct SilcServerEntryStruct {
166 /* Generic data structure. DO NOT add anything before this! */
167 SilcIDListDataStruct data;
175 /* Pointer to the router */
176 SilcServerEntry router;
178 /* Connection data */
183 SILC Channel Client entry structure.
185 This entry used only by the SilcChannelEntry object and it holds
186 information about current clients (ie. users) on channel. Following
187 short description of the fields:
189 SilcClientEntry client
191 Pointer to the client list. This is the client currently on channel.
195 Client's current mode on the channel.
197 SilcChannelEntry channel
199 Back pointer back to channel. As this structure is also used by
200 SilcClientEntry we have this here for fast access to the channel when
201 used by SilcClientEntry.
204 typedef struct SilcChannelClientEntryStruct {
205 SilcClientEntry client;
207 SilcChannelEntry channel;
208 } *SilcChannelClientEntry;
211 SILC Client entry object.
213 This entry holds information about connected clients ie. users in the SILC
214 network. The contents of this entrt is depended on whether we are normal
215 server or router server and whether the list is a local or global list.
217 This entry is defined as follows:
219 Server type List type Contents
220 =======================================================================
221 server local list All clients in server
222 server global list NULL
223 router local list All clients in cell
224 router global list All clients in SILC
226 Following short description of the fields:
228 SilcIDListDataStruct data
230 Generic data structure to hold data common to all ID entries.
232 unsigned char *nickname
234 The nickname of the client.
238 The name of the server where the client is from. MAy be NULL.
242 Client's usename. This is defined in the following manner:
244 Server type List type Contents
245 ====================================================
246 server local list User's name
247 router local list NULL
248 router global list NULL
250 Router doesn't hold this information since it is not vital data
251 for the router. If this information is needed by the client it is
252 fetched when it is needed.
256 Information about user. This is free information and can be virtually
257 anything. This is defined in following manner:
259 Server type List type Contents
260 ====================================================
261 server local list User's information
262 router local list NULL
263 router global list NULL
265 Router doesn't hold this information since it is not vital data
266 for the router. If this information is needed by the client it is
267 fetched when it is needed.
271 ID of the client. This includes all the information SILC will ever
272 need. Notice that no nickname of the user is saved anywhere. This is
273 beacuse of SilcClientID includes 88 bit hash value of the user's
274 nickname which can be used to track down specific user by their
275 nickname. Nickname is not relevant information that would need to be
280 Client's mode. Client maybe for example server operator or
281 router operator (SILC operator).
285 Time of last time client executed command. We are strict and will
286 not allow any command to be exeucted more than once in about
287 2 seconds. This is result of normal time().
291 Counter to check command bursts. By default, up to 5 commands
292 are allowed before limiting the execution. See command flags
295 SilcServerEntry router
297 This is a pointer to the server list. This is the router server whose
298 cell this client is coming from. This is used to route messages to
301 SilcHashTable channels;
303 All the channels this client has joined. The context saved in the
304 hash table shares memory with the channel entrys `user_list' hash
309 A pointer, usually, to the socket list for fast referencing to
310 the data used in connection with this client. This may be anything
311 but as just said, this is usually pointer to the socket connection
314 uint16 resolve_cmd_ident
316 Command identifier for the entry when the entry's data.status
317 is SILC_IDLIST_STATUS_RESOLVING. If this entry is asked to be
318 resolved when the status is set then the resolver may attach to
319 this command identifier and handle the process after the resolving
323 struct SilcClientEntryStruct {
324 /* Generic data structure. DO NOT add anything before this! */
325 SilcIDListDataStruct data;
327 unsigned char *nickname;
337 /* Pointer to the router */
338 SilcServerEntry router;
340 /* All channels this client has joined */
341 SilcHashTable channels;
343 /* Connection data */
346 /* data.status is RESOLVING and this includes the resolving command
348 uint16 resolve_cmd_ident;
352 SILC Channel entry object.
354 This entry holds information about channels in SILC network. The contents
355 of this entry is depended on whether we are normal server or router server
356 and whether the list is a local or global list.
358 This entry is defined as follows:
360 Server type List type Contents
361 =======================================================================
362 server local list All channels in server
363 server global list NULL
364 router local list All channels in cell
365 router global list All channels in SILC
367 Following short description of the fields:
371 Logical name of the channel.
375 Current mode of the channel. See lib/silccore/silcchannel.h for
380 ID of the channel. This includes all the information SILC will ever
385 Boolean value to tell whether there are users outside this server
386 on this channel. This is set to TRUE if router sends message to
387 the server that there are users outside your server on your
388 channel as well. This way server knows that messages needs to be
389 sent to the router for further routing. If this is a normal
390 server and this channel is not created on this server this field
391 is always TRUE. If this server is a router this field is ignored.
395 Current topic of the channel.
399 Default cipher of the channel. If this is NULL then server picks
400 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
404 Default hmac of the channel. If this is NULL then server picks
405 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
407 SilcPublicKey founder_key
408 SilcAuthMethod founder_method
409 unsigned char *founder_passwd
410 uint32 founder_passwd_len
412 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
413 the founder's public key, authentication method and the password
414 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
415 then the `founder_passwd' is NULL.
417 SilcHashTable user_list
419 All users joined on this channel. Note that the context saved to
420 this entry shares memory with the client entrys `channels' hash
423 SilcServerEntry router
425 This is a pointer to the server list. This is the router server
426 whose cell this channel belongs to. This is used to route messages
429 SilcCipher channel_key
431 The key of the channel (the cipher actually).
436 Raw key data of the channel key.
438 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
440 Current initial vector. Initial vector is received always along
441 with the channel packet. By default this is filled with NULL.
447 SilcServerChannelRekey rekey
449 Channel key re-key context.
452 struct SilcChannelEntryStruct {
461 SilcPublicKey founder_key;
462 SilcAuthMethod founder_method;
463 unsigned char *founder_passwd;
464 uint32 founder_passwd_len;
467 unsigned char *passphrase;
471 /* All users on this channel */
472 SilcHashTable user_list;
474 /* Pointer to the router */
475 SilcServerEntry router;
478 SilcCipher channel_key;
481 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
484 SilcServerChannelRekey rekey;
490 As for remainder these lists are defined as follows:
492 Entry list (cache) Server type List type Contents
493 =======================================================================
494 servers server local list Server itself
495 servers server global list NULL
496 servers router local list All servers in cell
497 servers router global list All servers in SILC
499 clients server local list All clients in server
500 clients server global list NULL
501 clients router local list All clients in cell
502 clients router global list All clients in SILC
504 channels server local list All channels in server
505 channels server global list NULL
506 channels router local list All channels in cell
507 channels router global list All channels in SILC
509 As seen on the list normal server never defines a global list. This is
510 because of normal server don't know anything about anything global data,
511 they get it from the router if and when they need it. Routers, on the
512 other hand, always define local and global lists because routers really
513 know all the relevant data in the SILC network.
515 This object is used as local and global list by the server/router.
516 Above table shows how this is defined on different conditions.
518 This object holds pointers to the ID cache system. Every ID cache entry
519 has a specific context pointer to allocated entry (server, client or
523 typedef struct SilcIDListStruct {
526 SilcIDCache channels;
530 ID Entry for Unknown connections.
532 This is used during authentication phases where we still don't know
533 what kind of connection remote connection is, hence, we will use this
534 structure instead until we know what type of connection remote end is.
536 This is not in any list. This is always individually allocated and
541 /* Generic data structure. DO NOT add anything before this! */
542 SilcIDListDataStruct data;
546 void silc_idlist_add_data(void *entry, SilcIDListData idata);
547 void silc_idlist_del_data(void *entry);
548 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
550 silc_idlist_add_server(SilcIDList id_list,
551 char *server_name, int server_type,
552 SilcServerID *id, SilcServerEntry router,
555 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
556 bool registered, SilcIDCacheEntry *ret_entry);
558 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
559 bool registered, SilcIDCacheEntry *ret_entry);
561 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
562 int port, bool registered,
563 SilcIDCacheEntry *ret_entry);
565 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
566 SilcServerID *new_id);
567 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
569 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
570 char *userinfo, SilcClientID *id,
571 SilcServerEntry router, void *connection);
572 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
573 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
575 SilcClientEntry **clients,
576 uint32 *clients_count);
577 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
579 SilcClientEntry **clients,
580 uint32 *clients_count);
582 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
583 bool registered, SilcIDCacheEntry *ret_entry);
585 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
586 SilcClientID *new_id);
587 void silc_idlist_client_destructor(SilcIDCache cache,
588 SilcIDCacheEntry entry);
590 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
591 SilcChannelID *id, SilcServerEntry router,
592 SilcCipher channel_key, SilcHmac hmac);
593 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
595 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
596 SilcIDCacheEntry *ret_entry);
598 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
599 SilcIDCacheEntry *ret_entry);
601 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
602 SilcChannelID *new_id);
604 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
605 uint32 *channels_count);