diff options
Diffstat (limited to 'src/peerinfo/test_peerinfo_shipped_hellos.c')
-rw-r--r-- | src/peerinfo/test_peerinfo_shipped_hellos.c | 144 |
1 files changed, 0 insertions, 144 deletions
diff --git a/src/peerinfo/test_peerinfo_shipped_hellos.c b/src/peerinfo/test_peerinfo_shipped_hellos.c deleted file mode 100644 index 45ea73be6..000000000 --- a/src/peerinfo/test_peerinfo_shipped_hellos.c +++ /dev/null | |||
@@ -1,144 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2004, 2009 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file peerinfo/test_peerinfo_shipped_hellos.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 | |||
35 | static struct GNUNET_PEERINFO_IteratorContext *ic; | ||
36 | |||
37 | static struct GNUNET_PEERINFO_Handle *h; | ||
38 | |||
39 | static int global_ret; | ||
40 | |||
41 | |||
42 | static int | ||
43 | addr_cb (void *cls, | ||
44 | const struct GNUNET_HELLO_Address *address, | ||
45 | struct GNUNET_TIME_Absolute expiration) | ||
46 | { | ||
47 | unsigned int *addr = cls; | ||
48 | |||
49 | (*addr)++; | ||
50 | return GNUNET_OK; | ||
51 | } | ||
52 | |||
53 | |||
54 | static void | ||
55 | process (void *cls, | ||
56 | const struct GNUNET_PeerIdentity *peer, | ||
57 | const struct GNUNET_HELLO_Message *hello, | ||
58 | const char *err_msg) | ||
59 | { | ||
60 | static unsigned int calls = 0; | ||
61 | unsigned int addr; | ||
62 | |||
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 | { | ||
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 | } | ||
90 | } | ||
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 | { | ||
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 | } | ||
110 | } | ||
111 | } | ||
112 | |||
113 | |||
114 | static void | ||
115 | run (void *cls, | ||
116 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
117 | struct GNUNET_TESTING_Peer *peer) | ||
118 | { | ||
119 | h = GNUNET_PEERINFO_connect (cfg); | ||
120 | GNUNET_assert (NULL != h); | ||
121 | ic = GNUNET_PEERINFO_iterate (h, | ||
122 | GNUNET_YES, | ||
123 | NULL, | ||
124 | &process, | ||
125 | cls); | ||
126 | GNUNET_assert (NULL != ic); | ||
127 | } | ||
128 | |||
129 | |||
130 | int | ||
131 | main (int argc, | ||
132 | char *argv[]) | ||
133 | { | ||
134 | global_ret = 3; | ||
135 | if (0 != GNUNET_TESTING_service_run ("test_peerinfo_shipped_hellos", | ||
136 | "peerinfo", | ||
137 | "test_peerinfo_api_data.conf", | ||
138 | &run, NULL)) | ||
139 | return 1; | ||
140 | return global_ret; | ||
141 | } | ||
142 | |||
143 | |||
144 | /* end of test_peerinfo_shipped_hellos.c */ | ||