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_util_lib.h"
42 * Prefix that every HELLO URI must start with.
44 #define GNUNET_HELLO_URI_PREFIX "gnunet://hello/"
47 * Prefix that every FRIEND HELLO URI must start with.
49 #define GNUNET_FRIEND_HELLO_URI_PREFIX "gnunet://friend-hello/"
53 * Additional local information about an address
55 * These information are only valid for the local peer and are not serialized
56 * when a #GNUNET_HELLO_Message is created
58 enum GNUNET_HELLO_AddressInfo
61 * No additional information
63 GNUNET_HELLO_ADDRESS_INFO_NONE = 0,
66 * This is an inbound address and cannot be used to initiate an outbound
67 * connection to another peer
69 GNUNET_HELLO_ADDRESS_INFO_INBOUND = 1
74 * An address for communicating with a peer. We frequently
75 * need this tuple and the components cannot really be
76 * separated. This is NOT the format that would be used
79 struct GNUNET_HELLO_Address
83 * For which peer is this an address?
85 struct GNUNET_PeerIdentity peer;
88 * Extended information about address
90 * This field contains additional #GNUNET_HELLO_AddressInfo flags e.g.
91 * to indicate an address is inbound and cannot be used to initiate an
92 * outbound connection.
94 * These information are only valid for the local peer and are not serialized
95 * when a #GNUNET_HELLO_Message is created
97 enum GNUNET_HELLO_AddressInfo local_info;
100 * Name of the transport plugin enabling the communication using
103 const char *transport_name;
106 * Binary representation of the address (plugin-specific).
111 * Number of bytes in 'address'.
113 size_t address_length;
118 * Allocate an address struct.
120 * @param peer the peer
121 * @param transport_name plugin name
122 * @param address binary address
123 * @param address_length number of bytes in 'address'
124 * @return the address struct
126 struct GNUNET_HELLO_Address *
127 GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
128 const char *transport_name, const void *address,
129 size_t address_length);
133 * Copy an address struct.
135 * @param address address to copy
136 * @return a copy of the address struct
138 struct GNUNET_HELLO_Address *
139 GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address);
143 * Compare two addresses. Does NOT compare the peer identity,
144 * that is assumed already to match!
146 * @param a1 first address
147 * @param a2 second address
148 * @return 0 if the addresses are equal, -1 if a1<a2, 1 if a1>a2.
151 GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1,
152 const struct GNUNET_HELLO_Address *a2);
155 * Get the size of an address struct.
157 * @param address address
161 GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address);
167 * @param addr address to free
169 #define GNUNET_HELLO_address_free(addr) GNUNET_free(addr)
173 * A HELLO message is used to exchange information about
174 * transports with other peers. This struct is guaranteed
175 * to start with a "GNUNET_MessageHeader", everything else
176 * should be internal to the HELLO library.
178 struct GNUNET_HELLO_Message;
181 /** Return HELLO type
183 * @param h HELLO Message to test
184 * @return GNUNET_YES or GNUNET_NO
187 GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h);
191 * Copy the given address information into
192 * the given buffer using the format of HELLOs.
194 * @param address address to add
195 * @param expiration expiration for the address
196 * @param target where to copy the address
197 * @param max maximum number of bytes to copy to target
198 * @return number of bytes copied, 0 if
199 * the target buffer was not big enough.
202 GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address,
203 struct GNUNET_TIME_Absolute expiration, char *target,
208 * Callback function used to fill a buffer of max bytes with a list of
209 * addresses in the format used by HELLOs. Should use
210 * "GNUNET_HELLO_add_address" as a helper function.
213 * @param max maximum number of bytes that can be written to buf
214 * @param buf where to write the address information
215 * @return number of bytes written, 0 to signal the
216 * end of the iteration.
218 typedef size_t (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls,
224 * Construct a HELLO message given the public key,
225 * expiration time and an iterator that spews the
226 * transport addresses.
228 * If friend only is set to GNUNET_YES we create a FRIEND_HELLO which will
229 * not be gossiped to other peers
231 * @return the hello message
233 struct GNUNET_HELLO_Message *
234 GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *publicKey,
235 GNUNET_HELLO_GenerateAddressListCallback addrgen,
241 * Return the size of the given HELLO message.
242 * @param hello to inspect
243 * @return the size, 0 if HELLO is invalid
246 GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello);
250 * Construct a HELLO message by merging the
251 * addresses in two existing HELLOs (which
252 * must be for the same peer).
254 * @param h1 first HELLO message
255 * @param h2 the second HELLO message
256 * @return the combined hello message
258 struct GNUNET_HELLO_Message *
259 GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
260 const struct GNUNET_HELLO_Message *h2);
264 * Test if two HELLO messages contain the same addresses.
265 * If they only differ in expiration time, the lowest
266 * expiration time larger than 'now' where they differ
269 * @param h1 first HELLO message
270 * @param h2 the second HELLO message
271 * @param now time to use for deciding which addresses have
272 * expired and should not be considered at all
273 * @return absolute time forever if the two HELLOs are
274 * totally identical; smallest timestamp >= now if
275 * they only differ in timestamps;
276 * zero if the some addresses with expirations >= now
277 * do not match at all
279 struct GNUNET_TIME_Absolute
280 GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
281 const struct GNUNET_HELLO_Message *h2,
282 struct GNUNET_TIME_Absolute now);
286 * Iterator callback to go over all addresses.
289 * @param address the address
290 * @param expiration expiration time
291 * @return GNUNET_OK to keep the address,
292 * GNUNET_NO to delete it from the HELLO
293 * GNUNET_SYSERR to stop iterating (but keep current address)
295 typedef int (*GNUNET_HELLO_AddressIterator) (void *cls,
296 const struct GNUNET_HELLO_Address *
298 struct GNUNET_TIME_Absolute
303 * When does the last address in the given HELLO expire?
305 * @param msg HELLO to inspect
306 * @return time the last address expires, 0 if there are no addresses in the HELLO
308 struct GNUNET_TIME_Absolute
309 GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg);
313 * Iterate over all of the addresses in the HELLO.
315 * @param msg HELLO to iterate over; client does not need to
316 * have verified that msg is well-formed (beyond starting
317 * with a GNUNET_MessageHeader of the right type).
318 * @param return_modified if a modified copy should be returned,
319 * otherwise NULL will be returned
320 * @param it iterator to call on each address
321 * @param it_cls closure for it
322 * @return the modified HELLO or NULL
324 struct GNUNET_HELLO_Message *
325 GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
327 GNUNET_HELLO_AddressIterator it, void *it_cls);
331 * Iterate over addresses in "new_hello" that
332 * are NOT already present in "old_hello".
334 * @param new_hello a HELLO message
335 * @param old_hello a HELLO message
336 * @param expiration_limit ignore addresses in old_hello
337 * that expired before the given time stamp
338 * @param it iterator to call on each address
339 * @param it_cls closure for it
342 GNUNET_HELLO_iterate_new_addresses (const struct GNUNET_HELLO_Message
344 const struct GNUNET_HELLO_Message
346 struct GNUNET_TIME_Absolute
348 GNUNET_HELLO_AddressIterator it,
353 * Get the public key from a HELLO message.
355 * @param hello the hello message
356 * @param publicKey where to copy the public key information, can be NULL
357 * @return GNUNET_SYSERR if the HELLO was malformed
360 GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello,
361 struct GNUNET_CRYPTO_EddsaPublicKey *publicKey);
365 * Get the peer identity from a HELLO message.
367 * @param hello the hello message
368 * @param peer where to store the peer's identity
369 * @return GNUNET_SYSERR if the HELLO was malformed
372 GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
373 struct GNUNET_PeerIdentity *peer);
377 * Get the header from a HELLO message, used so other code
378 * can correctly send HELLO messages.
380 * @param hello the hello message
382 * @return header or NULL if the HELLO was malformed
384 struct GNUNET_MessageHeader *
385 GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello);
388 typedef struct GNUNET_TRANSPORT_PluginFunctions *
389 (*GNUNET_HELLO_TransportPluginsFind) (const char *name);
393 * Compose a hello URI string from a hello message.
395 * @param hello Hello message
396 * @param plugins_find Function to find transport plugins by name
397 * @return Hello URI string
400 GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello,
401 GNUNET_HELLO_TransportPluginsFind plugins_find);
404 * Parse a hello URI string to a hello message.
406 * @param uri URI string to parse
407 * @param pubkey Pointer to struct where public key is parsed
408 * @param hello Pointer to struct where hello message is parsed
409 * @param plugins_find Function to find transport plugins by name
410 * @return GNUNET_OK on success, GNUNET_SYSERR if the URI was invalid, GNUNET_NO on other errors
413 GNUNET_HELLO_parse_uri (const char *uri,
414 struct GNUNET_CRYPTO_EddsaPublicKey *pubkey,
415 struct GNUNET_HELLO_Message **hello,
416 GNUNET_HELLO_TransportPluginsFind plugins_find);
418 #if 0 /* keep Emacsens' auto-indent happy */
426 /* ifndef GNUNET_HELLO_LIB_H */
428 /* end of gnunet_hello_lib.h */