2 This file is part of GNUnet.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file rps/rps-test_util.c
23 * @brief Some utils faciliating the view into the internals for the sampler
24 * needed for evaluation
26 * @author Julius Bünger
30 #include "gnunet_util_lib.h"
34 #define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler",__VA_ARGS__)
42 to_file_ (char *file_name, char *line)
44 struct GNUNET_DISK_FileHandle *f;
45 char output_buffer[512];
51 if (NULL == (f = GNUNET_DISK_file_open (file_name,
52 GNUNET_DISK_OPEN_APPEND |
53 GNUNET_DISK_OPEN_WRITE |
54 GNUNET_DISK_OPEN_CREATE,
55 GNUNET_DISK_PERM_USER_WRITE)))
57 LOG (GNUNET_ERROR_TYPE_WARNING,
58 "Not able to open file %s\n",
62 size = GNUNET_snprintf (output_buffer,
63 sizeof (output_buffer),
65 GNUNET_TIME_absolute_get ().abs_value_us,
69 LOG (GNUNET_ERROR_TYPE_WARNING,
70 "Failed to write string to buffer (size: %i)\n",
75 size2 = GNUNET_DISK_file_write (f, output_buffer, size);
78 LOG (GNUNET_ERROR_TYPE_WARNING,
79 "Unable to write to file! (Size: %u, size2: %u)\n",
85 if (GNUNET_YES != GNUNET_DISK_file_close (f))
86 LOG (GNUNET_ERROR_TYPE_WARNING,
87 "Unable to close file\n");
91 auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key)
98 size_t keylen = (sizeof (struct GNUNET_CRYPTO_AuthKey)) * 8;
100 name_buf_size = 512 * sizeof (char);
101 name_buf = GNUNET_malloc (name_buf_size);
104 keylen += 5 - keylen % 5;
106 buf = GNUNET_malloc (keylen + 1);
108 end = GNUNET_STRINGS_data_to_string (&(auth_key.key),
109 sizeof (struct GNUNET_CRYPTO_AuthKey),
123 size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s-", buf);
125 LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n");
133 create_file (const char *name)
136 size_t name_buf_size;
141 prefix = "/tmp/rps/";
142 name_buf_size = (strlen (prefix) + strlen (name) + 2) * sizeof (char);
143 name_buf = GNUNET_malloc (name_buf_size);
145 size = GNUNET_snprintf (name_buf, name_buf_size, "%s%s-", prefix, name);
147 LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n");
149 GNUNET_DISK_directory_create (prefix);
151 file_name = GNUNET_malloc (strlen (name_buf) + 6);
153 if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf)))
154 LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n");
156 GNUNET_free (name_buf);
163 /* end of gnunet-service-rps.c */