aboutsummaryrefslogtreecommitdiff
path: root/src/arm/arm_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-05-21 15:00:57 +0000
committerChristian Grothoff <christian@grothoff.org>2013-05-21 15:00:57 +0000
commit10561f9cfb81341449a94edb54fc7154ad8ab9e0 (patch)
tree2da88f4c191c2c3b02c1f9de5622a5f2fb8fa4bd /src/arm/arm_api.c
parent778791c966977cbeb841555c415c24c5778f5378 (diff)
downloadgnunet-10561f9cfb81341449a94edb54fc7154ad8ab9e0.tar.gz
gnunet-10561f9cfb81341449a94edb54fc7154ad8ab9e0.zip
fixing ARM restarting, adding monitor mode to command line
Diffstat (limited to 'src/arm/arm_api.c')
-rw-r--r--src/arm/arm_api.c77
1 files changed, 73 insertions, 4 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index eb9194eec..8cdcfdeb5 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -83,6 +83,12 @@ struct GNUNET_ARM_Handle
83 void *conn_status_cls; 83 void *conn_status_cls;
84 84
85 /** 85 /**
86 * ARM control message for the 'arm_termination_handler'
87 * with the continuation to call once the ARM shutdown is done.
88 */
89 struct ARMControlMessage *thm;
90
91 /**
86 * ID of the reconnect task (if any). 92 * ID of the reconnect task (if any).
87 */ 93 */
88 GNUNET_SCHEDULER_TaskIdentifier reconnect_task; 94 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
@@ -266,6 +272,40 @@ find_cm_by_id (struct GNUNET_ARM_Handle *h, uint64_t id)
266 272
267 273
268/** 274/**
275 * Handler for ARM 'termination' reply (failure to receive).
276 *
277 * @param cls our "struct GNUNET_ARM_Handle"
278 * @param msg expected to be NULL
279 */
280static void
281arm_termination_handler (void *cls, const struct GNUNET_MessageHeader *msg)
282{
283 struct GNUNET_ARM_Handle *h = cls;
284 struct ARMControlMessage *cm;
285
286 if (NULL != msg)
287 {
288 GNUNET_break (0);
289 GNUNET_CLIENT_receive (h->client, &arm_termination_handler, h,
290 GNUNET_TIME_UNIT_FOREVER_REL);
291 return;
292 }
293 cm = h->thm;
294 h->thm = NULL;
295 h->currently_down = GNUNET_YES;
296 GNUNET_CLIENT_disconnect (h->client);
297 h->client = NULL;
298 if (NULL != cm->result_cont)
299 cm->result_cont (cm->cont_cls,
300 GNUNET_ARM_REQUEST_SENT_OK,
301 (const char *) &cm->msg[1],
302 GNUNET_ARM_RESULT_STOPPED);
303 GNUNET_free (cm->msg);
304 GNUNET_free (cm);
305}
306
307
308/**
269 * Handler for ARM replies. 309 * Handler for ARM replies.
270 * 310 *
271 * @param cls our "struct GNUNET_ARM_Handle" 311 * @param cls our "struct GNUNET_ARM_Handle"
@@ -374,6 +414,32 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
374 GNUNET_free (cm); 414 GNUNET_free (cm);
375 return; 415 return;
376 } 416 }
417 if ( (GNUNET_MESSAGE_TYPE_ARM_RESULT == ntohs (msg->type)) &&
418 (0 == strcasecmp ((const char *) &cm->msg[1],
419 "arm")) &&
420 (NULL != (res = (const struct GNUNET_ARM_ResultMessage *) msg)) &&
421 (GNUNET_ARM_RESULT_STOPPING == ntohl (res->result)) )
422 {
423 /* special case: if we are stopping 'gnunet-service-arm', we do not just
424 wait for the result message, but also wait for the service to close
425 the connection (and then we have to close our client handle as well);
426 this is done by installing a different receive handler, waiting for
427 the connection to go down */
428 if (NULL != h->thm)
429 {
430 GNUNET_break (0);
431 cm->result_cont (h->thm->cont_cls,
432 GNUNET_ARM_REQUEST_SENT_OK,
433 (const char *) &h->thm->msg[1],
434 GNUNET_ARM_RESULT_IS_NOT_KNOWN);
435 GNUNET_free (h->thm->msg);
436 GNUNET_free (h->thm);
437 }
438 h->thm = cm;
439 GNUNET_CLIENT_receive (h->client, &arm_termination_handler, h,
440 GNUNET_TIME_UNIT_FOREVER_REL);
441 return;
442 }
377 GNUNET_CLIENT_receive (h->client, &client_notify_handler, h, 443 GNUNET_CLIENT_receive (h->client, &client_notify_handler, h,
378 GNUNET_TIME_UNIT_FOREVER_REL); 444 GNUNET_TIME_UNIT_FOREVER_REL);
379 switch (ntohs (msg->type)) 445 switch (ntohs (msg->type))
@@ -845,8 +911,9 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
845 memcpy (&msg[1], service_name, slen); 911 memcpy (&msg[1], service_name, slen);
846 cm->msg = msg; 912 cm->msg = msg;
847 LOG (GNUNET_ERROR_TYPE_DEBUG, 913 LOG (GNUNET_ERROR_TYPE_DEBUG,
848 "Inserting a control message into the queue. Timeout is %llu\n", 914 "Inserting a control message into the queue. Timeout is %s\n",
849 GNUNET_TIME_absolute_get_remaining (cm->timeout).rel_value); 915 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (cm->timeout),
916 GNUNET_NO));
850 GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, 917 GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
851 h->control_pending_tail, cm); 918 h->control_pending_tail, cm);
852 cm->timeout_task_id = 919 cm->timeout_task_id =
@@ -959,8 +1026,10 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
959 */ 1026 */
960void 1027void
961GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, 1028GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
962 const char *service_name, struct GNUNET_TIME_Relative timeout, 1029 const char *service_name,
963 GNUNET_ARM_ResultCallback cont, void *cont_cls) 1030 struct GNUNET_TIME_Relative timeout,
1031 GNUNET_ARM_ResultCallback cont,
1032 void *cont_cls)
964{ 1033{
965 LOG (GNUNET_ERROR_TYPE_DEBUG, 1034 LOG (GNUNET_ERROR_TYPE_DEBUG,
966 "Stopping service `%s' within %s\n", 1035 "Stopping service `%s' within %s\n",