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;
62 /* PKCS and public key */
64 SilcPublicKey public_key;
66 long last_receive; /* Time last received data */
67 long last_sent; /* Time last sent data */
68 unsigned char registered; /* Boolean whether connection is registered */
69 } *SilcIDListData, SilcIDListDataStruct;
72 SILC Server entry object.
74 This entry holds information about servers in SILC network. However,
75 contents of this entry is highly dependent of what kind of server we are
76 (normal server or router server) and whether the entry is used as a local
77 list or a global list. These factors dictates the contents of this entry.
79 This entry is defined as follows:
81 Server type List type Contents
82 =======================================================================
83 server local list Server itself
84 server global list NULL
85 router local list All servers is the cell
86 router global list All servers in the SILC network
88 Following short description of the fields:
90 SilcIDListDataStruct data
92 Generic data structure to hold data common to all ID entries.
96 Logical name of the server. There is no limit of the length of the
97 server name. This is usually the same name as defined in DNS.
101 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
106 ID of the server. This includes all the relevant information about
107 the server SILC will ever need. These are also the informations
108 that is broadcasted between servers and routers in the SILC network.
110 SilcServerEntry router
112 This is a pointer back to the server list. This is the router server
113 where this server is connected to. If this is the router itself and
114 it doesn't have a route this is NULL.
117 SilcCipher receive_key
119 Data sending and receiving keys.
123 A pointer, usually, to the socket list for fast referencing to
124 the data used in connection with this server. This may be anything
125 but as just said, this is usually pointer to the socket connection
129 struct SilcServerEntryStruct {
130 /* Generic data structure. DO NOT add anything before this! */
131 SilcIDListDataStruct data;
138 /* Pointer to the router */
139 SilcServerEntry router;
141 /* Connection data */
146 SILC Channel Client entry structure.
148 This entry used only by the SilcChannelEntry object and it holds
149 information about current clients (ie. users) on channel. Following
150 short description of the fields:
152 SilcClientEntry client
154 Pointer to the client list. This is the client currently on channel.
158 Client's current mode on the channel.
160 SilcChannelEntry channel
162 Back pointer back to channel. As this structure is also used by
163 SilcClientEntry we have this here for fast access to the channel when
164 used by SilcClientEntry.
166 struct SilcChannelClientEntryStruct *client_list
167 struct SilcChannelClientEntryStruct *channel_list
169 List member pointers. This structure is used by channel entry and
170 client entry thus we must have separate list member pointers for
171 them since we are using same entry for both lists (the entry is not
172 duplicated). SilcList requires this.
175 typedef struct SilcChannelClientEntryStruct {
176 SilcClientEntry client;
178 SilcChannelEntry channel;
179 struct SilcChannelClientEntryStruct *client_list;
180 struct SilcChannelClientEntryStruct *channel_list;
181 } *SilcChannelClientEntry;
184 SILC Client entry object.
186 This entry holds information about connected clients ie. users in the SILC
187 network. The contents of this entrt is depended on whether we are normal
188 server or router server and whether the list is a local or global list.
190 This entry is defined as follows:
192 Server type List type Contents
193 =======================================================================
194 server local list All clients in server
195 server global list NULL
196 router local list All clients in cell
197 router global list All clients in SILC
199 Following short description of the fields:
201 SilcIDListDataStruct data
203 Generic data structure to hold data common to all ID entries.
207 Client's (meaning user's) real name. This is defined in following
210 Server type List type Contents
211 ====================================================
212 server local list User's name
213 router local list NULL
214 router global list NULL
216 Router doesn't hold this information since it is not vital data
217 for the router. If this information is needed by the client it is
218 fetched when it is needed.
222 Information about user. This is free information and can be virtually
223 anything. This is defined in following manner:
225 Server type List type Contents
226 ====================================================
227 server local list User's information
228 router local list NULL
229 router global list NULL
231 Router doesn't hold this information since it is not vital data
232 for the router. If this information is needed by the client it is
233 fetched when it is needed.
237 ID of the client. This includes all the information SILC will ever
238 need. Notice that no nickname of the user is saved anywhere. This is
239 beacuse of SilcClientID includes 88 bit hash value of the user's
240 nickname which can be used to track down specific user by their
241 nickname. Nickname is not relevant information that would need to be
246 Client's mode. Client maybe for example server operator or
247 router operator (SILC operator).
251 Time of last time client executed command. We are strict and will
252 not allow any command to be exeucted more than once in about
253 2 seconds. This is result of normal time().
257 Counter to check command bursts. By default, up to 5 commands
258 are allowed before limiting the execution. See command flags
261 SilcServerEntry router
263 This is a pointer to the server list. This is the router server whose
264 cell this client is coming from. This is used to route messages to
269 List of channels this client has joined.
273 A pointer, usually, to the socket list for fast referencing to
274 the data used in connection with this client. This may be anything
275 but as just said, this is usually pointer to the socket connection
279 struct SilcClientEntryStruct {
280 /* Generic data structure. DO NOT add anything before this! */
281 SilcIDListDataStruct data;
283 unsigned char *nickname;
292 /* Pointer to the router */
293 SilcServerEntry router;
295 /* List of channels client has joined to */
298 /* Connection data */
303 SILC Channel entry object.
305 This entry holds information about channels in SILC network. The contents
306 of this entry is depended on whether we are normal server or router server
307 and whether the list is a local or global list.
309 This entry is defined as follows:
311 Server type List type Contents
312 =======================================================================
313 server local list All channels in server
314 server global list NULL
315 router local list All channels in cell
316 router global list All channels in SILC
318 Following short description of the fields:
322 Logical name of the channel.
326 Current mode of the channel. See lib/silccore/silcchannel.h for
331 ID of the channel. This includes all the information SILC will ever
336 Boolean value to tell whether there are users outside this server
337 on this channel. This is set to TRUE if router sends message to
338 the server that there are users outside your server on your
339 channel as well. This way server knows that messages needs to be
340 sent to the router for further routing. If this is a normal
341 server and this channel is not created on this server this field
342 is always TRUE. If this server is a router this field is ignored.
346 Current topic of the channel.
350 Default cipher of the channel. If this is NULL then server picks
351 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
353 SilcServerEntry router
355 This is a pointer to the server list. This is the router server
356 whose cell this channel belongs to. This is used to route messages
359 SilcCipher channel_key
361 The key of the channel (the cipher actually).
366 Raw key data of the channel key.
368 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
370 Current initial vector. Initial vector is received always along
371 with the channel packet. By default this is filled with NULL.
378 struct SilcChannelEntryStruct {
386 /* Data that is related to different channel modes. */
388 unsigned int user_limit;
389 unsigned char *passphrase;
390 unsigned char *ban_list;
391 unsigned char *invite_list;
392 unsigned char *cipher;
393 unsigned int key_len;
396 /* List of users on channel */
399 /* Pointer to the router */
400 SilcServerEntry router;
403 SilcCipher channel_key;
405 unsigned int key_len;
406 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
413 As for remainder these lists are defined as follows:
415 Entry list (cache) Server type List type Contents
416 =======================================================================
417 servers server local list Server itself
418 servers server global list NULL
419 servers router local list All servers in cell
420 servers router global list All servers in SILC
422 clients server local list All clients in server
423 clients server global list NULL
424 clients router local list All clients in cell
425 clients router global list All clients in SILC
427 channels server local list All channels in server
428 channels server global list NULL
429 channels router local list All channels in cell
430 channels router global list All channels in SILC
432 As seen on the list normal server never defines a global list. This is
433 because of normal server don't know anything about anything global data,
434 they get it from the router if and when they need it. Routers, on the
435 other hand, always define local and global lists because routers really
436 know all the relevant data in the SILC network.
438 This object is used as local and global list by the server/router.
439 Above table shows how this is defined on different conditions.
441 This object holds pointers to the ID cache system. Every ID cache entry
442 has a specific context pointer to allocated entry (server, client or
446 typedef struct SilcIDListStruct {
449 SilcIDCache channels;
453 ID Entry for Unknown connections.
455 This is used during authentication phases where we still don't know
456 what kind of connection remote connection is, hence, we will use this
457 structure instead until we know what type of connection remote end is.
459 This is not in any list. This is always individually allocated and
464 /* Generic data structure. DO NOT add anything before this! */
465 SilcIDListDataStruct data;
469 void silc_idlist_add_data(void *entry, SilcIDListData idata);
470 void silc_idlist_del_data(void *entry);
471 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
473 silc_idlist_add_server(SilcIDList id_list,
474 char *server_name, int server_type,
475 SilcServerID *id, SilcServerEntry router,
478 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
479 SilcIDCacheEntry *ret_entry);
481 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
482 SilcIDCacheEntry *ret_entry);
484 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
485 int port, SilcIDCacheEntry *ret_entry);
487 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
488 SilcServerID *new_id);
489 void silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
491 silc_idlist_add_client(SilcIDList id_list, unsigned char *nickname,
492 char *username, char *userinfo, SilcClientID *id,
493 SilcServerEntry router, void *connection);
494 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
496 silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
497 char *server, unsigned int *clients_count);
499 silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
501 unsigned int *clients_count);
503 silc_idlist_find_client_by_nickname(SilcIDList id_list, char *nickname,
505 SilcIDCacheEntry *ret_entry);
507 silc_idlist_find_client_by_hash(SilcIDList id_list, char *nickname,
508 SilcHash md5hash, SilcIDCacheEntry *ret_entry);
510 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
511 SilcIDCacheEntry *ret_entry);
513 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
514 SilcClientID *new_id);
515 void silc_idlist_client_destructor(SilcIDCache cache,
516 SilcIDCacheEntry entry);
518 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
519 SilcChannelID *id, SilcServerEntry router,
520 SilcCipher channel_key, SilcHmac hmac);
521 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
523 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
524 SilcIDCacheEntry *ret_entry);
526 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
527 SilcIDCacheEntry *ret_entry);
529 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
530 SilcChannelID *new_id);