aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-02-24 09:40:02 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-02-24 09:40:02 +0000
commit43fd556485065c1e662f852bcc789bbbe95e0a9a (patch)
tree915f2f4dbe7418011567a8fb1acc680e40782d93 /src
parent4bf097a83030f69bffba531214bb71f351470518 (diff)
downloadgnunet-43fd556485065c1e662f852bcc789bbbe95e0a9a.tar.gz
gnunet-43fd556485065c1e662f852bcc789bbbe95e0a9a.zip
- operation id for api
Diffstat (limited to 'src')
-rw-r--r--src/namestore/namestore_api.c69
-rw-r--r--src/namestore/test_namestore_api.c5
2 files changed, 70 insertions, 4 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index e8547574a..ff3ae0dd1 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -40,6 +40,11 @@
40 */ 40 */
41struct GNUNET_NAMESTORE_QueueEntry 41struct GNUNET_NAMESTORE_QueueEntry
42{ 42{
43 struct GNUNET_NAMESTORE_QueueEntry *next;
44 struct GNUNET_NAMESTORE_QueueEntry *prev;
45
46 uint64_t op_id;
47
43 char *data; /*stub data pointer*/ 48 char *data; /*stub data pointer*/
44}; 49};
45 50
@@ -110,6 +115,16 @@ struct GNUNET_NAMESTORE_Handle
110 * Should we reconnect to service due to some serious error? 115 * Should we reconnect to service due to some serious error?
111 */ 116 */
112 int reconnect; 117 int reconnect;
118
119
120 /**
121 * Pending namestore operations
122 */
123
124 struct GNUNET_NAMESTORE_QueueEntry * op_head;
125 struct GNUNET_NAMESTORE_QueueEntry * op_tail;
126
127 uint64_t op_id;
113}; 128};
114 129
115struct GNUNET_NAMESTORE_SimpleRecord 130struct GNUNET_NAMESTORE_SimpleRecord
@@ -153,8 +168,10 @@ static void
153process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg) 168process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg)
154{ 169{
155 struct GNUNET_NAMESTORE_Handle *nsh = cls; 170 struct GNUNET_NAMESTORE_Handle *nsh = cls;
171 struct GNUNET_NAMESTORE_QueueEntry *qe;
156 uint16_t size; 172 uint16_t size;
157 uint16_t type; 173 uint16_t type;
174 uint64_t op_id = UINT64_MAX;
158 175
159 if (NULL == msg) 176 if (NULL == msg)
160 { 177 {
@@ -165,6 +182,27 @@ process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg)
165 size = ntohs (msg->size); 182 size = ntohs (msg->size);
166 type = ntohs (msg->type); 183 type = ntohs (msg->type);
167 184
185 /* find matching operation */
186 if (op_id > nsh->op_id)
187 {
188 GNUNET_break_op (0);
189 GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
190 GNUNET_TIME_UNIT_FOREVER_REL);
191 return;
192 }
193 for (qe = nsh->op_head; qe != NULL; qe = qe->next)
194 {
195 if (qe->op_id == op_id)
196 break;
197 }
198 if (qe == NULL)
199 {
200 GNUNET_break_op (0);
201 GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
202 GNUNET_TIME_UNIT_FOREVER_REL);
203 return;
204 }
205
168 switch (type) { 206 switch (type) {
169 case GNUNET_MESSAGE_TYPE_TEST: 207 case GNUNET_MESSAGE_TYPE_TEST:
170 /* handle message here */ 208 /* handle message here */
@@ -318,7 +356,13 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *nsh)
318 nsh); 356 nsh);
319} 357}
320 358
321 359static void
360enqeue_namestore_operation (struct GNUNET_NAMESTORE_Handle *nsh, struct GNUNET_NAMESTORE_QueueEntry *qe)
361{
362 qe->op_id = nsh->op_id;
363 nsh->op_id ++;
364 GNUNET_CONTAINER_DLL_insert(nsh->op_head, nsh->op_tail, qe);
365}
322 366
323/** 367/**
324 * Initialize the connection with the NAMESTORE service. 368 * Initialize the connection with the NAMESTORE service.
@@ -334,10 +378,10 @@ GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
334 nsh = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Handle)); 378 nsh = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Handle));
335 nsh->cfg = cfg; 379 nsh->cfg = cfg;
336 nsh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect_task, nsh); 380 nsh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect_task, nsh);
381 nsh->op_id = 0;
337 return nsh; 382 return nsh;
338} 383}
339 384
340
341/** 385/**
342 * Shutdown connection with the NAMESTORE service. 386 * Shutdown connection with the NAMESTORE service.
343 * 387 *
@@ -347,12 +391,20 @@ void
347GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *nsh, int drop) 391GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *nsh, int drop)
348{ 392{
349 struct PendingMessage *p; 393 struct PendingMessage *p;
394 struct GNUNET_NAMESTORE_QueueEntry *q;
350 395
351 while (NULL != (p = nsh->pending_head)) 396 while (NULL != (p = nsh->pending_head))
352 { 397 {
353 GNUNET_CONTAINER_DLL_remove (nsh->pending_head, nsh->pending_tail, p); 398 GNUNET_CONTAINER_DLL_remove (nsh->pending_head, nsh->pending_tail, p);
354 GNUNET_free (p); 399 GNUNET_free (p);
355 } 400 }
401
402 while (NULL != (q = nsh->op_head))
403 {
404 GNUNET_CONTAINER_DLL_remove (nsh->op_head, nsh->op_tail, q);
405 GNUNET_free (q);
406 }
407
356 if (NULL != nsh->client) 408 if (NULL != nsh->client)
357 { 409 {
358 GNUNET_CLIENT_disconnect (nsh->client, GNUNET_NO); 410 GNUNET_CLIENT_disconnect (nsh->client, GNUNET_NO);
@@ -398,7 +450,19 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
398 void *cont_cls) 450 void *cont_cls)
399{ 451{
400 struct GNUNET_NAMESTORE_QueueEntry *qe; 452 struct GNUNET_NAMESTORE_QueueEntry *qe;
453 struct PendingMessage *pe;
454 size_t msg_size = 0;
401 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 455 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
456 enqeue_namestore_operation(h, qe);
457
458 /* set msg_size*/
459 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
460
461 /* create msg here */
462
463 GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe);
464 do_transmit(h);
465
402#if 0 466#if 0
403 struct GNUNET_NAMESTORE_SimpleRecord *sr; 467 struct GNUNET_NAMESTORE_SimpleRecord *sr;
404 sr = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_SimpleRecord)); 468 sr = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_SimpleRecord));
@@ -526,6 +590,7 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
526{ 590{
527 struct GNUNET_NAMESTORE_QueueEntry *qe; 591 struct GNUNET_NAMESTORE_QueueEntry *qe;
528 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 592 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
593
529#if 0 594#if 0
530 struct GNUNET_NAMESTORE_SimpleRecord *iter; 595 struct GNUNET_NAMESTORE_SimpleRecord *iter;
531 for (iter=h->records_head; iter != NULL; iter=iter->next) 596 for (iter=h->records_head; iter != NULL; iter=iter->next)
diff --git a/src/namestore/test_namestore_api.c b/src/namestore/test_namestore_api.c
index 65223929a..765dbec65 100644
--- a/src/namestore/test_namestore_api.c
+++ b/src/namestore/test_namestore_api.c
@@ -82,7 +82,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
82 res = 1; 82 res = 1;
83} 83}
84 84
85 85/*
86static void 86static void
87end (void) 87end (void)
88{ 88{
@@ -102,6 +102,7 @@ end (void)
102 102
103 res = 0; 103 res = 0;
104} 104}
105*/
105 106
106 107
107static void 108static void
@@ -116,7 +117,7 @@ run (void *cls, char *const *args, const char *cfgfile,
116 nsh = GNUNET_NAMESTORE_connect (cfg); 117 nsh = GNUNET_NAMESTORE_connect (cfg);
117 GNUNET_break (NULL != nsh); 118 GNUNET_break (NULL != nsh);
118 119
119 GNUNET_NAMESTORE_lookup_name (nsh, NULL, NULL, 0, NULL, NULL); 120 //GNUNET_NAMESTORE_lookup_name (nsh, NULL, NULL, 0, NULL, NULL);
120 121
121 //stop_arm (); 122 //stop_arm ();
122 //end (); 123 //end ();