diff options
author | t3sserakt <t3ss@posteo.de> | 2023-10-23 10:57:11 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2023-10-23 10:57:41 +0200 |
commit | b5e243908f1539b9f00bfe5c485804d02d682aab (patch) | |
tree | 8394d8e54177c418aa3b6ea3ca1e1b6d7d70b776 | |
parent | 7a3df52b28649fd5a0b7f0f29e5656df4022e4f6 (diff) | |
download | gnunet-b5e243908f1539b9f00bfe5c485804d02d682aab.tar.gz gnunet-b5e243908f1539b9f00bfe5c485804d02d682aab.zip |
News: Removed old hello functionality.
23 files changed, 110 insertions, 2708 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index e39f467b9..cf8c49cf1 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am | |||
@@ -54,7 +54,6 @@ gnunetinclude_HEADERS = \ | |||
54 | gnunet_gnsrecord_json_lib.h \ | 54 | gnunet_gnsrecord_json_lib.h \ |
55 | gnunet_gnsrecord_plugin.h \ | 55 | gnunet_gnsrecord_plugin.h \ |
56 | gnu_name_system_record_types.h \ | 56 | gnu_name_system_record_types.h \ |
57 | gnunet_hello_lib.h \ | ||
58 | gnunet_hello_uri_lib.h \ | 57 | gnunet_hello_uri_lib.h \ |
59 | gnunet_helper_lib.h \ | 58 | gnunet_helper_lib.h \ |
60 | gnunet_identity_service.h \ | 59 | gnunet_identity_service.h \ |
@@ -121,7 +120,6 @@ gnunetinclude_HEADERS = \ | |||
121 | gnunet_transport_communication_service.h \ | 120 | gnunet_transport_communication_service.h \ |
122 | gnunet_transport_monitor_service.h \ | 121 | gnunet_transport_monitor_service.h \ |
123 | gnunet_transport_core_service.h \ | 122 | gnunet_transport_core_service.h \ |
124 | gnunet_transport_hello_service.h \ | ||
125 | gnunet_transport_testing_ng_lib.h \ | 123 | gnunet_transport_testing_ng_lib.h \ |
126 | gnunet_tun_lib.h \ | 124 | gnunet_tun_lib.h \ |
127 | gnunet_uri_lib.h \ | 125 | gnunet_uri_lib.h \ |
diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index 3d1264991..a1ea31c25 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h | |||
@@ -43,7 +43,6 @@ | |||
43 | 43 | ||
44 | #include "gnunet_util_lib.h" | 44 | #include "gnunet_util_lib.h" |
45 | #include "gnunet_block_lib.h" | 45 | #include "gnunet_block_lib.h" |
46 | #include "gnunet_hello_lib.h" | ||
47 | 46 | ||
48 | #ifdef __cplusplus | 47 | #ifdef __cplusplus |
49 | extern "C" | 48 | extern "C" |
diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h deleted file mode 100644 index b57f48ac5..000000000 --- a/src/include/gnunet_hello_lib.h +++ /dev/null | |||
@@ -1,545 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2010, 2011 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @addtogroup Backbone | ||
23 | * @{ | ||
24 | * | ||
25 | * @author Christian Grothoff | ||
26 | * @file | ||
27 | * Helper library for handling HELLOs | ||
28 | * | ||
29 | * @defgroup hello Hello library | ||
30 | * Helper library for handling HELLOs | ||
31 | * | ||
32 | * @see [Documentation](https://gnunet.org/gnunets-hostlist-subsystem) | ||
33 | * | ||
34 | * @{ | ||
35 | */ | ||
36 | |||
37 | #ifndef GNUNET_HELLO_LIB_H | ||
38 | #define GNUNET_HELLO_LIB_H | ||
39 | |||
40 | #ifdef __cplusplus | ||
41 | extern "C" { | ||
42 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
43 | } | ||
44 | #endif | ||
45 | #endif | ||
46 | |||
47 | |||
48 | #include "gnunet_util_lib.h" | ||
49 | |||
50 | /** | ||
51 | * Prefix that every HELLO URI must start with. | ||
52 | */ | ||
53 | #define GNUNET_HELLO_URI_PREFIX "gnunet://hello/" | ||
54 | |||
55 | /** | ||
56 | * Prefix that every FRIEND HELLO URI must start with. | ||
57 | */ | ||
58 | #define GNUNET_FRIEND_HELLO_URI_PREFIX "gnunet://friend-hello/" | ||
59 | |||
60 | /** | ||
61 | * Separator used in HELLO URI | ||
62 | */ | ||
63 | #define GNUNET_HELLO_URI_SEP '+' | ||
64 | |||
65 | |||
66 | /** | ||
67 | * Additional local information about an address | ||
68 | * | ||
69 | * These information are only valid for the local peer and are not serialized | ||
70 | * when a #GNUNET_HELLO_Message is created | ||
71 | */ | ||
72 | enum GNUNET_HELLO_AddressInfo | ||
73 | { | ||
74 | /** | ||
75 | * No additional information | ||
76 | */ | ||
77 | GNUNET_HELLO_ADDRESS_INFO_NONE = 0, | ||
78 | |||
79 | /** | ||
80 | * This is an inbound address and cannot be used to initiate an outbound | ||
81 | * connection to another peer | ||
82 | */ | ||
83 | GNUNET_HELLO_ADDRESS_INFO_INBOUND = 1 | ||
84 | }; | ||
85 | |||
86 | |||
87 | /** | ||
88 | * An address for communicating with a peer. We frequently | ||
89 | * need this tuple and the components cannot really be | ||
90 | * separated. This is NOT the format that would be used | ||
91 | * on the wire. | ||
92 | */ | ||
93 | struct GNUNET_HELLO_Address | ||
94 | { | ||
95 | /** | ||
96 | * For which peer is this an address? | ||
97 | */ | ||
98 | struct GNUNET_PeerIdentity peer; | ||
99 | |||
100 | /** | ||
101 | * Name of the transport plugin enabling the communication using | ||
102 | * this address. | ||
103 | */ | ||
104 | const char *transport_name; | ||
105 | |||
106 | /** | ||
107 | * Binary representation of the address (plugin-specific). | ||
108 | */ | ||
109 | const void *address; | ||
110 | |||
111 | /** | ||
112 | * Number of bytes in @e address. | ||
113 | */ | ||
114 | size_t address_length; | ||
115 | |||
116 | /** | ||
117 | * Extended information about address | ||
118 | * | ||
119 | * This field contains additional #GNUNET_HELLO_AddressInfo flags e.g. | ||
120 | * to indicate an address is inbound and cannot be used to initiate an | ||
121 | * outbound connection. | ||
122 | * | ||
123 | * These information are only valid for the local peer and are not serialized | ||
124 | * when a #GNUNET_HELLO_Message is created | ||
125 | */ | ||
126 | enum GNUNET_HELLO_AddressInfo local_info; | ||
127 | }; | ||
128 | |||
129 | |||
130 | /** | ||
131 | * Allocate an address struct. | ||
132 | * | ||
133 | * @param peer the peer | ||
134 | * @param transport_name plugin name | ||
135 | * @param address binary address | ||
136 | * @param address_length number of bytes in @a address | ||
137 | * @param local_info additional local information for the address | ||
138 | * @return the address struct | ||
139 | */ | ||
140 | struct GNUNET_HELLO_Address * | ||
141 | GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, | ||
142 | const char *transport_name, | ||
143 | const void *address, | ||
144 | size_t address_length, | ||
145 | enum GNUNET_HELLO_AddressInfo local_info); | ||
146 | |||
147 | |||
148 | /** | ||
149 | * Copy an address struct. | ||
150 | * | ||
151 | * @param address address to copy | ||
152 | * @return a copy of the address struct | ||
153 | */ | ||
154 | struct GNUNET_HELLO_Address * | ||
155 | GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address); | ||
156 | |||
157 | |||
158 | /** | ||
159 | * Compare two addresses. Does NOT compare the peer identity, | ||
160 | * that is assumed already to match! | ||
161 | * | ||
162 | * @param a1 first address | ||
163 | * @param a2 second address | ||
164 | * @return 0 if the addresses are equal, -1 if @a a1< @a a2, 1 if @a a1> @a a2. | ||
165 | */ | ||
166 | int | ||
167 | GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, | ||
168 | const struct GNUNET_HELLO_Address *a2); | ||
169 | |||
170 | |||
171 | /** | ||
172 | * Get the size of an address struct. | ||
173 | * | ||
174 | * @param address address | ||
175 | * @return the size | ||
176 | */ | ||
177 | size_t | ||
178 | GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address); | ||
179 | |||
180 | |||
181 | /** | ||
182 | * Check if an address has a local option set | ||
183 | * | ||
184 | * @param address the address to check | ||
185 | * @param option the respective option to check for | ||
186 | * @return #GNUNET_YES or #GNUNET_NO | ||
187 | */ | ||
188 | int | ||
189 | GNUNET_HELLO_address_check_option (const struct GNUNET_HELLO_Address *address, | ||
190 | enum GNUNET_HELLO_AddressInfo option); | ||
191 | |||
192 | |||
193 | /** | ||
194 | * Free an address. | ||
195 | * | ||
196 | * @param addr address to free | ||
197 | */ | ||
198 | #define GNUNET_HELLO_address_free(addr) GNUNET_free (addr) | ||
199 | |||
200 | |||
201 | GNUNET_NETWORK_STRUCT_BEGIN | ||
202 | |||
203 | /** | ||
204 | * A HELLO message is used to exchange information about | ||
205 | * transports with other peers. This struct is always | ||
206 | * followed by the actual network addresses which have | ||
207 | * the format: | ||
208 | * | ||
209 | * 1) transport-name (0-terminated) | ||
210 | * 2) address-length (uint16_t, network byte order; possibly | ||
211 | * unaligned!) | ||
212 | * 3) address expiration (`struct GNUNET_TIME_AbsoluteNBO`); possibly | ||
213 | * unaligned!) | ||
214 | * 4) address (address-length bytes; possibly unaligned!) | ||
215 | */ | ||
216 | struct GNUNET_HELLO_Message | ||
217 | { | ||
218 | /** | ||
219 | * Type will be #GNUNET_MESSAGE_TYPE_HELLO. | ||
220 | */ | ||
221 | struct GNUNET_MessageHeader header; | ||
222 | |||
223 | /** | ||
224 | * Use in F2F mode: Do not gossip this HELLO message | ||
225 | */ | ||
226 | uint32_t friend_only GNUNET_PACKED; | ||
227 | |||
228 | /** | ||
229 | * The public key of the peer. | ||
230 | */ | ||
231 | struct GNUNET_CRYPTO_EddsaPublicKey publicKey; | ||
232 | }; | ||
233 | GNUNET_NETWORK_STRUCT_END | ||
234 | |||
235 | |||
236 | /** | ||
237 | * Return HELLO type | ||
238 | * | ||
239 | * @param h HELLO Message to test | ||
240 | * @return #GNUNET_YES for friend-only or #GNUNET_NO otherwise | ||
241 | */ | ||
242 | int | ||
243 | GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h); | ||
244 | |||
245 | |||
246 | /** | ||
247 | * Copy the given address information into | ||
248 | * the given buffer using the format of HELLOs. | ||
249 | * | ||
250 | * @param address address to add | ||
251 | * @param expiration expiration for the address | ||
252 | * @param target where to copy the address | ||
253 | * @param max maximum number of bytes to copy to @a target | ||
254 | * @return number of bytes copied, 0 if | ||
255 | * the target buffer was not big enough. | ||
256 | */ | ||
257 | size_t | ||
258 | GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, | ||
259 | struct GNUNET_TIME_Absolute expiration, | ||
260 | char *target, | ||
261 | size_t max); | ||
262 | |||
263 | |||
264 | /** | ||
265 | * Callback function used to fill a buffer of max bytes with a list of | ||
266 | * addresses in the format used by HELLOs. Should use | ||
267 | * #GNUNET_HELLO_add_address() as a helper function. | ||
268 | * | ||
269 | * @param cls closure | ||
270 | * @param max maximum number of bytes that can be written to @a buf | ||
271 | * @param buf where to write the address information | ||
272 | * @return number of bytes written or 0, #GNUNET_SYSERR to signal the | ||
273 | * end of the iteration. | ||
274 | */ | ||
275 | typedef ssize_t | ||
276 | (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls, | ||
277 | size_t max, | ||
278 | void *buf); | ||
279 | |||
280 | |||
281 | /** | ||
282 | * Construct a HELLO message given the public key, | ||
283 | * expiration time and an iterator that spews the | ||
284 | * transport addresses. | ||
285 | * | ||
286 | * If friend only is set to #GNUNET_YES we create a FRIEND_HELLO which | ||
287 | * will not be gossiped to other peers. | ||
288 | * | ||
289 | * @param public_key public key to include in the HELLO | ||
290 | * @param addrgen callback to invoke to get addresses | ||
291 | * @param addrgen_cls closure for @a addrgen | ||
292 | * @param friend_only should the returned HELLO be only visible to friends? | ||
293 | * @return the hello message | ||
294 | */ | ||
295 | struct GNUNET_HELLO_Message * | ||
296 | GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, | ||
297 | GNUNET_HELLO_GenerateAddressListCallback addrgen, | ||
298 | void *addrgen_cls, | ||
299 | int friend_only); | ||
300 | |||
301 | |||
302 | /** | ||
303 | * Return the size of the given HELLO message. | ||
304 | * | ||
305 | * @param hello to inspect | ||
306 | * @return the size, 0 if HELLO is invalid | ||
307 | */ | ||
308 | uint16_t | ||
309 | GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello); | ||
310 | |||
311 | |||
312 | /** | ||
313 | * Construct a HELLO message by merging the | ||
314 | * addresses in two existing HELLOs (which | ||
315 | * must be for the same peer). | ||
316 | * | ||
317 | * @param h1 first HELLO message | ||
318 | * @param h2 the second HELLO message | ||
319 | * @return the combined hello message | ||
320 | */ | ||
321 | struct GNUNET_HELLO_Message * | ||
322 | GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1, | ||
323 | const struct GNUNET_HELLO_Message *h2); | ||
324 | |||
325 | |||
326 | /** | ||
327 | * Test if two HELLO messages contain the same addresses. | ||
328 | * If they only differ in expiration time, the lowest | ||
329 | * expiration time larger than 'now' where they differ | ||
330 | * is returned. | ||
331 | * | ||
332 | * @param h1 first HELLO message | ||
333 | * @param h2 the second HELLO message | ||
334 | * @param now time to use for deciding which addresses have | ||
335 | * expired and should not be considered at all | ||
336 | * @return absolute time forever if the two HELLOs are | ||
337 | * totally identical; smallest timestamp >= now if | ||
338 | * they only differ in timestamps; | ||
339 | * zero if the some addresses with expirations >= now | ||
340 | * do not match at all | ||
341 | */ | ||
342 | struct GNUNET_TIME_Absolute | ||
343 | GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1, | ||
344 | const struct GNUNET_HELLO_Message *h2, | ||
345 | struct GNUNET_TIME_Absolute now); | ||
346 | |||
347 | |||
348 | /** | ||
349 | * Iterator callback to go over all addresses. | ||
350 | * | ||
351 | * @param cls closure | ||
352 | * @param address the address | ||
353 | * @param expiration expiration time | ||
354 | * @return #GNUNET_OK to keep the address, | ||
355 | * #GNUNET_NO to delete it from the HELLO | ||
356 | * #GNUNET_SYSERR to stop iterating (but keep current address) | ||
357 | */ | ||
358 | typedef int (*GNUNET_HELLO_AddressIterator) ( | ||
359 | void *cls, | ||
360 | const struct GNUNET_HELLO_Address *address, | ||
361 | struct GNUNET_TIME_Absolute expiration); | ||
362 | |||
363 | |||
364 | /** | ||
365 | * When does the last address in the given HELLO expire? | ||
366 | * | ||
367 | * @param msg HELLO to inspect | ||
368 | * @return time the last address expires, 0 if there are no addresses in the HELLO | ||
369 | */ | ||
370 | struct GNUNET_TIME_Absolute | ||
371 | GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg); | ||
372 | |||
373 | |||
374 | /** | ||
375 | * Iterate over all of the addresses in the HELLO. | ||
376 | * | ||
377 | * @param msg HELLO to iterate over; client does not need to | ||
378 | * have verified that msg is well-formed (beyond starting | ||
379 | * with a GNUNET_MessageHeader of the right type). | ||
380 | * @param return_modified if a modified copy should be returned, | ||
381 | * otherwise NULL will be returned | ||
382 | * @param it iterator to call on each address | ||
383 | * @param it_cls closure for @a it | ||
384 | * @return the modified HELLO or NULL | ||
385 | */ | ||
386 | struct GNUNET_HELLO_Message * | ||
387 | GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, | ||
388 | int return_modified, | ||
389 | GNUNET_HELLO_AddressIterator it, | ||
390 | void *it_cls); | ||
391 | |||
392 | |||
393 | /** | ||
394 | * Iterate over addresses in @a new_hello that are NOT already present | ||
395 | * in @a old_hello. Note that if the address is present in @a old_hello | ||
396 | * but the expiration time in @a new_hello is more recent, the | ||
397 | * iterator is also called. | ||
398 | * | ||
399 | * @param new_hello a HELLO message | ||
400 | * @param old_hello a HELLO message | ||
401 | * @param expiration_limit ignore addresses in old_hello | ||
402 | * that expired before the given time stamp | ||
403 | * @param it iterator to call on each address | ||
404 | * @param it_cls closure for @a it | ||
405 | */ | ||
406 | void | ||
407 | GNUNET_HELLO_iterate_new_addresses ( | ||
408 | const struct GNUNET_HELLO_Message *new_hello, | ||
409 | const struct GNUNET_HELLO_Message *old_hello, | ||
410 | struct GNUNET_TIME_Absolute expiration_limit, | ||
411 | GNUNET_HELLO_AddressIterator it, | ||
412 | void *it_cls); | ||
413 | |||
414 | |||
415 | /** | ||
416 | * Get the peer identity from a HELLO message. | ||
417 | * | ||
418 | * @param hello the hello message | ||
419 | * @param peer where to store the peer's identity | ||
420 | * @return #GNUNET_SYSERR if the HELLO was malformed | ||
421 | */ | ||
422 | int | ||
423 | GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello, | ||
424 | struct GNUNET_PeerIdentity *peer); | ||
425 | |||
426 | |||
427 | /** | ||
428 | * Get the header from a HELLO message, used so other code | ||
429 | * can correctly send HELLO messages. | ||
430 | * | ||
431 | * @param hello the hello message | ||
432 | * | ||
433 | * @return header or NULL if the HELLO was malformed | ||
434 | */ | ||
435 | struct GNUNET_MessageHeader * | ||
436 | GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello); | ||
437 | |||
438 | |||
439 | /** | ||
440 | * Helper function to load/access transport plugins. | ||
441 | * FIXME: pass closure! | ||
442 | * | ||
443 | * @param name name of the transport plugin to load | ||
444 | * @return NULL if a plugin with name @a name is not known/loadable | ||
445 | */ | ||
446 | typedef struct GNUNET_TRANSPORT_PluginFunctions *( | ||
447 | *GNUNET_HELLO_TransportPluginsFind) (const char *name); | ||
448 | |||
449 | |||
450 | /** | ||
451 | * Compose a hello URI string from a hello message. | ||
452 | * | ||
453 | * @param hello Hello message | ||
454 | * @param plugins_find Function to find transport plugins by name | ||
455 | * @return Hello URI string | ||
456 | */ | ||
457 | char * | ||
458 | GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello, | ||
459 | GNUNET_HELLO_TransportPluginsFind plugins_find); | ||
460 | |||
461 | |||
462 | /** | ||
463 | * Parse a hello URI string to a hello message. | ||
464 | * | ||
465 | * @param uri URI string to parse | ||
466 | * @param pubkey Pointer to struct where public key is parsed | ||
467 | * @param hello Pointer to struct where hello message is parsed | ||
468 | * @param plugins_find Function to find transport plugins by name | ||
469 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the URI was invalid, #GNUNET_NO on other errors | ||
470 | */ | ||
471 | int | ||
472 | GNUNET_HELLO_parse_uri (const char *uri, | ||
473 | struct GNUNET_CRYPTO_EddsaPublicKey *pubkey, | ||
474 | struct GNUNET_HELLO_Message **hello, | ||
475 | GNUNET_HELLO_TransportPluginsFind plugins_find); | ||
476 | |||
477 | |||
478 | /* NG API */ | ||
479 | #include "gnunet_util_lib.h" | ||
480 | |||
481 | |||
482 | /** | ||
483 | * Build address record by signing raw information with private key. | ||
484 | * | ||
485 | * @param address text address to sign | ||
486 | * @param nt network type of @a address | ||
487 | * @param mono_time when was @a address valid | ||
488 | * @param private_key signing key to use | ||
489 | * @param[out] result where to write address record (allocated) | ||
490 | * @param[out] result_size set to size of @a result | ||
491 | */ | ||
492 | void | ||
493 | GNUNET_HELLO_sign_address ( | ||
494 | const char *address, | ||
495 | enum GNUNET_NetworkType nt, | ||
496 | struct GNUNET_TIME_Absolute mono_time, | ||
497 | const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, | ||
498 | void **result, | ||
499 | size_t *result_size); | ||
500 | |||
501 | |||
502 | /** | ||
503 | * Check signature and extract address record. | ||
504 | * | ||
505 | * @param raw raw signed address | ||
506 | * @param raw_size size of @a raw | ||
507 | * @param pid public key to use for signature verification | ||
508 | * @param[out] nt set to network type | ||
509 | * @param[out] mono_time when was the address generated | ||
510 | * @return NULL on error, otherwise the address | ||
511 | */ | ||
512 | char * | ||
513 | GNUNET_HELLO_extract_address (const void *raw, | ||
514 | size_t raw_size, | ||
515 | const struct GNUNET_PeerIdentity *pid, | ||
516 | enum GNUNET_NetworkType *nt, | ||
517 | struct GNUNET_TIME_Absolute *mono_time); | ||
518 | |||
519 | |||
520 | /** | ||
521 | * Given an address as a string, extract the prefix that identifies | ||
522 | * the communicator offering transmissions to that address. | ||
523 | * | ||
524 | * @param address a peer's address | ||
525 | * @return NULL if the address is mal-formed, otherwise the prefix | ||
526 | */ | ||
527 | char * | ||
528 | GNUNET_HELLO_address_to_prefix (const char *address); | ||
529 | |||
530 | |||
531 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
532 | { | ||
533 | #endif | ||
534 | #ifdef __cplusplus | ||
535 | } | ||
536 | #endif | ||
537 | |||
538 | /* ifndef GNUNET_HELLO_LIB_H */ | ||
539 | #endif | ||
540 | |||
541 | /** @} */ /* end of group */ | ||
542 | |||
543 | /** @} */ /* end of group addition */ | ||
544 | |||
545 | /* end of gnunet_hello_lib.h */ | ||
diff --git a/src/include/gnunet_hello_uri_lib.h b/src/include/gnunet_hello_uri_lib.h index 1c804f590..7ebf75a9e 100644 --- a/src/include/gnunet_hello_uri_lib.h +++ b/src/include/gnunet_hello_uri_lib.h | |||
@@ -258,6 +258,35 @@ GNUNET_HELLO_dht_msg_to_block (const struct GNUNET_MessageHeader *hello, | |||
258 | struct GNUNET_TIME_Absolute *block_expiration); | 258 | struct GNUNET_TIME_Absolute *block_expiration); |
259 | 259 | ||
260 | 260 | ||
261 | /** | ||
262 | * Given an address as a string, extract the prefix that identifies | ||
263 | * the communicator offering transmissions to that address. | ||
264 | * | ||
265 | * @param address a peer's address | ||
266 | * @return NULL if the address is mal-formed, otherwise the prefix | ||
267 | */ | ||
268 | char * | ||
269 | GNUNET_HELLO_address_to_prefix (const char *address); | ||
270 | |||
271 | /** | ||
272 | * Build address record by signing raw information with private key. | ||
273 | * | ||
274 | * @param address text address to sign | ||
275 | * @param nt network type of @a address | ||
276 | * @param mono_time when was @a address valid | ||
277 | * @param private_key signing key to use | ||
278 | * @param[out] result where to write address record (allocated) | ||
279 | * @param[out] result_size set to size of @a result | ||
280 | */ | ||
281 | void | ||
282 | GNUNET_HELLO_sign_address ( | ||
283 | const char *address, | ||
284 | enum GNUNET_NetworkType nt, | ||
285 | struct GNUNET_TIME_Absolute mono_time, | ||
286 | const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, | ||
287 | void **result, | ||
288 | size_t *result_size); | ||
289 | |||
261 | #if 0 /* keep Emacsens' auto-indent happy */ | 290 | #if 0 /* keep Emacsens' auto-indent happy */ |
262 | { | 291 | { |
263 | #endif | 292 | #endif |
diff --git a/src/include/gnunet_transport_hello_service.h b/src/include/gnunet_transport_hello_service.h deleted file mode 100644 index 34d3c8e4a..000000000 --- a/src/include/gnunet_transport_hello_service.h +++ /dev/null | |||
@@ -1,209 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009-2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @addtogroup Backbone | ||
23 | * @{ | ||
24 | * | ||
25 | * @author Christian Grothoff | ||
26 | * | ||
27 | * @file | ||
28 | * obtain information about our current address | ||
29 | * | ||
30 | * @deprecated, in TNG applications should query PEERSTORE directly! | ||
31 | * | ||
32 | * @defgroup transport Transport service | ||
33 | * address information | ||
34 | * | ||
35 | * @see [Documentation](https://gnunet.org/transport-service) | ||
36 | * | ||
37 | * @{ | ||
38 | */ | ||
39 | #ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H | ||
40 | #define GNUNET_TRANSPORT_HELLO_SERVICE_H | ||
41 | |||
42 | #ifdef __cplusplus | ||
43 | extern "C" { | ||
44 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
45 | } | ||
46 | #endif | ||
47 | #endif | ||
48 | |||
49 | |||
50 | #include "gnunet_util_lib.h" | ||
51 | #include "gnunet_ats_service.h" | ||
52 | |||
53 | /** | ||
54 | * Version number of the transport API. | ||
55 | */ | ||
56 | #define GNUNET_TRANSPORT_HELLO_VERSION 0x00000000 | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Some addresses contain sensitive information or are | ||
61 | * not suitable for global distribution. We use address | ||
62 | * classes to filter addresses by which domain they make | ||
63 | * sense to be used in. These are used in a bitmask. | ||
64 | */ | ||
65 | enum GNUNET_TRANSPORT_AddressClass | ||
66 | { | ||
67 | /** | ||
68 | * No address. | ||
69 | */ | ||
70 | GNUNET_TRANSPORT_AC_NONE = 0, | ||
71 | |||
72 | /** | ||
73 | * Addresses that fall into no other category | ||
74 | * (i.e. incoming which we cannot use elsewhere). | ||
75 | */ | ||
76 | GNUNET_TRANSPORT_AC_OTHER = 1, | ||
77 | |||
78 | /** | ||
79 | * Addresses that are global and are insensitive | ||
80 | * (i.e. IPv4). | ||
81 | */ | ||
82 | GNUNET_TRANSPORT_AC_GLOBAL = 2, | ||
83 | |||
84 | /** | ||
85 | * Addresses that are global and are sensitive | ||
86 | * (i.e. IPv6 with our MAC). | ||
87 | */ | ||
88 | GNUNET_TRANSPORT_AC_GLOBAL_PRIVATE = 4, | ||
89 | |||
90 | /** | ||
91 | * Addresses useful in the local wired network, | ||
92 | * i.e. a MAC. Sensitive, but obvious to people nearby. | ||
93 | * Useful for broadcasts. | ||
94 | */ | ||
95 | GNUNET_TRANSPORT_AC_LAN = 8, | ||
96 | |||
97 | /** | ||
98 | * Addresses useful in the local wireless network, | ||
99 | * i.e. a MAC. Sensitive, but obvious to people nearby. | ||
100 | * Useful for broadcasts. | ||
101 | */ | ||
102 | GNUNET_TRANSPORT_AC_WLAN = 16, | ||
103 | |||
104 | /** | ||
105 | * Addresses useful in the local bluetooth network. Sensitive, but | ||
106 | * obvious to people nearby. Useful for broadcasts. | ||
107 | */ | ||
108 | GNUNET_TRANSPORT_AC_BT = 32, | ||
109 | |||
110 | /** | ||
111 | * Bitmask for "any" address. | ||
112 | */ | ||
113 | GNUNET_TRANSPORT_AC_ANY = 65535 | ||
114 | }; | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Function called whenever there is an update to the | ||
119 | * HELLO of this peer. | ||
120 | * | ||
121 | * @param cls closure | ||
122 | * @param hello our updated HELLO | ||
123 | */ | ||
124 | typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) ( | ||
125 | void *cls, | ||
126 | const struct GNUNET_MessageHeader *hello); | ||
127 | |||
128 | |||
129 | /** | ||
130 | * Handle to cancel a #GNUNET_TRANSPORT_hello_get() operation. | ||
131 | */ | ||
132 | struct GNUNET_TRANSPORT_HelloGetHandle; | ||
133 | |||
134 | |||
135 | /** | ||
136 | * Obtain updates on changes to the HELLO message for this peer. The callback | ||
137 | * given in this function is never called synchronously. | ||
138 | * | ||
139 | * @param cfg configuration to use | ||
140 | * @param ac which network type should the addresses from the HELLO belong to? | ||
141 | * @param rec function to call with the HELLO | ||
142 | * @param rec_cls closure for @a rec | ||
143 | * @return handle to cancel the operation | ||
144 | */ | ||
145 | struct GNUNET_TRANSPORT_HelloGetHandle * | ||
146 | GNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
147 | enum GNUNET_TRANSPORT_AddressClass ac, | ||
148 | GNUNET_TRANSPORT_HelloUpdateCallback rec, | ||
149 | void *rec_cls) __attribute__((deprecated)); | ||
150 | |||
151 | |||
152 | /** | ||
153 | * Stop receiving updates about changes to our HELLO message. | ||
154 | * | ||
155 | * @param ghh handle to cancel | ||
156 | */ | ||
157 | void | ||
158 | GNUNET_TRANSPORT_hello_get_cancel (struct | ||
159 | GNUNET_TRANSPORT_HelloGetHandle *ghh) | ||
160 | __attribute__((deprecated)); | ||
161 | |||
162 | |||
163 | /** | ||
164 | * Function with addresses found in a HELLO. | ||
165 | * | ||
166 | * @param cls closure | ||
167 | * @param peer identity of the peer | ||
168 | * @param address the address (UTF-8, 0-terminated) | ||
169 | * @param nt network type of the address | ||
170 | * @param expiration when does this address expire? | ||
171 | */ | ||
172 | typedef void (*GNUNET_TRANSPORT_AddressCallback)( | ||
173 | void *cls, | ||
174 | const struct GNUNET_PeerIdentity *peer, | ||
175 | const char *address, | ||
176 | enum GNUNET_NetworkType nt, | ||
177 | struct GNUNET_TIME_Absolute expiration) __attribute__((deprecated)); | ||
178 | |||
179 | |||
180 | /** | ||
181 | * Parse a HELLO message that we have received into its | ||
182 | * constituent addresses. | ||
183 | * | ||
184 | * @param hello message to parse | ||
185 | * @param cb function to call on each address found | ||
186 | * @param cb_cls closure for @a cb | ||
187 | * @return #GNUNET_OK if hello was well-formed, #GNUNET_SYSERR if not | ||
188 | */ | ||
189 | int | ||
190 | GNUNET_TRANSPORT_hello_parse (const struct GNUNET_MessageHeader *hello, | ||
191 | GNUNET_TRANSPORT_AddressCallback cb, | ||
192 | void *cb_cls) __attribute__((deprecated)); | ||
193 | |||
194 | |||
195 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
196 | { | ||
197 | #endif | ||
198 | #ifdef __cplusplus | ||
199 | } | ||
200 | #endif | ||
201 | |||
202 | /* ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H */ | ||
203 | #endif | ||
204 | |||
205 | /** @} */ /* end of group */ | ||
206 | |||
207 | /** @} */ /* end of group addition */ | ||
208 | |||
209 | /* end of gnunet_transport_hello_service.h */ | ||
diff --git a/src/lib/hello/Makefile.am b/src/lib/hello/Makefile.am index 4435dba42..cbc193a0a 100644 --- a/src/lib/hello/Makefile.am +++ b/src/lib/hello/Makefile.am | |||
@@ -9,8 +9,6 @@ endif | |||
9 | lib_LTLIBRARIES = libgnunethello.la | 9 | lib_LTLIBRARIES = libgnunethello.la |
10 | 10 | ||
11 | libgnunethello_la_SOURCES = \ | 11 | libgnunethello_la_SOURCES = \ |
12 | address.c \ | ||
13 | hello-ng.c \ | ||
14 | hello-uri.c | 12 | hello-uri.c |
15 | libgnunethello_la_LIBADD = \ | 13 | libgnunethello_la_LIBADD = \ |
16 | $(top_builddir)/src/lib/util/libgnunetutil.la $(XLIB) \ | 14 | $(top_builddir)/src/lib/util/libgnunetutil.la $(XLIB) \ |
diff --git a/src/lib/hello/address.c b/src/lib/hello/address.c deleted file mode 100644 index 6a1b68029..000000000 --- a/src/lib/hello/address.c +++ /dev/null | |||
@@ -1,139 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file hello/address.c | ||
23 | * @brief helper functions for handling addresses | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_hello_lib.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | |||
30 | |||
31 | /** | ||
32 | * Check if an address has a local option set | ||
33 | * | ||
34 | * @param address the address to check | ||
35 | * @param option the respective option to check for | ||
36 | * @return #GNUNET_YES or #GNUNET_NO | ||
37 | */ | ||
38 | int | ||
39 | GNUNET_HELLO_address_check_option (const struct GNUNET_HELLO_Address *address, | ||
40 | enum GNUNET_HELLO_AddressInfo option) | ||
41 | { | ||
42 | if (option == (address->local_info & option)) | ||
43 | return GNUNET_YES; | ||
44 | return GNUNET_NO; | ||
45 | } | ||
46 | |||
47 | |||
48 | /** | ||
49 | * Get the size of an address struct. | ||
50 | * | ||
51 | * @param address address | ||
52 | * @return the size | ||
53 | */ | ||
54 | size_t | ||
55 | GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address) | ||
56 | { | ||
57 | return sizeof(struct GNUNET_HELLO_Address) + address->address_length | ||
58 | + strlen (address->transport_name) + 1; | ||
59 | } | ||
60 | |||
61 | |||
62 | struct GNUNET_HELLO_Address * | ||
63 | GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, | ||
64 | const char *transport_name, | ||
65 | const void *address, | ||
66 | size_t address_length, | ||
67 | enum GNUNET_HELLO_AddressInfo local_info) | ||
68 | { | ||
69 | struct GNUNET_HELLO_Address *addr; | ||
70 | size_t slen; | ||
71 | char *end; | ||
72 | |||
73 | slen = strlen (transport_name) + 1; | ||
74 | addr = GNUNET_malloc (sizeof(struct GNUNET_HELLO_Address) | ||
75 | + address_length + slen); | ||
76 | addr->peer = *peer; | ||
77 | addr->address = &addr[1]; | ||
78 | addr->address_length = address_length; | ||
79 | addr->local_info = local_info; | ||
80 | end = (char *) &addr[1]; | ||
81 | addr->transport_name = &end[address_length]; | ||
82 | GNUNET_memcpy (end, | ||
83 | address, | ||
84 | address_length); | ||
85 | GNUNET_memcpy (&end[address_length], | ||
86 | transport_name, | ||
87 | slen); | ||
88 | return addr; | ||
89 | } | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Copy an address struct. | ||
94 | * | ||
95 | * @param address address to copy | ||
96 | * @return a copy of the address struct | ||
97 | */ | ||
98 | struct GNUNET_HELLO_Address * | ||
99 | GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address) | ||
100 | { | ||
101 | if (NULL == address) | ||
102 | return NULL; | ||
103 | return GNUNET_HELLO_address_allocate (&address->peer, | ||
104 | address->transport_name, | ||
105 | address->address, | ||
106 | address->address_length, | ||
107 | address->local_info); | ||
108 | } | ||
109 | |||
110 | |||
111 | int | ||
112 | GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, | ||
113 | const struct GNUNET_HELLO_Address *a2) | ||
114 | { | ||
115 | int ret; | ||
116 | |||
117 | if ((NULL == a1) && | ||
118 | (NULL == a2)) | ||
119 | return 0; | ||
120 | if (NULL == a1) | ||
121 | return 1; | ||
122 | if (NULL == a2) | ||
123 | return -1; | ||
124 | ret = strcmp (a1->transport_name, a2->transport_name); | ||
125 | if (0 != ret) | ||
126 | return ret; | ||
127 | if (a1->local_info != a2->local_info) | ||
128 | return (((int) a1->local_info) < ((int) a2->local_info)) ? -1 : 1; | ||
129 | if (a1->address_length < a2->address_length) | ||
130 | return -1; | ||
131 | if (a1->address_length > a2->address_length) | ||
132 | return 1; | ||
133 | return memcmp (a1->address, | ||
134 | a2->address, | ||
135 | a1->address_length); | ||
136 | } | ||
137 | |||
138 | |||
139 | /* end of address.c */ | ||
diff --git a/src/lib/hello/gnunet-hello.c b/src/lib/hello/gnunet-hello.c index 7f43e77b9..aaa4b5005 100644 --- a/src/lib/hello/gnunet-hello.c +++ b/src/lib/hello/gnunet-hello.c | |||
@@ -24,7 +24,6 @@ | |||
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_protocols.h" | 26 | #include "gnunet_protocols.h" |
27 | #include "gnunet_hello_lib.h" | ||
28 | #include "gnunet_hello_uri_lib.h" | 27 | #include "gnunet_hello_uri_lib.h" |
29 | #include "gnunet_transport_plugin.h" | 28 | #include "gnunet_transport_plugin.h" |
30 | 29 | ||
diff --git a/src/lib/hello/hello-uri.c b/src/lib/hello/hello-uri.c index 25f8948fe..4d0cb4ee0 100644 --- a/src/lib/hello/hello-uri.c +++ b/src/lib/hello/hello-uri.c | |||
@@ -44,6 +44,27 @@ | |||
44 | GNUNET_NETWORK_STRUCT_BEGIN | 44 | GNUNET_NETWORK_STRUCT_BEGIN |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Binary block we sign when we sign an address. | ||
48 | */ | ||
49 | struct SignedAddress | ||
50 | { | ||
51 | /** | ||
52 | * Purpose must be #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS | ||
53 | */ | ||
54 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
55 | |||
56 | /** | ||
57 | * When was the address generated. | ||
58 | */ | ||
59 | struct GNUNET_TIME_AbsoluteNBO mono_time; | ||
60 | |||
61 | /** | ||
62 | * Hash of the address. | ||
63 | */ | ||
64 | struct GNUNET_HashCode addr_hash GNUNET_PACKED; | ||
65 | }; | ||
66 | |||
67 | /** | ||
47 | * Message signed as part of a HELLO block/URL. | 68 | * Message signed as part of a HELLO block/URL. |
48 | */ | 69 | */ |
49 | struct HelloSignaturePurpose | 70 | struct HelloSignaturePurpose |
@@ -962,3 +983,63 @@ GNUNET_HELLO_dht_msg_to_block (const struct GNUNET_MessageHeader *hello, | |||
962 | } | 983 | } |
963 | return ret; | 984 | return ret; |
964 | } | 985 | } |
986 | |||
987 | |||
988 | /** | ||
989 | * Given an address as a string, extract the prefix that identifies | ||
990 | * the communicator offering transmissions to that address. | ||
991 | * | ||
992 | * @param address a peer's address | ||
993 | * @return NULL if the address is mal-formed, otherwise the prefix | ||
994 | */ | ||
995 | char * | ||
996 | GNUNET_HELLO_address_to_prefix (const char *address) | ||
997 | { | ||
998 | const char *dash; | ||
999 | |||
1000 | dash = strchr (address, '-'); | ||
1001 | if (NULL == dash) | ||
1002 | return NULL; | ||
1003 | return GNUNET_strndup (address, dash - address); | ||
1004 | } | ||
1005 | |||
1006 | |||
1007 | /** | ||
1008 | * Build address record by signing raw information with private key. | ||
1009 | * | ||
1010 | * @param address text address at @a communicator to sign | ||
1011 | * @param nt network type of @a address | ||
1012 | * @param mono_time monotonic time at which @a address was valid | ||
1013 | * @param private_key signing key to use | ||
1014 | * @param[out] result where to write address record (allocated) | ||
1015 | * @param[out] result_size set to size of @a result | ||
1016 | */ | ||
1017 | void | ||
1018 | GNUNET_HELLO_sign_address ( | ||
1019 | const char *address, | ||
1020 | enum GNUNET_NetworkType nt, | ||
1021 | struct GNUNET_TIME_Absolute mono_time, | ||
1022 | const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, | ||
1023 | void **result, | ||
1024 | size_t *result_size) | ||
1025 | { | ||
1026 | struct SignedAddress sa; | ||
1027 | struct GNUNET_CRYPTO_EddsaSignature sig; | ||
1028 | char *sig_str; | ||
1029 | |||
1030 | sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); | ||
1031 | sa.purpose.size = htonl (sizeof(sa)); | ||
1032 | sa.mono_time = GNUNET_TIME_absolute_hton (mono_time); | ||
1033 | GNUNET_CRYPTO_hash (address, strlen (address), &sa.addr_hash); | ||
1034 | GNUNET_CRYPTO_eddsa_sign (private_key, &sa, &sig); | ||
1035 | sig_str = NULL; | ||
1036 | (void) GNUNET_STRINGS_base64_encode (&sig, sizeof(sig), &sig_str); | ||
1037 | *result_size = | ||
1038 | 1 + GNUNET_asprintf ((char **) result, | ||
1039 | "%s;%llu;%u;%s", | ||
1040 | sig_str, | ||
1041 | (unsigned long long) mono_time.abs_value_us, | ||
1042 | (unsigned int) nt, | ||
1043 | address); | ||
1044 | GNUNET_free (sig_str); | ||
1045 | } | ||
diff --git a/src/lib/hello/hello.c b/src/lib/hello/hello.c deleted file mode 100644 index 45d27c5d4..000000000 --- a/src/lib/hello/hello.c +++ /dev/null | |||
@@ -1,1249 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2015 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file hello/hello.c | ||
23 | * @brief helper library for handling HELLOs | ||
24 | * @author Christian Grothoff | ||
25 | * @author Matthias Wachs | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_hello_lib.h" | ||
29 | #include "gnunet_protocols.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_transport_plugin.h" | ||
32 | |||
33 | /** | ||
34 | * Context used for building our own URI. | ||
35 | */ | ||
36 | struct GNUNET_HELLO_ComposeUriContext | ||
37 | { | ||
38 | /** | ||
39 | * Final URI. | ||
40 | */ | ||
41 | char *uri; | ||
42 | |||
43 | /** | ||
44 | * Function for finding transport plugins by name. | ||
45 | */ | ||
46 | GNUNET_HELLO_TransportPluginsFind plugins_find; | ||
47 | }; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Context for #add_address_to_hello(). | ||
52 | */ | ||
53 | struct GNUNET_HELLO_ParseUriContext | ||
54 | { | ||
55 | /** | ||
56 | * Position in the URI with the next address to parse. | ||
57 | */ | ||
58 | const char *pos; | ||
59 | |||
60 | /** | ||
61 | * Set to #GNUNET_SYSERR to indicate parse errors. | ||
62 | */ | ||
63 | int ret; | ||
64 | |||
65 | /** | ||
66 | * Counter | ||
67 | */ | ||
68 | unsigned int counter_total; | ||
69 | |||
70 | /** | ||
71 | * Counter skipped addresses | ||
72 | */ | ||
73 | unsigned int counter_added; | ||
74 | |||
75 | /** | ||
76 | * Function for finding transport plugins by name. | ||
77 | */ | ||
78 | GNUNET_HELLO_TransportPluginsFind plugins_find; | ||
79 | }; | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Return HELLO type | ||
84 | * | ||
85 | * @param h HELLO Message to test | ||
86 | * @return #GNUNET_YES for friend-only or #GNUNET_NO otherwise | ||
87 | */ | ||
88 | int | ||
89 | GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h) | ||
90 | { | ||
91 | if (GNUNET_YES == ntohl (h->friend_only)) | ||
92 | return GNUNET_YES; | ||
93 | return GNUNET_NO; | ||
94 | } | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Copy the given address information into | ||
99 | * the given buffer using the format of HELLOs. | ||
100 | * | ||
101 | * @param address the address | ||
102 | * @param expiration expiration for the @a address | ||
103 | * @param target where to copy the @a address | ||
104 | * @param max maximum number of bytes to copy to target | ||
105 | * @return number of bytes copied, 0 if | ||
106 | * the target buffer was not big enough. | ||
107 | */ | ||
108 | size_t | ||
109 | GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, | ||
110 | struct GNUNET_TIME_Absolute expiration, | ||
111 | char *target, | ||
112 | size_t max) | ||
113 | { | ||
114 | uint16_t alen; | ||
115 | size_t slen; | ||
116 | struct GNUNET_TIME_AbsoluteNBO exp; | ||
117 | |||
118 | slen = strlen (address->transport_name) + 1; | ||
119 | if (slen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
120 | + address->address_length > max) | ||
121 | return 0; | ||
122 | exp = GNUNET_TIME_absolute_hton (expiration); | ||
123 | alen = htons ((uint16_t) address->address_length); | ||
124 | GNUNET_memcpy (target, address->transport_name, slen); | ||
125 | GNUNET_memcpy (&target[slen], &alen, sizeof(uint16_t)); | ||
126 | slen += sizeof(uint16_t); | ||
127 | GNUNET_memcpy (&target[slen], &exp, sizeof(struct GNUNET_TIME_AbsoluteNBO)); | ||
128 | slen += sizeof(struct GNUNET_TIME_AbsoluteNBO); | ||
129 | GNUNET_memcpy (&target[slen], address->address, address->address_length); | ||
130 | slen += address->address_length; | ||
131 | return slen; | ||
132 | } | ||
133 | |||
134 | |||
135 | /** | ||
136 | * Get the size of an address entry in a HELLO message. | ||
137 | * | ||
138 | * @param buf pointer to the start of the address entry | ||
139 | * @param max maximum size of the entry (end of @a buf) | ||
140 | * @param ralen set to the address length | ||
141 | * @return size of the entry, or 0 if @a max is not large enough | ||
142 | */ | ||
143 | static size_t | ||
144 | get_hello_address_size (const char *buf, | ||
145 | size_t max, | ||
146 | uint16_t *ralen) | ||
147 | { | ||
148 | const char *pos; | ||
149 | uint16_t alen; | ||
150 | size_t left; | ||
151 | size_t slen; | ||
152 | |||
153 | left = max; | ||
154 | pos = buf; | ||
155 | slen = 1; | ||
156 | while ((left > 0) && ('\0' != *pos)) | ||
157 | { | ||
158 | left--; | ||
159 | pos++; | ||
160 | slen++; | ||
161 | } | ||
162 | if (0 == left) | ||
163 | { | ||
164 | /* 0-termination not found */ | ||
165 | GNUNET_break_op (0); | ||
166 | return 0; | ||
167 | } | ||
168 | pos++; | ||
169 | if (left < sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO)) | ||
170 | { | ||
171 | /* not enough space for addrlen */ | ||
172 | GNUNET_break_op (0); | ||
173 | return 0; | ||
174 | } | ||
175 | GNUNET_memcpy (&alen, pos, sizeof(uint16_t)); | ||
176 | alen = ntohs (alen); | ||
177 | *ralen = alen; | ||
178 | slen += alen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO); | ||
179 | if (max < slen) | ||
180 | { | ||
181 | /* not enough space for addr */ | ||
182 | GNUNET_break_op (0); | ||
183 | return 0; | ||
184 | } | ||
185 | return slen; | ||
186 | } | ||
187 | |||
188 | |||
189 | /** | ||
190 | * Construct a HELLO message given the public key, | ||
191 | * expiration time and an iterator that spews the | ||
192 | * transport addresses. | ||
193 | * | ||
194 | * If friend only is set to #GNUNET_YES we create a FRIEND_HELLO which | ||
195 | * will not be gossiped to other peers. | ||
196 | * | ||
197 | * @param public_key public key to include in the HELLO | ||
198 | * @param addrgen callback to invoke to get addresses | ||
199 | * @param addrgen_cls closure for @a addrgen | ||
200 | * @param friend_only should the returned HELLO be only visible to friends? | ||
201 | * @return the hello message | ||
202 | */ | ||
203 | struct GNUNET_HELLO_Message * | ||
204 | GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, | ||
205 | GNUNET_HELLO_GenerateAddressListCallback addrgen, | ||
206 | void *addrgen_cls, | ||
207 | int friend_only) | ||
208 | { | ||
209 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1 - 256 | ||
210 | - sizeof(struct GNUNET_HELLO_Message)]; | ||
211 | size_t max; | ||
212 | size_t used; | ||
213 | size_t ret; | ||
214 | struct GNUNET_HELLO_Message *hello; | ||
215 | |||
216 | GNUNET_assert (NULL != public_key); | ||
217 | GNUNET_assert ((GNUNET_YES == friend_only) || | ||
218 | (GNUNET_NO == friend_only)); | ||
219 | max = sizeof(buffer); | ||
220 | used = 0; | ||
221 | if (NULL != addrgen) | ||
222 | { | ||
223 | while (GNUNET_SYSERR != (ret = addrgen (addrgen_cls, | ||
224 | max, | ||
225 | &buffer[used]))) | ||
226 | { | ||
227 | max -= ret; | ||
228 | used += ret; | ||
229 | } | ||
230 | } | ||
231 | hello = GNUNET_malloc (sizeof(struct GNUNET_HELLO_Message) + used); | ||
232 | hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO); | ||
233 | hello->header.size = htons (sizeof(struct GNUNET_HELLO_Message) + used); | ||
234 | hello->friend_only = htonl (friend_only); | ||
235 | hello->publicKey = *public_key; | ||
236 | GNUNET_memcpy (&hello[1], | ||
237 | buffer, | ||
238 | used); | ||
239 | return hello; | ||
240 | } | ||
241 | |||
242 | |||
243 | /** | ||
244 | * Iterate over all of the addresses in the HELLO. | ||
245 | * | ||
246 | * @param msg HELLO to iterate over | ||
247 | * @param return_modified if a modified copy should be returned, | ||
248 | * otherwise NULL will be returned | ||
249 | * @param it iterator to call on each address | ||
250 | * @param it_cls closure for @a it | ||
251 | * @return modified HELLO message | ||
252 | */ | ||
253 | struct GNUNET_HELLO_Message * | ||
254 | GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, | ||
255 | int return_modified, | ||
256 | GNUNET_HELLO_AddressIterator it, | ||
257 | void *it_cls) | ||
258 | { | ||
259 | struct GNUNET_HELLO_Address address; | ||
260 | uint16_t msize; | ||
261 | struct GNUNET_HELLO_Message *ret; | ||
262 | const char *inptr; | ||
263 | size_t insize; | ||
264 | size_t esize; | ||
265 | size_t wpos; | ||
266 | char *woff; | ||
267 | uint16_t alen; | ||
268 | struct GNUNET_TIME_AbsoluteNBO expire; | ||
269 | int iret; | ||
270 | |||
271 | msize = GNUNET_HELLO_size (msg); | ||
272 | if ((msize < sizeof(struct GNUNET_HELLO_Message)) || | ||
273 | (ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | ||
274 | { | ||
275 | GNUNET_break_op (0); | ||
276 | return NULL; | ||
277 | } | ||
278 | ret = NULL; | ||
279 | if (return_modified) | ||
280 | { | ||
281 | ret = GNUNET_malloc (msize); | ||
282 | GNUNET_memcpy (ret, | ||
283 | msg, | ||
284 | msize); | ||
285 | } | ||
286 | inptr = (const char *) &msg[1]; | ||
287 | insize = msize - sizeof(struct GNUNET_HELLO_Message); | ||
288 | wpos = 0; | ||
289 | woff = (NULL != ret) ? (char *) &ret[1] : NULL; | ||
290 | address.peer.public_key = msg->publicKey; | ||
291 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
292 | "HELLO has %u bytes of address data\n", | ||
293 | (unsigned int) insize); | ||
294 | |||
295 | while (insize > 0) | ||
296 | { | ||
297 | esize = get_hello_address_size (inptr, | ||
298 | insize, | ||
299 | &alen); | ||
300 | if (0 == esize) | ||
301 | { | ||
302 | GNUNET_break (0); | ||
303 | GNUNET_free (ret); | ||
304 | return NULL; | ||
305 | } | ||
306 | /* need GNUNET_memcpy() due to possibility of misalignment */ | ||
307 | GNUNET_memcpy (&expire, | ||
308 | &inptr[esize - alen - sizeof(struct | ||
309 | GNUNET_TIME_AbsoluteNBO)], | ||
310 | sizeof(struct GNUNET_TIME_AbsoluteNBO)); | ||
311 | address.address = &inptr[esize - alen]; | ||
312 | address.address_length = alen; | ||
313 | address.transport_name = inptr; | ||
314 | address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; | ||
315 | iret = it (it_cls, | ||
316 | &address, | ||
317 | GNUNET_TIME_absolute_ntoh (expire)); | ||
318 | if (GNUNET_SYSERR == iret) | ||
319 | break; | ||
320 | if ((GNUNET_OK == iret) && | ||
321 | (NULL != ret)) | ||
322 | { | ||
323 | /* copy address over */ | ||
324 | GNUNET_memcpy (woff, | ||
325 | inptr, | ||
326 | esize); | ||
327 | woff += esize; | ||
328 | wpos += esize; | ||
329 | } | ||
330 | insize -= esize; | ||
331 | inptr += esize; | ||
332 | } | ||
333 | if (NULL != ret) | ||
334 | ret->header.size = ntohs (sizeof(struct GNUNET_HELLO_Message) + wpos); | ||
335 | return ret; | ||
336 | } | ||
337 | |||
338 | |||
339 | /** | ||
340 | * Closure for #get_match_exp(). | ||
341 | */ | ||
342 | struct ExpireContext | ||
343 | { | ||
344 | /** | ||
345 | * Address we are looking for. | ||
346 | */ | ||
347 | const struct GNUNET_HELLO_Address *address; | ||
348 | |||
349 | /** | ||
350 | * Set to #GNUNET_YES if we found the @e address. | ||
351 | */ | ||
352 | int found; | ||
353 | |||
354 | /** | ||
355 | * Set to the expiration of the match if @e found is #GNUNET_YES. | ||
356 | */ | ||
357 | struct GNUNET_TIME_Absolute expiration; | ||
358 | }; | ||
359 | |||
360 | |||
361 | /** | ||
362 | * Store the expiration time of an address that matches the template. | ||
363 | * | ||
364 | * @param cls the `struct ExpireContext` | ||
365 | * @param address address to match against the template | ||
366 | * @param expiration expiration time of @a address, to store in @a cls | ||
367 | * @return #GNUNET_SYSERR if we found a matching address, #GNUNET_OK otherwise | ||
368 | */ | ||
369 | static int | ||
370 | get_match_exp (void *cls, | ||
371 | const struct GNUNET_HELLO_Address *address, | ||
372 | struct GNUNET_TIME_Absolute expiration) | ||
373 | { | ||
374 | struct ExpireContext *ec = cls; | ||
375 | |||
376 | if (0 != GNUNET_HELLO_address_cmp (address, | ||
377 | ec->address)) | ||
378 | return GNUNET_OK; | ||
379 | ec->found = GNUNET_YES; | ||
380 | ec->expiration = expiration; | ||
381 | return GNUNET_SYSERR; /* done here */ | ||
382 | } | ||
383 | |||
384 | |||
385 | /** | ||
386 | * Context for a #GNUNET_HELLO_Merge operation. | ||
387 | */ | ||
388 | struct MergeContext | ||
389 | { | ||
390 | /** | ||
391 | * First HELLO we are merging. | ||
392 | */ | ||
393 | const struct GNUNET_HELLO_Message *h1; | ||
394 | |||
395 | /** | ||
396 | * Second HELLO we are merging. | ||
397 | */ | ||
398 | const struct GNUNET_HELLO_Message *h2; | ||
399 | |||
400 | /** | ||
401 | * Either @e h1 or @e h2, used when copying | ||
402 | * to compare against (so we only copy the | ||
403 | * most recent entry). | ||
404 | */ | ||
405 | const struct GNUNET_HELLO_Message *other; | ||
406 | |||
407 | /** | ||
408 | * Buffer where we copy to. | ||
409 | */ | ||
410 | char *buf; | ||
411 | |||
412 | /** | ||
413 | * Number of bytes allocated in @e buf | ||
414 | */ | ||
415 | size_t max; | ||
416 | |||
417 | /** | ||
418 | * Current (write) offset in @e buf. | ||
419 | */ | ||
420 | size_t ret; | ||
421 | |||
422 | /** | ||
423 | * Should we copy addresses with an identical value | ||
424 | * and expiration time in @e other, or do we only | ||
425 | * copy addresses with strictly later expiration times? | ||
426 | */ | ||
427 | int take_equal; | ||
428 | }; | ||
429 | |||
430 | |||
431 | /** | ||
432 | * Append the address @a address to the buffer from | ||
433 | * the merge context IF it is more recent than equivalent | ||
434 | * addresses in `other`. | ||
435 | * | ||
436 | * @param cls the `struct MergeContext` | ||
437 | * @param address the HELLO address we might copy | ||
438 | * @param expiration expiration time for @a address | ||
439 | * @return always #GNUNET_OK | ||
440 | */ | ||
441 | static int | ||
442 | copy_latest (void *cls, | ||
443 | const struct GNUNET_HELLO_Address *address, | ||
444 | struct GNUNET_TIME_Absolute expiration) | ||
445 | { | ||
446 | struct MergeContext *mc = cls; | ||
447 | struct ExpireContext ec; | ||
448 | |||
449 | ec.address = address; | ||
450 | ec.found = GNUNET_NO; | ||
451 | /* check if address exists in other */ | ||
452 | GNUNET_HELLO_iterate_addresses (mc->other, | ||
453 | GNUNET_NO, | ||
454 | &get_match_exp, | ||
455 | &ec); | ||
456 | if ((GNUNET_NO == ec.found) || | ||
457 | (ec.expiration.abs_value_us < expiration.abs_value_us) || | ||
458 | ((ec.expiration.abs_value_us == expiration.abs_value_us) && | ||
459 | (GNUNET_YES == mc->take_equal))) | ||
460 | { | ||
461 | /* copy address to buffer */ | ||
462 | mc->ret += | ||
463 | GNUNET_HELLO_add_address (address, | ||
464 | expiration, | ||
465 | &mc->buf[mc->ret], | ||
466 | mc->max - mc->ret); | ||
467 | } | ||
468 | return GNUNET_OK; | ||
469 | } | ||
470 | |||
471 | |||
472 | /** | ||
473 | * Function called to build the HELLO during | ||
474 | * #GNUNET_HELLO_merge() by merging addresses from | ||
475 | * two original HELLOs. | ||
476 | * | ||
477 | * @param cls the `struct MergeContext` | ||
478 | * @param max number of bytes we can write at most in @a buf | ||
479 | * @param buf where to copy the addresses | ||
480 | * @return #GNUNET_SYSERR to end iteration, otherwise number of bytes written to @a buf | ||
481 | */ | ||
482 | static ssize_t | ||
483 | merge_addr (void *cls, | ||
484 | size_t max, | ||
485 | void *buf) | ||
486 | { | ||
487 | struct MergeContext *mc = cls; | ||
488 | |||
489 | if (NULL == mc->h1) | ||
490 | return GNUNET_SYSERR; /* Stop iteration */ | ||
491 | mc->ret = 0; | ||
492 | mc->max = max; | ||
493 | mc->buf = buf; | ||
494 | mc->take_equal = GNUNET_NO; | ||
495 | mc->other = mc->h2; | ||
496 | /* copy addresses from h1, if strictly larger expiration than h2 */ | ||
497 | GNUNET_HELLO_iterate_addresses (mc->h1, | ||
498 | GNUNET_NO, | ||
499 | ©_latest, | ||
500 | mc); | ||
501 | mc->take_equal = GNUNET_YES; | ||
502 | mc->other = mc->h1; | ||
503 | /* copy addresses from h2, if larger or equal expiration than h1 */ | ||
504 | GNUNET_HELLO_iterate_addresses (mc->h2, | ||
505 | GNUNET_NO, | ||
506 | ©_latest, | ||
507 | mc); | ||
508 | /* set marker to stop iteration */ | ||
509 | mc->h1 = NULL; | ||
510 | return mc->ret; | ||
511 | } | ||
512 | |||
513 | |||
514 | struct GNUNET_HELLO_Message * | ||
515 | GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1, | ||
516 | const struct GNUNET_HELLO_Message *h2) | ||
517 | { | ||
518 | struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 }; | ||
519 | int friend_only; | ||
520 | |||
521 | if (h1->friend_only != h2->friend_only) | ||
522 | friend_only = GNUNET_YES; /* One of the HELLOs is friend only */ | ||
523 | else | ||
524 | friend_only = ntohl (h1->friend_only); /* Both HELLO's have the same type */ | ||
525 | |||
526 | return GNUNET_HELLO_create (&h1->publicKey, | ||
527 | &merge_addr, | ||
528 | &mc, | ||
529 | friend_only); | ||
530 | } | ||
531 | |||
532 | |||
533 | /** | ||
534 | * Context used in #GNUNET_HELLO_iterate_new_addresses() to | ||
535 | * figure out which addresses are in fact 'new'. | ||
536 | */ | ||
537 | struct DeltaContext | ||
538 | { | ||
539 | /** | ||
540 | * We should ignore addresses that expire before this time. | ||
541 | */ | ||
542 | struct GNUNET_TIME_Absolute expiration_limit; | ||
543 | |||
544 | /** | ||
545 | * Function to call on addresses that are indeed new. | ||
546 | */ | ||
547 | GNUNET_HELLO_AddressIterator it; | ||
548 | |||
549 | /** | ||
550 | * Closure for @e it. | ||
551 | */ | ||
552 | void *it_cls; | ||
553 | |||
554 | /** | ||
555 | * HELLO with known addresses, addresses in this HELLO | ||
556 | * we must always ignore. | ||
557 | */ | ||
558 | const struct GNUNET_HELLO_Message *old_hello; | ||
559 | }; | ||
560 | |||
561 | |||
562 | /** | ||
563 | * Check if the given address is 'new', and if so, call | ||
564 | * the iterator. Compares the existing address against | ||
565 | * addresses in the context's `old_hello` and calls the | ||
566 | * iterator on those that are new (and not expired). | ||
567 | * | ||
568 | * @param cls the `struct DeltaContext` | ||
569 | * @param address an address to check whether it is new | ||
570 | * @param expiration expiration time for @a address | ||
571 | * @return #GNUNET_YES if the address is ignored, otherwise | ||
572 | * whatever the iterator returned. | ||
573 | */ | ||
574 | static int | ||
575 | delta_match (void *cls, | ||
576 | const struct GNUNET_HELLO_Address *address, | ||
577 | struct GNUNET_TIME_Absolute expiration) | ||
578 | { | ||
579 | struct DeltaContext *dc = cls; | ||
580 | int ret; | ||
581 | struct ExpireContext ec; | ||
582 | |||
583 | ec.address = address; | ||
584 | ec.found = GNUNET_NO; | ||
585 | GNUNET_HELLO_iterate_addresses (dc->old_hello, | ||
586 | GNUNET_NO, | ||
587 | &get_match_exp, | ||
588 | &ec); | ||
589 | if ((GNUNET_YES == ec.found) && | ||
590 | ((ec.expiration.abs_value_us > expiration.abs_value_us) || | ||
591 | (ec.expiration.abs_value_us >= dc->expiration_limit.abs_value_us))) | ||
592 | return GNUNET_YES; /* skip: found and boring */ | ||
593 | ret = dc->it (dc->it_cls, | ||
594 | address, | ||
595 | expiration); | ||
596 | return ret; | ||
597 | } | ||
598 | |||
599 | |||
600 | void | ||
601 | GNUNET_HELLO_iterate_new_addresses (const struct | ||
602 | GNUNET_HELLO_Message *new_hello, | ||
603 | const struct | ||
604 | GNUNET_HELLO_Message *old_hello, | ||
605 | struct GNUNET_TIME_Absolute | ||
606 | expiration_limit, | ||
607 | GNUNET_HELLO_AddressIterator it, | ||
608 | void *it_cls) | ||
609 | { | ||
610 | struct DeltaContext dc; | ||
611 | |||
612 | dc.expiration_limit = expiration_limit; | ||
613 | dc.it = it; | ||
614 | dc.it_cls = it_cls; | ||
615 | dc.old_hello = old_hello; | ||
616 | GNUNET_assert (NULL == | ||
617 | GNUNET_HELLO_iterate_addresses (new_hello, | ||
618 | GNUNET_NO, | ||
619 | &delta_match, | ||
620 | &dc)); | ||
621 | } | ||
622 | |||
623 | |||
624 | /** | ||
625 | * Return the size of the given HELLO message. | ||
626 | * @param hello to inspect | ||
627 | * @return the size, 0 if HELLO is invalid | ||
628 | */ | ||
629 | uint16_t | ||
630 | GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello) | ||
631 | { | ||
632 | uint16_t ret = ntohs (hello->header.size); | ||
633 | |||
634 | if ((ret < sizeof(struct GNUNET_HELLO_Message)) || | ||
635 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | ||
636 | return 0; | ||
637 | return ret; | ||
638 | } | ||
639 | |||
640 | |||
641 | /** | ||
642 | * Get the peer identity from a HELLO message. | ||
643 | * | ||
644 | * @param hello the hello message | ||
645 | * @param peer where to store the peer's identity | ||
646 | * @return #GNUNET_SYSERR if the HELLO was malformed | ||
647 | */ | ||
648 | int | ||
649 | GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello, | ||
650 | struct GNUNET_PeerIdentity *peer) | ||
651 | { | ||
652 | uint16_t ret = ntohs (hello->header.size); | ||
653 | |||
654 | if ((ret < sizeof(struct GNUNET_HELLO_Message)) || | ||
655 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | ||
656 | return GNUNET_SYSERR; | ||
657 | peer->public_key = hello->publicKey; | ||
658 | return GNUNET_OK; | ||
659 | } | ||
660 | |||
661 | |||
662 | /** | ||
663 | * Get the header from a HELLO message, used so other code | ||
664 | * can correctly send HELLO messages. | ||
665 | * | ||
666 | * @param hello the hello message | ||
667 | * | ||
668 | * @return header or NULL if the HELLO was malformed | ||
669 | */ | ||
670 | struct GNUNET_MessageHeader * | ||
671 | GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello) | ||
672 | { | ||
673 | uint16_t ret = ntohs (hello->header.size); | ||
674 | |||
675 | if ((ret < sizeof(struct GNUNET_HELLO_Message)) || | ||
676 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | ||
677 | return NULL; | ||
678 | |||
679 | return &hello->header; | ||
680 | } | ||
681 | |||
682 | |||
683 | /** | ||
684 | * Context used for comparing HELLOs in #GNUNET_HELLO_equals(). | ||
685 | */ | ||
686 | struct EqualsContext | ||
687 | { | ||
688 | /** | ||
689 | * Addresses that expired before this date are ignored for | ||
690 | * the comparison. | ||
691 | */ | ||
692 | struct GNUNET_TIME_Absolute expiration_limit; | ||
693 | |||
694 | /** | ||
695 | * Earliest expiration time for which we found a match | ||
696 | * with a difference in expiration times. | ||
697 | * At this time, the two HELLOs may start to diverge. | ||
698 | */ | ||
699 | struct GNUNET_TIME_Absolute result; | ||
700 | |||
701 | /** | ||
702 | * HELLO message to compare against. (First set to the second | ||
703 | * HELLO, then set to the first HELLO.) | ||
704 | */ | ||
705 | const struct GNUNET_HELLO_Message *ref; | ||
706 | |||
707 | /** | ||
708 | * Address we are currently looking for. | ||
709 | */ | ||
710 | const struct GNUNET_HELLO_Address *address; | ||
711 | |||
712 | /** | ||
713 | * Expiration time of @e address. | ||
714 | */ | ||
715 | struct GNUNET_TIME_Absolute expiration; | ||
716 | |||
717 | /** | ||
718 | * Did we find the address we were looking for? | ||
719 | */ | ||
720 | int found; | ||
721 | }; | ||
722 | |||
723 | |||
724 | /** | ||
725 | * Check if the given address matches the address we are currently | ||
726 | * looking for. If so, sets `found` to #GNUNET_YES and, if the | ||
727 | * expiration times for the two addresses differ, updates `result` to | ||
728 | * the minimum of our @a expiration and the existing value | ||
729 | * | ||
730 | * @param cls the `struct EqualsContext` | ||
731 | * @param address address from the reference HELLO | ||
732 | * @param expiration expiration time for @a address | ||
733 | * @return #GNUNET_YES if the address is expired or does not match | ||
734 | * #GNUNET_SYSERR if the address does match. | ||
735 | */ | ||
736 | static int | ||
737 | find_other_matching (void *cls, | ||
738 | const struct GNUNET_HELLO_Address *address, | ||
739 | struct GNUNET_TIME_Absolute expiration) | ||
740 | { | ||
741 | struct EqualsContext *ec = cls; | ||
742 | |||
743 | if (expiration.abs_value_us < ec->expiration_limit.abs_value_us) | ||
744 | return GNUNET_YES; | ||
745 | if (0 == GNUNET_HELLO_address_cmp (address, ec->address)) | ||
746 | { | ||
747 | ec->found = GNUNET_YES; | ||
748 | if (expiration.abs_value_us < ec->expiration.abs_value_us) | ||
749 | ec->result = GNUNET_TIME_absolute_min (expiration, | ||
750 | ec->result); | ||
751 | return GNUNET_SYSERR; | ||
752 | } | ||
753 | return GNUNET_YES; | ||
754 | } | ||
755 | |||
756 | |||
757 | /** | ||
758 | * Helper function for #GNUNET_HELLO_equals(). Checks | ||
759 | * if the given @a address exists also in the other HELLO; | ||
760 | * if not, the result time is set to zero and the iteration | ||
761 | * is aborted. | ||
762 | * | ||
763 | * @param cls the `struct EqualsContext` | ||
764 | * @param address address to locate | ||
765 | * @param expiration expiration time of the current address | ||
766 | * @return #GNUNET_OK if the address exists or is expired, | ||
767 | * #GNUNET_SYSERR if it was not found | ||
768 | */ | ||
769 | static int | ||
770 | find_matching (void *cls, | ||
771 | const struct GNUNET_HELLO_Address *address, | ||
772 | struct GNUNET_TIME_Absolute expiration) | ||
773 | { | ||
774 | struct EqualsContext *ec = cls; | ||
775 | |||
776 | if (expiration.abs_value_us < ec->expiration_limit.abs_value_us) | ||
777 | return GNUNET_OK; /* expired, we don't care */ | ||
778 | ec->address = address; | ||
779 | ec->expiration = expiration; | ||
780 | ec->found = GNUNET_NO; | ||
781 | GNUNET_HELLO_iterate_addresses (ec->ref, | ||
782 | GNUNET_NO, | ||
783 | &find_other_matching, | ||
784 | ec); | ||
785 | if (GNUNET_NO == ec->found) | ||
786 | { | ||
787 | /* not found, we differ *now* */ | ||
788 | ec->result = GNUNET_TIME_UNIT_ZERO_ABS; | ||
789 | return GNUNET_SYSERR; | ||
790 | } | ||
791 | return GNUNET_OK; | ||
792 | } | ||
793 | |||
794 | |||
795 | /** | ||
796 | * Test if two HELLO messages contain the same addresses. | ||
797 | * If they only differ in expiration time, the lowest | ||
798 | * expiration time larger than @a now where they differ | ||
799 | * is returned. | ||
800 | * | ||
801 | * @param h1 first HELLO message | ||
802 | * @param h2 the second HELLO message | ||
803 | * @param now time to use for deciding which addresses have | ||
804 | * expired and should not be considered at all | ||
805 | * @return absolute time forever if the two HELLOs are | ||
806 | * totally identical; smallest timestamp >= @a now if | ||
807 | * they only differ in timestamps; | ||
808 | * zero if the some addresses with expirations >= @a now | ||
809 | * do not match at all | ||
810 | */ | ||
811 | struct GNUNET_TIME_Absolute | ||
812 | GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1, | ||
813 | const struct GNUNET_HELLO_Message *h2, | ||
814 | struct GNUNET_TIME_Absolute now) | ||
815 | { | ||
816 | struct EqualsContext ec; | ||
817 | |||
818 | if (h1->header.type != h2->header.type) | ||
819 | return GNUNET_TIME_UNIT_ZERO_ABS; | ||
820 | if (0 != | ||
821 | GNUNET_memcmp (&h1->publicKey, | ||
822 | &h2->publicKey)) | ||
823 | return GNUNET_TIME_UNIT_ZERO_ABS; | ||
824 | ec.expiration_limit = now; | ||
825 | ec.result = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
826 | ec.ref = h2; | ||
827 | GNUNET_HELLO_iterate_addresses (h1, | ||
828 | GNUNET_NO, | ||
829 | &find_matching, | ||
830 | &ec); | ||
831 | if (ec.result.abs_value_us == GNUNET_TIME_UNIT_ZERO.rel_value_us) | ||
832 | return ec.result; | ||
833 | ec.ref = h1; | ||
834 | GNUNET_HELLO_iterate_addresses (h2, | ||
835 | GNUNET_NO, | ||
836 | &find_matching, | ||
837 | &ec); | ||
838 | return ec.result; | ||
839 | } | ||
840 | |||
841 | |||
842 | /** | ||
843 | * Iterator to find the time when the last address will expire. | ||
844 | * Updates the maximum value stored in @a cls. | ||
845 | * | ||
846 | * @param cls where to store the max, a `struct GNUNET_TIME_Absolute` | ||
847 | * @param address an address (ignored) | ||
848 | * @param expiration expiration time for @a address | ||
849 | * @return #GNUNET_OK (always) | ||
850 | */ | ||
851 | static int | ||
852 | find_max_expire (void *cls, | ||
853 | const struct GNUNET_HELLO_Address *address, | ||
854 | struct GNUNET_TIME_Absolute expiration) | ||
855 | { | ||
856 | struct GNUNET_TIME_Absolute *max = cls; | ||
857 | |||
858 | *max = GNUNET_TIME_absolute_max (*max, expiration); | ||
859 | return GNUNET_OK; | ||
860 | } | ||
861 | |||
862 | |||
863 | /** | ||
864 | * When does the last address in the given HELLO expire? | ||
865 | * | ||
866 | * @param msg HELLO to inspect | ||
867 | * @return time the last address expires, 0 if there are no addresses in the HELLO | ||
868 | */ | ||
869 | struct GNUNET_TIME_Absolute | ||
870 | GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg) | ||
871 | { | ||
872 | struct GNUNET_TIME_Absolute ret; | ||
873 | |||
874 | ret = GNUNET_TIME_UNIT_ZERO_ABS; | ||
875 | GNUNET_HELLO_iterate_addresses (msg, | ||
876 | GNUNET_NO, | ||
877 | &find_max_expire, | ||
878 | &ret); | ||
879 | return ret; | ||
880 | } | ||
881 | |||
882 | |||
883 | /** | ||
884 | * GNUnet URIs are of the general form "gnunet://MODULE/IDENTIFIER". | ||
885 | * The specific structure of "IDENTIFIER" depends on the module and | ||
886 | * maybe differentiated into additional subcategories if applicable. | ||
887 | * This module only deals with hello identifiers (MODULE = "hello"). | ||
888 | * <p> | ||
889 | * | ||
890 | * The concrete URI format is: | ||
891 | * | ||
892 | * "gnunet://hello/PEER[+YYYYMMDDHHMMSS+<TYPE>+<ADDRESS>]...". | ||
893 | * These URIs can be used to add a peer record to peerinfo service. | ||
894 | * PEER is the string representation of peer's public key. | ||
895 | * YYYYMMDDHHMMSS is the expiration date. | ||
896 | * TYPE is a transport type. | ||
897 | * ADDRESS is the address, its format depends upon the transport type. | ||
898 | * The concrete transport types and corresponding address formats are: | ||
899 | * | ||
900 | * <ul><li> | ||
901 | * | ||
902 | * <TCP|UDP>!IPADDRESS | ||
903 | * IPVDDRESS is either IPV4 .-delimited address in form of XXX.XXX.XXX.XXX:PPPPP | ||
904 | * or IPV6 :-delimited address with '[' and ']' (according to RFC2732): | ||
905 | * [XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX]:PPPPP | ||
906 | * PPPPP is the port number. May be 0. | ||
907 | * | ||
908 | * </li><li> | ||
909 | * | ||
910 | * [add SMTP, HTTP and other addresses here] | ||
911 | * | ||
912 | * </li></ul> | ||
913 | * | ||
914 | * The encoding for hexadecimal values is defined in the crypto_hash.c | ||
915 | * module in the gnunetutil library and discussed there. | ||
916 | * | ||
917 | * Examples: | ||
918 | * | ||
919 | * gnunet://hello/V8XXK9GAN5ZJFRFQP8MQX3D83BZTSBQVHKWWD0JPE63Z821906EG+20120302010059+TCP+192.168.0.1:2086+TCP+64.23.8.174:0 | ||
920 | * gnunet://hello/V8XXK9GAN5ZJFRFQP8MQX3D83BZTSBQVHKWWD0JPE63Z821906EG+20120302010059+TCP+[2001:db8:85a3:8d3:1319:8a2e:370:7348]:2086 | ||
921 | * | ||
922 | * <p> | ||
923 | */ | ||
924 | |||
925 | |||
926 | /** | ||
927 | * Function that is called on each address of this peer. | ||
928 | * Expands the corresponding URI string. | ||
929 | * | ||
930 | * @param cls the `struct GNUNET_HELLO_ComposeUriContext` | ||
931 | * @param address address to add | ||
932 | * @param expiration expiration time for the address | ||
933 | * @return #GNUNET_OK (continue iteration). | ||
934 | */ | ||
935 | static int | ||
936 | add_address_to_uri (void *cls, | ||
937 | const struct GNUNET_HELLO_Address *address, | ||
938 | struct GNUNET_TIME_Absolute expiration) | ||
939 | { | ||
940 | struct GNUNET_HELLO_ComposeUriContext *ctx = cls; | ||
941 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | ||
942 | const char *addr; | ||
943 | char *ret; | ||
944 | char *addr_dup; | ||
945 | char *pos; | ||
946 | char tbuf[16] = ""; | ||
947 | char *client_str = "_client"; | ||
948 | struct tm *t; | ||
949 | time_t seconds; | ||
950 | |||
951 | papi = ctx->plugins_find (address->transport_name); | ||
952 | if (NULL == papi) | ||
953 | { | ||
954 | /* Not an error - we might just not have the right plugin. */ | ||
955 | return GNUNET_OK; | ||
956 | } | ||
957 | if (NULL == papi->address_to_string) | ||
958 | { | ||
959 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
960 | "URI conversion not implemented for plugin `%s'\n", | ||
961 | address->transport_name); | ||
962 | return GNUNET_OK; | ||
963 | } | ||
964 | addr = papi->address_to_string (papi->cls, | ||
965 | address->address, | ||
966 | address->address_length); | ||
967 | if ((NULL == addr) || | ||
968 | (0 == strlen (addr))) | ||
969 | return GNUNET_OK; | ||
970 | |||
971 | addr_dup = GNUNET_strdup (addr); | ||
972 | if (NULL != (pos = strstr (addr_dup, "_server"))) | ||
973 | GNUNET_memcpy (pos, | ||
974 | client_str, | ||
975 | strlen (client_str)); /* Replace all server addresses with client addresses */ | ||
976 | |||
977 | seconds = expiration.abs_value_us / 1000LL / 1000LL; | ||
978 | t = gmtime (&seconds); | ||
979 | |||
980 | GNUNET_asprintf (&ret, | ||
981 | "%s%c%s%c%s%c%s", | ||
982 | ctx->uri, | ||
983 | GNUNET_HELLO_URI_SEP, | ||
984 | strftime (tbuf, | ||
985 | sizeof(tbuf), | ||
986 | "%Y%m%d%H%M%S", | ||
987 | t) ? tbuf : "0", | ||
988 | GNUNET_HELLO_URI_SEP, | ||
989 | address->transport_name, | ||
990 | GNUNET_HELLO_URI_SEP, | ||
991 | addr_dup); | ||
992 | GNUNET_free (addr_dup); | ||
993 | GNUNET_free (ctx->uri); | ||
994 | ctx->uri = ret; | ||
995 | return GNUNET_OK; | ||
996 | } | ||
997 | |||
998 | |||
999 | /** | ||
1000 | * Compose a hello URI string from a hello message. | ||
1001 | * | ||
1002 | * @param hello Hello message | ||
1003 | * @param plugins_find Function to find transport plugins by name | ||
1004 | * @return Hello URI string | ||
1005 | */ | ||
1006 | char * | ||
1007 | GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello, | ||
1008 | GNUNET_HELLO_TransportPluginsFind plugins_find) | ||
1009 | { | ||
1010 | struct GNUNET_HELLO_ComposeUriContext ctx; | ||
1011 | char *pkey; | ||
1012 | |||
1013 | ctx.plugins_find = plugins_find; | ||
1014 | pkey = GNUNET_CRYPTO_eddsa_public_key_to_string (&hello->publicKey); | ||
1015 | GNUNET_asprintf (&ctx.uri, | ||
1016 | "%s%s", | ||
1017 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) | ||
1018 | ? GNUNET_FRIEND_HELLO_URI_PREFIX | ||
1019 | : GNUNET_HELLO_URI_PREFIX, | ||
1020 | pkey); | ||
1021 | GNUNET_free (pkey); | ||
1022 | GNUNET_HELLO_iterate_addresses (hello, | ||
1023 | GNUNET_NO, | ||
1024 | &add_address_to_uri, | ||
1025 | &ctx); | ||
1026 | return ctx.uri; | ||
1027 | } | ||
1028 | |||
1029 | |||
1030 | /* ************************* Parse HELLO URI ********************* */ | ||
1031 | |||
1032 | |||
1033 | /** | ||
1034 | * We're building a HELLO. Parse the next address from the | ||
1035 | * parsing context and append it. | ||
1036 | * | ||
1037 | * @param cls the `struct GNUNET_HELLO_ParseUriContext` | ||
1038 | * @param max number of bytes available for HELLO construction | ||
1039 | * @param buffer where to copy the next address (in binary format) | ||
1040 | * @return number of bytes added to buffer, #GNUNET_SYSERR on error | ||
1041 | */ | ||
1042 | static ssize_t | ||
1043 | add_address_to_hello (void *cls, | ||
1044 | size_t max, | ||
1045 | void *buffer) | ||
1046 | { | ||
1047 | struct GNUNET_HELLO_ParseUriContext *ctx = cls; | ||
1048 | const char *tname; | ||
1049 | const char *address; | ||
1050 | char *uri_address; | ||
1051 | const char *end; | ||
1052 | char *plugin_name; | ||
1053 | struct tm expiration_time; | ||
1054 | time_t expiration_seconds; | ||
1055 | struct GNUNET_TIME_Absolute expire; | ||
1056 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | ||
1057 | void *addr; | ||
1058 | size_t addr_len; | ||
1059 | struct GNUNET_HELLO_Address haddr; | ||
1060 | ssize_t ret; | ||
1061 | |||
1062 | if (NULL == ctx->pos) | ||
1063 | return GNUNET_SYSERR; | ||
1064 | if (GNUNET_HELLO_URI_SEP != ctx->pos[0]) | ||
1065 | { | ||
1066 | ctx->ret = GNUNET_SYSERR; | ||
1067 | GNUNET_break (0); | ||
1068 | return GNUNET_SYSERR; | ||
1069 | } | ||
1070 | ctx->pos++; | ||
1071 | |||
1072 | if (('0' == ctx->pos[0]) && | ||
1073 | (GNUNET_HELLO_URI_SEP == ctx->pos[1])) | ||
1074 | { | ||
1075 | expire = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
1076 | tname = ctx->pos + 1; | ||
1077 | } | ||
1078 | else | ||
1079 | { | ||
1080 | memset (&expiration_time, 0, sizeof(expiration_time)); | ||
1081 | tname = strptime (ctx->pos, | ||
1082 | "%Y%m%d%H%M%S", | ||
1083 | &expiration_time); | ||
1084 | if (NULL == tname) | ||
1085 | { | ||
1086 | ctx->ret = GNUNET_SYSERR; | ||
1087 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1088 | _ ( | ||
1089 | "Failed to parse HELLO message: missing expiration time\n")); | ||
1090 | GNUNET_break (0); | ||
1091 | return GNUNET_SYSERR; | ||
1092 | } | ||
1093 | |||
1094 | expiration_seconds = mktime (&expiration_time); | ||
1095 | if (expiration_seconds == (time_t) -1) | ||
1096 | { | ||
1097 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1098 | _ ( | ||
1099 | "Failed to parse HELLO message: invalid expiration time\n")); | ||
1100 | ctx->ret = GNUNET_SYSERR; | ||
1101 | GNUNET_break (0); | ||
1102 | return GNUNET_SYSERR; | ||
1103 | } | ||
1104 | expire.abs_value_us = expiration_seconds * 1000LL * 1000LL; | ||
1105 | } | ||
1106 | if (GNUNET_HELLO_URI_SEP != tname[0]) | ||
1107 | { | ||
1108 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1109 | _ ("Failed to parse HELLO message: malformed\n")); | ||
1110 | ctx->ret = GNUNET_SYSERR; | ||
1111 | GNUNET_break (0); | ||
1112 | return GNUNET_SYSERR; | ||
1113 | } | ||
1114 | tname++; | ||
1115 | address = strchr (tname, | ||
1116 | (int) GNUNET_HELLO_URI_SEP); | ||
1117 | if (NULL == address) | ||
1118 | { | ||
1119 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1120 | _ ( | ||
1121 | "Failed to parse HELLO message: missing transport plugin\n")); | ||
1122 | ctx->ret = GNUNET_SYSERR; | ||
1123 | GNUNET_break (0); | ||
1124 | return GNUNET_SYSERR; | ||
1125 | } | ||
1126 | address++; | ||
1127 | end = strchr (address, (int) GNUNET_HELLO_URI_SEP); | ||
1128 | ctx->pos = end; | ||
1129 | ctx->counter_total++; | ||
1130 | plugin_name = GNUNET_strndup (tname, address - (tname + 1)); | ||
1131 | papi = ctx->plugins_find (plugin_name); | ||
1132 | if (NULL == papi) | ||
1133 | { | ||
1134 | /* Not an error - we might just not have the right plugin. | ||
1135 | * Skip this part, advance to the next one and recurse. | ||
1136 | * But only if this is not the end of string. | ||
1137 | */ | ||
1138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1139 | _ ("Plugin `%s' not found, skipping address\n"), | ||
1140 | plugin_name); | ||
1141 | GNUNET_free (plugin_name); | ||
1142 | return 0; | ||
1143 | } | ||
1144 | if (NULL == papi->string_to_address) | ||
1145 | { | ||
1146 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1147 | _ ("Plugin `%s' does not support URIs yet\n"), | ||
1148 | plugin_name); | ||
1149 | GNUNET_free (plugin_name); | ||
1150 | GNUNET_break (0); | ||
1151 | return 0; | ||
1152 | } | ||
1153 | uri_address = GNUNET_strndup (address, end - address); | ||
1154 | if (GNUNET_OK != | ||
1155 | papi->string_to_address (papi->cls, | ||
1156 | uri_address, | ||
1157 | strlen (uri_address) + 1, | ||
1158 | &addr, | ||
1159 | &addr_len)) | ||
1160 | { | ||
1161 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1162 | _ ("Failed to parse `%s' as an address for plugin `%s'\n"), | ||
1163 | uri_address, | ||
1164 | plugin_name); | ||
1165 | GNUNET_free (plugin_name); | ||
1166 | GNUNET_free (uri_address); | ||
1167 | return 0; | ||
1168 | } | ||
1169 | GNUNET_free (uri_address); | ||
1170 | /* address.peer is unset - not used by add_address() */ | ||
1171 | haddr.address_length = addr_len; | ||
1172 | haddr.address = addr; | ||
1173 | haddr.transport_name = plugin_name; | ||
1174 | ret = GNUNET_HELLO_add_address (&haddr, | ||
1175 | expire, | ||
1176 | buffer, | ||
1177 | max); | ||
1178 | ctx->counter_added++; | ||
1179 | GNUNET_free (addr); | ||
1180 | GNUNET_free (plugin_name); | ||
1181 | return ret; | ||
1182 | } | ||
1183 | |||
1184 | |||
1185 | /** | ||
1186 | * Parse a hello URI string to a hello message. | ||
1187 | * | ||
1188 | * @param uri URI string to parse | ||
1189 | * @param pubkey Pointer to struct where public key is parsed | ||
1190 | * @param hello Pointer to struct where hello message is parsed | ||
1191 | * @param plugins_find Function to find transport plugins by name | ||
1192 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the URI was invalid, #GNUNET_NO on other errors | ||
1193 | */ | ||
1194 | int | ||
1195 | GNUNET_HELLO_parse_uri (const char *uri, | ||
1196 | struct GNUNET_CRYPTO_EddsaPublicKey *pubkey, | ||
1197 | struct GNUNET_HELLO_Message **hello, | ||
1198 | GNUNET_HELLO_TransportPluginsFind plugins_find) | ||
1199 | { | ||
1200 | const char *pks; | ||
1201 | const char *exc; | ||
1202 | int friend_only; | ||
1203 | struct GNUNET_HELLO_ParseUriContext ctx; | ||
1204 | |||
1205 | if (0 == strncmp (uri, | ||
1206 | GNUNET_HELLO_URI_PREFIX, | ||
1207 | strlen (GNUNET_HELLO_URI_PREFIX))) | ||
1208 | { | ||
1209 | pks = &uri[strlen (GNUNET_HELLO_URI_PREFIX)]; | ||
1210 | friend_only = GNUNET_NO; | ||
1211 | } | ||
1212 | else if (0 == strncmp (uri, | ||
1213 | GNUNET_FRIEND_HELLO_URI_PREFIX, | ||
1214 | strlen (GNUNET_FRIEND_HELLO_URI_PREFIX))) | ||
1215 | { | ||
1216 | pks = &uri[strlen (GNUNET_FRIEND_HELLO_URI_PREFIX)]; | ||
1217 | friend_only = GNUNET_YES; | ||
1218 | } | ||
1219 | else | ||
1220 | return GNUNET_SYSERR; | ||
1221 | exc = strchr (pks, GNUNET_HELLO_URI_SEP); | ||
1222 | |||
1223 | if (GNUNET_OK != | ||
1224 | GNUNET_STRINGS_string_to_data (pks, | ||
1225 | (NULL == exc) ? strlen (pks) : (exc - pks), | ||
1226 | (unsigned char *) pubkey, | ||
1227 | sizeof(*pubkey))) | ||
1228 | return GNUNET_SYSERR; | ||
1229 | |||
1230 | ctx.pos = exc; | ||
1231 | ctx.ret = GNUNET_OK; | ||
1232 | ctx.counter_total = 0; | ||
1233 | ctx.counter_added = 0; | ||
1234 | ctx.plugins_find = plugins_find; | ||
1235 | *hello = GNUNET_HELLO_create (pubkey, | ||
1236 | &add_address_to_hello, | ||
1237 | &ctx, | ||
1238 | friend_only); | ||
1239 | |||
1240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1241 | "HELLO URI contained %u addresses, added %u addresses\n", | ||
1242 | ctx.counter_total, | ||
1243 | ctx.counter_added); | ||
1244 | |||
1245 | return ctx.ret; | ||
1246 | } | ||
1247 | |||
1248 | |||
1249 | /* end of hello.c */ | ||
diff --git a/src/lib/hello/test_friend_hello.c b/src/lib/hello/test_friend_hello.c deleted file mode 100644 index 1b092c0b8..000000000 --- a/src/lib/hello/test_friend_hello.c +++ /dev/null | |||
@@ -1,185 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file hello/test_friend_hello.c | ||
22 | * @brief test for hello.c | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_hello_lib.h" | ||
27 | |||
28 | |||
29 | static ssize_t | ||
30 | my_addr_gen (void *cls, | ||
31 | size_t max, | ||
32 | void *buf) | ||
33 | { | ||
34 | unsigned int *i = cls; | ||
35 | size_t ret; | ||
36 | struct GNUNET_HELLO_Address address; | ||
37 | |||
38 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
39 | "DEBUG: my_addr_gen called with i = %d\n", *i); | ||
40 | if (0 == *i) | ||
41 | return GNUNET_SYSERR; /* Stop iteration */ | ||
42 | memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); | ||
43 | address.address = "address_information"; | ||
44 | address.transport_name = "test"; | ||
45 | address.address_length = *i; | ||
46 | ret = | ||
47 | GNUNET_HELLO_add_address (&address, GNUNET_TIME_absolute_get (), buf, | ||
48 | max); | ||
49 | (*i)--; | ||
50 | return ret; | ||
51 | } | ||
52 | |||
53 | |||
54 | static int | ||
55 | check_addr (void *cls, | ||
56 | const struct GNUNET_HELLO_Address *address, | ||
57 | struct GNUNET_TIME_Absolute expiration) | ||
58 | { | ||
59 | unsigned int *i = cls; | ||
60 | |||
61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
62 | "DEBUG: check_addr called with i = %d and addrlen = %u\n", | ||
63 | *i, (unsigned int) address->address_length); | ||
64 | GNUNET_assert (address->address_length > 0); | ||
65 | GNUNET_assert (*i & (1 << (address->address_length - 1))); | ||
66 | *i -= (1 << (address->address_length - 1)); | ||
67 | GNUNET_assert (0 == | ||
68 | strncmp ("address_information", address->address, | ||
69 | address->address_length)); | ||
70 | GNUNET_assert (0 == strcmp ("test", address->transport_name)); | ||
71 | return GNUNET_OK; | ||
72 | } | ||
73 | |||
74 | |||
75 | static int | ||
76 | remove_some (void *cls, | ||
77 | const struct GNUNET_HELLO_Address *address, | ||
78 | struct GNUNET_TIME_Absolute expiration) | ||
79 | { | ||
80 | unsigned int *i = cls; | ||
81 | |||
82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
83 | "DEBUG: remove_some called with i = %d and addrlen = %u\n", | ||
84 | *i, (unsigned int) address->address_length); | ||
85 | GNUNET_assert (address->address_length > 0); | ||
86 | if (*i & (1 << (address->address_length - 1))) | ||
87 | { | ||
88 | *i -= (1 << (address->address_length - 1)); | ||
89 | return GNUNET_NO; | ||
90 | } | ||
91 | return GNUNET_OK; | ||
92 | } | ||
93 | |||
94 | |||
95 | int | ||
96 | main (int argc, char *argv[]) | ||
97 | { | ||
98 | struct GNUNET_HELLO_Message *msg1; | ||
99 | struct GNUNET_HELLO_Message *msg2; | ||
100 | struct GNUNET_HELLO_Message *msg3; | ||
101 | struct GNUNET_CRYPTO_EddsaPublicKey publicKey; | ||
102 | struct GNUNET_TIME_Absolute startup_time; | ||
103 | unsigned int i; | ||
104 | |||
105 | GNUNET_log_setup ("test-hello", "DEBUG", NULL); | ||
106 | startup_time = GNUNET_TIME_absolute_get (); | ||
107 | memset (&publicKey, 42, sizeof(publicKey)); | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
109 | "Testing HELLO creation (without addresses)...\n"); | ||
110 | i = 0; | ||
111 | msg1 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES); | ||
112 | GNUNET_assert (msg1 != NULL); | ||
113 | GNUNET_assert (0 < GNUNET_HELLO_size (msg1)); | ||
114 | |||
115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
116 | "Testing address iteration (empty set)...\n"); | ||
117 | GNUNET_assert (NULL == | ||
118 | GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr, | ||
119 | &i)); | ||
120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
121 | "Testing HELLO creation (with one address)...\n"); | ||
122 | i = 1; | ||
123 | msg2 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES); | ||
124 | GNUNET_assert (msg2 != NULL); | ||
125 | GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2)); | ||
126 | |||
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
128 | "Testing address iteration (one address)...\n"); | ||
129 | i = 1; | ||
130 | GNUNET_assert (NULL == | ||
131 | GNUNET_HELLO_iterate_addresses (msg2, GNUNET_NO, &check_addr, | ||
132 | &i)); | ||
133 | GNUNET_assert (i == 0); | ||
134 | GNUNET_free (msg1); | ||
135 | |||
136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
137 | "Testing HELLO creation (with two addresses)...\n"); | ||
138 | i = 2; | ||
139 | msg3 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES); | ||
140 | GNUNET_assert (msg3 != NULL); | ||
141 | GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3)); | ||
142 | |||
143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
144 | "Testing address iteration (two addresses)...\n"); | ||
145 | i = 3; | ||
146 | GNUNET_assert (NULL == | ||
147 | GNUNET_HELLO_iterate_addresses (msg3, GNUNET_NO, &check_addr, | ||
148 | &i)); | ||
149 | GNUNET_assert (i == 0); | ||
150 | |||
151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
152 | "Testing HELLO merge...\n"); | ||
153 | msg1 = GNUNET_HELLO_merge (msg2, msg3); | ||
154 | GNUNET_assert (GNUNET_HELLO_size (msg1) == GNUNET_HELLO_size (msg3)); | ||
155 | |||
156 | i = 3; | ||
157 | GNUNET_assert (NULL == | ||
158 | GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr, | ||
159 | &i)); | ||
160 | GNUNET_assert (i == 0); | ||
161 | GNUNET_free (msg1); | ||
162 | |||
163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
164 | "Testing address iteration to copy HELLO...\n"); | ||
165 | i = 2; | ||
166 | msg1 = GNUNET_HELLO_iterate_addresses (msg3, GNUNET_YES, &remove_some, &i); | ||
167 | GNUNET_assert (msg1 != NULL); | ||
168 | GNUNET_assert (i == 0); | ||
169 | i = 1; | ||
170 | GNUNET_assert (NULL == | ||
171 | GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr, | ||
172 | &i)); | ||
173 | GNUNET_assert (i == 0); | ||
174 | GNUNET_free (msg1); | ||
175 | |||
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
177 | "Testing delta address iteration...\n"); | ||
178 | i = 2; | ||
179 | GNUNET_HELLO_iterate_new_addresses (msg3, msg2, startup_time, &check_addr, | ||
180 | &i); | ||
181 | GNUNET_assert (i == 0); | ||
182 | GNUNET_free (msg2); | ||
183 | GNUNET_free (msg3); | ||
184 | return 0; /* testcase passed */ | ||
185 | } | ||
diff --git a/src/lib/hello/test_hello-ng.c b/src/lib/hello/test_hello-ng.c deleted file mode 100644 index ef84e2425..000000000 --- a/src/lib/hello/test_hello-ng.c +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2022 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | #include "platform.h" | ||
21 | #include "gnunet_util_lib.h" | ||
22 | #include "gnunet_nt_lib.h" | ||
23 | #include "gnunet_hello_lib.h" | ||
24 | |||
25 | int | ||
26 | main (int argc, | ||
27 | char *argv[]) | ||
28 | { | ||
29 | struct GNUNET_CRYPTO_EddsaPublicKey pubKey; | ||
30 | struct GNUNET_CRYPTO_EddsaPrivateKey privKey; | ||
31 | struct GNUNET_PeerIdentity pid; | ||
32 | struct GNUNET_TIME_Absolute t = GNUNET_TIME_absolute_get (); | ||
33 | char *res; | ||
34 | char *address; | ||
35 | size_t res_len; | ||
36 | enum GNUNET_NetworkType nt; | ||
37 | |||
38 | GNUNET_CRYPTO_eddsa_key_create (&privKey); | ||
39 | GNUNET_CRYPTO_eddsa_key_get_public (&privKey, | ||
40 | &pubKey); | ||
41 | pid.public_key = pubKey; | ||
42 | GNUNET_HELLO_sign_address ("127.0.0.1:8080", | ||
43 | GNUNET_NT_LAN, | ||
44 | t, | ||
45 | &privKey, | ||
46 | (void**) &res, | ||
47 | &res_len); | ||
48 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | ||
49 | "%s\n", res); | ||
50 | GNUNET_assert (NULL != | ||
51 | (address = | ||
52 | GNUNET_HELLO_extract_address ((void**) res, | ||
53 | res_len, | ||
54 | &pid, | ||
55 | &nt, | ||
56 | &t))); | ||
57 | GNUNET_free (address); | ||
58 | GNUNET_free (res); | ||
59 | return 0; | ||
60 | } | ||
diff --git a/src/lib/hello/test_hello.c b/src/lib/hello/test_hello.c deleted file mode 100644 index 8631d2af3..000000000 --- a/src/lib/hello/test_hello.c +++ /dev/null | |||
@@ -1,253 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2009, 2015 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file hello/test_hello.c | ||
22 | * @brief test for hello.c | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_hello_lib.h" | ||
27 | |||
28 | |||
29 | /** | ||
30 | * | ||
31 | * | ||
32 | * @param cls | ||
33 | * @param max | ||
34 | * @param buf | ||
35 | * @return | ||
36 | */ | ||
37 | static ssize_t | ||
38 | my_addr_gen (void *cls, | ||
39 | size_t max, | ||
40 | void *buf) | ||
41 | { | ||
42 | unsigned int *i = cls; | ||
43 | size_t ret; | ||
44 | struct GNUNET_HELLO_Address address; | ||
45 | |||
46 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
47 | "DEBUG: my_addr_gen called with i = %d\n", | ||
48 | *i); | ||
49 | if (0 == *i) | ||
50 | return GNUNET_SYSERR; | ||
51 | memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); | ||
52 | address.address = "address_information"; | ||
53 | address.transport_name = "test"; | ||
54 | address.address_length = *i; | ||
55 | ret = GNUNET_HELLO_add_address (&address, | ||
56 | GNUNET_TIME_absolute_get (), | ||
57 | buf, | ||
58 | max); | ||
59 | (*i)--; | ||
60 | return ret; | ||
61 | } | ||
62 | |||
63 | |||
64 | /** | ||
65 | * | ||
66 | * | ||
67 | * @param cls | ||
68 | * @param address | ||
69 | * @param expiration | ||
70 | * @return | ||
71 | */ | ||
72 | static int | ||
73 | check_addr (void *cls, | ||
74 | const struct GNUNET_HELLO_Address *address, | ||
75 | struct GNUNET_TIME_Absolute expiration) | ||
76 | { | ||
77 | unsigned int *i = cls; | ||
78 | |||
79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
80 | "DEBUG: check_addr called with i = %d and addrlen = %u\n", | ||
81 | *i, | ||
82 | (unsigned int) address->address_length); | ||
83 | GNUNET_assert (address->address_length > 0); | ||
84 | GNUNET_assert (*i & (1 << (address->address_length - 1))); | ||
85 | *i -= (1 << (address->address_length - 1)); | ||
86 | GNUNET_assert (0 == | ||
87 | strncmp ("address_information", | ||
88 | address->address, | ||
89 | address->address_length)); | ||
90 | GNUNET_assert (0 == strcmp ("test", | ||
91 | address->transport_name)); | ||
92 | return GNUNET_OK; | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * | ||
98 | * | ||
99 | * @param cls | ||
100 | * @param address | ||
101 | * @param expiration | ||
102 | * @return | ||
103 | */ | ||
104 | static int | ||
105 | remove_some (void *cls, | ||
106 | const struct GNUNET_HELLO_Address *address, | ||
107 | struct GNUNET_TIME_Absolute expiration) | ||
108 | { | ||
109 | unsigned int *i = cls; | ||
110 | |||
111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
112 | "DEBUG: remove_some called with i = %d and addrlen = %u\n", | ||
113 | *i, | ||
114 | (unsigned int) address->address_length); | ||
115 | GNUNET_assert (address->address_length > 0); | ||
116 | if (*i & (1 << (address->address_length - 1))) | ||
117 | { | ||
118 | *i -= (1 << (address->address_length - 1)); | ||
119 | return GNUNET_NO; | ||
120 | } | ||
121 | return GNUNET_OK; | ||
122 | } | ||
123 | |||
124 | |||
125 | int | ||
126 | main (int argc, | ||
127 | char *argv[]) | ||
128 | { | ||
129 | struct GNUNET_HELLO_Message *msg1; | ||
130 | struct GNUNET_HELLO_Message *msg2; | ||
131 | struct GNUNET_HELLO_Message *msg3; | ||
132 | struct GNUNET_CRYPTO_EddsaPublicKey publicKey; | ||
133 | struct GNUNET_PeerIdentity pid; | ||
134 | struct GNUNET_TIME_Absolute startup_time; | ||
135 | unsigned int i; | ||
136 | |||
137 | GNUNET_log_setup ("test-hello", | ||
138 | "DEBUG", | ||
139 | NULL); | ||
140 | startup_time = GNUNET_TIME_absolute_get (); | ||
141 | memset (&publicKey, 42, sizeof(publicKey)); | ||
142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
143 | "Testing HELLO creation (without addresses)...\n"); | ||
144 | i = 0; | ||
145 | msg1 = GNUNET_HELLO_create (&publicKey, | ||
146 | &my_addr_gen, | ||
147 | &i, | ||
148 | GNUNET_NO); | ||
149 | GNUNET_assert (msg1 != NULL); | ||
150 | GNUNET_assert (0 < GNUNET_HELLO_size (msg1)); | ||
151 | |||
152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
153 | "Testing address iteration (empty set)...\n"); | ||
154 | GNUNET_assert (NULL == | ||
155 | GNUNET_HELLO_iterate_addresses (msg1, | ||
156 | GNUNET_NO, | ||
157 | &check_addr, | ||
158 | &i)); | ||
159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
160 | "Testing HELLO creation (with one address)...\n"); | ||
161 | i = 1; | ||
162 | msg2 = GNUNET_HELLO_create (&publicKey, | ||
163 | &my_addr_gen, | ||
164 | &i, | ||
165 | GNUNET_NO); | ||
166 | GNUNET_assert (msg2 != NULL); | ||
167 | GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2)); | ||
168 | |||
169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
170 | "Testing address iteration (one address)...\n"); | ||
171 | i = 1; | ||
172 | GNUNET_assert (NULL == | ||
173 | GNUNET_HELLO_iterate_addresses (msg2, | ||
174 | GNUNET_NO, | ||
175 | &check_addr, | ||
176 | &i)); | ||
177 | GNUNET_assert (i == 0); | ||
178 | |||
179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
180 | "Testing get_key from HELLO...\n"); | ||
181 | GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (msg2, &pid)); | ||
182 | GNUNET_assert (0 == GNUNET_memcmp (&publicKey, | ||
183 | &pid.public_key)); | ||
184 | GNUNET_free (msg1); | ||
185 | |||
186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
187 | "Testing HELLO creation (with two addresses)...\n"); | ||
188 | i = 2; | ||
189 | msg3 = GNUNET_HELLO_create (&publicKey, | ||
190 | &my_addr_gen, | ||
191 | &i, | ||
192 | GNUNET_NO); | ||
193 | GNUNET_assert (msg3 != NULL); | ||
194 | GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3)); | ||
195 | |||
196 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
197 | "Testing address iteration (two addresses)...\n"); | ||
198 | i = 3; | ||
199 | GNUNET_assert (NULL == | ||
200 | GNUNET_HELLO_iterate_addresses (msg3, | ||
201 | GNUNET_NO, | ||
202 | &check_addr, | ||
203 | &i)); | ||
204 | GNUNET_assert (i == 0); | ||
205 | |||
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
207 | "Testing HELLO merge...\n"); | ||
208 | msg1 = GNUNET_HELLO_merge (msg2, msg3); | ||
209 | GNUNET_assert (GNUNET_HELLO_size (msg1) == GNUNET_HELLO_size (msg3)); | ||
210 | |||
211 | i = 3; | ||
212 | GNUNET_assert (NULL == | ||
213 | GNUNET_HELLO_iterate_addresses (msg1, | ||
214 | GNUNET_NO, | ||
215 | &check_addr, | ||
216 | &i)); | ||
217 | GNUNET_assert (i == 0); | ||
218 | GNUNET_free (msg1); | ||
219 | |||
220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
221 | "Testing address iteration to copy HELLO...\n"); | ||
222 | i = 2; | ||
223 | msg1 = GNUNET_HELLO_iterate_addresses (msg3, | ||
224 | GNUNET_YES, | ||
225 | &remove_some, | ||
226 | &i); | ||
227 | GNUNET_assert (msg1 != NULL); | ||
228 | GNUNET_assert (i == 0); | ||
229 | i = 1; | ||
230 | GNUNET_assert (NULL == | ||
231 | GNUNET_HELLO_iterate_addresses (msg1, | ||
232 | GNUNET_NO, | ||
233 | &check_addr, | ||
234 | &i)); | ||
235 | GNUNET_assert (i == 0); | ||
236 | GNUNET_free (msg1); | ||
237 | |||
238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
239 | "Testing delta address iteration...\n"); | ||
240 | i = 2; | ||
241 | GNUNET_HELLO_iterate_new_addresses (msg3, | ||
242 | msg2, | ||
243 | startup_time, | ||
244 | &check_addr, | ||
245 | &i); | ||
246 | GNUNET_assert (i == 0); | ||
247 | GNUNET_free (msg2); | ||
248 | GNUNET_free (msg3); | ||
249 | return 0; /* testcase passed */ | ||
250 | } | ||
251 | |||
252 | |||
253 | /* end of test_hello.c */ | ||
diff --git a/src/service/core/core_api_cmd_connecting_peers.c b/src/service/core/core_api_cmd_connecting_peers.c index ce2184a3c..0dde3d61b 100644 --- a/src/service/core/core_api_cmd_connecting_peers.c +++ b/src/service/core/core_api_cmd_connecting_peers.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "gnunet_testing_netjail_lib.h" | 29 | #include "gnunet_testing_netjail_lib.h" |
30 | #include "gnunet_transport_application_service.h" | 30 | #include "gnunet_transport_application_service.h" |
31 | #include "gnunet_hello_lib.h" | ||
32 | #include "gnunet_transport_core_service.h" | 31 | #include "gnunet_transport_core_service.h" |
33 | 32 | ||
34 | /** | 33 | /** |
diff --git a/src/service/dht/dht_api.c b/src/service/dht/dht_api.c index 62a8dd0fd..6a218e29d 100644 --- a/src/service/dht/dht_api.c +++ b/src/service/dht/dht_api.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include "gnunet_constants.h" | 29 | #include "gnunet_constants.h" |
30 | #include "gnunet_signatures.h" | 30 | #include "gnunet_signatures.h" |
31 | #include "gnunet_arm_service.h" | 31 | #include "gnunet_arm_service.h" |
32 | #include "gnunet_hello_lib.h" | ||
33 | #include "gnunet_protocols.h" | 32 | #include "gnunet_protocols.h" |
34 | #include "gnunet_dht_service.h" | 33 | #include "gnunet_dht_service.h" |
35 | #include "dht.h" | 34 | #include "dht.h" |
diff --git a/src/service/dht/test_dht_api.c b/src/service/dht/test_dht_api.c index 044983b7e..0b51477fe 100644 --- a/src/service/dht/test_dht_api.c +++ b/src/service/dht/test_dht_api.c | |||
@@ -26,7 +26,6 @@ | |||
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_hello_lib.h" | ||
30 | #include "gnunet_testing_lib.h" | 29 | #include "gnunet_testing_lib.h" |
31 | #include "gnunet_dht_service.h" | 30 | #include "gnunet_dht_service.h" |
32 | 31 | ||
diff --git a/src/service/transport/gnunet-service-transport.c b/src/service/transport/gnunet-service-transport.c index ec3019161..5825dff14 100644 --- a/src/service/transport/gnunet-service-transport.c +++ b/src/service/transport/gnunet-service-transport.c | |||
@@ -77,7 +77,6 @@ | |||
77 | #include "gnunet_statistics_service.h" | 77 | #include "gnunet_statistics_service.h" |
78 | #include "gnunet_transport_monitor_service.h" | 78 | #include "gnunet_transport_monitor_service.h" |
79 | #include "gnunet_peerstore_service.h" | 79 | #include "gnunet_peerstore_service.h" |
80 | #include "gnunet_hello_lib.h" | ||
81 | #include "gnunet_hello_uri_lib.h" | 80 | #include "gnunet_hello_uri_lib.h" |
82 | #include "gnunet_signatures.h" | 81 | #include "gnunet_signatures.h" |
83 | #include "transport.h" | 82 | #include "transport.h" |
diff --git a/src/service/transport/transport-testing-communicator.c b/src/service/transport/transport-testing-communicator.c index 553426b66..168b29ce5 100644 --- a/src/service/transport/transport-testing-communicator.c +++ b/src/service/transport/transport-testing-communicator.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include "gnunet_protocols.h" | 29 | #include "gnunet_protocols.h" |
30 | #include "gnunet_constants.h" | 30 | #include "gnunet_constants.h" |
31 | #include "transport-testing-communicator.h" | 31 | #include "transport-testing-communicator.h" |
32 | #include "gnunet_hello_lib.h" | ||
33 | #include "gnunet_signatures.h" | 32 | #include "gnunet_signatures.h" |
34 | #include "transport.h" | 33 | #include "transport.h" |
35 | #include <inttypes.h> | 34 | #include <inttypes.h> |
diff --git a/src/service/transport/transport-testing2.c b/src/service/transport/transport-testing2.c index afa0b0ad4..b88a2b7e9 100644 --- a/src/service/transport/transport-testing2.c +++ b/src/service/transport/transport-testing2.c | |||
@@ -247,15 +247,6 @@ notify_connect (void *cls, | |||
247 | } | 247 | } |
248 | 248 | ||
249 | 249 | ||
250 | /** | ||
251 | * Offer the current HELLO of P2 to P1. | ||
252 | * | ||
253 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest` | ||
254 | */ | ||
255 | static void | ||
256 | offer_hello (void *cls); | ||
257 | |||
258 | |||
259 | static void | 250 | static void |
260 | notify_disconnect (void *cls, | 251 | notify_disconnect (void *cls, |
261 | const struct GNUNET_PeerIdentity *peer, | 252 | const struct GNUNET_PeerIdentity *peer, |
@@ -318,9 +309,6 @@ notify_disconnect (void *cls, | |||
318 | { | 309 | { |
319 | cc->connected = GNUNET_NO; | 310 | cc->connected = GNUNET_NO; |
320 | /* start trying to connect */ | 311 | /* start trying to connect */ |
321 | if (NULL == cc->tct) | ||
322 | cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello, | ||
323 | cc); | ||
324 | if (NULL == cc->ah_sh) | 312 | if (NULL == cc->ah_sh) |
325 | cc->ah_sh = GNUNET_TRANSPORT_application_suggest (cc->p1->ah, | 313 | cc->ah_sh = GNUNET_TRANSPORT_application_suggest (cc->p1->ah, |
326 | &p2->id, | 314 | &p2->id, |
@@ -725,45 +713,6 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct | |||
725 | }*/ | 713 | }*/ |
726 | 714 | ||
727 | 715 | ||
728 | static void | ||
729 | offer_hello (void *cls) | ||
730 | { | ||
731 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; | ||
732 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1; | ||
733 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = cc->p2; | ||
734 | struct GNUNET_TIME_Absolute t; | ||
735 | enum GNUNET_NetworkType nt = 0; | ||
736 | char *addr; | ||
737 | |||
738 | cc->tct = NULL; | ||
739 | { | ||
740 | char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id)); | ||
741 | |||
742 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
743 | "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %s\n", | ||
744 | p1->no, | ||
745 | GNUNET_i2s (&p1->id), | ||
746 | p2->no, | ||
747 | p2_s, | ||
748 | p2->hello); | ||
749 | GNUNET_free (p2_s); | ||
750 | } | ||
751 | |||
752 | addr = GNUNET_HELLO_extract_address (p2->hello, | ||
753 | p2->hello_size, | ||
754 | &p2->id, | ||
755 | &nt, | ||
756 | &t); | ||
757 | GNUNET_assert (NULL != addr); | ||
758 | GNUNET_assert (NULL != p1->hello); | ||
759 | GNUNET_TRANSPORT_application_validate (p1->ah, | ||
760 | &p2->id, | ||
761 | nt, | ||
762 | addr); | ||
763 | GNUNET_free (addr); | ||
764 | } | ||
765 | |||
766 | |||
767 | /** | 716 | /** |
768 | * Initiate a connection from p1 to p2 by offering p1 p2's HELLO message | 717 | * Initiate a connection from p1 to p2 by offering p1 p2's HELLO message |
769 | * | 718 | * |
@@ -816,8 +765,6 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct | |||
816 | GNUNET_CONTAINER_DLL_insert (tth->cc_head, | 765 | GNUNET_CONTAINER_DLL_insert (tth->cc_head, |
817 | tth->cc_tail, | 766 | tth->cc_tail, |
818 | cc); | 767 | cc); |
819 | cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello, | ||
820 | cc); | ||
821 | cc->ah_sh = GNUNET_TRANSPORT_application_suggest (cc->p1->ah, | 768 | cc->ah_sh = GNUNET_TRANSPORT_application_suggest (cc->p1->ah, |
822 | &p2->id, | 769 | &p2->id, |
823 | GNUNET_MQ_PRIO_BEST_EFFORT, | 770 | GNUNET_MQ_PRIO_BEST_EFFORT, |
diff --git a/src/service/transport/transport-testing2.h b/src/service/transport/transport-testing2.h index 8f1071e8f..a68c9df38 100644 --- a/src/service/transport/transport-testing2.h +++ b/src/service/transport/transport-testing2.h | |||
@@ -28,7 +28,6 @@ | |||
28 | #define TRANSPORT_TESTING_H | 28 | #define TRANSPORT_TESTING_H |
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_hello_lib.h" | ||
32 | #include "gnunet_peerstore_service.h" | 31 | #include "gnunet_peerstore_service.h" |
33 | #include "gnunet_transport_core_service.h" | 32 | #include "gnunet_transport_core_service.h" |
34 | #include "gnunet_transport_application_service.h" | 33 | #include "gnunet_transport_application_service.h" |
diff --git a/src/service/transport/transport_api2_core.c b/src/service/transport/transport_api2_core.c index 0d2a0ac7f..3eb6c651e 100644 --- a/src/service/transport/transport_api2_core.c +++ b/src/service/transport/transport_api2_core.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_constants.h" | 28 | #include "gnunet_constants.h" |
29 | #include "gnunet_arm_service.h" | 29 | #include "gnunet_arm_service.h" |
30 | #include "gnunet_hello_lib.h" | ||
31 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
32 | #include "gnunet_transport_core_service.h" | 31 | #include "gnunet_transport_core_service.h" |
33 | #include "transport.h" | 32 | #include "transport.h" |
diff --git a/src/service/transport/transport_api_cmd_backchannel_check.c b/src/service/transport/transport_api_cmd_backchannel_check.c index 68bdae69c..388001496 100644 --- a/src/service/transport/transport_api_cmd_backchannel_check.c +++ b/src/service/transport/transport_api_cmd_backchannel_check.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include "gnunet_testing_ng_lib.h" | 29 | #include "gnunet_testing_ng_lib.h" |
30 | #include "gnunet_testing_netjail_lib.h" | 30 | #include "gnunet_testing_netjail_lib.h" |
31 | #include "gnunet_transport_application_service.h" | 31 | #include "gnunet_transport_application_service.h" |
32 | #include "gnunet_hello_lib.h" | ||
33 | #include "transport-testing-cmds.h" | 32 | #include "transport-testing-cmds.h" |
34 | 33 | ||
35 | /** | 34 | /** |
diff --git a/src/service/transport/transport_api_cmd_connecting_peers.c b/src/service/transport/transport_api_cmd_connecting_peers.c index c59c4b006..c3f63d920 100644 --- a/src/service/transport/transport_api_cmd_connecting_peers.c +++ b/src/service/transport/transport_api_cmd_connecting_peers.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "gnunet_testing_netjail_lib.h" | 29 | #include "gnunet_testing_netjail_lib.h" |
30 | #include "gnunet_transport_application_service.h" | 30 | #include "gnunet_transport_application_service.h" |
31 | #include "gnunet_hello_lib.h" | ||
32 | #include "transport-testing-cmds.h" | 31 | #include "transport-testing-cmds.h" |
33 | 32 | ||
34 | /** | 33 | /** |