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.c97
1 files changed, 60 insertions, 37 deletions
diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c
index 5c08293a4..77b6f36dd 100644
--- a/src/arm/test_gnunet_service_arm.c
+++ b/src/arm/test_gnunet_service_arm.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -40,14 +40,16 @@
40 40
41static int ret = 1; 41static int ret = 1;
42 42
43static int resolved_ok = 0; 43static int resolved_ok;
44 44
45static int asked_for_a_list = 0; 45static int asked_for_a_list;
46 46
47static struct GNUNET_ARM_Handle *arm; 47static struct GNUNET_ARM_Handle *arm;
48 48
49
49static void 50static void
50trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 51trigger_disconnect (void *cls,
52 const struct GNUNET_SCHEDULER_TaskContext *tc)
51{ 53{
52 GNUNET_ARM_disconnect_and_free (arm); 54 GNUNET_ARM_disconnect_and_free (arm);
53 arm = NULL; 55 arm = NULL;
@@ -71,40 +73,52 @@ arm_stop_cb (void *cls,
71static void 73static void
72service_list (void *cls, 74service_list (void *cls,
73 enum GNUNET_ARM_RequestStatus rs, 75 enum GNUNET_ARM_RequestStatus rs,
74 unsigned int count, const char *const*list) 76 unsigned int count,
77 const char *const*list)
75{ 78{
79 unsigned int i;
80
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
77 "%u services are are currently running\n", 82 "%u services are are currently running\n",
78 count); 83 count);
79 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 84 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
80 goto stop_arm; 85 goto stop_arm;
81 if (1 == count) 86 for (i=0;i<count;i++)
82 { 87 {
83 GNUNET_break (0 == strcasecmp (list[0], "resolver (gnunet-service-resolver)")); 88 if (0 == strcasecmp (list[i],
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got service list, now stopping arm\n"); 89 "resolver (gnunet-service-resolver)"));
85 ret = 0; 90 {
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
92 "Got service list, now stopping arm\n");
93 ret = 0;
94 }
86 } 95 }
87 96
88 stop_arm: 97 stop_arm:
89 GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL); 98 GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT,
99 &arm_stop_cb, NULL);
90} 100}
91 101
92 102
93static void 103static void
94hostNameResolveCB (void *cls, const struct sockaddr *addr, socklen_t addrlen) 104hostNameResolveCB (void *cls,
105 const struct sockaddr *addr,
106 socklen_t addrlen)
95{ 107{
96 if ((ret == 0) || (ret == 4) || (resolved_ok == 1)) 108 if ((ret == 0) || (ret == 4) || (resolved_ok == 1))
97 return; 109 return;
98 if (NULL == addr) 110 if (NULL == addr)
99 { 111 {
100 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Name not resolved!\n"); 112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
113 "Name not resolved!\n");
101 ret = 3; 114 ret = 3;
102 GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL); 115 GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT,
116 &arm_stop_cb, NULL);
103 } 117 }
104 else if (asked_for_a_list == 0) 118 else if (asked_for_a_list == 0)
105 { 119 {
106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
107 "Resolved hostname, now checking the service list\n"); 121 "Resolved hostname, now checking the service list\n");
108 GNUNET_ARM_request_service_list (arm, TIMEOUT, service_list, NULL); 122 GNUNET_ARM_request_service_list (arm, TIMEOUT, service_list, NULL);
109 asked_for_a_list = 1; 123 asked_for_a_list = 1;
110 resolved_ok = 1; 124 resolved_ok = 1;
@@ -121,21 +135,26 @@ arm_start_cb (void *cls,
121 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); 135 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
122 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); 136 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
124 "Trying to resolve our own hostname!\n"); 138 "Trying to resolve our own hostname!\n");
125 /* connect to the resolver service */ 139 /* connect to the resolver service */
126 if (NULL == GNUNET_RESOLVER_hostname_resolve ( 140 if (NULL ==
127 AF_UNSPEC, TIMEOUT, &hostNameResolveCB, NULL)) 141 GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, TIMEOUT,
142 &hostNameResolveCB, NULL))
128 { 143 {
129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 144 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
130 "Unable initiate connection to resolver service\n"); 145 "Unable initiate connection to resolver service\n");
131 ret = 2; 146 ret = 2;
132 GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL); 147 GNUNET_ARM_request_service_stop (arm,
148 "arm", TIMEOUT,
149 &arm_stop_cb, NULL);
133 } 150 }
134} 151}
135 152
136 153
137static void 154static void
138run (void *cls, char *const *args, const char *cfgfile, 155run (void *cls,
156 char *const *args,
157 const char *cfgfile,
139 const struct GNUNET_CONFIGURATION_Handle *c) 158 const struct GNUNET_CONFIGURATION_Handle *c)
140{ 159{
141 char *armconfig; 160 char *armconfig;
@@ -144,10 +163,10 @@ run (void *cls, char *const *args, const char *cfgfile,
144 { 163 {
145 if (GNUNET_OK != 164 if (GNUNET_OK !=
146 GNUNET_CONFIGURATION_get_value_filename (c, "arm", "CONFIG", 165 GNUNET_CONFIGURATION_get_value_filename (c, "arm", "CONFIG",
147 &armconfig)) 166 &armconfig))
148 { 167 {
149 GNUNET_CONFIGURATION_set_value_string ((struct GNUNET_CONFIGURATION_Handle 168 GNUNET_CONFIGURATION_set_value_string ((struct GNUNET_CONFIGURATION_Handle *) c,
150 *) c, "arm", "CONFIG", 169 "arm", "CONFIG",
151 cfgfile); 170 cfgfile);
152 } 171 }
153 else 172 else
@@ -155,7 +174,9 @@ run (void *cls, char *const *args, const char *cfgfile,
155 } 174 }
156 arm = GNUNET_ARM_connect (c, NULL, NULL); 175 arm = GNUNET_ARM_connect (c, NULL, NULL);
157 GNUNET_ARM_request_service_start (arm, "arm", 176 GNUNET_ARM_request_service_start (arm, "arm",
158 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL); 177 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
178 START_TIMEOUT,
179 &arm_start_cb, NULL);
159} 180}
160 181
161 182
@@ -173,27 +194,29 @@ main (int argc, char *av[])
173 char hostname[GNUNET_OS_get_hostname_max_length () + 1]; 194 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
174 195
175 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 196 if (0 != gethostname (hostname, sizeof (hostname) - 1))
176 { 197 {
177 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 198 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
178 "gethostname"); 199 "gethostname");
179 FPRINTF (stderr, 200 FPRINTF (stderr,
180 "%s", "Failed to determine my own hostname, testcase not run.\n"); 201 "%s",
181 return 0; 202 "Failed to determine my own hostname, testcase not run.\n");
182 } 203 return 0;
204 }
183 if (NULL == gethostbyname (hostname)) 205 if (NULL == gethostbyname (hostname))
184 { 206 {
185 FPRINTF (stderr, 207 FPRINTF (stderr,
186 "Failed to resolve my hostname `%s', testcase not run.\n", 208 "Failed to resolve my hostname `%s', testcase not run.\n",
187 hostname); 209 hostname);
188 return 0; 210 return 0;
189 } 211 }
190 GNUNET_log_setup ("test-gnunet-service-arm", 212 GNUNET_log_setup ("test-gnunet-service-arm",
191 "WARNING", 213 "WARNING",
192 NULL); 214 NULL);
193 GNUNET_break (GNUNET_OK == 215 GNUNET_break (GNUNET_OK ==
194 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 216 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
195 argv, "test-gnunet-service-arm", 217 argv, "test-gnunet-service-arm",
196 "nohelp", options, &run, NULL)); 218 "nohelp", options,
219 &run, NULL));
197 return ret; 220 return ret;
198} 221}
199 222