aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/peerinfo/Makefile.am9
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c4
-rw-r--r--src/peerinfo/test_peerinfo_shipped_hellos.c118
3 files changed, 129 insertions, 2 deletions
diff --git a/src/peerinfo/Makefile.am b/src/peerinfo/Makefile.am
index 89ce66a26..c3863ab65 100644
--- a/src/peerinfo/Makefile.am
+++ b/src/peerinfo/Makefile.am
@@ -47,6 +47,7 @@ if HAVE_BENCHMARKS
47endif 47endif
48 48
49check_PROGRAMS = \ 49check_PROGRAMS = \
50 test_peerinfo_shipped_hellos \
50 test_peerinfo_api \ 51 test_peerinfo_api \
51 test_peerinfo_api_friend_only \ 52 test_peerinfo_api_friend_only \
52 test_peerinfo_api_notify_friend_only \ 53 test_peerinfo_api_notify_friend_only \
@@ -56,6 +57,14 @@ if ENABLE_TEST_RUN
56TESTS = $(check_PROGRAMS) 57TESTS = $(check_PROGRAMS)
57endif 58endif
58 59
60test_peerinfo_shipped_hellos_SOURCES = \
61 test_peerinfo_shipped_hellos.c
62test_peerinfo_shipped_hellos_LDADD = \
63 $(top_builddir)/src/hello/libgnunethello.la \
64 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
65 $(top_builddir)/src/testing/libgnunettesting.la \
66 $(top_builddir)/src/util/libgnunetutil.la
67
59test_peerinfo_api_SOURCES = \ 68test_peerinfo_api_SOURCES = \
60 test_peerinfo_api.c 69 test_peerinfo_api.c
61test_peerinfo_api_LDADD = \ 70test_peerinfo_api_LDADD = \
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index a66dd02e1..309b954f1 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -341,7 +341,7 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext *
341 return; 341 return;
342 342
343 size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); 343 size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
344 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Read %u bytes from `%s'\n", size_total, fn); 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from `%s'\n", size_total, fn);
345 if (size_total < sizeof (struct GNUNET_MessageHeader)) 345 if (size_total < sizeof (struct GNUNET_MessageHeader))
346 { 346 {
347 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 347 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -546,7 +546,7 @@ hosts_directory_scan_callback (void *cls, const char *fullname)
546 filename = fullname; 546 filename = fullname;
547 else 547 else
548 filename ++; 548 filename ++;
549 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Reading `%s'\n", filename); 549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reading `%s'\n", filename);
550 550
551 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) 551 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey))
552 { 552 {
diff --git a/src/peerinfo/test_peerinfo_shipped_hellos.c b/src/peerinfo/test_peerinfo_shipped_hellos.c
new file mode 100644
index 000000000..e8cbd519d
--- /dev/null
+++ b/src/peerinfo/test_peerinfo_shipped_hellos.c
@@ -0,0 +1,118 @@
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_api.c
23 * @brief testcase for shipped HELLOs getting parsed
24 * @author Christian Grothoff
25 * @author Matthias Wachs
26 *
27 */
28#include "platform.h"
29#include "gnunet_hello_lib.h"
30#include "gnunet_util_lib.h"
31#include "gnunet_peerinfo_service.h"
32#include "gnunet_testing_lib.h"
33#include "peerinfo.h"
34
35static struct GNUNET_PEERINFO_IteratorContext *ic;
36
37static struct GNUNET_PEERINFO_Handle *h;
38
39static int global_ret;
40
41static int
42addr_cb (void *cls,
43 const struct GNUNET_HELLO_Address *address,
44 struct GNUNET_TIME_Absolute expiration)
45{;
46 int *addr = cls;
47 (*addr) ++;
48 return GNUNET_OK;
49}
50
51static void
52process (void *cls, const struct GNUNET_PeerIdentity *peer,
53 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
54{
55 static unsigned int calls = 0;
56 int addr;
57
58 if (err_msg != NULL)
59 {
60 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
61 _("Error in communication with PEERINFO service\n"));
62 }
63 if (NULL != peer)
64 {
65 addr = 0;
66 if (NULL != hello)
67 {
68 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &addr_cb, &addr);
69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got information about peer `%s' with %u addresses \n",
70 GNUNET_i2s (peer), addr);
71 calls++;
72 }
73 else
74 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail: Got information about peer `%s' without HELLO \n",
75 GNUNET_i2s (peer));
76 }
77 else
78 {
79 if (0 == calls)
80 {
81 fprintf (stderr, "Failed: %u callbacks\n", calls);
82 global_ret = 1;
83 }
84 else
85 {
86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed: %u callbacks\n", calls);
87 global_ret = 0;
88 }
89 }
90}
91
92
93static void
94run (void *cls,
95 const struct GNUNET_CONFIGURATION_Handle *cfg,
96 struct GNUNET_TESTING_Peer *peer)
97{
98 h = GNUNET_PEERINFO_connect (cfg);
99 GNUNET_assert (NULL != h);
100 ic = GNUNET_PEERINFO_iterate (h, GNUNET_YES, NULL,
101 GNUNET_TIME_relative_multiply
102 (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls);
103}
104
105
106int
107main (int argc, char *argv[])
108{
109 global_ret = 3;
110 if (0 != GNUNET_TESTING_service_run ("test_peerinfo_system_hellos",
111 "peerinfo",
112 "test_peerinfo_api_data.conf",
113 &run, NULL))
114 return 1;
115 return global_ret;
116}
117
118/* end of test_peerinfo_shipped_hellos.c */