aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/test_gnunet_daemon_hostlist.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-04-28 19:32:10 +0200
committerChristian Grothoff <christian@grothoff.org>2019-04-28 19:32:20 +0200
commit3f945e6798d8d736ceb104b59ea1269a7abdfe8a (patch)
treeb93e3dc99deda0987e85cb256b3903de8bd74853 /src/hostlist/test_gnunet_daemon_hostlist.c
parent1227fc30369a55b82e77d35d8d128090e37dd437 (diff)
downloadgnunet-3f945e6798d8d736ceb104b59ea1269a7abdfe8a.tar.gz
gnunet-3f945e6798d8d736ceb104b59ea1269a7abdfe8a.zip
towards flow control in TNG
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist.c')
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist.c124
1 files changed, 49 insertions, 75 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c
index 1bcf4e86a..557b91d1c 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist.c
@@ -11,7 +11,7 @@
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
@@ -26,7 +26,6 @@
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
27#include "gnunet_arm_service.h" 27#include "gnunet_arm_service.h"
28#include "gnunet_transport_service.h" 28#include "gnunet_transport_service.h"
29#include "gnunet_transport_core_service.h"
30#include "gnunet_transport_hello_service.h" 29#include "gnunet_transport_hello_service.h"
31 30
32 31
@@ -103,26 +102,23 @@ timeout_error (void *cls)
103 */ 102 */
104static void * 103static void *
105notify_connect (void *cls, 104notify_connect (void *cls,
106 const struct GNUNET_PeerIdentity *peer, 105 const struct GNUNET_PeerIdentity *peer,
107 struct GNUNET_MQ_Handle *mq) 106 struct GNUNET_MQ_Handle *mq)
108{ 107{
109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
110 "Peers connected, shutting down.\n");
111 ok = 0; 109 ok = 0;
112 if (NULL != timeout_task) 110 if (NULL != timeout_task)
113 { 111 {
114 GNUNET_SCHEDULER_cancel (timeout_task); 112 GNUNET_SCHEDULER_cancel (timeout_task);
115 timeout_task = NULL; 113 timeout_task = NULL;
116 } 114 }
117 GNUNET_SCHEDULER_add_now (&clean_up, 115 GNUNET_SCHEDULER_add_now (&clean_up, NULL);
118 NULL);
119 return NULL; 116 return NULL;
120} 117}
121 118
122 119
123static void 120static void
124process_hello (void *cls, 121process_hello (void *cls, const struct GNUNET_MessageHeader *message)
125 const struct GNUNET_MessageHeader *message)
126{ 122{
127 struct PeerContext *p = cls; 123 struct PeerContext *p = cls;
128 124
@@ -134,39 +130,35 @@ process_hello (void *cls,
134 130
135 131
136static void 132static void
137setup_peer (struct PeerContext *p, 133setup_peer (struct PeerContext *p, const char *cfgname)
138 const char *cfgname)
139{ 134{
140 char *binary; 135 char *binary;
141 136
142 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 137 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
143 p->cfg = GNUNET_CONFIGURATION_create (); 138 p->cfg = GNUNET_CONFIGURATION_create ();
144 p->arm_proc = 139 p->arm_proc = GNUNET_OS_start_process (GNUNET_YES,
145 GNUNET_OS_start_process (GNUNET_YES, 140 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
146 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 141 NULL,
147 NULL, 142 NULL,
148 NULL, 143 NULL,
149 NULL, 144 binary,
150 binary, 145 "gnunet-service-arm",
151 "gnunet-service-arm", 146 "-c",
152 "-c", 147 cfgname,
153 cfgname, 148 NULL);
154 NULL); 149 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
155 GNUNET_assert (GNUNET_OK ==
156 GNUNET_CONFIGURATION_load (p->cfg,
157 cfgname));
158 p->th = GNUNET_TRANSPORT_core_connect (p->cfg, 150 p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
159 NULL, 151 NULL,
160 NULL, 152 NULL,
161 p, 153 p,
162 &notify_connect, 154 &notify_connect,
163 NULL, 155 NULL,
164 NULL); 156 NULL);
165 GNUNET_assert (NULL != p->th); 157 GNUNET_assert (NULL != p->th);
166 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 158 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
167 GNUNET_TRANSPORT_AC_ANY, 159 GNUNET_TRANSPORT_AC_ANY,
168 &process_hello, 160 &process_hello,
169 p); 161 p);
170 GNUNET_free (binary); 162 GNUNET_free (binary);
171} 163}
172 164
@@ -176,18 +168,13 @@ waitpid_task (void *cls)
176{ 168{
177 struct PeerContext *p = cls; 169 struct PeerContext *p = cls;
178 170
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n");
172 if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG))
173 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
174 if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc))
175 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
180 "Killing ARM process.\n"); 177 "ARM process %u stopped\n",
181 if (0 != GNUNET_OS_process_kill (p->arm_proc,
182 GNUNET_TERM_SIG))
183 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
184 "kill");
185 if (GNUNET_OK !=
186 GNUNET_OS_process_wait (p->arm_proc))
187 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
188 "waitpid");
189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
190 "ARM process %u stopped\n",
191 GNUNET_OS_process_get_pid (p->arm_proc)); 178 GNUNET_OS_process_get_pid (p->arm_proc));
192 GNUNET_OS_process_destroy (p->arm_proc); 179 GNUNET_OS_process_destroy (p->arm_proc);
193 p->arm_proc = NULL; 180 p->arm_proc = NULL;
@@ -198,11 +185,8 @@ waitpid_task (void *cls)
198static void 185static void
199stop_arm (struct PeerContext *p) 186stop_arm (struct PeerContext *p)
200{ 187{
201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
202 "Asking ARM to stop core service\n"); 189 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
203 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
204 &waitpid_task,
205 p);
206} 190}
207 191
208 192
@@ -225,36 +209,28 @@ run (void *cls,
225{ 209{
226 GNUNET_assert (ok == 1); 210 GNUNET_assert (ok == 1);
227 ok++; 211 ok++;
228 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 212 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
229 &timeout_error, 213 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
230 NULL); 214 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
231 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 215 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
232 NULL);
233 setup_peer (&p1,
234 "test_gnunet_daemon_hostlist_peer1.conf");
235 setup_peer (&p2,
236 "test_gnunet_daemon_hostlist_peer2.conf");
237} 216}
238 217
239 218
240static int 219static int
241check () 220check ()
242{ 221{
243 char *const argv[] = { 222 char *const argv[] = {"test-gnunet-daemon-hostlist",
244 "test-gnunet-daemon-hostlist", 223 "-c",
245 "-c", "test_gnunet_daemon_hostlist_data.conf", 224 "test_gnunet_daemon_hostlist_data.conf",
246 NULL 225 NULL};
247 }; 226 struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END};
248 struct GNUNET_GETOPT_CommandLineOption options[] = {
249 GNUNET_GETOPT_OPTION_END
250 };
251 ok = 1; 227 ok = 1;
252 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 228 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
253 argv, 229 argv,
254 "test-gnunet-daemon-hostlist", 230 "test-gnunet-daemon-hostlist",
255 "nohelp", 231 "nohelp",
256 options, 232 options,
257 &run, 233 &run,
258 &ok); 234 &ok);
259 return ok; 235 return ok;
260} 236}
@@ -271,9 +247,7 @@ main (int argc, char *argv[])
271 "GNUNET_TEST_HOME"); 247 "GNUNET_TEST_HOME");
272 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", 248 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
273 "GNUNET_TEST_HOME"); 249 "GNUNET_TEST_HOME");
274 GNUNET_log_setup ("test-gnunet-daemon-hostlist", 250 GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL);
275 "WARNING",
276 NULL);
277 ret = check (); 251 ret = check ();
278 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", 252 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
279 "GNUNET_TEST_HOME"); 253 "GNUNET_TEST_HOME");