move
authorChristian Grothoff <christian@grothoff.org>
Tue, 15 Sep 2009 15:58:09 +0000 (15:58 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 15 Sep 2009 15:58:09 +0000 (15:58 +0000)
configure.ac
src/Makefile.am
src/fs/Makefile.am
src/include/gnunet_util_lib.h
src/peer/Makefile.am [deleted file]
src/peer/peer.c [deleted file]
src/util/Makefile.am
src/util/peer.c [new file with mode: 0644]

index 20bff6c6af1eac69aef12f806805dabe7d90c7bc..28094e057dfaf1a5366a62e7e293e644b314b0ea 100644 (file)
@@ -753,7 +753,6 @@ src/hello/Makefile
 src/include/Makefile
 src/include/gnunet_directories.h
 src/hostlist/Makefile
-src/peer/Makefile
 src/peerinfo/Makefile
 src/resolver/Makefile
 src/statistics/Makefile
index a394944d2c367c5a4421b4e3e7b159ffdb7101f9..7e92437c6ada757232c6c1614adf03ed75790b35 100644 (file)
@@ -13,7 +13,6 @@ SUBDIRS = \
   arm \
   fragmentation \
   hello \
-  peer \
   peerinfo \
   resolver \
   statistics \
index a91459e64391f13af2a1d7f6c2f0b802e12e9bc3..e2f2e62678afc2ad5cd13ee8601700a49fdb5fd6 100644 (file)
@@ -88,7 +88,6 @@ gnunet_service_fs_LDADD =  \
  $(top_builddir)/src/fs/libgnunetfs.la \
  $(top_builddir)/src/datastore/libgnunetdatastore.la \
  $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/peer/libgnunetpeer.la \
  $(top_builddir)/src/util/libgnunetutil.la \
  $(GN_LIBINTL)
 
index 6bb87bf4dfe9b43eb326e4b85bf97999c4112598..1c5e1d7a17c3f85b481fbeb6fc7edc3a66e2b736 100644 (file)
@@ -47,6 +47,7 @@ extern "C"
 #include "gnunet_getopt_lib.h"
 #include "gnunet_network_lib.h"
 #include "gnunet_os_lib.h"
+#include "gnunet_peer_lib.h"
 #include "gnunet_plugin_lib.h"
 #include "gnunet_program_lib.h"
 #include "gnunet_protocols.h"
diff --git a/src/peer/Makefile.am b/src/peer/Makefile.am
deleted file mode 100644 (file)
index bd268cf..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-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
-
-lib_LTLIBRARIES = libgnunetpeer.la
-
-libgnunetpeer_la_SOURCES = \
-  peer.c 
-libgnunetpeer_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la $(XLIB)
-
-#check_PROGRAMS = \
-# test_peer
-#
-#TESTS = $(check_PROGRAMS)
-#
-#test_peer_SOURCES = \
-# test_peer.c
-#test_peer_LDADD = \
-# $(top_builddir)/src/peer/libgnunetpeer.la \
-# $(top_builddir)/src/util/libgnunetutil.la  
-
diff --git a/src/peer/peer.c b/src/peer/peer.c
deleted file mode 100644 (file)
index 02c95f4..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
-      This file is part of GNUnet
-     (C) 2006, 2008, 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 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., 51 Franklin Street, Fifth Floor,
-      Boston, MA 02110-1301, USA.
- */
-
-/**
- * @file peer/peer.c
- * @brief peer-ID table that assigns integer IDs to peer-IDs to save memory
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_peer_lib.h"
-
-
-struct PeerEntry
-{
-  /**
-   * the identifier itself
-   */
-  struct GNUNET_PeerIdentity id;
-
-  /**
-   * Short version of the identifier;
-   * if the RC==0, then index of next
-   * free slot in table, otherwise 
-   * equal to this slot in the table. 
-   */
-  GNUNET_PEER_Id pid;
-
-  /**
-   * Reference counter, 0 if this slot
-   * is not used.
-   */
-  unsigned int rc;
-};
-
-
-/**
- * Table with our interned peer IDs.
- */
-static struct PeerEntry *table;
-
-/**
- * Hashmap of PeerIdentities to "struct PeerEntry"
- * (for fast lookup).  NULL until the library
- * is actually being used.
- */
-static struct GNUNET_CONTAINER_MultiHashMap *map;
-
-/**
- * Size of the "table".
- */
-static unsigned int size;
-
-/**
- * Index of the beginning of the free list in the table; set to "size"
- * if no slots are free in the table.
- */
-static unsigned int free_list_start;
-
-
-/**
- * Intern an peer identity.  If the identity is already known, its
- * reference counter will be increased by one.
- *
- * @param pid identity to intern
- * @return the interned identity.
- */
-GNUNET_PEER_Id
-GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
-{
-  GNUNET_PEER_Id ret;
-  struct PeerEntry *e;
-  unsigned int i;
-
-  if (pid == NULL)
-    return 0;
-  if (NULL == map)
-    map = GNUNET_CONTAINER_multihashmap_create (32);
-  e = GNUNET_CONTAINER_multihashmap_get (map,
-                                        &pid->hashPubKey);
-  if (e != NULL)
-    {
-      GNUNET_assert (e->rc > 0);
-      e->rc++;
-      return e->pid;
-    }
-  ret = free_list_start;
-  if (ret == size)
-    {
-      GNUNET_array_grow (table, size, size + 16);
-      for (i=ret;i<size;i++)
-       table[i].pid = i + 1;
-    }
-  if (ret == 0)
-    {
-      table[0].pid = 0;
-      table[0].rc = 1;
-      ret = 1;
-    }
-  GNUNET_assert (ret < size);
-  GNUNET_assert (table[ret].rc == 0);
-  free_list_start = table[ret].pid;
-  table[ret].id = *pid;
-  table[ret].rc = 1;
-  table[ret].pid = ret;
-  GNUNET_CONTAINER_multihashmap_put (map,
-                                    &pid->hashPubKey,
-                                    &table[ret],
-                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
-  return ret;
-}
-
-
-/**
- * Decrement multiple RCs of peer identities by one.
- * 
- * @param ids array of PIDs to decrement the RCs of
- * @param count size of the ids array
- */
-void
-GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, 
-                          unsigned int count)
-{
-  int i;
-  GNUNET_PEER_Id id;
-
-  if (count == 0)
-    return;
-  for (i = count - 1; i >= 0; i--)
-    {
-      id = ids[i];
-      GNUNET_assert (id < size);
-      GNUNET_assert (table[id].rc > 0);
-      table[id].rc--;
-      if (table[id].rc == 0)
-       {
-         GNUNET_CONTAINER_multihashmap_remove (map,
-                                               &table[id].id.hashPubKey,
-                                               &table[id]);
-         table[id].pid = free_list_start;
-         free_list_start = id;
-       }
-    }
-}
-
-
-/**
- * Change the reference counter of an interned PID.
- *
- * @param id identity to change the RC of
- * @param delta how much to change the RC
- */
-void
-GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
-{
-  if (id == 0)
-    return;
-  GNUNET_assert (id < size);
-  GNUNET_assert (table[id].rc > 0);
-  GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta));
-  table[id].rc += delta;
-  if (table[id].rc == 0)
-    {
-      GNUNET_CONTAINER_multihashmap_remove (map,
-                                           &table[id].id.hashPubKey,
-                                           &table[id]);
-      table[id].pid = free_list_start;
-      free_list_start = id;
-    }
-}
-
-
-/**
- * Convert an interned PID to a normal peer identity.
- *
- * @param id interned PID to convert
- * @param pid where to write the normal peer identity
- */
-void
-GNUNET_PEER_resolve (GNUNET_PEER_Id id, 
-                    struct GNUNET_PeerIdentity * pid)
-{
-  if (id == 0)
-    {
-      memset (pid, 0, sizeof (struct GNUNET_PeerIdentity));
-      GNUNET_break (0);
-      return;
-    }
-  GNUNET_assert (id < size);
-  GNUNET_assert (table[id].rc > 0);
-  *pid = table[id].id;
-}
-
-
-/* end of peer.c */
index a4e633eb95e42beab85e64fd521a6e4b6c3204ca..d7e5ada548b4dd0858d43ba06494937454594c35 100644 (file)
@@ -41,6 +41,7 @@ libgnunetutil_la_SOURCES = \
   os_load.c \
   os_network.c \
   os_priority.c \
+  peer.c \
   plugin.c \
   program.c \
   pseudonym.c \
diff --git a/src/util/peer.c b/src/util/peer.c
new file mode 100644 (file)
index 0000000..acb1b39
--- /dev/null
@@ -0,0 +1,212 @@
+/*
+      This file is part of GNUnet
+     (C) 2006, 2008, 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 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., 51 Franklin Street, Fifth Floor,
+      Boston, MA 02110-1301, USA.
+ */
+
+/**
+ * @file util/peer.c
+ * @brief peer-ID table that assigns integer IDs to peer-IDs to save memory
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_peer_lib.h"
+
+
+struct PeerEntry
+{
+  /**
+   * the identifier itself
+   */
+  struct GNUNET_PeerIdentity id;
+
+  /**
+   * Short version of the identifier;
+   * if the RC==0, then index of next
+   * free slot in table, otherwise 
+   * equal to this slot in the table. 
+   */
+  GNUNET_PEER_Id pid;
+
+  /**
+   * Reference counter, 0 if this slot
+   * is not used.
+   */
+  unsigned int rc;
+};
+
+
+/**
+ * Table with our interned peer IDs.
+ */
+static struct PeerEntry *table;
+
+/**
+ * Hashmap of PeerIdentities to "struct PeerEntry"
+ * (for fast lookup).  NULL until the library
+ * is actually being used.
+ */
+static struct GNUNET_CONTAINER_MultiHashMap *map;
+
+/**
+ * Size of the "table".
+ */
+static unsigned int size;
+
+/**
+ * Index of the beginning of the free list in the table; set to "size"
+ * if no slots are free in the table.
+ */
+static unsigned int free_list_start;
+
+
+/**
+ * Intern an peer identity.  If the identity is already known, its
+ * reference counter will be increased by one.
+ *
+ * @param pid identity to intern
+ * @return the interned identity.
+ */
+GNUNET_PEER_Id
+GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
+{
+  GNUNET_PEER_Id ret;
+  struct PeerEntry *e;
+  unsigned int i;
+
+  if (pid == NULL)
+    return 0;
+  if (NULL == map)
+    map = GNUNET_CONTAINER_multihashmap_create (32);
+  e = GNUNET_CONTAINER_multihashmap_get (map,
+                                        &pid->hashPubKey);
+  if (e != NULL)
+    {
+      GNUNET_assert (e->rc > 0);
+      e->rc++;
+      return e->pid;
+    }
+  ret = free_list_start;
+  if (ret == size)
+    {
+      GNUNET_array_grow (table, size, size + 16);
+      for (i=ret;i<size;i++)
+       table[i].pid = i + 1;
+    }
+  if (ret == 0)
+    {
+      table[0].pid = 0;
+      table[0].rc = 1;
+      ret = 1;
+    }
+  GNUNET_assert (ret < size);
+  GNUNET_assert (table[ret].rc == 0);
+  free_list_start = table[ret].pid;
+  table[ret].id = *pid;
+  table[ret].rc = 1;
+  table[ret].pid = ret;
+  GNUNET_CONTAINER_multihashmap_put (map,
+                                    &pid->hashPubKey,
+                                    &table[ret],
+                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+  return ret;
+}
+
+
+/**
+ * Decrement multiple RCs of peer identities by one.
+ * 
+ * @param ids array of PIDs to decrement the RCs of
+ * @param count size of the ids array
+ */
+void
+GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, 
+                          unsigned int count)
+{
+  int i;
+  GNUNET_PEER_Id id;
+
+  if (count == 0)
+    return;
+  for (i = count - 1; i >= 0; i--)
+    {
+      id = ids[i];
+      GNUNET_assert (id < size);
+      GNUNET_assert (table[id].rc > 0);
+      table[id].rc--;
+      if (table[id].rc == 0)
+       {
+         GNUNET_CONTAINER_multihashmap_remove (map,
+                                               &table[id].id.hashPubKey,
+                                               &table[id]);
+         table[id].pid = free_list_start;
+         free_list_start = id;
+       }
+    }
+}
+
+
+/**
+ * Change the reference counter of an interned PID.
+ *
+ * @param id identity to change the RC of
+ * @param delta how much to change the RC
+ */
+void
+GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
+{
+  if (id == 0)
+    return;
+  GNUNET_assert (id < size);
+  GNUNET_assert (table[id].rc > 0);
+  GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta));
+  table[id].rc += delta;
+  if (table[id].rc == 0)
+    {
+      GNUNET_CONTAINER_multihashmap_remove (map,
+                                           &table[id].id.hashPubKey,
+                                           &table[id]);
+      table[id].pid = free_list_start;
+      free_list_start = id;
+    }
+}
+
+
+/**
+ * Convert an interned PID to a normal peer identity.
+ *
+ * @param id interned PID to convert
+ * @param pid where to write the normal peer identity
+ */
+void
+GNUNET_PEER_resolve (GNUNET_PEER_Id id, 
+                    struct GNUNET_PeerIdentity * pid)
+{
+  if (id == 0)
+    {
+      memset (pid, 0, sizeof (struct GNUNET_PeerIdentity));
+      GNUNET_break (0);
+      return;
+    }
+  GNUNET_assert (id < size);
+  GNUNET_assert (table[id].rc > 0);
+  *pid = table[id].id;
+}
+
+
+/* end of peer.c */