aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_gnunet_service_fs_migration.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_gnunet_service_fs_migration.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/fs/test_gnunet_service_fs_migration.c')
-rw-r--r--src/fs/test_gnunet_service_fs_migration.c178
1 files changed, 73 insertions, 105 deletions
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c
index 092cedfc2..9a209521f 100644
--- a/src/fs/test_gnunet_service_fs_migration.c
+++ b/src/fs/test_gnunet_service_fs_migration.c
@@ -53,172 +53,140 @@ static int ok;
53static struct GNUNET_TIME_Absolute start_time; 53static struct GNUNET_TIME_Absolute start_time;
54 54
55static void 55static void
56do_stop (void *cls, 56do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 const struct GNUNET_SCHEDULER_TaskContext *tc)
58{ 57{
59 struct GNUNET_TIME_Relative del; 58 struct GNUNET_TIME_Relative del;
60 char *fancy; 59 char *fancy;
61 60
62 GNUNET_FS_TEST_daemons_stop (2, 61 GNUNET_FS_TEST_daemons_stop (2, daemons);
63 daemons);
64 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 62 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
65 { 63 {
66 del = GNUNET_TIME_absolute_get_duration (start_time); 64 del = GNUNET_TIME_absolute_get_duration (start_time);
67 if (del.rel_value == 0) 65 if (del.rel_value == 0)
68 del.rel_value = 1; 66 del.rel_value = 1;
69 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.rel_value); 67 fancy =
70 fprintf (stdout, 68 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
71 "Download speed was %s/s\n", 69 1000LL / del.rel_value);
72 fancy); 70 fprintf (stdout, "Download speed was %s/s\n", fancy);
73 GNUNET_free (fancy); 71 GNUNET_free (fancy);
74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 72 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
75 "Finished download, shutting down\n", 73 "Finished download, shutting down\n",
76 (unsigned long long) FILESIZE); 74 (unsigned long long) FILESIZE);
77 } 75 }
78 else 76 else
79 { 77 {
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 78 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "Timeout during download, shutting down with error\n"); 79 "Timeout during download, shutting down with error\n");
82 ok = 1; 80 ok = 1;
83 } 81 }
84} 82}
85 83
86 84
87static void 85static void
88do_download (void *cls, 86do_download (void *cls, const char *emsg)
89 const char *emsg)
90{ 87{
91 struct GNUNET_FS_Uri *uri = cls; 88 struct GNUNET_FS_Uri *uri = cls;
92 89
93 if (emsg != NULL) 90 if (emsg != NULL)
94 { 91 {
95 GNUNET_FS_TEST_daemons_stop (2, 92 GNUNET_FS_TEST_daemons_stop (2, daemons);
96 daemons); 93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 94 "Failed to stop source daemon: %s\n", emsg);
98 "Failed to stop source daemon: %s\n", 95 GNUNET_FS_uri_destroy (uri);
99 emsg); 96 ok = 1;
100 GNUNET_FS_uri_destroy (uri); 97 return;
101 ok = 1; 98 }
102 return;
103 }
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 99 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Downloading %llu bytes\n", 100 "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
106 (unsigned long long) FILESIZE);
107 start_time = GNUNET_TIME_absolute_get (); 101 start_time = GNUNET_TIME_absolute_get ();
108 GNUNET_FS_TEST_download (daemons[0], 102 GNUNET_FS_TEST_download (daemons[0],
109 TIMEOUT, 103 TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL);
110 1, SEED, uri,
111 VERBOSE,
112 &do_stop, NULL);
113 GNUNET_FS_uri_destroy (uri); 104 GNUNET_FS_uri_destroy (uri);
114} 105}
115 106
116 107
117static void 108static void
118stop_source_peer (void *cls, 109stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
119 const struct GNUNET_SCHEDULER_TaskContext *tc)
120{ 110{
121 struct GNUNET_FS_Uri *uri = cls; 111 struct GNUNET_FS_Uri *uri = cls;
122 struct GNUNET_TESTING_PeerGroup *pg; 112 struct GNUNET_TESTING_PeerGroup *pg;
123 113
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n");
125 "Stopping source peer\n");
126 pg = GNUNET_FS_TEST_get_group (daemons); 115 pg = GNUNET_FS_TEST_get_group (daemons);
127 GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT, 116 GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT, &do_download, uri);
128 &do_download,
129 uri);
130} 117}
131 118
132 119
133static void 120static void
134do_wait (void *cls, 121do_wait (void *cls, const struct GNUNET_FS_Uri *uri)
135 const struct GNUNET_FS_Uri *uri)
136{ 122{
137 struct GNUNET_FS_Uri *d; 123 struct GNUNET_FS_Uri *d;
138 124
139 if (NULL == uri) 125 if (NULL == uri)
140 { 126 {
141 GNUNET_FS_TEST_daemons_stop (2, 127 GNUNET_FS_TEST_daemons_stop (2, daemons);
142 daemons); 128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 129 "Timeout during upload attempt, shutting down with error\n");
144 "Timeout during upload attempt, shutting down with error\n"); 130 ok = 1;
145 ok = 1; 131 return;
146 return; 132 }
147 } 133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting to allow content to migrate\n");
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "Waiting to allow content to migrate\n");
150 d = GNUNET_FS_uri_dup (uri); 134 d = GNUNET_FS_uri_dup (uri);
151 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, 135 (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, &stop_source_peer, d);
152 &stop_source_peer,
153 d);
154} 136}
155 137
156 138
157static void 139static void
158do_publish (void *cls, 140do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
159 const struct GNUNET_SCHEDULER_TaskContext *tc)
160{ 141{
161 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 142 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
162 { 143 {
163 GNUNET_FS_TEST_daemons_stop (2, 144 GNUNET_FS_TEST_daemons_stop (2, daemons);
164 daemons); 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 146 "Timeout during connect attempt, shutting down with error\n");
166 "Timeout during connect attempt, shutting down with error\n"); 147 ok = 1;
167 ok = 1; 148 return;
168 return; 149 }
169 }
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Publishing %llu bytes\n", 151 "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
172 (unsigned long long) FILESIZE);
173 GNUNET_FS_TEST_publish (daemons[1], 152 GNUNET_FS_TEST_publish (daemons[1],
174 TIMEOUT, 153 TIMEOUT,
175 1, GNUNET_NO, FILESIZE, SEED, 154 1, GNUNET_NO, FILESIZE, SEED,
176 VERBOSE, 155 VERBOSE, &do_wait, NULL);
177 &do_wait, NULL);
178} 156}
179 157
180 158
181static void 159static void
182do_connect (void *cls, 160do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
183 const struct GNUNET_SCHEDULER_TaskContext *tc)
184{ 161{
185 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 162 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
186 { 163 {
187 fprintf (stderr, 164 fprintf (stderr, "Daemons failed to start!\n");
188 "Daemons failed to start!\n"); 165 GNUNET_break (0);
189 GNUNET_break (0); 166 ok = 1;
190 ok = 1; 167 return;
191 return; 168 }
192 }
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Daemons started, will now try to connect them\n"); 170 "Daemons started, will now try to connect them\n");
195 GNUNET_FS_TEST_daemons_connect (daemons[0], 171 GNUNET_FS_TEST_daemons_connect (daemons[0],
196 daemons[1], 172 daemons[1], TIMEOUT, &do_publish, NULL);
197 TIMEOUT,
198 &do_publish,
199 NULL);
200} 173}
201 174
202 175
203static void 176static void
204run (void *cls, 177run (void *cls,
205 char *const *args, 178 char *const *args,
206 const char *cfgfile, 179 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
207 const struct GNUNET_CONFIGURATION_Handle *cfg)
208{ 180{
209 GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf", 181 GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf",
210 TIMEOUT, 182 TIMEOUT, 2, daemons, &do_connect, NULL);
211 2,
212 daemons,
213 &do_connect,
214 NULL);
215} 183}
216 184
217 185
218int 186int
219main (int argc, char *argv[]) 187main (int argc, char *argv[])
220{ 188{
221 char *const argvx[] = { 189 char *const argvx[] = {
222 "test-gnunet-service-fs-migration", 190 "test-gnunet-service-fs-migration",
223 "-c", 191 "-c",
224 "fs_test_lib_data.conf", 192 "fs_test_lib_data.conf",
@@ -232,16 +200,16 @@ main (int argc, char *argv[])
232 }; 200 };
233 201
234 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); 202 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
235 GNUNET_log_setup ("test_gnunet_service_fs_migration", 203 GNUNET_log_setup ("test_gnunet_service_fs_migration",
236#if VERBOSE 204#if VERBOSE
237 "DEBUG", 205 "DEBUG",
238#else 206#else
239 "WARNING", 207 "WARNING",
240#endif 208#endif
241 NULL); 209 NULL);
242 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 210 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
243 argvx, "test-gnunet-service-fs-migration", 211 argvx, "test-gnunet-service-fs-migration",
244 "nohelp", options, &run, NULL); 212 "nohelp", options, &run, NULL);
245 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); 213 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
246 return ok; 214 return ok;
247} 215}