diff options
author | Gabor X Toth <*@tg-x.net> | 2014-03-13 19:03:12 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2014-03-13 19:03:12 +0000 |
commit | e3b0d9da6051251e66c8795f96d33fc9a439decd (patch) | |
tree | c23439301f748d1f04702cc51e5bc7b653ed5572 /src | |
parent | 49fb1901d18e1e42c41b7cd8817e5778ed473470 (diff) | |
download | gnunet-e3b0d9da6051251e66c8795f96d33fc9a439decd.tar.gz gnunet-e3b0d9da6051251e66c8795f96d33fc9a439decd.zip |
PSYC: some code cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/psyc/gnunet-service-psyc.c | 130 |
1 files changed, 46 insertions, 84 deletions
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c index 1b1f4b1db..fb3aa65f7 100644 --- a/src/psyc/gnunet-service-psyc.c +++ b/src/psyc/gnunet-service-psyc.c | |||
@@ -143,9 +143,22 @@ struct Channel | |||
143 | */ | 143 | */ |
144 | struct GNUNET_CONTAINER_MultiHashMap *recv_msgs; | 144 | struct GNUNET_CONTAINER_MultiHashMap *recv_msgs; |
145 | 145 | ||
146 | /** | ||
147 | * FIXME | ||
148 | */ | ||
146 | GNUNET_SCHEDULER_TaskIdentifier tmit_task; | 149 | GNUNET_SCHEDULER_TaskIdentifier tmit_task; |
147 | 150 | ||
148 | /** | 151 | /** |
152 | * Public key of the channel. | ||
153 | */ | ||
154 | struct GNUNET_CRYPTO_EddsaPublicKey pub_key; | ||
155 | |||
156 | /** | ||
157 | * Hash of @a pub_key. | ||
158 | */ | ||
159 | struct GNUNET_HashCode pub_key_hash; | ||
160 | |||
161 | /** | ||
149 | * Expected value size for the modifier being received from the PSYC service. | 162 | * Expected value size for the modifier being received from the PSYC service. |
150 | */ | 163 | */ |
151 | uint32_t tmit_mod_value_size_expected; | 164 | uint32_t tmit_mod_value_size_expected; |
@@ -160,6 +173,9 @@ struct Channel | |||
160 | */ | 173 | */ |
161 | uint8_t tmit_state; | 174 | uint8_t tmit_state; |
162 | 175 | ||
176 | /** | ||
177 | * FIXME | ||
178 | */ | ||
163 | uint8_t in_transmit; | 179 | uint8_t in_transmit; |
164 | 180 | ||
165 | /** | 181 | /** |
@@ -195,11 +211,6 @@ struct Master | |||
195 | struct GNUNET_CRYPTO_EddsaPrivateKey priv_key; | 211 | struct GNUNET_CRYPTO_EddsaPrivateKey priv_key; |
196 | 212 | ||
197 | /** | 213 | /** |
198 | * Public key of the channel. | ||
199 | */ | ||
200 | struct GNUNET_CRYPTO_EddsaPublicKey pub_key; | ||
201 | |||
202 | /** | ||
203 | * Handle for the multicast origin. | 214 | * Handle for the multicast origin. |
204 | */ | 215 | */ |
205 | struct GNUNET_MULTICAST_Origin *origin; | 216 | struct GNUNET_MULTICAST_Origin *origin; |
@@ -232,11 +243,6 @@ struct Master | |||
232 | * @see enum GNUNET_PSYC_Policy | 243 | * @see enum GNUNET_PSYC_Policy |
233 | */ | 244 | */ |
234 | uint32_t policy; | 245 | uint32_t policy; |
235 | |||
236 | /** | ||
237 | * Hash of @a pub_key | ||
238 | */ | ||
239 | struct GNUNET_HashCode pub_key_hash; | ||
240 | }; | 246 | }; |
241 | 247 | ||
242 | 248 | ||
@@ -256,11 +262,6 @@ struct Slave | |||
256 | struct GNUNET_CRYPTO_EddsaPrivateKey slave_key; | 262 | struct GNUNET_CRYPTO_EddsaPrivateKey slave_key; |
257 | 263 | ||
258 | /** | 264 | /** |
259 | * Public key of the channel. | ||
260 | */ | ||
261 | struct GNUNET_CRYPTO_EddsaPublicKey chan_key; | ||
262 | |||
263 | /** | ||
264 | * Handle for the multicast member. | 265 | * Handle for the multicast member. |
265 | */ | 266 | */ |
266 | struct GNUNET_MULTICAST_Member *member; | 267 | struct GNUNET_MULTICAST_Member *member; |
@@ -299,11 +300,6 @@ struct Slave | |||
299 | * Maximum request ID for this channel. | 300 | * Maximum request ID for this channel. |
300 | */ | 301 | */ |
301 | uint64_t max_request_id; | 302 | uint64_t max_request_id; |
302 | |||
303 | /** | ||
304 | * Hash of @a chan_key. | ||
305 | */ | ||
306 | struct GNUNET_HashCode chan_key_hash; | ||
307 | }; | 303 | }; |
308 | 304 | ||
309 | 305 | ||
@@ -343,7 +339,7 @@ client_cleanup (struct Channel *ch) | |||
343 | struct Master *mst = (struct Master *) ch; | 339 | struct Master *mst = (struct Master *) ch; |
344 | if (NULL != mst->origin) | 340 | if (NULL != mst->origin) |
345 | GNUNET_MULTICAST_origin_stop (mst->origin); | 341 | GNUNET_MULTICAST_origin_stop (mst->origin); |
346 | GNUNET_CONTAINER_multihashmap_remove (clients, &mst->pub_key_hash, mst); | 342 | GNUNET_CONTAINER_multihashmap_remove (clients, &ch->pub_key_hash, mst); |
347 | } | 343 | } |
348 | else | 344 | else |
349 | { | 345 | { |
@@ -518,7 +514,6 @@ hash_key_from_hll (struct GNUNET_HashCode *key, uint64_t n) | |||
518 | 514 | ||
519 | static void | 515 | static void |
520 | fragment_cache_insert (struct Channel *ch, | 516 | fragment_cache_insert (struct Channel *ch, |
521 | const struct GNUNET_HashCode *chan_key_hash, | ||
522 | const struct GNUNET_HashCode *msg_id, | 517 | const struct GNUNET_HashCode *msg_id, |
523 | struct FragmentCache *frag_cache, | 518 | struct FragmentCache *frag_cache, |
524 | const struct GNUNET_MULTICAST_MessageHeader *mmsg, | 519 | const struct GNUNET_MULTICAST_MessageHeader *mmsg, |
@@ -526,7 +521,8 @@ fragment_cache_insert (struct Channel *ch, | |||
526 | { | 521 | { |
527 | uint16_t size = ntohs (mmsg->header.size); | 522 | uint16_t size = ntohs (mmsg->header.size); |
528 | struct GNUNET_CONTAINER_MultiHashMap | 523 | struct GNUNET_CONTAINER_MultiHashMap |
529 | *chan_msgs = GNUNET_CONTAINER_multihashmap_get (recv_cache, chan_key_hash); | 524 | *chan_msgs = GNUNET_CONTAINER_multihashmap_get (recv_cache, |
525 | &ch->pub_key_hash); | ||
530 | 526 | ||
531 | if (NULL == frag_cache) | 527 | if (NULL == frag_cache) |
532 | { | 528 | { |
@@ -544,7 +540,7 @@ fragment_cache_insert (struct Channel *ch, | |||
544 | if (NULL == chan_msgs) | 540 | if (NULL == chan_msgs) |
545 | { | 541 | { |
546 | chan_msgs = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | 542 | chan_msgs = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); |
547 | GNUNET_CONTAINER_multihashmap_put (recv_cache, chan_key_hash, chan_msgs, | 543 | GNUNET_CONTAINER_multihashmap_put (recv_cache, &ch->pub_key_hash, chan_msgs, |
548 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 544 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
549 | } | 545 | } |
550 | } | 546 | } |
@@ -591,7 +587,6 @@ fragment_cache_insert (struct Channel *ch, | |||
591 | 587 | ||
592 | static void | 588 | static void |
593 | fragment_cache_clear (struct Channel *ch, | 589 | fragment_cache_clear (struct Channel *ch, |
594 | const struct GNUNET_HashCode *chan_key_hash, | ||
595 | const struct GNUNET_HashCode *msg_id, | 590 | const struct GNUNET_HashCode *msg_id, |
596 | struct FragmentCache *frag_cache, | 591 | struct FragmentCache *frag_cache, |
597 | uint8_t send_to_client) | 592 | uint8_t send_to_client) |
@@ -600,7 +595,8 @@ fragment_cache_clear (struct Channel *ch, | |||
600 | "%p Clearing message fragment cache.\n", ch); | 595 | "%p Clearing message fragment cache.\n", ch); |
601 | 596 | ||
602 | struct GNUNET_CONTAINER_MultiHashMap | 597 | struct GNUNET_CONTAINER_MultiHashMap |
603 | *chan_msgs = GNUNET_CONTAINER_multihashmap_get (recv_cache, chan_key_hash); | 598 | *chan_msgs = GNUNET_CONTAINER_multihashmap_get (recv_cache, |
599 | &ch->pub_key_hash); | ||
604 | GNUNET_assert (NULL != chan_msgs); | 600 | GNUNET_assert (NULL != chan_msgs); |
605 | struct GNUNET_HashCode *frag_id; | 601 | struct GNUNET_HashCode *frag_id; |
606 | 602 | ||
@@ -640,11 +636,9 @@ fragment_cache_clear (struct Channel *ch, | |||
640 | * Store it using PSYCstore and send it to the client of the channel. | 636 | * Store it using PSYCstore and send it to the client of the channel. |
641 | */ | 637 | */ |
642 | static void | 638 | static void |
643 | message_cb (struct Channel *ch, | 639 | message_cb (void *cls, const struct GNUNET_MessageHeader *msg) |
644 | const struct GNUNET_CRYPTO_EddsaPublicKey *chan_key, | ||
645 | const struct GNUNET_HashCode *chan_key_hash, | ||
646 | const struct GNUNET_MessageHeader *msg) | ||
647 | { | 640 | { |
641 | struct Channel *ch = cls; | ||
648 | uint16_t type = ntohs (msg->type); | 642 | uint16_t type = ntohs (msg->type); |
649 | uint16_t size = ntohs (msg->size); | 643 | uint16_t size = ntohs (msg->size); |
650 | 644 | ||
@@ -656,14 +650,14 @@ message_cb (struct Channel *ch, | |||
656 | { | 650 | { |
657 | case GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE: | 651 | case GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE: |
658 | { | 652 | { |
659 | GNUNET_PSYCSTORE_fragment_store (store, chan_key, | 653 | GNUNET_PSYCSTORE_fragment_store (store, &ch->pub_key, |
660 | (const struct | 654 | (const struct |
661 | GNUNET_MULTICAST_MessageHeader *) msg, | 655 | GNUNET_MULTICAST_MessageHeader *) msg, |
662 | 0, NULL, NULL); | 656 | 0, NULL, NULL); |
663 | 657 | ||
664 | #if TODO | 658 | #if TODO |
665 | /* FIXME: apply modifiers to state in PSYCstore */ | 659 | /* FIXME: apply modifiers to state in PSYCstore */ |
666 | GNUNET_PSYCSTORE_state_modify (store, chan_key, | 660 | GNUNET_PSYCSTORE_state_modify (store, &ch->pub_key, |
667 | GNUNET_ntohll (mmsg->message_id), | 661 | GNUNET_ntohll (mmsg->message_id), |
668 | meth->mod_count, mods, | 662 | meth->mod_count, mods, |
669 | rcb, rcb_cls); | 663 | rcb, rcb_cls); |
@@ -707,7 +701,7 @@ message_cb (struct Channel *ch, | |||
707 | { | 701 | { |
708 | if (GNUNET_ntohll (mmsg->fragment_offset) == frag_cache->header_size) | 702 | if (GNUNET_ntohll (mmsg->fragment_offset) == frag_cache->header_size) |
709 | { /* first data fragment after the header, send cached fragments */ | 703 | { /* first data fragment after the header, send cached fragments */ |
710 | fragment_cache_clear (ch, chan_key_hash, &msg_id, frag_cache, GNUNET_YES); | 704 | fragment_cache_clear (ch, &msg_id, frag_cache, GNUNET_YES); |
711 | message_to_client (ch, mmsg); | 705 | message_to_client (ch, mmsg); |
712 | break; | 706 | break; |
713 | } | 707 | } |
@@ -721,13 +715,13 @@ message_cb (struct Channel *ch, | |||
721 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER: | 715 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER: |
722 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT: | 716 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT: |
723 | /* not all modifiers arrived yet, cache fragment */ | 717 | /* not all modifiers arrived yet, cache fragment */ |
724 | fragment_cache_insert (ch, chan_key_hash, &msg_id, frag_cache, mmsg, ptype); | 718 | fragment_cache_insert (ch, &msg_id, frag_cache, mmsg, ptype); |
725 | break; | 719 | break; |
726 | 720 | ||
727 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL: | 721 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL: |
728 | if (NULL != frag_cache) | 722 | if (NULL != frag_cache) |
729 | { /* fragments not yet sent to client, remove from cache */ | 723 | { /* fragments not yet sent to client, remove from cache */ |
730 | fragment_cache_clear (ch, chan_key_hash, &msg_id, frag_cache, GNUNET_NO); | 724 | fragment_cache_clear (ch, &msg_id, frag_cache, GNUNET_NO); |
731 | } | 725 | } |
732 | else | 726 | else |
733 | { | 727 | { |
@@ -746,38 +740,6 @@ message_cb (struct Channel *ch, | |||
746 | 740 | ||
747 | 741 | ||
748 | /** | 742 | /** |
749 | * Incoming message fragment from multicast for a master. | ||
750 | */ | ||
751 | static void | ||
752 | master_message_cb (void *cls, const struct GNUNET_MessageHeader *msg) | ||
753 | { | ||
754 | struct Master *mst = cls; | ||
755 | GNUNET_assert (NULL != mst); | ||
756 | |||
757 | struct GNUNET_CRYPTO_EddsaPublicKey *chan_key = &mst->pub_key; | ||
758 | struct GNUNET_HashCode *chan_key_hash = &mst->pub_key_hash; | ||
759 | |||
760 | message_cb (&mst->channel, chan_key, chan_key_hash, msg); | ||
761 | } | ||
762 | |||
763 | |||
764 | /** | ||
765 | * Incoming message fragment from multicast for a slave. | ||
766 | */ | ||
767 | static void | ||
768 | slave_message_cb (void *cls, const struct GNUNET_MessageHeader *msg) | ||
769 | { | ||
770 | struct Slave *slv = cls; | ||
771 | GNUNET_assert (NULL != slv); | ||
772 | |||
773 | struct GNUNET_CRYPTO_EddsaPublicKey *chan_key = &slv->chan_key; | ||
774 | struct GNUNET_HashCode *chan_key_hash = &slv->chan_key_hash; | ||
775 | |||
776 | message_cb (&slv->channel, chan_key, chan_key_hash, msg); | ||
777 | } | ||
778 | |||
779 | |||
780 | /** | ||
781 | * Incoming request fragment from multicast for a master. | 743 | * Incoming request fragment from multicast for a master. |
782 | * | 744 | * |
783 | * @param cls Master. | 745 | * @param cls Master. |
@@ -870,7 +832,7 @@ master_counters_cb (void *cls, int result, uint64_t max_fragment_id, | |||
870 | max_fragment_id + 1, | 832 | max_fragment_id + 1, |
871 | join_cb, membership_test_cb, | 833 | join_cb, membership_test_cb, |
872 | replay_fragment_cb, replay_message_cb, | 834 | replay_fragment_cb, replay_message_cb, |
873 | request_cb, master_message_cb, ch); | 835 | request_cb, message_cb, ch); |
874 | ch->ready = GNUNET_YES; | 836 | ch->ready = GNUNET_YES; |
875 | } | 837 | } |
876 | GNUNET_SERVER_notification_context_add (nc, ch->client); | 838 | GNUNET_SERVER_notification_context_add (nc, ch->client); |
@@ -900,13 +862,13 @@ slave_counters_cb (void *cls, int result, uint64_t max_fragment_id, | |||
900 | { | 862 | { |
901 | slv->max_message_id = max_message_id; | 863 | slv->max_message_id = max_message_id; |
902 | slv->member | 864 | slv->member |
903 | = GNUNET_MULTICAST_member_join (cfg, &slv->chan_key, &slv->slave_key, | 865 | = GNUNET_MULTICAST_member_join (cfg, &ch->pub_key, &slv->slave_key, |
904 | &slv->origin, | 866 | &slv->origin, |
905 | slv->relay_count, slv->relays, | 867 | slv->relay_count, slv->relays, |
906 | slv->join_req, join_cb, | 868 | slv->join_req, join_cb, |
907 | membership_test_cb, | 869 | membership_test_cb, |
908 | replay_fragment_cb, replay_message_cb, | 870 | replay_fragment_cb, replay_message_cb, |
909 | slave_message_cb, ch); | 871 | message_cb, ch); |
910 | ch->ready = GNUNET_YES; | 872 | ch->ready = GNUNET_YES; |
911 | } | 873 | } |
912 | 874 | ||
@@ -927,21 +889,21 @@ handle_master_start (void *cls, struct GNUNET_SERVER_Client *client, | |||
927 | const struct MasterStartRequest *req | 889 | const struct MasterStartRequest *req |
928 | = (const struct MasterStartRequest *) msg; | 890 | = (const struct MasterStartRequest *) msg; |
929 | struct Master *mst = GNUNET_new (struct Master); | 891 | struct Master *mst = GNUNET_new (struct Master); |
930 | mst->channel.client = client; | 892 | struct Channel *ch = &mst->channel; |
931 | mst->channel.is_master = GNUNET_YES; | 893 | ch->client = client; |
894 | ch->is_master = GNUNET_YES; | ||
932 | mst->policy = ntohl (req->policy); | 895 | mst->policy = ntohl (req->policy); |
933 | mst->priv_key = req->channel_key; | 896 | mst->priv_key = req->channel_key; |
934 | GNUNET_CRYPTO_eddsa_key_get_public (&mst->priv_key, &mst->pub_key); | 897 | GNUNET_CRYPTO_eddsa_key_get_public (&mst->priv_key, &ch->pub_key); |
935 | GNUNET_CRYPTO_hash (&mst->pub_key, sizeof (mst->pub_key), &mst->pub_key_hash); | 898 | GNUNET_CRYPTO_hash (&ch->pub_key, sizeof (ch->pub_key), &ch->pub_key_hash); |
936 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
937 | "%p Master connected to channel %s.\n", | 900 | "%p Master connected to channel %s.\n", |
938 | mst, GNUNET_h2s (&mst->pub_key_hash)); | 901 | mst, GNUNET_h2s (&ch->pub_key_hash)); |
939 | 902 | ||
940 | GNUNET_PSYCSTORE_counters_get (store, &mst->pub_key, | 903 | GNUNET_PSYCSTORE_counters_get (store, &ch->pub_key, master_counters_cb, mst); |
941 | master_counters_cb, mst); | ||
942 | 904 | ||
943 | GNUNET_SERVER_client_set_user_context (client, &mst->channel); | 905 | GNUNET_SERVER_client_set_user_context (client, &mst->channel); |
944 | GNUNET_CONTAINER_multihashmap_put (clients, &mst->pub_key_hash, mst, | 906 | GNUNET_CONTAINER_multihashmap_put (clients, &ch->pub_key_hash, mst, |
945 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 907 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
946 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 908 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
947 | } | 909 | } |
@@ -957,12 +919,13 @@ handle_slave_join (void *cls, struct GNUNET_SERVER_Client *client, | |||
957 | const struct SlaveJoinRequest *req | 919 | const struct SlaveJoinRequest *req |
958 | = (const struct SlaveJoinRequest *) msg; | 920 | = (const struct SlaveJoinRequest *) msg; |
959 | struct Slave *slv = GNUNET_new (struct Slave); | 921 | struct Slave *slv = GNUNET_new (struct Slave); |
922 | struct Channel *ch = &slv->channel; | ||
960 | slv->channel.client = client; | 923 | slv->channel.client = client; |
961 | slv->channel.is_master = GNUNET_NO; | 924 | slv->channel.is_master = GNUNET_NO; |
962 | slv->slave_key = req->slave_key; | 925 | slv->slave_key = req->slave_key; |
963 | slv->chan_key = req->channel_key; | 926 | ch->pub_key = req->channel_key; |
964 | GNUNET_CRYPTO_hash (&slv->chan_key, sizeof (slv->chan_key), | 927 | GNUNET_CRYPTO_hash (&ch->pub_key, sizeof (ch->pub_key), |
965 | &slv->chan_key_hash); | 928 | &ch->pub_key_hash); |
966 | slv->origin = req->origin; | 929 | slv->origin = req->origin; |
967 | slv->relay_count = ntohl (req->relay_count); | 930 | slv->relay_count = ntohl (req->relay_count); |
968 | if (0 < slv->relay_count) | 931 | if (0 < slv->relay_count) |
@@ -978,10 +941,9 @@ handle_slave_join (void *cls, struct GNUNET_SERVER_Client *client, | |||
978 | 941 | ||
979 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 942 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
980 | "%p Slave connected to channel %s.\n", | 943 | "%p Slave connected to channel %s.\n", |
981 | slv, GNUNET_h2s (&slv->chan_key_hash)); | 944 | slv, GNUNET_h2s (&ch->pub_key_hash)); |
982 | 945 | ||
983 | GNUNET_PSYCSTORE_counters_get (store, &slv->chan_key, | 946 | GNUNET_PSYCSTORE_counters_get (store, &ch->pub_key, slave_counters_cb, slv); |
984 | slave_counters_cb, slv); | ||
985 | 947 | ||
986 | GNUNET_SERVER_client_set_user_context (client, &slv->channel); | 948 | GNUNET_SERVER_client_set_user_context (client, &slv->channel); |
987 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 949 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |