diff options
author | Gabor X Toth <*@tg-x.net> | 2014-07-27 13:17:03 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2014-07-27 13:17:03 +0000 |
commit | b63820a52b63d264bead047d0d6f4b76a94c4030 (patch) | |
tree | a678202b91694d3582ae61c57a7badac483693d1 /src/psyc | |
parent | 2f0367bf715c7c0abd12b3e167f329311a35f6e2 (diff) | |
download | gnunet-b63820a52b63d264bead047d0d6f4b76a94c4030.tar.gz gnunet-b63820a52b63d264bead047d0d6f4b76a94c4030.zip |
psyc: membership store
Diffstat (limited to 'src/psyc')
-rw-r--r-- | src/psyc/gnunet-service-psyc.c | 43 | ||||
-rw-r--r-- | src/psyc/psyc.h | 21 | ||||
-rw-r--r-- | src/psyc/psyc_api.c | 26 | ||||
-rw-r--r-- | src/psyc/test_psyc.c | 39 |
4 files changed, 76 insertions, 53 deletions
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c index 9d6f12420..e7020bc69 100644 --- a/src/psyc/gnunet-service-psyc.c +++ b/src/psyc/gnunet-service-psyc.c | |||
@@ -2048,24 +2048,46 @@ client_recv_psyc_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
2048 | 2048 | ||
2049 | 2049 | ||
2050 | /** | 2050 | /** |
2051 | * Client requests to add a slave to the membership database. | 2051 | * Received result of GNUNET_PSYCSTORE_membership_store() |
2052 | */ | 2052 | */ |
2053 | static void | 2053 | static void |
2054 | client_recv_slave_add (void *cls, struct GNUNET_SERVER_Client *client, | 2054 | store_recv_membership_store_result (void *cls, int64_t result, const char *err_msg) |
2055 | const struct GNUNET_MessageHeader *msg) | ||
2056 | { | 2055 | { |
2057 | 2056 | struct GNUNET_MULTICAST_MembershipTestHandle *mth = cls; | |
2057 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2058 | "%p GNUNET_PSYCSTORE_membership_store() returned %" PRId64 " (%s)\n", | ||
2059 | mth, result, err_msg); | ||
2060 | /* FIXME: send result to client */ | ||
2058 | } | 2061 | } |
2059 | 2062 | ||
2060 | 2063 | ||
2061 | /** | 2064 | /** |
2062 | * Client requests to remove a slave from the membership database. | 2065 | * Client requests to add/remove a slave in the membership database. |
2063 | */ | 2066 | */ |
2064 | static void | 2067 | static void |
2065 | client_recv_slave_remove (void *cls, struct GNUNET_SERVER_Client *client, | 2068 | client_recv_membership_store (void *cls, struct GNUNET_SERVER_Client *client, |
2066 | const struct GNUNET_MessageHeader *msg) | 2069 | const struct GNUNET_MessageHeader *msg) |
2067 | { | 2070 | { |
2071 | struct Channel * | ||
2072 | chn = GNUNET_SERVER_client_get_user_context (client, struct Channel); | ||
2073 | GNUNET_assert (NULL != chn); | ||
2074 | |||
2075 | const struct ChannelMembershipStoreRequest * | ||
2076 | req = (const struct ChannelMembershipStoreRequest *) msg; | ||
2077 | |||
2078 | uint64_t announced_at = GNUNET_ntohll (req->announced_at); | ||
2079 | uint64_t effective_since = GNUNET_ntohll (req->effective_since); | ||
2080 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2081 | "%p Received membership store request from client.\n", chn); | ||
2082 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2083 | "%p did_join: %u, announced_at: %" PRIu64 ", effective_since: %" PRIu64 "\n", | ||
2084 | chn, req->did_join, announced_at, effective_since); | ||
2068 | 2085 | ||
2086 | GNUNET_PSYCSTORE_membership_store (store, &chn->pub_key, &req->slave_key, | ||
2087 | req->did_join, announced_at, effective_since, | ||
2088 | 0, /* FIXME: group_generation */ | ||
2089 | &store_recv_membership_store_result, chn); | ||
2090 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
2069 | } | 2091 | } |
2070 | 2092 | ||
2071 | 2093 | ||
@@ -2115,11 +2137,8 @@ static const struct GNUNET_SERVER_MessageHandler server_handlers[] = { | |||
2115 | { &client_recv_psyc_message, NULL, | 2137 | { &client_recv_psyc_message, NULL, |
2116 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 0 }, | 2138 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 0 }, |
2117 | 2139 | ||
2118 | { &client_recv_slave_add, NULL, | 2140 | { &client_recv_membership_store, NULL, |
2119 | GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD, 0 }, | 2141 | GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_MEMBERSHIP_STORE, 0 }, |
2120 | |||
2121 | { &client_recv_slave_remove, NULL, | ||
2122 | GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM, 0 }, | ||
2123 | 2142 | ||
2124 | { &client_recv_story_request, NULL, | 2143 | { &client_recv_story_request, NULL, |
2125 | GNUNET_MESSAGE_TYPE_PSYC_STORY_REQUEST, 0 }, | 2144 | GNUNET_MESSAGE_TYPE_PSYC_STORY_REQUEST, 0 }, |
diff --git a/src/psyc/psyc.h b/src/psyc/psyc.h index 82800a334..21131e7d3 100644 --- a/src/psyc/psyc.h +++ b/src/psyc/psyc.h | |||
@@ -105,35 +105,22 @@ struct SlaveJoinRequest | |||
105 | }; | 105 | }; |
106 | 106 | ||
107 | 107 | ||
108 | struct ChannelSlaveAddRequest | 108 | struct ChannelMembershipStoreRequest |
109 | { | 109 | { |
110 | /** | 110 | /** |
111 | * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD | 111 | * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_MEMBERSHIP_STORE |
112 | */ | 112 | */ |
113 | struct GNUNET_MessageHeader header; | 113 | struct GNUNET_MessageHeader header; |
114 | 114 | ||
115 | uint32_t reserved; | 115 | uint32_t reserved; |
116 | 116 | ||
117 | struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key; | 117 | struct GNUNET_CRYPTO_EcdsaPublicKey slave_key; |
118 | 118 | ||
119 | uint64_t announced_at; | 119 | uint64_t announced_at; |
120 | 120 | ||
121 | uint64_t effective_since; | 121 | uint64_t effective_since; |
122 | }; | ||
123 | |||
124 | 122 | ||
125 | struct ChannelSlaveRemoveRequest | 123 | uint8_t did_join; |
126 | { | ||
127 | /** | ||
128 | * Type: GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM | ||
129 | */ | ||
130 | struct GNUNET_MessageHeader header; | ||
131 | |||
132 | uint32_t reserved; | ||
133 | |||
134 | struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key; | ||
135 | |||
136 | uint64_t announced_at; | ||
137 | }; | 124 | }; |
138 | 125 | ||
139 | 126 | ||
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c index a43b1ef5f..ca25b1b01 100644 --- a/src/psyc/psyc_api.c +++ b/src/psyc/psyc_api.c | |||
@@ -810,12 +810,14 @@ GNUNET_PSYC_channel_slave_add (struct GNUNET_PSYC_Channel *chn, | |||
810 | uint64_t announced_at, | 810 | uint64_t announced_at, |
811 | uint64_t effective_since) | 811 | uint64_t effective_since) |
812 | { | 812 | { |
813 | struct ChannelSlaveAddRequest *add = GNUNET_malloc (sizeof (*add)); | 813 | struct ChannelMembershipStoreRequest *req = GNUNET_malloc (sizeof (*req)); |
814 | add->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD); | 814 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_MEMBERSHIP_STORE); |
815 | add->header.size = htons (sizeof (*add)); | 815 | req->header.size = htons (sizeof (*req)); |
816 | add->announced_at = GNUNET_htonll (announced_at); | 816 | req->slave_key = *slave_key; |
817 | add->effective_since = GNUNET_htonll (effective_since); | 817 | req->announced_at = GNUNET_htonll (announced_at); |
818 | GNUNET_CLIENT_MANAGER_transmit (chn->client, &add->header); | 818 | req->effective_since = GNUNET_htonll (effective_since); |
819 | req->did_join = GNUNET_YES; | ||
820 | GNUNET_CLIENT_MANAGER_transmit (chn->client, &req->header); | ||
819 | } | 821 | } |
820 | 822 | ||
821 | 823 | ||
@@ -845,11 +847,13 @@ GNUNET_PSYC_channel_slave_remove (struct GNUNET_PSYC_Channel *chn, | |||
845 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 847 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
846 | uint64_t announced_at) | 848 | uint64_t announced_at) |
847 | { | 849 | { |
848 | struct ChannelSlaveRemoveRequest *rm = GNUNET_malloc (sizeof (*rm)); | 850 | struct ChannelMembershipStoreRequest *req = GNUNET_malloc (sizeof (*req)); |
849 | rm->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM); | 851 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_MEMBERSHIP_STORE); |
850 | rm->header.size = htons (sizeof (*rm)); | 852 | req->header.size = htons (sizeof (*req)); |
851 | rm->announced_at = GNUNET_htonll (announced_at); | 853 | req->slave_key = *slave_key; |
852 | GNUNET_CLIENT_MANAGER_transmit (chn->client, &rm->header); | 854 | req->announced_at = GNUNET_htonll (announced_at); |
855 | req->did_join = GNUNET_NO; | ||
856 | GNUNET_CLIENT_MANAGER_transmit (chn->client, &req->header); | ||
853 | } | 857 | } |
854 | 858 | ||
855 | 859 | ||
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c index da69f40b1..5eadef62c 100644 --- a/src/psyc/test_psyc.c +++ b/src/psyc/test_psyc.c | |||
@@ -413,20 +413,8 @@ slave_join (); | |||
413 | 413 | ||
414 | 414 | ||
415 | void | 415 | void |
416 | join_decision_cb (void *cls, | 416 | slave_transmit () |
417 | const struct GNUNET_PSYC_JoinDecisionMessage *dcsn, | ||
418 | int is_admitted, | ||
419 | const struct GNUNET_PSYC_Message *join_msg) | ||
420 | { | 417 | { |
421 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
422 | "Slave got join decision: %d\n", is_admitted); | ||
423 | |||
424 | if (GNUNET_YES != is_admitted) | ||
425 | { /* First join request is refused, retry. */ | ||
426 | GNUNET_assert (1 == join_req_count); | ||
427 | slave_join (); | ||
428 | return; | ||
429 | } | ||
430 | 418 | ||
431 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Slave sending request to master.\n"); | 419 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Slave sending request to master.\n"); |
432 | 420 | ||
@@ -450,6 +438,26 @@ join_decision_cb (void *cls, | |||
450 | 438 | ||
451 | 439 | ||
452 | void | 440 | void |
441 | join_decision_cb (void *cls, | ||
442 | const struct GNUNET_PSYC_JoinDecisionMessage *dcsn, | ||
443 | int is_admitted, | ||
444 | const struct GNUNET_PSYC_Message *join_msg) | ||
445 | { | ||
446 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
447 | "Slave got join decision: %d\n", is_admitted); | ||
448 | |||
449 | if (GNUNET_YES != is_admitted) | ||
450 | { /* First join request is refused, retry. */ | ||
451 | GNUNET_assert (1 == join_req_count); | ||
452 | slave_join (); | ||
453 | return; | ||
454 | } | ||
455 | |||
456 | slave_transmit (); | ||
457 | } | ||
458 | |||
459 | |||
460 | void | ||
453 | join_request_cb (void *cls, | 461 | join_request_cb (void *cls, |
454 | const struct GNUNET_PSYC_JoinRequestMessage *req, | 462 | const struct GNUNET_PSYC_JoinRequestMessage *req, |
455 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 463 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
@@ -465,6 +473,11 @@ join_request_cb (void *cls, | |||
465 | /* Reject first request */ | 473 | /* Reject first request */ |
466 | int is_admitted = (0 < join_req_count++) ? GNUNET_YES : GNUNET_NO; | 474 | int is_admitted = (0 < join_req_count++) ? GNUNET_YES : GNUNET_NO; |
467 | GNUNET_PSYC_join_decision (jh, is_admitted, 0, NULL, NULL); | 475 | GNUNET_PSYC_join_decision (jh, is_admitted, 0, NULL, NULL); |
476 | |||
477 | /* Membership store */ | ||
478 | struct GNUNET_PSYC_Channel *chn = GNUNET_PSYC_master_get_channel (mst); | ||
479 | GNUNET_PSYC_channel_slave_add (chn, slave_key, 2, 2); | ||
480 | GNUNET_PSYC_channel_slave_remove (chn, &slave_pub_key, 2); | ||
468 | } | 481 | } |
469 | 482 | ||
470 | 483 | ||