diff options
-rw-r--r-- | src/arm/arm_api.c | 55 | ||||
-rw-r--r-- | src/arm/arm_monitor_api.c | 57 | ||||
-rw-r--r-- | src/arm/gnunet-arm.c | 32 | ||||
-rw-r--r-- | src/arm/test_arm_api.c | 15 | ||||
-rw-r--r-- | src/arm/test_exponential_backoff.c | 25 | ||||
-rw-r--r-- | src/arm/test_gnunet_service_arm.c | 3 | ||||
-rw-r--r-- | src/include/gnunet_arm_service.h | 48 | ||||
-rw-r--r-- | src/regex/gnunet-regex-profiler.c | 3 |
8 files changed, 112 insertions, 126 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index 18b4d220c..49cc55315 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -176,7 +176,7 @@ struct ARMControlMessage | |||
176 | static void | 176 | static void |
177 | client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg); | 177 | client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg); |
178 | 178 | ||
179 | static void | 179 | static int |
180 | reconnect_arm (struct GNUNET_ARM_Handle *h); | 180 | reconnect_arm (struct GNUNET_ARM_Handle *h); |
181 | 181 | ||
182 | static void | 182 | static void |
@@ -246,7 +246,7 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h) | |||
246 | } | 246 | } |
247 | 247 | ||
248 | if (NULL != h->conn_status) | 248 | if (NULL != h->conn_status) |
249 | h->conn_status (h->conn_status_cls, h, GNUNET_NO, GNUNET_NO); | 249 | h->conn_status (h->conn_status_cls, h, GNUNET_NO); |
250 | 250 | ||
251 | h->currently_down = GNUNET_YES; | 251 | h->currently_down = GNUNET_YES; |
252 | 252 | ||
@@ -286,7 +286,7 @@ transmit_arm_message (void *cls, size_t size, void *buf) | |||
286 | { | 286 | { |
287 | h->currently_down = GNUNET_NO; | 287 | h->currently_down = GNUNET_NO; |
288 | if (NULL != h->conn_status) | 288 | if (NULL != h->conn_status) |
289 | h->conn_status (h->conn_status_cls, h, GNUNET_YES, GNUNET_NO); | 289 | h->conn_status (h->conn_status_cls, h, GNUNET_YES); |
290 | h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 290 | h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
291 | GNUNET_CLIENT_receive (h->client, &client_notify_handler, h, | 291 | GNUNET_CLIENT_receive (h->client, &client_notify_handler, h, |
292 | GNUNET_TIME_UNIT_FOREVER_REL); | 292 | GNUNET_TIME_UNIT_FOREVER_REL); |
@@ -384,7 +384,7 @@ trigger_next_request (struct GNUNET_ARM_Handle *h, int ignore_currently_down) | |||
384 | * | 384 | * |
385 | * @param h arm handle | 385 | * @param h arm handle |
386 | */ | 386 | */ |
387 | static void | 387 | static int |
388 | reconnect_arm (struct GNUNET_ARM_Handle *h) | 388 | reconnect_arm (struct GNUNET_ARM_Handle *h) |
389 | { | 389 | { |
390 | GNUNET_assert (NULL == h->client); | 390 | GNUNET_assert (NULL == h->client); |
@@ -395,52 +395,45 @@ reconnect_arm (struct GNUNET_ARM_Handle *h) | |||
395 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 395 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
396 | "arm_api, GNUNET_CLIENT_connect returned NULL\n"); | 396 | "arm_api, GNUNET_CLIENT_connect returned NULL\n"); |
397 | if (NULL != h->conn_status) | 397 | if (NULL != h->conn_status) |
398 | h->conn_status (h->conn_status_cls, h, GNUNET_NO, GNUNET_YES); | 398 | h->conn_status (h->conn_status_cls, h, GNUNET_SYSERR); |
399 | return; | 399 | return GNUNET_SYSERR; |
400 | } | 400 | } |
401 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 401 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
402 | "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); | 402 | "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); |
403 | trigger_next_request (h, GNUNET_YES); | 403 | trigger_next_request (h, GNUNET_YES); |
404 | return GNUNET_OK; | ||
404 | } | 405 | } |
405 | 406 | ||
406 | 407 | ||
407 | /** | 408 | /** |
408 | * Set up a context for communicating with ARM. Note that this | 409 | * Set up a context for communicating with ARM, then |
409 | * can be done even if the ARM service is not yet running. | 410 | * start connecting to the ARM service using that context. |
410 | * Never fails. | ||
411 | * | 411 | * |
412 | * @param cfg configuration to use (needed to contact ARM; | 412 | * @param cfg configuration to use (needed to contact ARM; |
413 | * the ARM service may internally use a different | 413 | * the ARM service may internally use a different |
414 | * configuration to determine how to start the service). | 414 | * configuration to determine how to start the service). |
415 | * @return context to use for further ARM operations | ||
416 | */ | ||
417 | struct GNUNET_ARM_Handle * | ||
418 | GNUNET_ARM_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
419 | { | ||
420 | struct GNUNET_ARM_Handle *ret; | ||
421 | |||
422 | ret = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle)); | ||
423 | ret->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
424 | ret->currently_down = GNUNET_YES; | ||
425 | ret->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
426 | return ret; | ||
427 | } | ||
428 | |||
429 | |||
430 | /** | ||
431 | * Start connecting to the ARM service using the context. | ||
432 | * | ||
433 | * @param h ARM handle | ||
434 | * @param conn_status will be called when connecting/disconnecting | 415 | * @param conn_status will be called when connecting/disconnecting |
435 | * @param cls closure for conn_status | 416 | * @param cls closure for conn_status |
417 | * @return context to use for further ARM operations, NULL on error. | ||
436 | */ | 418 | */ |
437 | void | 419 | struct GNUNET_ARM_Handle * |
438 | GNUNET_ARM_connect (struct GNUNET_ARM_Handle *h, | 420 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
439 | GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls) | 421 | GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls) |
440 | { | 422 | { |
423 | struct GNUNET_ARM_Handle *h; | ||
424 | |||
425 | h = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle)); | ||
426 | h->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
427 | h->currently_down = GNUNET_YES; | ||
428 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
441 | h->conn_status = conn_status; | 429 | h->conn_status = conn_status; |
442 | h->conn_status_cls = cls; | 430 | h->conn_status_cls = cls; |
443 | reconnect_arm (h); | 431 | if (GNUNET_OK != reconnect_arm (h)) |
432 | { | ||
433 | GNUNET_free (h); | ||
434 | return NULL; | ||
435 | } | ||
436 | return h; | ||
444 | } | 437 | } |
445 | 438 | ||
446 | 439 | ||
diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c index dc690b904..fa9e0faab 100644 --- a/src/arm/arm_monitor_api.c +++ b/src/arm/arm_monitor_api.c | |||
@@ -88,7 +88,7 @@ struct GNUNET_ARM_MonitorHandle | |||
88 | static void | 88 | static void |
89 | monitor_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg); | 89 | monitor_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg); |
90 | 90 | ||
91 | static void | 91 | static int |
92 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h); | 92 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h); |
93 | 93 | ||
94 | /** | 94 | /** |
@@ -211,7 +211,7 @@ transmit_monitoring_init_message (void *cls, size_t size, void *buf) | |||
211 | } | 211 | } |
212 | 212 | ||
213 | 213 | ||
214 | static void | 214 | static int |
215 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | 215 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) |
216 | { | 216 | { |
217 | GNUNET_assert (NULL == h->monitor); | 217 | GNUNET_assert (NULL == h->monitor); |
@@ -220,56 +220,49 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | |||
220 | { | 220 | { |
221 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 221 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
222 | "arm_api, GNUNET_CLIENT_connect returned NULL\n"); | 222 | "arm_api, GNUNET_CLIENT_connect returned NULL\n"); |
223 | GNUNET_CLIENT_disconnect (h->monitor); | 223 | if (NULL != h->service_status) |
224 | h->monitor = NULL; | 224 | h->service_status (h->cls, h, NULL, GNUNET_ARM_SERVICE_STOPPED); |
225 | return; | 225 | return GNUNET_SYSERR; |
226 | } | 226 | } |
227 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 227 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
228 | "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); | 228 | "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); |
229 | h->cth = GNUNET_CLIENT_notify_transmit_ready (h->monitor, | 229 | h->cth = GNUNET_CLIENT_notify_transmit_ready (h->monitor, |
230 | sizeof (struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, | 230 | sizeof (struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, |
231 | GNUNET_NO, &transmit_monitoring_init_message, h); | 231 | GNUNET_NO, &transmit_monitoring_init_message, h); |
232 | return GNUNET_OK; | ||
232 | } | 233 | } |
233 | 234 | ||
234 | 235 | ||
235 | /** | 236 | /** |
236 | * Setup a context for monitoring ARM. Note that this | 237 | * Setup a context for monitoring ARM, then |
237 | * can be done even if the ARM service is not yet running. | 238 | * start connecting to the ARM service for monitoring using that context. |
238 | * Never fails. | ||
239 | * | 239 | * |
240 | * @param cfg configuration to use (needed to contact ARM; | 240 | * @param cfg configuration to use (needed to contact ARM; |
241 | * the ARM service may internally use a different | 241 | * the ARM service may internally use a different |
242 | * configuration to determine how to start the service). | 242 | * configuration to determine how to start the service). |
243 | * @return context to use for further ARM monitoring operations | ||
244 | */ | ||
245 | struct GNUNET_ARM_MonitorHandle * | ||
246 | GNUNET_ARM_monitor_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
247 | { | ||
248 | struct GNUNET_ARM_MonitorHandle *ret; | ||
249 | |||
250 | ret = GNUNET_malloc (sizeof (struct GNUNET_ARM_MonitorHandle)); | ||
251 | ret->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
252 | ret->currently_down = GNUNET_YES; | ||
253 | ret->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
254 | ret->init_timeout_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
255 | return ret; | ||
256 | } | ||
257 | |||
258 | |||
259 | /** | ||
260 | * Start connecting to the ARM service for monitoring using the context. | ||
261 | * | ||
262 | * @param h ARM monitor handle | ||
263 | * @param cont callback to invoke on status updates | 243 | * @param cont callback to invoke on status updates |
264 | * @param cont_cls closure | 244 | * @param cont_cls closure |
245 | * @return context to use for further ARM monitor operations, NULL on error. | ||
265 | */ | 246 | */ |
266 | void | 247 | struct GNUNET_ARM_MonitorHandle * |
267 | GNUNET_ARM_monitor (struct GNUNET_ARM_MonitorHandle *h, | 248 | GNUNET_ARM_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg, |
268 | GNUNET_ARM_ServiceStatusCallback cont, void *cont_cls) | 249 | GNUNET_ARM_ServiceStatusCallback cont, void *cont_cls) |
269 | { | 250 | { |
251 | struct GNUNET_ARM_MonitorHandle *h; | ||
252 | |||
253 | h = GNUNET_malloc (sizeof (struct GNUNET_ARM_MonitorHandle)); | ||
254 | h->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
255 | h->currently_down = GNUNET_YES; | ||
256 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
257 | h->init_timeout_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
270 | h->service_status = cont; | 258 | h->service_status = cont; |
271 | h->cls = cont_cls; | 259 | h->cls = cont_cls; |
272 | reconnect_arm_monitor (h); | 260 | if (GNUNET_OK != reconnect_arm_monitor (h)) |
261 | { | ||
262 | GNUNET_free (h); | ||
263 | return NULL; | ||
264 | } | ||
265 | return h; | ||
273 | } | 266 | } |
274 | 267 | ||
275 | 268 | ||
@@ -280,7 +273,7 @@ GNUNET_ARM_monitor (struct GNUNET_ARM_MonitorHandle *h, | |||
280 | * @param h the handle that was being used | 273 | * @param h the handle that was being used |
281 | */ | 274 | */ |
282 | void | 275 | void |
283 | GNUNET_ARM_monitor_disconnect (struct GNUNET_ARM_MonitorHandle *handle) | 276 | GNUNET_ARM_monitor_disconnect_and_free (struct GNUNET_ARM_MonitorHandle *handle) |
284 | { | 277 | { |
285 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); | 278 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); |
286 | if (NULL != handle->cth) | 279 | if (NULL != handle->cth) |
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 095d60e36..3d94fed80 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c | |||
@@ -179,7 +179,7 @@ static void | |||
179 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 179 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
180 | { | 180 | { |
181 | GNUNET_ARM_disconnect_and_free (h); | 181 | GNUNET_ARM_disconnect_and_free (h); |
182 | GNUNET_ARM_monitor_disconnect (m); | 182 | GNUNET_ARM_monitor_disconnect_and_free (m); |
183 | h = NULL; | 183 | h = NULL; |
184 | m = NULL; | 184 | m = NULL; |
185 | if ((end == GNUNET_YES) && (delete == GNUNET_YES)) | 185 | if ((end == GNUNET_YES) && (delete == GNUNET_YES)) |
@@ -246,14 +246,15 @@ static void action_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t | |||
246 | * | 246 | * |
247 | * @param cls closure | 247 | * @param cls closure |
248 | * @param arm handle to the ARM connection | 248 | * @param arm handle to the ARM connection |
249 | * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected | 249 | * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected, |
250 | * GNUNET_SYSERR on error. | ||
250 | * @param error GNUNET_YES if we encountered a permanent error, and there | 251 | * @param error GNUNET_YES if we encountered a permanent error, and there |
251 | * will be no re-connection. | 252 | * will be no re-connection. |
252 | */ | 253 | */ |
253 | static void | 254 | static void |
254 | conn_status (void *cls, struct GNUNET_ARM_Handle *arm, unsigned char connected, unsigned char error) | 255 | conn_status (void *cls, struct GNUNET_ARM_Handle *arm, char connected) |
255 | { | 256 | { |
256 | if (GNUNET_YES == error) | 257 | if (GNUNET_SYSERR == connected) |
257 | { | 258 | { |
258 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 259 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
259 | _("Fatal error initializing ARM API.\n")); | 260 | _("Fatal error initializing ARM API.\n")); |
@@ -575,13 +576,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
575 | else | 576 | else |
576 | GNUNET_free (armconfig); | 577 | GNUNET_free (armconfig); |
577 | } | 578 | } |
578 | h = GNUNET_ARM_alloc (cfg); | 579 | h = GNUNET_ARM_connect (cfg, conn_status, NULL); |
579 | m = GNUNET_ARM_monitor_alloc (cfg); | 580 | if (NULL != h) |
580 | GNUNET_ARM_connect (h, conn_status, NULL); | 581 | { |
581 | GNUNET_ARM_monitor (m, srv_status, NULL); | 582 | m = GNUNET_ARM_monitor (cfg, srv_status, NULL); |
582 | GNUNET_SCHEDULER_add_now (action_loop, NULL); | 583 | if (NULL != m) |
583 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 584 | { |
584 | shutdown_task, NULL); | 585 | GNUNET_SCHEDULER_add_now (action_loop, NULL); |
586 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
587 | shutdown_task, NULL); | ||
588 | } | ||
589 | else | ||
590 | { | ||
591 | GNUNET_ARM_disconnect_and_free (h); | ||
592 | h = NULL; | ||
593 | } | ||
594 | } | ||
585 | } | 595 | } |
586 | 596 | ||
587 | 597 | ||
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c index 865f3dfa0..65e8b7797 100644 --- a/src/arm/test_arm_api.c +++ b/src/arm/test_arm_api.c | |||
@@ -71,7 +71,7 @@ resolver_stop_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_Reques | |||
71 | GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL); | 71 | GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL); |
72 | #else | 72 | #else |
73 | arm_stop_cb (NULL, GNUNET_ARM_STATUS_SENT_OK, "arm", GNUNET_ARM_SERVICE_STOPPING); | 73 | arm_stop_cb (NULL, GNUNET_ARM_STATUS_SENT_OK, "arm", GNUNET_ARM_SERVICE_STOPPING); |
74 | arm_conn (NULL, GNUNET_NO, GNUNET_NO); | 74 | arm_conn (NULL, GNUNET_NO); |
75 | #endif | 75 | #endif |
76 | } | 76 | } |
77 | 77 | ||
@@ -119,9 +119,9 @@ trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
119 | 119 | ||
120 | 120 | ||
121 | void | 121 | void |
122 | arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, unsigned char connected, unsigned char error) | 122 | arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, char connected) |
123 | { | 123 | { |
124 | if (GNUNET_YES == error) | 124 | if (GNUNET_SYSERR == connected) |
125 | { | 125 | { |
126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
127 | _("Fatal error initializing ARM API.\n")); | 127 | _("Fatal error initializing ARM API.\n")); |
@@ -129,7 +129,7 @@ arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, unsigned char connected, uns | |||
129 | GNUNET_assert (0); | 129 | GNUNET_assert (0); |
130 | return; | 130 | return; |
131 | } | 131 | } |
132 | if (connected) | 132 | if (GNUNET_YES == connected) |
133 | { | 133 | { |
134 | /* (1), arm connection should be established */ | 134 | /* (1), arm connection should be established */ |
135 | FPRINTF (stderr, "%s", "Connected to ARM\n"); | 135 | FPRINTF (stderr, "%s", "Connected to ARM\n"); |
@@ -201,13 +201,14 @@ task (void *cls, char *const *args, const char *cfgfile, | |||
201 | else | 201 | else |
202 | GNUNET_free (armconfig); | 202 | GNUNET_free (armconfig); |
203 | } | 203 | } |
204 | arm = GNUNET_ARM_alloc (cfg); | 204 | arm = GNUNET_ARM_connect (cfg, arm_conn, NULL); |
205 | GNUNET_ARM_connect (arm, arm_conn, NULL); | 205 | if (NULL == arm) |
206 | return; | ||
206 | #if START_ARM | 207 | #if START_ARM |
207 | GNUNET_ARM_request_service_start (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL); | 208 | GNUNET_ARM_request_service_start (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL); |
208 | #else | 209 | #else |
209 | arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_STARTING); | 210 | arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_STARTING); |
210 | arm_conn (NULL, GNUNET_YES, GNUNET_NO); | 211 | arm_conn (NULL, arm, GNUNET_YES); |
211 | #endif | 212 | #endif |
212 | } | 213 | } |
213 | 214 | ||
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c index 5613794c3..30d614c2f 100644 --- a/src/arm/test_exponential_backoff.c +++ b/src/arm/test_exponential_backoff.c | |||
@@ -280,7 +280,7 @@ static void | |||
280 | trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 280 | trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
281 | { | 281 | { |
282 | GNUNET_ARM_disconnect_and_free (arm); | 282 | GNUNET_ARM_disconnect_and_free (arm); |
283 | GNUNET_ARM_monitor_disconnect (mon); | 283 | GNUNET_ARM_monitor_disconnect_and_free (mon); |
284 | } | 284 | } |
285 | 285 | ||
286 | 286 | ||
@@ -360,16 +360,25 @@ task (void *cls, char *const *args, const char *cfgfile, | |||
360 | GNUNET_free (armconfig); | 360 | GNUNET_free (armconfig); |
361 | } | 361 | } |
362 | 362 | ||
363 | arm = GNUNET_ARM_alloc (cfg); | 363 | arm = GNUNET_ARM_connect (cfg, NULL, NULL); |
364 | GNUNET_ARM_connect (arm, NULL, NULL); | 364 | if (NULL != arm) |
365 | mon = GNUNET_ARM_monitor_alloc (cfg); | 365 | { |
366 | GNUNET_ARM_monitor (mon, srv_status, NULL); | 366 | mon = GNUNET_ARM_monitor (cfg, srv_status, NULL); |
367 | if (NULL != mon) | ||
368 | { | ||
367 | #if START_ARM | 369 | #if START_ARM |
368 | GNUNET_ARM_request_service_start (arm, "arm", | 370 | GNUNET_ARM_request_service_start (arm, "arm", |
369 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_TIME_UNIT_ZERO, arm_start_cb, NULL); | 371 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_TIME_UNIT_ZERO, arm_start_cb, NULL); |
370 | #else | 372 | #else |
371 | arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_SERVICE_STARTING); | 373 | arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_SERVICE_STARTING); |
372 | #endif | 374 | #endif |
375 | } | ||
376 | else | ||
377 | { | ||
378 | GNUNET_ARM_disconnect_and_free (arm); | ||
379 | arm = NULL; | ||
380 | } | ||
381 | } | ||
373 | } | 382 | } |
374 | 383 | ||
375 | static int | 384 | static int |
diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c index 50f01e932..9cdda77df 100644 --- a/src/arm/test_gnunet_service_arm.c +++ b/src/arm/test_gnunet_service_arm.c | |||
@@ -134,8 +134,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
134 | else | 134 | else |
135 | GNUNET_free (armconfig); | 135 | GNUNET_free (armconfig); |
136 | } | 136 | } |
137 | arm = GNUNET_ARM_alloc (c); | 137 | arm = GNUNET_ARM_connect (c, NULL, NULL); |
138 | GNUNET_ARM_connect (arm, NULL, NULL); | ||
139 | GNUNET_ARM_request_service_start (arm, "arm", | 138 | GNUNET_ARM_request_service_start (arm, "arm", |
140 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL); | 139 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL); |
141 | } | 140 | } |
diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h index 4d0f083f7..4cc247d19 100644 --- a/src/include/gnunet_arm_service.h +++ b/src/include/gnunet_arm_service.h | |||
@@ -179,11 +179,12 @@ struct GNUNET_ARM_Handle; | |||
179 | * Function called whenever we connect to or disconnect from ARM. | 179 | * Function called whenever we connect to or disconnect from ARM. |
180 | * | 180 | * |
181 | * @param cls closure | 181 | * @param cls closure |
182 | * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected | 182 | * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected, |
183 | * GNUNET_SYSERR if there was an error. | ||
183 | * @param error GNUNET_YES if we encountered a permanent error, and there | 184 | * @param error GNUNET_YES if we encountered a permanent error, and there |
184 | * will be no re-connection. | 185 | * will be no re-connection. |
185 | */ | 186 | */ |
186 | typedef void (*GNUNET_ARM_ConnectionStatusCallback) (void *cls, struct GNUNET_ARM_Handle *arm, unsigned char connected, unsigned char error); | 187 | typedef void (*GNUNET_ARM_ConnectionStatusCallback) (void *cls, struct GNUNET_ARM_Handle *arm, char connected); |
187 | 188 | ||
188 | 189 | ||
189 | /** | 190 | /** |
@@ -217,28 +218,18 @@ typedef void (*GNUNET_ARM_ServiceListCallback) (void *cls, struct GNUNET_ARM_Han | |||
217 | 218 | ||
218 | 219 | ||
219 | /** | 220 | /** |
220 | * Setup a context for communicating with ARM. Note that this | 221 | * Set up a context for communicating with ARM, then |
221 | * can be done even if the ARM service is not yet running. | 222 | * start connecting to the ARM service using that context. |
222 | * Never fails. | ||
223 | * | 223 | * |
224 | * @param cfg configuration to use (needed to contact ARM; | 224 | * @param cfg configuration to use (needed to contact ARM; |
225 | * the ARM service may internally use a different | 225 | * the ARM service may internally use a different |
226 | * configuration to determine how to start the service). | 226 | * configuration to determine how to start the service). |
227 | * @return context to use for further ARM operations | 227 | * @param conn_status will be called when connecting/disconnecting |
228 | */ | ||
229 | struct GNUNET_ARM_Handle * | ||
230 | GNUNET_ARM_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
231 | |||
232 | /** | ||
233 | * Start connecting to the ARM service using the context. | ||
234 | * @param conn_status called when we (dis)connect from/to ARM. | ||
235 | * It's also called on connection errors. | ||
236 | * @param cls closure for conn_status | 228 | * @param cls closure for conn_status |
237 | * | 229 | * @return context to use for further ARM operations, NULL on error. |
238 | * @param h ARM handle | ||
239 | */ | 230 | */ |
240 | void | 231 | struct GNUNET_ARM_Handle * |
241 | GNUNET_ARM_connect (struct GNUNET_ARM_Handle *h, | 232 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
242 | GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls); | 233 | GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls); |
243 | 234 | ||
244 | 235 | ||
@@ -321,27 +312,18 @@ typedef void (*GNUNET_ARM_ServiceStatusCallback) (void *cls, struct GNUNET_ARM_M | |||
321 | 312 | ||
322 | 313 | ||
323 | /** | 314 | /** |
324 | * Setup a context for monitoring ARM. Note that this | 315 | * Setup a context for monitoring ARM, then |
325 | * can be done even if the ARM service is not yet running. | 316 | * start connecting to the ARM service for monitoring using that context. |
326 | * Never fails. | ||
327 | * | 317 | * |
328 | * @param cfg configuration to use (needed to contact ARM; | 318 | * @param cfg configuration to use (needed to contact ARM; |
329 | * the ARM service may internally use a different | 319 | * the ARM service may internally use a different |
330 | * configuration to determine how to start the service). | 320 | * configuration to determine how to start the service). |
331 | * @return context to use for further ARM monitor operations | ||
332 | */ | ||
333 | struct GNUNET_ARM_MonitorHandle * | ||
334 | GNUNET_ARM_monitor_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
335 | |||
336 | /** | ||
337 | * Start connecting to the ARM service for monitoring using the context. | ||
338 | * | ||
339 | * @param h ARM monitor handle | ||
340 | * @param cont callback to invoke on status updates | 321 | * @param cont callback to invoke on status updates |
341 | * @param cont_cls closure | 322 | * @param cont_cls closure |
323 | * @return context to use for further ARM monitor operations, NULL on error. | ||
342 | */ | 324 | */ |
343 | void | 325 | struct GNUNET_ARM_MonitorHandle * |
344 | GNUNET_ARM_monitor (struct GNUNET_ARM_MonitorHandle *h, | 326 | GNUNET_ARM_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg, |
345 | GNUNET_ARM_ServiceStatusCallback cont, void *cont_cls); | 327 | GNUNET_ARM_ServiceStatusCallback cont, void *cont_cls); |
346 | 328 | ||
347 | 329 | ||
@@ -352,7 +334,7 @@ GNUNET_ARM_monitor (struct GNUNET_ARM_MonitorHandle *h, | |||
352 | * @param h the handle that was being used | 334 | * @param h the handle that was being used |
353 | */ | 335 | */ |
354 | void | 336 | void |
355 | GNUNET_ARM_monitor_disconnect (struct GNUNET_ARM_MonitorHandle *h); | 337 | GNUNET_ARM_monitor_disconnect_and_free (struct GNUNET_ARM_MonitorHandle *h); |
356 | 338 | ||
357 | 339 | ||
358 | #if 0 /* keep Emacsens' auto-indent happy */ | 340 | #if 0 /* keep Emacsens' auto-indent happy */ |
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index 057ab7056..1c4e43f60 100644 --- a/src/regex/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-profiler.c | |||
@@ -1006,8 +1006,7 @@ arm_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1006 | { | 1006 | { |
1007 | struct RegexPeer *peer = cls; | 1007 | struct RegexPeer *peer = cls; |
1008 | 1008 | ||
1009 | peer->arm_handle = GNUNET_ARM_alloc (cfg); | 1009 | peer->arm_handle = GNUNET_ARM_connect (cfg, NULL, NULL); |
1010 | GNUNET_ARM_connect (peer->arm_handle, NULL, NULL); | ||
1011 | 1010 | ||
1012 | return peer->arm_handle; | 1011 | return peer->arm_handle; |
1013 | } | 1012 | } |