diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-06-03 09:34:15 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-06-03 09:34:15 +0000 |
commit | 7d6e6b045a300cf753e685bc18ec0b1e264d1a25 (patch) | |
tree | 2e7069a9bfb46aef0ea9a45b944fbc934aaa2ce1 /src/hello | |
parent | 84bcdbdd34bfa4d597ae2635146fe15631b46f44 (diff) | |
download | gnunet-7d6e6b045a300cf753e685bc18ec0b1e264d1a25.tar.gz gnunet-7d6e6b045a300cf753e685bc18ec0b1e264d1a25.zip |
fix for bug #0003416: do not stop parsing uri when plugin is not found
- changed semantics for address generator cb: GNUNET_SYSERR indicates stop, >= 0 indicates bytes added
Diffstat (limited to 'src/hello')
-rw-r--r-- | src/hello/gnunet-hello.c | 4 | ||||
-rw-r--r-- | src/hello/hello.c | 55 | ||||
-rw-r--r-- | src/hello/test_friend_hello.c | 4 | ||||
-rw-r--r-- | src/hello/test_hello.c | 4 |
4 files changed, 44 insertions, 23 deletions
diff --git a/src/hello/gnunet-hello.c b/src/hello/gnunet-hello.c index e857bde26..93eaeef2b 100644 --- a/src/hello/gnunet-hello.c +++ b/src/hello/gnunet-hello.c | |||
@@ -85,14 +85,14 @@ add_to_buf (void *cls, const struct GNUNET_HELLO_Address *address, | |||
85 | * @param buf where to add the addresses | 85 | * @param buf where to add the addresses |
86 | * @return number of bytes added, 0 to terminate | 86 | * @return number of bytes added, 0 to terminate |
87 | */ | 87 | */ |
88 | static size_t | 88 | static ssize_t |
89 | add_from_hello (void *cls, size_t max, void *buf) | 89 | add_from_hello (void *cls, size_t max, void *buf) |
90 | { | 90 | { |
91 | struct GNUNET_HELLO_Message **orig = cls; | 91 | struct GNUNET_HELLO_Message **orig = cls; |
92 | struct AddContext ac; | 92 | struct AddContext ac; |
93 | 93 | ||
94 | if (NULL == *orig) | 94 | if (NULL == *orig) |
95 | return 0; /* already done */ | 95 | return GNUNET_SYSERR; /* already done */ |
96 | ac.buf = buf; | 96 | ac.buf = buf; |
97 | ac.max = max; | 97 | ac.max = max; |
98 | ac.ret = 0; | 98 | ac.ret = 0; |
diff --git a/src/hello/hello.c b/src/hello/hello.c index 4b7036125..1f9ef0f7e 100644 --- a/src/hello/hello.c +++ b/src/hello/hello.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * @file hello/hello.c | 22 | * @file hello/hello.c |
23 | * @brief helper library for handling HELLOs | 23 | * @brief helper library for handling HELLOs |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * @author Matthias Wachs | ||
25 | */ | 26 | */ |
26 | #include "platform.h" | 27 | #include "platform.h" |
27 | #include "gnunet_hello_lib.h" | 28 | #include "gnunet_hello_lib.h" |
@@ -98,6 +99,17 @@ struct GNUNET_HELLO_ParseUriContext | |||
98 | int ret; | 99 | int ret; |
99 | 100 | ||
100 | /** | 101 | /** |
102 | * Counter | ||
103 | */ | ||
104 | unsigned int counter_total; | ||
105 | |||
106 | /** | ||
107 | * Counter skipped addresses | ||
108 | */ | ||
109 | unsigned int counter_added; | ||
110 | |||
111 | |||
112 | /** | ||
101 | * Function for finding transport plugins by name. | 113 | * Function for finding transport plugins by name. |
102 | */ | 114 | */ |
103 | GNUNET_HELLO_TransportPluginsFind plugins_find; | 115 | GNUNET_HELLO_TransportPluginsFind plugins_find; |
@@ -237,7 +249,7 @@ GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *publicKey, | |||
237 | used = 0; | 249 | used = 0; |
238 | if (addrgen != NULL) | 250 | if (addrgen != NULL) |
239 | { | 251 | { |
240 | while (0 != (ret = addrgen (addrgen_cls, max, &buffer[used]))) | 252 | while (GNUNET_SYSERR != (ret = addrgen (addrgen_cls, max, &buffer[used]))) |
241 | { | 253 | { |
242 | max -= ret; | 254 | max -= ret; |
243 | used += ret; | 255 | used += ret; |
@@ -395,13 +407,13 @@ copy_latest (void *cls, const struct GNUNET_HELLO_Address *address, | |||
395 | } | 407 | } |
396 | 408 | ||
397 | 409 | ||
398 | static size_t | 410 | static ssize_t |
399 | merge_addr (void *cls, size_t max, void *buf) | 411 | merge_addr (void *cls, size_t max, void *buf) |
400 | { | 412 | { |
401 | struct MergeContext *mc = cls; | 413 | struct MergeContext *mc = cls; |
402 | 414 | ||
403 | if (mc->h1 == NULL) | 415 | if (mc->h1 == NULL) |
404 | return 0; | 416 | return GNUNET_SYSERR; /* Stop iteration */ |
405 | mc->ret = 0; | 417 | mc->ret = 0; |
406 | mc->max = max; | 418 | mc->max = max; |
407 | mc->buf = buf; | 419 | mc->buf = buf; |
@@ -433,11 +445,11 @@ GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1, | |||
433 | int friend_only; | 445 | int friend_only; |
434 | 446 | ||
435 | if (h1->friend_only != h2->friend_only) | 447 | if (h1->friend_only != h2->friend_only) |
436 | friend_only = GNUNET_YES; /* One of the HELLOs is friend only */ | 448 | friend_only = GNUNET_YES; /* One of the HELLOs is friend only */ |
437 | else | 449 | else |
438 | friend_only = ntohl (h1->friend_only); /* Both HELLO's have the same type */ | 450 | friend_only = ntohl (h1->friend_only); /* Both HELLO's have the same type */ |
439 | 451 | ||
440 | return GNUNET_HELLO_create (&h1->publicKey, &merge_addr, &mc, friend_only); | 452 | return GNUNET_HELLO_create (&h1->publicKey, &merge_addr, &mc, friend_only); |
441 | } | 453 | } |
442 | 454 | ||
443 | 455 | ||
@@ -895,9 +907,9 @@ GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello, | |||
895 | * @param cls the 'struct GNUNET_HELLO_AddressParsingContext' | 907 | * @param cls the 'struct GNUNET_HELLO_AddressParsingContext' |
896 | * @param max number of bytes available for HELLO construction | 908 | * @param max number of bytes available for HELLO construction |
897 | * @param buffer where to copy the next address (in binary format) | 909 | * @param buffer where to copy the next address (in binary format) |
898 | * @return number of bytes added to buffer | 910 | * @return number of bytes added to buffer, GNUNET_SYSERR on error |
899 | */ | 911 | */ |
900 | static size_t | 912 | static ssize_t |
901 | add_address_to_hello (void *cls, size_t max, void *buffer) | 913 | add_address_to_hello (void *cls, size_t max, void *buffer) |
902 | { | 914 | { |
903 | struct GNUNET_HELLO_ParseUriContext *ctx = cls; | 915 | struct GNUNET_HELLO_ParseUriContext *ctx = cls; |
@@ -914,15 +926,16 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
914 | void *addr; | 926 | void *addr; |
915 | size_t addr_len; | 927 | size_t addr_len; |
916 | struct GNUNET_HELLO_Address haddr; | 928 | struct GNUNET_HELLO_Address haddr; |
917 | size_t ret; | 929 | ssize_t ret; |
930 | |||
918 | 931 | ||
919 | if (NULL == ctx->pos) | 932 | if (NULL == ctx->pos) |
920 | return 0; | 933 | return GNUNET_SYSERR; |
921 | if ('!' != ctx->pos[0]) | 934 | if ('!' != ctx->pos[0]) |
922 | { | 935 | { |
923 | ctx->ret = GNUNET_SYSERR; | 936 | ctx->ret = GNUNET_SYSERR; |
924 | GNUNET_break (0); | 937 | GNUNET_break (0); |
925 | return 0; | 938 | return GNUNET_SYSERR; |
926 | } | 939 | } |
927 | ctx->pos++; | 940 | ctx->pos++; |
928 | 941 | ||
@@ -943,7 +956,7 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
943 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 956 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
944 | _("Failed to parse HELLO message: missing expiration time\n")); | 957 | _("Failed to parse HELLO message: missing expiration time\n")); |
945 | GNUNET_break (0); | 958 | GNUNET_break (0); |
946 | return 0; | 959 | return GNUNET_SYSERR; |
947 | } | 960 | } |
948 | 961 | ||
949 | expiration_seconds = mktime (&expiration_time); | 962 | expiration_seconds = mktime (&expiration_time); |
@@ -953,7 +966,7 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
953 | _("Failed to parse HELLO message: invalid expiration time\n")); | 966 | _("Failed to parse HELLO message: invalid expiration time\n")); |
954 | ctx->ret = GNUNET_SYSERR; | 967 | ctx->ret = GNUNET_SYSERR; |
955 | GNUNET_break (0); | 968 | GNUNET_break (0); |
956 | return 0; | 969 | return GNUNET_SYSERR; |
957 | } | 970 | } |
958 | expire.abs_value_us = expiration_seconds * 1000LL * 1000LL; | 971 | expire.abs_value_us = expiration_seconds * 1000LL * 1000LL; |
959 | } | 972 | } |
@@ -963,7 +976,7 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
963 | _("Failed to parse HELLO message: malformed\n")); | 976 | _("Failed to parse HELLO message: malformed\n")); |
964 | ctx->ret = GNUNET_SYSERR; | 977 | ctx->ret = GNUNET_SYSERR; |
965 | GNUNET_break (0); | 978 | GNUNET_break (0); |
966 | return 0; | 979 | return GNUNET_SYSERR; |
967 | } | 980 | } |
968 | tname++; | 981 | tname++; |
969 | address = strchr (tname, (int) '!'); | 982 | address = strchr (tname, (int) '!'); |
@@ -973,11 +986,12 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
973 | _("Failed to parse HELLO message: missing transport plugin\n")); | 986 | _("Failed to parse HELLO message: missing transport plugin\n")); |
974 | ctx->ret = GNUNET_SYSERR; | 987 | ctx->ret = GNUNET_SYSERR; |
975 | GNUNET_break (0); | 988 | GNUNET_break (0); |
976 | return 0; | 989 | return GNUNET_SYSERR; |
977 | } | 990 | } |
978 | address++; | 991 | address++; |
979 | end = strchr (address, (int) '!'); | 992 | end = strchr (address, (int) '!'); |
980 | ctx->pos = end; | 993 | ctx->pos = end; |
994 | ctx->counter_total ++; | ||
981 | plugin_name = GNUNET_strndup (tname, address - (tname+1)); | 995 | plugin_name = GNUNET_strndup (tname, address - (tname+1)); |
982 | papi = ctx->plugins_find (plugin_name); | 996 | papi = ctx->plugins_find (plugin_name); |
983 | if (NULL == papi) | 997 | if (NULL == papi) |
@@ -986,7 +1000,7 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
986 | * Skip this part, advance to the next one and recurse. | 1000 | * Skip this part, advance to the next one and recurse. |
987 | * But only if this is not the end of string. | 1001 | * But only if this is not the end of string. |
988 | */ | 1002 | */ |
989 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1003 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
990 | _("Plugin `%s' not found, skipping address\n"), | 1004 | _("Plugin `%s' not found, skipping address\n"), |
991 | plugin_name); | 1005 | plugin_name); |
992 | GNUNET_free (plugin_name); | 1006 | GNUNET_free (plugin_name); |
@@ -994,7 +1008,7 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
994 | } | 1008 | } |
995 | if (NULL == papi->string_to_address) | 1009 | if (NULL == papi->string_to_address) |
996 | { | 1010 | { |
997 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1011 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
998 | _("Plugin `%s' does not support URIs yet\n"), | 1012 | _("Plugin `%s' does not support URIs yet\n"), |
999 | plugin_name); | 1013 | plugin_name); |
1000 | GNUNET_free (plugin_name); | 1014 | GNUNET_free (plugin_name); |
@@ -1027,6 +1041,7 @@ add_address_to_hello (void *cls, size_t max, void *buffer) | |||
1027 | haddr.address = addr; | 1041 | haddr.address = addr; |
1028 | haddr.transport_name = plugin_name; | 1042 | haddr.transport_name = plugin_name; |
1029 | ret = GNUNET_HELLO_add_address (&haddr, expire, buffer, max); | 1043 | ret = GNUNET_HELLO_add_address (&haddr, expire, buffer, max); |
1044 | ctx->counter_added ++; | ||
1030 | GNUNET_free (addr); | 1045 | GNUNET_free (addr); |
1031 | GNUNET_free (plugin_name); | 1046 | GNUNET_free (plugin_name); |
1032 | return ret; | 1047 | return ret; |
@@ -1080,9 +1095,15 @@ GNUNET_HELLO_parse_uri (const char *uri, | |||
1080 | 1095 | ||
1081 | ctx.pos = exc; | 1096 | ctx.pos = exc; |
1082 | ctx.ret = GNUNET_OK; | 1097 | ctx.ret = GNUNET_OK; |
1098 | ctx.counter_total = 0; | ||
1099 | ctx.counter_added = 0; | ||
1083 | ctx.plugins_find = plugins_find; | 1100 | ctx.plugins_find = plugins_find; |
1084 | *hello = GNUNET_HELLO_create (pubkey, &add_address_to_hello, &ctx, friend_only); | 1101 | *hello = GNUNET_HELLO_create (pubkey, &add_address_to_hello, &ctx, friend_only); |
1085 | 1102 | ||
1103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1104 | _("HELLO URI contained %u addresses, added %u addresses\n"), | ||
1105 | ctx.counter_total, ctx.counter_added); | ||
1106 | |||
1086 | return ctx.ret; | 1107 | return ctx.ret; |
1087 | } | 1108 | } |
1088 | 1109 | ||
diff --git a/src/hello/test_friend_hello.c b/src/hello/test_friend_hello.c index 019bf4b9a..79a55925c 100644 --- a/src/hello/test_friend_hello.c +++ b/src/hello/test_friend_hello.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_hello_lib.h" | 26 | #include "gnunet_hello_lib.h" |
27 | 27 | ||
28 | static size_t | 28 | static ssize_t |
29 | my_addr_gen (void *cls, size_t max, void *buf) | 29 | my_addr_gen (void *cls, size_t max, void *buf) |
30 | { | 30 | { |
31 | unsigned int *i = cls; | 31 | unsigned int *i = cls; |
@@ -35,7 +35,7 @@ my_addr_gen (void *cls, size_t max, void *buf) | |||
35 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 35 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
36 | "DEBUG: my_addr_gen called with i = %d\n", *i); | 36 | "DEBUG: my_addr_gen called with i = %d\n", *i); |
37 | if (0 == *i) | 37 | if (0 == *i) |
38 | return 0; | 38 | return GNUNET_SYSERR; /* Stop iteration */ |
39 | memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); | 39 | memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); |
40 | address.address = "address_information"; | 40 | address.address = "address_information"; |
41 | address.transport_name = "test"; | 41 | address.transport_name = "test"; |
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c index ff80f1889..d5d30fa1c 100644 --- a/src/hello/test_hello.c +++ b/src/hello/test_hello.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_hello_lib.h" | 26 | #include "gnunet_hello_lib.h" |
27 | 27 | ||
28 | static size_t | 28 | static ssize_t |
29 | my_addr_gen (void *cls, size_t max, void *buf) | 29 | my_addr_gen (void *cls, size_t max, void *buf) |
30 | { | 30 | { |
31 | unsigned int *i = cls; | 31 | unsigned int *i = cls; |
@@ -35,7 +35,7 @@ my_addr_gen (void *cls, size_t max, void *buf) | |||
35 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 35 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
36 | "DEBUG: my_addr_gen called with i = %d\n", *i); | 36 | "DEBUG: my_addr_gen called with i = %d\n", *i); |
37 | if (0 == *i) | 37 | if (0 == *i) |
38 | return 0; | 38 | return GNUNET_SYSERR; |
39 | memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); | 39 | memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); |
40 | address.address = "address_information"; | 40 | address.address = "address_information"; |
41 | address.transport_name = "test"; | 41 | address.transport_name = "test"; |