diff options
author | Julius Bünger <buenger@mytum.de> | 2018-10-20 14:21:02 +0200 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2018-10-20 14:47:31 +0200 |
commit | d2bdef77c4f13b1e51ac72340b7e1cc1535f6bb3 (patch) | |
tree | 25b0af7a6fb8389827e0cf7fbb22730bda266ee0 /src/rps | |
parent | 061e86b157b1f13062ef879656a1c2678a8b6f35 (diff) | |
download | gnunet-d2bdef77c4f13b1e51ac72340b7e1cc1535f6bb3.tar.gz gnunet-d2bdef77c4f13b1e51ac72340b7e1cc1535f6bb3.zip |
RPS: Fix writing internals to disk
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/Makefile.am | 3 | ||||
-rw-r--r-- | src/rps/rps-test_util.c | 72 | ||||
-rw-r--r-- | src/rps/rps-test_util.h | 21 |
3 files changed, 18 insertions, 78 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am index e6b74c9a2..3b5b1ef3e 100644 --- a/src/rps/Makefile.am +++ b/src/rps/Makefile.am | |||
@@ -30,6 +30,7 @@ gnunet_rps_LDADD = \ | |||
30 | lib_LTLIBRARIES = libgnunetrps.la | 30 | lib_LTLIBRARIES = libgnunetrps.la |
31 | 31 | ||
32 | libgnunetrps_la_SOURCES = \ | 32 | libgnunetrps_la_SOURCES = \ |
33 | gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \ | ||
33 | rps-test_util.h rps-test_util.c \ | 34 | rps-test_util.h rps-test_util.c \ |
34 | rps-sampler_common.h rps-sampler_common.c \ | 35 | rps-sampler_common.h rps-sampler_common.c \ |
35 | rps-sampler_client.h rps-sampler_client.c \ | 36 | rps-sampler_client.h rps-sampler_client.c \ |
@@ -40,6 +41,8 @@ libgnunetrps_la_LIBADD = \ | |||
40 | libgnunetrps_la_LDFLAGS = \ | 41 | libgnunetrps_la_LDFLAGS = \ |
41 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | 42 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ |
42 | -version-info 0:0:0 | 43 | -version-info 0:0:0 |
44 | # Fix 'created both with libtool and without' error: | ||
45 | libgnunetrps_la_CFLAGS = $(AM_CFLAGS) | ||
43 | 46 | ||
44 | 47 | ||
45 | libexec_PROGRAMS = \ | 48 | libexec_PROGRAMS = \ |
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index ffd43f6b1..f3367e01b 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c | |||
@@ -57,76 +57,6 @@ static char buf_unaligned; | |||
57 | */ | 57 | */ |
58 | static unsigned num_bits_buf_unaligned; | 58 | static unsigned num_bits_buf_unaligned; |
59 | 59 | ||
60 | void | ||
61 | to_file_ (const char *file_name, char *line) | ||
62 | { | ||
63 | struct GNUNET_DISK_FileHandle *f; | ||
64 | char output_buffer[512]; | ||
65 | size_t output_buffer_size = 512; | ||
66 | char *output_buffer_p; | ||
67 | //size_t size; | ||
68 | int size; | ||
69 | int size2; | ||
70 | |||
71 | |||
72 | if (NULL == (f = GNUNET_DISK_file_open (file_name, | ||
73 | GNUNET_DISK_OPEN_APPEND | | ||
74 | GNUNET_DISK_OPEN_WRITE | | ||
75 | GNUNET_DISK_OPEN_CREATE, | ||
76 | GNUNET_DISK_PERM_USER_READ | | ||
77 | GNUNET_DISK_PERM_USER_WRITE | | ||
78 | GNUNET_DISK_PERM_GROUP_READ | | ||
79 | GNUNET_DISK_PERM_OTHER_READ))) | ||
80 | { | ||
81 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
82 | "Not able to open file %s\n", | ||
83 | file_name); | ||
84 | return; | ||
85 | } | ||
86 | output_buffer_size = strlen (line) + 18; | ||
87 | if (512 < output_buffer_size) | ||
88 | { | ||
89 | output_buffer_p = GNUNET_malloc ((output_buffer_size) * sizeof (char)); | ||
90 | } else { | ||
91 | output_buffer_p = &output_buffer[0]; | ||
92 | } | ||
93 | size = GNUNET_snprintf (output_buffer_p, | ||
94 | output_buffer_size, | ||
95 | "%llu %s\n", | ||
96 | (GNUNET_TIME_absolute_get ().abs_value_us) / 1000000, // microsec -> sec | ||
97 | line); | ||
98 | if (0 > size) | ||
99 | { | ||
100 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
101 | "Failed to write string to buffer (size: %i)\n", | ||
102 | size); | ||
103 | return; | ||
104 | } | ||
105 | |||
106 | size2 = GNUNET_DISK_file_write (f, output_buffer_p, size); | ||
107 | if (size != size2) | ||
108 | { | ||
109 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
110 | "Unable to write to file! (Size: %u, size2: %u)\n", | ||
111 | size, | ||
112 | size2); | ||
113 | |||
114 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
115 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
116 | "Unable to close file\n"); | ||
117 | |||
118 | return; | ||
119 | } | ||
120 | |||
121 | if (512 < output_buffer_size) | ||
122 | { | ||
123 | GNUNET_free (output_buffer_p); | ||
124 | } | ||
125 | |||
126 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
127 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
128 | "Unable to close file\n"); | ||
129 | } | ||
130 | 60 | ||
131 | void | 61 | void |
132 | to_file_raw (const char *file_name, const char *buf, size_t size_buf) | 62 | to_file_raw (const char *file_name, const char *buf, size_t size_buf) |
@@ -457,7 +387,7 @@ static int ensure_folder_exist (void) | |||
457 | return GNUNET_YES; | 387 | return GNUNET_YES; |
458 | } | 388 | } |
459 | 389 | ||
460 | const char * | 390 | char * |
461 | store_prefix_file_name (const struct GNUNET_PeerIdentity *peer, | 391 | store_prefix_file_name (const struct GNUNET_PeerIdentity *peer, |
462 | const char *prefix) | 392 | const char *prefix) |
463 | { | 393 | { |
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h index 2e6560723..11093420e 100644 --- a/src/rps/rps-test_util.h +++ b/src/rps/rps-test_util.h | |||
@@ -29,9 +29,6 @@ | |||
29 | #define TO_FILE 1 | 29 | #define TO_FILE 1 |
30 | 30 | ||
31 | 31 | ||
32 | void | ||
33 | to_file_ (const char *file_name, char *line); | ||
34 | |||
35 | char * | 32 | char * |
36 | auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key); | 33 | auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key); |
37 | 34 | ||
@@ -45,23 +42,33 @@ create_file (const char *name); | |||
45 | * This function is used to facilitate writing important information to disk | 42 | * This function is used to facilitate writing important information to disk |
46 | */ | 43 | */ |
47 | #ifdef TO_FILE | 44 | #ifdef TO_FILE |
48 | # define to_file(file_name, ...) do {char tmp_buf[512];\ | 45 | # define to_file(file_name, ...) do {char tmp_buf[512] = "";\ |
49 | int size;\ | 46 | int size;\ |
50 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | 47 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ |
51 | if (0 > size)\ | 48 | if (0 > size)\ |
52 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | 49 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ |
53 | "Failed to create tmp_buf\n");\ | 50 | "Failed to create tmp_buf\n");\ |
54 | else\ | 51 | else\ |
55 | to_file_(file_name,tmp_buf);\ | 52 | GNUNET_DISK_fn_write(file_name,tmp_buf, sizeof(tmp_buf),\ |
53 | GNUNET_DISK_PERM_USER_READ |\ | ||
54 | GNUNET_DISK_PERM_USER_WRITE |\ | ||
55 | GNUNET_DISK_PERM_GROUP_READ |\ | ||
56 | GNUNET_DISK_PERM_OTHER_READ);\ | ||
56 | } while (0); | 57 | } while (0); |
57 | # define to_file_w_len(file_name, len, ...) do {char tmp_buf[len];\ | 58 | |
59 | #define to_file_w_len(file_name, len, ...) do {char tmp_buf[len];\ | ||
58 | int size;\ | 60 | int size;\ |
61 | memset (tmp_buf, 0, len);\ | ||
59 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | 62 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ |
60 | if (0 > size)\ | 63 | if (0 > size)\ |
61 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | 64 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ |
62 | "Failed to create tmp_buf\n");\ | 65 | "Failed to create tmp_buf\n");\ |
63 | else\ | 66 | else\ |
64 | to_file_(file_name,tmp_buf);\ | 67 | GNUNET_DISK_fn_write(file_name,tmp_buf, len, \ |
68 | GNUNET_DISK_PERM_USER_READ |\ | ||
69 | GNUNET_DISK_PERM_USER_WRITE |\ | ||
70 | GNUNET_DISK_PERM_GROUP_READ |\ | ||
71 | GNUNET_DISK_PERM_OTHER_READ);\ | ||
65 | } while (0); | 72 | } while (0); |
66 | #else /* TO_FILE */ | 73 | #else /* TO_FILE */ |
67 | # define to_file(file_name, ...) | 74 | # define to_file(file_name, ...) |