gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r19826 - in gnunet/src: gns include


From: gnunet
Subject: [GNUnet-SVN] r19826 - in gnunet/src: gns include
Date: Thu, 16 Feb 2012 21:05:40 +0100

Author: schanzen
Date: 2012-02-16 21:05:40 +0100 (Thu, 16 Feb 2012)
New Revision: 19826

Modified:
   gnunet/src/gns/Makefile.am
   gnunet/src/gns/gns.h
   gnunet/src/gns/gns_api.c
   gnunet/src/gns/gnunet-gns-add.c
   gnunet/src/gns/gnunet-gns-lookup.c
   gnunet/src/gns/gnunet-service-gns.c
   gnunet/src/include/gnunet_dht_service.h
   gnunet/src/include/gnunet_gns_service.h
Log:
- commit after up, ty!


Modified: gnunet/src/gns/Makefile.am
===================================================================
--- gnunet/src/gns/Makefile.am  2012-02-16 18:30:18 UTC (rev 19825)
+++ gnunet/src/gns/Makefile.am  2012-02-16 20:05:40 UTC (rev 19826)
@@ -12,14 +12,14 @@
 
 plugindir = $(libdir)/gnunet
 
-pkgcfg_DATA = \
-  dns.conf
+#pkgcfg_DATA = \
+#  dns.conf
 
 lib_LTLIBRARIES = \
   libgnunetgns.la
 
 bin_PROGRAMS = \
-  gnunet-service-gns $(HIJACKBIN)
+  gnunet-service-gns
 
 noinst_PROGRAMS = \
   gnunet-gns-lookup gnunet-gns-add
@@ -37,6 +37,15 @@
 gnunet_dns_add_DEPENDENCIES = \
   libgnunetgns.la
 
+gnunet_gns_lookup_SOURCES = \
+ gnunet-gns-lookup.c
+gnunet_gns_lookup_LDADD = \
+  $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(GN_LIBINTL)
+gnunet_dns_lookup_DEPENDENCIES = \
+  libgnunetgns.la
+
 gnunet_service_gns_SOURCES = \
  gnunet-service-gns.c 
 gnunet_service_gns_LDADD = \
@@ -45,6 +54,7 @@
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/util/libgnunetutil.la \
        $(top_builddir)/src/dns/libgnunetdns.la \
+       $(top_builddir)/src/dns/libgnunetdnsparser.la \
   $(GN_LIBINTL)
 
 libgnunetgns_la_SOURCES = \

Modified: gnunet/src/gns/gns.h
===================================================================
--- gnunet/src/gns/gns.h        2012-02-16 18:30:18 UTC (rev 19825)
+++ gnunet/src/gns/gns.h        2012-02-16 20:05:40 UTC (rev 19826)
@@ -40,6 +40,11 @@
   struct GNUNET_MessageHeader header;
 
   /**
+   * A key. TODO some uid
+   */
+  GNUNET_HashCode key;
+
+  /**
    * Unique identifier for this request (for key collisions).
    */
   // FIXME: unaligned

Modified: gnunet/src/gns/gns_api.c
===================================================================
--- gnunet/src/gns/gns_api.c    2012-02-16 18:30:18 UTC (rev 19825)
+++ gnunet/src/gns/gns_api.c    2012-02-16 20:05:40 UTC (rev 19826)
@@ -231,6 +231,35 @@
 }
 
 /**
+ * Add the request corresponding to the given handle
+ * to the pending queue (if it is not already in there).
+ *
+ * @param cls the 'struct GNUNET_GNS_Handle*'
+ * @param key key for the request (not used)
+ * @param value the 'struct GNUNET_GNS_LookupHandle*'
+ * @return GNUNET_YES (always)
+ */
+static int
+add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value)
+{
+  struct GNUNET_GNS_Handle *handle = cls;
+  struct GNUNET_GNS_LookupHandle *rh = value;
+
+  if (GNUNET_NO == rh->message->in_pending_queue)
+  {
+#if DEBUG_DHT
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Retransmitting request related to %s to GNS %p\n", GNUNET_h2s(key),
+         handle);
+#endif
+    GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
+                                 rh->message);
+    rh->message->in_pending_queue = GNUNET_YES;
+  }
+  return GNUNET_YES;
+}
+
+/**
  * Try reconnecting to the GNS service.
  *
  * @param cls GNUNET_GNS_Handle
@@ -349,10 +378,8 @@
   handle->th = NULL;
   if (buf == NULL)
   {
-#if DEBUG_GNS
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
          "Transmission to GNS service failed!  Reconnecting!\n");
-#endif
     do_disconnect (handle);
     return 0;
   }
@@ -562,6 +589,7 @@
 
 /**
  * Perform an asynchronous Lookup operation on the GNS.
+ * TODO: Still not sure what we query for... "names" it is for now
  *
  * @param handle handle to the GNS service
  * @param timeout how long to wait for transmission of this request to the 
service
@@ -572,18 +600,26 @@
  */
 struct GNUNET_GNS_LookupHandle *
 GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
-                      struct GNUNET_TIME_Relative timeout,
-                      const char * name,
-                      enum GNUNET_GNS_RecordType type,
-                      GNUNET_GNS_LookupIterator iter,
-                      void *iter_cls)
+                         struct GNUNET_TIME_Relative timeout,
+                         const char * name,
+                         enum GNUNET_GNS_RecordType type,
+                         GNUNET_GNS_LookupIterator iter,
+                         void *iter_cls)
 {
   /* IPC to look for local entries, start dht lookup, return lookup_handle */
   struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
   struct GNUNET_GNS_LookupHandle *lookup_handle;
+  GNUNET_HashCode key;
   size_t msize;
   struct PendingMessage *pending;
 
+  if (NULL == name)
+  {
+    return NULL;
+  }
+
+  GNUNET_CRYPTO_hash (name, strlen(name), &key);
+
   msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name);
 #if DEBUG_GNS
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lookup for %s in GNS %p\n",
@@ -597,6 +633,7 @@
   lookup_msg->header.size = htons (msize);
   lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP);
   lookup_msg->namelen = strlen(name);
+  lookup_msg->key = key;
   memcpy(&lookup_msg[1], name, strlen(name));
   handle->uid_gen++;
   lookup_msg->unique_id = handle->uid_gen;
@@ -608,7 +645,8 @@
   lookup_handle->iter_cls = iter_cls;
   lookup_handle->message = pending;
   lookup_handle->unique_id = lookup_msg->unique_id;
-  GNUNET_CONTAINER_multihashmap_put (handle->active_requests, key, 
lookup_handle,
+  GNUNET_CONTAINER_multihashmap_put (handle->active_requests, &lookup_msg->key,
+                                     lookup_handle,
                                      
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
   process_pending_messages (handle);
   return lookup_handle;

Modified: gnunet/src/gns/gnunet-gns-add.c
===================================================================
--- gnunet/src/gns/gnunet-gns-add.c     2012-02-16 18:30:18 UTC (rev 19825)
+++ gnunet/src/gns/gnunet-gns-add.c     2012-02-16 20:05:40 UTC (rev 19826)
@@ -144,8 +144,9 @@
   if (verbose)
     FPRINTF (stderr, _("Issuing add request for `%s' with data `%s'!\n"),
              record_key, data);
-  GNUNET_GNS_add_record (gns_handle, &record_key, record_type,
-                  strlen (data), data, expiration, timeout);
+  GNUNET_GNS_add_record (gns_handle, record_key,
+                         0/*RecordType*/,
+                         strlen (data), data, expiration, timeout);
 
 }
 

Modified: gnunet/src/gns/gnunet-gns-lookup.c
===================================================================
--- gnunet/src/gns/gnunet-gns-lookup.c  2012-02-16 18:30:18 UTC (rev 19825)
+++ gnunet/src/gns/gnunet-gns-lookup.c  2012-02-16 20:05:40 UTC (rev 19826)
@@ -120,17 +120,12 @@
  * @param data pointer to the result data
  */
 static void
-get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
-                     const GNUNET_HashCode * key,
-                     const struct GNUNET_PeerIdentity *get_path,
-                     unsigned int get_path_length,
-                     const struct GNUNET_PeerIdentity *put_path,
-                     unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
-                     size_t size, const void *data)
+lookup_result_iterator (void *cls,
+                        const GNUNET_HashCode * key,
+                        const struct GNUNET_GNS_Record *record,
+                        unsigned int num_records)
 {
-  FPRINTF (stdout, "Result %d, type %d:\n%.*s\n", result_count, type,
-           (unsigned int) size, (char *) data);
-  result_count++;
+  FPRINTF (stdout, "Results %d\n", num_records);
 }
 
 
@@ -147,7 +142,6 @@
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
   struct GNUNET_TIME_Relative timeout;
-  GNUNET_HashCode key;
 
   cfg = c;
 
@@ -159,9 +153,9 @@
     return;
   }
 
-  lookup_handle = GNUNET_GNS_connect (cfg, 1);
+  gns_handle = GNUNET_GNS_connect (cfg, 1);
 
-  if (lookup_handle == NULL)
+  if (gns_handle == NULL)
   {
     if (verbose)
       FPRINTF (stderr, "%s",  "Couldn't connect to GNS service!\n");
@@ -171,11 +165,6 @@
   else if (verbose)
     FPRINTF (stderr, "%s",  "Connected to GNS service!\n");
 
-  if (query_type == GNUNET_BLOCK_TYPE_ANY)      /* Type of data not set */
-    query_type = GNUNET_BLOCK_TYPE_TEST;
-
-  GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
-
   timeout =
       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 
timeout_request);
   absolute_timeout = GNUNET_TIME_relative_to_absolute (timeout);
@@ -184,10 +173,11 @@
     FPRINTF (stderr, "Issuing lookup request for %s!\n", query_key);
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
                                 (absolute_timeout), &cleanup_task, NULL);
-  get_handle =
-      GNUNET_GNS_lookup_start (lookup_handle, timeout, query_type, &key, 
replication,
-                            GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator,
-                            NULL);
+  lookup_handle =
+      GNUNET_GNS_lookup_start (gns_handle, timeout, query_key,
+                               0/*GNS_RecordType*/,
+                               &lookup_result_iterator,
+                               NULL);
 
 }
 

Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-02-16 18:30:18 UTC (rev 19825)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-02-16 20:05:40 UTC (rev 19826)
@@ -27,14 +27,19 @@
 #include "gnunet_util_lib.h"
 #include "gnunet_transport_service.h"
 #include "gnunet_dns_service.h"
+#include "gnunet_dnsparser_lib.h"
 #include "gnunet_gns_service.h"
-#include "gnunet-service-gns.h"
+#include "gns.h"
 
 
+/* TODO into gnunet_protocols */
+#define GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 23
+#define GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT 24
+
 /**
  * Our handle to the DNS handler library
  */
-struct GNUNET_DNS_Handle *dns_handler;
+struct GNUNET_DNS_Handle *dns_handle;
 
 /**
  * The configuration the GNS service is running with
@@ -42,6 +47,11 @@
 const struct GNUNET_CONFIGURATION_Handle *GNS_cfg;
 
 /**
+ * Our notification context.
+ */
+static struct GNUNET_SERVER_NotificationContext *nc;
+
+/**
  * Task run during shutdown.
  *
  * @param cls unused
@@ -50,7 +60,7 @@
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-       GNUNET_DNS_disconnect(dns_handle);
+  GNUNET_DNS_disconnect(dns_handle);
 }
 
 /**
@@ -63,56 +73,75 @@
  */
 void
 handle_dns_request(void *cls,
-                                                                        struct 
GNUNET_DNS_RequestHandle *rh,
-                                                                        size_t 
request_length,
-                                                                        const 
char *request)
+                   struct GNUNET_DNS_RequestHandle *rh,
+                   size_t request_length,
+                   const char *request)
 {
-       /**
-        * TODO: parse request for tld
-        * Queue rh and gns handle (or use cls)
-        * How should lookup behave:
-        *  - sync and return result or "NX"
-        *  - async like dht with iter
-        *  Maybe provide both, useful for cli app
-        **/
+  /**
+   * TODO: parse request for tld
+   * Queue rh and gns handle (or use cls)
+   * How should lookup behave:
+   *  - sync and return result or "NX"
+   *  - async like dht with iter
+   *  Maybe provide both, useful for cli app
+   **/
   struct GNUNET_DNSPARSER_Packet *p;
-       int namelen;
-       
-       p = GNUNET_DNSPARSER_parse (request, request_length);
-       if (NULL == p)
-       {
-               fprintf (stderr, "Received malformed DNS packet, leaving it 
untouched\n");
-               GNUNET_DNS_request_forward (rh);
-               return;
-       }
-       /**
-        * TODO factor out
-        * Check tld and decide if we or
-        * legacy dns is responsible
-        **/
-       for (i=0;i<p->num_queries;i++)
-       {
-               namelen = strlen(&p->queries[i]->name);
-               if (namelen >= 7)
-               {
-                       /**
-                        * TODO off by 1?
-                        * Move our tld/root to config file
-                        * Generate fake DNS reply that replaces .gnunet with 
.org
-                        **/
-                       if (0 == strcmp((&p->queries[i]->name)+(namelen-7), 
".gnunet"))
-                       {
-                               GNUNET_DNS_request_answer(rh, 0 /*length*/, 
NULL/*reply*/);
-                       }
-                       else
-                       {
-                               GNUNET_DNS_request_forward (rh);
-                       }
-               }
-       }
+  int namelen;
+  int i;
+  char *tail;
+  
+  p = GNUNET_DNSPARSER_parse (request, request_length);
+  if (NULL == p)
+  {
+    fprintf (stderr, "Received malformed DNS packet, leaving it untouched\n");
+    GNUNET_DNS_request_forward (rh);
+    return;
+  }
+  /**
+   * TODO factor out
+   * Check tld and decide if we or
+   * legacy dns is responsible
+   **/
+  for (i=0;i<p->num_queries;i++)
+  {
+    namelen = strlen(p->queries[i].name);
+    if (namelen >= 7)
+    {
+      /**
+       * TODO off by 1?
+       * Move our tld/root to config file
+       * Generate fake DNS reply that replaces .gnunet with .org
+       **/
+      tail = p->queries[i].name+(namelen-7);
+      if (0 == strcmp(tail, ".gnunet"))
+      {
+        /* Do db lookup here. Make dht lookup if necessary */
+        GNUNET_DNS_request_answer(rh, 0 /*length*/, NULL/*reply*/);
+      }
+      else
+      {
+        GNUNET_DNS_request_forward (rh);
+      }
+    }
+  }
 }
 
+/*TODO*/
+static void
+handle_client_record_lookup(void *cls,
+                            struct GNUNET_SERVER_Client *client,
+                            const struct GNUNET_MessageHeader *message)
+{
+}
 
+/*TODO*/
+static void
+handle_client_record_add(void *cls,
+                         struct GNUNET_SERVER_Client *client,
+                         const struct GNUNET_MessageHeader *message)
+{
+}
+
 /**
  * Process GNS requests.
  *
@@ -124,35 +153,35 @@
 run (void *cls, struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
-       /* The IPC message types */
-       static const struct GNUNET_SERVER_MessageHandler handlers[] = {
-               /* callback, cls, type, size */
-               {&handle_client_record_lookup, NULL, 
GNUNET_MESSAGE_TYPE_GNS_RECORD_LOOKUP,
-                       sizeof (struct GNUNET_GNS_Lookup)},
-               {&handle_client_record_add, NULL, 
GNUNET_MESSAGE_TYPE_GNS_RECORD_ADD,
-                       sizeof (struct GNUNET_GNS_Record)},
-               {NULL, NULL, 0, 0}
-       };
-       
-       nc = GNUNET_SERVER_notification_context_create (server, 1);
+  /* The IPC message types */
+  static const struct GNUNET_SERVER_MessageHandler handlers[] = {
+    /* callback, cls, type, size */
+    {&handle_client_record_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP,
+      0},
+    /*{&handle_client_record_add, NULL, GNUNET_MESSAGE_TYPE_GNS_CLIENT_ADD,
+      0},*/
+    {NULL, NULL, 0, 0}
+  };
+  
+  nc = GNUNET_SERVER_notification_context_create (server, 1);
 
-       /* TODO do some config parsing */
+  /* TODO do some config parsing */
 
-       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 
&shutdown_task,
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
                                 NULL);
-       /**
-        * Do gnunet dns init here
-        * */
-       dns_handle = GNUNET_DNS_connect(c,
-                                                                               
                                                        
GNUNET_DNS_FLAG_PRE_RESOLUTION,
-                                                                               
                                                        &handle_dns_request, /* 
rh */
-                                                                               
                                                        NULL); /* Closure */
-       GNUNET_SERVER_add_handlers (server, handlers);
-       /**
-        * Esp the lookup would require to keep track of the clients' context
-        * See dht.
-        * GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
-        **/
+  /**
+   * Do gnunet dns init here
+   * */
+  dns_handle = GNUNET_DNS_connect(c,
+                                  GNUNET_DNS_FLAG_PRE_RESOLUTION,
+                                  &handle_dns_request, /* rh */
+                                  NULL); /* Closure */
+  GNUNET_SERVER_add_handlers (server, handlers);
+  /**
+   * Esp the lookup would require to keep track of the clients' context
+   * See dht.
+   * GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
+   **/
 }
 
 

Modified: gnunet/src/include/gnunet_dht_service.h
===================================================================
--- gnunet/src/include/gnunet_dht_service.h     2012-02-16 18:30:18 UTC (rev 
19825)
+++ gnunet/src/include/gnunet_dht_service.h     2012-02-16 20:05:40 UTC (rev 
19826)
@@ -272,7 +272,7 @@
  *
  * @param handle The handle to the monitor request returned by monitor_start.
  *
- * On return get_handle will no longer be valid, caller must not use again!!!
+ * On return handle will no longer be valid, caller must not use again!!!
  */
 void
 GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle);

Modified: gnunet/src/include/gnunet_gns_service.h
===================================================================
--- gnunet/src/include/gnunet_gns_service.h     2012-02-16 18:30:18 UTC (rev 
19825)
+++ gnunet/src/include/gnunet_gns_service.h     2012-02-16 20:05:40 UTC (rev 
19826)
@@ -80,7 +80,7 @@
  * @return NULL on error
  */
 struct GNUNET_GNS_Handle *
-GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg
+GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
                     unsigned int ht_len);
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]