aboutsummaryrefslogtreecommitdiff
path: root/src/arm/test_gnunet_service_arm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/test_gnunet_service_arm.c')
-rw-r--r--src/arm/test_gnunet_service_arm.c252
1 files changed, 126 insertions, 126 deletions
diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c
index 9508581de..8c8c664f9 100644
--- a/src/arm/test_gnunet_service_arm.c
+++ b/src/arm/test_gnunet_service_arm.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 * @file arm/test_gnunet_service_arm.c 21 * @file arm/test_gnunet_service_arm.c
22 * @brief testcase for gnunet-service-arm.c; tests ARM by making it start the resolver 22 * @brief testcase for gnunet-service-arm.c; tests ARM by making it start the resolver
@@ -34,9 +34,9 @@
34 * (by checking if running before starting, so really this time is always waited on 34 * (by checking if running before starting, so really this time is always waited on
35 * startup (annoying)). 35 * startup (annoying)).
36 */ 36 */
37#define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50) 37#define START_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50)
38 38
39#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 39#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
40 40
41 41
42static int ret = 1; 42static int ret = 1;
@@ -51,141 +51,141 @@ static const char hostname[] = "www.gnu.org"; /* any domain should do */
51 51
52 52
53static void 53static void
54trigger_disconnect (void *cls) 54trigger_disconnect(void *cls)
55{ 55{
56 GNUNET_ARM_disconnect (arm); 56 GNUNET_ARM_disconnect(arm);
57 arm = NULL; 57 arm = NULL;
58} 58}
59 59
60 60
61static void 61static void
62arm_stop_cb (void *cls, 62arm_stop_cb(void *cls,
63 enum GNUNET_ARM_RequestStatus status, 63 enum GNUNET_ARM_RequestStatus status,
64 enum GNUNET_ARM_Result result) 64 enum GNUNET_ARM_Result result)
65{ 65{
66 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); 66 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
67 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); 67 GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED);
68 if (result != GNUNET_ARM_RESULT_STOPPED) 68 if (result != GNUNET_ARM_RESULT_STOPPED)
69 { 69 {
70 GNUNET_break (0); 70 GNUNET_break(0);
71 ret = 4; 71 ret = 4;
72 } 72 }
73 GNUNET_SCHEDULER_add_now (&trigger_disconnect, NULL); 73 GNUNET_SCHEDULER_add_now(&trigger_disconnect, NULL);
74} 74}
75 75
76 76
77static void 77static void
78service_list (void *cls, 78service_list(void *cls,
79 enum GNUNET_ARM_RequestStatus rs, 79 enum GNUNET_ARM_RequestStatus rs,
80 unsigned int count, 80 unsigned int count,
81 const char *const*list) 81 const char *const*list)
82{ 82{
83 unsigned int i; 83 unsigned int i;
84 84
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 85 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
86 "%u services are are currently running\n", 86 "%u services are are currently running\n",
87 count); 87 count);
88 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 88 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
89 goto stop_arm; 89 goto stop_arm;
90 for (i=0;i<count;i++) 90 for (i = 0; i < count; i++)
91 {
92 if (0 == strcasecmp (list[i],
93 "resolver (gnunet-service-resolver)"))
94 { 91 {
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 92 if (0 == strcasecmp(list[i],
96 "Got service list, now stopping arm\n"); 93 "resolver (gnunet-service-resolver)"))
97 ret = 0; 94 {
95 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
96 "Got service list, now stopping arm\n");
97 ret = 0;
98 }
98 } 99 }
99 }
100 100
101 stop_arm: 101stop_arm:
102 GNUNET_ARM_request_service_stop (arm, 102 GNUNET_ARM_request_service_stop(arm,
103 "arm", 103 "arm",
104 &arm_stop_cb, 104 &arm_stop_cb,
105 NULL); 105 NULL);
106} 106}
107 107
108 108
109static void 109static void
110hostname_resolve_cb (void *cls, 110hostname_resolve_cb(void *cls,
111 const struct sockaddr *addr, 111 const struct sockaddr *addr,
112 socklen_t addrlen) 112 socklen_t addrlen)
113{ 113{
114 if ((0 == ret) || (4 == ret) || (1 == resolved_ok)) 114 if ((0 == ret) || (4 == ret) || (1 == resolved_ok))
115 return; 115 return;
116 if (NULL == addr) 116 if (NULL == addr)
117 { 117 {
118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 118 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
119 "Failed to resolve hostname!\n"); 119 "Failed to resolve hostname!\n");
120 GNUNET_break (0); 120 GNUNET_break(0);
121 ret = 3; 121 ret = 3;
122 GNUNET_ARM_request_service_stop (arm, 122 GNUNET_ARM_request_service_stop(arm,
123 "arm", 123 "arm",
124 &arm_stop_cb, 124 &arm_stop_cb,
125 NULL); 125 NULL);
126 return; 126 return;
127 } 127 }
128 if (0 == asked_for_a_list) 128 if (0 == asked_for_a_list)
129 { 129 {
130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 130 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
131 "Resolved hostname, now checking the service list\n"); 131 "Resolved hostname, now checking the service list\n");
132 GNUNET_ARM_request_service_list (arm, 132 GNUNET_ARM_request_service_list(arm,
133 &service_list, 133 &service_list,
134 NULL); 134 NULL);
135 asked_for_a_list = 1; 135 asked_for_a_list = 1;
136 resolved_ok = 1; 136 resolved_ok = 1;
137 } 137 }
138} 138}
139 139
140 140
141static void 141static void
142arm_start_cb (void *cls, 142arm_start_cb(void *cls,
143 enum GNUNET_ARM_RequestStatus status, 143 enum GNUNET_ARM_RequestStatus status,
144 enum GNUNET_ARM_Result result) 144 enum GNUNET_ARM_Result result)
145{ 145{
146 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); 146 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK);
147 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); 147 GNUNET_break(result == GNUNET_ARM_RESULT_STARTING);
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 148 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
149 "Trying to resolve a hostname via the resolver service!\n"); 149 "Trying to resolve a hostname via the resolver service!\n");
150 /* connect to the resolver service */ 150 /* connect to the resolver service */
151 if (NULL == 151 if (NULL ==
152 GNUNET_RESOLVER_ip_get (hostname, 152 GNUNET_RESOLVER_ip_get(hostname,
153 AF_UNSPEC, 153 AF_UNSPEC,
154 TIMEOUT, 154 TIMEOUT,
155 &hostname_resolve_cb, 155 &hostname_resolve_cb,
156 NULL)) 156 NULL))
157 { 157 {
158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 158 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
159 "Unable initiate connection to resolver service\n"); 159 "Unable initiate connection to resolver service\n");
160 GNUNET_break (0); 160 GNUNET_break(0);
161 ret = 2; 161 ret = 2;
162 GNUNET_ARM_request_service_stop (arm, 162 GNUNET_ARM_request_service_stop(arm,
163 "arm", 163 "arm",
164 &arm_stop_cb, 164 &arm_stop_cb,
165 NULL); 165 NULL);
166 } 166 }
167} 167}
168 168
169 169
170static void 170static void
171run (void *cls, 171run(void *cls,
172 char *const *args, 172 char *const *args,
173 const char *cfgfile, 173 const char *cfgfile,
174 const struct GNUNET_CONFIGURATION_Handle *c) 174 const struct GNUNET_CONFIGURATION_Handle *c)
175{ 175{
176 arm = GNUNET_ARM_connect (c, 176 arm = GNUNET_ARM_connect(c,
177 NULL, 177 NULL,
178 NULL); 178 NULL);
179 GNUNET_ARM_request_service_start (arm, 179 GNUNET_ARM_request_service_start(arm,
180 "arm", 180 "arm",
181 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 181 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
182 &arm_start_cb, 182 &arm_start_cb,
183 NULL); 183 NULL);
184} 184}
185 185
186 186
187int 187int
188main (int argc, char *av[]) 188main(int argc, char *av[])
189{ 189{
190 static char *const argv[] = { 190 static char *const argv[] = {
191 "test-gnunet-service-arm", 191 "test-gnunet-service-arm",
@@ -203,27 +203,27 @@ main (int argc, char *av[])
203 struct addrinfo *ai; 203 struct addrinfo *ai;
204 int ret; 204 int ret;
205 205
206 if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai))) 206 if (0 != (ret = getaddrinfo(hostname, NULL, NULL, &ai)))
207 { 207 {
208 fprintf (stderr, 208 fprintf(stderr,
209 "Failed to resolve `%s', testcase not run.\n", 209 "Failed to resolve `%s', testcase not run.\n",
210 hostname); 210 hostname);
211 return 77; 211 return 77;
212 } 212 }
213 freeaddrinfo (ai); 213 freeaddrinfo(ai);
214 } 214 }
215#elif HAVE_GETHOSTBYNAME2 215#elif HAVE_GETHOSTBYNAME2
216 { 216 {
217 struct hostent *host; 217 struct hostent *host;
218 218
219 host = gethostbyname2 (hostname, AF_INET); 219 host = gethostbyname2(hostname, AF_INET);
220 if (NULL == host) 220 if (NULL == host)
221 host = gethostbyname2 (hostname, AF_INET6); 221 host = gethostbyname2(hostname, AF_INET6);
222 if (NULL == host) 222 if (NULL == host)
223 { 223 {
224 fprintf (stderr, 224 fprintf(stderr,
225 "Failed to resolve `%s', testcase not run.\n", 225 "Failed to resolve `%s', testcase not run.\n",
226 hostname); 226 hostname);
227 return 77; 227 return 77;
228 } 228 }
229 } 229 }
@@ -231,34 +231,34 @@ main (int argc, char *av[])
231 { 231 {
232 struct hostent *host; 232 struct hostent *host;
233 233
234 host = gethostbyname (hostname); 234 host = gethostbyname(hostname);
235 if (NULL == host) 235 if (NULL == host)
236 { 236 {
237 fprintf (stderr, 237 fprintf(stderr,
238 "Failed to resolve `%s', testcase not run.\n", 238 "Failed to resolve `%s', testcase not run.\n",
239 hostname); 239 hostname);
240 return 77; 240 return 77;
241 } 241 }
242 } 242 }
243#else 243#else
244 fprintf (stderr, 244 fprintf(stderr,
245 "libc fails to have resolver function, testcase not run.\n"); 245 "libc fails to have resolver function, testcase not run.\n");
246 return 77; 246 return 77;
247#endif 247#endif
248 GNUNET_log_setup ("test-gnunet-service-arm", 248 GNUNET_log_setup("test-gnunet-service-arm",
249 "WARNING", 249 "WARNING",
250 NULL); 250 NULL);
251 GNUNET_break (GNUNET_OK == 251 GNUNET_break(GNUNET_OK ==
252 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 252 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
253 argv, "test-gnunet-service-arm", 253 argv, "test-gnunet-service-arm",
254 "nohelp", options, 254 "nohelp", options,
255 &run, NULL)); 255 &run, NULL));
256 if (0 != ret) 256 if (0 != ret)
257 { 257 {
258 fprintf (stderr, 258 fprintf(stderr,
259 "Test failed with error code %d\n", 259 "Test failed with error code %d\n",
260 ret); 260 ret);
261 } 261 }
262 return ret; 262 return ret;
263} 263}
264 264