[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: make stop_peer cmd asynchronous
From: |
gnunet |
Subject: |
[gnunet] branch master updated: make stop_peer cmd asynchronous |
Date: |
Mon, 20 May 2024 17:24:35 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 6939b894f make stop_peer cmd asynchronous
6939b894f is described below
commit 6939b894f32093634a4a84f2420b38a28c3f4fe5
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon May 20 17:24:30 2024 +0200
make stop_peer cmd asynchronous
---
src/include/gnunet_testing_arm_lib.h | 2 +-
src/service/arm/arm_api.c | 77 +++++++++++++++-----------
src/service/arm/testing_arm_cmd_stop_peer.c | 85 ++++++++++++++++++++++-------
3 files changed, 111 insertions(+), 53 deletions(-)
diff --git a/src/include/gnunet_testing_arm_lib.h
b/src/include/gnunet_testing_arm_lib.h
index abc5d187a..66852b506 100644
--- a/src/include/gnunet_testing_arm_lib.h
+++ b/src/include/gnunet_testing_arm_lib.h
@@ -37,7 +37,7 @@ GNUNET_TESTING_cmd_stop_peer (
#define GNUNET_TESTING_ARM_SIMPLE_TRAITS(op, prefix) \
op (prefix, \
arm_handle, \
- const struct GNUNET_ARM_Handle)
+ struct GNUNET_ARM_Handle)
GNUNET_TESTING_ARM_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT,
diff --git a/src/service/arm/arm_api.c b/src/service/arm/arm_api.c
index 1360ecf14..bc5efbd3f 100644
--- a/src/service/arm/arm_api.c
+++ b/src/service/arm/arm_api.c
@@ -346,7 +346,7 @@ pool_get (const char *pool_start,
* @param lres the message received from the arm service
* @return #GNUNET_OK if message is well-formed
*/
-static int
+static enum GNUNET_GenericReturnValue
check_arm_list_result (void *cls,
const struct GNUNET_ARM_ListResultMessage *lres)
{
@@ -515,7 +515,7 @@ mq_error_handler (void *cls,
* @param h arm handle
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-static int
+static enum GNUNET_GenericReturnValue
reconnect_arm (struct GNUNET_ARM_Handle *h)
{
struct GNUNET_MQ_MessageHandler handlers[] = {
@@ -574,9 +574,10 @@ reconnect_arm (struct GNUNET_ARM_Handle *h)
* @return context to use for further ARM operations, NULL on error.
*/
struct GNUNET_ARM_Handle *
-GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_ARM_ConnectionStatusCallback conn_status,
- void *conn_status_cls)
+GNUNET_ARM_connect (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_ARM_ConnectionStatusCallback conn_status,
+ void *conn_status_cls)
{
struct GNUNET_ARM_Handle *h;
@@ -673,17 +674,19 @@ start_arm_service (struct GNUNET_ARM_Handle *h,
ld[1] = -1;
lsocks = ld;
}
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg,
- "arm",
- "PREFIX",
- &loprefix))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (h->cfg,
+ "arm",
+ "PREFIX",
+ &loprefix))
loprefix = GNUNET_strdup ("");
else
loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix);
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg,
- "arm",
- "OPTIONS",
- &lopostfix))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (h->cfg,
+ "arm",
+ "OPTIONS",
+ &lopostfix))
lopostfix = GNUNET_strdup ("");
else
lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg,
@@ -701,10 +704,11 @@ start_arm_service (struct GNUNET_ARM_Handle *h,
GNUNET_free (lopostfix);
return GNUNET_ARM_RESULT_IS_NOT_KNOWN;
}
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg,
- "arm",
- "CONFIG",
- &config))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (h->cfg,
+ "arm",
+ "CONFIG",
+ &config))
config = NULL;
binary = GNUNET_OS_get_libexec_binary_path (cbinary);
GNUNET_asprintf ("edbinary,
@@ -850,10 +854,14 @@ change_service (struct GNUNET_ARM_Handle *h,
GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
h->operation_pending_tail,
op);
- env = GNUNET_MQ_msg_extra (msg, slen, type);
+ env = GNUNET_MQ_msg_extra (msg,
+ slen,
+ type);
msg->reserved = htonl (0);
msg->request_id = GNUNET_htonll (op->id);
- GNUNET_memcpy (&msg[1], service_name, slen);
+ GNUNET_memcpy (&msg[1],
+ service_name,
+ slen);
GNUNET_MQ_send (h->mq, env);
return op;
}
@@ -907,7 +915,7 @@ notify_starting (void *cls)
op->result_cont (op->cont_cls,
GNUNET_ARM_REQUEST_SENT_OK,
op->starting_ret);
- GNUNET_DISK_file_close(op->rfd);
+ GNUNET_DISK_file_close (op->rfd);
GNUNET_free (op);
}
@@ -923,12 +931,13 @@ notify_starting (void *cls)
* @return handle for the operation, NULL on error
*/
struct GNUNET_ARM_Operation *
-GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
- const char *service_name,
- enum GNUNET_OS_InheritStdioFlags
- std_inheritance,
- GNUNET_ARM_ResultCallback cont,
- void *cont_cls)
+GNUNET_ARM_request_service_start (
+ struct GNUNET_ARM_Handle *h,
+ const char *service_name,
+ enum GNUNET_OS_InheritStdioFlags
+ std_inheritance,
+ GNUNET_ARM_ResultCallback cont,
+ void *cont_cls)
{
struct GNUNET_ARM_Operation *op;
enum GNUNET_ARM_Result ret;
@@ -1035,10 +1044,11 @@ GNUNET_ARM_request_service_start (struct
GNUNET_ARM_Handle *h,
* @return handle for the operation, NULL on error
*/
struct GNUNET_ARM_Operation *
-GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
- const char *service_name,
- GNUNET_ARM_ResultCallback cont,
- void *cont_cls)
+GNUNET_ARM_request_service_stop (
+ struct GNUNET_ARM_Handle *h,
+ const char *service_name,
+ GNUNET_ARM_ResultCallback cont,
+ void *cont_cls)
{
struct GNUNET_ARM_Operation *op;
@@ -1070,9 +1080,10 @@ GNUNET_ARM_request_service_stop (struct
GNUNET_ARM_Handle *h,
* @return handle for the operation, NULL on error
*/
struct GNUNET_ARM_Operation *
-GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
- GNUNET_ARM_ServiceListCallback cont,
- void *cont_cls)
+GNUNET_ARM_request_service_list (
+ struct GNUNET_ARM_Handle *h,
+ GNUNET_ARM_ServiceListCallback cont,
+ void *cont_cls)
{
struct GNUNET_ARM_Operation *op;
struct GNUNET_MQ_Envelope *env;
diff --git a/src/service/arm/testing_arm_cmd_stop_peer.c
b/src/service/arm/testing_arm_cmd_stop_peer.c
index f0394dd5e..e83b2bf29 100644
--- a/src/service/arm/testing_arm_cmd_stop_peer.c
+++ b/src/service/arm/testing_arm_cmd_stop_peer.c
@@ -27,11 +27,12 @@
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include "gnunet_testbed_lib.h"
-#include "gnunet_testing_transport_lib.h"
+#include "gnunet_testing_arm_lib.h"
+#include "gnunet_arm_service.h"
+
/**
* Struct to hold information for callbacks.
- *
*/
struct StopPeerState
{
@@ -39,9 +40,48 @@ struct StopPeerState
* Label of the cmd to start the peer.
*/
const char *start_label;
+
+ /**
+ * Label of the cmd.
+ */
+ const char *label;
+
+ struct GNUNET_ARM_Operation *op;
+
+ struct GNUNET_TESTING_Interpreter *is;
+
+ struct GNUNET_TESTING_AsyncContext ac;
};
+/**
+ * Function called in response to a start/stop request.
+ * Will be called when request was not sent successfully,
+ * or when a reply comes. If the request was not sent successfully,
+ * @a rs will indicate that, and @a result will be undefined.
+ *
+ * @param cls closure
+ * @param rs status of the request
+ * @param result result of the operation
+ */
+static void
+stop_cb (
+ void *cls,
+ enum GNUNET_ARM_RequestStatus rs,
+ enum GNUNET_ARM_Result result)
+{
+ struct StopPeerState *stop_ps = cls;
+
+ stop_ps->op = NULL;
+ if (GNUNET_ARM_RESULT_STOPPED != result)
+ {
+ GNUNET_TESTING_async_fail (&stop_ps->ac);
+ return;
+ }
+ GNUNET_TESTING_async_finish (&stop_ps->ac);
+}
+
+
/**
* The run method of this cmd will stop all services of a peer which were used
to test the transport service.
*
@@ -52,26 +92,23 @@ stop_peer_run (void *cls,
{
struct StopPeerState *stop_ps = cls;
const struct GNUNET_TESTING_Command *start_cmd;
- struct GNUNET_OS_Process **proc;
+ struct GNUNET_ARM_Handle *ah;
+ stop_ps->is = is;
start_cmd
= GNUNET_TESTING_interpreter_lookup_command (is,
stop_ps->start_label);
if (NULL == start_cmd)
GNUNET_TESTING_FAIL (is);
- /* FIMXE: maybe use the *ARM* handle to stop the peer
- and actually _wait_ for it to be down (making this
- an asynchronous operation...) instead of just
- killing it without waiting for it to be done?
- Or use a child wait handle and wait for
- completion, and then NULL *proc in start? */
if (GNUNET_OK !=
- GNUNET_TESTING_get_trait_process (start_cmd,
- &proc))
+ GNUNET_TESTING_ARM_get_trait_arm_handle (start_cmd,
+ &ah))
GNUNET_TESTING_FAIL (is);
- if (0 !=
- GNUNET_OS_process_kill (*proc,
- SIGTERM))
+ stop_ps->op = GNUNET_ARM_request_service_stop (ah,
+ "arm",
+ &stop_cb,
+ stop_ps);
+ if (NULL == stop_ps->op)
GNUNET_TESTING_FAIL (is);
}
@@ -85,6 +122,13 @@ stop_peer_cleanup (void *cls)
{
struct StopPeerState *sps = cls;
+ if (NULL != sps->op)
+ {
+ GNUNET_TESTING_command_incomplete (sps->is,
+ sps->label);
+ GNUNET_ARM_operation_cancel (sps->op);
+ sps->op = NULL;
+ }
GNUNET_free (sps);
}
@@ -119,9 +163,12 @@ GNUNET_TESTING_cmd_stop_peer (const char *label,
sps = GNUNET_new (struct StopPeerState);
sps->start_label = start_label;
- return GNUNET_TESTING_command_new (sps,
- label,
- &stop_peer_run,
- &stop_peer_cleanup,
- &stop_peer_traits);
+ sps->label = label;
+ return GNUNET_TESTING_command_new_ac (
+ sps,
+ label,
+ &stop_peer_run,
+ &stop_peer_cleanup,
+ &stop_peer_traits,
+ &sps->ac);
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: make stop_peer cmd asynchronous,
gnunet <=