-check if /dev/net/tun exists and skip test otherwise
[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 (NULL, loprefix, binary, "-c", config,
414 #if DEBUG_ARM
415                                "-L", "DEBUG",
416 #endif
417                                /* no daemonization! */
418                                lopostfix, NULL);
419     }
420   else
421     {
422       proc = do_start_process (NULL, loprefix, binary, "-c", config,
423 #if DEBUG_ARM
424                                "-L", "DEBUG",
425 #endif
426                                "-d", lopostfix, NULL);
427     }
428   GNUNET_free (binary);
429   GNUNET_free (config);
430   GNUNET_free (loprefix);
431   GNUNET_free (lopostfix);
432   if (proc == NULL)
433     {
434       if (pos->callback != NULL)
435         pos->callback (pos->cls, GNUNET_ARM_PROCESS_FAILURE);
436       GNUNET_free (pos);
437       return;
438     }
439   if (pos->callback != NULL)
440     pos->callback (pos->cls, GNUNET_ARM_PROCESS_STARTING);
441   GNUNET_free (proc);
442   GNUNET_free (pos);
443 }
444
445
446 /**
447  * Process a response from ARM to a request for a change in service
448  * status.
449  *
450  * @param cls the request context
451  * @param msg the response
452  */
453 static void
454 handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
455 {
456   struct RequestContext *sc = cls;
457   const struct GNUNET_ARM_ResultMessage *res;
458   enum GNUNET_ARM_ProcessStatus status;
459
460   if ((msg == NULL) ||
461       (ntohs (msg->size) != sizeof (struct GNUNET_ARM_ResultMessage)))
462     {
463       LOG (GNUNET_ERROR_TYPE_WARNING,
464            _
465            ("Error receiving response to `%s' request from ARM for service `%s'\n"),
466            (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) ? "START" : "STOP",
467            (const char *) &sc[1]);
468       GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO);
469       sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg);
470       GNUNET_assert (NULL != sc->h->client);
471       if (sc->callback != NULL)
472         sc->callback (sc->cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
473       GNUNET_free (sc);
474       return;
475     }
476   res = (const struct GNUNET_ARM_ResultMessage *) msg;
477 #if DEBUG_ARM
478   LOG (GNUNET_ERROR_TYPE_DEBUG,
479        "Received response from ARM for service `%s': %u\n",
480        (const char *) &sc[1], ntohs (msg->type));
481 #endif
482   status = (enum GNUNET_ARM_ProcessStatus) ntohl (res->status);
483   if (sc->callback != NULL)
484     sc->callback (sc->cls, status);
485   GNUNET_free (sc);
486 }
487
488
489 /**
490  * Start or stop a service.
491  *
492  * @param h handle to ARM
493  * @param service_name name of the service
494  * @param timeout how long to wait before failing for good
495  * @param cb callback to invoke when service is ready
496  * @param cb_cls closure for callback
497  * @param type type of the request
498  */
499 static void
500 change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
501                 struct GNUNET_TIME_Relative timeout, GNUNET_ARM_Callback cb,
502                 void *cb_cls, uint16_t type)
503 {
504   struct RequestContext *sctx;
505   size_t slen;
506   struct GNUNET_MessageHeader *msg;
507
508   slen = strlen (service_name) + 1;
509   if (slen + sizeof (struct GNUNET_MessageHeader) >=
510       GNUNET_SERVER_MAX_MESSAGE_SIZE)
511     {
512       GNUNET_break (0);
513       if (cb != NULL)
514         cb (cb_cls, GNUNET_NO);
515       return;
516     }
517 #if DEBUG_ARM
518   LOG (GNUNET_ERROR_TYPE_DEBUG,
519        (type ==
520         GNUNET_MESSAGE_TYPE_ARM_START) ?
521        _("Requesting start of service `%s'.\n") :
522        _("Requesting termination of service `%s'.\n"), service_name);
523 #endif
524   sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
525   sctx->h = h;
526   sctx->callback = cb;
527   sctx->cls = cb_cls;
528   sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
529   sctx->type = type;
530   memcpy (&sctx[1], service_name, slen);
531   msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader) + slen);
532   msg->size = htons (sizeof (struct GNUNET_MessageHeader) + slen);
533   msg->type = htons (sctx->type);
534   memcpy (&msg[1], service_name, slen);
535   if (GNUNET_OK !=
536       GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, msg,
537                                                GNUNET_TIME_absolute_get_remaining
538                                                (sctx->timeout), GNUNET_YES,
539                                                &handle_response, sctx))
540     {
541       LOG (GNUNET_ERROR_TYPE_WARNING,
542            (type ==
543             GNUNET_MESSAGE_TYPE_ARM_START) ?
544            _("Error while trying to transmit request to start `%s' to ARM\n")
545            :
546            _("Error while trying to transmit request to stop `%s' to ARM\n"),
547            (const char *) &service_name);
548       if (cb != NULL)
549         cb (cb_cls, GNUNET_SYSERR);
550       GNUNET_free (sctx);
551       GNUNET_free (msg);
552       return;
553     }
554   GNUNET_free (msg);
555 }
556
557
558 /**
559  * Start a service.
560  *
561  * @param h handle to ARM
562  * @param service_name name of the service
563  * @param timeout how long to wait before failing for good
564  * @param cb callback to invoke when service is ready
565  * @param cb_cls closure for callback
566  */
567 void
568 GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
569                           const char *service_name,
570                           struct GNUNET_TIME_Relative timeout,
571                           GNUNET_ARM_Callback cb, void *cb_cls)
572 {
573   struct RequestContext *sctx;
574   struct GNUNET_CLIENT_Connection *client;
575   size_t slen;
576
577 #if DEBUG_ARM
578   LOG (GNUNET_ERROR_TYPE_DEBUG,
579        _("Asked to start service `%s' within %llu ms\n"), service_name,
580        (unsigned long long) timeout.rel_value);
581 #endif
582   if (0 == strcasecmp ("arm", service_name))
583     {
584       slen = strlen ("arm") + 1;
585       sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
586       sctx->h = h;
587       sctx->callback = cb;
588       sctx->cls = cb_cls;
589       sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
590       memcpy (&sctx[1], service_name, slen);
591       GNUNET_CLIENT_service_test ("arm", h->cfg, timeout, &arm_service_report,
592                                   sctx);
593       return;
594     }
595   if (h->client == NULL)
596     {
597       client = GNUNET_CLIENT_connect ("arm", h->cfg);
598       if (client == NULL)
599         {
600           LOG (GNUNET_ERROR_TYPE_DEBUG,
601                "arm_api, GNUNET_CLIENT_connect returned NULL\n");
602           cb (cb_cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
603           return;
604         }
605       LOG (GNUNET_ERROR_TYPE_DEBUG,
606            "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
607       h->client = client;
608     }
609   LOG (GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n");
610   change_service (h, service_name, timeout, cb, cb_cls,
611                   GNUNET_MESSAGE_TYPE_ARM_START);
612 }
613
614
615 /**
616  * Callback from the arm stop service call, indicates that the arm service
617  * is well and truly dead, won't die, or an error occurred.
618  *
619  * @param cls closure for the callback
620  * @param reason reason for callback
621  */
622 static void
623 arm_shutdown_callback (void *cls, enum GNUNET_ARM_ProcessStatus reason)
624 {
625   struct ARM_ShutdownContext *arm_shutdown_ctx = cls;
626
627   if (arm_shutdown_ctx->cb != NULL)
628     arm_shutdown_ctx->cb (arm_shutdown_ctx->cb_cls, reason);
629
630   GNUNET_free (arm_shutdown_ctx);
631 }
632
633
634 /**
635  * Stop a service.
636  *
637  * @param h handle to ARM
638  * @param service_name name of the service
639  * @param timeout how long to wait before failing for good
640  * @param cb callback to invoke when service is ready
641  * @param cb_cls closure for callback
642  */
643 void
644 GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h,
645                          const char *service_name,
646                          struct GNUNET_TIME_Relative timeout,
647                          GNUNET_ARM_Callback cb, void *cb_cls)
648 {
649   struct ARM_ShutdownContext *arm_shutdown_ctx;
650   struct GNUNET_CLIENT_Connection *client;
651
652   LOG (GNUNET_ERROR_TYPE_INFO, _("Stopping service `%s' within %llu ms\n"),
653        service_name, (unsigned long long) timeout.rel_value);
654   if (h->client == NULL)
655     {
656       client = GNUNET_CLIENT_connect ("arm", h->cfg);
657       if (client == NULL)
658         {
659           cb (cb_cls, GNUNET_SYSERR);
660           return;
661         }
662       h->client = client;
663     }
664   if (0 == strcasecmp ("arm", service_name))
665     {
666       arm_shutdown_ctx = GNUNET_malloc (sizeof (struct ARM_ShutdownContext));
667       arm_shutdown_ctx->cb = cb;
668       arm_shutdown_ctx->cb_cls = cb_cls;
669       arm_service_shutdown (h->client, timeout, &arm_shutdown_callback,
670                             arm_shutdown_ctx);
671       h->client = NULL;
672       return;
673     }
674   change_service (h, service_name, timeout, cb, cb_cls,
675                   GNUNET_MESSAGE_TYPE_ARM_STOP);
676 }
677
678
679 /* end of arm_api.c */