2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2010, 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_hello_lib.h
23 * @brief helper library for handling HELLOs
24 * @author Christian Grothoff
27 #ifndef GNUNET_HELLO_LIB_H
28 #define GNUNET_HELLO_LIB_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_common.h"
39 #include "gnunet_crypto_lib.h"
43 * Prefix that every HELLO URI must start with.
45 #define GNUNET_HELLO_URI_PREFIX "gnunet://hello/"
48 * Prefix that every FRIEND HELLO URI must start with.
50 #define GNUNET_FRIEND_HELLO_URI_PREFIX "gnunet://friend-hello/"
53 * An address for communicating with a peer. We frequently
54 * need this tuple and the components cannot really be
55 * separated. This is NOT the format that would be used
58 struct GNUNET_HELLO_Address
62 * For which peer is this an address?
64 struct GNUNET_PeerIdentity peer;
67 * Name of the transport plugin enabling the communication using
70 const char *transport_name;
73 * Binary representation of the address (plugin-specific).
78 * Number of bytes in 'address'.
80 size_t address_length;
86 * Allocate an address struct.
88 * @param peer the peer
89 * @param transport_name plugin name
90 * @param address binary address
91 * @param address_length number of bytes in 'address'
92 * @return the address struct
94 struct GNUNET_HELLO_Address *
95 GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
96 const char *transport_name, const void *address,
97 size_t address_length);
101 * Copy an address struct.
103 * @param address address to copy
104 * @return a copy of the address struct
106 struct GNUNET_HELLO_Address *
107 GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address);
111 * Compare two addresses. Does NOT compare the peer identity,
112 * that is assumed already to match!
114 * @param a1 first address
115 * @param a2 second address
116 * @return 0 if the addresses are equal, -1 if a1<a2, 1 if a1>a2.
119 GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1,
120 const struct GNUNET_HELLO_Address *a2);
124 * Get the size of an address struct.
126 * @param address address
130 GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address);
135 * @param addr address to free
137 #define GNUNET_HELLO_address_free(addr) GNUNET_free(addr)
141 * A HELLO message is used to exchange information about
142 * transports with other peers. This struct is guaranteed
143 * to start with a "GNUNET_MessageHeader", everything else
144 * should be internal to the HELLO library.
146 struct GNUNET_HELLO_Message;
149 /** Return HELLO type
151 * @param h HELLO Message to test
152 * @return GNUNET_YES or GNUNET_NO
155 GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h);
159 * Copy the given address information into
160 * the given buffer using the format of HELLOs.
162 * @param address address to add
163 * @param expiration expiration for the address
164 * @param target where to copy the address
165 * @param max maximum number of bytes to copy to target
166 * @return number of bytes copied, 0 if
167 * the target buffer was not big enough.
170 GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address,
171 struct GNUNET_TIME_Absolute expiration, char *target,
176 * Callback function used to fill a buffer of max bytes with a list of
177 * addresses in the format used by HELLOs. Should use
178 * "GNUNET_HELLO_add_address" as a helper function.
181 * @param max maximum number of bytes that can be written to buf
182 * @param buf where to write the address information
183 * @return number of bytes written, 0 to signal the
184 * end of the iteration.
186 typedef size_t (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls,
192 * Construct a HELLO message given the public key,
193 * expiration time and an iterator that spews the
194 * transport addresses.
196 * If friend only is set to GNUNET_YES we create a FRIEND_HELLO which will
197 * not be gossiped to other peers
199 * @return the hello message
201 struct GNUNET_HELLO_Message *
202 GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicSignKey *publicKey,
203 GNUNET_HELLO_GenerateAddressListCallback addrgen,
209 * Return the size of the given HELLO message.
210 * @param hello to inspect
211 * @return the size, 0 if HELLO is invalid
214 GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello);
218 * Construct a HELLO message by merging the
219 * addresses in two existing HELLOs (which
220 * must be for the same peer).
222 * @param h1 first HELLO message
223 * @param h2 the second HELLO message
224 * @return the combined hello message
226 struct GNUNET_HELLO_Message *
227 GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
228 const struct GNUNET_HELLO_Message *h2);
232 * Test if two HELLO messages contain the same addresses.
233 * If they only differ in expiration time, the lowest
234 * expiration time larger than 'now' where they differ
237 * @param h1 first HELLO message
238 * @param h2 the second HELLO message
239 * @param now time to use for deciding which addresses have
240 * expired and should not be considered at all
241 * @return absolute time forever if the two HELLOs are
242 * totally identical; smallest timestamp >= now if
243 * they only differ in timestamps;
244 * zero if the some addresses with expirations >= now
245 * do not match at all
247 struct GNUNET_TIME_Absolute
248 GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
249 const struct GNUNET_HELLO_Message *h2,
250 struct GNUNET_TIME_Absolute now);
254 * Iterator callback to go over all addresses.
257 * @param address the address
258 * @param expiration expiration time
259 * @return GNUNET_OK to keep the address,
260 * GNUNET_NO to delete it from the HELLO
261 * GNUNET_SYSERR to stop iterating (but keep current address)
263 typedef int (*GNUNET_HELLO_AddressIterator) (void *cls,
264 const struct GNUNET_HELLO_Address *
266 struct GNUNET_TIME_Absolute
271 * When does the last address in the given HELLO expire?
273 * @param msg HELLO to inspect
274 * @return time the last address expires, 0 if there are no addresses in the HELLO
276 struct GNUNET_TIME_Absolute
277 GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg);
281 * Iterate over all of the addresses in the HELLO.
283 * @param msg HELLO to iterate over; client does not need to
284 * have verified that msg is well-formed (beyond starting
285 * with a GNUNET_MessageHeader of the right type).
286 * @param return_modified if a modified copy should be returned,
287 * otherwise NULL will be returned
288 * @param it iterator to call on each address
289 * @param it_cls closure for it
290 * @return the modified HELLO or NULL
292 struct GNUNET_HELLO_Message *
293 GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
295 GNUNET_HELLO_AddressIterator it, void *it_cls);
299 * Iterate over addresses in "new_hello" that
300 * are NOT already present in "old_hello".
302 * @param new_hello a HELLO message
303 * @param old_hello a HELLO message
304 * @param expiration_limit ignore addresses in old_hello
305 * that expired before the given time stamp
306 * @param it iterator to call on each address
307 * @param it_cls closure for it
310 GNUNET_HELLO_iterate_new_addresses (const struct GNUNET_HELLO_Message
312 const struct GNUNET_HELLO_Message
314 struct GNUNET_TIME_Absolute
316 GNUNET_HELLO_AddressIterator it,
321 * Get the public key from a HELLO message.
323 * @param hello the hello message
324 * @param publicKey where to copy the public key information, can be NULL
325 * @return GNUNET_SYSERR if the HELLO was malformed
328 GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello,
329 struct GNUNET_CRYPTO_EccPublicSignKey *publicKey);
333 * Get the peer identity from a HELLO message.
335 * @param hello the hello message
336 * @param peer where to store the peer's identity
337 * @return GNUNET_SYSERR if the HELLO was malformed
340 GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
341 struct GNUNET_PeerIdentity *peer);
345 * Get the header from a HELLO message, used so other code
346 * can correctly send HELLO messages.
348 * @param hello the hello message
350 * @return header or NULL if the HELLO was malformed
352 struct GNUNET_MessageHeader *
353 GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello);
356 typedef struct GNUNET_TRANSPORT_PluginFunctions *
357 (*GNUNET_HELLO_TransportPluginsFind) (const char *name);
361 * Compose a hello URI string from a hello message.
363 * @param hello Hello message
364 * @param plugins_find Function to find transport plugins by name
365 * @return Hello URI string
368 GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello,
369 GNUNET_HELLO_TransportPluginsFind plugins_find);
372 * Parse a hello URI string to a hello message.
374 * @param uri URI string to parse
375 * @param pubkey Pointer to struct where public key is parsed
376 * @param hello Pointer to struct where hello message is parsed
377 * @param plugins_find Function to find transport plugins by name
378 * @return GNUNET_OK on success, GNUNET_SYSERR if the URI was invalid, GNUNET_NO on other errors
381 GNUNET_HELLO_parse_uri (const char *uri,
382 struct GNUNET_CRYPTO_EccPublicSignKey *pubkey,
383 struct GNUNET_HELLO_Message **hello,
384 GNUNET_HELLO_TransportPluginsFind plugins_find);
386 #if 0 /* keep Emacsens' auto-indent happy */
394 /* ifndef GNUNET_HELLO_LIB_H */
396 /* end of gnunet_hello_lib.h */