aboutsummaryrefslogtreecommitdiff
path: root/src/arm/arm_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/arm_api.c')
-rw-r--r--src/arm/arm_api.c61
1 files changed, 17 insertions, 44 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index e404f8d27..f935c590f 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -49,11 +49,6 @@ struct GNUNET_ARM_Handle
49 */ 49 */
50 struct GNUNET_CONFIGURATION_Handle *cfg; 50 struct GNUNET_CONFIGURATION_Handle *cfg;
51 51
52 /**
53 * Scheduler to use.
54 */
55 struct GNUNET_SCHEDULER_Handle *sched;
56
57}; 52};
58 53
59 54
@@ -63,11 +58,6 @@ struct GNUNET_ARM_Handle
63struct ShutdownContext 58struct ShutdownContext
64{ 59{
65 /** 60 /**
66 * Scheduler to be used to call continuation
67 */
68 struct GNUNET_SCHEDULER_Handle *sched;
69
70 /**
71 * Connection to the service that is being shutdown. 61 * Connection to the service that is being shutdown.
72 */ 62 */
73 struct GNUNET_CLIENT_Connection *sock; 63 struct GNUNET_CLIENT_Connection *sock;
@@ -80,7 +70,7 @@ struct ShutdownContext
80 /** 70 /**
81 * Task set up to cancel the shutdown request on timeout. 71 * Task set up to cancel the shutdown request on timeout.
82 */ 72 */
83 GNUNET_SCHEDULER_TaskIdentifier timeout_task; 73 GNUNET_SCHEDULER_TaskIdentifier cancel_task;
84 74
85 /** 75 /**
86 * Task to call once shutdown complete 76 * Task to call once shutdown complete
@@ -99,7 +89,6 @@ struct ShutdownContext
99 89
100}; 90};
101 91
102
103/** 92/**
104 * Handler receiving response to service shutdown requests. 93 * Handler receiving response to service shutdown requests.
105 * First call with NULL: service misbehaving, or something. 94 * First call with NULL: service misbehaving, or something.
@@ -112,8 +101,7 @@ struct ShutdownContext
112 * @param msg NULL, indicating socket closure. 101 * @param msg NULL, indicating socket closure.
113 */ 102 */
114static void 103static void
115service_shutdown_handler (void *cls, 104service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
116 const struct GNUNET_MessageHeader *msg)
117{ 105{
118 struct ShutdownContext *shutdown_ctx = cls; 106 struct ShutdownContext *shutdown_ctx = cls;
119 107
@@ -124,7 +112,7 @@ service_shutdown_handler (void *cls,
124 "Service handle shutdown before ACK!\n"); 112 "Service handle shutdown before ACK!\n");
125 if (shutdown_ctx->cont != NULL) 113 if (shutdown_ctx->cont != NULL)
126 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); 114 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
127 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->timeout_task); 115 GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
128 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 116 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
129 GNUNET_free(shutdown_ctx); 117 GNUNET_free(shutdown_ctx);
130 } 118 }
@@ -137,7 +125,7 @@ service_shutdown_handler (void *cls,
137 if (shutdown_ctx->cont != NULL) 125 if (shutdown_ctx->cont != NULL)
138 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO); 126 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO);
139 127
140 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->timeout_task); 128 GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
141 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 129 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
142 GNUNET_free(shutdown_ctx); 130 GNUNET_free(shutdown_ctx);
143 } 131 }
@@ -165,7 +153,7 @@ service_shutdown_handler (void *cls,
165 if (shutdown_ctx->cont != NULL) 153 if (shutdown_ctx->cont != NULL)
166 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES); 154 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES);
167 155
168 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->timeout_task); 156 GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
169 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 157 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
170 GNUNET_free(shutdown_ctx); 158 GNUNET_free(shutdown_ctx);
171 break; 159 break;
@@ -173,21 +161,17 @@ service_shutdown_handler (void *cls,
173 } 161 }
174} 162}
175 163
176
177/** 164/**
178 * Shutting down took too long, cancel receive and return error. 165 * Shutting down took too long, cancel receive and return error.
179 * 166 *
180 * @param cls closure 167 * @param cls closure
181 * @param tc context information (why was this task triggered now) 168 * @param tc context information (why was this task triggered now)
182 */ 169 */
183static void 170void service_shutdown_cancel (void *cls,
184service_shutdown_timeout (void *cls, 171 const struct GNUNET_SCHEDULER_TaskContext * tc)
185 const struct GNUNET_SCHEDULER_TaskContext * tc)
186{ 172{
187 struct ShutdownContext *shutdown_ctx = cls; 173 struct ShutdownContext *shutdown_ctx = cls;
188 174 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n");
189 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
190 _("Timeout during attempt to shutdown service. Hoping it is simply down already.\n"));
191 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); 175 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
192 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 176 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
193 GNUNET_free(shutdown_ctx); 177 GNUNET_free(shutdown_ctx);
@@ -222,10 +206,9 @@ write_shutdown (void *cls, size_t size, void *buf)
222 GNUNET_CLIENT_receive (shutdown_ctx->sock, 206 GNUNET_CLIENT_receive (shutdown_ctx->sock,
223 &service_shutdown_handler, shutdown_ctx, 207 &service_shutdown_handler, shutdown_ctx,
224 GNUNET_TIME_UNIT_FOREVER_REL); 208 GNUNET_TIME_UNIT_FOREVER_REL);
225 shutdown_ctx->timeout_task = GNUNET_SCHEDULER_add_delayed (shutdown_ctx->sched, 209 shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout),
226 GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout), 210 &service_shutdown_cancel,
227 &service_shutdown_timeout, 211 shutdown_ctx);
228 shutdown_ctx);
229 msg = (struct GNUNET_MessageHeader *) buf; 212 msg = (struct GNUNET_MessageHeader *) buf;
230 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN); 213 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN);
231 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 214 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -240,7 +223,6 @@ write_shutdown (void *cls, size_t size, void *buf)
240 * be used by the caller after this call 223 * be used by the caller after this call
241 * (calling this function frees "sock" after a while). 224 * (calling this function frees "sock" after a while).
242 * 225 *
243 * @param sched the scheduler to use for calling shutdown continuation
244 * @param sock the socket connected to the service 226 * @param sock the socket connected to the service
245 * @param timeout how long to wait before giving up on transmission 227 * @param timeout how long to wait before giving up on transmission
246 * @param cont continuation to call once the service is really down 228 * @param cont continuation to call once the service is really down
@@ -248,16 +230,13 @@ write_shutdown (void *cls, size_t size, void *buf)
248 * 230 *
249 */ 231 */
250static void 232static void
251arm_service_shutdown (struct GNUNET_SCHEDULER_Handle *sched, 233arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
252 struct GNUNET_CLIENT_Connection *sock,
253 struct GNUNET_TIME_Relative timeout, 234 struct GNUNET_TIME_Relative timeout,
254 GNUNET_CLIENT_ShutdownTask cont, 235 GNUNET_CLIENT_ShutdownTask cont,
255 void *cont_cls) 236 void *cont_cls)
256{ 237{
257 struct ShutdownContext *shutdown_ctx; 238 struct ShutdownContext *shutdown_ctx;
258
259 shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); 239 shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext));
260 shutdown_ctx->sched = sched;
261 shutdown_ctx->cont = cont; 240 shutdown_ctx->cont = cont;
262 shutdown_ctx->cont_cls = cont_cls; 241 shutdown_ctx->cont_cls = cont_cls;
263 shutdown_ctx->sock = sock; 242 shutdown_ctx->sock = sock;
@@ -278,20 +257,17 @@ arm_service_shutdown (struct GNUNET_SCHEDULER_Handle *sched,
278 * @param cfg configuration to use (needed to contact ARM; 257 * @param cfg configuration to use (needed to contact ARM;
279 * the ARM service may internally use a different 258 * the ARM service may internally use a different
280 * configuration to determine how to start the service). 259 * configuration to determine how to start the service).
281 * @param sched scheduler to use
282 * @param service service that *this* process is implementing/providing, can be NULL 260 * @param service service that *this* process is implementing/providing, can be NULL
283 * @return context to use for further ARM operations, NULL on error 261 * @return context to use for further ARM operations, NULL on error
284 */ 262 */
285struct GNUNET_ARM_Handle * 263struct GNUNET_ARM_Handle *
286GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 264GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
287 struct GNUNET_SCHEDULER_Handle *sched,
288 const char *service) 265 const char *service)
289{ 266{
290 struct GNUNET_ARM_Handle *ret; 267 struct GNUNET_ARM_Handle *ret;
291 268
292 ret = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle)); 269 ret = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle));
293 ret->cfg = GNUNET_CONFIGURATION_dup (cfg); 270 ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
294 ret->sched = sched;
295 return ret; 271 return ret;
296} 272}
297 273
@@ -517,8 +493,7 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
517 : "STOP", 493 : "STOP",
518 (const char*) &sc[1]); 494 (const char*) &sc[1]);
519 GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO); 495 GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO);
520 sc->h->client = GNUNET_CLIENT_connect (sc->h->sched, 496 sc->h->client = GNUNET_CLIENT_connect ("arm",
521 "arm",
522 sc->h->cfg); 497 sc->h->cfg);
523 GNUNET_assert (NULL != sc->h->client); 498 GNUNET_assert (NULL != sc->h->client);
524 GNUNET_CLIENT_ignore_shutdown (sc->h->client, GNUNET_YES); 499 GNUNET_CLIENT_ignore_shutdown (sc->h->client, GNUNET_YES);
@@ -641,7 +616,6 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
641 struct RequestContext *sctx; 616 struct RequestContext *sctx;
642 struct GNUNET_CLIENT_Connection *client; 617 struct GNUNET_CLIENT_Connection *client;
643 size_t slen; 618 size_t slen;
644
645#if DEBUG_ARM 619#if DEBUG_ARM
646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
647 _("Asked to start service `%s' within %llu ms\n"), service_name, 621 _("Asked to start service `%s' within %llu ms\n"), service_name,
@@ -656,14 +630,13 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
656 sctx->cls = cb_cls; 630 sctx->cls = cb_cls;
657 sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); 631 sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
658 memcpy (&sctx[1], service_name, slen); 632 memcpy (&sctx[1], service_name, slen);
659 GNUNET_CLIENT_service_test (h->sched, 633 GNUNET_CLIENT_service_test ("arm",
660 "arm",
661 h->cfg, timeout, &arm_service_report, sctx); 634 h->cfg, timeout, &arm_service_report, sctx);
662 return; 635 return;
663 } 636 }
664 if (h->client == NULL) 637 if (h->client == NULL)
665 { 638 {
666 client = GNUNET_CLIENT_connect (h->sched, "arm", h->cfg); 639 client = GNUNET_CLIENT_connect ("arm", h->cfg);
667 if (client == NULL) 640 if (client == NULL)
668 { 641 {
669 cb (cb_cls, GNUNET_SYSERR); 642 cb (cb_cls, GNUNET_SYSERR);
@@ -718,7 +691,7 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h,
718 (unsigned long long) timeout.rel_value); 691 (unsigned long long) timeout.rel_value);
719 if (h->client == NULL) 692 if (h->client == NULL)
720 { 693 {
721 client = GNUNET_CLIENT_connect (h->sched, "arm", h->cfg); 694 client = GNUNET_CLIENT_connect ("arm", h->cfg);
722 if (client == NULL) 695 if (client == NULL)
723 { 696 {
724 cb (cb_cls, GNUNET_SYSERR); 697 cb (cb_cls, GNUNET_SYSERR);
@@ -732,7 +705,7 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h,
732 arm_shutdown_ctx = GNUNET_malloc(sizeof(struct ARM_ShutdownContext)); 705 arm_shutdown_ctx = GNUNET_malloc(sizeof(struct ARM_ShutdownContext));
733 arm_shutdown_ctx->cb = cb; 706 arm_shutdown_ctx->cb = cb;
734 arm_shutdown_ctx->cb_cls = cb_cls; 707 arm_shutdown_ctx->cb_cls = cb_cls;
735 arm_service_shutdown (h->sched, h->client, timeout, &arm_shutdown_callback, arm_shutdown_ctx); 708 arm_service_shutdown (h->client, timeout, &arm_shutdown_callback, arm_shutdown_ctx);
736 h->client = NULL; 709 h->client = NULL;
737 return; 710 return;
738 } 711 }