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