gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r5896 - GNUnet/src/applications/dht/module


From: gnunet
Subject: [GNUnet-SVN] r5896 - GNUnet/src/applications/dht/module
Date: Thu, 13 Dec 2007 23:00:58 -0700 (MST)

Author: grothoff
Date: 2007-12-13 23:00:58 -0700 (Thu, 13 Dec 2007)
New Revision: 5896

Removed:
   GNUnet/src/applications/dht/module/dstore.c
   GNUnet/src/applications/dht/module/dstore.h
Modified:
   GNUnet/src/applications/dht/module/Makefile.am
   GNUnet/src/applications/dht/module/cs.c
   GNUnet/src/applications/dht/module/routing.c
Log:
stupid code be gone

Modified: GNUnet/src/applications/dht/module/Makefile.am
===================================================================
--- GNUnet/src/applications/dht/module/Makefile.am      2007-12-14 05:22:01 UTC 
(rev 5895)
+++ GNUnet/src/applications/dht/module/Makefile.am      2007-12-14 06:00:58 UTC 
(rev 5896)
@@ -7,7 +7,6 @@
 
 libgnunetmodule_dht_la_SOURCES = \
   cs.c \
-  dstore.c dstore.h \
   routing.c routing.h \
   service.c \
   table.c table.h 

Modified: GNUnet/src/applications/dht/module/cs.c
===================================================================
--- GNUnet/src/applications/dht/module/cs.c     2007-12-14 05:22:01 UTC (rev 
5895)
+++ GNUnet/src/applications/dht/module/cs.c     2007-12-14 06:00:58 UTC (rev 
5896)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      Copyright (C) 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+      Copyright (C) 2004, 2005, 2006, 2007 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
@@ -45,19 +45,19 @@
  */
 static GNUNET_DHT_ServiceAPI *dhtAPI;
 
-typedef struct
+typedef struct DHT_CLIENT_GET_RECORD
 {
 
+  struct DHT_CLIENT_GET_RECORD * next;
+
   struct GNUNET_ClientHandle *client;
 
   struct GNUNET_DHT_GetHandle *get_record;
 
-} DHT_CLIENT_GET_RECORD;
+};
 
-static DHT_CLIENT_GET_RECORD **getRecords;
+static struct DHT_CLIENT_GET_RECORD * getRecords;
 
-static unsigned int getRecordsSize;
-
 /**
  * Lock.
  */
@@ -92,11 +92,11 @@
   return GNUNET_OK;
 }
 
-int
+static int
 get_result (const GNUNET_HashCode * key, const GNUNET_DataContainer * value,
             void *cls)
 {
-  DHT_CLIENT_GET_RECORD *record = cls;
+  struct DHT_CLIENT_GET_RECORD *record = cls;
   CS_dht_request_put_MESSAGE *msg;
   size_t n;
 
@@ -140,29 +140,41 @@
   return GNUNET_OK;
 }
 
+/**
+ * Find the record, remove it from the linked list
+ * and cancel the operation with the DHT API.
+ */
 static void
 get_timeout (void *cls)
 {
-  DHT_CLIENT_GET_RECORD *record = cls;
+  struct DHT_CLIENT_GET_RECORD *record = cls;
+  struct DHT_CLIENT_GET_RECORD * pos;
+  struct DHT_CLIENT_GET_RECORD * prev;
   int i;
   int found;
 
   found = GNUNET_NO;
   GNUNET_mutex_lock (lock);
-  for (i = getRecordsSize - 1; i >= 0; i--)
-    if (getRecords[i] == record)
-      {
-        getRecords[i] = getRecords[getRecordsSize - 1];
-        GNUNET_array_grow (getRecords, getRecordsSize, getRecordsSize - 1);
-        found = GNUNET_YES;
-        break;
-      }
-  GNUNET_mutex_unlock (lock);
-  if (found == GNUNET_YES)
+  pos = getRecords;
+  prev = NULL;
+  while (pos != NULL)
     {
-      dhtAPI->get_stop (record->get_record);
-      GNUNET_free (record);
+      if (pos == record)
+       break;
+      prev = pos;
+      pos = pos->next;
     }
+  if (pos == NULL) {
+    GNUNET_mutex_unlock (lock);
+    return;
+  }
+  if (prev == NULL)
+    getRecords = pos->next;
+  else
+    prev->next = pos->next;
+  GNUNET_mutex_unlock (lock);
+  dhtAPI->get_stop (record->get_record);
+  GNUNET_free (record);
 }
 
 /**
@@ -172,8 +184,8 @@
 csGet (struct GNUNET_ClientHandle *client,
        const GNUNET_MessageHeader * message)
 {
-  const CS_dht_request_get_MESSAGE *get;
-  DHT_CLIENT_GET_RECORD *cpc;
+  const CS_dht_request_get_MESSAGE * get;
+  struct DHT_CLIENT_GET_RECORD * cpc;
 
   if (ntohs (message->size) != sizeof (CS_dht_request_get_MESSAGE))
     {
@@ -187,14 +199,15 @@
                  __LINE__);
 #endif
   get = (const CS_dht_request_get_MESSAGE *) message;
-  cpc = GNUNET_malloc (sizeof (DHT_CLIENT_GET_RECORD));
+  cpc = GNUNET_malloc (sizeof (struct DHT_CLIENT_GET_RECORD));
   cpc->client = client;
   cpc->get_record = dhtAPI->get_start (ntohl (get->type),
                                        &get->key,
                                        GNUNET_ntohll (get->timeout),
-                                       &get_result, cpc, &get_timeout, cpc);
+                                       &get_result, cpc, &get_timeout, cpc);  
   GNUNET_mutex_lock (lock);
-  GNUNET_array_append (getRecords, getRecordsSize, cpc);
+  cpc->next = getRecords;
+  getRecords = cpc;
   GNUNET_mutex_unlock (lock);
   return GNUNET_OK;
 }
@@ -206,24 +219,30 @@
 static void
 csClientExit (struct GNUNET_ClientHandle *client)
 {
-  int i;
-  struct GNUNET_DHT_GetHandle *gr;
-  DHT_CLIENT_GET_RECORD *cgr;
+  struct GNUNET_DHT_GetHandle * gr;
+  struct DHT_CLIENT_GET_RECORD * pos;
+  struct DHT_CLIENT_GET_RECORD * prev;
+
   GNUNET_mutex_lock (lock);
-  for (i = 0; i < getRecordsSize; i++)
+  pos = getRecords;
+  prev = NULL;
+  while (pos != NULL) 
     {
-      cgr = getRecords[i];
-      if (cgr->client == client)
-        {
-          gr = cgr->get_record;
-          getRecords[i] = getRecords[getRecordsSize - 1];
-          GNUNET_array_grow (getRecords, getRecordsSize, getRecordsSize - 1);
+      if (pos->client == client)
+       {
+         gr = pos->get_record;
+         if (prev == NULL)
+           getRecords = pos->next;
+         else
+           prev->next = pos->next;
           GNUNET_mutex_unlock (lock);
           dhtAPI->get_stop (gr);
-          GNUNET_free (cgr);
+          GNUNET_free (pos);
           GNUNET_mutex_lock (lock);
-          i--;
+         pos = getRecords;
         }
+      prev = pos;
+      pos = pos->next;
     }
   GNUNET_mutex_unlock (lock);
 }

Deleted: GNUnet/src/applications/dht/module/dstore.c
===================================================================
--- GNUnet/src/applications/dht/module/dstore.c 2007-12-14 05:22:01 UTC (rev 
5895)
+++ GNUnet/src/applications/dht/module/dstore.c 2007-12-14 06:00:58 UTC (rev 
5896)
@@ -1,101 +0,0 @@
-/*
-      This file is part of GNUnet
-      (C) 2004, 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 module/dstore.c
- * @brief entries in local DHT
- * @author Simo Viitanen, Christian Grothoff
- */
-
-#include "platform.h"
-#include "dstore.h"
-#include "gnunet_blockstore.h"
-
-#define DEBUG_DSTORE GNUNET_NO
-
-static GNUNET_Dstore_ServiceAPI *dstore;
-
-static GNUNET_CoreAPIForPlugins *coreAPI;
-
-/**
- * Lookup in the local datastore.
- * @return total number of results found
- */
-int
-dht_store_get (const GNUNET_HashCode * key,
-               unsigned int type, GNUNET_ResultProcessor handler, void *cls)
-{
-  return dstore->get (key, type, handler, cls);
-}
-
-/**
- * Store the given data in the local datastore.
- */
-void
-dht_store_put (unsigned int type,
-               const GNUNET_HashCode * key,
-               GNUNET_CronTime discard_time, unsigned int size,
-               const char *data)
-{
-  if (discard_time < GNUNET_get_time ())
-    {
-#if DEBUG_DSTORE
-      GNUNET_GE_LOG (coreAPI->ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
-                     GNUNET_GE_DEVELOPER,
-                     "Content already expired (%llu < %llu), will not keep.\n",
-                     discard_time, GNUNET_get_time ());
-#endif
-      return;
-    }
-  dstore->put (key, type, discard_time, size, data);
-}
-
-/**
- * Initialize dstore DHT component.
- *
- * @param capi the core API
- * @return GNUNET_OK on success
- */
-int
-init_dht_store (size_t max_size, GNUNET_CoreAPIForPlugins * capi)
-{
-  coreAPI = capi;
-  dstore = coreAPI->GNUNET_CORE_request_service ("dstore");
-  if (dstore == NULL)
-    return GNUNET_SYSERR;
-  return GNUNET_OK;
-}
-
-/**
- * Shutdown dstore DHT component.
- *
- * @return GNUNET_OK on success
- */
-int
-done_dht_store ()
-{
-  coreAPI->GNUNET_CORE_release_service (dstore);
-  coreAPI = NULL;
-  dstore = NULL;
-  return GNUNET_OK;
-}
-
-/* end of dstore.c */

Deleted: GNUnet/src/applications/dht/module/dstore.h
===================================================================
--- GNUnet/src/applications/dht/module/dstore.h 2007-12-14 05:22:01 UTC (rev 
5895)
+++ GNUnet/src/applications/dht/module/dstore.h 2007-12-14 06:00:58 UTC (rev 
5896)
@@ -1,64 +0,0 @@
-/*
-      This file is part of GNUnet
-      (C) 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 module/dstore.h
- * @brief entries in local DHT
- * @author Christian Grothoff
- */
-
-#ifndef DHT_DSTORE_H
-#define DHT_DSTORE_H
-
-#include "gnunet_util.h"
-#include "gnunet_dstore_service.h"
-
-/**
- * Lookup in the local datastore.
- * @return total number of results found
- */
-int dht_store_get (const GNUNET_HashCode * key,
-                   unsigned int type, GNUNET_ResultProcessor handler,
-                   void *cls);
-
-/**
- * Store the given data in the local datastore.
- */
-void dht_store_put (unsigned int type,
-                    const GNUNET_HashCode * key,
-                    GNUNET_CronTime discard_time, unsigned int size,
-                    const char *data);
-
-/**
- * Initialize dstore DHT component.
- *
- * @param capi the core API
- * @return GNUNET_OK on success
- */
-int init_dht_store (size_t max_size, GNUNET_CoreAPIForPlugins * capi);
-
-/**
- * Shutdown dstore DHT component.
- *
- * @return GNUNET_OK on success
- */
-int done_dht_store (void);
-
-#endif

Modified: GNUnet/src/applications/dht/module/routing.c
===================================================================
--- GNUnet/src/applications/dht/module/routing.c        2007-12-14 05:22:01 UTC 
(rev 5895)
+++ GNUnet/src/applications/dht/module/routing.c        2007-12-14 06:00:58 UTC 
(rev 5896)
@@ -194,6 +194,8 @@
  */
 static GNUNET_Stats_ServiceAPI *stats;
 
+static GNUNET_Dstore_ServiceAPI *dstore;
+
 static struct GNUNET_Mutex *lock;
 
 static GNUNET_CoreAPIForPlugins *coreAPI;
@@ -476,7 +478,7 @@
 #endif
       return GNUNET_OK;           /* could not route */
     }
-  total = dht_store_get (&get->key, ntohl (get->type), &routeResult, NULL);
+  total = dstore->get (&get->key, ntohl (get->type), &routeResult, NULL);
   if ((total > GET_TRIES) && (sender != NULL))
     {
 #if DEBUG_ROUTING
@@ -613,11 +615,11 @@
                      &put[1], CONTENT_LIFETIME + now,
                      CONTENT_LIFETIME);
 #endif
-      dht_store_put (ntohl (put->type),
-                     &put->key,
-                     CONTENT_LIFETIME + now,
-                     ntohs (put->header.size) - sizeof (DHT_MESSAGE),
-                     (const char *) &put[1]);
+      dstore->put (ntohl (put->type),
+                  &put->key,
+                  CONTENT_LIFETIME + now,
+                  ntohs (put->header.size) - sizeof (DHT_MESSAGE),
+                  (const char *) &put[1]);
     }
   else
     {
@@ -812,7 +814,11 @@
                                             "DHT",
                                             "TABLESIZE",
                                             128, 1024 * 1024, 1024, &rts);
+  dstore = coreAPI->GNUNET_CORE_request_service ("dstore");
+  if (dstore == NULL) 
+    return GNUNET_SYSERR;    
   GNUNET_array_grow (records, rt_size, rts);
+
   lock = GNUNET_mutex_create (GNUNET_NO);
   stats = capi->GNUNET_CORE_request_service ("stats");
   if (stats != NULL)
@@ -828,6 +834,7 @@
       stat_results_received =
         stats->create (gettext_noop ("# dht results received"));
     }
+
   GNUNET_GE_LOG (coreAPI->ectx,
                  GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
                  _("`%s' registering p2p handlers: %d %d %d\n"),
@@ -873,6 +880,7 @@
         }
     }
   GNUNET_array_grow (records, rt_size, 0);
+  coreAPI->GNUNET_CORE_release_service (dstore);
   return GNUNET_OK;
 }
 





reply via email to

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