static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
+/**
+ * Our notification context.
+ */
+static struct GNUNET_SERVER_NotificationContext *snc;
+
static char *db_lib_name;
static struct GNUNET_NAMESTORE_Client *client_head;
GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
GNUNET_free (nc);
+ GNUNET_SERVER_notification_context_destroy (snc);
+ snc = NULL;
+
GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database));
GNUNET_free (db_lib_name);
}
+static struct GNUNET_NAMESTORE_Client *
+client_lookup (struct GNUNET_SERVER_Client *client)
+{
+ struct GNUNET_NAMESTORE_Client * nc;
+
+ GNUNET_assert (NULL != client);
+
+ for (nc = client_head; nc != NULL; nc = nc->next)
+ {
+ if (client == nc->client)
+ break;
+ }
+ return nc;
+}
+
+
/**
* Called whenever a client is disconnected. Frees our
* resources associated with that client.
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)
+ nc = client_lookup (client);
+
+ if ((NULL == client) || (NULL == nc))
return;
for (no = nc->op_head; no != NULL; no = no->next)
struct GNUNET_SERVER_Client * client,
const struct GNUNET_MessageHeader * message)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
struct GNUNET_NAMESTORE_Client * nc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Client));
nc->client = client;
-
+ GNUNET_SERVER_notification_context_add (snc, client);
GNUNET_CONTAINER_DLL_insert(client_head, client_tail, nc);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
const struct GNUNET_MessageHeader * message)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_LOOKUP_NAME");
+
+ struct GNUNET_NAMESTORE_Client *nc;
+ uint32_t id = 0;
+ size_t r_size = 0;
+
+ nc = client_lookup(client);
+ if (nc == NULL)
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+
+ struct LookupNameMessage * ln_msg = (struct LookupNameMessage *) message;
+ id = ntohl (ln_msg->op_id);
+
+ /* do the actual lookup */
+
+ /* send response */
+ struct LookupNameResponseMessage lnr_msg;
+ r_size = sizeof (struct LookupNameResponseMessage);
+
+ lnr_msg.header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
+ lnr_msg.header.size = ntohs (r_size);
+ lnr_msg.op_id = htonl (id);
+
+ GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &lnr_msg, GNUNET_NO);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
{&handle_start, NULL,
GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)},
{&handle_lookup_name, NULL,
- GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0},
+ GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, sizeof (struct LookupNameMessage)},
{NULL, NULL, 0, 0}
};
/* Configuring server handles */
GNUNET_SERVER_add_handlers (server, handlers);
+ snc = GNUNET_SERVER_notification_context_create (server, 16);
GNUNET_SERVER_disconnect_notify (server,
&client_disconnect_notification,
NULL);
struct GNUNET_NAMESTORE_Handle *nsh;
- uint64_t op_id;
+ uint32_t op_id;
GNUNET_NAMESTORE_ContinuationWithStatus cont;
void *cont_cls;
struct GNUNET_NAMESTORE_QueueEntry * op_head;
struct GNUNET_NAMESTORE_QueueEntry * op_tail;
- uint64_t op_id;
+ uint32_t op_id;
/**
* Pending namestore zone iterator entries
static void
force_reconnect (struct GNUNET_NAMESTORE_Handle *nsh);
+static void
+handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
+ struct LookupNameResponseMessage * msg,
+ size_t size)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n",
+ "LOOKUP_NAME_RESPONSE");
+
+ struct GNUNET_NAMESTORE_Handle *nsh = qe->nsh;
+
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key = NULL;
+ struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get_forever();
+ const char *name = "";
+ unsigned int rd_count = 0;
+ const struct GNUNET_NAMESTORE_RecordData *rd = NULL;
+ const struct GNUNET_CRYPTO_RsaSignature *signature = NULL;
+
+ /* TODO: extract real values */
+
+ /* Lookup complete, remove queue entry */
+ GNUNET_CONTAINER_DLL_remove (nsh->op_head, nsh->op_tail, qe);
+
+ /* Notify */
+ if (qe->proc != NULL)
+ qe->proc (qe->proc_cls, zone_key, expire, name, rd_count, rd, signature);
+
+ GNUNET_free (qe);
+
+}
+
/**
* Type of a function to call when we receive a message
process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_NAMESTORE_Handle *nsh = cls;
+ struct GenericMessage * gm;
struct GNUNET_NAMESTORE_QueueEntry *qe;
uint16_t size;
uint16_t type;
- uint64_t op_id = UINT64_MAX;
+ uint32_t op_id = UINT32_MAX;
if (NULL == msg)
{
size = ntohs (msg->size);
type = ntohs (msg->type);
- /* find matching operation */
+ if (size < sizeof (struct GenericMessage))
+ {
+ GNUNET_break_op (0);
+ GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ return;
+ }
+
+ gm = (struct GenericMessage *) msg;
+ op_id = ntohl (gm->op_id);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message type %i size %i op %u\n", type, size, op_id);
+
+ /* Find matching operation */
if (op_id > nsh->op_id)
{
+ /* No matching pending operation found */
GNUNET_break_op (0);
GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
GNUNET_TIME_UNIT_FOREVER_REL);
}
if (qe == NULL)
{
+ /* No matching pending operation found */
GNUNET_break_op (0);
GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
GNUNET_TIME_UNIT_FOREVER_REL);
return;
}
+ /* handle different message type */
switch (type) {
- case GNUNET_MESSAGE_TYPE_TEST:
- /* handle message here */
+ case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE:
+ handle_lookup_name_response (qe, (struct LookupNameResponseMessage *) msg, size);
break;
default:
+ GNUNET_break_op (0);
break;
}
- size++; // FIXME: just working around compiler warning here...
+
GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
GNUNET_TIME_UNIT_FOREVER_REL);
nsh);
}
-static void
-enqeue_namestore_operation (struct GNUNET_NAMESTORE_Handle *nsh, struct GNUNET_NAMESTORE_QueueEntry *qe)
+static uint32_t
+get_op_id (struct GNUNET_NAMESTORE_Handle *nsh)
{
- qe->op_id = nsh->op_id;
+ uint32_t op_id = nsh->op_id;
nsh->op_id ++;
- GNUNET_CONTAINER_DLL_insert(nsh->op_head, nsh->op_tail, qe);
+ return op_id;
}
/**
struct GNUNET_NAMESTORE_QueueEntry *qe;
struct PendingMessage *pe;
size_t msg_size = 0;
+ uint32_t id = 0;
GNUNET_assert (NULL != h);
-
+ id = get_op_id(h);
qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
qe->nsh = h;
qe->cont = cont;
qe->cont_cls = cont_cls;
- enqeue_namestore_operation(h, qe);
+ qe->op_id = id;
+ GNUNET_CONTAINER_DLL_insert(h->op_head, h->op_tail, qe);
/* set msg_size*/
pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
qe->nsh = h;
qe->cont = cont;
qe->cont_cls = cont_cls;
- enqeue_namestore_operation(h, qe);
+ get_op_id(h);
/* set msg_size*/
pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
qe->nsh = h;
qe->cont = cont;
qe->cont_cls = cont_cls;
- enqeue_namestore_operation(h, qe);
+ get_op_id(h);
/* set msg_size*/
pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
struct GNUNET_NAMESTORE_QueueEntry *qe;
struct PendingMessage *pe;
size_t msg_size = 0;
+ uint32_t id = 0;
GNUNET_assert (NULL != h);
-
+ id = get_op_id(h);
qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
qe->nsh = h;
qe->proc = proc;
qe->proc_cls = proc_cls;
- enqeue_namestore_operation(h, qe);
+ qe->op_id = id;
+ GNUNET_CONTAINER_DLL_insert(h->op_head, h->op_tail, 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);
+ msg->op_id = htonl (id);
- /* create msg done */
-
+ /* transmit message */
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)
- {
- proc(proc_cls, iter->zone, iter->name, iter->record_type,
- iter->expiration,
- iter->flags,
- NULL /*sig loc*/,
- iter->data_size /*size*/,
- iter->data /* data */);
- }
- proc(proc_cls, zone, name, record_type,
- GNUNET_TIME_absolute_get_forever(), 0, NULL, 0, NULL); /*TERMINATE*/
-#endif
-
-
-
return qe;
}