RPS: Fix writing internals to disk
authorJulius Bünger <buenger@mytum.de>
Sat, 20 Oct 2018 12:21:02 +0000 (14:21 +0200)
committerJulius Bünger <buenger@mytum.de>
Sat, 20 Oct 2018 12:47:31 +0000 (14:47 +0200)
src/rps/Makefile.am
src/rps/rps-test_util.c
src/rps/rps-test_util.h

index e6b74c9a2166ab7d8d68669be2b7ff865afd173d..3b5b1ef3ea77fcb05d5cf1922c975bb0d875836f 100644 (file)
@@ -30,6 +30,7 @@ gnunet_rps_LDADD = \
 lib_LTLIBRARIES = libgnunetrps.la
 
 libgnunetrps_la_SOURCES = \
+ gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \
   rps-test_util.h rps-test_util.c \
   rps-sampler_common.h rps-sampler_common.c \
   rps-sampler_client.h rps-sampler_client.c \
@@ -40,6 +41,8 @@ libgnunetrps_la_LIBADD = \
 libgnunetrps_la_LDFLAGS = \
   $(GN_LIB_LDFLAGS)  $(WINFLAGS) \
   -version-info 0:0:0
+# Fix 'created both with libtool and without' error:
+libgnunetrps_la_CFLAGS = $(AM_CFLAGS)
 
 
 libexec_PROGRAMS = \
index ffd43f6b10d8b548a6d789bf049c1ff1b0915700..f3367e01bec05a2c8e50d8dcd65ea7fe64ac26f3 100644 (file)
@@ -57,76 +57,6 @@ static char buf_unaligned;
  */
 static unsigned num_bits_buf_unaligned;
 
-void
-to_file_ (const char *file_name, char *line)
-{
-  struct GNUNET_DISK_FileHandle *f;
-  char output_buffer[512];
-  size_t output_buffer_size = 512;
-  char *output_buffer_p;
-  //size_t size;
-  int size;
-  int size2;
-
-
-  if (NULL == (f = GNUNET_DISK_file_open (file_name,
-                                          GNUNET_DISK_OPEN_APPEND |
-                                          GNUNET_DISK_OPEN_WRITE |
-                                          GNUNET_DISK_OPEN_CREATE,
-                                          GNUNET_DISK_PERM_USER_READ |
-                                          GNUNET_DISK_PERM_USER_WRITE |
-                                          GNUNET_DISK_PERM_GROUP_READ |
-                                          GNUNET_DISK_PERM_OTHER_READ)))
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Not able to open file %s\n",
-         file_name);
-    return;
-  }
-  output_buffer_size = strlen (line) + 18;
-  if (512 < output_buffer_size)
-  {
-    output_buffer_p = GNUNET_malloc ((output_buffer_size) * sizeof (char));
-  } else {
-    output_buffer_p = &output_buffer[0];
-  }
-  size = GNUNET_snprintf (output_buffer_p,
-                          output_buffer_size,
-                          "%llu %s\n",
-                          (GNUNET_TIME_absolute_get ().abs_value_us) / 1000000, // microsec -> sec
-                          line);
-  if (0 > size)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Failed to write string to buffer (size: %i)\n",
-         size);
-    return;
-  }
-
-  size2 = GNUNET_DISK_file_write (f, output_buffer_p, size);
-  if (size != size2)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Unable to write to file! (Size: %u, size2: %u)\n",
-         size,
-         size2);
-
-    if (GNUNET_YES != GNUNET_DISK_file_close (f))
-      LOG (GNUNET_ERROR_TYPE_WARNING,
-           "Unable to close file\n");
-
-    return;
-  }
-
-  if (512 < output_buffer_size)
-  {
-    GNUNET_free (output_buffer_p);
-  }
-
-  if (GNUNET_YES != GNUNET_DISK_file_close (f))
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Unable to close file\n");
-}
 
 void
 to_file_raw (const char *file_name, const char *buf, size_t size_buf)
@@ -457,7 +387,7 @@ static int ensure_folder_exist (void)
   return GNUNET_YES;
 }
 
-const char *
+char *
 store_prefix_file_name (const struct GNUNET_PeerIdentity *peer,
     const char *prefix)
 {
index 2e656072369b2787befda98f414155cab230c565..11093420e8b86357bc4f07cbec1aafd408ff93da 100644 (file)
@@ -29,9 +29,6 @@
 #define TO_FILE 1
 
 
-void
-to_file_ (const char *file_name, char *line);
-
 char *
 auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key);
 
@@ -45,23 +42,33 @@ create_file (const char *name);
  * This function is used to facilitate writing important information to disk
  */
 #ifdef TO_FILE
-#  define to_file(file_name, ...) do {char tmp_buf[512];\
+#  define to_file(file_name, ...) do {char tmp_buf[512] = "";\
     int size;\
     size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
     if (0 > size)\
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
            "Failed to create tmp_buf\n");\
     else\
-      to_file_(file_name,tmp_buf);\
+      GNUNET_DISK_fn_write(file_name,tmp_buf, sizeof(tmp_buf),\
+                            GNUNET_DISK_PERM_USER_READ |\
+                            GNUNET_DISK_PERM_USER_WRITE |\
+                            GNUNET_DISK_PERM_GROUP_READ |\
+                            GNUNET_DISK_PERM_OTHER_READ);\
   } while (0);
-#  define to_file_w_len(file_name, len, ...) do {char tmp_buf[len];\
+
+#define to_file_w_len(file_name, len, ...) do {char tmp_buf[len];\
     int size;\
+    memset (tmp_buf, 0, len);\
     size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
     if (0 > size)\
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
            "Failed to create tmp_buf\n");\
     else\
-      to_file_(file_name,tmp_buf);\
+      GNUNET_DISK_fn_write(file_name,tmp_buf, len, \
+                            GNUNET_DISK_PERM_USER_READ |\
+                            GNUNET_DISK_PERM_USER_WRITE |\
+                            GNUNET_DISK_PERM_GROUP_READ |\
+                            GNUNET_DISK_PERM_OTHER_READ);\
   } while (0);
 #else /* TO_FILE */
 #  define to_file(file_name, ...)