aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rps/gnunet-rps-profiler.c1
-rw-r--r--src/rps/gnunet-service-rps.c1
-rw-r--r--src/rps/rps-test_util.c99
-rw-r--r--src/rps/rps-test_util.h40
-rw-r--r--src/rps/test_rps.c1
5 files changed, 131 insertions, 11 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c
index 5ccf1017e..35a77e1bb 100644
--- a/src/rps/gnunet-rps-profiler.c
+++ b/src/rps/gnunet-rps-profiler.c
@@ -1102,6 +1102,7 @@ shutdown_op (void *cls)
1102 { 1102 {
1103 clean_peer (i); 1103 clean_peer (i);
1104 } 1104 }
1105 close_all_files();
1105} 1106}
1106 1107
1107static void 1108static void
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 20b314db3..f121db5b8 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -4556,6 +4556,7 @@ shutdown_task (void *cls)
4556 GNUNET_free (tmp_att_peer); 4556 GNUNET_free (tmp_att_peer);
4557 } 4557 }
4558#endif /* ENABLE_MALICIOUS */ 4558#endif /* ENABLE_MALICIOUS */
4559 close_all_files();
4559} 4560}
4560 4561
4561 4562
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index a6ea033cd..d0d195229 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -56,6 +56,105 @@ static char buf_unaligned;
56 */ 56 */
57static unsigned num_bits_buf_unaligned; 57static unsigned num_bits_buf_unaligned;
58 58
59static struct GNUNET_CONTAINER_MultiHashMap *open_files;
60
61
62
63/**
64 * @brief Get file handle
65 *
66 * If necessary, create file handle and store it with the other file handles.
67 *
68 * @param name Name of the file
69 *
70 * @return File handle
71 */
72struct GNUNET_DISK_FileHandle *
73get_file_handle (const char *name)
74{
75 struct GNUNET_HashCode hash;
76 struct GNUNET_DISK_FileHandle *fh;
77
78 if (NULL == open_files)
79 {
80 open_files = GNUNET_CONTAINER_multihashmap_create (16,
81 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
82 }
83 GNUNET_CRYPTO_hash (name,
84 strnlen (name,
85 512),
86 &hash);
87 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (open_files,
88 &hash))
89 {
90 fh = GNUNET_DISK_file_open (name,
91 GNUNET_DISK_OPEN_APPEND,
92 GNUNET_DISK_PERM_USER_READ |
93 GNUNET_DISK_PERM_USER_WRITE |
94 GNUNET_DISK_PERM_GROUP_READ);
95 GNUNET_CONTAINER_multihashmap_put (open_files,
96 &hash,
97 fh,
98 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
99 return fh;
100 }
101 else
102 {
103 fh = GNUNET_CONTAINER_multihashmap_get (open_files,
104 &hash);
105 return fh;
106 }
107}
108
109
110/**
111 * @brief Closes the file of the current entry
112 *
113 * Implements #GNUNET_CONTAINER_HashMapIterator
114 *
115 * @param cls unused
116 * @param key unused
117 * @param value the file handle
118 *
119 * @return #GNUNET_YES if we should continue to
120 * iterate,
121 * #GNUNET_NO if not.
122 */
123int
124close_files_iter (void *cls,
125 const struct GNUNET_HashCode *key,
126 void *value)
127{
128 (void) cls;
129 (void) key;
130 struct GNUNET_DISK_FileHandle *fh = value;
131
132 if (NULL != fh)
133 {
134 GNUNET_DISK_file_close (fh);
135 }
136 return GNUNET_YES;
137}
138
139
140/**
141 * @brief Close all files that were opened with #get_file_handle
142 *
143 * @return Success of iterating over files
144 */
145int
146close_all_files ()
147{
148 int ret;
149
150 ret = GNUNET_CONTAINER_multihashmap_iterate (open_files,
151 close_files_iter,
152 NULL);
153 GNUNET_CONTAINER_multihashmap_destroy (open_files);
154 return ret;
155}
156
157
59 158
60void 159void
61to_file_raw (const char *file_name, const char *buf, size_t size_buf) 160to_file_raw (const char *file_name, const char *buf, size_t size_buf)
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h
index a806f11cd..5dfcc5f6a 100644
--- a/src/rps/rps-test_util.h
+++ b/src/rps/rps-test_util.h
@@ -39,23 +39,43 @@ char *
39create_file (const char *name); 39create_file (const char *name);
40 40
41/** 41/**
42 * @brief Get file handle
43 *
44 * If necessary, create file handle and store it with the other file handles.
45 *
46 * @param name Name of the file
47 *
48 * @return File handle
49 */
50struct GNUNET_DISK_FileHandle *
51get_file_handle (const char *name);
52
53/**
54 * @brief Close all files that were opened with #get_file_handle
55 *
56 * @return Success of iterating over files
57 */
58int
59close_all_files ();
60
61/**
42 * This function is used to facilitate writing important information to disk 62 * This function is used to facilitate writing important information to disk
43 */ 63 */
44#ifdef TO_FILE 64#ifdef TO_FILE
45# define to_file(file_name, ...) do {char tmp_buf[512] = "";\ 65#define to_file(file_name, ...) do {GNUNET_assert (NULL != file_name);\
66 char tmp_buf[512] = "";\
46 int size;\ 67 int size;\
47 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ 68 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
48 if (0 > size)\ 69 if (0 > size)\
49 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ 70 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
50 "Failed to create tmp_buf\n");\ 71 "Failed to create tmp_buf\n");\
51 else\ 72 else\
52 GNUNET_DISK_fn_write(file_name, tmp_buf, strnlen(tmp_buf, 512),\ 73 GNUNET_DISK_file_write (get_file_handle (file_name),\
53 GNUNET_DISK_PERM_USER_READ |\ 74 tmp_buf,\
54 GNUNET_DISK_PERM_USER_WRITE |\ 75 strnlen (tmp_buf, 512));\
55 GNUNET_DISK_PERM_GROUP_READ |\
56 GNUNET_DISK_PERM_OTHER_READ);\
57 } while (0); 76 } while (0);
58 77
78
59#define to_file_w_len(file_name, len, ...) do {char tmp_buf[len];\ 79#define to_file_w_len(file_name, len, ...) do {char tmp_buf[len];\
60 int size;\ 80 int size;\
61 memset (tmp_buf, 0, len);\ 81 memset (tmp_buf, 0, len);\
@@ -64,11 +84,9 @@ create_file (const char *name);
64 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ 84 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
65 "Failed to create tmp_buf\n");\ 85 "Failed to create tmp_buf\n");\
66 else\ 86 else\
67 GNUNET_DISK_fn_write(file_name, tmp_buf, strnlen(tmp_buf, len), \ 87 GNUNET_DISK_file_write (get_file_handle (file_name),\
68 GNUNET_DISK_PERM_USER_READ |\ 88 tmp_buf,\
69 GNUNET_DISK_PERM_USER_WRITE |\ 89 strnlen (tmp_buf, 512));\
70 GNUNET_DISK_PERM_GROUP_READ |\
71 GNUNET_DISK_PERM_OTHER_READ);\
72 } while (0); 90 } while (0);
73#else /* TO_FILE */ 91#else /* TO_FILE */
74# define to_file(file_name, ...) 92# define to_file(file_name, ...)
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 63a6007ae..72dc90b17 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -806,6 +806,7 @@ shutdown_op (void *cls)
806 GNUNET_TESTBED_operation_done (rps_peers[i].op); 806 GNUNET_TESTBED_operation_done (rps_peers[i].op);
807 } 807 }
808 } 808 }
809 close_all_files();
809} 810}
810 811
811 812