diff options
author | Gabor X Toth <*@tg-x.net> | 2014-07-23 16:19:49 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2014-07-23 16:19:49 +0000 |
commit | 3cf8ba0b60f8495892fa76635e9c23555d0a304c (patch) | |
tree | 5f27648bdb3cf3409628e4e5edc26f811cbd03a5 /src/psyc/test_psyc.c | |
parent | 252b5599987b7ba03b879a8c2d1c455ad4c9834a (diff) | |
download | gnunet-3cf8ba0b60f8495892fa76635e9c23555d0a304c.tar.gz gnunet-3cf8ba0b60f8495892fa76635e9c23555d0a304c.zip |
social: implement enter/leave/messaging; psyc: improvements and fixes
- social: implement enter/leave, send/receive messages, slicer
- psyc, social: add struct GNUNET_PSYC_Message for single-fragment join messages
- psyc: add message callback in addition to message part callback
- client_manager, social, psyc, multicast: add disconnect callback
Diffstat (limited to 'src/psyc/test_psyc.c')
-rw-r--r-- | src/psyc/test_psyc.c | 93 |
1 files changed, 67 insertions, 26 deletions
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c index 0077bc9b7..495e3be47 100644 --- a/src/psyc/test_psyc.c +++ b/src/psyc/test_psyc.c | |||
@@ -62,8 +62,6 @@ static struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key; | |||
62 | static struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key; | 62 | static struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key; |
63 | static struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key; | 63 | static struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key; |
64 | 64 | ||
65 | struct GNUNET_PSYC_MasterTransmitHandle *mth; | ||
66 | |||
67 | struct TransmitClosure | 65 | struct TransmitClosure |
68 | { | 66 | { |
69 | struct GNUNET_PSYC_MasterTransmitHandle *mst_tmit; | 67 | struct GNUNET_PSYC_MasterTransmitHandle *mst_tmit; |
@@ -95,6 +93,28 @@ static void | |||
95 | master_transmit (); | 93 | master_transmit (); |
96 | 94 | ||
97 | 95 | ||
96 | void master_stopped (void *cls) | ||
97 | { | ||
98 | if (NULL != tmit) | ||
99 | { | ||
100 | GNUNET_ENV_environment_destroy (tmit->env); | ||
101 | GNUNET_free (tmit); | ||
102 | tmit = NULL; | ||
103 | } | ||
104 | GNUNET_SCHEDULER_shutdown (); | ||
105 | } | ||
106 | |||
107 | void slave_parted (void *cls) | ||
108 | { | ||
109 | if (NULL != mst) | ||
110 | { | ||
111 | GNUNET_PSYC_master_stop (mst, GNUNET_NO, &master_stopped, NULL); | ||
112 | mst = NULL; | ||
113 | } | ||
114 | else | ||
115 | master_stopped (NULL); | ||
116 | } | ||
117 | |||
98 | /** | 118 | /** |
99 | * Clean up all resources used. | 119 | * Clean up all resources used. |
100 | */ | 120 | */ |
@@ -103,21 +123,11 @@ cleanup () | |||
103 | { | 123 | { |
104 | if (NULL != slv) | 124 | if (NULL != slv) |
105 | { | 125 | { |
106 | GNUNET_PSYC_slave_part (slv); | 126 | GNUNET_PSYC_slave_part (slv, GNUNET_NO, &slave_parted, NULL); |
107 | slv = NULL; | 127 | slv = NULL; |
108 | } | 128 | } |
109 | if (NULL != mst) | 129 | else |
110 | { | 130 | slave_parted (NULL); |
111 | GNUNET_PSYC_master_stop (mst); | ||
112 | mst = NULL; | ||
113 | } | ||
114 | if (NULL != tmit) | ||
115 | { | ||
116 | GNUNET_ENV_environment_destroy (tmit->env); | ||
117 | GNUNET_free (tmit); | ||
118 | tmit = NULL; | ||
119 | } | ||
120 | GNUNET_SCHEDULER_shutdown (); | ||
121 | } | 131 | } |
122 | 132 | ||
123 | 133 | ||
@@ -171,7 +181,20 @@ end () | |||
171 | 181 | ||
172 | static void | 182 | static void |
173 | master_message_cb (void *cls, uint64_t message_id, uint32_t flags, | 183 | master_message_cb (void *cls, uint64_t message_id, uint32_t flags, |
174 | const struct GNUNET_MessageHeader *msg) | 184 | const struct GNUNET_PSYC_MessageHeader *msg) |
185 | { | ||
186 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
187 | "Master got PSYC message fragment of size %u " | ||
188 | "belonging to message ID %llu with flags %x\n", | ||
189 | ntohs (msg->header.size), message_id, flags); | ||
190 | // FIXME | ||
191 | } | ||
192 | |||
193 | |||
194 | static void | ||
195 | master_message_part_cb (void *cls, uint64_t message_id, | ||
196 | uint64_t data_offset, uint32_t flags, | ||
197 | const struct GNUNET_MessageHeader *msg) | ||
175 | { | 198 | { |
176 | if (NULL == msg) | 199 | if (NULL == msg) |
177 | { | 200 | { |
@@ -215,7 +238,20 @@ master_message_cb (void *cls, uint64_t message_id, uint32_t flags, | |||
215 | 238 | ||
216 | static void | 239 | static void |
217 | slave_message_cb (void *cls, uint64_t message_id, uint32_t flags, | 240 | slave_message_cb (void *cls, uint64_t message_id, uint32_t flags, |
218 | const struct GNUNET_MessageHeader *msg) | 241 | const struct GNUNET_PSYC_MessageHeader *msg) |
242 | { | ||
243 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
244 | "Slave got PSYC message fragment of size %u " | ||
245 | "belonging to message ID %llu with flags %x\n", | ||
246 | ntohs (msg->header.size), message_id, flags); | ||
247 | // FIXME | ||
248 | } | ||
249 | |||
250 | |||
251 | static void | ||
252 | slave_message_part_cb (void *cls, uint64_t message_id, | ||
253 | uint64_t data_offset, uint32_t flags, | ||
254 | const struct GNUNET_MessageHeader *msg) | ||
219 | { | 255 | { |
220 | if (NULL == msg) | 256 | if (NULL == msg) |
221 | { | 257 | { |
@@ -371,7 +407,7 @@ tmit_notify_mod (void *cls, uint16_t *data_size, void *data, uint8_t *oper, | |||
371 | memcpy (data, value, value_size); | 407 | memcpy (data, value, value_size); |
372 | } | 408 | } |
373 | 409 | ||
374 | return 0 == tmit->mod_value_size ? GNUNET_YES : GNUNET_NO; | 410 | return GNUNET_NO; |
375 | } | 411 | } |
376 | 412 | ||
377 | 413 | ||
@@ -380,8 +416,10 @@ slave_join (); | |||
380 | 416 | ||
381 | 417 | ||
382 | static void | 418 | static void |
383 | join_decision_cb (void *cls, int is_admitted, | 419 | join_decision_cb (void *cls, |
384 | const struct GNUNET_PSYC_MessageHeader *join_msg) | 420 | const struct GNUNET_PSYC_JoinDecisionMessage *dcsn, |
421 | int is_admitted, | ||
422 | const struct GNUNET_PSYC_Message *join_msg) | ||
385 | { | 423 | { |
386 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 424 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
387 | "Slave got join decision: %d\n", is_admitted); | 425 | "Slave got join decision: %d\n", is_admitted); |
@@ -415,8 +453,10 @@ join_decision_cb (void *cls, int is_admitted, | |||
415 | 453 | ||
416 | 454 | ||
417 | static void | 455 | static void |
418 | join_request_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 456 | join_request_cb (void *cls, |
419 | const struct GNUNET_PSYC_MessageHeader *msg, | 457 | const struct GNUNET_PSYC_JoinRequestMessage *req, |
458 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | ||
459 | const struct GNUNET_PSYC_Message *join_msg, | ||
420 | struct GNUNET_PSYC_JoinHandle *jh) | 460 | struct GNUNET_PSYC_JoinHandle *jh) |
421 | { | 461 | { |
422 | struct GNUNET_HashCode slave_key_hash; | 462 | struct GNUNET_HashCode slave_key_hash; |
@@ -450,11 +490,11 @@ slave_join () | |||
450 | "_foo", "bar baz", 7); | 490 | "_foo", "bar baz", 7); |
451 | GNUNET_ENV_environment_add (env, GNUNET_ENV_OP_ASSIGN, | 491 | GNUNET_ENV_environment_add (env, GNUNET_ENV_OP_ASSIGN, |
452 | "_foo_bar", "foo bar baz", 11); | 492 | "_foo_bar", "foo bar baz", 11); |
453 | struct GNUNET_MessageHeader * | 493 | struct GNUNET_PSYC_Message * |
454 | join_msg = GNUNET_PSYC_message_create ("_request_join", env, "some data", 9); | 494 | join_msg = GNUNET_PSYC_message_create ("_request_join", env, "some data", 9); |
455 | 495 | ||
456 | slv = GNUNET_PSYC_slave_join (cfg, &channel_pub_key, slave_key, &origin, | 496 | slv = GNUNET_PSYC_slave_join (cfg, &channel_pub_key, slave_key, &origin, 0, NULL, |
457 | 0, NULL, &slave_message_cb, | 497 | &slave_message_cb, &slave_message_part_cb, |
458 | &slave_connect_cb, &join_decision_cb, NULL, | 498 | &slave_connect_cb, &join_decision_cb, NULL, |
459 | join_msg); | 499 | join_msg); |
460 | GNUNET_ENV_environment_destroy (env); | 500 | GNUNET_ENV_environment_destroy (env); |
@@ -551,7 +591,8 @@ run (void *cls, | |||
551 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting master.\n"); | 591 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting master.\n"); |
552 | mst = GNUNET_PSYC_master_start (cfg, channel_key, GNUNET_PSYC_CHANNEL_PRIVATE, | 592 | mst = GNUNET_PSYC_master_start (cfg, channel_key, GNUNET_PSYC_CHANNEL_PRIVATE, |
553 | &master_start_cb, &join_request_cb, | 593 | &master_start_cb, &join_request_cb, |
554 | &master_message_cb, NULL); | 594 | &master_message_cb, &master_message_part_cb, |
595 | NULL); | ||
555 | } | 596 | } |
556 | 597 | ||
557 | 598 | ||