- using de/serialization functionality
[oweals/gnunet.git] / src / arm / arm_api.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010 Christian Grothoff (and other contributing authors)
4
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
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file arm/arm_api.c
23  * @brief API for accessing the ARM service
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_arm_service.h"
28 #include "gnunet_client_lib.h"
29 #include "gnunet_getopt_lib.h"
30 #include "gnunet_os_lib.h"
31 #include "gnunet_protocols.h"
32 #include "gnunet_server_lib.h"
33 #include "arm.h"
34
35 #define LOG(kind,...) GNUNET_log_from (kind, "arm-api",__VA_ARGS__)
36
37 /**
38  * Handle for interacting with ARM.
39  */
40 struct GNUNET_ARM_Handle
41 {
42
43   /**
44    * Our connection to the ARM service.
45    */
46   struct GNUNET_CLIENT_Connection *client;
47
48   /**
49    * The configuration that we are using.
50    */
51   struct GNUNET_CONFIGURATION_Handle *cfg;
52
53 };
54
55
56 /**
57  * Context for handling the shutdown of a service.
58  */
59 struct ShutdownContext
60 {
61   /**
62    * Connection to the service that is being shutdown.
63    */
64   struct GNUNET_CLIENT_Connection *sock;
65
66   /**
67    * Time allowed for shutdown to happen.
68    */
69   struct GNUNET_TIME_Absolute timeout;
70
71   /**
72    * Task set up to cancel the shutdown request on timeout.
73    */
74   GNUNET_SCHEDULER_TaskIdentifier cancel_task;
75
76   /**
77    * Task to call once shutdown complete
78    */
79   GNUNET_CLIENT_ShutdownTask cont;
80
81   /**
82    * Closure for shutdown continuation
83    */
84   void *cont_cls;
85
86   /**
87    * Result of the operation
88    */
89   enum GNUNET_ARM_ProcessStatus confirmed;
90
91 };
92
93
94 /**
95  * Handler receiving response to service shutdown requests.
96  * First call with NULL: service misbehaving, or something.
97  * First call with GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK:
98  *   - service will shutdown
99  * Second call with NULL:
100  *   - service has now really shut down.
101  *
102  * @param cls closure
103  * @param msg NULL, indicating socket closure.
104  */
105 static void
106 service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
107 {
108   struct ShutdownContext *shutdown_ctx = cls;
109   const struct GNUNET_ARM_ResultMessage *rmsg;
110
111   if (msg == NULL)
112   {
113     if (shutdown_ctx->cont != NULL)
114     {
115       if (shutdown_ctx->confirmed == GNUNET_ARM_PROCESS_SHUTDOWN)
116       {
117         /* shutdown is now complete, as we waited for the network disconnect... */
118         shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_ARM_PROCESS_DOWN);
119       }
120       else
121       {
122         /* communication error */
123         shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
124       }
125     }
126     GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
127     GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
128     GNUNET_free (shutdown_ctx);
129     return;
130   }
131   if (ntohs (msg->size) ==
132       sizeof (struct GNUNET_ARM_ResultMessage))
133   {
134     rmsg = (const struct GNUNET_ARM_ResultMessage*) msg;
135     shutdown_ctx->confirmed = (enum GNUNET_ARM_ProcessStatus) ntohl (rmsg->status);
136     if (shutdown_ctx->confirmed != GNUNET_ARM_PROCESS_SHUTDOWN)
137     {
138       /* ARM is not shutting down, well, report the error and be done with it... */
139       shutdown_ctx->cont (shutdown_ctx->cont_cls, shutdown_ctx->confirmed);
140       GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
141       GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
142       GNUNET_free (shutdown_ctx);
143       return;
144     }
145   }
146   GNUNET_CLIENT_receive (shutdown_ctx->sock, &service_shutdown_handler,
147                          shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
148 }
149
150
151 /**
152  * Shutting down took too long, cancel receive and return error.
153  *
154  * @param cls closure
155  * @param tc context information (why was this task triggered now)
156  */
157 static void
158 service_shutdown_cancel (void *cls,
159                          const struct GNUNET_SCHEDULER_TaskContext *tc)
160 {
161   struct ShutdownContext *shutdown_ctx = cls;
162
163   shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_ARM_PROCESS_COMMUNICATION_TIMEOUT);
164   GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
165   GNUNET_free (shutdown_ctx);
166 }
167
168
169 /**
170  * If possible, write a shutdown message to the target
171  * buffer and destroy the client connection.
172  *
173  * @param cls the "struct GNUNET_CLIENT_Connection" to destroy
174  * @param size number of bytes available in buf
175  * @param buf NULL on error, otherwise target buffer
176  * @return number of bytes written to buf
177  */
178 static size_t
179 write_shutdown (void *cls, size_t size, void *buf)
180 {
181   struct GNUNET_MessageHeader *msg;
182   struct ShutdownContext *shutdown_ctx = cls;
183
184   if (size < sizeof (struct GNUNET_MessageHeader))
185     {
186       LOG (GNUNET_ERROR_TYPE_WARNING,
187            _("Failed to transmit shutdown request to client.\n"));
188       shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
189       GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
190       GNUNET_free (shutdown_ctx);
191       return 0;                 /* client disconnected */
192     }
193
194   GNUNET_CLIENT_receive (shutdown_ctx->sock, &service_shutdown_handler,
195                          shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
196   shutdown_ctx->cancel_task =
197     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
198                                   (shutdown_ctx->timeout),
199                                   &service_shutdown_cancel, shutdown_ctx);
200   msg = (struct GNUNET_MessageHeader *) buf;
201   msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN);
202   msg->size = htons (sizeof (struct GNUNET_MessageHeader));
203   return sizeof (struct GNUNET_MessageHeader);
204 }
205
206
207 /**
208  * Request that the service should shutdown.
209  * Afterwards, the connection will automatically be
210  * disconnected.  Hence the "sock" should not
211  * be used by the caller after this call
212  * (calling this function frees "sock" after a while).
213  *
214  * @param sock the socket connected to the service
215  * @param timeout how long to wait before giving up on transmission
216  * @param cont continuation to call once the service is really down
217  * @param cont_cls closure for continuation
218  *
219  */
220 static void
221 arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
222                       struct GNUNET_TIME_Relative timeout,
223                       GNUNET_CLIENT_ShutdownTask cont, void *cont_cls)
224 {
225   struct ShutdownContext *shutdown_ctx;
226
227   shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
228   shutdown_ctx->cont = cont;
229   shutdown_ctx->cont_cls = cont_cls;
230   shutdown_ctx->sock = sock;
231   shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
232   shutdown_ctx->confirmed = GNUNET_ARM_PROCESS_COMMUNICATION_ERROR;    
233   /* FIXME: store return value? */
234   GNUNET_CLIENT_notify_transmit_ready (sock,
235                                        sizeof (struct GNUNET_MessageHeader),
236                                        timeout, GNUNET_YES, &write_shutdown,
237                                        shutdown_ctx);
238 }
239
240
241 /**
242  * Setup a context for communicating with ARM.  Note that this
243  * can be done even if the ARM service is not yet running.
244  *
245  * @param cfg configuration to use (needed to contact ARM;
246  *        the ARM service may internally use a different
247  *        configuration to determine how to start the service).
248  * @param service service that *this* process is implementing/providing, can be NULL
249  * @return context to use for further ARM operations, NULL on error
250  */
251 struct GNUNET_ARM_Handle *
252 GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
253                     const char *service)
254 {
255   struct GNUNET_ARM_Handle *ret;
256
257   ret = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle));
258   ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
259   return ret;
260 }
261
262
263 /**
264  * Disconnect from the ARM service.
265  *
266  * @param h the handle that was being used
267  */
268 void
269 GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h)
270 {
271   if (h->client != NULL)
272     GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
273   GNUNET_CONFIGURATION_destroy (h->cfg);
274   GNUNET_free (h);
275 }
276
277
278 struct ARM_ShutdownContext
279 {
280   /**
281    * Callback to call once shutdown complete.
282    */
283   GNUNET_ARM_Callback cb;
284
285   /**
286    * Closure for callback.
287    */
288   void *cb_cls;
289 };
290
291
292 /**
293  * Internal state for a request with ARM.
294  */
295 struct RequestContext
296 {
297
298   /**
299    * Pointer to our handle with ARM.
300    */
301   struct GNUNET_ARM_Handle *h;
302
303   /**
304    * Function to call with a status code for the requested operation.
305    */
306   GNUNET_ARM_Callback callback;
307
308   /**
309    * Closure for "callback".
310    */
311   void *cls;
312
313   /**
314    * Timeout for the operation.
315    */
316   struct GNUNET_TIME_Absolute timeout;
317
318   /**
319    * Type of the request expressed as a message type (start or stop).
320    */
321   uint16_t type;
322
323 };
324
325 #include "do_start_process.c"
326
327
328 /**
329  * A client specifically requested starting of ARM itself.
330  * This function is called with information about whether
331  * or not ARM is running; if it is, report success.  If
332  * it is not, start the ARM process.
333  *
334  * @param cls the context for the request that we will report on (struct RequestContext*)
335  * @param tc why were we called (reason says if ARM is running)
336  */
337 static void
338 arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
339 {
340   struct RequestContext *pos = cls;
341   struct GNUNET_OS_Process *proc;
342   char *binary;
343   char *config;
344   char *loprefix;
345   char *lopostfix;
346
347   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
348     {
349 #if DEBUG_ARM
350       LOG (GNUNET_ERROR_TYPE_DEBUG, "Looks like `%s' is already running.\n",
351            "gnunet-service-arm");
352 #endif
353       /* arm is running! */
354       if (pos->callback != NULL)
355         pos->callback (pos->cls, GNUNET_ARM_PROCESS_ALREADY_RUNNING);
356       GNUNET_free (pos);
357       return;
358     }
359 #if DEBUG_ARM
360   LOG (GNUNET_ERROR_TYPE_DEBUG,
361        "Looks like `%s' is not running, will start it.\n",
362        "gnunet-service-arm");
363 #endif
364   if (GNUNET_OK !=
365       GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, "arm", "PREFIX",
366                                              &loprefix))
367     loprefix = GNUNET_strdup ("");
368   if (GNUNET_OK !=
369       GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, "arm", "OPTIONS",
370                                              &lopostfix))
371     lopostfix = GNUNET_strdup ("");
372   if (GNUNET_OK !=
373       GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, "arm", "BINARY",
374                                              &binary))
375     {
376       LOG (GNUNET_ERROR_TYPE_WARNING,
377            _
378            ("Configuration failes to specify option `%s' in section `%s'!\n"),
379            "BINARY", "arm");
380       if (pos->callback != NULL)
381         pos->callback (pos->cls, GNUNET_ARM_PROCESS_UNKNOWN);
382       GNUNET_free (pos);
383       GNUNET_free (loprefix);
384       GNUNET_free (lopostfix);
385       return;
386     }
387   if (GNUNET_OK !=
388       GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg, "arm", "CONFIG",
389                                                &config))
390     {
391       LOG (GNUNET_ERROR_TYPE_WARNING,
392            _("Configuration fails to specify option `%s' in section `%s'!\n"),
393            "CONFIG", "arm");
394       if (pos->callback != NULL)
395         pos->callback (pos->cls, GNUNET_ARM_PROCESS_UNKNOWN);
396       GNUNET_free (binary);
397       GNUNET_free (pos);
398       GNUNET_free (loprefix);
399       GNUNET_free (lopostfix);
400       return;
401     }
402   if ((GNUNET_YES ==
403        GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING", "WEAKRANDOM"))
404       && (GNUNET_YES ==
405           GNUNET_CONFIGURATION_get_value_yesno (pos->h->cfg, "TESTING",
406                                                 "WEAKRANDOM"))
407       && (GNUNET_NO ==
408           GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING",
409                                            "HOSTFILE")))
410     {
411       /* Means we are ONLY running locally */
412       /* we're clearly running a test, don't daemonize */
413       proc = do_start_process (GNUNET_NO,
414                                NULL, loprefix, binary, "-c", config,
415 #if DEBUG_ARM
416                                "-L", "DEBUG",
417 #endif
418                                /* no daemonization! */
419                                lopostfix, NULL);
420     }
421   else
422     {
423       proc = do_start_process (GNUNET_NO,
424                                NULL, loprefix, binary, "-c", config,
425 #if DEBUG_ARM
426                                "-L", "DEBUG",
427 #endif
428                                "-d", lopostfix, NULL);
429     }
430   GNUNET_free (binary);
431   GNUNET_free (config);
432   GNUNET_free (loprefix);
433   GNUNET_free (lopostfix);
434   if (proc == NULL)
435     {
436       if (pos->callback != NULL)
437         pos->callback (pos->cls, GNUNET_ARM_PROCESS_FAILURE);
438       GNUNET_free (pos);
439       return;
440     }
441   if (pos->callback != NULL)
442     pos->callback (pos->cls, GNUNET_ARM_PROCESS_STARTING);
443   GNUNET_free (proc);
444   GNUNET_free (pos);
445 }
446
447
448 /**
449  * Process a response from ARM to a request for a change in service
450  * status.
451  *
452  * @param cls the request context
453  * @param msg the response
454  */
455 static void
456 handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
457 {
458   struct RequestContext *sc = cls;
459   const struct GNUNET_ARM_ResultMessage *res;
460   enum GNUNET_ARM_ProcessStatus status;
461
462   if ((msg == NULL) ||
463       (ntohs (msg->size) != sizeof (struct GNUNET_ARM_ResultMessage)))
464     {
465       LOG (GNUNET_ERROR_TYPE_WARNING,
466            _
467            ("Error receiving response to `%s' request from ARM for service `%s'\n"),
468            (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) ? "START" : "STOP",
469            (const char *) &sc[1]);
470       GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO);
471       sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg);
472       GNUNET_assert (NULL != sc->h->client);
473       if (sc->callback != NULL)
474         sc->callback (sc->cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
475       GNUNET_free (sc);
476       return;
477     }
478   res = (const struct GNUNET_ARM_ResultMessage *) msg;
479 #if DEBUG_ARM
480   LOG (GNUNET_ERROR_TYPE_DEBUG,
481        "Received response from ARM for service `%s': %u\n",
482        (const char *) &sc[1], ntohs (msg->type));
483 #endif
484   status = (enum GNUNET_ARM_ProcessStatus) ntohl (res->status);
485   if (sc->callback != NULL)
486     sc->callback (sc->cls, status);
487   GNUNET_free (sc);
488 }
489
490
491 /**
492  * Start or stop a service.
493  *
494  * @param h handle to ARM
495  * @param service_name name of the service
496  * @param timeout how long to wait before failing for good
497  * @param cb callback to invoke when service is ready
498  * @param cb_cls closure for callback
499  * @param type type of the request
500  */
501 static void
502 change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
503                 struct GNUNET_TIME_Relative timeout, GNUNET_ARM_Callback cb,
504                 void *cb_cls, uint16_t type)
505 {
506   struct RequestContext *sctx;
507   size_t slen;
508   struct GNUNET_MessageHeader *msg;
509
510   slen = strlen (service_name) + 1;
511   if (slen + sizeof (struct GNUNET_MessageHeader) >=
512       GNUNET_SERVER_MAX_MESSAGE_SIZE)
513     {
514       GNUNET_break (0);
515       if (cb != NULL)
516         cb (cb_cls, GNUNET_NO);
517       return;
518     }
519 #if DEBUG_ARM
520   LOG (GNUNET_ERROR_TYPE_DEBUG,
521        (type ==
522         GNUNET_MESSAGE_TYPE_ARM_START) ?
523        _("Requesting start of service `%s'.\n") :
524        _("Requesting termination of service `%s'.\n"), service_name);
525 #endif
526   sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
527   sctx->h = h;
528   sctx->callback = cb;
529   sctx->cls = cb_cls;
530   sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
531   sctx->type = type;
532   memcpy (&sctx[1], service_name, slen);
533   msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader) + slen);
534   msg->size = htons (sizeof (struct GNUNET_MessageHeader) + slen);
535   msg->type = htons (sctx->type);
536   memcpy (&msg[1], service_name, slen);
537   if (GNUNET_OK !=
538       GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, msg,
539                                                GNUNET_TIME_absolute_get_remaining
540                                                (sctx->timeout), GNUNET_YES,
541                                                &handle_response, sctx))
542     {
543       LOG (GNUNET_ERROR_TYPE_WARNING,
544            (type ==
545             GNUNET_MESSAGE_TYPE_ARM_START) ?
546            _("Error while trying to transmit request to start `%s' to ARM\n")
547            :
548            _("Error while trying to transmit request to stop `%s' to ARM\n"),
549            (const char *) &service_name);
550       if (cb != NULL)
551         cb (cb_cls, GNUNET_SYSERR);
552       GNUNET_free (sctx);
553       GNUNET_free (msg);
554       return;
555     }
556   GNUNET_free (msg);
557 }
558
559
560 /**
561  * Start a service.
562  *
563  * @param h handle to ARM
564  * @param service_name name of the service
565  * @param timeout how long to wait before failing for good
566  * @param cb callback to invoke when service is ready
567  * @param cb_cls closure for callback
568  */
569 void
570 GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
571                           const char *service_name,
572                           struct GNUNET_TIME_Relative timeout,
573                           GNUNET_ARM_Callback cb, void *cb_cls)
574 {
575   struct RequestContext *sctx;
576   struct GNUNET_CLIENT_Connection *client;
577   size_t slen;
578
579 #if DEBUG_ARM
580   LOG (GNUNET_ERROR_TYPE_DEBUG,
581        _("Asked to start service `%s' within %llu ms\n"), service_name,
582        (unsigned long long) timeout.rel_value);
583 #endif
584   if (0 == strcasecmp ("arm", service_name))
585     {
586       slen = strlen ("arm") + 1;
587       sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
588       sctx->h = h;
589       sctx->callback = cb;
590       sctx->cls = cb_cls;
591       sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
592       memcpy (&sctx[1], service_name, slen);
593       GNUNET_CLIENT_service_test ("arm", h->cfg, timeout, &arm_service_report,
594                                   sctx);
595       return;
596     }
597   if (h->client == NULL)
598     {
599       client = GNUNET_CLIENT_connect ("arm", h->cfg);
600       if (client == NULL)
601         {
602           LOG (GNUNET_ERROR_TYPE_DEBUG,
603                "arm_api, GNUNET_CLIENT_connect returned NULL\n");
604           cb (cb_cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
605           return;
606         }
607       LOG (GNUNET_ERROR_TYPE_DEBUG,
608            "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
609       h->client = client;
610     }
611   LOG (GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n");
612   change_service (h, service_name, timeout, cb, cb_cls,
613                   GNUNET_MESSAGE_TYPE_ARM_START);
614 }
615
616
617 /**
618  * Callback from the arm stop service call, indicates that the arm service
619  * is well and truly dead, won't die, or an error occurred.
620  *
621  * @param cls closure for the callback
622  * @param reason reason for callback
623  */
624 static void
625 arm_shutdown_callback (void *cls, enum GNUNET_ARM_ProcessStatus reason)
626 {
627   struct ARM_ShutdownContext *arm_shutdown_ctx = cls;
628
629   if (arm_shutdown_ctx->cb != NULL)
630     arm_shutdown_ctx->cb (arm_shutdown_ctx->cb_cls, reason);
631
632   GNUNET_free (arm_shutdown_ctx);
633 }
634
635
636 /**
637  * Stop a service.
638  *
639  * @param h handle to ARM
640  * @param service_name name of the service
641  * @param timeout how long to wait before failing for good
642  * @param cb callback to invoke when service is ready
643  * @param cb_cls closure for callback
644  */
645 void
646 GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h,
647                          const char *service_name,
648                          struct GNUNET_TIME_Relative timeout,
649                          GNUNET_ARM_Callback cb, void *cb_cls)
650 {
651   struct ARM_ShutdownContext *arm_shutdown_ctx;
652   struct GNUNET_CLIENT_Connection *client;
653
654   LOG (GNUNET_ERROR_TYPE_INFO, _("Stopping service `%s' within %llu ms\n"),
655        service_name, (unsigned long long) timeout.rel_value);
656   if (h->client == NULL)
657     {
658       client = GNUNET_CLIENT_connect ("arm", h->cfg);
659       if (client == NULL)
660         {
661           cb (cb_cls, GNUNET_SYSERR);
662           return;
663         }
664       h->client = client;
665     }
666   if (0 == strcasecmp ("arm", service_name))
667     {
668       arm_shutdown_ctx = GNUNET_malloc (sizeof (struct ARM_ShutdownContext));
669       arm_shutdown_ctx->cb = cb;
670       arm_shutdown_ctx->cb_cls = cb_cls;
671       arm_service_shutdown (h->client, timeout, &arm_shutdown_callback,
672                             arm_shutdown_ctx);
673       h->client = NULL;
674       return;
675     }
676   change_service (h, service_name, timeout, cb, cb_cls,
677                   GNUNET_MESSAGE_TYPE_ARM_STOP);
678 }
679
680
681 /* end of arm_api.c */