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 * An address for communicating with a peer. We frequently
44 * need this tuple and the components cannot really be
45 * separated. This is NOT the format that would be used
48 struct GNUNET_HELLO_Address
52 * For which peer is this an address?
54 struct GNUNET_PeerIdentity peer;
57 * Name of the transport plugin enabling the communication using
60 const char *transport_name;
63 * Binary representation of the address (plugin-specific).
68 * Number of bytes in 'address'.
70 size_t address_length;
76 * Allocate an address struct.
78 * @param peer the peer
79 * @param transport_name plugin name
80 * @param address binary address
81 * @param address_length number of bytes in 'address'
82 * @return the address struct
84 struct GNUNET_HELLO_Address *
85 GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
86 const char *transport_name,
88 size_t address_length);
92 * Copy an address struct.
94 * @param address address to copy
95 * @return a copy of the address struct
97 struct GNUNET_HELLO_Address *
98 GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address);
102 * Compare two addresses. Does NOT compare the peer identity,
103 * that is assumed already to match!
105 * @param a1 first address
106 * @param a2 second address
107 * @return 0 if the addresses are equal, -1 if a1<a2, 1 if a1>a2.
110 GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1,
111 const struct GNUNET_HELLO_Address *a2);
115 * Get the size of an address struct.
117 * @param address address
121 GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address);
126 * @param addr address to free
128 #define GNUNET_HELLO_address_free(addr) GNUNET_free(addr)
132 * A HELLO message is used to exchange information about
133 * transports with other peers. This struct is guaranteed
134 * to start with a "GNUNET_MessageHeader", everything else
135 * should be internal to the HELLO library.
137 struct GNUNET_HELLO_Message;
141 * Copy the given address information into
142 * the given buffer using the format of HELLOs.
144 * @param address address to add
145 * @param expiration expiration for the address
146 * @param target where to copy the address
147 * @param max maximum number of bytes to copy to target
148 * @return number of bytes copied, 0 if
149 * the target buffer was not big enough.
152 GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address,
153 struct GNUNET_TIME_Absolute expiration,
159 * Callback function used to fill a buffer of max bytes with a list of
160 * addresses in the format used by HELLOs. Should use
161 * "GNUNET_HELLO_add_address" as a helper function.
164 * @param max maximum number of bytes that can be written to buf
165 * @param buf where to write the address information
166 * @return number of bytes written, 0 to signal the
167 * end of the iteration.
169 typedef size_t (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls,
175 * Construct a HELLO message given the public key,
176 * expiration time and an iterator that spews the
177 * transport addresses.
179 * @return the hello message
181 struct GNUNET_HELLO_Message *
182 GNUNET_HELLO_create (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
184 GNUNET_HELLO_GenerateAddressListCallback addrgen,
189 * Return the size of the given HELLO message.
190 * @param hello to inspect
191 * @return the size, 0 if HELLO is invalid
194 GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello);
198 * Construct a HELLO message by merging the
199 * addresses in two existing HELLOs (which
200 * must be for the same peer).
202 * @param h1 first HELLO message
203 * @param h2 the second HELLO message
204 * @return the combined hello message
206 struct GNUNET_HELLO_Message *
207 GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
208 const struct GNUNET_HELLO_Message *h2);
212 * Test if two HELLO messages contain the same addresses.
213 * If they only differ in expiration time, the lowest
214 * expiration time larger than 'now' where they differ
217 * @param h1 first HELLO message
218 * @param h2 the second HELLO message
219 * @param now time to use for deciding which addresses have
220 * expired and should not be considered at all
221 * @return absolute time forever if the two HELLOs are
222 * totally identical; smallest timestamp >= now if
223 * they only differ in timestamps;
224 * zero if the some addresses with expirations >= now
225 * do not match at all
227 struct GNUNET_TIME_Absolute
228 GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
229 const struct GNUNET_HELLO_Message *h2,
230 struct GNUNET_TIME_Absolute now);
234 * Iterator callback to go over all addresses.
237 * @param address the address
238 * @param expiration expiration time
239 * @return GNUNET_OK to keep the address,
240 * GNUNET_NO to delete it from the HELLO
241 * GNUNET_SYSERR to stop iterating (but keep current address)
243 typedef int (*GNUNET_HELLO_AddressIterator) (void *cls,
244 const struct GNUNET_HELLO_Address *address,
245 struct GNUNET_TIME_Absolute expiration);
249 * When does the last address in the given HELLO expire?
251 * @param msg HELLO to inspect
252 * @return time the last address expires, 0 if there are no addresses in the HELLO
254 struct GNUNET_TIME_Absolute
255 GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg);
259 * Iterate over all of the addresses in the HELLO.
261 * @param msg HELLO to iterate over; client does not need to
262 * have verified that msg is well-formed (beyond starting
263 * with a GNUNET_MessageHeader of the right type).
264 * @param return_modified if a modified copy should be returned,
265 * otherwise NULL will be returned
266 * @param it iterator to call on each address
267 * @param it_cls closure for it
268 * @return the modified HELLO or NULL
270 struct GNUNET_HELLO_Message *
271 GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
273 GNUNET_HELLO_AddressIterator it, void *it_cls);
277 * Iterate over addresses in "new_hello" that
278 * are NOT already present in "old_hello".
280 * @param new_hello a HELLO message
281 * @param old_hello a HELLO message
282 * @param expiration_limit ignore addresses in old_hello
283 * that expired before the given time stamp
284 * @param it iterator to call on each address
285 * @param it_cls closure for it
288 GNUNET_HELLO_iterate_new_addresses (const struct GNUNET_HELLO_Message
290 const struct GNUNET_HELLO_Message
292 struct GNUNET_TIME_Absolute
294 GNUNET_HELLO_AddressIterator it,
299 * Get the public key from a HELLO message.
301 * @param hello the hello message
302 * @param publicKey where to copy the public key information, can be NULL
303 * @return GNUNET_SYSERR if the HELLO was malformed
306 GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello,
307 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
312 * Get the peer identity from a HELLO message.
314 * @param hello the hello message
315 * @param peer where to store the peer's identity
316 * @return GNUNET_SYSERR if the HELLO was malformed
319 GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
320 struct GNUNET_PeerIdentity *peer);
324 * Get the header from a HELLO message, used so other code
325 * can correctly send HELLO messages.
327 * @param hello the hello message
329 * @return header or NULL if the HELLO was malformed
331 struct GNUNET_MessageHeader *
332 GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello);
334 /* ifndef GNUNET_HELLO_LIB_H */
336 /* end of gnunet_hello_lib.h */