gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r6924 - in GNUnet/src/applications/fs: . pseudonyms


From: gnunet
Subject: [GNUnet-SVN] r6924 - in GNUnet/src/applications/fs: . pseudonyms
Date: Thu, 29 May 2008 21:36:06 -0600 (MDT)

Author: grothoff
Date: 2008-05-29 21:36:04 -0600 (Thu, 29 May 2008)
New Revision: 6924

Added:
   GNUnet/src/applications/fs/pseudonyms/
   GNUnet/src/applications/fs/pseudonyms/Makefile.am
   GNUnet/src/applications/fs/pseudonyms/check.conf
   GNUnet/src/applications/fs/pseudonyms/common.c
   GNUnet/src/applications/fs/pseudonyms/common.h
   GNUnet/src/applications/fs/pseudonyms/info.c
   GNUnet/src/applications/fs/pseudonyms/info.h
   GNUnet/src/applications/fs/pseudonyms/info_test.c
   GNUnet/src/applications/fs/pseudonyms/names.c
   GNUnet/src/applications/fs/pseudonyms/notification.c
   GNUnet/src/applications/fs/pseudonyms/notification.h
Log:
moving pseudonym support into new library

Added: GNUnet/src/applications/fs/pseudonyms/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/pseudonyms/Makefile.am                           
(rev 0)
+++ GNUnet/src/applications/fs/pseudonyms/Makefile.am   2008-05-30 03:36:04 UTC 
(rev 6924)
@@ -0,0 +1,29 @@
+INCLUDES = -I$(top_srcdir)/src/include
+
+lib_LTLIBRARIES = \
+  libgnunetpseudonym.la 
+
+libgnunetpseudonym_la_SOURCES = \
+  common.c common.h \
+  names.c \
+  info.c info.h \
+  notification.c  notification.h 
+libgnunetpseudonym_la_LIBADD = \
+ $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
+ $(top_builddir)/src/util/libgnunetutil.la 
+
+check_PROGRAMS = \
+  info_test
+
+TESTS = $(check_PROGRAMS)
+
+EXTRA_DIST = check.conf 
+
+info_test_SOURCES = \
+  info_test.c 
+info_test_LDADD = \
+  $(top_builddir)/src/applications/fs/pseudonyms/libgnunetpseudonym.la \
+  $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
+  $(top_builddir)/src/util/libgnunetutil.la 
+
+

Copied: GNUnet/src/applications/fs/pseudonyms/check.conf (from rev 6923, 
GNUnet/src/applications/fs/namespace/check.conf)
===================================================================
--- GNUnet/src/applications/fs/pseudonyms/check.conf                            
(rev 0)
+++ GNUnet/src/applications/fs/pseudonyms/check.conf    2008-05-30 03:36:04 UTC 
(rev 6924)
@@ -0,0 +1,16 @@
+# General settings
+[GNUNET]
+GNUNET_HOME = "/tmp/gnunet-pseudonym-test"
+LOGLEVEL = "WARNING"
+LOGFILE = ""
+PROCESS-PRIORITY = "NORMAL"
+
+# Network options for the clients
+[NETWORK]
+HOST = "localhost:2087"
+
+
+[TESTING]
+WEAKRANDOM = YES
+
+

Copied: GNUnet/src/applications/fs/pseudonyms/common.c (from rev 6923, 
GNUnet/src/applications/fs/namespace/common.c)
===================================================================
--- GNUnet/src/applications/fs/pseudonyms/common.c                              
(rev 0)
+++ GNUnet/src/applications/fs/pseudonyms/common.c      2008-05-30 03:36:04 UTC 
(rev 6924)
@@ -0,0 +1,68 @@
+/*
+     This file is part of GNUnet
+     (C) 2003, 2004, 2005, 2006, 2007, 2008 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 2, 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 applications/fs/namespace/common.c
+ * @brief helper functions
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_directories.h"
+#include "common.h"
+
+/**
+ * Get the filename (or directory name) for the given
+ * pseudonym identifier and directory prefix.
+ */
+char *
+GNUNET_PSEUDO_internal_get_data_filename_ (struct GNUNET_GE_Context *ectx,
+                                       struct GNUNET_GC_Configuration *cfg,
+                                       const char *prefix,
+                                       const GNUNET_HashCode * psid)
+{
+  char *tmp;
+  char *ret;
+  GNUNET_EncName enc;
+
+  GNUNET_GC_get_configuration_value_filename (cfg,
+                                              "GNUNET",
+                                              "GNUNET_HOME",
+                                              GNUNET_DEFAULT_HOME_DIRECTORY,
+                                              &tmp);
+  ret =
+    GNUNET_malloc (strlen (tmp) + strlen (prefix) +
+                   sizeof (GNUNET_EncName) + 20);
+  strcpy (ret, tmp);
+  GNUNET_free (tmp);
+  if (ret[strlen (ret) - 1] != DIR_SEPARATOR)
+    strcat (ret, DIR_SEPARATOR_STR);
+  strcat (ret, prefix);
+  GNUNET_disk_directory_create (ectx, ret);
+  if (psid != NULL)
+    {
+      GNUNET_hash_to_enc (psid, &enc);
+      strcat (ret, (const char *) &enc);
+    }
+  return ret;
+}
+
+/* end of common.c */

Copied: GNUnet/src/applications/fs/pseudonyms/common.h (from rev 6923, 
GNUnet/src/applications/fs/namespace/common.h)
===================================================================
--- GNUnet/src/applications/fs/pseudonyms/common.h                              
(rev 0)
+++ GNUnet/src/applications/fs/pseudonyms/common.h      2008-05-30 03:36:04 UTC 
(rev 6924)
@@ -0,0 +1,48 @@
+/*
+     This file is part of GNUnet
+     (C) 2003, 2004, 2005, 2006, 2007, 2008 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 2, 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 applications/fs/pseudonyms/common.h
+ * @brief helper functions
+ * @author Christian Grothoff
+ */
+
+
+#include "gnunet_pseudonym_lib.h"
+
+#ifndef PS_COMMON_H
+#define PS_COMMON_H
+
+#define PS_METADATA_DIR "data" DIR_SEPARATOR_STR "pseudonyms/metadata" 
DIR_SEPARATOR_STR
+#define PS_NAMES_DIR    "data" DIR_SEPARATOR_STR "pseudonyms/names"    
DIR_SEPARATOR_STR
+
+/**
+ * Get the filename (or directory name) for the given
+ * pseudonym identifier and directory prefix.
+ *
+ * @param prefix PS_METADATA_DIR or PS_NAMES_DIR 
+ * @param psid maybe NULL
+ */
+char *GNUNET_PSEUDO_internal_get_data_filename_ (struct GNUNET_GE_Context 
*ectx,
+                                                struct GNUNET_GC_Configuration
+                                                *cfg, const char *prefix,
+                                                const GNUNET_HashCode * psid);
+
+#endif

Copied: GNUnet/src/applications/fs/pseudonyms/info.c (from rev 6923, 
GNUnet/src/applications/fs/namespace/namespace_info.c)
===================================================================
--- GNUnet/src/applications/fs/pseudonyms/info.c                                
(rev 0)
+++ GNUnet/src/applications/fs/pseudonyms/info.c        2008-05-30 03:36:04 UTC 
(rev 6924)
@@ -0,0 +1,308 @@
+/*
+     This file is part of GNUnet
+     (C) 2003, 2004, 2005, 2006, 2007, 2008 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 2, 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 applications/fs/pseudonym/info.c
+ * @brief keeping track of pseudonyms and metadata about them
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_directories.h"
+#include "gnunet_pseudonym_lib.h"
+#include "gnunet_util.h"
+#include "info.h"
+#include "notification.h"
+#include "common.h"
+
+
+static void
+write_pseudonym_info (struct GNUNET_GE_Context *ectx,
+                      struct GNUNET_GC_Configuration *cfg,
+                      const GNUNET_HashCode * nsid,
+                      const struct GNUNET_ECRS_MetaData *meta,
+                      int ranking, 
+                     const char *ns_name)
+{
+  unsigned int size;
+  unsigned int tag;
+  unsigned int off;
+  char *buf;
+  char *fn;
+
+  fn = GNUNET_PSEUDO_internal_get_data_filename_ (ectx,
+                                                 cfg,
+                                                 PS_METADATA_DIR, nsid);
+  size =
+    GNUNET_ECRS_meta_data_get_serialized_size (meta,
+                                               GNUNET_ECRS_SERIALIZE_FULL);
+  tag = size + sizeof (int) + 1;
+  off = 0;
+  if (ns_name != NULL)
+    {
+      off = strlen (ns_name);
+      tag += off;
+    }
+  buf = GNUNET_malloc (tag);
+  ((int *) buf)[0] = htonl (ranking);   /* ranking */
+  if (ns_name != NULL)
+    {
+      memcpy (&buf[sizeof (int)], ns_name, off + 1);
+    }
+  else
+    {
+      buf[sizeof (int)] = '\0';
+    }
+  GNUNET_GE_ASSERT (ectx,
+                    size == GNUNET_ECRS_meta_data_serialize (ectx,
+                                                             meta,
+                                                             &buf[sizeof
+                                                                  (int) +
+                                                                  off + 1],
+                                                             size,
+                                                             
GNUNET_ECRS_SERIALIZE_FULL));
+  GNUNET_disk_file_write (ectx, fn, buf, tag, "660");
+  GNUNET_free (fn);
+  GNUNET_free (buf);
+  /* create entry for pseudonym name in names */
+  GNUNET_free_non_null (GNUNET_PSEUDO_id_to_name (ectx, cfg, nsid));
+}
+
+int
+GNUNET_PSEUDO_internal_read_info_ (struct GNUNET_GE_Context *ectx,
+                                            struct GNUNET_GC_Configuration 
*cfg,
+                                            const GNUNET_HashCode * nsid,
+                                            struct GNUNET_ECRS_MetaData **meta,
+                                            int *ranking, char **ns_name)
+{
+  unsigned long long len;
+  unsigned int size;
+  unsigned int zend;
+  char *buf;
+  char *fn;
+
+  if (meta != NULL)
+    *meta = NULL;
+  if (ns_name != NULL)
+    *ns_name = NULL;
+  fn = GNUNET_PSEUDO_internal_get_data_filename_ (ectx,
+                                                 cfg,
+                                                 PS_METADATA_DIR, nsid);
+  if ((GNUNET_OK != GNUNET_disk_file_test (ectx,
+                                           fn) ||
+       (GNUNET_OK != GNUNET_disk_file_size (ectx, fn, &len, GNUNET_YES))))
+    {
+      GNUNET_free (fn);
+      return GNUNET_SYSERR;
+    }
+  if (len <= sizeof (int) + 1)
+    {
+      GNUNET_free (fn);
+      return GNUNET_SYSERR;
+    }
+  if (len > 16 * 1024 * 1024)
+    {
+      /* too big, must be invalid! remove! */
+      GNUNET_GE_BREAK (ectx, 0);
+      UNLINK (fn);
+      GNUNET_free (fn);
+      return GNUNET_SYSERR;
+    }
+  buf = GNUNET_malloc (len);
+  if (len != GNUNET_disk_file_read (ectx, fn, len, buf))
+    {
+      GNUNET_free (buf);
+      GNUNET_free (fn);
+      return GNUNET_SYSERR;
+    }
+  if (ranking != NULL)
+    *ranking = ntohl (((int *) buf)[0]);
+  zend = sizeof (int);
+  while ((zend < len) && (buf[zend] != '\0'))
+    zend++;
+  if (zend == len)
+    {
+      GNUNET_free (buf);
+      GNUNET_free (fn);
+      return GNUNET_SYSERR;
+    }
+  if (ns_name != NULL)
+    {
+      if (zend != sizeof (int))
+        *ns_name = GNUNET_strdup (&buf[sizeof (int)]);
+      else
+        *ns_name = NULL;
+    }
+  zend++;
+  size = len - zend;
+  if (meta != NULL)
+    {
+      *meta = GNUNET_ECRS_meta_data_deserialize (ectx, &buf[zend], size);
+      if ((*meta) == NULL)
+        {
+          /* invalid data! remove! */
+          GNUNET_GE_BREAK (ectx, 0);
+          UNLINK (fn);
+          GNUNET_free (buf);
+          GNUNET_free (fn);
+          return GNUNET_SYSERR;
+        }
+    }
+  GNUNET_free (fn);
+  GNUNET_free (buf);
+  return GNUNET_OK;
+}
+
+struct ListPseudonymClosure
+{
+  GNUNET_PSEUDO_PseudonymIterator iterator;
+  void *closure;
+  struct GNUNET_GE_Context *ectx;
+  struct GNUNET_GC_Configuration *cfg;
+};
+
+static int
+list_pseudonym_helper (const char *fn, const char *dirName, void *cls)
+{ 
+  struct ListPseudonymClosure *c = cls;
+  int ret;
+  GNUNET_HashCode id;
+  int rating;
+  struct GNUNET_ECRS_MetaData *meta;
+
+  ret = GNUNET_OK;
+  if (GNUNET_OK != GNUNET_enc_to_hash (fn, &id))
+    return GNUNET_OK;           /* invalid name */
+  if (GNUNET_OK !=
+      GNUNET_PSEUDO_internal_read_info_ (c->ectx, c->cfg, &id, &meta,
+                                        &rating, NULL))
+    return GNUNET_OK;           /* ignore entry */
+  if (c->iterator != NULL)
+    ret = c->iterator (c->closure, &id, meta, rating);
+  GNUNET_ECRS_meta_data_destroy (meta);
+  return ret;
+}
+
+/**
+ * List all available pseudonyms.
+ */
+int
+GNUNET_PSEUDO_list_all (struct GNUNET_GE_Context *ectx,
+                       struct GNUNET_GC_Configuration *cfg,
+                       GNUNET_PSEUDO_PseudonymIterator iterator,
+                       void *closure)
+{
+  struct ListPseudonymClosure cls;
+  char *fn;
+  int ret;
+
+  cls.iterator = iterator;
+  cls.closure = closure;
+  cls.ectx = ectx;
+  cls.cfg = cfg;
+  fn =
+    GNUNET_PSEUDO_internal_get_data_filename_ (ectx, cfg, PS_METADATA_DIR, 
NULL);
+  GNUNET_disk_directory_create (ectx, fn);
+  ret = GNUNET_disk_directory_scan (ectx, fn, &list_pseudonym_helper, &cls);
+  GNUNET_free (fn);
+  return ret;
+}
+
+/**
+ * Change the ranking of a pseudonym.
+ *
+ * @param nsid id of the pseudonym
+ * @param delta by how much should the rating be
+ *  changed?
+ * @return new rating of the pseudonym
+ */
+int
+GNUNET_PSEUDO_rank (struct GNUNET_GE_Context *ectx,
+                   struct GNUNET_GC_Configuration *cfg,
+                   const GNUNET_HashCode * nsid, int delta)
+{
+  struct GNUNET_ECRS_MetaData *meta;
+  int ret;
+  int ranking;
+  char *name;
+
+  name = NULL;
+  ret =
+    GNUNET_PSEUDO_internal_read_info_ (ectx, cfg, nsid, &meta, &ranking,
+                                                &name);
+  if (ret == GNUNET_SYSERR)
+    {
+      ranking = 0;
+      meta = GNUNET_ECRS_meta_data_create ();
+    }
+  ranking += delta;
+  write_pseudonym_info (ectx, cfg, nsid, meta, ranking, name);
+  GNUNET_ECRS_meta_data_destroy (meta);
+  GNUNET_free_non_null (name);
+  return ranking;
+}
+
+/**
+ * Insert metadata into existing MD record (passed as cls).
+ */
+static int
+merge_meta_helper (EXTRACTOR_KeywordType type, const char *data, void *cls)
+{
+  struct GNUNET_ECRS_MetaData *meta = cls;
+  GNUNET_ECRS_meta_data_insert (meta, type, data);
+  return GNUNET_OK;
+}
+
+/**
+ * Add a pseudonym to the set of known pseudonyms.
+ * For all pseudonym advertisements that we discover
+ * FSUI should automatically call this function.
+ *
+ * @param id the pseudonym identifier
+ */
+void
+GNUNET_PSEUDO_add (struct GNUNET_GE_Context *ectx,
+                  struct GNUNET_GC_Configuration *cfg,
+                  const GNUNET_HashCode *id,
+                  const struct GNUNET_ECRS_MetaData *meta)
+{
+  char *name;
+  int ranking;
+  struct GNUNET_ECRS_MetaData *old;
+
+  ranking = 0;
+  if (GNUNET_OK ==
+      GNUNET_PSEUDO_internal_read_info_ (ectx, cfg, id, &old, &ranking,
+                                                  &name))
+    {
+      GNUNET_ECRS_meta_data_get_contents (meta, &merge_meta_helper, old);
+      write_pseudonym_info (ectx, cfg, id, old, ranking, name);
+      GNUNET_ECRS_meta_data_destroy (old);
+    }
+  else
+    {
+      write_pseudonym_info (ectx, cfg, id, meta, ranking, NULL);
+    }
+  GNUNET_PSEUDO_internal_notify_ (id, meta, ranking);
+  GNUNET_free_non_null (name);
+}
+
+
+/* end of info.c */

Copied: GNUnet/src/applications/fs/pseudonyms/info.h (from rev 6923, 
GNUnet/src/applications/fs/namespace/namespace_info.h)
===================================================================
--- GNUnet/src/applications/fs/pseudonyms/info.h                                
(rev 0)
+++ GNUnet/src/applications/fs/pseudonyms/info.h        2008-05-30 03:36:04 UTC 
(rev 6924)
@@ -0,0 +1,40 @@
+/*
+     This file is part of GNUnet
+     (C) 2003, 2004, 2005, 2006, 2007, 2008 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 2, 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 applications/fs/pseudonym/info.h
+ * @brief keeping track of pseudonyms and metadata about them
+ * @author Christian Grothoff
+ */
+
+#ifndef NAMESPACE_INFO_H
+#define NAMESPACE_INFO_H
+
+#include "gnunet_namespace_lib.h"
+#include "gnunet_util.h"
+
+int
+GNUNET_PSEUDO_internal_read_info_ (struct GNUNET_GE_Context *ectx,
+                                  struct GNUNET_GC_Configuration *cfg,
+                                  const GNUNET_HashCode * nsid,
+                                  struct GNUNET_ECRS_MetaData **meta,
+                                  int *ranking, char **ns_name);
+
+#endif

Copied: GNUnet/src/applications/fs/pseudonyms/info_test.c (from rev 6923, 
GNUnet/src/applications/fs/namespace/namespace_infotest.c)
===================================================================
--- GNUnet/src/applications/fs/pseudonyms/info_test.c                           
(rev 0)
+++ GNUnet/src/applications/fs/pseudonyms/info_test.c   2008-05-30 03:36:04 UTC 
(rev 6924)
@@ -0,0 +1,68 @@
+/*
+     This file is part of GNUnet.
+     (C) 2005, 2006 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 2, 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 applications/fs/pseudonym/info_test.c
+ * @brief testcase for info.c
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_ecrs_lib.h"
+#include "gnunet_pseudonym_lib.h"
+#include "gnunet_pseudonym_lib.h"
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto 
FAILURE; }
+
+int
+main (int argc, char *argv[])
+{
+  int ok;
+  struct GNUNET_ECRS_MetaData *meta = NULL;
+  GNUNET_HashCode id;
+  int old;
+  int newVal;
+  struct GNUNET_GC_Configuration *cfg;
+  struct GNUNET_GE_Context *ectx;
+
+  GNUNET_disable_entropy_gathering ();
+  cfg = GNUNET_GC_create ();
+  if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+    {
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+  /* ACTUAL TEST CODE */
+  old = GNUNET_PSEUDO_list_all (ectx, cfg, NULL, NULL);
+  meta = GNUNET_ECRS_meta_data_create ();
+  GNUNET_ECRS_meta_data_insert (meta, 0, "test");
+  GNUNET_create_random_hash (&id); 
+  GNUNET_PSEUDO_add(ectx, cfg, &id, meta);
+  newVal = GNUNET_PSEUDO_list_all (ectx, cfg, NULL, NULL);
+  CHECK (old < newVal);
+  /* END OF TEST CODE */
+FAILURE:
+  GNUNET_ECRS_meta_data_destroy (meta);
+  GNUNET_GC_free (cfg);
+  return (ok == GNUNET_YES) ? 0 : 1;
+}
+
+/* end of info_test.c */

Copied: GNUnet/src/applications/fs/pseudonyms/names.c (from rev 6923, 
GNUnet/src/applications/fs/namespace/names.c)
===================================================================
--- GNUnet/src/applications/fs/pseudonyms/names.c                               
(rev 0)
+++ GNUnet/src/applications/fs/pseudonyms/names.c       2008-05-30 03:36:04 UTC 
(rev 6924)
@@ -0,0 +1,170 @@
+/*
+     This file is part of GNUnet
+     (C) 2003, 2004, 2005, 2006, 2007, 2008 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 2, 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 applications/fs/namespace/names.c
+ * @brief create unique, human-readable names for namespaces
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include <extractor.h>
+#include "gnunet_directories.h"
+#include "gnunet_namespace_lib.h"
+#include "gnunet_util.h"
+#include "info.h"
+#include "common.h"
+
+
+/**
+ * Return the unique, human readable name for the given namespace.
+ *
+ * @return NULL on failure (should never happen)
+ */
+char *
+GNUNET_PSEUDO_id_to_name (struct GNUNET_GE_Context *ectx,
+                         struct GNUNET_GC_Configuration *cfg,
+                         const GNUNET_HashCode * nsid)
+{
+  struct GNUNET_ECRS_MetaData *meta;
+  char *name;
+  GNUNET_HashCode nh;
+  char *fn;
+  unsigned long long len;
+  int fd;
+  unsigned int i;
+  unsigned int idx;
+  char *ret;
+
+  meta = NULL;
+  name = NULL;
+  if (GNUNET_OK == 
+      GNUNET_PSEUDO_internal_read_info_ (ectx, cfg, nsid, &meta, NULL,
+                                        &name))
+    {
+      if ((meta != NULL) && (name == NULL))
+       name = GNUNET_ECRS_meta_data_get_first_by_types (meta,
+                                                        EXTRACTOR_TITLE,
+                                                        EXTRACTOR_FILENAME,
+                                                        EXTRACTOR_DESCRIPTION,
+                                                        EXTRACTOR_SUBJECT,
+                                                        EXTRACTOR_PUBLISHER,
+                                                        EXTRACTOR_AUTHOR,
+                                                        EXTRACTOR_COMMENT,
+                                                        EXTRACTOR_SUMMARY,
+                                                        EXTRACTOR_OWNER, -1);
+      if (meta != NULL)
+       {
+         GNUNET_ECRS_meta_data_destroy (meta);
+         meta = NULL;
+       }
+    }
+  if (name == NULL)
+    name = GNUNET_strdup (_("no-name"));
+  GNUNET_hash (name, strlen (name), &nh);
+  fn = GNUNET_PSEUDO_internal_get_data_filename_ (ectx,
+                                                 cfg, PS_NAMES_DIR, &nh);
+  if ((GNUNET_OK != GNUNET_disk_file_test (ectx,
+                                           fn) ||
+       (GNUNET_OK != GNUNET_disk_file_size (ectx, fn, &len, GNUNET_YES))))
+    {
+      GNUNET_free (fn);
+      return NULL;
+    }
+  fd = GNUNET_disk_file_open (ectx, fn, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+  i = 0;
+  idx = -1;
+  while ((len >= sizeof (GNUNET_HashCode)) &&
+         (sizeof (GNUNET_HashCode)
+          == READ (fd, &nh, sizeof (GNUNET_HashCode))))
+    {
+      if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode)))
+        {
+          idx = i;
+          break;
+        }
+      i++;
+      len -= sizeof (GNUNET_HashCode);
+    }
+  if (idx == -1)
+    {
+      idx = i;
+      WRITE (fd, nsid, sizeof (GNUNET_HashCode));
+    }
+  CLOSE (fd);
+  ret = GNUNET_malloc (strlen (name) + 32);
+  GNUNET_snprintf (ret, strlen (name) + 32, "%s-%u", name, idx);
+  GNUNET_free (name);
+  GNUNET_free (fn);
+  return ret;
+}
+
+/**
+ * Get the namespace ID belonging to the given namespace name.
+ *
+ * @return GNUNET_OK on success
+ */
+int
+GNUNET_PSEUDO_name_to_id (struct GNUNET_GE_Context *ectx,
+                         struct GNUNET_GC_Configuration *cfg,
+                         const char *ns_uname, GNUNET_HashCode * nsid)
+{
+  size_t slen;
+  unsigned long long len;
+  unsigned int idx;
+  char *name;
+  GNUNET_HashCode nh;
+  char *fn;
+  int fd;
+
+  idx = -1;
+  slen = strlen (ns_uname);
+  while ((slen > 0) && (1 != sscanf (&ns_uname[slen - 1], "-%u", &idx)))
+    slen--;
+  if (slen == 0)
+    return GNUNET_SYSERR;
+  name = GNUNET_strdup (ns_uname);
+  name[slen] = '\0';
+  GNUNET_hash (name, strlen (name), &nh);
+  GNUNET_free (name);
+  fn = GNUNET_PSEUDO_internal_get_data_filename_ (ectx,
+                                                 cfg, PS_NAMES_DIR, &nh);
+  if ((GNUNET_OK != GNUNET_disk_file_test (ectx,
+                                           fn) ||
+       (GNUNET_OK != GNUNET_disk_file_size (ectx, fn, &len, GNUNET_YES))) ||
+      ((idx + 1) * sizeof (GNUNET_HashCode) > len))
+    {
+      GNUNET_free (fn);
+      return GNUNET_SYSERR;
+    }
+  fd = GNUNET_disk_file_open (ectx, fn, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+  GNUNET_free (fn);
+  LSEEK (fd, idx * sizeof (GNUNET_HashCode), SEEK_SET);
+  if (sizeof (GNUNET_HashCode) != READ (fd, nsid, sizeof (GNUNET_HashCode)))
+    {
+      CLOSE (fd);
+      return GNUNET_SYSERR;
+    }
+  CLOSE (fd);
+  return GNUNET_OK;
+}
+
+
+/* end of names.c */

Copied: GNUnet/src/applications/fs/pseudonyms/notification.c (from rev 6923, 
GNUnet/src/applications/fs/namespace/namespace_notification.c)
===================================================================
--- GNUnet/src/applications/fs/pseudonyms/notification.c                        
        (rev 0)
+++ GNUnet/src/applications/fs/pseudonyms/notification.c        2008-05-30 
03:36:04 UTC (rev 6924)
@@ -0,0 +1,136 @@
+/*
+     This file is part of GNUnet
+     (C) 2003, 2004, 2005, 2006, 2007, 2008 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 2, 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 applications/fs/pseudonym/pseudonym_notification.c
+ * @brief implementation of the notification mechanism
+ * @author Christian Grothoff
+ */
+
+
+#include "platform.h"
+#include "gnunet_directories.h"
+#include "gnunet_pseudonym_lib.h"
+#include "gnunet_util.h"
+
+struct DiscoveryCallback
+{
+  struct DiscoveryCallback *next;
+  GNUNET_PSEUDO_PseudonymIterator callback;
+  void *closure;
+};
+
+static struct DiscoveryCallback *head;
+
+static struct GNUNET_Mutex *lock;
+
+/**
+ * Internal notification about new tracked URI.
+ */
+void
+GNUNET_PSEUDO_internal_notify_ (const GNUNET_HashCode * id,
+                               const struct GNUNET_ECRS_MetaData *md, 
+                               int rating)
+{
+  struct DiscoveryCallback *pos;
+
+  GNUNET_mutex_lock (lock);
+  pos = head;
+  while (pos != NULL)
+    {
+      pos->callback (pos->closure, id, md, rating);
+      pos = pos->next;
+    }
+  GNUNET_mutex_unlock (lock);
+}
+
+
+
+/**
+ * Register callback to be invoked whenever we discover
+ * a new pseudonym.
+ */
+int
+GNUNET_PSEUDO_register_discovery_callback (struct GNUNET_GE_Context *ectx,
+                                          struct GNUNET_GC_Configuration *cfg,
+                                          GNUNET_PSEUDO_PseudonymIterator 
iterator,
+                                          void *closure)
+{
+  struct DiscoveryCallback *list;
+
+  list = GNUNET_malloc (sizeof (struct DiscoveryCallback));
+  list->callback = iterator;
+  list->closure = closure;
+  GNUNET_mutex_lock (lock);
+  list->next = head;
+  head = list;
+  GNUNET_PSEUDO_list_all (ectx, cfg, iterator, closure);
+  GNUNET_mutex_unlock (lock);
+  return GNUNET_OK;
+}
+
+/**
+ * Unregister pseudonym discovery callback.
+ */
+int
+GNUNET_PSEUDO_unregister_discovery_callback (GNUNET_PSEUDO_PseudonymIterator 
iterator,
+                                         void *closure)
+{
+  struct DiscoveryCallback *prev;
+  struct DiscoveryCallback *pos;
+
+  prev = NULL;
+  GNUNET_mutex_lock (lock);
+  pos = head;
+  while ((pos != NULL) &&
+         ((pos->callback != iterator) || (pos->closure != closure)))
+    {
+      prev = pos;
+      pos = pos->next;
+    }
+  if (pos == NULL)
+    {
+      GNUNET_mutex_unlock (lock);
+      return GNUNET_SYSERR;
+    }
+  if (prev == NULL)
+    head = pos->next;
+  else
+    prev->next = pos->next;
+  GNUNET_free (pos);
+  GNUNET_mutex_unlock (lock);
+  return GNUNET_OK;
+}
+
+
+
+void __attribute__ ((constructor)) GNUNET_PSEUDO_ltdl_init ()
+{
+  lock = GNUNET_mutex_create (GNUNET_NO);
+}
+
+void __attribute__ ((destructor)) GNUNET_PSEUDO_ltdl_fini ()
+{
+  GNUNET_mutex_destroy (lock);
+  lock = NULL;
+}
+
+
+/* end of notification.c */

Copied: GNUnet/src/applications/fs/pseudonyms/notification.h (from rev 6923, 
GNUnet/src/applications/fs/namespace/namespace_notification.h)
===================================================================
--- GNUnet/src/applications/fs/pseudonyms/notification.h                        
        (rev 0)
+++ GNUnet/src/applications/fs/pseudonyms/notification.h        2008-05-30 
03:36:04 UTC (rev 6924)
@@ -0,0 +1,41 @@
+/*
+     This file is part of GNUnet
+     (C) 2003, 2004, 2005, 2006, 2007, 2008 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 2, 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 applications/fs/pseudonym/pseudonym_notification.h
+ * @brief implementation of the notification mechanism
+ * @author Christian Grothoff
+ */
+
+
+#include "gnunet_pseudonym_lib.h"
+
+#ifndef PSEUDONYM_NOTIFICATON_H
+#define PSEUDONYM_NOTIFICATON_H
+
+/**
+ * Internal notification about new tracked pseudonym.
+ */
+void
+GNUNET_PSEUDO_internal_notify_ (const GNUNET_HashCode * id,
+                               const struct GNUNET_ECRS_MetaData *md,
+                               int rating);
+
+#endif





reply via email to

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