aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist
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
parent1227fc30369a55b82e77d35d8d128090e37dd437 (diff)
downloadgnunet-3f945e6798d8d736ceb104b59ea1269a7abdfe8a.tar.gz
gnunet-3f945e6798d8d736ceb104b59ea1269a7abdfe8a.zip
towards flow control in TNG
Diffstat (limited to 'src/hostlist')
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist.c124
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c142
2 files changed, 107 insertions, 159 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");
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");