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 /* Hash selected in the SKE protocol, NULL if not needed at all */
64 /* HMAC and raw key data */
66 unsigned char *hmac_key;
67 unsigned int hmac_key_len;
70 SilcPublicKey public_key;
72 long last_receive; /* Time last received data */
73 long last_sent; /* Time last sent data */
74 unsigned char registered; /* Boolean whether connection is registered */
75 } *SilcIDListData, SilcIDListDataStruct;
78 SILC Server entry object.
80 This entry holds information about servers in SILC network. However,
81 contents of this entry is highly dependent of what kind of server we are
82 (normal server or router server) and whether the entry is used as a local
83 list or a global list. These factors dictates the contents of this entry.
85 This entry is defined as follows:
87 Server type List type Contents
88 =======================================================================
89 server local list Server itself
90 server global list NULL
91 router local list All servers is the cell
92 router global list All servers in the SILC network
94 Following short description of the fields:
96 SilcIDListDataStruct data
98 Generic data structure to hold data common to all ID entries.
102 Logical name of the server. There is no limit of the length of the
103 server name. This is usually the same name as defined in DNS.
107 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
112 ID of the server. This includes all the relevant information about
113 the server SILC will ever need. These are also the informations
114 that is broadcasted between servers and routers in the SILC network.
119 Server info (from INFO command) saved temporarily and motd (from
120 MOTD command) saved temporarily.
122 SilcServerEntry router
124 This is a pointer back to the server list. This is the router server
125 where this server is connected to. If this is the router itself and
126 it doesn't have a route this is NULL.
129 SilcCipher receive_key
131 Data sending and receiving keys.
135 A pointer, usually, to the socket list for fast referencing to
136 the data used in connection with this server. This may be anything
137 but as just said, this is usually pointer to the socket connection
141 struct SilcServerEntryStruct {
142 /* Generic data structure. DO NOT add anything before this! */
143 SilcIDListDataStruct data;
151 /* Pointer to the router */
152 SilcServerEntry router;
154 /* Connection data */
159 SILC Channel Client entry structure.
161 This entry used only by the SilcChannelEntry object and it holds
162 information about current clients (ie. users) on channel. Following
163 short description of the fields:
165 SilcClientEntry client
167 Pointer to the client list. This is the client currently on channel.
171 Client's current mode on the channel.
173 SilcChannelEntry channel
175 Back pointer back to channel. As this structure is also used by
176 SilcClientEntry we have this here for fast access to the channel when
177 used by SilcClientEntry.
179 struct SilcChannelClientEntryStruct *client_list
180 struct SilcChannelClientEntryStruct *channel_list
182 List member pointers. This structure is used by channel entry and
183 client entry thus we must have separate list member pointers for
184 them since we are using same entry for both lists (the entry is not
185 duplicated). SilcList requires this.
188 typedef struct SilcChannelClientEntryStruct {
189 SilcClientEntry client;
191 SilcChannelEntry channel;
192 struct SilcChannelClientEntryStruct *client_list;
193 struct SilcChannelClientEntryStruct *channel_list;
194 } *SilcChannelClientEntry;
197 SILC Client entry object.
199 This entry holds information about connected clients ie. users in the SILC
200 network. The contents of this entrt is depended on whether we are normal
201 server or router server and whether the list is a local or global list.
203 This entry is defined as follows:
205 Server type List type Contents
206 =======================================================================
207 server local list All clients in server
208 server global list NULL
209 router local list All clients in cell
210 router global list All clients in SILC
212 Following short description of the fields:
214 SilcIDListDataStruct data
216 Generic data structure to hold data common to all ID entries.
220 Client's usename. This is defined in the following manner:
222 Server type List type Contents
223 ====================================================
224 server local list User's name
225 router local list NULL
226 router global list NULL
228 Router doesn't hold this information since it is not vital data
229 for the router. If this information is needed by the client it is
230 fetched when it is needed.
234 Information about user. This is free information and can be virtually
235 anything. This is defined in following manner:
237 Server type List type Contents
238 ====================================================
239 server local list User's information
240 router local list NULL
241 router global list NULL
243 Router doesn't hold this information since it is not vital data
244 for the router. If this information is needed by the client it is
245 fetched when it is needed.
249 ID of the client. This includes all the information SILC will ever
250 need. Notice that no nickname of the user is saved anywhere. This is
251 beacuse of SilcClientID includes 88 bit hash value of the user's
252 nickname which can be used to track down specific user by their
253 nickname. Nickname is not relevant information that would need to be
258 Client's mode. Client maybe for example server operator or
259 router operator (SILC operator).
263 Time of last time client executed command. We are strict and will
264 not allow any command to be exeucted more than once in about
265 2 seconds. This is result of normal time().
269 Counter to check command bursts. By default, up to 5 commands
270 are allowed before limiting the execution. See command flags
273 SilcServerEntry router
275 This is a pointer to the server list. This is the router server whose
276 cell this client is coming from. This is used to route messages to
281 List of channels this client has joined.
285 A pointer, usually, to the socket list for fast referencing to
286 the data used in connection with this client. This may be anything
287 but as just said, this is usually pointer to the socket connection
291 struct SilcClientEntryStruct {
292 /* Generic data structure. DO NOT add anything before this! */
293 SilcIDListDataStruct data;
295 unsigned char *nickname;
304 /* Pointer to the router */
305 SilcServerEntry router;
307 /* List of channels client has joined to */
310 /* Connection data */
315 SILC Channel entry object.
317 This entry holds information about channels in SILC network. The contents
318 of this entry is depended on whether we are normal server or router server
319 and whether the list is a local or global list.
321 This entry is defined as follows:
323 Server type List type Contents
324 =======================================================================
325 server local list All channels in server
326 server global list NULL
327 router local list All channels in cell
328 router global list All channels in SILC
330 Following short description of the fields:
334 Logical name of the channel.
338 Current mode of the channel. See lib/silccore/silcchannel.h for
343 ID of the channel. This includes all the information SILC will ever
348 Boolean value to tell whether there are users outside this server
349 on this channel. This is set to TRUE if router sends message to
350 the server that there are users outside your server on your
351 channel as well. This way server knows that messages needs to be
352 sent to the router for further routing. If this is a normal
353 server and this channel is not created on this server this field
354 is always TRUE. If this server is a router this field is ignored.
358 Current topic of the channel.
362 Default cipher of the channel. If this is NULL then server picks
363 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
367 Default hmac of the channel. If this is NULL then server picks
368 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
370 SilcPublicKey founder_key
371 SilcAuthMethod founder_method
372 unsigned char *founder_passwd
373 unsigned int founder_passwd_len
375 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
376 the founder's public key, authentication method and the password
377 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
378 then the `founder_passwd' is NULL.
380 SilcServerEntry router
382 This is a pointer to the server list. This is the router server
383 whose cell this channel belongs to. This is used to route messages
386 SilcCipher channel_key
388 The key of the channel (the cipher actually).
393 Raw key data of the channel key.
395 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
397 Current initial vector. Initial vector is received always along
398 with the channel packet. By default this is filled with NULL.
404 SilcServerChannelRekey rekey
406 Channel key re-key context.
409 struct SilcChannelEntryStruct {
418 SilcPublicKey founder_key;
419 SilcAuthMethod founder_method;
420 unsigned char *founder_passwd;
421 unsigned int founder_passwd_len;
423 unsigned int user_limit;
424 unsigned char *passphrase;
428 /* List of users on channel */
431 /* Pointer to the router */
432 SilcServerEntry router;
435 SilcCipher channel_key;
437 unsigned int key_len;
438 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
441 SilcServerChannelRekey rekey;
447 As for remainder these lists are defined as follows:
449 Entry list (cache) Server type List type Contents
450 =======================================================================
451 servers server local list Server itself
452 servers server global list NULL
453 servers router local list All servers in cell
454 servers router global list All servers in SILC
456 clients server local list All clients in server
457 clients server global list NULL
458 clients router local list All clients in cell
459 clients router global list All clients in SILC
461 channels server local list All channels in server
462 channels server global list NULL
463 channels router local list All channels in cell
464 channels router global list All channels in SILC
466 As seen on the list normal server never defines a global list. This is
467 because of normal server don't know anything about anything global data,
468 they get it from the router if and when they need it. Routers, on the
469 other hand, always define local and global lists because routers really
470 know all the relevant data in the SILC network.
472 This object is used as local and global list by the server/router.
473 Above table shows how this is defined on different conditions.
475 This object holds pointers to the ID cache system. Every ID cache entry
476 has a specific context pointer to allocated entry (server, client or
480 typedef struct SilcIDListStruct {
483 SilcIDCache channels;
487 ID Entry for Unknown connections.
489 This is used during authentication phases where we still don't know
490 what kind of connection remote connection is, hence, we will use this
491 structure instead until we know what type of connection remote end is.
493 This is not in any list. This is always individually allocated and
498 /* Generic data structure. DO NOT add anything before this! */
499 SilcIDListDataStruct data;
503 void silc_idlist_add_data(void *entry, SilcIDListData idata);
504 void silc_idlist_del_data(void *entry);
505 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
507 silc_idlist_add_server(SilcIDList id_list,
508 char *server_name, int server_type,
509 SilcServerID *id, SilcServerEntry router,
512 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
513 SilcIDCacheEntry *ret_entry);
515 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
516 SilcIDCacheEntry *ret_entry);
518 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
519 int port, SilcIDCacheEntry *ret_entry);
521 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
522 SilcServerID *new_id);
523 void silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
525 silc_idlist_add_client(SilcIDList id_list, unsigned char *nickname,
526 unsigned int nickname_len, char *username,
527 char *userinfo, SilcClientID *id,
528 SilcServerEntry router, void *connection);
529 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
531 silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
532 char *server, unsigned int *clients_count);
534 silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
536 unsigned int *clients_count);
538 silc_idlist_find_client_by_hash(SilcIDList id_list, char *nickname,
539 SilcHash md5hash, SilcIDCacheEntry *ret_entry);
541 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
542 SilcIDCacheEntry *ret_entry);
544 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
545 SilcClientID *new_id);
546 void silc_idlist_client_destructor(SilcIDCache cache,
547 SilcIDCacheEntry entry);
549 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
550 SilcChannelID *id, SilcServerEntry router,
551 SilcCipher channel_key, SilcHmac hmac);
552 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
554 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
555 SilcIDCacheEntry *ret_entry);
557 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
558 SilcIDCacheEntry *ret_entry);
560 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
561 SilcChannelID *new_id);
563 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
564 unsigned int *channels_count);