[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r20371 - in gnunet/src: gns include
From: |
gnunet |
Subject: |
[GNUnet-SVN] r20371 - in gnunet/src: gns include |
Date: |
Thu, 8 Mar 2012 17:13:47 +0100 |
Author: schanzen
Date: 2012-03-08 17:13:47 +0100 (Thu, 08 Mar 2012)
New Revision: 20371
Modified:
gnunet/src/gns/Makefile.am
gnunet/src/gns/gns.conf.in
gnunet/src/gns/gns_api.c
gnunet/src/gns/gnunet-service-gns.c
gnunet/src/gns/test_gns_simple_lookup.c
gnunet/src/gns/test_gns_simple_lookup.conf
gnunet/src/gns/test_gns_simple_shorten.c
gnunet/src/include/gnunet_gns_service.h
Log:
-lookup now works in test, removed dns hijack from defaults
Modified: gnunet/src/gns/Makefile.am
===================================================================
--- gnunet/src/gns/Makefile.am 2012-03-08 15:47:18 UTC (rev 20370)
+++ gnunet/src/gns/Makefile.am 2012-03-08 16:13:47 UTC (rev 20371)
@@ -27,7 +27,8 @@
# gnunet-gns-lookup
check_PROGRAMS = \
- test_gns_simple_shorten
+ test_gns_simple_shorten \
+ test_gns_simple_lookup
# test_gns_simple_lookup
@@ -49,16 +50,18 @@
# $(top_builddir)/src/namestore/libgnunetnamestore.la \
# $(top_builddir)/src/testing/libgnunettesting.la
-#test_gns_simple_lookup_SOURCES = \
-# test_gns_simple_lookup.c
-#test_gns_simple_lookup_LDADD = \
-# $(top_builddir)/src/util/libgnunetutil.la \
-# $(top_builddir)/src/namestore/libgnunetnamestore.la \
-# $(top_builddir)/src/testing/libgnunettesting.la
-#test_gns_simple_lookup_DEPENDENCIES = \
-# $(top_builddir)/src/util/libgnunetutil.la \
-# $(top_builddir)/src/namestore/libgnunetnamestore.la \
-# $(top_builddir)/src/testing/libgnunettesting.la
+test_gns_simple_lookup_SOURCES = \
+ test_gns_simple_lookup.c
+test_gns_simple_lookup_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la \
+ $(top_builddir)/src/gns/libgnunetgns.la \
+ $(top_builddir)/src/testing/libgnunettesting.la
+test_gns_simple_lookup_DEPENDENCIES = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la \
+ $(top_builddir)/src/gns/libgnunetgns.la \
+ $(top_builddir)/src/testing/libgnunettesting.la
#test_gns_simple_delegated_lookup_SOURCES = \
# test_gns_simple_delegated_lookup.c
@@ -104,6 +107,7 @@
gnunet_gns_LDADD = \
$(top_builddir)/src/gns/libgnunetgns.la \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la \
$(GN_LIBINTL)
gnunet_gns_DEPENDENCIES = \
libgnunetgns.la
@@ -145,11 +149,13 @@
libgnunetgns_la_SOURCES = \
gns_api.c gns.h
libgnunetgns_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la $(XLIB)
+ $(top_builddir)/src/util/libgnunetutil.la $(XLIB) \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la
libgnunetgns_la_LDFLAGS = \
$(GN_LIB_LDFLAGS)
libgnunetgns_la_DEPENDENCIES = \
- $(top_builddir)/src/util/libgnunetutil.la
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la
libgnunet_plugin_block_gns_la_SOURCES = \
plugin_block_gns.c
Modified: gnunet/src/gns/gns.conf.in
===================================================================
--- gnunet/src/gns/gns.conf.in 2012-03-08 15:47:18 UTC (rev 20370)
+++ gnunet/src/gns/gns.conf.in 2012-03-08 16:13:47 UTC (rev 20371)
@@ -6,8 +6,7 @@
BINARY = gnunet-service-gns
UNIXPATH = /tmp/gnunet-service-gns.sock
ZONEKEY = $SERVICEHOME/gns/zonekey
-HIJACK_DNS = YES
-OPTIONS = -L INFO
+HIJACK_DNS = NO
[fcfsd]
HTTPPORT = 18080
Modified: gnunet/src/gns/gns_api.c
===================================================================
--- gnunet/src/gns/gns_api.c 2012-03-08 15:47:18 UTC (rev 20370)
+++ gnunet/src/gns/gns_api.c 2012-03-08 16:13:47 UTC (rev 20371)
@@ -35,10 +35,6 @@
#include "gns.h"
#include "gnunet_gns_service.h"
-#define DEBUG_GNS_API GNUNET_EXTRA_LOGGING
-
-#define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__)
-
/* TODO into gnunet_protocols */
#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP 23
#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 24
@@ -67,8 +63,11 @@
struct GNUNET_GNS_Handle *gns_handle;
/* processor to call on shorten result */
- GNUNET_GNS_ShortenResultProcessor proc;
+ GNUNET_GNS_ShortenResultProcessor shorten_proc;
+ /* processor to call on lookup result */
+ GNUNET_GNS_LookupResultProcessor lookup_proc;
+
/* processor closure */
void *proc_cls;
@@ -355,7 +354,7 @@
"Received shortened reply `%s' from GNS service\n",
short_name);
- qe->proc(qe->proc_cls, short_name);
+ qe->shorten_proc(qe->proc_cls, short_name);
}
@@ -373,6 +372,31 @@
process_lookup_reply (struct GNUNET_GNS_QueueEntry *qe,
const struct GNUNET_GNS_ClientLookupResultMessage *msg)
{
+ struct GNUNET_GNS_Handle *h = qe->gns_handle;
+ int rd_count = ntohl(msg->rd_count);
+ size_t len = ntohs (((struct GNUNET_MessageHeader*)msg)->size);
+ struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+
+ GNUNET_CONTAINER_DLL_remove(h->lookup_head, h->lookup_tail, qe);
+
+ if (len < sizeof (struct GNUNET_GNS_ClientLookupResultMessage))
+ {
+ GNUNET_break (0);
+ force_reconnect (h);
+ return;
+ }
+
+ len -= sizeof(struct GNUNET_GNS_ClientLookupResultMessage);
+
+ GNUNET_NAMESTORE_records_deserialize (len, (char*)&msg[1],
+ rd_count,
+ rd);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received lookup reply from GNS service (count=%d)\n",
+ ntohl(msg->rd_count));
+
+ qe->lookup_proc(qe->proc_cls, rd_count, rd);
}
/**
@@ -522,12 +546,51 @@
*/
struct GNUNET_GNS_QueueEntry *
GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
- const char * name,
- enum GNUNET_GNS_RecordType type,
- GNUNET_GNS_LookupIterator iter,
- void *iter_cls)
+ const char * name,
+ enum GNUNET_GNS_RecordType type,
+ GNUNET_GNS_LookupResultProcessor proc,
+ void *proc_cls)
{
- return NULL;
+ /* IPC to shorten gns names, return shorten_handle */
+ struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
+ struct GNUNET_GNS_QueueEntry *qe;
+ size_t msize;
+ struct PendingMessage *pending;
+
+ if (NULL == name)
+ {
+ return NULL;
+ }
+
+ msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name) + 1;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten %s in GNS\n", name);
+
+ qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry));
+ qe->gns_handle = handle;
+ qe->lookup_proc = proc;
+ qe->proc_cls = proc_cls;
+ qe->r_id = get_request_id(handle);
+ GNUNET_CONTAINER_DLL_insert_tail(handle->lookup_head,
+ handle->lookup_tail, qe);
+
+ pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
+ memset(pending, 0, (sizeof (struct PendingMessage) + msize));
+
+ pending->size = msize;
+
+ lookup_msg = (struct GNUNET_GNS_ClientLookupMessage *) &pending[1];
+ lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
+ lookup_msg->header.size = htons (msize);
+ lookup_msg->id = htonl(qe->r_id);
+ lookup_msg->type = htonl(type);
+
+ memcpy(&lookup_msg[1], name, strlen(name));
+
+ GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
+ pending);
+
+ process_pending_messages (handle);
+ return qe;
}
@@ -562,7 +625,7 @@
qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry));
qe->gns_handle = handle;
- qe->proc = proc;
+ qe->shorten_proc = proc;
qe->proc_cls = proc_cls;
qe->r_id = get_request_id(handle);
GNUNET_CONTAINER_DLL_insert_tail(handle->shorten_head,
Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-03-08 15:47:18 UTC (rev 20370)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-03-08 16:13:47 UTC (rev 20371)
@@ -153,8 +153,8 @@
/* request id */
uint64_t unique_id;
- /* request key */
- GNUNET_HashCode key;
+ /* request type */
+ enum GNUNET_GNS_RecordType type;
/* name to shorten */
char* name;
@@ -172,8 +172,8 @@
/* request id */
uint64_t unique_id;
- /* request key */
- GNUNET_HashCode key;
+ /* request type */
+ enum GNUNET_GNS_RecordType type;
/* the name to look up */
char* name; //Needed?
@@ -2229,13 +2229,142 @@
}
/**
- * TODO
+ * Reply to client with the result from our lookup.
+ *
+ * @param cls the closure (our client lookup handle)
+ * @param rh the request handle of the lookup
+ * @param rd_count the number of records
+ * @param rd the record data
*/
static void
+reply_to_client(void* cls, struct GNUNET_GNS_ResolverHandle *rh,
+ uint32_t rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd)
+{
+ struct ClientLookupHandle* clh = (struct ClientLookupHandle*)cls;
+ struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
+ size_t len;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %d
results\n",
+ "LOOKUP_RESULT", rd_count);
+
+ len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
+ rmsg = GNUNET_malloc(len+sizeof(struct
GNUNET_GNS_ClientLookupResultMessage));
+
+ rmsg->id = clh->unique_id;
+ rmsg->rd_count = htonl(rd_count);
+ rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
+ rmsg->header.size =
+ htons(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
+
+ GNUNET_NAMESTORE_records_serialize (rd_count, rd, len, (char*)&rmsg[1]);
+
+ GNUNET_SERVER_notification_context_unicast (nc, clh->client,
+ (const struct GNUNET_MessageHeader *) rmsg,
+ GNUNET_NO);
+ GNUNET_SERVER_receive_done (clh->client, GNUNET_OK);
+ GNUNET_free(rmsg);
+ GNUNET_free(clh->name);
+ GNUNET_free(clh);
+
+}
+
+/**
+ * Lookup a given name
+ *
+ * @param name the name to looku[
+ * @param clh the client lookup handle
+ */
+static void
+lookup_name(char* name, struct ClientLookupHandle* clh)
+{
+
+ struct GNUNET_GNS_ResolverHandle *rh;
+ struct RecordLookupHandle* rlh;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting resolution for %s (type=%d)!\n",
+ name, clh->type);
+
+ rh = GNUNET_malloc(sizeof (struct GNUNET_GNS_ResolverHandle));
+ rlh = GNUNET_malloc(sizeof(struct RecordLookupHandle));
+
+ rh->authority = zone_hash;
+
+ rlh->record_type = clh->type;
+ rlh->name = clh->name;
+ rlh->proc = &reply_to_client;
+ rlh->proc_cls = clh;
+
+ rh->proc_cls = rlh;
+
+ rh->name = GNUNET_malloc(strlen(name)
+ - strlen(gnunet_tld) + 1);
+ memset(rh->name, 0,
+ strlen(name)-strlen(gnunet_tld) + 1);
+ memcpy(rh->name, name,
+ strlen(name)-strlen(gnunet_tld));
+
+ rh->authority_name = GNUNET_malloc(sizeof(char)*MAX_DNS_LABEL_LENGTH);
+
+ rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain));
+ rh->authority_chain_head->prev = NULL;
+ rh->authority_chain_head->next = NULL;
+ rh->authority_chain_tail = rh->authority_chain_head;
+ rh->authority_chain_head->zone = zone_hash;
+
+ /* Start resolution in our zone */
+ rh->proc = &process_ns_delegation_dns; //FIXME rename
+ resolve_delegation_from_ns(rh);
+}
+
+
+/**
+ * Handle lookup requests from client
+ *
+ * @param cls the closure
+ * @param client the client
+ * @param message the message
+ */
+static void
handle_lookup(void *cls,
struct GNUNET_SERVER_Client * client,
const struct GNUNET_MessageHeader * message)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP");
+
+ size_t msg_size = 0;
+ struct ClientLookupHandle *clh;
+
+ if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+
+ GNUNET_SERVER_notification_context_add (nc, client);
+
+ struct GNUNET_GNS_ClientLookupMessage *sh_msg =
+ (struct GNUNET_GNS_ClientLookupMessage *) message;
+
+ msg_size = ntohs(message->size);
+
+ if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
+
+ clh = GNUNET_malloc(sizeof(struct ClientLookupHandle));
+ clh->client = client;
+ clh->name = GNUNET_malloc(strlen((char*)&sh_msg[1]) + 1);
+ strcpy(clh->name, (char*)&sh_msg[1]);
+ clh->unique_id = sh_msg->id;
+ clh->type = ntohl(sh_msg->type);
+
+ lookup_name((char*)&sh_msg[1], clh);
}
/**
Modified: gnunet/src/gns/test_gns_simple_lookup.c
===================================================================
--- gnunet/src/gns/test_gns_simple_lookup.c 2012-03-08 15:47:18 UTC (rev
20370)
+++ gnunet/src/gns/test_gns_simple_lookup.c 2012-03-08 16:13:47 UTC (rev
20371)
@@ -77,6 +77,8 @@
static struct GNUNET_NAMESTORE_Handle *namestore_handle;
+static struct GNUNET_GNS_Handle *gns_handle;
+
const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
@@ -95,41 +97,39 @@
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok);
}
-/**
- * Function scheduled to be run on the successful start of services
- * tries to look up the dns record for TEST_DOMAIN
- */
+
static void
-finish_testing (void *cls, int32_t success, const char *emsg)
+on_lookup_result(void *cls, uint32_t rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd)
{
- struct hostent *he;
struct in_addr a;
+ int i;
char* addr;
- GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES);
-
- he = gethostbyname (TEST_DOMAIN);
-
- if (!he)
+ if (rd_count == 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "gethostbyname failed, rp_filtering?\n");
+ "Lookup failed, rp_filtering?\n");
ok = 2;
}
else
{
ok = 1;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", he->h_name);
- while (*he->h_addr_list)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
+ for (i=0; i<rd_count; i++)
{
- memcpy(&a, *he->h_addr_list++, sizeof(a));
- addr = inet_ntoa(a);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
- if (0 == strcmp(addr, TEST_IP))
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
+ if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ memcpy(&a, rd[i].data, sizeof(a));
+ addr = inet_ntoa(a);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
+ if (0 == strcmp(addr, TEST_IP))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"%s correctly resolved to %s!\n", TEST_DOMAIN, addr);
- ok = 0;
+ ok = 0;
+ }
}
else
{
@@ -142,7 +142,33 @@
GNUNET_YES, GNUNET_NO);
}
+
/**
+ * Function scheduled to be run on the successful start of services
+ * tries to look up the dns record for TEST_DOMAIN
+ */
+static void
+commence_testing (void *cls, int32_t success, const char *emsg)
+{
+
+
+ GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES);
+
+ gns_handle = GNUNET_GNS_connect(cfg);
+
+ if (NULL == gns_handle)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to connect to GNS!\n");
+ ok = 2;
+ }
+
+ GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
+ &on_lookup_result, TEST_DOMAIN);
+}
+
+
+/**
* Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
* down the peers without freeing memory associated with GET request.
*/
@@ -216,7 +242,7 @@
alice_key,
TEST_RECORD_NAME,
&rd,
- &finish_testing,
+ &commence_testing,
NULL);
}
Modified: gnunet/src/gns/test_gns_simple_lookup.conf
===================================================================
--- gnunet/src/gns/test_gns_simple_lookup.conf 2012-03-08 15:47:18 UTC (rev
20370)
+++ gnunet/src/gns/test_gns_simple_lookup.conf 2012-03-08 16:13:47 UTC (rev
20371)
@@ -74,7 +74,7 @@
AUTOSTART = YES
BINARY = gnunet-service-gns
ZONEKEY = zonekey
-HIJACK_DNS = YES
+HIJACK_DNS = NO
UNIXPATH = /tmp/gnunet-service-gns.sock
HOME = $SERVICEHOME
CONFIG = $DEFAULTCONFIG
Modified: gnunet/src/gns/test_gns_simple_shorten.c
===================================================================
--- gnunet/src/gns/test_gns_simple_shorten.c 2012-03-08 15:47:18 UTC (rev
20370)
+++ gnunet/src/gns/test_gns_simple_shorten.c 2012-03-08 16:13:47 UTC (rev
20371)
@@ -93,7 +93,7 @@
* Called when gns shorten finishes
*/
static void
-process_shorten_result(void* cls, const char* lname, const char* sname)
+process_shorten_result(void* cls, const char* sname)
{
GNUNET_GNS_disconnect(gns_handle);
@@ -108,12 +108,12 @@
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s shortened to %s\n", lname, sname);
+ "%s shortened to %s\n", (char*)cls, sname);
if (0 != strcmp(sname, TEST_EXPECTED_RESULT))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"shorten test failed! (wanted: %s got: %s\n",
- lname, sname);
+ (char*)cls, sname);
ok = 1;
}
@@ -152,7 +152,8 @@
return;
}
- GNUNET_GNS_shorten(gns_handle, TEST_DOMAIN, &process_shorten_result, NULL);
+ GNUNET_GNS_shorten(gns_handle, TEST_DOMAIN, &process_shorten_result,
+ TEST_DOMAIN);
}
Modified: gnunet/src/include/gnunet_gns_service.h
===================================================================
--- gnunet/src/include/gnunet_gns_service.h 2012-03-08 15:47:18 UTC (rev
20370)
+++ gnunet/src/include/gnunet_gns_service.h 2012-03-08 16:13:47 UTC (rev
20371)
@@ -104,7 +104,7 @@
/* *************** Standard API: lookup ******************* */
/**
- * Iterator called on each result obtained for a GNS
+ * Iterator called on obtained result for a GNS
* lookup
*
* @param cls closure
@@ -112,8 +112,7 @@
* @param rd_count number of records
* @param rd the records in reply
*/
-typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
- const char * name,
+typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls,
uint32_t rd_count,
const struct
GNUNET_NAMESTORE_RecordData *rd);
@@ -125,17 +124,17 @@
* @param handle handle to the GNS service
* @param name the name to look up
* @param type the GNUNET_GNS_RecordType to look for
- * @param iter function to call on each result
- * @param iter_cls closure for iter
+ * @param proc function to call on result
+ * @param proc_cls closure for iter
*
- * @return handle to stop the async lookup
+ * @return handle to the queued request
*/
struct GNUNET_GNS_QueueEntry *
GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
const char * name,
enum GNUNET_GNS_RecordType type,
- GNUNET_GNS_LookupIterator iter,
- void *iter_cls);
+ GNUNET_GNS_LookupResultProcessor proc,
+ void *proc_cls);
/* *************** Standard API: shorten ******************* */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r20371 - in gnunet/src: gns include,
gnunet <=