diff options
Diffstat (limited to 'src/hello/hello.c')
-rw-r--r-- | src/hello/hello.c | 843 |
1 files changed, 428 insertions, 415 deletions
diff --git a/src/hello/hello.c b/src/hello/hello.c index 021451a08..e701e1f17 100644 --- a/src/hello/hello.c +++ b/src/hello/hello.c | |||
@@ -33,7 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * Context used for building our own URI. | 34 | * Context used for building our own URI. |
35 | */ | 35 | */ |
36 | struct GNUNET_HELLO_ComposeUriContext { | 36 | struct GNUNET_HELLO_ComposeUriContext |
37 | { | ||
37 | /** | 38 | /** |
38 | * Final URI. | 39 | * Final URI. |
39 | */ | 40 | */ |
@@ -49,7 +50,8 @@ struct GNUNET_HELLO_ComposeUriContext { | |||
49 | /** | 50 | /** |
50 | * Context for #add_address_to_hello(). | 51 | * Context for #add_address_to_hello(). |
51 | */ | 52 | */ |
52 | struct GNUNET_HELLO_ParseUriContext { | 53 | struct GNUNET_HELLO_ParseUriContext |
54 | { | ||
53 | /** | 55 | /** |
54 | * Position in the URI with the next address to parse. | 56 | * Position in the URI with the next address to parse. |
55 | */ | 57 | */ |
@@ -84,9 +86,9 @@ struct GNUNET_HELLO_ParseUriContext { | |||
84 | * @return #GNUNET_YES for friend-only or #GNUNET_NO otherwise | 86 | * @return #GNUNET_YES for friend-only or #GNUNET_NO otherwise |
85 | */ | 87 | */ |
86 | int | 88 | int |
87 | GNUNET_HELLO_is_friend_only(const struct GNUNET_HELLO_Message *h) | 89 | GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h) |
88 | { | 90 | { |
89 | if (GNUNET_YES == ntohl(h->friend_only)) | 91 | if (GNUNET_YES == ntohl (h->friend_only)) |
90 | return GNUNET_YES; | 92 | return GNUNET_YES; |
91 | return GNUNET_NO; | 93 | return GNUNET_NO; |
92 | } | 94 | } |
@@ -104,27 +106,27 @@ GNUNET_HELLO_is_friend_only(const struct GNUNET_HELLO_Message *h) | |||
104 | * the target buffer was not big enough. | 106 | * the target buffer was not big enough. |
105 | */ | 107 | */ |
106 | size_t | 108 | size_t |
107 | GNUNET_HELLO_add_address(const struct GNUNET_HELLO_Address *address, | 109 | GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, |
108 | struct GNUNET_TIME_Absolute expiration, | 110 | struct GNUNET_TIME_Absolute expiration, |
109 | char *target, | 111 | char *target, |
110 | size_t max) | 112 | size_t max) |
111 | { | 113 | { |
112 | uint16_t alen; | 114 | uint16_t alen; |
113 | size_t slen; | 115 | size_t slen; |
114 | struct GNUNET_TIME_AbsoluteNBO exp; | 116 | struct GNUNET_TIME_AbsoluteNBO exp; |
115 | 117 | ||
116 | slen = strlen(address->transport_name) + 1; | 118 | slen = strlen (address->transport_name) + 1; |
117 | if (slen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO) + | 119 | if (slen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO) |
118 | address->address_length > max) | 120 | + address->address_length > max) |
119 | return 0; | 121 | return 0; |
120 | exp = GNUNET_TIME_absolute_hton(expiration); | 122 | exp = GNUNET_TIME_absolute_hton (expiration); |
121 | alen = htons((uint16_t)address->address_length); | 123 | alen = htons ((uint16_t) address->address_length); |
122 | GNUNET_memcpy(target, address->transport_name, slen); | 124 | GNUNET_memcpy (target, address->transport_name, slen); |
123 | GNUNET_memcpy(&target[slen], &alen, sizeof(uint16_t)); | 125 | GNUNET_memcpy (&target[slen], &alen, sizeof(uint16_t)); |
124 | slen += sizeof(uint16_t); | 126 | slen += sizeof(uint16_t); |
125 | GNUNET_memcpy(&target[slen], &exp, sizeof(struct GNUNET_TIME_AbsoluteNBO)); | 127 | GNUNET_memcpy (&target[slen], &exp, sizeof(struct GNUNET_TIME_AbsoluteNBO)); |
126 | slen += sizeof(struct GNUNET_TIME_AbsoluteNBO); | 128 | slen += sizeof(struct GNUNET_TIME_AbsoluteNBO); |
127 | GNUNET_memcpy(&target[slen], address->address, address->address_length); | 129 | GNUNET_memcpy (&target[slen], address->address, address->address_length); |
128 | slen += address->address_length; | 130 | slen += address->address_length; |
129 | return slen; | 131 | return slen; |
130 | } | 132 | } |
@@ -139,9 +141,9 @@ GNUNET_HELLO_add_address(const struct GNUNET_HELLO_Address *address, | |||
139 | * @return size of the entry, or 0 if @a max is not large enough | 141 | * @return size of the entry, or 0 if @a max is not large enough |
140 | */ | 142 | */ |
141 | static size_t | 143 | static size_t |
142 | get_hello_address_size(const char *buf, | 144 | get_hello_address_size (const char *buf, |
143 | size_t max, | 145 | size_t max, |
144 | uint16_t *ralen) | 146 | uint16_t *ralen) |
145 | { | 147 | { |
146 | const char *pos; | 148 | const char *pos; |
147 | uint16_t alen; | 149 | uint16_t alen; |
@@ -152,34 +154,34 @@ get_hello_address_size(const char *buf, | |||
152 | pos = buf; | 154 | pos = buf; |
153 | slen = 1; | 155 | slen = 1; |
154 | while ((left > 0) && ('\0' != *pos)) | 156 | while ((left > 0) && ('\0' != *pos)) |
155 | { | 157 | { |
156 | left--; | 158 | left--; |
157 | pos++; | 159 | pos++; |
158 | slen++; | 160 | slen++; |
159 | } | 161 | } |
160 | if (0 == left) | 162 | if (0 == left) |
161 | { | 163 | { |
162 | /* 0-termination not found */ | 164 | /* 0-termination not found */ |
163 | GNUNET_break_op(0); | 165 | GNUNET_break_op (0); |
164 | return 0; | 166 | return 0; |
165 | } | 167 | } |
166 | pos++; | 168 | pos++; |
167 | if (left < sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO)) | 169 | if (left < sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO)) |
168 | { | 170 | { |
169 | /* not enough space for addrlen */ | 171 | /* not enough space for addrlen */ |
170 | GNUNET_break_op(0); | 172 | GNUNET_break_op (0); |
171 | return 0; | 173 | return 0; |
172 | } | 174 | } |
173 | GNUNET_memcpy(&alen, pos, sizeof(uint16_t)); | 175 | GNUNET_memcpy (&alen, pos, sizeof(uint16_t)); |
174 | alen = ntohs(alen); | 176 | alen = ntohs (alen); |
175 | *ralen = alen; | 177 | *ralen = alen; |
176 | slen += alen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO); | 178 | slen += alen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO); |
177 | if (max < slen) | 179 | if (max < slen) |
178 | { | 180 | { |
179 | /* not enough space for addr */ | 181 | /* not enough space for addr */ |
180 | GNUNET_break_op(0); | 182 | GNUNET_break_op (0); |
181 | return 0; | 183 | return 0; |
182 | } | 184 | } |
183 | return slen; | 185 | return slen; |
184 | } | 186 | } |
185 | 187 | ||
@@ -199,41 +201,41 @@ get_hello_address_size(const char *buf, | |||
199 | * @return the hello message | 201 | * @return the hello message |
200 | */ | 202 | */ |
201 | struct GNUNET_HELLO_Message * | 203 | struct GNUNET_HELLO_Message * |
202 | GNUNET_HELLO_create(const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, | 204 | GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, |
203 | GNUNET_HELLO_GenerateAddressListCallback addrgen, | 205 | GNUNET_HELLO_GenerateAddressListCallback addrgen, |
204 | void *addrgen_cls, | 206 | void *addrgen_cls, |
205 | int friend_only) | 207 | int friend_only) |
206 | { | 208 | { |
207 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1 - 256 - | 209 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1 - 256 |
208 | sizeof(struct GNUNET_HELLO_Message)]; | 210 | - sizeof(struct GNUNET_HELLO_Message)]; |
209 | size_t max; | 211 | size_t max; |
210 | size_t used; | 212 | size_t used; |
211 | size_t ret; | 213 | size_t ret; |
212 | struct GNUNET_HELLO_Message *hello; | 214 | struct GNUNET_HELLO_Message *hello; |
213 | 215 | ||
214 | GNUNET_assert(NULL != public_key); | 216 | GNUNET_assert (NULL != public_key); |
215 | GNUNET_assert((GNUNET_YES == friend_only) || | 217 | GNUNET_assert ((GNUNET_YES == friend_only) || |
216 | (GNUNET_NO == friend_only)); | 218 | (GNUNET_NO == friend_only)); |
217 | max = sizeof(buffer); | 219 | max = sizeof(buffer); |
218 | used = 0; | 220 | used = 0; |
219 | if (NULL != addrgen) | 221 | if (NULL != addrgen) |
222 | { | ||
223 | while (GNUNET_SYSERR != (ret = addrgen (addrgen_cls, | ||
224 | max, | ||
225 | &buffer[used]))) | ||
220 | { | 226 | { |
221 | while (GNUNET_SYSERR != (ret = addrgen(addrgen_cls, | 227 | max -= ret; |
222 | max, | 228 | used += ret; |
223 | &buffer[used]))) | ||
224 | { | ||
225 | max -= ret; | ||
226 | used += ret; | ||
227 | } | ||
228 | } | 229 | } |
229 | hello = GNUNET_malloc(sizeof(struct GNUNET_HELLO_Message) + used); | 230 | } |
230 | hello->header.type = htons(GNUNET_MESSAGE_TYPE_HELLO); | 231 | hello = GNUNET_malloc (sizeof(struct GNUNET_HELLO_Message) + used); |
231 | hello->header.size = htons(sizeof(struct GNUNET_HELLO_Message) + used); | 232 | hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO); |
232 | hello->friend_only = htonl(friend_only); | 233 | hello->header.size = htons (sizeof(struct GNUNET_HELLO_Message) + used); |
234 | hello->friend_only = htonl (friend_only); | ||
233 | hello->publicKey = *public_key; | 235 | hello->publicKey = *public_key; |
234 | GNUNET_memcpy(&hello[1], | 236 | GNUNET_memcpy (&hello[1], |
235 | buffer, | 237 | buffer, |
236 | used); | 238 | used); |
237 | return hello; | 239 | return hello; |
238 | } | 240 | } |
239 | 241 | ||
@@ -249,10 +251,10 @@ GNUNET_HELLO_create(const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, | |||
249 | * @return modified HELLO message | 251 | * @return modified HELLO message |
250 | */ | 252 | */ |
251 | struct GNUNET_HELLO_Message * | 253 | struct GNUNET_HELLO_Message * |
252 | GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, | 254 | GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, |
253 | int return_modified, | 255 | int return_modified, |
254 | GNUNET_HELLO_AddressIterator it, | 256 | GNUNET_HELLO_AddressIterator it, |
255 | void *it_cls) | 257 | void *it_cls) |
256 | { | 258 | { |
257 | struct GNUNET_HELLO_Address address; | 259 | struct GNUNET_HELLO_Address address; |
258 | uint16_t msize; | 260 | uint16_t msize; |
@@ -266,69 +268,70 @@ GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, | |||
266 | struct GNUNET_TIME_AbsoluteNBO expire; | 268 | struct GNUNET_TIME_AbsoluteNBO expire; |
267 | int iret; | 269 | int iret; |
268 | 270 | ||
269 | msize = GNUNET_HELLO_size(msg); | 271 | msize = GNUNET_HELLO_size (msg); |
270 | if ((msize < sizeof(struct GNUNET_HELLO_Message)) || | 272 | if ((msize < sizeof(struct GNUNET_HELLO_Message)) || |
271 | (ntohs(msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | 273 | (ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) |
272 | { | 274 | { |
273 | GNUNET_break_op(0); | 275 | GNUNET_break_op (0); |
274 | return NULL; | 276 | return NULL; |
275 | } | 277 | } |
276 | ret = NULL; | 278 | ret = NULL; |
277 | if (return_modified) | 279 | if (return_modified) |
278 | { | 280 | { |
279 | ret = GNUNET_malloc(msize); | 281 | ret = GNUNET_malloc (msize); |
280 | GNUNET_memcpy(ret, | 282 | GNUNET_memcpy (ret, |
281 | msg, | 283 | msg, |
282 | msize); | 284 | msize); |
283 | } | 285 | } |
284 | inptr = (const char *)&msg[1]; | 286 | inptr = (const char *) &msg[1]; |
285 | insize = msize - sizeof(struct GNUNET_HELLO_Message); | 287 | insize = msize - sizeof(struct GNUNET_HELLO_Message); |
286 | wpos = 0; | 288 | wpos = 0; |
287 | woff = (NULL != ret) ? (char *)&ret[1] : NULL; | 289 | woff = (NULL != ret) ? (char *) &ret[1] : NULL; |
288 | address.peer.public_key = msg->publicKey; | 290 | address.peer.public_key = msg->publicKey; |
289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 291 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
290 | "HELLO has %u bytes of address data\n", | 292 | "HELLO has %u bytes of address data\n", |
291 | (unsigned int)insize); | 293 | (unsigned int) insize); |
292 | 294 | ||
293 | while (insize > 0) | 295 | while (insize > 0) |
296 | { | ||
297 | esize = get_hello_address_size (inptr, | ||
298 | insize, | ||
299 | &alen); | ||
300 | if (0 == esize) | ||
294 | { | 301 | { |
295 | esize = get_hello_address_size(inptr, | 302 | GNUNET_break (0); |
296 | insize, | 303 | GNUNET_free_non_null (ret); |
297 | &alen); | 304 | return NULL; |
298 | if (0 == esize) | ||
299 | { | ||
300 | GNUNET_break(0); | ||
301 | GNUNET_free_non_null(ret); | ||
302 | return NULL; | ||
303 | } | ||
304 | /* need GNUNET_memcpy() due to possibility of misalignment */ | ||
305 | GNUNET_memcpy(&expire, | ||
306 | &inptr[esize - alen - sizeof(struct GNUNET_TIME_AbsoluteNBO)], | ||
307 | sizeof(struct GNUNET_TIME_AbsoluteNBO)); | ||
308 | address.address = &inptr[esize - alen]; | ||
309 | address.address_length = alen; | ||
310 | address.transport_name = inptr; | ||
311 | address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; | ||
312 | iret = it(it_cls, | ||
313 | &address, | ||
314 | GNUNET_TIME_absolute_ntoh(expire)); | ||
315 | if (GNUNET_SYSERR == iret) | ||
316 | break; | ||
317 | if ((GNUNET_OK == iret) && | ||
318 | (NULL != ret)) | ||
319 | { | ||
320 | /* copy address over */ | ||
321 | GNUNET_memcpy(woff, | ||
322 | inptr, | ||
323 | esize); | ||
324 | woff += esize; | ||
325 | wpos += esize; | ||
326 | } | ||
327 | insize -= esize; | ||
328 | inptr += esize; | ||
329 | } | 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 | } | ||
330 | if (NULL != ret) | 333 | if (NULL != ret) |
331 | ret->header.size = ntohs(sizeof(struct GNUNET_HELLO_Message) + wpos); | 334 | ret->header.size = ntohs (sizeof(struct GNUNET_HELLO_Message) + wpos); |
332 | return ret; | 335 | return ret; |
333 | } | 336 | } |
334 | 337 | ||
@@ -336,7 +339,8 @@ GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, | |||
336 | /** | 339 | /** |
337 | * Closure for #get_match_exp(). | 340 | * Closure for #get_match_exp(). |
338 | */ | 341 | */ |
339 | struct ExpireContext { | 342 | struct ExpireContext |
343 | { | ||
340 | /** | 344 | /** |
341 | * Address we are looking for. | 345 | * Address we are looking for. |
342 | */ | 346 | */ |
@@ -363,14 +367,14 @@ struct ExpireContext { | |||
363 | * @return #GNUNET_SYSERR if we found a matching address, #GNUNET_OK otherwise | 367 | * @return #GNUNET_SYSERR if we found a matching address, #GNUNET_OK otherwise |
364 | */ | 368 | */ |
365 | static int | 369 | static int |
366 | get_match_exp(void *cls, | 370 | get_match_exp (void *cls, |
367 | const struct GNUNET_HELLO_Address *address, | 371 | const struct GNUNET_HELLO_Address *address, |
368 | struct GNUNET_TIME_Absolute expiration) | 372 | struct GNUNET_TIME_Absolute expiration) |
369 | { | 373 | { |
370 | struct ExpireContext *ec = cls; | 374 | struct ExpireContext *ec = cls; |
371 | 375 | ||
372 | if (0 != GNUNET_HELLO_address_cmp(address, | 376 | if (0 != GNUNET_HELLO_address_cmp (address, |
373 | ec->address)) | 377 | ec->address)) |
374 | return GNUNET_OK; | 378 | return GNUNET_OK; |
375 | ec->found = GNUNET_YES; | 379 | ec->found = GNUNET_YES; |
376 | ec->expiration = expiration; | 380 | ec->expiration = expiration; |
@@ -381,7 +385,8 @@ get_match_exp(void *cls, | |||
381 | /** | 385 | /** |
382 | * Context for a #GNUNET_HELLO_Merge operation. | 386 | * Context for a #GNUNET_HELLO_Merge operation. |
383 | */ | 387 | */ |
384 | struct MergeContext { | 388 | struct MergeContext |
389 | { | ||
385 | /** | 390 | /** |
386 | * First HELLO we are merging. | 391 | * First HELLO we are merging. |
387 | */ | 392 | */ |
@@ -434,9 +439,9 @@ struct MergeContext { | |||
434 | * @return always #GNUNET_OK | 439 | * @return always #GNUNET_OK |
435 | */ | 440 | */ |
436 | static int | 441 | static int |
437 | copy_latest(void *cls, | 442 | copy_latest (void *cls, |
438 | const struct GNUNET_HELLO_Address *address, | 443 | const struct GNUNET_HELLO_Address *address, |
439 | struct GNUNET_TIME_Absolute expiration) | 444 | struct GNUNET_TIME_Absolute expiration) |
440 | { | 445 | { |
441 | struct MergeContext *mc = cls; | 446 | struct MergeContext *mc = cls; |
442 | struct ExpireContext ec; | 447 | struct ExpireContext ec; |
@@ -444,22 +449,22 @@ copy_latest(void *cls, | |||
444 | ec.address = address; | 449 | ec.address = address; |
445 | ec.found = GNUNET_NO; | 450 | ec.found = GNUNET_NO; |
446 | /* check if address exists in other */ | 451 | /* check if address exists in other */ |
447 | GNUNET_HELLO_iterate_addresses(mc->other, | 452 | GNUNET_HELLO_iterate_addresses (mc->other, |
448 | GNUNET_NO, | 453 | GNUNET_NO, |
449 | &get_match_exp, | 454 | &get_match_exp, |
450 | &ec); | 455 | &ec); |
451 | if ((GNUNET_NO == ec.found) || | 456 | if ((GNUNET_NO == ec.found) || |
452 | (ec.expiration.abs_value_us < expiration.abs_value_us) || | 457 | (ec.expiration.abs_value_us < expiration.abs_value_us) || |
453 | ((ec.expiration.abs_value_us == expiration.abs_value_us) && | 458 | ((ec.expiration.abs_value_us == expiration.abs_value_us) && |
454 | (GNUNET_YES == mc->take_equal))) | 459 | (GNUNET_YES == mc->take_equal))) |
455 | { | 460 | { |
456 | /* copy address to buffer */ | 461 | /* copy address to buffer */ |
457 | mc->ret += | 462 | mc->ret += |
458 | GNUNET_HELLO_add_address(address, | 463 | GNUNET_HELLO_add_address (address, |
459 | expiration, | 464 | expiration, |
460 | &mc->buf[mc->ret], | 465 | &mc->buf[mc->ret], |
461 | mc->max - mc->ret); | 466 | mc->max - mc->ret); |
462 | } | 467 | } |
463 | return GNUNET_OK; | 468 | return GNUNET_OK; |
464 | } | 469 | } |
465 | 470 | ||
@@ -475,9 +480,9 @@ copy_latest(void *cls, | |||
475 | * @return #GNUNET_SYSERR to end iteration, otherwise number of bytes written to @a buf | 480 | * @return #GNUNET_SYSERR to end iteration, otherwise number of bytes written to @a buf |
476 | */ | 481 | */ |
477 | static ssize_t | 482 | static ssize_t |
478 | merge_addr(void *cls, | 483 | merge_addr (void *cls, |
479 | size_t max, | 484 | size_t max, |
480 | void *buf) | 485 | void *buf) |
481 | { | 486 | { |
482 | struct MergeContext *mc = cls; | 487 | struct MergeContext *mc = cls; |
483 | 488 | ||
@@ -489,17 +494,17 @@ merge_addr(void *cls, | |||
489 | mc->take_equal = GNUNET_NO; | 494 | mc->take_equal = GNUNET_NO; |
490 | mc->other = mc->h2; | 495 | mc->other = mc->h2; |
491 | /* copy addresses from h1, if strictly larger expiration than h2 */ | 496 | /* copy addresses from h1, if strictly larger expiration than h2 */ |
492 | GNUNET_HELLO_iterate_addresses(mc->h1, | 497 | GNUNET_HELLO_iterate_addresses (mc->h1, |
493 | GNUNET_NO, | 498 | GNUNET_NO, |
494 | ©_latest, | 499 | ©_latest, |
495 | mc); | 500 | mc); |
496 | mc->take_equal = GNUNET_YES; | 501 | mc->take_equal = GNUNET_YES; |
497 | mc->other = mc->h1; | 502 | mc->other = mc->h1; |
498 | /* copy addresses from h2, if larger or equal expiration than h1 */ | 503 | /* copy addresses from h2, if larger or equal expiration than h1 */ |
499 | GNUNET_HELLO_iterate_addresses(mc->h2, | 504 | GNUNET_HELLO_iterate_addresses (mc->h2, |
500 | GNUNET_NO, | 505 | GNUNET_NO, |
501 | ©_latest, | 506 | ©_latest, |
502 | mc); | 507 | mc); |
503 | /* set marker to stop iteration */ | 508 | /* set marker to stop iteration */ |
504 | mc->h1 = NULL; | 509 | mc->h1 = NULL; |
505 | return mc->ret; | 510 | return mc->ret; |
@@ -516,8 +521,8 @@ merge_addr(void *cls, | |||
516 | * @return the combined HELLO message | 521 | * @return the combined HELLO message |
517 | */ | 522 | */ |
518 | struct GNUNET_HELLO_Message * | 523 | struct GNUNET_HELLO_Message * |
519 | GNUNET_HELLO_merge(const struct GNUNET_HELLO_Message *h1, | 524 | GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1, |
520 | const struct GNUNET_HELLO_Message *h2) | 525 | const struct GNUNET_HELLO_Message *h2) |
521 | { | 526 | { |
522 | struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 }; | 527 | struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 }; |
523 | int friend_only; | 528 | int friend_only; |
@@ -525,12 +530,12 @@ GNUNET_HELLO_merge(const struct GNUNET_HELLO_Message *h1, | |||
525 | if (h1->friend_only != h2->friend_only) | 530 | if (h1->friend_only != h2->friend_only) |
526 | friend_only = GNUNET_YES; /* One of the HELLOs is friend only */ | 531 | friend_only = GNUNET_YES; /* One of the HELLOs is friend only */ |
527 | else | 532 | else |
528 | friend_only = ntohl(h1->friend_only); /* Both HELLO's have the same type */ | 533 | friend_only = ntohl (h1->friend_only); /* Both HELLO's have the same type */ |
529 | 534 | ||
530 | return GNUNET_HELLO_create(&h1->publicKey, | 535 | return GNUNET_HELLO_create (&h1->publicKey, |
531 | &merge_addr, | 536 | &merge_addr, |
532 | &mc, | 537 | &mc, |
533 | friend_only); | 538 | friend_only); |
534 | } | 539 | } |
535 | 540 | ||
536 | 541 | ||
@@ -538,7 +543,8 @@ GNUNET_HELLO_merge(const struct GNUNET_HELLO_Message *h1, | |||
538 | * Context used in #GNUNET_HELLO_iterate_new_addresses() to | 543 | * Context used in #GNUNET_HELLO_iterate_new_addresses() to |
539 | * figure out which addresses are in fact 'new'. | 544 | * figure out which addresses are in fact 'new'. |
540 | */ | 545 | */ |
541 | struct DeltaContext { | 546 | struct DeltaContext |
547 | { | ||
542 | /** | 548 | /** |
543 | * We should ignore addresses that expire before this time. | 549 | * We should ignore addresses that expire before this time. |
544 | */ | 550 | */ |
@@ -575,9 +581,9 @@ struct DeltaContext { | |||
575 | * whatever the iterator returned. | 581 | * whatever the iterator returned. |
576 | */ | 582 | */ |
577 | static int | 583 | static int |
578 | delta_match(void *cls, | 584 | delta_match (void *cls, |
579 | const struct GNUNET_HELLO_Address *address, | 585 | const struct GNUNET_HELLO_Address *address, |
580 | struct GNUNET_TIME_Absolute expiration) | 586 | struct GNUNET_TIME_Absolute expiration) |
581 | { | 587 | { |
582 | struct DeltaContext *dc = cls; | 588 | struct DeltaContext *dc = cls; |
583 | int ret; | 589 | int ret; |
@@ -585,17 +591,17 @@ delta_match(void *cls, | |||
585 | 591 | ||
586 | ec.address = address; | 592 | ec.address = address; |
587 | ec.found = GNUNET_NO; | 593 | ec.found = GNUNET_NO; |
588 | GNUNET_HELLO_iterate_addresses(dc->old_hello, | 594 | GNUNET_HELLO_iterate_addresses (dc->old_hello, |
589 | GNUNET_NO, | 595 | GNUNET_NO, |
590 | &get_match_exp, | 596 | &get_match_exp, |
591 | &ec); | 597 | &ec); |
592 | if ((GNUNET_YES == ec.found) && | 598 | if ((GNUNET_YES == ec.found) && |
593 | ((ec.expiration.abs_value_us > expiration.abs_value_us) || | 599 | ((ec.expiration.abs_value_us > expiration.abs_value_us) || |
594 | (ec.expiration.abs_value_us >= dc->expiration_limit.abs_value_us))) | 600 | (ec.expiration.abs_value_us >= dc->expiration_limit.abs_value_us))) |
595 | return GNUNET_YES; /* skip: found and boring */ | 601 | return GNUNET_YES; /* skip: found and boring */ |
596 | ret = dc->it(dc->it_cls, | 602 | ret = dc->it (dc->it_cls, |
597 | address, | 603 | address, |
598 | expiration); | 604 | expiration); |
599 | return ret; | 605 | return ret; |
600 | } | 606 | } |
601 | 607 | ||
@@ -614,11 +620,14 @@ delta_match(void *cls, | |||
614 | * @param it_cls closure for @a it | 620 | * @param it_cls closure for @a it |
615 | */ | 621 | */ |
616 | void | 622 | void |
617 | GNUNET_HELLO_iterate_new_addresses(const struct GNUNET_HELLO_Message *new_hello, | 623 | GNUNET_HELLO_iterate_new_addresses (const struct |
618 | const struct GNUNET_HELLO_Message *old_hello, | 624 | GNUNET_HELLO_Message *new_hello, |
619 | struct GNUNET_TIME_Absolute expiration_limit, | 625 | const struct |
620 | GNUNET_HELLO_AddressIterator it, | 626 | GNUNET_HELLO_Message *old_hello, |
621 | void *it_cls) | 627 | struct GNUNET_TIME_Absolute |
628 | expiration_limit, | ||
629 | GNUNET_HELLO_AddressIterator it, | ||
630 | void *it_cls) | ||
622 | { | 631 | { |
623 | struct DeltaContext dc; | 632 | struct DeltaContext dc; |
624 | 633 | ||
@@ -626,11 +635,11 @@ GNUNET_HELLO_iterate_new_addresses(const struct GNUNET_HELLO_Message *new_hello, | |||
626 | dc.it = it; | 635 | dc.it = it; |
627 | dc.it_cls = it_cls; | 636 | dc.it_cls = it_cls; |
628 | dc.old_hello = old_hello; | 637 | dc.old_hello = old_hello; |
629 | GNUNET_assert(NULL == | 638 | GNUNET_assert (NULL == |
630 | GNUNET_HELLO_iterate_addresses(new_hello, | 639 | GNUNET_HELLO_iterate_addresses (new_hello, |
631 | GNUNET_NO, | 640 | GNUNET_NO, |
632 | &delta_match, | 641 | &delta_match, |
633 | &dc)); | 642 | &dc)); |
634 | } | 643 | } |
635 | 644 | ||
636 | 645 | ||
@@ -640,12 +649,12 @@ GNUNET_HELLO_iterate_new_addresses(const struct GNUNET_HELLO_Message *new_hello, | |||
640 | * @return the size, 0 if HELLO is invalid | 649 | * @return the size, 0 if HELLO is invalid |
641 | */ | 650 | */ |
642 | uint16_t | 651 | uint16_t |
643 | GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello) | 652 | GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello) |
644 | { | 653 | { |
645 | uint16_t ret = ntohs(hello->header.size); | 654 | uint16_t ret = ntohs (hello->header.size); |
646 | 655 | ||
647 | if ((ret < sizeof(struct GNUNET_HELLO_Message)) || | 656 | if ((ret < sizeof(struct GNUNET_HELLO_Message)) || |
648 | (ntohs(hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | 657 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) |
649 | return 0; | 658 | return 0; |
650 | return ret; | 659 | return ret; |
651 | } | 660 | } |
@@ -659,13 +668,13 @@ GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello) | |||
659 | * @return #GNUNET_SYSERR if the HELLO was malformed | 668 | * @return #GNUNET_SYSERR if the HELLO was malformed |
660 | */ | 669 | */ |
661 | int | 670 | int |
662 | GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, | 671 | GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello, |
663 | struct GNUNET_PeerIdentity *peer) | 672 | struct GNUNET_PeerIdentity *peer) |
664 | { | 673 | { |
665 | uint16_t ret = ntohs(hello->header.size); | 674 | uint16_t ret = ntohs (hello->header.size); |
666 | 675 | ||
667 | if ((ret < sizeof(struct GNUNET_HELLO_Message)) || | 676 | if ((ret < sizeof(struct GNUNET_HELLO_Message)) || |
668 | (ntohs(hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | 677 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) |
669 | return GNUNET_SYSERR; | 678 | return GNUNET_SYSERR; |
670 | peer->public_key = hello->publicKey; | 679 | peer->public_key = hello->publicKey; |
671 | return GNUNET_OK; | 680 | return GNUNET_OK; |
@@ -681,12 +690,12 @@ GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, | |||
681 | * @return header or NULL if the HELLO was malformed | 690 | * @return header or NULL if the HELLO was malformed |
682 | */ | 691 | */ |
683 | struct GNUNET_MessageHeader * | 692 | struct GNUNET_MessageHeader * |
684 | GNUNET_HELLO_get_header(struct GNUNET_HELLO_Message *hello) | 693 | GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello) |
685 | { | 694 | { |
686 | uint16_t ret = ntohs(hello->header.size); | 695 | uint16_t ret = ntohs (hello->header.size); |
687 | 696 | ||
688 | if ((ret < sizeof(struct GNUNET_HELLO_Message)) || | 697 | if ((ret < sizeof(struct GNUNET_HELLO_Message)) || |
689 | (ntohs(hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | 698 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) |
690 | return NULL; | 699 | return NULL; |
691 | 700 | ||
692 | return &hello->header; | 701 | return &hello->header; |
@@ -696,7 +705,8 @@ GNUNET_HELLO_get_header(struct GNUNET_HELLO_Message *hello) | |||
696 | /** | 705 | /** |
697 | * Context used for comparing HELLOs in #GNUNET_HELLO_equals(). | 706 | * Context used for comparing HELLOs in #GNUNET_HELLO_equals(). |
698 | */ | 707 | */ |
699 | struct EqualsContext { | 708 | struct EqualsContext |
709 | { | ||
700 | /** | 710 | /** |
701 | * Addresses that expired before this date are ignored for | 711 | * Addresses that expired before this date are ignored for |
702 | * the comparisson. | 712 | * the comparisson. |
@@ -746,22 +756,22 @@ struct EqualsContext { | |||
746 | * #GNUNET_SYSERR if the address does match. | 756 | * #GNUNET_SYSERR if the address does match. |
747 | */ | 757 | */ |
748 | static int | 758 | static int |
749 | find_other_matching(void *cls, | 759 | find_other_matching (void *cls, |
750 | const struct GNUNET_HELLO_Address *address, | 760 | const struct GNUNET_HELLO_Address *address, |
751 | struct GNUNET_TIME_Absolute expiration) | 761 | struct GNUNET_TIME_Absolute expiration) |
752 | { | 762 | { |
753 | struct EqualsContext *ec = cls; | 763 | struct EqualsContext *ec = cls; |
754 | 764 | ||
755 | if (expiration.abs_value_us < ec->expiration_limit.abs_value_us) | 765 | if (expiration.abs_value_us < ec->expiration_limit.abs_value_us) |
756 | return GNUNET_YES; | 766 | return GNUNET_YES; |
757 | if (0 == GNUNET_HELLO_address_cmp(address, ec->address)) | 767 | if (0 == GNUNET_HELLO_address_cmp (address, ec->address)) |
758 | { | 768 | { |
759 | ec->found = GNUNET_YES; | 769 | ec->found = GNUNET_YES; |
760 | if (expiration.abs_value_us < ec->expiration.abs_value_us) | 770 | if (expiration.abs_value_us < ec->expiration.abs_value_us) |
761 | ec->result = GNUNET_TIME_absolute_min(expiration, | 771 | ec->result = GNUNET_TIME_absolute_min (expiration, |
762 | ec->result); | 772 | ec->result); |
763 | return GNUNET_SYSERR; | 773 | return GNUNET_SYSERR; |
764 | } | 774 | } |
765 | return GNUNET_YES; | 775 | return GNUNET_YES; |
766 | } | 776 | } |
767 | 777 | ||
@@ -779,9 +789,9 @@ find_other_matching(void *cls, | |||
779 | * #GNUNET_SYSERR if it was not found | 789 | * #GNUNET_SYSERR if it was not found |
780 | */ | 790 | */ |
781 | static int | 791 | static int |
782 | find_matching(void *cls, | 792 | find_matching (void *cls, |
783 | const struct GNUNET_HELLO_Address *address, | 793 | const struct GNUNET_HELLO_Address *address, |
784 | struct GNUNET_TIME_Absolute expiration) | 794 | struct GNUNET_TIME_Absolute expiration) |
785 | { | 795 | { |
786 | struct EqualsContext *ec = cls; | 796 | struct EqualsContext *ec = cls; |
787 | 797 | ||
@@ -790,16 +800,16 @@ find_matching(void *cls, | |||
790 | ec->address = address; | 800 | ec->address = address; |
791 | ec->expiration = expiration; | 801 | ec->expiration = expiration; |
792 | ec->found = GNUNET_NO; | 802 | ec->found = GNUNET_NO; |
793 | GNUNET_HELLO_iterate_addresses(ec->ref, | 803 | GNUNET_HELLO_iterate_addresses (ec->ref, |
794 | GNUNET_NO, | 804 | GNUNET_NO, |
795 | &find_other_matching, | 805 | &find_other_matching, |
796 | ec); | 806 | ec); |
797 | if (GNUNET_NO == ec->found) | 807 | if (GNUNET_NO == ec->found) |
798 | { | 808 | { |
799 | /* not found, we differ *now* */ | 809 | /* not found, we differ *now* */ |
800 | ec->result = GNUNET_TIME_UNIT_ZERO_ABS; | 810 | ec->result = GNUNET_TIME_UNIT_ZERO_ABS; |
801 | return GNUNET_SYSERR; | 811 | return GNUNET_SYSERR; |
802 | } | 812 | } |
803 | return GNUNET_OK; | 813 | return GNUNET_OK; |
804 | } | 814 | } |
805 | 815 | ||
@@ -821,32 +831,32 @@ find_matching(void *cls, | |||
821 | * do not match at all | 831 | * do not match at all |
822 | */ | 832 | */ |
823 | struct GNUNET_TIME_Absolute | 833 | struct GNUNET_TIME_Absolute |
824 | GNUNET_HELLO_equals(const struct GNUNET_HELLO_Message *h1, | 834 | GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1, |
825 | const struct GNUNET_HELLO_Message *h2, | 835 | const struct GNUNET_HELLO_Message *h2, |
826 | struct GNUNET_TIME_Absolute now) | 836 | struct GNUNET_TIME_Absolute now) |
827 | { | 837 | { |
828 | struct EqualsContext ec; | 838 | struct EqualsContext ec; |
829 | 839 | ||
830 | if (h1->header.type != h2->header.type) | 840 | if (h1->header.type != h2->header.type) |
831 | return GNUNET_TIME_UNIT_ZERO_ABS; | 841 | return GNUNET_TIME_UNIT_ZERO_ABS; |
832 | if (0 != | 842 | if (0 != |
833 | GNUNET_memcmp(&h1->publicKey, | 843 | GNUNET_memcmp (&h1->publicKey, |
834 | &h2->publicKey)) | 844 | &h2->publicKey)) |
835 | return GNUNET_TIME_UNIT_ZERO_ABS; | 845 | return GNUNET_TIME_UNIT_ZERO_ABS; |
836 | ec.expiration_limit = now; | 846 | ec.expiration_limit = now; |
837 | ec.result = GNUNET_TIME_UNIT_FOREVER_ABS; | 847 | ec.result = GNUNET_TIME_UNIT_FOREVER_ABS; |
838 | ec.ref = h2; | 848 | ec.ref = h2; |
839 | GNUNET_HELLO_iterate_addresses(h1, | 849 | GNUNET_HELLO_iterate_addresses (h1, |
840 | GNUNET_NO, | 850 | GNUNET_NO, |
841 | &find_matching, | 851 | &find_matching, |
842 | &ec); | 852 | &ec); |
843 | if (ec.result.abs_value_us == GNUNET_TIME_UNIT_ZERO.rel_value_us) | 853 | if (ec.result.abs_value_us == GNUNET_TIME_UNIT_ZERO.rel_value_us) |
844 | return ec.result; | 854 | return ec.result; |
845 | ec.ref = h1; | 855 | ec.ref = h1; |
846 | GNUNET_HELLO_iterate_addresses(h2, | 856 | GNUNET_HELLO_iterate_addresses (h2, |
847 | GNUNET_NO, | 857 | GNUNET_NO, |
848 | &find_matching, | 858 | &find_matching, |
849 | &ec); | 859 | &ec); |
850 | return ec.result; | 860 | return ec.result; |
851 | } | 861 | } |
852 | 862 | ||
@@ -861,13 +871,13 @@ GNUNET_HELLO_equals(const struct GNUNET_HELLO_Message *h1, | |||
861 | * @return #GNUNET_OK (always) | 871 | * @return #GNUNET_OK (always) |
862 | */ | 872 | */ |
863 | static int | 873 | static int |
864 | find_max_expire(void *cls, | 874 | find_max_expire (void *cls, |
865 | const struct GNUNET_HELLO_Address *address, | 875 | const struct GNUNET_HELLO_Address *address, |
866 | struct GNUNET_TIME_Absolute expiration) | 876 | struct GNUNET_TIME_Absolute expiration) |
867 | { | 877 | { |
868 | struct GNUNET_TIME_Absolute *max = cls; | 878 | struct GNUNET_TIME_Absolute *max = cls; |
869 | 879 | ||
870 | *max = GNUNET_TIME_absolute_max(*max, expiration); | 880 | *max = GNUNET_TIME_absolute_max (*max, expiration); |
871 | return GNUNET_OK; | 881 | return GNUNET_OK; |
872 | } | 882 | } |
873 | 883 | ||
@@ -879,15 +889,15 @@ find_max_expire(void *cls, | |||
879 | * @return time the last address expires, 0 if there are no addresses in the HELLO | 889 | * @return time the last address expires, 0 if there are no addresses in the HELLO |
880 | */ | 890 | */ |
881 | struct GNUNET_TIME_Absolute | 891 | struct GNUNET_TIME_Absolute |
882 | GNUNET_HELLO_get_last_expiration(const struct GNUNET_HELLO_Message *msg) | 892 | GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg) |
883 | { | 893 | { |
884 | struct GNUNET_TIME_Absolute ret; | 894 | struct GNUNET_TIME_Absolute ret; |
885 | 895 | ||
886 | ret = GNUNET_TIME_UNIT_ZERO_ABS; | 896 | ret = GNUNET_TIME_UNIT_ZERO_ABS; |
887 | GNUNET_HELLO_iterate_addresses(msg, | 897 | GNUNET_HELLO_iterate_addresses (msg, |
888 | GNUNET_NO, | 898 | GNUNET_NO, |
889 | &find_max_expire, | 899 | &find_max_expire, |
890 | &ret); | 900 | &ret); |
891 | return ret; | 901 | return ret; |
892 | } | 902 | } |
893 | 903 | ||
@@ -946,9 +956,9 @@ GNUNET_HELLO_get_last_expiration(const struct GNUNET_HELLO_Message *msg) | |||
946 | * @return #GNUNET_OK (continue iteration). | 956 | * @return #GNUNET_OK (continue iteration). |
947 | */ | 957 | */ |
948 | static int | 958 | static int |
949 | add_address_to_uri(void *cls, | 959 | add_address_to_uri (void *cls, |
950 | const struct GNUNET_HELLO_Address *address, | 960 | const struct GNUNET_HELLO_Address *address, |
951 | struct GNUNET_TIME_Absolute expiration) | 961 | struct GNUNET_TIME_Absolute expiration) |
952 | { | 962 | { |
953 | struct GNUNET_HELLO_ComposeUriContext *ctx = cls; | 963 | struct GNUNET_HELLO_ComposeUriContext *ctx = cls; |
954 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 964 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
@@ -961,49 +971,49 @@ add_address_to_uri(void *cls, | |||
961 | struct tm *t; | 971 | struct tm *t; |
962 | time_t seconds; | 972 | time_t seconds; |
963 | 973 | ||
964 | papi = ctx->plugins_find(address->transport_name); | 974 | papi = ctx->plugins_find (address->transport_name); |
965 | if (NULL == papi) | 975 | if (NULL == papi) |
966 | { | 976 | { |
967 | /* Not an error - we might just not have the right plugin. */ | 977 | /* Not an error - we might just not have the right plugin. */ |
968 | return GNUNET_OK; | 978 | return GNUNET_OK; |
969 | } | 979 | } |
970 | if (NULL == papi->address_to_string) | 980 | if (NULL == papi->address_to_string) |
971 | { | 981 | { |
972 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
973 | "URI conversion not implemented for plugin `%s'\n", | 983 | "URI conversion not implemented for plugin `%s'\n", |
974 | address->transport_name); | 984 | address->transport_name); |
975 | return GNUNET_OK; | 985 | return GNUNET_OK; |
976 | } | 986 | } |
977 | addr = papi->address_to_string(papi->cls, | 987 | addr = papi->address_to_string (papi->cls, |
978 | address->address, | 988 | address->address, |
979 | address->address_length); | 989 | address->address_length); |
980 | if ((NULL == addr) || | 990 | if ((NULL == addr) || |
981 | (0 == strlen(addr))) | 991 | (0 == strlen (addr))) |
982 | return GNUNET_OK; | 992 | return GNUNET_OK; |
983 | 993 | ||
984 | addr_dup = GNUNET_strdup(addr); | 994 | addr_dup = GNUNET_strdup (addr); |
985 | if (NULL != (pos = strstr(addr_dup, "_server"))) | 995 | if (NULL != (pos = strstr (addr_dup, "_server"))) |
986 | GNUNET_memcpy(pos, | 996 | GNUNET_memcpy (pos, |
987 | client_str, | 997 | client_str, |
988 | strlen(client_str)); /* Replace all server addresses with client addresses */ | 998 | strlen (client_str)); /* Replace all server addresses with client addresses */ |
989 | 999 | ||
990 | seconds = expiration.abs_value_us / 1000LL / 1000LL; | 1000 | seconds = expiration.abs_value_us / 1000LL / 1000LL; |
991 | t = gmtime(&seconds); | 1001 | t = gmtime (&seconds); |
992 | 1002 | ||
993 | GNUNET_asprintf(&ret, | 1003 | GNUNET_asprintf (&ret, |
994 | "%s%c%s%c%s%c%s", | 1004 | "%s%c%s%c%s%c%s", |
995 | ctx->uri, | 1005 | ctx->uri, |
996 | GNUNET_HELLO_URI_SEP, | 1006 | GNUNET_HELLO_URI_SEP, |
997 | strftime(tbuf, | 1007 | strftime (tbuf, |
998 | sizeof(tbuf), | 1008 | sizeof(tbuf), |
999 | "%Y%m%d%H%M%S", | 1009 | "%Y%m%d%H%M%S", |
1000 | t) ? tbuf : "0", | 1010 | t) ? tbuf : "0", |
1001 | GNUNET_HELLO_URI_SEP, | 1011 | GNUNET_HELLO_URI_SEP, |
1002 | address->transport_name, | 1012 | address->transport_name, |
1003 | GNUNET_HELLO_URI_SEP, | 1013 | GNUNET_HELLO_URI_SEP, |
1004 | addr_dup); | 1014 | addr_dup); |
1005 | GNUNET_free(addr_dup); | 1015 | GNUNET_free (addr_dup); |
1006 | GNUNET_free(ctx->uri); | 1016 | GNUNET_free (ctx->uri); |
1007 | ctx->uri = ret; | 1017 | ctx->uri = ret; |
1008 | return GNUNET_OK; | 1018 | return GNUNET_OK; |
1009 | } | 1019 | } |
@@ -1017,25 +1027,25 @@ add_address_to_uri(void *cls, | |||
1017 | * @return Hello URI string | 1027 | * @return Hello URI string |
1018 | */ | 1028 | */ |
1019 | char * | 1029 | char * |
1020 | GNUNET_HELLO_compose_uri(const struct GNUNET_HELLO_Message *hello, | 1030 | GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello, |
1021 | GNUNET_HELLO_TransportPluginsFind plugins_find) | 1031 | GNUNET_HELLO_TransportPluginsFind plugins_find) |
1022 | { | 1032 | { |
1023 | struct GNUNET_HELLO_ComposeUriContext ctx; | 1033 | struct GNUNET_HELLO_ComposeUriContext ctx; |
1024 | char *pkey; | 1034 | char *pkey; |
1025 | 1035 | ||
1026 | ctx.plugins_find = plugins_find; | 1036 | ctx.plugins_find = plugins_find; |
1027 | pkey = GNUNET_CRYPTO_eddsa_public_key_to_string(&hello->publicKey); | 1037 | pkey = GNUNET_CRYPTO_eddsa_public_key_to_string (&hello->publicKey); |
1028 | GNUNET_asprintf(&ctx.uri, | 1038 | GNUNET_asprintf (&ctx.uri, |
1029 | "%s%s", | 1039 | "%s%s", |
1030 | (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) | 1040 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) |
1031 | ? GNUNET_FRIEND_HELLO_URI_PREFIX | 1041 | ? GNUNET_FRIEND_HELLO_URI_PREFIX |
1032 | : GNUNET_HELLO_URI_PREFIX, | 1042 | : GNUNET_HELLO_URI_PREFIX, |
1033 | pkey); | 1043 | pkey); |
1034 | GNUNET_free(pkey); | 1044 | GNUNET_free (pkey); |
1035 | GNUNET_HELLO_iterate_addresses(hello, | 1045 | GNUNET_HELLO_iterate_addresses (hello, |
1036 | GNUNET_NO, | 1046 | GNUNET_NO, |
1037 | &add_address_to_uri, | 1047 | &add_address_to_uri, |
1038 | &ctx); | 1048 | &ctx); |
1039 | return ctx.uri; | 1049 | return ctx.uri; |
1040 | } | 1050 | } |
1041 | 1051 | ||
@@ -1053,9 +1063,9 @@ GNUNET_HELLO_compose_uri(const struct GNUNET_HELLO_Message *hello, | |||
1053 | * @return number of bytes added to buffer, #GNUNET_SYSERR on error | 1063 | * @return number of bytes added to buffer, #GNUNET_SYSERR on error |
1054 | */ | 1064 | */ |
1055 | static ssize_t | 1065 | static ssize_t |
1056 | add_address_to_hello(void *cls, | 1066 | add_address_to_hello (void *cls, |
1057 | size_t max, | 1067 | size_t max, |
1058 | void *buffer) | 1068 | void *buffer) |
1059 | { | 1069 | { |
1060 | struct GNUNET_HELLO_ParseUriContext *ctx = cls; | 1070 | struct GNUNET_HELLO_ParseUriContext *ctx = cls; |
1061 | const char *tname; | 1071 | const char *tname; |
@@ -1075,119 +1085,122 @@ add_address_to_hello(void *cls, | |||
1075 | if (NULL == ctx->pos) | 1085 | if (NULL == ctx->pos) |
1076 | return GNUNET_SYSERR; | 1086 | return GNUNET_SYSERR; |
1077 | if (GNUNET_HELLO_URI_SEP != ctx->pos[0]) | 1087 | if (GNUNET_HELLO_URI_SEP != ctx->pos[0]) |
1078 | { | 1088 | { |
1079 | ctx->ret = GNUNET_SYSERR; | 1089 | ctx->ret = GNUNET_SYSERR; |
1080 | GNUNET_break(0); | 1090 | GNUNET_break (0); |
1081 | return GNUNET_SYSERR; | 1091 | return GNUNET_SYSERR; |
1082 | } | 1092 | } |
1083 | ctx->pos++; | 1093 | ctx->pos++; |
1084 | 1094 | ||
1085 | if (('0' == ctx->pos[0]) && | 1095 | if (('0' == ctx->pos[0]) && |
1086 | (GNUNET_HELLO_URI_SEP == ctx->pos[1])) | 1096 | (GNUNET_HELLO_URI_SEP == ctx->pos[1])) |
1087 | { | 1097 | { |
1088 | expire = GNUNET_TIME_UNIT_FOREVER_ABS; | 1098 | expire = GNUNET_TIME_UNIT_FOREVER_ABS; |
1089 | tname = ctx->pos + 1; | 1099 | tname = ctx->pos + 1; |
1090 | } | 1100 | } |
1091 | else | 1101 | else |
1102 | { | ||
1103 | memset (&expiration_time, 0, sizeof(expiration_time)); | ||
1104 | tname = strptime (ctx->pos, | ||
1105 | "%Y%m%d%H%M%S", | ||
1106 | &expiration_time); | ||
1107 | if (NULL == tname) | ||
1092 | { | 1108 | { |
1093 | memset(&expiration_time, 0, sizeof(expiration_time)); | ||
1094 | tname = strptime(ctx->pos, | ||
1095 | "%Y%m%d%H%M%S", | ||
1096 | &expiration_time); | ||
1097 | if (NULL == tname) | ||
1098 | { | ||
1099 | ctx->ret = GNUNET_SYSERR; | ||
1100 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1101 | _("Failed to parse HELLO message: missing expiration time\n")); | ||
1102 | GNUNET_break(0); | ||
1103 | return GNUNET_SYSERR; | ||
1104 | } | ||
1105 | |||
1106 | expiration_seconds = mktime(&expiration_time); | ||
1107 | if (expiration_seconds == (time_t)-1) | ||
1108 | { | ||
1109 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1110 | _("Failed to parse HELLO message: invalid expiration time\n")); | ||
1111 | ctx->ret = GNUNET_SYSERR; | ||
1112 | GNUNET_break(0); | ||
1113 | return GNUNET_SYSERR; | ||
1114 | } | ||
1115 | expire.abs_value_us = expiration_seconds * 1000LL * 1000LL; | ||
1116 | } | ||
1117 | if (GNUNET_HELLO_URI_SEP != tname[0]) | ||
1118 | { | ||
1119 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1120 | _("Failed to parse HELLO message: malformed\n")); | ||
1121 | ctx->ret = GNUNET_SYSERR; | 1109 | ctx->ret = GNUNET_SYSERR; |
1122 | GNUNET_break(0); | 1110 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1111 | _ ( | ||
1112 | "Failed to parse HELLO message: missing expiration time\n")); | ||
1113 | GNUNET_break (0); | ||
1123 | return GNUNET_SYSERR; | 1114 | return GNUNET_SYSERR; |
1124 | } | 1115 | } |
1125 | tname++; | 1116 | |
1126 | address = strchr(tname, | 1117 | expiration_seconds = mktime (&expiration_time); |
1127 | (int)GNUNET_HELLO_URI_SEP); | 1118 | if (expiration_seconds == (time_t) -1) |
1128 | if (NULL == address) | ||
1129 | { | 1119 | { |
1130 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1131 | _("Failed to parse HELLO message: missing transport plugin\n")); | 1121 | _ ( |
1122 | "Failed to parse HELLO message: invalid expiration time\n")); | ||
1132 | ctx->ret = GNUNET_SYSERR; | 1123 | ctx->ret = GNUNET_SYSERR; |
1133 | GNUNET_break(0); | 1124 | GNUNET_break (0); |
1134 | return GNUNET_SYSERR; | 1125 | return GNUNET_SYSERR; |
1135 | } | 1126 | } |
1127 | expire.abs_value_us = expiration_seconds * 1000LL * 1000LL; | ||
1128 | } | ||
1129 | if (GNUNET_HELLO_URI_SEP != tname[0]) | ||
1130 | { | ||
1131 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1132 | _ ("Failed to parse HELLO message: malformed\n")); | ||
1133 | ctx->ret = GNUNET_SYSERR; | ||
1134 | GNUNET_break (0); | ||
1135 | return GNUNET_SYSERR; | ||
1136 | } | ||
1137 | tname++; | ||
1138 | address = strchr (tname, | ||
1139 | (int) GNUNET_HELLO_URI_SEP); | ||
1140 | if (NULL == address) | ||
1141 | { | ||
1142 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1143 | _ ( | ||
1144 | "Failed to parse HELLO message: missing transport plugin\n")); | ||
1145 | ctx->ret = GNUNET_SYSERR; | ||
1146 | GNUNET_break (0); | ||
1147 | return GNUNET_SYSERR; | ||
1148 | } | ||
1136 | address++; | 1149 | address++; |
1137 | end = strchr(address, (int)GNUNET_HELLO_URI_SEP); | 1150 | end = strchr (address, (int) GNUNET_HELLO_URI_SEP); |
1138 | ctx->pos = end; | 1151 | ctx->pos = end; |
1139 | ctx->counter_total++; | 1152 | ctx->counter_total++; |
1140 | plugin_name = GNUNET_strndup(tname, address - (tname + 1)); | 1153 | plugin_name = GNUNET_strndup (tname, address - (tname + 1)); |
1141 | papi = ctx->plugins_find(plugin_name); | 1154 | papi = ctx->plugins_find (plugin_name); |
1142 | if (NULL == papi) | 1155 | if (NULL == papi) |
1143 | { | 1156 | { |
1144 | /* Not an error - we might just not have the right plugin. | 1157 | /* Not an error - we might just not have the right plugin. |
1145 | * Skip this part, advance to the next one and recurse. | 1158 | * Skip this part, advance to the next one and recurse. |
1146 | * But only if this is not the end of string. | 1159 | * But only if this is not the end of string. |
1147 | */ | 1160 | */ |
1148 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1161 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1149 | _("Plugin `%s' not found, skipping address\n"), | 1162 | _ ("Plugin `%s' not found, skipping address\n"), |
1150 | plugin_name); | 1163 | plugin_name); |
1151 | GNUNET_free(plugin_name); | 1164 | GNUNET_free (plugin_name); |
1152 | return 0; | 1165 | return 0; |
1153 | } | 1166 | } |
1154 | if (NULL == papi->string_to_address) | 1167 | if (NULL == papi->string_to_address) |
1155 | { | 1168 | { |
1156 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1169 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1157 | _("Plugin `%s' does not support URIs yet\n"), | 1170 | _ ("Plugin `%s' does not support URIs yet\n"), |
1158 | plugin_name); | 1171 | plugin_name); |
1159 | GNUNET_free(plugin_name); | 1172 | GNUNET_free (plugin_name); |
1160 | GNUNET_break(0); | 1173 | GNUNET_break (0); |
1161 | return 0; | 1174 | return 0; |
1162 | } | 1175 | } |
1163 | uri_address = GNUNET_strndup(address, end - address); | 1176 | uri_address = GNUNET_strndup (address, end - address); |
1164 | if (GNUNET_OK != | 1177 | if (GNUNET_OK != |
1165 | papi->string_to_address(papi->cls, | 1178 | papi->string_to_address (papi->cls, |
1166 | uri_address, | 1179 | uri_address, |
1167 | strlen(uri_address) + 1, | 1180 | strlen (uri_address) + 1, |
1168 | &addr, | 1181 | &addr, |
1169 | &addr_len)) | 1182 | &addr_len)) |
1170 | { | 1183 | { |
1171 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1172 | _("Failed to parse `%s' as an address for plugin `%s'\n"), | 1185 | _ ("Failed to parse `%s' as an address for plugin `%s'\n"), |
1173 | uri_address, | 1186 | uri_address, |
1174 | plugin_name); | 1187 | plugin_name); |
1175 | GNUNET_free(plugin_name); | 1188 | GNUNET_free (plugin_name); |
1176 | GNUNET_free(uri_address); | 1189 | GNUNET_free (uri_address); |
1177 | return 0; | 1190 | return 0; |
1178 | } | 1191 | } |
1179 | GNUNET_free(uri_address); | 1192 | GNUNET_free (uri_address); |
1180 | /* address.peer is unset - not used by add_address() */ | 1193 | /* address.peer is unset - not used by add_address() */ |
1181 | haddr.address_length = addr_len; | 1194 | haddr.address_length = addr_len; |
1182 | haddr.address = addr; | 1195 | haddr.address = addr; |
1183 | haddr.transport_name = plugin_name; | 1196 | haddr.transport_name = plugin_name; |
1184 | ret = GNUNET_HELLO_add_address(&haddr, | 1197 | ret = GNUNET_HELLO_add_address (&haddr, |
1185 | expire, | 1198 | expire, |
1186 | buffer, | 1199 | buffer, |
1187 | max); | 1200 | max); |
1188 | ctx->counter_added++; | 1201 | ctx->counter_added++; |
1189 | GNUNET_free(addr); | 1202 | GNUNET_free (addr); |
1190 | GNUNET_free(plugin_name); | 1203 | GNUNET_free (plugin_name); |
1191 | return ret; | 1204 | return ret; |
1192 | } | 1205 | } |
1193 | 1206 | ||
@@ -1202,39 +1215,39 @@ add_address_to_hello(void *cls, | |||
1202 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the URI was invalid, #GNUNET_NO on other errors | 1215 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the URI was invalid, #GNUNET_NO on other errors |
1203 | */ | 1216 | */ |
1204 | int | 1217 | int |
1205 | GNUNET_HELLO_parse_uri(const char *uri, | 1218 | GNUNET_HELLO_parse_uri (const char *uri, |
1206 | struct GNUNET_CRYPTO_EddsaPublicKey *pubkey, | 1219 | struct GNUNET_CRYPTO_EddsaPublicKey *pubkey, |
1207 | struct GNUNET_HELLO_Message **hello, | 1220 | struct GNUNET_HELLO_Message **hello, |
1208 | GNUNET_HELLO_TransportPluginsFind plugins_find) | 1221 | GNUNET_HELLO_TransportPluginsFind plugins_find) |
1209 | { | 1222 | { |
1210 | const char *pks; | 1223 | const char *pks; |
1211 | const char *exc; | 1224 | const char *exc; |
1212 | int friend_only; | 1225 | int friend_only; |
1213 | struct GNUNET_HELLO_ParseUriContext ctx; | 1226 | struct GNUNET_HELLO_ParseUriContext ctx; |
1214 | 1227 | ||
1215 | if (0 == strncmp(uri, | 1228 | if (0 == strncmp (uri, |
1216 | GNUNET_HELLO_URI_PREFIX, | 1229 | GNUNET_HELLO_URI_PREFIX, |
1217 | strlen(GNUNET_HELLO_URI_PREFIX))) | 1230 | strlen (GNUNET_HELLO_URI_PREFIX))) |
1218 | { | 1231 | { |
1219 | pks = &uri[strlen(GNUNET_HELLO_URI_PREFIX)]; | 1232 | pks = &uri[strlen (GNUNET_HELLO_URI_PREFIX)]; |
1220 | friend_only = GNUNET_NO; | 1233 | friend_only = GNUNET_NO; |
1221 | } | 1234 | } |
1222 | else if (0 == strncmp(uri, | 1235 | else if (0 == strncmp (uri, |
1223 | GNUNET_FRIEND_HELLO_URI_PREFIX, | 1236 | GNUNET_FRIEND_HELLO_URI_PREFIX, |
1224 | strlen(GNUNET_FRIEND_HELLO_URI_PREFIX))) | 1237 | strlen (GNUNET_FRIEND_HELLO_URI_PREFIX))) |
1225 | { | 1238 | { |
1226 | pks = &uri[strlen(GNUNET_FRIEND_HELLO_URI_PREFIX)]; | 1239 | pks = &uri[strlen (GNUNET_FRIEND_HELLO_URI_PREFIX)]; |
1227 | friend_only = GNUNET_YES; | 1240 | friend_only = GNUNET_YES; |
1228 | } | 1241 | } |
1229 | else | 1242 | else |
1230 | return GNUNET_SYSERR; | 1243 | return GNUNET_SYSERR; |
1231 | exc = strchr(pks, GNUNET_HELLO_URI_SEP); | 1244 | exc = strchr (pks, GNUNET_HELLO_URI_SEP); |
1232 | 1245 | ||
1233 | if (GNUNET_OK != | 1246 | if (GNUNET_OK != |
1234 | GNUNET_STRINGS_string_to_data(pks, | 1247 | GNUNET_STRINGS_string_to_data (pks, |
1235 | (NULL == exc) ? strlen(pks) : (exc - pks), | 1248 | (NULL == exc) ? strlen (pks) : (exc - pks), |
1236 | (unsigned char *)pubkey, | 1249 | (unsigned char *) pubkey, |
1237 | sizeof(*pubkey))) | 1250 | sizeof(*pubkey))) |
1238 | return GNUNET_SYSERR; | 1251 | return GNUNET_SYSERR; |
1239 | 1252 | ||
1240 | ctx.pos = exc; | 1253 | ctx.pos = exc; |
@@ -1242,15 +1255,15 @@ GNUNET_HELLO_parse_uri(const char *uri, | |||
1242 | ctx.counter_total = 0; | 1255 | ctx.counter_total = 0; |
1243 | ctx.counter_added = 0; | 1256 | ctx.counter_added = 0; |
1244 | ctx.plugins_find = plugins_find; | 1257 | ctx.plugins_find = plugins_find; |
1245 | *hello = GNUNET_HELLO_create(pubkey, | 1258 | *hello = GNUNET_HELLO_create (pubkey, |
1246 | &add_address_to_hello, | 1259 | &add_address_to_hello, |
1247 | &ctx, | 1260 | &ctx, |
1248 | friend_only); | 1261 | friend_only); |
1249 | 1262 | ||
1250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1251 | "HELLO URI contained %u addresses, added %u addresses\n", | 1264 | "HELLO URI contained %u addresses, added %u addresses\n", |
1252 | ctx.counter_total, | 1265 | ctx.counter_total, |
1253 | ctx.counter_added); | 1266 | ctx.counter_added); |
1254 | 1267 | ||
1255 | return ctx.ret; | 1268 | return ctx.ret; |
1256 | } | 1269 | } |