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;
30 Generic ID list data structure.
32 This structure is included in all ID list entries and it includes data
33 pointers that are common to all ID entries. This structure is always
34 defined to the first field in the ID entries and is used to explicitly
35 cast to this type without first explicitly casting to correct ID entry
36 type. Hence, the ID list entry is casted to this type to get this data
37 from the ID entry (which is usually opaque pointer).
39 Note that some of the fields may be NULL.
43 /* Send and receive symmetric keys */
45 SilcCipher receive_key;
47 /* Hash selected in the SKE protocol, NULL if not needed at all */
50 /* HMAC and raw key data */
52 unsigned char *hmac_key;
53 unsigned int hmac_key_len;
55 /* PKCS and public key */
57 SilcPublicKey public_key;
59 long last_receive; /* Time last received data */
60 long last_sent; /* Time last sent data */
61 unsigned char registered; /* Boolean whether connection is registered */
62 } *SilcIDListData, SilcIDListDataStruct;
65 SILC Server entry object.
67 This entry holds information about servers in SILC network. However,
68 contents of this entry is highly dependent of what kind of server we are
69 (normal server or router server) and whether the entry is used as a local
70 list or a global list. These factors dictates the contents of this entry.
72 This entry is defined as follows:
74 Server type List type Contents
75 =======================================================================
76 server local list Server itself
77 server global list NULL
78 router local list All servers is the cell
79 router global list All servers in the SILC network
81 Following short description of the fields:
83 SilcIDListDataStruct data
85 Generic data structure to hold data common to all ID entries.
89 Logical name of the server. There is no limit of the length of the
90 server name. This is usually the same name as defined in DNS.
94 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
99 ID of the server. This includes all the relevant information about
100 the server SILC will ever need. These are also the informations
101 that is broadcasted between servers and routers in the SILC network.
103 SilcServerEntry router
105 This is a pointer back to the server list. This is the router server
106 where this server is connected to. If this is the router itself and
107 it doesn't have a route this is NULL.
110 SilcCipher receive_key
112 Data sending and receiving keys.
116 A pointer, usually, to the socket list for fast referencing to
117 the data used in connection with this server. This may be anything
118 but as just said, this is usually pointer to the socket connection
122 struct SilcServerEntryStruct {
123 /* Generic data structure. DO NOT add anything before this! */
124 SilcIDListDataStruct data;
130 /* Pointer to the router */
131 SilcServerEntry router;
133 /* Connection data */
138 SILC Channel Client entry structure.
140 This entry used only by the SilcChannelEntry object and it holds
141 information about current clients (ie. users) on channel. Following
142 short description of the fields:
144 SilcClientEntry client
146 Pointer to the client list. This is the client currently on channel.
150 Client's current mode on the channel.
152 SilcChannelEntry channel
154 Back pointer back to channel. As this structure is also used by
155 SilcClientEntry we have this here for fast access to the channel when
156 used by SilcClientEntry.
158 struct SilcChannelClientEntryStruct *client_list
159 struct SilcChannelClientEntryStruct *channel_list
161 List member pointers. This structure is used by channel entry and
162 client entry thus we must have separate list member pointers for
163 them since we are using same entry for both lists (the entry is not
164 duplicated). SilcList requires this.
167 typedef struct SilcChannelClientEntryStruct {
168 SilcClientEntry client;
170 SilcChannelEntry channel;
171 struct SilcChannelClientEntryStruct *client_list;
172 struct SilcChannelClientEntryStruct *channel_list;
173 } *SilcChannelClientEntry;
176 SILC Client entry object.
178 This entry holds information about connected clients ie. users in the SILC
179 network. The contents of this entrt is depended on whether we are normal
180 server or router server and whether the list is a local or global list.
182 This entry is defined as follows:
184 Server type List type Contents
185 =======================================================================
186 server local list All clients in server
187 server global list NULL
188 router local list All clients in cell
189 router global list All clients in SILC
191 Following short description of the fields:
193 SilcIDListDataStruct data
195 Generic data structure to hold data common to all ID entries.
199 Client's (meaning user's) real name. This is defined in following
202 Server type List type Contents
203 ====================================================
204 server local list User's name
205 router local list NULL
206 router global list NULL
208 Router doesn't hold this information since it is not vital data
209 for the router. If this information is needed by the client it is
210 fetched when it is needed.
214 Information about user. This is free information and can be virtually
215 anything. This is defined in following manner:
217 Server type List type Contents
218 ====================================================
219 server local list User's information
220 router local list NULL
221 router global list NULL
223 Router doesn't hold this information since it is not vital data
224 for the router. If this information is needed by the client it is
225 fetched when it is needed.
229 ID of the client. This includes all the information SILC will ever
230 need. Notice that no nickname of the user is saved anywhere. This is
231 beacuse of SilcClientID includes 88 bit hash value of the user's
232 nickname which can be used to track down specific user by their
233 nickname. Nickname is not relevant information that would need to be
238 Client's mode. Client maybe for example server operator or
239 router operator (SILC operator).
243 Time of last time client executed command. We are strict and will
244 not allow any command to be exeucted more than once in about
245 2 seconds. This is result of normal time().
249 Counter to check command bursts. By default, up to 5 commands
250 are allowed before limiting the execution. See command flags
253 SilcServerEntry router
255 This is a pointer to the server list. This is the router server whose
256 cell this client is coming from. This is used to route messages to
261 List of channels this client has joined.
265 A pointer, usually, to the socket list for fast referencing to
266 the data used in connection with this client. This may be anything
267 but as just said, this is usually pointer to the socket connection
271 struct SilcClientEntryStruct {
272 /* Generic data structure. DO NOT add anything before this! */
273 SilcIDListDataStruct data;
275 unsigned char *nickname;
284 /* Pointer to the router */
285 SilcServerEntry router;
287 /* List of channels client has joined to */
290 /* Connection data */
295 SILC Channel entry object.
297 This entry holds information about channels in SILC network. The contents
298 of this entry is depended on whether we are normal server or router server
299 and whether the list is a local or global list.
301 This entry is defined as follows:
303 Server type List type Contents
304 =======================================================================
305 server local list All channels in server
306 server global list NULL
307 router local list All channels in cell
308 router global list All channels in SILC
310 Following short description of the fields:
314 Logical name of the channel.
318 Current mode of the channel. See lib/silccore/silcchannel.h for
323 ID of the channel. This includes all the information SILC will ever
328 Boolean value to tell whether there are users outside this server
329 on this channel. This is set to TRUE if router sends message to
330 the server that there are users outside your server on your
331 channel as well. This way server knows that messages needs to be
332 sent to the router for further routing. If this is a normal
333 server and this channel is not created on this server this field
334 is always TRUE. If this server is a router this field is ignored.
338 Current topic of the channel.
342 Default cipher of the channel. If this is NULL then server picks
343 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
345 SilcServerEntry router
347 This is a pointer to the server list. This is the router server
348 whose cell this channel belongs to. This is used to route messages
351 SilcCipher channel_key
353 The key of the channel (the cipher actually).
358 Raw key data of the channel key.
360 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
362 Current initial vector. Initial vector is received always along
363 with the channel packet. By default this is filled with NULL.
370 struct SilcChannelEntryStruct {
378 /* Data that is related to different channel modes. */
380 unsigned int user_limit;
381 unsigned char *passphrase;
382 unsigned char *ban_list;
383 unsigned char *invite_list;
384 unsigned char *cipher;
385 unsigned int key_len;
388 /* List of users on channel */
391 /* Pointer to the router */
392 SilcServerEntry router;
395 SilcCipher channel_key;
397 unsigned int key_len;
398 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
405 As for remainder these lists are defined as follows:
407 Entry list (cache) Server type List type Contents
408 =======================================================================
409 servers server local list Server itself
410 servers server global list NULL
411 servers router local list All servers in cell
412 servers router global list All servers in SILC
414 clients server local list All clients in server
415 clients server global list NULL
416 clients router local list All clients in cell
417 clients router global list All clients in SILC
419 channels server local list All channels in server
420 channels server global list NULL
421 channels router local list All channels in cell
422 channels router global list All channels in SILC
424 As seen on the list normal server never defines a global list. This is
425 because of normal server don't know anything about anything global data,
426 they get it from the router if and when they need it. Routers, on the
427 other hand, always define local and global lists because routers really
428 know all the relevant data in the SILC network.
430 This object is used as local and global list by the server/router.
431 Above table shows how this is defined on different conditions.
433 This object holds pointers to the ID cache system. Every ID cache entry
434 has a specific context pointer to allocated entry (server, client or
438 typedef struct SilcIDListStruct {
441 SilcIDCache channels;
445 ID Entry for Unknown connections.
447 This is used during authentication phases where we still don't know
448 what kind of connection remote connection is, hence, we will use this
449 structure instead until we know what type of connection remote end is.
451 This is not in any list. This is always individually allocated and
456 /* Generic data structure. DO NOT add anything before this! */
457 SilcIDListDataStruct data;
461 void silc_idlist_add_data(void *entry, SilcIDListData idata);
462 void silc_idlist_del_data(void *entry);
464 silc_idlist_add_server(SilcIDList id_list,
465 char *server_name, int server_type,
466 SilcServerID *id, SilcServerEntry router,
469 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
470 SilcIDCacheEntry *ret_entry);
472 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
473 SilcIDCacheEntry *ret_entry);
475 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
476 int port, SilcIDCacheEntry *ret_entry);
478 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
479 SilcServerID *new_id);
480 void silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
482 silc_idlist_add_client(SilcIDList id_list, unsigned char *nickname,
483 char *username, char *userinfo, SilcClientID *id,
484 SilcServerEntry router, void *connection);
485 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
487 silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
488 char *server, unsigned int *clients_count);
490 silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
492 unsigned int *clients_count);
494 silc_idlist_find_client_by_nickname(SilcIDList id_list, char *nickname,
496 SilcIDCacheEntry *ret_entry);
498 silc_idlist_find_client_by_hash(SilcIDList id_list, char *nickname,
499 SilcHash md5hash, SilcIDCacheEntry *ret_entry);
501 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
502 SilcIDCacheEntry *ret_entry);
504 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
505 SilcClientID *new_id);
506 void silc_idlist_client_destructor(SilcIDCache cache,
507 SilcIDCacheEntry entry);
509 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
510 SilcChannelID *id, SilcServerEntry router,
511 SilcCipher channel_key, SilcHmac hmac);
512 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
514 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
515 SilcIDCacheEntry *ret_entry);
517 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
518 SilcIDCacheEntry *ret_entry);
520 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
521 SilcChannelID *new_id);