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;
43 /* Generic rekey context for connections */
45 /* Current sending encryption key, provided for re-key. The `pfs'
46 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
47 unsigned char *send_enc_key;
56 Generic ID list data structure.
58 This structure is included in all ID list entries and it includes data
59 pointers that are common to all ID entries. This structure is always
60 defined to the first field in the ID entries and is used to explicitly
61 cast to this type without first explicitly casting to correct ID entry
62 type. Hence, the ID list entry is casted to this type to get this data
63 from the ID entry (which is usually opaque pointer).
65 Note that some of the fields may be NULL.
69 /* Send and receive symmetric keys */
71 SilcCipher receive_key;
74 SilcServerRekey rekey;
76 /* Hash selected in the SKE protocol, NULL if not needed at all */
83 SilcPublicKey public_key;
85 long last_receive; /* Time last received data */
86 long last_sent; /* Time last sent data */
87 bool registered; /* Boolean whether connection is registered */
88 } *SilcIDListData, SilcIDListDataStruct;
91 SILC Server entry object.
93 This entry holds information about servers in SILC network. However,
94 contents of this entry is highly dependent of what kind of server we are
95 (normal server or router server) and whether the entry is used as a local
96 list or a global list. These factors dictates the contents of this entry.
98 This entry is defined as follows:
100 Server type List type Contents
101 =======================================================================
102 server local list Server itself
103 server global list NULL
104 router local list All servers is the cell
105 router global list All servers in the SILC network
107 Following short description of the fields:
109 SilcIDListDataStruct data
111 Generic data structure to hold data common to all ID entries.
115 Logical name of the server. There is no limit of the length of the
116 server name. This is usually the same name as defined in DNS.
120 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
125 ID of the server. This includes all the relevant information about
126 the server SILC will ever need. These are also the informations
127 that is broadcasted between servers and routers in the SILC network.
132 Server info (from INFO command) saved temporarily and motd (from
133 MOTD command) saved temporarily.
135 SilcServerEntry router
137 This is a pointer back to the server list. This is the router server
138 where this server is connected to. If this is the router itself and
139 it doesn't have a route this is NULL.
142 SilcCipher receive_key
144 Data sending and receiving keys.
148 A pointer, usually, to the socket list for fast referencing to
149 the data used in connection with this server. This may be anything
150 but as just said, this is usually pointer to the socket connection
154 struct SilcServerEntryStruct {
155 /* Generic data structure. DO NOT add anything before this! */
156 SilcIDListDataStruct data;
164 /* Pointer to the router */
165 SilcServerEntry router;
167 /* Connection data */
172 SILC Channel Client entry structure.
174 This entry used only by the SilcChannelEntry object and it holds
175 information about current clients (ie. users) on channel. Following
176 short description of the fields:
178 SilcClientEntry client
180 Pointer to the client list. This is the client currently on channel.
184 Client's current mode on the channel.
186 SilcChannelEntry channel
188 Back pointer back to channel. As this structure is also used by
189 SilcClientEntry we have this here for fast access to the channel when
190 used by SilcClientEntry.
192 struct SilcChannelClientEntryStruct *client_list
193 struct SilcChannelClientEntryStruct *channel_list
195 List member pointers. This structure is used by channel entry and
196 client entry thus we must have separate list member pointers for
197 them since we are using same entry for both lists (the entry is not
198 duplicated). SilcList requires this.
201 typedef struct SilcChannelClientEntryStruct {
202 SilcClientEntry client;
204 SilcChannelEntry channel;
205 struct SilcChannelClientEntryStruct *client_list;
206 struct SilcChannelClientEntryStruct *channel_list;
207 } *SilcChannelClientEntry;
210 SILC Client entry object.
212 This entry holds information about connected clients ie. users in the SILC
213 network. The contents of this entrt is depended on whether we are normal
214 server or router server and whether the list is a local or global list.
216 This entry is defined as follows:
218 Server type List type Contents
219 =======================================================================
220 server local list All clients in server
221 server global list NULL
222 router local list All clients in cell
223 router global list All clients in SILC
225 Following short description of the fields:
227 SilcIDListDataStruct data
229 Generic data structure to hold data common to all ID entries.
233 Client's usename. This is defined in the following manner:
235 Server type List type Contents
236 ====================================================
237 server local list User's name
238 router local list NULL
239 router global list NULL
241 Router doesn't hold this information since it is not vital data
242 for the router. If this information is needed by the client it is
243 fetched when it is needed.
247 Information about user. This is free information and can be virtually
248 anything. This is defined in following manner:
250 Server type List type Contents
251 ====================================================
252 server local list User's information
253 router local list NULL
254 router global list NULL
256 Router doesn't hold this information since it is not vital data
257 for the router. If this information is needed by the client it is
258 fetched when it is needed.
262 ID of the client. This includes all the information SILC will ever
263 need. Notice that no nickname of the user is saved anywhere. This is
264 beacuse of SilcClientID includes 88 bit hash value of the user's
265 nickname which can be used to track down specific user by their
266 nickname. Nickname is not relevant information that would need to be
271 Client's mode. Client maybe for example server operator or
272 router operator (SILC operator).
276 Time of last time client executed command. We are strict and will
277 not allow any command to be exeucted more than once in about
278 2 seconds. This is result of normal time().
282 Counter to check command bursts. By default, up to 5 commands
283 are allowed before limiting the execution. See command flags
286 SilcServerEntry router
288 This is a pointer to the server list. This is the router server whose
289 cell this client is coming from. This is used to route messages to
294 List of channels this client has joined.
298 A pointer, usually, to the socket list for fast referencing to
299 the data used in connection with this client. This may be anything
300 but as just said, this is usually pointer to the socket connection
304 struct SilcClientEntryStruct {
305 /* Generic data structure. DO NOT add anything before this! */
306 SilcIDListDataStruct data;
308 unsigned char *nickname;
317 /* Pointer to the router */
318 SilcServerEntry router;
320 /* List of channels client has joined to */
323 /* Connection data */
328 SILC Channel entry object.
330 This entry holds information about channels in SILC network. The contents
331 of this entry is depended on whether we are normal server or router server
332 and whether the list is a local or global list.
334 This entry is defined as follows:
336 Server type List type Contents
337 =======================================================================
338 server local list All channels in server
339 server global list NULL
340 router local list All channels in cell
341 router global list All channels in SILC
343 Following short description of the fields:
347 Logical name of the channel.
351 Current mode of the channel. See lib/silccore/silcchannel.h for
356 ID of the channel. This includes all the information SILC will ever
361 Boolean value to tell whether there are users outside this server
362 on this channel. This is set to TRUE if router sends message to
363 the server that there are users outside your server on your
364 channel as well. This way server knows that messages needs to be
365 sent to the router for further routing. If this is a normal
366 server and this channel is not created on this server this field
367 is always TRUE. If this server is a router this field is ignored.
371 Current topic of the channel.
375 Default cipher of the channel. If this is NULL then server picks
376 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
380 Default hmac of the channel. If this is NULL then server picks
381 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
383 SilcPublicKey founder_key
384 SilcAuthMethod founder_method
385 unsigned char *founder_passwd
386 uint32 founder_passwd_len
388 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
389 the founder's public key, authentication method and the password
390 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
391 then the `founder_passwd' is NULL.
393 SilcServerEntry router
395 This is a pointer to the server list. This is the router server
396 whose cell this channel belongs to. This is used to route messages
399 SilcCipher channel_key
401 The key of the channel (the cipher actually).
406 Raw key data of the channel key.
408 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
410 Current initial vector. Initial vector is received always along
411 with the channel packet. By default this is filled with NULL.
417 SilcServerChannelRekey rekey
419 Channel key re-key context.
422 struct SilcChannelEntryStruct {
431 SilcPublicKey founder_key;
432 SilcAuthMethod founder_method;
433 unsigned char *founder_passwd;
434 uint32 founder_passwd_len;
437 unsigned char *passphrase;
441 /* List of users on channel */
444 /* Pointer to the router */
445 SilcServerEntry router;
448 SilcCipher channel_key;
451 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
454 SilcServerChannelRekey rekey;
460 As for remainder these lists are defined as follows:
462 Entry list (cache) Server type List type Contents
463 =======================================================================
464 servers server local list Server itself
465 servers server global list NULL
466 servers router local list All servers in cell
467 servers router global list All servers in SILC
469 clients server local list All clients in server
470 clients server global list NULL
471 clients router local list All clients in cell
472 clients router global list All clients in SILC
474 channels server local list All channels in server
475 channels server global list NULL
476 channels router local list All channels in cell
477 channels router global list All channels in SILC
479 As seen on the list normal server never defines a global list. This is
480 because of normal server don't know anything about anything global data,
481 they get it from the router if and when they need it. Routers, on the
482 other hand, always define local and global lists because routers really
483 know all the relevant data in the SILC network.
485 This object is used as local and global list by the server/router.
486 Above table shows how this is defined on different conditions.
488 This object holds pointers to the ID cache system. Every ID cache entry
489 has a specific context pointer to allocated entry (server, client or
493 typedef struct SilcIDListStruct {
496 SilcIDCache channels;
500 ID Entry for Unknown connections.
502 This is used during authentication phases where we still don't know
503 what kind of connection remote connection is, hence, we will use this
504 structure instead until we know what type of connection remote end is.
506 This is not in any list. This is always individually allocated and
511 /* Generic data structure. DO NOT add anything before this! */
512 SilcIDListDataStruct data;
516 void silc_idlist_add_data(void *entry, SilcIDListData idata);
517 void silc_idlist_del_data(void *entry);
518 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
520 silc_idlist_add_server(SilcIDList id_list,
521 char *server_name, int server_type,
522 SilcServerID *id, SilcServerEntry router,
525 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
526 SilcIDCacheEntry *ret_entry);
528 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
529 SilcIDCacheEntry *ret_entry);
531 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
532 int port, SilcIDCacheEntry *ret_entry);
534 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
535 SilcServerID *new_id);
536 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
538 silc_idlist_add_client(SilcIDList id_list, unsigned char *nickname,
539 uint32 nickname_len, char *username,
540 char *userinfo, SilcClientID *id,
541 SilcServerEntry router, void *connection);
542 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
543 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
545 SilcClientEntry **clients,
546 uint32 *clients_count);
547 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
549 SilcClientEntry **clients,
550 uint32 *clients_count);
552 silc_idlist_find_client_by_hash(SilcIDList id_list, char *nickname,
553 SilcHash md5hash, SilcIDCacheEntry *ret_entry);
555 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
556 SilcIDCacheEntry *ret_entry);
558 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
559 SilcClientID *new_id);
560 void silc_idlist_client_destructor(SilcIDCache cache,
561 SilcIDCacheEntry entry);
563 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
564 SilcChannelID *id, SilcServerEntry router,
565 SilcCipher channel_key, SilcHmac hmac);
566 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
568 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
569 SilcIDCacheEntry *ret_entry);
571 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
572 SilcIDCacheEntry *ret_entry);
574 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
575 SilcChannelID *new_id);
577 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
578 uint32 *channels_count);