diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-26 21:12:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-26 21:12:56 +0000 |
commit | 8c2dc7d19810d58f23c43bf900e2fb3eebe06fed (patch) | |
tree | 9173a966e2f51a34d9259a0126484e05d44dcaac /src/core/test_core_api_start_only.c | |
parent | a89ea716333ad5ad43757a946efc01cb5e95a0c0 (diff) | |
download | gnunet-8c2dc7d19810d58f23c43bf900e2fb3eebe06fed.tar.gz gnunet-8c2dc7d19810d58f23c43bf900e2fb3eebe06fed.zip |
-converting CORE service to new transport MQ API
Diffstat (limited to 'src/core/test_core_api_start_only.c')
-rw-r--r-- | src/core/test_core_api_start_only.c | 117 |
1 files changed, 72 insertions, 45 deletions
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index 42bf4e452..07a402189 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c | |||
@@ -25,10 +25,7 @@ | |||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_arm_service.h" | 26 | #include "gnunet_arm_service.h" |
27 | #include "gnunet_core_service.h" | 27 | #include "gnunet_core_service.h" |
28 | #include "gnunet_getopt_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_os_lib.h" | ||
30 | #include "gnunet_program_lib.h" | ||
31 | #include "gnunet_scheduler_lib.h" | ||
32 | 29 | ||
33 | #define TIMEOUT 5 | 30 | #define TIMEOUT 5 |
34 | 31 | ||
@@ -46,32 +43,28 @@ static struct PeerContext p1; | |||
46 | 43 | ||
47 | static struct PeerContext p2; | 44 | static struct PeerContext p2; |
48 | 45 | ||
49 | static struct GNUNET_SCHEDULER_Task * timeout_task_id; | 46 | static struct GNUNET_SCHEDULER_Task *timeout_task_id; |
50 | 47 | ||
51 | static int ok; | 48 | static int ok; |
52 | 49 | ||
53 | #if VERBOSE | ||
54 | #define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | ||
55 | #else | ||
56 | #define OKPP do { ok++; } while (0) | ||
57 | #endif | ||
58 | |||
59 | |||
60 | 50 | ||
61 | static void | 51 | static void |
62 | connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) | 52 | connect_notify (void *cls, |
53 | const struct GNUNET_PeerIdentity *peer) | ||
63 | { | 54 | { |
64 | } | 55 | } |
65 | 56 | ||
66 | 57 | ||
67 | static void | 58 | static void |
68 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) | 59 | disconnect_notify (void *cls, |
60 | const struct GNUNET_PeerIdentity *peer) | ||
69 | { | 61 | { |
70 | } | 62 | } |
71 | 63 | ||
72 | 64 | ||
73 | static int | 65 | static int |
74 | inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, | 66 | inbound_notify (void *cls, |
67 | const struct GNUNET_PeerIdentity *other, | ||
75 | const struct GNUNET_MessageHeader *message) | 68 | const struct GNUNET_MessageHeader *message) |
76 | { | 69 | { |
77 | return GNUNET_OK; | 70 | return GNUNET_OK; |
@@ -79,7 +72,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, | |||
79 | 72 | ||
80 | 73 | ||
81 | static int | 74 | static int |
82 | outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, | 75 | outbound_notify (void *cls, |
76 | const struct GNUNET_PeerIdentity *other, | ||
83 | const struct GNUNET_MessageHeader *message) | 77 | const struct GNUNET_MessageHeader *message) |
84 | { | 78 | { |
85 | return GNUNET_OK; | 79 | return GNUNET_OK; |
@@ -112,33 +106,45 @@ init_notify (void *cls, | |||
112 | { | 106 | { |
113 | /* connect p2 */ | 107 | /* connect p2 */ |
114 | p2.ch = | 108 | p2.ch = |
115 | GNUNET_CORE_connect (p2.cfg, &p2, &init_notify, &connect_notify, | 109 | GNUNET_CORE_connect (p2.cfg, |
116 | &disconnect_notify, &inbound_notify, GNUNET_YES, | 110 | &p2, |
117 | &outbound_notify, GNUNET_YES, handlers); | 111 | &init_notify, |
112 | &connect_notify, | ||
113 | &disconnect_notify, | ||
114 | &inbound_notify, GNUNET_YES, | ||
115 | &outbound_notify, GNUNET_YES, | ||
116 | handlers); | ||
118 | } | 117 | } |
119 | else | 118 | else |
120 | { | 119 | { |
121 | GNUNET_assert (p == &p2); | 120 | GNUNET_assert (p == &p2); |
122 | GNUNET_SCHEDULER_cancel (timeout_task_id); | 121 | GNUNET_SCHEDULER_cancel (timeout_task_id); |
123 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 122 | timeout_task_id = NULL; |
123 | GNUNET_SCHEDULER_add_now (&shutdown_task, | ||
124 | NULL); | ||
124 | } | 125 | } |
125 | } | 126 | } |
126 | 127 | ||
127 | 128 | ||
128 | static void | 129 | static void |
129 | setup_peer (struct PeerContext *p, const char *cfgname) | 130 | setup_peer (struct PeerContext *p, |
131 | const char *cfgname) | ||
130 | { | 132 | { |
131 | char *binary; | 133 | char *binary; |
132 | 134 | ||
133 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 135 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
134 | p->cfg = GNUNET_CONFIGURATION_create (); | 136 | p->cfg = GNUNET_CONFIGURATION_create (); |
135 | p->arm_proc = | 137 | p->arm_proc = |
136 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 138 | GNUNET_OS_start_process (GNUNET_YES, |
139 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
137 | NULL, NULL, NULL, | 140 | NULL, NULL, NULL, |
138 | binary, | 141 | binary, |
139 | "gnunet-service-arm", | 142 | "gnunet-service-arm", |
140 | "-c", cfgname, NULL); | 143 | "-c", cfgname, |
141 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 144 | NULL); |
145 | GNUNET_assert (GNUNET_OK == | ||
146 | GNUNET_CONFIGURATION_load (p->cfg, | ||
147 | cfgname)); | ||
142 | GNUNET_free (binary); | 148 | GNUNET_free (binary); |
143 | } | 149 | } |
144 | 150 | ||
@@ -147,12 +153,12 @@ static void | |||
147 | timeout_task (void *cls) | 153 | timeout_task (void *cls) |
148 | { | 154 | { |
149 | FPRINTF (stderr, "%s", "Timeout.\n"); | 155 | FPRINTF (stderr, "%s", "Timeout.\n"); |
150 | if (p1.ch != NULL) | 156 | if (NULL != p1.ch) |
151 | { | 157 | { |
152 | GNUNET_CORE_disconnect (p1.ch); | 158 | GNUNET_CORE_disconnect (p1.ch); |
153 | p1.ch = NULL; | 159 | p1.ch = NULL; |
154 | } | 160 | } |
155 | if (p2.ch != NULL) | 161 | if (NULL != p2.ch) |
156 | { | 162 | { |
157 | GNUNET_CORE_disconnect (p2.ch); | 163 | GNUNET_CORE_disconnect (p2.ch); |
158 | p2.ch = NULL; | 164 | p2.ch = NULL; |
@@ -162,34 +168,47 @@ timeout_task (void *cls) | |||
162 | 168 | ||
163 | 169 | ||
164 | static void | 170 | static void |
165 | run (void *cls, char *const *args, const char *cfgfile, | 171 | run (void *cls, |
172 | char *const *args, | ||
173 | const char *cfgfile, | ||
166 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 174 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
167 | { | 175 | { |
168 | GNUNET_assert (ok == 1); | 176 | GNUNET_assert (ok == 1); |
169 | OKPP; | 177 | ok++; |
170 | setup_peer (&p1, "test_core_api_peer1.conf"); | 178 | setup_peer (&p1, "test_core_api_peer1.conf"); |
171 | setup_peer (&p2, "test_core_api_peer2.conf"); | 179 | setup_peer (&p2, "test_core_api_peer2.conf"); |
172 | timeout_task_id = | 180 | timeout_task_id = |
173 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 181 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
174 | (GNUNET_TIME_UNIT_MINUTES, TIMEOUT), | 182 | (GNUNET_TIME_UNIT_MINUTES, |
183 | TIMEOUT), | ||
175 | &timeout_task, NULL); | 184 | &timeout_task, NULL); |
176 | p1.ch = | 185 | p1.ch = GNUNET_CORE_connect (p1.cfg, |
177 | GNUNET_CORE_connect (p1.cfg, &p1, &init_notify, &connect_notify, | 186 | &p1, |
178 | &disconnect_notify, &inbound_notify, GNUNET_YES, | 187 | &init_notify, |
179 | &outbound_notify, GNUNET_YES, handlers); | 188 | &connect_notify, |
189 | &disconnect_notify, | ||
190 | &inbound_notify, GNUNET_YES, | ||
191 | &outbound_notify, GNUNET_YES, | ||
192 | handlers); | ||
180 | } | 193 | } |
181 | 194 | ||
182 | 195 | ||
183 | static void | 196 | static void |
184 | stop_arm (struct PeerContext *p) | 197 | stop_arm (struct PeerContext *p) |
185 | { | 198 | { |
186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n"); | 199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
187 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) | 200 | "Stopping peer\n"); |
188 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 201 | if (0 != GNUNET_OS_process_kill (p->arm_proc, |
189 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | 202 | GNUNET_TERM_SIG)) |
190 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 203 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | 204 | "kill"); |
192 | GNUNET_OS_process_get_pid (p->arm_proc)); | 205 | if (GNUNET_OK != |
206 | GNUNET_OS_process_wait (p->arm_proc)) | ||
207 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
208 | "waitpid"); | ||
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
210 | "ARM process %u stopped\n", | ||
211 | (unsigned int) GNUNET_OS_process_get_pid (p->arm_proc)); | ||
193 | GNUNET_OS_process_destroy (p->arm_proc); | 212 | GNUNET_OS_process_destroy (p->arm_proc); |
194 | p->arm_proc = NULL; | 213 | p->arm_proc = NULL; |
195 | GNUNET_CONFIGURATION_destroy (p->cfg); | 214 | GNUNET_CONFIGURATION_destroy (p->cfg); |
@@ -199,7 +218,8 @@ stop_arm (struct PeerContext *p) | |||
199 | static int | 218 | static int |
200 | check () | 219 | check () |
201 | { | 220 | { |
202 | char *const argv[] = { "test-core-api-start-only", | 221 | char *const argv[] = { |
222 | "test-core-api-start-only", | ||
203 | "-c", | 223 | "-c", |
204 | "test_core_api_data.conf", | 224 | "test_core_api_data.conf", |
205 | NULL | 225 | NULL |
@@ -211,9 +231,15 @@ check () | |||
211 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); | 231 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); |
212 | 232 | ||
213 | ok = 1; | 233 | ok = 1; |
214 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, | 234 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
215 | "test-core-api-start-only", "nohelp", options, &run, &ok); | 235 | argv, |
216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test finished\n"); | 236 | "test-core-api-start-only", |
237 | "nohelp", | ||
238 | options, | ||
239 | &run, | ||
240 | &ok); | ||
241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
242 | "Test finished\n"); | ||
217 | stop_arm (&p1); | 243 | stop_arm (&p1); |
218 | stop_arm (&p2); | 244 | stop_arm (&p2); |
219 | return ok; | 245 | return ok; |
@@ -221,7 +247,8 @@ check () | |||
221 | 247 | ||
222 | 248 | ||
223 | int | 249 | int |
224 | main (int argc, char *argv[]) | 250 | main (int argc, |
251 | char *argv[]) | ||
225 | { | 252 | { |
226 | int ret; | 253 | int ret; |
227 | 254 | ||