gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r8021 - in GNUnet/src: applications/fs/ecrs applications/fs


From: gnunet
Subject: [GNUnet-SVN] r8021 - in GNUnet/src: applications/fs/ecrs applications/fs/gap applications/testing include
Date: Fri, 26 Dec 2008 22:57:31 -0700 (MST)

Author: grothoff
Date: 2008-12-26 22:57:31 -0700 (Fri, 26 Dec 2008)
New Revision: 8021

Modified:
   GNUnet/src/applications/fs/ecrs/download.c
   GNUnet/src/applications/fs/gap/plan.c
   GNUnet/src/applications/fs/gap/shared.c
   GNUnet/src/applications/testing/testing.c
   GNUnet/src/include/gnunet_util_containers.h
Log:
more use of DLL macros

Modified: GNUnet/src/applications/fs/ecrs/download.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/download.c  2008-12-27 05:57:07 UTC (rev 
8020)
+++ GNUnet/src/applications/fs/ecrs/download.c  2008-12-27 05:57:31 UTC (rev 
8021)
@@ -223,14 +223,14 @@
   while (rm->head != NULL)
     {
       pos = rm->head;
+      GNUNET_DLL_remove(rm->head, rm->tail, pos);
       if (rm->my_sctx != GNUNET_YES)
         GNUNET_FS_stop_search (rm->sctx, &content_receive_callback, pos);
-      rm->head = pos->next;
       GNUNET_free (pos);
     }
   if (rm->my_sctx != GNUNET_YES)
     GNUNET_FS_resume_search_context (rm->sctx);
-  rm->tail = NULL;
+  GNUNET_GE_ASSERT(NULL, rm->tail == NULL);
   if (rm->handle >= 0)
     CLOSE (rm->handle);
   if (rm->main != NULL)
@@ -302,13 +302,7 @@
 {
   struct GNUNET_ECRS_DownloadContext *rm = node->ctx;
 
-  node->next = rm->head;
-  if (node->next != NULL)
-    node->next->prev = node;
-  node->prev = NULL;
-  rm->head = node;
-  if (rm->tail == NULL)
-    rm->tail = node;
+  GNUNET_DLL_insert(rm->head, rm->tail, node);
   GNUNET_FS_start_search (rm->sctx,
                           rm->have_target == GNUNET_NO ? NULL : &rm->target,
                           GNUNET_ECRS_BLOCKTYPE_DATA, 1,
@@ -337,14 +331,7 @@
 {
   struct GNUNET_ECRS_DownloadContext *rm = node->ctx;
 
-  if (node->prev == NULL)
-    rm->head = node->next;
-  else
-    node->prev->next = node->next;
-  if (node->next == NULL)
-    rm->tail = node->prev;
-  else
-    node->next->prev = node->prev;
+  GNUNET_DLL_remove(rm->head, rm->tail, node);
   GNUNET_free (node);
   if (rm->head == NULL)
     GNUNET_thread_stop_sleep (rm->main);

Modified: GNUnet/src/applications/fs/gap/plan.c
===================================================================
--- GNUnet/src/applications/fs/gap/plan.c       2008-12-27 05:57:07 UTC (rev 
8020)
+++ GNUnet/src/applications/fs/gap/plan.c       2008-12-27 05:57:31 UTC (rev 
8021)
@@ -341,25 +341,7 @@
   while (total-- > 0)
     pos = pos->next;
   /* insert into datastructure at pos */
-  if (pos == NULL)
-    {
-      if (qpl->tail != NULL)
-        qpl->tail->next = entry;
-      else
-        qpl->head = entry;
-      entry->prev = qpl->tail;
-      qpl->tail = entry;
-    }
-  else
-    {
-      entry->next = pos->next;
-      if (pos->next == NULL)
-        qpl->tail = entry;
-      else
-        pos->next->prev = entry;
-      entry->prev = pos;
-      pos->next = entry;
-    }
+  GNUNET_DLL_insert_after(qpl->head, qpl->tail, pos, entry);
 }
 
 /**
@@ -742,14 +724,7 @@
           if (ret != 0)
             {
               /* remove e from e's doubly-linked list */
-              if (e->prev != NULL)
-                e->prev->next = e->next;
-              else
-                pl->head = e->next;
-              if (e->next != NULL)
-                e->next->prev = e->prev;
-              else
-                pl->tail = e->prev;
+             GNUNET_DLL_remove(pl->head, pl->tail, e);
               /* remove e from singly-linked list of request */
               prev = NULL;
               pos = e->request->plan_entries;

Modified: GNUnet/src/applications/fs/gap/shared.c
===================================================================
--- GNUnet/src/applications/fs/gap/shared.c     2008-12-27 05:57:07 UTC (rev 
8020)
+++ GNUnet/src/applications/fs/gap/shared.c     2008-12-27 05:57:31 UTC (rev 
8021)
@@ -49,14 +49,7 @@
     {
       planl = rl->plan_entries;
       rl->plan_entries = planl->plan_entries_next;
-      if (planl->next != NULL)
-        planl->next->prev = planl->prev;
-      else
-        planl->list->tail = planl->prev;
-      if (planl->prev != NULL)
-        planl->prev->next = planl->next;
-      else
-        planl->list->head = planl->next;
+      GNUNET_DLL_remove(planl->list->head, planl->list->tail, planl);
       GNUNET_free (planl);
     }
   if (rl->bloomfilter != NULL)

Modified: GNUnet/src/applications/testing/testing.c
===================================================================
--- GNUnet/src/applications/testing/testing.c   2008-12-27 05:57:07 UTC (rev 
8020)
+++ GNUnet/src/applications/testing/testing.c   2008-12-27 05:57:31 UTC (rev 
8021)
@@ -86,7 +86,9 @@
   GNUNET_MessageHello *hello;
   int round;
 
+#if VERBOSE
   fprintf (stderr, "Starting peer on port %u\n", app_port);
+#endif
 #if 0
   /* do not usually do this -- may easily
      exhaust entropy pool for hostkey generation... */
@@ -262,7 +264,9 @@
       sock1 = GNUNET_client_connection_create (NULL, cfg1);
       sock2 = GNUNET_client_connection_create (NULL, cfg2);
       ret = -20;
+#if VERBOSE
       fprintf (stderr, _("Waiting for peers to connect"));
+#endif
       while ((ret++ < -1) && (GNUNET_shutdown_test () == GNUNET_NO))
         {
           h1 = NULL;
@@ -275,7 +279,9 @@
                                                       h2)) &&
               (GNUNET_OK == GNUNET_IDENTITY_peer_add (sock2, h1)))
             {
+#if VERBOSE
               fprintf (stderr, ".");
+#endif
               if (GNUNET_YES == GNUNET_IDENTITY_request_connect (sock1,
                                                                  
&h2->senderIdentity))
                 {
@@ -313,13 +319,17 @@
           GNUNET_IDENTITY_request_peer_infos (sock2, &printInfo, NULL);
 #endif
         }
+#if VERBOSE
       fprintf (stderr, "%s\n", ret == GNUNET_OK ? "!" : "?");
+#endif
       GNUNET_client_connection_destroy (sock1);
       GNUNET_client_connection_destroy (sock2);
     }
   else
     {
+#if VERBOSE
       fprintf (stderr, "Failed to establish connection with peers.\n");
+#endif
     }
   GNUNET_GC_free (cfg1);
   GNUNET_GC_free (cfg2);

Modified: GNUnet/src/include/gnunet_util_containers.h
===================================================================
--- GNUnet/src/include/gnunet_util_containers.h 2008-12-27 05:57:07 UTC (rev 
8020)
+++ GNUnet/src/include/gnunet_util_containers.h 2008-12-27 05:57:31 UTC (rev 
8021)
@@ -538,6 +538,31 @@
   (head) = (element);
 
 /**
+ * Insert an element into a DLL after the given other 
+ * element.  Insert at the head if the other
+ * element is NULL.
+ */
+#define GNUNET_DLL_insert_after(head,tail,other,element) \
+  (element)->prev = (other); \
+  if (NULL == other) \
+    { \
+      (element)->next = (head); \
+      (head) = (element); \
+    } \
+  else \
+    { \
+      (element)->next = (other)->next; \
+      (other)->next = (element); \
+    } \
+  if (NULL == (element)->next) \
+    (tail) = (element); \
+  else \
+    (element)->next->prev = (element); 
+
+
+
+
+/**
  * Remove an element from a DLL. Assumes
  * that head, tail and element are structs
  * with prev and next fields.





reply via email to

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