aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_publish.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs/test_fs_publish.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/fs/test_fs_publish.c')
-rw-r--r--src/fs/test_fs_publish.c274
1 files changed, 131 insertions, 143 deletions
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c
index dcce43cdf..d53b5b0ae 100644
--- a/src/fs/test_fs_publish.c
+++ b/src/fs/test_fs_publish.c
@@ -46,7 +46,7 @@
46 46
47/** 47/**
48 * How long should our test-content live? 48 * How long should our test-content live?
49 */ 49 */
50#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 50#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
51 51
52struct PeerContext 52struct PeerContext
@@ -72,8 +72,7 @@ static char *fn2;
72static int err; 72static int err;
73 73
74static void 74static void
75abort_publish_task (void *cls, 75abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
76 const struct GNUNET_SCHEDULER_TaskContext *tc)
77{ 76{
78 GNUNET_FS_publish_stop (publish); 77 GNUNET_FS_publish_stop (publish);
79 publish = NULL; 78 publish = NULL;
@@ -87,90 +86,86 @@ abort_publish_task (void *cls,
87 86
88 87
89static void * 88static void *
90progress_cb (void *cls, 89progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
91 const struct GNUNET_FS_ProgressInfo *event)
92{ 90{
93 void *ret; 91 void *ret;
94 92
95 ret = NULL; 93 ret = NULL;
96 switch (event->status) 94 switch (event->status)
97 { 95 {
98 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 96 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
99 ret = event->value.publish.cctx; 97 ret = event->value.publish.cctx;
100 printf ("Publish complete, %llu kbps.\n", 98 printf ("Publish complete, %llu kbps.\n",
101 (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).rel_value) / 1024)); 99 (unsigned long long) (FILESIZE * 1000 /
102 if (0 == strcmp ("publish-context-dir", 100 (1 +
103 event->value.publish.cctx)) 101 GNUNET_TIME_absolute_get_duration
104 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 102 (start).rel_value) / 1024));
105 NULL, 103 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
106 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 104 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
107 break; 105 NULL,
108 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 106 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
109 ret = event->value.publish.cctx; 107 break;
110 GNUNET_assert (publish == event->value.publish.pc); 108 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
109 ret = event->value.publish.cctx;
110 GNUNET_assert (publish == event->value.publish.pc);
111#if VERBOSE 111#if VERBOSE
112 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 112 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n",
113 (unsigned long long) event->value.publish.completed, 113 (unsigned long long) event->value.publish.completed,
114 (unsigned long long) event->value.publish.size, 114 (unsigned long long) event->value.publish.size,
115 event->value.publish.specifics.progress.depth, 115 event->value.publish.specifics.progress.depth,
116 (unsigned long long) event->value.publish.specifics.progress.offset); 116 (unsigned long long) event->value.publish.specifics.
117 progress.offset);
117#endif 118#endif
118 break; 119 break;
119 case GNUNET_FS_STATUS_PUBLISH_ERROR: 120 case GNUNET_FS_STATUS_PUBLISH_ERROR:
120 ret = event->value.publish.cctx; 121 ret = event->value.publish.cctx;
121 fprintf (stderr, 122 fprintf (stderr,
122 "Error publishing file: %s\n", 123 "Error publishing file: %s\n",
123 event->value.publish.specifics.error.message); 124 event->value.publish.specifics.error.message);
124 err = 1; 125 err = 1;
125 if (0 == strcmp ("publish-context-dir", 126 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
126 event->value.publish.cctx)) 127 {
127 { 128 fprintf (stderr, "Scheduling abort task for error on `%s'\n",
128 fprintf (stderr, "Scheduling abort task for error on `%s'\n", 129 (const char *) event->value.publish.cctx);
129 (const char*) event->value.publish.cctx); 130 GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
130 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 131 NULL,
131 NULL, 132 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
132 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 133 }
133 } 134 break;
134 break; 135 case GNUNET_FS_STATUS_PUBLISH_START:
135 case GNUNET_FS_STATUS_PUBLISH_START: 136 ret = event->value.publish.cctx;
136 ret = event->value.publish.cctx; 137 if (0 == strcmp ("publish-context1", event->value.publish.cctx))
137 if (0 == strcmp ("publish-context1", 138 {
138 event->value.publish.cctx)) 139 GNUNET_assert (0 == strcmp ("publish-context-dir",
139 { 140 event->value.publish.pctx));
140 GNUNET_assert (0 == strcmp ("publish-context-dir", 141 GNUNET_assert (FILESIZE == event->value.publish.size);
141 event->value.publish.pctx)); 142 GNUNET_assert (0 == event->value.publish.completed);
142 GNUNET_assert (FILESIZE == event->value.publish.size); 143 GNUNET_assert (1 == event->value.publish.anonymity);
143 GNUNET_assert (0 == event->value.publish.completed); 144 }
144 GNUNET_assert (1 == event->value.publish.anonymity); 145 else if (0 == strcmp ("publish-context2", event->value.publish.cctx))
145 } 146 {
146 else if (0 == strcmp ("publish-context2", 147 GNUNET_assert (0 == strcmp ("publish-context-dir",
147 event->value.publish.cctx)) 148 event->value.publish.pctx));
148 { 149 GNUNET_assert (FILESIZE == event->value.publish.size);
149 GNUNET_assert (0 == strcmp ("publish-context-dir", 150 GNUNET_assert (0 == event->value.publish.completed);
150 event->value.publish.pctx)); 151 GNUNET_assert (2 == event->value.publish.anonymity);
151 GNUNET_assert (FILESIZE == event->value.publish.size); 152 }
152 GNUNET_assert (0 == event->value.publish.completed); 153 else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
153 GNUNET_assert (2 == event->value.publish.anonymity); 154 {
154 } 155 GNUNET_assert (0 == event->value.publish.completed);
155 else if (0 == strcmp ("publish-context-dir", 156 GNUNET_assert (3 == event->value.publish.anonymity);
156 event->value.publish.cctx))
157 {
158 GNUNET_assert (0 == event->value.publish.completed);
159 GNUNET_assert (3 == event->value.publish.anonymity);
160 }
161 else
162 GNUNET_assert (0);
163 break;
164 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
165 if (0 == strcmp ("publish-context-dir",
166 event->value.publish.cctx))
167 GNUNET_assert (publish == event->value.publish.pc);
168 break;
169 default:
170 printf ("Unexpected event: %d\n",
171 event->status);
172 break;
173 } 157 }
158 else
159 GNUNET_assert (0);
160 break;
161 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
162 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
163 GNUNET_assert (publish == event->value.publish.pc);
164 break;
165 default:
166 printf ("Unexpected event: %d\n", event->status);
167 break;
168 }
174 return ret; 169 return ret;
175} 170}
176 171
@@ -181,11 +176,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
181 p->cfg = GNUNET_CONFIGURATION_create (); 176 p->cfg = GNUNET_CONFIGURATION_create ();
182#if START_ARM 177#if START_ARM
183 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 178 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
184 "gnunet-service-arm", 179 "gnunet-service-arm",
185#if VERBOSE 180#if VERBOSE
186 "-L", "DEBUG", 181 "-L", "DEBUG",
187#endif 182#endif
188 "-c", cfgname, NULL); 183 "-c", cfgname, NULL);
189#endif 184#endif
190 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 185 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
191} 186}
@@ -196,16 +191,17 @@ stop_arm (struct PeerContext *p)
196{ 191{
197#if START_ARM 192#if START_ARM
198 if (NULL != p->arm_proc) 193 if (NULL != p->arm_proc)
199 { 194 {
200 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 195 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
201 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 196 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
202 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 197 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
203 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 198 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); 200 "ARM process %u stopped\n",
206 GNUNET_OS_process_close (p->arm_proc); 201 GNUNET_OS_process_get_pid (p->arm_proc));
207 p->arm_proc = NULL; 202 GNUNET_OS_process_close (p->arm_proc);
208 } 203 p->arm_proc = NULL;
204 }
209#endif 205#endif
210 GNUNET_CONFIGURATION_destroy (p->cfg); 206 GNUNET_CONFIGURATION_destroy (p->cfg);
211} 207}
@@ -214,8 +210,7 @@ stop_arm (struct PeerContext *p)
214static void 210static void
215run (void *cls, 211run (void *cls,
216 char *const *args, 212 char *const *args,
217 const char *cfgfile, 213 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
218 const struct GNUNET_CONFIGURATION_Handle *cfg)
219{ 214{
220 const char *keywords[] = { 215 const char *keywords[] = {
221 "down_foo", 216 "down_foo",
@@ -232,21 +227,20 @@ run (void *cls,
232 227
233 setup_peer (&p1, "test_fs_publish_data.conf"); 228 setup_peer (&p1, "test_fs_publish_data.conf");
234 fs = GNUNET_FS_start (cfg, 229 fs = GNUNET_FS_start (cfg,
235 "test-fs-publish", 230 "test-fs-publish",
236 &progress_cb, 231 &progress_cb,
237 NULL, 232 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
238 GNUNET_FS_FLAGS_NONE, 233 GNUNET_assert (NULL != fs);
239 GNUNET_FS_OPTIONS_END);
240 GNUNET_assert (NULL != fs);
241 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); 234 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
242 buf = GNUNET_malloc (FILESIZE); 235 buf = GNUNET_malloc (FILESIZE);
243 for (i = 0; i < FILESIZE; i++) 236 for (i = 0; i < FILESIZE; i++)
244 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 237 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
245 GNUNET_assert (FILESIZE == 238 GNUNET_assert (FILESIZE ==
246 GNUNET_DISK_fn_write (fn1, 239 GNUNET_DISK_fn_write (fn1,
247 buf, 240 buf,
248 FILESIZE, 241 FILESIZE,
249 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 242 GNUNET_DISK_PERM_USER_READ |
243 GNUNET_DISK_PERM_USER_WRITE));
250 GNUNET_free (buf); 244 GNUNET_free (buf);
251 245
252 fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); 246 fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
@@ -254,10 +248,11 @@ run (void *cls,
254 for (i = 0; i < FILESIZE; i++) 248 for (i = 0; i < FILESIZE; i++)
255 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 249 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
256 GNUNET_assert (FILESIZE == 250 GNUNET_assert (FILESIZE ==
257 GNUNET_DISK_fn_write (fn2, 251 GNUNET_DISK_fn_write (fn2,
258 buf, 252 buf,
259 FILESIZE, 253 FILESIZE,
260 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); 254 GNUNET_DISK_PERM_USER_READ |
255 GNUNET_DISK_PERM_USER_WRITE));
261 GNUNET_free (buf); 256 GNUNET_free (buf);
262 257
263 meta = GNUNET_CONTAINER_meta_data_create (); 258 meta = GNUNET_CONTAINER_meta_data_create ();
@@ -268,29 +263,23 @@ run (void *cls,
268 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 263 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
269 264
270 fi1 = GNUNET_FS_file_information_create_from_file (fs, 265 fi1 = GNUNET_FS_file_information_create_from_file (fs,
271 "publish-context1", 266 "publish-context1",
272 fn1, 267 fn1,
273 kuri, 268 kuri,
274 meta, 269 meta, GNUNET_YES, &bo);
275 GNUNET_YES, 270
276 &bo);
277
278 GNUNET_assert (NULL != fi1); 271 GNUNET_assert (NULL != fi1);
279 bo.anonymity_level = 2; 272 bo.anonymity_level = 2;
280 fi2 = GNUNET_FS_file_information_create_from_file (fs, 273 fi2 = GNUNET_FS_file_information_create_from_file (fs,
281 "publish-context2", 274 "publish-context2",
282 fn2, 275 fn2,
283 kuri, 276 kuri,
284 meta, 277 meta, GNUNET_YES, &bo);
285 GNUNET_YES,
286 &bo);
287 GNUNET_assert (NULL != fi2); 278 GNUNET_assert (NULL != fi2);
288 bo.anonymity_level = 3; 279 bo.anonymity_level = 3;
289 fidir = GNUNET_FS_file_information_create_empty_directory (fs, 280 fidir = GNUNET_FS_file_information_create_empty_directory (fs,
290 "publish-context-dir", 281 "publish-context-dir",
291 kuri, 282 kuri, meta, &bo);
292 meta,
293 &bo);
294 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 283 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
295 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 284 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
296 GNUNET_FS_uri_destroy (kuri); 285 GNUNET_FS_uri_destroy (kuri);
@@ -298,9 +287,9 @@ run (void *cls,
298 GNUNET_assert (NULL != fidir); 287 GNUNET_assert (NULL != fidir);
299 start = GNUNET_TIME_absolute_get (); 288 start = GNUNET_TIME_absolute_get ();
300 publish = GNUNET_FS_publish_start (fs, 289 publish = GNUNET_FS_publish_start (fs,
301 fidir, 290 fidir,
302 NULL, NULL, NULL, 291 NULL, NULL, NULL,
303 GNUNET_FS_PUBLISH_OPTION_NONE); 292 GNUNET_FS_PUBLISH_OPTION_NONE);
304 GNUNET_assert (publish != NULL); 293 GNUNET_assert (publish != NULL);
305} 294}
306 295
@@ -308,7 +297,7 @@ run (void *cls,
308int 297int
309main (int argc, char *argv[]) 298main (int argc, char *argv[])
310{ 299{
311 char *const argvx[] = { 300 char *const argvx[] = {
312 "test-fs-publish", 301 "test-fs-publish",
313 "-c", 302 "-c",
314 "test_fs_publish_data.conf", 303 "test_fs_publish_data.conf",
@@ -321,28 +310,27 @@ main (int argc, char *argv[])
321 GNUNET_GETOPT_OPTION_END 310 GNUNET_GETOPT_OPTION_END
322 }; 311 };
323 312
324 GNUNET_log_setup ("test_fs_publish", 313 GNUNET_log_setup ("test_fs_publish",
325#if VERBOSE 314#if VERBOSE
326 "DEBUG", 315 "DEBUG",
327#else 316#else
328 "WARNING", 317 "WARNING",
329#endif 318#endif
330 NULL); 319 NULL);
331 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 320 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
332 argvx, "test-fs-publish", 321 argvx, "test-fs-publish", "nohelp", options, &run, NULL);
333 "nohelp", options, &run, NULL);
334 stop_arm (&p1); 322 stop_arm (&p1);
335 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/"); 323 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
336 if (fn1 != NULL) 324 if (fn1 != NULL)
337 { 325 {
338 GNUNET_DISK_directory_remove (fn1); 326 GNUNET_DISK_directory_remove (fn1);
339 GNUNET_free (fn1); 327 GNUNET_free (fn1);
340 } 328 }
341 if (fn2 != NULL) 329 if (fn2 != NULL)
342 { 330 {
343 GNUNET_DISK_directory_remove (fn2); 331 GNUNET_DISK_directory_remove (fn2);
344 GNUNET_free (fn2); 332 GNUNET_free (fn2);
345 } 333 }
346 return err; 334 return err;
347} 335}
348 336