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
36 /* Channel key re-key context. */
39 SilcChannelEntry channel;
41 } *SilcServerChannelRekey;
44 Generic ID list data structure.
46 This structure is included in all ID list entries and it includes data
47 pointers that are common to all ID entries. This structure is always
48 defined to the first field in the ID entries and is used to explicitly
49 cast to this type without first explicitly casting to correct ID entry
50 type. Hence, the ID list entry is casted to this type to get this data
51 from the ID entry (which is usually opaque pointer).
53 Note that some of the fields may be NULL.
57 /* Send and receive symmetric keys */
59 SilcCipher receive_key;
61 /* Current sending encryption key, provided for re-key. The `pfs'
62 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
63 unsigned char *send_enc_key;
67 /* Hash selected in the SKE protocol, NULL if not needed at all */
74 SilcPublicKey public_key;
76 long last_receive; /* Time last received data */
77 long last_sent; /* Time last sent data */
78 bool registered; /* Boolean whether connection is registered */
79 } *SilcIDListData, SilcIDListDataStruct;
82 SILC Server entry object.
84 This entry holds information about servers in SILC network. However,
85 contents of this entry is highly dependent of what kind of server we are
86 (normal server or router server) and whether the entry is used as a local
87 list or a global list. These factors dictates the contents of this entry.
89 This entry is defined as follows:
91 Server type List type Contents
92 =======================================================================
93 server local list Server itself
94 server global list NULL
95 router local list All servers is the cell
96 router global list All servers in the SILC network
98 Following short description of the fields:
100 SilcIDListDataStruct data
102 Generic data structure to hold data common to all ID entries.
106 Logical name of the server. There is no limit of the length of the
107 server name. This is usually the same name as defined in DNS.
111 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
116 ID of the server. This includes all the relevant information about
117 the server SILC will ever need. These are also the informations
118 that is broadcasted between servers and routers in the SILC network.
123 Server info (from INFO command) saved temporarily and motd (from
124 MOTD command) saved temporarily.
126 SilcServerEntry router
128 This is a pointer back to the server list. This is the router server
129 where this server is connected to. If this is the router itself and
130 it doesn't have a route this is NULL.
133 SilcCipher receive_key
135 Data sending and receiving keys.
139 A pointer, usually, to the socket list for fast referencing to
140 the data used in connection with this server. This may be anything
141 but as just said, this is usually pointer to the socket connection
145 struct SilcServerEntryStruct {
146 /* Generic data structure. DO NOT add anything before this! */
147 SilcIDListDataStruct data;
155 /* Pointer to the router */
156 SilcServerEntry router;
158 /* Connection data */
163 SILC Channel Client entry structure.
165 This entry used only by the SilcChannelEntry object and it holds
166 information about current clients (ie. users) on channel. Following
167 short description of the fields:
169 SilcClientEntry client
171 Pointer to the client list. This is the client currently on channel.
175 Client's current mode on the channel.
177 SilcChannelEntry channel
179 Back pointer back to channel. As this structure is also used by
180 SilcClientEntry we have this here for fast access to the channel when
181 used by SilcClientEntry.
183 struct SilcChannelClientEntryStruct *client_list
184 struct SilcChannelClientEntryStruct *channel_list
186 List member pointers. This structure is used by channel entry and
187 client entry thus we must have separate list member pointers for
188 them since we are using same entry for both lists (the entry is not
189 duplicated). SilcList requires this.
192 typedef struct SilcChannelClientEntryStruct {
193 SilcClientEntry client;
195 SilcChannelEntry channel;
196 struct SilcChannelClientEntryStruct *client_list;
197 struct SilcChannelClientEntryStruct *channel_list;
198 } *SilcChannelClientEntry;
201 SILC Client entry object.
203 This entry holds information about connected clients ie. users in the SILC
204 network. The contents of this entrt is depended on whether we are normal
205 server or router server and whether the list is a local or global list.
207 This entry is defined as follows:
209 Server type List type Contents
210 =======================================================================
211 server local list All clients in server
212 server global list NULL
213 router local list All clients in cell
214 router global list All clients in SILC
216 Following short description of the fields:
218 SilcIDListDataStruct data
220 Generic data structure to hold data common to all ID entries.
224 Client's usename. This is defined in the following manner:
226 Server type List type Contents
227 ====================================================
228 server local list User's name
229 router local list NULL
230 router global list NULL
232 Router doesn't hold this information since it is not vital data
233 for the router. If this information is needed by the client it is
234 fetched when it is needed.
238 Information about user. This is free information and can be virtually
239 anything. This is defined in following manner:
241 Server type List type Contents
242 ====================================================
243 server local list User's information
244 router local list NULL
245 router global list NULL
247 Router doesn't hold this information since it is not vital data
248 for the router. If this information is needed by the client it is
249 fetched when it is needed.
253 ID of the client. This includes all the information SILC will ever
254 need. Notice that no nickname of the user is saved anywhere. This is
255 beacuse of SilcClientID includes 88 bit hash value of the user's
256 nickname which can be used to track down specific user by their
257 nickname. Nickname is not relevant information that would need to be
262 Client's mode. Client maybe for example server operator or
263 router operator (SILC operator).
267 Time of last time client executed command. We are strict and will
268 not allow any command to be exeucted more than once in about
269 2 seconds. This is result of normal time().
273 Counter to check command bursts. By default, up to 5 commands
274 are allowed before limiting the execution. See command flags
277 SilcServerEntry router
279 This is a pointer to the server list. This is the router server whose
280 cell this client is coming from. This is used to route messages to
285 List of channels this client has joined.
289 A pointer, usually, to the socket list for fast referencing to
290 the data used in connection with this client. This may be anything
291 but as just said, this is usually pointer to the socket connection
295 struct SilcClientEntryStruct {
296 /* Generic data structure. DO NOT add anything before this! */
297 SilcIDListDataStruct data;
299 unsigned char *nickname;
308 /* Pointer to the router */
309 SilcServerEntry router;
311 /* List of channels client has joined to */
314 /* Connection data */
319 SILC Channel entry object.
321 This entry holds information about channels in SILC network. The contents
322 of this entry is depended on whether we are normal server or router server
323 and whether the list is a local or global list.
325 This entry is defined as follows:
327 Server type List type Contents
328 =======================================================================
329 server local list All channels in server
330 server global list NULL
331 router local list All channels in cell
332 router global list All channels in SILC
334 Following short description of the fields:
338 Logical name of the channel.
342 Current mode of the channel. See lib/silccore/silcchannel.h for
347 ID of the channel. This includes all the information SILC will ever
352 Boolean value to tell whether there are users outside this server
353 on this channel. This is set to TRUE if router sends message to
354 the server that there are users outside your server on your
355 channel as well. This way server knows that messages needs to be
356 sent to the router for further routing. If this is a normal
357 server and this channel is not created on this server this field
358 is always TRUE. If this server is a router this field is ignored.
362 Current topic of the channel.
366 Default cipher of the channel. If this is NULL then server picks
367 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
371 Default hmac of the channel. If this is NULL then server picks
372 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
374 SilcPublicKey founder_key
375 SilcAuthMethod founder_method
376 unsigned char *founder_passwd
377 uint32 founder_passwd_len
379 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
380 the founder's public key, authentication method and the password
381 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
382 then the `founder_passwd' is NULL.
384 SilcServerEntry router
386 This is a pointer to the server list. This is the router server
387 whose cell this channel belongs to. This is used to route messages
390 SilcCipher channel_key
392 The key of the channel (the cipher actually).
397 Raw key data of the channel key.
399 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
401 Current initial vector. Initial vector is received always along
402 with the channel packet. By default this is filled with NULL.
408 SilcServerChannelRekey rekey
410 Channel key re-key context.
413 struct SilcChannelEntryStruct {
422 SilcPublicKey founder_key;
423 SilcAuthMethod founder_method;
424 unsigned char *founder_passwd;
425 uint32 founder_passwd_len;
428 unsigned char *passphrase;
432 /* List of users on channel */
435 /* Pointer to the router */
436 SilcServerEntry router;
439 SilcCipher channel_key;
442 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
445 SilcServerChannelRekey rekey;
451 As for remainder these lists are defined as follows:
453 Entry list (cache) Server type List type Contents
454 =======================================================================
455 servers server local list Server itself
456 servers server global list NULL
457 servers router local list All servers in cell
458 servers router global list All servers in SILC
460 clients server local list All clients in server
461 clients server global list NULL
462 clients router local list All clients in cell
463 clients router global list All clients in SILC
465 channels server local list All channels in server
466 channels server global list NULL
467 channels router local list All channels in cell
468 channels router global list All channels in SILC
470 As seen on the list normal server never defines a global list. This is
471 because of normal server don't know anything about anything global data,
472 they get it from the router if and when they need it. Routers, on the
473 other hand, always define local and global lists because routers really
474 know all the relevant data in the SILC network.
476 This object is used as local and global list by the server/router.
477 Above table shows how this is defined on different conditions.
479 This object holds pointers to the ID cache system. Every ID cache entry
480 has a specific context pointer to allocated entry (server, client or
484 typedef struct SilcIDListStruct {
487 SilcIDCache channels;
491 ID Entry for Unknown connections.
493 This is used during authentication phases where we still don't know
494 what kind of connection remote connection is, hence, we will use this
495 structure instead until we know what type of connection remote end is.
497 This is not in any list. This is always individually allocated and
502 /* Generic data structure. DO NOT add anything before this! */
503 SilcIDListDataStruct data;
507 void silc_idlist_add_data(void *entry, SilcIDListData idata);
508 void silc_idlist_del_data(void *entry);
509 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
511 silc_idlist_add_server(SilcIDList id_list,
512 char *server_name, int server_type,
513 SilcServerID *id, SilcServerEntry router,
516 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
517 SilcIDCacheEntry *ret_entry);
519 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
520 SilcIDCacheEntry *ret_entry);
522 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
523 int port, SilcIDCacheEntry *ret_entry);
525 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
526 SilcServerID *new_id);
527 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
529 silc_idlist_add_client(SilcIDList id_list, unsigned char *nickname,
530 uint32 nickname_len, char *username,
531 char *userinfo, SilcClientID *id,
532 SilcServerEntry router, void *connection);
533 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
534 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
536 SilcClientEntry **clients,
537 uint32 *clients_count);
538 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
540 SilcClientEntry **clients,
541 uint32 *clients_count);
543 silc_idlist_find_client_by_hash(SilcIDList id_list, char *nickname,
544 SilcHash md5hash, SilcIDCacheEntry *ret_entry);
546 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
547 SilcIDCacheEntry *ret_entry);
549 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
550 SilcClientID *new_id);
551 void silc_idlist_client_destructor(SilcIDCache cache,
552 SilcIDCacheEntry entry);
554 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
555 SilcChannelID *id, SilcServerEntry router,
556 SilcCipher channel_key, SilcHmac hmac);
557 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
559 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
560 SilcIDCacheEntry *ret_entry);
562 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
563 SilcIDCacheEntry *ret_entry);
565 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
566 SilcChannelID *new_id);
568 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
569 uint32 *channels_count);