diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-08-28 21:34:36 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-08-28 21:34:36 +0000 |
commit | 57924abe125fa52dce4dc2e84cb0a7c4dcd04579 (patch) | |
tree | 51420ad914e9ac3c0b7ab0974cf574afe4f5f715 /src/peerinfo | |
parent | 3cb045c1df8bda92f5b4f54b5f9bf4463096cac0 (diff) | |
download | gnunet-57924abe125fa52dce4dc2e84cb0a7c4dcd04579.tar.gz gnunet-57924abe125fa52dce4dc2e84cb0a7c4dcd04579.zip |
train hacks
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/Makefile.am | 10 | ||||
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 195 | ||||
-rwxr-xr-x | src/peerinfo/perf_peerinfo_api.c | 217 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api.c | 2 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api_data.conf | 3 |
5 files changed, 328 insertions, 99 deletions
diff --git a/src/peerinfo/Makefile.am b/src/peerinfo/Makefile.am index 31c7ab92d..116095f2a 100644 --- a/src/peerinfo/Makefile.am +++ b/src/peerinfo/Makefile.am | |||
@@ -35,7 +35,8 @@ gnunet_service_peerinfo_LDADD = \ | |||
35 | 35 | ||
36 | 36 | ||
37 | check_PROGRAMS = \ | 37 | check_PROGRAMS = \ |
38 | test_peerinfo_api | 38 | test_peerinfo_api \ |
39 | perf_peerinfo_api | ||
39 | 40 | ||
40 | if !DISABLE_TEST_RUN | 41 | if !DISABLE_TEST_RUN |
41 | TESTS = $(check_PROGRAMS) | 42 | TESTS = $(check_PROGRAMS) |
@@ -48,5 +49,12 @@ test_peerinfo_api_LDADD = \ | |||
48 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | 49 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ |
49 | $(top_builddir)/src/util/libgnunetutil.la | 50 | $(top_builddir)/src/util/libgnunetutil.la |
50 | 51 | ||
52 | perf_peerinfo_api_SOURCES = \ | ||
53 | perf_peerinfo_api.c | ||
54 | perf_peerinfo_api_LDADD = \ | ||
55 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
56 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | ||
57 | $(top_builddir)/src/util/libgnunetutil.la | ||
58 | |||
51 | EXTRA_DIST = \ | 59 | EXTRA_DIST = \ |
52 | test_peerinfo_api_data.conf | 60 | test_peerinfo_api_data.conf |
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index ee8749955..4879eea34 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -33,6 +33,7 @@ | |||
33 | 33 | ||
34 | #include "platform.h" | 34 | #include "platform.h" |
35 | #include "gnunet_crypto_lib.h" | 35 | #include "gnunet_crypto_lib.h" |
36 | #include "gnunet_container_lib.h" | ||
36 | #include "gnunet_disk_lib.h" | 37 | #include "gnunet_disk_lib.h" |
37 | #include "gnunet_hello_lib.h" | 38 | #include "gnunet_hello_lib.h" |
38 | #include "gnunet_protocols.h" | 39 | #include "gnunet_protocols.h" |
@@ -57,11 +58,6 @@ struct HostEntry | |||
57 | { | 58 | { |
58 | 59 | ||
59 | /** | 60 | /** |
60 | * This is a linked list. | ||
61 | */ | ||
62 | struct HostEntry *next; | ||
63 | |||
64 | /** | ||
65 | * Identity of the peer. | 61 | * Identity of the peer. |
66 | */ | 62 | */ |
67 | struct GNUNET_PeerIdentity identity; | 63 | struct GNUNET_PeerIdentity identity; |
@@ -75,9 +71,10 @@ struct HostEntry | |||
75 | 71 | ||
76 | 72 | ||
77 | /** | 73 | /** |
78 | * The in-memory list of known hosts. | 74 | * The in-memory list of known hosts, mapping of |
75 | * host IDs to 'struct HostEntry*' values. | ||
79 | */ | 76 | */ |
80 | static struct HostEntry *hosts; | 77 | static struct GNUNET_CONTAINER_MultiHashMap *hostmap; |
81 | 78 | ||
82 | /** | 79 | /** |
83 | * Clients to immediately notify about all changes. | 80 | * Clients to immediately notify about all changes. |
@@ -163,24 +160,6 @@ get_host_filename (const struct GNUNET_PeerIdentity *id) | |||
163 | 160 | ||
164 | 161 | ||
165 | /** | 162 | /** |
166 | * Find the host entry for the given peer. FIXME: replace by hash map! | ||
167 | * @return NULL if not found | ||
168 | */ | ||
169 | static struct HostEntry * | ||
170 | lookup_host_entry (const struct GNUNET_PeerIdentity *id) | ||
171 | { | ||
172 | struct HostEntry *pos; | ||
173 | |||
174 | pos = hosts; | ||
175 | while ((pos != NULL) && | ||
176 | (0 != | ||
177 | memcmp (id, &pos->identity, sizeof (struct GNUNET_PeerIdentity)))) | ||
178 | pos = pos->next; | ||
179 | return pos; | ||
180 | } | ||
181 | |||
182 | |||
183 | /** | ||
184 | * Broadcast information about the given entry to all | 163 | * Broadcast information about the given entry to all |
185 | * clients that care. | 164 | * clients that care. |
186 | * | 165 | * |
@@ -215,7 +194,8 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
215 | struct GNUNET_TIME_Absolute now; | 194 | struct GNUNET_TIME_Absolute now; |
216 | char *fn; | 195 | char *fn; |
217 | 196 | ||
218 | entry = lookup_host_entry (identity); | 197 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, |
198 | &identity->hashPubKey); | ||
219 | if (entry != NULL) | 199 | if (entry != NULL) |
220 | return; | 200 | return; |
221 | GNUNET_STATISTICS_update (stats, | 201 | GNUNET_STATISTICS_update (stats, |
@@ -250,8 +230,10 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
250 | } | 230 | } |
251 | } | 231 | } |
252 | GNUNET_free (fn); | 232 | GNUNET_free (fn); |
253 | entry->next = hosts; | 233 | GNUNET_CONTAINER_multihashmap_put (hostmap, |
254 | hosts = entry; | 234 | &identity->hashPubKey, |
235 | entry, | ||
236 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
255 | notify_all (entry); | 237 | notify_all (entry); |
256 | } | 238 | } |
257 | 239 | ||
@@ -275,7 +257,8 @@ remove_garbage (const char *fullname) | |||
275 | 257 | ||
276 | 258 | ||
277 | static int | 259 | static int |
278 | hosts_directory_scan_callback (void *cls, const char *fullname) | 260 | hosts_directory_scan_callback (void *cls, |
261 | const char *fullname) | ||
279 | { | 262 | { |
280 | unsigned int *matched = cls; | 263 | unsigned int *matched = cls; |
281 | struct GNUNET_PeerIdentity identity; | 264 | struct GNUNET_PeerIdentity identity; |
@@ -350,7 +333,8 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
350 | struct GNUNET_TIME_Absolute delta; | 333 | struct GNUNET_TIME_Absolute delta; |
351 | 334 | ||
352 | add_host_to_known_hosts (peer); | 335 | add_host_to_known_hosts (peer); |
353 | host = lookup_host_entry (peer); | 336 | host = GNUNET_CONTAINER_multihashmap_get (hostmap, |
337 | &peer->hashPubKey); | ||
354 | GNUNET_assert (host != NULL); | 338 | GNUNET_assert (host != NULL); |
355 | if (host->hello == NULL) | 339 | if (host->hello == NULL) |
356 | { | 340 | { |
@@ -383,63 +367,43 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
383 | } | 367 | } |
384 | 368 | ||
385 | 369 | ||
370 | |||
386 | /** | 371 | /** |
387 | * Do transmit info either for only the host matching the given | 372 | * Do transmit info about peer to given host. |
388 | * argument or for all known hosts. | ||
389 | * | 373 | * |
390 | * @param only NULL to hit all hosts, otherwise specifies a particular target | 374 | * @param cls NULL to hit all hosts, otherwise specifies a particular target |
391 | * @param client who is making the request (and will thus receive our confirmation) | 375 | * @param key hostID |
376 | * @param value information to transmit | ||
377 | * @return GNUNET_YES (continue to iterate) | ||
392 | */ | 378 | */ |
393 | static void | 379 | static int |
394 | send_to_each_host (const struct GNUNET_PeerIdentity *only, | 380 | add_to_tc (void *cls, |
395 | struct GNUNET_SERVER_Client *client) | 381 | const GNUNET_HashCode *key, |
382 | void *value) | ||
396 | { | 383 | { |
397 | struct HostEntry *pos; | 384 | struct GNUNET_SERVER_TransmitContext *tc = cls; |
385 | struct HostEntry *pos = value; | ||
398 | struct InfoMessage *im; | 386 | struct InfoMessage *im; |
399 | uint16_t hs; | 387 | uint16_t hs; |
400 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 388 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
401 | struct GNUNET_SERVER_TransmitContext *tc; | ||
402 | int match; | ||
403 | 389 | ||
404 | tc = GNUNET_SERVER_transmit_context_create (client); | 390 | hs = 0; |
405 | match = GNUNET_NO; | 391 | im = (struct InfoMessage *) buf; |
406 | pos = hosts; | 392 | if (pos->hello != NULL) |
407 | while (pos != NULL) | ||
408 | { | 393 | { |
409 | if ((only == NULL) || | 394 | hs = GNUNET_HELLO_size (pos->hello); |
410 | (0 == | 395 | GNUNET_assert (hs < |
411 | memcmp (only, &pos->identity, | 396 | GNUNET_SERVER_MAX_MESSAGE_SIZE - |
412 | sizeof (struct GNUNET_PeerIdentity)))) | 397 | sizeof (struct InfoMessage)); |
413 | { | 398 | memcpy (&im[1], pos->hello, hs); |
414 | hs = 0; | ||
415 | im = (struct InfoMessage *) buf; | ||
416 | if (pos->hello != NULL) | ||
417 | { | ||
418 | hs = GNUNET_HELLO_size (pos->hello); | ||
419 | GNUNET_assert (hs < | ||
420 | GNUNET_SERVER_MAX_MESSAGE_SIZE - | ||
421 | sizeof (struct InfoMessage)); | ||
422 | memcpy (&im[1], pos->hello, hs); | ||
423 | match = GNUNET_YES; | ||
424 | } | ||
425 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | ||
426 | im->header.size = htons (sizeof (struct InfoMessage) + hs); | ||
427 | im->reserved = htonl (0); | ||
428 | im->peer = pos->identity; | ||
429 | GNUNET_SERVER_transmit_context_append_message (tc, | ||
430 | &im->header); | ||
431 | } | ||
432 | pos = pos->next; | ||
433 | } | 399 | } |
434 | if ( (only != NULL) && | 400 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
435 | (match == GNUNET_NO) ) | 401 | im->header.size = htons (sizeof (struct InfoMessage) + hs); |
436 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 402 | im->reserved = htonl (0); |
437 | "No `%s' message was found for peer `%4s'\n", | 403 | im->peer = pos->identity; |
438 | "HELLO", | 404 | GNUNET_SERVER_transmit_context_append_message (tc, |
439 | GNUNET_i2s (only)); | 405 | &im->header); |
440 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 406 | return GNUNET_YES; |
441 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | ||
442 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | ||
443 | } | 407 | } |
444 | 408 | ||
445 | 409 | ||
@@ -500,7 +464,6 @@ cron_clean_data_hosts (void *cls, | |||
500 | now = GNUNET_TIME_absolute_get (); | 464 | now = GNUNET_TIME_absolute_get (); |
501 | GNUNET_DISK_directory_scan (networkIdDirectory, | 465 | GNUNET_DISK_directory_scan (networkIdDirectory, |
502 | &discard_hosts_helper, &now); | 466 | &discard_hosts_helper, &now); |
503 | |||
504 | GNUNET_SCHEDULER_add_delayed (tc->sched, | 467 | GNUNET_SCHEDULER_add_delayed (tc->sched, |
505 | DATA_HOST_CLEAN_FREQ, | 468 | DATA_HOST_CLEAN_FREQ, |
506 | &cron_clean_data_hosts, NULL); | 469 | &cron_clean_data_hosts, NULL); |
@@ -553,6 +516,7 @@ handle_get (void *cls, | |||
553 | const struct GNUNET_MessageHeader *message) | 516 | const struct GNUNET_MessageHeader *message) |
554 | { | 517 | { |
555 | const struct ListPeerMessage *lpm; | 518 | const struct ListPeerMessage *lpm; |
519 | struct GNUNET_SERVER_TransmitContext *tc; | ||
556 | 520 | ||
557 | lpm = (const struct ListPeerMessage *) message; | 521 | lpm = (const struct ListPeerMessage *) message; |
558 | #if DEBUG_PEERINFO | 522 | #if DEBUG_PEERINFO |
@@ -561,7 +525,14 @@ handle_get (void *cls, | |||
561 | "GET", | 525 | "GET", |
562 | GNUNET_i2s (&lpm->peer)); | 526 | GNUNET_i2s (&lpm->peer)); |
563 | #endif | 527 | #endif |
564 | send_to_each_host (&lpm->peer, client); | 528 | tc = GNUNET_SERVER_transmit_context_create (client); |
529 | GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, | ||
530 | &lpm->peer.hashPubKey, | ||
531 | &add_to_tc, | ||
532 | tc); | ||
533 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | ||
534 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | ||
535 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | ||
565 | } | 536 | } |
566 | 537 | ||
567 | 538 | ||
@@ -577,12 +548,39 @@ handle_get_all (void *cls, | |||
577 | struct GNUNET_SERVER_Client *client, | 548 | struct GNUNET_SERVER_Client *client, |
578 | const struct GNUNET_MessageHeader *message) | 549 | const struct GNUNET_MessageHeader *message) |
579 | { | 550 | { |
551 | struct GNUNET_SERVER_TransmitContext *tc; | ||
552 | |||
580 | #if DEBUG_PEERINFO | 553 | #if DEBUG_PEERINFO |
581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
582 | "`%s' message received\n", | 555 | "`%s' message received\n", |
583 | "GET_ALL"); | 556 | "GET_ALL"); |
584 | #endif | 557 | #endif |
585 | send_to_each_host (NULL, client); | 558 | tc = GNUNET_SERVER_transmit_context_create (client); |
559 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, | ||
560 | &add_to_tc, | ||
561 | tc); | ||
562 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | ||
563 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | ||
564 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | ||
565 | } | ||
566 | |||
567 | |||
568 | static int | ||
569 | do_notify_entry (void *cls, | ||
570 | const GNUNET_HashCode *key, | ||
571 | void *value) | ||
572 | { | ||
573 | struct GNUNET_SERVER_Client *client = cls; | ||
574 | struct HostEntry *he = value; | ||
575 | struct InfoMessage *msg; | ||
576 | |||
577 | msg = make_info_message (he); | ||
578 | GNUNET_SERVER_notification_context_unicast (notify_list, | ||
579 | client, | ||
580 | &msg->header, | ||
581 | GNUNET_NO); | ||
582 | GNUNET_free (msg); | ||
583 | return GNUNET_YES; | ||
586 | } | 584 | } |
587 | 585 | ||
588 | 586 | ||
@@ -595,12 +593,9 @@ handle_get_all (void *cls, | |||
595 | */ | 593 | */ |
596 | static void | 594 | static void |
597 | handle_notify (void *cls, | 595 | handle_notify (void *cls, |
598 | struct GNUNET_SERVER_Client *client, | 596 | struct GNUNET_SERVER_Client *client, |
599 | const struct GNUNET_MessageHeader *message) | 597 | const struct GNUNET_MessageHeader *message) |
600 | { | 598 | { |
601 | struct InfoMessage *msg; | ||
602 | struct HostEntry *pos; | ||
603 | |||
604 | #if DEBUG_PEERINFO | 599 | #if DEBUG_PEERINFO |
605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
606 | "`%s' message received\n", | 601 | "`%s' message received\n", |
@@ -608,20 +603,22 @@ handle_notify (void *cls, | |||
608 | #endif | 603 | #endif |
609 | GNUNET_SERVER_notification_context_add (notify_list, | 604 | GNUNET_SERVER_notification_context_add (notify_list, |
610 | client); | 605 | client); |
611 | pos = hosts; | 606 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, |
612 | while (NULL != pos) | 607 | &do_notify_entry, |
613 | { | 608 | client); |
614 | msg = make_info_message (pos); | ||
615 | GNUNET_SERVER_notification_context_unicast (notify_list, | ||
616 | client, | ||
617 | &msg->header, | ||
618 | GNUNET_NO); | ||
619 | GNUNET_free (msg); | ||
620 | pos = pos->next; | ||
621 | } | ||
622 | } | 609 | } |
623 | 610 | ||
624 | 611 | ||
612 | static int | ||
613 | free_host_entry (void *cls, | ||
614 | const GNUNET_HashCode *key, | ||
615 | void *value) | ||
616 | { | ||
617 | struct HostEntry *he = value; | ||
618 | GNUNET_free (he); | ||
619 | return GNUNET_YES; | ||
620 | } | ||
621 | |||
625 | /** | 622 | /** |
626 | * Clean up our state. Called during shutdown. | 623 | * Clean up our state. Called during shutdown. |
627 | * | 624 | * |
@@ -634,6 +631,10 @@ shutdown_task (void *cls, | |||
634 | { | 631 | { |
635 | GNUNET_SERVER_notification_context_destroy (notify_list); | 632 | GNUNET_SERVER_notification_context_destroy (notify_list); |
636 | notify_list = NULL; | 633 | notify_list = NULL; |
634 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, | ||
635 | &free_host_entry, | ||
636 | NULL); | ||
637 | GNUNET_CONTAINER_multihashmap_destroy (hostmap); | ||
637 | if (stats != NULL) | 638 | if (stats != NULL) |
638 | { | 639 | { |
639 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 640 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
@@ -666,6 +667,8 @@ run (void *cls, | |||
666 | sizeof (struct GNUNET_MessageHeader)}, | 667 | sizeof (struct GNUNET_MessageHeader)}, |
667 | {NULL, NULL, 0, 0} | 668 | {NULL, NULL, 0, 0} |
668 | }; | 669 | }; |
670 | |||
671 | hostmap = GNUNET_CONTAINER_multihashmap_create (1024); | ||
669 | stats = GNUNET_STATISTICS_create (sched, "peerinfo", cfg); | 672 | stats = GNUNET_STATISTICS_create (sched, "peerinfo", cfg); |
670 | notify_list = GNUNET_SERVER_notification_context_create (server, 0); | 673 | notify_list = GNUNET_SERVER_notification_context_create (server, 0); |
671 | GNUNET_assert (GNUNET_OK == | 674 | GNUNET_assert (GNUNET_OK == |
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c new file mode 100755 index 000000000..1c0df0332 --- /dev/null +++ b/src/peerinfo/perf_peerinfo_api.c | |||
@@ -0,0 +1,217 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2004, 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file peerinfo/test_peerinfo_hammer.c | ||
23 | * @brief testcase for peerinfo_api.c, hopefully hammer the peerinfo service | ||
24 | * @author Nathan Evans | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_hello_lib.h" | ||
29 | #include "gnunet_getopt_lib.h" | ||
30 | #include "gnunet_os_lib.h" | ||
31 | #include "gnunet_peerinfo_service.h" | ||
32 | #include "gnunet_program_lib.h" | ||
33 | #include "gnunet_time_lib.h" | ||
34 | #include "peerinfo.h" | ||
35 | |||
36 | #define START_SERVICE 1 | ||
37 | |||
38 | #define NUM_REQUESTS 5000 | ||
39 | |||
40 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
41 | |||
42 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
43 | |||
44 | static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS]; | ||
45 | |||
46 | static struct GNUNET_PEERINFO_Handle *h; | ||
47 | |||
48 | static unsigned int numpeers; | ||
49 | |||
50 | static int | ||
51 | check_it (void *cls, | ||
52 | const char *tname, | ||
53 | struct GNUNET_TIME_Absolute expiration, | ||
54 | const void *addr, uint16_t addrlen) | ||
55 | { | ||
56 | if (addrlen > 0) | ||
57 | { | ||
58 | #if DEBUG | ||
59 | fprintf (stderr, | ||
60 | "name: %s, addr: %s\n", | ||
61 | tname, | ||
62 | (const char*) addr); | ||
63 | #endif | ||
64 | } | ||
65 | return GNUNET_OK; | ||
66 | } | ||
67 | |||
68 | |||
69 | static size_t | ||
70 | address_generator (void *cls, size_t max, void *buf) | ||
71 | { | ||
72 | size_t *agc = cls; | ||
73 | size_t ret; | ||
74 | char *address; | ||
75 | |||
76 | if (*agc == 0) | ||
77 | return 0; | ||
78 | |||
79 | GNUNET_asprintf(&address, "Address%d", *agc); | ||
80 | |||
81 | ret = GNUNET_HELLO_add_address ("peerinfotest", | ||
82 | GNUNET_TIME_relative_to_absolute | ||
83 | (GNUNET_TIME_UNIT_HOURS), address, strlen(address) + 1, | ||
84 | buf, max); | ||
85 | *agc = 0; | ||
86 | return ret; | ||
87 | } | ||
88 | |||
89 | |||
90 | static void | ||
91 | add_peer (size_t i) | ||
92 | { | ||
93 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; | ||
94 | struct GNUNET_PeerIdentity pid; | ||
95 | struct GNUNET_HELLO_Message *h2; | ||
96 | size_t agc; | ||
97 | |||
98 | agc = 2; | ||
99 | memset (&pkey, i, sizeof (pkey)); | ||
100 | GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); | ||
101 | h2 = GNUNET_HELLO_create (&pkey, &address_generator, &i); | ||
102 | GNUNET_PEERINFO_add_peer (h, h2); | ||
103 | GNUNET_free (h2); | ||
104 | } | ||
105 | |||
106 | |||
107 | static void | ||
108 | process (void *cls, | ||
109 | const struct GNUNET_PeerIdentity *peer, | ||
110 | const struct GNUNET_HELLO_Message *hello) | ||
111 | { | ||
112 | if (peer == NULL) | ||
113 | { | ||
114 | #if DEBUG | ||
115 | fprintf(stderr, "Process received NULL response\n"); | ||
116 | #endif | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | #if DEBUG | ||
121 | fprintf(stderr, "Processed a peer\n"); | ||
122 | #endif | ||
123 | numpeers++; | ||
124 | if (0 && (hello != NULL)) | ||
125 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, NULL); | ||
126 | |||
127 | } | ||
128 | } | ||
129 | |||
130 | |||
131 | static void | ||
132 | run (void *cls, | ||
133 | struct GNUNET_SCHEDULER_Handle *s, | ||
134 | char *const *args, | ||
135 | const char *cfgfile, | ||
136 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
137 | { | ||
138 | size_t i; | ||
139 | sched = s; | ||
140 | cfg = c; | ||
141 | h = GNUNET_PEERINFO_connect (sched, cfg); | ||
142 | |||
143 | for (i = 0; i < NUM_REQUESTS; i++) | ||
144 | { | ||
145 | add_peer (i); | ||
146 | ic[i] = GNUNET_PEERINFO_iterate (h, | ||
147 | NULL, | ||
148 | GNUNET_TIME_relative_multiply | ||
149 | (GNUNET_TIME_UNIT_SECONDS, 30), | ||
150 | &process, cls); | ||
151 | } | ||
152 | fprintf (stderr, | ||
153 | "Issued %u requests\n", | ||
154 | NUM_REQUESTS); | ||
155 | } | ||
156 | |||
157 | static int | ||
158 | check () | ||
159 | { | ||
160 | int ok = 3; | ||
161 | char *const argv[] = { "test-peerinfo-hammer", | ||
162 | "-c", | ||
163 | "test_peerinfo_api_data.conf", | ||
164 | #if DEBUG_PEERINFO | ||
165 | "-L", "DEBUG", | ||
166 | #endif | ||
167 | NULL | ||
168 | }; | ||
169 | #if START_SERVICE | ||
170 | pid_t pid; | ||
171 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
172 | GNUNET_GETOPT_OPTION_END | ||
173 | }; | ||
174 | pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", | ||
175 | "gnunet-service-peerinfo", | ||
176 | #if DEBUG_PEERINFO | ||
177 | "-L", "DEBUG", | ||
178 | #endif | ||
179 | "-c", "test_peerinfo_api_data.conf", NULL); | ||
180 | #endif | ||
181 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | ||
182 | argv, "test-peerinfo-api", "nohelp", | ||
183 | options, &run, &ok); | ||
184 | fprintf (stderr, | ||
185 | "Processed %u/%u peers\n", | ||
186 | numpeers, | ||
187 | NUM_REQUESTS); | ||
188 | #if START_SERVICE | ||
189 | if (0 != PLIBC_KILL (pid, SIGTERM)) | ||
190 | { | ||
191 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
192 | ok = 1; | ||
193 | } | ||
194 | GNUNET_OS_process_wait(pid); | ||
195 | #endif | ||
196 | return ok; | ||
197 | } | ||
198 | |||
199 | |||
200 | int | ||
201 | main (int argc, char *argv[]) | ||
202 | { | ||
203 | int ret = 0; | ||
204 | |||
205 | GNUNET_log_setup ("test_peerinfo_api", | ||
206 | #if DEBUG_PEERINFO | ||
207 | "DEBUG", | ||
208 | #else | ||
209 | "WARNING", | ||
210 | #endif | ||
211 | NULL); | ||
212 | ret = check (); | ||
213 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo"); | ||
214 | return ret; | ||
215 | } | ||
216 | |||
217 | /* end of test_peerinfo_hammer.c */ | ||
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 47304d549..a3c2c99eb 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c | |||
@@ -208,7 +208,7 @@ main (int argc, char *argv[]) | |||
208 | #endif | 208 | #endif |
209 | NULL); | 209 | NULL); |
210 | ret = check (); | 210 | ret = check (); |
211 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-peerinfo"); | 211 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo"); |
212 | return ret; | 212 | return ret; |
213 | } | 213 | } |
214 | 214 | ||
diff --git a/src/peerinfo/test_peerinfo_api_data.conf b/src/peerinfo/test_peerinfo_api_data.conf index a81ffccb9..998df571a 100644 --- a/src/peerinfo/test_peerinfo_api_data.conf +++ b/src/peerinfo/test_peerinfo_api_data.conf | |||
@@ -1,5 +1,6 @@ | |||
1 | [PATHS] | 1 | [PATHS] |
2 | SERVICEHOME = /tmp/test-gnunetd-peerinfo/ | 2 | SERVICEHOME = /tmp/test-gnunet-peerinfo/ |
3 | 3 | ||
4 | [peerinfo] | 4 | [peerinfo] |
5 | PORT = 22354 | 5 | PORT = 22354 |
6 | DEBUG = NO | ||