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
37 Generic ID list data structure.
39 This structure is included in all ID list entries and it includes data
40 pointers that are common to all ID entries. This structure is always
41 defined to the first field in the ID entries and is used to explicitly
42 cast to this type without first explicitly casting to correct ID entry
43 type. Hence, the ID list entry is casted to this type to get this data
44 from the ID entry (which is usually opaque pointer).
46 Note that some of the fields may be NULL.
50 /* Send and receive symmetric keys */
52 SilcCipher receive_key;
54 /* Hash selected in the SKE protocol, NULL if not needed at all */
57 /* HMAC and raw key data */
59 unsigned char *hmac_key;
60 unsigned int hmac_key_len;
63 SilcPublicKey public_key;
65 long last_receive; /* Time last received data */
66 long last_sent; /* Time last sent data */
67 unsigned char registered; /* Boolean whether connection is registered */
68 } *SilcIDListData, SilcIDListDataStruct;
71 SILC Server entry object.
73 This entry holds information about servers in SILC network. However,
74 contents of this entry is highly dependent of what kind of server we are
75 (normal server or router server) and whether the entry is used as a local
76 list or a global list. These factors dictates the contents of this entry.
78 This entry is defined as follows:
80 Server type List type Contents
81 =======================================================================
82 server local list Server itself
83 server global list NULL
84 router local list All servers is the cell
85 router global list All servers in the SILC network
87 Following short description of the fields:
89 SilcIDListDataStruct data
91 Generic data structure to hold data common to all ID entries.
95 Logical name of the server. There is no limit of the length of the
96 server name. This is usually the same name as defined in DNS.
100 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
105 ID of the server. This includes all the relevant information about
106 the server SILC will ever need. These are also the informations
107 that is broadcasted between servers and routers in the SILC network.
112 Server info (from INFO command) saved temporarily and motd (from
113 MOTD command) saved temporarily.
115 SilcServerEntry router
117 This is a pointer back to the server list. This is the router server
118 where this server is connected to. If this is the router itself and
119 it doesn't have a route this is NULL.
122 SilcCipher receive_key
124 Data sending and receiving keys.
128 A pointer, usually, to the socket list for fast referencing to
129 the data used in connection with this server. This may be anything
130 but as just said, this is usually pointer to the socket connection
134 struct SilcServerEntryStruct {
135 /* Generic data structure. DO NOT add anything before this! */
136 SilcIDListDataStruct data;
144 /* Pointer to the router */
145 SilcServerEntry router;
147 /* Connection data */
152 SILC Channel Client entry structure.
154 This entry used only by the SilcChannelEntry object and it holds
155 information about current clients (ie. users) on channel. Following
156 short description of the fields:
158 SilcClientEntry client
160 Pointer to the client list. This is the client currently on channel.
164 Client's current mode on the channel.
166 SilcChannelEntry channel
168 Back pointer back to channel. As this structure is also used by
169 SilcClientEntry we have this here for fast access to the channel when
170 used by SilcClientEntry.
172 struct SilcChannelClientEntryStruct *client_list
173 struct SilcChannelClientEntryStruct *channel_list
175 List member pointers. This structure is used by channel entry and
176 client entry thus we must have separate list member pointers for
177 them since we are using same entry for both lists (the entry is not
178 duplicated). SilcList requires this.
181 typedef struct SilcChannelClientEntryStruct {
182 SilcClientEntry client;
184 SilcChannelEntry channel;
185 struct SilcChannelClientEntryStruct *client_list;
186 struct SilcChannelClientEntryStruct *channel_list;
187 } *SilcChannelClientEntry;
190 SILC Client entry object.
192 This entry holds information about connected clients ie. users in the SILC
193 network. The contents of this entrt is depended on whether we are normal
194 server or router server and whether the list is a local or global list.
196 This entry is defined as follows:
198 Server type List type Contents
199 =======================================================================
200 server local list All clients in server
201 server global list NULL
202 router local list All clients in cell
203 router global list All clients in SILC
205 Following short description of the fields:
207 SilcIDListDataStruct data
209 Generic data structure to hold data common to all ID entries.
213 Client's usename. This is defined in the following manner:
215 Server type List type Contents
216 ====================================================
217 server local list User's name
218 router local list NULL
219 router global list NULL
221 Router doesn't hold this information since it is not vital data
222 for the router. If this information is needed by the client it is
223 fetched when it is needed.
227 Information about user. This is free information and can be virtually
228 anything. This is defined in following manner:
230 Server type List type Contents
231 ====================================================
232 server local list User's information
233 router local list NULL
234 router global list NULL
236 Router doesn't hold this information since it is not vital data
237 for the router. If this information is needed by the client it is
238 fetched when it is needed.
242 ID of the client. This includes all the information SILC will ever
243 need. Notice that no nickname of the user is saved anywhere. This is
244 beacuse of SilcClientID includes 88 bit hash value of the user's
245 nickname which can be used to track down specific user by their
246 nickname. Nickname is not relevant information that would need to be
251 Client's mode. Client maybe for example server operator or
252 router operator (SILC operator).
256 Time of last time client executed command. We are strict and will
257 not allow any command to be exeucted more than once in about
258 2 seconds. This is result of normal time().
262 Counter to check command bursts. By default, up to 5 commands
263 are allowed before limiting the execution. See command flags
266 SilcServerEntry router
268 This is a pointer to the server list. This is the router server whose
269 cell this client is coming from. This is used to route messages to
274 List of channels this client has joined.
278 A pointer, usually, to the socket list for fast referencing to
279 the data used in connection with this client. This may be anything
280 but as just said, this is usually pointer to the socket connection
284 struct SilcClientEntryStruct {
285 /* Generic data structure. DO NOT add anything before this! */
286 SilcIDListDataStruct data;
288 unsigned char *nickname;
297 /* Pointer to the router */
298 SilcServerEntry router;
300 /* List of channels client has joined to */
303 /* Connection data */
308 SILC Channel entry object.
310 This entry holds information about channels in SILC network. The contents
311 of this entry is depended on whether we are normal server or router server
312 and whether the list is a local or global list.
314 This entry is defined as follows:
316 Server type List type Contents
317 =======================================================================
318 server local list All channels in server
319 server global list NULL
320 router local list All channels in cell
321 router global list All channels in SILC
323 Following short description of the fields:
327 Logical name of the channel.
331 Current mode of the channel. See lib/silccore/silcchannel.h for
336 ID of the channel. This includes all the information SILC will ever
341 Boolean value to tell whether there are users outside this server
342 on this channel. This is set to TRUE if router sends message to
343 the server that there are users outside your server on your
344 channel as well. This way server knows that messages needs to be
345 sent to the router for further routing. If this is a normal
346 server and this channel is not created on this server this field
347 is always TRUE. If this server is a router this field is ignored.
351 Current topic of the channel.
355 Default cipher of the channel. If this is NULL then server picks
356 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
360 Default hmac of the channel. If this is NULL then server picks
361 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
363 SilcPublicKey founder_key
364 SilcAuthMethod founder_method
365 unsigned char *founder_passwd
366 unsigned int founder_passwd_len
368 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
369 the founder's public key, authentication method and the password
370 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
371 then the `founder_passwd' is NULL.
373 SilcServerEntry router
375 This is a pointer to the server list. This is the router server
376 whose cell this channel belongs to. This is used to route messages
379 SilcCipher channel_key
381 The key of the channel (the cipher actually).
386 Raw key data of the channel key.
388 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
390 Current initial vector. Initial vector is received always along
391 with the channel packet. By default this is filled with NULL.
398 struct SilcChannelEntryStruct {
407 SilcPublicKey founder_key;
408 SilcAuthMethod founder_method;
409 unsigned char *founder_passwd;
410 unsigned int founder_passwd_len;
412 unsigned int user_limit;
413 unsigned char *passphrase;
417 /* List of users on channel */
420 /* Pointer to the router */
421 SilcServerEntry router;
424 SilcCipher channel_key;
426 unsigned int key_len;
427 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
434 As for remainder these lists are defined as follows:
436 Entry list (cache) Server type List type Contents
437 =======================================================================
438 servers server local list Server itself
439 servers server global list NULL
440 servers router local list All servers in cell
441 servers router global list All servers in SILC
443 clients server local list All clients in server
444 clients server global list NULL
445 clients router local list All clients in cell
446 clients router global list All clients in SILC
448 channels server local list All channels in server
449 channels server global list NULL
450 channels router local list All channels in cell
451 channels router global list All channels in SILC
453 As seen on the list normal server never defines a global list. This is
454 because of normal server don't know anything about anything global data,
455 they get it from the router if and when they need it. Routers, on the
456 other hand, always define local and global lists because routers really
457 know all the relevant data in the SILC network.
459 This object is used as local and global list by the server/router.
460 Above table shows how this is defined on different conditions.
462 This object holds pointers to the ID cache system. Every ID cache entry
463 has a specific context pointer to allocated entry (server, client or
467 typedef struct SilcIDListStruct {
470 SilcIDCache channels;
474 ID Entry for Unknown connections.
476 This is used during authentication phases where we still don't know
477 what kind of connection remote connection is, hence, we will use this
478 structure instead until we know what type of connection remote end is.
480 This is not in any list. This is always individually allocated and
485 /* Generic data structure. DO NOT add anything before this! */
486 SilcIDListDataStruct data;
490 void silc_idlist_add_data(void *entry, SilcIDListData idata);
491 void silc_idlist_del_data(void *entry);
492 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
494 silc_idlist_add_server(SilcIDList id_list,
495 char *server_name, int server_type,
496 SilcServerID *id, SilcServerEntry router,
499 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
500 SilcIDCacheEntry *ret_entry);
502 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
503 SilcIDCacheEntry *ret_entry);
505 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
506 int port, SilcIDCacheEntry *ret_entry);
508 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
509 SilcServerID *new_id);
510 void silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
512 silc_idlist_add_client(SilcIDList id_list, unsigned char *nickname,
513 unsigned int nickname_len, char *username,
514 char *userinfo, SilcClientID *id,
515 SilcServerEntry router, void *connection);
516 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
518 silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
519 char *server, unsigned int *clients_count);
521 silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
523 unsigned int *clients_count);
525 silc_idlist_find_client_by_hash(SilcIDList id_list, char *nickname,
526 SilcHash md5hash, SilcIDCacheEntry *ret_entry);
528 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
529 SilcIDCacheEntry *ret_entry);
531 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
532 SilcClientID *new_id);
533 void silc_idlist_client_destructor(SilcIDCache cache,
534 SilcIDCacheEntry entry);
536 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
537 SilcChannelID *id, SilcServerEntry router,
538 SilcCipher channel_key, SilcHmac hmac);
539 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
541 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
542 SilcIDCacheEntry *ret_entry);
544 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
545 SilcIDCacheEntry *ret_entry);
547 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
548 SilcChannelID *new_id);
550 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
551 unsigned int *channels_count);