aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-05-11 19:40:39 +0000
committerChristian Grothoff <christian@grothoff.org>2010-05-11 19:40:39 +0000
commit5882a0a99902e4555f78a05a3d68dc72f864437f (patch)
treec080e0c35c98a1548d7dd8c1f1df6c16ba93508a /src
parentf557d63b75c8b14922e4a308dfc486f7e4e9f6db (diff)
downloadgnunet-5882a0a99902e4555f78a05a3d68dc72f864437f.tar.gz
gnunet-5882a0a99902e4555f78a05a3d68dc72f864437f.zip
die unstoppable multi api, die
Diffstat (limited to 'src')
-rw-r--r--src/arm/arm_api.c167
-rw-r--r--src/core/test_core_api.c5
-rw-r--r--src/core/test_core_api_start_only.c12
-rw-r--r--src/datastore/datastore_api.c1
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist.c1
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist.conf1
-rw-r--r--src/include/gnunet_arm_service.h31
-rw-r--r--src/transport/transport_api.c1
8 files changed, 5 insertions, 214 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index cd4343dbd..45a38ea9b 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -706,171 +706,4 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h,
706} 706}
707 707
708 708
709/**
710 * Function to call for each service.
711 *
712 * @param h handle to ARM
713 * @param service_name name of the service
714 * @param timeout how long to wait before failing for good
715 * @param cb callback to invoke when service is ready
716 * @param cb_cls closure for callback
717 */
718typedef void (*ServiceOperation) (struct GNUNET_ARM_Handle *h,
719 const char *service_name,
720 struct GNUNET_TIME_Relative timeout,
721 GNUNET_ARM_Callback cb, void *cb_cls);
722
723
724/**
725 * Context for starting or stopping multiple services.
726 */
727struct MultiContext
728{
729 /**
730 * NULL-terminated array of services to start or stop.
731 */
732 char **services;
733
734 /**
735 * Our handle to ARM.
736 */
737 struct GNUNET_ARM_Handle *h;
738
739 /**
740 * Identifies the operation (start or stop).
741 */
742 ServiceOperation op;
743
744 /**
745 * Current position in "services".
746 */
747 unsigned int pos;
748};
749
750
751/**
752 * Run the operation for the next service in the multi-service
753 * request.
754 *
755 * @param cls the "struct MultiContext" that is being processed
756 * @param success status of the previous operation (ignored)
757 */
758static void
759next_operation (void *cls,
760 int success)
761{
762 struct MultiContext *mc = cls;
763 char *pos;
764
765 if (NULL == (pos = mc->services[mc->pos]))
766 {
767 GNUNET_free (mc->services);
768 GNUNET_ARM_disconnect (mc->h);
769 GNUNET_free (mc);
770 return;
771 }
772 mc->pos++;
773 mc->op (mc->h, pos, MULTI_TIMEOUT, &next_operation, mc);
774 GNUNET_free (pos);
775}
776
777
778/**
779 * Run a multi-service request.
780 *
781 * @param cfg configuration to use (needed to contact ARM;
782 * the ARM service may internally use a different
783 * configuration to determine how to start the service).
784 * @param sched scheduler to use
785 * @param op the operation to perform for each service
786 * @param va NULL-terminated list of services
787 */
788static void
789run_multi_request (const struct GNUNET_CONFIGURATION_Handle *cfg,
790 struct GNUNET_SCHEDULER_Handle *sched,
791 ServiceOperation op,
792 va_list va)
793{
794 va_list cp;
795 unsigned int total;
796 struct MultiContext *mc;
797 struct GNUNET_ARM_Handle *h;
798 const char *c;
799
800 h = GNUNET_ARM_connect (cfg, sched, NULL);
801 if (NULL == h)
802 {
803 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
804 _("Error while trying to transmit to ARM service\n"));
805 return;
806 }
807 total = 1;
808 va_copy (cp, va);
809 while (NULL != (va_arg (cp, const char*))) total++;
810 va_end (cp);
811 mc = GNUNET_malloc (sizeof(struct MultiContext));
812 mc->services = GNUNET_malloc (total * sizeof (char*));
813 mc->h = h;
814 mc->op = op;
815 total = 0;
816 va_copy (cp, va);
817 while (NULL != (c = va_arg (cp, const char*)))
818 mc->services[total++] = GNUNET_strdup (c);
819 va_end (cp);
820 next_operation (mc, GNUNET_YES);
821}
822
823
824/**
825 * Start multiple services in the specified order. Convenience
826 * function. Works asynchronously, failures are not reported.
827 *
828 * @param cfg configuration to use (needed to contact ARM;
829 * the ARM service may internally use a different
830 * configuration to determine how to start the service).
831 * @param sched scheduler to use
832 * @param ... NULL-terminated list of service names (const char*)
833 */
834void
835GNUNET_ARM_start_services (const struct GNUNET_CONFIGURATION_Handle *cfg,
836 struct GNUNET_SCHEDULER_Handle *sched,
837 ...)
838{
839 va_list ap;
840
841 va_start (ap, sched);
842 run_multi_request (cfg, sched, &GNUNET_ARM_start_service, ap);
843 va_end (ap);
844}
845
846
847/**
848 * Stop multiple services in the specified order. Convenience
849 * function. Works asynchronously, failures are not reported.
850 * Should normally only be called from gnunet-arm or testcases,
851 * stopping a service is generally otherwise a bad idea.
852 *
853 * @param cfg configuration to use (needed to contact ARM;
854 * the ARM service may internally use a different
855 * configuration to determine how to start the service).
856 * @param sched scheduler to use
857 * @param ... NULL-terminated list of service names (const char*)
858 */
859void
860GNUNET_ARM_stop_services (const struct GNUNET_CONFIGURATION_Handle *cfg,
861 struct GNUNET_SCHEDULER_Handle *sched,
862 ...)
863{
864 va_list ap;
865
866 va_start (ap, sched);
867 run_multi_request (cfg, sched, &GNUNET_ARM_stop_service, ap);
868 va_end (ap);
869}
870
871
872
873
874
875
876/* end of arm_api.c */ 709/* end of arm_api.c */
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index 6b8387461..676bbb29c 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -82,8 +82,6 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
82 GNUNET_CORE_disconnect (p2.ch); 82 GNUNET_CORE_disconnect (p2.ch);
83 GNUNET_TRANSPORT_disconnect (p1.th); 83 GNUNET_TRANSPORT_disconnect (p1.th);
84 GNUNET_TRANSPORT_disconnect (p2.th); 84 GNUNET_TRANSPORT_disconnect (p2.th);
85 GNUNET_ARM_stop_services (p1.cfg, sched, "core", NULL);
86 GNUNET_ARM_stop_services (p2.cfg, sched, "core", NULL);
87 ok = 0; 85 ok = 0;
88} 86}
89 87
@@ -99,8 +97,6 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
99 GNUNET_CORE_disconnect (p2.ch); 97 GNUNET_CORE_disconnect (p2.ch);
100 GNUNET_TRANSPORT_disconnect (p1.th); 98 GNUNET_TRANSPORT_disconnect (p1.th);
101 GNUNET_TRANSPORT_disconnect (p2.th); 99 GNUNET_TRANSPORT_disconnect (p2.th);
102 GNUNET_ARM_stop_services (p1.cfg, sched, "core", NULL);
103 GNUNET_ARM_stop_services (p2.cfg, sched, "core", NULL);
104 ok = 42; 100 ok = 42;
105} 101}
106 102
@@ -300,7 +296,6 @@ setup_peer (struct PeerContext *p, const char *cfgname)
300 "-c", cfgname, NULL); 296 "-c", cfgname, NULL);
301#endif 297#endif
302 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 298 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
303 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
304 p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, NULL, NULL); 299 p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, NULL, NULL);
305 GNUNET_assert (p->th != NULL); 300 GNUNET_assert (p->th != NULL);
306 GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); 301 GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c
index f33597836..a655d0b51 100644
--- a/src/core/test_core_api_start_only.c
+++ b/src/core/test_core_api_start_only.c
@@ -31,7 +31,7 @@
31#include "gnunet_program_lib.h" 31#include "gnunet_program_lib.h"
32#include "gnunet_scheduler_lib.h" 32#include "gnunet_scheduler_lib.h"
33 33
34#define VERBOSE GNUNET_YES 34#define VERBOSE GNUNET_NO
35 35
36#define START_ARM GNUNET_YES 36#define START_ARM GNUNET_YES
37 37
@@ -142,9 +142,6 @@ init_notify (void *cls,
142 GNUNET_assert (cls == &p2); 142 GNUNET_assert (cls == &p2);
143 GNUNET_CORE_disconnect (p1.ch); 143 GNUNET_CORE_disconnect (p1.ch);
144 GNUNET_CORE_disconnect (p2.ch); 144 GNUNET_CORE_disconnect (p2.ch);
145 GNUNET_ARM_stop_services (p1.cfg, sched, "core", NULL);
146 GNUNET_ARM_stop_services (p2.cfg, sched, "core", NULL);
147
148 ok = 0; 145 ok = 0;
149 } 146 }
150} 147}
@@ -163,7 +160,6 @@ setup_peer (struct PeerContext *p, const char *cfgname)
163 "-c", cfgname, NULL); 160 "-c", cfgname, NULL);
164#endif 161#endif
165 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 162 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
166 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
167} 163}
168 164
169 165
@@ -209,7 +205,7 @@ stop_arm (struct PeerContext *p)
209static int 205static int
210check () 206check ()
211{ 207{
212 char *const argv[] = { "test-core-api", 208 char *const argv[] = { "test-core-api-start-only",
213 "-c", 209 "-c",
214 "test_core_api_data.conf", 210 "test_core_api_data.conf",
215#if VERBOSE 211#if VERBOSE
@@ -223,7 +219,7 @@ check ()
223 219
224 ok = 1; 220 ok = 1;
225 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 221 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
226 argv, "test-core-api", "nohelp", options, &run, &ok); 222 argv, "test-core-api-start-only", "nohelp", options, &run, &ok);
227 stop_arm (&p1); 223 stop_arm (&p1);
228 stop_arm (&p2); 224 stop_arm (&p2);
229 return ok; 225 return ok;
@@ -234,7 +230,7 @@ main (int argc, char *argv[])
234{ 230{
235 int ret; 231 int ret;
236 232
237 GNUNET_log_setup ("test-core-api", 233 GNUNET_log_setup ("test-core-api-start-only",
238#if VERBOSE 234#if VERBOSE
239 "DEBUG", 235 "DEBUG",
240#else 236#else
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index 1c50dabee..c8b4f2e91 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -97,7 +97,6 @@ struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct
97 c = GNUNET_CLIENT_connect (sched, "datastore", cfg); 97 c = GNUNET_CLIENT_connect (sched, "datastore", cfg);
98 if (c == NULL) 98 if (c == NULL)
99 return NULL; /* oops */ 99 return NULL; /* oops */
100 GNUNET_ARM_start_services (cfg, sched, "datastore", NULL);
101 h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle) + 100 h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle) +
102 GNUNET_SERVER_MAX_MESSAGE_SIZE); 101 GNUNET_SERVER_MAX_MESSAGE_SIZE);
103 h->client = c; 102 h->client = c;
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c
index 3e179e5d9..a70caa986 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist.c
@@ -127,7 +127,6 @@ process_hello (void *cls,
127 GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p); 127 GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p);
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
129 "Received HELLO, starting hostlist service.\n"); 129 "Received HELLO, starting hostlist service.\n");
130 GNUNET_ARM_start_services (p->cfg, sched, "hostlist", NULL);
131} 130}
132 131
133 132
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.conf b/src/hostlist/test_gnunet_daemon_hostlist.conf
index eedb1cd42..9541f6de5 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist.conf
+++ b/src/hostlist/test_gnunet_daemon_hostlist.conf
@@ -16,6 +16,7 @@ PLUGINS = tcp
16 16
17[arm] 17[arm]
18PORT = 12466 18PORT = 12466
19DEFAULTSERVICES = hostlist
19#GLOBAL_PREFIX = xterm -e valgrind --tool=memcheck 20#GLOBAL_PREFIX = xterm -e valgrind --tool=memcheck
20 21
21[statistics] 22[statistics]
diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h
index 8e68cd5ee..07722c97f 100644
--- a/src/include/gnunet_arm_service.h
+++ b/src/include/gnunet_arm_service.h
@@ -132,37 +132,6 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h,
132 GNUNET_ARM_Callback cb, void *cb_cls); 132 GNUNET_ARM_Callback cb, void *cb_cls);
133 133
134 134
135/**
136 * Start multiple services in the specified order. Convenience
137 * function. Works asynchronously, failures are not reported.
138 *
139 * @param cfg configuration to use (needed to contact ARM;
140 * the ARM service may internally use a different
141 * configuration to determine how to start the service).
142 * @param sched scheduler to use
143 * @param ... NULL-terminated list of service names (const char*)
144 */
145void
146GNUNET_ARM_start_services (const struct GNUNET_CONFIGURATION_Handle *cfg,
147 struct GNUNET_SCHEDULER_Handle *sched,
148 ...);
149
150
151/**
152 * Stop multiple services in the specified order. Convenience
153 * function. Works asynchronously, failures are not reported.
154 *
155 * @param cfg configuration to use (needed to contact ARM;
156 * the ARM service may internally use a different
157 * configuration to determine how to start the service).
158 * @param sched scheduler to use
159 * @param ... NULL-terminated list of service names (const char*)
160 */
161void
162GNUNET_ARM_stop_services (const struct GNUNET_CONFIGURATION_Handle *cfg,
163 struct GNUNET_SCHEDULER_Handle *sched,
164 ...);
165
166 135
167#if 0 /* keep Emacsens' auto-indent happy */ 136#if 0 /* keep Emacsens' auto-indent happy */
168{ 137{
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index a392b65fb..aaea7162c 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -1278,7 +1278,6 @@ GNUNET_TRANSPORT_connect (struct GNUNET_SCHEDULER_Handle *sched,
1278{ 1278{
1279 struct GNUNET_TRANSPORT_Handle *ret; 1279 struct GNUNET_TRANSPORT_Handle *ret;
1280 1280
1281 GNUNET_ARM_start_services (cfg, sched, "peerinfo", "transport", NULL);
1282 ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle)); 1281 ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle));
1283 ret->sched = sched; 1282 ret->sched = sched;
1284 ret->cfg = cfg; 1283 ret->cfg = cfg;