diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-29 19:18:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-29 19:18:54 +0000 |
commit | 905713e8a7392c78dbd3ef89e40b5c6281afd4c5 (patch) | |
tree | e0927c02f01331f9855c48b0311390869ba3f869 /src/hostlist/test_gnunet_daemon_hostlist.c | |
parent | fda186a0d462dcbd221118c06a3ec6db6a819088 (diff) | |
download | gnunet-905713e8a7392c78dbd3ef89e40b5c6281afd4c5.tar.gz gnunet-905713e8a7392c78dbd3ef89e40b5c6281afd4c5.zip |
convert tests to new transport API
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist.c')
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 103 |
1 files changed, 67 insertions, 36 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index 6a5850c4d..9a1e6d3d7 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2009 GNUnet e.V. | 3 | Copyright (C) 2009, 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 |
@@ -26,6 +26,7 @@ | |||
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" | ||
29 | 30 | ||
30 | 31 | ||
31 | /** | 32 | /** |
@@ -40,7 +41,7 @@ static struct GNUNET_SCHEDULER_Task *timeout_task; | |||
40 | struct PeerContext | 41 | struct PeerContext |
41 | { | 42 | { |
42 | struct GNUNET_CONFIGURATION_Handle *cfg; | 43 | struct GNUNET_CONFIGURATION_Handle *cfg; |
43 | struct GNUNET_TRANSPORT_Handle *th; | 44 | struct GNUNET_TRANSPORT_CoreHandle *th; |
44 | struct GNUNET_MessageHeader *hello; | 45 | struct GNUNET_MessageHeader *hello; |
45 | struct GNUNET_TRANSPORT_GetHelloHandle *ghh; | 46 | struct GNUNET_TRANSPORT_GetHelloHandle *ghh; |
46 | struct GNUNET_OS_Process *arm_proc; | 47 | struct GNUNET_OS_Process *arm_proc; |
@@ -54,29 +55,30 @@ static struct PeerContext p2; | |||
54 | static void | 55 | static void |
55 | clean_up (void *cls) | 56 | clean_up (void *cls) |
56 | { | 57 | { |
57 | if (p1.th != NULL) | 58 | if (NULL != p1.th) |
58 | { | 59 | { |
59 | if (p1.ghh != NULL) | 60 | if (NULL != p1.ghh) |
60 | { | 61 | { |
61 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); | 62 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); |
62 | p1.ghh = NULL; | 63 | p1.ghh = NULL; |
63 | } | 64 | } |
64 | GNUNET_TRANSPORT_disconnect (p1.th); | 65 | GNUNET_TRANSPORT_core_disconnect (p1.th); |
65 | p1.th = NULL; | 66 | p1.th = NULL; |
66 | } | 67 | } |
67 | if (p2.th != NULL) | 68 | if (NULL != p2.th) |
68 | { | 69 | { |
69 | if (p2.ghh != NULL) | 70 | if (NULL != p2.ghh) |
70 | { | 71 | { |
71 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); | 72 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); |
72 | p2.ghh = NULL; | 73 | p2.ghh = NULL; |
73 | } | 74 | } |
74 | GNUNET_TRANSPORT_disconnect (p2.th); | 75 | GNUNET_TRANSPORT_core_disconnect (p2.th); |
75 | p2.th = NULL; | 76 | p2.th = NULL; |
76 | } | 77 | } |
77 | GNUNET_SCHEDULER_shutdown (); | 78 | GNUNET_SCHEDULER_shutdown (); |
78 | } | 79 | } |
79 | 80 | ||
81 | |||
80 | /** | 82 | /** |
81 | * Timeout, give up. | 83 | * Timeout, give up. |
82 | */ | 84 | */ |
@@ -96,24 +98,24 @@ timeout_error (void *cls) | |||
96 | * | 98 | * |
97 | * @param cls closure | 99 | * @param cls closure |
98 | * @param peer the peer that connected | 100 | * @param peer the peer that connected |
99 | * @param latency current latency of the connection | 101 | * @param mq message queue to send messages to the peer |
100 | * @param distance in overlay hops, as given by transport plugin | ||
101 | */ | 102 | */ |
102 | static void | 103 | static void * |
103 | notify_connect (void *cls, | 104 | notify_connect (void *cls, |
104 | const struct GNUNET_PeerIdentity *peer) | 105 | const struct GNUNET_PeerIdentity *peer, |
106 | struct GNUNET_MQ_Handle *mq) | ||
105 | { | 107 | { |
106 | if (peer == NULL) | ||
107 | return; | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
109 | "Peers connected, shutting down.\n"); | 109 | "Peers connected, shutting down.\n"); |
110 | ok = 0; | 110 | ok = 0; |
111 | if (timeout_task != NULL) | 111 | if (NULL != timeout_task) |
112 | { | 112 | { |
113 | GNUNET_SCHEDULER_cancel (timeout_task); | 113 | GNUNET_SCHEDULER_cancel (timeout_task); |
114 | timeout_task = NULL; | 114 | timeout_task = NULL; |
115 | } | 115 | } |
116 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); | 116 | GNUNET_SCHEDULER_add_now (&clean_up, |
117 | NULL); | ||
118 | return NULL; | ||
117 | } | 119 | } |
118 | 120 | ||
119 | 121 | ||
@@ -131,23 +133,38 @@ process_hello (void *cls, | |||
131 | 133 | ||
132 | 134 | ||
133 | static void | 135 | static void |
134 | setup_peer (struct PeerContext *p, const char *cfgname) | 136 | setup_peer (struct PeerContext *p, |
137 | const char *cfgname) | ||
135 | { | 138 | { |
136 | char *binary; | 139 | char *binary; |
137 | 140 | ||
138 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 141 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
139 | p->cfg = GNUNET_CONFIGURATION_create (); | 142 | p->cfg = GNUNET_CONFIGURATION_create (); |
140 | p->arm_proc = | 143 | p->arm_proc = |
141 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 144 | GNUNET_OS_start_process (GNUNET_YES, |
142 | NULL, NULL, NULL, | 145 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
146 | NULL, | ||
147 | NULL, | ||
148 | NULL, | ||
143 | binary, | 149 | binary, |
144 | "gnunet-service-arm", | 150 | "gnunet-service-arm", |
145 | "-c", cfgname, NULL); | 151 | "-c", |
146 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 152 | cfgname, |
147 | p->th = | 153 | NULL); |
148 | GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, ¬ify_connect, NULL); | 154 | GNUNET_assert (GNUNET_OK == |
155 | GNUNET_CONFIGURATION_load (p->cfg, | ||
156 | cfgname)); | ||
157 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, | ||
158 | NULL, | ||
159 | NULL, | ||
160 | p, | ||
161 | ¬ify_connect, | ||
162 | NULL, | ||
163 | NULL); | ||
149 | GNUNET_assert (p->th != NULL); | 164 | GNUNET_assert (p->th != NULL); |
150 | p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, &process_hello, p); | 165 | p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, |
166 | &process_hello, | ||
167 | p); | ||
151 | GNUNET_free (binary); | 168 | GNUNET_free (binary); |
152 | } | 169 | } |
153 | 170 | ||
@@ -157,12 +174,18 @@ waitpid_task (void *cls) | |||
157 | { | 174 | { |
158 | struct PeerContext *p = cls; | 175 | struct PeerContext *p = cls; |
159 | 176 | ||
160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); | 177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
161 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) | 178 | "Killing ARM process.\n"); |
162 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 179 | if (0 != GNUNET_OS_process_kill (p->arm_proc, |
163 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | 180 | GNUNET_TERM_SIG)) |
164 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 181 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | 182 | "kill"); |
183 | if (GNUNET_OK != | ||
184 | GNUNET_OS_process_wait (p->arm_proc)) | ||
185 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
186 | "waitpid"); | ||
187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
188 | "ARM process %u stopped\n", | ||
166 | GNUNET_OS_process_get_pid (p->arm_proc)); | 189 | GNUNET_OS_process_get_pid (p->arm_proc)); |
167 | GNUNET_OS_process_destroy (p->arm_proc); | 190 | GNUNET_OS_process_destroy (p->arm_proc); |
168 | p->arm_proc = NULL; | 191 | p->arm_proc = NULL; |
@@ -176,7 +199,8 @@ stop_arm (struct PeerContext *p) | |||
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
177 | "Asking ARM to stop core service\n"); | 200 | "Asking ARM to stop core service\n"); |
178 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 201 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
179 | &waitpid_task, p); | 202 | &waitpid_task, |
203 | p); | ||
180 | } | 204 | } |
181 | 205 | ||
182 | 206 | ||
@@ -204,15 +228,18 @@ run (void *cls, | |||
204 | NULL); | 228 | NULL); |
205 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 229 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
206 | NULL); | 230 | NULL); |
207 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | 231 | setup_peer (&p1, |
208 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | 232 | "test_gnunet_daemon_hostlist_peer1.conf"); |
233 | setup_peer (&p2, | ||
234 | "test_gnunet_daemon_hostlist_peer2.conf"); | ||
209 | } | 235 | } |
210 | 236 | ||
211 | 237 | ||
212 | static int | 238 | static int |
213 | check () | 239 | check () |
214 | { | 240 | { |
215 | char *const argv[] = { "test-gnunet-daemon-hostlist", | 241 | char *const argv[] = { |
242 | "test-gnunet-daemon-hostlist", | ||
216 | "-c", "test_gnunet_daemon_hostlist_data.conf", | 243 | "-c", "test_gnunet_daemon_hostlist_data.conf", |
217 | NULL | 244 | NULL |
218 | }; | 245 | }; |
@@ -220,8 +247,12 @@ check () | |||
220 | GNUNET_GETOPT_OPTION_END | 247 | GNUNET_GETOPT_OPTION_END |
221 | }; | 248 | }; |
222 | ok = 1; | 249 | ok = 1; |
223 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, | 250 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
224 | "test-gnunet-daemon-hostlist", "nohelp", options, &run, | 251 | argv, |
252 | "test-gnunet-daemon-hostlist", | ||
253 | "nohelp", | ||
254 | options, | ||
255 | &run, | ||
225 | &ok); | 256 | &ok); |
226 | return ok; | 257 | return ok; |
227 | } | 258 | } |