5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2000 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.
21 /****h* silccore/SilcIDAPI
25 * These are important ID types used in SILC. SILC server creates these
26 * but SILC client has to handle these as well since these are used in
27 * packet sending and reception. However, client never creates these
28 * but it receives the correct ID's from server. Clients, servers and
29 * channels are identified by the these ID's.
31 * The ID's are based on IP addresses. The IP address provides a good
32 * way to distinguish the ID's from other ID's. The ID's supports both
40 /****d* silccore/SilcIDAPI/SilcIdType
44 * typedef uint16 SilcIdType;
48 * SILC ID type definitions and the ID types.
52 typedef uint16 SilcIdType;
54 /* The SILC ID Types */
55 #define SILC_ID_NONE 0
56 #define SILC_ID_SERVER 1
57 #define SILC_ID_CLIENT 2
58 #define SILC_ID_CHANNEL 3
61 /* The ID Lenghts. These are IPv4 based and should be noted if used directly
62 that these cannot be used with IPv6. */
63 #define SILC_ID_SERVER_LEN (64 / 8)
64 #define SILC_ID_CLIENT_LEN (128 / 8)
65 #define SILC_ID_CHANNEL_LEN (64 / 8)
67 #define CLIENTID_HASH_LEN (88 / 8) /* Client ID's 88 bit MD5 hash */
69 /****s* silccore/SilcIDAPI/SilcIDIP
73 * typedef struct { ... } SilcIDIP;
77 * Generic IP address structure to indicate either IPv4 or IPv6 address.
78 * This structure is used inside all SILC ID's. The true length of the
79 * ID depends of the length of the IP address.
84 unsigned char data[16]; /* IP data (in MSB first order) */
85 uint8 data_len; /* Length of the data (4 or 16) */
89 /****s* silccore/SilcIDAPI/SilcServerID
93 * typedef struct { ... } SilcServerID;
97 * 64 or 160 bit SilcServerID structure:
101 * 16 bit random number
106 SilcIDIP ip; /* n bit IP address */
107 uint16 port; /* 16 bit port */
108 uint16 rnd; /* 16 bit random number */
112 /****s* silccore/SilcIDAPI/SilcClientID
116 * typedef struct { ... } SilcClientID;
120 * 128 or 224 bit SilcClientID structure:
122 * n bit ServerID IP address [bits 1-32 or bits 1-128]
123 * 8 bit random number
124 * 88 bit hash value from nickname
129 SilcIDIP ip; /* n bit IP address */
130 unsigned char rnd; /* 8 bit random number */
131 unsigned char hash[CLIENTID_HASH_LEN]; /* 88 bit MD5 hash */
135 /****s* silccore/SilcIDAPI/SilcChannelID
139 * typedef struct { ... } SilcChannelID;
143 * 64 or 160 bit SilcChannel ID structure:
145 * n bit Router's ServerID IP address [bits 1-32 or bits 1-128]
146 * 16 bit Router's ServerID port [bits 33-48 or bits 129-144]
147 * 16 bit random number
152 SilcIDIP ip; /* n bit IP address */
153 uint16 port; /* 16 bit port */
154 uint16 rnd; /* 16 bit random number */
160 /****d* silccore/SilcIDAPI/SILC_ID_COMPARE
164 * #define SILC_ID_COMPARE ...
168 * Compares two ID's. Returns TRUE if they match and FALSE if they do
173 #define SILC_ID_COMPARE(id1, id2, len) (!memcmp(id1, id2, len))
176 /****d* silccore/SilcIDAPI/SILC_ID_CLIENT_COMPARE
180 * #define SILC_ID_CLIENT_COMPARE ...
184 * Compares Client ID's. Returns TRUE if they match.
188 #define SILC_ID_CLIENT_COMPARE(id1, id2) \
189 SILC_ID_COMPARE(id1, id2, sizeof(SilcClientID))
192 /****d* silccore/SilcIDAPI/SILC_ID_SERVER_COMPARE
196 * #define SILC_ID_SERVER_COMPARE ...
200 * Compares Server ID's. Returns TRUE if they match.
204 #define SILC_ID_SERVER_COMPARE(id1, id2) \
205 SILC_ID_COMPARE(id1, id2, sizeof(SilcServerID))
208 /****d* silccore/SilcIDAPI/SILC_ID_CHANNEL_COMPARE
212 * #define SILC_ID_CHANNEL_COMPARE ...
216 * Compares Channel ID's. Returns TRUE if they match.
220 #define SILC_ID_CHANNEL_COMPARE(id1, id2) \
221 SILC_ID_COMPARE(id1, id2, sizeof(SilcChannelID))
224 /****d* silccore/SilcIDAPI/SILC_ID_COMPARE_TYPE
228 * #define SILC_ID_COMPARE_TYPE ...
232 * Compares two ID's by type. Returns TRUE if they match.
236 #define SILC_ID_COMPARE_TYPE(id1, id2, type) \
237 (type == SILC_ID_SERVER ? SILC_ID_SERVER_COMPARE(id1, id2) : \
238 type == SILC_ID_CLIENT ? SILC_ID_CLIENT_COMPARE(id1, id2) : \
239 SILC_ID_CHANNEL_COMPARE(id1, id2))
242 /****d* silccore/SilcIDAPI/SILC_ID_COMPARE_HASH
246 * #define SILC_ID_COMPARE_HASH ...
250 * Compares the nickname hash of the Client ID. Returns TRUE if
251 * they match. Since the nickname hash is based on the nickname of
252 * the client this can be used to search the ID by nickname (taking
253 * the hash out of it) or using the hash from the ID.
257 #define SILC_ID_COMPARE_HASH(id1, id2) \
258 (!memcmp((id1)->hash, (id2)->hash, CLIENTID_HASH_LEN))
263 /****f* silccore/SilcIDAPI/silc_id_id2str
267 * unsigned char *silc_id_id2str(void *id, SilcIdType type);
271 * Converts an ID of type `type' to data. This can be used to
272 * convert the ID's to data for inclusion in the packets.
275 unsigned char *silc_id_id2str(void *id, SilcIdType type);
277 /****f* silccore/SilcIDAPI/silc_id_str2id
281 * void *silc_id_str2id(unsigned char *id, uint32 id_len, SilcIdType type);
285 * Converts ID data string to an ID. This can be used to get the
286 * ID out of data that has been taken for example from packet.
289 void *silc_id_str2id(unsigned char *id, uint32 id_len, SilcIdType type);
291 /****f* silccore/SilcIDAPI/silc_id_get_len
295 * uint32 silc_id_get_len(void *id, SilcIdType type);
299 * Returns the true length of the ID of the type `type'.
302 uint32 silc_id_get_len(void *id, SilcIdType type);
304 /****f* silccore/SilcIDAPI/silc_id_dup
308 * void *silc_id_dup(void *id, SilcIdType type);
312 * Duplicates the ID of the type `type'. The caller must free the
316 void *silc_id_dup(void *id, SilcIdType type);