diff options
author | Gabor X Toth <*@tg-x.net> | 2014-07-27 11:35:43 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2014-07-27 11:35:43 +0000 |
commit | 1ac8baae5380d8f83efb31390568b717e871823a (patch) | |
tree | dc363148002cba0f94d9e2c9a6f3b2576bb39793 /src/psycstore/gnunet-service-psycstore.c | |
parent | 0ea6bab62cd1d29e32c5d442d865e1b6bf82bef1 (diff) | |
download | gnunet-1ac8baae5380d8f83efb31390568b717e871823a.tar.gz gnunet-1ac8baae5380d8f83efb31390568b717e871823a.zip |
psycstore: add option to perform membership test when retrieving fragment or message
Diffstat (limited to 'src/psycstore/gnunet-service-psycstore.c')
-rw-r--r-- | src/psycstore/gnunet-service-psycstore.c | 96 |
1 files changed, 86 insertions, 10 deletions
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c index 8a70bb22f..87ace92be 100644 --- a/src/psycstore/gnunet-service-psycstore.c +++ b/src/psycstore/gnunet-service-psycstore.c | |||
@@ -122,11 +122,43 @@ send_result_code (struct GNUNET_SERVER_Client *client, uint32_t result_code, | |||
122 | GNUNET_free (res); | 122 | GNUNET_free (res); |
123 | } | 123 | } |
124 | 124 | ||
125 | enum | ||
126 | { | ||
127 | MEMBERSHIP_TEST_NOT_NEEDED = 0, | ||
128 | MEMBERSHIP_TEST_NEEDED = 1, | ||
129 | MEMBERSHIP_TEST_DONE = 2, | ||
130 | } MessageMembershipTest; | ||
125 | 131 | ||
126 | struct SendClosure | 132 | struct SendClosure |
127 | { | 133 | { |
128 | struct GNUNET_SERVER_Client *client; | 134 | struct GNUNET_SERVER_Client *client; |
135 | |||
136 | /** | ||
137 | * Channel's public key. | ||
138 | */ | ||
139 | struct GNUNET_CRYPTO_EddsaPublicKey channel_key; | ||
140 | |||
141 | /** | ||
142 | * Slave's public key. | ||
143 | */ | ||
144 | struct GNUNET_CRYPTO_EcdsaPublicKey slave_key; | ||
145 | |||
146 | /** | ||
147 | * Operation ID. | ||
148 | */ | ||
129 | uint64_t op_id; | 149 | uint64_t op_id; |
150 | |||
151 | /** | ||
152 | * Membership test result. | ||
153 | */ | ||
154 | int membership_test_result; | ||
155 | |||
156 | /** | ||
157 | * Do membership test with @a slave_key before returning fragment? | ||
158 | * @see enum MessageMembershipTest | ||
159 | */ | ||
160 | uint8_t membership_test; | ||
161 | |||
130 | }; | 162 | }; |
131 | 163 | ||
132 | 164 | ||
@@ -136,6 +168,24 @@ send_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg, | |||
136 | { | 168 | { |
137 | struct SendClosure *sc = cls; | 169 | struct SendClosure *sc = cls; |
138 | struct FragmentResult *res; | 170 | struct FragmentResult *res; |
171 | |||
172 | if (MEMBERSHIP_TEST_NEEDED == sc->membership_test) | ||
173 | { | ||
174 | sc->membership_test = MEMBERSHIP_TEST_DONE; | ||
175 | sc->membership_test_result | ||
176 | = db->membership_test (db->cls, &sc->channel_key, &sc->slave_key, | ||
177 | GNUNET_ntohll (msg->message_id)); | ||
178 | switch (sc->membership_test_result) | ||
179 | { | ||
180 | case GNUNET_YES: | ||
181 | break; | ||
182 | |||
183 | case GNUNET_NO: | ||
184 | case GNUNET_SYSERR: | ||
185 | return GNUNET_NO; | ||
186 | } | ||
187 | } | ||
188 | |||
139 | size_t msg_size = ntohs (msg->header.size); | 189 | size_t msg_size = ntohs (msg->header.size); |
140 | 190 | ||
141 | res = GNUNET_malloc (sizeof (struct FragmentResult) + msg_size); | 191 | res = GNUNET_malloc (sizeof (struct FragmentResult) + msg_size); |
@@ -152,7 +202,7 @@ send_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg, | |||
152 | GNUNET_SERVER_notification_context_unicast (nc, sc->client, &res->header, | 202 | GNUNET_SERVER_notification_context_unicast (nc, sc->client, &res->header, |
153 | GNUNET_NO); | 203 | GNUNET_NO); |
154 | GNUNET_free (res); | 204 | GNUNET_free (res); |
155 | return GNUNET_OK; | 205 | return GNUNET_YES; |
156 | } | 206 | } |
157 | 207 | ||
158 | 208 | ||
@@ -255,9 +305,12 @@ handle_fragment_get (void *cls, | |||
255 | struct GNUNET_SERVER_Client *client, | 305 | struct GNUNET_SERVER_Client *client, |
256 | const struct GNUNET_MessageHeader *msg) | 306 | const struct GNUNET_MessageHeader *msg) |
257 | { | 307 | { |
258 | const struct FragmentGetRequest *req | 308 | const struct FragmentGetRequest * |
259 | = (const struct FragmentGetRequest *) msg; | 309 | req = (const struct FragmentGetRequest *) msg; |
260 | struct SendClosure sc = { .op_id = req->op_id, .client = client }; | 310 | struct SendClosure |
311 | sc = { .op_id = req->op_id, .client = client, | ||
312 | .channel_key = req->channel_key, .slave_key = req->slave_key, | ||
313 | .membership_test = req->do_membership_test }; | ||
261 | 314 | ||
262 | int ret = db->fragment_get (db->cls, &req->channel_key, | 315 | int ret = db->fragment_get (db->cls, &req->channel_key, |
263 | GNUNET_ntohll (req->fragment_id), | 316 | GNUNET_ntohll (req->fragment_id), |
@@ -266,6 +319,22 @@ handle_fragment_get (void *cls, | |||
266 | { | 319 | { |
267 | case GNUNET_YES: | 320 | case GNUNET_YES: |
268 | case GNUNET_NO: | 321 | case GNUNET_NO: |
322 | if (MEMBERSHIP_TEST_DONE == sc.membership_test) | ||
323 | { | ||
324 | switch (sc.membership_test_result) | ||
325 | { | ||
326 | case GNUNET_YES: | ||
327 | break; | ||
328 | |||
329 | case GNUNET_NO: | ||
330 | ret = GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED; | ||
331 | break; | ||
332 | |||
333 | case GNUNET_SYSERR: | ||
334 | ret = GNUNET_SYSERR; | ||
335 | break; | ||
336 | } | ||
337 | } | ||
269 | break; | 338 | break; |
270 | default: | 339 | default: |
271 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 340 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -282,8 +351,13 @@ handle_message_get (void *cls, | |||
282 | struct GNUNET_SERVER_Client *client, | 351 | struct GNUNET_SERVER_Client *client, |
283 | const struct GNUNET_MessageHeader *msg) | 352 | const struct GNUNET_MessageHeader *msg) |
284 | { | 353 | { |
285 | const struct MessageGetRequest *req = (const struct MessageGetRequest *) msg; | 354 | const struct MessageGetRequest * |
286 | struct SendClosure sc = { .op_id = req->op_id, .client = client }; | 355 | req = (const struct MessageGetRequest *) msg; |
356 | struct SendClosure | ||
357 | sc = { .op_id = req->op_id, .client = client, | ||
358 | .channel_key = req->channel_key, .slave_key = req->slave_key, | ||
359 | .membership_test = req->do_membership_test }; | ||
360 | |||
287 | uint64_t ret_frags = 0; | 361 | uint64_t ret_frags = 0; |
288 | int64_t ret = db->message_get (db->cls, &req->channel_key, | 362 | int64_t ret = db->message_get (db->cls, &req->channel_key, |
289 | GNUNET_ntohll (req->message_id), | 363 | GNUNET_ntohll (req->message_id), |
@@ -309,10 +383,12 @@ handle_message_get_fragment (void *cls, | |||
309 | struct GNUNET_SERVER_Client *client, | 383 | struct GNUNET_SERVER_Client *client, |
310 | const struct GNUNET_MessageHeader *msg) | 384 | const struct GNUNET_MessageHeader *msg) |
311 | { | 385 | { |
312 | const struct MessageGetFragmentRequest *req = | 386 | const struct MessageGetFragmentRequest * |
313 | (const struct MessageGetFragmentRequest *) msg; | 387 | req = (const struct MessageGetFragmentRequest *) msg; |
314 | 388 | struct SendClosure | |
315 | struct SendClosure sc = { .op_id = req->op_id, .client = client }; | 389 | sc = { .op_id = req->op_id, .client = client, |
390 | .channel_key = req->channel_key, .slave_key = req->slave_key, | ||
391 | .membership_test = req->do_membership_test }; | ||
316 | 392 | ||
317 | int ret = db->message_get_fragment (db->cls, &req->channel_key, | 393 | int ret = db->message_get_fragment (db->cls, &req->channel_key, |
318 | GNUNET_ntohll (req->message_id), | 394 | GNUNET_ntohll (req->message_id), |