diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
commit | 5746309cb4be2073d550ad7a6885e918631dbc38 (patch) | |
tree | 89455bc4aadf977816b38df13f990372cd81d71a /src/fs/test_fs_publish.c | |
parent | 6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff) | |
download | gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip |
indentation
Diffstat (limited to 'src/fs/test_fs_publish.c')
-rw-r--r-- | src/fs/test_fs_publish.c | 90 |
1 files changed, 38 insertions, 52 deletions
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index d53b5b0ae..797c4c9a8 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c | |||
@@ -98,11 +98,10 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
98 | printf ("Publish complete, %llu kbps.\n", | 98 | printf ("Publish complete, %llu kbps.\n", |
99 | (unsigned long long) (FILESIZE * 1000 / | 99 | (unsigned long long) (FILESIZE * 1000 / |
100 | (1 + | 100 | (1 + |
101 | GNUNET_TIME_absolute_get_duration | 101 | GNUNET_TIME_absolute_get_duration (start). |
102 | (start).rel_value) / 1024)); | 102 | rel_value) / 1024)); |
103 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | 103 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) |
104 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, | 104 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL, |
105 | NULL, | ||
106 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 105 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
107 | break; | 106 | break; |
108 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 107 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
@@ -113,22 +112,20 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
113 | (unsigned long long) event->value.publish.completed, | 112 | (unsigned long long) event->value.publish.completed, |
114 | (unsigned long long) event->value.publish.size, | 113 | (unsigned long long) event->value.publish.size, |
115 | event->value.publish.specifics.progress.depth, | 114 | event->value.publish.specifics.progress.depth, |
116 | (unsigned long long) event->value.publish.specifics. | 115 | (unsigned long long) event->value.publish.specifics.progress. |
117 | progress.offset); | 116 | offset); |
118 | #endif | 117 | #endif |
119 | break; | 118 | break; |
120 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 119 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
121 | ret = event->value.publish.cctx; | 120 | ret = event->value.publish.cctx; |
122 | fprintf (stderr, | 121 | fprintf (stderr, "Error publishing file: %s\n", |
123 | "Error publishing file: %s\n", | ||
124 | event->value.publish.specifics.error.message); | 122 | event->value.publish.specifics.error.message); |
125 | err = 1; | 123 | err = 1; |
126 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | 124 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) |
127 | { | 125 | { |
128 | fprintf (stderr, "Scheduling abort task for error on `%s'\n", | 126 | fprintf (stderr, "Scheduling abort task for error on `%s'\n", |
129 | (const char *) event->value.publish.cctx); | 127 | (const char *) event->value.publish.cctx); |
130 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, | 128 | GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL, |
131 | NULL, | ||
132 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 129 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
133 | } | 130 | } |
134 | break; | 131 | break; |
@@ -136,16 +133,16 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
136 | ret = event->value.publish.cctx; | 133 | ret = event->value.publish.cctx; |
137 | if (0 == strcmp ("publish-context1", event->value.publish.cctx)) | 134 | if (0 == strcmp ("publish-context1", event->value.publish.cctx)) |
138 | { | 135 | { |
139 | GNUNET_assert (0 == strcmp ("publish-context-dir", | 136 | GNUNET_assert (0 == |
140 | event->value.publish.pctx)); | 137 | strcmp ("publish-context-dir", event->value.publish.pctx)); |
141 | GNUNET_assert (FILESIZE == event->value.publish.size); | 138 | GNUNET_assert (FILESIZE == event->value.publish.size); |
142 | GNUNET_assert (0 == event->value.publish.completed); | 139 | GNUNET_assert (0 == event->value.publish.completed); |
143 | GNUNET_assert (1 == event->value.publish.anonymity); | 140 | GNUNET_assert (1 == event->value.publish.anonymity); |
144 | } | 141 | } |
145 | else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) | 142 | else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) |
146 | { | 143 | { |
147 | GNUNET_assert (0 == strcmp ("publish-context-dir", | 144 | GNUNET_assert (0 == |
148 | event->value.publish.pctx)); | 145 | strcmp ("publish-context-dir", event->value.publish.pctx)); |
149 | GNUNET_assert (FILESIZE == event->value.publish.size); | 146 | GNUNET_assert (FILESIZE == event->value.publish.size); |
150 | GNUNET_assert (0 == event->value.publish.completed); | 147 | GNUNET_assert (0 == event->value.publish.completed); |
151 | GNUNET_assert (2 == event->value.publish.anonymity); | 148 | GNUNET_assert (2 == event->value.publish.anonymity); |
@@ -175,12 +172,13 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
175 | { | 172 | { |
176 | p->cfg = GNUNET_CONFIGURATION_create (); | 173 | p->cfg = GNUNET_CONFIGURATION_create (); |
177 | #if START_ARM | 174 | #if START_ARM |
178 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 175 | p->arm_proc = |
179 | "gnunet-service-arm", | 176 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
177 | "gnunet-service-arm", | ||
180 | #if VERBOSE | 178 | #if VERBOSE |
181 | "-L", "DEBUG", | 179 | "-L", "DEBUG", |
182 | #endif | 180 | #endif |
183 | "-c", cfgname, NULL); | 181 | "-c", cfgname, NULL); |
184 | #endif | 182 | #endif |
185 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 183 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
186 | } | 184 | } |
@@ -196,8 +194,7 @@ stop_arm (struct PeerContext *p) | |||
196 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 194 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
197 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | 195 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
198 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 196 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", |
200 | "ARM process %u stopped\n", | ||
201 | GNUNET_OS_process_get_pid (p->arm_proc)); | 198 | GNUNET_OS_process_get_pid (p->arm_proc)); |
202 | GNUNET_OS_process_close (p->arm_proc); | 199 | GNUNET_OS_process_close (p->arm_proc); |
203 | p->arm_proc = NULL; | 200 | p->arm_proc = NULL; |
@@ -208,9 +205,8 @@ stop_arm (struct PeerContext *p) | |||
208 | 205 | ||
209 | 206 | ||
210 | static void | 207 | static void |
211 | run (void *cls, | 208 | run (void *cls, char *const *args, const char *cfgfile, |
212 | char *const *args, | 209 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
213 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
214 | { | 210 | { |
215 | const char *keywords[] = { | 211 | const char *keywords[] = { |
216 | "down_foo", | 212 | "down_foo", |
@@ -226,19 +222,15 @@ run (void *cls, | |||
226 | struct GNUNET_FS_BlockOptions bo; | 222 | struct GNUNET_FS_BlockOptions bo; |
227 | 223 | ||
228 | setup_peer (&p1, "test_fs_publish_data.conf"); | 224 | setup_peer (&p1, "test_fs_publish_data.conf"); |
229 | fs = GNUNET_FS_start (cfg, | 225 | fs = GNUNET_FS_start (cfg, "test-fs-publish", &progress_cb, NULL, |
230 | "test-fs-publish", | 226 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
231 | &progress_cb, | ||
232 | NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | ||
233 | GNUNET_assert (NULL != fs); | 227 | GNUNET_assert (NULL != fs); |
234 | fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); | 228 | fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); |
235 | buf = GNUNET_malloc (FILESIZE); | 229 | buf = GNUNET_malloc (FILESIZE); |
236 | for (i = 0; i < FILESIZE; i++) | 230 | for (i = 0; i < FILESIZE; i++) |
237 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 231 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
238 | GNUNET_assert (FILESIZE == | 232 | GNUNET_assert (FILESIZE == |
239 | GNUNET_DISK_fn_write (fn1, | 233 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, |
240 | buf, | ||
241 | FILESIZE, | ||
242 | GNUNET_DISK_PERM_USER_READ | | 234 | GNUNET_DISK_PERM_USER_READ | |
243 | GNUNET_DISK_PERM_USER_WRITE)); | 235 | GNUNET_DISK_PERM_USER_WRITE)); |
244 | GNUNET_free (buf); | 236 | GNUNET_free (buf); |
@@ -248,9 +240,7 @@ run (void *cls, | |||
248 | for (i = 0; i < FILESIZE; i++) | 240 | for (i = 0; i < FILESIZE; i++) |
249 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 241 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
250 | GNUNET_assert (FILESIZE == | 242 | GNUNET_assert (FILESIZE == |
251 | GNUNET_DISK_fn_write (fn2, | 243 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, |
252 | buf, | ||
253 | FILESIZE, | ||
254 | GNUNET_DISK_PERM_USER_READ | | 244 | GNUNET_DISK_PERM_USER_READ | |
255 | GNUNET_DISK_PERM_USER_WRITE)); | 245 | GNUNET_DISK_PERM_USER_WRITE)); |
256 | GNUNET_free (buf); | 246 | GNUNET_free (buf); |
@@ -262,34 +252,30 @@ run (void *cls, | |||
262 | bo.replication_level = 0; | 252 | bo.replication_level = 0; |
263 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); | 253 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
264 | 254 | ||
265 | fi1 = GNUNET_FS_file_information_create_from_file (fs, | 255 | fi1 = |
266 | "publish-context1", | 256 | GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1, |
267 | fn1, | 257 | kuri, meta, GNUNET_YES, &bo); |
268 | kuri, | ||
269 | meta, GNUNET_YES, &bo); | ||
270 | 258 | ||
271 | GNUNET_assert (NULL != fi1); | 259 | GNUNET_assert (NULL != fi1); |
272 | bo.anonymity_level = 2; | 260 | bo.anonymity_level = 2; |
273 | fi2 = GNUNET_FS_file_information_create_from_file (fs, | 261 | fi2 = |
274 | "publish-context2", | 262 | GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2, |
275 | fn2, | 263 | kuri, meta, GNUNET_YES, &bo); |
276 | kuri, | ||
277 | meta, GNUNET_YES, &bo); | ||
278 | GNUNET_assert (NULL != fi2); | 264 | GNUNET_assert (NULL != fi2); |
279 | bo.anonymity_level = 3; | 265 | bo.anonymity_level = 3; |
280 | fidir = GNUNET_FS_file_information_create_empty_directory (fs, | 266 | fidir = |
281 | "publish-context-dir", | 267 | GNUNET_FS_file_information_create_empty_directory (fs, |
282 | kuri, meta, &bo); | 268 | "publish-context-dir", |
269 | kuri, meta, &bo); | ||
283 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); | 270 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); |
284 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); | 271 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); |
285 | GNUNET_FS_uri_destroy (kuri); | 272 | GNUNET_FS_uri_destroy (kuri); |
286 | GNUNET_CONTAINER_meta_data_destroy (meta); | 273 | GNUNET_CONTAINER_meta_data_destroy (meta); |
287 | GNUNET_assert (NULL != fidir); | 274 | GNUNET_assert (NULL != fidir); |
288 | start = GNUNET_TIME_absolute_get (); | 275 | start = GNUNET_TIME_absolute_get (); |
289 | publish = GNUNET_FS_publish_start (fs, | 276 | publish = |
290 | fidir, | 277 | GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, |
291 | NULL, NULL, NULL, | 278 | GNUNET_FS_PUBLISH_OPTION_NONE); |
292 | GNUNET_FS_PUBLISH_OPTION_NONE); | ||
293 | GNUNET_assert (publish != NULL); | 279 | GNUNET_assert (publish != NULL); |
294 | } | 280 | } |
295 | 281 | ||
@@ -317,8 +303,8 @@ main (int argc, char *argv[]) | |||
317 | "WARNING", | 303 | "WARNING", |
318 | #endif | 304 | #endif |
319 | NULL); | 305 | NULL); |
320 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | 306 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, |
321 | argvx, "test-fs-publish", "nohelp", options, &run, NULL); | 307 | "test-fs-publish", "nohelp", options, &run, NULL); |
322 | stop_arm (&p1); | 308 | stop_arm (&p1); |
323 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/"); | 309 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/"); |
324 | if (fn1 != NULL) | 310 | if (fn1 != NULL) |