gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r7812 - GNUnet/src/applications/topology_default


From: gnunet
Subject: [GNUnet-SVN] r7812 - GNUnet/src/applications/topology_default
Date: Thu, 30 Oct 2008 06:07:52 -0600 (MDT)

Author: durner
Date: 2008-10-30 06:07:52 -0600 (Thu, 30 Oct 2008)
New Revision: 7812

Modified:
   GNUnet/src/applications/topology_default/topology.c
Log:
reload friends config only if necessary

Modified: GNUnet/src/applications/topology_default/topology.c
===================================================================
--- GNUnet/src/applications/topology_default/topology.c 2008-10-28 05:45:35 UTC 
(rev 7811)
+++ GNUnet/src/applications/topology_default/topology.c 2008-10-30 12:07:52 UTC 
(rev 7812)
@@ -105,6 +105,10 @@
  */
 static int friends_only;
 
+/**
+ * Last modification of friends file
+ */
+static time_t friends_mtime;
 
 
 /**
@@ -420,11 +424,11 @@
 {
   char *fn;
   char *data;
-  unsigned long long size;
   size_t pos;
   GNUNET_EncName enc;
   GNUNET_HashCode hc;
   unsigned long long opt;
+  struct stat frstat;
 
   if (0 != strcmp (section, "F2F"))
     return 0;
@@ -452,8 +456,7 @@
     {
       GNUNET_disk_file_write (ectx, fn, NULL, 0, "600");
     }
-  if ((0 == GNUNET_disk_file_test (ectx, fn))
-      || (GNUNET_OK != GNUNET_disk_file_size (ectx, fn, &size, GNUNET_YES)))
+  if ((0 == GNUNET_disk_file_test (ectx, fn)) || (0 != STAT (fn, &frstat)))
     {
       GNUNET_free (fn);
       fn = NULL;
@@ -466,10 +469,15 @@
           return GNUNET_SYSERR;
         }
     }
-  if ((fn != NULL) && (size > 0))
+  if (frstat.st_mtime != friends_mtime)
+    friends_mtime = frstat.st_mtime;
+  else
+    return 0;
+  if ((fn != NULL) && (frstat.st_size > 0))
     {
-      data = GNUNET_malloc (size);
-      if (size != GNUNET_disk_file_read (ectx, fn, size, data))
+      data = GNUNET_malloc (frstat.st_size);
+      if (frstat.st_size !=
+          GNUNET_disk_file_read (ectx, fn, frstat.st_size, data))
         {
           GNUNET_GE_LOG (ectx,
                          GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
@@ -481,10 +489,10 @@
       GNUNET_free (fn);
       fn = NULL;
       pos = 0;
-      while ((pos < size) && isspace (data[pos]))
+      while ((pos < frstat.st_size) && isspace (data[pos]))
         pos++;
-      while ((size >= sizeof (GNUNET_EncName)) &&
-             (pos <= size - sizeof (GNUNET_EncName)))
+      while ((frstat.st_size >= sizeof (GNUNET_EncName)) &&
+             (pos <= frstat.st_size - sizeof (GNUNET_EncName)))
         {
           memcpy (&enc, &data[pos], sizeof (GNUNET_EncName));
           if (!isspace (enc.encoding[sizeof (GNUNET_EncName) - 1]))
@@ -495,7 +503,7 @@
                              _
                              ("Syntax error in topology specification, 
skipping bytes.\n"));
               pos++;
-              while ((pos < size) && (!isspace (data[pos])))
+              while ((pos < frstat.st_size) && (!isspace (data[pos])))
                 pos++;
               continue;
             }
@@ -515,7 +523,7 @@
                              &enc);
             }
           pos = pos + sizeof (GNUNET_EncName);
-          while ((pos < size) && isspace (data[pos]))
+          while ((pos < frstat.st_size) && isspace (data[pos]))
             pos++;
         }
       if ((minimum_friend_count > friendCount) && (friends_only == GNUNET_NO))





reply via email to

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