aboutsummaryrefslogtreecommitdiff
path: root/src/zklaim/zklaim_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zklaim/zklaim_api.c')
-rw-r--r--src/zklaim/zklaim_api.c154
1 files changed, 127 insertions, 27 deletions
diff --git a/src/zklaim/zklaim_api.c b/src/zklaim/zklaim_api.c
index f54ede342..73998925b 100644
--- a/src/zklaim/zklaim_api.c
+++ b/src/zklaim/zklaim_api.c
@@ -28,36 +28,10 @@
28#include "gnunet_zklaim_service.h" 28#include "gnunet_zklaim_service.h"
29#include "zklaim/zklaim.h" 29#include "zklaim/zklaim.h"
30#include "zklaim_api.h" 30#include "zklaim_api.h"
31#include "zklaim_functions.h"
31 32
32#define LOG(kind,...) GNUNET_log_from (kind, "zklaim-api",__VA_ARGS__) 33#define LOG(kind,...) GNUNET_log_from (kind, "zklaim-api",__VA_ARGS__)
33 34
34/**
35 * Handle for an ego.
36 */
37struct GNUNET_ZKLAIM_Context
38{
39 /**
40 * ZKlaim context.
41 */
42 struct zklaim_ctx *zk_ctx;
43
44 /**
45 * Current name associated with this context.
46 */
47 char *name;
48
49 /**
50 * Attributes associated with context
51 */
52 char *attrs;
53
54 /**
55 * Client context associated with this ego.
56 */
57 void *ctx;
58
59};
60
61 35
62/** 36/**
63 * Handle for an operation with the service. 37 * Handle for an operation with the service.
@@ -93,6 +67,11 @@ struct GNUNET_ZKLAIM_Operation
93 GNUNET_ZKLAIM_ContinuationWithStatus cont; 67 GNUNET_ZKLAIM_ContinuationWithStatus cont;
94 68
95 /** 69 /**
70 * Context result
71 */
72 GNUNET_ZKLAIM_ContextResult ctx_cont;
73
74 /**
96 * Closure for @e cont or @e cb. 75 * Closure for @e cont or @e cb.
97 */ 76 */
98 void *cls; 77 void *cls;
@@ -273,6 +252,67 @@ handle_zklaim_result_code (void *cls,
273 GNUNET_free (op); 252 GNUNET_free (op);
274} 253}
275 254
255/**
256 * We received a result code from the service. Check the message
257 * is well-formed.
258 *
259 * @param cls closure
260 * @param rcm result message received
261 * @return #GNUNET_OK if the message is well-formed
262 */
263static int
264check_zklaim_result_ctx (void *cls,
265 const struct ContextMessage *cm)
266{
267 //TODO check for data sanity
268 return GNUNET_OK;
269}
270
271
272/**
273 * We received a context result from the service.
274 *
275 * @param cls closure
276 * @param rcm result message received
277 */
278static void
279handle_zklaim_result_ctx (void *cls,
280 const struct ContextMessage *cm)
281{
282 struct GNUNET_ZKLAIM_Handle *h = cls;
283 struct GNUNET_ZKLAIM_Operation *op;
284 struct GNUNET_ZKLAIM_Context ctx;
285 uint16_t ctx_len = ntohs (cm->ctx_len);
286
287 op = h->op_head;
288 if (NULL == op)
289 {
290 GNUNET_break (0);
291 reschedule_connect (h);
292 return;
293 }
294 GNUNET_CONTAINER_DLL_remove (h->op_head,
295 h->op_tail,
296 op);
297 ctx.attrs = (char*)&cm[1];
298 ctx.ctx = zklaim_context_new ();
299 zklaim_ctx_deserialize (ctx.ctx,
300 (unsigned char *) &cm[1]+ strlen (ctx.attrs) + 1,
301 ctx_len);
302 if (NULL != op->ctx_cont)
303 {
304 if (0 > ctx_len)
305 op->ctx_cont (op->cls,
306 &ctx);
307 else
308 op->ctx_cont (op->cls,
309 &ctx);
310 }
311 zklaim_ctx_free (ctx.ctx);
312 GNUNET_free (op);
313}
314
315
276 316
277/** 317/**
278 * Try again to connect to the zklaim service. 318 * Try again to connect to the zklaim service.
@@ -288,6 +328,10 @@ reconnect (void *cls)
288 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CODE, 328 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CODE,
289 struct ResultCodeMessage, 329 struct ResultCodeMessage,
290 h), 330 h),
331 GNUNET_MQ_hd_var_size (zklaim_result_ctx,
332 GNUNET_MESSAGE_TYPE_ZKLAIM_RESULT_CTX,
333 struct ContextMessage,
334 h),
291 GNUNET_MQ_handler_end () 335 GNUNET_MQ_handler_end ()
292 }; 336 };
293 337
@@ -430,4 +474,60 @@ GNUNET_ZKLAIM_disconnect (struct GNUNET_ZKLAIM_Handle *h)
430 GNUNET_free (h); 474 GNUNET_free (h);
431} 475}
432 476
477/**
478 * Lookup context
479 */
480struct GNUNET_ZKLAIM_Operation*
481GNUNET_ZKLAIM_lookup_context (struct GNUNET_ZKLAIM_Handle *h,
482 const char *name,
483 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
484 GNUNET_ZKLAIM_ContextResult cont,
485 void* cont_cls)
486{
487 struct GNUNET_ZKLAIM_Operation *op;
488 struct GNUNET_MQ_Envelope *env;
489 struct LookupMessage *lm;
490 size_t slen;
491
492 if (NULL == h->mq)
493 return NULL;
494 slen = strlen (name) + 1;
495 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct LookupMessage))
496 {
497 GNUNET_break (0);
498 return NULL;
499 }
500 op = GNUNET_new (struct GNUNET_ZKLAIM_Operation);
501 op->h = h;
502 op->ctx_cont = cont;
503 op->cls = cont_cls;
504 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
505 h->op_tail,
506 op);
507 env = GNUNET_MQ_msg_extra (lm,
508 slen,
509 GNUNET_MESSAGE_TYPE_ZKLAIM_CREATE);
510 lm->name_len = htons (slen);
511 lm->reserved = htons (0);
512 lm->private_key = *key;
513 GNUNET_memcpy (&lm[1],
514 name,
515 slen);
516 GNUNET_MQ_send (h->mq,
517 env);
518 return op;
519}
520
521void
522GNUNET_ZKLAIM_issue_from_context (struct GNUNET_ZKLAIM_Context *ctx,
523 struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
524 GNUNET_ZKLAIM_PayloadIterator iter,
525 void* iter_cls)
526{
527 ZKLAIM_context_issue (ctx,
528 key,
529 iter,
530 iter_cls);
531}
532
433/* end of zklaim_api.c */ 533/* end of zklaim_api.c */