aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist_reconnect.c')
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c142
1 files changed, 58 insertions, 84 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
index 5dc116ccd..28b2db0de 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.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,7 @@
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_core_service.h" 29#include "gnunet_transport_service.h"
30#include "gnunet_transport_hello_service.h" 30#include "gnunet_transport_hello_service.h"
31 31
32/** 32/**
@@ -76,11 +76,10 @@ timeout_error (void *cls)
76 */ 76 */
77static void * 77static void *
78notify_connect (void *cls, 78notify_connect (void *cls,
79 const struct GNUNET_PeerIdentity *peer, 79 const struct GNUNET_PeerIdentity *peer,
80 struct GNUNET_MQ_Handle *mq) 80 struct GNUNET_MQ_Handle *mq)
81{ 81{
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
83 "Peers connected, shutting down.\n");
84 ok = 0; 83 ok = 0;
85 GNUNET_SCHEDULER_shutdown (); 84 GNUNET_SCHEDULER_shutdown ();
86 return NULL; 85 return NULL;
@@ -88,8 +87,7 @@ notify_connect (void *cls,
88 87
89 88
90static void 89static void
91process_hello (void *cls, 90process_hello (void *cls, const struct GNUNET_MessageHeader *message)
92 const struct GNUNET_MessageHeader *message)
93{ 91{
94 struct PeerContext *p = cls; 92 struct PeerContext *p = cls;
95 93
@@ -101,39 +99,35 @@ process_hello (void *cls,
101 99
102 100
103static void 101static void
104setup_peer (struct PeerContext *p, 102setup_peer (struct PeerContext *p, const char *cfgname)
105 const char *cfgname)
106{ 103{
107 char *binary; 104 char *binary;
108 105
109 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 106 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
110 p->cfg = GNUNET_CONFIGURATION_create (); 107 p->cfg = GNUNET_CONFIGURATION_create ();
111 p->arm_proc = 108 p->arm_proc = GNUNET_OS_start_process (GNUNET_YES,
112 GNUNET_OS_start_process (GNUNET_YES, 109 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
113 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 110 NULL,
114 NULL, 111 NULL,
115 NULL, 112 NULL,
116 NULL, 113 binary,
117 binary, 114 "gnunet-service-arm",
118 "gnunet-service-arm", 115 "-c",
119 "-c", 116 cfgname,
120 cfgname, 117 NULL);
121 NULL); 118 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
122 GNUNET_assert (GNUNET_OK ==
123 GNUNET_CONFIGURATION_load (p->cfg,
124 cfgname));
125 p->th = GNUNET_TRANSPORT_core_connect (p->cfg, 119 p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
126 NULL, 120 NULL,
127 NULL, 121 NULL,
128 p, 122 p,
129 &notify_connect, 123 &notify_connect,
130 NULL, 124 NULL,
131 NULL); 125 NULL);
132 GNUNET_assert (NULL != p->th); 126 GNUNET_assert (NULL != p->th);
133 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 127 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
134 GNUNET_TRANSPORT_AC_ANY, 128 GNUNET_TRANSPORT_AC_ANY,
135 &process_hello, 129 &process_hello,
136 p); 130 p);
137 GNUNET_free (binary); 131 GNUNET_free (binary);
138} 132}
139 133
@@ -143,18 +137,13 @@ waitpid_task (void *cls)
143{ 137{
144 struct PeerContext *p = cls; 138 struct PeerContext *p = cls;
145 139
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n");
141 if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG))
142 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
143 if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc))
144 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Killing ARM process.\n"); 146 "ARM process %u stopped\n",
148 if (0 != GNUNET_OS_process_kill (p->arm_proc,
149 GNUNET_TERM_SIG))
150 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
151 "kill");
152 if (GNUNET_OK !=
153 GNUNET_OS_process_wait (p->arm_proc))
154 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
155 "waitpid");
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
157 "ARM process %u stopped\n",
158 GNUNET_OS_process_get_pid (p->arm_proc)); 147 GNUNET_OS_process_get_pid (p->arm_proc));
159 GNUNET_OS_process_destroy (p->arm_proc); 148 GNUNET_OS_process_destroy (p->arm_proc);
160 p->arm_proc = NULL; 149 p->arm_proc = NULL;
@@ -165,11 +154,8 @@ waitpid_task (void *cls)
165static void 154static void
166stop_arm (struct PeerContext *p) 155stop_arm (struct PeerContext *p)
167{ 156{
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
169 "Asking ARM to stop core service\n"); 158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
170 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
171 &waitpid_task,
172 p);
173} 159}
174 160
175 161
@@ -217,30 +203,22 @@ run (void *cls,
217{ 203{
218 GNUNET_assert (ok == 1); 204 GNUNET_assert (ok == 1);
219 ok++; 205 ok++;
220 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 206 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
221 &timeout_error, 207 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
222 NULL); 208 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
223 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 209 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
224 NULL);
225 setup_peer (&p1,
226 "test_gnunet_daemon_hostlist_peer1.conf");
227 setup_peer (&p2,
228 "test_gnunet_daemon_hostlist_peer2.conf");
229} 210}
230 211
231 212
232int 213int
233main (int argcx, 214main (int argcx, char *argvx[])
234 char *argvx[])
235{ 215{
236 static char *const argv[] = { 216 static char *const argv[] = {"test-gnunet-daemon-hostlist",
237 "test-gnunet-daemon-hostlist", 217 "-c",
238 "-c", "test_gnunet_daemon_hostlist_data.conf", 218 "test_gnunet_daemon_hostlist_data.conf",
239 NULL 219 NULL};
240 };
241 static struct GNUNET_GETOPT_CommandLineOption options[] = { 220 static struct GNUNET_GETOPT_CommandLineOption options[] = {
242 GNUNET_GETOPT_OPTION_END 221 GNUNET_GETOPT_OPTION_END};
243 };
244 222
245 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", 223 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
246 "GNUNET_TEST_HOME"); 224 "GNUNET_TEST_HOME");
@@ -248,32 +226,28 @@ main (int argcx,
248 "GNUNET_TEST_HOME"); 226 "GNUNET_TEST_HOME");
249 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", 227 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
250 "GNUNET_TEST_HOME"); 228 "GNUNET_TEST_HOME");
251 GNUNET_log_setup ("test-gnunet-daemon-hostlist", 229 GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL);
252 "WARNING",
253 NULL);
254 ok = 1; 230 ok = 1;
255 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 231 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
256 argv, 232 argv,
257 "test-gnunet-daemon-hostlist", 233 "test-gnunet-daemon-hostlist",
258 "nohelp", 234 "nohelp",
259 options, 235 options,
260 &run, 236 &run,
261 &ok); 237 &ok);
262 if (0 == ok) 238 if (0 == ok)
263 { 239 {
264 FPRINTF (stderr, "%s", "."); 240 FPRINTF (stderr, "%s", ".");
265 /* now do it again */ 241 /* now do it again */
266 ok = 1; 242 ok = 1;
267 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 243 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
268 argv, 244 argv,
269 "test-gnunet-daemon-hostlist", 245 "test-gnunet-daemon-hostlist",
270 "nohelp", 246 "nohelp",
271 options, 247 options,
272 &run, 248 &run,
273 &ok); 249 &ok);
274 FPRINTF (stderr, 250 FPRINTF (stderr, "%s", ".\n");
275 "%s",
276 ".\n");
277 } 251 }
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");