aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-29 19:18:54 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-29 19:18:54 +0000
commit905713e8a7392c78dbd3ef89e40b5c6281afd4c5 (patch)
treee0927c02f01331f9855c48b0311390869ba3f869 /src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
parentfda186a0d462dcbd221118c06a3ec6db6a819088 (diff)
downloadgnunet-905713e8a7392c78dbd3ef89e40b5c6281afd4c5.tar.gz
gnunet-905713e8a7392c78dbd3ef89e40b5c6281afd4c5.zip
convert tests to new transport API
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist_reconnect.c')
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c121
1 files changed, 80 insertions, 41 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
index 30f26717f..e0c193ed3 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010 GNUnet e.V. 3 Copyright (C) 2010, 2016 GNUnet e.V.
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
@@ -19,14 +19,14 @@
19*/ 19*/
20/** 20/**
21 * @file hostlist/test_gnunet_daemon_hostlist_reconnect.c 21 * @file hostlist/test_gnunet_daemon_hostlist_reconnect.c
22 * @brief test for gnunet_daemon_hostslist.c; tries to re-start the peers 22 * @brief test for gnunet-daemon-hostslist.c; tries to re-start the peers
23 * and connect a second time 23 * and connect a second time
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_arm_service.h" 28#include "gnunet_arm_service.h"
29#include "gnunet_transport_service.h" 29#include "gnunet_transport_core_service.h"
30 30
31/** 31/**
32 * How long until we give up on transmitting the message? 32 * How long until we give up on transmitting the message?
@@ -35,12 +35,12 @@
35 35
36static int ok; 36static int ok;
37 37
38static struct GNUNET_SCHEDULER_Task * timeout_task; 38static struct GNUNET_SCHEDULER_Task *timeout_task;
39 39
40struct PeerContext 40struct PeerContext
41{ 41{
42 struct GNUNET_CONFIGURATION_Handle *cfg; 42 struct GNUNET_CONFIGURATION_Handle *cfg;
43 struct GNUNET_TRANSPORT_Handle *th; 43 struct GNUNET_TRANSPORT_CoreHandle *th;
44 struct GNUNET_MessageHeader *hello; 44 struct GNUNET_MessageHeader *hello;
45 struct GNUNET_TRANSPORT_GetHelloHandle *ghh; 45 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
46 struct GNUNET_OS_Process *arm_proc; 46 struct GNUNET_OS_Process *arm_proc;
@@ -70,19 +70,19 @@ timeout_error (void *cls)
70 * 70 *
71 * @param cls closure 71 * @param cls closure
72 * @param peer the peer that connected 72 * @param peer the peer that connected
73 * @param latency current latency of the connection 73 * @param mq message queue to send to @a peer
74 * @param distance in overlay hops, as given by transport plugin 74 * @return NULL
75 */ 75 */
76static void 76static void
77notify_connect (void *cls, 77notify_connect (void *cls,
78 const struct GNUNET_PeerIdentity *peer) 78 const struct GNUNET_PeerIdentity *peer,
79 struct GNUNET_MQ_Handle *mq)
79{ 80{
80 if (peer == NULL)
81 return;
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
83 "Peers connected, shutting down.\n"); 82 "Peers connected, shutting down.\n");
84 ok = 0; 83 ok = 0;
85 GNUNET_SCHEDULER_shutdown (); 84 GNUNET_SCHEDULER_shutdown ();
85 return NULL;
86} 86}
87 87
88 88
@@ -100,23 +100,38 @@ process_hello (void *cls,
100 100
101 101
102static void 102static void
103setup_peer (struct PeerContext *p, const char *cfgname) 103setup_peer (struct PeerContext *p,
104 const char *cfgname)
104{ 105{
105 char *binary; 106 char *binary;
106 107
107 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 108 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
108 p->cfg = GNUNET_CONFIGURATION_create (); 109 p->cfg = GNUNET_CONFIGURATION_create ();
109 p->arm_proc = 110 p->arm_proc =
110 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 111 GNUNET_OS_start_process (GNUNET_YES,
111 NULL, NULL, NULL, 112 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
113 NULL,
114 NULL,
115 NULL,
112 binary, 116 binary,
113 "gnunet-service-arm", 117 "gnunet-service-arm",
114 "-c", cfgname, NULL); 118 "-c",
115 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 119 cfgname,
116 p->th = 120 NULL);
117 GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, &notify_connect, NULL); 121 GNUNET_assert (GNUNET_OK ==
118 GNUNET_assert (p->th != NULL); 122 GNUNET_CONFIGURATION_load (p->cfg,
119 p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, &process_hello, p); 123 cfgname));
124 p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
125 NULL,
126 NULL,
127 p,
128 &notify_connect,
129 NULL,
130 NULL);
131 GNUNET_assert (NULL != p->th);
132 p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg,
133 &process_hello,
134 p);
120 GNUNET_free (binary); 135 GNUNET_free (binary);
121} 136}
122 137
@@ -126,12 +141,18 @@ waitpid_task (void *cls)
126{ 141{
127 struct PeerContext *p = cls; 142 struct PeerContext *p = cls;
128 143
129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); 144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
130 if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) 145 "Killing ARM process.\n");
131 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 146 if (0 != GNUNET_OS_process_kill (p->arm_proc,
132 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 147 GNUNET_TERM_SIG))
133 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 148 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", 149 "kill");
150 if (GNUNET_OK !=
151 GNUNET_OS_process_wait (p->arm_proc))
152 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
153 "waitpid");
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
155 "ARM process %u stopped\n",
135 GNUNET_OS_process_get_pid (p->arm_proc)); 156 GNUNET_OS_process_get_pid (p->arm_proc));
136 GNUNET_OS_process_destroy (p->arm_proc); 157 GNUNET_OS_process_destroy (p->arm_proc);
137 p->arm_proc = NULL; 158 p->arm_proc = NULL;
@@ -142,9 +163,11 @@ waitpid_task (void *cls)
142static void 163static void
143stop_arm (struct PeerContext *p) 164stop_arm (struct PeerContext *p)
144{ 165{
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); 166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
167 "Asking ARM to stop core service\n");
146 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 168 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
147 &waitpid_task, p); 169 &waitpid_task,
170 p);
148} 171}
149 172
150 173
@@ -164,9 +187,9 @@ shutdown_task (void *cls)
164 GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); 187 GNUNET_TRANSPORT_get_hello_cancel (p1.ghh);
165 p1.ghh = NULL; 188 p1.ghh = NULL;
166 } 189 }
167 if (p1.th != NULL) 190 if (NULL != p1.th)
168 { 191 {
169 GNUNET_TRANSPORT_disconnect (p1.th); 192 GNUNET_TRANSPORT_core_disconnect (p1.th);
170 p1.th = NULL; 193 p1.th = NULL;
171 } 194 }
172 if (NULL != p2.ghh) 195 if (NULL != p2.ghh)
@@ -174,9 +197,9 @@ shutdown_task (void *cls)
174 GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); 197 GNUNET_TRANSPORT_get_hello_cancel (p2.ghh);
175 p2.ghh = NULL; 198 p2.ghh = NULL;
176 } 199 }
177 if (p2.th != NULL) 200 if (NULL != p2.th)
178 { 201 {
179 GNUNET_TRANSPORT_disconnect (p2.th); 202 GNUNET_TRANSPORT_core_disconnect (p2.th);
180 p2.th = NULL; 203 p2.th = NULL;
181 } 204 }
182 stop_arm (&p1); 205 stop_arm (&p1);
@@ -185,22 +208,28 @@ shutdown_task (void *cls)
185 208
186 209
187static void 210static void
188run (void *cls, char *const *args, const char *cfgfile, 211run (void *cls,
212 char *const *args,
213 const char *cfgfile,
189 const struct GNUNET_CONFIGURATION_Handle *cfg) 214 const struct GNUNET_CONFIGURATION_Handle *cfg)
190{ 215{
191 GNUNET_assert (ok == 1); 216 GNUNET_assert (ok == 1);
192 ok++; 217 ok++;
193 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 218 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
194 &timeout_error, NULL); 219 &timeout_error,
220 NULL);
195 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 221 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
196 NULL); 222 NULL);
197 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); 223 setup_peer (&p1,
198 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); 224 "test_gnunet_daemon_hostlist_peer1.conf");
225 setup_peer (&p2,
226 "test_gnunet_daemon_hostlist_peer2.conf");
199} 227}
200 228
201 229
202int 230int
203main (int argcx, char *argvx[]) 231main (int argcx,
232 char *argvx[])
204{ 233{
205 static char *const argv[] = { 234 static char *const argv[] = {
206 "test-gnunet-daemon-hostlist", 235 "test-gnunet-daemon-hostlist",
@@ -218,18 +247,28 @@ main (int argcx, char *argvx[])
218 "WARNING", 247 "WARNING",
219 NULL); 248 NULL);
220 ok = 1; 249 ok = 1;
221 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, 250 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
222 "test-gnunet-daemon-hostlist", "nohelp", options, &run, 251 argv,
252 "test-gnunet-daemon-hostlist",
253 "nohelp",
254 options,
255 &run,
223 &ok); 256 &ok);
224 if (0 == ok) 257 if (0 == ok)
225 { 258 {
226 FPRINTF (stderr, "%s", "."); 259 FPRINTF (stderr, "%s", ".");
227 /* now do it again */ 260 /* now do it again */
228 ok = 1; 261 ok = 1;
229 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, 262 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
230 "test-gnunet-daemon-hostlist", "nohelp", options, &run, 263 argv,
264 "test-gnunet-daemon-hostlist",
265 "nohelp",
266 options,
267 &run,
231 &ok); 268 &ok);
232 FPRINTF (stderr, "%s", ".\n"); 269 FPRINTF (stderr,
270 "%s",
271 ".\n");
233 } 272 }
234 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); 273 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
235 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); 274 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");