diff options
Diffstat (limited to 'src/core/test_core_api_preferences.c')
-rw-r--r-- | src/core/test_core_api_preferences.c | 123 |
1 files changed, 50 insertions, 73 deletions
diff --git a/src/core/test_core_api_preferences.c b/src/core/test_core_api_preferences.c index 200ae4176..e5d5deb1b 100644 --- a/src/core/test_core_api_preferences.c +++ b/src/core/test_core_api_preferences.c | |||
@@ -151,13 +151,11 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
151 | return sizeof (struct GNUNET_MessageHeader); | 151 | return sizeof (struct GNUNET_MessageHeader); |
152 | } | 152 | } |
153 | 153 | ||
154 | static void | 154 | static void preference_cb (void *cls, const struct GNUNET_PeerIdentity *peer, |
155 | preference_cb (void *cls, | 155 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
156 | const struct | 156 | int32_t amount, |
157 | GNUNET_PeerIdentity *peer, | 157 | struct GNUNET_TIME_Relative res_delay, |
158 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 158 | uint64_t preference); |
159 | int32_t amount, | ||
160 | struct GNUNET_TIME_Relative res_delay, uint64_t preference); | ||
161 | 159 | ||
162 | static void | 160 | static void |
163 | do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 161 | do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -173,20 +171,17 @@ do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
173 | } | 171 | } |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
175 | "Requesting reservatin of 32k from core in 1s!\n"); | 173 | "Requesting reservatin of 32k from core in 1s!\n"); |
176 | irc = GNUNET_CORE_peer_change_preference (p1.ch, | 174 | irc = |
177 | &p2.id, | 175 | GNUNET_CORE_peer_change_preference (p1.ch, &p2.id, |
178 | GNUNET_TIME_UNIT_SECONDS, | 176 | GNUNET_TIME_UNIT_SECONDS, |
179 | GNUNET_BANDWIDTH_VALUE_MAX, | 177 | GNUNET_BANDWIDTH_VALUE_MAX, |
180 | 1000000 /* bandwidth for 1s */ , | 178 | 1000000 /* bandwidth for 1s */ , |
181 | 0, &preference_cb, pc); | 179 | 0, &preference_cb, pc); |
182 | } | 180 | } |
183 | 181 | ||
184 | static void | 182 | static void |
185 | preference_cb (void *cls, | 183 | preference_cb (void *cls, const struct GNUNET_PeerIdentity *peer, |
186 | const struct | 184 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, int32_t amount, |
187 | GNUNET_PeerIdentity *peer, | ||
188 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
189 | int32_t amount, | ||
190 | struct GNUNET_TIME_Relative res_delay, uint64_t preference) | 185 | struct GNUNET_TIME_Relative res_delay, uint64_t preference) |
191 | { | 186 | { |
192 | struct PeerContext *pc = cls; | 187 | struct PeerContext *pc = cls; |
@@ -212,15 +207,14 @@ preference_cb (void *cls, | |||
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
213 | "Asking core (1) for transmission to peer `%4s'\n", | 208 | "Asking core (1) for transmission to peer `%4s'\n", |
214 | GNUNET_i2s (&p2.id)); | 209 | GNUNET_i2s (&p2.id)); |
215 | if (NULL == (th = GNUNET_CORE_notify_transmit_ready (p1.ch, | 210 | if (NULL == |
216 | GNUNET_YES, | 211 | (th = |
217 | 0, | 212 | GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_YES, 0, |
218 | GNUNET_TIME_relative_multiply | 213 | GNUNET_TIME_relative_multiply |
219 | (GNUNET_TIME_UNIT_SECONDS, | 214 | (GNUNET_TIME_UNIT_SECONDS, 45), |
220 | 45), &p2.id, | 215 | &p2.id, |
221 | sizeof (struct | 216 | sizeof (struct GNUNET_MessageHeader), |
222 | GNUNET_MessageHeader), | 217 | &transmit_ready, &p1))) |
223 | &transmit_ready, &p1))) | ||
224 | { | 218 | { |
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
226 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", | 220 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", |
@@ -230,8 +224,7 @@ preference_cb (void *cls, | |||
230 | 224 | ||
231 | 225 | ||
232 | static void | 226 | static void |
233 | connect_notify (void *cls, | 227 | connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, |
234 | const struct GNUNET_PeerIdentity *peer, | ||
235 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 228 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
236 | { | 229 | { |
237 | struct PeerContext *pc = cls; | 230 | struct PeerContext *pc = cls; |
@@ -286,14 +279,13 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
286 | th = NULL; | 279 | th = NULL; |
287 | } | 280 | } |
288 | } | 281 | } |
289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n", |
290 | "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); | 283 | GNUNET_i2s (peer)); |
291 | } | 284 | } |
292 | 285 | ||
293 | 286 | ||
294 | static int | 287 | static int |
295 | inbound_notify (void *cls, | 288 | inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, |
296 | const struct GNUNET_PeerIdentity *other, | ||
297 | const struct GNUNET_MessageHeader *message, | 289 | const struct GNUNET_MessageHeader *message, |
298 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 290 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
299 | { | 291 | { |
@@ -304,8 +296,7 @@ inbound_notify (void *cls, | |||
304 | 296 | ||
305 | 297 | ||
306 | static int | 298 | static int |
307 | outbound_notify (void *cls, | 299 | outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, |
308 | const struct GNUNET_PeerIdentity *other, | ||
309 | const struct GNUNET_MessageHeader *message, | 300 | const struct GNUNET_MessageHeader *message, |
310 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 301 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
311 | { | 302 | { |
@@ -318,13 +309,12 @@ outbound_notify (void *cls, | |||
318 | 309 | ||
319 | 310 | ||
320 | static int | 311 | static int |
321 | process_mtype (void *cls, | 312 | process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, |
322 | const struct GNUNET_PeerIdentity *peer, | ||
323 | const struct GNUNET_MessageHeader *message, | 313 | const struct GNUNET_MessageHeader *message, |
324 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 314 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
325 | { | 315 | { |
326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message from `%4s'.\n", |
327 | "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); | 317 | GNUNET_i2s (peer)); |
328 | GNUNET_assert (ok == 5); | 318 | GNUNET_assert (ok == 5); |
329 | OKPP; | 319 | OKPP; |
330 | GNUNET_SCHEDULER_cancel (err_task); | 320 | GNUNET_SCHEDULER_cancel (err_task); |
@@ -345,8 +335,8 @@ static void | |||
345 | ask_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 335 | ask_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
346 | { | 336 | { |
347 | ask_task = | 337 | ask_task = |
348 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 338 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &ask_connect_task, |
349 | &ask_connect_task, NULL); | 339 | NULL); |
350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
351 | "Asking core (1) AGAIN to connect to peer `%4s'\n", | 341 | "Asking core (1) AGAIN to connect to peer `%4s'\n", |
352 | GNUNET_i2s (&p2.id)); | 342 | GNUNET_i2s (&p2.id)); |
@@ -355,15 +345,13 @@ ask_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
355 | 345 | ||
356 | 346 | ||
357 | static void | 347 | static void |
358 | init_notify (void *cls, | 348 | init_notify (void *cls, struct GNUNET_CORE_Handle *server, |
359 | struct GNUNET_CORE_Handle *server, | ||
360 | const struct GNUNET_PeerIdentity *my_identity, | 349 | const struct GNUNET_PeerIdentity *my_identity, |
361 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 350 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
362 | { | 351 | { |
363 | struct PeerContext *p = cls; | 352 | struct PeerContext *p = cls; |
364 | 353 | ||
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 354 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core connection to `%4s' established\n", |
366 | "Core connection to `%4s' established\n", | ||
367 | GNUNET_i2s (my_identity)); | 355 | GNUNET_i2s (my_identity)); |
368 | GNUNET_assert (server != NULL); | 356 | GNUNET_assert (server != NULL); |
369 | p->id = *my_identity; | 357 | p->id = *my_identity; |
@@ -373,14 +361,9 @@ init_notify (void *cls, | |||
373 | GNUNET_assert (ok == 2); | 361 | GNUNET_assert (ok == 2); |
374 | OKPP; | 362 | OKPP; |
375 | /* connect p2 */ | 363 | /* connect p2 */ |
376 | GNUNET_CORE_connect (p2.cfg, 1, | 364 | GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, |
377 | &p2, | 365 | &disconnect_notify, NULL, &inbound_notify, GNUNET_YES, |
378 | &init_notify, | 366 | &outbound_notify, GNUNET_YES, handlers); |
379 | &connect_notify, | ||
380 | &disconnect_notify, | ||
381 | NULL, | ||
382 | &inbound_notify, | ||
383 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | ||
384 | } | 367 | } |
385 | else | 368 | else |
386 | { | 369 | { |
@@ -432,12 +415,13 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
432 | { | 415 | { |
433 | p->cfg = GNUNET_CONFIGURATION_create (); | 416 | p->cfg = GNUNET_CONFIGURATION_create (); |
434 | #if START_ARM | 417 | #if START_ARM |
435 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 418 | p->arm_proc = |
436 | "gnunet-service-arm", | 419 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
420 | "gnunet-service-arm", | ||
437 | #if VERBOSE | 421 | #if VERBOSE |
438 | "-L", "DEBUG", | 422 | "-L", "DEBUG", |
439 | #endif | 423 | #endif |
440 | "-c", cfgname, NULL); | 424 | "-c", cfgname, NULL); |
441 | #endif | 425 | #endif |
442 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 426 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
443 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); | 427 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); |
@@ -447,22 +431,16 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
447 | 431 | ||
448 | 432 | ||
449 | static void | 433 | static void |
450 | run (void *cls, | 434 | run (void *cls, char *const *args, const char *cfgfile, |
451 | char *const *args, | 435 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
452 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
453 | { | 436 | { |
454 | GNUNET_assert (ok == 1); | 437 | GNUNET_assert (ok == 1); |
455 | OKPP; | 438 | OKPP; |
456 | setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf"); | 439 | setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf"); |
457 | setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf"); | 440 | setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf"); |
458 | GNUNET_CORE_connect (p1.cfg, 1, | 441 | GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, |
459 | &p1, | 442 | &disconnect_notify, NULL, &inbound_notify, GNUNET_YES, |
460 | &init_notify, | 443 | &outbound_notify, GNUNET_YES, handlers); |
461 | &connect_notify, | ||
462 | &disconnect_notify, | ||
463 | NULL, | ||
464 | &inbound_notify, | ||
465 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | ||
466 | } | 444 | } |
467 | 445 | ||
468 | static void | 446 | static void |
@@ -473,8 +451,7 @@ stop_arm (struct PeerContext *p) | |||
473 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 451 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
474 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | 452 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
475 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 453 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 454 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", |
477 | "ARM process %u stopped\n", | ||
478 | GNUNET_OS_process_get_pid (p->arm_proc)); | 455 | GNUNET_OS_process_get_pid (p->arm_proc)); |
479 | GNUNET_OS_process_close (p->arm_proc); | 456 | GNUNET_OS_process_close (p->arm_proc); |
480 | p->arm_proc = NULL; | 457 | p->arm_proc = NULL; |
@@ -497,9 +474,9 @@ check () | |||
497 | GNUNET_GETOPT_OPTION_END | 474 | GNUNET_GETOPT_OPTION_END |
498 | }; | 475 | }; |
499 | ok = 1; | 476 | ok = 1; |
500 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 477 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, |
501 | argv, "test-core-api-preferences", "nohelp", options, | 478 | "test-core-api-preferences", "nohelp", options, &run, |
502 | &run, &ok); | 479 | &ok); |
503 | stop_arm (&p1); | 480 | stop_arm (&p1); |
504 | stop_arm (&p2); | 481 | stop_arm (&p2); |
505 | return ok; | 482 | return ok; |