diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/util/resolver_api.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/util/resolver_api.c')
-rw-r--r-- | src/util/resolver_api.c | 1284 |
1 files changed, 645 insertions, 639 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 6c56786b0..a1e30bbd4 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -29,9 +29,11 @@ | |||
29 | #include "gnunet_resolver_service.h" | 29 | #include "gnunet_resolver_service.h" |
30 | #include "resolver.h" | 30 | #include "resolver.h" |
31 | 31 | ||
32 | #define LOG(kind, ...) GNUNET_log_from(kind, "util-resolver-api", __VA_ARGS__) | 32 | #define LOG(kind, ...) GNUNET_log_from (kind, "util-resolver-api", __VA_ARGS__) |
33 | 33 | ||
34 | #define LOG_STRERROR(kind, syscall) GNUNET_log_from_strerror(kind, "util-resolver-api", syscall) | 34 | #define LOG_STRERROR(kind, syscall) GNUNET_log_from_strerror (kind, \ |
35 | "util-resolver-api", \ | ||
36 | syscall) | ||
35 | 37 | ||
36 | /** | 38 | /** |
37 | * Maximum supported length for a hostname | 39 | * Maximum supported length for a hostname |
@@ -97,7 +99,8 @@ static struct GNUNET_SCHEDULER_Task *s_task; | |||
97 | * the request prior to the timeout or successful execution. Also | 99 | * the request prior to the timeout or successful execution. Also |
98 | * used to track our internal state for the request. | 100 | * used to track our internal state for the request. |
99 | */ | 101 | */ |
100 | struct GNUNET_RESOLVER_RequestHandle { | 102 | struct GNUNET_RESOLVER_RequestHandle |
103 | { | ||
101 | /** | 104 | /** |
102 | * Next entry in DLL of requests. | 105 | * Next entry in DLL of requests. |
103 | */ | 106 | */ |
@@ -184,61 +187,63 @@ struct GNUNET_RESOLVER_RequestHandle { | |||
184 | * #GNUNET_SYSERR otherwise. | 187 | * #GNUNET_SYSERR otherwise. |
185 | */ | 188 | */ |
186 | static int | 189 | static int |
187 | check_config() | 190 | check_config () |
188 | { | 191 | { |
189 | char *hostname; | 192 | char *hostname; |
190 | struct sockaddr_in v4; | 193 | struct sockaddr_in v4; |
191 | struct sockaddr_in6 v6; | 194 | struct sockaddr_in6 v6; |
192 | 195 | ||
193 | if (GNUNET_OK == | 196 | if (GNUNET_OK == |
194 | GNUNET_CONFIGURATION_have_value(resolver_cfg, | 197 | GNUNET_CONFIGURATION_have_value (resolver_cfg, |
195 | "resolver", | 198 | "resolver", |
196 | "UNIXPATH")) | 199 | "UNIXPATH")) |
197 | return GNUNET_OK; | 200 | return GNUNET_OK; |
198 | memset(&v4, 0, sizeof(v4)); | 201 | memset (&v4, 0, sizeof(v4)); |
199 | v4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | 202 | v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
200 | v4.sin_family = AF_INET; | 203 | v4.sin_family = AF_INET; |
201 | #if HAVE_SOCKADDR_IN_SIN_LEN | 204 | #if HAVE_SOCKADDR_IN_SIN_LEN |
202 | v4.sin_len = sizeof(v4); | 205 | v4.sin_len = sizeof(v4); |
203 | #endif | 206 | #endif |
204 | memset(&v6, 0, sizeof(v6)); | 207 | memset (&v6, 0, sizeof(v6)); |
205 | v6.sin6_family = AF_INET6; | 208 | v6.sin6_family = AF_INET6; |
206 | #if HAVE_SOCKADDR_IN_SIN_LEN | 209 | #if HAVE_SOCKADDR_IN_SIN_LEN |
207 | v6.sin6_len = sizeof(v6); | 210 | v6.sin6_len = sizeof(v6); |
208 | #endif | 211 | #endif |
209 | if (GNUNET_OK != | 212 | if (GNUNET_OK != |
210 | GNUNET_CONFIGURATION_get_value_string(resolver_cfg, | 213 | GNUNET_CONFIGURATION_get_value_string (resolver_cfg, |
211 | "resolver", | 214 | "resolver", |
212 | "HOSTNAME", | 215 | "HOSTNAME", |
213 | &hostname)) | 216 | &hostname)) |
214 | { | 217 | { |
215 | LOG(GNUNET_ERROR_TYPE_INFO, | 218 | LOG (GNUNET_ERROR_TYPE_INFO, |
216 | _("Missing `%s' for `%s' in configuration, DNS resolution will be unavailable.\n"), | 219 | _ ( |
217 | "HOSTNAME", | 220 | "Missing `%s' for `%s' in configuration, DNS resolution will be unavailable.\n"), |
218 | "resolver"); | 221 | "HOSTNAME", |
219 | return GNUNET_SYSERR; | 222 | "resolver"); |
220 | } | 223 | return GNUNET_SYSERR; |
221 | if ((1 == inet_pton(AF_INET, hostname, &v4)) || | 224 | } |
222 | (1 == inet_pton(AF_INET6, hostname, &v6))) | 225 | if ((1 == inet_pton (AF_INET, hostname, &v4)) || |
223 | { | 226 | (1 == inet_pton (AF_INET6, hostname, &v6))) |
224 | GNUNET_free(hostname); | 227 | { |
225 | return GNUNET_OK; | 228 | GNUNET_free (hostname); |
226 | } | 229 | return GNUNET_OK; |
230 | } | ||
227 | for (unsigned int i = 0; | 231 | for (unsigned int i = 0; |
228 | NULL != loopback[i]; | 232 | NULL != loopback[i]; |
229 | i++) | 233 | i++) |
230 | if (0 == strcasecmp(loopback[i], | 234 | if (0 == strcasecmp (loopback[i], |
231 | hostname)) | 235 | hostname)) |
232 | { | 236 | { |
233 | GNUNET_free(hostname); | 237 | GNUNET_free (hostname); |
234 | return GNUNET_OK; | 238 | return GNUNET_OK; |
235 | } | 239 | } |
236 | LOG(GNUNET_ERROR_TYPE_INFO, | 240 | LOG (GNUNET_ERROR_TYPE_INFO, |
237 | _("Missing `%s' or numeric IP address for `%s' of `%s' in configuration, DNS resolution will be unavailable.\n"), | 241 | _ ( |
238 | "localhost", | 242 | "Missing `%s' or numeric IP address for `%s' of `%s' in configuration, DNS resolution will be unavailable.\n"), |
239 | "HOSTNAME", | 243 | "localhost", |
240 | "resolver"); | 244 | "HOSTNAME", |
241 | GNUNET_free(hostname); | 245 | "resolver"); |
246 | GNUNET_free (hostname); | ||
242 | return GNUNET_SYSERR; | 247 | return GNUNET_SYSERR; |
243 | } | 248 | } |
244 | 249 | ||
@@ -249,9 +254,9 @@ check_config() | |||
249 | * @param cfg configuration to use | 254 | * @param cfg configuration to use |
250 | */ | 255 | */ |
251 | void | 256 | void |
252 | GNUNET_RESOLVER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) | 257 | GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
253 | { | 258 | { |
254 | GNUNET_assert(NULL != cfg); | 259 | GNUNET_assert (NULL != cfg); |
255 | backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 260 | backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
256 | resolver_cfg = cfg; | 261 | resolver_cfg = cfg; |
257 | } | 262 | } |
@@ -261,35 +266,35 @@ GNUNET_RESOLVER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
261 | * Destroy the connection to the resolver service. | 266 | * Destroy the connection to the resolver service. |
262 | */ | 267 | */ |
263 | void | 268 | void |
264 | GNUNET_RESOLVER_disconnect() | 269 | GNUNET_RESOLVER_disconnect () |
265 | { | 270 | { |
266 | struct GNUNET_RESOLVER_RequestHandle *rh; | 271 | struct GNUNET_RESOLVER_RequestHandle *rh; |
267 | 272 | ||
268 | while (NULL != (rh = req_head)) | 273 | while (NULL != (rh = req_head)) |
269 | { | 274 | { |
270 | GNUNET_assert(GNUNET_SYSERR == rh->was_transmitted); | 275 | GNUNET_assert (GNUNET_SYSERR == rh->was_transmitted); |
271 | GNUNET_CONTAINER_DLL_remove(req_head, | 276 | GNUNET_CONTAINER_DLL_remove (req_head, |
272 | req_tail, | 277 | req_tail, |
273 | rh); | 278 | rh); |
274 | GNUNET_free(rh); | 279 | GNUNET_free (rh); |
275 | } | 280 | } |
276 | if (NULL != mq) | 281 | if (NULL != mq) |
277 | { | 282 | { |
278 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 283 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
279 | "Disconnecting from DNS service\n"); | 284 | "Disconnecting from DNS service\n"); |
280 | GNUNET_MQ_destroy(mq); | 285 | GNUNET_MQ_destroy (mq); |
281 | mq = NULL; | 286 | mq = NULL; |
282 | } | 287 | } |
283 | if (NULL != r_task) | 288 | if (NULL != r_task) |
284 | { | 289 | { |
285 | GNUNET_SCHEDULER_cancel(r_task); | 290 | GNUNET_SCHEDULER_cancel (r_task); |
286 | r_task = NULL; | 291 | r_task = NULL; |
287 | } | 292 | } |
288 | if (NULL != s_task) | 293 | if (NULL != s_task) |
289 | { | 294 | { |
290 | GNUNET_SCHEDULER_cancel(s_task); | 295 | GNUNET_SCHEDULER_cancel (s_task); |
291 | s_task = NULL; | 296 | s_task = NULL; |
292 | } | 297 | } |
293 | } | 298 | } |
294 | 299 | ||
295 | 300 | ||
@@ -297,11 +302,11 @@ GNUNET_RESOLVER_disconnect() | |||
297 | * Task executed on system shutdown. | 302 | * Task executed on system shutdown. |
298 | */ | 303 | */ |
299 | static void | 304 | static void |
300 | shutdown_task(void *cls) | 305 | shutdown_task (void *cls) |
301 | { | 306 | { |
302 | (void)cls; | 307 | (void) cls; |
303 | s_task = NULL; | 308 | s_task = NULL; |
304 | GNUNET_RESOLVER_disconnect(); | 309 | GNUNET_RESOLVER_disconnect (); |
305 | backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 310 | backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
306 | } | 311 | } |
307 | 312 | ||
@@ -310,7 +315,7 @@ shutdown_task(void *cls) | |||
310 | * Consider disconnecting if we have no further requests pending. | 315 | * Consider disconnecting if we have no further requests pending. |
311 | */ | 316 | */ |
312 | static void | 317 | static void |
313 | check_disconnect() | 318 | check_disconnect () |
314 | { | 319 | { |
315 | for (struct GNUNET_RESOLVER_RequestHandle *rh = req_head; | 320 | for (struct GNUNET_RESOLVER_RequestHandle *rh = req_head; |
316 | NULL != rh; | 321 | NULL != rh; |
@@ -318,15 +323,15 @@ check_disconnect() | |||
318 | if (GNUNET_SYSERR != rh->was_transmitted) | 323 | if (GNUNET_SYSERR != rh->was_transmitted) |
319 | return; | 324 | return; |
320 | if (NULL != r_task) | 325 | if (NULL != r_task) |
321 | { | 326 | { |
322 | GNUNET_SCHEDULER_cancel(r_task); | 327 | GNUNET_SCHEDULER_cancel (r_task); |
323 | r_task = NULL; | 328 | r_task = NULL; |
324 | } | 329 | } |
325 | if (NULL != s_task) | 330 | if (NULL != s_task) |
326 | return; | 331 | return; |
327 | s_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MILLISECONDS, | 332 | s_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, |
328 | &shutdown_task, | 333 | &shutdown_task, |
329 | NULL); | 334 | NULL); |
330 | } | 335 | } |
331 | 336 | ||
332 | 337 | ||
@@ -339,49 +344,49 @@ check_disconnect() | |||
339 | * @return address as a string, NULL on error | 344 | * @return address as a string, NULL on error |
340 | */ | 345 | */ |
341 | static char * | 346 | static char * |
342 | no_resolve(int af, | 347 | no_resolve (int af, |
343 | const void *ip, | 348 | const void *ip, |
344 | socklen_t ip_len) | 349 | socklen_t ip_len) |
345 | { | 350 | { |
346 | char buf[INET6_ADDRSTRLEN]; | 351 | char buf[INET6_ADDRSTRLEN]; |
347 | 352 | ||
348 | switch (af) | 353 | switch (af) |
354 | { | ||
355 | case AF_INET: | ||
356 | if (ip_len != sizeof(struct in_addr)) | ||
357 | return NULL; | ||
358 | if (NULL == | ||
359 | inet_ntop (AF_INET, | ||
360 | ip, | ||
361 | buf, | ||
362 | sizeof(buf))) | ||
349 | { | 363 | { |
350 | case AF_INET: | 364 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, |
351 | if (ip_len != sizeof(struct in_addr)) | 365 | "inet_ntop"); |
352 | return NULL; | 366 | return NULL; |
353 | if (NULL == | 367 | } |
354 | inet_ntop(AF_INET, | 368 | break; |
355 | ip, | ||
356 | buf, | ||
357 | sizeof(buf))) | ||
358 | { | ||
359 | LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, | ||
360 | "inet_ntop"); | ||
361 | return NULL; | ||
362 | } | ||
363 | break; | ||
364 | |||
365 | case AF_INET6: | ||
366 | if (ip_len != sizeof(struct in6_addr)) | ||
367 | return NULL; | ||
368 | if (NULL == | ||
369 | inet_ntop(AF_INET6, | ||
370 | ip, | ||
371 | buf, | ||
372 | sizeof(buf))) | ||
373 | { | ||
374 | LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, | ||
375 | "inet_ntop"); | ||
376 | return NULL; | ||
377 | } | ||
378 | break; | ||
379 | 369 | ||
380 | default: | 370 | case AF_INET6: |
381 | GNUNET_break(0); | 371 | if (ip_len != sizeof(struct in6_addr)) |
372 | return NULL; | ||
373 | if (NULL == | ||
374 | inet_ntop (AF_INET6, | ||
375 | ip, | ||
376 | buf, | ||
377 | sizeof(buf))) | ||
378 | { | ||
379 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, | ||
380 | "inet_ntop"); | ||
382 | return NULL; | 381 | return NULL; |
383 | } | 382 | } |
384 | return GNUNET_strdup(buf); | 383 | break; |
384 | |||
385 | default: | ||
386 | GNUNET_break (0); | ||
387 | return NULL; | ||
388 | } | ||
389 | return GNUNET_strdup (buf); | ||
385 | } | 390 | } |
386 | 391 | ||
387 | 392 | ||
@@ -389,7 +394,7 @@ no_resolve(int af, | |||
389 | * Adjust exponential back-off and reconnect to the service. | 394 | * Adjust exponential back-off and reconnect to the service. |
390 | */ | 395 | */ |
391 | static void | 396 | static void |
392 | reconnect(void); | 397 | reconnect (void); |
393 | 398 | ||
394 | 399 | ||
395 | /** | 400 | /** |
@@ -401,16 +406,16 @@ reconnect(void); | |||
401 | * @param error error code | 406 | * @param error error code |
402 | */ | 407 | */ |
403 | static void | 408 | static void |
404 | mq_error_handler(void *cls, | 409 | mq_error_handler (void *cls, |
405 | enum GNUNET_MQ_Error error) | 410 | enum GNUNET_MQ_Error error) |
406 | { | 411 | { |
407 | (void)cls; | 412 | (void) cls; |
408 | GNUNET_MQ_destroy(mq); | 413 | GNUNET_MQ_destroy (mq); |
409 | mq = NULL; | 414 | mq = NULL; |
410 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 415 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
411 | "MQ error %d, reconnecting\n", | 416 | "MQ error %d, reconnecting\n", |
412 | error); | 417 | error); |
413 | reconnect(); | 418 | reconnect (); |
414 | } | 419 | } |
415 | 420 | ||
416 | 421 | ||
@@ -418,44 +423,44 @@ mq_error_handler(void *cls, | |||
418 | * Process pending requests to the resolver. | 423 | * Process pending requests to the resolver. |
419 | */ | 424 | */ |
420 | static void | 425 | static void |
421 | process_requests() | 426 | process_requests () |
422 | { | 427 | { |
423 | struct GNUNET_RESOLVER_GetMessage *msg; | 428 | struct GNUNET_RESOLVER_GetMessage *msg; |
424 | struct GNUNET_MQ_Envelope *env; | 429 | struct GNUNET_MQ_Envelope *env; |
425 | struct GNUNET_RESOLVER_RequestHandle *rh = req_head; | 430 | struct GNUNET_RESOLVER_RequestHandle *rh = req_head; |
426 | 431 | ||
427 | if (NULL == mq) | 432 | if (NULL == mq) |
428 | { | 433 | { |
429 | reconnect(); | 434 | reconnect (); |
430 | return; | 435 | return; |
431 | } | 436 | } |
432 | if (NULL == rh) | 437 | if (NULL == rh) |
433 | { | 438 | { |
434 | /* nothing to do, release socket really soon if there is nothing | 439 | /* nothing to do, release socket really soon if there is nothing |
435 | * else happening... */ | 440 | * else happening... */ |
436 | if (NULL == s_task) | 441 | if (NULL == s_task) |
437 | s_task = | 442 | s_task = |
438 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MILLISECONDS, | 443 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, |
439 | &shutdown_task, | 444 | &shutdown_task, |
440 | NULL); | 445 | NULL); |
441 | return; | 446 | return; |
442 | } | 447 | } |
443 | if (GNUNET_NO != rh->was_transmitted) | 448 | if (GNUNET_NO != rh->was_transmitted) |
444 | return; /* waiting for reply */ | 449 | return; /* waiting for reply */ |
445 | env = GNUNET_MQ_msg_extra(msg, | 450 | env = GNUNET_MQ_msg_extra (msg, |
446 | rh->data_len, | 451 | rh->data_len, |
447 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); | 452 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); |
448 | msg->direction = htonl(rh->direction); | 453 | msg->direction = htonl (rh->direction); |
449 | msg->af = htonl(rh->af); | 454 | msg->af = htonl (rh->af); |
450 | msg->client_id = rh->id; | 455 | msg->client_id = rh->id; |
451 | GNUNET_memcpy(&msg[1], | 456 | GNUNET_memcpy (&msg[1], |
452 | &rh[1], | 457 | &rh[1], |
453 | rh->data_len); | 458 | rh->data_len); |
454 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 459 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
455 | "Transmitting DNS resolution request (ID %u) to DNS service\n", | 460 | "Transmitting DNS resolution request (ID %u) to DNS service\n", |
456 | rh->id); | 461 | rh->id); |
457 | GNUNET_MQ_send(mq, | 462 | GNUNET_MQ_send (mq, |
458 | env); | 463 | env); |
459 | rh->was_transmitted = GNUNET_YES; | 464 | rh->was_transmitted = GNUNET_YES; |
460 | } | 465 | } |
461 | 466 | ||
@@ -467,11 +472,11 @@ process_requests() | |||
467 | * @param msg message with the hostname | 472 | * @param msg message with the hostname |
468 | */ | 473 | */ |
469 | static int | 474 | static int |
470 | check_response(void *cls, | 475 | check_response (void *cls, |
471 | const struct GNUNET_RESOLVER_ResponseMessage *msg) | 476 | const struct GNUNET_RESOLVER_ResponseMessage *msg) |
472 | { | 477 | { |
473 | (void)cls; | 478 | (void) cls; |
474 | (void)msg; | 479 | (void) msg; |
475 | 480 | ||
476 | /* implemented in #handle_response() for now */ | 481 | /* implemented in #handle_response() for now */ |
477 | return GNUNET_OK; | 482 | return GNUNET_OK; |
@@ -487,8 +492,8 @@ check_response(void *cls, | |||
487 | * @param msg message with the response | 492 | * @param msg message with the response |
488 | */ | 493 | */ |
489 | static void | 494 | static void |
490 | handle_response(void *cls, | 495 | handle_response (void *cls, |
491 | const struct GNUNET_RESOLVER_ResponseMessage *msg) | 496 | const struct GNUNET_RESOLVER_ResponseMessage *msg) |
492 | { | 497 | { |
493 | struct GNUNET_RESOLVER_RequestHandle *rh = req_head; | 498 | struct GNUNET_RESOLVER_RequestHandle *rh = req_head; |
494 | uint16_t size; | 499 | uint16_t size; |
@@ -496,141 +501,142 @@ handle_response(void *cls, | |||
496 | uint32_t client_request_id = msg->client_id; | 501 | uint32_t client_request_id = msg->client_id; |
497 | 502 | ||
498 | for (; rh != NULL; rh = rh->next) | 503 | for (; rh != NULL; rh = rh->next) |
499 | { | 504 | { |
500 | if (rh->id == client_request_id) | 505 | if (rh->id == client_request_id) |
501 | break; | 506 | break; |
502 | } | 507 | } |
503 | 508 | ||
504 | (void)cls; | 509 | (void) cls; |
505 | if (NULL == rh) | 510 | if (NULL == rh) |
506 | { | 511 | { |
507 | /* Resolver service sent extra replies to query (after terminator)? Bad! */ | 512 | /* Resolver service sent extra replies to query (after terminator)? Bad! */ |
508 | GNUNET_break(0); | 513 | GNUNET_break (0); |
509 | GNUNET_MQ_destroy(mq); | 514 | GNUNET_MQ_destroy (mq); |
510 | mq = NULL; | 515 | mq = NULL; |
511 | reconnect(); | 516 | reconnect (); |
512 | return; | 517 | return; |
513 | } | 518 | } |
514 | size = ntohs(msg->header.size); | 519 | size = ntohs (msg->header.size); |
515 | if (size == sizeof(struct GNUNET_RESOLVER_ResponseMessage)) | 520 | if (size == sizeof(struct GNUNET_RESOLVER_ResponseMessage)) |
521 | { | ||
522 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
523 | "Received empty response from DNS service\n"); | ||
524 | /* message contains not data, just header; end of replies */ | ||
525 | /* check if request was canceled */ | ||
526 | if (GNUNET_SYSERR != rh->was_transmitted) | ||
516 | { | 527 | { |
517 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 528 | /* no reverse lookup was successful, return IP as string */ |
518 | "Received empty response from DNS service\n"); | 529 | if (NULL != rh->name_callback) |
519 | /* message contains not data, just header; end of replies */ | 530 | { |
520 | /* check if request was canceled */ | 531 | if (GNUNET_NO == rh->received_response) |
521 | if (GNUNET_SYSERR != rh->was_transmitted) | ||
522 | { | 532 | { |
523 | /* no reverse lookup was successful, return IP as string */ | 533 | nret = no_resolve (rh->af, |
524 | if (NULL != rh->name_callback) | 534 | &rh[1], |
525 | { | 535 | rh->data_len); |
526 | if (GNUNET_NO == rh->received_response) | 536 | rh->name_callback (rh->cls, nret); |
527 | { | 537 | GNUNET_free (nret); |
528 | nret = no_resolve(rh->af, | ||
529 | &rh[1], | ||
530 | rh->data_len); | ||
531 | rh->name_callback(rh->cls, nret); | ||
532 | GNUNET_free(nret); | ||
533 | } | ||
534 | /* finally, make termination call */ | ||
535 | if (GNUNET_SYSERR != rh->was_transmitted) | ||
536 | rh->name_callback(rh->cls, | ||
537 | NULL); | ||
538 | } | ||
539 | if ((NULL != rh->addr_callback) && | ||
540 | (GNUNET_SYSERR != rh->was_transmitted)) | ||
541 | rh->addr_callback(rh->cls, | ||
542 | NULL, | ||
543 | 0); | ||
544 | } | 538 | } |
545 | rh->was_transmitted = GNUNET_NO; | 539 | /* finally, make termination call */ |
546 | GNUNET_RESOLVER_request_cancel(rh); | 540 | if (GNUNET_SYSERR != rh->was_transmitted) |
547 | process_requests(); | 541 | rh->name_callback (rh->cls, |
548 | return; | 542 | NULL); |
543 | } | ||
544 | if ((NULL != rh->addr_callback) && | ||
545 | (GNUNET_SYSERR != rh->was_transmitted)) | ||
546 | rh->addr_callback (rh->cls, | ||
547 | NULL, | ||
548 | 0); | ||
549 | } | 549 | } |
550 | rh->was_transmitted = GNUNET_NO; | ||
551 | GNUNET_RESOLVER_request_cancel (rh); | ||
552 | process_requests (); | ||
553 | return; | ||
554 | } | ||
550 | /* return reverse lookup results to caller */ | 555 | /* return reverse lookup results to caller */ |
551 | if (NULL != rh->name_callback) | 556 | if (NULL != rh->name_callback) |
552 | { | 557 | { |
553 | const char *hostname; | 558 | const char *hostname; |
554 | 559 | ||
555 | hostname = (const char *)&msg[1]; | 560 | hostname = (const char *) &msg[1]; |
556 | if (hostname[size - sizeof(struct GNUNET_RESOLVER_ResponseMessage) - 1] != '\0') | 561 | if (hostname[size - sizeof(struct GNUNET_RESOLVER_ResponseMessage) - 1] != |
557 | { | 562 | '\0') |
558 | GNUNET_break(0); | 563 | { |
559 | if (GNUNET_SYSERR != rh->was_transmitted) | 564 | GNUNET_break (0); |
560 | rh->name_callback(rh->cls, | 565 | if (GNUNET_SYSERR != rh->was_transmitted) |
561 | NULL); | 566 | rh->name_callback (rh->cls, |
562 | rh->was_transmitted = GNUNET_NO; | 567 | NULL); |
563 | GNUNET_RESOLVER_request_cancel(rh); | 568 | rh->was_transmitted = GNUNET_NO; |
564 | GNUNET_MQ_destroy(mq); | 569 | GNUNET_RESOLVER_request_cancel (rh); |
565 | mq = NULL; | 570 | GNUNET_MQ_destroy (mq); |
566 | reconnect(); | 571 | mq = NULL; |
567 | return; | 572 | reconnect (); |
568 | } | 573 | return; |
569 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
570 | "Resolver returns `%s' for IP `%s'.\n", | ||
571 | hostname, | ||
572 | GNUNET_a2s((const void *)&rh[1], | ||
573 | rh->data_len)); | ||
574 | if (rh->was_transmitted != GNUNET_SYSERR) | ||
575 | rh->name_callback(rh->cls, | ||
576 | hostname); | ||
577 | rh->received_response = GNUNET_YES; | ||
578 | } | 574 | } |
575 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
576 | "Resolver returns `%s' for IP `%s'.\n", | ||
577 | hostname, | ||
578 | GNUNET_a2s ((const void *) &rh[1], | ||
579 | rh->data_len)); | ||
580 | if (rh->was_transmitted != GNUNET_SYSERR) | ||
581 | rh->name_callback (rh->cls, | ||
582 | hostname); | ||
583 | rh->received_response = GNUNET_YES; | ||
584 | } | ||
579 | /* return lookup results to caller */ | 585 | /* return lookup results to caller */ |
580 | if (NULL != rh->addr_callback) | 586 | if (NULL != rh->addr_callback) |
587 | { | ||
588 | struct sockaddr_in v4; | ||
589 | struct sockaddr_in6 v6; | ||
590 | const struct sockaddr *sa; | ||
591 | socklen_t salen; | ||
592 | const void *ip; | ||
593 | size_t ip_len; | ||
594 | |||
595 | ip = &msg[1]; | ||
596 | ip_len = size - sizeof(struct GNUNET_RESOLVER_ResponseMessage); | ||
597 | if (ip_len == sizeof(struct in_addr)) | ||
581 | { | 598 | { |
582 | struct sockaddr_in v4; | 599 | memset (&v4, 0, sizeof(v4)); |
583 | struct sockaddr_in6 v6; | 600 | v4.sin_family = AF_INET; |
584 | const struct sockaddr *sa; | 601 | v4.sin_addr = *(struct in_addr*) ip; |
585 | socklen_t salen; | ||
586 | const void *ip; | ||
587 | size_t ip_len; | ||
588 | |||
589 | ip = &msg[1]; | ||
590 | ip_len = size - sizeof(struct GNUNET_RESOLVER_ResponseMessage); | ||
591 | if (ip_len == sizeof(struct in_addr)) | ||
592 | { | ||
593 | memset(&v4, 0, sizeof(v4)); | ||
594 | v4.sin_family = AF_INET; | ||
595 | v4.sin_addr = *(struct in_addr*)ip; | ||
596 | #if HAVE_SOCKADDR_IN_SIN_LEN | 602 | #if HAVE_SOCKADDR_IN_SIN_LEN |
597 | v4.sin_len = sizeof(v4); | 603 | v4.sin_len = sizeof(v4); |
598 | #endif | 604 | #endif |
599 | salen = sizeof(v4); | 605 | salen = sizeof(v4); |
600 | sa = (const struct sockaddr *)&v4; | 606 | sa = (const struct sockaddr *) &v4; |
601 | } | 607 | } |
602 | else if (ip_len == sizeof(struct in6_addr)) | 608 | else if (ip_len == sizeof(struct in6_addr)) |
603 | { | 609 | { |
604 | memset(&v6, 0, sizeof(v6)); | 610 | memset (&v6, 0, sizeof(v6)); |
605 | v6.sin6_family = AF_INET6; | 611 | v6.sin6_family = AF_INET6; |
606 | v6.sin6_addr = *(struct in6_addr*)ip; | 612 | v6.sin6_addr = *(struct in6_addr*) ip; |
607 | #if HAVE_SOCKADDR_IN_SIN_LEN | 613 | #if HAVE_SOCKADDR_IN_SIN_LEN |
608 | v6.sin6_len = sizeof(v6); | 614 | v6.sin6_len = sizeof(v6); |
609 | #endif | 615 | #endif |
610 | salen = sizeof(v6); | 616 | salen = sizeof(v6); |
611 | sa = (const struct sockaddr *)&v6; | 617 | sa = (const struct sockaddr *) &v6; |
612 | } | 618 | } |
613 | else | 619 | else |
614 | { | 620 | { |
615 | GNUNET_break(0); | 621 | GNUNET_break (0); |
616 | if (GNUNET_SYSERR != rh->was_transmitted) | ||
617 | rh->addr_callback(rh->cls, | ||
618 | NULL, | ||
619 | 0); | ||
620 | rh->was_transmitted = GNUNET_NO; | ||
621 | GNUNET_RESOLVER_request_cancel(rh); | ||
622 | GNUNET_MQ_destroy(mq); | ||
623 | mq = NULL; | ||
624 | reconnect(); | ||
625 | return; | ||
626 | } | ||
627 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
628 | "Received IP from DNS service\n"); | ||
629 | if (GNUNET_SYSERR != rh->was_transmitted) | 622 | if (GNUNET_SYSERR != rh->was_transmitted) |
630 | rh->addr_callback(rh->cls, | 623 | rh->addr_callback (rh->cls, |
631 | sa, | 624 | NULL, |
632 | salen); | 625 | 0); |
626 | rh->was_transmitted = GNUNET_NO; | ||
627 | GNUNET_RESOLVER_request_cancel (rh); | ||
628 | GNUNET_MQ_destroy (mq); | ||
629 | mq = NULL; | ||
630 | reconnect (); | ||
631 | return; | ||
633 | } | 632 | } |
633 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
634 | "Received IP from DNS service\n"); | ||
635 | if (GNUNET_SYSERR != rh->was_transmitted) | ||
636 | rh->addr_callback (rh->cls, | ||
637 | sa, | ||
638 | salen); | ||
639 | } | ||
634 | } | 640 | } |
635 | 641 | ||
636 | 642 | ||
@@ -642,7 +648,7 @@ handle_response(void *cls, | |||
642 | * @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request | 648 | * @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request |
643 | */ | 649 | */ |
644 | static void | 650 | static void |
645 | numeric_resolution(void *cls) | 651 | numeric_resolution (void *cls) |
646 | { | 652 | { |
647 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; | 653 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; |
648 | struct sockaddr_in v4; | 654 | struct sockaddr_in v4; |
@@ -650,63 +656,63 @@ numeric_resolution(void *cls) | |||
650 | const char *hostname; | 656 | const char *hostname; |
651 | 657 | ||
652 | rh->task = NULL; | 658 | rh->task = NULL; |
653 | memset(&v4, 0, sizeof(v4)); | 659 | memset (&v4, 0, sizeof(v4)); |
654 | v4.sin_family = AF_INET; | 660 | v4.sin_family = AF_INET; |
655 | #if HAVE_SOCKADDR_IN_SIN_LEN | 661 | #if HAVE_SOCKADDR_IN_SIN_LEN |
656 | v4.sin_len = sizeof(v4); | 662 | v4.sin_len = sizeof(v4); |
657 | #endif | 663 | #endif |
658 | memset(&v6, 0, sizeof(v6)); | 664 | memset (&v6, 0, sizeof(v6)); |
659 | v6.sin6_family = AF_INET6; | 665 | v6.sin6_family = AF_INET6; |
660 | #if HAVE_SOCKADDR_IN_SIN_LEN | 666 | #if HAVE_SOCKADDR_IN_SIN_LEN |
661 | v6.sin6_len = sizeof(v6); | 667 | v6.sin6_len = sizeof(v6); |
662 | #endif | 668 | #endif |
663 | hostname = (const char *)&rh[1]; | 669 | hostname = (const char *) &rh[1]; |
664 | if (((rh->af == AF_UNSPEC) || | 670 | if (((rh->af == AF_UNSPEC) || |
665 | (rh->af == AF_INET)) && | 671 | (rh->af == AF_INET)) && |
666 | (1 == inet_pton(AF_INET, | 672 | (1 == inet_pton (AF_INET, |
667 | hostname, | 673 | hostname, |
668 | &v4.sin_addr))) | 674 | &v4.sin_addr))) |
675 | { | ||
676 | rh->addr_callback (rh->cls, | ||
677 | (const struct sockaddr *) &v4, | ||
678 | sizeof(v4)); | ||
679 | if ((rh->af == AF_UNSPEC) && | ||
680 | (GNUNET_SYSERR != rh->was_transmitted) && | ||
681 | (1 == inet_pton (AF_INET6, | ||
682 | hostname, | ||
683 | &v6.sin6_addr))) | ||
669 | { | 684 | { |
670 | rh->addr_callback(rh->cls, | 685 | /* this can happen on some systems IF "hostname" is "localhost" */ |
671 | (const struct sockaddr *)&v4, | 686 | rh->addr_callback (rh->cls, |
672 | sizeof(v4)); | 687 | (const struct sockaddr *) &v6, |
673 | if ((rh->af == AF_UNSPEC) && | 688 | sizeof(v6)); |
674 | (GNUNET_SYSERR != rh->was_transmitted) && | ||
675 | (1 == inet_pton(AF_INET6, | ||
676 | hostname, | ||
677 | &v6.sin6_addr))) | ||
678 | { | ||
679 | /* this can happen on some systems IF "hostname" is "localhost" */ | ||
680 | rh->addr_callback(rh->cls, | ||
681 | (const struct sockaddr *)&v6, | ||
682 | sizeof(v6)); | ||
683 | } | ||
684 | if (GNUNET_SYSERR != rh->was_transmitted) | ||
685 | rh->addr_callback(rh->cls, | ||
686 | NULL, | ||
687 | 0); | ||
688 | GNUNET_free(rh); | ||
689 | return; | ||
690 | } | 689 | } |
690 | if (GNUNET_SYSERR != rh->was_transmitted) | ||
691 | rh->addr_callback (rh->cls, | ||
692 | NULL, | ||
693 | 0); | ||
694 | GNUNET_free (rh); | ||
695 | return; | ||
696 | } | ||
691 | if (((rh->af == AF_UNSPEC) || | 697 | if (((rh->af == AF_UNSPEC) || |
692 | (rh->af == AF_INET6)) && | 698 | (rh->af == AF_INET6)) && |
693 | (1 == inet_pton(AF_INET6, | 699 | (1 == inet_pton (AF_INET6, |
694 | hostname, | 700 | hostname, |
695 | &v6.sin6_addr))) | 701 | &v6.sin6_addr))) |
696 | { | 702 | { |
697 | rh->addr_callback(rh->cls, | 703 | rh->addr_callback (rh->cls, |
698 | (const struct sockaddr *)&v6, | 704 | (const struct sockaddr *) &v6, |
699 | sizeof(v6)); | 705 | sizeof(v6)); |
700 | if (GNUNET_SYSERR != rh->was_transmitted) | 706 | if (GNUNET_SYSERR != rh->was_transmitted) |
701 | rh->addr_callback(rh->cls, | 707 | rh->addr_callback (rh->cls, |
702 | NULL, | 708 | NULL, |
703 | 0); | 709 | 0); |
704 | GNUNET_free(rh); | 710 | GNUNET_free (rh); |
705 | return; | 711 | return; |
706 | } | 712 | } |
707 | /* why are we here? this task should not have been scheduled! */ | 713 | /* why are we here? this task should not have been scheduled! */ |
708 | GNUNET_assert(0); | 714 | GNUNET_assert (0); |
709 | GNUNET_free(rh); | 715 | GNUNET_free (rh); |
710 | } | 716 | } |
711 | 717 | ||
712 | 718 | ||
@@ -718,61 +724,61 @@ numeric_resolution(void *cls) | |||
718 | * @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request | 724 | * @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request |
719 | */ | 725 | */ |
720 | static void | 726 | static void |
721 | loopback_resolution(void *cls) | 727 | loopback_resolution (void *cls) |
722 | { | 728 | { |
723 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; | 729 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; |
724 | struct sockaddr_in v4; | 730 | struct sockaddr_in v4; |
725 | struct sockaddr_in6 v6; | 731 | struct sockaddr_in6 v6; |
726 | 732 | ||
727 | rh->task = NULL; | 733 | rh->task = NULL; |
728 | memset(&v4, 0, sizeof(v4)); | 734 | memset (&v4, 0, sizeof(v4)); |
729 | v4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | 735 | v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
730 | v4.sin_family = AF_INET; | 736 | v4.sin_family = AF_INET; |
731 | #if HAVE_SOCKADDR_IN_SIN_LEN | 737 | #if HAVE_SOCKADDR_IN_SIN_LEN |
732 | v4.sin_len = sizeof(v4); | 738 | v4.sin_len = sizeof(v4); |
733 | #endif | 739 | #endif |
734 | memset(&v6, 0, sizeof(v6)); | 740 | memset (&v6, 0, sizeof(v6)); |
735 | v6.sin6_family = AF_INET6; | 741 | v6.sin6_family = AF_INET6; |
736 | #if HAVE_SOCKADDR_IN_SIN_LEN | 742 | #if HAVE_SOCKADDR_IN_SIN_LEN |
737 | v6.sin6_len = sizeof(v6); | 743 | v6.sin6_len = sizeof(v6); |
738 | #endif | 744 | #endif |
739 | v6.sin6_addr = in6addr_loopback; | 745 | v6.sin6_addr = in6addr_loopback; |
740 | switch (rh->af) | 746 | switch (rh->af) |
741 | { | 747 | { |
742 | case AF_INET: | 748 | case AF_INET: |
743 | rh->addr_callback(rh->cls, | 749 | rh->addr_callback (rh->cls, |
744 | (const struct sockaddr *)&v4, | 750 | (const struct sockaddr *) &v4, |
745 | sizeof(v4)); | 751 | sizeof(v4)); |
746 | break; | 752 | break; |
747 | 753 | ||
748 | case AF_INET6: | 754 | case AF_INET6: |
749 | rh->addr_callback(rh->cls, | 755 | rh->addr_callback (rh->cls, |
750 | (const struct sockaddr *)&v6, | 756 | (const struct sockaddr *) &v6, |
751 | sizeof(v6)); | 757 | sizeof(v6)); |
752 | break; | 758 | break; |
753 | 759 | ||
754 | case AF_UNSPEC: | 760 | case AF_UNSPEC: |
755 | rh->addr_callback(rh->cls, | 761 | rh->addr_callback (rh->cls, |
756 | (const struct sockaddr *)&v6, | 762 | (const struct sockaddr *) &v6, |
757 | sizeof(v6)); | 763 | sizeof(v6)); |
758 | rh->addr_callback(rh->cls, | 764 | rh->addr_callback (rh->cls, |
759 | (const struct sockaddr *)&v4, | 765 | (const struct sockaddr *) &v4, |
760 | sizeof(v4)); | 766 | sizeof(v4)); |
761 | 767 | ||
762 | break; | 768 | break; |
763 | 769 | ||
764 | default: | 770 | default: |
765 | GNUNET_break(0); | 771 | GNUNET_break (0); |
766 | break; | 772 | break; |
767 | } | 773 | } |
768 | if (GNUNET_SYSERR != rh->was_transmitted) | 774 | if (GNUNET_SYSERR != rh->was_transmitted) |
769 | rh->addr_callback(rh->cls, | 775 | rh->addr_callback (rh->cls, |
770 | NULL, | 776 | NULL, |
771 | 0); | 777 | 0); |
772 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 778 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
773 | "Finished resolving hostname `%s'.\n", | 779 | "Finished resolving hostname `%s'.\n", |
774 | (const char *)&rh[1]); | 780 | (const char *) &rh[1]); |
775 | GNUNET_free(rh); | 781 | GNUNET_free (rh); |
776 | } | 782 | } |
777 | 783 | ||
778 | 784 | ||
@@ -782,35 +788,35 @@ loopback_resolution(void *cls) | |||
782 | * @param cls NULL | 788 | * @param cls NULL |
783 | */ | 789 | */ |
784 | static void | 790 | static void |
785 | reconnect_task(void *cls) | 791 | reconnect_task (void *cls) |
786 | { | 792 | { |
787 | struct GNUNET_MQ_MessageHandler handlers[] = { | 793 | struct GNUNET_MQ_MessageHandler handlers[] = { |
788 | GNUNET_MQ_hd_var_size(response, | 794 | GNUNET_MQ_hd_var_size (response, |
789 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE, | 795 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE, |
790 | struct GNUNET_RESOLVER_ResponseMessage, | 796 | struct GNUNET_RESOLVER_ResponseMessage, |
791 | NULL), | 797 | NULL), |
792 | GNUNET_MQ_handler_end() | 798 | GNUNET_MQ_handler_end () |
793 | }; | 799 | }; |
794 | 800 | ||
795 | (void)cls; | 801 | (void) cls; |
796 | r_task = NULL; | 802 | r_task = NULL; |
797 | if (NULL == req_head) | 803 | if (NULL == req_head) |
798 | return; /* no work pending */ | 804 | return; /* no work pending */ |
799 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 805 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
800 | "Trying to connect to DNS service\n"); | 806 | "Trying to connect to DNS service\n"); |
801 | mq = GNUNET_CLIENT_connect(resolver_cfg, | 807 | mq = GNUNET_CLIENT_connect (resolver_cfg, |
802 | "resolver", | 808 | "resolver", |
803 | handlers, | 809 | handlers, |
804 | &mq_error_handler, | 810 | &mq_error_handler, |
805 | NULL); | 811 | NULL); |
806 | if (NULL == mq) | 812 | if (NULL == mq) |
807 | { | 813 | { |
808 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 814 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
809 | "Failed to connect, will try again later\n"); | 815 | "Failed to connect, will try again later\n"); |
810 | reconnect(); | 816 | reconnect (); |
811 | return; | 817 | return; |
812 | } | 818 | } |
813 | process_requests(); | 819 | process_requests (); |
814 | } | 820 | } |
815 | 821 | ||
816 | 822 | ||
@@ -818,49 +824,49 @@ reconnect_task(void *cls) | |||
818 | * Adjust exponential back-off and reconnect to the service. | 824 | * Adjust exponential back-off and reconnect to the service. |
819 | */ | 825 | */ |
820 | static void | 826 | static void |
821 | reconnect() | 827 | reconnect () |
822 | { | 828 | { |
823 | struct GNUNET_RESOLVER_RequestHandle *rh; | 829 | struct GNUNET_RESOLVER_RequestHandle *rh; |
824 | 830 | ||
825 | if (NULL != r_task) | 831 | if (NULL != r_task) |
826 | return; | 832 | return; |
827 | GNUNET_assert(NULL == mq); | 833 | GNUNET_assert (NULL == mq); |
828 | if (NULL != (rh = req_head)) | 834 | if (NULL != (rh = req_head)) |
835 | { | ||
836 | switch (rh->was_transmitted) | ||
829 | { | 837 | { |
830 | switch (rh->was_transmitted) | 838 | case GNUNET_NO: |
831 | { | 839 | /* nothing more to do */ |
832 | case GNUNET_NO: | 840 | break; |
833 | /* nothing more to do */ | 841 | |
834 | break; | 842 | case GNUNET_YES: |
835 | 843 | /* disconnected, transmit again! */ | |
836 | case GNUNET_YES: | 844 | rh->was_transmitted = GNUNET_NO; |
837 | /* disconnected, transmit again! */ | 845 | break; |
838 | rh->was_transmitted = GNUNET_NO; | 846 | |
839 | break; | 847 | case GNUNET_SYSERR: |
840 | 848 | /* request was cancelled, remove entirely */ | |
841 | case GNUNET_SYSERR: | 849 | GNUNET_CONTAINER_DLL_remove (req_head, |
842 | /* request was cancelled, remove entirely */ | 850 | req_tail, |
843 | GNUNET_CONTAINER_DLL_remove(req_head, | 851 | rh); |
844 | req_tail, | 852 | GNUNET_free (rh); |
845 | rh); | 853 | check_disconnect (); |
846 | GNUNET_free(rh); | 854 | break; |
847 | check_disconnect(); | 855 | |
848 | break; | 856 | default: |
849 | 857 | GNUNET_assert (0); | |
850 | default: | 858 | break; |
851 | GNUNET_assert(0); | ||
852 | break; | ||
853 | } | ||
854 | } | 859 | } |
855 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 860 | } |
856 | "Will try to connect to DNS service in %s\n", | 861 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
857 | GNUNET_STRINGS_relative_time_to_string(backoff, | 862 | "Will try to connect to DNS service in %s\n", |
858 | GNUNET_YES)); | 863 | GNUNET_STRINGS_relative_time_to_string (backoff, |
859 | GNUNET_assert(NULL != resolver_cfg); | 864 | GNUNET_YES)); |
860 | r_task = GNUNET_SCHEDULER_add_delayed(backoff, | 865 | GNUNET_assert (NULL != resolver_cfg); |
861 | &reconnect_task, | 866 | r_task = GNUNET_SCHEDULER_add_delayed (backoff, |
862 | NULL); | 867 | &reconnect_task, |
863 | backoff = GNUNET_TIME_STD_BACKOFF(backoff); | 868 | NULL); |
869 | backoff = GNUNET_TIME_STD_BACKOFF (backoff); | ||
864 | } | 870 | } |
865 | 871 | ||
866 | 872 | ||
@@ -870,52 +876,52 @@ reconnect() | |||
870 | * @param cls the `struct GNUNET_RESOLVER_RequestHandle *` | 876 | * @param cls the `struct GNUNET_RESOLVER_RequestHandle *` |
871 | */ | 877 | */ |
872 | static void | 878 | static void |
873 | handle_lookup_timeout(void *cls) | 879 | handle_lookup_timeout (void *cls) |
874 | { | 880 | { |
875 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; | 881 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; |
876 | 882 | ||
877 | rh->task = NULL; | 883 | rh->task = NULL; |
878 | if (GNUNET_NO == rh->direction) | 884 | if (GNUNET_NO == rh->direction) |
879 | { | 885 | { |
880 | LOG(GNUNET_ERROR_TYPE_INFO, | 886 | LOG (GNUNET_ERROR_TYPE_INFO, |
881 | _("Timeout trying to resolve hostname `%s'.\n"), | 887 | _ ("Timeout trying to resolve hostname `%s'.\n"), |
882 | (const char *)&rh[1]); | 888 | (const char *) &rh[1]); |
883 | if (NULL != rh->addr_callback) | 889 | if (NULL != rh->addr_callback) |
884 | rh->addr_callback(rh->cls, | 890 | rh->addr_callback (rh->cls, |
885 | NULL, | 891 | NULL, |
886 | 0); | 892 | 0); |
887 | } | 893 | } |
888 | else | 894 | else |
889 | { | 895 | { |
890 | #if !defined(GNUNET_CULL_LOGGING) | 896 | #if ! defined(GNUNET_CULL_LOGGING) |
891 | char buf[INET6_ADDRSTRLEN]; | 897 | char buf[INET6_ADDRSTRLEN]; |
892 | 898 | ||
893 | LOG(GNUNET_ERROR_TYPE_INFO, | 899 | LOG (GNUNET_ERROR_TYPE_INFO, |
894 | _("Timeout trying to resolve IP address `%s'.\n"), | 900 | _ ("Timeout trying to resolve IP address `%s'.\n"), |
895 | inet_ntop(rh->af, | 901 | inet_ntop (rh->af, |
896 | (const void *)&rh[1], | 902 | (const void *) &rh[1], |
897 | buf, | 903 | buf, |
898 | sizeof(buf))); | 904 | sizeof(buf))); |
899 | #endif | 905 | #endif |
900 | if (GNUNET_NO == rh->received_response) | 906 | if (GNUNET_NO == rh->received_response) |
901 | { | 907 | { |
902 | char *nret; | 908 | char *nret; |
903 | 909 | ||
904 | nret = no_resolve(rh->af, | 910 | nret = no_resolve (rh->af, |
905 | &rh[1], | 911 | &rh[1], |
906 | rh->data_len); | 912 | rh->data_len); |
907 | if (NULL != rh->name_callback) | ||
908 | rh->name_callback(rh->cls, nret); | ||
909 | GNUNET_free(nret); | ||
910 | } | ||
911 | /* finally, make termination call */ | ||
912 | if (NULL != rh->name_callback) | 913 | if (NULL != rh->name_callback) |
913 | rh->name_callback(rh->cls, | 914 | rh->name_callback (rh->cls, nret); |
914 | NULL); | 915 | GNUNET_free (nret); |
915 | } | 916 | } |
917 | /* finally, make termination call */ | ||
918 | if (NULL != rh->name_callback) | ||
919 | rh->name_callback (rh->cls, | ||
920 | NULL); | ||
921 | } | ||
916 | rh->was_transmitted = GNUNET_NO; | 922 | rh->was_transmitted = GNUNET_NO; |
917 | GNUNET_RESOLVER_request_cancel(rh); | 923 | GNUNET_RESOLVER_request_cancel (rh); |
918 | process_requests(); | 924 | process_requests (); |
919 | } | 925 | } |
920 | 926 | ||
921 | 927 | ||
@@ -930,83 +936,83 @@ handle_lookup_timeout(void *cls) | |||
930 | * @return handle that can be used to cancel the request, NULL on error | 936 | * @return handle that can be used to cancel the request, NULL on error |
931 | */ | 937 | */ |
932 | struct GNUNET_RESOLVER_RequestHandle * | 938 | struct GNUNET_RESOLVER_RequestHandle * |
933 | GNUNET_RESOLVER_ip_get(const char *hostname, | 939 | GNUNET_RESOLVER_ip_get (const char *hostname, |
934 | int af, | 940 | int af, |
935 | struct GNUNET_TIME_Relative timeout, | 941 | struct GNUNET_TIME_Relative timeout, |
936 | GNUNET_RESOLVER_AddressCallback callback, | 942 | GNUNET_RESOLVER_AddressCallback callback, |
937 | void *callback_cls) | 943 | void *callback_cls) |
938 | { | 944 | { |
939 | struct GNUNET_RESOLVER_RequestHandle *rh; | 945 | struct GNUNET_RESOLVER_RequestHandle *rh; |
940 | size_t slen; | 946 | size_t slen; |
941 | struct in_addr v4; | 947 | struct in_addr v4; |
942 | struct in6_addr v6; | 948 | struct in6_addr v6; |
943 | 949 | ||
944 | slen = strlen(hostname) + 1; | 950 | slen = strlen (hostname) + 1; |
945 | if (slen + sizeof(struct GNUNET_RESOLVER_GetMessage) >= | 951 | if (slen + sizeof(struct GNUNET_RESOLVER_GetMessage) >= |
946 | GNUNET_MAX_MESSAGE_SIZE) | 952 | GNUNET_MAX_MESSAGE_SIZE) |
947 | { | 953 | { |
948 | GNUNET_break(0); | 954 | GNUNET_break (0); |
949 | return NULL; | 955 | return NULL; |
950 | } | 956 | } |
951 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 957 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
952 | "Trying to resolve hostname `%s'.\n", | 958 | "Trying to resolve hostname `%s'.\n", |
953 | hostname); | 959 | hostname); |
954 | rh = GNUNET_malloc(sizeof(struct GNUNET_RESOLVER_RequestHandle) + slen); | 960 | rh = GNUNET_malloc (sizeof(struct GNUNET_RESOLVER_RequestHandle) + slen); |
955 | rh->af = af; | 961 | rh->af = af; |
956 | rh->id = ++last_request_id; | 962 | rh->id = ++last_request_id; |
957 | rh->addr_callback = callback; | 963 | rh->addr_callback = callback; |
958 | rh->cls = callback_cls; | 964 | rh->cls = callback_cls; |
959 | GNUNET_memcpy(&rh[1], | 965 | GNUNET_memcpy (&rh[1], |
960 | hostname, | 966 | hostname, |
961 | slen); | 967 | slen); |
962 | rh->data_len = slen; | 968 | rh->data_len = slen; |
963 | rh->timeout = GNUNET_TIME_relative_to_absolute(timeout); | 969 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
964 | rh->direction = GNUNET_NO; | 970 | rh->direction = GNUNET_NO; |
965 | /* first, check if this is a numeric address */ | 971 | /* first, check if this is a numeric address */ |
966 | if (((1 == inet_pton(AF_INET, | 972 | if (((1 == inet_pton (AF_INET, |
967 | hostname, | 973 | hostname, |
968 | &v4)) && | 974 | &v4)) && |
969 | ((af == AF_INET) || | 975 | ((af == AF_INET) || |
970 | (af == AF_UNSPEC))) || | 976 | (af == AF_UNSPEC))) || |
971 | ((1 == inet_pton(AF_INET6, | 977 | ((1 == inet_pton (AF_INET6, |
972 | hostname, | 978 | hostname, |
973 | &v6)) && | 979 | &v6)) && |
974 | ((af == AF_INET6) || | 980 | ((af == AF_INET6) || |
975 | (af == AF_UNSPEC)))) | 981 | (af == AF_UNSPEC)))) |
976 | { | 982 | { |
977 | rh->task = GNUNET_SCHEDULER_add_now(&numeric_resolution, | 983 | rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, |
978 | rh); | 984 | rh); |
979 | return rh; | 985 | return rh; |
980 | } | 986 | } |
981 | /* then, check if this is a loopback address */ | 987 | /* then, check if this is a loopback address */ |
982 | for (unsigned int i = 0; | 988 | for (unsigned int i = 0; |
983 | NULL != loopback[i]; | 989 | NULL != loopback[i]; |
984 | i++) | 990 | i++) |
985 | if (0 == strcasecmp(loopback[i], | 991 | if (0 == strcasecmp (loopback[i], |
986 | hostname)) | 992 | hostname)) |
987 | { | ||
988 | rh->task = GNUNET_SCHEDULER_add_now(&loopback_resolution, | ||
989 | rh); | ||
990 | return rh; | ||
991 | } | ||
992 | if (GNUNET_OK != check_config()) | ||
993 | { | 993 | { |
994 | GNUNET_free(rh); | 994 | rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, |
995 | return NULL; | 995 | rh); |
996 | return rh; | ||
996 | } | 997 | } |
997 | rh->task = GNUNET_SCHEDULER_add_delayed(timeout, | 998 | if (GNUNET_OK != check_config ()) |
998 | &handle_lookup_timeout, | 999 | { |
999 | rh); | 1000 | GNUNET_free (rh); |
1000 | GNUNET_CONTAINER_DLL_insert_tail(req_head, | 1001 | return NULL; |
1001 | req_tail, | 1002 | } |
1002 | rh); | 1003 | rh->task = GNUNET_SCHEDULER_add_delayed (timeout, |
1004 | &handle_lookup_timeout, | ||
1005 | rh); | ||
1006 | GNUNET_CONTAINER_DLL_insert_tail (req_head, | ||
1007 | req_tail, | ||
1008 | rh); | ||
1003 | rh->was_queued = GNUNET_YES; | 1009 | rh->was_queued = GNUNET_YES; |
1004 | if (NULL != s_task) | 1010 | if (NULL != s_task) |
1005 | { | 1011 | { |
1006 | GNUNET_SCHEDULER_cancel(s_task); | 1012 | GNUNET_SCHEDULER_cancel (s_task); |
1007 | s_task = NULL; | 1013 | s_task = NULL; |
1008 | } | 1014 | } |
1009 | process_requests(); | 1015 | process_requests (); |
1010 | return rh; | 1016 | return rh; |
1011 | } | 1017 | } |
1012 | 1018 | ||
@@ -1020,32 +1026,32 @@ GNUNET_RESOLVER_ip_get(const char *hostname, | |||
1020 | * @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request | 1026 | * @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request |
1021 | */ | 1027 | */ |
1022 | static void | 1028 | static void |
1023 | numeric_reverse(void *cls) | 1029 | numeric_reverse (void *cls) |
1024 | { | 1030 | { |
1025 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; | 1031 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; |
1026 | char *result; | 1032 | char *result; |
1027 | 1033 | ||
1028 | rh->task = NULL; | 1034 | rh->task = NULL; |
1029 | result = no_resolve(rh->af, | 1035 | result = no_resolve (rh->af, |
1030 | &rh[1], | 1036 | &rh[1], |
1031 | rh->data_len); | 1037 | rh->data_len); |
1032 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1038 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1033 | "Resolver returns `%s'.\n", | 1039 | "Resolver returns `%s'.\n", |
1034 | result); | 1040 | result); |
1035 | if (NULL != result) | 1041 | if (NULL != result) |
1036 | { | 1042 | { |
1037 | rh->name_callback(rh->cls, | 1043 | rh->name_callback (rh->cls, |
1038 | result); | 1044 | result); |
1039 | GNUNET_free(result); | 1045 | GNUNET_free (result); |
1040 | } | 1046 | } |
1041 | rh->name_callback(rh->cls, | 1047 | rh->name_callback (rh->cls, |
1042 | NULL); | 1048 | NULL); |
1043 | if (NULL != rh->task) | 1049 | if (NULL != rh->task) |
1044 | { | 1050 | { |
1045 | GNUNET_SCHEDULER_cancel(rh->task); | 1051 | GNUNET_SCHEDULER_cancel (rh->task); |
1046 | rh->task = NULL; | 1052 | rh->task = NULL; |
1047 | } | 1053 | } |
1048 | GNUNET_free(rh); | 1054 | GNUNET_free (rh); |
1049 | } | 1055 | } |
1050 | 1056 | ||
1051 | 1057 | ||
@@ -1062,73 +1068,73 @@ numeric_reverse(void *cls) | |||
1062 | * @return handle that can be used to cancel the request | 1068 | * @return handle that can be used to cancel the request |
1063 | */ | 1069 | */ |
1064 | struct GNUNET_RESOLVER_RequestHandle * | 1070 | struct GNUNET_RESOLVER_RequestHandle * |
1065 | GNUNET_RESOLVER_hostname_get(const struct sockaddr *sa, | 1071 | GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, |
1066 | socklen_t salen, | 1072 | socklen_t salen, |
1067 | int do_resolve, | 1073 | int do_resolve, |
1068 | struct GNUNET_TIME_Relative timeout, | 1074 | struct GNUNET_TIME_Relative timeout, |
1069 | GNUNET_RESOLVER_HostnameCallback callback, | 1075 | GNUNET_RESOLVER_HostnameCallback callback, |
1070 | void *cls) | 1076 | void *cls) |
1071 | { | 1077 | { |
1072 | struct GNUNET_RESOLVER_RequestHandle *rh; | 1078 | struct GNUNET_RESOLVER_RequestHandle *rh; |
1073 | size_t ip_len; | 1079 | size_t ip_len; |
1074 | const void *ip; | 1080 | const void *ip; |
1075 | 1081 | ||
1076 | if (GNUNET_OK != check_config()) | 1082 | if (GNUNET_OK != check_config ()) |
1077 | { | 1083 | { |
1078 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1084 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1079 | _("Resolver not configured correctly.\n")); | 1085 | _ ("Resolver not configured correctly.\n")); |
1080 | return NULL; | 1086 | return NULL; |
1081 | } | 1087 | } |
1082 | 1088 | ||
1083 | switch (sa->sa_family) | 1089 | switch (sa->sa_family) |
1084 | { | 1090 | { |
1085 | case AF_INET: | 1091 | case AF_INET: |
1086 | GNUNET_assert(salen == sizeof(struct sockaddr_in)); | 1092 | GNUNET_assert (salen == sizeof(struct sockaddr_in)); |
1087 | ip_len = sizeof(struct in_addr); | 1093 | ip_len = sizeof(struct in_addr); |
1088 | ip = &((const struct sockaddr_in*)sa)->sin_addr; | 1094 | ip = &((const struct sockaddr_in*) sa)->sin_addr; |
1089 | break; | 1095 | break; |
1090 | 1096 | ||
1091 | case AF_INET6: | 1097 | case AF_INET6: |
1092 | GNUNET_assert(salen == sizeof(struct sockaddr_in6)); | 1098 | GNUNET_assert (salen == sizeof(struct sockaddr_in6)); |
1093 | ip_len = sizeof(struct in6_addr); | 1099 | ip_len = sizeof(struct in6_addr); |
1094 | ip = &((const struct sockaddr_in6*)sa)->sin6_addr; | 1100 | ip = &((const struct sockaddr_in6*) sa)->sin6_addr; |
1095 | break; | 1101 | break; |
1096 | 1102 | ||
1097 | default: | 1103 | default: |
1098 | GNUNET_break(0); | 1104 | GNUNET_break (0); |
1099 | return NULL; | 1105 | return NULL; |
1100 | } | 1106 | } |
1101 | rh = GNUNET_malloc(sizeof(struct GNUNET_RESOLVER_RequestHandle) + salen); | 1107 | rh = GNUNET_malloc (sizeof(struct GNUNET_RESOLVER_RequestHandle) + salen); |
1102 | rh->name_callback = callback; | 1108 | rh->name_callback = callback; |
1103 | rh->cls = cls; | 1109 | rh->cls = cls; |
1104 | rh->af = sa->sa_family; | 1110 | rh->af = sa->sa_family; |
1105 | rh->id = ++last_request_id; | 1111 | rh->id = ++last_request_id; |
1106 | rh->timeout = GNUNET_TIME_relative_to_absolute(timeout); | 1112 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1107 | GNUNET_memcpy(&rh[1], | 1113 | GNUNET_memcpy (&rh[1], |
1108 | ip, | 1114 | ip, |
1109 | ip_len); | 1115 | ip_len); |
1110 | rh->data_len = ip_len; | 1116 | rh->data_len = ip_len; |
1111 | rh->direction = GNUNET_YES; | 1117 | rh->direction = GNUNET_YES; |
1112 | rh->received_response = GNUNET_NO; | 1118 | rh->received_response = GNUNET_NO; |
1113 | if (GNUNET_NO == do_resolve) | 1119 | if (GNUNET_NO == do_resolve) |
1114 | { | 1120 | { |
1115 | rh->task = GNUNET_SCHEDULER_add_now(&numeric_reverse, | 1121 | rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, |
1116 | rh); | 1122 | rh); |
1117 | return rh; | 1123 | return rh; |
1118 | } | 1124 | } |
1119 | rh->task = GNUNET_SCHEDULER_add_delayed(timeout, | 1125 | rh->task = GNUNET_SCHEDULER_add_delayed (timeout, |
1120 | &handle_lookup_timeout, | 1126 | &handle_lookup_timeout, |
1121 | rh); | 1127 | rh); |
1122 | GNUNET_CONTAINER_DLL_insert_tail(req_head, | 1128 | GNUNET_CONTAINER_DLL_insert_tail (req_head, |
1123 | req_tail, | 1129 | req_tail, |
1124 | rh); | 1130 | rh); |
1125 | rh->was_queued = GNUNET_YES; | 1131 | rh->was_queued = GNUNET_YES; |
1126 | if (NULL != s_task) | 1132 | if (NULL != s_task) |
1127 | { | 1133 | { |
1128 | GNUNET_SCHEDULER_cancel(s_task); | 1134 | GNUNET_SCHEDULER_cancel (s_task); |
1129 | s_task = NULL; | 1135 | s_task = NULL; |
1130 | } | 1136 | } |
1131 | process_requests(); | 1137 | process_requests (); |
1132 | return rh; | 1138 | return rh; |
1133 | } | 1139 | } |
1134 | 1140 | ||
@@ -1139,78 +1145,78 @@ GNUNET_RESOLVER_hostname_get(const struct sockaddr *sa, | |||
1139 | * @return fqdn | 1145 | * @return fqdn |
1140 | */ | 1146 | */ |
1141 | char * | 1147 | char * |
1142 | GNUNET_RESOLVER_local_fqdn_get() | 1148 | GNUNET_RESOLVER_local_fqdn_get () |
1143 | { | 1149 | { |
1144 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; | 1150 | char hostname[GNUNET_OS_get_hostname_max_length () + 1]; |
1145 | 1151 | ||
1146 | if (0 != gethostname(hostname, | 1152 | if (0 != gethostname (hostname, |
1147 | sizeof(hostname) - 1)) | 1153 | sizeof(hostname) - 1)) |
1148 | { | 1154 | { |
1149 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1155 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1150 | "gethostname"); | 1156 | "gethostname"); |
1151 | return NULL; | 1157 | return NULL; |
1152 | } | 1158 | } |
1153 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1159 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1154 | "Resolving our FQDN `%s'\n", | 1160 | "Resolving our FQDN `%s'\n", |
1155 | hostname); | 1161 | hostname); |
1156 | #if HAVE_GETADDRINFO | 1162 | #if HAVE_GETADDRINFO |
1157 | { | 1163 | { |
1158 | struct addrinfo *ai; | 1164 | struct addrinfo *ai; |
1159 | int ret; | 1165 | int ret; |
1160 | char *rval; | 1166 | char *rval; |
1161 | 1167 | ||
1162 | if (0 != (ret = getaddrinfo(hostname, | 1168 | if (0 != (ret = getaddrinfo (hostname, |
1163 | NULL, | 1169 | NULL, |
1164 | NULL, | 1170 | NULL, |
1165 | &ai))) | 1171 | &ai))) |
1166 | { | 1172 | { |
1167 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1173 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1168 | _("Could not resolve our FQDN: %s\n"), | 1174 | _ ("Could not resolve our FQDN: %s\n"), |
1169 | gai_strerror(ret)); | 1175 | gai_strerror (ret)); |
1170 | return NULL; | 1176 | return NULL; |
1171 | } | 1177 | } |
1172 | if (NULL != ai->ai_canonname) | 1178 | if (NULL != ai->ai_canonname) |
1173 | rval = GNUNET_strdup(ai->ai_canonname); | 1179 | rval = GNUNET_strdup (ai->ai_canonname); |
1174 | else | 1180 | else |
1175 | rval = GNUNET_strdup(hostname); | 1181 | rval = GNUNET_strdup (hostname); |
1176 | freeaddrinfo(ai); | 1182 | freeaddrinfo (ai); |
1177 | return rval; | 1183 | return rval; |
1178 | } | 1184 | } |
1179 | #elif HAVE_GETHOSTBYNAME2 | 1185 | #elif HAVE_GETHOSTBYNAME2 |
1180 | { | 1186 | { |
1181 | struct hostent *host; | 1187 | struct hostent *host; |
1182 | 1188 | ||
1183 | host = gethostbyname2(hostname, | 1189 | host = gethostbyname2 (hostname, |
1184 | AF_INET); | 1190 | AF_INET); |
1185 | if (NULL == host) | 1191 | if (NULL == host) |
1186 | host = gethostbyname2(hostname, | 1192 | host = gethostbyname2 (hostname, |
1187 | AF_INET6); | 1193 | AF_INET6); |
1188 | if (NULL == host) | 1194 | if (NULL == host) |
1189 | { | 1195 | { |
1190 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1196 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1191 | _("Could not resolve our FQDN: %s\n"), | 1197 | _ ("Could not resolve our FQDN: %s\n"), |
1192 | hstrerror(h_errno)); | 1198 | hstrerror (h_errno)); |
1193 | return NULL; | 1199 | return NULL; |
1194 | } | 1200 | } |
1195 | return GNUNET_strdup(host->h_name); | 1201 | return GNUNET_strdup (host->h_name); |
1196 | } | 1202 | } |
1197 | #elif HAVE_GETHOSTBYNAME | 1203 | #elif HAVE_GETHOSTBYNAME |
1198 | { | 1204 | { |
1199 | struct hostent *host; | 1205 | struct hostent *host; |
1200 | 1206 | ||
1201 | host = gethostbyname(hostname); | 1207 | host = gethostbyname (hostname); |
1202 | if (NULL == host) | 1208 | if (NULL == host) |
1203 | { | 1209 | { |
1204 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1210 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1205 | _("Could not resolve our FQDN: %s\n"), | 1211 | _ ("Could not resolve our FQDN: %s\n"), |
1206 | hstrerror(h_errno)); | 1212 | hstrerror (h_errno)); |
1207 | return NULL; | 1213 | return NULL; |
1208 | } | 1214 | } |
1209 | return GNUNET_strdup(host->h_name); | 1215 | return GNUNET_strdup (host->h_name); |
1210 | } | 1216 | } |
1211 | #else | 1217 | #else |
1212 | /* fallback: just hope name is already FQDN */ | 1218 | /* fallback: just hope name is already FQDN */ |
1213 | return GNUNET_strdup(hostname); | 1219 | return GNUNET_strdup (hostname); |
1214 | #endif | 1220 | #endif |
1215 | } | 1221 | } |
1216 | 1222 | ||
@@ -1225,27 +1231,27 @@ GNUNET_RESOLVER_local_fqdn_get() | |||
1225 | * @return handle that can be used to cancel the request, NULL on error | 1231 | * @return handle that can be used to cancel the request, NULL on error |
1226 | */ | 1232 | */ |
1227 | struct GNUNET_RESOLVER_RequestHandle * | 1233 | struct GNUNET_RESOLVER_RequestHandle * |
1228 | GNUNET_RESOLVER_hostname_resolve(int af, | 1234 | GNUNET_RESOLVER_hostname_resolve (int af, |
1229 | struct GNUNET_TIME_Relative timeout, | 1235 | struct GNUNET_TIME_Relative timeout, |
1230 | GNUNET_RESOLVER_AddressCallback callback, | 1236 | GNUNET_RESOLVER_AddressCallback callback, |
1231 | void *cls) | 1237 | void *cls) |
1232 | { | 1238 | { |
1233 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; | 1239 | char hostname[GNUNET_OS_get_hostname_max_length () + 1]; |
1234 | 1240 | ||
1235 | if (0 != gethostname(hostname, sizeof(hostname) - 1)) | 1241 | if (0 != gethostname (hostname, sizeof(hostname) - 1)) |
1236 | { | 1242 | { |
1237 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1243 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1238 | "gethostname"); | 1244 | "gethostname"); |
1239 | return NULL; | 1245 | return NULL; |
1240 | } | 1246 | } |
1241 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1247 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1242 | "Resolving our hostname `%s'\n", | 1248 | "Resolving our hostname `%s'\n", |
1243 | hostname); | 1249 | hostname); |
1244 | return GNUNET_RESOLVER_ip_get(hostname, | 1250 | return GNUNET_RESOLVER_ip_get (hostname, |
1245 | af, | 1251 | af, |
1246 | timeout, | 1252 | timeout, |
1247 | callback, | 1253 | callback, |
1248 | cls); | 1254 | cls); |
1249 | } | 1255 | } |
1250 | 1256 | ||
1251 | 1257 | ||
@@ -1258,30 +1264,30 @@ GNUNET_RESOLVER_hostname_resolve(int af, | |||
1258 | * @param rh handle of request to cancel | 1264 | * @param rh handle of request to cancel |
1259 | */ | 1265 | */ |
1260 | void | 1266 | void |
1261 | GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh) | 1267 | GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh) |
1262 | { | 1268 | { |
1263 | if (GNUNET_NO == rh->direction) | 1269 | if (GNUNET_NO == rh->direction) |
1264 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1270 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1265 | "Asked to cancel request to resolve hostname `%s'.\n", | 1271 | "Asked to cancel request to resolve hostname `%s'.\n", |
1266 | (const char *)&rh[1]); | 1272 | (const char *) &rh[1]); |
1267 | if (NULL != rh->task) | 1273 | if (NULL != rh->task) |
1268 | { | 1274 | { |
1269 | GNUNET_SCHEDULER_cancel(rh->task); | 1275 | GNUNET_SCHEDULER_cancel (rh->task); |
1270 | rh->task = NULL; | 1276 | rh->task = NULL; |
1271 | } | 1277 | } |
1272 | if (GNUNET_NO == rh->was_transmitted) | 1278 | if (GNUNET_NO == rh->was_transmitted) |
1273 | { | 1279 | { |
1274 | if (GNUNET_YES == rh->was_queued) | 1280 | if (GNUNET_YES == rh->was_queued) |
1275 | GNUNET_CONTAINER_DLL_remove(req_head, | 1281 | GNUNET_CONTAINER_DLL_remove (req_head, |
1276 | req_tail, | 1282 | req_tail, |
1277 | rh); | 1283 | rh); |
1278 | GNUNET_free(rh); | 1284 | GNUNET_free (rh); |
1279 | check_disconnect(); | 1285 | check_disconnect (); |
1280 | return; | 1286 | return; |
1281 | } | 1287 | } |
1282 | GNUNET_assert(GNUNET_YES == rh->was_transmitted); | 1288 | GNUNET_assert (GNUNET_YES == rh->was_transmitted); |
1283 | rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */ | 1289 | rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */ |
1284 | check_disconnect(); | 1290 | check_disconnect (); |
1285 | } | 1291 | } |
1286 | 1292 | ||
1287 | 1293 | ||