diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-04-01 17:54:06 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-04-01 17:54:06 +0000 |
commit | 4e3864ec2681a43fb13f5d6af6093ebed5a68196 (patch) | |
tree | 62fe35f676784c78e7f7db8bbe3f1506611d11fe /src | |
parent | e1de3162b194d2c72ad66aafcf803477caa41730 (diff) | |
download | gnunet-4e3864ec2681a43fb13f5d6af6093ebed5a68196.tar.gz gnunet-4e3864ec2681a43fb13f5d6af6093ebed5a68196.zip |
- only have asynchronous peer stop
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_testing_lib.h | 115 | ||||
-rw-r--r-- | src/testing/test_testing_peerstartup2.c | 71 | ||||
-rw-r--r-- | src/testing/testing.c | 172 |
3 files changed, 110 insertions, 248 deletions
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index 6b3333188..7181b9ca1 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h | |||
@@ -242,7 +242,9 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer); | |||
242 | 242 | ||
243 | 243 | ||
244 | /** | 244 | /** |
245 | * Stop the peer. | 245 | * Stop the peer. This call is blocking as it kills the peer's main ARM process |
246 | * by sending a SIGTERM and waits on it. For asynchronous shutdown of peer, see | ||
247 | * GNUNET_TESTING_peer_stop_async(). | ||
246 | * | 248 | * |
247 | * @param peer peer to stop | 249 | * @param peer peer to stop |
248 | * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running) | 250 | * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running) |
@@ -287,117 +289,32 @@ GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer); | |||
287 | /** | 289 | /** |
288 | * Callback to inform whether the peer is running or stopped. | 290 | * Callback to inform whether the peer is running or stopped. |
289 | * | 291 | * |
290 | * @param cls the closure from GNUNET_TESTING_peer_configure2() | 292 | * @param cls the closure given to GNUNET_TESTING_peer_stop_async() |
291 | * @param peer the respective peer whose status is being reported | 293 | * @param peer the respective peer whose status is being reported |
292 | * @param success GNUNET_YES if the peer is running; GNUNET_NO if the peer is | 294 | * @param success GNUNET_YES if the peer is stopped; GNUNET_SYSERR upon any |
293 | * not running; GNUNET_SYSERR upon error communicating with the peer's | 295 | * error |
294 | * ARM service | ||
295 | */ | 296 | */ |
296 | typedef void (*GNUNET_TESTING_PeerStatusCallback) (void *cls, | 297 | typedef void (*GNUNET_TESTING_PeerStopCallback) (void *cls, |
297 | struct GNUNET_TESTING_Peer * | 298 | struct GNUNET_TESTING_Peer * |
298 | peer, | 299 | peer, |
299 | int success); | 300 | int success); |
300 | |||
301 | |||
302 | /** | ||
303 | * Wrapper over GNUNET_TESTING_peer_configure() to set the | ||
304 | * GNUNET_TESTING_PeerStatusCallback() for using functions | ||
305 | * GNUNET_TESTING_peer_start2() and GNUNET_TESTING_peer_stop2() | ||
306 | * | ||
307 | * @param system system to use to coordinate resource usage | ||
308 | * @param cfg configuration to use; will be UPDATED (to reflect needed | ||
309 | * changes in port numbers and paths) | ||
310 | * @param key_number number of the hostkey to use for the peer | ||
311 | * @param id identifier for the daemon, will be set, can be NULL | ||
312 | * @param emsg set to freshly allocated error message (set to NULL on success), | ||
313 | * can be NULL | ||
314 | * @param status_cb the status callback to call upon peer start and stop | ||
315 | * @return handle to the peer, NULL on error | ||
316 | */ | ||
317 | struct GNUNET_TESTING_Peer * | ||
318 | GNUNET_TESTING_peer_configure2 (struct GNUNET_TESTING_System *system, | ||
319 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
320 | uint32_t key_number, | ||
321 | struct GNUNET_PeerIdentity *id, | ||
322 | char **emsg, | ||
323 | GNUNET_TESTING_PeerStatusCallback status_cb, | ||
324 | void *cls); | ||
325 | |||
326 | |||
327 | /** | ||
328 | * Start a peer asynchronously using ARM API. Peer's startup is signaled | ||
329 | * through the GNUNET_TESTING_PeerStatusCallback() given to | ||
330 | * GNUNET_TESTING_peer_configure2(). To use this function the peer must be | ||
331 | * configured earlier using GNUNET_TESTING_peer_configure2(); | ||
332 | * | ||
333 | * @param peer the peer to start | ||
334 | * @param timeout how long to wait before giving up to start the peer | ||
335 | * @return GNUNET_OK upon successfully giving the request to the ARM API (this | ||
336 | * does not mean that the peer is successfully started); GNUNET_SYSERR | ||
337 | * upon any error. | ||
338 | */ | ||
339 | int | ||
340 | GNUNET_TESTING_peer_start2 (struct GNUNET_TESTING_Peer *peer, | ||
341 | struct GNUNET_TIME_Relative timeout); | ||
342 | 301 | ||
343 | 302 | ||
344 | /** | 303 | /** |
345 | * Stop a peer asynchronously using ARM API. Peer's shutdown is signaled | 304 | * Stop a peer asynchronously using ARM API. Peer's shutdown is signaled |
346 | * through the GNUNET_TESTING_PeerStatusCallback() given to | 305 | * through the GNUNET_TESTING_PeerStopCallback(). |
347 | * GNUNET_TESTING_peer_configure2(). To use this function the peer must be | ||
348 | * configured earlier using GNUNET_TESTING_peer_configure2(); | ||
349 | * | 306 | * |
350 | * @param peer the peer to stop | 307 | * @param peer the peer to stop |
351 | * @param timeout how long to wait before giving up to stop the peer | 308 | * @param cb the callback to signal peer shutdown |
309 | * @param cb_cls closure for the above callback | ||
352 | * @return GNUNET_OK upon successfully giving the request to the ARM API (this | 310 | * @return GNUNET_OK upon successfully giving the request to the ARM API (this |
353 | * does not mean that the peer is successfully stopped); GNUNET_SYSERR | 311 | * does not mean that the peer is successfully stopped); GNUNET_SYSERR |
354 | * upon any error. | 312 | * upon any error. |
355 | */ | 313 | */ |
356 | int | 314 | int |
357 | GNUNET_TESTING_peer_stop2 (struct GNUNET_TESTING_Peer *peer, | 315 | GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, |
358 | struct GNUNET_TIME_Relative timeout); | 316 | GNUNET_TESTING_PeerStopCallback cb, |
359 | 317 | void *cb_cls); | |
360 | |||
361 | /** | ||
362 | * Start a service at a peer using its ARM service. To use this function the | ||
363 | * peer must be configured earlier using GNUNET_TESTING_peer_configure2(); | ||
364 | * | ||
365 | * @param peer the peer whose service has to be started | ||
366 | * @param service_name name of the service to start | ||
367 | * @param timeout how long should the ARM API try to send the request to start | ||
368 | * the service | ||
369 | * @param cont the callback to call with result and status from ARM API | ||
370 | * @param cont_cls the closure for the above callback | ||
371 | * @return GNUNET_OK upon successfully queuing the service start request; | ||
372 | * GNUNET_SYSERR upon error | ||
373 | */ | ||
374 | int | ||
375 | GNUNET_TESTING_peer_service_start (struct GNUNET_TESTING_Peer *peer, | ||
376 | const char *service_name, | ||
377 | struct GNUNET_TIME_Relative timeout, | ||
378 | GNUNET_ARM_ResultCallback cont, | ||
379 | void *cont_cls); | ||
380 | |||
381 | |||
382 | /** | ||
383 | * Stop a service at a peer using its ARM service. To use this function the | ||
384 | * peer must be configured earlier using GNUNET_TESTING_peer_configure2(); | ||
385 | * | ||
386 | * @param peer the peer whose service has to be stopped | ||
387 | * @param service_name name of the service to stop | ||
388 | * @param timeout how long should the ARM API try to send the request to stop | ||
389 | * the service | ||
390 | * @param cont the callback to call with result and status from ARM API | ||
391 | * @param cont_cls the closure for the above callback | ||
392 | * @return GNUNET_OK upon successfully queuing the service stop request; | ||
393 | * GNUNET_SYSERR upon error | ||
394 | */ | ||
395 | int | ||
396 | GNUNET_TESTING_peer_service_stop (struct GNUNET_TESTING_Peer *peer, | ||
397 | const char *service_name, | ||
398 | struct GNUNET_TIME_Relative timeout, | ||
399 | GNUNET_ARM_ResultCallback cont, | ||
400 | void *cont_cls); | ||
401 | 318 | ||
402 | 319 | ||
403 | /** | 320 | /** |
diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c index 25b9ba2ea..d290aff16 100644 --- a/src/testing/test_testing_peerstartup2.c +++ b/src/testing/test_testing_peerstartup2.c | |||
@@ -36,11 +36,14 @@ | |||
36 | 36 | ||
37 | #define FAIL_TEST(cond) \ | 37 | #define FAIL_TEST(cond) \ |
38 | do { \ | 38 | do { \ |
39 | if ((!(cond)) && (GNUNET_OK == status)) { \ | 39 | if (!(cond)) { \ |
40 | status = GNUNET_SYSERR; \ | 40 | GNUNET_break (0); \ |
41 | if (GNUNET_OK == status) { \ | ||
42 | status = GNUNET_SYSERR; \ | ||
43 | } \ | ||
41 | } \ | 44 | } \ |
42 | } while (0) \ | 45 | } while (0) \ |
43 | 46 | ||
44 | 47 | ||
45 | /** | 48 | /** |
46 | * The status of the test | 49 | * The status of the test |
@@ -103,20 +106,7 @@ do_shutdown2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
103 | * @param tc the tast context | 106 | * @param tc the tast context |
104 | */ | 107 | */ |
105 | static void | 108 | static void |
106 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 109 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
107 | { | ||
108 | struct TestingContext *test_ctx = cls; | ||
109 | |||
110 | GNUNET_assert (NULL != test_ctx); | ||
111 | if (NULL != test_ctx->peer) | ||
112 | { | ||
113 | FAIL_TEST (GNUNET_OK == GNUNET_TESTING_peer_stop2 (test_ctx->peer, | ||
114 | GNUNET_TIME_UNIT_MINUTES)); | ||
115 | |||
116 | } | ||
117 | else | ||
118 | do_shutdown (test_ctx, tc); | ||
119 | } | ||
120 | 110 | ||
121 | 111 | ||
122 | static void | 112 | static void |
@@ -127,13 +117,11 @@ peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) | |||
127 | switch (test_ctx->state) | 117 | switch (test_ctx->state) |
128 | { | 118 | { |
129 | case PEER_INIT: | 119 | case PEER_INIT: |
130 | FAIL_TEST (GNUNET_YES == success); | 120 | FAIL_TEST (0); |
131 | test_ctx->state = PEER_STARTED; | ||
132 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
133 | &do_shutdown, test_ctx); | ||
134 | break; | 121 | break; |
135 | case PEER_STARTED: | 122 | case PEER_STARTED: |
136 | FAIL_TEST (GNUNET_NO == success); | 123 | FAIL_TEST (GNUNET_YES == success); |
124 | test_ctx->state = PEER_STOPPED; | ||
137 | GNUNET_SCHEDULER_add_now (&do_shutdown2, cls); | 125 | GNUNET_SCHEDULER_add_now (&do_shutdown2, cls); |
138 | break; | 126 | break; |
139 | case PEER_STOPPED: | 127 | case PEER_STOPPED: |
@@ -143,6 +131,31 @@ peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) | |||
143 | 131 | ||
144 | 132 | ||
145 | /** | 133 | /** |
134 | * Task for shutdown | ||
135 | * | ||
136 | * @param cls the testing context | ||
137 | * @param tc the tast context | ||
138 | */ | ||
139 | static void | ||
140 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
141 | { | ||
142 | struct TestingContext *test_ctx = cls; | ||
143 | |||
144 | GNUNET_assert (NULL != test_ctx); | ||
145 | if (NULL != test_ctx->peer) | ||
146 | { | ||
147 | FAIL_TEST (GNUNET_OK == | ||
148 | GNUNET_TESTING_peer_stop_async (test_ctx->peer, | ||
149 | &peer_status_cb, | ||
150 | test_ctx)); | ||
151 | |||
152 | } | ||
153 | else | ||
154 | do_shutdown (test_ctx, tc); | ||
155 | } | ||
156 | |||
157 | |||
158 | /** | ||
146 | * Main point of test execution | 159 | * Main point of test execution |
147 | */ | 160 | */ |
148 | static void | 161 | static void |
@@ -162,20 +175,20 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
162 | goto end; | 175 | goto end; |
163 | test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); | 176 | test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); |
164 | test_ctx->peer = | 177 | test_ctx->peer = |
165 | GNUNET_TESTING_peer_configure2 (test_ctx->system, | 178 | GNUNET_TESTING_peer_configure (test_ctx->system, |
166 | test_ctx->cfg, | 179 | test_ctx->cfg, |
167 | 0, &id, &emsg, | 180 | 0, &id, &emsg); |
168 | &peer_status_cb, | ||
169 | test_ctx); | ||
170 | if (NULL == test_ctx->peer) | 181 | if (NULL == test_ctx->peer) |
171 | { | 182 | { |
172 | if (NULL != emsg) | 183 | if (NULL != emsg) |
173 | printf ("Test failed upon error: %s", emsg); | 184 | printf ("Test failed upon error: %s", emsg); |
174 | goto end; | 185 | goto end; |
175 | } | 186 | } |
176 | if (GNUNET_OK != GNUNET_TESTING_peer_start2 (test_ctx->peer, | 187 | if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) |
177 | GNUNET_TIME_UNIT_MINUTES)) | ||
178 | goto end; | 188 | goto end; |
189 | test_ctx->state = PEER_STARTED; | ||
190 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
191 | &do_shutdown, test_ctx); | ||
179 | return; | 192 | return; |
180 | 193 | ||
181 | end: | 194 | end: |
diff --git a/src/testing/testing.c b/src/testing/testing.c index f4584db30..9d2c69ab7 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -186,15 +186,19 @@ struct GNUNET_TESTING_Peer | |||
186 | struct GNUNET_ARM_Handle *ah; | 186 | struct GNUNET_ARM_Handle *ah; |
187 | 187 | ||
188 | /** | 188 | /** |
189 | * Handle to ARM monitoring | ||
190 | */ | ||
191 | struct GNUNET_ARM_MonitorHandle *mh; | ||
192 | |||
193 | /** | ||
189 | * The config of the peer | 194 | * The config of the peer |
190 | */ | 195 | */ |
191 | struct GNUNET_CONFIGURATION_Handle *cfg; | 196 | struct GNUNET_CONFIGURATION_Handle *cfg; |
192 | 197 | ||
193 | /** | 198 | /** |
194 | * The callback to call if asynchronous functions are used for peer/service | 199 | * The callback to call asynchronously when a peer is stopped |
195 | * start/stop requests | ||
196 | */ | 200 | */ |
197 | GNUNET_TESTING_PeerStatusCallback cb; | 201 | GNUNET_TESTING_PeerStopCallback cb; |
198 | 202 | ||
199 | /** | 203 | /** |
200 | * The closure for the above callback | 204 | * The closure for the above callback |
@@ -518,25 +522,6 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, | |||
518 | 522 | ||
519 | 523 | ||
520 | /** | 524 | /** |
521 | * Reserve a SERVICEHOME path for a peer. | ||
522 | * | ||
523 | * @param system system to use for reservation tracking | ||
524 | * @return NULL on error, otherwise fresh unique path to use | ||
525 | * as the servicehome for the peer; must be freed by the caller | ||
526 | */ | ||
527 | // static | ||
528 | char * | ||
529 | reserve_path (struct GNUNET_TESTING_System *system) | ||
530 | { | ||
531 | char *reserved_path; | ||
532 | |||
533 | GNUNET_asprintf (&reserved_path, | ||
534 | "%s/%u", system->tmppath, system->path_counter++); | ||
535 | return reserved_path; | ||
536 | } | ||
537 | |||
538 | |||
539 | /** | ||
540 | * Testing includes a number of pre-created hostkeys for | 525 | * Testing includes a number of pre-created hostkeys for |
541 | * faster peer startup. This function can be used to | 526 | * faster peer startup. This function can be used to |
542 | * access the n-th key of those pre-created hostkeys; note | 527 | * access the n-th key of those pre-created hostkeys; note |
@@ -984,6 +969,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
984 | } | 969 | } |
985 | peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer)); | 970 | peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer)); |
986 | peer->cfgfile = config_filename; /* Free in peer_destroy */ | 971 | peer->cfgfile = config_filename; /* Free in peer_destroy */ |
972 | peer->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
987 | libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 973 | libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
988 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary)) | 974 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary)) |
989 | { | 975 | { |
@@ -1001,46 +987,6 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
1001 | 987 | ||
1002 | 988 | ||
1003 | /** | 989 | /** |
1004 | * Wrapper over GNUNET_TESTING_peer_configure() to set the | ||
1005 | * GNUNET_TESTING_PeerStatusCallback() for using functions | ||
1006 | * GNUNET_TESTING_peer_start2() and GNUNET_TESTING_peer_stop2() | ||
1007 | * | ||
1008 | * @param system system to use to coordinate resource usage | ||
1009 | * @param cfg configuration to use; will be UPDATED (to reflect needed | ||
1010 | * changes in port numbers and paths) | ||
1011 | * @param key_number number of the hostkey to use for the peer | ||
1012 | * @param id identifier for the daemon, will be set, can be NULL | ||
1013 | * @param emsg set to freshly allocated error message (set to NULL on success), | ||
1014 | * can be NULL | ||
1015 | * @param status_cb the status callback to call upon peer start and stop | ||
1016 | * @return handle to the peer, NULL on error | ||
1017 | */ | ||
1018 | struct GNUNET_TESTING_Peer * | ||
1019 | GNUNET_TESTING_peer_configure2 (struct GNUNET_TESTING_System *system, | ||
1020 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
1021 | uint32_t key_number, | ||
1022 | struct GNUNET_PeerIdentity *id, | ||
1023 | char **emsg, | ||
1024 | GNUNET_TESTING_PeerStatusCallback status_cb, | ||
1025 | void *cls) | ||
1026 | { | ||
1027 | struct GNUNET_TESTING_Peer *peer; | ||
1028 | |||
1029 | peer = GNUNET_TESTING_peer_configure (system, | ||
1030 | cfg, | ||
1031 | key_number, | ||
1032 | id, | ||
1033 | emsg); | ||
1034 | if (NULL == peer) | ||
1035 | return NULL; | ||
1036 | peer->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
1037 | peer->cb = status_cb; | ||
1038 | peer->cb_cls = cls; | ||
1039 | return peer; | ||
1040 | } | ||
1041 | |||
1042 | |||
1043 | /** | ||
1044 | * Obtain the peer identity from a peer handle. | 990 | * Obtain the peer identity from a peer handle. |
1045 | * | 991 | * |
1046 | * @param peer peer handle for which we want the peer's identity | 992 | * @param peer peer handle for which we want the peer's identity |
@@ -1159,56 +1105,6 @@ GNUNET_TESTING_peer_service_stop (struct GNUNET_TESTING_Peer *peer, | |||
1159 | 1105 | ||
1160 | 1106 | ||
1161 | /** | 1107 | /** |
1162 | * Function called whenever we connect to or disconnect from ARM. | ||
1163 | * | ||
1164 | * @param cls closure | ||
1165 | * @param arm handle to the ARM connection | ||
1166 | * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected, | ||
1167 | * GNUNET_SYSERR on error. | ||
1168 | */ | ||
1169 | static void | ||
1170 | conn_status (void *cls, struct GNUNET_ARM_Handle *arm, | ||
1171 | int connected) | ||
1172 | { | ||
1173 | struct GNUNET_TESTING_Peer *peer = cls; | ||
1174 | |||
1175 | peer->cb (peer->cb_cls, peer, connected); | ||
1176 | } | ||
1177 | |||
1178 | |||
1179 | /** | ||
1180 | * Start a peer asynchronously using ARM API. Peer's startup is signaled | ||
1181 | * through the GNUNET_TESTING_PeerStatusCallback() given to | ||
1182 | * GNUNET_TESTING_peer_configure2(). To use this function the peer must be | ||
1183 | * configured earlier using GNUNET_TESTING_peer_configure2(); | ||
1184 | * | ||
1185 | * @param peer the peer to start | ||
1186 | * @param timeout how long to wait before giving up to start the peer | ||
1187 | * @return GNUNET_OK upon successfully giving the request to the ARM API (this | ||
1188 | * does not mean that the peer is successfully started); GNUNET_SYSERR | ||
1189 | * upon any error. | ||
1190 | */ | ||
1191 | int | ||
1192 | GNUNET_TESTING_peer_start2 (struct GNUNET_TESTING_Peer *peer, | ||
1193 | struct GNUNET_TIME_Relative timeout) | ||
1194 | { | ||
1195 | if (NULL != peer->ah) | ||
1196 | { | ||
1197 | GNUNET_break (0); | ||
1198 | return GNUNET_SYSERR; | ||
1199 | } | ||
1200 | GNUNET_assert (NULL != peer->cb); | ||
1201 | GNUNET_assert (NULL != peer->cfg); | ||
1202 | peer->ah = GNUNET_ARM_connect (peer->cfg, &conn_status, peer); | ||
1203 | if (NULL == peer->ah) | ||
1204 | return GNUNET_SYSERR; | ||
1205 | GNUNET_TESTING_peer_service_start (peer, "arm", timeout, NULL, NULL); | ||
1206 | return GNUNET_OK; | ||
1207 | } | ||
1208 | |||
1209 | |||
1210 | |||
1211 | /** | ||
1212 | * Sends SIGTERM to the peer's main process | 1108 | * Sends SIGTERM to the peer's main process |
1213 | * | 1109 | * |
1214 | * @param peer the handle to the peer | 1110 | * @param peer the handle to the peer |
@@ -1270,25 +1166,59 @@ GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer) | |||
1270 | 1166 | ||
1271 | 1167 | ||
1272 | /** | 1168 | /** |
1169 | * Function called whenever we connect to or disconnect from ARM. | ||
1170 | * | ||
1171 | * @param cls closure | ||
1172 | * @param arm handle to the ARM connection | ||
1173 | * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected, | ||
1174 | * GNUNET_SYSERR on error. | ||
1175 | */ | ||
1176 | static void | ||
1177 | disconn_status (void *cls, struct GNUNET_ARM_Handle *arm, | ||
1178 | int connected) | ||
1179 | { | ||
1180 | struct GNUNET_TESTING_Peer *peer = cls; | ||
1181 | |||
1182 | if (GNUNET_SYSERR == connected) | ||
1183 | { | ||
1184 | peer->cb (peer->cb_cls, peer, connected); | ||
1185 | return; | ||
1186 | } | ||
1187 | if (GNUNET_YES == connected) | ||
1188 | { | ||
1189 | GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_kill (peer)); | ||
1190 | return; | ||
1191 | } | ||
1192 | GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_wait (peer)); | ||
1193 | GNUNET_ARM_disconnect_and_free (peer->ah); | ||
1194 | peer->ah = NULL; | ||
1195 | peer->cb (peer->cb_cls, peer, GNUNET_YES); | ||
1196 | } | ||
1197 | |||
1198 | |||
1199 | /** | ||
1273 | * Stop a peer asynchronously using ARM API. Peer's shutdown is signaled | 1200 | * Stop a peer asynchronously using ARM API. Peer's shutdown is signaled |
1274 | * through the GNUNET_TESTING_PeerStatusCallback() given to | 1201 | * through the GNUNET_TESTING_PeerStopCallback(). |
1275 | * GNUNET_TESTING_peer_configure2(). To use this function the peer must be | ||
1276 | * configured earlier using GNUNET_TESTING_peer_configure2(); | ||
1277 | * | 1202 | * |
1278 | * @param peer the peer to stop | 1203 | * @param peer the peer to stop |
1279 | * @param timeout how long to wait before giving up to stop the peer | 1204 | * @param cb the callback to signal peer shutdown |
1205 | * @param cb_cls closure for the above callback | ||
1280 | * @return GNUNET_OK upon successfully giving the request to the ARM API (this | 1206 | * @return GNUNET_OK upon successfully giving the request to the ARM API (this |
1281 | * does not mean that the peer is successfully stopped); GNUNET_SYSERR | 1207 | * does not mean that the peer is successfully stopped); GNUNET_SYSERR |
1282 | * upon any error. | 1208 | * upon any error. |
1283 | */ | 1209 | */ |
1284 | int | 1210 | int |
1285 | GNUNET_TESTING_peer_stop2 (struct GNUNET_TESTING_Peer *peer, | 1211 | GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, |
1286 | struct GNUNET_TIME_Relative timeout) | 1212 | GNUNET_TESTING_PeerStopCallback cb, |
1213 | void *cb_cls) | ||
1287 | { | 1214 | { |
1215 | if (NULL == peer->main_process) | ||
1216 | return GNUNET_SYSERR; | ||
1217 | peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer); | ||
1288 | if (NULL == peer->ah) | 1218 | if (NULL == peer->ah) |
1289 | return GNUNET_SYSERR; | 1219 | return GNUNET_SYSERR; |
1290 | GNUNET_assert (NULL != peer->cb); | 1220 | peer->cb = cb; |
1291 | GNUNET_TESTING_peer_service_stop (peer, "arm", timeout, NULL, NULL); | 1221 | peer->cb_cls = cb_cls; |
1292 | return GNUNET_OK; | 1222 | return GNUNET_OK; |
1293 | } | 1223 | } |
1294 | 1224 | ||
@@ -1307,6 +1237,8 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer) | |||
1307 | GNUNET_TESTING_peer_stop (peer); | 1237 | GNUNET_TESTING_peer_stop (peer); |
1308 | if (NULL != peer->ah) | 1238 | if (NULL != peer->ah) |
1309 | GNUNET_ARM_disconnect_and_free (peer->ah); | 1239 | GNUNET_ARM_disconnect_and_free (peer->ah); |
1240 | if (NULL != peer->mh) | ||
1241 | GNUNET_ARM_monitor_disconnect_and_free (peer->mh); | ||
1310 | GNUNET_free (peer->cfgfile); | 1242 | GNUNET_free (peer->cfgfile); |
1311 | if (NULL != peer->cfg) | 1243 | if (NULL != peer->cfg) |
1312 | GNUNET_CONFIGURATION_destroy (peer->cfg); | 1244 | GNUNET_CONFIGURATION_destroy (peer->cfg); |