From: Matthias Wachs Date: Fri, 24 Feb 2012 10:57:17 +0000 (+0000) Subject: - changes X-Git-Tag: initial-import-from-subversion-38251~14671 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e485bea7f1ffc881334748f759ffe8c665131a44;p=oweals%2Fgnunet.git - changes --- 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 @@ #include "gnunet_namestore_plugin.h" #include "namestore.h" + + +/** + * A namestore operation. + */ +struct GNUNET_NAMESTORE_Operation +{ + struct GNUNET_NAMESTORE_Operation *next; + struct GNUNET_NAMESTORE_Operation *prev; + + uint64_t op_id; + + char *data; /*stub data pointer*/ +}; + + +/** + * A namestore client + */ +struct GNUNET_NAMESTORE_Client +{ + struct GNUNET_NAMESTORE_Client *next; + struct GNUNET_NAMESTORE_Client *prev; + + struct GNUNET_SERVER_Client * client; + + struct GNUNET_NAMESTORE_Operation *op_head; + struct GNUNET_NAMESTORE_Operation *op_tail; +}; + + + /** * Configuration handle. */ @@ -39,6 +71,10 @@ static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; static char *db_lib_name; +static struct GNUNET_NAMESTORE_Client *client_head; +static struct GNUNET_NAMESTORE_Client *client_tail; + + /** * Task run during shutdown. * @@ -50,6 +86,21 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); + struct GNUNET_NAMESTORE_Operation * no; + struct GNUNET_NAMESTORE_Client * nc; + + for (nc = client_head; nc != NULL; nc = nc->next) + { + for (no = nc->op_head; no != NULL; no = no->next) + { + GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); + GNUNET_free (no); + } + } + + GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); + GNUNET_free (nc); + GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); GNUNET_free (db_lib_name); } @@ -64,8 +115,29 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client) { - if (NULL != client) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client); + struct GNUNET_NAMESTORE_Operation * no; + struct GNUNET_NAMESTORE_Client * nc; + if (NULL == client) + return; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client); + + for (nc = client_head; nc != NULL; nc = nc->next) + { + if (client == nc->client) + break; + } + if (NULL == client) + return; + + for (no = nc->op_head; no != NULL; no = no->next) + { + GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); + GNUNET_free (no); + } + + GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); + GNUNET_free (nc); } static void handle_start (void *cls, @@ -73,6 +145,12 @@ static void handle_start (void *cls, const struct GNUNET_MessageHeader * message) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n"); + + struct GNUNET_NAMESTORE_Client * nc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Client)); + nc->client = client; + + GNUNET_CONTAINER_DLL_insert(client_head, client_tail, nc); + GNUNET_SERVER_receive_done (client, GNUNET_OK); } 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 uint64_t op_id; + GNUNET_NAMESTORE_ContinuationWithStatus cont; + void *cont_cls; + + GNUNET_NAMESTORE_RecordProcessor proc; + void *proc_cls; + char *data; /*stub data pointer*/ }; @@ -452,7 +458,12 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, struct GNUNET_NAMESTORE_QueueEntry *qe; struct PendingMessage *pe; size_t msg_size = 0; + + GNUNET_assert (NULL != h); + qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); + qe->cont = cont; + qe->cont_cls = cont_cls; enqeue_namestore_operation(h, qe); /* set msg_size*/ @@ -520,7 +531,25 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls) { - return NULL; + struct GNUNET_NAMESTORE_QueueEntry *qe; + struct PendingMessage *pe; + size_t msg_size = 0; + + GNUNET_assert (NULL != h); + + qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); + qe->cont = cont; + qe->cont_cls = cont_cls; + enqeue_namestore_operation(h, qe); + + /* set msg_size*/ + pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); + + /* create msg here */ + + GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe); + do_transmit(h); + return qe; } @@ -548,7 +577,24 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h, void *cont_cls) { struct GNUNET_NAMESTORE_QueueEntry *qe; + struct PendingMessage *pe; + size_t msg_size = 0; + + GNUNET_assert (NULL != h); + qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); + qe->cont = cont; + qe->cont_cls = cont_cls; + enqeue_namestore_operation(h, qe); + + /* set msg_size*/ + pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); + + /* create msg here */ + + GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe); + do_transmit(h); + #if 0 struct GNUNET_NAMESTORE_SimpleRecord *iter; for (iter=h->records_head; iter != NULL; iter=iter->next) @@ -589,7 +635,33 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls) { struct GNUNET_NAMESTORE_QueueEntry *qe; + struct PendingMessage *pe; + size_t msg_size = 0; + + GNUNET_assert (NULL != h); + qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); + qe->proc = proc; + qe->proc_cls = proc_cls; + enqeue_namestore_operation(h, qe); + + /* set msg_size*/ + msg_size = sizeof (struct LookupNameMessage); + pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); + + /* create msg here */ + + struct LookupNameMessage * msg; + pe->size = msg_size; + pe->is_init = GNUNET_NO; + msg = (struct LookupNameMessage *) &pe[1]; + msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME); + msg->header.size = htons (msg_size); + + /* create msg done */ + + GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe); + do_transmit(h); #if 0 struct GNUNET_NAMESTORE_SimpleRecord *iter; @@ -606,20 +678,7 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, GNUNET_TIME_absolute_get_forever(), 0, NULL, 0, NULL); /*TERMINATE*/ #endif - GNUNET_assert (NULL != h); - struct PendingMessage * p; - struct LookupNameMessage * msg; - size_t msg_len = sizeof (struct LookupNameMessage); - - p = GNUNET_malloc (sizeof (struct PendingMessage) + msg_len); - p->size = msg_len; - p->is_init = GNUNET_NO; - msg = (struct LookupNameMessage *) &p[1]; - msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME); - msg->header.size = htons (msg_len); - GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, p); - do_transmit (h); return qe; }