diff options
Diffstat (limited to 'src/core/test_core_api.c')
-rw-r--r-- | src/core/test_core_api.c | 205 |
1 files changed, 96 insertions, 109 deletions
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index d45560a5d..b5e93a8a2 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c | |||
@@ -44,7 +44,7 @@ struct PeerContext | |||
44 | { | 44 | { |
45 | struct GNUNET_CONFIGURATION_Handle *cfg; | 45 | struct GNUNET_CONFIGURATION_Handle *cfg; |
46 | struct GNUNET_CORE_Handle *ch; | 46 | struct GNUNET_CORE_Handle *ch; |
47 | struct GNUNET_PeerIdentity id; | 47 | struct GNUNET_PeerIdentity id; |
48 | struct GNUNET_TRANSPORT_Handle *th; | 48 | struct GNUNET_TRANSPORT_Handle *th; |
49 | struct GNUNET_MessageHeader *hello; | 49 | struct GNUNET_MessageHeader *hello; |
50 | int connect_status; | 50 | int connect_status; |
@@ -71,14 +71,12 @@ static int ok; | |||
71 | 71 | ||
72 | 72 | ||
73 | static void | 73 | static void |
74 | process_hello (void *cls, | 74 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
75 | const struct GNUNET_MessageHeader *message) | ||
76 | { | 75 | { |
77 | struct PeerContext *p = cls; | 76 | struct PeerContext *p = cls; |
78 | 77 | ||
79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
80 | "Received (my) `%s' from transport service\n", | 79 | "Received (my) `%s' from transport service\n", "HELLO"); |
81 | "HELLO"); | ||
82 | GNUNET_assert (message != NULL); | 80 | GNUNET_assert (message != NULL); |
83 | if ((p == &p1) && (p2.th != NULL)) | 81 | if ((p == &p1) && (p2.th != NULL)) |
84 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); | 82 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); |
@@ -105,31 +103,31 @@ static void | |||
105 | terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 103 | terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
106 | { | 104 | { |
107 | #if VERBOSE | 105 | #if VERBOSE |
108 | fprintf(stderr, "ENDING ANGRILY %u\n", ok); | 106 | fprintf (stderr, "ENDING ANGRILY %u\n", ok); |
109 | #endif | 107 | #endif |
110 | GNUNET_break (0); | 108 | GNUNET_break (0); |
111 | if (NULL != p1.ch) | 109 | if (NULL != p1.ch) |
112 | { | 110 | { |
113 | GNUNET_CORE_disconnect (p1.ch); | 111 | GNUNET_CORE_disconnect (p1.ch); |
114 | p1.ch = NULL; | 112 | p1.ch = NULL; |
115 | } | 113 | } |
116 | if (NULL != p2.ch) | 114 | if (NULL != p2.ch) |
117 | { | 115 | { |
118 | GNUNET_CORE_disconnect (p2.ch); | 116 | GNUNET_CORE_disconnect (p2.ch); |
119 | p2.ch = NULL; | 117 | p2.ch = NULL; |
120 | } | 118 | } |
121 | if (p1.th != NULL) | 119 | if (p1.th != NULL) |
122 | { | 120 | { |
123 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); | 121 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); |
124 | GNUNET_TRANSPORT_disconnect (p1.th); | 122 | GNUNET_TRANSPORT_disconnect (p1.th); |
125 | p1.th = NULL; | 123 | p1.th = NULL; |
126 | } | 124 | } |
127 | if (p2.th != NULL) | 125 | if (p2.th != NULL) |
128 | { | 126 | { |
129 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); | 127 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); |
130 | GNUNET_TRANSPORT_disconnect (p2.th); | 128 | GNUNET_TRANSPORT_disconnect (p2.th); |
131 | p2.th = NULL; | 129 | p2.th = NULL; |
132 | } | 130 | } |
133 | ok = 42; | 131 | ok = 42; |
134 | } | 132 | } |
135 | 133 | ||
@@ -154,54 +152,51 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
154 | static void | 152 | static void |
155 | connect_notify (void *cls, | 153 | connect_notify (void *cls, |
156 | const struct GNUNET_PeerIdentity *peer, | 154 | const struct GNUNET_PeerIdentity *peer, |
157 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 155 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
158 | { | 156 | { |
159 | struct PeerContext *pc = cls; | 157 | struct PeerContext *pc = cls; |
160 | 158 | ||
161 | if (0 == memcmp (&pc->id, | 159 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
162 | peer, | ||
163 | sizeof (struct GNUNET_PeerIdentity))) | ||
164 | return; | 160 | return; |
165 | GNUNET_assert (pc->connect_status == 0); | 161 | GNUNET_assert (pc->connect_status == 0); |
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
167 | "Encrypted connection established to peer `%4s'\n", | 163 | "Encrypted connection established to peer `%4s'\n", |
168 | GNUNET_i2s (peer)); | 164 | GNUNET_i2s (peer)); |
169 | if (GNUNET_SCHEDULER_NO_TASK != con_task) | 165 | if (GNUNET_SCHEDULER_NO_TASK != con_task) |
170 | { | 166 | { |
171 | GNUNET_SCHEDULER_cancel (con_task); | 167 | GNUNET_SCHEDULER_cancel (con_task); |
172 | con_task = GNUNET_SCHEDULER_NO_TASK; | 168 | con_task = GNUNET_SCHEDULER_NO_TASK; |
173 | } | 169 | } |
174 | pc->connect_status = 1; | 170 | pc->connect_status = 1; |
175 | if (pc == &p1) | 171 | if (pc == &p1) |
172 | { | ||
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
174 | "Asking core (1) for transmission to peer `%4s'\n", | ||
175 | GNUNET_i2s (&p2.id)); | ||
176 | if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch, | ||
177 | GNUNET_YES, | ||
178 | 0, | ||
179 | GNUNET_TIME_relative_multiply | ||
180 | (GNUNET_TIME_UNIT_SECONDS, | ||
181 | 45), &p2.id, | ||
182 | sizeof (struct | ||
183 | GNUNET_MessageHeader), | ||
184 | &transmit_ready, &p1)) | ||
176 | { | 185 | { |
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
178 | "Asking core (1) for transmission to peer `%4s'\n", | 187 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", |
179 | GNUNET_i2s (&p2.id)); | 188 | GNUNET_i2s (&p2.id)); |
180 | if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch, | ||
181 | GNUNET_YES, | ||
182 | 0, | ||
183 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45), | ||
184 | &p2.id, | ||
185 | sizeof (struct GNUNET_MessageHeader), | ||
186 | &transmit_ready, &p1)) | ||
187 | { | ||
188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
189 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", | ||
190 | GNUNET_i2s (&p2.id)); | ||
191 | } | ||
192 | } | 189 | } |
190 | } | ||
193 | } | 191 | } |
194 | 192 | ||
195 | 193 | ||
196 | static void | 194 | static void |
197 | disconnect_notify (void *cls, | 195 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) |
198 | const struct GNUNET_PeerIdentity *peer) | ||
199 | { | 196 | { |
200 | struct PeerContext *pc = cls; | 197 | struct PeerContext *pc = cls; |
201 | 198 | ||
202 | if (0 == memcmp (&pc->id, | 199 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
203 | peer, | ||
204 | sizeof (struct GNUNET_PeerIdentity))) | ||
205 | return; | 200 | return; |
206 | pc->connect_status = 0; | 201 | pc->connect_status = 0; |
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -213,7 +208,7 @@ static int | |||
213 | inbound_notify (void *cls, | 208 | inbound_notify (void *cls, |
214 | const struct GNUNET_PeerIdentity *other, | 209 | const struct GNUNET_PeerIdentity *other, |
215 | const struct GNUNET_MessageHeader *message, | 210 | const struct GNUNET_MessageHeader *message, |
216 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 211 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
217 | { | 212 | { |
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
219 | "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); | 214 | "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); |
@@ -225,7 +220,7 @@ static int | |||
225 | outbound_notify (void *cls, | 220 | outbound_notify (void *cls, |
226 | const struct GNUNET_PeerIdentity *other, | 221 | const struct GNUNET_PeerIdentity *other, |
227 | const struct GNUNET_MessageHeader *message, | 222 | const struct GNUNET_MessageHeader *message, |
228 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 223 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
229 | { | 224 | { |
230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
231 | "Core notifies about outbound data for `%4s'.\n", | 226 | "Core notifies about outbound data for `%4s'.\n", |
@@ -239,7 +234,7 @@ static int | |||
239 | process_mtype (void *cls, | 234 | process_mtype (void *cls, |
240 | const struct GNUNET_PeerIdentity *peer, | 235 | const struct GNUNET_PeerIdentity *peer, |
241 | const struct GNUNET_MessageHeader *message, | 236 | const struct GNUNET_MessageHeader *message, |
242 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 237 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
243 | { | 238 | { |
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
245 | "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); | 240 | "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); |
@@ -258,23 +253,19 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { | |||
258 | 253 | ||
259 | 254 | ||
260 | static void | 255 | static void |
261 | connect_task (void *cls, | 256 | connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
262 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
263 | { | 257 | { |
264 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 258 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
265 | { | 259 | { |
266 | con_task = GNUNET_SCHEDULER_NO_TASK; | 260 | con_task = GNUNET_SCHEDULER_NO_TASK; |
267 | return; | 261 | return; |
268 | } | 262 | } |
269 | con_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 263 | con_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
270 | &connect_task, | 264 | &connect_task, NULL); |
271 | NULL); | ||
272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
273 | "Asking core (1) to connect to peer `%4s'\n", | 266 | "Asking core (1) to connect to peer `%4s'\n", |
274 | GNUNET_i2s (&p2.id)); | 267 | GNUNET_i2s (&p2.id)); |
275 | GNUNET_CORE_peer_request_connect (p1.ch, | 268 | GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); |
276 | &p2.id, | ||
277 | NULL, NULL); | ||
278 | } | 269 | } |
279 | 270 | ||
280 | static void | 271 | static void |
@@ -292,28 +283,27 @@ init_notify (void *cls, | |||
292 | p->id = *my_identity; | 283 | p->id = *my_identity; |
293 | p->ch = server; | 284 | p->ch = server; |
294 | if (cls == &p1) | 285 | if (cls == &p1) |
295 | { | 286 | { |
296 | GNUNET_assert (ok == 2); | 287 | GNUNET_assert (ok == 2); |
297 | OKPP; | 288 | OKPP; |
298 | /* connect p2 */ | 289 | /* connect p2 */ |
299 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, | 290 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, |
300 | &p2, | 291 | &p2, |
301 | &init_notify, | 292 | &init_notify, |
302 | &connect_notify, | 293 | &connect_notify, |
303 | &disconnect_notify, | 294 | &disconnect_notify, |
304 | NULL, | 295 | NULL, |
305 | &inbound_notify, | 296 | &inbound_notify, |
306 | GNUNET_YES, | 297 | GNUNET_YES, |
307 | &outbound_notify, GNUNET_YES, handlers); | 298 | &outbound_notify, GNUNET_YES, handlers); |
308 | } | 299 | } |
309 | else | 300 | else |
310 | { | 301 | { |
311 | GNUNET_assert (ok == 3); | 302 | GNUNET_assert (ok == 3); |
312 | OKPP; | 303 | OKPP; |
313 | GNUNET_assert (cls == &p2); | 304 | GNUNET_assert (cls == &p2); |
314 | con_task = GNUNET_SCHEDULER_add_now (&connect_task, | 305 | con_task = GNUNET_SCHEDULER_add_now (&connect_task, NULL); |
315 | NULL); | 306 | } |
316 | } | ||
317 | } | 307 | } |
318 | 308 | ||
319 | 309 | ||
@@ -323,11 +313,11 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
323 | p->cfg = GNUNET_CONFIGURATION_create (); | 313 | p->cfg = GNUNET_CONFIGURATION_create (); |
324 | #if START_ARM | 314 | #if START_ARM |
325 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 315 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
326 | "gnunet-service-arm", | 316 | "gnunet-service-arm", |
327 | #if VERBOSE | 317 | #if VERBOSE |
328 | "-L", "DEBUG", | 318 | "-L", "DEBUG", |
329 | #endif | 319 | #endif |
330 | "-c", cfgname, NULL); | 320 | "-c", cfgname, NULL); |
331 | #endif | 321 | #endif |
332 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 322 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
333 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); | 323 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); |
@@ -339,24 +329,20 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
339 | static void | 329 | static void |
340 | run (void *cls, | 330 | run (void *cls, |
341 | char *const *args, | 331 | char *const *args, |
342 | const char *cfgfile, | 332 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
343 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
344 | { | 333 | { |
345 | GNUNET_assert (ok == 1); | 334 | GNUNET_assert (ok == 1); |
346 | OKPP; | 335 | OKPP; |
347 | setup_peer (&p1, "test_core_api_peer1.conf"); | 336 | setup_peer (&p1, "test_core_api_peer1.conf"); |
348 | setup_peer (&p2, "test_core_api_peer2.conf"); | 337 | setup_peer (&p2, "test_core_api_peer2.conf"); |
349 | err_task = | 338 | err_task = |
350 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), | 339 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
351 | &terminate_task_error, NULL); | 340 | (GNUNET_TIME_UNIT_SECONDS, 120), |
352 | p1.ch = GNUNET_CORE_connect (p1.cfg, 1, | 341 | &terminate_task_error, NULL); |
353 | &p1, | 342 | p1.ch = |
354 | &init_notify, | 343 | GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, |
355 | &connect_notify, | 344 | &disconnect_notify, NULL, &inbound_notify, |
356 | &disconnect_notify, | 345 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
357 | NULL, | ||
358 | &inbound_notify, | ||
359 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | ||
360 | } | 346 | } |
361 | 347 | ||
362 | static void | 348 | static void |
@@ -365,10 +351,11 @@ stop_arm (struct PeerContext *p) | |||
365 | #if START_ARM | 351 | #if START_ARM |
366 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 352 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
367 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 353 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
368 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 354 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
369 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 355 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
371 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 357 | "ARM process %u stopped\n", |
358 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
372 | GNUNET_OS_process_close (p->arm_proc); | 359 | GNUNET_OS_process_close (p->arm_proc); |
373 | p->arm_proc = NULL; | 360 | p->arm_proc = NULL; |
374 | #endif | 361 | #endif |
@@ -410,7 +397,7 @@ main (int argc, char *argv[]) | |||
410 | #endif | 397 | #endif |
411 | NULL); | 398 | NULL); |
412 | ret = check (); | 399 | ret = check (); |
413 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); | 400 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); |
414 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); | 401 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); |
415 | 402 | ||
416 | return ret; | 403 | return ret; |