#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.
*/
static char *db_lib_name;
+static struct GNUNET_NAMESTORE_Client *client_head;
+static struct GNUNET_NAMESTORE_Client *client_tail;
+
+
/**
* Task run during shutdown.
*
{
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);
}
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,
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);
}
uint64_t op_id;
+ GNUNET_NAMESTORE_ContinuationWithStatus cont;
+ void *cont_cls;
+
+ GNUNET_NAMESTORE_RecordProcessor proc;
+ void *proc_cls;
+
char *data; /*stub data pointer*/
};
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*/
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;
}
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)
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;
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;
}