gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r19812 - in gnunet/src: gns include
Date: Wed, 15 Feb 2012 14:39:46 +0100

Author: schanzen
Date: 2012-02-15 14:39:46 +0100 (Wed, 15 Feb 2012)
New Revision: 19812

Added:
   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_gns_service.h
Log:
Added preliminary API and stubs for GNS



Added: gnunet/src/gns/gns_api.c
===================================================================
--- gnunet/src/gns/gns_api.c                            (rev 0)
+++ gnunet/src/gns/gns_api.c    2012-02-15 13:39:46 UTC (rev 19812)
@@ -0,0 +1,303 @@
+/*
+     This file is part of GNUnet.
+     (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file gns/gns_api.c
+ * @brief library to access the GNS service
+ * @author Martin Schanzenbach
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_constants.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_hello_lib.h"
+#include "gnunet_protocols.h"
+#include "gnunet_dht_service.h"
+
+#define DEBUG_GNS_API GNUNET_EXTRA_LOGGING
+
+#define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__)
+
+/**
+ * Handle to a Lookup request
+ */
+struct GNUNET_GNS_LookupHandle
+{
+
+  /**
+   * Iterator to call on data receipt
+   */
+  GNUNET_GNS_LookupIterator iter;
+
+  /**
+   * Closure for the iterator callback
+   */
+  void *iter_cls;
+
+  /**
+   * Main handle to this GNS api
+   */
+  struct GNUNET_GNS_Handle *gns_handle;
+
+  /**
+   * Key that this get request is for
+   */
+  GNUNET_HashCode key;
+
+  /**
+   * Unique identifier for this request (for key collisions).
+   */
+  uint64_t unique_id;
+
+};
+
+
+/**
+ * Connection to the GNS service.
+ */
+struct GNUNET_GNS_Handle
+{
+
+  /**
+   * Configuration to use.
+   */
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+  /**
+   * Socket (if available).
+   */
+  struct GNUNET_CLIENT_Connection *client;
+
+  /**
+   * Currently pending transmission request (or NULL).
+   */
+  struct GNUNET_CLIENT_TransmitHandle *th;
+
+  GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
+
+  /**
+   * How quickly should we retry?  Used for exponential back-off on
+   * connect-errors.
+   */
+  struct GNUNET_TIME_Relative retry_time;
+
+  /**
+   * Generator for unique ids.
+   */
+  uint64_t uid_gen;
+
+  /**
+   * Did we start our receive loop yet?
+   */
+  int in_receive;
+};
+
+
+/**
+ * Try to (re)connect to the GNS service.
+ *
+ * @return GNUNET_YES on success, GNUNET_NO on failure.
+ */
+static int
+try_connect (struct GNUNET_GNS_Handle *handle)
+{
+  if (handle->client != NULL)
+    return GNUNET_OK;
+  handle->in_receive = GNUNET_NO;
+  handle->client = GNUNET_CLIENT_connect ("gns", handle->cfg);
+  if (handle->client == NULL)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         _("Failed to connect to the GNS service!\n"));
+    return GNUNET_NO;
+  }
+  return GNUNET_YES;
+}
+
+/**
+ * Try reconnecting to the GNS service.
+ *
+ * @param cls GNUNET_GNS_Handle
+ * @param tc scheduler context
+ */
+static void
+try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_GNS_Handle *handle = cls;
+
+#if DEBUG_DHT
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with GNS %p\n", handle);
+#endif
+  handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value)
+    handle->retry_time = GNUNET_CONSTANTS_SERVICE_RETRY;
+  else
+    handle->retry_time = GNUNET_TIME_relative_multiply (handle->retry_time, 2);
+  if (handle->retry_time.rel_value > 
GNUNET_CONSTANTS_SERVICE_TIMEOUT.rel_value)
+    handle->retry_time = GNUNET_CONSTANTS_SERVICE_TIMEOUT;
+  handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  if (GNUNET_YES != try_connect (handle))
+  {
+#if DEBUG_DHT
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "GNS reconnect failed(!)\n");
+#endif
+    return;
+  }
+  GNUNET_CONTAINER_multihashmap_iterate (handle->active_requests,
+                                         &add_request_to_pending, handle);
+  process_pending_messages (handle);
+}
+
+
+/**
+ * Try reconnecting to the GNS service.
+ *
+ * @param handle handle to gns to (possibly) disconnect and reconnect
+ */
+static void
+do_disconnect (struct GNUNET_GNS_Handle *handle)
+{
+  if (handle->client == NULL)
+    return;
+  GNUNET_assert (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
+  if (NULL != handle->th)
+    GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
+  handle->th = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Disconnecting from GNS service, will try to reconnect in %llu 
ms\n",
+              (unsigned long long) handle->retry_time.rel_value);
+  GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
+  handle->client = NULL;
+  handle->reconnect_task =
+      GNUNET_SCHEDULER_add_delayed (handle->retry_time, &try_reconnect, 
handle);
+}
+
+
+/**
+ * Initialize the connection with the GNS service.
+ *
+ * @param cfg configuration to use
+ * @return handle to the GNS service, or NULL on error
+ */
+struct GNUNET_GNS_Handle *
+GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                    unsigned int ht_len)
+{
+  struct GNUNET_GNS_Handle *handle;
+
+  handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_Handle));
+  handle->cfg = cfg;
+  handle->uid_gen =
+      GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
+  handle->active_requests = GNUNET_CONTAINER_multihashmap_create (ht_len);
+  if (GNUNET_NO == try_connect (handle))
+  {
+    GNUNET_GNS_disconnect (handle);
+    return NULL;
+  }
+  return handle;
+}
+
+
+/**
+ * Shutdown connection with the GNS service.
+ *
+ * @param handle handle of the GNS connection to stop
+ */
+void
+GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
+{
+       /* disco from GNS */
+}
+
+
+/**
+ * Add a new record to the GNS.
+ *
+ * @param handle handle to GNS service
+ * @param key the key to store under
+ * @param desired_replication_level estimate of how many
+ *                nearest peers this request should reach
+ * @param options routing options for this message
+ * @param type type of the value
+ * @param size number of bytes in data; must be less than 64k
+ * @param data the data to store
+ * @param exp desired expiration time for the value
+ * @param timeout how long to wait for transmission of this request
+ * @param cont continuation to call when done (transmitting request to service)
+ * @param cont_cls closure for cont
+ */
+void
+GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle, const GNUNET_HashCode 
* key,
+                uint32_t desired_replication_level,
+                enum GNUNET_DHT_RouteOption options,
+                enum GNUNET_BLOCK_Type type, size_t size, const char *data,
+                struct GNUNET_TIME_Absolute exp,
+                struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task 
cont,
+                void *cont_cls)
+{
+       /* add record to local db, dht; sign etc */
+}
+
+
+/**
+ * Perform an asynchronous Lookup operation on the GNS.
+ *
+ * @param handle handle to the GNS service
+ * @param timeout how long to wait for transmission of this request to the 
service
+ * @param type expected type of the response object
+ * @param key the key to look up
+ * @param desired_replication_level estimate of how many
+                  nearest peers this request should reach
+ * @param options routing options for this message
+ * @param xquery extended query data (can be NULL, depending on type)
+ * @param xquery_size number of bytes in xquery
+ * @param iter function to call on each result
+ * @param iter_cls closure for iter
+ * @return handle to stop the async get
+ */
+struct GNUNET_GNS_LookupHandle *
+GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
+                      struct GNUNET_TIME_Relative timeout,
+                      enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key,
+                      uint32_t desired_replication_level,
+                      enum GNUNET_DHT_RouteOption options, const void *xquery,
+                      size_t xquery_size, GNUNET_GNS_LookupIterator iter,
+                      void *iter_cls)
+{
+  /* look for local entries, start dht lookup, return lookup_handle */
+}
+
+
+/**
+ * Stop async GNS lookup.
+ *
+ * @param lookup_handle handle to the GNS lookup operation to stop
+ */
+void
+GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle)
+{
+  struct GNUNET_DHT_Handle *handle;
+       /* TODO Stop dht lookups */
+}
+
+
+/* end of gns_api.c */

Added: gnunet/src/gns/gnunet-gns-add.c
===================================================================
--- gnunet/src/gns/gnunet-gns-add.c                             (rev 0)
+++ gnunet/src/gns/gnunet-gns-add.c     2012-02-15 13:39:46 UTC (rev 19812)
@@ -0,0 +1,203 @@
+/*
+     This file is part of GNUnet.
+     (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and 
other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file gns/gnunet-gns-add.c
+ * @brief search for data in GNS
+ * @author Martin Schanzenbach
+ */
+#include "platform.h"
+#include "gnunet_gns_service.h"
+
+/**
+ * The type of the record
+ */
+static unsigned int record_type;
+
+/**
+ * The key for the recprd
+ */
+static char *record_key;
+
+/**
+ * User supplied timeout value
+ */
+static unsigned long long timeout_request = 5;
+
+/**
+ * User supplied expiration value
+ */
+static unsigned long long expiration_seconds = 3600;
+
+/**
+ * Desired replication level.
+ */
+static unsigned int replication = 5;
+
+/**
+ * Be verbose
+ */
+static int verbose;
+
+/**
+ * Handle to the GNS
+ */
+static struct GNUNET_GNS_Handle *gns_handle;
+
+
+/**
+ * Global handle of the configuration
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
+ * Global status value
+ */
+static int ret;
+
+/**
+ * The data to insert into the dht
+ */
+static char *data;
+
+static void
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (gns_handle != NULL)
+  {
+    GNUNET_GNS_disconnect (gns_handle);
+    gns_handle = NULL;
+  }
+}
+
+/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ * @param tc context information (why was this task triggered now)
+ */
+void
+message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (verbose)
+    FPRINTF (stderr, "%s",  _("PUT request sent!\n"));
+  GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+}
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be 
NULL!)
+ * @param c configuration
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *c)
+{
+  struct GNUNET_TIME_Relative timeout;
+  struct GNUNET_TIME_Absolute expiration;
+
+  cfg = c;
+
+  if ((record_key == NULL) || (data == NULL))
+  {
+    FPRINTF (stderr, "%s",  _("Must provide KEY and DATA for GNS record!\n"));
+    ret = 1;
+    return;
+  }
+
+  gns_handle = GNUNET_GNS_connect (cfg, 1);
+  if (gns_handle == NULL)
+  {
+    FPRINTF (stderr, _("Could not connect to %s service!\n"), "GNS");
+    ret = 1;
+    return;
+  }
+  else if (verbose)
+    FPRINTF (stderr, _("Connected to %s service!\n"), "GNS");
+
+  if (query_type == GNUNET_BLOCK_TYPE_ANY)      /* Type of data not set */
+    query_type = GNUNET_BLOCK_TYPE_TEST;
+
+  timeout =
+      GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 
timeout_request);
+  expiration =
+      GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
+                                        (GNUNET_TIME_UNIT_SECONDS,
+                                         expiration_seconds));
+
+  if (verbose)
+    FPRINTF (stderr, _("Issuing add request for `%s' with data `%s'!\n"),
+             record_key, data);
+  GNUNET_GNS_add (gns_handle, &record_key, replication, GNUNET_DHT_RO_NONE, 
record_type,
+                  strlen (data), data, expiration, timeout, &message_sent_cont,
+                  NULL);
+
+}
+
+
+/**
+ * gnunet-gns-add command line options
+ */
+static struct GNUNET_GETOPT_CommandLineOption options[] = {
+  {'d', "data", "DATA",
+   gettext_noop ("the data to insert under the key"),
+   1, &GNUNET_GETOPT_set_string, &data},
+  {'e', "expiration", "EXPIRATION",
+   gettext_noop ("how long to store this entry in the GNS (in seconds)"),
+   1, &GNUNET_GETOPT_set_ulong, &expiration_seconds},
+  {'k', "key", "KEY",
+   gettext_noop ("the record key"),
+   1, &GNUNET_GETOPT_set_string, &record_key},
+  {'r', "replication", "LEVEL",
+   gettext_noop ("how many replicas to create"),
+   1, &GNUNET_GETOPT_set_uint, &replication},
+  {'t', "type", "TYPE",
+   gettext_noop ("the type to insert record as"),
+   1, &GNUNET_GETOPT_set_uint, &record_type},
+  {'T', "timeout", "TIMEOUT",
+   gettext_noop ("how long to execute this query before giving up?"),
+   1, &GNUNET_GETOPT_set_ulong, &timeout_request},
+  {'V', "verbose", NULL,
+   gettext_noop ("be verbose (print progress information)"),
+   0, &GNUNET_GETOPT_set_one, &verbose},
+  GNUNET_GETOPT_OPTION_END
+};
+
+
+/**
+ * Entry point for gnunet-gns-add
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc, char *const *argv)
+{
+  return (GNUNET_OK ==
+          GNUNET_PROGRAM_run (argc, argv, "gnunet-gns-add",
+                              gettext_noop
+                              ("Issue an add to the GNUnet NS of DATA under 
KEY."),
+                              options, &run, NULL)) ? ret : 1;
+}
+
+/* end of gnunet-gns-put.c */

Added: gnunet/src/gns/gnunet-gns-lookup.c
===================================================================
--- gnunet/src/gns/gnunet-gns-lookup.c                          (rev 0)
+++ gnunet/src/gns/gnunet-gns-lookup.c  2012-02-15 13:39:46 UTC (rev 19812)
@@ -0,0 +1,235 @@
+/*
+     This file is part of GNUnet.
+     (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and 
other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file gns/gnunet-gns-lookup.c
+ * @brief search for records in GNS
+ * @author Martin Schanzenbach
+ */
+#include "platform.h"
+#include "gnunet_gns_service.h"
+
+/**
+ * The type of the query
+ */
+static unsigned int query_type;
+
+/**
+ * Desired replication level
+ */
+static unsigned int replication = 5;
+
+/**
+ * The key for the query
+ */
+static char *query_key;
+
+/**
+ * User supplied timeout value (in seconds)
+ */
+static unsigned long long timeout_request = 5;
+
+/**
+ * When this request should really die
+ */
+struct GNUNET_TIME_Absolute absolute_timeout;
+
+/**
+ * Be verbose
+ */
+static int verbose;
+
+/**
+ * Handle to the GNS
+ */
+static struct GNUNET_GNS_Handle *gns_handle;
+
+/**
+ * Global handle of the configuration
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
+ * Handle for the lookup request
+ */
+static struct GNUNET_GNS_LookupHandle *lookup_handle;
+
+/**
+ * Count of results found
+ */
+static unsigned int result_count;
+
+/**
+ * Global status value
+ */
+static int ret;
+
+
+static void
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (gns_handle != NULL)
+  {
+    GNUNET_GNS_disconnect (gns_handle);
+    gns_handle = NULL;
+  }
+}
+
+
+static void
+cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (lookup_handle != NULL)
+  {
+    GNUNET_GNS_lookup_stop (lookup_handle);
+    lookup_handle = NULL;
+  }
+  GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+}
+
+
+/**
+ * Iterator called on each result obtained for a GNS
+ * operation that expects a reply
+ *
+ * @param cls closure
+ * @param exp when will this value expire
+ * @param key key of the result
+ * @param get_path peers on reply path (or NULL if not recorded)
+ * @param get_path_length number of entries in get_path
+ * @param put_path peers on the PUT path (or NULL if not recorded)
+ * @param put_path_length number of entries in get_path
+ * @param type type of the result
+ * @param size number of bytes in data
+ * @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)
+{
+  FPRINTF (stdout, "Result %d, type %d:\n%.*s\n", result_count, type,
+           (unsigned int) size, (char *) data);
+  result_count++;
+}
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be 
NULL!)
+ * @param c configuration
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *c)
+{
+  struct GNUNET_TIME_Relative timeout;
+  GNUNET_HashCode key;
+
+  cfg = c;
+
+  if (query_key == NULL)
+  {
+    if (verbose)
+      FPRINTF (stderr, "%s",  "Must provide key for GNS lookup!\n");
+    ret = 1;
+    return;
+  }
+
+  lookup_handle = GNUNET_GNS_connect (cfg, 1);
+
+  if (lookup_handle == NULL)
+  {
+    if (verbose)
+      FPRINTF (stderr, "%s",  "Couldn't connect to GNS service!\n");
+    ret = 1;
+    return;
+  }
+  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);
+
+  if (verbose)
+    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);
+
+}
+
+
+/**
+ * gnunet-dht-get command line options
+ */
+static struct GNUNET_GETOPT_CommandLineOption options[] = {
+  {'k', "key", "KEY",
+   gettext_noop ("the query key"),
+   1, &GNUNET_GETOPT_set_string, &query_key},
+  {'r', "replication", "LEVEL",
+   gettext_noop ("how many parallel requests (replicas) to create"),
+   1, &GNUNET_GETOPT_set_uint, &replication},
+  {'t', "type", "TYPE",
+   gettext_noop ("the type of data to look for"),
+   1, &GNUNET_GETOPT_set_uint, &query_type},
+  {'T', "timeout", "TIMEOUT",
+   gettext_noop ("how long to execute this query before giving up?"),
+   1, &GNUNET_GETOPT_set_ulong, &timeout_request},
+  {'V', "verbose", NULL,
+   gettext_noop ("be verbose (print progress information)"),
+   0, &GNUNET_GETOPT_set_one, &verbose},
+  GNUNET_GETOPT_OPTION_END
+};
+
+
+/**
+ * Entry point for gnunet-gns-lookup
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc, char *const *argv)
+{
+  return (GNUNET_OK ==
+          GNUNET_PROGRAM_run (argc, argv, "gnunet-gns-get",
+                              gettext_noop
+                              ("Issue a request to the GNUnet Naming System, 
prints results."),
+                              options, &run, NULL)) ? ret : 1;
+}
+
+/* end of gnunet-gns-lookup.c */

Added: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c                         (rev 0)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-02-15 13:39:46 UTC (rev 19812)
@@ -0,0 +1,93 @@
+/*
+     This file is part of GNUnet.
+     (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file gns/gnunet-service-gns.c
+ * @brief GNUnet GNS service
+ * @author Martin Schanzenbach
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_transport_service.h"
+#include "gnunet_gns_service.h"
+#include "gnunet-service-gns.h"
+
+
+/**
+ * Our handle to the BLOCK library.
+ */
+struct GNUNET_BLOCK_Context *GDS_block_context;
+
+/**
+ * The configuration the GNS service is running with
+ */
+const struct GNUNET_CONFIGURATION_Handle *GDS_cfg;
+
+/**
+ * Task run during shutdown.
+ *
+ * @param cls unused
+ * @param tc unused
+ */
+static void
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+       /* TODO: Do sth here */
+}
+
+
+/**
+ * Process GNS requests.
+ *
+ * @param cls closure
+ * @param server the initialized server
+ * @param c configuration to use
+ */
+static void
+run (void *cls, struct GNUNET_SERVER_Handle *server,
+     const struct GNUNET_CONFIGURATION_Handle *c)
+{
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
+                                NULL);
+       /* Do gnunet dns init here */
+}
+
+
+/**
+ * The main function for the GNS service.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc, char *const *argv)
+{
+  int ret;
+
+  ret =
+      (GNUNET_OK ==
+       GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run,
+                           NULL)) ? 0 : 1;
+  GDS_CLIENTS_done ();
+  return ret;
+}
+
+/* end of gnunet-service-gns.c */

Added: gnunet/src/include/gnunet_gns_service.h
===================================================================
--- gnunet/src/include/gnunet_gns_service.h                             (rev 0)
+++ gnunet/src/include/gnunet_gns_service.h     2012-02-15 13:39:46 UTC (rev 
19812)
@@ -0,0 +1,173 @@
+/*
+      This file is part of GNUnet
+      (C) 2004, 2005, 2006, 2008, 2009, 2011 Christian Grothoff (and other 
contributing authors)
+
+      GNUnet is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 3, or (at your
+      option) any later version.
+
+      GNUnet is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with GNUnet; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file include/gnunet_gns_service.h
+ * @brief API to the GNS service
+ * @author Martin Schanzenbach
+ */
+
+#ifndef GNUNET_GNS_SERVICE_H
+#define GNUNET_GNS_SERVICE_H
+
+#include "gnunet_util_lib.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#if 0                           /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+
+/**
+ * Connection to the GNS service.
+ */
+struct GNUNET_GNS_Handle;
+
+/**
+ * Handle to control a get operation.
+ */
+struct GNUNET_GNS_LookupHandle;
+
+/**
+ * Initialize the connection with the GNS service.
+ *
+ * @param cfg configuration to use
+ * @return NULL on error
+ */
+struct GNUNET_GNS_Handle *
+GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
+
+
+/**
+ * Shutdown connection with the GNS service.
+ *
+ * @param handle connection to shut down
+ */
+void
+GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
+
+
+/* *************** Standard API: add and lookup ******************* */
+
+/**
+ * Perform an add operation storing records in the GNS.
+ *
+ * @param handle handle to GNS service
+ * @param key the key to store under
+ * @param desired_replication_level estimate of how many
+ *                nearest peers this request should reach
+ * @param options routing options for this message
+ * @param type type of the value
+ * @param size number of bytes in data; must be less than 64k
+ * @param data the data to store
+ * @param exp desired expiration time for the value
+ * @param timeout how long to wait for transmission of this request
+ * @param cont continuation to call when done (transmitting request to service)
+ * @param cont_cls closure for cont
+ */
+void
+GNUNET_GNS_add (struct GNUNET_GNS_Handle *handle, const GNUNET_HashCode * key,
+                uint32_t desired_replication_level,
+                enum GNUNET_DHT_RouteOption options,
+                enum GNUNET_BLOCK_Type type, size_t size, const char *data,
+                struct GNUNET_TIME_Absolute exp,
+                struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task 
cont,
+                void *cont_cls);
+
+
+/**
+ * Iterator called on each result obtained for a GNS
+ * operation that expects a reply TODO: eh?
+ *
+ * @param cls closure
+ * @param exp when will this value expire
+ * @param key key of the result
+ * @param get_path peers on reply path (or NULL if not recorded)
+ * @param get_path_length number of entries in get_path
+ * @param put_path peers on the PUT path (or NULL if not recorded)
+ * @param put_path_length number of entries in get_path
+ * @param type type of the result
+ * @param size number of bytes in data
+ * @param data pointer to the result data
+ */
+typedef void (*GNUNET_GNS_LookupIterator) (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);
+
+
+
+/**
+ * Perform an asynchronous lookup operation on the GNS.
+ *
+ * @param handle handle to the GNS service
+ * @param timeout how long to wait for transmission of this request to the 
service
+ * @param type expected type of the response object
+ * @param key the key to look up
+ * @param desired_replication_level estimate of how many
+                  nearest peers this request should reach
+ * @param options routing options for this message
+ * @param xquery extended query data (can be NULL, depending on type)
+ * @param xquery_size number of bytes in xquery
+ * @param iter function to call on each result
+ * @param iter_cls closure for iter
+ *
+ * @return handle to stop the async get
+ */
+struct GNUNET_GNS_LookupHandle *
+GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
+                      struct GNUNET_TIME_Relative timeout,
+                      enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key,
+                      uint32_t desired_replication_level,
+                      enum GNUNET_DHT_RouteOption options, const void *xquery,
+                      size_t xquery_size, GNUNET_GNS_LookupIterator iter,
+                      void *iter_cls);
+
+
+/**
+ * Stop async GNS lookup.  Frees associated resources.
+ *
+ * @param lookup_handle lookup operation to stop.
+ *
+ * On return lookup_handle will no longer be valid, caller
+ * must not use again!!!
+ */
+void
+GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle);
+
+
+#if 0                           /* keep Emacsens' auto-indent happy */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+/* gnunet_gns_service.h */




reply via email to

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