2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2010 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"
42 * A HELLO message is used to exchange information about
43 * transports with other peers. This struct is guaranteed
44 * to start with a "GNUNET_MessageHeader", everything else
45 * should be internal to the HELLO library.
47 struct GNUNET_HELLO_Message;
51 * Copy the given address information into
52 * the given buffer using the format of HELLOs.
54 * @param tname name of the transport plugin
55 * @param expiration expiration for the address
56 * @param addr the address
57 * @param addr_len length of the address in bytes
58 * @param target where to copy the address
59 * @param max maximum number of bytes to copy to target
60 * @return number of bytes copied, 0 if
61 * the target buffer was not big enough.
64 GNUNET_HELLO_add_address (const char *tname,
65 struct GNUNET_TIME_Absolute expiration,
66 const void *addr, uint16_t addr_len, char *target,
71 * Callback function used to fill a buffer of max bytes with a list of
72 * addresses in the format used by HELLOs. Should use
73 * "GNUNET_HELLO_add_address" as a helper function.
76 * @param max maximum number of bytes that can be written to buf
77 * @param buf where to write the address information
78 * @return number of bytes written, 0 to signal the
79 * end of the iteration.
81 typedef size_t (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls,
87 * Construct a HELLO message given the public key,
88 * expiration time and an iterator that spews the
89 * transport addresses.
91 * @return the hello message
93 struct GNUNET_HELLO_Message *
94 GNUNET_HELLO_create (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
96 GNUNET_HELLO_GenerateAddressListCallback addrgen,
101 * Return the size of the given HELLO message.
102 * @param hello to inspect
103 * @return the size, 0 if HELLO is invalid
106 GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello);
110 * Construct a HELLO message by merging the
111 * addresses in two existing HELLOs (which
112 * must be for the same peer).
114 * @param h1 first HELLO message
115 * @param h2 the second HELLO message
116 * @return the combined hello message
118 struct GNUNET_HELLO_Message *
119 GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
120 const struct GNUNET_HELLO_Message *h2);
124 * Test if two HELLO messages contain the same addresses.
125 * If they only differ in expiration time, the lowest
126 * expiration time larger than 'now' where they differ
129 * @param h1 first HELLO message
130 * @param h2 the second HELLO message
131 * @param now time to use for deciding which addresses have
132 * expired and should not be considered at all
133 * @return absolute time forever if the two HELLOs are
134 * totally identical; smallest timestamp >= now if
135 * they only differ in timestamps;
136 * zero if the some addresses with expirations >= now
137 * do not match at all
139 struct GNUNET_TIME_Absolute
140 GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
141 const struct GNUNET_HELLO_Message *h2,
142 struct GNUNET_TIME_Absolute now);
146 * Iterator callback to go over all addresses.
149 * @param tname name of the transport
150 * @param expiration expiration time
151 * @param addr the address
152 * @param addrlen length of the address
153 * @return GNUNET_OK to keep the address,
154 * GNUNET_NO to delete it from the HELLO
155 * GNUNET_SYSERR to stop iterating (but keep current address)
157 typedef int (*GNUNET_HELLO_AddressIterator) (void *cls, const char *tname,
158 struct GNUNET_TIME_Absolute
159 expiration, const void *addr,
164 * When does the last address in the given HELLO expire?
166 * @param msg HELLO to inspect
167 * @return time the last address expires, 0 if there are no addresses in the HELLO
169 struct GNUNET_TIME_Absolute
170 GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg);
174 * Iterate over all of the addresses in the HELLO.
176 * @param msg HELLO to iterate over; client does not need to
177 * have verified that msg is well-formed (beyond starting
178 * with a GNUNET_MessageHeader of the right type).
179 * @param return_modified if a modified copy should be returned,
180 * otherwise NULL will be returned
181 * @param it iterator to call on each address
182 * @param it_cls closure for it
183 * @return the modified HELLO or NULL
185 struct GNUNET_HELLO_Message *
186 GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
188 GNUNET_HELLO_AddressIterator it, void *it_cls);
192 * Iterate over addresses in "new_hello" that
193 * are NOT already present in "old_hello".
195 * @param new_hello a HELLO message
196 * @param old_hello a HELLO message
197 * @param expiration_limit ignore addresses in old_hello
198 * that expired before the given time stamp
199 * @param it iterator to call on each address
200 * @param it_cls closure for it
203 GNUNET_HELLO_iterate_new_addresses (const struct GNUNET_HELLO_Message
205 const struct GNUNET_HELLO_Message
207 struct GNUNET_TIME_Absolute
209 GNUNET_HELLO_AddressIterator it,
214 * Get the public key from a HELLO message.
216 * @param hello the hello message
217 * @param publicKey where to copy the public key information, can be NULL
218 * @return GNUNET_SYSERR if the HELLO was malformed
221 GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello,
222 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
227 * Get the peer identity from a HELLO message.
229 * @param hello the hello message
230 * @param peer where to store the peer's identity
231 * @return GNUNET_SYSERR if the HELLO was malformed
234 GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
235 struct GNUNET_PeerIdentity *peer);
239 * Get the header from a HELLO message, used so other code
240 * can correctly send HELLO messages.
242 * @param hello the hello message
244 * @return header or NULL if the HELLO was malformed
246 struct GNUNET_MessageHeader *
247 GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello);
249 /* ifndef GNUNET_HELLO_LIB_H */
251 /* end of gnunet_hello_lib.h */