diff options
author | Gabor X Toth <*@tg-x.net> | 2014-05-26 22:16:05 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2014-05-26 22:16:05 +0000 |
commit | 83495695331fcfa8824d7a6d407b82cfcfc8b13c (patch) | |
tree | 2d2a7717d81890f5142da9561bccf9e164b1deee /src/psyc/test_psyc.c | |
parent | 1cfab01aaea932539c39dcb2118ec4d6c6d44381 (diff) | |
download | gnunet-83495695331fcfa8824d7a6d407b82cfcfc8b13c.tar.gz gnunet-83495695331fcfa8824d7a6d407b82cfcfc8b13c.zip |
psyc, multicast: join decision, tests
Diffstat (limited to 'src/psyc/test_psyc.c')
-rw-r--r-- | src/psyc/test_psyc.c | 86 |
1 files changed, 55 insertions, 31 deletions
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c index 4195e464b..8b4aad773 100644 --- a/src/psyc/test_psyc.c +++ b/src/psyc/test_psyc.c | |||
@@ -35,9 +35,9 @@ | |||
35 | #include "gnunet_env_lib.h" | 35 | #include "gnunet_env_lib.h" |
36 | #include "gnunet_psyc_service.h" | 36 | #include "gnunet_psyc_service.h" |
37 | 37 | ||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
39 | 39 | ||
40 | #define DEBUG_SERVICE 0 | 40 | #define DEBUG_SERVICE 1 |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
@@ -79,6 +79,7 @@ struct TransmitClosure | |||
79 | 79 | ||
80 | struct TransmitClosure *tmit; | 80 | struct TransmitClosure *tmit; |
81 | 81 | ||
82 | static int join_req_count; | ||
82 | 83 | ||
83 | enum | 84 | enum |
84 | { | 85 | { |
@@ -167,8 +168,8 @@ end () | |||
167 | 168 | ||
168 | 169 | ||
169 | static void | 170 | static void |
170 | master_message (void *cls, uint64_t message_id, uint32_t flags, | 171 | master_message_cb (void *cls, uint64_t message_id, uint32_t flags, |
171 | const struct GNUNET_MessageHeader *msg) | 172 | const struct GNUNET_MessageHeader *msg) |
172 | { | 173 | { |
173 | if (NULL == msg) | 174 | if (NULL == msg) |
174 | { | 175 | { |
@@ -211,8 +212,8 @@ master_message (void *cls, uint64_t message_id, uint32_t flags, | |||
211 | 212 | ||
212 | 213 | ||
213 | static void | 214 | static void |
214 | slave_message (void *cls, uint64_t message_id, uint32_t flags, | 215 | slave_message_cb (void *cls, uint64_t message_id, uint32_t flags, |
215 | const struct GNUNET_MessageHeader *msg) | 216 | const struct GNUNET_MessageHeader *msg) |
216 | { | 217 | { |
217 | if (NULL == msg) | 218 | if (NULL == msg) |
218 | { | 219 | { |
@@ -243,23 +244,6 @@ slave_message (void *cls, uint64_t message_id, uint32_t flags, | |||
243 | 244 | ||
244 | 245 | ||
245 | static void | 246 | static void |
246 | join_request (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key, | ||
247 | const struct GNUNET_PSYC_MessageHeader *msg, | ||
248 | struct GNUNET_PSYC_JoinHandle *jh) | ||
249 | { | ||
250 | struct GNUNET_HashCode slave_key_hash; | ||
251 | GNUNET_CRYPTO_hash (slave_key, sizeof (*slave_key), &slave_key_hash); | ||
252 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
253 | "Got join request from %s.\n", | ||
254 | GNUNET_h2s (&slave_key_hash)); | ||
255 | |||
256 | GNUNET_PSYC_join_decision (jh, GNUNET_YES, 0, NULL, "_notice_join", NULL, | ||
257 | "you're in", 9); | ||
258 | // FIXME: also test refusing entry | ||
259 | } | ||
260 | |||
261 | |||
262 | static void | ||
263 | transmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 247 | transmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
264 | { | 248 | { |
265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n"); | 249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n"); |
@@ -392,9 +376,23 @@ tmit_notify_data (void *cls, uint16_t *data_size, void *data) | |||
392 | 376 | ||
393 | 377 | ||
394 | static void | 378 | static void |
395 | slave_joined (void *cls, uint64_t max_message_id) | 379 | slave_join (); |
380 | |||
381 | |||
382 | static void | ||
383 | join_decision_cb (void *cls, int is_admitted, | ||
384 | const struct GNUNET_PSYC_MessageHeader *join_msg) | ||
396 | { | 385 | { |
397 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Slave joined: %lu\n", max_message_id); | 386 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
387 | "Slave got join decision: %d\n", is_admitted); | ||
388 | |||
389 | if (GNUNET_YES != is_admitted) | ||
390 | { /* First join request is refused, retry. */ | ||
391 | //GNUNET_assert (1 == join_req_count); | ||
392 | slave_join (); | ||
393 | return; | ||
394 | } | ||
395 | |||
398 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Slave sending request to master.\n"); | 396 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Slave sending request to master.\n"); |
399 | 397 | ||
400 | test = TEST_SLAVE_TRANSMIT; | 398 | test = TEST_SLAVE_TRANSMIT; |
@@ -414,20 +412,46 @@ slave_joined (void *cls, uint64_t max_message_id) | |||
414 | GNUNET_PSYC_SLAVE_TRANSMIT_NONE); | 412 | GNUNET_PSYC_SLAVE_TRANSMIT_NONE); |
415 | } | 413 | } |
416 | 414 | ||
415 | |||
416 | static void | ||
417 | join_request_cb (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key, | ||
418 | const struct GNUNET_PSYC_MessageHeader *msg, | ||
419 | struct GNUNET_PSYC_JoinHandle *jh) | ||
420 | { | ||
421 | struct GNUNET_HashCode slave_key_hash; | ||
422 | GNUNET_CRYPTO_hash (slave_key, sizeof (*slave_key), &slave_key_hash); | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
424 | "Got join request from %s.\n", | ||
425 | GNUNET_h2s (&slave_key_hash)); | ||
426 | |||
427 | /* Reject first request */ | ||
428 | int is_admitted = (0 < join_req_count++) ? GNUNET_YES : GNUNET_NO; | ||
429 | GNUNET_PSYC_join_decision (jh, is_admitted, 0, NULL, NULL); | ||
430 | } | ||
431 | |||
432 | |||
433 | static void | ||
434 | slave_connect_cb (void *cls, uint64_t max_message_id) | ||
435 | { | ||
436 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
437 | "Slave connected: %lu\n", max_message_id); | ||
438 | } | ||
439 | |||
440 | |||
417 | static void | 441 | static void |
418 | slave_join () | 442 | slave_join () |
419 | { | 443 | { |
420 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Joining slave.\n"); | 444 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Joining slave.\n"); |
421 | 445 | ||
422 | struct GNUNET_PeerIdentity origin; | 446 | struct GNUNET_PeerIdentity origin; // FIXME: this peer |
423 | struct GNUNET_PeerIdentity relays[16]; | ||
424 | struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create (); | 447 | struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create (); |
425 | GNUNET_ENV_environment_add (env, GNUNET_ENV_OP_ASSIGN, | 448 | GNUNET_ENV_environment_add (env, GNUNET_ENV_OP_ASSIGN, |
426 | "_foo", "bar baz", 7); | 449 | "_foo", "bar baz", 7); |
427 | GNUNET_ENV_environment_add (env, GNUNET_ENV_OP_ASSIGN, | 450 | GNUNET_ENV_environment_add (env, GNUNET_ENV_OP_ASSIGN, |
428 | "_foo_bar", "foo bar baz", 11); | 451 | "_foo_bar", "foo bar baz", 11); |
429 | slv = GNUNET_PSYC_slave_join (cfg, &channel_pub_key, slave_key, &origin, | 452 | slv = GNUNET_PSYC_slave_join (cfg, &channel_pub_key, slave_key, &origin, |
430 | 16, relays, &slave_message, &slave_joined, NULL, | 453 | 0, NULL, &slave_message_cb, |
454 | &slave_connect_cb, &join_decision_cb, NULL, | ||
431 | "_request_join", env, "some data", 9); | 455 | "_request_join", env, "some data", 9); |
432 | GNUNET_ENV_environment_destroy (env); | 456 | GNUNET_ENV_environment_destroy (env); |
433 | } | 457 | } |
@@ -485,7 +509,7 @@ master_transmit () | |||
485 | 509 | ||
486 | 510 | ||
487 | static void | 511 | static void |
488 | master_started (void *cls, uint64_t max_message_id) | 512 | master_start_cb (void *cls, uint64_t max_message_id) |
489 | { | 513 | { |
490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
491 | "Master started: %" PRIu64 "\n", max_message_id); | 515 | "Master started: %" PRIu64 "\n", max_message_id); |
@@ -521,8 +545,8 @@ run (void *cls, | |||
521 | 545 | ||
522 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting master.\n"); | 546 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting master.\n"); |
523 | mst = GNUNET_PSYC_master_start (cfg, channel_key, GNUNET_PSYC_CHANNEL_PRIVATE, | 547 | mst = GNUNET_PSYC_master_start (cfg, channel_key, GNUNET_PSYC_CHANNEL_PRIVATE, |
524 | &master_message, &join_request, | 548 | &master_start_cb, &join_request_cb, |
525 | &master_started, NULL); | 549 | &master_message_cb, NULL); |
526 | } | 550 | } |
527 | 551 | ||
528 | 552 | ||