aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_transport_plugin.h31
-rw-r--r--src/include/gnunet_transport_service.h20
-rw-r--r--src/transport/gnunet-service-transport_clients.c66
-rw-r--r--src/transport/gnunet-transport.c381
-rw-r--r--src/transport/plugin_transport_bluetooth.c77
-rw-r--r--src/transport/plugin_transport_http_client.c25
-rw-r--r--src/transport/plugin_transport_http_common.c24
-rw-r--r--src/transport/plugin_transport_tcp.c198
-rw-r--r--src/transport/plugin_transport_udp.c96
-rw-r--r--src/transport/plugin_transport_unix.c81
-rw-r--r--src/transport/plugin_transport_wlan.c87
-rw-r--r--src/transport/transport.h40
-rw-r--r--src/transport/transport_api_address_to_string.c128
13 files changed, 740 insertions, 514 deletions
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h
index 7fc12d4bb..b32b94004 100644
--- a/src/include/gnunet_transport_plugin.h
+++ b/src/include/gnunet_transport_plugin.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors) 3 (C) 2009-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -194,18 +194,28 @@ typedef struct GNUNET_TIME_Relative
194 const struct GNUNET_PeerIdentity *peer, 194 const struct GNUNET_PeerIdentity *peer,
195 size_t amount_recved); 195 size_t amount_recved);
196 196
197/**
198 * FIXME: document!
199 */
197typedef void 200typedef void
198(*GNUNET_TRANSPORT_RegisterQuotaNotification) (void *cls, 201(*GNUNET_TRANSPORT_RegisterQuotaNotification) (void *cls,
199 const struct GNUNET_PeerIdentity *peer, 202 const struct GNUNET_PeerIdentity *peer,
200 const char *plugin, 203 const char *plugin,
201 struct Session *session); 204 struct Session *session);
202 205
206/**
207 * FIXME: document!
208 */
203typedef void 209typedef void
204(*GNUNET_TRANSPORT_UnregisterQuotaNotification) (void *cls, 210(*GNUNET_TRANSPORT_UnregisterQuotaNotification) (void *cls,
205 const struct GNUNET_PeerIdentity *peer, const char *plugin, struct Session *session); 211 const struct GNUNET_PeerIdentity *peer,
212 const char *plugin,
213 struct Session *session);
206 214
207/** 215/**
208 * Function that returns a HELLO message. 216 * Function that returns a HELLO message.
217 *
218 * @return HELLO message (FIXME with what?)
209 */ 219 */
210typedef const struct GNUNET_MessageHeader * 220typedef const struct GNUNET_MessageHeader *
211(*GNUNET_TRANSPORT_GetHelloCallback) (void); 221(*GNUNET_TRANSPORT_GetHelloCallback) (void);
@@ -284,8 +294,14 @@ struct GNUNET_TRANSPORT_PluginEnvironment
284 */ 294 */
285 GNUNET_TRANSPORT_UpdateAddressMetrics update_address_metrics; 295 GNUNET_TRANSPORT_UpdateAddressMetrics update_address_metrics;
286 296
297 /**
298 * FIXME: document!
299 */
287 GNUNET_TRANSPORT_RegisterQuotaNotification register_quota_notification; 300 GNUNET_TRANSPORT_RegisterQuotaNotification register_quota_notification;
288 301
302 /**
303 * FIXME: document!
304 */
289 GNUNET_TRANSPORT_UnregisterQuotaNotification unregister_quota_notification; 305 GNUNET_TRANSPORT_UnregisterQuotaNotification unregister_quota_notification;
290 306
291 /** 307 /**
@@ -412,12 +428,17 @@ typedef void
412 428
413/** 429/**
414 * Function called by the pretty printer for the resolved address for 430 * Function called by the pretty printer for the resolved address for
415 * each human-readable address obtained. 431 * each human-readable address obtained. The callback can be called
432 * several times. The last invocation must be with a @a address of
433 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
434 * errors, the callback might be called first with @a address NULL and
435 * @a res being #GNUNET_SYSERR. In that case, there must still be a
436 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
416 * 437 *
417 * @param cls closure 438 * @param cls closure
418 * @param address one of the names for the host, NULL on last callback 439 * @param address one of the names for the host, NULL on last callback
419 * @param res GNUNET_OK if conversion was successful, GNUNET_SYSERR on failure, 440 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on failure,
420 * GNUNET_OK on last callback 441 * #GNUNET_OK on last callback
421 */ 442 */
422typedef void 443typedef void
423(*GNUNET_TRANSPORT_AddressStringCallback) (void *cls, 444(*GNUNET_TRANSPORT_AddressStringCallback) (void *cls,
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h
index 9e82a0dda..3a4d282e4 100644
--- a/src/include/gnunet_transport_service.h
+++ b/src/include/gnunet_transport_service.h
@@ -277,18 +277,20 @@ typedef void
277 277
278 278
279/** 279/**
280 * Function to call with a textual representation of an address. 280 * Function to call with a textual representation of an address. This
281 * This function will be called several times with different possible 281 * function will be called several times with different possible
282 * textual representations, and a last time with NULL to signal the end 282 * textual representations, and a last time with @address being NULL
283 * of the iteration. 283 * to signal the end of the iteration. Note that @address NULL
284 * always is the last call, regardless of the value in @a res.
284 * 285 *
285 * @param cls closure 286 * @param cls closure
286 * @param address NULL on error or end of iteration, 287 * @param address NULL on end of iteration,
287 * otherwise 0-terminated printable UTF-8 string 288 * otherwise 0-terminated printable UTF-8 string,
289 * in particular an empty string if @a res is #GNUNET_NO
288 * @param res result of the address to string conversion: 290 * @param res result of the address to string conversion:
289 * if #GNUNET_OK: address was valid (conversion to 291 * if #GNUNET_OK: conversion successful
290 * string might still have failed) 292 * if #GNUNET_NO: address was invalid (or not supported)
291 * if #GNUNET_SYSERR: address is invalid 293 * if #GNUNET_SYSERR: communication error (IPC error)
292 */ 294 */
293typedef void 295typedef void
294(*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, 296(*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index b19a15bc7..37cebb1c7 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -854,64 +854,76 @@ clients_handle_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
854 854
855/** 855/**
856 * Take the given address and append it to the set of results sent back to 856 * Take the given address and append it to the set of results sent back to
857 * the client. 857 * the client. This function may be called serveral times for a single
858 * conversion. The last invocation will be with a @a address of
859 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
860 * errors, the callback might be called first with @a address NULL and
861 * @a res being #GNUNET_SYSERR. In that case, there will still be a
862 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
858 * 863 *
859 * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*') 864 * @param cls the transmission context used (`struct GNUNET_SERVER_TransmitContext *`)
860 * @param buf text to transmit 865 * @param buf text to transmit (contains the human-readable address, or NULL)
861 * @param res GNUNET_OK if conversion was successful, GNUNET_SYSERR on error 866 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error,
867 * never #GNUNET_NO
862 */ 868 */
863static void 869static void
864transmit_address_to_client (void *cls, const char *buf, int res) 870transmit_address_to_client (void *cls,
871 const char *buf,
872 int res)
865{ 873{
866 struct AddressToStringContext *actx = cls; 874 struct AddressToStringContext *actx = cls;
867 struct AddressToStringResultMessage *atsm; 875 struct AddressToStringResultMessage *atsm;
868 size_t len; 876 size_t len;
877 size_t slen;
869 878
879 GNUNET_assert ( (GNUNET_OK == res) ||
880 (GNUNET_SYSERR == res) );
870 if (NULL == buf) 881 if (NULL == buf)
871 { 882 {
872 GNUNET_assert ((res == GNUNET_OK) || (res == GNUNET_SYSERR));
873
874 len = sizeof (struct AddressToStringResultMessage); 883 len = sizeof (struct AddressToStringResultMessage);
875 atsm = GNUNET_malloc (len); 884 atsm = GNUNET_malloc (len);
876 atsm->header.size = ntohs (len); 885 atsm->header.size = ntohs (len);
877 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 886 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
878
879 if (GNUNET_OK == res) 887 if (GNUNET_OK == res)
880 { 888 {
881 /* done, transmit */ 889 /* this was the last call, transmit */
882 atsm->res = htonl (GNUNET_YES); 890 atsm->res = htonl (GNUNET_OK);
883 atsm->addr_len = htonl (0); 891 atsm->addr_len = htonl (0);
884 GNUNET_SERVER_transmit_context_append_message (actx->tc, 892 GNUNET_SERVER_transmit_context_append_message (actx->tc,
885 (const struct GNUNET_MessageHeader *) atsm); 893 (const struct GNUNET_MessageHeader *) atsm);
886 894 GNUNET_SERVER_transmit_context_run (actx->tc,
887 GNUNET_SERVER_transmit_context_run (actx->tc, GNUNET_TIME_UNIT_FOREVER_REL); 895 GNUNET_TIME_UNIT_FOREVER_REL);
888 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx); 896 GNUNET_CONTAINER_DLL_remove (a2s_head,
897 a2s_tail,
898 actx);
889 GNUNET_free (actx); 899 GNUNET_free (actx);
890 } 900 }
891 if (GNUNET_SYSERR == res) 901 if (GNUNET_SYSERR == res)
892 { 902 {
893 /* address conversion failed */ 903 /* address conversion failed, but there will be more callbacks */
894 904 atsm->res = htonl (GNUNET_SYSERR);
895 atsm->res = htonl (GNUNET_NO);
896 atsm->addr_len = htonl (0); 905 atsm->addr_len = htonl (0);
897 GNUNET_SERVER_transmit_context_append_message (actx->tc, 906 GNUNET_SERVER_transmit_context_append_message (actx->tc,
898 (const struct GNUNET_MessageHeader *) atsm); 907 (const struct GNUNET_MessageHeader *) atsm);
899 GNUNET_free (atsm); 908 GNUNET_free (atsm);
900 } 909 }
901 } 910 }
902 else 911 else
903 { 912 {
904 GNUNET_assert (res == GNUNET_OK); 913 GNUNET_assert (GNUNET_OK == res);
905 /* succesful conversion, append*/ 914 /* succesful conversion, append*/
906 len = sizeof (struct AddressToStringResultMessage) + strlen (buf) + 1; 915 slen = strlen (buf) + 1;
916 len = sizeof (struct AddressToStringResultMessage) + slen;
907 atsm = GNUNET_malloc (len); 917 atsm = GNUNET_malloc (len);
908 atsm->header.size = ntohs (len); 918 atsm->header.size = ntohs (len);
909 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 919 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
910 atsm->res = htonl (GNUNET_YES); 920 atsm->res = htonl (GNUNET_YES);
911 atsm->addr_len = htonl (strlen (buf) + 1); 921 atsm->addr_len = htonl (slen);
912 memcpy (&atsm[1], buf, strlen (buf) + 1); 922 memcpy (&atsm[1],
923 buf,
924 slen);
913 GNUNET_SERVER_transmit_context_append_message (actx->tc, 925 GNUNET_SERVER_transmit_context_append_message (actx->tc,
914 (const struct GNUNET_MessageHeader *) atsm); 926 (const struct GNUNET_MessageHeader *) atsm);
915 GNUNET_free (atsm); 927 GNUNET_free (atsm);
916 } 928 }
917} 929}
@@ -983,8 +995,12 @@ clients_handle_address_to_string (void *cls,
983 actx->tc = tc; 995 actx->tc = tc;
984 GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx); 996 GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx);
985 GNUNET_SERVER_disable_receive_done_warning (client); 997 GNUNET_SERVER_disable_receive_done_warning (client);
986 papi->address_pretty_printer (papi->cls, plugin_name, address, address_len, 998 papi->address_pretty_printer (papi->cls,
987 numeric, rtimeout, &transmit_address_to_client, 999 plugin_name,
1000 address, address_len,
1001 numeric,
1002 rtimeout,
1003 &transmit_address_to_client,
988 actx); 1004 actx);
989} 1005}
990 1006
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index edc253dae..8cd606f81 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -561,92 +561,119 @@ resolve_validation_address (const struct GNUNET_PeerIdentity *id,
561 enum GNUNET_TRANSPORT_ValidationState state); 561 enum GNUNET_TRANSPORT_ValidationState state);
562 562
563 563
564
565/**
566 * Function to call with a textual representation of an address. This
567 * function will be called several times with different possible
568 * textual representations, and a last time with @address being NULL
569 * to signal the end of the iteration. Note that @address NULL
570 * always is the last call, regardless of the value in @a res.
571 *
572 * @param cls closure
573 * @param address NULL on end of iteration,
574 * otherwise 0-terminated printable UTF-8 string,
575 * in particular an empty string if @a res is #GNUNET_NO
576 * @param res result of the address to string conversion:
577 * if #GNUNET_OK: conversion successful
578 * if #GNUNET_NO: address was invalid (or not supported)
579 * if #GNUNET_SYSERR: communication error (IPC error)
580 */
564static void 581static void
565process_validation_string (void *cls, const char *address, int res) 582process_validation_string (void *cls,
583 const char *address,
584 int res)
566{ 585{
567 struct ValidationResolutionContext *vc = cls; 586 struct ValidationResolutionContext *vc = cls;
568 char *s_valid; 587 char *s_valid;
569 char *s_last; 588 char *s_last;
570 char *s_next; 589 char *s_next;
571 590
572 if (address != NULL ) 591 if (NULL != address)
573 { 592 {
574 if (GNUNET_SYSERR == res) 593 if (GNUNET_SYSERR == res)
575 { 594 {
576 FPRINTF (stderr, "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n", 595 FPRINTF (stderr,
577 GNUNET_i2s (&vc->id), 596 "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n",
578 vc->addrcp->transport_name, 597 GNUNET_i2s (&vc->id),
579 vc->addrcp->address_length); 598 vc->addrcp->transport_name,
599 vc->addrcp->address_length);
580 } 600 }
581 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us) 601 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us)
582 s_valid = GNUNET_strdup("never"); 602 s_valid = GNUNET_strdup ("never");
583 else 603 else
584 s_valid = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->valid_until)); 604 s_valid = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->valid_until));
585 605
586 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->last_validation.abs_value_us) 606 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->last_validation.abs_value_us)
587 s_last = GNUNET_strdup("never"); 607 s_last = GNUNET_strdup ("never");
588 else 608 else
589 s_last = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->last_validation)); 609 s_last = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->last_validation));
590 610
591 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->next_validation.abs_value_us) 611 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->next_validation.abs_value_us)
592 s_next = GNUNET_strdup("never"); 612 s_next = GNUNET_strdup ("never");
593 else 613 else
594 s_next = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->next_validation)); 614 s_next = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->next_validation));
595 615
596 FPRINTF (stdout, 616 FPRINTF (stdout,
597 _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"), 617 _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"),
598 GNUNET_i2s (&vc->id), 618 GNUNET_i2s (&vc->id),
599 (GNUNET_OK == res) ? address : "<invalid address>", 619 (GNUNET_OK == res) ? address : "<invalid address>",
600 (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "", 620 (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "",
601 "Valid until : ", s_valid, 621 "Valid until : ", s_valid,
602 "Last validation: ",s_last, 622 "Last validation: ",s_last,
603 "Next validation: ", s_next); 623 "Next validation: ", s_next);
604 GNUNET_free (s_valid); 624 GNUNET_free (s_valid);
605 GNUNET_free (s_last); 625 GNUNET_free (s_last);
606 GNUNET_free (s_next); 626 GNUNET_free (s_next);
607 vc->printed = GNUNET_YES; 627 vc->printed = GNUNET_YES;
628 return;
608 } 629 }
609 else 630 /* last call, we are done */
631 GNUNET_assert (address_resolutions > 0);
632 address_resolutions--;
633 if ( (GNUNET_SYSERR == res) &&
634 (GNUNET_NO == vc->printed) )
610 { 635 {
611 /* done */ 636 if (numeric == GNUNET_NO)
612
613 GNUNET_assert(address_resolutions > 0);
614 address_resolutions--;
615 if ((GNUNET_SYSERR == res) && (GNUNET_NO == vc->printed))
616 { 637 {
617 if (numeric == GNUNET_NO) 638 /* Failed to resolve address, try numeric lookup
618 { 639 (note: this should be unnecessary, as
619 /* Failed to resolve address, try numeric lookup */ 640 transport should fallback to numeric lookup
620 resolve_validation_address (&vc->id, vc->addrcp, GNUNET_NO, 641 internally if DNS takes too long anyway) */
621 vc->last_validation, vc->valid_until, vc->next_validation, 642 resolve_validation_address (&vc->id,
622 vc->state); 643 vc->addrcp,
623 } 644 GNUNET_NO,
624 else 645 vc->last_validation,
625 { 646 vc->valid_until,
626 FPRINTF (stdout, _("Peer `%s' %s `%s' \n"), 647 vc->next_validation,
627 GNUNET_i2s (&vc->id), "<unable to resolve address>", 648 vc->state);
628 GNUNET_TRANSPORT_vs2s (vc->state));
629 }
630 } 649 }
631 GNUNET_free (vc->transport); 650 else
632 GNUNET_free (vc->addrcp);
633 GNUNET_CONTAINER_DLL_remove(vc_head, vc_tail, vc);
634 GNUNET_free(vc);
635 if ((0 == address_resolutions) && (iterate_validation))
636 { 651 {
637 if (GNUNET_SCHEDULER_NO_TASK != end) 652 FPRINTF (stdout,
638 { 653 _("Peer `%s' %s `%s' \n"),
639 GNUNET_SCHEDULER_cancel (end); 654 GNUNET_i2s (&vc->id),
640 end = GNUNET_SCHEDULER_NO_TASK; 655 "<unable to resolve address>",
641 } 656 GNUNET_TRANSPORT_vs2s (vc->state));
642 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 657 }
643 { 658 }
644 GNUNET_SCHEDULER_cancel (op_timeout); 659 GNUNET_free (vc->transport);
645 op_timeout = GNUNET_SCHEDULER_NO_TASK; 660 GNUNET_free (vc->addrcp);
646 } 661 GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, vc);
647 ret = 0; 662 GNUNET_free (vc);
648 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL ); 663 if ((0 == address_resolutions) && (iterate_validation))
664 {
665 if (GNUNET_SCHEDULER_NO_TASK != end)
666 {
667 GNUNET_SCHEDULER_cancel (end);
668 end = GNUNET_SCHEDULER_NO_TASK;
669 }
670 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
671 {
672 GNUNET_SCHEDULER_cancel (op_timeout);
673 op_timeout = GNUNET_SCHEDULER_NO_TASK;
649 } 674 }
675 ret = 0;
676 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
650 } 677 }
651} 678}
652 679
@@ -654,11 +681,12 @@ process_validation_string (void *cls, const char *address, int res)
654 681
655static void 682static void
656resolve_validation_address (const struct GNUNET_PeerIdentity *id, 683resolve_validation_address (const struct GNUNET_PeerIdentity *id,
657 const struct GNUNET_HELLO_Address *address, int numeric, 684 const struct GNUNET_HELLO_Address *address,
658 struct GNUNET_TIME_Absolute last_validation, 685 int numeric,
659 struct GNUNET_TIME_Absolute valid_until, 686 struct GNUNET_TIME_Absolute last_validation,
660 struct GNUNET_TIME_Absolute next_validation, 687 struct GNUNET_TIME_Absolute valid_until,
661 enum GNUNET_TRANSPORT_ValidationState state) 688 struct GNUNET_TIME_Absolute next_validation,
689 enum GNUNET_TRANSPORT_ValidationState state)
662{ 690{
663 struct ValidationResolutionContext *vc; 691 struct ValidationResolutionContext *vc;
664 692
@@ -677,8 +705,11 @@ resolve_validation_address (const struct GNUNET_PeerIdentity *id,
677 vc->next_validation = next_validation; 705 vc->next_validation = next_validation;
678 706
679 /* Resolve address to string */ 707 /* Resolve address to string */
680 vc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric, 708 vc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
681 RESOLUTION_TIMEOUT, &process_validation_string, vc); 709 address,
710 numeric,
711 RESOLUTION_TIMEOUT,
712 &process_validation_string, vc);
682} 713}
683 714
684 715
@@ -910,7 +941,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
910 * @param peer the peer that disconnected 941 * @param peer the peer that disconnected
911 */ 942 */
912static void 943static void
913notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 944notify_disconnect (void *cls,
945 const struct GNUNET_PeerIdentity *peer)
914{ 946{
915 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity))) 947 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
916 return; 948 return;
@@ -957,14 +989,19 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
957 * @param peer the peer that connected 989 * @param peer the peer that connected
958 */ 990 */
959static void 991static void
960monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 992monitor_notify_connect (void *cls,
993 const struct GNUNET_PeerIdentity *peer)
961{ 994{
962 monitor_connect_counter++; 995 monitor_connect_counter++;
963 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 996 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
964 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 997 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
965 998
966 FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"), now_str, 999 FPRINTF (stdout,
967 _("Connected to"), GNUNET_i2s (peer), monitor_connect_counter); 1000 _("%24s: %-17s %4s (%u connections in total)\n"),
1001 now_str,
1002 _("Connected to"),
1003 GNUNET_i2s (peer),
1004 monitor_connect_counter);
968} 1005}
969 1006
970 1007
@@ -976,7 +1013,8 @@ monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
976 * @param peer the peer that disconnected 1013 * @param peer the peer that disconnected
977 */ 1014 */
978static void 1015static void
979monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 1016monitor_notify_disconnect (void *cls,
1017 const struct GNUNET_PeerIdentity *peer)
980{ 1018{
981 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 1019 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
982 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 1020 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
@@ -984,8 +1022,12 @@ monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
984 GNUNET_assert(monitor_connect_counter > 0); 1022 GNUNET_assert(monitor_connect_counter > 0);
985 monitor_connect_counter--; 1023 monitor_connect_counter--;
986 1024
987 FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"), now_str, 1025 FPRINTF (stdout,
988 _("Disconnected from"), GNUNET_i2s (peer), monitor_connect_counter); 1026 _("%24s: %-17s %4s (%u connections in total)\n"),
1027 now_str,
1028 _("Disconnected from"),
1029 GNUNET_i2s (peer),
1030 monitor_connect_counter);
989} 1031}
990 1032
991 1033
@@ -1006,8 +1048,10 @@ notify_receive (void *cls,
1006 if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type)) 1048 if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type))
1007 return; 1049 return;
1008 if (verbosity > 0) 1050 if (verbosity > 0)
1009 FPRINTF (stdout, _("Received %u bytes from %s\n"), 1051 FPRINTF (stdout,
1010 (unsigned int) ntohs (message->size), GNUNET_i2s (peer)); 1052 _("Received %u bytes from %s\n"),
1053 (unsigned int) ntohs (message->size),
1054 GNUNET_i2s (peer));
1011 1055
1012 if (traffic_received == 0) 1056 if (traffic_received == 0)
1013 start_time = GNUNET_TIME_absolute_get (); 1057 start_time = GNUNET_TIME_absolute_get ();
@@ -1036,83 +1080,125 @@ print_info (const struct GNUNET_PeerIdentity *id,
1036 if ( ((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || 1080 if ( ((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) ||
1037 (GNUNET_YES == monitor_connections) ) 1081 (GNUNET_YES == monitor_connections) )
1038 { 1082 {
1039 FPRINTF (stdout, _("Peer `%s': %s %s in state `%s' until %s\n"), 1083 FPRINTF (stdout,
1040 GNUNET_i2s (id), 1084 _("Peer `%s': %s %s in state `%s' until %s\n"),
1041 (NULL == transport) ? "<none>" : transport, 1085 GNUNET_i2s (id),
1042 (NULL == transport) ? "<none>" : addr, 1086 (NULL == transport) ? "<none>" : transport,
1043 GNUNET_TRANSPORT_ps2s (state), 1087 (NULL == transport) ? "<none>" : addr,
1044 GNUNET_STRINGS_absolute_time_to_string (state_timeout)); 1088 GNUNET_TRANSPORT_ps2s (state),
1089 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
1045 } 1090 }
1046 else if ( (GNUNET_YES == iterate_connections) && 1091 else if ( (GNUNET_YES == iterate_connections) &&
1047 (GNUNET_TRANSPORT_is_connected(state)) ) 1092 (GNUNET_TRANSPORT_is_connected(state)) )
1048 { 1093 {
1049 /* Only connected peers, skip state */ 1094 /* Only connected peers, skip state */
1050 FPRINTF (stdout, _("Peer `%s': %s %s\n"), GNUNET_i2s (id), transport, addr); 1095 FPRINTF (stdout,
1096 _("Peer `%s': %s %s\n"),
1097 GNUNET_i2s (id),
1098 transport,
1099 addr);
1051 } 1100 }
1052} 1101}
1053 1102
1054 1103
1104/**
1105 * Function called with a textual representation of an address. This
1106 * function will be called several times with different possible
1107 * textual representations, and a last time with @address being NULL
1108 * to signal the end of the iteration. Note that @address NULL
1109 * always is the last call, regardless of the value in @a res.
1110 *
1111 * @param cls closure
1112 * @param address NULL on end of iteration,
1113 * otherwise 0-terminated printable UTF-8 string,
1114 * in particular an empty string if @a res is #GNUNET_NO
1115 * @param res result of the address to string conversion:
1116 * if #GNUNET_OK: conversion successful
1117 * if #GNUNET_NO: address was invalid (or not supported)
1118 * if #GNUNET_SYSERR: communication error (IPC error)
1119 */
1055static void 1120static void
1056process_peer_string (void *cls, const char *address, int res) 1121process_peer_string (void *cls,
1122 const char *address,
1123 int res)
1057{ 1124{
1058 struct PeerResolutionContext *rc = cls; 1125 struct PeerResolutionContext *rc = cls;
1059 1126
1060 if (GNUNET_SYSERR == res) 1127 if (NULL != address)
1061 { 1128 {
1062 FPRINTF (stderr, "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n", 1129 if (GNUNET_SYSERR == res)
1063 GNUNET_i2s (&rc->id), 1130 {
1064 rc->addrcp->transport_name, 1131 FPRINTF (stderr,
1065 rc->addrcp->address_length); 1132 "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n",
1066 print_info (&rc->id, rc->transport, NULL, rc->state, rc->state_timeout); 1133 GNUNET_i2s (&rc->id),
1067 rc->printed = GNUNET_YES; 1134 rc->addrcp->transport_name,
1135 rc->addrcp->address_length);
1136 print_info (&rc->id,
1137 rc->transport,
1138 NULL,
1139 rc->state,
1140 rc->state_timeout);
1141 rc->printed = GNUNET_YES;
1142 return;
1143 }
1144 if (GNUNET_OK == res)
1145 {
1146 print_info (&rc->id,
1147 rc->transport,
1148 address,
1149 rc->state,
1150 rc->state_timeout);
1151 rc->printed = GNUNET_YES;
1152 return; /* Wait for done call */
1153 }
1154 /* GNUNET_NO == res: ignore, was simply not supported */
1068 return; 1155 return;
1069 } 1156 }
1157 /* NULL == address, last call, we are done */
1070 1158
1071 if ((GNUNET_OK == res) && (address != NULL)) 1159 GNUNET_assert (address_resolutions > 0);
1160 address_resolutions--;
1161 if (GNUNET_NO == rc->printed)
1072 { 1162 {
1073 print_info (&rc->id, rc->transport, address, rc->state, rc->state_timeout); 1163 if (numeric == GNUNET_NO)
1074 rc->printed = GNUNET_YES; 1164 {
1075 return; /* Wait for done call */ 1165 /* Failed to resolve address, try numeric lookup
1166 (note: this should not be needed, as transport
1167 should fallback to numeric conversion if DNS takes
1168 too long) */
1169 resolve_peer_address (&rc->id,
1170 rc->addrcp,
1171 GNUNET_YES,
1172 rc->state,
1173 rc->state_timeout);
1174 }
1175 else
1176 {
1177 print_info (&rc->id,
1178 rc->transport,
1179 NULL,
1180 rc->state,
1181 rc->state_timeout);
1182 }
1076 } 1183 }
1077 1184 GNUNET_free (rc->transport);
1078 if (NULL == address) 1185 GNUNET_free (rc->addrcp);
1186 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc);
1187 GNUNET_free (rc);
1188 if ((0 == address_resolutions) && (iterate_connections))
1079 { 1189 {
1080 /* done */ 1190 if (GNUNET_SCHEDULER_NO_TASK != end)
1081 GNUNET_assert(address_resolutions > 0);
1082 address_resolutions--;
1083 if (GNUNET_NO == rc->printed)
1084 { 1191 {
1085 if (numeric == GNUNET_NO) 1192 GNUNET_SCHEDULER_cancel (end);
1086 { 1193 end = GNUNET_SCHEDULER_NO_TASK;
1087 /* Failed to resolve address, try numeric lookup */
1088 resolve_peer_address (&rc->id, rc->addrcp, GNUNET_YES,
1089 rc->state, rc->state_timeout);
1090 }
1091 else
1092 {
1093 print_info (&rc->id, rc->transport, NULL,
1094 rc->state, rc->state_timeout);
1095 }
1096 } 1194 }
1097 GNUNET_free (rc->transport); 1195 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
1098 GNUNET_free (rc->addrcp);
1099 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc);
1100 GNUNET_free(rc);
1101 if ((0 == address_resolutions) && (iterate_connections))
1102 { 1196 {
1103 if (GNUNET_SCHEDULER_NO_TASK != end) 1197 GNUNET_SCHEDULER_cancel (op_timeout);
1104 { 1198 op_timeout = GNUNET_SCHEDULER_NO_TASK;
1105 GNUNET_SCHEDULER_cancel (end);
1106 end = GNUNET_SCHEDULER_NO_TASK;
1107 }
1108 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
1109 {
1110 GNUNET_SCHEDULER_cancel (op_timeout);
1111 op_timeout = GNUNET_SCHEDULER_NO_TASK;
1112 }
1113 ret = 0;
1114 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
1115 } 1199 }
1200 ret = 0;
1201 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
1116 } 1202 }
1117} 1203}
1118 1204
@@ -1138,8 +1224,11 @@ resolve_peer_address (const struct GNUNET_PeerIdentity *id,
1138 rc->state = state; 1224 rc->state = state;
1139 rc->state_timeout = state_timeout; 1225 rc->state_timeout = state_timeout;
1140 /* Resolve address to string */ 1226 /* Resolve address to string */
1141 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric, 1227 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
1142 RESOLUTION_TIMEOUT, &process_peer_string, rc); 1228 address,
1229 numeric,
1230 RESOLUTION_TIMEOUT,
1231 &process_peer_string, rc);
1143} 1232}
1144 1233
1145 1234
@@ -1177,12 +1266,14 @@ process_peer_iteration_cb (void *cls,
1177 1266
1178 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 1267 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
1179 GNUNET_SCHEDULER_cancel (op_timeout); 1268 GNUNET_SCHEDULER_cancel (op_timeout);
1180 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, 1269 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1270 &operation_timeout,
1181 NULL); 1271 NULL);
1182 1272
1183 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1184 "Received address for peer `%s': %s\n", 1274 "Received address for peer `%s': %s\n",
1185 GNUNET_i2s (peer), address->transport_name); 1275 GNUNET_i2s (peer),
1276 address->transport_name);
1186 1277
1187 if (NULL != address) 1278 if (NULL != address)
1188 resolve_peer_address (peer, address, numeric, state, state_timeout); 1279 resolve_peer_address (peer, address, numeric, state, state_timeout);
@@ -1221,7 +1312,8 @@ process_peer_monitoring_cb (void *cls,
1221 1312
1222 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 1313 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
1223 GNUNET_SCHEDULER_cancel (op_timeout); 1314 GNUNET_SCHEDULER_cancel (op_timeout);
1224 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, 1315 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1316 &operation_timeout,
1225 NULL); 1317 NULL);
1226 1318
1227 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer))) 1319 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer)))
@@ -1254,15 +1346,26 @@ process_peer_monitoring_cb (void *cls,
1254 m->state_timeout = state_timeout; 1346 m->state_timeout = state_timeout;
1255 1347
1256 if (NULL != address) 1348 if (NULL != address)
1257 resolve_peer_address (peer, m->address, numeric, m->state, m->state_timeout); 1349 resolve_peer_address (peer,
1350 m->address,
1351 numeric,
1352 m->state,
1353 m->state_timeout);
1258 else 1354 else
1259 print_info (peer, NULL, NULL, m->state, m->state_timeout); 1355 print_info (peer,
1356 NULL,
1357 NULL,
1358 m->state,
1359 m->state_timeout);
1260} 1360}
1261 1361
1362
1262static void 1363static void
1263try_connect_cb (void *cls, const int result) 1364try_connect_cb (void *cls,
1365 const int result)
1264{ 1366{
1265 static int retries = 0; 1367 static int retries = 0;
1368
1266 if (GNUNET_OK == result) 1369 if (GNUNET_OK == result)
1267 { 1370 {
1268 tc_handle = NULL; 1371 tc_handle = NULL;
@@ -1274,8 +1377,9 @@ try_connect_cb (void *cls, const int result)
1274 NULL ); 1377 NULL );
1275 else 1378 else
1276 { 1379 {
1277 FPRINTF (stderr, "%s", 1380 FPRINTF (stderr,
1278 _("Failed to send connect request to transport service\n") ); 1381 "%s",
1382 _("Failed to send connect request to transport service\n") );
1279 if (GNUNET_SCHEDULER_NO_TASK != end) 1383 if (GNUNET_SCHEDULER_NO_TASK != end)
1280 GNUNET_SCHEDULER_cancel (end); 1384 GNUNET_SCHEDULER_cancel (end);
1281 ret = 1; 1385 ret = 1;
@@ -1284,8 +1388,10 @@ try_connect_cb (void *cls, const int result)
1284 } 1388 }
1285} 1389}
1286 1390
1391
1287static void 1392static void
1288try_disconnect_cb (void *cls, const int result) 1393try_disconnect_cb (void *cls,
1394 const int result)
1289{ 1395{
1290 static int retries = 0; 1396 static int retries = 0;
1291 if (GNUNET_OK == result) 1397 if (GNUNET_OK == result)
@@ -1309,6 +1415,7 @@ try_disconnect_cb (void *cls, const int result)
1309 } 1415 }
1310} 1416}
1311 1417
1418
1312/** 1419/**
1313 * Function called with the result of the check if the 'transport' 1420 * Function called with the result of the check if the 'transport'
1314 * service is running. 1421 * service is running.
diff --git a/src/transport/plugin_transport_bluetooth.c b/src/transport/plugin_transport_bluetooth.c
index aad96cf69..8ab64b15c 100644
--- a/src/transport/plugin_transport_bluetooth.c
+++ b/src/transport/plugin_transport_bluetooth.c
@@ -504,7 +504,9 @@ struct MacAndSession
504 * @return string representing the same address 504 * @return string representing the same address
505 */ 505 */
506static const char * 506static const char *
507bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen); 507bluetooth_plugin_address_to_string (void *cls,
508 const void *addr,
509 size_t addrlen);
508 510
509/** 511/**
510 * Print MAC addresses nicely. 512 * Print MAC addresses nicely.
@@ -1055,7 +1057,9 @@ create_macendpoint (struct Plugin *plugin,
1055 1, GNUNET_NO); 1057 1, GNUNET_NO);
1056 LOG (GNUNET_ERROR_TYPE_DEBUG, 1058 LOG (GNUNET_ERROR_TYPE_DEBUG,
1057 "New MAC endpoint `%s'\n", 1059 "New MAC endpoint `%s'\n",
1058 bluetooth_plugin_address_to_string(NULL, addr, sizeof (struct WlanAddress))); 1060 bluetooth_plugin_address_to_string(NULL,
1061 addr,
1062 sizeof (struct WlanAddress)));
1059 return pos; 1063 return pos;
1060} 1064}
1061 1065
@@ -1119,8 +1123,11 @@ bluetooth_plugin_get_session (void *cls,
1119 LOG (GNUNET_ERROR_TYPE_DEBUG, 1123 LOG (GNUNET_ERROR_TYPE_DEBUG,
1120 "Service asked to create session for peer `%s' with MAC `%s'\n", 1124 "Service asked to create session for peer `%s' with MAC `%s'\n",
1121 GNUNET_i2s (&address->peer), 1125 GNUNET_i2s (&address->peer),
1122 bluetooth_plugin_address_to_string(NULL, address->address, address->address_length)); 1126 bluetooth_plugin_address_to_string(NULL,
1123 endpoint = create_macendpoint (plugin, (struct WlanAddress *) address->address); 1127 address->address,
1128 address->address_length));
1129 endpoint = create_macendpoint (plugin,
1130 (struct WlanAddress *) address->address);
1124 return get_session (endpoint, &address->peer); 1131 return get_session (endpoint, &address->peer);
1125} 1132}
1126 1133
@@ -1300,8 +1307,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1300 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", 1307 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n",
1301 (unsigned int) msize, 1308 (unsigned int) msize,
1302 GNUNET_i2s (&tmpsource), 1309 GNUNET_i2s (&tmpsource),
1303 bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, 1310 bluetooth_plugin_address_to_string (NULL,
1304 sizeof (mas->endpoint->addr))); 1311 &mas->endpoint->addr,
1312 sizeof (mas->endpoint->addr)));
1305 1313
1306 GNUNET_STATISTICS_update (plugin->env->stats, 1314 GNUNET_STATISTICS_update (plugin->env->stats,
1307 _("# HELLO messages received via Bluetooth"), 1, 1315 _("# HELLO messages received via Bluetooth"), 1,
@@ -1325,10 +1333,13 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1325 LOG (GNUNET_ERROR_TYPE_DEBUG, 1333 LOG (GNUNET_ERROR_TYPE_DEBUG,
1326 "Processing %u bytes of FRAGMENT from MAC %s\n", 1334 "Processing %u bytes of FRAGMENT from MAC %s\n",
1327 (unsigned int) msize, 1335 (unsigned int) msize,
1328 bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, 1336 bluetooth_plugin_address_to_string (NULL,
1329 sizeof (mas->endpoint->addr))); 1337 &mas->endpoint->addr,
1338 sizeof (mas->endpoint->addr)));
1330 GNUNET_STATISTICS_update (plugin->env->stats, 1339 GNUNET_STATISTICS_update (plugin->env->stats,
1331 _("# fragments received via Bluetooth"), 1, GNUNET_NO); 1340 _("# fragments received via Bluetooth"),
1341 1,
1342 GNUNET_NO);
1332 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, 1343 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag,
1333 hdr); 1344 hdr);
1334 break; 1345 break;
@@ -1347,8 +1358,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1347 { 1358 {
1348 LOG (GNUNET_ERROR_TYPE_DEBUG, 1359 LOG (GNUNET_ERROR_TYPE_DEBUG,
1349 "Got last ACK, finished message transmission to `%s' (%p)\n", 1360 "Got last ACK, finished message transmission to `%s' (%p)\n",
1350 bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, 1361 bluetooth_plugin_address_to_string (NULL,
1351 sizeof (mas->endpoint->addr)), 1362 &mas->endpoint->addr,
1363 sizeof (mas->endpoint->addr)),
1352 fm); 1364 fm);
1353 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); 1365 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
1354 if (NULL != fm->cont) 1366 if (NULL != fm->cont)
@@ -1363,15 +1375,17 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1363 { 1375 {
1364 LOG (GNUNET_ERROR_TYPE_DEBUG, 1376 LOG (GNUNET_ERROR_TYPE_DEBUG,
1365 "Got an ACK, message transmission to `%s' not yet finished\n", 1377 "Got an ACK, message transmission to `%s' not yet finished\n",
1366 bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, 1378 bluetooth_plugin_address_to_string (NULL,
1367 sizeof (mas->endpoint->addr))); 1379 &mas->endpoint->addr,
1380 sizeof (mas->endpoint->addr)));
1368 break; 1381 break;
1369 } 1382 }
1370 } 1383 }
1371 LOG (GNUNET_ERROR_TYPE_DEBUG, 1384 LOG (GNUNET_ERROR_TYPE_DEBUG,
1372 "ACK not matched against any active fragmentation with MAC `%s'\n", 1385 "ACK not matched against any active fragmentation with MAC `%s'\n",
1373 bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, 1386 bluetooth_plugin_address_to_string (NULL,
1374 sizeof (mas->endpoint->addr))); 1387 &mas->endpoint->addr,
1388 sizeof (mas->endpoint->addr)));
1375 break; 1389 break;
1376 case GNUNET_MESSAGE_TYPE_WLAN_DATA: 1390 case GNUNET_MESSAGE_TYPE_WLAN_DATA:
1377 if (NULL == mas->endpoint) 1391 if (NULL == mas->endpoint)
@@ -1675,7 +1689,9 @@ bluetooth_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
1675 * @return string representing the same address 1689 * @return string representing the same address
1676 */ 1690 */
1677static const char * 1691static const char *
1678bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) 1692bluetooth_plugin_address_to_string (void *cls,
1693 const void *addr,
1694 size_t addrlen)
1679{ 1695{
1680 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac; 1696 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1681 static char macstr[36]; 1697 static char macstr[36];
@@ -1686,9 +1702,12 @@ bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1686 return NULL; 1702 return NULL;
1687 } 1703 }
1688 mac = &((struct WlanAddress *) addr)->mac; 1704 mac = &((struct WlanAddress *) addr)->mac;
1689 GNUNET_snprintf (macstr, sizeof (macstr), "%s.%u.%s", 1705 GNUNET_snprintf (macstr,
1690 PLUGIN_NAME, ntohl (((struct WlanAddress *) addr)->options), 1706 sizeof (macstr),
1691 mac_to_string (mac)); 1707 "%s.%u.%s",
1708 PLUGIN_NAME,
1709 ntohl (((struct WlanAddress *) addr)->options),
1710 mac_to_string (mac));
1692 return macstr; 1711 return macstr;
1693} 1712}
1694 1713
@@ -1704,7 +1723,7 @@ bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1704 * @param numeric should (IP) addresses be displayed in numeric form? 1723 * @param numeric should (IP) addresses be displayed in numeric form?
1705 * @param timeout after how long should we give up? 1724 * @param timeout after how long should we give up?
1706 * @param asc function to call on each string 1725 * @param asc function to call on each string
1707 * @param asc_cls closure for asc 1726 * @param asc_cls closure for @a asc
1708 */ 1727 */
1709static void 1728static void
1710bluetooth_plugin_address_pretty_printer (void *cls, const char *type, 1729bluetooth_plugin_address_pretty_printer (void *cls, const char *type,
@@ -1714,19 +1733,15 @@ bluetooth_plugin_address_pretty_printer (void *cls, const char *type,
1714 GNUNET_TRANSPORT_AddressStringCallback asc, 1733 GNUNET_TRANSPORT_AddressStringCallback asc,
1715 void *asc_cls) 1734 void *asc_cls)
1716{ 1735{
1717 char *ret; 1736 const char *ret;
1718 1737
1719 if (sizeof (struct WlanAddress) != addrlen) 1738 if (sizeof (struct WlanAddress) == addrlen)
1720 { 1739 ret = bluetooth_plugin_address_to_string(NULL, addr, addrlen);
1721 /* invalid address */
1722 asc (asc_cls, NULL, GNUNET_SYSERR);
1723 }
1724 else 1740 else
1725 { 1741 ret = NULL;
1726 ret = GNUNET_strdup (bluetooth_plugin_address_to_string(NULL, addr, addrlen)); 1742 asc (asc_cls,
1727 asc (asc_cls, ret, GNUNET_OK); 1743 ret,
1728 GNUNET_free (ret); 1744 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1729 }
1730 asc (asc_cls, NULL, GNUNET_OK); 1745 asc (asc_cls, NULL, GNUNET_OK);
1731} 1746}
1732 1747
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 15150b3dc..d853cc7f7 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -1190,20 +1190,25 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1190 { 1190 {
1191 if ((0 != msg->data.result) || (http_statuscode != 200)) 1191 if ((0 != msg->data.result) || (http_statuscode != 200))
1192 { 1192 {
1193 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1193 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1194 "Session %p/connection %p: PUT connection to `%s' ended with status %i reason %i: `%s'\n", 1194 plugin->name,
1195 s, msg->easy_handle, GNUNET_i2s (&s->target), 1195 "Session %p/connection %p: PUT connection to `%s' ended with status %i reason %i: `%s'\n",
1196 http_statuscode, 1196 s, msg->easy_handle,
1197 msg->data.result, 1197 GNUNET_i2s (&s->target),
1198 curl_easy_strerror (msg->data.result)); 1198 http_statuscode,
1199 msg->data.result,
1200 curl_easy_strerror (msg->data.result));
1199 } 1201 }
1200 else 1202 else
1201 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1203 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1202 "Session %p/connection %p: PUT connection to `%s' ended normal\n", 1204 plugin->name,
1203 s, msg->easy_handle, GNUNET_i2s (&s->target)); 1205 "Session %p/connection %p: PUT connection to `%s' ended normal\n",
1204 if (s->client_get == NULL) 1206 s, msg->easy_handle,
1207 GNUNET_i2s (&s->target));
1208 if (NULL == s->client_get)
1205 { 1209 {
1206 /* Disconnect other transmission direction and tell transport */ 1210 /* Disconnect other transmission direction and tell transport */
1211 /* FIXME? */
1207 } 1212 }
1208 curl_multi_remove_handle (plugin->curl_multi_handle, easy_h); 1213 curl_multi_remove_handle (plugin->curl_multi_handle, easy_h);
1209 curl_easy_cleanup (easy_h); 1214 curl_easy_cleanup (easy_h);
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
index f5712db58..02129f37d 100644
--- a/src/transport/plugin_transport_http_common.c
+++ b/src/transport/plugin_transport_http_common.c
@@ -207,18 +207,24 @@ http_common_plugin_address_pretty_printer (void *cls,
207 void *asc_cls) 207 void *asc_cls)
208{ 208{
209 const struct HttpAddress *address = addr; 209 const struct HttpAddress *address = addr;
210 210 const char *ret;
211 if (NULL 211
212 == http_common_plugin_address_to_string (NULL, type, address, addrlen)) 212 ret = http_common_plugin_address_to_string (NULL,
213 asc (asc_cls, NULL, GNUNET_SYSERR); 213 type,
214 else 214 address,
215 asc (asc_cls, 215 addrlen);
216 http_common_plugin_address_to_string (NULL, type, address, addrlen), 216 asc (asc_cls,
217 GNUNET_OK); 217 NULL,
218 asc (asc_cls, NULL, GNUNET_OK); 218 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
219 asc (asc_cls,
220 NULL,
221 GNUNET_OK);
219} 222}
220 223
221 224
225/**
226 * FIXME.
227 */
222const char * 228const char *
223http_common_plugin_address_to_url (void *cls, 229http_common_plugin_address_to_url (void *cls,
224 const void *addr, 230 const void *addr,
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index ed3ecbc6b..ca90d461d 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -1,21 +1,21 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2002--2013 Christian Grothoff (and other contributing authors) 3 (C) 2002--2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
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 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 */ 19 */
20/** 20/**
21 * @file transport/plugin_transport_tcp.c 21 * @file transport/plugin_transport_tcp.c
@@ -562,13 +562,15 @@ tcp_address_to_string (void *cls,
562 sb = &a4; 562 sb = &a4;
563 break; 563 break;
564 default: 564 default:
565 LOG(GNUNET_ERROR_TYPE_WARNING, _("Unexpected address length: %u bytes\n"), 565 LOG (GNUNET_ERROR_TYPE_WARNING,
566 (unsigned int ) addrlen); 566 _("Unexpected address length: %u bytes\n"),
567 (unsigned int ) addrlen);
567 return NULL ; 568 return NULL ;
568 } 569 }
569 if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) 570 if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN))
570 { 571 {
571 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 572 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
573 "inet_ntop");
572 return NULL ; 574 return NULL ;
573 } 575 }
574 GNUNET_snprintf (rbuf, sizeof(rbuf), 576 GNUNET_snprintf (rbuf, sizeof(rbuf),
@@ -816,9 +818,11 @@ tcp_disconnect_session (void *cls,
816 818
817 while (NULL != (pm = session->pending_messages_head)) 819 while (NULL != (pm = session->pending_messages_head))
818 { 820 {
819 LOG(GNUNET_ERROR_TYPE_DEBUG, 821 LOG (GNUNET_ERROR_TYPE_DEBUG,
820 pm->transmit_cont != NULL ? "Could not deliver message to `%4s'.\n" : "Could not deliver message to `%4s', notifying.\n", 822 (NULL != pm->transmit_cont)
821 GNUNET_i2s (&session->target)); 823 ? "Could not deliver message to `%4s'.\n"
824 : "Could not deliver message to `%4s', notifying.\n",
825 GNUNET_i2s (&session->target));
822 GNUNET_STATISTICS_update (session->plugin->env->stats, 826 GNUNET_STATISTICS_update (session->plugin->env->stats,
823 gettext_noop ("# bytes currently in TCP buffers"), 827 gettext_noop ("# bytes currently in TCP buffers"),
824 -(int64_t) pm->message_size, GNUNET_NO); 828 -(int64_t) pm->message_size, GNUNET_NO);
@@ -1651,7 +1655,8 @@ static struct PrettyPrinterContext *ppc_dll_head;
1651static struct PrettyPrinterContext *ppc_dll_tail; 1655static struct PrettyPrinterContext *ppc_dll_tail;
1652 1656
1653/** 1657/**
1654 * Context for address to string conversion. 1658 * Context for address to string conversion, closure
1659 * for #append_port().
1655 */ 1660 */
1656struct PrettyPrinterContext 1661struct PrettyPrinterContext
1657{ 1662{
@@ -1681,7 +1686,7 @@ struct PrettyPrinterContext
1681 GNUNET_TRANSPORT_AddressStringCallback asc; 1686 GNUNET_TRANSPORT_AddressStringCallback asc;
1682 1687
1683 /** 1688 /**
1684 * Clsoure for 'asc'. 1689 * Clsoure for @e asc.
1685 */ 1690 */
1686 void *asc_cls; 1691 void *asc_cls;
1687 1692
@@ -1701,64 +1706,54 @@ struct PrettyPrinterContext
1701 uint32_t options; 1706 uint32_t options;
1702}; 1707};
1703 1708
1704static void
1705ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1706{
1707 struct PrettyPrinterContext *ppc = cls;
1708
1709 ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1710 if (NULL != ppc->resolver_handle)
1711 {
1712 GNUNET_RESOLVER_request_cancel (ppc->resolver_handle);
1713 ppc->resolver_handle = NULL;
1714 }
1715 GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc);
1716 GNUNET_free(ppc);
1717}
1718 1709
1719/** 1710/**
1720 * Append our port and forward the result. 1711 * Append our port and forward the result.
1721 * 1712 *
1722 * @param cls the 'struct PrettyPrinterContext*' 1713 * @param cls the `struct PrettyPrinterContext *`
1723 * @param hostname hostname part of the address 1714 * @param hostname hostname part of the address
1724 */ 1715 */
1725static void 1716static void
1726append_port (void *cls, const char *hostname) 1717append_port (void *cls,
1718 const char *hostname)
1727{ 1719{
1728 struct PrettyPrinterContext *ppc = cls; 1720 struct PrettyPrinterContext *ppc = cls;
1729 struct PrettyPrinterContext *cur;
1730 char *ret; 1721 char *ret;
1731 1722
1732 if (NULL == hostname) 1723 if (NULL == hostname)
1733 { 1724 {
1734 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); /* Final call, done */ 1725 /* Final call, done */
1735 GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc);
1736 GNUNET_SCHEDULER_cancel (ppc->timeout_task);
1737 ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1738 ppc->resolver_handle = NULL; 1726 ppc->resolver_handle = NULL;
1739 GNUNET_free(ppc); 1727 GNUNET_CONTAINER_DLL_remove (ppc_dll_head,
1728 ppc_dll_tail,
1729 ppc);
1730 ppc->asc (ppc->asc_cls,
1731 NULL,
1732 GNUNET_OK);
1733 GNUNET_free (ppc);
1740 return; 1734 return;
1741 } 1735 }
1742 for (cur = ppc_dll_head; (NULL != cur); cur = cur->next)
1743 if (cur == ppc)
1744 break;
1745 if (NULL == cur)
1746 {
1747 ppc->asc (ppc->asc_cls, NULL, GNUNET_SYSERR);
1748 GNUNET_break(0);
1749 return;
1750 }
1751
1752 if (GNUNET_YES == ppc->ipv6) 1736 if (GNUNET_YES == ppc->ipv6)
1753 GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, 1737 GNUNET_asprintf (&ret,
1754 ppc->port); 1738 "%s.%u.[%s]:%d",
1739 PLUGIN_NAME,
1740 ppc->options,
1741 hostname,
1742 ppc->port);
1755 else 1743 else
1756 GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, 1744 GNUNET_asprintf (&ret,
1757 ppc->port); 1745 "%s.%u.%s:%d",
1758 ppc->asc (ppc->asc_cls, ret, GNUNET_OK); 1746 PLUGIN_NAME,
1759 GNUNET_free(ret); 1747 ppc->options,
1748 hostname,
1749 ppc->port);
1750 ppc->asc (ppc->asc_cls,
1751 ret,
1752 GNUNET_OK);
1753 GNUNET_free (ret);
1760} 1754}
1761 1755
1756
1762/** 1757/**
1763 * Convert the transports address to a nice, human-readable 1758 * Convert the transports address to a nice, human-readable
1764 * format. 1759 * format.
@@ -1767,18 +1762,21 @@ append_port (void *cls, const char *hostname)
1767 * @param type name of the transport that generated the address 1762 * @param type name of the transport that generated the address
1768 * @param addr one of the addresses of the host, NULL for the last address 1763 * @param addr one of the addresses of the host, NULL for the last address
1769 * the specific address format depends on the transport 1764 * the specific address format depends on the transport
1770 * @param addrlen length of the address 1765 * @param addrlen length of the @a addr
1771 * @param numeric should (IP) addresses be displayed in numeric form? 1766 * @param numeric should (IP) addresses be displayed in numeric form?
1772 * @param timeout after how long should we give up? 1767 * @param timeout after how long should we give up?
1773 * @param asc function to call on each string 1768 * @param asc function to call on each string
1774 * @param asc_cls closure for asc 1769 * @param asc_cls closure for @a asc
1775 *
1776 */ 1770 */
1777static void 1771static void
1778tcp_plugin_address_pretty_printer (void *cls, const char *type, 1772tcp_plugin_address_pretty_printer (void *cls,
1779 const void *addr, size_t addrlen, int numeric, 1773 const char *type,
1780 struct GNUNET_TIME_Relative timeout, 1774 const void *addr,
1781 GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) 1775 size_t addrlen,
1776 int numeric,
1777 struct GNUNET_TIME_Relative timeout,
1778 GNUNET_TRANSPORT_AddressStringCallback asc,
1779 void *asc_cls)
1782{ 1780{
1783 struct PrettyPrinterContext *ppc; 1781 struct PrettyPrinterContext *ppc;
1784 const void *sb; 1782 const void *sb;
@@ -1790,7 +1788,7 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type,
1790 uint16_t port; 1788 uint16_t port;
1791 uint32_t options; 1789 uint32_t options;
1792 1790
1793 if (addrlen == sizeof(struct IPv6TcpAddress)) 1791 if (sizeof(struct IPv6TcpAddress) == addrlen)
1794 { 1792 {
1795 t6 = addr; 1793 t6 = addr;
1796 memset (&a6, 0, sizeof(a6)); 1794 memset (&a6, 0, sizeof(a6));
@@ -1802,7 +1800,7 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type,
1802 sb = &a6; 1800 sb = &a6;
1803 sbs = sizeof(a6); 1801 sbs = sizeof(a6);
1804 } 1802 }
1805 else if (addrlen == sizeof(struct IPv4TcpAddress)) 1803 else if (sizeof(struct IPv4TcpAddress) == addrlen)
1806 { 1804 {
1807 t4 = addr; 1805 t4 = addr;
1808 memset (&a4, 0, sizeof(a4)); 1806 memset (&a4, 0, sizeof(a4));
@@ -1830,21 +1828,23 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type,
1830 ppc->asc_cls = asc_cls; 1828 ppc->asc_cls = asc_cls;
1831 ppc->port = port; 1829 ppc->port = port;
1832 ppc->options = options; 1830 ppc->options = options;
1833 ppc->timeout_task = GNUNET_SCHEDULER_add_delayed ( 1831 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
1834 GNUNET_TIME_relative_multiply (timeout, 2), &ppc_cancel_task, ppc); 1832 sbs,
1835 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, 1833 ! numeric,
1836 timeout, &append_port, ppc); 1834 timeout,
1837 if (NULL != ppc->resolver_handle) 1835 &append_port, ppc);
1836 if (NULL == ppc->resolver_handle)
1838 { 1837 {
1839 GNUNET_CONTAINER_DLL_insert(ppc_dll_head, ppc_dll_tail, ppc); 1838 GNUNET_break (0);
1840 } 1839 GNUNET_free (ppc);
1841 else 1840 return;
1842 {
1843 GNUNET_break(0);
1844 GNUNET_free(ppc);
1845 } 1841 }
1842 GNUNET_CONTAINER_DLL_insert (ppc_dll_head,
1843 ppc_dll_tail,
1844 ppc);
1846} 1845}
1847 1846
1847
1848/** 1848/**
1849 * Check if the given port is plausible (must be either our listen 1849 * Check if the given port is plausible (must be either our listen
1850 * port or our advertised port), or any port if we are behind NAT 1850 * port or our advertised port), or any port if we are behind NAT
@@ -2496,12 +2496,14 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2496 aport = 0; 2496 aport = 0;
2497 if (bport != 0) 2497 if (bport != 0)
2498 { 2498 {
2499 service = GNUNET_SERVICE_start ("transport-tcp", env->cfg, 2499 service = GNUNET_SERVICE_start ("transport-tcp",
2500 GNUNET_SERVICE_OPTION_NONE); 2500 env->cfg,
2501 if (service == NULL ) 2501 GNUNET_SERVICE_OPTION_NONE);
2502 if (service == NULL)
2502 { 2503 {
2503 LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to start service.\n")); 2504 LOG (GNUNET_ERROR_TYPE_WARNING,
2504 return NULL ; 2505 _("Failed to start service.\n"));
2506 return NULL;
2505 } 2507 }
2506 } 2508 }
2507 else 2509 else
@@ -2555,7 +2557,6 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2555 api->cls = plugin; 2557 api->cls = plugin;
2556 api->send = &tcp_plugin_send; 2558 api->send = &tcp_plugin_send;
2557 api->get_session = &tcp_plugin_get_session; 2559 api->get_session = &tcp_plugin_get_session;
2558
2559 api->disconnect_session = &tcp_disconnect_session; 2560 api->disconnect_session = &tcp_disconnect_session;
2560 api->query_keepalive_factor = &tcp_query_keepalive_factor; 2561 api->query_keepalive_factor = &tcp_query_keepalive_factor;
2561 api->disconnect_peer = &tcp_plugin_disconnect; 2562 api->disconnect_peer = &tcp_plugin_disconnect;
@@ -2588,9 +2589,10 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2588 GNUNET_free(api); 2589 GNUNET_free(api);
2589 return NULL; 2590 return NULL;
2590 } 2591 }
2591 plugin->server = GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, 2592 plugin->server
2592 plugin, NULL, 2593 = GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check,
2593 idle_timeout, GNUNET_YES); 2594 plugin, NULL,
2595 idle_timeout, GNUNET_YES);
2594 } 2596 }
2595 plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); 2597 plugin->handlers = GNUNET_malloc (sizeof (my_handlers));
2596 memcpy (plugin->handlers, my_handlers, sizeof(my_handlers)); 2598 memcpy (plugin->handlers, my_handlers, sizeof(my_handlers));
@@ -2656,13 +2658,13 @@ libgnunet_plugin_transport_tcp_done (void *cls)
2656 next = ppc_dll_head; 2658 next = ppc_dll_head;
2657 for (cur = next; NULL != cur; cur = next) 2659 for (cur = next; NULL != cur; cur = next)
2658 { 2660 {
2661 GNUNET_break (0);
2659 next = cur->next; 2662 next = cur->next;
2660 GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, cur); 2663 GNUNET_CONTAINER_DLL_remove (ppc_dll_head,
2661 if (NULL != cur->resolver_handle) 2664 ppc_dll_tail,
2662 GNUNET_RESOLVER_request_cancel (cur->resolver_handle); 2665 cur);
2663 GNUNET_SCHEDULER_cancel (cur->timeout_task); 2666 GNUNET_RESOLVER_request_cancel (cur->resolver_handle);
2664 GNUNET_free(cur); 2667 GNUNET_free (cur);
2665 GNUNET_break(0);
2666 } 2668 }
2667 2669
2668 if (NULL != plugin->service) 2670 if (NULL != plugin->service)
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 9bf2d8181..08a532aed 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -75,7 +75,7 @@ static struct PrettyPrinterContext *ppc_dll_tail;
75 75
76 76
77/** 77/**
78 * Closure for 'append_port'. 78 * Closure for #append_port().
79 */ 79 */
80struct PrettyPrinterContext 80struct PrettyPrinterContext
81{ 81{
@@ -717,23 +717,6 @@ udp_string_to_address (void *cls,
717} 717}
718 718
719 719
720static void
721ppc_cancel_task (void *cls,
722 const struct GNUNET_SCHEDULER_TaskContext *tc)
723{
724 struct PrettyPrinterContext *ppc = cls;
725
726 ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
727 if (NULL != ppc->resolver_handle)
728 {
729 GNUNET_RESOLVER_request_cancel (ppc->resolver_handle);
730 ppc->resolver_handle = NULL;
731 }
732 GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc);
733 GNUNET_free(ppc);
734}
735
736
737/** 720/**
738 * Append our port and forward the result. 721 * Append our port and forward the result.
739 * 722 *
@@ -744,37 +727,39 @@ static void
744append_port (void *cls, const char *hostname) 727append_port (void *cls, const char *hostname)
745{ 728{
746 struct PrettyPrinterContext *ppc = cls; 729 struct PrettyPrinterContext *ppc = cls;
747 struct PrettyPrinterContext *cur;
748 char *ret; 730 char *ret;
749 731
750 if (hostname == NULL ) 732 if (NULL == hostname)
751 { 733 {
752 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); /* Final call, done */ 734 /* Final call, done */
753 GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); 735 ppc->asc (ppc->asc_cls,
754 GNUNET_SCHEDULER_cancel (ppc->timeout_task); 736 NULL,
755 ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; 737 GNUNET_OK);
738 GNUNET_CONTAINER_DLL_remove (ppc_dll_head,
739 ppc_dll_tail,
740 ppc);
756 ppc->resolver_handle = NULL; 741 ppc->resolver_handle = NULL;
757 GNUNET_free(ppc); 742 GNUNET_free (ppc);
758 return; 743 return;
759 } 744 }
760 for (cur = ppc_dll_head; (NULL != cur); cur = cur->next)
761 if (cur == ppc)
762 break;
763 if (NULL == cur)
764 {
765 ppc->asc (ppc->asc_cls, NULL, GNUNET_SYSERR);
766 GNUNET_break(0);
767 return;
768 }
769
770 if (GNUNET_YES == ppc->ipv6) 745 if (GNUNET_YES == ppc->ipv6)
771 GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, 746 GNUNET_asprintf (&ret,
772 ppc->port); 747 "%s.%u.[%s]:%d",
748 PLUGIN_NAME,
749 ppc->options,
750 hostname,
751 ppc->port);
773 else 752 else
774 GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, 753 GNUNET_asprintf (&ret,
775 ppc->port); 754 "%s.%u.%s:%d",
776 ppc->asc (ppc->asc_cls, ret, GNUNET_OK); 755 PLUGIN_NAME,
777 GNUNET_free(ret); 756 ppc->options,
757 hostname,
758 ppc->port);
759 ppc->asc (ppc->asc_cls,
760 ret,
761 GNUNET_OK);
762 GNUNET_free (ret);
778} 763}
779 764
780 765
@@ -845,7 +830,7 @@ udp_plugin_address_pretty_printer (void *cls,
845 else 830 else
846 { 831 {
847 /* invalid address */ 832 /* invalid address */
848 GNUNET_break_op(0); 833 GNUNET_break_op (0);
849 asc (asc_cls, NULL , GNUNET_SYSERR); 834 asc (asc_cls, NULL , GNUNET_SYSERR);
850 asc (asc_cls, NULL, GNUNET_OK); 835 asc (asc_cls, NULL, GNUNET_OK);
851 return; 836 return;
@@ -859,11 +844,15 @@ udp_plugin_address_pretty_printer (void *cls,
859 ppc->ipv6 = GNUNET_YES; 844 ppc->ipv6 = GNUNET_YES;
860 else 845 else
861 ppc->ipv6 = GNUNET_NO; 846 ppc->ipv6 = GNUNET_NO;
862 ppc->timeout_task = GNUNET_SCHEDULER_add_delayed ( 847 GNUNET_CONTAINER_DLL_insert (ppc_dll_head,
863 GNUNET_TIME_relative_multiply (timeout, 2), &ppc_cancel_task, ppc); 848 ppc_dll_tail,
864 GNUNET_CONTAINER_DLL_insert(ppc_dll_head, ppc_dll_tail, ppc); 849 ppc);
865 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, 850 ppc->resolver_handle
866 timeout, &append_port, ppc); 851 = GNUNET_RESOLVER_hostname_get (sb,
852 sbs,
853 ! numeric,
854 timeout,
855 &append_port, ppc);
867} 856}
868 857
869 858
@@ -3313,8 +3302,8 @@ libgnunet_plugin_transport_udp_done (void *cls)
3313 } 3302 }
3314 3303
3315 /* Clean up sessions */ 3304 /* Clean up sessions */
3316 LOG(GNUNET_ERROR_TYPE_DEBUG, 3305 LOG (GNUNET_ERROR_TYPE_DEBUG,
3317 "Cleaning up sessions\n"); 3306 "Cleaning up sessions\n");
3318 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 3307 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
3319 &disconnect_and_free_it, plugin); 3308 &disconnect_and_free_it, plugin);
3320 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); 3309 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions);
@@ -3322,12 +3311,13 @@ libgnunet_plugin_transport_udp_done (void *cls)
3322 next = ppc_dll_head; 3311 next = ppc_dll_head;
3323 for (cur = next; NULL != cur; cur = next) 3312 for (cur = next; NULL != cur; cur = next)
3324 { 3313 {
3314 GNUNET_break(0);
3325 next = cur->next; 3315 next = cur->next;
3326 GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, cur); 3316 GNUNET_CONTAINER_DLL_remove (ppc_dll_head,
3317 ppc_dll_tail,
3318 cur);
3327 GNUNET_RESOLVER_request_cancel (cur->resolver_handle); 3319 GNUNET_RESOLVER_request_cancel (cur->resolver_handle);
3328 GNUNET_SCHEDULER_cancel (cur->timeout_task); 3320 GNUNET_free (cur);
3329 GNUNET_free(cur);
3330 GNUNET_break(0);
3331 } 3321 }
3332 GNUNET_free (plugin); 3322 GNUNET_free (plugin);
3333 GNUNET_free (api); 3323 GNUNET_free (api);
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 792d7718e..03c38f4e1 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -64,9 +64,9 @@ GNUNET_NETWORK_STRUCT_BEGIN
64 64
65struct UnixAddress 65struct UnixAddress
66{ 66{
67 uint32_t options GNUNET_PACKED; 67 uint32_t options GNUNET_PACKED;
68 68
69 uint32_t addrlen GNUNET_PACKED; 69 uint32_t addrlen GNUNET_PACKED;
70}; 70};
71 71
72 72
@@ -340,6 +340,7 @@ reschedule_session_timeout (struct Session *s);
340static void 340static void
341unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 341unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
342 342
343
343static struct sockaddr_un * 344static struct sockaddr_un *
344unix_address_to_sockaddr (const char *unixpath, 345unix_address_to_sockaddr (const char *unixpath,
345 socklen_t *sock_len) 346 socklen_t *sock_len)
@@ -372,11 +373,13 @@ unix_address_to_sockaddr (const char *unixpath,
372 * 373 *
373 * @param cls closure 374 * @param cls closure
374 * @param addr binary address 375 * @param addr binary address
375 * @param addrlen length of the address 376 * @param addrlen length of the @a addr
376 * @return string representing the same address 377 * @return string representing the same address
377 */ 378 */
378static const char * 379static const char *
379unix_address_to_string (void *cls, const void *addr, size_t addrlen) 380unix_address_to_string (void *cls,
381 const void *addr,
382 size_t addrlen)
380{ 383{
381 static char rbuf[1024]; 384 static char rbuf[1024];
382 struct UnixAddress *ua = (struct UnixAddress *) addr; 385 struct UnixAddress *ua = (struct UnixAddress *) addr;
@@ -387,7 +390,7 @@ unix_address_to_string (void *cls, const void *addr, size_t addrlen)
387 if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) 390 if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen))
388 { 391 {
389 GNUNET_break(0); 392 GNUNET_break(0);
390 return NULL ; 393 return NULL;
391 } 394 }
392 addrstr = (char *) &ua[1]; 395 addrstr = (char *) &ua[1];
393 addr_str_len = ntohl (ua->addrlen); 396 addr_str_len = ntohl (ua->addrlen);
@@ -395,39 +398,36 @@ unix_address_to_string (void *cls, const void *addr, size_t addrlen)
395 if (addr_str_len != addrlen - sizeof(struct UnixAddress)) 398 if (addr_str_len != addrlen - sizeof(struct UnixAddress))
396 { 399 {
397 GNUNET_break(0); 400 GNUNET_break(0);
398 return NULL ; 401 return NULL;
399 } 402 }
400 403
401 if ('\0' != addrstr[addr_str_len - 1]) 404 if ('\0' != addrstr[addr_str_len - 1])
402 { 405 {
403 GNUNET_break(0); 406 GNUNET_break(0);
404 return NULL ; 407 return NULL;
405 } 408 }
406 if (strlen (addrstr) + 1 != addr_str_len) 409 if (strlen (addrstr) + 1 != addr_str_len)
407 { 410 {
408 GNUNET_break(0); 411 GNUNET_break(0);
409 return NULL ; 412 return NULL;
410 } 413 }
411 414
412 off = 0; 415 off = 0;
413 if ('\0' == addrstr[0]) 416 if ('\0' == addrstr[0])
414 off++; 417 off++;
415 memset (rbuf, 0, sizeof (rbuf)); 418 memset (rbuf, 0, sizeof (rbuf));
416 GNUNET_snprintf (rbuf, sizeof (rbuf) - 1, "%s.%u.%s%.*s", 419 GNUNET_snprintf (rbuf,
417 PLUGIN_NAME, 420 sizeof (rbuf) - 1,
418 ntohl (ua->options), 421 "%s.%u.%s%.*s",
419 (off == 1) ? "@" : "", 422 PLUGIN_NAME,
420 (int) (addr_str_len - off), 423 ntohl (ua->options),
421 &addrstr[off]); 424 (off == 1) ? "@" : "",
422/* 425 (int) (addr_str_len - off),
423 GNUNET_snprintf (rbuf, sizeof(rbuf), "%s.%u.%s", PLUGIN_NAME, 426 &addrstr[off]);
424 ntohl (ua->options), addrstr);*/
425 return rbuf; 427 return rbuf;
426} 428}
427 429
428 430
429
430
431/** 431/**
432 * Re-schedule the main 'select' callback (unix_plugin_select) 432 * Re-schedule the main 'select' callback (unix_plugin_select)
433 * for this plugin. 433 * for this plugin.
@@ -547,7 +547,9 @@ unix_session_disconnect (void *cls,
547 LOG (GNUNET_ERROR_TYPE_DEBUG, 547 LOG (GNUNET_ERROR_TYPE_DEBUG,
548 "Disconnecting session for peer `%s' `%s'\n", 548 "Disconnecting session for peer `%s' `%s'\n",
549 GNUNET_i2s (&s->target), 549 GNUNET_i2s (&s->target),
550 unix_address_to_string (NULL, s->address->address, s->address->address_length) ); 550 unix_address_to_string (NULL,
551 s->address->address,
552 s->address->address_length));
551 plugin->env->session_end (plugin->env->cls, s->address, s); 553 plugin->env->session_end (plugin->env->cls, s->address, s);
552 removed = GNUNET_NO; 554 removed = GNUNET_NO;
553 next = plugin->msg_head; 555 next = plugin->msg_head;
@@ -870,7 +872,8 @@ unix_plugin_get_session (void *cls,
870 &get_session_it, &gsi); 872 &get_session_it, &gsi);
871 if (NULL != gsi.res) 873 if (NULL != gsi.res)
872 { 874 {
873 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for address `%s'\n", 875 LOG (GNUNET_ERROR_TYPE_DEBUG,
876 "Found existing session %p for address `%s'\n",
874 gsi.res, 877 gsi.res,
875 unix_address_to_string (NULL, address->address, address->address_length)); 878 unix_address_to_string (NULL, address->address, address->address_length));
876 return gsi.res; 879 return gsi.res;
@@ -887,7 +890,10 @@ unix_plugin_get_session (void *cls,
887 s); 890 s);
888 LOG (GNUNET_ERROR_TYPE_DEBUG, 891 LOG (GNUNET_ERROR_TYPE_DEBUG,
889 "Creating a new session %p for address `%s'\n", 892 "Creating a new session %p for address `%s'\n",
890 s, unix_address_to_string (NULL, address->address, address->address_length)); 893 s,
894 unix_address_to_string (NULL,
895 address->address,
896 address->address_length));
891 (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map, 897 (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map,
892 &address->peer, s, 898 &address->peer, s,
893 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 899 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
@@ -961,8 +967,9 @@ unix_plugin_send (void *cls,
961 LOG (GNUNET_ERROR_TYPE_ERROR, 967 LOG (GNUNET_ERROR_TYPE_ERROR,
962 "Invalid session for peer `%s' `%s'\n", 968 "Invalid session for peer `%s' `%s'\n",
963 GNUNET_i2s (&session->target), 969 GNUNET_i2s (&session->target),
964 unix_address_to_string(NULL, session->address->address, 970 unix_address_to_string(NULL,
965 session->address->address_length)); 971 session->address->address,
972 session->address->address_length));
966 GNUNET_break (0); 973 GNUNET_break (0);
967 return GNUNET_SYSERR; 974 return GNUNET_SYSERR;
968 } 975 }
@@ -970,8 +977,9 @@ unix_plugin_send (void *cls,
970 "Sending %u bytes with session for peer `%s' `%s'\n", 977 "Sending %u bytes with session for peer `%s' `%s'\n",
971 msgbuf_size, 978 msgbuf_size,
972 GNUNET_i2s (&session->target), 979 GNUNET_i2s (&session->target),
973 unix_address_to_string(NULL, session->address->address, 980 unix_address_to_string (NULL,
974 session->address->address_length)); 981 session->address->address,
982 session->address->address_length));
975 ssize = sizeof (struct UNIXMessage) + msgbuf_size; 983 ssize = sizeof (struct UNIXMessage) + msgbuf_size;
976 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); 984 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
977 message->header.size = htons (ssize); 985 message->header.size = htons (ssize);
@@ -1024,7 +1032,7 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1024 GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); 1032 GNUNET_assert (ua_len >= sizeof (struct UnixAddress));
1025 LOG (GNUNET_ERROR_TYPE_DEBUG, 1033 LOG (GNUNET_ERROR_TYPE_DEBUG,
1026 "Received message from %s\n", 1034 "Received message from %s\n",
1027 unix_address_to_string(NULL, ua, ua_len)); 1035 unix_address_to_string (NULL, ua, ua_len));
1028 GNUNET_STATISTICS_update (plugin->env->stats, 1036 GNUNET_STATISTICS_update (plugin->env->stats,
1029 "# bytes received via UNIX", 1037 "# bytes received via UNIX",
1030 ntohs (currhdr->size), 1038 ntohs (currhdr->size),
@@ -1419,12 +1427,17 @@ unix_plugin_address_pretty_printer (void *cls, const char *type,
1419 GNUNET_TRANSPORT_AddressStringCallback asc, 1427 GNUNET_TRANSPORT_AddressStringCallback asc,
1420 void *asc_cls) 1428 void *asc_cls)
1421{ 1429{
1422 if ((NULL != addr) && (addrlen > 0)) 1430 const char *ret;
1423 { 1431
1424 asc (asc_cls, unix_address_to_string (NULL, addr, addrlen), GNUNET_OK); 1432 if ( (NULL != addr) && (addrlen > 0))
1425 } 1433 ret = unix_address_to_string (NULL,
1434 addr,
1435 addrlen);
1426 else 1436 else
1427 asc (asc_cls, NULL, GNUNET_SYSERR); 1437 ret = NULL;
1438 asc (asc_cls,
1439 ret,
1440 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1428 asc (asc_cls, NULL, GNUNET_OK); 1441 asc (asc_cls, NULL, GNUNET_OK);
1429} 1442}
1430 1443
@@ -1433,7 +1446,7 @@ unix_plugin_address_pretty_printer (void *cls, const char *type,
1433 * Function called to convert a string address to 1446 * Function called to convert a string address to
1434 * a binary address. 1447 * a binary address.
1435 * 1448 *
1436 * @param cls closure ('struct Plugin*') 1449 * @param cls closure (`struct Plugin *`)
1437 * @param addr string address 1450 * @param addr string address
1438 * @param addrlen length of the @a addr (strlen(addr) + '\0') 1451 * @param addrlen length of the @a addr (strlen(addr) + '\0')
1439 * @param buf location to store the buffer 1452 * @param buf location to store the buffer
@@ -1573,7 +1586,7 @@ reschedule_session_timeout (struct Session *s)
1573 * 1586 *
1574 * @param cls the plugin 1587 * @param cls the plugin
1575 * @param key peer identity (unused) 1588 * @param key peer identity (unused)
1576 * @param value the 'struct Session' to disconnect 1589 * @param value the `struct Session *` to disconnect
1577 * @return #GNUNET_YES (always, continue to iterate) 1590 * @return #GNUNET_YES (always, continue to iterate)
1578 */ 1591 */
1579static int 1592static int
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index f0197feb8..6da3365eb 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -1073,7 +1073,9 @@ create_macendpoint (struct Plugin *plugin, struct WlanAddress *mac)
1073 if (0 == memcmp (mac, &pos->wlan_addr, sizeof (pos->wlan_addr))) 1073 if (0 == memcmp (mac, &pos->wlan_addr, sizeof (pos->wlan_addr)))
1074 { 1074 {
1075 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing MAC endpoint `%s'\n", 1075 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing MAC endpoint `%s'\n",
1076 wlan_plugin_address_to_string(NULL, &pos->wlan_addr.mac, sizeof (pos->wlan_addr))); 1076 wlan_plugin_address_to_string (NULL,
1077 &pos->wlan_addr.mac,
1078 sizeof (pos->wlan_addr)));
1077 return pos; 1079 return pos;
1078 } 1080 }
1079 } 1081 }
@@ -1097,8 +1099,11 @@ create_macendpoint (struct Plugin *plugin, struct WlanAddress *mac)
1097 plugin->mac_count++; 1099 plugin->mac_count++;
1098 GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"), 1100 GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"),
1099 1, GNUNET_NO); 1101 1, GNUNET_NO);
1100 LOG (GNUNET_ERROR_TYPE_DEBUG, "New MAC endpoint `%s'\n", 1102 LOG (GNUNET_ERROR_TYPE_DEBUG,
1101 wlan_plugin_address_to_string(NULL, &pos->wlan_addr, sizeof (struct WlanAddress))); 1103 "New MAC endpoint `%s'\n",
1104 wlan_plugin_address_to_string (NULL,
1105 &pos->wlan_addr,
1106 sizeof (struct WlanAddress)));
1102 return pos; 1107 return pos;
1103} 1108}
1104 1109
@@ -1144,7 +1149,9 @@ wlan_plugin_get_session (void *cls,
1144 LOG (GNUNET_ERROR_TYPE_DEBUG, 1149 LOG (GNUNET_ERROR_TYPE_DEBUG,
1145 "Service asked to create session for peer `%s' with MAC `%s'\n", 1150 "Service asked to create session for peer `%s' with MAC `%s'\n",
1146 GNUNET_i2s (&address->peer), 1151 GNUNET_i2s (&address->peer),
1147 wlan_plugin_address_to_string(NULL, address->address, address->address_length)); 1152 wlan_plugin_address_to_string (NULL,
1153 address->address,
1154 address->address_length));
1148 endpoint = create_macendpoint (plugin, (struct WlanAddress *) address->address); 1155 endpoint = create_macendpoint (plugin, (struct WlanAddress *) address->address);
1149 return get_session (endpoint, &address->peer); 1156 return get_session (endpoint, &address->peer);
1150} 1157}
@@ -1295,8 +1302,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1295 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", 1302 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n",
1296 (unsigned int) msize, 1303 (unsigned int) msize,
1297 GNUNET_i2s (&tmpsource), 1304 GNUNET_i2s (&tmpsource),
1298 wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, 1305 wlan_plugin_address_to_string (NULL,
1299 sizeof (mas->endpoint->wlan_addr))); 1306 &mas->endpoint->wlan_addr,
1307 sizeof (mas->endpoint->wlan_addr)));
1300 1308
1301 GNUNET_STATISTICS_update (plugin->env->stats, 1309 GNUNET_STATISTICS_update (plugin->env->stats,
1302 _("# HELLO messages received via WLAN"), 1, 1310 _("# HELLO messages received via WLAN"), 1,
@@ -1320,8 +1328,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1320 LOG (GNUNET_ERROR_TYPE_DEBUG, 1328 LOG (GNUNET_ERROR_TYPE_DEBUG,
1321 "Processing %u bytes of FRAGMENT from MAC %s\n", 1329 "Processing %u bytes of FRAGMENT from MAC %s\n",
1322 (unsigned int) msize, 1330 (unsigned int) msize,
1323 wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, 1331 wlan_plugin_address_to_string (NULL,
1324 sizeof (mas->endpoint->wlan_addr))); 1332 &mas->endpoint->wlan_addr,
1333 sizeof (mas->endpoint->wlan_addr)));
1325 GNUNET_STATISTICS_update (plugin->env->stats, 1334 GNUNET_STATISTICS_update (plugin->env->stats,
1326 _("# fragments received via WLAN"), 1, GNUNET_NO); 1335 _("# fragments received via WLAN"), 1, GNUNET_NO);
1327 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, 1336 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag,
@@ -1342,8 +1351,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1342 { 1351 {
1343 LOG (GNUNET_ERROR_TYPE_DEBUG, 1352 LOG (GNUNET_ERROR_TYPE_DEBUG,
1344 "Got last ACK, finished message transmission to `%s' (%p)\n", 1353 "Got last ACK, finished message transmission to `%s' (%p)\n",
1345 wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, 1354 wlan_plugin_address_to_string (NULL,
1346 sizeof (mas->endpoint->wlan_addr)), 1355 &mas->endpoint->wlan_addr,
1356 sizeof (mas->endpoint->wlan_addr)),
1347 fm); 1357 fm);
1348 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); 1358 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
1349 if (NULL != fm->cont) 1359 if (NULL != fm->cont)
@@ -1358,15 +1368,17 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1358 { 1368 {
1359 LOG (GNUNET_ERROR_TYPE_DEBUG, 1369 LOG (GNUNET_ERROR_TYPE_DEBUG,
1360 "Got an ACK, message transmission to `%s' not yet finished\n", 1370 "Got an ACK, message transmission to `%s' not yet finished\n",
1361 wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, 1371 wlan_plugin_address_to_string (NULL,
1362 sizeof (mas->endpoint->wlan_addr))); 1372 &mas->endpoint->wlan_addr,
1373 sizeof (mas->endpoint->wlan_addr)));
1363 break; 1374 break;
1364 } 1375 }
1365 } 1376 }
1366 LOG (GNUNET_ERROR_TYPE_DEBUG, 1377 LOG (GNUNET_ERROR_TYPE_DEBUG,
1367 "ACK not matched against any active fragmentation with MAC `%s'\n", 1378 "ACK not matched against any active fragmentation with MAC `%s'\n",
1368 wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, 1379 wlan_plugin_address_to_string (NULL,
1369 sizeof (mas->endpoint->wlan_addr))); 1380 &mas->endpoint->wlan_addr,
1381 sizeof (mas->endpoint->wlan_addr)));
1370 break; 1382 break;
1371 case GNUNET_MESSAGE_TYPE_WLAN_DATA: 1383 case GNUNET_MESSAGE_TYPE_WLAN_DATA:
1372 if (NULL == mas->endpoint) 1384 if (NULL == mas->endpoint)
@@ -1681,7 +1693,9 @@ wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
1681 * @return string representing the same address 1693 * @return string representing the same address
1682 */ 1694 */
1683static const char * 1695static const char *
1684wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) 1696wlan_plugin_address_to_string (void *cls,
1697 const void *addr,
1698 size_t addrlen)
1685{ 1699{
1686 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac; 1700 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1687 static char macstr[36]; 1701 static char macstr[36];
@@ -1692,9 +1706,12 @@ wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1692 return NULL; 1706 return NULL;
1693 } 1707 }
1694 mac = &((struct WlanAddress *) addr)->mac; 1708 mac = &((struct WlanAddress *) addr)->mac;
1695 GNUNET_snprintf (macstr, sizeof (macstr), "%s.%u.%s", 1709 GNUNET_snprintf (macstr,
1696 PLUGIN_NAME, ntohl (((struct WlanAddress *) addr)->options), 1710 sizeof (macstr),
1697 mac_to_string (mac)); 1711 "%s.%u.%s",
1712 PLUGIN_NAME,
1713 ntohl (((struct WlanAddress *) addr)->options),
1714 mac_to_string (mac));
1698 return macstr; 1715 return macstr;
1699} 1716}
1700 1717
@@ -1710,29 +1727,29 @@ wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1710 * @param numeric should (IP) addresses be displayed in numeric form? 1727 * @param numeric should (IP) addresses be displayed in numeric form?
1711 * @param timeout after how long should we give up? 1728 * @param timeout after how long should we give up?
1712 * @param asc function to call on each string 1729 * @param asc function to call on each string
1713 * @param asc_cls closure for asc 1730 * @param asc_cls closure for @a asc
1714 */ 1731 */
1715static void 1732static void
1716wlan_plugin_address_pretty_printer (void *cls, const char *type, 1733wlan_plugin_address_pretty_printer (void *cls,
1717 const void *addr, size_t addrlen, 1734 const char *type,
1735 const void *addr,
1736 size_t addrlen,
1718 int numeric, 1737 int numeric,
1719 struct GNUNET_TIME_Relative timeout, 1738 struct GNUNET_TIME_Relative timeout,
1720 GNUNET_TRANSPORT_AddressStringCallback asc, 1739 GNUNET_TRANSPORT_AddressStringCallback asc,
1721 void *asc_cls) 1740 void *asc_cls)
1722{ 1741{
1723 char *ret; 1742 const char *ret;
1724 1743
1725 if (sizeof (struct WlanAddress) != addrlen) 1744 if (sizeof (struct WlanAddress) == addrlen)
1726 { 1745 ret = wlan_plugin_address_to_string (NULL,
1727 /* invalid address */ 1746 addr,
1728 asc (asc_cls, NULL, GNUNET_SYSERR); 1747 addrlen);
1729 }
1730 else 1748 else
1731 { 1749 ret = NULL;
1732 ret = GNUNET_strdup (wlan_plugin_address_to_string(NULL, addr, addrlen)); 1750 asc (asc_cls,
1733 asc (asc_cls, ret, GNUNET_OK); 1751 ret,
1734 GNUNET_free (ret); 1752 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1735 }
1736 asc (asc_cls, NULL, GNUNET_OK); 1753 asc (asc_cls, NULL, GNUNET_OK);
1737} 1754}
1738 1755
@@ -1815,13 +1832,13 @@ libgnunet_plugin_transport_wlan_done (void *cls)
1815 * Function called to convert a string address to 1832 * Function called to convert a string address to
1816 * a binary address. 1833 * a binary address.
1817 * 1834 *
1818 * @param cls closure ('struct Plugin*') 1835 * @param cls closure (`struct Plugin *`)
1819 * @param addr string address 1836 * @param addr string address
1820 * @param addrlen length of the address 1837 * @param addrlen length of the address
1821 * @param buf location to store the buffer 1838 * @param buf location to store the buffer
1822 * @param added location to store the number of bytes in the buffer. 1839 * @param added location to store the number of bytes in the buffer.
1823 * If the function returns GNUNET_SYSERR, its contents are undefined. 1840 * If the function returns #GNUNET_SYSERR, its contents are undefined.
1824 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 1841 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1825 */ 1842 */
1826static int 1843static int
1827wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen, 1844wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen,
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 68c685c29..cbbefb7e1 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -278,31 +278,32 @@ struct SendOkMessage
278 278
279/** 279/**
280 * Message used to notify the transport API about an address to string 280 * Message used to notify the transport API about an address to string
281 * conversion. Message is followed by the string with length strlen 281 * conversion. Message is followed by the string with the humand-readable
282 * address. For each lookup, multiple results may be returned. The
283 * last message must have a @e res of #GNUNET_OK and an @e addr_len
284 * of zero.
282 */ 285 */
283struct AddressToStringResultMessage 286struct AddressToStringResultMessage
284{ 287{
285 288
286 /** 289 /**
287 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK 290 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
288 */ 291 */
289 struct GNUNET_MessageHeader header; 292 struct GNUNET_MessageHeader header;
290 293
291 /** 294 /**
292 * GNUNET_OK if the conversion succeeded, 295 * #GNUNET_OK if the conversion succeeded,
293 * GNUNET_SYSERR if it failed 296 * #GNUNET_SYSERR if it failed
294 */ 297 */
295 uint32_t res GNUNET_PACKED; 298 uint32_t res GNUNET_PACKED;
296 299
297 /** 300 /**
298 * Length of the following string 301 * Length of the following string, zero if @e is #GNUNET_SYSERR
299 */ 302 */
300 uint32_t addr_len GNUNET_PACKED; 303 uint32_t addr_len GNUNET_PACKED;
301}; 304};
302 305
303 306
304
305
306/** 307/**
307 * Message used to notify the transport service about a message 308 * Message used to notify the transport service about a message
308 * to be transmitted to another peer. The actual message follows. 309 * to be transmitted to another peer. The actual message follows.
@@ -342,7 +343,7 @@ struct AddressLookupMessage
342{ 343{
343 344
344 /** 345 /**
345 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING 346 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
346 */ 347 */
347 struct GNUNET_MessageHeader header; 348 struct GNUNET_MessageHeader header;
348 349
@@ -358,11 +359,11 @@ struct AddressLookupMessage
358 uint16_t addrlen GNUNET_PACKED; 359 uint16_t addrlen GNUNET_PACKED;
359 360
360 /** 361 /**
361 * timeout to give up. 362 * timeout to give up (for DNS resolution timeout mostly)
362 */ 363 */
363 struct GNUNET_TIME_RelativeNBO timeout; 364 struct GNUNET_TIME_RelativeNBO timeout;
364 365
365 /* followed by 'addrlen' bytes of the actual address, then 366 /* followed by @e addrlen bytes of the actual address, then
366 * followed by the 0-terminated name of the transport */ 367 * followed by the 0-terminated name of the transport */
367}; 368};
368 369
@@ -414,10 +415,19 @@ struct ValidationIterateResponseMessage
414 */ 415 */
415 uint32_t state GNUNET_PACKED; 416 uint32_t state GNUNET_PACKED;
416 417
418 /**
419 * FIXME
420 */
417 struct GNUNET_TIME_AbsoluteNBO last_validation; 421 struct GNUNET_TIME_AbsoluteNBO last_validation;
418 422
423 /**
424 * FIXME
425 */
419 struct GNUNET_TIME_AbsoluteNBO valid_until; 426 struct GNUNET_TIME_AbsoluteNBO valid_until;
420 427
428 /**
429 * FIXME
430 */
421 struct GNUNET_TIME_AbsoluteNBO next_validation; 431 struct GNUNET_TIME_AbsoluteNBO next_validation;
422}; 432};
423 433
@@ -476,7 +486,7 @@ struct PeerMonitorMessage
476struct TrafficMetricMessage 486struct TrafficMetricMessage
477{ 487{
478 /** 488 /**
479 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC 489 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
480 */ 490 */
481 struct GNUNET_MessageHeader header; 491 struct GNUNET_MessageHeader header;
482 492
@@ -535,7 +545,7 @@ struct PeerIterateResponseMessage
535 uint32_t local_address_info GNUNET_PACKED; 545 uint32_t local_address_info GNUNET_PACKED;
536 546
537 /** 547 /**
538 * State this peer is in as #GNUNET_TRANSPORT_PeerState enumeration element 548 * State this peer is in as an `enum GNUNET_TRANSPORT_PeerState`
539 */ 549 */
540 uint32_t state GNUNET_PACKED; 550 uint32_t state GNUNET_PACKED;
541 551
@@ -560,13 +570,13 @@ struct BlacklistMessage
560{ 570{
561 571
562 /** 572 /**
563 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or 573 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
564 * GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY. 574 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
565 */ 575 */
566 struct GNUNET_MessageHeader header; 576 struct GNUNET_MessageHeader header;
567 577
568 /** 578 /**
569 * 0 for the query, GNUNET_OK (allowed) or GNUNET_SYSERR (disallowed) 579 * 0 for the query, #GNUNET_OK (allowed) or #GNUNET_SYSERR (disallowed)
570 * for the response. 580 * for the response.
571 */ 581 */
572 uint32_t is_allowed GNUNET_PACKED; 582 uint32_t is_allowed GNUNET_PACKED;
diff --git a/src/transport/transport_api_address_to_string.c b/src/transport/transport_api_address_to_string.c
index d881f9a08..afd0c7deb 100644
--- a/src/transport/transport_api_address_to_string.c
+++ b/src/transport/transport_api_address_to_string.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors) 3 (C) 2009-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -17,6 +17,11 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/**
21 * @file transport/transport_api_address_to_string.c
22 * @author Christian Grothoff
23 * @brief enable clients to convert addresses to human readable strings
24 */
20#include "platform.h" 25#include "platform.h"
21#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
22#include "gnunet_arm_service.h" 27#include "gnunet_arm_service.h"
@@ -36,7 +41,7 @@ struct GNUNET_TRANSPORT_AddressToStringContext
36 GNUNET_TRANSPORT_AddressToStringCallback cb; 41 GNUNET_TRANSPORT_AddressToStringCallback cb;
37 42
38 /** 43 /**
39 * Closure for cb. 44 * Closure for @e cb.
40 */ 45 */
41 void *cb_cls; 46 void *cb_cls;
42 47
@@ -45,10 +50,6 @@ struct GNUNET_TRANSPORT_AddressToStringContext
45 */ 50 */
46 struct GNUNET_CLIENT_Connection *client; 51 struct GNUNET_CLIENT_Connection *client;
47 52
48 /**
49 * When should this operation time out?
50 */
51 struct GNUNET_TIME_Absolute timeout;
52}; 53};
53 54
54 55
@@ -64,18 +65,17 @@ address_response_processor (void *cls,
64 const struct GNUNET_MessageHeader *msg) 65 const struct GNUNET_MessageHeader *msg)
65{ 66{
66 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; 67 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
67 struct AddressToStringResultMessage *atsm; 68 const struct AddressToStringResultMessage *atsm;
68 const char *address; 69 const char *address;
69 uint16_t size; 70 uint16_t size;
70 uint32_t result; 71 int result;
71 uint32_t addr_len; 72 uint32_t addr_len;
72 char *empty_str = "";
73 73
74 if (NULL == msg) 74 if (NULL == msg)
75 { 75 {
76 alucb->cb (alucb->cb_cls, 76 alucb->cb (alucb->cb_cls,
77 NULL, 77 NULL,
78 GNUNET_OK); 78 GNUNET_SYSERR);
79 GNUNET_CLIENT_disconnect (alucb->client); 79 GNUNET_CLIENT_disconnect (alucb->client);
80 GNUNET_free (alucb); 80 GNUNET_free (alucb);
81 return; 81 return;
@@ -86,54 +86,72 @@ address_response_processor (void *cls,
86 size = ntohs (msg->size); 86 size = ntohs (msg->size);
87 if (size < sizeof (struct AddressToStringResultMessage)) 87 if (size < sizeof (struct AddressToStringResultMessage))
88 { 88 {
89 alucb->cb (alucb->cb_cls, NULL, GNUNET_OK); 89 GNUNET_break (0);
90 alucb->cb (alucb->cb_cls,
91 NULL,
92 GNUNET_SYSERR);
90 GNUNET_CLIENT_disconnect (alucb->client); 93 GNUNET_CLIENT_disconnect (alucb->client);
91 GNUNET_free (alucb); 94 GNUNET_free (alucb);
92 return; 95 return;
93 } 96 }
94 atsm = (struct AddressToStringResultMessage *) msg; 97 atsm = (const struct AddressToStringResultMessage *) msg;
95 98 result = (int) ntohl (atsm->res);
96 result = ntohl (atsm->res);
97 addr_len = ntohl (atsm->addr_len); 99 addr_len = ntohl (atsm->addr_len);
98 100 if (GNUNET_SYSERR == result)
99 if (size == (sizeof (struct AddressToStringResultMessage)))
100 { 101 {
101 /* done, success depends on result */ 102 /* expect more replies; as this is not the last
102 alucb->cb (alucb->cb_cls, NULL, result); 103 call, we must pass the empty string for the address */
103 GNUNET_CLIENT_disconnect (alucb->client); 104 alucb->cb (alucb->cb_cls,
104 GNUNET_free (alucb); 105 "",
106 GNUNET_NO);
107 GNUNET_CLIENT_receive (alucb->client,
108 &address_response_processor,
109 alucb,
110 GNUNET_TIME_UNIT_FOREVER_REL);
105 return; 111 return;
106 } 112 }
107 113 if (size == (sizeof (struct AddressToStringResultMessage)))
108 if (GNUNET_NO == result)
109 { 114 {
110 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client %p failed to resolve address \n", 115 if (GNUNET_OK != result)
111 alucb->client); 116 {
112 GNUNET_break (0); 117 GNUNET_break (0);
113 alucb->cb (alucb->cb_cls, empty_str, GNUNET_SYSERR); 118 alucb->cb (alucb->cb_cls,
114 119 NULL,
115 /* expect more replies */ 120 GNUNET_SYSERR);
116 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb, 121 GNUNET_CLIENT_disconnect (alucb->client);
117 GNUNET_TIME_absolute_get_remaining (alucb->timeout)); 122 GNUNET_free (alucb);
123 return;
124 }
125 /* we are done (successfully, without communication errors) */
126 alucb->cb (alucb->cb_cls,
127 NULL,
128 GNUNET_OK);
129 GNUNET_CLIENT_disconnect (alucb->client);
130 GNUNET_free (alucb);
118 return; 131 return;
119 } 132 }
120
121 address = (const char *) &atsm[1]; 133 address = (const char *) &atsm[1];
122 if ( (addr_len > (size - (sizeof (struct AddressToStringResultMessage)))) || 134 if ( (addr_len > (size - (sizeof (struct AddressToStringResultMessage)))) ||
123 (address[addr_len -1] != '\0') ) 135 (address[addr_len -1] != '\0') )
124 { 136 {
125 /* invalid reply */ 137 /* invalid reply */
126 GNUNET_break (0); 138 GNUNET_break (0);
127 alucb->cb (alucb->cb_cls, NULL, GNUNET_SYSERR); 139 alucb->cb (alucb->cb_cls,
140 NULL,
141 GNUNET_SYSERR);
128 GNUNET_CLIENT_disconnect (alucb->client); 142 GNUNET_CLIENT_disconnect (alucb->client);
129 GNUNET_free (alucb); 143 GNUNET_free (alucb);
130 return; 144 return;
131 } 145 }
132
133 /* expect more replies */ 146 /* expect more replies */
134 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb, 147 GNUNET_CLIENT_receive (alucb->client,
135 GNUNET_TIME_absolute_get_remaining (alucb->timeout)); 148 &address_response_processor,
136 alucb->cb (alucb->cb_cls, address, GNUNET_OK); 149 alucb,
150 GNUNET_TIME_UNIT_FOREVER_REL);
151 /* return normal reply to caller */
152 alucb->cb (alucb->cb_cls,
153 address,
154 GNUNET_OK);
137} 155}
138 156
139 157
@@ -146,17 +164,16 @@ address_response_processor (void *cls,
146 * (otherwise do reverse DNS lookup) 164 * (otherwise do reverse DNS lookup)
147 * @param timeout how long is the lookup allowed to take at most 165 * @param timeout how long is the lookup allowed to take at most
148 * @param aluc function to call with the results 166 * @param aluc function to call with the results
149 * @param aluc_cls closure for aluc 167 * @param aluc_cls closure for @a aluc
150 * @return handle to cancel the operation, NULL on error 168 * @return handle to cancel the operation, NULL on error
151 */ 169 */
152struct GNUNET_TRANSPORT_AddressToStringContext * 170struct GNUNET_TRANSPORT_AddressToStringContext *
153GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle 171GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
154 *cfg,
155 const struct GNUNET_HELLO_Address *address, 172 const struct GNUNET_HELLO_Address *address,
156 int numeric, 173 int numeric,
157 struct GNUNET_TIME_Relative timeout, 174 struct GNUNET_TIME_Relative timeout,
158 GNUNET_TRANSPORT_AddressToStringCallback 175 GNUNET_TRANSPORT_AddressToStringCallback aluc,
159 aluc, void *aluc_cls) 176 void *aluc_cls)
160{ 177{
161 size_t len; 178 size_t len;
162 size_t alen; 179 size_t alen;
@@ -166,7 +183,7 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
166 struct GNUNET_CLIENT_Connection *client; 183 struct GNUNET_CLIENT_Connection *client;
167 char *addrbuf; 184 char *addrbuf;
168 185
169 GNUNET_assert (address != NULL); 186 GNUNET_assert (NULL != address);
170 alen = address->address_length; 187 alen = address->address_length;
171 slen = strlen (address->transport_name) + 1; 188 slen = strlen (address->transport_name) + 1;
172 len = sizeof (struct AddressLookupMessage) + alen + slen; 189 len = sizeof (struct AddressLookupMessage) + alen + slen;
@@ -178,8 +195,11 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
178 client = GNUNET_CLIENT_connect ("transport", cfg); 195 client = GNUNET_CLIENT_connect ("transport", cfg);
179 if (NULL == client) 196 if (NULL == client)
180 return NULL; 197 return NULL;
181 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client %p tries to resolve for peer `%s'address len %u \n", 198 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
182 client, GNUNET_i2s (&address->peer), address->address_length); 199 "Client %p tries to resolve for peer `%s'address len %u \n",
200 client,
201 GNUNET_i2s (&address->peer),
202 address->address_length);
183 203
184 msg = GNUNET_malloc (len); 204 msg = GNUNET_malloc (len);
185 msg->header.size = htons (len); 205 msg->header.size = htons (len);
@@ -188,17 +208,21 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
188 msg->addrlen = htons ((uint16_t) alen); 208 msg->addrlen = htons ((uint16_t) alen);
189 msg->timeout = GNUNET_TIME_relative_hton (timeout); 209 msg->timeout = GNUNET_TIME_relative_hton (timeout);
190 addrbuf = (char *) &msg[1]; 210 addrbuf = (char *) &msg[1];
191 memcpy (addrbuf, address->address, alen); 211 memcpy (addrbuf,
192 memcpy (&addrbuf[alen], address->transport_name, slen); 212 address->address,
193 213 alen);
214 memcpy (&addrbuf[alen],
215 address->transport_name,
216 slen);
194 alc = GNUNET_new (struct GNUNET_TRANSPORT_AddressToStringContext); 217 alc = GNUNET_new (struct GNUNET_TRANSPORT_AddressToStringContext);
195 alc->cb = aluc; 218 alc->cb = aluc;
196 alc->cb_cls = aluc_cls; 219 alc->cb_cls = aluc_cls;
197 alc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
198 alc->client = client; 220 alc->client = client;
199 GNUNET_assert (GNUNET_OK == 221 GNUNET_assert (GNUNET_OK ==
200 GNUNET_CLIENT_transmit_and_get_response (client, &msg->header, 222 GNUNET_CLIENT_transmit_and_get_response (client,
201 timeout, GNUNET_YES, 223 &msg->header,
224 GNUNET_TIME_UNIT_FOREVER_REL,
225 GNUNET_YES,
202 &address_response_processor, 226 &address_response_processor,
203 alc)); 227 alc));
204 GNUNET_free (msg); 228 GNUNET_free (msg);
@@ -212,9 +236,7 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
212 * @param pic the context handle 236 * @param pic the context handle
213 */ 237 */
214void 238void
215GNUNET_TRANSPORT_address_to_string_cancel (struct 239GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStringContext *pic)
216 GNUNET_TRANSPORT_AddressToStringContext
217 *pic)
218{ 240{
219 GNUNET_CLIENT_disconnect (pic->client); 241 GNUNET_CLIENT_disconnect (pic->client);
220 GNUNET_free (pic); 242 GNUNET_free (pic);