diff options
author | Gabor X Toth <*@tg-x.net> | 2014-07-27 11:35:49 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2014-07-27 11:35:49 +0000 |
commit | 2f0367bf715c7c0abd12b3e167f329311a35f6e2 (patch) | |
tree | 64a3726c19b1740eaf03f437106db5f9cc565202 /src/psyc | |
parent | 1ac8baae5380d8f83efb31390568b717e871823a (diff) | |
download | gnunet-2f0367bf715c7c0abd12b3e167f329311a35f6e2.tar.gz gnunet-2f0367bf715c7c0abd12b3e167f329311a35f6e2.zip |
psyc: multicast callbacks for membership test and fragment/message replay
Diffstat (limited to 'src/psyc')
-rw-r--r-- | src/psyc/gnunet-service-psyc.c | 153 |
1 files changed, 118 insertions, 35 deletions
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c index 285bd9f73..9d6f12420 100644 --- a/src/psyc/gnunet-service-psyc.c +++ b/src/psyc/gnunet-service-psyc.c | |||
@@ -708,16 +708,89 @@ mcast_recv_join_decision (void *cls, int is_admitted, | |||
708 | } | 708 | } |
709 | 709 | ||
710 | 710 | ||
711 | /** | ||
712 | * Received result of GNUNET_PSYCSTORE_membership_test() | ||
713 | */ | ||
714 | static void | ||
715 | store_recv_membership_test_result (void *cls, int64_t result, const char *err_msg) | ||
716 | { | ||
717 | struct GNUNET_MULTICAST_MembershipTestHandle *mth = cls; | ||
718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
719 | "%p GNUNET_PSYCSTORE_membership_test() returned %" PRId64 " (%s)\n", | ||
720 | mth, result, err_msg); | ||
721 | |||
722 | GNUNET_MULTICAST_membership_test_result (mth, result); | ||
723 | } | ||
724 | |||
725 | |||
726 | /** | ||
727 | * Incoming membership test request from multicast. | ||
728 | */ | ||
711 | static void | 729 | static void |
712 | mcast_recv_membership_test (void *cls, | 730 | mcast_recv_membership_test (void *cls, |
713 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 731 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
714 | uint64_t message_id, uint64_t group_generation, | 732 | uint64_t message_id, uint64_t group_generation, |
715 | struct GNUNET_MULTICAST_MembershipTestHandle *mth) | 733 | struct GNUNET_MULTICAST_MembershipTestHandle *mth) |
716 | { | 734 | { |
735 | struct Channel *chn = cls; | ||
736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
737 | "%p Received membership test request from multicast.\n", | ||
738 | mth); | ||
739 | GNUNET_PSYCSTORE_membership_test (store, &chn->pub_key, slave_key, | ||
740 | message_id, group_generation, | ||
741 | &store_recv_membership_test_result, mth); | ||
742 | } | ||
743 | |||
744 | |||
745 | static int | ||
746 | store_recv_fragment_replay (void *cls, | ||
747 | struct GNUNET_MULTICAST_MessageHeader *msg, | ||
748 | enum GNUNET_PSYCSTORE_MessageFlags flags) | ||
749 | { | ||
750 | struct GNUNET_MULTICAST_ReplayHandle *rh = cls; | ||
717 | 751 | ||
752 | GNUNET_MULTICAST_replay_response (rh, &msg->header, GNUNET_MULTICAST_REC_OK); | ||
753 | return GNUNET_YES; | ||
718 | } | 754 | } |
719 | 755 | ||
720 | 756 | ||
757 | /** | ||
758 | * Received result of GNUNET_PSYCSTORE_fragment_get() for multicast replay. | ||
759 | */ | ||
760 | static void | ||
761 | store_recv_fragment_replay_result (void *cls, int64_t result, const char *err_msg) | ||
762 | { | ||
763 | struct GNUNET_MULTICAST_ReplayHandle *rh = cls; | ||
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
765 | "%p Fragment replay: PSYCSTORE returned %" PRId64 " (%s)\n", | ||
766 | rh, result, err_msg); | ||
767 | |||
768 | switch (result) | ||
769 | { | ||
770 | case GNUNET_YES: | ||
771 | break; | ||
772 | |||
773 | case GNUNET_NO: | ||
774 | GNUNET_MULTICAST_replay_response (rh, NULL, | ||
775 | GNUNET_MULTICAST_REC_NOT_FOUND); | ||
776 | break; | ||
777 | |||
778 | case GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED: | ||
779 | GNUNET_MULTICAST_replay_response (rh, NULL, | ||
780 | GNUNET_MULTICAST_REC_ACCESS_DENIED); | ||
781 | |||
782 | case GNUNET_SYSERR: | ||
783 | GNUNET_MULTICAST_replay_response (rh, NULL, | ||
784 | GNUNET_MULTICAST_REC_INTERNAL_ERROR); | ||
785 | break; | ||
786 | } | ||
787 | GNUNET_MULTICAST_replay_response_end (rh); | ||
788 | } | ||
789 | |||
790 | |||
791 | /** | ||
792 | * Incoming fragment replay request from multicast. | ||
793 | */ | ||
721 | static void | 794 | static void |
722 | mcast_recv_replay_fragment (void *cls, | 795 | mcast_recv_replay_fragment (void *cls, |
723 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 796 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
@@ -725,10 +798,16 @@ mcast_recv_replay_fragment (void *cls, | |||
725 | struct GNUNET_MULTICAST_ReplayHandle *rh) | 798 | struct GNUNET_MULTICAST_ReplayHandle *rh) |
726 | 799 | ||
727 | { | 800 | { |
728 | 801 | struct Channel *chn = cls; | |
802 | GNUNET_PSYCSTORE_fragment_get (store, &chn->pub_key, slave_key, fragment_id, | ||
803 | &store_recv_fragment_replay, | ||
804 | &store_recv_fragment_replay_result, rh); | ||
729 | } | 805 | } |
730 | 806 | ||
731 | 807 | ||
808 | /** | ||
809 | * Incoming message replay request from multicast. | ||
810 | */ | ||
732 | static void | 811 | static void |
733 | mcast_recv_replay_message (void *cls, | 812 | mcast_recv_replay_message (void *cls, |
734 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 813 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
@@ -737,7 +816,10 @@ mcast_recv_replay_message (void *cls, | |||
737 | uint64_t flags, | 816 | uint64_t flags, |
738 | struct GNUNET_MULTICAST_ReplayHandle *rh) | 817 | struct GNUNET_MULTICAST_ReplayHandle *rh) |
739 | { | 818 | { |
740 | 819 | struct Channel *chn = cls; | |
820 | GNUNET_PSYCSTORE_message_get (store, &chn->pub_key, slave_key, message_id, | ||
821 | &store_recv_fragment_replay, | ||
822 | &store_recv_fragment_replay_result, rh); | ||
741 | } | 823 | } |
742 | 824 | ||
743 | 825 | ||
@@ -1190,7 +1272,7 @@ message_queue_drop (struct Channel *chn) | |||
1190 | 1272 | ||
1191 | 1273 | ||
1192 | /** | 1274 | /** |
1193 | * Handle the result of a GNUNET_PSYCSTORE_fragment_store() operation. | 1275 | * Received result of GNUNET_PSYCSTORE_fragment_store(). |
1194 | */ | 1276 | */ |
1195 | static void | 1277 | static void |
1196 | store_recv_fragment_store_result (void *cls, int64_t result, const char *err_msg) | 1278 | store_recv_fragment_store_result (void *cls, int64_t result, const char *err_msg) |
@@ -2020,6 +2102,38 @@ client_recv_state_get_prefix (void *cls, struct GNUNET_SERVER_Client *client, | |||
2020 | } | 2102 | } |
2021 | 2103 | ||
2022 | 2104 | ||
2105 | static const struct GNUNET_SERVER_MessageHandler server_handlers[] = { | ||
2106 | { &client_recv_master_start, NULL, | ||
2107 | GNUNET_MESSAGE_TYPE_PSYC_MASTER_START, 0 }, | ||
2108 | |||
2109 | { &client_recv_slave_join, NULL, | ||
2110 | GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN, 0 }, | ||
2111 | |||
2112 | { &client_recv_join_decision, NULL, | ||
2113 | GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, 0 }, | ||
2114 | |||
2115 | { &client_recv_psyc_message, NULL, | ||
2116 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 0 }, | ||
2117 | |||
2118 | { &client_recv_slave_add, NULL, | ||
2119 | GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD, 0 }, | ||
2120 | |||
2121 | { &client_recv_slave_remove, NULL, | ||
2122 | GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM, 0 }, | ||
2123 | |||
2124 | { &client_recv_story_request, NULL, | ||
2125 | GNUNET_MESSAGE_TYPE_PSYC_STORY_REQUEST, 0 }, | ||
2126 | |||
2127 | { &client_recv_state_get, NULL, | ||
2128 | GNUNET_MESSAGE_TYPE_PSYC_STATE_GET, 0 }, | ||
2129 | |||
2130 | { &client_recv_state_get_prefix, NULL, | ||
2131 | GNUNET_MESSAGE_TYPE_PSYC_STATE_GET_PREFIX, 0 }, | ||
2132 | |||
2133 | { NULL, NULL, 0, 0 } | ||
2134 | }; | ||
2135 | |||
2136 | |||
2023 | /** | 2137 | /** |
2024 | * Initialize the PSYC service. | 2138 | * Initialize the PSYC service. |
2025 | * | 2139 | * |
@@ -2031,37 +2145,6 @@ static void | |||
2031 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 2145 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
2032 | const struct GNUNET_CONFIGURATION_Handle *c) | 2146 | const struct GNUNET_CONFIGURATION_Handle *c) |
2033 | { | 2147 | { |
2034 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
2035 | { &client_recv_master_start, NULL, | ||
2036 | GNUNET_MESSAGE_TYPE_PSYC_MASTER_START, 0 }, | ||
2037 | |||
2038 | { &client_recv_slave_join, NULL, | ||
2039 | GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN, 0 }, | ||
2040 | |||
2041 | { &client_recv_join_decision, NULL, | ||
2042 | GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, 0 }, | ||
2043 | |||
2044 | { &client_recv_psyc_message, NULL, | ||
2045 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 0 }, | ||
2046 | |||
2047 | { &client_recv_slave_add, NULL, | ||
2048 | GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD, 0 }, | ||
2049 | |||
2050 | { &client_recv_slave_remove, NULL, | ||
2051 | GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM, 0 }, | ||
2052 | |||
2053 | { &client_recv_story_request, NULL, | ||
2054 | GNUNET_MESSAGE_TYPE_PSYC_STORY_REQUEST, 0 }, | ||
2055 | |||
2056 | { &client_recv_state_get, NULL, | ||
2057 | GNUNET_MESSAGE_TYPE_PSYC_STATE_GET, 0 }, | ||
2058 | |||
2059 | { &client_recv_state_get_prefix, NULL, | ||
2060 | GNUNET_MESSAGE_TYPE_PSYC_STATE_GET_PREFIX, 0 }, | ||
2061 | |||
2062 | { NULL, NULL, 0, 0 } | ||
2063 | }; | ||
2064 | |||
2065 | cfg = c; | 2148 | cfg = c; |
2066 | store = GNUNET_PSYCSTORE_connect (cfg); | 2149 | store = GNUNET_PSYCSTORE_connect (cfg); |
2067 | stats = GNUNET_STATISTICS_create ("psyc", cfg); | 2150 | stats = GNUNET_STATISTICS_create ("psyc", cfg); |
@@ -2070,7 +2153,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
2070 | channel_slaves = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | 2153 | channel_slaves = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); |
2071 | recv_cache = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); | 2154 | recv_cache = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); |
2072 | nc = GNUNET_SERVER_notification_context_create (server, 1); | 2155 | nc = GNUNET_SERVER_notification_context_create (server, 1); |
2073 | GNUNET_SERVER_add_handlers (server, handlers); | 2156 | GNUNET_SERVER_add_handlers (server, server_handlers); |
2074 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); | 2157 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); |
2075 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 2158 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
2076 | &shutdown_task, NULL); | 2159 | &shutdown_task, NULL); |