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