diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/peerinfo | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 1301 | ||||
-rw-r--r-- | src/peerinfo/peerinfo.h | 22 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 427 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api_notify.c | 170 | ||||
-rw-r--r-- | src/peerinfo/perf_peerinfo_api.c | 150 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api.c | 127 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api_friend_only.c | 155 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api_notify_friend_only.c | 226 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_shipped_hellos.c | 134 |
9 files changed, 1344 insertions, 1368 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index a884c5b76..25a3fabd7 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.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 peerinfo/gnunet-service-peerinfo.c | 22 | * @file peerinfo/gnunet-service-peerinfo.c |
@@ -39,21 +39,19 @@ | |||
39 | * How often do we scan the HOST_DIR for new entries? | 39 | * How often do we scan the HOST_DIR for new entries? |
40 | */ | 40 | */ |
41 | #define DATA_HOST_FREQ \ | 41 | #define DATA_HOST_FREQ \ |
42 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 42 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * How often do we discard old entries in data/hosts/? | 45 | * How often do we discard old entries in data/hosts/? |
46 | */ | 46 | */ |
47 | #define DATA_HOST_CLEAN_FREQ \ | 47 | #define DATA_HOST_CLEAN_FREQ \ |
48 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) | 48 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) |
49 | 49 | ||
50 | 50 | ||
51 | /** | 51 | /** |
52 | * In-memory cache of known hosts. | 52 | * In-memory cache of known hosts. |
53 | */ | 53 | */ |
54 | struct HostEntry | 54 | struct HostEntry { |
55 | { | ||
56 | |||
57 | /** | 55 | /** |
58 | * Identity of the peer. | 56 | * Identity of the peer. |
59 | */ | 57 | */ |
@@ -74,8 +72,7 @@ struct HostEntry | |||
74 | /** | 72 | /** |
75 | * Result of reading a file | 73 | * Result of reading a file |
76 | */ | 74 | */ |
77 | struct ReadHostFileContext | 75 | struct ReadHostFileContext { |
78 | { | ||
79 | /** | 76 | /** |
80 | * Hello for the peer (can be NULL) | 77 | * Hello for the peer (can be NULL) |
81 | */ | 78 | */ |
@@ -135,7 +132,7 @@ static struct GNUNET_SCHEDULER_Task *cron_scan; | |||
135 | * @return generated notification message | 132 | * @return generated notification message |
136 | */ | 133 | */ |
137 | static struct InfoMessage * | 134 | static struct InfoMessage * |
138 | make_info_message (const struct HostEntry *he, int include_friend_only) | 135 | make_info_message(const struct HostEntry *he, int include_friend_only) |
139 | { | 136 | { |
140 | struct InfoMessage *im; | 137 | struct InfoMessage *im; |
141 | struct GNUNET_HELLO_Message *src; | 138 | struct GNUNET_HELLO_Message *src; |
@@ -145,12 +142,12 @@ make_info_message (const struct HostEntry *he, int include_friend_only) | |||
145 | src = he->friend_only_hello; | 142 | src = he->friend_only_hello; |
146 | else | 143 | else |
147 | src = he->hello; | 144 | src = he->hello; |
148 | hs = (NULL == src) ? 0 : GNUNET_HELLO_size (src); | 145 | hs = (NULL == src) ? 0 : GNUNET_HELLO_size(src); |
149 | im = GNUNET_malloc (sizeof (struct InfoMessage) + hs); | 146 | im = GNUNET_malloc(sizeof(struct InfoMessage) + hs); |
150 | im->header.size = htons (hs + sizeof (struct InfoMessage)); | 147 | im->header.size = htons(hs + sizeof(struct InfoMessage)); |
151 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 148 | im->header.type = htons(GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
152 | im->peer = he->identity; | 149 | im->peer = he->identity; |
153 | GNUNET_memcpy (&im[1], src, hs); | 150 | GNUNET_memcpy(&im[1], src, hs); |
154 | return im; | 151 | return im; |
155 | } | 152 | } |
156 | 153 | ||
@@ -164,19 +161,19 @@ make_info_message (const struct HostEntry *he, int include_friend_only) | |||
164 | * @return #GNUNET_NO if expiration smaller than the current time | 161 | * @return #GNUNET_NO if expiration smaller than the current time |
165 | */ | 162 | */ |
166 | static int | 163 | static int |
167 | discard_expired (void *cls, | 164 | discard_expired(void *cls, |
168 | const struct GNUNET_HELLO_Address *address, | 165 | const struct GNUNET_HELLO_Address *address, |
169 | struct GNUNET_TIME_Absolute expiration) | 166 | struct GNUNET_TIME_Absolute expiration) |
170 | { | 167 | { |
171 | const struct GNUNET_TIME_Absolute *now = cls; | 168 | const struct GNUNET_TIME_Absolute *now = cls; |
172 | 169 | ||
173 | if (now->abs_value_us > expiration.abs_value_us) | 170 | if (now->abs_value_us > expiration.abs_value_us) |
174 | { | 171 | { |
175 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 172 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
176 | _ ("Removing expired address of transport `%s'\n"), | 173 | _("Removing expired address of transport `%s'\n"), |
177 | address->transport_name); | 174 | address->transport_name); |
178 | return GNUNET_NO; | 175 | return GNUNET_NO; |
179 | } | 176 | } |
180 | return GNUNET_OK; | 177 | return GNUNET_OK; |
181 | } | 178 | } |
182 | 179 | ||
@@ -190,14 +187,14 @@ discard_expired (void *cls, | |||
190 | * @return #GNUNET_OK (always) | 187 | * @return #GNUNET_OK (always) |
191 | */ | 188 | */ |
192 | static int | 189 | static int |
193 | count_addresses (void *cls, | 190 | count_addresses(void *cls, |
194 | const struct GNUNET_HELLO_Address *address, | 191 | const struct GNUNET_HELLO_Address *address, |
195 | struct GNUNET_TIME_Absolute expiration) | 192 | struct GNUNET_TIME_Absolute expiration) |
196 | { | 193 | { |
197 | unsigned int *cnt = cls; | 194 | unsigned int *cnt = cls; |
198 | 195 | ||
199 | (void) address; | 196 | (void)address; |
200 | (void) expiration; | 197 | (void)expiration; |
201 | (*cnt)++; | 198 | (*cnt)++; |
202 | return GNUNET_OK; | 199 | return GNUNET_OK; |
203 | } | 200 | } |
@@ -211,17 +208,17 @@ count_addresses (void *cls, | |||
211 | * @return filename of the form DIRECTORY/HOSTID | 208 | * @return filename of the form DIRECTORY/HOSTID |
212 | */ | 209 | */ |
213 | static char * | 210 | static char * |
214 | get_host_filename (const struct GNUNET_PeerIdentity *id) | 211 | get_host_filename(const struct GNUNET_PeerIdentity *id) |
215 | { | 212 | { |
216 | char *fn; | 213 | char *fn; |
217 | 214 | ||
218 | if (NULL == networkIdDirectory) | 215 | if (NULL == networkIdDirectory) |
219 | return NULL; | 216 | return NULL; |
220 | GNUNET_asprintf (&fn, | 217 | GNUNET_asprintf(&fn, |
221 | "%s%s%s", | 218 | "%s%s%s", |
222 | networkIdDirectory, | 219 | networkIdDirectory, |
223 | DIR_SEPARATOR_STR, | 220 | DIR_SEPARATOR_STR, |
224 | GNUNET_i2s_full (id)); | 221 | GNUNET_i2s_full(id)); |
225 | return fn; | 222 | return fn; |
226 | } | 223 | } |
227 | 224 | ||
@@ -233,24 +230,24 @@ get_host_filename (const struct GNUNET_PeerIdentity *id) | |||
233 | * @param entry entry to broadcast about | 230 | * @param entry entry to broadcast about |
234 | */ | 231 | */ |
235 | static void | 232 | static void |
236 | notify_all (struct HostEntry *entry) | 233 | notify_all(struct HostEntry *entry) |
237 | { | 234 | { |
238 | struct InfoMessage *msg_pub; | 235 | struct InfoMessage *msg_pub; |
239 | struct InfoMessage *msg_friend; | 236 | struct InfoMessage *msg_friend; |
240 | 237 | ||
241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 238 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
242 | "Notifying all clients about peer `%s'\n", | 239 | "Notifying all clients about peer `%s'\n", |
243 | GNUNET_i2s (&entry->identity)); | 240 | GNUNET_i2s(&entry->identity)); |
244 | msg_pub = make_info_message (entry, GNUNET_NO); | 241 | msg_pub = make_info_message(entry, GNUNET_NO); |
245 | GNUNET_notification_context_broadcast (notify_list, | 242 | GNUNET_notification_context_broadcast(notify_list, |
246 | &msg_pub->header, | 243 | &msg_pub->header, |
247 | GNUNET_NO); | 244 | GNUNET_NO); |
248 | GNUNET_free (msg_pub); | 245 | GNUNET_free(msg_pub); |
249 | msg_friend = make_info_message (entry, GNUNET_YES); | 246 | msg_friend = make_info_message(entry, GNUNET_YES); |
250 | GNUNET_notification_context_broadcast (notify_friend_only_list, | 247 | GNUNET_notification_context_broadcast(notify_friend_only_list, |
251 | &msg_friend->header, | 248 | &msg_friend->header, |
252 | GNUNET_NO); | 249 | GNUNET_NO); |
253 | GNUNET_free (msg_friend); | 250 | GNUNET_free(msg_friend); |
254 | } | 251 | } |
255 | 252 | ||
256 | 253 | ||
@@ -261,8 +258,8 @@ notify_all (struct HostEntry *entry) | |||
261 | * @param hello the verified (!) hello message | 258 | * @param hello the verified (!) hello message |
262 | */ | 259 | */ |
263 | static void | 260 | static void |
264 | update_hello (const struct GNUNET_PeerIdentity *peer, | 261 | update_hello(const struct GNUNET_PeerIdentity *peer, |
265 | const struct GNUNET_HELLO_Message *hello); | 262 | const struct GNUNET_HELLO_Message *hello); |
266 | 263 | ||
267 | 264 | ||
268 | /** | 265 | /** |
@@ -277,9 +274,9 @@ update_hello (const struct GNUNET_PeerIdentity *peer, | |||
277 | * @param r ReadHostFileContext to store the resutl | 274 | * @param r ReadHostFileContext to store the resutl |
278 | */ | 275 | */ |
279 | static void | 276 | static void |
280 | read_host_file (const char *fn, | 277 | read_host_file(const char *fn, |
281 | int unlink_garbage, | 278 | int unlink_garbage, |
282 | struct ReadHostFileContext *r) | 279 | struct ReadHostFileContext *r) |
283 | { | 280 | { |
284 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; | 281 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; |
285 | ssize_t size_total; | 282 | ssize_t size_total; |
@@ -293,114 +290,114 @@ read_host_file (const char *fn, | |||
293 | r->friend_only_hello = NULL; | 290 | r->friend_only_hello = NULL; |
294 | r->hello = NULL; | 291 | r->hello = NULL; |
295 | 292 | ||
296 | if (GNUNET_YES != GNUNET_DISK_file_test (fn)) | 293 | if (GNUNET_YES != GNUNET_DISK_file_test(fn)) |
297 | return; | 294 | return; |
298 | size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | 295 | size_total = GNUNET_DISK_fn_read(fn, buffer, sizeof(buffer)); |
299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 296 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
300 | "Read %d bytes from `%s'\n", | 297 | "Read %d bytes from `%s'\n", |
301 | (int) size_total, | 298 | (int)size_total, |
302 | fn); | 299 | fn); |
303 | if ((size_total < 0) || | 300 | if ((size_total < 0) || |
304 | (((size_t) size_total) < sizeof (struct GNUNET_MessageHeader))) | 301 | (((size_t)size_total) < sizeof(struct GNUNET_MessageHeader))) |
305 | { | ||
306 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
307 | _ ("Failed to parse HELLO in file `%s': %s\n"), | ||
308 | fn, | ||
309 | "File has invalid size"); | ||
310 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) && | ||
311 | (ENOENT != errno)) | ||
312 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
313 | return; | ||
314 | } | ||
315 | |||
316 | read_pos = 0; | ||
317 | while (read_pos < (size_t) size_total) | ||
318 | { | ||
319 | hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; | ||
320 | size_hello = GNUNET_HELLO_size (hello); | ||
321 | if ((0 == size_hello) || (((size_t) size_total) - read_pos < size_hello)) | ||
322 | { | 302 | { |
323 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 303 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
324 | _ ("Failed to parse HELLO in file `%s'\n"), | 304 | _("Failed to parse HELLO in file `%s': %s\n"), |
325 | fn); | 305 | fn, |
326 | if (0 == read_pos) | 306 | "File has invalid size"); |
327 | { | 307 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink(fn)) && |
328 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) && | 308 | (ENOENT != errno)) |
329 | (ENOENT != errno)) | 309 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
330 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
331 | } | ||
332 | else | ||
333 | { | ||
334 | if ((GNUNET_YES == unlink_garbage) && (0 != truncate (fn, read_pos)) && | ||
335 | (ENOENT != errno)) | ||
336 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", fn); | ||
337 | } | ||
338 | return; | 310 | return; |
339 | } | 311 | } |
340 | 312 | ||
341 | now = GNUNET_TIME_absolute_get (); | 313 | read_pos = 0; |
342 | hello_clean = GNUNET_HELLO_iterate_addresses (hello, | 314 | while (read_pos < (size_t)size_total) |
343 | GNUNET_YES, | ||
344 | &discard_expired, | ||
345 | &now); | ||
346 | if (NULL == hello_clean) | ||
347 | { | 315 | { |
348 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 316 | hello = (const struct GNUNET_HELLO_Message *)&buffer[read_pos]; |
349 | _ ("Failed to parse HELLO in file `%s'\n"), | 317 | size_hello = GNUNET_HELLO_size(hello); |
350 | fn); | 318 | if ((0 == size_hello) || (((size_t)size_total) - read_pos < size_hello)) |
351 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) && | 319 | { |
352 | (ENOENT != errno)) | 320 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
353 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 321 | _("Failed to parse HELLO in file `%s'\n"), |
354 | return; | 322 | fn); |
355 | } | 323 | if (0 == read_pos) |
356 | left = 0; | 324 | { |
357 | (void) GNUNET_HELLO_iterate_addresses (hello_clean, | 325 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink(fn)) && |
326 | (ENOENT != errno)) | ||
327 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
328 | } | ||
329 | else | ||
330 | { | ||
331 | if ((GNUNET_YES == unlink_garbage) && (0 != truncate(fn, read_pos)) && | ||
332 | (ENOENT != errno)) | ||
333 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "truncate", fn); | ||
334 | } | ||
335 | return; | ||
336 | } | ||
337 | |||
338 | now = GNUNET_TIME_absolute_get(); | ||
339 | hello_clean = GNUNET_HELLO_iterate_addresses(hello, | ||
340 | GNUNET_YES, | ||
341 | &discard_expired, | ||
342 | &now); | ||
343 | if (NULL == hello_clean) | ||
344 | { | ||
345 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
346 | _("Failed to parse HELLO in file `%s'\n"), | ||
347 | fn); | ||
348 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink(fn)) && | ||
349 | (ENOENT != errno)) | ||
350 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
351 | return; | ||
352 | } | ||
353 | left = 0; | ||
354 | (void)GNUNET_HELLO_iterate_addresses(hello_clean, | ||
358 | GNUNET_NO, | 355 | GNUNET_NO, |
359 | &count_addresses, | 356 | &count_addresses, |
360 | &left); | 357 | &left); |
361 | 358 | ||
362 | if (0 == left) | 359 | if (0 == left) |
363 | { | 360 | { |
364 | GNUNET_free (hello_clean); | 361 | GNUNET_free(hello_clean); |
365 | break; | 362 | break; |
366 | } | 363 | } |
367 | 364 | ||
368 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello_clean)) | 365 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello_clean)) |
369 | { | 366 | { |
370 | if (NULL == r->hello) | 367 | if (NULL == r->hello) |
371 | r->hello = hello_clean; | 368 | r->hello = hello_clean; |
369 | else | ||
370 | { | ||
371 | GNUNET_break(0); | ||
372 | GNUNET_free(r->hello); | ||
373 | r->hello = hello_clean; | ||
374 | } | ||
375 | } | ||
372 | else | 376 | else |
373 | { | 377 | { |
374 | GNUNET_break (0); | 378 | if (NULL == r->friend_only_hello) |
375 | GNUNET_free (r->hello); | 379 | r->friend_only_hello = hello_clean; |
376 | r->hello = hello_clean; | 380 | else |
377 | } | 381 | { |
382 | GNUNET_break(0); | ||
383 | GNUNET_free(r->friend_only_hello); | ||
384 | r->friend_only_hello = hello_clean; | ||
385 | } | ||
386 | } | ||
387 | read_pos += size_hello; | ||
378 | } | 388 | } |
379 | else | ||
380 | { | ||
381 | if (NULL == r->friend_only_hello) | ||
382 | r->friend_only_hello = hello_clean; | ||
383 | else | ||
384 | { | ||
385 | GNUNET_break (0); | ||
386 | GNUNET_free (r->friend_only_hello); | ||
387 | r->friend_only_hello = hello_clean; | ||
388 | } | ||
389 | } | ||
390 | read_pos += size_hello; | ||
391 | } | ||
392 | 389 | ||
393 | if (0 == left) | 390 | if (0 == left) |
394 | { | 391 | { |
395 | /* no addresses left, remove from disk */ | 392 | /* no addresses left, remove from disk */ |
396 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn))) | 393 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink(fn))) |
397 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 394 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
398 | } | 395 | } |
399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 396 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
400 | "Found `%s' and `%s' HELLO message in file\n", | 397 | "Found `%s' and `%s' HELLO message in file\n", |
401 | (NULL != r->hello) ? "public" : "NON-public", | 398 | (NULL != r->hello) ? "public" : "NON-public", |
402 | (NULL != r->friend_only_hello) ? "friend only" | 399 | (NULL != r->friend_only_hello) ? "friend only" |
403 | : "NO friend only"); | 400 | : "NO friend only"); |
404 | } | 401 | } |
405 | 402 | ||
406 | 403 | ||
@@ -411,44 +408,44 @@ read_host_file (const char *fn, | |||
411 | * @return the HostEntry | 408 | * @return the HostEntry |
412 | */ | 409 | */ |
413 | static struct HostEntry * | 410 | static struct HostEntry * |
414 | add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | 411 | add_host_to_known_hosts(const struct GNUNET_PeerIdentity *identity) |
415 | { | 412 | { |
416 | struct HostEntry *entry; | 413 | struct HostEntry *entry; |
417 | struct ReadHostFileContext r; | 414 | struct ReadHostFileContext r; |
418 | char *fn; | 415 | char *fn; |
419 | 416 | ||
420 | entry = GNUNET_CONTAINER_multipeermap_get (hostmap, identity); | 417 | entry = GNUNET_CONTAINER_multipeermap_get(hostmap, identity); |
421 | if (NULL == entry) | 418 | if (NULL == entry) |
422 | { | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
424 | "Adding new peer `%s'\n", | ||
425 | GNUNET_i2s (identity)); | ||
426 | GNUNET_STATISTICS_update (stats, | ||
427 | gettext_noop ("# peers known"), | ||
428 | 1, | ||
429 | GNUNET_NO); | ||
430 | entry = GNUNET_new (struct HostEntry); | ||
431 | entry->identity = *identity; | ||
432 | GNUNET_assert (GNUNET_OK == | ||
433 | GNUNET_CONTAINER_multipeermap_put ( | ||
434 | hostmap, | ||
435 | &entry->identity, | ||
436 | entry, | ||
437 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
438 | notify_all (entry); | ||
439 | fn = get_host_filename (identity); | ||
440 | if (NULL != fn) | ||
441 | { | 419 | { |
442 | read_host_file (fn, GNUNET_YES, &r); | 420 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
443 | if (NULL != r.hello) | 421 | "Adding new peer `%s'\n", |
444 | update_hello (identity, r.hello); | 422 | GNUNET_i2s(identity)); |
445 | if (NULL != r.friend_only_hello) | 423 | GNUNET_STATISTICS_update(stats, |
446 | update_hello (identity, r.friend_only_hello); | 424 | gettext_noop("# peers known"), |
447 | GNUNET_free_non_null (r.hello); | 425 | 1, |
448 | GNUNET_free_non_null (r.friend_only_hello); | 426 | GNUNET_NO); |
449 | GNUNET_free (fn); | 427 | entry = GNUNET_new(struct HostEntry); |
428 | entry->identity = *identity; | ||
429 | GNUNET_assert(GNUNET_OK == | ||
430 | GNUNET_CONTAINER_multipeermap_put( | ||
431 | hostmap, | ||
432 | &entry->identity, | ||
433 | entry, | ||
434 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
435 | notify_all(entry); | ||
436 | fn = get_host_filename(identity); | ||
437 | if (NULL != fn) | ||
438 | { | ||
439 | read_host_file(fn, GNUNET_YES, &r); | ||
440 | if (NULL != r.hello) | ||
441 | update_hello(identity, r.hello); | ||
442 | if (NULL != r.friend_only_hello) | ||
443 | update_hello(identity, r.friend_only_hello); | ||
444 | GNUNET_free_non_null(r.hello); | ||
445 | GNUNET_free_non_null(r.friend_only_hello); | ||
446 | GNUNET_free(fn); | ||
447 | } | ||
450 | } | 448 | } |
451 | } | ||
452 | return entry; | 449 | return entry; |
453 | } | 450 | } |
454 | 451 | ||
@@ -460,27 +457,26 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
460 | * @param fullname name of the file to remove | 457 | * @param fullname name of the file to remove |
461 | */ | 458 | */ |
462 | static void | 459 | static void |
463 | remove_garbage (const char *fullname) | 460 | remove_garbage(const char *fullname) |
464 | { | 461 | { |
465 | if (0 == unlink (fullname)) | 462 | if (0 == unlink(fullname)) |
466 | GNUNET_log ( | 463 | GNUNET_log( |
467 | GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 464 | GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
468 | _ ( | 465 | _( |
469 | "File `%s' in directory `%s' does not match naming convention. Removed.\n"), | 466 | "File `%s' in directory `%s' does not match naming convention. Removed.\n"), |
470 | fullname, | 467 | fullname, |
471 | networkIdDirectory); | 468 | networkIdDirectory); |
472 | else | 469 | else |
473 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 470 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
474 | "unlink", | 471 | "unlink", |
475 | fullname); | 472 | fullname); |
476 | } | 473 | } |
477 | 474 | ||
478 | 475 | ||
479 | /** | 476 | /** |
480 | * Closure for #hosts_directory_scan_callback(). | 477 | * Closure for #hosts_directory_scan_callback(). |
481 | */ | 478 | */ |
482 | struct DirScanContext | 479 | struct DirScanContext { |
483 | { | ||
484 | /** | 480 | /** |
485 | * #GNUNET_YES if we should remove files that are broken, | 481 | * #GNUNET_YES if we should remove files that are broken, |
486 | * #GNUNET_NO if the directory we are iterating over should | 482 | * #GNUNET_NO if the directory we are iterating over should |
@@ -506,7 +502,7 @@ struct DirScanContext | |||
506 | * @return #GNUNET_OK (continue iteration) | 502 | * @return #GNUNET_OK (continue iteration) |
507 | */ | 503 | */ |
508 | static int | 504 | static int |
509 | hosts_directory_scan_callback (void *cls, const char *fullname) | 505 | hosts_directory_scan_callback(void *cls, const char *fullname) |
510 | { | 506 | { |
511 | struct DirScanContext *dsc = cls; | 507 | struct DirScanContext *dsc = cls; |
512 | struct GNUNET_PeerIdentity identity; | 508 | struct GNUNET_PeerIdentity identity; |
@@ -516,81 +512,81 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
516 | struct GNUNET_PeerIdentity id_friend; | 512 | struct GNUNET_PeerIdentity id_friend; |
517 | struct GNUNET_PeerIdentity id; | 513 | struct GNUNET_PeerIdentity id; |
518 | 514 | ||
519 | if (GNUNET_YES != GNUNET_DISK_file_test (fullname)) | 515 | if (GNUNET_YES != GNUNET_DISK_file_test(fullname)) |
520 | return GNUNET_OK; /* ignore non-files */ | 516 | return GNUNET_OK; /* ignore non-files */ |
521 | 517 | ||
522 | filename = strrchr (fullname, DIR_SEPARATOR); | 518 | filename = strrchr(fullname, DIR_SEPARATOR); |
523 | if ((NULL == filename) || (1 > strlen (filename))) | 519 | if ((NULL == filename) || (1 > strlen(filename))) |
524 | filename = fullname; | 520 | filename = fullname; |
525 | else | 521 | else |
526 | filename++; | 522 | filename++; |
527 | 523 | ||
528 | read_host_file (fullname, dsc->remove_files, &r); | 524 | read_host_file(fullname, dsc->remove_files, &r); |
529 | if ((NULL == r.hello) && (NULL == r.friend_only_hello)) | 525 | if ((NULL == r.hello) && (NULL == r.friend_only_hello)) |
530 | return GNUNET_OK; | 526 | return GNUNET_OK; |
531 | if (NULL != r.friend_only_hello) | 527 | if (NULL != r.friend_only_hello) |
532 | { | ||
533 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend)) | ||
534 | { | 528 | { |
535 | if (GNUNET_YES == dsc->remove_files) | 529 | if (GNUNET_OK != GNUNET_HELLO_get_id(r.friend_only_hello, &id_friend)) |
536 | remove_garbage (fullname); | 530 | { |
537 | return GNUNET_OK; | 531 | if (GNUNET_YES == dsc->remove_files) |
532 | remove_garbage(fullname); | ||
533 | return GNUNET_OK; | ||
534 | } | ||
535 | id = id_friend; | ||
538 | } | 536 | } |
539 | id = id_friend; | ||
540 | } | ||
541 | if (NULL != r.hello) | 537 | if (NULL != r.hello) |
542 | { | ||
543 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.hello, &id_public)) | ||
544 | { | 538 | { |
545 | if (GNUNET_YES == dsc->remove_files) | 539 | if (GNUNET_OK != GNUNET_HELLO_get_id(r.hello, &id_public)) |
546 | remove_garbage (fullname); | 540 | { |
547 | return GNUNET_OK; | 541 | if (GNUNET_YES == dsc->remove_files) |
542 | remove_garbage(fullname); | ||
543 | return GNUNET_OK; | ||
544 | } | ||
545 | id = id_public; | ||
548 | } | 546 | } |
549 | id = id_public; | ||
550 | } | ||
551 | 547 | ||
552 | if ((NULL != r.hello) && (NULL != r.friend_only_hello) && | 548 | if ((NULL != r.hello) && (NULL != r.friend_only_hello) && |
553 | (0 != GNUNET_memcmp (&id_friend, &id_public))) | 549 | (0 != GNUNET_memcmp(&id_friend, &id_public))) |
554 | { | ||
555 | /* HELLOs are not for the same peer */ | ||
556 | GNUNET_break (0); | ||
557 | if (GNUNET_YES == dsc->remove_files) | ||
558 | remove_garbage (fullname); | ||
559 | return GNUNET_OK; | ||
560 | } | ||
561 | if (GNUNET_OK == | ||
562 | GNUNET_CRYPTO_eddsa_public_key_from_string (filename, | ||
563 | strlen (filename), | ||
564 | &identity.public_key)) | ||
565 | { | ||
566 | if (0 != GNUNET_memcmp (&id, &identity)) | ||
567 | { | 550 | { |
568 | /* HELLOs are not for the same peer */ | 551 | /* HELLOs are not for the same peer */ |
569 | GNUNET_break (0); | 552 | GNUNET_break(0); |
570 | if (GNUNET_YES == dsc->remove_files) | 553 | if (GNUNET_YES == dsc->remove_files) |
571 | remove_garbage (fullname); | 554 | remove_garbage(fullname); |
572 | return GNUNET_OK; | 555 | return GNUNET_OK; |
573 | } | 556 | } |
574 | } | 557 | if (GNUNET_OK == |
558 | GNUNET_CRYPTO_eddsa_public_key_from_string(filename, | ||
559 | strlen(filename), | ||
560 | &identity.public_key)) | ||
561 | { | ||
562 | if (0 != GNUNET_memcmp(&id, &identity)) | ||
563 | { | ||
564 | /* HELLOs are not for the same peer */ | ||
565 | GNUNET_break(0); | ||
566 | if (GNUNET_YES == dsc->remove_files) | ||
567 | remove_garbage(fullname); | ||
568 | return GNUNET_OK; | ||
569 | } | ||
570 | } | ||
575 | 571 | ||
576 | /* ok, found something valid, remember HELLO */ | 572 | /* ok, found something valid, remember HELLO */ |
577 | add_host_to_known_hosts (&id); | 573 | add_host_to_known_hosts(&id); |
578 | if (NULL != r.hello) | 574 | if (NULL != r.hello) |
579 | { | 575 | { |
580 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 576 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
581 | "Updating peer `%s' public HELLO \n", | 577 | "Updating peer `%s' public HELLO \n", |
582 | GNUNET_i2s (&id)); | 578 | GNUNET_i2s(&id)); |
583 | update_hello (&id, r.hello); | 579 | update_hello(&id, r.hello); |
584 | GNUNET_free (r.hello); | 580 | GNUNET_free(r.hello); |
585 | } | 581 | } |
586 | if (NULL != r.friend_only_hello) | 582 | if (NULL != r.friend_only_hello) |
587 | { | 583 | { |
588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 584 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
589 | "Updating peer `%s' friend only HELLO \n", | 585 | "Updating peer `%s' friend only HELLO \n", |
590 | GNUNET_i2s (&id)); | 586 | GNUNET_i2s(&id)); |
591 | update_hello (&id, r.friend_only_hello); | 587 | update_hello(&id, r.friend_only_hello); |
592 | GNUNET_free (r.friend_only_hello); | 588 | GNUNET_free(r.friend_only_hello); |
593 | } | 589 | } |
594 | dsc->matched++; | 590 | dsc->matched++; |
595 | return GNUNET_OK; | 591 | return GNUNET_OK; |
596 | } | 592 | } |
@@ -602,39 +598,39 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
602 | * @param cls unused | 598 | * @param cls unused |
603 | */ | 599 | */ |
604 | static void | 600 | static void |
605 | cron_scan_directory_data_hosts (void *cls) | 601 | cron_scan_directory_data_hosts(void *cls) |
606 | { | 602 | { |
607 | static unsigned int retries; | 603 | static unsigned int retries; |
608 | struct DirScanContext dsc; | 604 | struct DirScanContext dsc; |
609 | 605 | ||
610 | (void) cls; | 606 | (void)cls; |
611 | cron_scan = NULL; | 607 | cron_scan = NULL; |
612 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory)) | 608 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create(networkIdDirectory)) |
613 | { | 609 | { |
614 | cron_scan = | 610 | cron_scan = |
615 | GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, | 611 | GNUNET_SCHEDULER_add_delayed_with_priority(DATA_HOST_FREQ, |
616 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 612 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
617 | &cron_scan_directory_data_hosts, | 613 | &cron_scan_directory_data_hosts, |
618 | NULL); | 614 | NULL); |
619 | return; | 615 | return; |
620 | } | 616 | } |
621 | dsc.matched = 0; | 617 | dsc.matched = 0; |
622 | dsc.remove_files = GNUNET_YES; | 618 | dsc.remove_files = GNUNET_YES; |
623 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 619 | GNUNET_log(GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
624 | _ ("Scanning directory `%s'\n"), | 620 | _("Scanning directory `%s'\n"), |
625 | networkIdDirectory); | 621 | networkIdDirectory); |
626 | GNUNET_DISK_directory_scan (networkIdDirectory, | 622 | GNUNET_DISK_directory_scan(networkIdDirectory, |
627 | &hosts_directory_scan_callback, | 623 | &hosts_directory_scan_callback, |
628 | &dsc); | 624 | &dsc); |
629 | if ((0 == dsc.matched) && (0 == (++retries & 31))) | 625 | if ((0 == dsc.matched) && (0 == (++retries & 31))) |
630 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 626 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
631 | _ ("Still no peers found in `%s'!\n"), | 627 | _("Still no peers found in `%s'!\n"), |
632 | networkIdDirectory); | 628 | networkIdDirectory); |
633 | cron_scan = | 629 | cron_scan = |
634 | GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, | 630 | GNUNET_SCHEDULER_add_delayed_with_priority(DATA_HOST_FREQ, |
635 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 631 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
636 | &cron_scan_directory_data_hosts, | 632 | &cron_scan_directory_data_hosts, |
637 | NULL); | 633 | NULL); |
638 | } | 634 | } |
639 | 635 | ||
640 | 636 | ||
@@ -646,29 +642,29 @@ cron_scan_directory_data_hosts (void *cls) | |||
646 | * @return merged HELLO | 642 | * @return merged HELLO |
647 | */ | 643 | */ |
648 | static struct GNUNET_HELLO_Message * | 644 | static struct GNUNET_HELLO_Message * |
649 | update_friend_hello (const struct GNUNET_HELLO_Message *hello, | 645 | update_friend_hello(const struct GNUNET_HELLO_Message *hello, |
650 | const struct GNUNET_HELLO_Message *friend_hello) | 646 | const struct GNUNET_HELLO_Message *friend_hello) |
651 | { | 647 | { |
652 | struct GNUNET_HELLO_Message *res; | 648 | struct GNUNET_HELLO_Message *res; |
653 | struct GNUNET_HELLO_Message *tmp; | 649 | struct GNUNET_HELLO_Message *tmp; |
654 | struct GNUNET_PeerIdentity pid; | 650 | struct GNUNET_PeerIdentity pid; |
655 | 651 | ||
656 | if (NULL != friend_hello) | 652 | if (NULL != friend_hello) |
657 | { | 653 | { |
658 | res = GNUNET_HELLO_merge (hello, friend_hello); | 654 | res = GNUNET_HELLO_merge(hello, friend_hello); |
659 | GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); | 655 | GNUNET_assert(GNUNET_YES == GNUNET_HELLO_is_friend_only(res)); |
660 | return res; | 656 | return res; |
661 | } | 657 | } |
662 | 658 | ||
663 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) | 659 | if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid)) |
664 | { | 660 | { |
665 | GNUNET_break (0); | 661 | GNUNET_break(0); |
666 | return NULL; | 662 | return NULL; |
667 | } | 663 | } |
668 | tmp = GNUNET_HELLO_create (&pid.public_key, NULL, NULL, GNUNET_YES); | 664 | tmp = GNUNET_HELLO_create(&pid.public_key, NULL, NULL, GNUNET_YES); |
669 | res = GNUNET_HELLO_merge (hello, tmp); | 665 | res = GNUNET_HELLO_merge(hello, tmp); |
670 | GNUNET_free (tmp); | 666 | GNUNET_free(tmp); |
671 | GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); | 667 | GNUNET_assert(GNUNET_YES == GNUNET_HELLO_is_friend_only(res)); |
672 | return res; | 668 | return res; |
673 | } | 669 | } |
674 | 670 | ||
@@ -680,8 +676,8 @@ update_friend_hello (const struct GNUNET_HELLO_Message *hello, | |||
680 | * @param hello the verified (!) hello message | 676 | * @param hello the verified (!) hello message |
681 | */ | 677 | */ |
682 | static void | 678 | static void |
683 | update_hello (const struct GNUNET_PeerIdentity *peer, | 679 | update_hello(const struct GNUNET_PeerIdentity *peer, |
684 | const struct GNUNET_HELLO_Message *hello) | 680 | const struct GNUNET_HELLO_Message *hello) |
685 | { | 681 | { |
686 | char *fn; | 682 | char *fn; |
687 | struct HostEntry *host; | 683 | struct HostEntry *host; |
@@ -696,145 +692,144 @@ update_hello (const struct GNUNET_PeerIdentity *peer, | |||
696 | unsigned int pos; | 692 | unsigned int pos; |
697 | char *buffer; | 693 | char *buffer; |
698 | 694 | ||
699 | host = GNUNET_CONTAINER_multipeermap_get (hostmap, peer); | 695 | host = GNUNET_CONTAINER_multipeermap_get(hostmap, peer); |
700 | GNUNET_assert (NULL != host); | 696 | GNUNET_assert(NULL != host); |
701 | 697 | ||
702 | friend_hello_type = GNUNET_HELLO_is_friend_only (hello); | 698 | friend_hello_type = GNUNET_HELLO_is_friend_only(hello); |
703 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 699 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
704 | "Updating %s HELLO for `%s'\n", | 700 | "Updating %s HELLO for `%s'\n", |
705 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", | 701 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", |
706 | GNUNET_i2s (peer)); | 702 | GNUNET_i2s(peer)); |
707 | 703 | ||
708 | dest = NULL; | 704 | dest = NULL; |
709 | if (GNUNET_YES == friend_hello_type) | 705 | if (GNUNET_YES == friend_hello_type) |
710 | { | 706 | { |
711 | dest = &host->friend_only_hello; | 707 | dest = &host->friend_only_hello; |
712 | } | 708 | } |
713 | else | 709 | else |
714 | { | 710 | { |
715 | dest = &host->hello; | 711 | dest = &host->hello; |
716 | } | 712 | } |
717 | 713 | ||
718 | if (NULL == (*dest)) | 714 | if (NULL == (*dest)) |
719 | { | 715 | { |
720 | (*dest) = GNUNET_malloc (GNUNET_HELLO_size (hello)); | 716 | (*dest) = GNUNET_malloc(GNUNET_HELLO_size(hello)); |
721 | GNUNET_memcpy ((*dest), hello, GNUNET_HELLO_size (hello)); | 717 | GNUNET_memcpy((*dest), hello, GNUNET_HELLO_size(hello)); |
722 | } | 718 | } |
723 | else | 719 | else |
724 | { | ||
725 | mrg = GNUNET_HELLO_merge ((*dest), hello); | ||
726 | delta = GNUNET_HELLO_equals (mrg, (*dest), GNUNET_TIME_absolute_get ()); | ||
727 | if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | ||
728 | { | 720 | { |
729 | /* no differences, just ignore the update */ | 721 | mrg = GNUNET_HELLO_merge((*dest), hello); |
730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 722 | delta = GNUNET_HELLO_equals(mrg, (*dest), GNUNET_TIME_absolute_get()); |
731 | "No change in %s HELLO for `%s'\n", | 723 | if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) |
732 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", | 724 | { |
733 | GNUNET_i2s (peer)); | 725 | /* no differences, just ignore the update */ |
734 | GNUNET_free (mrg); | 726 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
735 | return; | 727 | "No change in %s HELLO for `%s'\n", |
728 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", | ||
729 | GNUNET_i2s(peer)); | ||
730 | GNUNET_free(mrg); | ||
731 | return; | ||
732 | } | ||
733 | GNUNET_free((*dest)); | ||
734 | (*dest) = mrg; | ||
736 | } | 735 | } |
737 | GNUNET_free ((*dest)); | ||
738 | (*dest) = mrg; | ||
739 | } | ||
740 | 736 | ||
741 | if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type)) | 737 | if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type)) |
742 | { | 738 | { |
743 | /* Update friend only hello */ | 739 | /* Update friend only hello */ |
744 | mrg = update_friend_hello (host->hello, host->friend_only_hello); | 740 | mrg = update_friend_hello(host->hello, host->friend_only_hello); |
745 | if (NULL != host->friend_only_hello) | 741 | if (NULL != host->friend_only_hello) |
746 | GNUNET_free (host->friend_only_hello); | 742 | GNUNET_free(host->friend_only_hello); |
747 | host->friend_only_hello = mrg; | 743 | host->friend_only_hello = mrg; |
748 | } | 744 | } |
749 | 745 | ||
750 | if (NULL != host->hello) | 746 | if (NULL != host->hello) |
751 | GNUNET_assert ((GNUNET_NO == GNUNET_HELLO_is_friend_only (host->hello))); | 747 | GNUNET_assert((GNUNET_NO == GNUNET_HELLO_is_friend_only(host->hello))); |
752 | if (NULL != host->friend_only_hello) | 748 | if (NULL != host->friend_only_hello) |
753 | GNUNET_assert ( | 749 | GNUNET_assert( |
754 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (host->friend_only_hello))); | 750 | (GNUNET_YES == GNUNET_HELLO_is_friend_only(host->friend_only_hello))); |
755 | 751 | ||
756 | fn = get_host_filename (peer); | 752 | fn = get_host_filename(peer); |
757 | if ((NULL != fn) && (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn))) | 753 | if ((NULL != fn) && (GNUNET_OK == GNUNET_DISK_directory_create_for_file(fn))) |
758 | { | 754 | { |
759 | store_hello = GNUNET_NO; | 755 | store_hello = GNUNET_NO; |
760 | size = 0; | 756 | size = 0; |
761 | cnt = 0; | 757 | cnt = 0; |
762 | if (NULL != host->hello) | 758 | if (NULL != host->hello) |
763 | (void) GNUNET_HELLO_iterate_addresses (host->hello, | 759 | (void)GNUNET_HELLO_iterate_addresses(host->hello, |
764 | GNUNET_NO, | 760 | GNUNET_NO, |
765 | &count_addresses, | 761 | &count_addresses, |
766 | &cnt); | 762 | &cnt); |
767 | if (cnt > 0) | 763 | if (cnt > 0) |
768 | { | 764 | { |
769 | store_hello = GNUNET_YES; | 765 | store_hello = GNUNET_YES; |
770 | size += GNUNET_HELLO_size (host->hello); | 766 | size += GNUNET_HELLO_size(host->hello); |
771 | } | 767 | } |
772 | cnt = 0; | 768 | cnt = 0; |
773 | if (NULL != host->friend_only_hello) | 769 | if (NULL != host->friend_only_hello) |
774 | (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello, | 770 | (void)GNUNET_HELLO_iterate_addresses(host->friend_only_hello, |
775 | GNUNET_NO, | 771 | GNUNET_NO, |
776 | &count_addresses, | 772 | &count_addresses, |
777 | &cnt); | 773 | &cnt); |
778 | store_friend_hello = GNUNET_NO; | 774 | store_friend_hello = GNUNET_NO; |
779 | if (0 < cnt) | 775 | if (0 < cnt) |
780 | { | 776 | { |
781 | store_friend_hello = GNUNET_YES; | 777 | store_friend_hello = GNUNET_YES; |
782 | size += GNUNET_HELLO_size (host->friend_only_hello); | 778 | size += GNUNET_HELLO_size(host->friend_only_hello); |
783 | } | 779 | } |
784 | 780 | ||
785 | if ((GNUNET_NO == store_hello) && (GNUNET_NO == store_friend_hello)) | 781 | if ((GNUNET_NO == store_hello) && (GNUNET_NO == store_friend_hello)) |
786 | { | 782 | { |
787 | /* no valid addresses, don't put HELLO on disk; in fact, | 783 | /* no valid addresses, don't put HELLO on disk; in fact, |
788 | if one exists on disk, remove it */ | 784 | if one exists on disk, remove it */ |
789 | (void) unlink (fn); | 785 | (void)unlink(fn); |
790 | } | 786 | } |
791 | else | ||
792 | { | ||
793 | buffer = GNUNET_malloc (size); | ||
794 | pos = 0; | ||
795 | |||
796 | if (GNUNET_YES == store_hello) | ||
797 | { | ||
798 | GNUNET_memcpy (buffer, host->hello, GNUNET_HELLO_size (host->hello)); | ||
799 | pos += GNUNET_HELLO_size (host->hello); | ||
800 | } | ||
801 | if (GNUNET_YES == store_friend_hello) | ||
802 | { | ||
803 | GNUNET_memcpy (&buffer[pos], | ||
804 | host->friend_only_hello, | ||
805 | GNUNET_HELLO_size (host->friend_only_hello)); | ||
806 | pos += GNUNET_HELLO_size (host->friend_only_hello); | ||
807 | } | ||
808 | GNUNET_assert (pos == size); | ||
809 | |||
810 | if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn, | ||
811 | buffer, | ||
812 | size, | ||
813 | GNUNET_DISK_PERM_USER_READ | | ||
814 | GNUNET_DISK_PERM_USER_WRITE | | ||
815 | GNUNET_DISK_PERM_GROUP_READ | | ||
816 | GNUNET_DISK_PERM_OTHER_READ)) | ||
817 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | ||
818 | else | 787 | else |
819 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 788 | { |
820 | "Stored %s %s HELLO in %s with total size %u\n", | 789 | buffer = GNUNET_malloc(size); |
821 | (GNUNET_YES == store_friend_hello) ? "friend-only" : "", | 790 | pos = 0; |
822 | (GNUNET_YES == store_hello) ? "public" : "", | 791 | |
823 | fn, | 792 | if (GNUNET_YES == store_hello) |
824 | size); | 793 | { |
825 | GNUNET_free (buffer); | 794 | GNUNET_memcpy(buffer, host->hello, GNUNET_HELLO_size(host->hello)); |
795 | pos += GNUNET_HELLO_size(host->hello); | ||
796 | } | ||
797 | if (GNUNET_YES == store_friend_hello) | ||
798 | { | ||
799 | GNUNET_memcpy(&buffer[pos], | ||
800 | host->friend_only_hello, | ||
801 | GNUNET_HELLO_size(host->friend_only_hello)); | ||
802 | pos += GNUNET_HELLO_size(host->friend_only_hello); | ||
803 | } | ||
804 | GNUNET_assert(pos == size); | ||
805 | |||
806 | if (GNUNET_SYSERR == GNUNET_DISK_fn_write(fn, | ||
807 | buffer, | ||
808 | size, | ||
809 | GNUNET_DISK_PERM_USER_READ | | ||
810 | GNUNET_DISK_PERM_USER_WRITE | | ||
811 | GNUNET_DISK_PERM_GROUP_READ | | ||
812 | GNUNET_DISK_PERM_OTHER_READ)) | ||
813 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "write", fn); | ||
814 | else | ||
815 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
816 | "Stored %s %s HELLO in %s with total size %u\n", | ||
817 | (GNUNET_YES == store_friend_hello) ? "friend-only" : "", | ||
818 | (GNUNET_YES == store_hello) ? "public" : "", | ||
819 | fn, | ||
820 | size); | ||
821 | GNUNET_free(buffer); | ||
822 | } | ||
826 | } | 823 | } |
827 | } | 824 | GNUNET_free_non_null(fn); |
828 | GNUNET_free_non_null (fn); | 825 | notify_all(host); |
829 | notify_all (host); | ||
830 | } | 826 | } |
831 | 827 | ||
832 | 828 | ||
833 | /** | 829 | /** |
834 | * Closure for #add_to_tc() | 830 | * Closure for #add_to_tc() |
835 | */ | 831 | */ |
836 | struct TransmitContext | 832 | struct TransmitContext { |
837 | { | ||
838 | /** | 833 | /** |
839 | * Client to transmit to | 834 | * Client to transmit to |
840 | */ | 835 | */ |
@@ -856,7 +851,7 @@ struct TransmitContext | |||
856 | * @return #GNUNET_YES (continue to iterate) | 851 | * @return #GNUNET_YES (continue to iterate) |
857 | */ | 852 | */ |
858 | static int | 853 | static int |
859 | add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 854 | add_to_tc(void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
860 | { | 855 | { |
861 | struct TransmitContext *tc = cls; | 856 | struct TransmitContext *tc = cls; |
862 | struct HostEntry *pos = value; | 857 | struct HostEntry *pos = value; |
@@ -867,38 +862,38 @@ add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
867 | hs = 0; | 862 | hs = 0; |
868 | 863 | ||
869 | if ((NULL != pos->hello) && (GNUNET_NO == tc->friend_only)) | 864 | if ((NULL != pos->hello) && (GNUNET_NO == tc->friend_only)) |
870 | { | 865 | { |
871 | /* Copy public HELLO */ | 866 | /* Copy public HELLO */ |
872 | hs = GNUNET_HELLO_size (pos->hello); | 867 | hs = GNUNET_HELLO_size(pos->hello); |
873 | GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE - sizeof (struct InfoMessage)); | 868 | GNUNET_assert(hs < GNUNET_MAX_MESSAGE_SIZE - sizeof(struct InfoMessage)); |
874 | env = GNUNET_MQ_msg_extra (im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 869 | env = GNUNET_MQ_msg_extra(im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
875 | GNUNET_memcpy (&im[1], pos->hello, hs); | 870 | GNUNET_memcpy(&im[1], pos->hello, hs); |
876 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 871 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
877 | "Sending public HELLO with size %u for peer `%s'\n", | 872 | "Sending public HELLO with size %u for peer `%s'\n", |
878 | hs, | 873 | hs, |
879 | GNUNET_i2s (key)); | 874 | GNUNET_i2s(key)); |
880 | } | 875 | } |
881 | else if ((NULL != pos->friend_only_hello) && (GNUNET_YES == tc->friend_only)) | 876 | else if ((NULL != pos->friend_only_hello) && (GNUNET_YES == tc->friend_only)) |
882 | { | 877 | { |
883 | /* Copy friend only HELLO */ | 878 | /* Copy friend only HELLO */ |
884 | hs = GNUNET_HELLO_size (pos->friend_only_hello); | 879 | hs = GNUNET_HELLO_size(pos->friend_only_hello); |
885 | GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE - sizeof (struct InfoMessage)); | 880 | GNUNET_assert(hs < GNUNET_MAX_MESSAGE_SIZE - sizeof(struct InfoMessage)); |
886 | env = GNUNET_MQ_msg_extra (im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 881 | env = GNUNET_MQ_msg_extra(im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
887 | GNUNET_memcpy (&im[1], pos->friend_only_hello, hs); | 882 | GNUNET_memcpy(&im[1], pos->friend_only_hello, hs); |
888 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 883 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
889 | "Sending friend-only HELLO with size %u for peer `%s'\n", | 884 | "Sending friend-only HELLO with size %u for peer `%s'\n", |
890 | hs, | 885 | hs, |
891 | GNUNET_i2s (key)); | 886 | GNUNET_i2s(key)); |
892 | } | 887 | } |
893 | else | 888 | else |
894 | { | 889 | { |
895 | env = GNUNET_MQ_msg (im, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 890 | env = GNUNET_MQ_msg(im, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 891 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
897 | "Adding no HELLO for peer `%s'\n", | 892 | "Adding no HELLO for peer `%s'\n", |
898 | GNUNET_i2s (key)); | 893 | GNUNET_i2s(key)); |
899 | } | 894 | } |
900 | im->peer = pos->identity; | 895 | im->peer = pos->identity; |
901 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (tc->client), env); | 896 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(tc->client), env); |
902 | return GNUNET_YES; | 897 | return GNUNET_YES; |
903 | } | 898 | } |
904 | 899 | ||
@@ -911,7 +906,7 @@ add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
911 | * @return #GNUNET_OK (continue iteration) | 906 | * @return #GNUNET_OK (continue iteration) |
912 | */ | 907 | */ |
913 | static int | 908 | static int |
914 | discard_hosts_helper (void *cls, const char *fn) | 909 | discard_hosts_helper(void *cls, const char *fn) |
915 | { | 910 | { |
916 | struct GNUNET_TIME_Absolute *now = cls; | 911 | struct GNUNET_TIME_Absolute *now = cls; |
917 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; | 912 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; |
@@ -926,82 +921,82 @@ discard_hosts_helper (void *cls, const char *fn) | |||
926 | char *writebuffer; | 921 | char *writebuffer; |
927 | uint64_t fsize; | 922 | uint64_t fsize; |
928 | 923 | ||
929 | if (GNUNET_OK != GNUNET_DISK_file_size (fn, &fsize, GNUNET_YES, GNUNET_YES)) | 924 | if (GNUNET_OK != GNUNET_DISK_file_size(fn, &fsize, GNUNET_YES, GNUNET_YES)) |
930 | { | 925 | { |
931 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 926 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING | |
932 | GNUNET_ERROR_TYPE_BULK, | 927 | GNUNET_ERROR_TYPE_BULK, |
933 | "fstat", | 928 | "fstat", |
934 | fn); | 929 | fn); |
935 | return GNUNET_OK; | 930 | return GNUNET_OK; |
936 | } | 931 | } |
937 | read_size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | 932 | read_size = GNUNET_DISK_fn_read(fn, buffer, sizeof(buffer)); |
938 | 933 | ||
939 | if ((read_size < (int) sizeof (struct GNUNET_MessageHeader)) || | 934 | if ((read_size < (int)sizeof(struct GNUNET_MessageHeader)) || |
940 | (fsize > GNUNET_MAX_MESSAGE_SIZE)) | 935 | (fsize > GNUNET_MAX_MESSAGE_SIZE)) |
941 | { | 936 | { |
942 | if (0 != unlink (fn)) | 937 | if (0 != unlink(fn)) |
943 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 938 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING | |
944 | GNUNET_ERROR_TYPE_BULK, | 939 | GNUNET_ERROR_TYPE_BULK, |
945 | "unlink", | 940 | "unlink", |
946 | fn); | 941 | fn); |
947 | return GNUNET_OK; | 942 | return GNUNET_OK; |
948 | } | 943 | } |
949 | 944 | ||
950 | writebuffer = GNUNET_malloc (read_size); | 945 | writebuffer = GNUNET_malloc(read_size); |
951 | read_pos = 0; | 946 | read_pos = 0; |
952 | write_pos = 0; | 947 | write_pos = 0; |
953 | while (read_pos < read_size) | 948 | while (read_pos < read_size) |
954 | { | ||
955 | /* Check each HELLO */ | ||
956 | hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; | ||
957 | cur_hello_size = GNUNET_HELLO_size (hello); | ||
958 | if (0 == cur_hello_size) | ||
959 | { | 949 | { |
960 | /* Invalid data, discard */ | 950 | /* Check each HELLO */ |
961 | if (0 != unlink (fn)) | 951 | hello = (const struct GNUNET_HELLO_Message *)&buffer[read_pos]; |
962 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 952 | cur_hello_size = GNUNET_HELLO_size(hello); |
963 | GNUNET_ERROR_TYPE_BULK, | 953 | if (0 == cur_hello_size) |
964 | "unlink", | 954 | { |
965 | fn); | 955 | /* Invalid data, discard */ |
966 | GNUNET_free (writebuffer); | 956 | if (0 != unlink(fn)) |
967 | return GNUNET_OK; | 957 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING | |
968 | } | 958 | GNUNET_ERROR_TYPE_BULK, |
969 | new_hello = | 959 | "unlink", |
970 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now); | 960 | fn); |
971 | cnt = 0; | 961 | GNUNET_free(writebuffer); |
972 | if (NULL != new_hello) | 962 | return GNUNET_OK; |
973 | (void) GNUNET_HELLO_iterate_addresses (hello, | 963 | } |
964 | new_hello = | ||
965 | GNUNET_HELLO_iterate_addresses(hello, GNUNET_YES, &discard_expired, now); | ||
966 | cnt = 0; | ||
967 | if (NULL != new_hello) | ||
968 | (void)GNUNET_HELLO_iterate_addresses(hello, | ||
974 | GNUNET_NO, | 969 | GNUNET_NO, |
975 | &count_addresses, | 970 | &count_addresses, |
976 | &cnt); | 971 | &cnt); |
977 | if ((NULL != new_hello) && (0 < cnt)) | 972 | if ((NULL != new_hello) && (0 < cnt)) |
978 | { | 973 | { |
979 | /* Store new HELLO to write it when done */ | 974 | /* Store new HELLO to write it when done */ |
980 | new_hello_size = GNUNET_HELLO_size (new_hello); | 975 | new_hello_size = GNUNET_HELLO_size(new_hello); |
981 | GNUNET_memcpy (&writebuffer[write_pos], new_hello, new_hello_size); | 976 | GNUNET_memcpy(&writebuffer[write_pos], new_hello, new_hello_size); |
982 | write_pos += new_hello_size; | 977 | write_pos += new_hello_size; |
978 | } | ||
979 | read_pos += cur_hello_size; | ||
980 | GNUNET_free_non_null(new_hello); | ||
983 | } | 981 | } |
984 | read_pos += cur_hello_size; | ||
985 | GNUNET_free_non_null (new_hello); | ||
986 | } | ||
987 | 982 | ||
988 | if (0 < write_pos) | 983 | if (0 < write_pos) |
989 | { | 984 | { |
990 | GNUNET_DISK_fn_write (fn, | 985 | GNUNET_DISK_fn_write(fn, |
991 | writebuffer, | 986 | writebuffer, |
992 | write_pos, | 987 | write_pos, |
993 | GNUNET_DISK_PERM_USER_READ | | 988 | GNUNET_DISK_PERM_USER_READ | |
994 | GNUNET_DISK_PERM_USER_WRITE | | 989 | GNUNET_DISK_PERM_USER_WRITE | |
995 | GNUNET_DISK_PERM_GROUP_READ | | 990 | GNUNET_DISK_PERM_GROUP_READ | |
996 | GNUNET_DISK_PERM_OTHER_READ); | 991 | GNUNET_DISK_PERM_OTHER_READ); |
997 | } | 992 | } |
998 | else if (0 != unlink (fn)) | 993 | else if (0 != unlink(fn)) |
999 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 994 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING | |
1000 | GNUNET_ERROR_TYPE_BULK, | 995 | GNUNET_ERROR_TYPE_BULK, |
1001 | "unlink", | 996 | "unlink", |
1002 | fn); | 997 | fn); |
1003 | 998 | ||
1004 | GNUNET_free (writebuffer); | 999 | GNUNET_free(writebuffer); |
1005 | return GNUNET_OK; | 1000 | return GNUNET_OK; |
1006 | } | 1001 | } |
1007 | 1002 | ||
@@ -1013,20 +1008,20 @@ discard_hosts_helper (void *cls, const char *fn) | |||
1013 | * @param cls unused | 1008 | * @param cls unused |
1014 | */ | 1009 | */ |
1015 | static void | 1010 | static void |
1016 | cron_clean_data_hosts (void *cls) | 1011 | cron_clean_data_hosts(void *cls) |
1017 | { | 1012 | { |
1018 | struct GNUNET_TIME_Absolute now; | 1013 | struct GNUNET_TIME_Absolute now; |
1019 | 1014 | ||
1020 | (void) cls; | 1015 | (void)cls; |
1021 | cron_clean = NULL; | 1016 | cron_clean = NULL; |
1022 | now = GNUNET_TIME_absolute_get (); | 1017 | now = GNUNET_TIME_absolute_get(); |
1023 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 1018 | GNUNET_log(GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
1024 | _ ("Cleaning up directory `%s'\n"), | 1019 | _("Cleaning up directory `%s'\n"), |
1025 | networkIdDirectory); | 1020 | networkIdDirectory); |
1026 | GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); | 1021 | GNUNET_DISK_directory_scan(networkIdDirectory, &discard_hosts_helper, &now); |
1027 | cron_clean = GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, | 1022 | cron_clean = GNUNET_SCHEDULER_add_delayed(DATA_HOST_CLEAN_FREQ, |
1028 | &cron_clean_data_hosts, | 1023 | &cron_clean_data_hosts, |
1029 | NULL); | 1024 | NULL); |
1030 | } | 1025 | } |
1031 | 1026 | ||
1032 | 1027 | ||
@@ -1038,16 +1033,16 @@ cron_clean_data_hosts (void *cls) | |||
1038 | * @return #GNUNET_OK if @a hello is well-formed | 1033 | * @return #GNUNET_OK if @a hello is well-formed |
1039 | */ | 1034 | */ |
1040 | static int | 1035 | static int |
1041 | check_hello (void *cls, const struct GNUNET_HELLO_Message *hello) | 1036 | check_hello(void *cls, const struct GNUNET_HELLO_Message *hello) |
1042 | { | 1037 | { |
1043 | struct GNUNET_PeerIdentity pid; | 1038 | struct GNUNET_PeerIdentity pid; |
1044 | 1039 | ||
1045 | (void) cls; | 1040 | (void)cls; |
1046 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) | 1041 | if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid)) |
1047 | { | 1042 | { |
1048 | GNUNET_break (0); | 1043 | GNUNET_break(0); |
1049 | return GNUNET_SYSERR; | 1044 | return GNUNET_SYSERR; |
1050 | } | 1045 | } |
1051 | return GNUNET_OK; | 1046 | return GNUNET_OK; |
1052 | } | 1047 | } |
1053 | 1048 | ||
@@ -1059,18 +1054,18 @@ check_hello (void *cls, const struct GNUNET_HELLO_Message *hello) | |||
1059 | * @param hello the actual message | 1054 | * @param hello the actual message |
1060 | */ | 1055 | */ |
1061 | static void | 1056 | static void |
1062 | handle_hello (void *cls, const struct GNUNET_HELLO_Message *hello) | 1057 | handle_hello(void *cls, const struct GNUNET_HELLO_Message *hello) |
1063 | { | 1058 | { |
1064 | struct GNUNET_SERVICE_Client *client = cls; | 1059 | struct GNUNET_SERVICE_Client *client = cls; |
1065 | struct GNUNET_PeerIdentity pid; | 1060 | struct GNUNET_PeerIdentity pid; |
1066 | 1061 | ||
1067 | GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &pid)); | 1062 | GNUNET_assert(GNUNET_OK == GNUNET_HELLO_get_id(hello, &pid)); |
1068 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1063 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1069 | "HELLO message received for peer `%s'\n", | 1064 | "HELLO message received for peer `%s'\n", |
1070 | GNUNET_i2s (&pid)); | 1065 | GNUNET_i2s(&pid)); |
1071 | add_host_to_known_hosts (&pid); | 1066 | add_host_to_known_hosts(&pid); |
1072 | update_hello (&pid, hello); | 1067 | update_hello(&pid, hello); |
1073 | GNUNET_SERVICE_client_continue (client); | 1068 | GNUNET_SERVICE_client_continue(client); |
1074 | } | 1069 | } |
1075 | 1070 | ||
1076 | 1071 | ||
@@ -1081,25 +1076,25 @@ handle_hello (void *cls, const struct GNUNET_HELLO_Message *hello) | |||
1081 | * @param lpm the actual message | 1076 | * @param lpm the actual message |
1082 | */ | 1077 | */ |
1083 | static void | 1078 | static void |
1084 | handle_get (void *cls, const struct ListPeerMessage *lpm) | 1079 | handle_get(void *cls, const struct ListPeerMessage *lpm) |
1085 | { | 1080 | { |
1086 | struct GNUNET_SERVICE_Client *client = cls; | 1081 | struct GNUNET_SERVICE_Client *client = cls; |
1087 | struct TransmitContext tcx; | 1082 | struct TransmitContext tcx; |
1088 | struct GNUNET_MessageHeader *msg; | 1083 | struct GNUNET_MessageHeader *msg; |
1089 | struct GNUNET_MQ_Envelope *env; | 1084 | struct GNUNET_MQ_Envelope *env; |
1090 | 1085 | ||
1091 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1086 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1092 | "GET message received for peer `%s'\n", | 1087 | "GET message received for peer `%s'\n", |
1093 | GNUNET_i2s (&lpm->peer)); | 1088 | GNUNET_i2s(&lpm->peer)); |
1094 | tcx.friend_only = ntohl (lpm->include_friend_only); | 1089 | tcx.friend_only = ntohl(lpm->include_friend_only); |
1095 | tcx.client = client; | 1090 | tcx.client = client; |
1096 | GNUNET_CONTAINER_multipeermap_get_multiple (hostmap, | 1091 | GNUNET_CONTAINER_multipeermap_get_multiple(hostmap, |
1097 | &lpm->peer, | 1092 | &lpm->peer, |
1098 | &add_to_tc, | 1093 | &add_to_tc, |
1099 | &tcx); | 1094 | &tcx); |
1100 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 1095 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
1101 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 1096 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
1102 | GNUNET_SERVICE_client_continue (client); | 1097 | GNUNET_SERVICE_client_continue(client); |
1103 | } | 1098 | } |
1104 | 1099 | ||
1105 | 1100 | ||
@@ -1110,20 +1105,20 @@ handle_get (void *cls, const struct ListPeerMessage *lpm) | |||
1110 | * @param lapm the actual message | 1105 | * @param lapm the actual message |
1111 | */ | 1106 | */ |
1112 | static void | 1107 | static void |
1113 | handle_get_all (void *cls, const struct ListAllPeersMessage *lapm) | 1108 | handle_get_all(void *cls, const struct ListAllPeersMessage *lapm) |
1114 | { | 1109 | { |
1115 | struct GNUNET_SERVICE_Client *client = cls; | 1110 | struct GNUNET_SERVICE_Client *client = cls; |
1116 | struct TransmitContext tcx; | 1111 | struct TransmitContext tcx; |
1117 | struct GNUNET_MQ_Envelope *env; | 1112 | struct GNUNET_MQ_Envelope *env; |
1118 | struct GNUNET_MessageHeader *msg; | 1113 | struct GNUNET_MessageHeader *msg; |
1119 | 1114 | ||
1120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET_ALL message received\n"); | 1115 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "GET_ALL message received\n"); |
1121 | tcx.friend_only = ntohl (lapm->include_friend_only); | 1116 | tcx.friend_only = ntohl(lapm->include_friend_only); |
1122 | tcx.client = client; | 1117 | tcx.client = client; |
1123 | GNUNET_CONTAINER_multipeermap_iterate (hostmap, &add_to_tc, &tcx); | 1118 | GNUNET_CONTAINER_multipeermap_iterate(hostmap, &add_to_tc, &tcx); |
1124 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 1119 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
1125 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 1120 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
1126 | GNUNET_SERVICE_client_continue (client); | 1121 | GNUNET_SERVICE_client_continue(client); |
1127 | } | 1122 | } |
1128 | 1123 | ||
1129 | 1124 | ||
@@ -1134,7 +1129,7 @@ handle_get_all (void *cls, const struct ListAllPeersMessage *lapm) | |||
1134 | * @param nm the actual message | 1129 | * @param nm the actual message |
1135 | */ | 1130 | */ |
1136 | static void | 1131 | static void |
1137 | handle_notify (void *cls, const struct NotifyMessage *nm) | 1132 | handle_notify(void *cls, const struct NotifyMessage *nm) |
1138 | { | 1133 | { |
1139 | struct GNUNET_SERVICE_Client *client = cls; | 1134 | struct GNUNET_SERVICE_Client *client = cls; |
1140 | struct GNUNET_MQ_Handle *mq; | 1135 | struct GNUNET_MQ_Handle *mq; |
@@ -1142,19 +1137,19 @@ handle_notify (void *cls, const struct NotifyMessage *nm) | |||
1142 | struct GNUNET_MQ_Envelope *env; | 1137 | struct GNUNET_MQ_Envelope *env; |
1143 | struct GNUNET_MessageHeader *msg; | 1138 | struct GNUNET_MessageHeader *msg; |
1144 | 1139 | ||
1145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "NOTIFY message received\n"); | 1140 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "NOTIFY message received\n"); |
1146 | mq = GNUNET_SERVICE_client_get_mq (client); | 1141 | mq = GNUNET_SERVICE_client_get_mq(client); |
1147 | GNUNET_SERVICE_client_mark_monitor (client); | 1142 | GNUNET_SERVICE_client_mark_monitor(client); |
1148 | if (ntohl (nm->include_friend_only)) | 1143 | if (ntohl(nm->include_friend_only)) |
1149 | GNUNET_notification_context_add (notify_friend_only_list, mq); | 1144 | GNUNET_notification_context_add(notify_friend_only_list, mq); |
1150 | else | 1145 | else |
1151 | GNUNET_notification_context_add (notify_list, mq); | 1146 | GNUNET_notification_context_add(notify_list, mq); |
1152 | tcx.friend_only = ntohl (nm->include_friend_only); | 1147 | tcx.friend_only = ntohl(nm->include_friend_only); |
1153 | tcx.client = client; | 1148 | tcx.client = client; |
1154 | GNUNET_CONTAINER_multipeermap_iterate (hostmap, &add_to_tc, &tcx); | 1149 | GNUNET_CONTAINER_multipeermap_iterate(hostmap, &add_to_tc, &tcx); |
1155 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 1150 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
1156 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 1151 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
1157 | GNUNET_SERVICE_client_continue (client); | 1152 | GNUNET_SERVICE_client_continue(client); |
1158 | } | 1153 | } |
1159 | 1154 | ||
1160 | 1155 | ||
@@ -1167,12 +1162,12 @@ handle_notify (void *cls, const struct NotifyMessage *nm) | |||
1167 | * @return @a client | 1162 | * @return @a client |
1168 | */ | 1163 | */ |
1169 | static void * | 1164 | static void * |
1170 | client_connect_cb (void *cls, | 1165 | client_connect_cb(void *cls, |
1171 | struct GNUNET_SERVICE_Client *client, | 1166 | struct GNUNET_SERVICE_Client *client, |
1172 | struct GNUNET_MQ_Handle *mq) | 1167 | struct GNUNET_MQ_Handle *mq) |
1173 | { | 1168 | { |
1174 | (void) cls; | 1169 | (void)cls; |
1175 | (void) mq; | 1170 | (void)mq; |
1176 | return client; | 1171 | return client; |
1177 | } | 1172 | } |
1178 | 1173 | ||
@@ -1185,12 +1180,12 @@ client_connect_cb (void *cls, | |||
1185 | * @param app_ctx should be @a client | 1180 | * @param app_ctx should be @a client |
1186 | */ | 1181 | */ |
1187 | static void | 1182 | static void |
1188 | client_disconnect_cb (void *cls, | 1183 | client_disconnect_cb(void *cls, |
1189 | struct GNUNET_SERVICE_Client *client, | 1184 | struct GNUNET_SERVICE_Client *client, |
1190 | void *app_ctx) | 1185 | void *app_ctx) |
1191 | { | 1186 | { |
1192 | (void) cls; | 1187 | (void)cls; |
1193 | GNUNET_assert (app_ctx == client); | 1188 | GNUNET_assert(app_ctx == client); |
1194 | } | 1189 | } |
1195 | 1190 | ||
1196 | 1191 | ||
@@ -1203,15 +1198,15 @@ client_disconnect_cb (void *cls, | |||
1203 | * @return #GNUNET_YES (continue to iterate) | 1198 | * @return #GNUNET_YES (continue to iterate) |
1204 | */ | 1199 | */ |
1205 | static int | 1200 | static int |
1206 | free_host_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 1201 | free_host_entry(void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
1207 | { | 1202 | { |
1208 | struct HostEntry *he = value; | 1203 | struct HostEntry *he = value; |
1209 | 1204 | ||
1210 | (void) cls; | 1205 | (void)cls; |
1211 | (void) key; | 1206 | (void)key; |
1212 | GNUNET_free_non_null (he->hello); | 1207 | GNUNET_free_non_null(he->hello); |
1213 | GNUNET_free_non_null (he->friend_only_hello); | 1208 | GNUNET_free_non_null(he->friend_only_hello); |
1214 | GNUNET_free (he); | 1209 | GNUNET_free(he); |
1215 | return GNUNET_YES; | 1210 | return GNUNET_YES; |
1216 | } | 1211 | } |
1217 | 1212 | ||
@@ -1222,36 +1217,36 @@ free_host_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
1222 | * @param cls unused | 1217 | * @param cls unused |
1223 | */ | 1218 | */ |
1224 | static void | 1219 | static void |
1225 | shutdown_task (void *cls) | 1220 | shutdown_task(void *cls) |
1226 | { | 1221 | { |
1227 | (void) cls; | 1222 | (void)cls; |
1228 | GNUNET_notification_context_destroy (notify_list); | 1223 | GNUNET_notification_context_destroy(notify_list); |
1229 | notify_list = NULL; | 1224 | notify_list = NULL; |
1230 | GNUNET_notification_context_destroy (notify_friend_only_list); | 1225 | GNUNET_notification_context_destroy(notify_friend_only_list); |
1231 | notify_friend_only_list = NULL; | 1226 | notify_friend_only_list = NULL; |
1232 | 1227 | ||
1233 | GNUNET_CONTAINER_multipeermap_iterate (hostmap, &free_host_entry, NULL); | 1228 | GNUNET_CONTAINER_multipeermap_iterate(hostmap, &free_host_entry, NULL); |
1234 | GNUNET_CONTAINER_multipeermap_destroy (hostmap); | 1229 | GNUNET_CONTAINER_multipeermap_destroy(hostmap); |
1235 | if (NULL != stats) | 1230 | if (NULL != stats) |
1236 | { | 1231 | { |
1237 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 1232 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); |
1238 | stats = NULL; | 1233 | stats = NULL; |
1239 | } | 1234 | } |
1240 | if (NULL != cron_clean) | 1235 | if (NULL != cron_clean) |
1241 | { | 1236 | { |
1242 | GNUNET_SCHEDULER_cancel (cron_clean); | 1237 | GNUNET_SCHEDULER_cancel(cron_clean); |
1243 | cron_clean = NULL; | 1238 | cron_clean = NULL; |
1244 | } | 1239 | } |
1245 | if (NULL != cron_scan) | 1240 | if (NULL != cron_scan) |
1246 | { | 1241 | { |
1247 | GNUNET_SCHEDULER_cancel (cron_scan); | 1242 | GNUNET_SCHEDULER_cancel(cron_scan); |
1248 | cron_scan = NULL; | 1243 | cron_scan = NULL; |
1249 | } | 1244 | } |
1250 | if (NULL != networkIdDirectory) | 1245 | if (NULL != networkIdDirectory) |
1251 | { | 1246 | { |
1252 | GNUNET_free (networkIdDirectory); | 1247 | GNUNET_free(networkIdDirectory); |
1253 | networkIdDirectory = NULL; | 1248 | networkIdDirectory = NULL; |
1254 | } | 1249 | } |
1255 | } | 1250 | } |
1256 | 1251 | ||
1257 | 1252 | ||
@@ -1263,9 +1258,9 @@ shutdown_task (void *cls) | |||
1263 | * @param service the initialized service | 1258 | * @param service the initialized service |
1264 | */ | 1259 | */ |
1265 | static void | 1260 | static void |
1266 | run (void *cls, | 1261 | run(void *cls, |
1267 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1262 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1268 | struct GNUNET_SERVICE_Handle *service) | 1263 | struct GNUNET_SERVICE_Handle *service) |
1269 | { | 1264 | { |
1270 | char *peerdir; | 1265 | char *peerdir; |
1271 | char *ip; | 1266 | char *ip; |
@@ -1273,95 +1268,95 @@ run (void *cls, | |||
1273 | int noio; | 1268 | int noio; |
1274 | int use_included; | 1269 | int use_included; |
1275 | 1270 | ||
1276 | (void) cls; | 1271 | (void)cls; |
1277 | (void) service; | 1272 | (void)service; |
1278 | hostmap = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); | 1273 | hostmap = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); |
1279 | stats = GNUNET_STATISTICS_create ("peerinfo", cfg); | 1274 | stats = GNUNET_STATISTICS_create("peerinfo", cfg); |
1280 | notify_list = GNUNET_notification_context_create (0); | 1275 | notify_list = GNUNET_notification_context_create(0); |
1281 | notify_friend_only_list = GNUNET_notification_context_create (0); | 1276 | notify_friend_only_list = GNUNET_notification_context_create(0); |
1282 | noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO"); | 1277 | noio = GNUNET_CONFIGURATION_get_value_yesno(cfg, "peerinfo", "NO_IO"); |
1283 | use_included = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1278 | use_included = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
1284 | "peerinfo", | 1279 | "peerinfo", |
1285 | "USE_INCLUDED_HELLOS"); | 1280 | "USE_INCLUDED_HELLOS"); |
1286 | if (GNUNET_SYSERR == use_included) | 1281 | if (GNUNET_SYSERR == use_included) |
1287 | use_included = GNUNET_NO; | 1282 | use_included = GNUNET_NO; |
1288 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1283 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
1289 | if (GNUNET_YES != noio) | 1284 | if (GNUNET_YES != noio) |
1290 | { | ||
1291 | GNUNET_assert ( | ||
1292 | GNUNET_OK == | ||
1293 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
1294 | "peerinfo", | ||
1295 | "HOSTS", | ||
1296 | &networkIdDirectory)); | ||
1297 | if (GNUNET_OK != GNUNET_DISK_directory_create (networkIdDirectory)) | ||
1298 | { | 1285 | { |
1299 | GNUNET_SCHEDULER_shutdown (); | 1286 | GNUNET_assert( |
1300 | return; | 1287 | GNUNET_OK == |
1301 | } | 1288 | GNUNET_CONFIGURATION_get_value_filename(cfg, |
1302 | 1289 | "peerinfo", | |
1303 | cron_scan = | 1290 | "HOSTS", |
1304 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1291 | &networkIdDirectory)); |
1305 | &cron_scan_directory_data_hosts, | 1292 | if (GNUNET_OK != GNUNET_DISK_directory_create(networkIdDirectory)) |
1306 | NULL); | 1293 | { |
1307 | 1294 | GNUNET_SCHEDULER_shutdown(); | |
1308 | cron_clean = | 1295 | return; |
1309 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1296 | } |
1310 | &cron_clean_data_hosts, | 1297 | |
1311 | NULL); | 1298 | cron_scan = |
1312 | if (GNUNET_YES == use_included) | 1299 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, |
1313 | { | 1300 | &cron_scan_directory_data_hosts, |
1314 | ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | 1301 | NULL); |
1315 | GNUNET_asprintf (&peerdir, "%shellos", ip); | 1302 | |
1316 | GNUNET_free (ip); | 1303 | cron_clean = |
1317 | 1304 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, | |
1318 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1305 | &cron_clean_data_hosts, |
1319 | _ ("Importing HELLOs from `%s'\n"), | 1306 | NULL); |
1320 | peerdir); | 1307 | if (GNUNET_YES == use_included) |
1321 | dsc.matched = 0; | 1308 | { |
1322 | dsc.remove_files = GNUNET_NO; | 1309 | ip = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); |
1323 | 1310 | GNUNET_asprintf(&peerdir, "%shellos", ip); | |
1324 | GNUNET_DISK_directory_scan (peerdir, | 1311 | GNUNET_free(ip); |
1325 | &hosts_directory_scan_callback, | 1312 | |
1326 | &dsc); | 1313 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1327 | GNUNET_free (peerdir); | 1314 | _("Importing HELLOs from `%s'\n"), |
1328 | } | 1315 | peerdir); |
1329 | else | 1316 | dsc.matched = 0; |
1330 | { | 1317 | dsc.remove_files = GNUNET_NO; |
1331 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1318 | |
1332 | _ ("Skipping import of included HELLOs\n")); | 1319 | GNUNET_DISK_directory_scan(peerdir, |
1320 | &hosts_directory_scan_callback, | ||
1321 | &dsc); | ||
1322 | GNUNET_free(peerdir); | ||
1323 | } | ||
1324 | else | ||
1325 | { | ||
1326 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1327 | _("Skipping import of included HELLOs\n")); | ||
1328 | } | ||
1333 | } | 1329 | } |
1334 | } | ||
1335 | } | 1330 | } |
1336 | 1331 | ||
1337 | 1332 | ||
1338 | /** | 1333 | /** |
1339 | * Define "main" method using service macro. | 1334 | * Define "main" method using service macro. |
1340 | */ | 1335 | */ |
1341 | GNUNET_SERVICE_MAIN ( | 1336 | GNUNET_SERVICE_MAIN( |
1342 | "peerinfo", | 1337 | "peerinfo", |
1343 | GNUNET_SERVICE_OPTION_NONE, | 1338 | GNUNET_SERVICE_OPTION_NONE, |
1344 | &run, | 1339 | &run, |
1345 | &client_connect_cb, | 1340 | &client_connect_cb, |
1346 | &client_disconnect_cb, | 1341 | &client_disconnect_cb, |
1347 | NULL, | 1342 | NULL, |
1348 | GNUNET_MQ_hd_var_size (hello, | 1343 | GNUNET_MQ_hd_var_size(hello, |
1349 | GNUNET_MESSAGE_TYPE_HELLO, | 1344 | GNUNET_MESSAGE_TYPE_HELLO, |
1350 | struct GNUNET_HELLO_Message, | 1345 | struct GNUNET_HELLO_Message, |
1351 | NULL), | 1346 | NULL), |
1352 | GNUNET_MQ_hd_fixed_size (get, | 1347 | GNUNET_MQ_hd_fixed_size(get, |
1353 | GNUNET_MESSAGE_TYPE_PEERINFO_GET, | 1348 | GNUNET_MESSAGE_TYPE_PEERINFO_GET, |
1354 | struct ListPeerMessage, | 1349 | struct ListPeerMessage, |
1355 | NULL), | 1350 | NULL), |
1356 | GNUNET_MQ_hd_fixed_size (get_all, | 1351 | GNUNET_MQ_hd_fixed_size(get_all, |
1357 | GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, | 1352 | GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, |
1358 | struct ListAllPeersMessage, | 1353 | struct ListAllPeersMessage, |
1359 | NULL), | 1354 | NULL), |
1360 | GNUNET_MQ_hd_fixed_size (notify, | 1355 | GNUNET_MQ_hd_fixed_size(notify, |
1361 | GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, | 1356 | GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, |
1362 | struct NotifyMessage, | 1357 | struct NotifyMessage, |
1363 | NULL), | 1358 | NULL), |
1364 | GNUNET_MQ_handler_end ()); | 1359 | GNUNET_MQ_handler_end()); |
1365 | 1360 | ||
1366 | 1361 | ||
1367 | /* end of gnunet-service-peerinfo.c */ | 1362 | /* end of gnunet-service-peerinfo.c */ |
diff --git a/src/peerinfo/peerinfo.h b/src/peerinfo/peerinfo.h index ea1c6598c..85501593e 100644 --- a/src/peerinfo/peerinfo.h +++ b/src/peerinfo/peerinfo.h | |||
@@ -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 peerinfo/peerinfo.h | 22 | * @file peerinfo/peerinfo.h |
@@ -39,9 +39,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
39 | * Message requesting a listing of peers, | 39 | * Message requesting a listing of peers, |
40 | * restricted to the specified peer identity. | 40 | * restricted to the specified peer identity. |
41 | */ | 41 | */ |
42 | struct ListPeerMessage | 42 | struct ListPeerMessage { |
43 | { | ||
44 | |||
45 | /** | 43 | /** |
46 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET | 44 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET |
47 | */ | 45 | */ |
@@ -57,15 +55,13 @@ struct ListPeerMessage | |||
57 | * field, check header.size!). | 55 | * field, check header.size!). |
58 | */ | 56 | */ |
59 | struct GNUNET_PeerIdentity peer; | 57 | struct GNUNET_PeerIdentity peer; |
60 | |||
61 | }; | 58 | }; |
62 | 59 | ||
63 | /** | 60 | /** |
64 | * Message requesting a listing of all peers, | 61 | * Message requesting a listing of all peers, |
65 | * restricted to the specified peer identity. | 62 | * restricted to the specified peer identity. |
66 | */ | 63 | */ |
67 | struct ListAllPeersMessage | 64 | struct ListAllPeersMessage { |
68 | { | ||
69 | /** | 65 | /** |
70 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL | 66 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL |
71 | */ | 67 | */ |
@@ -75,15 +71,13 @@ struct ListAllPeersMessage | |||
75 | * Include friend only HELLOs and peers in callbacks | 71 | * Include friend only HELLOs and peers in callbacks |
76 | */ | 72 | */ |
77 | uint32_t include_friend_only GNUNET_PACKED; | 73 | uint32_t include_friend_only GNUNET_PACKED; |
78 | |||
79 | }; | 74 | }; |
80 | 75 | ||
81 | 76 | ||
82 | /** | 77 | /** |
83 | * Header for all communications. | 78 | * Header for all communications. |
84 | */ | 79 | */ |
85 | struct NotifyMessage | 80 | struct NotifyMessage { |
86 | { | ||
87 | /** | 81 | /** |
88 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY | 82 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY |
89 | */ | 83 | */ |
@@ -93,7 +87,6 @@ struct NotifyMessage | |||
93 | * Include friend only HELLOs and peers in callbacks | 87 | * Include friend only HELLOs and peers in callbacks |
94 | */ | 88 | */ |
95 | uint32_t include_friend_only GNUNET_PACKED; | 89 | uint32_t include_friend_only GNUNET_PACKED; |
96 | |||
97 | }; | 90 | }; |
98 | 91 | ||
99 | 92 | ||
@@ -104,9 +97,7 @@ struct NotifyMessage | |||
104 | * Check the header.size field to see if a HELLO is | 97 | * Check the header.size field to see if a HELLO is |
105 | * present. | 98 | * present. |
106 | */ | 99 | */ |
107 | struct InfoMessage | 100 | struct InfoMessage { |
108 | { | ||
109 | |||
110 | /** | 101 | /** |
111 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_INFO | 102 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_INFO |
112 | */ | 103 | */ |
@@ -121,7 +112,6 @@ struct InfoMessage | |||
121 | * About which peer are we talking here? | 112 | * About which peer are we talking here? |
122 | */ | 113 | */ |
123 | struct GNUNET_PeerIdentity peer; | 114 | struct GNUNET_PeerIdentity peer; |
124 | |||
125 | }; | 115 | }; |
126 | GNUNET_NETWORK_STRUCT_END | 116 | GNUNET_NETWORK_STRUCT_END |
127 | 117 | ||
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index 485b5e183..ada6f5462 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.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 peerinfo/peerinfo_api.c | 22 | * @file peerinfo/peerinfo_api.c |
@@ -28,15 +28,13 @@ | |||
28 | #include "gnunet_protocols.h" | 28 | #include "gnunet_protocols.h" |
29 | #include "peerinfo.h" | 29 | #include "peerinfo.h" |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "peerinfo-api",__VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "peerinfo-api", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Context for an iteration request. | 35 | * Context for an iteration request. |
36 | */ | 36 | */ |
37 | struct GNUNET_PEERINFO_IteratorContext | 37 | struct GNUNET_PEERINFO_IteratorContext { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Kept in a DLL. | 39 | * Kept in a DLL. |
42 | */ | 40 | */ |
@@ -76,15 +74,13 @@ struct GNUNET_PEERINFO_IteratorContext | |||
76 | * Only include friends in reply? | 74 | * Only include friends in reply? |
77 | */ | 75 | */ |
78 | int include_friend_only; | 76 | int include_friend_only; |
79 | |||
80 | }; | 77 | }; |
81 | 78 | ||
82 | 79 | ||
83 | /** | 80 | /** |
84 | * Handle to the peerinfo service. | 81 | * Handle to the peerinfo service. |
85 | */ | 82 | */ |
86 | struct GNUNET_PEERINFO_Handle | 83 | struct GNUNET_PEERINFO_Handle { |
87 | { | ||
88 | /** | 84 | /** |
89 | * Our configuration. | 85 | * Our configuration. |
90 | */ | 86 | */ |
@@ -109,7 +105,6 @@ struct GNUNET_PEERINFO_Handle | |||
109 | * ID for a reconnect task. | 105 | * ID for a reconnect task. |
110 | */ | 106 | */ |
111 | struct GNUNET_SCHEDULER_Task *r_task; | 107 | struct GNUNET_SCHEDULER_Task *r_task; |
112 | |||
113 | }; | 108 | }; |
114 | 109 | ||
115 | 110 | ||
@@ -119,7 +114,7 @@ struct GNUNET_PEERINFO_Handle | |||
119 | * @param h handle to the service | 114 | * @param h handle to the service |
120 | */ | 115 | */ |
121 | static void | 116 | static void |
122 | reconnect (struct GNUNET_PEERINFO_Handle *h); | 117 | reconnect(struct GNUNET_PEERINFO_Handle *h); |
123 | 118 | ||
124 | 119 | ||
125 | /** | 120 | /** |
@@ -130,18 +125,18 @@ reconnect (struct GNUNET_PEERINFO_Handle *h); | |||
130 | * establishment may happen asynchronously). | 125 | * establishment may happen asynchronously). |
131 | */ | 126 | */ |
132 | struct GNUNET_PEERINFO_Handle * | 127 | struct GNUNET_PEERINFO_Handle * |
133 | GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 128 | GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) |
134 | { | 129 | { |
135 | struct GNUNET_PEERINFO_Handle *h; | 130 | struct GNUNET_PEERINFO_Handle *h; |
136 | 131 | ||
137 | h = GNUNET_new (struct GNUNET_PEERINFO_Handle); | 132 | h = GNUNET_new(struct GNUNET_PEERINFO_Handle); |
138 | h->cfg = cfg; | 133 | h->cfg = cfg; |
139 | reconnect (h); | 134 | reconnect(h); |
140 | if (NULL == h->mq) | 135 | if (NULL == h->mq) |
141 | { | 136 | { |
142 | GNUNET_free (h); | 137 | GNUNET_free(h); |
143 | return NULL; | 138 | return NULL; |
144 | } | 139 | } |
145 | return h; | 140 | return h; |
146 | } | 141 | } |
147 | 142 | ||
@@ -156,28 +151,28 @@ GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
156 | * @param h handle to disconnect | 151 | * @param h handle to disconnect |
157 | */ | 152 | */ |
158 | void | 153 | void |
159 | GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h) | 154 | GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h) |
160 | { | 155 | { |
161 | struct GNUNET_PEERINFO_IteratorContext *ic; | 156 | struct GNUNET_PEERINFO_IteratorContext *ic; |
162 | 157 | ||
163 | while (NULL != (ic = h->ic_head)) | 158 | while (NULL != (ic = h->ic_head)) |
164 | { | 159 | { |
165 | GNUNET_CONTAINER_DLL_remove (h->ic_head, | 160 | GNUNET_CONTAINER_DLL_remove(h->ic_head, |
166 | h->ic_tail, | 161 | h->ic_tail, |
167 | ic); | 162 | ic); |
168 | GNUNET_free (ic); | 163 | GNUNET_free(ic); |
169 | } | 164 | } |
170 | if (NULL != h->mq) | 165 | if (NULL != h->mq) |
171 | { | 166 | { |
172 | GNUNET_MQ_destroy (h->mq); | 167 | GNUNET_MQ_destroy(h->mq); |
173 | h->mq = NULL; | 168 | h->mq = NULL; |
174 | } | 169 | } |
175 | if (NULL != h->r_task) | 170 | if (NULL != h->r_task) |
176 | { | 171 | { |
177 | GNUNET_SCHEDULER_cancel (h->r_task); | 172 | GNUNET_SCHEDULER_cancel(h->r_task); |
178 | h->r_task = NULL; | 173 | h->r_task = NULL; |
179 | } | 174 | } |
180 | GNUNET_free (h); | 175 | GNUNET_free(h); |
181 | } | 176 | } |
182 | 177 | ||
183 | 178 | ||
@@ -187,12 +182,12 @@ GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h) | |||
187 | * @param cls the `struct GNUNET_PEERINFO_Handle *` | 182 | * @param cls the `struct GNUNET_PEERINFO_Handle *` |
188 | */ | 183 | */ |
189 | static void | 184 | static void |
190 | reconnect_task (void *cls) | 185 | reconnect_task(void *cls) |
191 | { | 186 | { |
192 | struct GNUNET_PEERINFO_Handle *h = cls; | 187 | struct GNUNET_PEERINFO_Handle *h = cls; |
193 | 188 | ||
194 | h->r_task = NULL; | 189 | h->r_task = NULL; |
195 | reconnect (h); | 190 | reconnect(h); |
196 | } | 191 | } |
197 | 192 | ||
198 | 193 | ||
@@ -202,26 +197,26 @@ reconnect_task (void *cls) | |||
202 | * @param h handle to reconnect | 197 | * @param h handle to reconnect |
203 | */ | 198 | */ |
204 | static void | 199 | static void |
205 | do_reconnect (struct GNUNET_PEERINFO_Handle *h) | 200 | do_reconnect(struct GNUNET_PEERINFO_Handle *h) |
206 | { | 201 | { |
207 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 202 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
208 | 203 | ||
209 | GNUNET_MQ_destroy (h->mq); | 204 | GNUNET_MQ_destroy(h->mq); |
210 | h->mq = NULL; | 205 | h->mq = NULL; |
211 | if (NULL != ic) | 206 | if (NULL != ic) |
212 | { | 207 | { |
213 | GNUNET_CONTAINER_DLL_remove (h->ic_head, | 208 | GNUNET_CONTAINER_DLL_remove(h->ic_head, |
214 | h->ic_tail, | 209 | h->ic_tail, |
215 | ic); | 210 | ic); |
216 | if (NULL != ic->callback) | 211 | if (NULL != ic->callback) |
217 | ic->callback (ic->callback_cls, | 212 | ic->callback(ic->callback_cls, |
218 | NULL, | 213 | NULL, |
219 | NULL, | 214 | NULL, |
220 | _("Failed to receive response from `PEERINFO' service.")); | 215 | _("Failed to receive response from `PEERINFO' service.")); |
221 | GNUNET_free (ic); | 216 | GNUNET_free(ic); |
222 | } | 217 | } |
223 | h->r_task = GNUNET_SCHEDULER_add_now (&reconnect_task, | 218 | h->r_task = GNUNET_SCHEDULER_add_now(&reconnect_task, |
224 | h); | 219 | h); |
225 | } | 220 | } |
226 | 221 | ||
227 | 222 | ||
@@ -233,12 +228,12 @@ do_reconnect (struct GNUNET_PEERINFO_Handle *h) | |||
233 | * @param error error code | 228 | * @param error error code |
234 | */ | 229 | */ |
235 | static void | 230 | static void |
236 | mq_error_handler (void *cls, | 231 | mq_error_handler(void *cls, |
237 | enum GNUNET_MQ_Error error) | 232 | enum GNUNET_MQ_Error error) |
238 | { | 233 | { |
239 | struct GNUNET_PEERINFO_Handle *h = cls; | 234 | struct GNUNET_PEERINFO_Handle *h = cls; |
240 | 235 | ||
241 | do_reconnect (h); | 236 | do_reconnect(h); |
242 | } | 237 | } |
243 | 238 | ||
244 | 239 | ||
@@ -252,70 +247,70 @@ mq_error_handler (void *cls, | |||
252 | * @return #GNUNET_OK if the message is OK | 247 | * @return #GNUNET_OK if the message is OK |
253 | */ | 248 | */ |
254 | static int | 249 | static int |
255 | check_info (void *cls, | 250 | check_info(void *cls, |
256 | const struct InfoMessage *im) | 251 | const struct InfoMessage *im) |
257 | { | 252 | { |
258 | struct GNUNET_PEERINFO_Handle *h = cls; | 253 | struct GNUNET_PEERINFO_Handle *h = cls; |
259 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 254 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
260 | uint16_t ms = ntohs (im->header.size) - sizeof (*im); | 255 | uint16_t ms = ntohs(im->header.size) - sizeof(*im); |
261 | 256 | ||
262 | if (0 != ntohl (im->reserved)) | 257 | if (0 != ntohl(im->reserved)) |
263 | { | 258 | { |
264 | GNUNET_break (0); | 259 | GNUNET_break(0); |
265 | return GNUNET_SYSERR; | 260 | return GNUNET_SYSERR; |
266 | } | 261 | } |
267 | if (NULL == ic) | 262 | if (NULL == ic) |
268 | { | ||
269 | /* didn't expect a response, bad */ | ||
270 | GNUNET_break (0); | ||
271 | return GNUNET_SYSERR; | ||
272 | } | ||
273 | if ( (GNUNET_YES == ic->have_peer) && | ||
274 | (0 != GNUNET_memcmp (&ic->peer, | ||
275 | &im->peer)) ) | ||
276 | { | ||
277 | /* bogus message (from a different iteration call?); out of sequence! */ | ||
278 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
279 | "Received HELLO for peer `%s', expected peer `%s'\n", | ||
280 | GNUNET_i2s (&im->peer), | ||
281 | GNUNET_i2s (&ic->peer)); | ||
282 | GNUNET_break (0); | ||
283 | return GNUNET_SYSERR; | ||
284 | } | ||
285 | if (ms > sizeof (struct GNUNET_MessageHeader)) | ||
286 | { | ||
287 | const struct GNUNET_HELLO_Message *hello; | ||
288 | struct GNUNET_PeerIdentity id; | ||
289 | |||
290 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | ||
291 | if (ms != GNUNET_HELLO_size (hello)) | ||
292 | { | 263 | { |
293 | /* malformed message */ | 264 | /* didn't expect a response, bad */ |
294 | GNUNET_break (0); | 265 | GNUNET_break(0); |
295 | return GNUNET_SYSERR; | 266 | return GNUNET_SYSERR; |
296 | } | 267 | } |
297 | if (GNUNET_OK != | 268 | if ((GNUNET_YES == ic->have_peer) && |
298 | GNUNET_HELLO_get_id (hello, | 269 | (0 != GNUNET_memcmp(&ic->peer, |
299 | &id)) | 270 | &im->peer))) |
300 | { | 271 | { |
301 | /* malformed message */ | 272 | /* bogus message (from a different iteration call?); out of sequence! */ |
302 | GNUNET_break (0); | 273 | LOG(GNUNET_ERROR_TYPE_ERROR, |
274 | "Received HELLO for peer `%s', expected peer `%s'\n", | ||
275 | GNUNET_i2s(&im->peer), | ||
276 | GNUNET_i2s(&ic->peer)); | ||
277 | GNUNET_break(0); | ||
303 | return GNUNET_SYSERR; | 278 | return GNUNET_SYSERR; |
304 | } | 279 | } |
305 | if (0 != GNUNET_memcmp (&im->peer, | 280 | if (ms > sizeof(struct GNUNET_MessageHeader)) |
306 | &id)) | 281 | { |
282 | const struct GNUNET_HELLO_Message *hello; | ||
283 | struct GNUNET_PeerIdentity id; | ||
284 | |||
285 | hello = (const struct GNUNET_HELLO_Message *)&im[1]; | ||
286 | if (ms != GNUNET_HELLO_size(hello)) | ||
287 | { | ||
288 | /* malformed message */ | ||
289 | GNUNET_break(0); | ||
290 | return GNUNET_SYSERR; | ||
291 | } | ||
292 | if (GNUNET_OK != | ||
293 | GNUNET_HELLO_get_id(hello, | ||
294 | &id)) | ||
295 | { | ||
296 | /* malformed message */ | ||
297 | GNUNET_break(0); | ||
298 | return GNUNET_SYSERR; | ||
299 | } | ||
300 | if (0 != GNUNET_memcmp(&im->peer, | ||
301 | &id)) | ||
302 | { | ||
303 | /* malformed message */ | ||
304 | GNUNET_break(0); | ||
305 | return GNUNET_SYSERR; | ||
306 | } | ||
307 | } | ||
308 | else if (0 != ms) | ||
307 | { | 309 | { |
308 | /* malformed message */ | 310 | /* malformed message */ |
309 | GNUNET_break (0); | 311 | GNUNET_break(0); |
310 | return GNUNET_SYSERR; | 312 | return GNUNET_SYSERR; |
311 | } | 313 | } |
312 | } | ||
313 | else if (0 != ms) | ||
314 | { | ||
315 | /* malformed message */ | ||
316 | GNUNET_break (0); | ||
317 | return GNUNET_SYSERR; | ||
318 | } | ||
319 | return GNUNET_OK; | 314 | return GNUNET_OK; |
320 | } | 315 | } |
321 | 316 | ||
@@ -327,22 +322,22 @@ check_info (void *cls, | |||
327 | * @param im message received | 322 | * @param im message received |
328 | */ | 323 | */ |
329 | static void | 324 | static void |
330 | handle_info (void *cls, | 325 | handle_info(void *cls, |
331 | const struct InfoMessage *im) | 326 | const struct InfoMessage *im) |
332 | { | 327 | { |
333 | struct GNUNET_PEERINFO_Handle *h = cls; | 328 | struct GNUNET_PEERINFO_Handle *h = cls; |
334 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 329 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
335 | const struct GNUNET_HELLO_Message *hello = NULL; | 330 | const struct GNUNET_HELLO_Message *hello = NULL; |
336 | uint16_t ms; | 331 | uint16_t ms; |
337 | 332 | ||
338 | ms = ntohs (im->header.size); | 333 | ms = ntohs(im->header.size); |
339 | if (ms > sizeof (struct InfoMessage)) | 334 | if (ms > sizeof(struct InfoMessage)) |
340 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | 335 | hello = (const struct GNUNET_HELLO_Message *)&im[1]; |
341 | if (NULL != ic->callback) | 336 | if (NULL != ic->callback) |
342 | ic->callback (ic->callback_cls, | 337 | ic->callback(ic->callback_cls, |
343 | &im->peer, | 338 | &im->peer, |
344 | hello, | 339 | hello, |
345 | NULL); | 340 | NULL); |
346 | } | 341 | } |
347 | 342 | ||
348 | 343 | ||
@@ -352,7 +347,7 @@ handle_info (void *cls, | |||
352 | * @param h handle | 347 | * @param h handle |
353 | */ | 348 | */ |
354 | static void | 349 | static void |
355 | send_ic_request (struct GNUNET_PEERINFO_Handle *h) | 350 | send_ic_request(struct GNUNET_PEERINFO_Handle *h) |
356 | { | 351 | { |
357 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 352 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
358 | struct GNUNET_MQ_Envelope *env; | 353 | struct GNUNET_MQ_Envelope *env; |
@@ -360,35 +355,35 @@ send_ic_request (struct GNUNET_PEERINFO_Handle *h) | |||
360 | struct ListPeerMessage *lpm; | 355 | struct ListPeerMessage *lpm; |
361 | 356 | ||
362 | if (NULL == ic) | 357 | if (NULL == ic) |
363 | { | 358 | { |
364 | GNUNET_break (0); | 359 | GNUNET_break(0); |
365 | return; | 360 | return; |
366 | } | 361 | } |
367 | if (NULL == h->mq) | 362 | if (NULL == h->mq) |
368 | { | 363 | { |
369 | GNUNET_break (0); | 364 | GNUNET_break(0); |
370 | return; | 365 | return; |
371 | } | 366 | } |
372 | if (GNUNET_NO == ic->have_peer) | 367 | if (GNUNET_NO == ic->have_peer) |
373 | { | 368 | { |
374 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 369 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
375 | "Requesting list of peers from PEERINFO service\n"); | 370 | "Requesting list of peers from PEERINFO service\n"); |
376 | env = GNUNET_MQ_msg (lapm, | 371 | env = GNUNET_MQ_msg(lapm, |
377 | GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); | 372 | GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); |
378 | lapm->include_friend_only = htonl (ic->include_friend_only); | 373 | lapm->include_friend_only = htonl(ic->include_friend_only); |
379 | } | 374 | } |
380 | else | 375 | else |
381 | { | 376 | { |
382 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 377 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
383 | "Requesting information on peer `%s' from PEERINFO service\n", | 378 | "Requesting information on peer `%s' from PEERINFO service\n", |
384 | GNUNET_i2s (&ic->peer)); | 379 | GNUNET_i2s(&ic->peer)); |
385 | env = GNUNET_MQ_msg (lpm, | 380 | env = GNUNET_MQ_msg(lpm, |
386 | GNUNET_MESSAGE_TYPE_PEERINFO_GET); | 381 | GNUNET_MESSAGE_TYPE_PEERINFO_GET); |
387 | lpm->include_friend_only = htonl (ic->include_friend_only); | 382 | lpm->include_friend_only = htonl(ic->include_friend_only); |
388 | lpm->peer = ic->peer; | 383 | lpm->peer = ic->peer; |
389 | } | 384 | } |
390 | GNUNET_MQ_send (h->mq, | 385 | GNUNET_MQ_send(h->mq, |
391 | env); | 386 | env); |
392 | } | 387 | } |
393 | 388 | ||
394 | 389 | ||
@@ -402,32 +397,32 @@ send_ic_request (struct GNUNET_PEERINFO_Handle *h) | |||
402 | * @param msg message received, NULL on timeout or fatal error | 397 | * @param msg message received, NULL on timeout or fatal error |
403 | */ | 398 | */ |
404 | static void | 399 | static void |
405 | handle_end_iteration (void *cls, | 400 | handle_end_iteration(void *cls, |
406 | const struct GNUNET_MessageHeader *msg) | 401 | const struct GNUNET_MessageHeader *msg) |
407 | { | 402 | { |
408 | struct GNUNET_PEERINFO_Handle *h = cls; | 403 | struct GNUNET_PEERINFO_Handle *h = cls; |
409 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 404 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
410 | 405 | ||
411 | if (NULL == ic) | 406 | if (NULL == ic) |
412 | { | 407 | { |
413 | /* didn't expect a response, reconnect */ | 408 | /* didn't expect a response, reconnect */ |
414 | GNUNET_break (0); | 409 | GNUNET_break(0); |
415 | reconnect (h); | 410 | reconnect(h); |
416 | return; | 411 | return; |
417 | } | 412 | } |
418 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 413 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
419 | "Received end of list of peers from PEERINFO service\n"); | 414 | "Received end of list of peers from PEERINFO service\n"); |
420 | GNUNET_CONTAINER_DLL_remove (h->ic_head, | 415 | GNUNET_CONTAINER_DLL_remove(h->ic_head, |
421 | h->ic_tail, | 416 | h->ic_tail, |
422 | ic); | 417 | ic); |
423 | if (NULL != h->ic_head) | 418 | if (NULL != h->ic_head) |
424 | send_ic_request (h); | 419 | send_ic_request(h); |
425 | if (NULL != ic->callback) | 420 | if (NULL != ic->callback) |
426 | ic->callback (ic->callback_cls, | 421 | ic->callback(ic->callback_cls, |
427 | NULL, | 422 | NULL, |
428 | NULL, | 423 | NULL, |
429 | NULL); | 424 | NULL); |
430 | GNUNET_free (ic); | 425 | GNUNET_free(ic); |
431 | } | 426 | } |
432 | 427 | ||
433 | 428 | ||
@@ -437,37 +432,37 @@ handle_end_iteration (void *cls, | |||
437 | * @param h handle to the service | 432 | * @param h handle to the service |
438 | */ | 433 | */ |
439 | static void | 434 | static void |
440 | reconnect (struct GNUNET_PEERINFO_Handle *h) | 435 | reconnect(struct GNUNET_PEERINFO_Handle *h) |
441 | { | 436 | { |
442 | struct GNUNET_MQ_MessageHandler handlers[] = { | 437 | struct GNUNET_MQ_MessageHandler handlers[] = { |
443 | GNUNET_MQ_hd_var_size (info, | 438 | GNUNET_MQ_hd_var_size(info, |
444 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO, | 439 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO, |
445 | struct InfoMessage, | 440 | struct InfoMessage, |
446 | h), | 441 | h), |
447 | GNUNET_MQ_hd_fixed_size (end_iteration, | 442 | GNUNET_MQ_hd_fixed_size(end_iteration, |
448 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, | 443 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, |
449 | struct GNUNET_MessageHeader, | 444 | struct GNUNET_MessageHeader, |
450 | h), | 445 | h), |
451 | GNUNET_MQ_handler_end () | 446 | GNUNET_MQ_handler_end() |
452 | }; | 447 | }; |
453 | 448 | ||
454 | if (NULL != h->r_task) | 449 | if (NULL != h->r_task) |
455 | { | 450 | { |
456 | GNUNET_SCHEDULER_cancel (h->r_task); | 451 | GNUNET_SCHEDULER_cancel(h->r_task); |
457 | h->r_task = NULL; | 452 | h->r_task = NULL; |
458 | } | 453 | } |
459 | if (NULL != h->mq) | 454 | if (NULL != h->mq) |
460 | { | 455 | { |
461 | GNUNET_MQ_destroy (h->mq); | 456 | GNUNET_MQ_destroy(h->mq); |
462 | h->mq = NULL; | 457 | h->mq = NULL; |
463 | } | 458 | } |
464 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 459 | h->mq = GNUNET_CLIENT_connect(h->cfg, |
465 | "peerinfo", | 460 | "peerinfo", |
466 | handlers, | 461 | handlers, |
467 | &mq_error_handler, | 462 | &mq_error_handler, |
468 | h); | 463 | h); |
469 | if (NULL != h->ic_head) | 464 | if (NULL != h->ic_head) |
470 | send_ic_request (h); | 465 | send_ic_request(h); |
471 | } | 466 | } |
472 | 467 | ||
473 | 468 | ||
@@ -488,29 +483,29 @@ reconnect (struct GNUNET_PEERINFO_Handle *h) | |||
488 | * @return iterator context | 483 | * @return iterator context |
489 | */ | 484 | */ |
490 | struct GNUNET_PEERINFO_IteratorContext * | 485 | struct GNUNET_PEERINFO_IteratorContext * |
491 | GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | 486 | GNUNET_PEERINFO_iterate(struct GNUNET_PEERINFO_Handle *h, |
492 | int include_friend_only, | 487 | int include_friend_only, |
493 | const struct GNUNET_PeerIdentity *peer, | 488 | const struct GNUNET_PeerIdentity *peer, |
494 | GNUNET_PEERINFO_Processor callback, | 489 | GNUNET_PEERINFO_Processor callback, |
495 | void *callback_cls) | 490 | void *callback_cls) |
496 | { | 491 | { |
497 | struct GNUNET_PEERINFO_IteratorContext *ic; | 492 | struct GNUNET_PEERINFO_IteratorContext *ic; |
498 | 493 | ||
499 | ic = GNUNET_new (struct GNUNET_PEERINFO_IteratorContext); | 494 | ic = GNUNET_new(struct GNUNET_PEERINFO_IteratorContext); |
500 | ic->h = h; | 495 | ic->h = h; |
501 | ic->include_friend_only = include_friend_only; | 496 | ic->include_friend_only = include_friend_only; |
502 | ic->callback = callback; | 497 | ic->callback = callback; |
503 | ic->callback_cls = callback_cls; | 498 | ic->callback_cls = callback_cls; |
504 | if (NULL != peer) | 499 | if (NULL != peer) |
505 | { | 500 | { |
506 | ic->have_peer = GNUNET_YES; | 501 | ic->have_peer = GNUNET_YES; |
507 | ic->peer = *peer; | 502 | ic->peer = *peer; |
508 | } | 503 | } |
509 | GNUNET_CONTAINER_DLL_insert_tail (h->ic_head, | 504 | GNUNET_CONTAINER_DLL_insert_tail(h->ic_head, |
510 | h->ic_tail, | 505 | h->ic_tail, |
511 | ic); | 506 | ic); |
512 | if (h->ic_head == ic) | 507 | if (h->ic_head == ic) |
513 | send_ic_request (h); | 508 | send_ic_request(h); |
514 | return ic; | 509 | return ic; |
515 | } | 510 | } |
516 | 511 | ||
@@ -521,17 +516,17 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
521 | * @param ic context of the iterator to cancel | 516 | * @param ic context of the iterator to cancel |
522 | */ | 517 | */ |
523 | void | 518 | void |
524 | GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic) | 519 | GNUNET_PEERINFO_iterate_cancel(struct GNUNET_PEERINFO_IteratorContext *ic) |
525 | { | 520 | { |
526 | struct GNUNET_PEERINFO_Handle *h = ic->h; | 521 | struct GNUNET_PEERINFO_Handle *h = ic->h; |
527 | 522 | ||
528 | ic->callback = NULL; | 523 | ic->callback = NULL; |
529 | if (ic == h->ic_head) | 524 | if (ic == h->ic_head) |
530 | return; | 525 | return; |
531 | GNUNET_CONTAINER_DLL_remove (h->ic_head, | 526 | GNUNET_CONTAINER_DLL_remove(h->ic_head, |
532 | h->ic_tail, | 527 | h->ic_tail, |
533 | ic); | 528 | ic); |
534 | GNUNET_free (ic); | 529 | GNUNET_free(ic); |
535 | } | 530 | } |
536 | 531 | ||
537 | 532 | ||
@@ -554,29 +549,29 @@ GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic) | |||
554 | * calling @a cont must be prevented) | 549 | * calling @a cont must be prevented) |
555 | */ | 550 | */ |
556 | struct GNUNET_MQ_Envelope * | 551 | struct GNUNET_MQ_Envelope * |
557 | GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, | 552 | GNUNET_PEERINFO_add_peer(struct GNUNET_PEERINFO_Handle *h, |
558 | const struct GNUNET_HELLO_Message *hello, | 553 | const struct GNUNET_HELLO_Message *hello, |
559 | GNUNET_SCHEDULER_TaskCallback cont, | 554 | GNUNET_SCHEDULER_TaskCallback cont, |
560 | void *cont_cls) | 555 | void *cont_cls) |
561 | { | 556 | { |
562 | struct GNUNET_MQ_Envelope *env; | 557 | struct GNUNET_MQ_Envelope *env; |
563 | struct GNUNET_PeerIdentity peer; | 558 | struct GNUNET_PeerIdentity peer; |
564 | 559 | ||
565 | if (NULL == h->mq) | 560 | if (NULL == h->mq) |
566 | return NULL; | 561 | return NULL; |
567 | GNUNET_assert (GNUNET_OK == | 562 | GNUNET_assert(GNUNET_OK == |
568 | GNUNET_HELLO_get_id (hello, | 563 | GNUNET_HELLO_get_id(hello, |
569 | &peer)); | 564 | &peer)); |
570 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 565 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
571 | "Adding peer `%s' to PEERINFO database\n", | 566 | "Adding peer `%s' to PEERINFO database\n", |
572 | GNUNET_i2s (&peer)); | 567 | GNUNET_i2s(&peer)); |
573 | env = GNUNET_MQ_msg_copy ((const struct GNUNET_MessageHeader *) hello); | 568 | env = GNUNET_MQ_msg_copy((const struct GNUNET_MessageHeader *)hello); |
574 | if (NULL != cont) | 569 | if (NULL != cont) |
575 | GNUNET_MQ_notify_sent (env, | 570 | GNUNET_MQ_notify_sent(env, |
576 | cont, | 571 | cont, |
577 | cont_cls); | 572 | cont_cls); |
578 | GNUNET_MQ_send (h->mq, | 573 | GNUNET_MQ_send(h->mq, |
579 | env); | 574 | env); |
580 | return env; | 575 | return env; |
581 | } | 576 | } |
582 | 577 | ||
diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c index fc9b64858..130ce3a5d 100644 --- a/src/peerinfo/peerinfo_api_notify.c +++ b/src/peerinfo/peerinfo_api_notify.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 peerinfo/peerinfo_api_notify.c | 22 | * @file peerinfo/peerinfo_api_notify.c |
@@ -29,14 +29,12 @@ | |||
29 | #include "gnunet_protocols.h" | 29 | #include "gnunet_protocols.h" |
30 | #include "peerinfo.h" | 30 | #include "peerinfo.h" |
31 | 31 | ||
32 | #define LOG(kind,...) GNUNET_log_from (kind, "peerinfo-api",__VA_ARGS__) | 32 | #define LOG(kind, ...) GNUNET_log_from(kind, "peerinfo-api", __VA_ARGS__) |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Context for the info handler. | 35 | * Context for the info handler. |
36 | */ | 36 | */ |
37 | struct GNUNET_PEERINFO_NotifyContext | 37 | struct GNUNET_PEERINFO_NotifyContext { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Our connection to the PEERINFO service. | 39 | * Our connection to the PEERINFO service. |
42 | */ | 40 | */ |
@@ -75,7 +73,7 @@ struct GNUNET_PEERINFO_NotifyContext | |||
75 | * @param cls the `struct GNUNET_PEERINFO_NotifyContext *` | 73 | * @param cls the `struct GNUNET_PEERINFO_NotifyContext *` |
76 | */ | 74 | */ |
77 | static void | 75 | static void |
78 | reconnect (void *cls); | 76 | reconnect(void *cls); |
79 | 77 | ||
80 | 78 | ||
81 | /** | 79 | /** |
@@ -84,12 +82,12 @@ reconnect (void *cls); | |||
84 | * @param nc context to reconnect | 82 | * @param nc context to reconnect |
85 | */ | 83 | */ |
86 | static void | 84 | static void |
87 | do_reconnect (struct GNUNET_PEERINFO_NotifyContext *nc) | 85 | do_reconnect(struct GNUNET_PEERINFO_NotifyContext *nc) |
88 | { | 86 | { |
89 | GNUNET_MQ_destroy (nc->mq); | 87 | GNUNET_MQ_destroy(nc->mq); |
90 | nc->mq = NULL; | 88 | nc->mq = NULL; |
91 | nc->task = GNUNET_SCHEDULER_add_now (&reconnect, | 89 | nc->task = GNUNET_SCHEDULER_add_now(&reconnect, |
92 | nc); | 90 | nc); |
93 | } | 91 | } |
94 | 92 | ||
95 | 93 | ||
@@ -101,12 +99,12 @@ do_reconnect (struct GNUNET_PEERINFO_NotifyContext *nc) | |||
101 | * @param error error code | 99 | * @param error error code |
102 | */ | 100 | */ |
103 | static void | 101 | static void |
104 | mq_error_handler (void *cls, | 102 | mq_error_handler(void *cls, |
105 | enum GNUNET_MQ_Error error) | 103 | enum GNUNET_MQ_Error error) |
106 | { | 104 | { |
107 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | 105 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; |
108 | 106 | ||
109 | do_reconnect (nc); | 107 | do_reconnect(nc); |
110 | } | 108 | } |
111 | 109 | ||
112 | 110 | ||
@@ -118,28 +116,28 @@ mq_error_handler (void *cls, | |||
118 | * @return #GNUNET_OK if the message is well-formed | 116 | * @return #GNUNET_OK if the message is well-formed |
119 | */ | 117 | */ |
120 | static int | 118 | static int |
121 | check_notification (void *cls, | 119 | check_notification(void *cls, |
122 | const struct InfoMessage *im) | 120 | const struct InfoMessage *im) |
123 | { | 121 | { |
124 | uint16_t ms = ntohs (im->header.size) - sizeof (*im); | 122 | uint16_t ms = ntohs(im->header.size) - sizeof(*im); |
125 | 123 | ||
126 | if (ms >= sizeof (struct GNUNET_MessageHeader)) | 124 | if (ms >= sizeof(struct GNUNET_MessageHeader)) |
127 | { | ||
128 | const struct GNUNET_HELLO_Message *hello; | ||
129 | |||
130 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | ||
131 | if (ms != GNUNET_HELLO_size (hello)) | ||
132 | { | 125 | { |
133 | GNUNET_break (0); | 126 | const struct GNUNET_HELLO_Message *hello; |
134 | return GNUNET_SYSERR; | 127 | |
128 | hello = (const struct GNUNET_HELLO_Message *)&im[1]; | ||
129 | if (ms != GNUNET_HELLO_size(hello)) | ||
130 | { | ||
131 | GNUNET_break(0); | ||
132 | return GNUNET_SYSERR; | ||
133 | } | ||
134 | return GNUNET_OK; | ||
135 | } | 135 | } |
136 | return GNUNET_OK; | ||
137 | } | ||
138 | if (0 != ms) | 136 | if (0 != ms) |
139 | { | 137 | { |
140 | GNUNET_break (0); | 138 | GNUNET_break(0); |
141 | return GNUNET_SYSERR; | 139 | return GNUNET_SYSERR; |
142 | } | 140 | } |
143 | return GNUNET_OK; /* odd... */ | 141 | return GNUNET_OK; /* odd... */ |
144 | } | 142 | } |
145 | 143 | ||
@@ -151,23 +149,23 @@ check_notification (void *cls, | |||
151 | * @param im message received | 149 | * @param im message received |
152 | */ | 150 | */ |
153 | static void | 151 | static void |
154 | handle_notification (void *cls, | 152 | handle_notification(void *cls, |
155 | const struct InfoMessage *im) | 153 | const struct InfoMessage *im) |
156 | { | 154 | { |
157 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | 155 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; |
158 | const struct GNUNET_HELLO_Message *hello; | 156 | const struct GNUNET_HELLO_Message *hello; |
159 | uint16_t ms = ntohs (im->header.size) - sizeof (struct InfoMessage); | 157 | uint16_t ms = ntohs(im->header.size) - sizeof(struct InfoMessage); |
160 | 158 | ||
161 | if (0 == ms) | 159 | if (0 == ms) |
162 | return; | 160 | return; |
163 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | 161 | hello = (const struct GNUNET_HELLO_Message *)&im[1]; |
164 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 162 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
165 | "Received information about peer `%s' from peerinfo database\n", | 163 | "Received information about peer `%s' from peerinfo database\n", |
166 | GNUNET_i2s (&im->peer)); | 164 | GNUNET_i2s(&im->peer)); |
167 | nc->callback (nc->callback_cls, | 165 | nc->callback(nc->callback_cls, |
168 | &im->peer, | 166 | &im->peer, |
169 | hello, | 167 | hello, |
170 | NULL); | 168 | NULL); |
171 | } | 169 | } |
172 | 170 | ||
173 | 171 | ||
@@ -181,8 +179,8 @@ handle_notification (void *cls, | |||
181 | * @param msg message received, NULL on timeout or fatal error | 179 | * @param msg message received, NULL on timeout or fatal error |
182 | */ | 180 | */ |
183 | static void | 181 | static void |
184 | handle_end_iteration (void *cls, | 182 | handle_end_iteration(void *cls, |
185 | const struct GNUNET_MessageHeader *msg) | 183 | const struct GNUNET_MessageHeader *msg) |
186 | { | 184 | { |
187 | /* these are ignored by the notify API */ | 185 | /* these are ignored by the notify API */ |
188 | } | 186 | } |
@@ -194,36 +192,36 @@ handle_end_iteration (void *cls, | |||
194 | * @param cls the `struct GNUNET_PEERINFO_NotifyContext *` | 192 | * @param cls the `struct GNUNET_PEERINFO_NotifyContext *` |
195 | */ | 193 | */ |
196 | static void | 194 | static void |
197 | reconnect (void *cls) | 195 | reconnect(void *cls) |
198 | { | 196 | { |
199 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | 197 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; |
200 | struct GNUNET_MQ_MessageHandler handlers[] = { | 198 | struct GNUNET_MQ_MessageHandler handlers[] = { |
201 | GNUNET_MQ_hd_var_size (notification, | 199 | GNUNET_MQ_hd_var_size(notification, |
202 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO, | 200 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO, |
203 | struct InfoMessage, | 201 | struct InfoMessage, |
204 | nc), | 202 | nc), |
205 | GNUNET_MQ_hd_fixed_size (end_iteration, | 203 | GNUNET_MQ_hd_fixed_size(end_iteration, |
206 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, | 204 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, |
207 | struct GNUNET_MessageHeader, | 205 | struct GNUNET_MessageHeader, |
208 | nc), | 206 | nc), |
209 | GNUNET_MQ_handler_end () | 207 | GNUNET_MQ_handler_end() |
210 | }; | 208 | }; |
211 | struct GNUNET_MQ_Envelope *env; | 209 | struct GNUNET_MQ_Envelope *env; |
212 | struct NotifyMessage *nm; | 210 | struct NotifyMessage *nm; |
213 | 211 | ||
214 | nc->task = NULL; | 212 | nc->task = NULL; |
215 | nc->mq = GNUNET_CLIENT_connect (nc->cfg, | 213 | nc->mq = GNUNET_CLIENT_connect(nc->cfg, |
216 | "peerinfo", | 214 | "peerinfo", |
217 | handlers, | 215 | handlers, |
218 | &mq_error_handler, | 216 | &mq_error_handler, |
219 | nc); | 217 | nc); |
220 | if (NULL == nc->mq) | 218 | if (NULL == nc->mq) |
221 | return; | 219 | return; |
222 | env = GNUNET_MQ_msg (nm, | 220 | env = GNUNET_MQ_msg(nm, |
223 | GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY); | 221 | GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY); |
224 | nm->include_friend_only = htonl (nc->include_friend_only); | 222 | nm->include_friend_only = htonl(nc->include_friend_only); |
225 | GNUNET_MQ_send (nc->mq, | 223 | GNUNET_MQ_send(nc->mq, |
226 | env); | 224 | env); |
227 | } | 225 | } |
228 | 226 | ||
229 | 227 | ||
@@ -243,26 +241,26 @@ reconnect (void *cls) | |||
243 | * @return NULL on error | 241 | * @return NULL on error |
244 | */ | 242 | */ |
245 | struct GNUNET_PEERINFO_NotifyContext * | 243 | struct GNUNET_PEERINFO_NotifyContext * |
246 | GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, | 244 | GNUNET_PEERINFO_notify(const struct GNUNET_CONFIGURATION_Handle *cfg, |
247 | int include_friend_only, | 245 | int include_friend_only, |
248 | GNUNET_PEERINFO_Processor callback, | 246 | GNUNET_PEERINFO_Processor callback, |
249 | void *callback_cls) | 247 | void *callback_cls) |
250 | { | 248 | { |
251 | struct GNUNET_PEERINFO_NotifyContext *nc; | 249 | struct GNUNET_PEERINFO_NotifyContext *nc; |
252 | 250 | ||
253 | nc = GNUNET_new (struct GNUNET_PEERINFO_NotifyContext); | 251 | nc = GNUNET_new(struct GNUNET_PEERINFO_NotifyContext); |
254 | nc->cfg = cfg; | 252 | nc->cfg = cfg; |
255 | nc->callback = callback; | 253 | nc->callback = callback; |
256 | nc->callback_cls = callback_cls; | 254 | nc->callback_cls = callback_cls; |
257 | nc->include_friend_only = include_friend_only; | 255 | nc->include_friend_only = include_friend_only; |
258 | reconnect (nc); | 256 | reconnect(nc); |
259 | if (NULL == nc->mq) | 257 | if (NULL == nc->mq) |
260 | { | 258 | { |
261 | LOG (GNUNET_ERROR_TYPE_WARNING, | 259 | LOG(GNUNET_ERROR_TYPE_WARNING, |
262 | "Could not connect to PEERINFO service.\n"); | 260 | "Could not connect to PEERINFO service.\n"); |
263 | GNUNET_free (nc); | 261 | GNUNET_free(nc); |
264 | return NULL; | 262 | return NULL; |
265 | } | 263 | } |
266 | return nc; | 264 | return nc; |
267 | } | 265 | } |
268 | 266 | ||
@@ -273,19 +271,19 @@ GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
273 | * @param nc context to stop notifying | 271 | * @param nc context to stop notifying |
274 | */ | 272 | */ |
275 | void | 273 | void |
276 | GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc) | 274 | GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc) |
277 | { | 275 | { |
278 | if (NULL != nc->mq) | 276 | if (NULL != nc->mq) |
279 | { | 277 | { |
280 | GNUNET_MQ_destroy (nc->mq); | 278 | GNUNET_MQ_destroy(nc->mq); |
281 | nc->mq = NULL; | 279 | nc->mq = NULL; |
282 | } | 280 | } |
283 | if (NULL != nc->task) | 281 | if (NULL != nc->task) |
284 | { | 282 | { |
285 | GNUNET_SCHEDULER_cancel (nc->task); | 283 | GNUNET_SCHEDULER_cancel(nc->task); |
286 | nc->task = NULL; | 284 | nc->task = NULL; |
287 | } | 285 | } |
288 | GNUNET_free (nc); | 286 | GNUNET_free(nc); |
289 | } | 287 | } |
290 | 288 | ||
291 | /* end of peerinfo_api_notify.c */ | 289 | /* end of peerinfo_api_notify.c */ |
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c index d56e0c558..b9317478c 100644 --- a/src/peerinfo/perf_peerinfo_api.c +++ b/src/peerinfo/perf_peerinfo_api.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 peerinfo/perf_peerinfo_api.c | 22 | * @file peerinfo/perf_peerinfo_api.c |
@@ -48,40 +48,40 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
48 | 48 | ||
49 | 49 | ||
50 | static void | 50 | static void |
51 | do_shutdown (void *cls) | 51 | do_shutdown(void *cls) |
52 | { | 52 | { |
53 | if (NULL != tt) | 53 | if (NULL != tt) |
54 | { | 54 | { |
55 | GNUNET_SCHEDULER_cancel (tt); | 55 | GNUNET_SCHEDULER_cancel(tt); |
56 | tt = NULL; | 56 | tt = NULL; |
57 | } | 57 | } |
58 | for (unsigned int i = 0; i < NUM_REQUESTS; i++) | 58 | for (unsigned int i = 0; i < NUM_REQUESTS; i++) |
59 | if (NULL != ic[i]) | 59 | if (NULL != ic[i]) |
60 | GNUNET_PEERINFO_iterate_cancel (ic[i]); | 60 | GNUNET_PEERINFO_iterate_cancel(ic[i]); |
61 | GNUNET_PEERINFO_disconnect (h); | 61 | GNUNET_PEERINFO_disconnect(h); |
62 | h = NULL; | 62 | h = NULL; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | static void | 66 | static void |
67 | do_timeout (void *cls) | 67 | do_timeout(void *cls) |
68 | { | 68 | { |
69 | tt = NULL; | 69 | tt = NULL; |
70 | GNUNET_SCHEDULER_shutdown (); | 70 | GNUNET_SCHEDULER_shutdown(); |
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
74 | static int | 74 | static int |
75 | check_it (void *cls, | 75 | check_it(void *cls, |
76 | const struct GNUNET_HELLO_Address *address, | 76 | const struct GNUNET_HELLO_Address *address, |
77 | struct GNUNET_TIME_Absolute expiration) | 77 | struct GNUNET_TIME_Absolute expiration) |
78 | { | 78 | { |
79 | return GNUNET_OK; | 79 | return GNUNET_OK; |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | static ssize_t | 83 | static ssize_t |
84 | address_generator (void *cls, size_t max, void *buf) | 84 | address_generator(void *cls, size_t max, void *buf) |
85 | { | 85 | { |
86 | size_t *agc = cls; | 86 | size_t *agc = cls; |
87 | ssize_t ret; | 87 | ssize_t ret; |
@@ -91,100 +91,100 @@ address_generator (void *cls, size_t max, void *buf) | |||
91 | if (*agc == 0) | 91 | if (*agc == 0) |
92 | return GNUNET_SYSERR; /* Done */ | 92 | return GNUNET_SYSERR; /* Done */ |
93 | 93 | ||
94 | GNUNET_asprintf (&caddress, "Address%d", *agc); | 94 | GNUNET_asprintf(&caddress, "Address%d", *agc); |
95 | address.peer = pid; | 95 | address.peer = pid; |
96 | address.address_length = strlen (caddress) + 1; | 96 | address.address_length = strlen(caddress) + 1; |
97 | address.address = caddress; | 97 | address.address = caddress; |
98 | address.transport_name = "peerinfotest"; | 98 | address.transport_name = "peerinfotest"; |
99 | ret = | 99 | ret = |
100 | GNUNET_HELLO_add_address (&address, | 100 | GNUNET_HELLO_add_address(&address, |
101 | GNUNET_TIME_relative_to_absolute | 101 | GNUNET_TIME_relative_to_absolute |
102 | (GNUNET_TIME_UNIT_HOURS), buf, max); | 102 | (GNUNET_TIME_UNIT_HOURS), buf, max); |
103 | GNUNET_free (caddress); | 103 | GNUNET_free(caddress); |
104 | *agc = 0; | 104 | *agc = 0; |
105 | return ret; | 105 | return ret; |
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
109 | static void | 109 | static void |
110 | add_peer (size_t i) | 110 | add_peer(size_t i) |
111 | { | 111 | { |
112 | struct GNUNET_HELLO_Message *h2; | 112 | struct GNUNET_HELLO_Message *h2; |
113 | 113 | ||
114 | memset (&pid, i, sizeof (pid)); | 114 | memset(&pid, i, sizeof(pid)); |
115 | h2 = GNUNET_HELLO_create (&pid.public_key, | 115 | h2 = GNUNET_HELLO_create(&pid.public_key, |
116 | &address_generator, | 116 | &address_generator, |
117 | &i, | 117 | &i, |
118 | GNUNET_NO); | 118 | GNUNET_NO); |
119 | GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); | 119 | GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL); |
120 | GNUNET_free (h2); | 120 | GNUNET_free(h2); |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | static void | 124 | static void |
125 | process (void *cls, | 125 | process(void *cls, |
126 | const struct GNUNET_PeerIdentity *peer, | 126 | const struct GNUNET_PeerIdentity *peer, |
127 | const struct GNUNET_HELLO_Message *hello, | 127 | const struct GNUNET_HELLO_Message *hello, |
128 | const char *err_msg) | 128 | const char *err_msg) |
129 | { | 129 | { |
130 | struct GNUNET_PEERINFO_IteratorContext **icp = cls; | 130 | struct GNUNET_PEERINFO_IteratorContext **icp = cls; |
131 | 131 | ||
132 | if (NULL == peer) | 132 | if (NULL == peer) |
133 | { | 133 | { |
134 | *icp = NULL; | 134 | *icp = NULL; |
135 | return; | 135 | return; |
136 | } | 136 | } |
137 | numpeers++; | 137 | numpeers++; |
138 | if (0 && (NULL != hello) ) | 138 | if (0 && (NULL != hello)) |
139 | GNUNET_HELLO_iterate_addresses (hello, | 139 | GNUNET_HELLO_iterate_addresses(hello, |
140 | GNUNET_NO, | 140 | GNUNET_NO, |
141 | &check_it, | 141 | &check_it, |
142 | NULL); | 142 | NULL); |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
146 | static void | 146 | static void |
147 | run (void *cls, | 147 | run(void *cls, |
148 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 148 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
149 | struct GNUNET_TESTING_Peer *peer) | 149 | struct GNUNET_TESTING_Peer *peer) |
150 | { | 150 | { |
151 | h = GNUNET_PEERINFO_connect (cfg); | 151 | h = GNUNET_PEERINFO_connect(cfg); |
152 | GNUNET_assert (h != NULL); | 152 | GNUNET_assert(h != NULL); |
153 | for (unsigned int i = 0; i < NUM_REQUESTS; i++) | 153 | for (unsigned int i = 0; i < NUM_REQUESTS; i++) |
154 | { | 154 | { |
155 | add_peer (i); | 155 | add_peer(i); |
156 | ic[i] = GNUNET_PEERINFO_iterate (h, | 156 | ic[i] = GNUNET_PEERINFO_iterate(h, |
157 | GNUNET_YES, | 157 | GNUNET_YES, |
158 | NULL, | 158 | NULL, |
159 | &process, | 159 | &process, |
160 | &ic[i]); | 160 | &ic[i]); |
161 | } | 161 | } |
162 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 162 | tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
163 | 5), | 163 | 5), |
164 | &do_timeout, | 164 | &do_timeout, |
165 | NULL); | 165 | NULL); |
166 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 166 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
167 | NULL); | 167 | NULL); |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | int | 171 | int |
172 | main (int argc, | 172 | main(int argc, |
173 | char *argv[]) | 173 | char *argv[]) |
174 | { | 174 | { |
175 | if (0 != GNUNET_TESTING_service_run ("perf-gnunet-peerinfo", | 175 | if (0 != GNUNET_TESTING_service_run("perf-gnunet-peerinfo", |
176 | "peerinfo", | 176 | "peerinfo", |
177 | "test_peerinfo_api_data.conf", | 177 | "test_peerinfo_api_data.conf", |
178 | &run, NULL)) | 178 | &run, NULL)) |
179 | return 1; | 179 | return 1; |
180 | fprintf (stderr, | 180 | fprintf(stderr, |
181 | "Received %u/%u calls before timeout\n", | 181 | "Received %u/%u calls before timeout\n", |
182 | numpeers, | 182 | numpeers, |
183 | NUM_REQUESTS * NUM_REQUESTS / 2); | 183 | NUM_REQUESTS * NUM_REQUESTS / 2); |
184 | GAUGER ("PEERINFO", | 184 | GAUGER("PEERINFO", |
185 | "Peerinfo lookups", | 185 | "Peerinfo lookups", |
186 | numpeers / 5, | 186 | numpeers / 5, |
187 | "peers/s"); | 187 | "peers/s"); |
188 | return 0; | 188 | return 0; |
189 | } | 189 | } |
190 | 190 | ||
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 9060cf7b7..4c2184904 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.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 peerinfo/test_peerinfo_api.c | 22 | * @file peerinfo/test_peerinfo_api.c |
@@ -43,25 +43,25 @@ static int global_ret; | |||
43 | 43 | ||
44 | 44 | ||
45 | static int | 45 | static int |
46 | check_it (void *cls, const struct GNUNET_HELLO_Address *address, | 46 | check_it(void *cls, const struct GNUNET_HELLO_Address *address, |
47 | struct GNUNET_TIME_Absolute expiration) | 47 | struct GNUNET_TIME_Absolute expiration) |
48 | { | 48 | { |
49 | unsigned int *agc = cls; | 49 | unsigned int *agc = cls; |
50 | 50 | ||
51 | if (address != NULL) | 51 | if (address != NULL) |
52 | { | 52 | { |
53 | GNUNET_assert (0 == strcmp ("peerinfotest", address->transport_name)); | 53 | GNUNET_assert(0 == strcmp("peerinfotest", address->transport_name)); |
54 | GNUNET_assert (0 == | 54 | GNUNET_assert(0 == |
55 | strncmp ("Address", address->address, | 55 | strncmp("Address", address->address, |
56 | address->address_length)); | 56 | address->address_length)); |
57 | (*agc) -= (1 << (address->address_length - 1)); | 57 | (*agc) -= (1 << (address->address_length - 1)); |
58 | } | 58 | } |
59 | return GNUNET_OK; | 59 | return GNUNET_OK; |
60 | } | 60 | } |
61 | 61 | ||
62 | 62 | ||
63 | static ssize_t | 63 | static ssize_t |
64 | address_generator (void *cls, size_t max, void *buf) | 64 | address_generator(void *cls, size_t max, void *buf) |
65 | { | 65 | { |
66 | size_t *agc = cls; | 66 | size_t *agc = cls; |
67 | ssize_t ret; | 67 | ssize_t ret; |
@@ -69,14 +69,14 @@ address_generator (void *cls, size_t max, void *buf) | |||
69 | 69 | ||
70 | if (0 == *agc) | 70 | if (0 == *agc) |
71 | return GNUNET_SYSERR; /* Done */ | 71 | return GNUNET_SYSERR; /* Done */ |
72 | memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); | 72 | memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); |
73 | address.address = "Address"; | 73 | address.address = "Address"; |
74 | address.transport_name = "peerinfotest"; | 74 | address.transport_name = "peerinfotest"; |
75 | address.address_length = *agc; | 75 | address.address_length = *agc; |
76 | ret = | 76 | ret = |
77 | GNUNET_HELLO_add_address (&address, | 77 | GNUNET_HELLO_add_address(&address, |
78 | GNUNET_TIME_relative_to_absolute | 78 | GNUNET_TIME_relative_to_absolute |
79 | (GNUNET_TIME_UNIT_HOURS), buf, max); | 79 | (GNUNET_TIME_UNIT_HOURS), buf, max); |
80 | (*agc)--; | 80 | (*agc)--; |
81 | return ret; | 81 | return ret; |
82 | } | 82 | } |
@@ -84,85 +84,84 @@ address_generator (void *cls, size_t max, void *buf) | |||
84 | struct GNUNET_PeerIdentity pid; | 84 | struct GNUNET_PeerIdentity pid; |
85 | 85 | ||
86 | static void | 86 | static void |
87 | add_peer () | 87 | add_peer() |
88 | { | 88 | { |
89 | struct GNUNET_HELLO_Message *h2; | 89 | struct GNUNET_HELLO_Message *h2; |
90 | size_t agc; | 90 | size_t agc; |
91 | 91 | ||
92 | agc = 2; | 92 | agc = 2; |
93 | memset (&pid, 32, sizeof (pid)); | 93 | memset(&pid, 32, sizeof(pid)); |
94 | h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, GNUNET_NO); | 94 | h2 = GNUNET_HELLO_create(&pid.public_key, &address_generator, &agc, GNUNET_NO); |
95 | GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); | 95 | GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL); |
96 | GNUNET_free (h2); | 96 | GNUNET_free(h2); |
97 | |||
98 | } | 97 | } |
99 | 98 | ||
100 | 99 | ||
101 | static void | 100 | static void |
102 | process (void *cls, const struct GNUNET_PeerIdentity *peer, | 101 | process(void *cls, const struct GNUNET_PeerIdentity *peer, |
103 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | 102 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
104 | { | 103 | { |
105 | unsigned int agc; | 104 | unsigned int agc; |
106 | 105 | ||
107 | if (err_msg != NULL) | 106 | if (err_msg != NULL) |
108 | { | 107 | { |
109 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 108 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
110 | _("Error in communication with PEERINFO service\n")); | 109 | _("Error in communication with PEERINFO service\n")); |
111 | } | 110 | } |
112 | 111 | ||
113 | if (peer == NULL) | 112 | if (peer == NULL) |
114 | { | ||
115 | ic = NULL; | ||
116 | if ((3 == global_ret) && (retries < 50)) | ||
117 | { | 113 | { |
118 | /* try again */ | 114 | ic = NULL; |
119 | retries++; | 115 | if ((3 == global_ret) && (retries < 50)) |
120 | add_peer (); | 116 | { |
121 | ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL, | 117 | /* try again */ |
122 | &process, | 118 | retries++; |
123 | cls); | 119 | add_peer(); |
120 | ic = GNUNET_PEERINFO_iterate(h, GNUNET_NO, NULL, | ||
121 | &process, | ||
122 | cls); | ||
123 | return; | ||
124 | } | ||
125 | GNUNET_assert(peer == NULL); | ||
126 | GNUNET_assert(2 == global_ret); | ||
127 | GNUNET_PEERINFO_disconnect(h); | ||
128 | h = NULL; | ||
129 | global_ret = 0; | ||
124 | return; | 130 | return; |
125 | } | 131 | } |
126 | GNUNET_assert (peer == NULL); | ||
127 | GNUNET_assert (2 == global_ret); | ||
128 | GNUNET_PEERINFO_disconnect (h); | ||
129 | h = NULL; | ||
130 | global_ret = 0; | ||
131 | return; | ||
132 | } | ||
133 | if (hello != NULL) | 132 | if (hello != NULL) |
134 | { | 133 | { |
135 | GNUNET_assert (3 == global_ret); | 134 | GNUNET_assert(3 == global_ret); |
136 | agc = 3; | 135 | agc = 3; |
137 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, | 136 | GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, |
138 | &check_it, &agc); | 137 | &check_it, &agc); |
139 | GNUNET_assert (agc == 0); | 138 | GNUNET_assert(agc == 0); |
140 | global_ret = 2; | 139 | global_ret = 2; |
141 | } | 140 | } |
142 | } | 141 | } |
143 | 142 | ||
144 | 143 | ||
145 | static void | 144 | static void |
146 | run (void *cls, | 145 | run(void *cls, |
147 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 146 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
148 | struct GNUNET_TESTING_Peer *peer) | 147 | struct GNUNET_TESTING_Peer *peer) |
149 | { | 148 | { |
150 | h = GNUNET_PEERINFO_connect (cfg); | 149 | h = GNUNET_PEERINFO_connect(cfg); |
151 | GNUNET_assert (NULL != h); | 150 | GNUNET_assert(NULL != h); |
152 | add_peer (); | 151 | add_peer(); |
153 | ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, &pid, | 152 | ic = GNUNET_PEERINFO_iterate(h, GNUNET_NO, &pid, |
154 | &process, cls); | 153 | &process, cls); |
155 | } | 154 | } |
156 | 155 | ||
157 | 156 | ||
158 | int | 157 | int |
159 | main (int argc, char *argv[]) | 158 | main(int argc, char *argv[]) |
160 | { | 159 | { |
161 | global_ret = 3; | 160 | global_ret = 3; |
162 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerinfo", | 161 | if (0 != GNUNET_TESTING_service_run("test-gnunet-peerinfo", |
163 | "peerinfo", | 162 | "peerinfo", |
164 | "test_peerinfo_api_data.conf", | 163 | "test_peerinfo_api_data.conf", |
165 | &run, NULL)) | 164 | &run, NULL)) |
166 | return 1; | 165 | return 1; |
167 | return global_ret; | 166 | return global_ret; |
168 | } | 167 | } |
diff --git a/src/peerinfo/test_peerinfo_api_friend_only.c b/src/peerinfo/test_peerinfo_api_friend_only.c index d9d9200ac..a7bd69e6f 100644 --- a/src/peerinfo/test_peerinfo_api_friend_only.c +++ b/src/peerinfo/test_peerinfo_api_friend_only.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 peerinfo/test_peerinfo_api_friend_only.c | 22 | * @file peerinfo/test_peerinfo_api_friend_only.c |
@@ -46,9 +46,9 @@ static int global_ret; | |||
46 | 46 | ||
47 | 47 | ||
48 | static ssize_t | 48 | static ssize_t |
49 | address_generator (void *cls, | 49 | address_generator(void *cls, |
50 | size_t max, | 50 | size_t max, |
51 | void *buf) | 51 | void *buf) |
52 | { | 52 | { |
53 | size_t *agc = cls; | 53 | size_t *agc = cls; |
54 | ssize_t ret; | 54 | ssize_t ret; |
@@ -56,114 +56,113 @@ address_generator (void *cls, | |||
56 | 56 | ||
57 | if (0 == *agc) | 57 | if (0 == *agc) |
58 | return GNUNET_SYSERR; /* Done */ | 58 | return GNUNET_SYSERR; /* Done */ |
59 | memset (&address.peer, | 59 | memset(&address.peer, |
60 | 0, | 60 | 0, |
61 | sizeof (struct GNUNET_PeerIdentity)); | 61 | sizeof(struct GNUNET_PeerIdentity)); |
62 | address.address = "Address"; | 62 | address.address = "Address"; |
63 | address.transport_name = "peerinfotest"; | 63 | address.transport_name = "peerinfotest"; |
64 | address.address_length = *agc; | 64 | address.address_length = *agc; |
65 | ret = GNUNET_HELLO_add_address (&address, | 65 | ret = GNUNET_HELLO_add_address(&address, |
66 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), | 66 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS), |
67 | buf, | 67 | buf, |
68 | max); | 68 | max); |
69 | (*agc)--; | 69 | (*agc)--; |
70 | return ret; | 70 | return ret; |
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
74 | static void | 74 | static void |
75 | add_peer () | 75 | add_peer() |
76 | { | 76 | { |
77 | struct GNUNET_HELLO_Message *h2; | 77 | struct GNUNET_HELLO_Message *h2; |
78 | size_t agc; | 78 | size_t agc; |
79 | 79 | ||
80 | agc = 2; | 80 | agc = 2; |
81 | memset (&pid, 32, sizeof (pid)); | 81 | memset(&pid, 32, sizeof(pid)); |
82 | h2 = GNUNET_HELLO_create (&pid.public_key, | 82 | h2 = GNUNET_HELLO_create(&pid.public_key, |
83 | &address_generator, | 83 | &address_generator, |
84 | &agc, | 84 | &agc, |
85 | GNUNET_YES); | 85 | GNUNET_YES); |
86 | GNUNET_PEERINFO_add_peer (h, | 86 | GNUNET_PEERINFO_add_peer(h, |
87 | h2, | 87 | h2, |
88 | NULL, | 88 | NULL, |
89 | NULL); | 89 | NULL); |
90 | GNUNET_free (h2); | 90 | GNUNET_free(h2); |
91 | |||
92 | } | 91 | } |
93 | 92 | ||
94 | 93 | ||
95 | static void | 94 | static void |
96 | process (void *cls, | 95 | process(void *cls, |
97 | const struct GNUNET_PeerIdentity *peer, | 96 | const struct GNUNET_PeerIdentity *peer, |
98 | const struct GNUNET_HELLO_Message *hello, | 97 | const struct GNUNET_HELLO_Message *hello, |
99 | const char *err_msg) | 98 | const char *err_msg) |
100 | { | 99 | { |
101 | if (NULL != err_msg) | 100 | if (NULL != err_msg) |
102 | { | 101 | { |
103 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 102 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
104 | "Error in communication with PEERINFO service: %s\n", | 103 | "Error in communication with PEERINFO service: %s\n", |
105 | err_msg); | 104 | err_msg); |
106 | } | 105 | } |
107 | if (NULL == peer) | 106 | if (NULL == peer) |
108 | { | ||
109 | ic = NULL; | ||
110 | if ((3 == global_ret) && (retries < 50)) | ||
111 | { | 107 | { |
112 | /* try again */ | 108 | ic = NULL; |
113 | retries++; | 109 | if ((3 == global_ret) && (retries < 50)) |
114 | add_peer (); | 110 | { |
115 | ic = GNUNET_PEERINFO_iterate (h, | 111 | /* try again */ |
116 | GNUNET_NO, | 112 | retries++; |
117 | NULL, | 113 | add_peer(); |
118 | &process, | 114 | ic = GNUNET_PEERINFO_iterate(h, |
119 | cls); | 115 | GNUNET_NO, |
116 | NULL, | ||
117 | &process, | ||
118 | cls); | ||
119 | return; | ||
120 | } | ||
121 | GNUNET_assert(peer == NULL); | ||
122 | GNUNET_PEERINFO_disconnect(h); | ||
123 | h = NULL; | ||
124 | global_ret = 0; | ||
125 | return; | ||
126 | } | ||
127 | |||
128 | if ((NULL != hello) && | ||
129 | (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello))) | ||
130 | { | ||
131 | fprintf(stderr, | ||
132 | "Received friend-only HELLO\n"); | ||
133 | global_ret = 1; | ||
134 | GNUNET_PEERINFO_disconnect(h); | ||
135 | h = NULL; | ||
120 | return; | 136 | return; |
121 | } | 137 | } |
122 | GNUNET_assert (peer == NULL); | ||
123 | GNUNET_PEERINFO_disconnect (h); | ||
124 | h = NULL; | ||
125 | global_ret = 0; | ||
126 | return; | ||
127 | } | ||
128 | |||
129 | if ( (NULL != hello) && | ||
130 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ) | ||
131 | { | ||
132 | fprintf (stderr, | ||
133 | "Received friend-only HELLO\n"); | ||
134 | global_ret = 1; | ||
135 | GNUNET_PEERINFO_disconnect (h); | ||
136 | h = NULL; | ||
137 | return; | ||
138 | } | ||
139 | } | 138 | } |
140 | 139 | ||
141 | 140 | ||
142 | static void | 141 | static void |
143 | run (void *cls, | 142 | run(void *cls, |
144 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 143 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
145 | struct GNUNET_TESTING_Peer *peer) | 144 | struct GNUNET_TESTING_Peer *peer) |
146 | { | 145 | { |
147 | h = GNUNET_PEERINFO_connect (cfg); | 146 | h = GNUNET_PEERINFO_connect(cfg); |
148 | GNUNET_assert (NULL != h); | 147 | GNUNET_assert(NULL != h); |
149 | add_peer (); | 148 | add_peer(); |
150 | ic = GNUNET_PEERINFO_iterate (h, | 149 | ic = GNUNET_PEERINFO_iterate(h, |
151 | GNUNET_NO, | 150 | GNUNET_NO, |
152 | &pid, | 151 | &pid, |
153 | &process, | 152 | &process, |
154 | NULL); | 153 | NULL); |
155 | } | 154 | } |
156 | 155 | ||
157 | 156 | ||
158 | int | 157 | int |
159 | main (int argc, | 158 | main(int argc, |
160 | char *argv[]) | 159 | char *argv[]) |
161 | { | 160 | { |
162 | global_ret = 3; | 161 | global_ret = 3; |
163 | if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", | 162 | if (0 != GNUNET_TESTING_service_run("test-peerinfo-api-friend-only", |
164 | "peerinfo", | 163 | "peerinfo", |
165 | "test_peerinfo_api_data.conf", | 164 | "test_peerinfo_api_data.conf", |
166 | &run, NULL)) | 165 | &run, NULL)) |
167 | return 1; | 166 | return 1; |
168 | return global_ret; | 167 | return global_ret; |
169 | } | 168 | } |
diff --git a/src/peerinfo/test_peerinfo_api_notify_friend_only.c b/src/peerinfo/test_peerinfo_api_notify_friend_only.c index 0a9bfc083..80b5883de 100644 --- a/src/peerinfo/test_peerinfo_api_notify_friend_only.c +++ b/src/peerinfo/test_peerinfo_api_notify_friend_only.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2004, 2009 GNUnet e.V. | 3 | Copyright (C) 2004, 2009 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | 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 | */ |
@@ -34,7 +34,7 @@ | |||
34 | #include "gnunet_testing_lib.h" | 34 | #include "gnunet_testing_lib.h" |
35 | #include "peerinfo.h" | 35 | #include "peerinfo.h" |
36 | 36 | ||
37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) |
38 | 38 | ||
39 | static struct GNUNET_PEERINFO_Handle *h; | 39 | static struct GNUNET_PEERINFO_Handle *h; |
40 | static struct GNUNET_PEERINFO_NotifyContext *pnc_w_fo; | 40 | static struct GNUNET_PEERINFO_NotifyContext *pnc_w_fo; |
@@ -61,46 +61,46 @@ struct GNUNET_PeerIdentity pid; | |||
61 | struct GNUNET_SCHEDULER_Task *timeout_task; | 61 | struct GNUNET_SCHEDULER_Task *timeout_task; |
62 | 62 | ||
63 | static void | 63 | static void |
64 | end_badly (void *cls) | 64 | end_badly(void *cls) |
65 | { | 65 | { |
66 | timeout_task = NULL; | 66 | timeout_task = NULL; |
67 | GNUNET_break(0); | 67 | GNUNET_break(0); |
68 | if (NULL != pnc_wo_fo) | 68 | if (NULL != pnc_wo_fo) |
69 | { | 69 | { |
70 | GNUNET_PEERINFO_notify_cancel (pnc_wo_fo); | 70 | GNUNET_PEERINFO_notify_cancel(pnc_wo_fo); |
71 | pnc_wo_fo = NULL; | 71 | pnc_wo_fo = NULL; |
72 | } | 72 | } |
73 | if (NULL != pnc_w_fo) | 73 | if (NULL != pnc_w_fo) |
74 | { | 74 | { |
75 | GNUNET_PEERINFO_notify_cancel (pnc_w_fo); | 75 | GNUNET_PEERINFO_notify_cancel(pnc_w_fo); |
76 | pnc_w_fo = NULL; | 76 | pnc_w_fo = NULL; |
77 | } | 77 | } |
78 | if (NULL != h) | 78 | if (NULL != h) |
79 | { | 79 | { |
80 | GNUNET_PEERINFO_disconnect (h); | 80 | GNUNET_PEERINFO_disconnect(h); |
81 | h = NULL; | 81 | h = NULL; |
82 | } | 82 | } |
83 | global_ret = 255; | 83 | global_ret = 255; |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | static void | 87 | static void |
88 | done (void *cls) | 88 | done(void *cls) |
89 | { | 89 | { |
90 | if (NULL != pnc_w_fo) | 90 | if (NULL != pnc_w_fo) |
91 | GNUNET_PEERINFO_notify_cancel (pnc_w_fo); | 91 | GNUNET_PEERINFO_notify_cancel(pnc_w_fo); |
92 | pnc_w_fo = NULL; | 92 | pnc_w_fo = NULL; |
93 | if (NULL != pnc_wo_fo) | 93 | if (NULL != pnc_wo_fo) |
94 | GNUNET_PEERINFO_notify_cancel (pnc_wo_fo); | 94 | GNUNET_PEERINFO_notify_cancel(pnc_wo_fo); |
95 | pnc_wo_fo = NULL; | 95 | pnc_wo_fo = NULL; |
96 | GNUNET_PEERINFO_disconnect (h); | 96 | GNUNET_PEERINFO_disconnect(h); |
97 | h = NULL; | 97 | h = NULL; |
98 | 98 | ||
99 | if (NULL != timeout_task) | 99 | if (NULL != timeout_task) |
100 | { | 100 | { |
101 | GNUNET_SCHEDULER_cancel (timeout_task); | 101 | GNUNET_SCHEDULER_cancel(timeout_task); |
102 | timeout_task = NULL; | 102 | timeout_task = NULL; |
103 | } | 103 | } |
104 | 104 | ||
105 | if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo)) | 105 | if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo)) |
106 | global_ret = 0; | 106 | global_ret = 0; |
@@ -109,7 +109,7 @@ done (void *cls) | |||
109 | } | 109 | } |
110 | 110 | ||
111 | static ssize_t | 111 | static ssize_t |
112 | address_generator (void *cls, size_t max, void *buf) | 112 | address_generator(void *cls, size_t max, void *buf) |
113 | { | 113 | { |
114 | size_t *agc = cls; | 114 | size_t *agc = cls; |
115 | ssize_t ret; | 115 | ssize_t ret; |
@@ -117,137 +117,137 @@ address_generator (void *cls, size_t max, void *buf) | |||
117 | 117 | ||
118 | if (0 == *agc) | 118 | if (0 == *agc) |
119 | return GNUNET_SYSERR; /* Done */ | 119 | return GNUNET_SYSERR; /* Done */ |
120 | memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); | 120 | memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); |
121 | address.address = "Address"; | 121 | address.address = "Address"; |
122 | address.transport_name = "peerinfotest"; | 122 | address.transport_name = "peerinfotest"; |
123 | address.address_length = *agc; | 123 | address.address_length = *agc; |
124 | ret = GNUNET_HELLO_add_address (&address, | 124 | ret = GNUNET_HELLO_add_address(&address, |
125 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), buf, max); | 125 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS), buf, max); |
126 | (*agc)--; | 126 | (*agc)--; |
127 | return ret; | 127 | return ret; |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | static void | 131 | static void |
132 | process_w_fo (void *cls, | 132 | process_w_fo(void *cls, |
133 | const struct GNUNET_PeerIdentity *peer, | 133 | const struct GNUNET_PeerIdentity *peer, |
134 | const struct GNUNET_HELLO_Message *hello, | 134 | const struct GNUNET_HELLO_Message *hello, |
135 | const char *err_msg) | 135 | const char *err_msg) |
136 | { | 136 | { |
137 | if (err_msg != NULL) | 137 | if (err_msg != NULL) |
138 | { | ||
139 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
140 | _("Error in communication with PEERINFO service\n")); | ||
141 | GNUNET_SCHEDULER_add_now (&done, NULL); | ||
142 | return; | ||
143 | } | ||
144 | |||
145 | if (NULL != peer) | ||
146 | { | ||
147 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
148 | "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer), | ||
149 | (NULL != hello) ? "with" : "without"); | ||
150 | |||
151 | if (NULL == hello) | ||
152 | return; | ||
153 | |||
154 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello)) | ||
155 | { | 138 | { |
156 | GNUNET_break(0); | 139 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
140 | _("Error in communication with PEERINFO service\n")); | ||
141 | GNUNET_SCHEDULER_add_now(&done, NULL); | ||
157 | return; | 142 | return; |
158 | } | 143 | } |
159 | 144 | ||
160 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", | 145 | if (NULL != peer) |
161 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public", | ||
162 | GNUNET_i2s (peer)); | ||
163 | if (0 == GNUNET_memcmp (&pid, peer)) | ||
164 | { | 146 | { |
165 | res_cb_w_fo = GNUNET_YES; | 147 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
166 | GNUNET_SCHEDULER_add_now (&done, NULL); | 148 | "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s(peer), |
149 | (NULL != hello) ? "with" : "without"); | ||
150 | |||
151 | if (NULL == hello) | ||
152 | return; | ||
153 | |||
154 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello)) | ||
155 | { | ||
156 | GNUNET_break(0); | ||
157 | return; | ||
158 | } | ||
159 | |||
160 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", | ||
161 | (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) ? "friend only" : "public", | ||
162 | GNUNET_i2s(peer)); | ||
163 | if (0 == GNUNET_memcmp(&pid, peer)) | ||
164 | { | ||
165 | res_cb_w_fo = GNUNET_YES; | ||
166 | GNUNET_SCHEDULER_add_now(&done, NULL); | ||
167 | } | ||
168 | return; | ||
167 | } | 169 | } |
168 | return; | ||
169 | } | ||
170 | } | 170 | } |
171 | 171 | ||
172 | static void | 172 | static void |
173 | process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer, | 173 | process_wo_fo(void *cls, const struct GNUNET_PeerIdentity *peer, |
174 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | 174 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
175 | { | 175 | { |
176 | if (err_msg != NULL) | 176 | if (err_msg != NULL) |
177 | { | ||
178 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
179 | _("Error in communication with PEERINFO service\n")); | ||
180 | GNUNET_SCHEDULER_add_now (&done, NULL); | ||
181 | return; | ||
182 | } | ||
183 | |||
184 | if (NULL != peer) | ||
185 | { | ||
186 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
187 | "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer), | ||
188 | (NULL != hello) ? "with" : "without"); | ||
189 | |||
190 | if (NULL == hello) | ||
191 | return; | ||
192 | |||
193 | if (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) | ||
194 | { | 177 | { |
195 | GNUNET_break(0); | 178 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
179 | _("Error in communication with PEERINFO service\n")); | ||
180 | GNUNET_SCHEDULER_add_now(&done, NULL); | ||
196 | return; | 181 | return; |
197 | } | 182 | } |
198 | 183 | ||
199 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", | 184 | if (NULL != peer) |
200 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public", | ||
201 | GNUNET_i2s (peer)); | ||
202 | if (0 == GNUNET_memcmp (&pid, peer)) | ||
203 | { | 185 | { |
204 | GNUNET_break(0); | 186 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
205 | res_cb_wo_fo = GNUNET_YES; | 187 | "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s(peer), |
188 | (NULL != hello) ? "with" : "without"); | ||
189 | |||
190 | if (NULL == hello) | ||
191 | return; | ||
192 | |||
193 | if (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) | ||
194 | { | ||
195 | GNUNET_break(0); | ||
196 | return; | ||
197 | } | ||
198 | |||
199 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", | ||
200 | (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) ? "friend only" : "public", | ||
201 | GNUNET_i2s(peer)); | ||
202 | if (0 == GNUNET_memcmp(&pid, peer)) | ||
203 | { | ||
204 | GNUNET_break(0); | ||
205 | res_cb_wo_fo = GNUNET_YES; | ||
206 | } | ||
206 | } | 207 | } |
207 | } | ||
208 | } | 208 | } |
209 | 209 | ||
210 | 210 | ||
211 | static void | 211 | static void |
212 | add_peer () | 212 | add_peer() |
213 | { | 213 | { |
214 | struct GNUNET_HELLO_Message *h2; | 214 | struct GNUNET_HELLO_Message *h2; |
215 | size_t agc; | 215 | size_t agc; |
216 | 216 | ||
217 | agc = 2; | 217 | agc = 2; |
218 | memset (&pid, 32, sizeof(pid)); | 218 | memset(&pid, 32, sizeof(pid)); |
219 | h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, | 219 | h2 = GNUNET_HELLO_create(&pid.public_key, &address_generator, &agc, |
220 | GNUNET_YES); | 220 | GNUNET_YES); |
221 | GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); | 221 | GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL); |
222 | GNUNET_free(h2); | 222 | GNUNET_free(h2); |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | static void | 226 | static void |
227 | run (void *cls, | 227 | run(void *cls, |
228 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 228 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
229 | struct GNUNET_TESTING_Peer *peer) | 229 | struct GNUNET_TESTING_Peer *peer) |
230 | { | 230 | { |
231 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 231 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); |
232 | mycfg = cfg; | 232 | mycfg = cfg; |
233 | pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL); | 233 | pnc_w_fo = GNUNET_PEERINFO_notify(mycfg, GNUNET_YES, &process_w_fo, NULL); |
234 | pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL); | 234 | pnc_wo_fo = GNUNET_PEERINFO_notify(mycfg, GNUNET_NO, &process_wo_fo, NULL); |
235 | h = GNUNET_PEERINFO_connect (cfg); | 235 | h = GNUNET_PEERINFO_connect(cfg); |
236 | GNUNET_assert(NULL != h); | 236 | GNUNET_assert(NULL != h); |
237 | add_peer (); | 237 | add_peer(); |
238 | } | 238 | } |
239 | 239 | ||
240 | 240 | ||
241 | int | 241 | int |
242 | main (int argc, char *argv[]) | 242 | main(int argc, char *argv[]) |
243 | { | 243 | { |
244 | res_cb_w_fo = GNUNET_NO; | 244 | res_cb_w_fo = GNUNET_NO; |
245 | res_cb_wo_fo = GNUNET_NO; | 245 | res_cb_wo_fo = GNUNET_NO; |
246 | global_ret = 3; | 246 | global_ret = 3; |
247 | if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", | 247 | if (0 != GNUNET_TESTING_service_run("test-peerinfo-api-friend-only", |
248 | "peerinfo", | 248 | "peerinfo", |
249 | "test_peerinfo_api_data.conf", | 249 | "test_peerinfo_api_data.conf", |
250 | &run, NULL)) | 250 | &run, NULL)) |
251 | return 1; | 251 | return 1; |
252 | return global_ret; | 252 | return global_ret; |
253 | } | 253 | } |
diff --git a/src/peerinfo/test_peerinfo_shipped_hellos.c b/src/peerinfo/test_peerinfo_shipped_hellos.c index 4da6ef0ac..36deade1e 100644 --- a/src/peerinfo/test_peerinfo_shipped_hellos.c +++ b/src/peerinfo/test_peerinfo_shipped_hellos.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 peerinfo/test_peerinfo_shipped_hellos.c | 22 | * @file peerinfo/test_peerinfo_shipped_hellos.c |
@@ -40,102 +40,102 @@ static int global_ret; | |||
40 | 40 | ||
41 | 41 | ||
42 | static int | 42 | static int |
43 | addr_cb (void *cls, | 43 | addr_cb(void *cls, |
44 | const struct GNUNET_HELLO_Address *address, | 44 | const struct GNUNET_HELLO_Address *address, |
45 | struct GNUNET_TIME_Absolute expiration) | 45 | struct GNUNET_TIME_Absolute expiration) |
46 | { | 46 | { |
47 | unsigned int *addr = cls; | 47 | unsigned int *addr = cls; |
48 | 48 | ||
49 | (*addr) ++; | 49 | (*addr)++; |
50 | return GNUNET_OK; | 50 | return GNUNET_OK; |
51 | } | 51 | } |
52 | 52 | ||
53 | 53 | ||
54 | static void | 54 | static void |
55 | process (void *cls, | 55 | process(void *cls, |
56 | const struct GNUNET_PeerIdentity *peer, | 56 | const struct GNUNET_PeerIdentity *peer, |
57 | const struct GNUNET_HELLO_Message *hello, | 57 | const struct GNUNET_HELLO_Message *hello, |
58 | const char *err_msg) | 58 | const char *err_msg) |
59 | { | 59 | { |
60 | static unsigned int calls = 0; | 60 | static unsigned int calls = 0; |
61 | unsigned int addr; | 61 | unsigned int addr; |
62 | 62 | ||
63 | if (NULL != err_msg) | 63 | if (NULL != err_msg) |
64 | { | ||
65 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
66 | "Error in communication with PEERINFO service: %s\n", | ||
67 | err_msg); | ||
68 | } | ||
69 | if (NULL != peer) | ||
70 | { | ||
71 | addr = 0; | ||
72 | if (NULL != hello) | ||
73 | { | 64 | { |
74 | GNUNET_HELLO_iterate_addresses (hello, | 65 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
75 | GNUNET_NO, | 66 | "Error in communication with PEERINFO service: %s\n", |
76 | &addr_cb, | 67 | err_msg); |
77 | &addr); | ||
78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
79 | "Got information about peer %s with %u addresses\n", | ||
80 | GNUNET_i2s (peer), | ||
81 | addr); | ||
82 | calls++; | ||
83 | } | 68 | } |
84 | else | 69 | if (NULL != peer) |
85 | { | 70 | { |
86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 71 | addr = 0; |
87 | "Got no HELLP for peer %s\n", | 72 | if (NULL != hello) |
88 | GNUNET_i2s (peer)); | 73 | { |
74 | GNUNET_HELLO_iterate_addresses(hello, | ||
75 | GNUNET_NO, | ||
76 | &addr_cb, | ||
77 | &addr); | ||
78 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
79 | "Got information about peer %s with %u addresses\n", | ||
80 | GNUNET_i2s(peer), | ||
81 | addr); | ||
82 | calls++; | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
87 | "Got no HELLP for peer %s\n", | ||
88 | GNUNET_i2s(peer)); | ||
89 | } | ||
89 | } | 90 | } |
90 | } | ||
91 | else | 91 | else |
92 | { | ||
93 | if (0 == calls) | ||
94 | { | ||
95 | fprintf (stderr, | ||
96 | "Failed: got no callbacks!\n"); | ||
97 | global_ret = 1; | ||
98 | GNUNET_PEERINFO_disconnect (h); | ||
99 | h = NULL; | ||
100 | } | ||
101 | else | ||
102 | { | 92 | { |
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 93 | if (0 == calls) |
104 | "Got %u HELLOs in total\n", | 94 | { |
105 | calls); | 95 | fprintf(stderr, |
106 | global_ret = 0; | 96 | "Failed: got no callbacks!\n"); |
107 | GNUNET_PEERINFO_disconnect (h); | 97 | global_ret = 1; |
108 | h = NULL; | 98 | GNUNET_PEERINFO_disconnect(h); |
99 | h = NULL; | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
104 | "Got %u HELLOs in total\n", | ||
105 | calls); | ||
106 | global_ret = 0; | ||
107 | GNUNET_PEERINFO_disconnect(h); | ||
108 | h = NULL; | ||
109 | } | ||
109 | } | 110 | } |
110 | } | ||
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | static void | 114 | static void |
115 | run (void *cls, | 115 | run(void *cls, |
116 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 116 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
117 | struct GNUNET_TESTING_Peer *peer) | 117 | struct GNUNET_TESTING_Peer *peer) |
118 | { | 118 | { |
119 | h = GNUNET_PEERINFO_connect (cfg); | 119 | h = GNUNET_PEERINFO_connect(cfg); |
120 | GNUNET_assert (NULL != h); | 120 | GNUNET_assert(NULL != h); |
121 | ic = GNUNET_PEERINFO_iterate (h, | 121 | ic = GNUNET_PEERINFO_iterate(h, |
122 | GNUNET_YES, | 122 | GNUNET_YES, |
123 | NULL, | 123 | NULL, |
124 | &process, | 124 | &process, |
125 | cls); | 125 | cls); |
126 | GNUNET_assert (NULL != ic); | 126 | GNUNET_assert(NULL != ic); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | int | 130 | int |
131 | main (int argc, | 131 | main(int argc, |
132 | char *argv[]) | 132 | char *argv[]) |
133 | { | 133 | { |
134 | global_ret = 3; | 134 | global_ret = 3; |
135 | if (0 != GNUNET_TESTING_service_run ("test_peerinfo_shipped_hellos", | 135 | if (0 != GNUNET_TESTING_service_run("test_peerinfo_shipped_hellos", |
136 | "peerinfo", | 136 | "peerinfo", |
137 | "test_peerinfo_api_data.conf", | 137 | "test_peerinfo_api_data.conf", |
138 | &run, NULL)) | 138 | &run, NULL)) |
139 | return 1; | 139 | return 1; |
140 | return global_ret; | 140 | return global_ret; |
141 | } | 141 | } |