summaryrefslogtreecommitdiff
path: root/src/fs/test_fs_unindex_persistence.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_fs_unindex_persistence.c')
-rw-r--r--src/fs/test_fs_unindex_persistence.c321
1 files changed, 168 insertions, 153 deletions
diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c
index 50d45708a..7deebb95b 100644
--- a/src/fs/test_fs_unindex_persistence.c
+++ b/src/fs/test_fs_unindex_persistence.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file fs/test_fs_unindex_persistence.c 22 * @file fs/test_fs_unindex_persistence.c
@@ -36,12 +36,12 @@
36/** 36/**
37 * How long until we give up on transmitting the message? 37 * How long until we give up on transmitting the message?
38 */ 38 */
39#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 39#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60)
40 40
41/** 41/**
42 * How long should our test-content live? 42 * How long should our test-content live?
43 */ 43 */
44#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 44#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15)
45 45
46 46
47static struct GNUNET_TIME_Absolute start; 47static struct GNUNET_TIME_Absolute start;
@@ -58,40 +58,40 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
58 58
59 59
60static void 60static void
61abort_publish_task (void *cls) 61abort_publish_task(void *cls)
62{ 62{
63 GNUNET_FS_publish_stop (publish); 63 GNUNET_FS_publish_stop(publish);
64 publish = NULL; 64 publish = NULL;
65} 65}
66 66
67 67
68static void 68static void
69abort_unindex_task (void *cls) 69abort_unindex_task(void *cls)
70{ 70{
71 if (unindex != NULL) 71 if (unindex != NULL)
72 { 72 {
73 GNUNET_FS_unindex_stop (unindex); 73 GNUNET_FS_unindex_stop(unindex);
74 unindex = NULL; 74 unindex = NULL;
75 } 75 }
76 if (fn != NULL) 76 if (fn != NULL)
77 { 77 {
78 GNUNET_DISK_directory_remove (fn); 78 GNUNET_DISK_directory_remove(fn);
79 GNUNET_free (fn); 79 GNUNET_free(fn);
80 fn = NULL; 80 fn = NULL;
81 } 81 }
82} 82}
83 83
84 84
85static void * 85static void *
86progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); 86progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event);
87 87
88 88
89static void 89static void
90restart_fs_task (void *cls) 90restart_fs_task(void *cls)
91{ 91{
92 GNUNET_FS_stop (fs); 92 GNUNET_FS_stop(fs);
93 fs = GNUNET_FS_start (cfg, "test-fs-unindex-persistence", &progress_cb, NULL, 93 fs = GNUNET_FS_start(cfg, "test-fs-unindex-persistence", &progress_cb, NULL,
94 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 94 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
95} 95}
96 96
97 97
@@ -103,7 +103,7 @@ restart_fs_task (void *cls)
103 * @param ev type of the event to consider 103 * @param ev type of the event to consider
104 */ 104 */
105static void 105static void
106consider_restart (int ev) 106consider_restart(int ev)
107{ 107{
108 static int prev[32]; 108 static int prev[32];
109 static int off; 109 static int off;
@@ -113,125 +113,140 @@ consider_restart (int ev)
113 if (prev[i] == ev) 113 if (prev[i] == ev)
114 return; 114 return;
115 prev[off++] = ev; 115 prev[off++] = ev;
116 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, 116 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT,
117 &restart_fs_task, NULL); 117 &restart_fs_task, NULL);
118} 118}
119 119
120 120
121static void * 121static void *
122progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 122progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event)
123{ 123{
124 switch (event->status) 124 switch (event->status)
125 { 125 {
126 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 126 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 127 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
128 "Publish is progressing (%llu/%llu at level %u off %llu)...\n", 128 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
129 (unsigned long long) event->value.publish.completed, 129 (unsigned long long)event->value.publish.completed,
130 (unsigned long long) event->value.publish.size, 130 (unsigned long long)event->value.publish.size,
131 event->value.publish.specifics.progress.depth, 131 event->value.publish.specifics.progress.depth,
132 (unsigned long long) event->value.publish.specifics. 132 (unsigned long long)event->value.publish.specifics.
133 progress.offset); 133 progress.offset);
134 break; 134 break;
135 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: 135
136 break; 136 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
137 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 137 break;
138 printf ("Publishing complete, %llu kbps.\n", 138
139 (unsigned long long) (FILESIZE * 1000000LL / 139 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
140 printf("Publishing complete, %llu kbps.\n",
141 (unsigned long long)(FILESIZE * 1000000LL /
140 (1 + 142 (1 +
141 GNUNET_TIME_absolute_get_duration 143 GNUNET_TIME_absolute_get_duration
142 (start).rel_value_us) / 1024)); 144 (start).rel_value_us) / 1024));
143 start = GNUNET_TIME_absolute_get (); 145 start = GNUNET_TIME_absolute_get();
144 unindex = GNUNET_FS_unindex_start (fs, fn, "unindex"); 146 unindex = GNUNET_FS_unindex_start(fs, fn, "unindex");
145 GNUNET_assert (unindex != NULL); 147 GNUNET_assert(unindex != NULL);
146 break; 148 break;
147 case GNUNET_FS_STATUS_UNINDEX_COMPLETED: 149
148 printf ("Unindex complete, %llu kbps.\n", 150 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
149 (unsigned long long) (FILESIZE * 1000000LL / 151 printf("Unindex complete, %llu kbps.\n",
152 (unsigned long long)(FILESIZE * 1000000LL /
150 (1 + 153 (1 +
151 GNUNET_TIME_absolute_get_duration 154 GNUNET_TIME_absolute_get_duration
152 (start).rel_value_us) / 1024)); 155 (start).rel_value_us) / 1024));
153 GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); 156 GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL);
154 break; 157 break;
155 case GNUNET_FS_STATUS_UNINDEX_PROGRESS: 158
156 consider_restart (event->status); 159 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
157 GNUNET_assert (unindex == event->value.unindex.uc); 160 consider_restart(event->status);
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_assert(unindex == event->value.unindex.uc);
159 "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", 162 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
160 (unsigned long long) event->value.unindex.completed, 163 "Unindex is progressing (%llu/%llu at level %u off %llu)...\n",
161 (unsigned long long) event->value.unindex.size, 164 (unsigned long long)event->value.unindex.completed,
162 event->value.unindex.specifics.progress.depth, 165 (unsigned long long)event->value.unindex.size,
163 (unsigned long long) event->value.unindex.specifics. 166 event->value.unindex.specifics.progress.depth,
164 progress.offset); 167 (unsigned long long)event->value.unindex.specifics.
165 break; 168 progress.offset);
166 case GNUNET_FS_STATUS_PUBLISH_SUSPEND: 169 break;
167 if (event->value.publish.pc == publish) 170
168 publish = NULL; 171 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
169 break; 172 if (event->value.publish.pc == publish)
170 case GNUNET_FS_STATUS_PUBLISH_RESUME: 173 publish = NULL;
171 if (NULL == publish) 174 break;
172 { 175
173 publish = event->value.publish.pc; 176 case GNUNET_FS_STATUS_PUBLISH_RESUME:
174 return "publish-context"; 177 if (NULL == publish)
178 {
179 publish = event->value.publish.pc;
180 return "publish-context";
181 }
182 break;
183
184 case GNUNET_FS_STATUS_UNINDEX_SUSPEND:
185 GNUNET_assert(event->value.unindex.uc == unindex);
186 unindex = NULL;
187 break;
188
189 case GNUNET_FS_STATUS_UNINDEX_RESUME:
190 GNUNET_assert(NULL == unindex);
191 unindex = event->value.unindex.uc;
192 return "unindex";
193
194 case GNUNET_FS_STATUS_PUBLISH_ERROR:
195 fprintf(stderr, "Error publishing file: %s\n",
196 event->value.publish.specifics.error.message);
197 GNUNET_break(0);
198 GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL);
199 break;
200
201 case GNUNET_FS_STATUS_UNINDEX_ERROR:
202 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
203 "Error unindexing file: %s\n",
204 event->value.unindex.specifics.error.message);
205 GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL);
206 break;
207
208 case GNUNET_FS_STATUS_PUBLISH_START:
209 GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx));
210 GNUNET_assert(NULL == event->value.publish.pctx);
211 GNUNET_assert(FILESIZE == event->value.publish.size);
212 GNUNET_assert(0 == event->value.publish.completed);
213 GNUNET_assert(1 == event->value.publish.anonymity);
214 break;
215
216 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
217 GNUNET_assert(publish == event->value.publish.pc);
218 GNUNET_assert(FILESIZE == event->value.publish.size);
219 GNUNET_assert(1 == event->value.publish.anonymity);
220 GNUNET_FS_stop(fs);
221 fs = NULL;
222 break;
223
224 case GNUNET_FS_STATUS_UNINDEX_START:
225 consider_restart(event->status);
226 GNUNET_assert(unindex == NULL);
227 GNUNET_assert(0 == strcmp("unindex", event->value.unindex.cctx));
228 GNUNET_assert(0 == strcmp(fn, event->value.unindex.filename));
229 GNUNET_assert(FILESIZE == event->value.unindex.size);
230 GNUNET_assert(0 == event->value.unindex.completed);
231 break;
232
233 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
234 GNUNET_assert(unindex == event->value.unindex.uc);
235 GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL);
236 break;
237
238 default:
239 printf("Unexpected event: %d\n", event->status);
240 break;
175 } 241 }
176 break;
177 case GNUNET_FS_STATUS_UNINDEX_SUSPEND:
178 GNUNET_assert (event->value.unindex.uc == unindex);
179 unindex = NULL;
180 break;
181 case GNUNET_FS_STATUS_UNINDEX_RESUME:
182 GNUNET_assert (NULL == unindex);
183 unindex = event->value.unindex.uc;
184 return "unindex";
185 case GNUNET_FS_STATUS_PUBLISH_ERROR:
186 fprintf (stderr, "Error publishing file: %s\n",
187 event->value.publish.specifics.error.message);
188 GNUNET_break (0);
189 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
190 break;
191 case GNUNET_FS_STATUS_UNINDEX_ERROR:
192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
193 "Error unindexing file: %s\n",
194 event->value.unindex.specifics.error.message);
195 GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL);
196 break;
197 case GNUNET_FS_STATUS_PUBLISH_START:
198 GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx));
199 GNUNET_assert (NULL == event->value.publish.pctx);
200 GNUNET_assert (FILESIZE == event->value.publish.size);
201 GNUNET_assert (0 == event->value.publish.completed);
202 GNUNET_assert (1 == event->value.publish.anonymity);
203 break;
204 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
205 GNUNET_assert (publish == event->value.publish.pc);
206 GNUNET_assert (FILESIZE == event->value.publish.size);
207 GNUNET_assert (1 == event->value.publish.anonymity);
208 GNUNET_FS_stop (fs);
209 fs = NULL;
210 break;
211 case GNUNET_FS_STATUS_UNINDEX_START:
212 consider_restart (event->status);
213 GNUNET_assert (unindex == NULL);
214 GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx));
215 GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename));
216 GNUNET_assert (FILESIZE == event->value.unindex.size);
217 GNUNET_assert (0 == event->value.unindex.completed);
218 break;
219 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
220 GNUNET_assert (unindex == event->value.unindex.uc);
221 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
222 break;
223 default:
224 printf ("Unexpected event: %d\n", event->status);
225 break;
226 }
227 return NULL; 242 return NULL;
228} 243}
229 244
230 245
231static void 246static void
232run (void *cls, 247run(void *cls,
233 const struct GNUNET_CONFIGURATION_Handle *c, 248 const struct GNUNET_CONFIGURATION_Handle *c,
234 struct GNUNET_TESTING_Peer *peer) 249 struct GNUNET_TESTING_Peer *peer)
235{ 250{
236 const char *keywords[] = { 251 const char *keywords[] = {
237 "down_foo", 252 "down_foo",
@@ -245,44 +260,44 @@ run (void *cls,
245 struct GNUNET_FS_BlockOptions bo; 260 struct GNUNET_FS_BlockOptions bo;
246 261
247 cfg = c; 262 cfg = c;
248 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); 263 fn = GNUNET_DISK_mktemp("gnunet-unindex-test-dst");
249 fs = GNUNET_FS_start (cfg, "test-fs-unindex-persistence", &progress_cb, NULL, 264 fs = GNUNET_FS_start(cfg, "test-fs-unindex-persistence", &progress_cb, NULL,
250 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 265 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
251 GNUNET_assert (NULL != fs); 266 GNUNET_assert(NULL != fs);
252 buf = GNUNET_malloc (FILESIZE); 267 buf = GNUNET_malloc(FILESIZE);
253 for (i = 0; i < FILESIZE; i++) 268 for (i = 0; i < FILESIZE; i++)
254 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 269 buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256);
255 GNUNET_assert (FILESIZE == 270 GNUNET_assert(FILESIZE ==
256 GNUNET_DISK_fn_write (fn, buf, FILESIZE, 271 GNUNET_DISK_fn_write(fn, buf, FILESIZE,
257 GNUNET_DISK_PERM_USER_READ | 272 GNUNET_DISK_PERM_USER_READ |
258 GNUNET_DISK_PERM_USER_WRITE)); 273 GNUNET_DISK_PERM_USER_WRITE));
259 GNUNET_free (buf); 274 GNUNET_free(buf);
260 meta = GNUNET_CONTAINER_meta_data_create (); 275 meta = GNUNET_CONTAINER_meta_data_create();
261 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); 276 kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords);
262 bo.content_priority = 42; 277 bo.content_priority = 42;
263 bo.anonymity_level = 1; 278 bo.anonymity_level = 1;
264 bo.replication_level = 0; 279 bo.replication_level = 0;
265 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 280 bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME);
266 fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn, 281 fi = GNUNET_FS_file_information_create_from_file(fs, "publish-context", fn,
267 kuri, meta, GNUNET_YES, 282 kuri, meta, GNUNET_YES,
268 &bo); 283 &bo);
269 GNUNET_FS_uri_destroy (kuri); 284 GNUNET_FS_uri_destroy(kuri);
270 GNUNET_CONTAINER_meta_data_destroy (meta); 285 GNUNET_CONTAINER_meta_data_destroy(meta);
271 GNUNET_assert (NULL != fi); 286 GNUNET_assert(NULL != fi);
272 start = GNUNET_TIME_absolute_get (); 287 start = GNUNET_TIME_absolute_get();
273 publish = 288 publish =
274 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, 289 GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL,
275 GNUNET_FS_PUBLISH_OPTION_NONE); 290 GNUNET_FS_PUBLISH_OPTION_NONE);
276 GNUNET_assert (publish != NULL); 291 GNUNET_assert(publish != NULL);
277} 292}
278 293
279 294
280int 295int
281main (int argc, char *argv[]) 296main(int argc, char *argv[])
282{ 297{
283 if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex-persistence", 298 if (0 != GNUNET_TESTING_peer_run("test-fs-unindex-persistence",
284 "test_fs_unindex_data.conf", 299 "test_fs_unindex_data.conf",
285 &run, NULL)) 300 &run, NULL))
286 return 1; 301 return 1;
287 return 0; 302 return 0;
288} 303}