diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-24 10:57:17 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-24 10:57:17 +0000 |
commit | e485bea7f1ffc881334748f759ffe8c665131a44 (patch) | |
tree | 8155a7f08fa997270ae680768c1e297e04548e04 /src | |
parent | d95214984656e24aaff69870e400752965a38d09 (diff) | |
download | gnunet-e485bea7f1ffc881334748f759ffe8c665131a44.tar.gz gnunet-e485bea7f1ffc881334748f759ffe8c665131a44.zip |
- changes
Diffstat (limited to 'src')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 82 | ||||
-rw-r--r-- | src/namestore/namestore_api.c | 87 |
2 files changed, 153 insertions, 16 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 59126ba6a..000243e34 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -30,6 +30,38 @@ | |||
30 | #include "gnunet_namestore_plugin.h" | 30 | #include "gnunet_namestore_plugin.h" |
31 | #include "namestore.h" | 31 | #include "namestore.h" |
32 | 32 | ||
33 | |||
34 | |||
35 | /** | ||
36 | * A namestore operation. | ||
37 | */ | ||
38 | struct GNUNET_NAMESTORE_Operation | ||
39 | { | ||
40 | struct GNUNET_NAMESTORE_Operation *next; | ||
41 | struct GNUNET_NAMESTORE_Operation *prev; | ||
42 | |||
43 | uint64_t op_id; | ||
44 | |||
45 | char *data; /*stub data pointer*/ | ||
46 | }; | ||
47 | |||
48 | |||
49 | /** | ||
50 | * A namestore client | ||
51 | */ | ||
52 | struct GNUNET_NAMESTORE_Client | ||
53 | { | ||
54 | struct GNUNET_NAMESTORE_Client *next; | ||
55 | struct GNUNET_NAMESTORE_Client *prev; | ||
56 | |||
57 | struct GNUNET_SERVER_Client * client; | ||
58 | |||
59 | struct GNUNET_NAMESTORE_Operation *op_head; | ||
60 | struct GNUNET_NAMESTORE_Operation *op_tail; | ||
61 | }; | ||
62 | |||
63 | |||
64 | |||
33 | /** | 65 | /** |
34 | * Configuration handle. | 66 | * Configuration handle. |
35 | */ | 67 | */ |
@@ -39,6 +71,10 @@ static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; | |||
39 | 71 | ||
40 | static char *db_lib_name; | 72 | static char *db_lib_name; |
41 | 73 | ||
74 | static struct GNUNET_NAMESTORE_Client *client_head; | ||
75 | static struct GNUNET_NAMESTORE_Client *client_tail; | ||
76 | |||
77 | |||
42 | /** | 78 | /** |
43 | * Task run during shutdown. | 79 | * Task run during shutdown. |
44 | * | 80 | * |
@@ -50,6 +86,21 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
50 | { | 86 | { |
51 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); | 87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); |
52 | 88 | ||
89 | struct GNUNET_NAMESTORE_Operation * no; | ||
90 | struct GNUNET_NAMESTORE_Client * nc; | ||
91 | |||
92 | for (nc = client_head; nc != NULL; nc = nc->next) | ||
93 | { | ||
94 | for (no = nc->op_head; no != NULL; no = no->next) | ||
95 | { | ||
96 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); | ||
97 | GNUNET_free (no); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); | ||
102 | GNUNET_free (nc); | ||
103 | |||
53 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); | 104 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); |
54 | GNUNET_free (db_lib_name); | 105 | GNUNET_free (db_lib_name); |
55 | } | 106 | } |
@@ -64,8 +115,29 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
64 | static void | 115 | static void |
65 | client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client) | 116 | client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client) |
66 | { | 117 | { |
67 | if (NULL != client) | 118 | struct GNUNET_NAMESTORE_Operation * no; |
68 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client); | 119 | struct GNUNET_NAMESTORE_Client * nc; |
120 | if (NULL == client) | ||
121 | return; | ||
122 | |||
123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client); | ||
124 | |||
125 | for (nc = client_head; nc != NULL; nc = nc->next) | ||
126 | { | ||
127 | if (client == nc->client) | ||
128 | break; | ||
129 | } | ||
130 | if (NULL == client) | ||
131 | return; | ||
132 | |||
133 | for (no = nc->op_head; no != NULL; no = no->next) | ||
134 | { | ||
135 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); | ||
136 | GNUNET_free (no); | ||
137 | } | ||
138 | |||
139 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); | ||
140 | GNUNET_free (nc); | ||
69 | } | 141 | } |
70 | 142 | ||
71 | static void handle_start (void *cls, | 143 | static void handle_start (void *cls, |
@@ -73,6 +145,12 @@ static void handle_start (void *cls, | |||
73 | const struct GNUNET_MessageHeader * message) | 145 | const struct GNUNET_MessageHeader * message) |
74 | { | 146 | { |
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n"); | 147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n"); |
148 | |||
149 | struct GNUNET_NAMESTORE_Client * nc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Client)); | ||
150 | nc->client = client; | ||
151 | |||
152 | GNUNET_CONTAINER_DLL_insert(client_head, client_tail, nc); | ||
153 | |||
76 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 154 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
77 | } | 155 | } |
78 | 156 | ||
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index ff3ae0dd1..af39a834c 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -45,6 +45,12 @@ struct GNUNET_NAMESTORE_QueueEntry | |||
45 | 45 | ||
46 | uint64_t op_id; | 46 | uint64_t op_id; |
47 | 47 | ||
48 | GNUNET_NAMESTORE_ContinuationWithStatus cont; | ||
49 | void *cont_cls; | ||
50 | |||
51 | GNUNET_NAMESTORE_RecordProcessor proc; | ||
52 | void *proc_cls; | ||
53 | |||
48 | char *data; /*stub data pointer*/ | 54 | char *data; /*stub data pointer*/ |
49 | }; | 55 | }; |
50 | 56 | ||
@@ -452,7 +458,12 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
452 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 458 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
453 | struct PendingMessage *pe; | 459 | struct PendingMessage *pe; |
454 | size_t msg_size = 0; | 460 | size_t msg_size = 0; |
461 | |||
462 | GNUNET_assert (NULL != h); | ||
463 | |||
455 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | 464 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); |
465 | qe->cont = cont; | ||
466 | qe->cont_cls = cont_cls; | ||
456 | enqeue_namestore_operation(h, qe); | 467 | enqeue_namestore_operation(h, qe); |
457 | 468 | ||
458 | /* set msg_size*/ | 469 | /* set msg_size*/ |
@@ -520,7 +531,25 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h, | |||
520 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | 531 | GNUNET_NAMESTORE_ContinuationWithStatus cont, |
521 | void *cont_cls) | 532 | void *cont_cls) |
522 | { | 533 | { |
523 | return NULL; | 534 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
535 | struct PendingMessage *pe; | ||
536 | size_t msg_size = 0; | ||
537 | |||
538 | GNUNET_assert (NULL != h); | ||
539 | |||
540 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | ||
541 | qe->cont = cont; | ||
542 | qe->cont_cls = cont_cls; | ||
543 | enqeue_namestore_operation(h, qe); | ||
544 | |||
545 | /* set msg_size*/ | ||
546 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | ||
547 | |||
548 | /* create msg here */ | ||
549 | |||
550 | GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe); | ||
551 | do_transmit(h); | ||
552 | return qe; | ||
524 | } | 553 | } |
525 | 554 | ||
526 | 555 | ||
@@ -548,7 +577,24 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h, | |||
548 | void *cont_cls) | 577 | void *cont_cls) |
549 | { | 578 | { |
550 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 579 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
580 | struct PendingMessage *pe; | ||
581 | size_t msg_size = 0; | ||
582 | |||
583 | GNUNET_assert (NULL != h); | ||
584 | |||
551 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | 585 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); |
586 | qe->cont = cont; | ||
587 | qe->cont_cls = cont_cls; | ||
588 | enqeue_namestore_operation(h, qe); | ||
589 | |||
590 | /* set msg_size*/ | ||
591 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | ||
592 | |||
593 | /* create msg here */ | ||
594 | |||
595 | GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe); | ||
596 | do_transmit(h); | ||
597 | |||
552 | #if 0 | 598 | #if 0 |
553 | struct GNUNET_NAMESTORE_SimpleRecord *iter; | 599 | struct GNUNET_NAMESTORE_SimpleRecord *iter; |
554 | for (iter=h->records_head; iter != NULL; iter=iter->next) | 600 | for (iter=h->records_head; iter != NULL; iter=iter->next) |
@@ -589,7 +635,33 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, | |||
589 | GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls) | 635 | GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls) |
590 | { | 636 | { |
591 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 637 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
638 | struct PendingMessage *pe; | ||
639 | size_t msg_size = 0; | ||
640 | |||
641 | GNUNET_assert (NULL != h); | ||
642 | |||
592 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | 643 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); |
644 | qe->proc = proc; | ||
645 | qe->proc_cls = proc_cls; | ||
646 | enqeue_namestore_operation(h, qe); | ||
647 | |||
648 | /* set msg_size*/ | ||
649 | msg_size = sizeof (struct LookupNameMessage); | ||
650 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | ||
651 | |||
652 | /* create msg here */ | ||
653 | |||
654 | struct LookupNameMessage * msg; | ||
655 | pe->size = msg_size; | ||
656 | pe->is_init = GNUNET_NO; | ||
657 | msg = (struct LookupNameMessage *) &pe[1]; | ||
658 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME); | ||
659 | msg->header.size = htons (msg_size); | ||
660 | |||
661 | /* create msg done */ | ||
662 | |||
663 | GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe); | ||
664 | do_transmit(h); | ||
593 | 665 | ||
594 | #if 0 | 666 | #if 0 |
595 | struct GNUNET_NAMESTORE_SimpleRecord *iter; | 667 | struct GNUNET_NAMESTORE_SimpleRecord *iter; |
@@ -606,20 +678,7 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, | |||
606 | GNUNET_TIME_absolute_get_forever(), 0, NULL, 0, NULL); /*TERMINATE*/ | 678 | GNUNET_TIME_absolute_get_forever(), 0, NULL, 0, NULL); /*TERMINATE*/ |
607 | #endif | 679 | #endif |
608 | 680 | ||
609 | GNUNET_assert (NULL != h); | ||
610 | 681 | ||
611 | struct PendingMessage * p; | ||
612 | struct LookupNameMessage * msg; | ||
613 | size_t msg_len = sizeof (struct LookupNameMessage); | ||
614 | |||
615 | p = GNUNET_malloc (sizeof (struct PendingMessage) + msg_len); | ||
616 | p->size = msg_len; | ||
617 | p->is_init = GNUNET_NO; | ||
618 | msg = (struct LookupNameMessage *) &p[1]; | ||
619 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME); | ||
620 | msg->header.size = htons (msg_len); | ||
621 | GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, p); | ||
622 | do_transmit (h); | ||
623 | 682 | ||
624 | return qe; | 683 | return qe; |
625 | } | 684 | } |