aboutsummaryrefslogtreecommitdiff
path: root/src/zklaim/gnunet-service-zklaim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zklaim/gnunet-service-zklaim.c')
-rw-r--r--src/zklaim/gnunet-service-zklaim.c202
1 files changed, 187 insertions, 15 deletions
diff --git a/src/zklaim/gnunet-service-zklaim.c b/src/zklaim/gnunet-service-zklaim.c
index 91e70fc99..100a87f07 100644
--- a/src/zklaim/gnunet-service-zklaim.c
+++ b/src/zklaim/gnunet-service-zklaim.c
@@ -78,6 +78,17 @@ struct ZkClient
78 */ 78 */
79 struct CreateContextHandle *create_op_tail; 79 struct CreateContextHandle *create_op_tail;
80 80
81 /**
82 * Head of DLL of context issue ops
83 */
84 struct LookupHandle *lookup_op_head;
85
86 /**
87 * Tail of DLL of attribute store ops
88 */
89 struct LookupHandle *lookup_op_tail;
90
91
81}; 92};
82 93
83struct CreateContextHandle 94struct CreateContextHandle
@@ -124,6 +135,46 @@ struct CreateContextHandle
124 135
125}; 136};
126 137
138struct LookupHandle
139{
140 /**
141 * DLL
142 */
143 struct LookupHandle *next;
144
145 /**
146 * DLL
147 */
148 struct LookupHandle *prev;
149
150 /**
151 * Client connection
152 */
153 struct ZkClient *client;
154
155 /**
156 * Issuer private key
157 */
158 struct GNUNET_CRYPTO_EcdsaPrivateKey private_key;
159
160 /**
161 * Issuer public key
162 */
163 struct GNUNET_CRYPTO_EcdsaPublicKey public_key;
164
165 /**
166 * QueueEntry
167 */
168 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
169
170 /**
171 * The context name
172 */
173 char *name;
174
175};
176
177
127/** 178/**
128 * Cleanup task 179 * Cleanup task
129 */ 180 */
@@ -169,8 +220,9 @@ cleanup_create_handle (struct CreateContextHandle *handle)
169{ 220{
170 if (NULL != handle->ns_qe) 221 if (NULL != handle->ns_qe)
171 GNUNET_NAMESTORE_cancel (handle->ns_qe); 222 GNUNET_NAMESTORE_cancel (handle->ns_qe);
172 if (NULL != handle->name) 223 GNUNET_free_non_null (handle->name);
173 GNUNET_free (handle->name); 224 GNUNET_free_non_null (handle->name);
225 GNUNET_free_non_null (handle->attrs);
174 GNUNET_free (handle); 226 GNUNET_free (handle);
175} 227}
176 228
@@ -190,7 +242,9 @@ send_result (int32_t status,
190 GNUNET_MQ_send (cch->client->mq, 242 GNUNET_MQ_send (cch->client->mq,
191 env); 243 env);
192 cleanup_create_handle (cch); 244 cleanup_create_handle (cch);
193 245 GNUNET_CONTAINER_DLL_remove (cch->client->create_op_head,
246 cch->client->create_op_tail,
247 cch);
194} 248}
195 249
196static void 250static void
@@ -201,15 +255,10 @@ context_store_cont (void *cls,
201 struct CreateContextHandle *cch = cls; 255 struct CreateContextHandle *cch = cls;
202 256
203 cch->ns_qe = NULL; 257 cch->ns_qe = NULL;
204 GNUNET_CONTAINER_DLL_remove (cch->client->create_op_head,
205 cch->client->create_op_tail,
206 cch);
207
208 if (GNUNET_SYSERR == success) 258 if (GNUNET_SYSERR == success)
209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
210 "Failed to create context %s\n", 260 "Failed to create context %s\n",
211 emsg); 261 emsg);
212
213 send_result (success, cch); 262 send_result (success, cch);
214} 263}
215 264
@@ -297,7 +346,7 @@ handle_create_context_message (void *cls,
297 { 346 {
298 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 347 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
299 "Trusted Setup failed.\n"); 348 "Trusted Setup failed.\n");
300 send_result(GNUNET_SYSERR, cch); 349 send_result (GNUNET_SYSERR, cch);
301 zklaim_ctx_free (ctx); 350 zklaim_ctx_free (ctx);
302 return; 351 return;
303 } 352 }
@@ -317,16 +366,135 @@ handle_create_context_message (void *cls,
317 ctx_record.record_type = GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX; 366 ctx_record.record_type = GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX;
318 ctx_record.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 367 ctx_record.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
319 cch->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle, 368 cch->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle,
320 &cch->private_key, 369 &cch->private_key,
321 cch->name, 370 cch->name,
322 1, 371 1,
323 &ctx_record, 372 &ctx_record,
324 &context_store_cont, 373 &context_store_cont,
325 cch); 374 cch);
326 GNUNET_free (rdata); 375 GNUNET_free (rdata);
327 GNUNET_free (data); 376 GNUNET_free (data);
328} 377}
329 378
379/**
380 * Cleanup attribute store handle
381 *
382 * @param handle handle to clean up
383 */
384static void
385cleanup_lookup_handle (struct LookupHandle *handle)
386{
387 if (NULL != handle->ns_qe)
388 GNUNET_NAMESTORE_cancel (handle->ns_qe);
389 GNUNET_free_non_null (handle->name);
390 GNUNET_free (handle);
391}
392
393
394static void
395send_ctx_result (struct LookupHandle *lh,
396 const char* ctx,
397 size_t len)
398{
399 struct GNUNET_MQ_Envelope *env;
400 struct ContextMessage *r_msg;
401
402
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 "Sending RESULT_CODE message\n");
405 env = GNUNET_MQ_msg_extra (r_msg,
406 len,
407 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CTX);
408 r_msg->ctx_len = htonl (len);
409 memcpy ((char*)&r_msg[1],
410 ctx,
411 len);
412 GNUNET_MQ_send (lh->client->mq,
413 env);
414 cleanup_lookup_handle (lh);
415 GNUNET_CONTAINER_DLL_remove (lh->client->lookup_op_head,
416 lh->client->lookup_op_tail,
417 lh);
418}
419
420
421static void
422ctx_not_found_cb (void* cls)
423{
424 struct LookupHandle *lh = cls;
425
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
427 "Context %s not found!\n",
428 lh->name);
429
430 send_ctx_result (lh, NULL, 0);
431}
432
433
434static void
435ctx_found_cb (void *cls,
436 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
437 const char *label,
438 unsigned int rd_count,
439 const struct GNUNET_GNSRECORD_Data *rd)
440{
441 struct LookupHandle *lh = cls;
442
443 send_ctx_result (lh, (char*) rd->data, rd->data_size);
444}
445
446
447
448static int
449check_lookup_message(void *cls,
450 const struct LookupMessage *lm)
451{
452 uint16_t size;
453
454 size = ntohs (lm->header.size);
455 if (size <= sizeof (struct LookupMessage))
456 {
457 GNUNET_break (0);
458 return GNUNET_SYSERR;
459 }
460 return GNUNET_OK;
461}
462
463
464static void
465handle_lookup_message (void *cls,
466 const struct LookupMessage *lm)
467{
468 struct LookupHandle *lh;
469 struct ZkClient *zkc = cls;
470 size_t str_len;
471
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
473 "Received CREATE_REQUEST message\n");
474
475 str_len = ntohs (lm->name_len);
476
477 lh = GNUNET_new (struct LookupHandle);
478 lh->name = GNUNET_strndup ((char*)&lm[1], str_len-1);
479 lh->private_key = lm->private_key;
480 GNUNET_CRYPTO_ecdsa_key_get_public (&lm->private_key,
481 &lh->public_key);
482
483 GNUNET_SERVICE_client_continue (zkc->client);
484 lh->client = zkc;
485 GNUNET_CONTAINER_DLL_insert (zkc->lookup_op_head,
486 zkc->lookup_op_tail,
487 lh);
488
489 lh->ns_qe = GNUNET_NAMESTORE_records_lookup (ns_handle,
490 &lh->private_key,
491 lh->name,
492 &ctx_not_found_cb,
493 lh,
494 &ctx_found_cb,
495 lh);
496}
497
330 498
331 499
332/** 500/**
@@ -431,5 +599,9 @@ GNUNET_SERVICE_MAIN
431 GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE, 599 GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE,
432 struct CreateRequestMessage, 600 struct CreateRequestMessage,
433 NULL), 601 NULL),
602 GNUNET_MQ_hd_var_size (lookup_message,
603 GNUNET_MESSAGE_TYPE_ZKLAIM_LOOKUP_CTX,
604 struct LookupMessage,
605 NULL),
434 GNUNET_MQ_handler_end()); 606 GNUNET_MQ_handler_end());
435/* end of gnunet-service-zklaim.c */ 607/* end of gnunet-service-zklaim.c */