gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r28012 - in gnunet/src: . identity


From: gnunet
Subject: [GNUnet-SVN] r28012 - in gnunet/src: . identity
Date: Sun, 14 Jul 2013 20:20:56 +0200

Author: grothoff
Date: 2013-07-14 20:20:55 +0200 (Sun, 14 Jul 2013)
New Revision: 28012

Added:
   gnunet/src/identity/
   gnunet/src/identity/Makefile.am
   gnunet/src/identity/gnunet-identity.c
   gnunet/src/identity/gnunet-service-identity.c
   gnunet/src/identity/identity.conf.in
   gnunet/src/identity/identity.h
   gnunet/src/identity/identity_api.c
Log:
-skeleton for identity service

Added: gnunet/src/identity/Makefile.am
===================================================================
--- gnunet/src/identity/Makefile.am                             (rev 0)
+++ gnunet/src/identity/Makefile.am     2013-07-14 18:20:55 UTC (rev 28012)
@@ -0,0 +1,77 @@
+INCLUDES = -I$(top_srcdir)/src/include
+
+if MINGW
+ WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols 
+endif
+
+if USE_COVERAGE
+  AM_CFLAGS = --coverage -O0
+  XLIB = -lgcov
+endif
+
+pkgcfgdir= $(pkgdatadir)/config.d/
+
+libexecdir= $(pkglibdir)/libexec/
+
+pkgcfg_DATA = \
+  identity.conf
+
+
+lib_LTLIBRARIES = libgnunetidentity.la
+
+libgnunetidentity_la_SOURCES = \
+  identity_api.c identity.h
+libgnunetidentity_la_LIBADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(GN_LIBINTL) $(XLIB)
+libgnunetidentity_la_LDFLAGS = \
+  $(GN_LIB_LDFLAGS)  $(WINFLAGS) \
+  -version-info 0:0:0
+
+bin_PROGRAMS = \
+ gnunet-identity
+
+libexec_PROGRAMS = \
+ gnunet-service-identity 
+
+gnunet_service_identity_SOURCES = \
+ gnunet-service-identity.c         
+gnunet_service_identity_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/statistics/libgnunetstatistics.la \
+  $(GN_LIBINTL)
+gnunet_service_identity_DEPENDENCIES = \
+  libgnunetidentity.la                          
+
+gnunet_identity_SOURCES = \
+ gnunet-identity.c         
+gnunet_identity_LDADD = \
+  $(top_builddir)/src/identity/libgnunetidentity.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/statistics/libgnunetstatistics.la \
+  $(GN_LIBINTL)
+gnunet_service_identity_DEPENDENCIES = \
+  libgnunetidentity.la                          
+
+
+if HAVE_TESTING
+check_PROGRAMS = \
+ test_identity_api 
+endif
+
+if ENABLE_TEST_RUN
+TESTS = $(check_PROGRAMS) 
+endif
+
+test_identity_api_SOURCES = \
+ test_identity_api.c
+test_identity_api_LDADD = \
+  $(top_builddir)/src/identity/libgnunetidentity.la \
+  $(top_builddir)/src/testing/libgnunettesting.la \
+  $(top_builddir)/src/util/libgnunetutil.la 
+
+
+EXTRA_DIST = \
+  test_identity.conf 
+
+

Added: gnunet/src/identity/gnunet-identity.c
===================================================================
--- gnunet/src/identity/gnunet-identity.c                               (rev 0)
+++ gnunet/src/identity/gnunet-identity.c       2013-07-14 18:20:55 UTC (rev 
28012)
@@ -0,0 +1,106 @@
+/*
+     This file is part of GNUnet.
+     (C) 2013 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 identity/gnunet-identity.c
+ * @brief IDENTITY monitoring command line tool
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_identity_service.h"
+
+/**
+ * Handle to IDENTITY service.
+ */
+static struct GNUNET_IDENTITY_Handle *sh;
+
+/**
+ * Was verbose specified?
+ */
+static int verbose;
+
+
+/**
+ * Task run on shutdown.
+ *
+ * @param cls NULL
+ * @param tc unused
+ */
+static void
+shutdown_task (void *cls,
+              const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  GNUNET_IDENTITY_disconnect (sh);
+  sh = 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 cfg configuration
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  sh = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                               &shutdown_task, NULL);
+}
+
+
+/**
+ * The main function.
+ *
+ * @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 res;
+
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    {'V', "verbose", NULL,
+     gettext_noop ("verbose output"),
+     0, &GNUNET_GETOPT_set_one, &verbose},
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+    return 2;
+
+  res = GNUNET_PROGRAM_run (argc, argv, "gnunet-identity",
+                           gettext_noop ("Print information about IDENTITY 
state"), 
+                           options, &run,
+                           NULL);
+  GNUNET_free ((void *) argv);
+
+  if (GNUNET_OK != res)
+    return 1;
+  return 0;
+}
+
+/* end of gnunet-identity.c */

Added: gnunet/src/identity/gnunet-service-identity.c
===================================================================
--- gnunet/src/identity/gnunet-service-identity.c                               
(rev 0)
+++ gnunet/src/identity/gnunet-service-identity.c       2013-07-14 18:20:55 UTC 
(rev 28012)
@@ -0,0 +1,97 @@
+/*
+  This file is part of GNUnet.
+  (C) 2013 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 identity/gnunet-service-identity.c
+ * @brief network size estimation service
+ * @author Nathan Evans
+ * @author Christian Grothoff
+ *
+ * The purpose of this service is to estimate the size of the network.
+ * Given a specified interval, each peer hashes the most recent
+ * timestamp which is evenly divisible by that interval.  This hash is
+ * compared in distance to the peer identity to choose an offset.  The
+ * closer the peer identity to the hashed timestamp, the earlier the
+ * peer sends out a "nearest peer" message.  The closest peer's
+ * message should thus be received before any others, which stops
+ * those peer from sending their messages at a later duration.  So
+ * every peer should receive the same nearest peer message, and from
+ * this can calculate the expected number of peers in the network.
+ */
+#include "platform.h"
+#include <math.h>
+#include "gnunet_util_lib.h"
+#include "gnunet_constants.h"
+#include "gnunet_protocols.h"
+#include "gnunet_signatures.h"
+#include "gnunet_statistics_service.h"
+#include "gnunet_identity_service.h"
+#include "identity.h"
+
+/**
+ * Handle to our current configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
+ * Handle to the statistics service.
+ */
+static struct GNUNET_STATISTICS_Handle *stats;
+
+
+/**
+ * Handle network size estimate clients.
+ *
+ * @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)
+{
+  static const struct GNUNET_SERVER_MessageHandler handlers[] = {
+    // {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_START, 
sizeof (struct GNUNET_MessageHeader)},
+    {NULL, NULL, 0, 0}
+  };
+
+  cfg = c;
+  stats = GNUNET_STATISTICS_create ("identity", cfg);
+}
+
+
+/**
+ * The main function for the network size estimation 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)
+{
+  return (GNUNET_OK ==
+          GNUNET_SERVICE_run (argc, argv, "identity", 
GNUNET_SERVICE_OPTION_NONE,
+                              &run, NULL)) ? 0 : 1;
+}
+
+
+/* end of gnunet-service-identity.c */

Added: gnunet/src/identity/identity.conf.in
===================================================================
--- gnunet/src/identity/identity.conf.in                                (rev 0)
+++ gnunet/src/identity/identity.conf.in        2013-07-14 18:20:55 UTC (rev 
28012)
@@ -0,0 +1,39 @@
+[nse]
+AUTOSTART = YES
address@hidden@PORT = 2097
+HOSTNAME = localhost
+HOME = $SERVICEHOME
+BINARY = gnunet-service-nse
+ACCEPT_FROM = 127.0.0.1;
+ACCEPT_FROM6 = ::1;
+UNIXPATH = /tmp/test-nse-service-nse.unix
+UNIX_MATCH_UID = NO
+UNIX_MATCH_GID = YES
+PROOFFILE = $SERVICEHOME/.nse-proof
+
+# The directory where the NSE services logs timestamps everytime 
+# a size estime flooding message is received
+# This option is only used for benchmarking, not in production.
+HISTOGRAM_DIR = $SERVICEHOME
+
+# How 'slowly' should the proof-of-work be constructed (delay
+# between rounds); sane values between 0 and ~1000.
+# It should rarely make sense to change this value.
+# Only systems with slow CPUs where 5ms is a long time might
+# want it to be reduced.
+WORKDELAY = 5 ms
+
+# Note: changing any of the values below will make this peer
+# completely incompatible with other peers!
+
+# How often do peers exchange network size messages?
+# Note that all peers MUST use the same interval.
+# DO NOT CHANGE THIS VALUE, doing so will break the protocol!
+INTERVAL = 1 h
+
+# 2^22 hash operations take about 2-3h on a modern i7 (single-core)
+# for SCRYPT; with 2ms/op and 5ms workdelay, we can expect
+# the POW calculation to be done by a high-end peer in about 6h
+# DO NOT CHANGE THIS VALUE, doing so will break the protocol!
+WORKBITS = 22
+

Added: gnunet/src/identity/identity.h
===================================================================
--- gnunet/src/identity/identity.h                              (rev 0)
+++ gnunet/src/identity/identity.h      2013-07-14 18:20:55 UTC (rev 28012)
@@ -0,0 +1,57 @@
+/*
+     This file is part of GNUnet.
+     (C) 2013 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 Liceidentity 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 Liceidentity for more details.
+
+     You should have received a copy of the GNU General Public Liceidentity
+     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.
+*/
+
+/**
+ * @author Christian Grothoff
+ * @file identity/identity.h
+ *
+ * @brief Common type definitions for the identity
+ *        service and API.
+ */
+#ifndef IDENTITY_H
+#define IDENTITY_H
+
+#include "gnunet_common.h"
+
+/**
+ * Generate debug-level log messages?
+ */
+#define DEBUG_IDENTITY GNUNET_EXTRA_LOGGING
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Network size estimate sent from the service
+ * to clients.  Contains the current size estimate
+ * (or 0 if none has been calculated) and the
+ * standard deviation of known estimates.
+ *
+ */
+struct GNUNET_IDENTITY_XXXMessage
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_IDENTITY_XXX
+   */
+  struct GNUNET_MessageHeader header;
+
+};
+GNUNET_NETWORK_STRUCT_END
+
+#endif

Added: gnunet/src/identity/identity_api.c
===================================================================
--- gnunet/src/identity/identity_api.c                          (rev 0)
+++ gnunet/src/identity/identity_api.c  2013-07-14 18:20:55 UTC (rev 28012)
@@ -0,0 +1,239 @@
+/*
+     This file is part of GNUnet.
+     (C) 2013 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 Liceidentity 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 Liceidentity for more details.
+
+     You should have received a copy of the GNU General Public Liceidentity
+     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 identity/identity_api.c
+ * @brief api to get information from the network size estimation service
+ * @author Nathan Evans
+ */
+#include "platform.h"
+#include "gnunet_client_lib.h"
+#include "gnunet_constants.h"
+#include "gnunet_container_lib.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_hello_lib.h"
+#include "gnunet_protocols.h"
+#include "gnunet_server_lib.h"
+#include "gnunet_time_lib.h"
+#include "gnunet_identity_service.h"
+#include "identity.h"
+
+#define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__)
+
+/**
+ * Handle for the service.
+ */
+struct GNUNET_IDENTITY_Handle
+{
+  /**
+   * Configuration to use.
+   */
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+  /**
+   * Socket (if available).
+   */
+  struct GNUNET_CLIENT_Connection *client;
+
+  /**
+   * Currently pending transmission request.
+   */
+  struct GNUNET_CLIENT_TransmitHandle *th;
+
+  /**
+   * Task doing exponential back-off trying to reconnect.
+   */
+  GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
+
+  /**
+   * Time for next connect retry.
+   */
+  struct GNUNET_TIME_Relative reconnect_delay;
+
+};
+
+
+/**
+ * Try again to connect to network size estimation service.
+ *
+ * @param cls the handle to the transport service
+ * @param tc scheduler context
+ */
+static void
+reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+
+/**
+ * Type of a function to call when we receive a message
+ * from the service.
+ *
+ * @param cls closure
+ * @param msg message received, NULL on timeout or fatal error
+ */
+static void
+message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
+{
+  struct GNUNET_IDENTITY_Handle *h = cls;
+  const struct GNUNET_IDENTITY_ClientMessage *client_msg;
+
+  if (msg == NULL)
+  {
+    /* Error, timeout, death */
+    GNUNET_CLIENT_disconnect (h->client);
+    h->client = NULL;
+    h->reconnect_task =
+        GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
+    return;
+  }
+  // FIXME: process...
+  GNUNET_CLIENT_receive (h->client, &message_handler, h,
+                         GNUNET_TIME_UNIT_FOREVER_REL);
+}
+
+
+
+/**
+ * Reschedule a connect attempt to the service.
+ *
+ * @param h transport service to reconnect
+ */
+static void
+reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
+{
+  GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
+
+  if (NULL != h->th)
+  {
+    GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+    h->th = NULL;
+  }
+  if (NULL != h->client)
+  {
+    GNUNET_CLIENT_disconnect (h->client);
+    h->client = NULL;
+  }
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Scheduling task to reconnect to identity service in %llu ms.\n",
+       h->reconnect_delay.rel_value);
+  h->reconnect_task =
+      GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
+  h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
+}
+
+
+/**
+ * Transmit START message to service.
+ *
+ * @param cls unused
+ * @param size number of bytes available in buf
+ * @param buf where to copy the message
+ * @return number of bytes copied to buf
+ */
+static size_t
+send_start (void *cls, size_t size, void *buf)
+{
+  return sizeof (struct GNUNET_MessageHeader);
+}
+
+
+/**
+ * Try again to connect to network size estimation service.
+ *
+ * @param cls the handle to the transport service
+ * @param tc scheduler context
+ */
+static void
+reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_IDENTITY_Handle *h = cls;
+
+  h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+  {
+    /* shutdown, just give up */
+    return;
+  }
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Connecting to network size estimation service.\n");
+  GNUNET_assert (h->client == NULL);
+  h->client = GNUNET_CLIENT_connect ("identity", h->cfg);
+  GNUNET_assert (h->client != NULL);
+
+  h->th =
+      GNUNET_CLIENT_notify_transmit_ready (h->client,
+                                           sizeof (struct 
GNUNET_MessageHeader),
+                                           GNUNET_TIME_UNIT_FOREVER_REL,
+                                           GNUNET_NO, &send_start, h);
+  GNUNET_assert (h->th != NULL);
+}
+
+
+/**
+ * Connect to the identity service.
+ *
+ * @param cfg the configuration to use
+ * @param cb function to call on all identity events, can be NULL
+ * @param cb_cls closure for 'cb'
+ * @return handle to use
+ */
+struct GNUNET_IDENTITY_Handle *
+GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                        GNUNET_IDENTITY_Callback cb,
+                        void *cb_cls)
+{
+  struct GNUNET_IDENTITY_Handle *ret;
+
+  ret = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Handle));
+  ret->cfg = cfg;
+  ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
+  ret->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, ret);
+  return ret;
+}
+
+
+/**
+ * Disconnect from identity service
+ *
+ * @param h handle to destroy
+ */
+void
+GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h)
+{
+  GNUNET_assert (NULL != h);
+  if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
+  {
+    GNUNET_SCHEDULER_cancel (h->reconnect_task);
+    h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+  if (h->th != NULL)
+  {
+    GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+    h->th = NULL;
+  }
+  if (h->client != NULL)
+  {
+    GNUNET_CLIENT_disconnect (h->client);
+    h->client = NULL;
+  }
+  GNUNET_free (h);
+}
+
+/* end of identity_api.c */




reply via email to

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