diff options
Diffstat (limited to 'src/peerinfo/gnunet-service-peerinfo.c')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 332 |
1 files changed, 148 insertions, 184 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index d5d153b65..160993649 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -130,13 +130,13 @@ discard_expired (void *cls, | |||
130 | const void *addr, uint16_t addrlen) | 130 | const void *addr, uint16_t addrlen) |
131 | { | 131 | { |
132 | const struct GNUNET_TIME_Absolute *now = cls; | 132 | const struct GNUNET_TIME_Absolute *now = cls; |
133 | |||
133 | if (now->abs_value > expiration.abs_value) | 134 | if (now->abs_value > expiration.abs_value) |
134 | { | 135 | { |
135 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 136 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
136 | _("Removing expired address of transport `%s'\n"), | 137 | _("Removing expired address of transport `%s'\n"), tname); |
137 | tname); | 138 | return GNUNET_NO; |
138 | return GNUNET_NO; | 139 | } |
139 | } | ||
140 | return GNUNET_OK; | 140 | return GNUNET_OK; |
141 | } | 141 | } |
142 | 142 | ||
@@ -153,8 +153,7 @@ get_host_filename (const struct GNUNET_PeerIdentity *id) | |||
153 | char *fn; | 153 | char *fn; |
154 | 154 | ||
155 | GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil); | 155 | GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil); |
156 | GNUNET_asprintf (&fn, | 156 | GNUNET_asprintf (&fn, "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil); |
157 | "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil); | ||
158 | return fn; | 157 | return fn; |
159 | } | 158 | } |
160 | 159 | ||
@@ -172,8 +171,7 @@ notify_all (struct HostEntry *entry) | |||
172 | 171 | ||
173 | msg = make_info_message (entry); | 172 | msg = make_info_message (entry); |
174 | GNUNET_SERVER_notification_context_broadcast (notify_list, | 173 | GNUNET_SERVER_notification_context_broadcast (notify_list, |
175 | &msg->header, | 174 | &msg->header, GNUNET_NO); |
176 | GNUNET_NO); | ||
177 | GNUNET_free (msg); | 175 | GNUNET_free (msg); |
178 | } | 176 | } |
179 | 177 | ||
@@ -194,46 +192,41 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
194 | struct GNUNET_TIME_Absolute now; | 192 | struct GNUNET_TIME_Absolute now; |
195 | char *fn; | 193 | char *fn; |
196 | 194 | ||
197 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, | 195 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); |
198 | &identity->hashPubKey); | ||
199 | if (entry != NULL) | 196 | if (entry != NULL) |
200 | return; | 197 | return; |
201 | GNUNET_STATISTICS_update (stats, | 198 | GNUNET_STATISTICS_update (stats, |
202 | gettext_noop ("# peers known"), | 199 | gettext_noop ("# peers known"), 1, GNUNET_NO); |
203 | 1, | ||
204 | GNUNET_NO); | ||
205 | entry = GNUNET_malloc (sizeof (struct HostEntry)); | 200 | entry = GNUNET_malloc (sizeof (struct HostEntry)); |
206 | entry->identity = *identity; | 201 | entry->identity = *identity; |
207 | 202 | ||
208 | fn = get_host_filename (identity); | 203 | fn = get_host_filename (identity); |
209 | if (GNUNET_DISK_file_test (fn) == GNUNET_YES) | 204 | if (GNUNET_DISK_file_test (fn) == GNUNET_YES) |
205 | { | ||
206 | size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | ||
207 | hello = (const struct GNUNET_HELLO_Message *) buffer; | ||
208 | if ((size < sizeof (struct GNUNET_MessageHeader)) || | ||
209 | (size != ntohs ((((const struct GNUNET_MessageHeader *) hello)->size))) | ||
210 | || (size != GNUNET_HELLO_size (hello))) | ||
210 | { | 211 | { |
211 | size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | 212 | GNUNET_break (0); |
212 | hello = (const struct GNUNET_HELLO_Message *) buffer; | 213 | if (0 != UNLINK (fn)) |
213 | if ( (size < sizeof (struct GNUNET_MessageHeader)) || | 214 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
214 | (size != ntohs((((const struct GNUNET_MessageHeader*) hello)->size))) || | ||
215 | (size != GNUNET_HELLO_size (hello)) ) | ||
216 | { | ||
217 | GNUNET_break (0); | ||
218 | if (0 != UNLINK (fn)) | ||
219 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
220 | "unlink", | ||
221 | fn); | ||
222 | } | ||
223 | else | ||
224 | { | ||
225 | now = GNUNET_TIME_absolute_get (); | ||
226 | hello_clean = GNUNET_HELLO_iterate_addresses (hello, | ||
227 | GNUNET_YES, | ||
228 | &discard_expired, &now); | ||
229 | entry->hello = hello_clean; | ||
230 | } | ||
231 | } | 215 | } |
216 | else | ||
217 | { | ||
218 | now = GNUNET_TIME_absolute_get (); | ||
219 | hello_clean = GNUNET_HELLO_iterate_addresses (hello, | ||
220 | GNUNET_YES, | ||
221 | &discard_expired, &now); | ||
222 | entry->hello = hello_clean; | ||
223 | } | ||
224 | } | ||
232 | GNUNET_free (fn); | 225 | GNUNET_free (fn); |
233 | GNUNET_CONTAINER_multihashmap_put (hostmap, | 226 | GNUNET_CONTAINER_multihashmap_put (hostmap, |
234 | &identity->hashPubKey, | 227 | &identity->hashPubKey, |
235 | entry, | 228 | entry, |
236 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 229 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
237 | notify_all (entry); | 230 | notify_all (entry); |
238 | } | 231 | } |
239 | 232 | ||
@@ -257,8 +250,7 @@ remove_garbage (const char *fullname) | |||
257 | 250 | ||
258 | 251 | ||
259 | static int | 252 | static int |
260 | hosts_directory_scan_callback (void *cls, | 253 | hosts_directory_scan_callback (void *cls, const char *fullname) |
261 | const char *fullname) | ||
262 | { | 254 | { |
263 | unsigned int *matched = cls; | 255 | unsigned int *matched = cls; |
264 | struct GNUNET_PeerIdentity identity; | 256 | struct GNUNET_PeerIdentity identity; |
@@ -267,24 +259,24 @@ hosts_directory_scan_callback (void *cls, | |||
267 | if (GNUNET_DISK_file_test (fullname) != GNUNET_YES) | 259 | if (GNUNET_DISK_file_test (fullname) != GNUNET_YES) |
268 | return GNUNET_OK; /* ignore non-files */ | 260 | return GNUNET_OK; /* ignore non-files */ |
269 | if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) | 261 | if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) |
270 | { | 262 | { |
271 | remove_garbage (fullname); | 263 | remove_garbage (fullname); |
272 | return GNUNET_OK; | 264 | return GNUNET_OK; |
273 | } | 265 | } |
274 | filename = | 266 | filename = |
275 | &fullname[strlen (fullname) - | 267 | &fullname[strlen (fullname) - |
276 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1]; | 268 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1]; |
277 | if (filename[-1] != DIR_SEPARATOR) | 269 | if (filename[-1] != DIR_SEPARATOR) |
278 | { | 270 | { |
279 | remove_garbage (fullname); | 271 | remove_garbage (fullname); |
280 | return GNUNET_OK; | 272 | return GNUNET_OK; |
281 | } | 273 | } |
282 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, | 274 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, |
283 | &identity.hashPubKey)) | 275 | &identity.hashPubKey)) |
284 | { | 276 | { |
285 | remove_garbage (fullname); | 277 | remove_garbage (fullname); |
286 | return GNUNET_OK; | 278 | return GNUNET_OK; |
287 | } | 279 | } |
288 | (*matched)++; | 280 | (*matched)++; |
289 | add_host_to_known_hosts (&identity); | 281 | add_host_to_known_hosts (&identity); |
290 | return GNUNET_OK; | 282 | return GNUNET_OK; |
@@ -305,11 +297,11 @@ cron_scan_directory_data_hosts (void *cls, | |||
305 | return; | 297 | return; |
306 | count = 0; | 298 | count = 0; |
307 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory)) | 299 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory)) |
308 | { | 300 | { |
309 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, | 301 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, |
310 | &cron_scan_directory_data_hosts, NULL); | 302 | &cron_scan_directory_data_hosts, NULL); |
311 | return; | 303 | return; |
312 | } | 304 | } |
313 | GNUNET_DISK_directory_scan (networkIdDirectory, | 305 | GNUNET_DISK_directory_scan (networkIdDirectory, |
314 | &hosts_directory_scan_callback, &count); | 306 | &hosts_directory_scan_callback, &count); |
315 | if ((0 == count) && (0 == (++retries & 31))) | 307 | if ((0 == count) && (0 == (++retries & 31))) |
@@ -337,42 +329,39 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
337 | struct GNUNET_TIME_Absolute delta; | 329 | struct GNUNET_TIME_Absolute delta; |
338 | 330 | ||
339 | add_host_to_known_hosts (peer); | 331 | add_host_to_known_hosts (peer); |
340 | host = GNUNET_CONTAINER_multihashmap_get (hostmap, | 332 | host = GNUNET_CONTAINER_multihashmap_get (hostmap, &peer->hashPubKey); |
341 | &peer->hashPubKey); | ||
342 | GNUNET_assert (host != NULL); | 333 | GNUNET_assert (host != NULL); |
343 | if (host->hello == NULL) | 334 | if (host->hello == NULL) |
344 | { | 335 | { |
345 | host->hello = GNUNET_malloc (GNUNET_HELLO_size (hello)); | 336 | host->hello = GNUNET_malloc (GNUNET_HELLO_size (hello)); |
346 | memcpy (host->hello, hello, GNUNET_HELLO_size (hello)); | 337 | memcpy (host->hello, hello, GNUNET_HELLO_size (hello)); |
347 | } | 338 | } |
348 | else | 339 | else |
340 | { | ||
341 | mrg = GNUNET_HELLO_merge (host->hello, hello); | ||
342 | delta = GNUNET_HELLO_equals (mrg, host->hello, GNUNET_TIME_absolute_get ()); | ||
343 | if (delta.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) | ||
349 | { | 344 | { |
350 | mrg = GNUNET_HELLO_merge (host->hello, hello); | 345 | GNUNET_free (mrg); |
351 | delta = GNUNET_HELLO_equals (mrg, | 346 | return; |
352 | host->hello, | ||
353 | GNUNET_TIME_absolute_get ()); | ||
354 | if (delta.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) | ||
355 | { | ||
356 | GNUNET_free (mrg); | ||
357 | return; | ||
358 | } | ||
359 | GNUNET_free (host->hello); | ||
360 | host->hello = mrg; | ||
361 | } | 347 | } |
348 | GNUNET_free (host->hello); | ||
349 | host->hello = mrg; | ||
350 | } | ||
362 | fn = get_host_filename (peer); | 351 | fn = get_host_filename (peer); |
363 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) | 352 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) |
364 | { | 353 | { |
365 | if (GNUNET_SYSERR == | 354 | if (GNUNET_SYSERR == |
366 | GNUNET_DISK_fn_write (fn, | 355 | GNUNET_DISK_fn_write (fn, |
367 | host->hello, | 356 | host->hello, |
368 | GNUNET_HELLO_size (host->hello), | 357 | GNUNET_HELLO_size (host->hello), |
369 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | 358 | GNUNET_DISK_PERM_USER_READ | |
370 | | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ)) | 359 | GNUNET_DISK_PERM_USER_WRITE | |
371 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 360 | GNUNET_DISK_PERM_GROUP_READ | |
372 | "write", | 361 | GNUNET_DISK_PERM_OTHER_READ)) |
373 | fn); | 362 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); |
374 | 363 | ||
375 | } | 364 | } |
376 | GNUNET_free (fn); | 365 | GNUNET_free (fn); |
377 | notify_all (host); | 366 | notify_all (host); |
378 | } | 367 | } |
@@ -388,9 +377,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
388 | * @return GNUNET_YES (continue to iterate) | 377 | * @return GNUNET_YES (continue to iterate) |
389 | */ | 378 | */ |
390 | static int | 379 | static int |
391 | add_to_tc (void *cls, | 380 | add_to_tc (void *cls, const GNUNET_HashCode * key, void *value) |
392 | const GNUNET_HashCode *key, | ||
393 | void *value) | ||
394 | { | 381 | { |
395 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 382 | struct GNUNET_SERVER_TransmitContext *tc = cls; |
396 | struct HostEntry *pos = value; | 383 | struct HostEntry *pos = value; |
@@ -401,19 +388,18 @@ add_to_tc (void *cls, | |||
401 | hs = 0; | 388 | hs = 0; |
402 | im = (struct InfoMessage *) buf; | 389 | im = (struct InfoMessage *) buf; |
403 | if (pos->hello != NULL) | 390 | if (pos->hello != NULL) |
404 | { | 391 | { |
405 | hs = GNUNET_HELLO_size (pos->hello); | 392 | hs = GNUNET_HELLO_size (pos->hello); |
406 | GNUNET_assert (hs < | 393 | GNUNET_assert (hs < |
407 | GNUNET_SERVER_MAX_MESSAGE_SIZE - | 394 | GNUNET_SERVER_MAX_MESSAGE_SIZE - |
408 | sizeof (struct InfoMessage)); | 395 | sizeof (struct InfoMessage)); |
409 | memcpy (&im[1], pos->hello, hs); | 396 | memcpy (&im[1], pos->hello, hs); |
410 | } | 397 | } |
411 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 398 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
412 | im->header.size = htons (sizeof (struct InfoMessage) + hs); | 399 | im->header.size = htons (sizeof (struct InfoMessage) + hs); |
413 | im->reserved = htonl (0); | 400 | im->reserved = htonl (0); |
414 | im->peer = pos->identity; | 401 | im->peer = pos->identity; |
415 | GNUNET_SERVER_transmit_context_append_message (tc, | 402 | GNUNET_SERVER_transmit_context_append_message (tc, &im->header); |
416 | &im->header); | ||
417 | return GNUNET_YES; | 403 | return GNUNET_YES; |
418 | } | 404 | } |
419 | 405 | ||
@@ -432,31 +418,33 @@ discard_hosts_helper (void *cls, const char *fn) | |||
432 | 418 | ||
433 | size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | 419 | size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); |
434 | if (size < sizeof (struct GNUNET_MessageHeader)) | 420 | if (size < sizeof (struct GNUNET_MessageHeader)) |
435 | { | 421 | { |
436 | if (0 != UNLINK (fn)) | 422 | if (0 != UNLINK (fn)) |
437 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 423 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | |
438 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); | 424 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); |
439 | return GNUNET_OK; | 425 | return GNUNET_OK; |
440 | } | 426 | } |
441 | hello = (const struct GNUNET_HELLO_Message *) buffer; | 427 | hello = (const struct GNUNET_HELLO_Message *) buffer; |
442 | new_hello = GNUNET_HELLO_iterate_addresses (hello, | 428 | new_hello = GNUNET_HELLO_iterate_addresses (hello, |
443 | GNUNET_YES, | 429 | GNUNET_YES, |
444 | &discard_expired, now); | 430 | &discard_expired, now); |
445 | if (new_hello != NULL) | 431 | if (new_hello != NULL) |
446 | { | 432 | { |
447 | GNUNET_DISK_fn_write (fn, | 433 | GNUNET_DISK_fn_write (fn, |
448 | new_hello, | 434 | new_hello, |
449 | GNUNET_HELLO_size (new_hello), | 435 | GNUNET_HELLO_size (new_hello), |
450 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | 436 | GNUNET_DISK_PERM_USER_READ | |
451 | | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ); | 437 | GNUNET_DISK_PERM_USER_WRITE | |
452 | GNUNET_free (new_hello); | 438 | GNUNET_DISK_PERM_GROUP_READ | |
453 | } | 439 | GNUNET_DISK_PERM_OTHER_READ); |
440 | GNUNET_free (new_hello); | ||
441 | } | ||
454 | else | 442 | else |
455 | { | 443 | { |
456 | if (0 != UNLINK (fn)) | 444 | if (0 != UNLINK (fn)) |
457 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 445 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | |
458 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); | 446 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); |
459 | } | 447 | } |
460 | return GNUNET_OK; | 448 | return GNUNET_OK; |
461 | } | 449 | } |
462 | 450 | ||
@@ -465,16 +453,14 @@ discard_hosts_helper (void *cls, const char *fn) | |||
465 | * Call this method periodically to scan data/hosts for new hosts. | 453 | * Call this method periodically to scan data/hosts for new hosts. |
466 | */ | 454 | */ |
467 | static void | 455 | static void |
468 | cron_clean_data_hosts (void *cls, | 456 | cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
469 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
470 | { | 457 | { |
471 | struct GNUNET_TIME_Absolute now; | 458 | struct GNUNET_TIME_Absolute now; |
472 | 459 | ||
473 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 460 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
474 | return; | 461 | return; |
475 | now = GNUNET_TIME_absolute_get (); | 462 | now = GNUNET_TIME_absolute_get (); |
476 | GNUNET_DISK_directory_scan (networkIdDirectory, | 463 | GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); |
477 | &discard_hosts_helper, &now); | ||
478 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, | 464 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, |
479 | &cron_clean_data_hosts, NULL); | 465 | &cron_clean_data_hosts, NULL); |
480 | } | 466 | } |
@@ -489,24 +475,23 @@ cron_clean_data_hosts (void *cls, | |||
489 | */ | 475 | */ |
490 | static void | 476 | static void |
491 | handle_hello (void *cls, | 477 | handle_hello (void *cls, |
492 | struct GNUNET_SERVER_Client *client, | 478 | struct GNUNET_SERVER_Client *client, |
493 | const struct GNUNET_MessageHeader *message) | 479 | const struct GNUNET_MessageHeader *message) |
494 | { | 480 | { |
495 | const struct GNUNET_HELLO_Message *hello; | 481 | const struct GNUNET_HELLO_Message *hello; |
496 | struct GNUNET_PeerIdentity pid; | 482 | struct GNUNET_PeerIdentity pid; |
497 | 483 | ||
498 | hello = (const struct GNUNET_HELLO_Message *) message; | 484 | hello = (const struct GNUNET_HELLO_Message *) message; |
499 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) | 485 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) |
500 | { | 486 | { |
501 | GNUNET_break (0); | 487 | GNUNET_break (0); |
502 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 488 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
503 | return; | 489 | return; |
504 | } | 490 | } |
505 | #if DEBUG_PEERINFO | 491 | #if DEBUG_PEERINFO |
506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
507 | "`%s' message received for peer `%4s'\n", | 493 | "`%s' message received for peer `%4s'\n", |
508 | "HELLO", | 494 | "HELLO", GNUNET_i2s (&pid)); |
509 | GNUNET_i2s (&pid)); | ||
510 | #endif | 495 | #endif |
511 | bind_address (&pid, hello); | 496 | bind_address (&pid, hello); |
512 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 497 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -532,17 +517,15 @@ handle_get (void *cls, | |||
532 | GNUNET_break (0 == ntohl (lpm->reserved)); | 517 | GNUNET_break (0 == ntohl (lpm->reserved)); |
533 | #if DEBUG_PEERINFO | 518 | #if DEBUG_PEERINFO |
534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
535 | "`%s' message received for peer `%4s'\n", | 520 | "`%s' message received for peer `%4s'\n", |
536 | "GET", | 521 | "GET", GNUNET_i2s (&lpm->peer)); |
537 | GNUNET_i2s (&lpm->peer)); | ||
538 | #endif | 522 | #endif |
539 | tc = GNUNET_SERVER_transmit_context_create (client); | 523 | tc = GNUNET_SERVER_transmit_context_create (client); |
540 | GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, | 524 | GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, |
541 | &lpm->peer.hashPubKey, | 525 | &lpm->peer.hashPubKey, |
542 | &add_to_tc, | 526 | &add_to_tc, tc); |
543 | tc); | ||
544 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 527 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
545 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 528 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
546 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 529 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
547 | } | 530 | } |
548 | 531 | ||
@@ -562,24 +545,18 @@ handle_get_all (void *cls, | |||
562 | struct GNUNET_SERVER_TransmitContext *tc; | 545 | struct GNUNET_SERVER_TransmitContext *tc; |
563 | 546 | ||
564 | #if DEBUG_PEERINFO | 547 | #if DEBUG_PEERINFO |
565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL"); |
566 | "`%s' message received\n", | ||
567 | "GET_ALL"); | ||
568 | #endif | 549 | #endif |
569 | tc = GNUNET_SERVER_transmit_context_create (client); | 550 | tc = GNUNET_SERVER_transmit_context_create (client); |
570 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, | 551 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, tc); |
571 | &add_to_tc, | ||
572 | tc); | ||
573 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 552 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
574 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 553 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
575 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 554 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
576 | } | 555 | } |
577 | 556 | ||
578 | 557 | ||
579 | static int | 558 | static int |
580 | do_notify_entry (void *cls, | 559 | do_notify_entry (void *cls, const GNUNET_HashCode * key, void *value) |
581 | const GNUNET_HashCode *key, | ||
582 | void *value) | ||
583 | { | 560 | { |
584 | struct GNUNET_SERVER_Client *client = cls; | 561 | struct GNUNET_SERVER_Client *client = cls; |
585 | struct HostEntry *he = value; | 562 | struct HostEntry *he = value; |
@@ -587,9 +564,7 @@ do_notify_entry (void *cls, | |||
587 | 564 | ||
588 | msg = make_info_message (he); | 565 | msg = make_info_message (he); |
589 | GNUNET_SERVER_notification_context_unicast (notify_list, | 566 | GNUNET_SERVER_notification_context_unicast (notify_list, |
590 | client, | 567 | client, &msg->header, GNUNET_NO); |
591 | &msg->header, | ||
592 | GNUNET_NO); | ||
593 | GNUNET_free (msg); | 568 | GNUNET_free (msg); |
594 | return GNUNET_YES; | 569 | return GNUNET_YES; |
595 | } | 570 | } |
@@ -604,27 +579,20 @@ do_notify_entry (void *cls, | |||
604 | */ | 579 | */ |
605 | static void | 580 | static void |
606 | handle_notify (void *cls, | 581 | handle_notify (void *cls, |
607 | struct GNUNET_SERVER_Client *client, | 582 | struct GNUNET_SERVER_Client *client, |
608 | const struct GNUNET_MessageHeader *message) | 583 | const struct GNUNET_MessageHeader *message) |
609 | { | 584 | { |
610 | #if DEBUG_PEERINFO | 585 | #if DEBUG_PEERINFO |
611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY"); |
612 | "`%s' message received\n", | ||
613 | "NOTIFY"); | ||
614 | #endif | 587 | #endif |
615 | GNUNET_SERVER_notification_context_add (notify_list, | 588 | GNUNET_SERVER_notification_context_add (notify_list, client); |
616 | client); | 589 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, client); |
617 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, | ||
618 | &do_notify_entry, | ||
619 | client); | ||
620 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 590 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
621 | } | 591 | } |
622 | 592 | ||
623 | 593 | ||
624 | static int | 594 | static int |
625 | free_host_entry (void *cls, | 595 | free_host_entry (void *cls, const GNUNET_HashCode * key, void *value) |
626 | const GNUNET_HashCode *key, | ||
627 | void *value) | ||
628 | { | 596 | { |
629 | struct HostEntry *he = value; | 597 | struct HostEntry *he = value; |
630 | 598 | ||
@@ -640,20 +608,17 @@ free_host_entry (void *cls, | |||
640 | * @param tc scheduler task context, unused | 608 | * @param tc scheduler task context, unused |
641 | */ | 609 | */ |
642 | static void | 610 | static void |
643 | shutdown_task (void *cls, | 611 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
644 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
645 | { | 612 | { |
646 | GNUNET_SERVER_notification_context_destroy (notify_list); | 613 | GNUNET_SERVER_notification_context_destroy (notify_list); |
647 | notify_list = NULL; | 614 | notify_list = NULL; |
648 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, | 615 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &free_host_entry, NULL); |
649 | &free_host_entry, | ||
650 | NULL); | ||
651 | GNUNET_CONTAINER_multihashmap_destroy (hostmap); | 616 | GNUNET_CONTAINER_multihashmap_destroy (hostmap); |
652 | if (stats != NULL) | 617 | if (stats != NULL) |
653 | { | 618 | { |
654 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 619 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
655 | stats = NULL; | 620 | stats = NULL; |
656 | } | 621 | } |
657 | } | 622 | } |
658 | 623 | ||
659 | 624 | ||
@@ -690,11 +655,11 @@ run (void *cls, | |||
690 | &networkIdDirectory)); | 655 | &networkIdDirectory)); |
691 | GNUNET_DISK_directory_create (networkIdDirectory); | 656 | GNUNET_DISK_directory_create (networkIdDirectory); |
692 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 657 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
693 | &cron_scan_directory_data_hosts, NULL); | 658 | &cron_scan_directory_data_hosts, NULL); |
694 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 659 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
695 | &cron_clean_data_hosts, NULL); | 660 | &cron_clean_data_hosts, NULL); |
696 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 661 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
697 | &shutdown_task, NULL); | 662 | &shutdown_task, NULL); |
698 | GNUNET_SERVER_add_handlers (server, handlers); | 663 | GNUNET_SERVER_add_handlers (server, handlers); |
699 | } | 664 | } |
700 | 665 | ||
@@ -712,11 +677,10 @@ main (int argc, char *const *argv) | |||
712 | int ret; | 677 | int ret; |
713 | 678 | ||
714 | ret = (GNUNET_OK == | 679 | ret = (GNUNET_OK == |
715 | GNUNET_SERVICE_run (argc, | 680 | GNUNET_SERVICE_run (argc, |
716 | argv, | 681 | argv, |
717 | "peerinfo", | 682 | "peerinfo", |
718 | GNUNET_SERVICE_OPTION_NONE, | 683 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; |
719 | &run, NULL)) ? 0 : 1; | ||
720 | GNUNET_free_non_null (networkIdDirectory); | 684 | GNUNET_free_non_null (networkIdDirectory); |
721 | return ret; | 685 | return ret; |
722 | } | 686 | } |