diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/fs/fs_api.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/fs/fs_api.c')
-rw-r--r-- | src/fs/fs_api.c | 3372 |
1 files changed, 1701 insertions, 1671 deletions
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index f7b64a5c9..45051ddcb 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.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/fs_api.c | 22 | * @file fs/fs_api.c |
@@ -47,23 +47,23 @@ | |||
47 | * @param qe job to start | 47 | * @param qe job to start |
48 | */ | 48 | */ |
49 | static void | 49 | static void |
50 | start_job (struct GNUNET_FS_QueueEntry *qe) | 50 | start_job(struct GNUNET_FS_QueueEntry *qe) |
51 | { | 51 | { |
52 | qe->active = GNUNET_YES; | 52 | qe->active = GNUNET_YES; |
53 | qe->start (qe->cls); | 53 | qe->start(qe->cls); |
54 | qe->start_times++; | 54 | qe->start_times++; |
55 | qe->h->active_blocks += qe->blocks; | 55 | qe->h->active_blocks += qe->blocks; |
56 | qe->h->active_downloads++; | 56 | qe->h->active_downloads++; |
57 | qe->start_time = GNUNET_TIME_absolute_get (); | 57 | qe->start_time = GNUNET_TIME_absolute_get(); |
58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 58 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
59 | "Starting job %p (%u active)\n", | 59 | "Starting job %p (%u active)\n", |
60 | qe, | 60 | qe, |
61 | qe->h->active_downloads); | 61 | qe->h->active_downloads); |
62 | GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe); | 62 | GNUNET_CONTAINER_DLL_remove(qe->h->pending_head, qe->h->pending_tail, qe); |
63 | GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, | 63 | GNUNET_CONTAINER_DLL_insert_after(qe->h->running_head, |
64 | qe->h->running_tail, | 64 | qe->h->running_tail, |
65 | qe->h->running_tail, | 65 | qe->h->running_tail, |
66 | qe); | 66 | qe); |
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
@@ -74,25 +74,25 @@ start_job (struct GNUNET_FS_QueueEntry *qe) | |||
74 | * @param qe job to stop | 74 | * @param qe job to stop |
75 | */ | 75 | */ |
76 | static void | 76 | static void |
77 | stop_job (struct GNUNET_FS_QueueEntry *qe) | 77 | stop_job(struct GNUNET_FS_QueueEntry *qe) |
78 | { | 78 | { |
79 | qe->active = GNUNET_NO; | 79 | qe->active = GNUNET_NO; |
80 | qe->stop (qe->cls); | 80 | qe->stop(qe->cls); |
81 | GNUNET_assert (0 < qe->h->active_downloads); | 81 | GNUNET_assert(0 < qe->h->active_downloads); |
82 | qe->h->active_downloads--; | 82 | qe->h->active_downloads--; |
83 | qe->h->active_blocks -= qe->blocks; | 83 | qe->h->active_blocks -= qe->blocks; |
84 | qe->run_time = GNUNET_TIME_relative_add (qe->run_time, | 84 | qe->run_time = GNUNET_TIME_relative_add(qe->run_time, |
85 | GNUNET_TIME_absolute_get_duration ( | 85 | GNUNET_TIME_absolute_get_duration( |
86 | qe->start_time)); | 86 | qe->start_time)); |
87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 87 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
88 | "Stopping job %p (%u active)\n", | 88 | "Stopping job %p (%u active)\n", |
89 | qe, | 89 | qe, |
90 | qe->h->active_downloads); | 90 | qe->h->active_downloads); |
91 | GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe); | 91 | GNUNET_CONTAINER_DLL_remove(qe->h->running_head, qe->h->running_tail, qe); |
92 | GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, | 92 | GNUNET_CONTAINER_DLL_insert_after(qe->h->pending_head, |
93 | qe->h->pending_tail, | 93 | qe->h->pending_tail, |
94 | qe->h->pending_tail, | 94 | qe->h->pending_tail, |
95 | qe); | 95 | qe); |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
@@ -103,7 +103,7 @@ stop_job (struct GNUNET_FS_QueueEntry *qe) | |||
103 | * @param cls the `struct GNUNET_FS_Handle *` | 103 | * @param cls the `struct GNUNET_FS_Handle *` |
104 | */ | 104 | */ |
105 | static void | 105 | static void |
106 | process_job_queue (void *cls) | 106 | process_job_queue(void *cls) |
107 | { | 107 | { |
108 | struct GNUNET_FS_Handle *h = cls; | 108 | struct GNUNET_FS_Handle *h = cls; |
109 | struct GNUNET_FS_QueueEntry *qe; | 109 | struct GNUNET_FS_QueueEntry *qe; |
@@ -131,20 +131,22 @@ process_job_queue (void *cls) | |||
131 | num_probes_waiting = 0; | 131 | num_probes_waiting = 0; |
132 | num_downloads_waiting = 0; | 132 | num_downloads_waiting = 0; |
133 | for (qe = h->pending_head; NULL != qe; qe = qe->next) | 133 | for (qe = h->pending_head; NULL != qe; qe = qe->next) |
134 | { | ||
135 | switch (qe->priority) | ||
136 | { | 134 | { |
137 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: | 135 | switch (qe->priority) |
138 | num_probes_waiting++; | 136 | { |
139 | break; | 137 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: |
140 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 138 | num_probes_waiting++; |
141 | num_downloads_waiting++; | 139 | break; |
142 | break; | 140 | |
143 | default: | 141 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
144 | GNUNET_break (0); | 142 | num_downloads_waiting++; |
145 | break; | 143 | break; |
144 | |||
145 | default: | ||
146 | GNUNET_break(0); | ||
147 | break; | ||
148 | } | ||
146 | } | 149 | } |
147 | } | ||
148 | /* now, calculate some basic statistics on running jobs */ | 150 | /* now, calculate some basic statistics on running jobs */ |
149 | num_probes_active = 0; | 151 | num_probes_active = 0; |
150 | num_probes_expired = 0; | 152 | num_probes_expired = 0; |
@@ -152,161 +154,165 @@ process_job_queue (void *cls) | |||
152 | num_downloads_expired = 0; | 154 | num_downloads_expired = 0; |
153 | next = h->running_head; | 155 | next = h->running_head; |
154 | while (NULL != (qe = next)) | 156 | while (NULL != (qe = next)) |
155 | { | 157 | { |
156 | next = qe->next; | 158 | next = qe->next; |
157 | switch (qe->priority) | 159 | switch (qe->priority) |
158 | { | 160 | { |
159 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: | 161 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: |
160 | run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); | 162 | run_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2); |
161 | end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); | 163 | end_time = GNUNET_TIME_absolute_add(qe->start_time, run_time); |
162 | rst = GNUNET_TIME_absolute_get_remaining (end_time); | 164 | rst = GNUNET_TIME_absolute_get_remaining(end_time); |
163 | if (0 == rst.rel_value_us) | 165 | if (0 == rst.rel_value_us) |
164 | { | 166 | { |
165 | num_probes_expired++; | 167 | num_probes_expired++; |
166 | stop_job (qe); | 168 | stop_job(qe); |
167 | } | 169 | } |
168 | else | 170 | else |
169 | { | 171 | { |
170 | num_probes_active++; | 172 | num_probes_active++; |
171 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); | 173 | restart_at = GNUNET_TIME_relative_min(rst, restart_at); |
172 | } | 174 | } |
173 | break; | 175 | break; |
174 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 176 | |
175 | run_time = | 177 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
176 | GNUNET_TIME_relative_saturating_multiply (h->avg_block_latency, | 178 | run_time = |
177 | qe->blocks * qe->start_times); | 179 | GNUNET_TIME_relative_saturating_multiply(h->avg_block_latency, |
178 | end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); | 180 | qe->blocks * qe->start_times); |
179 | rst = GNUNET_TIME_absolute_get_remaining (end_time); | 181 | end_time = GNUNET_TIME_absolute_add(qe->start_time, run_time); |
180 | if (0 == rst.rel_value_us) | 182 | rst = GNUNET_TIME_absolute_get_remaining(end_time); |
181 | { | 183 | if (0 == rst.rel_value_us) |
182 | num_downloads_expired++; | 184 | { |
183 | stop_job (qe); | 185 | num_downloads_expired++; |
184 | } | 186 | stop_job(qe); |
185 | else | 187 | } |
186 | { | 188 | else |
187 | num_downloads_active++; | 189 | { |
188 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); | 190 | num_downloads_active++; |
189 | } | 191 | restart_at = GNUNET_TIME_relative_min(rst, restart_at); |
190 | break; | 192 | } |
191 | default: | 193 | break; |
192 | GNUNET_break (0); | 194 | |
193 | break; | 195 | default: |
196 | GNUNET_break(0); | ||
197 | break; | ||
198 | } | ||
194 | } | 199 | } |
195 | } | 200 | GNUNET_break(h->active_downloads == |
196 | GNUNET_break (h->active_downloads == | 201 | num_downloads_active + num_probes_active); |
197 | num_downloads_active + num_probes_active); | 202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 203 | "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", |
199 | "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", | 204 | num_probes_active, |
200 | num_probes_active, | 205 | num_probes_expired, |
201 | num_probes_expired, | 206 | num_probes_waiting, |
202 | num_probes_waiting, | 207 | num_downloads_active, |
203 | num_downloads_active, | 208 | num_downloads_expired, |
204 | num_downloads_expired, | 209 | num_downloads_waiting); |
205 | num_downloads_waiting); | 210 | GNUNET_break(h->active_downloads + num_probes_active <= |
206 | GNUNET_break (h->active_downloads + num_probes_active <= | 211 | h->max_parallel_downloads); |
207 | h->max_parallel_downloads); | ||
208 | /* calculate start/stop decisions */ | 212 | /* calculate start/stop decisions */ |
209 | if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) | 213 | if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) |
210 | { | 214 | { |
211 | /* stop as many probes as there are downloads and probes */ | 215 | /* stop as many probes as there are downloads and probes */ |
212 | num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting); | 216 | num_probes_change = -GNUNET_MIN(num_probes_active, num_downloads_waiting); |
213 | /* start as many downloads as there are free slots, including those | 217 | /* start as many downloads as there are free slots, including those |
214 | we just opened up */ | 218 | we just opened up */ |
215 | num_downloads_change = | 219 | num_downloads_change = |
216 | h->max_parallel_downloads - h->active_downloads - num_probes_change; | 220 | h->max_parallel_downloads - h->active_downloads - num_probes_change; |
217 | } | 221 | } |
218 | else | 222 | else |
219 | { | 223 | { |
220 | /* start all downloads (we can) */ | 224 | /* start all downloads (we can) */ |
221 | num_downloads_change = num_downloads_waiting; | 225 | num_downloads_change = num_downloads_waiting; |
222 | /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ | 226 | /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ |
223 | if (1 + h->max_parallel_downloads / 4 >= | 227 | if (1 + h->max_parallel_downloads / 4 >= |
224 | (h->active_downloads + num_downloads_change)) | 228 | (h->active_downloads + num_downloads_change)) |
225 | num_probes_change = | 229 | num_probes_change = |
226 | GNUNET_MIN (num_probes_waiting, | 230 | GNUNET_MIN(num_probes_waiting, |
227 | (1 + h->max_parallel_downloads / 4) - | 231 | (1 + h->max_parallel_downloads / 4) - |
228 | (h->active_downloads + num_downloads_change)); | 232 | (h->active_downloads + num_downloads_change)); |
229 | else | 233 | else |
230 | num_probes_change = 0; | 234 | num_probes_change = 0; |
231 | } | 235 | } |
232 | GNUNET_break (num_downloads_change <= num_downloads_waiting); | 236 | GNUNET_break(num_downloads_change <= num_downloads_waiting); |
233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 237 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
234 | "Changing %d probes and %d/%u/%u downloads\n", | 238 | "Changing %d probes and %d/%u/%u downloads\n", |
235 | num_probes_change, | 239 | num_probes_change, |
236 | num_downloads_change, | 240 | num_downloads_change, |
237 | (unsigned int) h->active_downloads, | 241 | (unsigned int)h->active_downloads, |
238 | (unsigned int) h->max_parallel_downloads); | 242 | (unsigned int)h->max_parallel_downloads); |
239 | /* actually stop probes */ | 243 | /* actually stop probes */ |
240 | next = h->running_head; | 244 | next = h->running_head; |
241 | while (NULL != (qe = next)) | 245 | while (NULL != (qe = next)) |
242 | { | ||
243 | next = qe->next; | ||
244 | if (GNUNET_FS_QUEUE_PRIORITY_PROBE != qe->priority) | ||
245 | continue; | ||
246 | if (num_probes_change < 0) | ||
247 | { | 246 | { |
248 | stop_job (qe); | 247 | next = qe->next; |
249 | num_probes_change++; | 248 | if (GNUNET_FS_QUEUE_PRIORITY_PROBE != qe->priority) |
250 | if (0 == num_probes_change) | 249 | continue; |
251 | break; | 250 | if (num_probes_change < 0) |
251 | { | ||
252 | stop_job(qe); | ||
253 | num_probes_change++; | ||
254 | if (0 == num_probes_change) | ||
255 | break; | ||
256 | } | ||
252 | } | 257 | } |
253 | } | 258 | GNUNET_break(0 <= num_probes_change); |
254 | GNUNET_break (0 <= num_probes_change); | ||
255 | 259 | ||
256 | /* start some more tasks if we now have empty slots */ | 260 | /* start some more tasks if we now have empty slots */ |
257 | block_limit_hit = GNUNET_NO; | 261 | block_limit_hit = GNUNET_NO; |
258 | next = h->pending_head; | 262 | next = h->pending_head; |
259 | while ((NULL != (qe = next)) && | 263 | while ((NULL != (qe = next)) && |
260 | ((num_probes_change > 0) || (num_downloads_change > 0))) | 264 | ((num_probes_change > 0) || (num_downloads_change > 0))) |
261 | { | 265 | { |
262 | next = qe->next; | 266 | next = qe->next; |
263 | switch (qe->priority) | 267 | switch (qe->priority) |
264 | { | 268 | { |
265 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: | 269 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: |
266 | if (num_probes_change > 0) | 270 | if (num_probes_change > 0) |
267 | { | 271 | { |
268 | start_job (qe); | 272 | start_job(qe); |
269 | num_probes_change--; | 273 | num_probes_change--; |
270 | run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); | 274 | run_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2); |
271 | restart_at = GNUNET_TIME_relative_min (run_time, restart_at); | 275 | restart_at = GNUNET_TIME_relative_min(run_time, restart_at); |
272 | } | 276 | } |
273 | break; | 277 | break; |
274 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 278 | |
275 | if ((num_downloads_change > 0) && | 279 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
276 | ((qe->blocks + h->active_blocks <= h->max_parallel_requests) || | 280 | if ((num_downloads_change > 0) && |
277 | ((qe->blocks > h->max_parallel_requests) && | 281 | ((qe->blocks + h->active_blocks <= h->max_parallel_requests) || |
278 | (0 == h->active_downloads)))) | 282 | ((qe->blocks > h->max_parallel_requests) && |
279 | { | 283 | (0 == h->active_downloads)))) |
280 | start_job (qe); | 284 | { |
281 | num_downloads_change--; | 285 | start_job(qe); |
282 | } | 286 | num_downloads_change--; |
283 | else if (num_downloads_change > 0) | 287 | } |
284 | block_limit_hit = GNUNET_YES; | 288 | else if (num_downloads_change > 0) |
285 | break; | 289 | block_limit_hit = GNUNET_YES; |
286 | default: | 290 | break; |
287 | GNUNET_break (0); | 291 | |
288 | break; | 292 | default: |
293 | GNUNET_break(0); | ||
294 | break; | ||
295 | } | ||
289 | } | 296 | } |
290 | } | 297 | GNUNET_break((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit)); |
291 | GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit)); | 298 | GNUNET_break(0 == num_probes_change); |
292 | GNUNET_break (0 == num_probes_change); | ||
293 | 299 | ||
294 | GNUNET_log ( | 300 | GNUNET_log( |
295 | GNUNET_ERROR_TYPE_DEBUG, | 301 | GNUNET_ERROR_TYPE_DEBUG, |
296 | "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", | 302 | "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", |
297 | h->active_downloads, | 303 | h->active_downloads, |
298 | h->max_parallel_requests, | 304 | h->max_parallel_requests, |
299 | num_probes_change, | 305 | num_probes_change, |
300 | num_downloads_change, | 306 | num_downloads_change, |
301 | GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES)); | 307 | GNUNET_STRINGS_relative_time_to_string(restart_at, GNUNET_YES)); |
302 | 308 | ||
303 | /* make sure we run again, callbacks might have | 309 | /* make sure we run again, callbacks might have |
304 | already re-scheduled the job, so cancel such | 310 | already re-scheduled the job, so cancel such |
305 | an operation (if it exists) */ | 311 | an operation (if it exists) */ |
306 | if (NULL != h->queue_job) | 312 | if (NULL != h->queue_job) |
307 | GNUNET_SCHEDULER_cancel (h->queue_job); | 313 | GNUNET_SCHEDULER_cancel(h->queue_job); |
308 | h->queue_job = | 314 | h->queue_job = |
309 | GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); | 315 | GNUNET_SCHEDULER_add_delayed(restart_at, &process_job_queue, h); |
310 | } | 316 | } |
311 | 317 | ||
312 | 318 | ||
@@ -322,31 +328,31 @@ process_job_queue (void *cls) | |||
322 | * @return queue handle | 328 | * @return queue handle |
323 | */ | 329 | */ |
324 | struct GNUNET_FS_QueueEntry * | 330 | struct GNUNET_FS_QueueEntry * |
325 | GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | 331 | GNUNET_FS_queue_(struct GNUNET_FS_Handle *h, |
326 | GNUNET_SCHEDULER_TaskCallback start, | 332 | GNUNET_SCHEDULER_TaskCallback start, |
327 | GNUNET_SCHEDULER_TaskCallback stop, | 333 | GNUNET_SCHEDULER_TaskCallback stop, |
328 | void *cls, | 334 | void *cls, |
329 | unsigned int blocks, | 335 | unsigned int blocks, |
330 | enum GNUNET_FS_QueuePriority priority) | 336 | enum GNUNET_FS_QueuePriority priority) |
331 | { | 337 | { |
332 | struct GNUNET_FS_QueueEntry *qe; | 338 | struct GNUNET_FS_QueueEntry *qe; |
333 | 339 | ||
334 | qe = GNUNET_new (struct GNUNET_FS_QueueEntry); | 340 | qe = GNUNET_new(struct GNUNET_FS_QueueEntry); |
335 | qe->h = h; | 341 | qe->h = h; |
336 | qe->start = start; | 342 | qe->start = start; |
337 | qe->stop = stop; | 343 | qe->stop = stop; |
338 | qe->cls = cls; | 344 | qe->cls = cls; |
339 | qe->queue_time = GNUNET_TIME_absolute_get (); | 345 | qe->queue_time = GNUNET_TIME_absolute_get(); |
340 | qe->blocks = blocks; | 346 | qe->blocks = blocks; |
341 | qe->priority = priority; | 347 | qe->priority = priority; |
342 | GNUNET_CONTAINER_DLL_insert_after (h->pending_head, | 348 | GNUNET_CONTAINER_DLL_insert_after(h->pending_head, |
343 | h->pending_tail, | 349 | h->pending_tail, |
344 | h->pending_tail, | 350 | h->pending_tail, |
345 | qe); | 351 | qe); |
346 | if (NULL != h->queue_job) | 352 | if (NULL != h->queue_job) |
347 | GNUNET_SCHEDULER_cancel (h->queue_job); | 353 | GNUNET_SCHEDULER_cancel(h->queue_job); |
348 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); | 354 | h->queue_job = GNUNET_SCHEDULER_add_now(&process_job_queue, h); |
349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe); | 355 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe); |
350 | return qe; | 356 | return qe; |
351 | } | 357 | } |
352 | 358 | ||
@@ -357,19 +363,19 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | |||
357 | * @param qe handle for the job | 363 | * @param qe handle for the job |
358 | */ | 364 | */ |
359 | void | 365 | void |
360 | GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe) | 366 | GNUNET_FS_dequeue_(struct GNUNET_FS_QueueEntry *qe) |
361 | { | 367 | { |
362 | struct GNUNET_FS_Handle *h; | 368 | struct GNUNET_FS_Handle *h; |
363 | 369 | ||
364 | h = qe->h; | 370 | h = qe->h; |
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe); | 371 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe); |
366 | if (GNUNET_YES == qe->active) | 372 | if (GNUNET_YES == qe->active) |
367 | stop_job (qe); | 373 | stop_job(qe); |
368 | GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe); | 374 | GNUNET_CONTAINER_DLL_remove(h->pending_head, h->pending_tail, qe); |
369 | GNUNET_free (qe); | 375 | GNUNET_free(qe); |
370 | if (NULL != h->queue_job) | 376 | if (NULL != h->queue_job) |
371 | GNUNET_SCHEDULER_cancel (h->queue_job); | 377 | GNUNET_SCHEDULER_cancel(h->queue_job); |
372 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); | 378 | h->queue_job = GNUNET_SCHEDULER_add_now(&process_job_queue, h); |
373 | } | 379 | } |
374 | 380 | ||
375 | 381 | ||
@@ -382,16 +388,16 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe) | |||
382 | * @return fresh top-level activity handle | 388 | * @return fresh top-level activity handle |
383 | */ | 389 | */ |
384 | struct TopLevelActivity * | 390 | struct TopLevelActivity * |
385 | GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | 391 | GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, |
386 | SuspendSignalFunction ssf, | 392 | SuspendSignalFunction ssf, |
387 | void *ssf_cls) | 393 | void *ssf_cls) |
388 | { | 394 | { |
389 | struct TopLevelActivity *ret; | 395 | struct TopLevelActivity *ret; |
390 | 396 | ||
391 | ret = GNUNET_new (struct TopLevelActivity); | 397 | ret = GNUNET_new(struct TopLevelActivity); |
392 | ret->ssf = ssf; | 398 | ret->ssf = ssf; |
393 | ret->ssf_cls = ssf_cls; | 399 | ret->ssf_cls = ssf_cls; |
394 | GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret); | 400 | GNUNET_CONTAINER_DLL_insert(h->top_head, h->top_tail, ret); |
395 | return ret; | 401 | return ret; |
396 | } | 402 | } |
397 | 403 | ||
@@ -403,18 +409,17 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | |||
403 | * @param top top level activity entry | 409 | * @param top top level activity entry |
404 | */ | 410 | */ |
405 | void | 411 | void |
406 | GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top) | 412 | GNUNET_FS_end_top(struct GNUNET_FS_Handle *h, struct TopLevelActivity *top) |
407 | { | 413 | { |
408 | GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top); | 414 | GNUNET_CONTAINER_DLL_remove(h->top_head, h->top_tail, top); |
409 | GNUNET_free (top); | 415 | GNUNET_free(top); |
410 | } | 416 | } |
411 | 417 | ||
412 | 418 | ||
413 | /** | 419 | /** |
414 | * Closure for #GNUNET_FS_data_reader_file_(). | 420 | * Closure for #GNUNET_FS_data_reader_file_(). |
415 | */ | 421 | */ |
416 | struct FileInfo | 422 | struct FileInfo { |
417 | { | ||
418 | /** | 423 | /** |
419 | * Name of the file to read. | 424 | * Name of the file to read. |
420 | */ | 425 | */ |
@@ -448,63 +453,63 @@ struct FileInfo | |||
448 | * @return number of bytes written, usually @a max, 0 on error | 453 | * @return number of bytes written, usually @a max, 0 on error |
449 | */ | 454 | */ |
450 | size_t | 455 | size_t |
451 | GNUNET_FS_data_reader_file_ (void *cls, | 456 | GNUNET_FS_data_reader_file_(void *cls, |
452 | uint64_t offset, | 457 | uint64_t offset, |
453 | size_t max, | 458 | size_t max, |
454 | void *buf, | 459 | void *buf, |
455 | char **emsg) | 460 | char **emsg) |
456 | { | 461 | { |
457 | struct FileInfo *fi = cls; | 462 | struct FileInfo *fi = cls; |
458 | ssize_t ret; | 463 | ssize_t ret; |
459 | 464 | ||
460 | if (UINT64_MAX == offset) | 465 | if (UINT64_MAX == offset) |
461 | { | ||
462 | if (NULL != fi->fd) | ||
463 | { | 466 | { |
464 | GNUNET_DISK_file_close (fi->fd); | 467 | if (NULL != fi->fd) |
465 | fi->fd = NULL; | 468 | { |
469 | GNUNET_DISK_file_close(fi->fd); | ||
470 | fi->fd = NULL; | ||
471 | } | ||
472 | return 0; | ||
466 | } | 473 | } |
467 | return 0; | ||
468 | } | ||
469 | if (0 == max) | 474 | if (0 == max) |
470 | { | 475 | { |
471 | if (NULL != fi->fd) | 476 | if (NULL != fi->fd) |
472 | GNUNET_DISK_file_close (fi->fd); | 477 | GNUNET_DISK_file_close(fi->fd); |
473 | GNUNET_free (fi->filename); | 478 | GNUNET_free(fi->filename); |
474 | GNUNET_free (fi); | 479 | GNUNET_free(fi); |
475 | return 0; | ||
476 | } | ||
477 | if (NULL == fi->fd) | ||
478 | { | ||
479 | fi->fd = GNUNET_DISK_file_open (fi->filename, | ||
480 | GNUNET_DISK_OPEN_READ, | ||
481 | GNUNET_DISK_PERM_NONE); | ||
482 | if (NULL == fi->fd) | ||
483 | { | ||
484 | GNUNET_asprintf (emsg, | ||
485 | _ ("Could not open file `%s': %s"), | ||
486 | fi->filename, | ||
487 | strerror (errno)); | ||
488 | return 0; | 480 | return 0; |
489 | } | 481 | } |
490 | } | 482 | if (NULL == fi->fd) |
483 | { | ||
484 | fi->fd = GNUNET_DISK_file_open(fi->filename, | ||
485 | GNUNET_DISK_OPEN_READ, | ||
486 | GNUNET_DISK_PERM_NONE); | ||
487 | if (NULL == fi->fd) | ||
488 | { | ||
489 | GNUNET_asprintf(emsg, | ||
490 | _("Could not open file `%s': %s"), | ||
491 | fi->filename, | ||
492 | strerror(errno)); | ||
493 | return 0; | ||
494 | } | ||
495 | } | ||
491 | if ((GNUNET_SYSERR == | 496 | if ((GNUNET_SYSERR == |
492 | GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) || | 497 | GNUNET_DISK_file_seek(fi->fd, offset, GNUNET_DISK_SEEK_SET)) || |
493 | (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max)))) | 498 | (-1 == (ret = GNUNET_DISK_file_read(fi->fd, buf, max)))) |
494 | { | 499 | { |
495 | GNUNET_asprintf (emsg, | 500 | GNUNET_asprintf(emsg, |
496 | _ ("Could not read file `%s': %s"), | 501 | _("Could not read file `%s': %s"), |
497 | fi->filename, | 502 | fi->filename, |
498 | strerror (errno)); | 503 | strerror(errno)); |
499 | return 0; | 504 | return 0; |
500 | } | 505 | } |
501 | if (ret != max) | 506 | if (ret != max) |
502 | { | 507 | { |
503 | GNUNET_asprintf (emsg, | 508 | GNUNET_asprintf(emsg, |
504 | _ ("Short read reading from file `%s'!"), | 509 | _("Short read reading from file `%s'!"), |
505 | fi->filename); | 510 | fi->filename); |
506 | return 0; | 511 | return 0; |
507 | } | 512 | } |
508 | return max; | 513 | return max; |
509 | } | 514 | } |
510 | 515 | ||
@@ -516,17 +521,17 @@ GNUNET_FS_data_reader_file_ (void *cls, | |||
516 | * @return closure to use, NULL on error | 521 | * @return closure to use, NULL on error |
517 | */ | 522 | */ |
518 | void * | 523 | void * |
519 | GNUNET_FS_make_file_reader_context_ (const char *filename) | 524 | GNUNET_FS_make_file_reader_context_(const char *filename) |
520 | { | 525 | { |
521 | struct FileInfo *fi; | 526 | struct FileInfo *fi; |
522 | 527 | ||
523 | fi = GNUNET_new (struct FileInfo); | 528 | fi = GNUNET_new(struct FileInfo); |
524 | fi->filename = GNUNET_STRINGS_filename_expand (filename); | 529 | fi->filename = GNUNET_STRINGS_filename_expand(filename); |
525 | if (NULL == fi->filename) | 530 | if (NULL == fi->filename) |
526 | { | 531 | { |
527 | GNUNET_free (fi); | 532 | GNUNET_free(fi); |
528 | return NULL; | 533 | return NULL; |
529 | } | 534 | } |
530 | return fi; | 535 | return fi; |
531 | } | 536 | } |
532 | 537 | ||
@@ -552,22 +557,22 @@ GNUNET_FS_make_file_reader_context_ (const char *filename) | |||
552 | * @return number of bytes written, usually @a max, 0 on error | 557 | * @return number of bytes written, usually @a max, 0 on error |
553 | */ | 558 | */ |
554 | size_t | 559 | size_t |
555 | GNUNET_FS_data_reader_copy_ (void *cls, | 560 | GNUNET_FS_data_reader_copy_(void *cls, |
556 | uint64_t offset, | 561 | uint64_t offset, |
557 | size_t max, | 562 | size_t max, |
558 | void *buf, | 563 | void *buf, |
559 | char **emsg) | 564 | char **emsg) |
560 | { | 565 | { |
561 | char *data = cls; | 566 | char *data = cls; |
562 | 567 | ||
563 | if (UINT64_MAX == offset) | 568 | if (UINT64_MAX == offset) |
564 | return 0; | 569 | return 0; |
565 | if (0 == max) | 570 | if (0 == max) |
566 | { | 571 | { |
567 | GNUNET_free_non_null (data); | 572 | GNUNET_free_non_null(data); |
568 | return 0; | 573 | return 0; |
569 | } | 574 | } |
570 | GNUNET_memcpy (buf, &data[offset], max); | 575 | GNUNET_memcpy(buf, &data[offset], max); |
571 | return max; | 576 | return max; |
572 | } | 577 | } |
573 | 578 | ||
@@ -582,30 +587,30 @@ GNUNET_FS_data_reader_copy_ (void *cls, | |||
582 | * @return NULL on error | 587 | * @return NULL on error |
583 | */ | 588 | */ |
584 | static char * | 589 | static char * |
585 | get_serialization_file_name (struct GNUNET_FS_Handle *h, | 590 | get_serialization_file_name(struct GNUNET_FS_Handle *h, |
586 | const char *ext, | 591 | const char *ext, |
587 | const char *ent) | 592 | const char *ent) |
588 | { | 593 | { |
589 | char *basename; | 594 | char *basename; |
590 | char *ret; | 595 | char *ret; |
591 | 596 | ||
592 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 597 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
593 | return NULL; /* persistence not requested */ | 598 | return NULL; /* persistence not requested */ |
594 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, | 599 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, |
595 | "fs", | 600 | "fs", |
596 | "STATE_DIR", | 601 | "STATE_DIR", |
597 | &basename)) | 602 | &basename)) |
598 | return NULL; | 603 | return NULL; |
599 | GNUNET_asprintf (&ret, | 604 | GNUNET_asprintf(&ret, |
600 | "%s%s%s%s%s%s%s", | 605 | "%s%s%s%s%s%s%s", |
601 | basename, | 606 | basename, |
602 | DIR_SEPARATOR_STR, | 607 | DIR_SEPARATOR_STR, |
603 | h->client_name, | 608 | h->client_name, |
604 | DIR_SEPARATOR_STR, | 609 | DIR_SEPARATOR_STR, |
605 | ext, | 610 | ext, |
606 | DIR_SEPARATOR_STR, | 611 | DIR_SEPARATOR_STR, |
607 | ent); | 612 | ent); |
608 | GNUNET_free (basename); | 613 | GNUNET_free(basename); |
609 | return ret; | 614 | return ret; |
610 | } | 615 | } |
611 | 616 | ||
@@ -622,33 +627,33 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h, | |||
622 | * @return NULL on error | 627 | * @return NULL on error |
623 | */ | 628 | */ |
624 | static char * | 629 | static char * |
625 | get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | 630 | get_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, |
626 | const char *ext, | 631 | const char *ext, |
627 | const char *uni, | 632 | const char *uni, |
628 | const char *ent) | 633 | const char *ent) |
629 | { | 634 | { |
630 | char *basename; | 635 | char *basename; |
631 | char *ret; | 636 | char *ret; |
632 | 637 | ||
633 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 638 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
634 | return NULL; /* persistence not requested */ | 639 | return NULL; /* persistence not requested */ |
635 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, | 640 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, |
636 | "fs", | 641 | "fs", |
637 | "STATE_DIR", | 642 | "STATE_DIR", |
638 | &basename)) | 643 | &basename)) |
639 | return NULL; | 644 | return NULL; |
640 | GNUNET_asprintf (&ret, | 645 | GNUNET_asprintf(&ret, |
641 | "%s%s%s%s%s%s%s.dir%s%s", | 646 | "%s%s%s%s%s%s%s.dir%s%s", |
642 | basename, | 647 | basename, |
643 | DIR_SEPARATOR_STR, | 648 | DIR_SEPARATOR_STR, |
644 | h->client_name, | 649 | h->client_name, |
645 | DIR_SEPARATOR_STR, | 650 | DIR_SEPARATOR_STR, |
646 | ext, | 651 | ext, |
647 | DIR_SEPARATOR_STR, | 652 | DIR_SEPARATOR_STR, |
648 | uni, | 653 | uni, |
649 | DIR_SEPARATOR_STR, | 654 | DIR_SEPARATOR_STR, |
650 | ent); | 655 | ent); |
651 | GNUNET_free (basename); | 656 | GNUNET_free(basename); |
652 | return ret; | 657 | return ret; |
653 | } | 658 | } |
654 | 659 | ||
@@ -662,16 +667,16 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
662 | * @return NULL on error | 667 | * @return NULL on error |
663 | */ | 668 | */ |
664 | static struct GNUNET_BIO_ReadHandle * | 669 | static struct GNUNET_BIO_ReadHandle * |
665 | get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | 670 | get_read_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent) |
666 | { | 671 | { |
667 | char *fn; | 672 | char *fn; |
668 | struct GNUNET_BIO_ReadHandle *ret; | 673 | struct GNUNET_BIO_ReadHandle *ret; |
669 | 674 | ||
670 | fn = get_serialization_file_name (h, ext, ent); | 675 | fn = get_serialization_file_name(h, ext, ent); |
671 | if (NULL == fn) | 676 | if (NULL == fn) |
672 | return NULL; | 677 | return NULL; |
673 | ret = GNUNET_BIO_read_open (fn); | 678 | ret = GNUNET_BIO_read_open(fn); |
674 | GNUNET_free (fn); | 679 | GNUNET_free(fn); |
675 | return ret; | 680 | return ret; |
676 | } | 681 | } |
677 | 682 | ||
@@ -685,17 +690,17 @@ get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | |||
685 | * @return NULL on error | 690 | * @return NULL on error |
686 | */ | 691 | */ |
687 | static struct GNUNET_BIO_WriteHandle * | 692 | static struct GNUNET_BIO_WriteHandle * |
688 | get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | 693 | get_write_handle(struct GNUNET_FS_Handle *h, const char *ext, const char *ent) |
689 | { | 694 | { |
690 | char *fn; | 695 | char *fn; |
691 | struct GNUNET_BIO_WriteHandle *ret; | 696 | struct GNUNET_BIO_WriteHandle *ret; |
692 | 697 | ||
693 | fn = get_serialization_file_name (h, ext, ent); | 698 | fn = get_serialization_file_name(h, ext, ent); |
694 | if (NULL == fn) | 699 | if (NULL == fn) |
695 | return NULL; | 700 | return NULL; |
696 | ret = GNUNET_BIO_write_open (fn); | 701 | ret = GNUNET_BIO_write_open(fn); |
697 | GNUNET_break (NULL != ret); | 702 | GNUNET_break(NULL != ret); |
698 | GNUNET_free (fn); | 703 | GNUNET_free(fn); |
699 | return ret; | 704 | return ret; |
700 | } | 705 | } |
701 | 706 | ||
@@ -710,19 +715,19 @@ get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | |||
710 | * @return NULL on error | 715 | * @return NULL on error |
711 | */ | 716 | */ |
712 | static struct GNUNET_BIO_WriteHandle * | 717 | static struct GNUNET_BIO_WriteHandle * |
713 | get_write_handle_in_dir (struct GNUNET_FS_Handle *h, | 718 | get_write_handle_in_dir(struct GNUNET_FS_Handle *h, |
714 | const char *ext, | 719 | const char *ext, |
715 | const char *uni, | 720 | const char *uni, |
716 | const char *ent) | 721 | const char *ent) |
717 | { | 722 | { |
718 | char *fn; | 723 | char *fn; |
719 | struct GNUNET_BIO_WriteHandle *ret; | 724 | struct GNUNET_BIO_WriteHandle *ret; |
720 | 725 | ||
721 | fn = get_serialization_file_name_in_dir (h, ext, uni, ent); | 726 | fn = get_serialization_file_name_in_dir(h, ext, uni, ent); |
722 | if (NULL == fn) | 727 | if (NULL == fn) |
723 | return NULL; | 728 | return NULL; |
724 | ret = GNUNET_BIO_write_open (fn); | 729 | ret = GNUNET_BIO_write_open(fn); |
725 | GNUNET_free (fn); | 730 | GNUNET_free(fn); |
726 | return ret; | 731 | return ret; |
727 | } | 732 | } |
728 | 733 | ||
@@ -735,24 +740,24 @@ get_write_handle_in_dir (struct GNUNET_FS_Handle *h, | |||
735 | * @param ent entity identifier | 740 | * @param ent entity identifier |
736 | */ | 741 | */ |
737 | void | 742 | void |
738 | GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, | 743 | GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, |
739 | const char *ext, | 744 | const char *ext, |
740 | const char *ent) | 745 | const char *ent) |
741 | { | 746 | { |
742 | char *filename; | 747 | char *filename; |
743 | 748 | ||
744 | if ((NULL == ent) || (0 == strlen (ent))) | 749 | if ((NULL == ent) || (0 == strlen(ent))) |
745 | { | 750 | { |
746 | GNUNET_break (0); | 751 | GNUNET_break(0); |
747 | return; | 752 | return; |
748 | } | 753 | } |
749 | filename = get_serialization_file_name (h, ext, ent); | 754 | filename = get_serialization_file_name(h, ext, ent); |
750 | if (NULL != filename) | 755 | if (NULL != filename) |
751 | { | 756 | { |
752 | if ((0 != unlink (filename)) && (ENOENT != errno)) | 757 | if ((0 != unlink(filename)) && (ENOENT != errno)) |
753 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 758 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
754 | GNUNET_free (filename); | 759 | GNUNET_free(filename); |
755 | } | 760 | } |
756 | } | 761 | } |
757 | 762 | ||
758 | 763 | ||
@@ -765,24 +770,24 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, | |||
765 | * @param ent entity identifier | 770 | * @param ent entity identifier |
766 | */ | 771 | */ |
767 | static void | 772 | static void |
768 | remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, | 773 | remove_sync_file_in_dir(struct GNUNET_FS_Handle *h, |
769 | const char *ext, | 774 | const char *ext, |
770 | const char *uni, | 775 | const char *uni, |
771 | const char *ent) | 776 | const char *ent) |
772 | { | 777 | { |
773 | char *filename; | 778 | char *filename; |
774 | 779 | ||
775 | if ((NULL == ent) || (0 == strlen (ent))) | 780 | if ((NULL == ent) || (0 == strlen(ent))) |
776 | { | 781 | { |
777 | GNUNET_break (0); | 782 | GNUNET_break(0); |
778 | return; | 783 | return; |
779 | } | 784 | } |
780 | filename = get_serialization_file_name_in_dir (h, ext, uni, ent); | 785 | filename = get_serialization_file_name_in_dir(h, ext, uni, ent); |
781 | if (NULL == filename) | 786 | if (NULL == filename) |
782 | return; | 787 | return; |
783 | if (0 != unlink (filename)) | 788 | if (0 != unlink(filename)) |
784 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 789 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
785 | GNUNET_free (filename); | 790 | GNUNET_free(filename); |
786 | } | 791 | } |
787 | 792 | ||
788 | 793 | ||
@@ -794,21 +799,21 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, | |||
794 | * @param uni unique name of parent | 799 | * @param uni unique name of parent |
795 | */ | 800 | */ |
796 | void | 801 | void |
797 | GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, | 802 | GNUNET_FS_remove_sync_dir_(struct GNUNET_FS_Handle *h, |
798 | const char *ext, | 803 | const char *ext, |
799 | const char *uni) | 804 | const char *uni) |
800 | { | 805 | { |
801 | char *dn; | 806 | char *dn; |
802 | 807 | ||
803 | if (NULL == uni) | 808 | if (NULL == uni) |
804 | return; | 809 | return; |
805 | dn = get_serialization_file_name_in_dir (h, ext, uni, ""); | 810 | dn = get_serialization_file_name_in_dir(h, ext, uni, ""); |
806 | if (NULL == dn) | 811 | if (NULL == dn) |
807 | return; | 812 | return; |
808 | if ((GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) && | 813 | if ((GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) && |
809 | (GNUNET_OK != GNUNET_DISK_directory_remove (dn))) | 814 | (GNUNET_OK != GNUNET_DISK_directory_remove(dn))) |
810 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", dn); | 815 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "rmdir", dn); |
811 | GNUNET_free (dn); | 816 | GNUNET_free(dn); |
812 | } | 817 | } |
813 | 818 | ||
814 | 819 | ||
@@ -827,13 +832,13 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, | |||
827 | * @return #GNUNET_OK on success | 832 | * @return #GNUNET_OK on success |
828 | */ | 833 | */ |
829 | static int | 834 | static int |
830 | write_start_time (struct GNUNET_BIO_WriteHandle *wh, | 835 | write_start_time(struct GNUNET_BIO_WriteHandle *wh, |
831 | struct GNUNET_TIME_Absolute timestamp) | 836 | struct GNUNET_TIME_Absolute timestamp) |
832 | { | 837 | { |
833 | struct GNUNET_TIME_Relative dur; | 838 | struct GNUNET_TIME_Relative dur; |
834 | 839 | ||
835 | dur = GNUNET_TIME_absolute_get_duration (timestamp); | 840 | dur = GNUNET_TIME_absolute_get_duration(timestamp); |
836 | return GNUNET_BIO_write_int64 (wh, dur.rel_value_us); | 841 | return GNUNET_BIO_write_int64(wh, dur.rel_value_us); |
837 | } | 842 | } |
838 | 843 | ||
839 | 844 | ||
@@ -852,14 +857,14 @@ write_start_time (struct GNUNET_BIO_WriteHandle *wh, | |||
852 | * @return #GNUNET_OK on success | 857 | * @return #GNUNET_OK on success |
853 | */ | 858 | */ |
854 | static int | 859 | static int |
855 | read_start_time (struct GNUNET_BIO_ReadHandle *rh, | 860 | read_start_time(struct GNUNET_BIO_ReadHandle *rh, |
856 | struct GNUNET_TIME_Absolute *timestamp) | 861 | struct GNUNET_TIME_Absolute *timestamp) |
857 | { | 862 | { |
858 | struct GNUNET_TIME_Relative dur; | 863 | struct GNUNET_TIME_Relative dur; |
859 | 864 | ||
860 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value_us)) | 865 | if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dur.rel_value_us)) |
861 | return GNUNET_SYSERR; | 866 | return GNUNET_SYSERR; |
862 | *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), dur); | 867 | *timestamp = GNUNET_TIME_absolute_subtract(GNUNET_TIME_absolute_get(), dur); |
863 | return GNUNET_OK; | 868 | return GNUNET_OK; |
864 | } | 869 | } |
865 | 870 | ||
@@ -874,7 +879,7 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh, | |||
874 | * @return NULL on error | 879 | * @return NULL on error |
875 | */ | 880 | */ |
876 | static struct GNUNET_FS_FileInformation * | 881 | static struct GNUNET_FS_FileInformation * |
877 | deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename); | 882 | deserialize_file_information(struct GNUNET_FS_Handle *h, const char *filename); |
878 | 883 | ||
879 | 884 | ||
880 | /** | 885 | /** |
@@ -888,9 +893,9 @@ deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename); | |||
888 | * @return NULL on error | 893 | * @return NULL on error |
889 | */ | 894 | */ |
890 | static struct GNUNET_FS_FileInformation * | 895 | static struct GNUNET_FS_FileInformation * |
891 | deserialize_fi_node (struct GNUNET_FS_Handle *h, | 896 | deserialize_fi_node(struct GNUNET_FS_Handle *h, |
892 | const char *fn, | 897 | const char *fn, |
893 | struct GNUNET_BIO_ReadHandle *rh) | 898 | struct GNUNET_BIO_ReadHandle *rh) |
894 | { | 899 | { |
895 | struct GNUNET_FS_FileInformation *ret; | 900 | struct GNUNET_FS_FileInformation *ret; |
896 | struct GNUNET_FS_FileInformation *nxt; | 901 | struct GNUNET_FS_FileInformation *nxt; |
@@ -901,204 +906,209 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
901 | char *filename; | 906 | char *filename; |
902 | uint32_t dsize; | 907 | uint32_t dsize; |
903 | 908 | ||
904 | if (GNUNET_OK != GNUNET_BIO_read (rh, "status flag", &b, sizeof (b))) | 909 | if (GNUNET_OK != GNUNET_BIO_read(rh, "status flag", &b, sizeof(b))) |
905 | { | 910 | { |
906 | GNUNET_break (0); | 911 | GNUNET_break(0); |
907 | return NULL; | 912 | return NULL; |
908 | } | 913 | } |
909 | ret = GNUNET_new (struct GNUNET_FS_FileInformation); | 914 | ret = GNUNET_new(struct GNUNET_FS_FileInformation); |
910 | ret->h = h; | 915 | ret->h = h; |
911 | ksks = NULL; | 916 | ksks = NULL; |
912 | chks = NULL; | 917 | chks = NULL; |
913 | skss = NULL; | 918 | skss = NULL; |
914 | filename = NULL; | 919 | filename = NULL; |
915 | if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || | 920 | if ((GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "metadata", &ret->meta)) || |
916 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) || | 921 | (GNUNET_OK != GNUNET_BIO_read_string(rh, "ksk-uri", &ksks, 32 * 1024)) || |
917 | ((NULL != ksks) && | 922 | ((NULL != ksks) && |
918 | ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) || | 923 | ((NULL == (ret->keywords = GNUNET_FS_uri_parse(ksks, NULL))) || |
919 | (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)))) || | 924 | (GNUNET_YES != GNUNET_FS_uri_test_ksk(ret->keywords)))) || |
920 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || | 925 | (GNUNET_OK != GNUNET_BIO_read_string(rh, "chk-uri", &chks, 1024)) || |
921 | ((NULL != chks) && | 926 | ((NULL != chks) && |
922 | ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || | 927 | ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse(chks, NULL))) || |
923 | (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) || | 928 | (GNUNET_YES != GNUNET_FS_uri_test_chk(ret->chk_uri)))) || |
924 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) || | 929 | (GNUNET_OK != GNUNET_BIO_read_string(rh, "sks-uri", &skss, 1024)) || |
925 | ((NULL != skss) && | 930 | ((NULL != skss) && |
926 | ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) || | 931 | ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse(skss, NULL))) || |
927 | (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) || | 932 | (GNUNET_YES != GNUNET_FS_uri_test_sks(ret->sks_uri)))) || |
928 | (GNUNET_OK != read_start_time (rh, &ret->start_time)) || | 933 | (GNUNET_OK != read_start_time(rh, &ret->start_time)) || |
929 | (GNUNET_OK != | 934 | (GNUNET_OK != |
930 | GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) || | 935 | GNUNET_BIO_read_string(rh, "emsg", &ret->emsg, 16 * 1024)) || |
931 | (GNUNET_OK != | 936 | (GNUNET_OK != |
932 | GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || | 937 | GNUNET_BIO_read_string(rh, "fn", &ret->filename, 16 * 1024)) || |
933 | (GNUNET_OK != | 938 | (GNUNET_OK != |
934 | GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || | 939 | GNUNET_BIO_read_int64(rh, &ret->bo.expiration_time.abs_value_us)) || |
935 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || | 940 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &ret->bo.anonymity_level)) || |
936 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) || | 941 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &ret->bo.content_priority)) || |
937 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level))) | 942 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &ret->bo.replication_level))) |
938 | { | ||
939 | GNUNET_break (0); | ||
940 | goto cleanup; | ||
941 | } | ||
942 | switch (b) | ||
943 | { | ||
944 | case 0: /* file-insert */ | ||
945 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) | ||
946 | { | 943 | { |
947 | GNUNET_break (0); | 944 | GNUNET_break(0); |
948 | goto cleanup; | 945 | goto cleanup; |
949 | } | 946 | } |
950 | ret->is_directory = GNUNET_NO; | 947 | switch (b) |
951 | ret->data.file.do_index = GNUNET_NO; | ||
952 | ret->data.file.have_hash = GNUNET_NO; | ||
953 | ret->data.file.index_start_confirmed = GNUNET_NO; | ||
954 | if (GNUNET_NO == ret->is_published) | ||
955 | { | 948 | { |
949 | case 0: /* file-insert */ | ||
950 | if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) | ||
951 | { | ||
952 | GNUNET_break(0); | ||
953 | goto cleanup; | ||
954 | } | ||
955 | ret->is_directory = GNUNET_NO; | ||
956 | ret->data.file.do_index = GNUNET_NO; | ||
957 | ret->data.file.have_hash = GNUNET_NO; | ||
958 | ret->data.file.index_start_confirmed = GNUNET_NO; | ||
959 | if (GNUNET_NO == ret->is_published) | ||
960 | { | ||
961 | if (NULL == ret->filename) | ||
962 | { | ||
963 | ret->data.file.reader = &GNUNET_FS_data_reader_copy_; | ||
964 | ret->data.file.reader_cls = | ||
965 | GNUNET_malloc_large(ret->data.file.file_size); | ||
966 | if (ret->data.file.reader_cls == NULL) | ||
967 | goto cleanup; | ||
968 | if (GNUNET_OK != GNUNET_BIO_read(rh, | ||
969 | "file-data", | ||
970 | ret->data.file.reader_cls, | ||
971 | ret->data.file.file_size)) | ||
972 | { | ||
973 | GNUNET_break(0); | ||
974 | goto cleanup; | ||
975 | } | ||
976 | } | ||
977 | else | ||
978 | { | ||
979 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | ||
980 | ret->data.file.reader_cls = | ||
981 | GNUNET_FS_make_file_reader_context_(ret->filename); | ||
982 | } | ||
983 | } | ||
984 | break; | ||
985 | |||
986 | case 1: /* file-index, no hash */ | ||
987 | if (NULL == ret->filename) | ||
988 | { | ||
989 | GNUNET_break(0); | ||
990 | goto cleanup; | ||
991 | } | ||
992 | if (GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) | ||
993 | { | ||
994 | GNUNET_break(0); | ||
995 | goto cleanup; | ||
996 | } | ||
997 | ret->is_directory = GNUNET_NO; | ||
998 | ret->data.file.do_index = GNUNET_YES; | ||
999 | ret->data.file.have_hash = GNUNET_NO; | ||
1000 | ret->data.file.index_start_confirmed = GNUNET_NO; | ||
1001 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | ||
1002 | ret->data.file.reader_cls = | ||
1003 | GNUNET_FS_make_file_reader_context_(ret->filename); | ||
1004 | break; | ||
1005 | |||
1006 | case 2: /* file-index-with-hash */ | ||
956 | if (NULL == ret->filename) | 1007 | if (NULL == ret->filename) |
957 | { | 1008 | { |
958 | ret->data.file.reader = &GNUNET_FS_data_reader_copy_; | 1009 | GNUNET_break(0); |
959 | ret->data.file.reader_cls = | ||
960 | GNUNET_malloc_large (ret->data.file.file_size); | ||
961 | if (ret->data.file.reader_cls == NULL) | ||
962 | goto cleanup; | 1010 | goto cleanup; |
963 | if (GNUNET_OK != GNUNET_BIO_read (rh, | 1011 | } |
964 | "file-data", | 1012 | if ((GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) || |
965 | ret->data.file.reader_cls, | 1013 | (GNUNET_OK != GNUNET_BIO_read(rh, |
966 | ret->data.file.file_size)) | 1014 | "fileid", |
1015 | &ret->data.file.file_id, | ||
1016 | sizeof(struct GNUNET_HashCode)))) | ||
967 | { | 1017 | { |
968 | GNUNET_break (0); | 1018 | GNUNET_break(0); |
969 | goto cleanup; | 1019 | goto cleanup; |
970 | } | 1020 | } |
971 | } | 1021 | ret->is_directory = GNUNET_NO; |
972 | else | 1022 | ret->data.file.do_index = GNUNET_YES; |
973 | { | 1023 | ret->data.file.have_hash = GNUNET_YES; |
974 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 1024 | ret->data.file.index_start_confirmed = GNUNET_NO; |
975 | ret->data.file.reader_cls = | 1025 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
976 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 1026 | ret->data.file.reader_cls = |
977 | } | 1027 | GNUNET_FS_make_file_reader_context_(ret->filename); |
978 | } | 1028 | break; |
979 | break; | 1029 | |
980 | case 1: /* file-index, no hash */ | 1030 | case 3: /* file-index-with-hash-confirmed */ |
981 | if (NULL == ret->filename) | 1031 | if (NULL == ret->filename) |
982 | { | 1032 | { |
983 | GNUNET_break (0); | 1033 | GNUNET_break(0); |
984 | goto cleanup; | 1034 | goto cleanup; |
985 | } | 1035 | } |
986 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) | 1036 | if ((GNUNET_OK != GNUNET_BIO_read_int64(rh, &ret->data.file.file_size)) || |
987 | { | 1037 | (GNUNET_OK != GNUNET_BIO_read(rh, |
988 | GNUNET_break (0); | 1038 | "fileid", |
989 | goto cleanup; | 1039 | &ret->data.file.file_id, |
990 | } | 1040 | sizeof(struct GNUNET_HashCode)))) |
991 | ret->is_directory = GNUNET_NO; | 1041 | { |
992 | ret->data.file.do_index = GNUNET_YES; | 1042 | GNUNET_break(0); |
993 | ret->data.file.have_hash = GNUNET_NO; | 1043 | goto cleanup; |
994 | ret->data.file.index_start_confirmed = GNUNET_NO; | 1044 | } |
995 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 1045 | ret->is_directory = GNUNET_NO; |
996 | ret->data.file.reader_cls = | 1046 | ret->data.file.do_index = GNUNET_YES; |
997 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 1047 | ret->data.file.have_hash = GNUNET_YES; |
998 | break; | 1048 | ret->data.file.index_start_confirmed = GNUNET_YES; |
999 | case 2: /* file-index-with-hash */ | 1049 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
1000 | if (NULL == ret->filename) | 1050 | ret->data.file.reader_cls = |
1001 | { | 1051 | GNUNET_FS_make_file_reader_context_(ret->filename); |
1002 | GNUNET_break (0); | 1052 | break; |
1003 | goto cleanup; | 1053 | |
1004 | } | 1054 | case 4: /* directory */ |
1005 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1055 | ret->is_directory = GNUNET_YES; |
1006 | (GNUNET_OK != GNUNET_BIO_read (rh, | 1056 | if ((GNUNET_OK != GNUNET_BIO_read_int32(rh, &dsize)) || |
1007 | "fileid", | 1057 | (GNUNET_OK != |
1008 | &ret->data.file.file_id, | 1058 | GNUNET_BIO_read_int64(rh, &ret->data.dir.contents_completed)) || |
1009 | sizeof (struct GNUNET_HashCode)))) | 1059 | (GNUNET_OK != |
1010 | { | 1060 | GNUNET_BIO_read_int64(rh, &ret->data.dir.contents_size)) || |
1011 | GNUNET_break (0); | 1061 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large(dsize))) || |
1012 | goto cleanup; | 1062 | (GNUNET_OK != |
1013 | } | 1063 | GNUNET_BIO_read(rh, "dir-data", ret->data.dir.dir_data, dsize)) || |
1014 | ret->is_directory = GNUNET_NO; | 1064 | (GNUNET_OK != |
1015 | ret->data.file.do_index = GNUNET_YES; | 1065 | GNUNET_BIO_read_string(rh, "ent-filename", &filename, 16 * 1024))) |
1016 | ret->data.file.have_hash = GNUNET_YES; | 1066 | { |
1017 | ret->data.file.index_start_confirmed = GNUNET_NO; | 1067 | GNUNET_break(0); |
1018 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 1068 | goto cleanup; |
1019 | ret->data.file.reader_cls = | 1069 | } |
1020 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 1070 | ret->data.dir.dir_size = (uint32_t)dsize; |
1021 | break; | 1071 | if (NULL != filename) |
1022 | case 3: /* file-index-with-hash-confirmed */ | 1072 | { |
1023 | if (NULL == ret->filename) | 1073 | ret->data.dir.entries = deserialize_file_information(h, filename); |
1024 | { | 1074 | GNUNET_free(filename); |
1025 | GNUNET_break (0); | 1075 | filename = NULL; |
1076 | nxt = ret->data.dir.entries; | ||
1077 | while (NULL != nxt) | ||
1078 | { | ||
1079 | nxt->dir = ret; | ||
1080 | nxt = nxt->next; | ||
1081 | } | ||
1082 | } | ||
1083 | break; | ||
1084 | |||
1085 | default: | ||
1086 | GNUNET_break(0); | ||
1026 | goto cleanup; | 1087 | goto cleanup; |
1027 | } | 1088 | } |
1028 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1089 | ret->serialization = GNUNET_strdup(fn); |
1029 | (GNUNET_OK != GNUNET_BIO_read (rh, | 1090 | if (GNUNET_OK != |
1030 | "fileid", | 1091 | GNUNET_BIO_read_string(rh, "nxt-filename", &filename, 16 * 1024)) |
1031 | &ret->data.file.file_id, | ||
1032 | sizeof (struct GNUNET_HashCode)))) | ||
1033 | { | 1092 | { |
1034 | GNUNET_break (0); | 1093 | GNUNET_break(0); |
1035 | goto cleanup; | 1094 | goto cleanup; |
1036 | } | 1095 | } |
1037 | ret->is_directory = GNUNET_NO; | 1096 | if (NULL != filename) |
1038 | ret->data.file.do_index = GNUNET_YES; | ||
1039 | ret->data.file.have_hash = GNUNET_YES; | ||
1040 | ret->data.file.index_start_confirmed = GNUNET_YES; | ||
1041 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | ||
1042 | ret->data.file.reader_cls = | ||
1043 | GNUNET_FS_make_file_reader_context_ (ret->filename); | ||
1044 | break; | ||
1045 | case 4: /* directory */ | ||
1046 | ret->is_directory = GNUNET_YES; | ||
1047 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || | ||
1048 | (GNUNET_OK != | ||
1049 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || | ||
1050 | (GNUNET_OK != | ||
1051 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || | ||
1052 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || | ||
1053 | (GNUNET_OK != | ||
1054 | GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || | ||
1055 | (GNUNET_OK != | ||
1056 | GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16 * 1024))) | ||
1057 | { | ||
1058 | GNUNET_break (0); | ||
1059 | goto cleanup; | ||
1060 | } | ||
1061 | ret->data.dir.dir_size = (uint32_t) dsize; | ||
1062 | if (NULL != filename) | ||
1063 | { | 1097 | { |
1064 | ret->data.dir.entries = deserialize_file_information (h, filename); | 1098 | ret->next = deserialize_file_information(h, filename); |
1065 | GNUNET_free (filename); | 1099 | GNUNET_free(filename); |
1066 | filename = NULL; | 1100 | filename = NULL; |
1067 | nxt = ret->data.dir.entries; | 1101 | } |
1068 | while (NULL != nxt) | 1102 | GNUNET_free_non_null(ksks); |
1069 | { | 1103 | GNUNET_free_non_null(skss); |
1070 | nxt->dir = ret; | 1104 | GNUNET_free_non_null(chks); |
1071 | nxt = nxt->next; | ||
1072 | } | ||
1073 | } | ||
1074 | break; | ||
1075 | default: | ||
1076 | GNUNET_break (0); | ||
1077 | goto cleanup; | ||
1078 | } | ||
1079 | ret->serialization = GNUNET_strdup (fn); | ||
1080 | if (GNUNET_OK != | ||
1081 | GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16 * 1024)) | ||
1082 | { | ||
1083 | GNUNET_break (0); | ||
1084 | goto cleanup; | ||
1085 | } | ||
1086 | if (NULL != filename) | ||
1087 | { | ||
1088 | ret->next = deserialize_file_information (h, filename); | ||
1089 | GNUNET_free (filename); | ||
1090 | filename = NULL; | ||
1091 | } | ||
1092 | GNUNET_free_non_null (ksks); | ||
1093 | GNUNET_free_non_null (skss); | ||
1094 | GNUNET_free_non_null (chks); | ||
1095 | return ret; | 1105 | return ret; |
1096 | cleanup: | 1106 | cleanup: |
1097 | GNUNET_free_non_null (ksks); | 1107 | GNUNET_free_non_null(ksks); |
1098 | GNUNET_free_non_null (chks); | 1108 | GNUNET_free_non_null(chks); |
1099 | GNUNET_free_non_null (skss); | 1109 | GNUNET_free_non_null(skss); |
1100 | GNUNET_free_non_null (filename); | 1110 | GNUNET_free_non_null(filename); |
1101 | GNUNET_FS_file_information_destroy (ret, NULL, NULL); | 1111 | GNUNET_FS_file_information_destroy(ret, NULL, NULL); |
1102 | return NULL; | 1112 | return NULL; |
1103 | } | 1113 | } |
1104 | 1114 | ||
@@ -1113,36 +1123,36 @@ cleanup: | |||
1113 | * @return NULL on error | 1123 | * @return NULL on error |
1114 | */ | 1124 | */ |
1115 | static struct GNUNET_FS_FileInformation * | 1125 | static struct GNUNET_FS_FileInformation * |
1116 | deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename) | 1126 | deserialize_file_information(struct GNUNET_FS_Handle *h, const char *filename) |
1117 | { | 1127 | { |
1118 | struct GNUNET_FS_FileInformation *ret; | 1128 | struct GNUNET_FS_FileInformation *ret; |
1119 | struct GNUNET_BIO_ReadHandle *rh; | 1129 | struct GNUNET_BIO_ReadHandle *rh; |
1120 | char *emsg; | 1130 | char *emsg; |
1121 | char *fn; | 1131 | char *fn; |
1122 | 1132 | ||
1123 | rh = get_read_handle (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); | 1133 | rh = get_read_handle(h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); |
1124 | if (NULL == rh) | 1134 | if (NULL == rh) |
1125 | return NULL; | 1135 | return NULL; |
1126 | ret = deserialize_fi_node (h, filename, rh); | 1136 | ret = deserialize_fi_node(h, filename, rh); |
1127 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 1137 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
1128 | { | 1138 | { |
1129 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1139 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1130 | _ ("Failed to resume publishing information `%s': %s\n"), | 1140 | _("Failed to resume publishing information `%s': %s\n"), |
1131 | filename, | 1141 | filename, |
1132 | emsg); | 1142 | emsg); |
1133 | GNUNET_free (emsg); | 1143 | GNUNET_free(emsg); |
1134 | } | 1144 | } |
1135 | if (NULL == ret) | 1145 | if (NULL == ret) |
1136 | { | ||
1137 | fn = | ||
1138 | get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); | ||
1139 | if (NULL != fn) | ||
1140 | { | 1146 | { |
1141 | if (0 != unlink (fn)) | 1147 | fn = |
1142 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 1148 | get_serialization_file_name(h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); |
1143 | GNUNET_free (fn); | 1149 | if (NULL != fn) |
1150 | { | ||
1151 | if (0 != unlink(fn)) | ||
1152 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
1153 | GNUNET_free(fn); | ||
1154 | } | ||
1144 | } | 1155 | } |
1145 | } | ||
1146 | return ret; | 1156 | return ret; |
1147 | } | 1157 | } |
1148 | 1158 | ||
@@ -1156,7 +1166,7 @@ deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename) | |||
1156 | * @return copy of the basename, NULL on error | 1166 | * @return copy of the basename, NULL on error |
1157 | */ | 1167 | */ |
1158 | static char * | 1168 | static char * |
1159 | get_serialization_short_name (const char *fullname) | 1169 | get_serialization_short_name(const char *fullname) |
1160 | { | 1170 | { |
1161 | const char *end; | 1171 | const char *end; |
1162 | const char *nxt; | 1172 | const char *nxt; |
@@ -1166,18 +1176,18 @@ get_serialization_short_name (const char *fullname) | |||
1166 | /* FIXME: we could do this faster since we know | 1176 | /* FIXME: we could do this faster since we know |
1167 | * the length of 'end'... */ | 1177 | * the length of 'end'... */ |
1168 | while ('\0' != *nxt) | 1178 | while ('\0' != *nxt) |
1169 | { | 1179 | { |
1170 | if (DIR_SEPARATOR == *nxt) | 1180 | if (DIR_SEPARATOR == *nxt) |
1171 | end = nxt + 1; | 1181 | end = nxt + 1; |
1172 | nxt++; | 1182 | nxt++; |
1173 | } | 1183 | } |
1174 | if ((NULL == end) || (0 == strlen (end))) | 1184 | if ((NULL == end) || (0 == strlen(end))) |
1175 | { | 1185 | { |
1176 | GNUNET_break (0); | 1186 | GNUNET_break(0); |
1177 | return NULL; | 1187 | return NULL; |
1178 | } | 1188 | } |
1179 | GNUNET_break (6 == strlen (end)); | 1189 | GNUNET_break(6 == strlen(end)); |
1180 | return GNUNET_strdup (end); | 1190 | return GNUNET_strdup(end); |
1181 | } | 1191 | } |
1182 | 1192 | ||
1183 | 1193 | ||
@@ -1190,7 +1200,7 @@ get_serialization_short_name (const char *fullname) | |||
1190 | * @return NULL on errror | 1200 | * @return NULL on errror |
1191 | */ | 1201 | */ |
1192 | static char * | 1202 | static char * |
1193 | make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) | 1203 | make_serialization_file_name(struct GNUNET_FS_Handle *h, const char *ext) |
1194 | { | 1204 | { |
1195 | char *fn; | 1205 | char *fn; |
1196 | char *dn; | 1206 | char *dn; |
@@ -1198,20 +1208,20 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) | |||
1198 | 1208 | ||
1199 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 1209 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
1200 | return NULL; /* persistence not requested */ | 1210 | return NULL; /* persistence not requested */ |
1201 | dn = get_serialization_file_name (h, ext, ""); | 1211 | dn = get_serialization_file_name(h, ext, ""); |
1202 | if (NULL == dn) | 1212 | if (NULL == dn) |
1203 | return NULL; | 1213 | return NULL; |
1204 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn)) | 1214 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(dn)) |
1205 | { | 1215 | { |
1206 | GNUNET_free (dn); | 1216 | GNUNET_free(dn); |
1207 | return NULL; | 1217 | return NULL; |
1208 | } | 1218 | } |
1209 | fn = GNUNET_DISK_mktemp (dn); | 1219 | fn = GNUNET_DISK_mktemp(dn); |
1210 | GNUNET_free (dn); | 1220 | GNUNET_free(dn); |
1211 | if (NULL == fn) | 1221 | if (NULL == fn) |
1212 | return NULL; /* epic fail */ | 1222 | return NULL; /* epic fail */ |
1213 | ret = get_serialization_short_name (fn); | 1223 | ret = get_serialization_short_name(fn); |
1214 | GNUNET_free (fn); | 1224 | GNUNET_free(fn); |
1215 | return ret; | 1225 | return ret; |
1216 | } | 1226 | } |
1217 | 1227 | ||
@@ -1226,9 +1236,9 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) | |||
1226 | * @return NULL on errror | 1236 | * @return NULL on errror |
1227 | */ | 1237 | */ |
1228 | static char * | 1238 | static char * |
1229 | make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | 1239 | make_serialization_file_name_in_dir(struct GNUNET_FS_Handle *h, |
1230 | const char *ext, | 1240 | const char *ext, |
1231 | const char *uni) | 1241 | const char *uni) |
1232 | { | 1242 | { |
1233 | char *fn; | 1243 | char *fn; |
1234 | char *dn; | 1244 | char *dn; |
@@ -1236,20 +1246,20 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
1236 | 1246 | ||
1237 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 1247 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
1238 | return NULL; /* persistence not requested */ | 1248 | return NULL; /* persistence not requested */ |
1239 | dn = get_serialization_file_name_in_dir (h, ext, uni, ""); | 1249 | dn = get_serialization_file_name_in_dir(h, ext, uni, ""); |
1240 | if (NULL == dn) | 1250 | if (NULL == dn) |
1241 | return NULL; | 1251 | return NULL; |
1242 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn)) | 1252 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(dn)) |
1243 | { | 1253 | { |
1244 | GNUNET_free (dn); | 1254 | GNUNET_free(dn); |
1245 | return NULL; | 1255 | return NULL; |
1246 | } | 1256 | } |
1247 | fn = GNUNET_DISK_mktemp (dn); | 1257 | fn = GNUNET_DISK_mktemp(dn); |
1248 | GNUNET_free (dn); | 1258 | GNUNET_free(dn); |
1249 | if (NULL == fn) | 1259 | if (NULL == fn) |
1250 | return NULL; /* epic fail */ | 1260 | return NULL; /* epic fail */ |
1251 | ret = get_serialization_short_name (fn); | 1261 | ret = get_serialization_short_name(fn); |
1252 | GNUNET_free (fn); | 1262 | GNUNET_free(fn); |
1253 | return ret; | 1263 | return ret; |
1254 | } | 1264 | } |
1255 | 1265 | ||
@@ -1262,8 +1272,8 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
1262 | * @return #GNUNET_OK on success | 1272 | * @return #GNUNET_OK on success |
1263 | */ | 1273 | */ |
1264 | static int | 1274 | static int |
1265 | copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, | 1275 | copy_from_reader(struct GNUNET_BIO_WriteHandle *wh, |
1266 | struct GNUNET_FS_FileInformation *fi) | 1276 | struct GNUNET_FS_FileInformation *fi) |
1267 | { | 1277 | { |
1268 | char buf[32 * 1024]; | 1278 | char buf[32 * 1024]; |
1269 | uint64_t off; | 1279 | uint64_t off; |
@@ -1274,19 +1284,19 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, | |||
1274 | emsg = NULL; | 1284 | emsg = NULL; |
1275 | off = 0; | 1285 | off = 0; |
1276 | while (off < fi->data.file.file_size) | 1286 | while (off < fi->data.file.file_size) |
1277 | { | 1287 | { |
1278 | left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); | 1288 | left = GNUNET_MIN(sizeof(buf), fi->data.file.file_size - off); |
1279 | ret = | 1289 | ret = |
1280 | fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); | 1290 | fi->data.file.reader(fi->data.file.reader_cls, off, left, buf, &emsg); |
1281 | if (0 == ret) | 1291 | if (0 == ret) |
1282 | { | 1292 | { |
1283 | GNUNET_free (emsg); | 1293 | GNUNET_free(emsg); |
1284 | return GNUNET_SYSERR; | 1294 | return GNUNET_SYSERR; |
1285 | } | 1295 | } |
1286 | if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret)) | 1296 | if (GNUNET_OK != GNUNET_BIO_write(wh, buf, ret)) |
1287 | return GNUNET_SYSERR; | 1297 | return GNUNET_SYSERR; |
1288 | off += ret; | 1298 | off += ret; |
1289 | } | 1299 | } |
1290 | return GNUNET_OK; | 1300 | return GNUNET_OK; |
1291 | } | 1301 | } |
1292 | 1302 | ||
@@ -1298,7 +1308,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, | |||
1298 | * @param fi file information to sync with disk | 1308 | * @param fi file information to sync with disk |
1299 | */ | 1309 | */ |
1300 | void | 1310 | void |
1301 | GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | 1311 | GNUNET_FS_file_information_sync_(struct GNUNET_FS_FileInformation *fi) |
1302 | { | 1312 | { |
1303 | char *fn; | 1313 | char *fn; |
1304 | struct GNUNET_BIO_WriteHandle *wh; | 1314 | struct GNUNET_BIO_WriteHandle *wh; |
@@ -1309,17 +1319,17 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1309 | 1319 | ||
1310 | if (NULL == fi->serialization) | 1320 | if (NULL == fi->serialization) |
1311 | fi->serialization = | 1321 | fi->serialization = |
1312 | make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); | 1322 | make_serialization_file_name(fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); |
1313 | if (NULL == fi->serialization) | 1323 | if (NULL == fi->serialization) |
1314 | return; | 1324 | return; |
1315 | wh = | 1325 | wh = |
1316 | get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); | 1326 | get_write_handle(fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); |
1317 | if (NULL == wh) | 1327 | if (NULL == wh) |
1318 | { | 1328 | { |
1319 | GNUNET_free (fi->serialization); | 1329 | GNUNET_free(fi->serialization); |
1320 | fi->serialization = NULL; | 1330 | fi->serialization = NULL; |
1321 | return; | 1331 | return; |
1322 | } | 1332 | } |
1323 | if (GNUNET_YES == fi->is_directory) | 1333 | if (GNUNET_YES == fi->is_directory) |
1324 | b = 4; | 1334 | b = 4; |
1325 | else if (GNUNET_YES == fi->data.file.index_start_confirmed) | 1335 | else if (GNUNET_YES == fi->data.file.index_start_confirmed) |
@@ -1331,143 +1341,147 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1331 | else | 1341 | else |
1332 | b = 0; | 1342 | b = 0; |
1333 | if (NULL != fi->keywords) | 1343 | if (NULL != fi->keywords) |
1334 | ksks = GNUNET_FS_uri_to_string (fi->keywords); | 1344 | ksks = GNUNET_FS_uri_to_string(fi->keywords); |
1335 | else | 1345 | else |
1336 | ksks = NULL; | 1346 | ksks = NULL; |
1337 | if (NULL != fi->chk_uri) | 1347 | if (NULL != fi->chk_uri) |
1338 | chks = GNUNET_FS_uri_to_string (fi->chk_uri); | 1348 | chks = GNUNET_FS_uri_to_string(fi->chk_uri); |
1339 | else | 1349 | else |
1340 | chks = NULL; | 1350 | chks = NULL; |
1341 | if (NULL != fi->sks_uri) | 1351 | if (NULL != fi->sks_uri) |
1342 | skss = GNUNET_FS_uri_to_string (fi->sks_uri); | 1352 | skss = GNUNET_FS_uri_to_string(fi->sks_uri); |
1343 | else | 1353 | else |
1344 | skss = NULL; | 1354 | skss = NULL; |
1345 | if ((GNUNET_OK != GNUNET_BIO_write (wh, &b, sizeof (b))) || | 1355 | if ((GNUNET_OK != GNUNET_BIO_write(wh, &b, sizeof(b))) || |
1346 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, fi->meta)) || | 1356 | (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, fi->meta)) || |
1347 | (GNUNET_OK != GNUNET_BIO_write_string (wh, ksks)) || | 1357 | (GNUNET_OK != GNUNET_BIO_write_string(wh, ksks)) || |
1348 | (GNUNET_OK != GNUNET_BIO_write_string (wh, chks)) || | 1358 | (GNUNET_OK != GNUNET_BIO_write_string(wh, chks)) || |
1349 | (GNUNET_OK != GNUNET_BIO_write_string (wh, skss)) || | 1359 | (GNUNET_OK != GNUNET_BIO_write_string(wh, skss)) || |
1350 | (GNUNET_OK != write_start_time (wh, fi->start_time)) || | 1360 | (GNUNET_OK != write_start_time(wh, fi->start_time)) || |
1351 | (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->emsg)) || | 1361 | (GNUNET_OK != GNUNET_BIO_write_string(wh, fi->emsg)) || |
1352 | (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->filename)) || | 1362 | (GNUNET_OK != GNUNET_BIO_write_string(wh, fi->filename)) || |
1353 | (GNUNET_OK != | 1363 | (GNUNET_OK != |
1354 | GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value_us)) || | 1364 | GNUNET_BIO_write_int64(wh, fi->bo.expiration_time.abs_value_us)) || |
1355 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) || | 1365 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->bo.anonymity_level)) || |
1356 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) || | 1366 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->bo.content_priority)) || |
1357 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level))) | 1367 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->bo.replication_level))) |
1358 | { | 1368 | { |
1359 | GNUNET_break (0); | 1369 | GNUNET_break(0); |
1360 | goto cleanup; | 1370 | goto cleanup; |
1361 | } | 1371 | } |
1362 | GNUNET_free_non_null (chks); | 1372 | GNUNET_free_non_null(chks); |
1363 | chks = NULL; | 1373 | chks = NULL; |
1364 | GNUNET_free_non_null (ksks); | 1374 | GNUNET_free_non_null(ksks); |
1365 | ksks = NULL; | 1375 | ksks = NULL; |
1366 | GNUNET_free_non_null (skss); | 1376 | GNUNET_free_non_null(skss); |
1367 | skss = NULL; | 1377 | skss = NULL; |
1368 | 1378 | ||
1369 | switch (b) | 1379 | switch (b) |
1370 | { | ||
1371 | case 0: /* file-insert */ | ||
1372 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) | ||
1373 | { | ||
1374 | GNUNET_break (0); | ||
1375 | goto cleanup; | ||
1376 | } | ||
1377 | if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename)) | ||
1378 | if (GNUNET_OK != copy_from_reader (wh, fi)) | ||
1379 | { | ||
1380 | GNUNET_break (0); | ||
1381 | goto cleanup; | ||
1382 | } | ||
1383 | break; | ||
1384 | case 1: /* file-index, no hash */ | ||
1385 | if (NULL == fi->filename) | ||
1386 | { | 1380 | { |
1387 | GNUNET_break (0); | 1381 | case 0: /* file-insert */ |
1388 | goto cleanup; | 1382 | if (GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size)) |
1389 | } | 1383 | { |
1390 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) | 1384 | GNUNET_break(0); |
1391 | { | 1385 | goto cleanup; |
1392 | GNUNET_break (0); | 1386 | } |
1387 | if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename)) | ||
1388 | if (GNUNET_OK != copy_from_reader(wh, fi)) | ||
1389 | { | ||
1390 | GNUNET_break(0); | ||
1391 | goto cleanup; | ||
1392 | } | ||
1393 | break; | ||
1394 | |||
1395 | case 1: /* file-index, no hash */ | ||
1396 | if (NULL == fi->filename) | ||
1397 | { | ||
1398 | GNUNET_break(0); | ||
1399 | goto cleanup; | ||
1400 | } | ||
1401 | if (GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size)) | ||
1402 | { | ||
1403 | GNUNET_break(0); | ||
1404 | goto cleanup; | ||
1405 | } | ||
1406 | break; | ||
1407 | |||
1408 | case 2: /* file-index-with-hash */ | ||
1409 | case 3: /* file-index-with-hash-confirmed */ | ||
1410 | if (NULL == fi->filename) | ||
1411 | { | ||
1412 | GNUNET_break(0); | ||
1413 | goto cleanup; | ||
1414 | } | ||
1415 | if ((GNUNET_OK != GNUNET_BIO_write_int64(wh, fi->data.file.file_size)) || | ||
1416 | (GNUNET_OK != GNUNET_BIO_write(wh, | ||
1417 | &fi->data.file.file_id, | ||
1418 | sizeof(struct GNUNET_HashCode)))) | ||
1419 | { | ||
1420 | GNUNET_break(0); | ||
1421 | goto cleanup; | ||
1422 | } | ||
1423 | break; | ||
1424 | |||
1425 | case 4: /* directory */ | ||
1426 | if ((NULL != fi->data.dir.entries) && | ||
1427 | (NULL == fi->data.dir.entries->serialization)) | ||
1428 | GNUNET_FS_file_information_sync_(fi->data.dir.entries); | ||
1429 | if ((GNUNET_OK != GNUNET_BIO_write_int32(wh, fi->data.dir.dir_size)) || | ||
1430 | (GNUNET_OK != | ||
1431 | GNUNET_BIO_write_int64(wh, fi->data.dir.contents_completed)) || | ||
1432 | (GNUNET_OK != | ||
1433 | GNUNET_BIO_write_int64(wh, fi->data.dir.contents_size)) || | ||
1434 | (GNUNET_OK != GNUNET_BIO_write(wh, | ||
1435 | fi->data.dir.dir_data, | ||
1436 | (uint32_t)fi->data.dir.dir_size)) || | ||
1437 | (GNUNET_OK != | ||
1438 | GNUNET_BIO_write_string(wh, | ||
1439 | (fi->data.dir.entries == NULL) | ||
1440 | ? NULL | ||
1441 | : fi->data.dir.entries->serialization))) | ||
1442 | { | ||
1443 | GNUNET_break(0); | ||
1444 | goto cleanup; | ||
1445 | } | ||
1446 | break; | ||
1447 | |||
1448 | default: | ||
1449 | GNUNET_assert(0); | ||
1393 | goto cleanup; | 1450 | goto cleanup; |
1394 | } | 1451 | } |
1395 | break; | 1452 | if ((NULL != fi->next) && (NULL == fi->next->serialization)) |
1396 | case 2: /* file-index-with-hash */ | 1453 | GNUNET_FS_file_information_sync_(fi->next); |
1397 | case 3: /* file-index-with-hash-confirmed */ | 1454 | if (GNUNET_OK != GNUNET_BIO_write_string(wh, |
1398 | if (NULL == fi->filename) | 1455 | (fi->next != NULL) |
1456 | ? fi->next->serialization | ||
1457 | : NULL)) | ||
1399 | { | 1458 | { |
1400 | GNUNET_break (0); | 1459 | GNUNET_break(0); |
1401 | goto cleanup; | 1460 | goto cleanup; |
1402 | } | 1461 | } |
1403 | if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || | 1462 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
1404 | (GNUNET_OK != GNUNET_BIO_write (wh, | ||
1405 | &fi->data.file.file_id, | ||
1406 | sizeof (struct GNUNET_HashCode)))) | ||
1407 | { | 1463 | { |
1408 | GNUNET_break (0); | 1464 | wh = NULL; |
1465 | GNUNET_break(0); | ||
1409 | goto cleanup; | 1466 | goto cleanup; |
1410 | } | 1467 | } |
1411 | break; | ||
1412 | case 4: /* directory */ | ||
1413 | if ((NULL != fi->data.dir.entries) && | ||
1414 | (NULL == fi->data.dir.entries->serialization)) | ||
1415 | GNUNET_FS_file_information_sync_ (fi->data.dir.entries); | ||
1416 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || | ||
1417 | (GNUNET_OK != | ||
1418 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || | ||
1419 | (GNUNET_OK != | ||
1420 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || | ||
1421 | (GNUNET_OK != GNUNET_BIO_write (wh, | ||
1422 | fi->data.dir.dir_data, | ||
1423 | (uint32_t) fi->data.dir.dir_size)) || | ||
1424 | (GNUNET_OK != | ||
1425 | GNUNET_BIO_write_string (wh, | ||
1426 | (fi->data.dir.entries == NULL) | ||
1427 | ? NULL | ||
1428 | : fi->data.dir.entries->serialization))) | ||
1429 | { | ||
1430 | GNUNET_break (0); | ||
1431 | goto cleanup; | ||
1432 | } | ||
1433 | break; | ||
1434 | default: | ||
1435 | GNUNET_assert (0); | ||
1436 | goto cleanup; | ||
1437 | } | ||
1438 | if ((NULL != fi->next) && (NULL == fi->next->serialization)) | ||
1439 | GNUNET_FS_file_information_sync_ (fi->next); | ||
1440 | if (GNUNET_OK != GNUNET_BIO_write_string (wh, | ||
1441 | (fi->next != NULL) | ||
1442 | ? fi->next->serialization | ||
1443 | : NULL)) | ||
1444 | { | ||
1445 | GNUNET_break (0); | ||
1446 | goto cleanup; | ||
1447 | } | ||
1448 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | ||
1449 | { | ||
1450 | wh = NULL; | ||
1451 | GNUNET_break (0); | ||
1452 | goto cleanup; | ||
1453 | } | ||
1454 | return; /* done! */ | 1468 | return; /* done! */ |
1455 | cleanup: | 1469 | cleanup: |
1456 | if (NULL != wh) | 1470 | if (NULL != wh) |
1457 | (void) GNUNET_BIO_write_close (wh); | 1471 | (void)GNUNET_BIO_write_close(wh); |
1458 | GNUNET_free_non_null (chks); | 1472 | GNUNET_free_non_null(chks); |
1459 | GNUNET_free_non_null (ksks); | 1473 | GNUNET_free_non_null(ksks); |
1460 | GNUNET_free_non_null (skss); | 1474 | GNUNET_free_non_null(skss); |
1461 | fn = get_serialization_file_name (fi->h, | 1475 | fn = get_serialization_file_name(fi->h, |
1462 | GNUNET_FS_SYNC_PATH_FILE_INFO, | 1476 | GNUNET_FS_SYNC_PATH_FILE_INFO, |
1463 | fi->serialization); | 1477 | fi->serialization); |
1464 | if (NULL != fn) | 1478 | if (NULL != fn) |
1465 | { | 1479 | { |
1466 | if (0 != unlink (fn)) | 1480 | if (0 != unlink(fn)) |
1467 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 1481 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
1468 | GNUNET_free (fn); | 1482 | GNUNET_free(fn); |
1469 | } | 1483 | } |
1470 | GNUNET_free (fi->serialization); | 1484 | GNUNET_free(fi->serialization); |
1471 | fi->serialization = NULL; | 1485 | fi->serialization = NULL; |
1472 | } | 1486 | } |
1473 | 1487 | ||
@@ -1481,19 +1495,19 @@ cleanup: | |||
1481 | * @return NULL if srch was not found in this subtree | 1495 | * @return NULL if srch was not found in this subtree |
1482 | */ | 1496 | */ |
1483 | static struct GNUNET_FS_FileInformation * | 1497 | static struct GNUNET_FS_FileInformation * |
1484 | find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch) | 1498 | find_file_position(struct GNUNET_FS_FileInformation *pos, const char *srch) |
1485 | { | 1499 | { |
1486 | struct GNUNET_FS_FileInformation *r; | 1500 | struct GNUNET_FS_FileInformation *r; |
1487 | 1501 | ||
1488 | while (NULL != pos) | 1502 | while (NULL != pos) |
1489 | { | 1503 | { |
1490 | if (0 == strcmp (srch, pos->serialization)) | 1504 | if (0 == strcmp(srch, pos->serialization)) |
1491 | return pos; | 1505 | return pos; |
1492 | if ((GNUNET_YES == pos->is_directory) && | 1506 | if ((GNUNET_YES == pos->is_directory) && |
1493 | (NULL != (r = find_file_position (pos->data.dir.entries, srch)))) | 1507 | (NULL != (r = find_file_position(pos->data.dir.entries, srch)))) |
1494 | return r; | 1508 | return r; |
1495 | pos = pos->next; | 1509 | pos = pos->next; |
1496 | } | 1510 | } |
1497 | return NULL; | 1511 | return NULL; |
1498 | } | 1512 | } |
1499 | 1513 | ||
@@ -1513,33 +1527,33 @@ find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch) | |||
1513 | * @return #GNUNET_OK to continue (always) | 1527 | * @return #GNUNET_OK to continue (always) |
1514 | */ | 1528 | */ |
1515 | static int | 1529 | static int |
1516 | fip_signal_resume (void *cls, | 1530 | fip_signal_resume(void *cls, |
1517 | struct GNUNET_FS_FileInformation *fi, | 1531 | struct GNUNET_FS_FileInformation *fi, |
1518 | uint64_t length, | 1532 | uint64_t length, |
1519 | struct GNUNET_CONTAINER_MetaData *meta, | 1533 | struct GNUNET_CONTAINER_MetaData *meta, |
1520 | struct GNUNET_FS_Uri **uri, | 1534 | struct GNUNET_FS_Uri **uri, |
1521 | struct GNUNET_FS_BlockOptions *bo, | 1535 | struct GNUNET_FS_BlockOptions *bo, |
1522 | int *do_index, | 1536 | int *do_index, |
1523 | void **client_info) | 1537 | void **client_info) |
1524 | { | 1538 | { |
1525 | struct GNUNET_FS_PublishContext *pc = cls; | 1539 | struct GNUNET_FS_PublishContext *pc = cls; |
1526 | struct GNUNET_FS_ProgressInfo pi; | 1540 | struct GNUNET_FS_ProgressInfo pi; |
1527 | 1541 | ||
1528 | if (GNUNET_YES == pc->skip_next_fi_callback) | 1542 | if (GNUNET_YES == pc->skip_next_fi_callback) |
1529 | { | 1543 | { |
1530 | pc->skip_next_fi_callback = GNUNET_NO; | 1544 | pc->skip_next_fi_callback = GNUNET_NO; |
1531 | return GNUNET_OK; | 1545 | return GNUNET_OK; |
1532 | } | 1546 | } |
1533 | pi.status = GNUNET_FS_STATUS_PUBLISH_RESUME; | 1547 | pi.status = GNUNET_FS_STATUS_PUBLISH_RESUME; |
1534 | pi.value.publish.specifics.resume.message = fi->emsg; | 1548 | pi.value.publish.specifics.resume.message = fi->emsg; |
1535 | pi.value.publish.specifics.resume.chk_uri = fi->chk_uri; | 1549 | pi.value.publish.specifics.resume.chk_uri = fi->chk_uri; |
1536 | *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0); | 1550 | *client_info = GNUNET_FS_publish_make_status_(&pi, pc, fi, 0); |
1537 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) | 1551 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) |
1538 | { | 1552 | { |
1539 | /* process entries in directory */ | 1553 | /* process entries in directory */ |
1540 | pc->skip_next_fi_callback = GNUNET_YES; | 1554 | pc->skip_next_fi_callback = GNUNET_YES; |
1541 | GNUNET_FS_file_information_inspect (fi, &fip_signal_resume, pc); | 1555 | GNUNET_FS_file_information_inspect(fi, &fip_signal_resume, pc); |
1542 | } | 1556 | } |
1543 | return GNUNET_OK; | 1557 | return GNUNET_OK; |
1544 | } | 1558 | } |
1545 | 1559 | ||
@@ -1553,7 +1567,7 @@ fip_signal_resume (void *cls, | |||
1553 | * @return #GNUNET_OK (continue to iterate) | 1567 | * @return #GNUNET_OK (continue to iterate) |
1554 | */ | 1568 | */ |
1555 | static int | 1569 | static int |
1556 | deserialize_publish_file (void *cls, const char *filename) | 1570 | deserialize_publish_file(void *cls, const char *filename) |
1557 | { | 1571 | { |
1558 | struct GNUNET_FS_Handle *h = cls; | 1572 | struct GNUNET_FS_Handle *h = cls; |
1559 | struct GNUNET_BIO_ReadHandle *rh; | 1573 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -1566,115 +1580,115 @@ deserialize_publish_file (void *cls, const char *filename) | |||
1566 | char *fi_pos; | 1580 | char *fi_pos; |
1567 | char *emsg; | 1581 | char *emsg; |
1568 | 1582 | ||
1569 | pc = GNUNET_new (struct GNUNET_FS_PublishContext); | 1583 | pc = GNUNET_new(struct GNUNET_FS_PublishContext); |
1570 | pc->h = h; | 1584 | pc->h = h; |
1571 | pc->serialization = get_serialization_short_name (filename); | 1585 | pc->serialization = get_serialization_short_name(filename); |
1572 | fi_root = NULL; | 1586 | fi_root = NULL; |
1573 | fi_pos = NULL; | 1587 | fi_pos = NULL; |
1574 | rh = GNUNET_BIO_read_open (filename); | 1588 | rh = GNUNET_BIO_read_open(filename); |
1575 | if (NULL == rh) | 1589 | if (NULL == rh) |
1576 | { | 1590 | { |
1577 | GNUNET_break (0); | 1591 | GNUNET_break(0); |
1578 | goto cleanup; | 1592 | goto cleanup; |
1579 | } | 1593 | } |
1580 | if ((GNUNET_OK != | 1594 | if ((GNUNET_OK != |
1581 | GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || | 1595 | GNUNET_BIO_read_string(rh, "publish-nid", &pc->nid, 1024)) || |
1582 | (GNUNET_OK != | 1596 | (GNUNET_OK != |
1583 | GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || | 1597 | GNUNET_BIO_read_string(rh, "publish-nuid", &pc->nuid, 1024)) || |
1584 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 1598 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) || |
1585 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || | 1599 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &all_done)) || |
1586 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || | 1600 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &have_ns)) || |
1587 | (GNUNET_OK != | 1601 | (GNUNET_OK != |
1588 | GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || | 1602 | GNUNET_BIO_read_string(rh, "publish-firoot", &fi_root, 128)) || |
1589 | (GNUNET_OK != | 1603 | (GNUNET_OK != |
1590 | GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || | 1604 | GNUNET_BIO_read_string(rh, "publish-fipos", &fi_pos, 128)) || |
1591 | ((GNUNET_YES == have_ns) && | 1605 | ((GNUNET_YES == have_ns) && |
1592 | (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns))))) | 1606 | (GNUNET_OK != GNUNET_BIO_read(rh, "publish-ns", &ns, sizeof(ns))))) |
1593 | { | 1607 | { |
1594 | GNUNET_break (0); | 1608 | GNUNET_break(0); |
1595 | goto cleanup; | 1609 | goto cleanup; |
1596 | } | 1610 | } |
1597 | pc->options = options; | 1611 | pc->options = options; |
1598 | pc->all_done = all_done; | 1612 | pc->all_done = all_done; |
1599 | if (NULL == fi_root) | 1613 | if (NULL == fi_root) |
1600 | { | 1614 | { |
1601 | GNUNET_break (0); | 1615 | GNUNET_break(0); |
1602 | goto cleanup; | 1616 | goto cleanup; |
1603 | } | 1617 | } |
1604 | pc->fi = deserialize_file_information (h, fi_root); | 1618 | pc->fi = deserialize_file_information(h, fi_root); |
1605 | if (NULL == pc->fi) | 1619 | if (NULL == pc->fi) |
1606 | { | 1620 | { |
1607 | GNUNET_break (0); | 1621 | GNUNET_break(0); |
1608 | goto cleanup; | 1622 | goto cleanup; |
1609 | } | 1623 | } |
1610 | if (GNUNET_YES == have_ns) | 1624 | if (GNUNET_YES == have_ns) |
1611 | { | 1625 | { |
1612 | pc->ns = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 1626 | pc->ns = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); |
1613 | *pc->ns = ns; | 1627 | *pc->ns = ns; |
1614 | } | 1628 | } |
1615 | if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) && | 1629 | if ((0 == (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) && |
1616 | (GNUNET_YES != pc->all_done)) | 1630 | (GNUNET_YES != pc->all_done)) |
1617 | { | 1631 | { |
1618 | pc->dsh = GNUNET_DATASTORE_connect (h->cfg); | 1632 | pc->dsh = GNUNET_DATASTORE_connect(h->cfg); |
1619 | if (NULL == pc->dsh) | 1633 | if (NULL == pc->dsh) |
1620 | goto cleanup; | 1634 | goto cleanup; |
1621 | } | 1635 | } |
1622 | if (NULL != fi_pos) | 1636 | if (NULL != fi_pos) |
1623 | { | 1637 | { |
1624 | pc->fi_pos = find_file_position (pc->fi, fi_pos); | 1638 | pc->fi_pos = find_file_position(pc->fi, fi_pos); |
1625 | GNUNET_free (fi_pos); | 1639 | GNUNET_free(fi_pos); |
1626 | fi_pos = NULL; | 1640 | fi_pos = NULL; |
1627 | if (NULL == pc->fi_pos) | 1641 | if (NULL == pc->fi_pos) |
1628 | { | 1642 | { |
1629 | /* failed to find position for resuming, outch! Will start from root! */ | 1643 | /* failed to find position for resuming, outch! Will start from root! */ |
1630 | GNUNET_break (0); | 1644 | GNUNET_break(0); |
1631 | if (GNUNET_YES != pc->all_done) | 1645 | if (GNUNET_YES != pc->all_done) |
1632 | pc->fi_pos = pc->fi; | 1646 | pc->fi_pos = pc->fi; |
1633 | } | 1647 | } |
1634 | } | 1648 | } |
1635 | GNUNET_free (fi_root); | 1649 | GNUNET_free(fi_root); |
1636 | fi_root = NULL; | 1650 | fi_root = NULL; |
1637 | /* generate RESUME event(s) */ | 1651 | /* generate RESUME event(s) */ |
1638 | GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_resume, pc); | 1652 | GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_resume, pc); |
1639 | 1653 | ||
1640 | /* re-start publishing (if needed)... */ | 1654 | /* re-start publishing (if needed)... */ |
1641 | if (GNUNET_YES != pc->all_done) | 1655 | if (GNUNET_YES != pc->all_done) |
1642 | { | 1656 | { |
1643 | GNUNET_assert (NULL == pc->upload_task); | 1657 | GNUNET_assert(NULL == pc->upload_task); |
1644 | pc->upload_task = | 1658 | pc->upload_task = |
1645 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 1659 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
1646 | &GNUNET_FS_publish_main_, | 1660 | &GNUNET_FS_publish_main_, |
1647 | pc); | 1661 | pc); |
1648 | } | 1662 | } |
1649 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 1663 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
1650 | { | 1664 | { |
1651 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1665 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1652 | _ ("Failure while resuming publishing operation `%s': %s\n"), | 1666 | _("Failure while resuming publishing operation `%s': %s\n"), |
1653 | filename, | 1667 | filename, |
1654 | emsg); | 1668 | emsg); |
1655 | GNUNET_free (emsg); | 1669 | GNUNET_free(emsg); |
1656 | } | 1670 | } |
1657 | pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc); | 1671 | pc->top = GNUNET_FS_make_top(h, &GNUNET_FS_publish_signal_suspend_, pc); |
1658 | return GNUNET_OK; | 1672 | return GNUNET_OK; |
1659 | cleanup: | 1673 | cleanup: |
1660 | GNUNET_free_non_null (pc->nid); | 1674 | GNUNET_free_non_null(pc->nid); |
1661 | GNUNET_free_non_null (pc->nuid); | 1675 | GNUNET_free_non_null(pc->nuid); |
1662 | GNUNET_free_non_null (fi_root); | 1676 | GNUNET_free_non_null(fi_root); |
1663 | GNUNET_free_non_null (fi_pos); | 1677 | GNUNET_free_non_null(fi_pos); |
1664 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) | 1678 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))) |
1665 | { | 1679 | { |
1666 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1680 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1667 | _ ("Failed to resume publishing operation `%s': %s\n"), | 1681 | _("Failed to resume publishing operation `%s': %s\n"), |
1668 | filename, | 1682 | filename, |
1669 | emsg); | 1683 | emsg); |
1670 | GNUNET_free (emsg); | 1684 | GNUNET_free(emsg); |
1671 | } | 1685 | } |
1672 | if (NULL != pc->fi) | 1686 | if (NULL != pc->fi) |
1673 | GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); | 1687 | GNUNET_FS_file_information_destroy(pc->fi, NULL, NULL); |
1674 | if (0 != unlink (filename)) | 1688 | if (0 != unlink(filename)) |
1675 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 1689 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
1676 | GNUNET_free (pc->serialization); | 1690 | GNUNET_free(pc->serialization); |
1677 | GNUNET_free (pc); | 1691 | GNUNET_free(pc); |
1678 | return GNUNET_OK; | 1692 | return GNUNET_OK; |
1679 | } | 1693 | } |
1680 | 1694 | ||
@@ -1688,65 +1702,65 @@ cleanup: | |||
1688 | * @param pc the struct to sync | 1702 | * @param pc the struct to sync |
1689 | */ | 1703 | */ |
1690 | void | 1704 | void |
1691 | GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | 1705 | GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc) |
1692 | { | 1706 | { |
1693 | struct GNUNET_BIO_WriteHandle *wh; | 1707 | struct GNUNET_BIO_WriteHandle *wh; |
1694 | int32_t have_ns; | 1708 | int32_t have_ns; |
1695 | 1709 | ||
1696 | if (NULL == pc->serialization) | 1710 | if (NULL == pc->serialization) |
1697 | pc->serialization = | 1711 | pc->serialization = |
1698 | make_serialization_file_name (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); | 1712 | make_serialization_file_name(pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); |
1699 | if (NULL == pc->serialization) | 1713 | if (NULL == pc->serialization) |
1700 | return; | 1714 | return; |
1701 | if (NULL == pc->fi) | 1715 | if (NULL == pc->fi) |
1702 | return; | 1716 | return; |
1703 | if (NULL == pc->fi->serialization) | 1717 | if (NULL == pc->fi->serialization) |
1704 | { | 1718 | { |
1705 | GNUNET_break (0); | 1719 | GNUNET_break(0); |
1706 | return; | 1720 | return; |
1707 | } | 1721 | } |
1708 | wh = get_write_handle (pc->h, | 1722 | wh = get_write_handle(pc->h, |
1709 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1723 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
1710 | pc->serialization); | 1724 | pc->serialization); |
1711 | if (NULL == wh) | 1725 | if (NULL == wh) |
1712 | { | 1726 | { |
1713 | GNUNET_break (0); | 1727 | GNUNET_break(0); |
1714 | goto cleanup; | 1728 | goto cleanup; |
1715 | } | 1729 | } |
1716 | have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO; | 1730 | have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO; |
1717 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nid)) || | 1731 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, pc->nid)) || |
1718 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nuid)) || | 1732 | (GNUNET_OK != GNUNET_BIO_write_string(wh, pc->nuid)) || |
1719 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->options)) || | 1733 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, pc->options)) || |
1720 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || | 1734 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, pc->all_done)) || |
1721 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || | 1735 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, have_ns)) || |
1722 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || | 1736 | (GNUNET_OK != GNUNET_BIO_write_string(wh, pc->fi->serialization)) || |
1723 | (GNUNET_OK != GNUNET_BIO_write_string (wh, | 1737 | (GNUNET_OK != GNUNET_BIO_write_string(wh, |
1724 | (NULL == pc->fi_pos) | 1738 | (NULL == pc->fi_pos) |
1725 | ? NULL | 1739 | ? NULL |
1726 | : pc->fi_pos->serialization)) || | 1740 | : pc->fi_pos->serialization)) || |
1727 | ((NULL != pc->ns) && | 1741 | ((NULL != pc->ns) && |
1728 | (GNUNET_OK != | 1742 | (GNUNET_OK != |
1729 | GNUNET_BIO_write (wh, | 1743 | GNUNET_BIO_write(wh, |
1730 | pc->ns, | 1744 | pc->ns, |
1731 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))) | 1745 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey))))) |
1732 | { | 1746 | { |
1733 | GNUNET_break (0); | 1747 | GNUNET_break(0); |
1734 | goto cleanup; | 1748 | goto cleanup; |
1735 | } | 1749 | } |
1736 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1750 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
1737 | { | 1751 | { |
1738 | wh = NULL; | 1752 | wh = NULL; |
1739 | GNUNET_break (0); | 1753 | GNUNET_break(0); |
1740 | goto cleanup; | 1754 | goto cleanup; |
1741 | } | 1755 | } |
1742 | return; | 1756 | return; |
1743 | cleanup: | 1757 | cleanup: |
1744 | if (NULL != wh) | 1758 | if (NULL != wh) |
1745 | (void) GNUNET_BIO_write_close (wh); | 1759 | (void)GNUNET_BIO_write_close(wh); |
1746 | GNUNET_FS_remove_sync_file_ (pc->h, | 1760 | GNUNET_FS_remove_sync_file_(pc->h, |
1747 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1761 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
1748 | pc->serialization); | 1762 | pc->serialization); |
1749 | GNUNET_free (pc->serialization); | 1763 | GNUNET_free(pc->serialization); |
1750 | pc->serialization = NULL; | 1764 | pc->serialization = NULL; |
1751 | } | 1765 | } |
1752 | 1766 | ||
@@ -1760,60 +1774,60 @@ cleanup: | |||
1760 | * @param uc the struct to sync | 1774 | * @param uc the struct to sync |
1761 | */ | 1775 | */ |
1762 | void | 1776 | void |
1763 | GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | 1777 | GNUNET_FS_unindex_sync_(struct GNUNET_FS_UnindexContext *uc) |
1764 | { | 1778 | { |
1765 | struct GNUNET_BIO_WriteHandle *wh; | 1779 | struct GNUNET_BIO_WriteHandle *wh; |
1766 | char *uris; | 1780 | char *uris; |
1767 | 1781 | ||
1768 | if (NULL == uc->serialization) | 1782 | if (NULL == uc->serialization) |
1769 | uc->serialization = | 1783 | uc->serialization = |
1770 | make_serialization_file_name (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); | 1784 | make_serialization_file_name(uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); |
1771 | if (NULL == uc->serialization) | 1785 | if (NULL == uc->serialization) |
1772 | return; | 1786 | return; |
1773 | wh = get_write_handle (uc->h, | 1787 | wh = get_write_handle(uc->h, |
1774 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 1788 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
1775 | uc->serialization); | 1789 | uc->serialization); |
1776 | if (NULL == wh) | 1790 | if (NULL == wh) |
1777 | { | 1791 | { |
1778 | GNUNET_break (0); | 1792 | GNUNET_break(0); |
1779 | goto cleanup; | 1793 | goto cleanup; |
1780 | } | 1794 | } |
1781 | if (NULL != uc->ksk_uri) | 1795 | if (NULL != uc->ksk_uri) |
1782 | uris = GNUNET_FS_uri_to_string (uc->ksk_uri); | 1796 | uris = GNUNET_FS_uri_to_string(uc->ksk_uri); |
1783 | else | 1797 | else |
1784 | uris = NULL; | 1798 | uris = NULL; |
1785 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uc->filename)) || | 1799 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uc->filename)) || |
1786 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, uc->file_size)) || | 1800 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, uc->file_size)) || |
1787 | (GNUNET_OK != write_start_time (wh, uc->start_time)) || | 1801 | (GNUNET_OK != write_start_time(wh, uc->start_time)) || |
1788 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) || | 1802 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)uc->state)) || |
1789 | (GNUNET_OK != | 1803 | (GNUNET_OK != |
1790 | GNUNET_BIO_write (wh, &uc->chk, sizeof (struct ContentHashKey))) || | 1804 | GNUNET_BIO_write(wh, &uc->chk, sizeof(struct ContentHashKey))) || |
1791 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 1805 | (GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || |
1792 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || | 1806 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)uc->ksk_offset)) || |
1793 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && | 1807 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && |
1794 | (GNUNET_OK != GNUNET_BIO_write (wh, | 1808 | (GNUNET_OK != GNUNET_BIO_write(wh, |
1795 | &uc->file_id, | 1809 | &uc->file_id, |
1796 | sizeof (struct GNUNET_HashCode)))) || | 1810 | sizeof(struct GNUNET_HashCode)))) || |
1797 | ((uc->state == UNINDEX_STATE_ERROR) && | 1811 | ((uc->state == UNINDEX_STATE_ERROR) && |
1798 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) | 1812 | (GNUNET_OK != GNUNET_BIO_write_string(wh, uc->emsg)))) |
1799 | { | 1813 | { |
1800 | GNUNET_break (0); | 1814 | GNUNET_break(0); |
1801 | goto cleanup; | 1815 | goto cleanup; |
1802 | } | 1816 | } |
1803 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1817 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
1804 | { | 1818 | { |
1805 | wh = NULL; | 1819 | wh = NULL; |
1806 | GNUNET_break (0); | 1820 | GNUNET_break(0); |
1807 | goto cleanup; | 1821 | goto cleanup; |
1808 | } | 1822 | } |
1809 | return; | 1823 | return; |
1810 | cleanup: | 1824 | cleanup: |
1811 | if (NULL != wh) | 1825 | if (NULL != wh) |
1812 | (void) GNUNET_BIO_write_close (wh); | 1826 | (void)GNUNET_BIO_write_close(wh); |
1813 | GNUNET_FS_remove_sync_file_ (uc->h, | 1827 | GNUNET_FS_remove_sync_file_(uc->h, |
1814 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 1828 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
1815 | uc->serialization); | 1829 | uc->serialization); |
1816 | GNUNET_free (uc->serialization); | 1830 | GNUNET_free(uc->serialization); |
1817 | uc->serialization = NULL; | 1831 | uc->serialization = NULL; |
1818 | } | 1832 | } |
1819 | 1833 | ||
@@ -1826,22 +1840,22 @@ cleanup: | |||
1826 | * @return #GNUNET_YES on success, #GNUNET_NO on error | 1840 | * @return #GNUNET_YES on success, #GNUNET_NO on error |
1827 | */ | 1841 | */ |
1828 | static int | 1842 | static int |
1829 | write_download_request (struct GNUNET_BIO_WriteHandle *wh, | 1843 | write_download_request(struct GNUNET_BIO_WriteHandle *wh, |
1830 | struct DownloadRequest *dr) | 1844 | struct DownloadRequest *dr) |
1831 | { | 1845 | { |
1832 | unsigned int i; | 1846 | unsigned int i; |
1833 | 1847 | ||
1834 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->state)) || | 1848 | if ((GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->state)) || |
1835 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dr->offset)) || | 1849 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, dr->offset)) || |
1836 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->num_children)) || | 1850 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->num_children)) || |
1837 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth))) | 1851 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, dr->depth))) |
1838 | return GNUNET_NO; | 1852 | return GNUNET_NO; |
1839 | if ((BRS_CHK_SET == dr->state) && | 1853 | if ((BRS_CHK_SET == dr->state) && |
1840 | (GNUNET_OK != | 1854 | (GNUNET_OK != |
1841 | GNUNET_BIO_write (wh, &dr->chk, sizeof (struct ContentHashKey)))) | 1855 | GNUNET_BIO_write(wh, &dr->chk, sizeof(struct ContentHashKey)))) |
1842 | return GNUNET_NO; | 1856 | return GNUNET_NO; |
1843 | for (i = 0; i < dr->num_children; i++) | 1857 | for (i = 0; i < dr->num_children; i++) |
1844 | if (GNUNET_NO == write_download_request (wh, dr->children[i])) | 1858 | if (GNUNET_NO == write_download_request(wh, dr->children[i])) |
1845 | return GNUNET_NO; | 1859 | return GNUNET_NO; |
1846 | return GNUNET_YES; | 1860 | return GNUNET_YES; |
1847 | } | 1861 | } |
@@ -1854,56 +1868,59 @@ write_download_request (struct GNUNET_BIO_WriteHandle *wh, | |||
1854 | * @return value the download request read from disk, NULL on error | 1868 | * @return value the download request read from disk, NULL on error |
1855 | */ | 1869 | */ |
1856 | static struct DownloadRequest * | 1870 | static struct DownloadRequest * |
1857 | read_download_request (struct GNUNET_BIO_ReadHandle *rh) | 1871 | read_download_request(struct GNUNET_BIO_ReadHandle *rh) |
1858 | { | 1872 | { |
1859 | struct DownloadRequest *dr; | 1873 | struct DownloadRequest *dr; |
1860 | unsigned int i; | 1874 | unsigned int i; |
1861 | 1875 | ||
1862 | dr = GNUNET_new (struct DownloadRequest); | 1876 | dr = GNUNET_new(struct DownloadRequest); |
1863 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->state)) || | 1877 | if ((GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->state)) || |
1864 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dr->offset)) || | 1878 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dr->offset)) || |
1865 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || | 1879 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->num_children)) || |
1866 | (dr->num_children > CHK_PER_INODE) || | 1880 | (dr->num_children > CHK_PER_INODE) || |
1867 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || | 1881 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dr->depth)) || |
1868 | ((0 == dr->depth) && (dr->num_children > 0)) || | 1882 | ((0 == dr->depth) && (dr->num_children > 0)) || |
1869 | ((dr->depth > 0) && (0 == dr->num_children))) | 1883 | ((dr->depth > 0) && (0 == dr->num_children))) |
1870 | { | 1884 | { |
1871 | GNUNET_break (0); | 1885 | GNUNET_break(0); |
1872 | dr->num_children = 0; | 1886 | dr->num_children = 0; |
1873 | goto cleanup; | 1887 | goto cleanup; |
1874 | } | 1888 | } |
1875 | if (dr->num_children > 0) | 1889 | if (dr->num_children > 0) |
1876 | dr->children = | 1890 | dr->children = |
1877 | GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); | 1891 | GNUNET_malloc(dr->num_children * sizeof(struct DownloadRequest *)); |
1878 | switch (dr->state) | 1892 | switch (dr->state) |
1879 | { | 1893 | { |
1880 | case BRS_INIT: | 1894 | case BRS_INIT: |
1881 | case BRS_RECONSTRUCT_DOWN: | 1895 | case BRS_RECONSTRUCT_DOWN: |
1882 | case BRS_RECONSTRUCT_META_UP: | 1896 | case BRS_RECONSTRUCT_META_UP: |
1883 | case BRS_RECONSTRUCT_UP: | 1897 | case BRS_RECONSTRUCT_UP: |
1884 | break; | 1898 | break; |
1885 | case BRS_CHK_SET: | 1899 | |
1886 | if (GNUNET_OK != | 1900 | case BRS_CHK_SET: |
1887 | GNUNET_BIO_read (rh, "chk", &dr->chk, sizeof (struct ContentHashKey))) | 1901 | if (GNUNET_OK != |
1902 | GNUNET_BIO_read(rh, "chk", &dr->chk, sizeof(struct ContentHashKey))) | ||
1903 | goto cleanup; | ||
1904 | break; | ||
1905 | |||
1906 | case BRS_DOWNLOAD_DOWN: | ||
1907 | case BRS_DOWNLOAD_UP: | ||
1908 | case BRS_ERROR: | ||
1909 | break; | ||
1910 | |||
1911 | default: | ||
1912 | GNUNET_break(0); | ||
1888 | goto cleanup; | 1913 | goto cleanup; |
1889 | break; | 1914 | } |
1890 | case BRS_DOWNLOAD_DOWN: | ||
1891 | case BRS_DOWNLOAD_UP: | ||
1892 | case BRS_ERROR: | ||
1893 | break; | ||
1894 | default: | ||
1895 | GNUNET_break (0); | ||
1896 | goto cleanup; | ||
1897 | } | ||
1898 | for (i = 0; i < dr->num_children; i++) | 1915 | for (i = 0; i < dr->num_children; i++) |
1899 | { | 1916 | { |
1900 | if (NULL == (dr->children[i] = read_download_request (rh))) | 1917 | if (NULL == (dr->children[i] = read_download_request(rh))) |
1901 | goto cleanup; | 1918 | goto cleanup; |
1902 | dr->children[i]->parent = dr; | 1919 | dr->children[i]->parent = dr; |
1903 | } | 1920 | } |
1904 | return dr; | 1921 | return dr; |
1905 | cleanup: | 1922 | cleanup: |
1906 | GNUNET_FS_free_download_request_ (dr); | 1923 | GNUNET_FS_free_download_request_(dr); |
1907 | return NULL; | 1924 | return NULL; |
1908 | } | 1925 | } |
1909 | 1926 | ||
@@ -1918,26 +1935,26 @@ cleanup: | |||
1918 | * @return the expanded file name, NULL for none | 1935 | * @return the expanded file name, NULL for none |
1919 | */ | 1936 | */ |
1920 | static char * | 1937 | static char * |
1921 | get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, | 1938 | get_download_sync_filename(struct GNUNET_FS_DownloadContext *dc, |
1922 | const char *uni, | 1939 | const char *uni, |
1923 | const char *ext) | 1940 | const char *ext) |
1924 | { | 1941 | { |
1925 | char *par; | 1942 | char *par; |
1926 | char *epar; | 1943 | char *epar; |
1927 | 1944 | ||
1928 | if (dc->parent == NULL) | 1945 | if (dc->parent == NULL) |
1929 | return get_serialization_file_name (dc->h, | 1946 | return get_serialization_file_name(dc->h, |
1930 | (dc->search != NULL) | 1947 | (dc->search != NULL) |
1931 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD | 1948 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD |
1932 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 1949 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
1933 | uni); | 1950 | uni); |
1934 | if (NULL == dc->parent->serialization) | 1951 | if (NULL == dc->parent->serialization) |
1935 | return NULL; | 1952 | return NULL; |
1936 | par = get_download_sync_filename (dc->parent, dc->parent->serialization, ""); | 1953 | par = get_download_sync_filename(dc->parent, dc->parent->serialization, ""); |
1937 | if (NULL == par) | 1954 | if (NULL == par) |
1938 | return NULL; | 1955 | return NULL; |
1939 | GNUNET_asprintf (&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext); | 1956 | GNUNET_asprintf(&epar, "%s.dir%s%s%s", par, DIR_SEPARATOR_STR, uni, ext); |
1940 | GNUNET_free (par); | 1957 | GNUNET_free(par); |
1941 | return epar; | 1958 | return epar; |
1942 | } | 1959 | } |
1943 | 1960 | ||
@@ -1951,7 +1968,7 @@ get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, | |||
1951 | * @param dc the struct to sync | 1968 | * @param dc the struct to sync |
1952 | */ | 1969 | */ |
1953 | void | 1970 | void |
1954 | GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | 1971 | GNUNET_FS_download_sync_(struct GNUNET_FS_DownloadContext *dc) |
1955 | { | 1972 | { |
1956 | struct GNUNET_BIO_WriteHandle *wh; | 1973 | struct GNUNET_BIO_WriteHandle *wh; |
1957 | char *uris; | 1974 | char *uris; |
@@ -1961,87 +1978,87 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | |||
1961 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 1978 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) |
1962 | return; /* we don't sync probes */ | 1979 | return; /* we don't sync probes */ |
1963 | if (NULL == dc->serialization) | 1980 | if (NULL == dc->serialization) |
1964 | { | ||
1965 | dir = get_download_sync_filename (dc, "", ""); | ||
1966 | if (NULL == dir) | ||
1967 | return; | ||
1968 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dir)) | ||
1969 | { | 1981 | { |
1970 | GNUNET_free (dir); | 1982 | dir = get_download_sync_filename(dc, "", ""); |
1971 | return; | 1983 | if (NULL == dir) |
1984 | return; | ||
1985 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(dir)) | ||
1986 | { | ||
1987 | GNUNET_free(dir); | ||
1988 | return; | ||
1989 | } | ||
1990 | fn = GNUNET_DISK_mktemp(dir); | ||
1991 | GNUNET_free(dir); | ||
1992 | if (NULL == fn) | ||
1993 | return; | ||
1994 | dc->serialization = get_serialization_short_name(fn); | ||
1972 | } | 1995 | } |
1973 | fn = GNUNET_DISK_mktemp (dir); | ||
1974 | GNUNET_free (dir); | ||
1975 | if (NULL == fn) | ||
1976 | return; | ||
1977 | dc->serialization = get_serialization_short_name (fn); | ||
1978 | } | ||
1979 | else | 1996 | else |
1980 | { | ||
1981 | fn = get_download_sync_filename (dc, dc->serialization, ""); | ||
1982 | if (NULL == fn) | ||
1983 | { | 1997 | { |
1984 | GNUNET_free (dc->serialization); | 1998 | fn = get_download_sync_filename(dc, dc->serialization, ""); |
1999 | if (NULL == fn) | ||
2000 | { | ||
2001 | GNUNET_free(dc->serialization); | ||
2002 | dc->serialization = NULL; | ||
2003 | GNUNET_free(fn); | ||
2004 | return; | ||
2005 | } | ||
2006 | } | ||
2007 | wh = GNUNET_BIO_write_open(fn); | ||
2008 | if (NULL == wh) | ||
2009 | { | ||
2010 | GNUNET_free(dc->serialization); | ||
1985 | dc->serialization = NULL; | 2011 | dc->serialization = NULL; |
1986 | GNUNET_free (fn); | 2012 | GNUNET_free(fn); |
1987 | return; | 2013 | return; |
1988 | } | 2014 | } |
1989 | } | 2015 | GNUNET_assert((GNUNET_YES == GNUNET_FS_uri_test_chk(dc->uri)) || |
1990 | wh = GNUNET_BIO_write_open (fn); | 2016 | (GNUNET_YES == GNUNET_FS_uri_test_loc(dc->uri))); |
1991 | if (NULL == wh) | 2017 | uris = GNUNET_FS_uri_to_string(dc->uri); |
1992 | { | 2018 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || |
1993 | GNUNET_free (dc->serialization); | 2019 | (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, dc->meta)) || |
1994 | dc->serialization = NULL; | 2020 | (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->emsg)) || |
1995 | GNUNET_free (fn); | 2021 | (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->filename)) || |
1996 | return; | 2022 | (GNUNET_OK != GNUNET_BIO_write_string(wh, dc->temp_filename)) || |
1997 | } | 2023 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->old_file_size)) || |
1998 | GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) || | 2024 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->offset)) || |
1999 | (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri))); | 2025 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->length)) || |
2000 | uris = GNUNET_FS_uri_to_string (dc->uri); | 2026 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, dc->completed)) || |
2001 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2027 | (GNUNET_OK != write_start_time(wh, dc->start_time)) || |
2002 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, dc->meta)) || | 2028 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, dc->anonymity)) || |
2003 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->emsg)) || | 2029 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)dc->options)) || |
2004 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->filename)) || | 2030 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)dc->has_finished))) |
2005 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->temp_filename)) || | ||
2006 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->old_file_size)) || | ||
2007 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->offset)) || | ||
2008 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->length)) || | ||
2009 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->completed)) || | ||
2010 | (GNUNET_OK != write_start_time (wh, dc->start_time)) || | ||
2011 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dc->anonymity)) || | ||
2012 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) || | ||
2013 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished))) | ||
2014 | { | ||
2015 | GNUNET_break (0); | ||
2016 | goto cleanup; | ||
2017 | } | ||
2018 | if (NULL == dc->emsg) | ||
2019 | { | ||
2020 | GNUNET_assert (dc->top_request != NULL); | ||
2021 | if (GNUNET_YES != write_download_request (wh, dc->top_request)) | ||
2022 | { | 2031 | { |
2023 | GNUNET_break (0); | 2032 | GNUNET_break(0); |
2024 | goto cleanup; | 2033 | goto cleanup; |
2025 | } | 2034 | } |
2026 | } | 2035 | if (NULL == dc->emsg) |
2027 | GNUNET_free_non_null (uris); | 2036 | { |
2037 | GNUNET_assert(dc->top_request != NULL); | ||
2038 | if (GNUNET_YES != write_download_request(wh, dc->top_request)) | ||
2039 | { | ||
2040 | GNUNET_break(0); | ||
2041 | goto cleanup; | ||
2042 | } | ||
2043 | } | ||
2044 | GNUNET_free_non_null(uris); | ||
2028 | uris = NULL; | 2045 | uris = NULL; |
2029 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2046 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
2030 | { | 2047 | { |
2031 | wh = NULL; | 2048 | wh = NULL; |
2032 | GNUNET_break (0); | 2049 | GNUNET_break(0); |
2033 | goto cleanup; | 2050 | goto cleanup; |
2034 | } | 2051 | } |
2035 | GNUNET_free (fn); | 2052 | GNUNET_free(fn); |
2036 | return; | 2053 | return; |
2037 | cleanup: | 2054 | cleanup: |
2038 | if (NULL != wh) | 2055 | if (NULL != wh) |
2039 | (void) GNUNET_BIO_write_close (wh); | 2056 | (void)GNUNET_BIO_write_close(wh); |
2040 | GNUNET_free_non_null (uris); | 2057 | GNUNET_free_non_null(uris); |
2041 | if (0 != unlink (fn)) | 2058 | if (0 != unlink(fn)) |
2042 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 2059 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
2043 | GNUNET_free (fn); | 2060 | GNUNET_free(fn); |
2044 | GNUNET_free (dc->serialization); | 2061 | GNUNET_free(dc->serialization); |
2045 | dc->serialization = NULL; | 2062 | dc->serialization = NULL; |
2046 | } | 2063 | } |
2047 | 2064 | ||
@@ -2055,7 +2072,7 @@ cleanup: | |||
2055 | * @param sr the struct to sync | 2072 | * @param sr the struct to sync |
2056 | */ | 2073 | */ |
2057 | void | 2074 | void |
2058 | GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | 2075 | GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr) |
2059 | { | 2076 | { |
2060 | struct GNUNET_BIO_WriteHandle *wh; | 2077 | struct GNUNET_BIO_WriteHandle *wh; |
2061 | char *uris; | 2078 | char *uris; |
@@ -2065,74 +2082,74 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2065 | uris = NULL; | 2082 | uris = NULL; |
2066 | if (NULL == sr->serialization) | 2083 | if (NULL == sr->serialization) |
2067 | sr->serialization = | 2084 | sr->serialization = |
2068 | make_serialization_file_name_in_dir (sr->h, | 2085 | make_serialization_file_name_in_dir(sr->h, |
2069 | (sr->sc->psearch_result == NULL) | 2086 | (sr->sc->psearch_result == NULL) |
2070 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2087 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2071 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2088 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2072 | sr->sc->serialization); | 2089 | sr->sc->serialization); |
2073 | if (NULL == sr->serialization) | 2090 | if (NULL == sr->serialization) |
2074 | return; | 2091 | return; |
2075 | wh = get_write_handle_in_dir (sr->h, | 2092 | wh = get_write_handle_in_dir(sr->h, |
2076 | (sr->sc->psearch_result == NULL) | 2093 | (sr->sc->psearch_result == NULL) |
2077 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2094 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2078 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2095 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2079 | sr->sc->serialization, | 2096 | sr->sc->serialization, |
2080 | sr->serialization); | 2097 | sr->serialization); |
2081 | if (NULL == wh) | 2098 | if (NULL == wh) |
2082 | { | 2099 | { |
2083 | GNUNET_break (0); | 2100 | GNUNET_break(0); |
2084 | goto cleanup; | 2101 | goto cleanup; |
2085 | } | 2102 | } |
2086 | uris = GNUNET_FS_uri_to_string (sr->uri); | 2103 | uris = GNUNET_FS_uri_to_string(sr->uri); |
2087 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2104 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || |
2088 | (GNUNET_OK != GNUNET_BIO_write_string (wh, | 2105 | (GNUNET_OK != GNUNET_BIO_write_string(wh, |
2089 | sr->download != NULL | 2106 | sr->download != NULL |
2090 | ? sr->download->serialization | 2107 | ? sr->download->serialization |
2091 | : NULL)) || | 2108 | : NULL)) || |
2092 | (GNUNET_OK != | 2109 | (GNUNET_OK != |
2093 | GNUNET_BIO_write_string (wh, | 2110 | GNUNET_BIO_write_string(wh, |
2094 | sr->update_search != NULL | 2111 | sr->update_search != NULL |
2095 | ? sr->update_search->serialization | 2112 | ? sr->update_search->serialization |
2096 | : NULL)) || | 2113 | : NULL)) || |
2097 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || | 2114 | (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, sr->meta)) || |
2098 | (GNUNET_OK != | 2115 | (GNUNET_OK != |
2099 | GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) || | 2116 | GNUNET_BIO_write(wh, &sr->key, sizeof(struct GNUNET_HashCode))) || |
2100 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || | 2117 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->mandatory_missing)) || |
2101 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || | 2118 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->optional_support)) || |
2102 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || | 2119 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->availability_success)) || |
2103 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials))) | 2120 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, sr->availability_trials))) |
2104 | { | 2121 | { |
2105 | GNUNET_break (0); | 2122 | GNUNET_break(0); |
2106 | goto cleanup; | 2123 | goto cleanup; |
2107 | } | 2124 | } |
2108 | if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && | 2125 | if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && |
2109 | (GNUNET_OK != | 2126 | (GNUNET_OK != |
2110 | GNUNET_BIO_write (wh, | 2127 | GNUNET_BIO_write(wh, |
2111 | sr->keyword_bitmap, | 2128 | sr->keyword_bitmap, |
2112 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) | 2129 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) |
2113 | { | 2130 | { |
2114 | GNUNET_break (0); | 2131 | GNUNET_break(0); |
2115 | goto cleanup; | 2132 | goto cleanup; |
2116 | } | 2133 | } |
2117 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2134 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
2118 | { | 2135 | { |
2119 | wh = NULL; | 2136 | wh = NULL; |
2120 | GNUNET_break (0); | 2137 | GNUNET_break(0); |
2121 | goto cleanup; | 2138 | goto cleanup; |
2122 | } | 2139 | } |
2123 | GNUNET_free_non_null (uris); | 2140 | GNUNET_free_non_null(uris); |
2124 | return; | 2141 | return; |
2125 | cleanup: | 2142 | cleanup: |
2126 | GNUNET_free_non_null (uris); | 2143 | GNUNET_free_non_null(uris); |
2127 | if (NULL != wh) | 2144 | if (NULL != wh) |
2128 | (void) GNUNET_BIO_write_close (wh); | 2145 | (void)GNUNET_BIO_write_close(wh); |
2129 | remove_sync_file_in_dir (sr->h, | 2146 | remove_sync_file_in_dir(sr->h, |
2130 | (NULL == sr->sc->psearch_result) | 2147 | (NULL == sr->sc->psearch_result) |
2131 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2148 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2132 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2149 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2133 | sr->sc->serialization, | 2150 | sr->sc->serialization, |
2134 | sr->serialization); | 2151 | sr->serialization); |
2135 | GNUNET_free (sr->serialization); | 2152 | GNUNET_free(sr->serialization); |
2136 | sr->serialization = NULL; | 2153 | sr->serialization = NULL; |
2137 | } | 2154 | } |
2138 | 2155 | ||
@@ -2146,7 +2163,7 @@ cleanup: | |||
2146 | * @param sc the struct to sync | 2163 | * @param sc the struct to sync |
2147 | */ | 2164 | */ |
2148 | void | 2165 | void |
2149 | GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) | 2166 | GNUNET_FS_search_sync_(struct GNUNET_FS_SearchContext *sc) |
2150 | { | 2167 | { |
2151 | struct GNUNET_BIO_WriteHandle *wh; | 2168 | struct GNUNET_BIO_WriteHandle *wh; |
2152 | char *uris; | 2169 | char *uris; |
@@ -2154,47 +2171,47 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) | |||
2154 | const char *category; | 2171 | const char *category; |
2155 | 2172 | ||
2156 | category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2173 | category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2157 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; | 2174 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; |
2158 | if (NULL == sc->serialization) | 2175 | if (NULL == sc->serialization) |
2159 | sc->serialization = make_serialization_file_name (sc->h, category); | 2176 | sc->serialization = make_serialization_file_name(sc->h, category); |
2160 | if (NULL == sc->serialization) | 2177 | if (NULL == sc->serialization) |
2161 | return; | 2178 | return; |
2162 | uris = NULL; | 2179 | uris = NULL; |
2163 | wh = get_write_handle (sc->h, category, sc->serialization); | 2180 | wh = get_write_handle(sc->h, category, sc->serialization); |
2164 | if (NULL == wh) | 2181 | if (NULL == wh) |
2165 | { | 2182 | { |
2166 | GNUNET_break (0); | 2183 | GNUNET_break(0); |
2167 | goto cleanup; | 2184 | goto cleanup; |
2168 | } | 2185 | } |
2169 | GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) || | 2186 | GNUNET_assert((GNUNET_YES == GNUNET_FS_uri_test_ksk(sc->uri)) || |
2170 | (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri))); | 2187 | (GNUNET_YES == GNUNET_FS_uri_test_sks(sc->uri))); |
2171 | uris = GNUNET_FS_uri_to_string (sc->uri); | 2188 | uris = GNUNET_FS_uri_to_string(sc->uri); |
2172 | in_pause = (sc->task != NULL) ? 'r' : '\0'; | 2189 | in_pause = (sc->task != NULL) ? 'r' : '\0'; |
2173 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2190 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, uris)) || |
2174 | (GNUNET_OK != write_start_time (wh, sc->start_time)) || | 2191 | (GNUNET_OK != write_start_time(wh, sc->start_time)) || |
2175 | (GNUNET_OK != GNUNET_BIO_write_string (wh, sc->emsg)) || | 2192 | (GNUNET_OK != GNUNET_BIO_write_string(wh, sc->emsg)) || |
2176 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) || | 2193 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, (uint32_t)sc->options)) || |
2177 | (GNUNET_OK != GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) || | 2194 | (GNUNET_OK != GNUNET_BIO_write(wh, &in_pause, sizeof(in_pause))) || |
2178 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity))) | 2195 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, sc->anonymity))) |
2179 | { | 2196 | { |
2180 | GNUNET_break (0); | 2197 | GNUNET_break(0); |
2181 | goto cleanup; | 2198 | goto cleanup; |
2182 | } | 2199 | } |
2183 | GNUNET_free (uris); | 2200 | GNUNET_free(uris); |
2184 | uris = NULL; | 2201 | uris = NULL; |
2185 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2202 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
2186 | { | 2203 | { |
2187 | wh = NULL; | 2204 | wh = NULL; |
2188 | GNUNET_break (0); | 2205 | GNUNET_break(0); |
2189 | goto cleanup; | 2206 | goto cleanup; |
2190 | } | 2207 | } |
2191 | return; | 2208 | return; |
2192 | cleanup: | 2209 | cleanup: |
2193 | if (NULL != wh) | 2210 | if (NULL != wh) |
2194 | (void) GNUNET_BIO_write_close (wh); | 2211 | (void)GNUNET_BIO_write_close(wh); |
2195 | GNUNET_free_non_null (uris); | 2212 | GNUNET_free_non_null(uris); |
2196 | GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization); | 2213 | GNUNET_FS_remove_sync_file_(sc->h, category, sc->serialization); |
2197 | GNUNET_free (sc->serialization); | 2214 | GNUNET_free(sc->serialization); |
2198 | sc->serialization = NULL; | 2215 | sc->serialization = NULL; |
2199 | } | 2216 | } |
2200 | 2217 | ||
@@ -2208,7 +2225,7 @@ cleanup: | |||
2208 | * @return #GNUNET_OK (continue to iterate) | 2225 | * @return #GNUNET_OK (continue to iterate) |
2209 | */ | 2226 | */ |
2210 | static int | 2227 | static int |
2211 | deserialize_unindex_file (void *cls, const char *filename) | 2228 | deserialize_unindex_file(void *cls, const char *filename) |
2212 | { | 2229 | { |
2213 | struct GNUNET_FS_Handle *h = cls; | 2230 | struct GNUNET_FS_Handle *h = cls; |
2214 | struct GNUNET_BIO_ReadHandle *rh; | 2231 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -2218,144 +2235,155 @@ deserialize_unindex_file (void *cls, const char *filename) | |||
2218 | char *uris; | 2235 | char *uris; |
2219 | uint32_t state; | 2236 | uint32_t state; |
2220 | 2237 | ||
2221 | uc = GNUNET_new (struct GNUNET_FS_UnindexContext); | 2238 | uc = GNUNET_new(struct GNUNET_FS_UnindexContext); |
2222 | uc->h = h; | 2239 | uc->h = h; |
2223 | uc->serialization = get_serialization_short_name (filename); | 2240 | uc->serialization = get_serialization_short_name(filename); |
2224 | rh = GNUNET_BIO_read_open (filename); | 2241 | rh = GNUNET_BIO_read_open(filename); |
2225 | if (NULL == rh) | 2242 | if (NULL == rh) |
2226 | { | 2243 | { |
2227 | GNUNET_break (0); | 2244 | GNUNET_break(0); |
2228 | goto cleanup; | 2245 | goto cleanup; |
2229 | } | 2246 | } |
2230 | uris = NULL; | 2247 | uris = NULL; |
2231 | if ((GNUNET_OK != | 2248 | if ((GNUNET_OK != |
2232 | GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) || | 2249 | GNUNET_BIO_read_string(rh, "unindex-fn", &uc->filename, 10 * 1024)) || |
2233 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || | 2250 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &uc->file_size)) || |
2234 | (GNUNET_OK != read_start_time (rh, &uc->start_time)) || | 2251 | (GNUNET_OK != read_start_time(rh, &uc->start_time)) || |
2235 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || | 2252 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &state)) || |
2236 | (GNUNET_OK != | 2253 | (GNUNET_OK != |
2237 | GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || | 2254 | GNUNET_BIO_read(rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) || |
2238 | (GNUNET_OK != | 2255 | (GNUNET_OK != |
2239 | GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || | 2256 | GNUNET_BIO_read_string(rh, "unindex-kskuri", &uris, 10 * 1024)) || |
2240 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset))) | 2257 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &uc->ksk_offset))) |
2241 | { | ||
2242 | GNUNET_free_non_null (uris); | ||
2243 | GNUNET_break (0); | ||
2244 | goto cleanup; | ||
2245 | } | ||
2246 | if (NULL != uris) | ||
2247 | { | ||
2248 | uc->ksk_uri = GNUNET_FS_uri_parse (uris, &emsg); | ||
2249 | GNUNET_free (uris); | ||
2250 | if (NULL == uc->ksk_uri) | ||
2251 | { | 2258 | { |
2252 | GNUNET_break (0); | 2259 | GNUNET_free_non_null(uris); |
2253 | GNUNET_free_non_null (emsg); | 2260 | GNUNET_break(0); |
2254 | goto cleanup; | 2261 | goto cleanup; |
2255 | } | 2262 | } |
2256 | } | 2263 | if (NULL != uris) |
2264 | { | ||
2265 | uc->ksk_uri = GNUNET_FS_uri_parse(uris, &emsg); | ||
2266 | GNUNET_free(uris); | ||
2267 | if (NULL == uc->ksk_uri) | ||
2268 | { | ||
2269 | GNUNET_break(0); | ||
2270 | GNUNET_free_non_null(emsg); | ||
2271 | goto cleanup; | ||
2272 | } | ||
2273 | } | ||
2257 | if ((uc->ksk_offset > 0) && | 2274 | if ((uc->ksk_offset > 0) && |
2258 | ((NULL == uc->ksk_uri) || | 2275 | ((NULL == uc->ksk_uri) || |
2259 | (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount))) | 2276 | (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount))) |
2260 | { | ||
2261 | GNUNET_break (0); | ||
2262 | goto cleanup; | ||
2263 | } | ||
2264 | uc->state = (enum UnindexState) state; | ||
2265 | switch (state) | ||
2266 | { | ||
2267 | case UNINDEX_STATE_HASHING: | ||
2268 | break; | ||
2269 | case UNINDEX_STATE_FS_NOTIFY: | ||
2270 | if (GNUNET_OK != GNUNET_BIO_read (rh, | ||
2271 | "unindex-hash", | ||
2272 | &uc->file_id, | ||
2273 | sizeof (struct GNUNET_HashCode))) | ||
2274 | { | 2277 | { |
2275 | GNUNET_break (0); | 2278 | GNUNET_break(0); |
2276 | goto cleanup; | 2279 | goto cleanup; |
2277 | } | 2280 | } |
2278 | break; | 2281 | uc->state = (enum UnindexState)state; |
2279 | case UNINDEX_STATE_DS_REMOVE: | 2282 | switch (state) |
2280 | case UNINDEX_STATE_EXTRACT_KEYWORDS: | 2283 | { |
2281 | case UNINDEX_STATE_DS_REMOVE_KBLOCKS: | 2284 | case UNINDEX_STATE_HASHING: |
2282 | break; | 2285 | break; |
2283 | case UNINDEX_STATE_COMPLETE: | 2286 | |
2284 | break; | 2287 | case UNINDEX_STATE_FS_NOTIFY: |
2285 | case UNINDEX_STATE_ERROR: | 2288 | if (GNUNET_OK != GNUNET_BIO_read(rh, |
2286 | if (GNUNET_OK != | 2289 | "unindex-hash", |
2287 | GNUNET_BIO_read_string (rh, "unindex-emsg", &uc->emsg, 10 * 1024)) | 2290 | &uc->file_id, |
2288 | { | 2291 | sizeof(struct GNUNET_HashCode))) |
2289 | GNUNET_break (0); | 2292 | { |
2293 | GNUNET_break(0); | ||
2294 | goto cleanup; | ||
2295 | } | ||
2296 | break; | ||
2297 | |||
2298 | case UNINDEX_STATE_DS_REMOVE: | ||
2299 | case UNINDEX_STATE_EXTRACT_KEYWORDS: | ||
2300 | case UNINDEX_STATE_DS_REMOVE_KBLOCKS: | ||
2301 | break; | ||
2302 | |||
2303 | case UNINDEX_STATE_COMPLETE: | ||
2304 | break; | ||
2305 | |||
2306 | case UNINDEX_STATE_ERROR: | ||
2307 | if (GNUNET_OK != | ||
2308 | GNUNET_BIO_read_string(rh, "unindex-emsg", &uc->emsg, 10 * 1024)) | ||
2309 | { | ||
2310 | GNUNET_break(0); | ||
2311 | goto cleanup; | ||
2312 | } | ||
2313 | break; | ||
2314 | |||
2315 | default: | ||
2316 | GNUNET_break(0); | ||
2290 | goto cleanup; | 2317 | goto cleanup; |
2291 | } | 2318 | } |
2292 | break; | 2319 | uc->top = GNUNET_FS_make_top(h, &GNUNET_FS_unindex_signal_suspend_, uc); |
2293 | default: | ||
2294 | GNUNET_break (0); | ||
2295 | goto cleanup; | ||
2296 | } | ||
2297 | uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc); | ||
2298 | pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; | 2320 | pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; |
2299 | pi.value.unindex.specifics.resume.message = uc->emsg; | 2321 | pi.value.unindex.specifics.resume.message = uc->emsg; |
2300 | GNUNET_FS_unindex_make_status_ (&pi, | 2322 | GNUNET_FS_unindex_make_status_(&pi, |
2301 | uc, | 2323 | uc, |
2302 | (uc->state == UNINDEX_STATE_COMPLETE) | 2324 | (uc->state == UNINDEX_STATE_COMPLETE) |
2303 | ? uc->file_size | 2325 | ? uc->file_size |
2304 | : 0); | 2326 | : 0); |
2305 | switch (uc->state) | 2327 | switch (uc->state) |
2306 | { | 2328 | { |
2307 | case UNINDEX_STATE_HASHING: | 2329 | case UNINDEX_STATE_HASHING: |
2308 | uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, | 2330 | uc->fhc = GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, |
2309 | uc->filename, | 2331 | uc->filename, |
2310 | HASHING_BLOCKSIZE, | 2332 | HASHING_BLOCKSIZE, |
2311 | &GNUNET_FS_unindex_process_hash_, | 2333 | &GNUNET_FS_unindex_process_hash_, |
2312 | uc); | 2334 | uc); |
2313 | break; | 2335 | break; |
2314 | case UNINDEX_STATE_FS_NOTIFY: | 2336 | |
2315 | uc->state = UNINDEX_STATE_HASHING; | 2337 | case UNINDEX_STATE_FS_NOTIFY: |
2316 | GNUNET_FS_unindex_process_hash_ (uc, &uc->file_id); | 2338 | uc->state = UNINDEX_STATE_HASHING; |
2317 | break; | 2339 | GNUNET_FS_unindex_process_hash_(uc, &uc->file_id); |
2318 | case UNINDEX_STATE_DS_REMOVE: | 2340 | break; |
2319 | GNUNET_FS_unindex_do_remove_ (uc); | 2341 | |
2320 | break; | 2342 | case UNINDEX_STATE_DS_REMOVE: |
2321 | case UNINDEX_STATE_EXTRACT_KEYWORDS: | 2343 | GNUNET_FS_unindex_do_remove_(uc); |
2322 | GNUNET_FS_unindex_do_extract_keywords_ (uc); | 2344 | break; |
2323 | break; | 2345 | |
2324 | case UNINDEX_STATE_DS_REMOVE_KBLOCKS: | 2346 | case UNINDEX_STATE_EXTRACT_KEYWORDS: |
2325 | GNUNET_FS_unindex_do_remove_kblocks_ (uc); | 2347 | GNUNET_FS_unindex_do_extract_keywords_(uc); |
2326 | break; | 2348 | break; |
2327 | case UNINDEX_STATE_COMPLETE: | 2349 | |
2328 | case UNINDEX_STATE_ERROR: | 2350 | case UNINDEX_STATE_DS_REMOVE_KBLOCKS: |
2329 | /* no need to resume any operation, we were done */ | 2351 | GNUNET_FS_unindex_do_remove_kblocks_(uc); |
2330 | break; | 2352 | break; |
2331 | default: | 2353 | |
2332 | break; | 2354 | case UNINDEX_STATE_COMPLETE: |
2333 | } | 2355 | case UNINDEX_STATE_ERROR: |
2334 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2356 | /* no need to resume any operation, we were done */ |
2335 | { | 2357 | break; |
2336 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2358 | |
2337 | _ ("Failure while resuming unindexing operation `%s': %s\n"), | 2359 | default: |
2338 | filename, | 2360 | break; |
2339 | emsg); | 2361 | } |
2340 | GNUNET_free (emsg); | 2362 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
2341 | } | 2363 | { |
2364 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
2365 | _("Failure while resuming unindexing operation `%s': %s\n"), | ||
2366 | filename, | ||
2367 | emsg); | ||
2368 | GNUNET_free(emsg); | ||
2369 | } | ||
2342 | return GNUNET_OK; | 2370 | return GNUNET_OK; |
2343 | cleanup: | 2371 | cleanup: |
2344 | GNUNET_free_non_null (uc->filename); | 2372 | GNUNET_free_non_null(uc->filename); |
2345 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) | 2373 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))) |
2346 | { | 2374 | { |
2347 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2375 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2348 | _ ("Failed to resume unindexing operation `%s': %s\n"), | 2376 | _("Failed to resume unindexing operation `%s': %s\n"), |
2349 | filename, | 2377 | filename, |
2350 | emsg); | 2378 | emsg); |
2351 | GNUNET_free (emsg); | 2379 | GNUNET_free(emsg); |
2352 | } | 2380 | } |
2353 | if (NULL != uc->serialization) | 2381 | if (NULL != uc->serialization) |
2354 | GNUNET_FS_remove_sync_file_ (h, | 2382 | GNUNET_FS_remove_sync_file_(h, |
2355 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 2383 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
2356 | uc->serialization); | 2384 | uc->serialization); |
2357 | GNUNET_free_non_null (uc->serialization); | 2385 | GNUNET_free_non_null(uc->serialization); |
2358 | GNUNET_free (uc); | 2386 | GNUNET_free(uc); |
2359 | return GNUNET_OK; | 2387 | return GNUNET_OK; |
2360 | } | 2388 | } |
2361 | 2389 | ||
@@ -2370,11 +2398,11 @@ cleanup: | |||
2370 | * @param serialization name under which the search was serialized | 2398 | * @param serialization name under which the search was serialized |
2371 | */ | 2399 | */ |
2372 | static void | 2400 | static void |
2373 | deserialize_download (struct GNUNET_FS_Handle *h, | 2401 | deserialize_download(struct GNUNET_FS_Handle *h, |
2374 | struct GNUNET_BIO_ReadHandle *rh, | 2402 | struct GNUNET_BIO_ReadHandle *rh, |
2375 | struct GNUNET_FS_DownloadContext *parent, | 2403 | struct GNUNET_FS_DownloadContext *parent, |
2376 | struct GNUNET_FS_SearchResult *search, | 2404 | struct GNUNET_FS_SearchResult *search, |
2377 | const char *serialization); | 2405 | const char *serialization); |
2378 | 2406 | ||
2379 | 2407 | ||
2380 | /** | 2408 | /** |
@@ -2386,10 +2414,10 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2386 | * @param serialization name under which the search was serialized | 2414 | * @param serialization name under which the search was serialized |
2387 | */ | 2415 | */ |
2388 | static struct GNUNET_FS_SearchContext * | 2416 | static struct GNUNET_FS_SearchContext * |
2389 | deserialize_search (struct GNUNET_FS_Handle *h, | 2417 | deserialize_search(struct GNUNET_FS_Handle *h, |
2390 | struct GNUNET_BIO_ReadHandle *rh, | 2418 | struct GNUNET_BIO_ReadHandle *rh, |
2391 | struct GNUNET_FS_SearchResult *psearch_result, | 2419 | struct GNUNET_FS_SearchResult *psearch_result, |
2392 | const char *serialization); | 2420 | const char *serialization); |
2393 | 2421 | ||
2394 | 2422 | ||
2395 | /** | 2423 | /** |
@@ -2401,7 +2429,7 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2401 | * @return #GNUNET_OK (continue to iterate) | 2429 | * @return #GNUNET_OK (continue to iterate) |
2402 | */ | 2430 | */ |
2403 | static int | 2431 | static int |
2404 | deserialize_search_result (void *cls, const char *filename) | 2432 | deserialize_search_result(void *cls, const char *filename) |
2405 | { | 2433 | { |
2406 | struct GNUNET_FS_SearchContext *sc = cls; | 2434 | struct GNUNET_FS_SearchContext *sc = cls; |
2407 | char *ser; | 2435 | char *ser; |
@@ -2413,133 +2441,133 @@ deserialize_search_result (void *cls, const char *filename) | |||
2413 | struct GNUNET_BIO_ReadHandle *drh; | 2441 | struct GNUNET_BIO_ReadHandle *drh; |
2414 | struct GNUNET_FS_SearchResult *sr; | 2442 | struct GNUNET_FS_SearchResult *sr; |
2415 | 2443 | ||
2416 | ser = get_serialization_short_name (filename); | 2444 | ser = get_serialization_short_name(filename); |
2417 | rh = GNUNET_BIO_read_open (filename); | 2445 | rh = GNUNET_BIO_read_open(filename); |
2418 | if (NULL == rh) | 2446 | if (NULL == rh) |
2419 | { | ||
2420 | if (NULL != ser) | ||
2421 | { | 2447 | { |
2422 | remove_sync_file_in_dir (sc->h, | 2448 | if (NULL != ser) |
2423 | (NULL == sc->psearch_result) | 2449 | { |
2424 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2450 | remove_sync_file_in_dir(sc->h, |
2425 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2451 | (NULL == sc->psearch_result) |
2426 | sc->serialization, | 2452 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2427 | ser); | 2453 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2428 | GNUNET_free (ser); | 2454 | sc->serialization, |
2455 | ser); | ||
2456 | GNUNET_free(ser); | ||
2457 | } | ||
2458 | return GNUNET_OK; | ||
2429 | } | 2459 | } |
2430 | return GNUNET_OK; | ||
2431 | } | ||
2432 | emsg = NULL; | 2460 | emsg = NULL; |
2433 | uris = NULL; | 2461 | uris = NULL; |
2434 | download = NULL; | 2462 | download = NULL; |
2435 | update_srch = NULL; | 2463 | update_srch = NULL; |
2436 | sr = GNUNET_new (struct GNUNET_FS_SearchResult); | 2464 | sr = GNUNET_new(struct GNUNET_FS_SearchResult); |
2437 | sr->h = sc->h; | 2465 | sr->h = sc->h; |
2438 | sr->sc = sc; | 2466 | sr->sc = sc; |
2439 | sr->serialization = ser; | 2467 | sr->serialization = ser; |
2440 | if ((GNUNET_OK != | 2468 | if ((GNUNET_OK != |
2441 | GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) || | 2469 | GNUNET_BIO_read_string(rh, "result-uri", &uris, 10 * 1024)) || |
2442 | (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2470 | (NULL == (sr->uri = GNUNET_FS_uri_parse(uris, &emsg))) || |
2443 | (GNUNET_OK != | 2471 | (GNUNET_OK != |
2444 | GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) || | 2472 | GNUNET_BIO_read_string(rh, "download-lnk", &download, 16)) || |
2445 | (GNUNET_OK != | 2473 | (GNUNET_OK != |
2446 | GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || | 2474 | GNUNET_BIO_read_string(rh, "search-lnk", &update_srch, 16)) || |
2447 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || | 2475 | (GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "result-meta", &sr->meta)) || |
2448 | (GNUNET_OK != GNUNET_BIO_read (rh, | 2476 | (GNUNET_OK != GNUNET_BIO_read(rh, |
2449 | "result-key", | 2477 | "result-key", |
2450 | &sr->key, | 2478 | &sr->key, |
2451 | sizeof (struct GNUNET_HashCode))) || | 2479 | sizeof(struct GNUNET_HashCode))) || |
2452 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || | 2480 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->mandatory_missing)) || |
2453 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || | 2481 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->optional_support)) || |
2454 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || | 2482 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->availability_success)) || |
2455 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) | 2483 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sr->availability_trials))) |
2456 | { | 2484 | { |
2457 | GNUNET_break (0); | 2485 | GNUNET_break(0); |
2458 | goto cleanup; | ||
2459 | } | ||
2460 | if (GNUNET_FS_URI_KSK == sr->sc->uri->type) | ||
2461 | { | ||
2462 | sr->keyword_bitmap = GNUNET_malloc ( | ||
2463 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ | ||
2464 | if (GNUNET_OK != | ||
2465 | GNUNET_BIO_read (rh, | ||
2466 | "keyword-bitmap", | ||
2467 | sr->keyword_bitmap, | ||
2468 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) | ||
2469 | { | ||
2470 | GNUNET_break (0); | ||
2471 | goto cleanup; | 2486 | goto cleanup; |
2472 | } | 2487 | } |
2473 | } | 2488 | if (GNUNET_FS_URI_KSK == sr->sc->uri->type) |
2474 | GNUNET_free (uris); | 2489 | { |
2490 | sr->keyword_bitmap = GNUNET_malloc( | ||
2491 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ | ||
2492 | if (GNUNET_OK != | ||
2493 | GNUNET_BIO_read(rh, | ||
2494 | "keyword-bitmap", | ||
2495 | sr->keyword_bitmap, | ||
2496 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) | ||
2497 | { | ||
2498 | GNUNET_break(0); | ||
2499 | goto cleanup; | ||
2500 | } | ||
2501 | } | ||
2502 | GNUNET_free(uris); | ||
2475 | if (NULL != download) | 2503 | if (NULL != download) |
2476 | { | 2504 | { |
2477 | drh = get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, download); | 2505 | drh = get_read_handle(sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, download); |
2478 | if (NULL != drh) | 2506 | if (NULL != drh) |
2479 | { | 2507 | { |
2480 | deserialize_download (sc->h, drh, NULL, sr, download); | 2508 | deserialize_download(sc->h, drh, NULL, sr, download); |
2481 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) | 2509 | if (GNUNET_OK != GNUNET_BIO_read_close(drh, &emsg)) |
2482 | { | 2510 | { |
2483 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2511 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2484 | _ ("Failed to resume sub-download `%s': %s\n"), | 2512 | _("Failed to resume sub-download `%s': %s\n"), |
2485 | download, | 2513 | download, |
2486 | emsg); | 2514 | emsg); |
2487 | GNUNET_free (emsg); | 2515 | GNUNET_free(emsg); |
2488 | } | 2516 | } |
2489 | } | 2517 | } |
2490 | GNUNET_free (download); | 2518 | GNUNET_free(download); |
2491 | } | 2519 | } |
2492 | if (NULL != update_srch) | 2520 | if (NULL != update_srch) |
2493 | { | 2521 | { |
2494 | drh = | 2522 | drh = |
2495 | get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); | 2523 | get_read_handle(sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); |
2496 | if (NULL != drh) | 2524 | if (NULL != drh) |
2497 | { | 2525 | { |
2498 | deserialize_search (sc->h, drh, sr, update_srch); | 2526 | deserialize_search(sc->h, drh, sr, update_srch); |
2499 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) | 2527 | if (GNUNET_OK != GNUNET_BIO_read_close(drh, &emsg)) |
2500 | { | 2528 | { |
2501 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2529 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2502 | _ ("Failed to resume sub-search `%s': %s\n"), | 2530 | _("Failed to resume sub-search `%s': %s\n"), |
2503 | update_srch, | 2531 | update_srch, |
2504 | emsg); | 2532 | emsg); |
2505 | GNUNET_free (emsg); | 2533 | GNUNET_free(emsg); |
2506 | } | 2534 | } |
2507 | } | 2535 | } |
2508 | GNUNET_free (update_srch); | 2536 | GNUNET_free(update_srch); |
2509 | } | 2537 | } |
2510 | GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put ( | 2538 | GNUNET_break(GNUNET_YES == GNUNET_CONTAINER_multihashmap_put( |
2511 | sc->master_result_map, | 2539 | sc->master_result_map, |
2512 | &sr->key, | 2540 | &sr->key, |
2513 | sr, | 2541 | sr, |
2514 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 2542 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
2515 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2543 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
2516 | { | 2544 | { |
2517 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2545 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2518 | _ ("Failure while resuming search operation `%s': %s\n"), | 2546 | _("Failure while resuming search operation `%s': %s\n"), |
2519 | filename, | 2547 | filename, |
2520 | emsg); | 2548 | emsg); |
2521 | GNUNET_free (emsg); | 2549 | GNUNET_free(emsg); |
2522 | } | 2550 | } |
2523 | return GNUNET_OK; | 2551 | return GNUNET_OK; |
2524 | cleanup: | 2552 | cleanup: |
2525 | GNUNET_free_non_null (download); | 2553 | GNUNET_free_non_null(download); |
2526 | GNUNET_free_non_null (emsg); | 2554 | GNUNET_free_non_null(emsg); |
2527 | GNUNET_free_non_null (uris); | 2555 | GNUNET_free_non_null(uris); |
2528 | GNUNET_free_non_null (update_srch); | 2556 | GNUNET_free_non_null(update_srch); |
2529 | if (NULL != sr->uri) | 2557 | if (NULL != sr->uri) |
2530 | GNUNET_FS_uri_destroy (sr->uri); | 2558 | GNUNET_FS_uri_destroy(sr->uri); |
2531 | if (NULL != sr->meta) | 2559 | if (NULL != sr->meta) |
2532 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); | 2560 | GNUNET_CONTAINER_meta_data_destroy(sr->meta); |
2533 | GNUNET_free (sr->serialization); | 2561 | GNUNET_free(sr->serialization); |
2534 | GNUNET_free (sr); | 2562 | GNUNET_free(sr); |
2535 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2563 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
2536 | { | 2564 | { |
2537 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2565 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2538 | _ ("Failure while resuming search operation `%s': %s\n"), | 2566 | _("Failure while resuming search operation `%s': %s\n"), |
2539 | filename, | 2567 | filename, |
2540 | emsg); | 2568 | emsg); |
2541 | GNUNET_free (emsg); | 2569 | GNUNET_free(emsg); |
2542 | } | 2570 | } |
2543 | return GNUNET_OK; | 2571 | return GNUNET_OK; |
2544 | } | 2572 | } |
2545 | 2573 | ||
@@ -2553,7 +2581,7 @@ cleanup: | |||
2553 | * @param dc download to resume | 2581 | * @param dc download to resume |
2554 | */ | 2582 | */ |
2555 | static void | 2583 | static void |
2556 | signal_download_resume (struct GNUNET_FS_DownloadContext *dc) | 2584 | signal_download_resume(struct GNUNET_FS_DownloadContext *dc) |
2557 | { | 2585 | { |
2558 | struct GNUNET_FS_DownloadContext *dcc; | 2586 | struct GNUNET_FS_DownloadContext *dcc; |
2559 | struct GNUNET_FS_ProgressInfo pi; | 2587 | struct GNUNET_FS_ProgressInfo pi; |
@@ -2561,13 +2589,13 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc) | |||
2561 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME; | 2589 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_RESUME; |
2562 | pi.value.download.specifics.resume.meta = dc->meta; | 2590 | pi.value.download.specifics.resume.meta = dc->meta; |
2563 | pi.value.download.specifics.resume.message = dc->emsg; | 2591 | pi.value.download.specifics.resume.message = dc->emsg; |
2564 | GNUNET_FS_download_make_status_ (&pi, dc); | 2592 | GNUNET_FS_download_make_status_(&pi, dc); |
2565 | dcc = dc->child_head; | 2593 | dcc = dc->child_head; |
2566 | while (NULL != dcc) | 2594 | while (NULL != dcc) |
2567 | { | 2595 | { |
2568 | signal_download_resume (dcc); | 2596 | signal_download_resume(dcc); |
2569 | dcc = dcc->next; | 2597 | dcc = dcc->next; |
2570 | } | 2598 | } |
2571 | } | 2599 | } |
2572 | 2600 | ||
2573 | 2601 | ||
@@ -2578,7 +2606,7 @@ signal_download_resume (struct GNUNET_FS_DownloadContext *dc) | |||
2578 | * @param sc search being resumed | 2606 | * @param sc search being resumed |
2579 | */ | 2607 | */ |
2580 | static void | 2608 | static void |
2581 | signal_search_resume (struct GNUNET_FS_SearchContext *sc); | 2609 | signal_search_resume(struct GNUNET_FS_SearchContext *sc); |
2582 | 2610 | ||
2583 | 2611 | ||
2584 | /** | 2612 | /** |
@@ -2591,36 +2619,36 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc); | |||
2591 | * @return #GNUNET_YES (we should continue to iterate) | 2619 | * @return #GNUNET_YES (we should continue to iterate) |
2592 | */ | 2620 | */ |
2593 | static int | 2621 | static int |
2594 | signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value) | 2622 | signal_result_resume(void *cls, const struct GNUNET_HashCode *key, void *value) |
2595 | { | 2623 | { |
2596 | struct GNUNET_FS_SearchContext *sc = cls; | 2624 | struct GNUNET_FS_SearchContext *sc = cls; |
2597 | struct GNUNET_FS_ProgressInfo pi; | 2625 | struct GNUNET_FS_ProgressInfo pi; |
2598 | struct GNUNET_FS_SearchResult *sr = value; | 2626 | struct GNUNET_FS_SearchResult *sr = value; |
2599 | 2627 | ||
2600 | if (0 == sr->mandatory_missing) | 2628 | if (0 == sr->mandatory_missing) |
2601 | { | 2629 | { |
2602 | pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT; | 2630 | pi.status = GNUNET_FS_STATUS_SEARCH_RESUME_RESULT; |
2603 | pi.value.search.specifics.resume_result.meta = sr->meta; | 2631 | pi.value.search.specifics.resume_result.meta = sr->meta; |
2604 | pi.value.search.specifics.resume_result.uri = sr->uri; | 2632 | pi.value.search.specifics.resume_result.uri = sr->uri; |
2605 | pi.value.search.specifics.resume_result.result = sr; | 2633 | pi.value.search.specifics.resume_result.result = sr; |
2606 | pi.value.search.specifics.resume_result.availability_rank = | 2634 | pi.value.search.specifics.resume_result.availability_rank = |
2607 | 2 * sr->availability_success - sr->availability_trials; | 2635 | 2 * sr->availability_success - sr->availability_trials; |
2608 | pi.value.search.specifics.resume_result.availability_certainty = | 2636 | pi.value.search.specifics.resume_result.availability_certainty = |
2609 | sr->availability_trials; | 2637 | sr->availability_trials; |
2610 | pi.value.search.specifics.resume_result.applicability_rank = | 2638 | pi.value.search.specifics.resume_result.applicability_rank = |
2611 | sr->optional_support; | 2639 | sr->optional_support; |
2612 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 2640 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); |
2613 | } | 2641 | } |
2614 | if (NULL != sr->download) | 2642 | if (NULL != sr->download) |
2615 | { | 2643 | { |
2616 | signal_download_resume (sr->download); | 2644 | signal_download_resume(sr->download); |
2617 | } | 2645 | } |
2618 | else | 2646 | else |
2619 | { | 2647 | { |
2620 | GNUNET_FS_search_start_probe_ (sr); | 2648 | GNUNET_FS_search_start_probe_(sr); |
2621 | } | 2649 | } |
2622 | if (NULL != sr->update_search) | 2650 | if (NULL != sr->update_search) |
2623 | signal_search_resume (sr->update_search); | 2651 | signal_search_resume(sr->update_search); |
2624 | return GNUNET_YES; | 2652 | return GNUNET_YES; |
2625 | } | 2653 | } |
2626 | 2654 | ||
@@ -2631,7 +2659,7 @@ signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
2631 | * @param sc search context to free | 2659 | * @param sc search context to free |
2632 | */ | 2660 | */ |
2633 | static void | 2661 | static void |
2634 | free_search_context (struct GNUNET_FS_SearchContext *sc); | 2662 | free_search_context(struct GNUNET_FS_SearchContext *sc); |
2635 | 2663 | ||
2636 | 2664 | ||
2637 | /** | 2665 | /** |
@@ -2643,18 +2671,18 @@ free_search_context (struct GNUNET_FS_SearchContext *sc); | |||
2643 | * @return #GNUNET_YES (we should continue to iterate) | 2671 | * @return #GNUNET_YES (we should continue to iterate) |
2644 | */ | 2672 | */ |
2645 | static int | 2673 | static int |
2646 | free_result (void *cls, const struct GNUNET_HashCode *key, void *value) | 2674 | free_result(void *cls, const struct GNUNET_HashCode *key, void *value) |
2647 | { | 2675 | { |
2648 | struct GNUNET_FS_SearchResult *sr = value; | 2676 | struct GNUNET_FS_SearchResult *sr = value; |
2649 | 2677 | ||
2650 | if (NULL != sr->update_search) | 2678 | if (NULL != sr->update_search) |
2651 | { | 2679 | { |
2652 | free_search_context (sr->update_search); | 2680 | free_search_context(sr->update_search); |
2653 | GNUNET_assert (NULL == sr->update_search); | 2681 | GNUNET_assert(NULL == sr->update_search); |
2654 | } | 2682 | } |
2655 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); | 2683 | GNUNET_CONTAINER_meta_data_destroy(sr->meta); |
2656 | GNUNET_FS_uri_destroy (sr->uri); | 2684 | GNUNET_FS_uri_destroy(sr->uri); |
2657 | GNUNET_free (sr); | 2685 | GNUNET_free(sr); |
2658 | return GNUNET_YES; | 2686 | return GNUNET_YES; |
2659 | } | 2687 | } |
2660 | 2688 | ||
@@ -2665,33 +2693,33 @@ free_result (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
2665 | * @param sc search context to free | 2693 | * @param sc search context to free |
2666 | */ | 2694 | */ |
2667 | static void | 2695 | static void |
2668 | free_search_context (struct GNUNET_FS_SearchContext *sc) | 2696 | free_search_context(struct GNUNET_FS_SearchContext *sc) |
2669 | { | 2697 | { |
2670 | if (NULL != sc->serialization) | 2698 | if (NULL != sc->serialization) |
2671 | { | 2699 | { |
2672 | GNUNET_FS_remove_sync_file_ (sc->h, | 2700 | GNUNET_FS_remove_sync_file_(sc->h, |
2673 | (sc->psearch_result == NULL) | 2701 | (sc->psearch_result == NULL) |
2674 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | ||
2675 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | ||
2676 | sc->serialization); | ||
2677 | GNUNET_FS_remove_sync_dir_ (sc->h, | ||
2678 | (sc->psearch_result == NULL) | ||
2679 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2702 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2680 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2703 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2681 | sc->serialization); | 2704 | sc->serialization); |
2682 | } | 2705 | GNUNET_FS_remove_sync_dir_(sc->h, |
2683 | GNUNET_free_non_null (sc->serialization); | 2706 | (sc->psearch_result == NULL) |
2684 | GNUNET_free_non_null (sc->emsg); | 2707 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2708 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | ||
2709 | sc->serialization); | ||
2710 | } | ||
2711 | GNUNET_free_non_null(sc->serialization); | ||
2712 | GNUNET_free_non_null(sc->emsg); | ||
2685 | if (NULL != sc->uri) | 2713 | if (NULL != sc->uri) |
2686 | GNUNET_FS_uri_destroy (sc->uri); | 2714 | GNUNET_FS_uri_destroy(sc->uri); |
2687 | if (NULL != sc->master_result_map) | 2715 | if (NULL != sc->master_result_map) |
2688 | { | 2716 | { |
2689 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 2717 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, |
2690 | &free_result, | 2718 | &free_result, |
2691 | sc); | 2719 | sc); |
2692 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); | 2720 | GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); |
2693 | } | 2721 | } |
2694 | GNUNET_free (sc); | 2722 | GNUNET_free(sc); |
2695 | } | 2723 | } |
2696 | 2724 | ||
2697 | 2725 | ||
@@ -2704,35 +2732,35 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) | |||
2704 | * @return #GNUNET_OK (continue to iterate) | 2732 | * @return #GNUNET_OK (continue to iterate) |
2705 | */ | 2733 | */ |
2706 | static int | 2734 | static int |
2707 | deserialize_subdownload (void *cls, const char *filename) | 2735 | deserialize_subdownload(void *cls, const char *filename) |
2708 | { | 2736 | { |
2709 | struct GNUNET_FS_DownloadContext *parent = cls; | 2737 | struct GNUNET_FS_DownloadContext *parent = cls; |
2710 | char *ser; | 2738 | char *ser; |
2711 | char *emsg; | 2739 | char *emsg; |
2712 | struct GNUNET_BIO_ReadHandle *rh; | 2740 | struct GNUNET_BIO_ReadHandle *rh; |
2713 | 2741 | ||
2714 | ser = get_serialization_short_name (filename); | 2742 | ser = get_serialization_short_name(filename); |
2715 | rh = GNUNET_BIO_read_open (filename); | 2743 | rh = GNUNET_BIO_read_open(filename); |
2716 | if (NULL == rh) | 2744 | if (NULL == rh) |
2717 | { | 2745 | { |
2718 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2746 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2719 | _ ( | 2747 | _( |
2720 | "Failed to resume sub-download `%s': could not open file `%s'\n"), | 2748 | "Failed to resume sub-download `%s': could not open file `%s'\n"), |
2721 | ser, | 2749 | ser, |
2722 | filename); | 2750 | filename); |
2723 | GNUNET_free (ser); | 2751 | GNUNET_free(ser); |
2724 | return GNUNET_OK; | 2752 | return GNUNET_OK; |
2725 | } | 2753 | } |
2726 | deserialize_download (parent->h, rh, parent, NULL, ser); | 2754 | deserialize_download(parent->h, rh, parent, NULL, ser); |
2727 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2755 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
2728 | { | 2756 | { |
2729 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2757 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2730 | _ ("Failed to resume sub-download `%s': %s\n"), | 2758 | _("Failed to resume sub-download `%s': %s\n"), |
2731 | ser, | 2759 | ser, |
2732 | emsg); | 2760 | emsg); |
2733 | GNUNET_free (emsg); | 2761 | GNUNET_free(emsg); |
2734 | } | 2762 | } |
2735 | GNUNET_free (ser); | 2763 | GNUNET_free(ser); |
2736 | return GNUNET_OK; | 2764 | return GNUNET_OK; |
2737 | } | 2765 | } |
2738 | 2766 | ||
@@ -2745,27 +2773,27 @@ deserialize_subdownload (void *cls, const char *filename) | |||
2745 | * @param dc context to free | 2773 | * @param dc context to free |
2746 | */ | 2774 | */ |
2747 | static void | 2775 | static void |
2748 | free_download_context (struct GNUNET_FS_DownloadContext *dc) | 2776 | free_download_context(struct GNUNET_FS_DownloadContext *dc) |
2749 | { | 2777 | { |
2750 | struct GNUNET_FS_DownloadContext *dcc; | 2778 | struct GNUNET_FS_DownloadContext *dcc; |
2751 | 2779 | ||
2752 | if (NULL != dc->meta) | 2780 | if (NULL != dc->meta) |
2753 | GNUNET_CONTAINER_meta_data_destroy (dc->meta); | 2781 | GNUNET_CONTAINER_meta_data_destroy(dc->meta); |
2754 | if (NULL != dc->uri) | 2782 | if (NULL != dc->uri) |
2755 | GNUNET_FS_uri_destroy (dc->uri); | 2783 | GNUNET_FS_uri_destroy(dc->uri); |
2756 | GNUNET_free_non_null (dc->temp_filename); | 2784 | GNUNET_free_non_null(dc->temp_filename); |
2757 | GNUNET_free_non_null (dc->emsg); | 2785 | GNUNET_free_non_null(dc->emsg); |
2758 | GNUNET_free_non_null (dc->filename); | 2786 | GNUNET_free_non_null(dc->filename); |
2759 | GNUNET_free_non_null (dc->serialization); | 2787 | GNUNET_free_non_null(dc->serialization); |
2760 | while (NULL != (dcc = dc->child_head)) | 2788 | while (NULL != (dcc = dc->child_head)) |
2761 | { | 2789 | { |
2762 | GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc); | 2790 | GNUNET_CONTAINER_DLL_remove(dc->child_head, dc->child_tail, dcc); |
2763 | free_download_context (dcc); | 2791 | free_download_context(dcc); |
2764 | } | 2792 | } |
2765 | GNUNET_FS_free_download_request_ (dc->top_request); | 2793 | GNUNET_FS_free_download_request_(dc->top_request); |
2766 | if (NULL != dc->active) | 2794 | if (NULL != dc->active) |
2767 | GNUNET_CONTAINER_multihashmap_destroy (dc->active); | 2795 | GNUNET_CONTAINER_multihashmap_destroy(dc->active); |
2768 | GNUNET_free (dc); | 2796 | GNUNET_free(dc); |
2769 | } | 2797 | } |
2770 | 2798 | ||
2771 | 2799 | ||
@@ -2779,11 +2807,11 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc) | |||
2779 | * @param serialization name under which the search was serialized | 2807 | * @param serialization name under which the search was serialized |
2780 | */ | 2808 | */ |
2781 | static void | 2809 | static void |
2782 | deserialize_download (struct GNUNET_FS_Handle *h, | 2810 | deserialize_download(struct GNUNET_FS_Handle *h, |
2783 | struct GNUNET_BIO_ReadHandle *rh, | 2811 | struct GNUNET_BIO_ReadHandle *rh, |
2784 | struct GNUNET_FS_DownloadContext *parent, | 2812 | struct GNUNET_FS_DownloadContext *parent, |
2785 | struct GNUNET_FS_SearchResult *search, | 2813 | struct GNUNET_FS_SearchResult *search, |
2786 | const char *serialization) | 2814 | const char *serialization) |
2787 | { | 2815 | { |
2788 | struct GNUNET_FS_DownloadContext *dc; | 2816 | struct GNUNET_FS_DownloadContext *dc; |
2789 | char *emsg; | 2817 | char *emsg; |
@@ -2794,86 +2822,86 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2794 | 2822 | ||
2795 | uris = NULL; | 2823 | uris = NULL; |
2796 | emsg = NULL; | 2824 | emsg = NULL; |
2797 | dc = GNUNET_new (struct GNUNET_FS_DownloadContext); | 2825 | dc = GNUNET_new(struct GNUNET_FS_DownloadContext); |
2798 | dc->parent = parent; | 2826 | dc->parent = parent; |
2799 | dc->h = h; | 2827 | dc->h = h; |
2800 | dc->serialization = GNUNET_strdup (serialization); | 2828 | dc->serialization = GNUNET_strdup(serialization); |
2801 | if ((GNUNET_OK != | 2829 | if ((GNUNET_OK != |
2802 | GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) || | 2830 | GNUNET_BIO_read_string(rh, "download-uri", &uris, 10 * 1024)) || |
2803 | (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2831 | (NULL == (dc->uri = GNUNET_FS_uri_parse(uris, &emsg))) || |
2804 | ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && | 2832 | ((GNUNET_YES != GNUNET_FS_uri_test_chk(dc->uri)) && |
2805 | (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || | 2833 | (GNUNET_YES != GNUNET_FS_uri_test_loc(dc->uri))) || |
2806 | (GNUNET_OK != | 2834 | (GNUNET_OK != |
2807 | GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || | 2835 | GNUNET_BIO_read_meta_data(rh, "download-meta", &dc->meta)) || |
2808 | (GNUNET_OK != | 2836 | (GNUNET_OK != |
2809 | GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || | 2837 | GNUNET_BIO_read_string(rh, "download-emsg", &dc->emsg, 10 * 1024)) || |
2810 | (GNUNET_OK != | 2838 | (GNUNET_OK != |
2811 | GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || | 2839 | GNUNET_BIO_read_string(rh, "download-fn", &dc->filename, 10 * 1024)) || |
2812 | (GNUNET_OK != GNUNET_BIO_read_string (rh, | 2840 | (GNUNET_OK != GNUNET_BIO_read_string(rh, |
2813 | "download-tfn", | 2841 | "download-tfn", |
2814 | &dc->temp_filename, | 2842 | &dc->temp_filename, |
2815 | 10 * 1024)) || | 2843 | 10 * 1024)) || |
2816 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || | 2844 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->old_file_size)) || |
2817 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || | 2845 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->offset)) || |
2818 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || | 2846 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->length)) || |
2819 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) || | 2847 | (GNUNET_OK != GNUNET_BIO_read_int64(rh, &dc->completed)) || |
2820 | (GNUNET_OK != read_start_time (rh, &dc->start_time)) || | 2848 | (GNUNET_OK != read_start_time(rh, &dc->start_time)) || |
2821 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) || | 2849 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &dc->anonymity)) || |
2822 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 2850 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) || |
2823 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status))) | 2851 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &status))) |
2824 | { | 2852 | { |
2825 | GNUNET_break (0); | 2853 | GNUNET_break(0); |
2826 | goto cleanup; | 2854 | goto cleanup; |
2827 | } | 2855 | } |
2828 | dc->options = (enum GNUNET_FS_DownloadOptions) options; | 2856 | dc->options = (enum GNUNET_FS_DownloadOptions)options; |
2829 | dc->active = | 2857 | dc->active = |
2830 | GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), | 2858 | GNUNET_CONTAINER_multihashmap_create(1 + 2 * (dc->length / DBLOCK_SIZE), |
2831 | GNUNET_NO); | 2859 | GNUNET_NO); |
2832 | dc->has_finished = (int) status; | 2860 | dc->has_finished = (int)status; |
2833 | dc->treedepth = | 2861 | dc->treedepth = |
2834 | GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); | 2862 | GNUNET_FS_compute_depth(GNUNET_FS_uri_chk_get_file_size(dc->uri)); |
2835 | if (GNUNET_FS_uri_test_loc (dc->uri)) | 2863 | if (GNUNET_FS_uri_test_loc(dc->uri)) |
2836 | GNUNET_assert (GNUNET_OK == | 2864 | GNUNET_assert(GNUNET_OK == |
2837 | GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target)); | 2865 | GNUNET_FS_uri_loc_get_peer_identity(dc->uri, &dc->target)); |
2838 | if (NULL == dc->emsg) | 2866 | if (NULL == dc->emsg) |
2839 | { | ||
2840 | dc->top_request = read_download_request (rh); | ||
2841 | if (NULL == dc->top_request) | ||
2842 | { | 2867 | { |
2843 | GNUNET_break (0); | 2868 | dc->top_request = read_download_request(rh); |
2844 | goto cleanup; | 2869 | if (NULL == dc->top_request) |
2870 | { | ||
2871 | GNUNET_break(0); | ||
2872 | goto cleanup; | ||
2873 | } | ||
2845 | } | 2874 | } |
2846 | } | 2875 | dn = get_download_sync_filename(dc, dc->serialization, ".dir"); |
2847 | dn = get_download_sync_filename (dc, dc->serialization, ".dir"); | ||
2848 | if (NULL != dn) | 2876 | if (NULL != dn) |
2849 | { | 2877 | { |
2850 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) | 2878 | if (GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) |
2851 | GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); | 2879 | GNUNET_DISK_directory_scan(dn, &deserialize_subdownload, dc); |
2852 | GNUNET_free (dn); | 2880 | GNUNET_free(dn); |
2853 | } | 2881 | } |
2854 | if (NULL != parent) | 2882 | if (NULL != parent) |
2855 | { | 2883 | { |
2856 | GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); | 2884 | GNUNET_CONTAINER_DLL_insert(parent->child_head, parent->child_tail, dc); |
2857 | } | 2885 | } |
2858 | if (NULL != search) | 2886 | if (NULL != search) |
2859 | { | 2887 | { |
2860 | dc->search = search; | 2888 | dc->search = search; |
2861 | search->download = dc; | 2889 | search->download = dc; |
2862 | } | 2890 | } |
2863 | if ((NULL == parent) && (NULL == search)) | 2891 | if ((NULL == parent) && (NULL == search)) |
2864 | { | 2892 | { |
2865 | dc->top = | 2893 | dc->top = |
2866 | GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); | 2894 | GNUNET_FS_make_top(dc->h, &GNUNET_FS_download_signal_suspend_, dc); |
2867 | signal_download_resume (dc); | 2895 | signal_download_resume(dc); |
2868 | } | 2896 | } |
2869 | GNUNET_free (uris); | 2897 | GNUNET_free(uris); |
2870 | GNUNET_assert (NULL == dc->job_queue); | 2898 | GNUNET_assert(NULL == dc->job_queue); |
2871 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); | 2899 | dc->task = GNUNET_SCHEDULER_add_now(&GNUNET_FS_download_start_task_, dc); |
2872 | return; | 2900 | return; |
2873 | cleanup: | 2901 | cleanup: |
2874 | GNUNET_free_non_null (uris); | 2902 | GNUNET_free_non_null(uris); |
2875 | GNUNET_free_non_null (emsg); | 2903 | GNUNET_free_non_null(emsg); |
2876 | free_download_context (dc); | 2904 | free_download_context(dc); |
2877 | } | 2905 | } |
2878 | 2906 | ||
2879 | 2907 | ||
@@ -2884,7 +2912,7 @@ cleanup: | |||
2884 | * @param sc search being resumed | 2912 | * @param sc search being resumed |
2885 | */ | 2913 | */ |
2886 | static void | 2914 | static void |
2887 | signal_search_resume (struct GNUNET_FS_SearchContext *sc) | 2915 | signal_search_resume(struct GNUNET_FS_SearchContext *sc) |
2888 | { | 2916 | { |
2889 | struct GNUNET_FS_ProgressInfo pi; | 2917 | struct GNUNET_FS_ProgressInfo pi; |
2890 | 2918 | ||
@@ -2892,10 +2920,10 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc) | |||
2892 | pi.value.search.specifics.resume.message = sc->emsg; | 2920 | pi.value.search.specifics.resume.message = sc->emsg; |
2893 | pi.value.search.specifics.resume.is_paused = | 2921 | pi.value.search.specifics.resume.is_paused = |
2894 | (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; | 2922 | (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; |
2895 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 2923 | sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); |
2896 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 2924 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, |
2897 | &signal_result_resume, | 2925 | &signal_result_resume, |
2898 | sc); | 2926 | sc); |
2899 | } | 2927 | } |
2900 | 2928 | ||
2901 | 2929 | ||
@@ -2908,10 +2936,10 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc) | |||
2908 | * @param serialization name under which the search was serialized | 2936 | * @param serialization name under which the search was serialized |
2909 | */ | 2937 | */ |
2910 | static struct GNUNET_FS_SearchContext * | 2938 | static struct GNUNET_FS_SearchContext * |
2911 | deserialize_search (struct GNUNET_FS_Handle *h, | 2939 | deserialize_search(struct GNUNET_FS_Handle *h, |
2912 | struct GNUNET_BIO_ReadHandle *rh, | 2940 | struct GNUNET_BIO_ReadHandle *rh, |
2913 | struct GNUNET_FS_SearchResult *psearch_result, | 2941 | struct GNUNET_FS_SearchResult *psearch_result, |
2914 | const char *serialization) | 2942 | const char *serialization) |
2915 | { | 2943 | { |
2916 | struct GNUNET_FS_SearchContext *sc; | 2944 | struct GNUNET_FS_SearchContext *sc; |
2917 | char *emsg; | 2945 | char *emsg; |
@@ -2921,64 +2949,64 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2921 | char in_pause; | 2949 | char in_pause; |
2922 | 2950 | ||
2923 | if ((NULL != psearch_result) && (NULL != psearch_result->update_search)) | 2951 | if ((NULL != psearch_result) && (NULL != psearch_result->update_search)) |
2924 | { | 2952 | { |
2925 | GNUNET_break (0); | 2953 | GNUNET_break(0); |
2926 | return NULL; | 2954 | return NULL; |
2927 | } | 2955 | } |
2928 | uris = NULL; | 2956 | uris = NULL; |
2929 | emsg = NULL; | 2957 | emsg = NULL; |
2930 | sc = GNUNET_new (struct GNUNET_FS_SearchContext); | 2958 | sc = GNUNET_new(struct GNUNET_FS_SearchContext); |
2931 | if (NULL != psearch_result) | 2959 | if (NULL != psearch_result) |
2932 | { | 2960 | { |
2933 | sc->psearch_result = psearch_result; | 2961 | sc->psearch_result = psearch_result; |
2934 | psearch_result->update_search = sc; | 2962 | psearch_result->update_search = sc; |
2935 | } | 2963 | } |
2936 | sc->h = h; | 2964 | sc->h = h; |
2937 | sc->serialization = GNUNET_strdup (serialization); | 2965 | sc->serialization = GNUNET_strdup(serialization); |
2938 | if ((GNUNET_OK != | 2966 | if ((GNUNET_OK != |
2939 | GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024)) || | 2967 | GNUNET_BIO_read_string(rh, "search-uri", &uris, 10 * 1024)) || |
2940 | (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2968 | (NULL == (sc->uri = GNUNET_FS_uri_parse(uris, &emsg))) || |
2941 | ((GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) && | 2969 | ((GNUNET_YES != GNUNET_FS_uri_test_ksk(sc->uri)) && |
2942 | (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri))) || | 2970 | (GNUNET_YES != GNUNET_FS_uri_test_sks(sc->uri))) || |
2943 | (GNUNET_OK != read_start_time (rh, &sc->start_time)) || | 2971 | (GNUNET_OK != read_start_time(rh, &sc->start_time)) || |
2944 | (GNUNET_OK != | 2972 | (GNUNET_OK != |
2945 | GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) || | 2973 | GNUNET_BIO_read_string(rh, "search-emsg", &sc->emsg, 10 * 1024)) || |
2946 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 2974 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &options)) || |
2947 | (GNUNET_OK != | 2975 | (GNUNET_OK != |
2948 | GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) || | 2976 | GNUNET_BIO_read(rh, "search-pause", &in_pause, sizeof(in_pause))) || |
2949 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity))) | 2977 | (GNUNET_OK != GNUNET_BIO_read_int32(rh, &sc->anonymity))) |
2950 | { | 2978 | { |
2951 | GNUNET_break (0); | 2979 | GNUNET_break(0); |
2952 | goto cleanup; | 2980 | goto cleanup; |
2953 | } | 2981 | } |
2954 | sc->options = (enum GNUNET_FS_SearchOptions) options; | 2982 | sc->options = (enum GNUNET_FS_SearchOptions)options; |
2955 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); | 2983 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_NO); |
2956 | dn = get_serialization_file_name_in_dir (h, | 2984 | dn = get_serialization_file_name_in_dir(h, |
2957 | (NULL == sc->psearch_result) | 2985 | (NULL == sc->psearch_result) |
2958 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2986 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2959 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2987 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2960 | sc->serialization, | 2988 | sc->serialization, |
2961 | ""); | 2989 | ""); |
2962 | if (NULL != dn) | 2990 | if (NULL != dn) |
2963 | { | 2991 | { |
2964 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) | 2992 | if (GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) |
2965 | GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc); | 2993 | GNUNET_DISK_directory_scan(dn, &deserialize_search_result, sc); |
2966 | GNUNET_free (dn); | 2994 | GNUNET_free(dn); |
2967 | } | 2995 | } |
2968 | if (('\0' == in_pause) && | 2996 | if (('\0' == in_pause) && |
2969 | (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))) | 2997 | (GNUNET_OK != GNUNET_FS_search_start_searching_(sc))) |
2970 | { | 2998 | { |
2971 | GNUNET_log ( | 2999 | GNUNET_log( |
2972 | GNUNET_ERROR_TYPE_WARNING, | 3000 | GNUNET_ERROR_TYPE_WARNING, |
2973 | _ ("Could not resume running search, will resume as paused search\n")); | 3001 | _("Could not resume running search, will resume as paused search\n")); |
2974 | } | 3002 | } |
2975 | signal_search_resume (sc); | 3003 | signal_search_resume(sc); |
2976 | GNUNET_free (uris); | 3004 | GNUNET_free(uris); |
2977 | return sc; | 3005 | return sc; |
2978 | cleanup: | 3006 | cleanup: |
2979 | GNUNET_free_non_null (emsg); | 3007 | GNUNET_free_non_null(emsg); |
2980 | free_search_context (sc); | 3008 | free_search_context(sc); |
2981 | GNUNET_free_non_null (uris); | 3009 | GNUNET_free_non_null(uris); |
2982 | return NULL; | 3010 | return NULL; |
2983 | } | 3011 | } |
2984 | 3012 | ||
@@ -2992,7 +3020,7 @@ cleanup: | |||
2992 | * @return #GNUNET_OK (continue to iterate) | 3020 | * @return #GNUNET_OK (continue to iterate) |
2993 | */ | 3021 | */ |
2994 | static int | 3022 | static int |
2995 | deserialize_search_file (void *cls, const char *filename) | 3023 | deserialize_search_file(void *cls, const char *filename) |
2996 | { | 3024 | { |
2997 | struct GNUNET_FS_Handle *h = cls; | 3025 | struct GNUNET_FS_Handle *h = cls; |
2998 | char *ser; | 3026 | char *ser; |
@@ -3001,36 +3029,36 @@ deserialize_search_file (void *cls, const char *filename) | |||
3001 | struct GNUNET_FS_SearchContext *sc; | 3029 | struct GNUNET_FS_SearchContext *sc; |
3002 | struct stat buf; | 3030 | struct stat buf; |
3003 | 3031 | ||
3004 | if (0 != stat (filename, &buf)) | 3032 | if (0 != stat(filename, &buf)) |
3005 | { | 3033 | { |
3006 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 3034 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
3007 | return GNUNET_OK; | 3035 | return GNUNET_OK; |
3008 | } | 3036 | } |
3009 | if (S_ISDIR (buf.st_mode)) | 3037 | if (S_ISDIR(buf.st_mode)) |
3010 | return GNUNET_OK; /* skip directories */ | 3038 | return GNUNET_OK; /* skip directories */ |
3011 | ser = get_serialization_short_name (filename); | 3039 | ser = get_serialization_short_name(filename); |
3012 | rh = GNUNET_BIO_read_open (filename); | 3040 | rh = GNUNET_BIO_read_open(filename); |
3013 | if (NULL == rh) | 3041 | if (NULL == rh) |
3014 | { | ||
3015 | if (NULL != ser) | ||
3016 | { | 3042 | { |
3017 | GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser); | 3043 | if (NULL != ser) |
3018 | GNUNET_free (ser); | 3044 | { |
3045 | GNUNET_FS_remove_sync_file_(h, GNUNET_FS_SYNC_PATH_MASTER_SEARCH, ser); | ||
3046 | GNUNET_free(ser); | ||
3047 | } | ||
3048 | return GNUNET_OK; | ||
3019 | } | 3049 | } |
3020 | return GNUNET_OK; | 3050 | sc = deserialize_search(h, rh, NULL, ser); |
3021 | } | ||
3022 | sc = deserialize_search (h, rh, NULL, ser); | ||
3023 | if (NULL != sc) | 3051 | if (NULL != sc) |
3024 | sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc); | 3052 | sc->top = GNUNET_FS_make_top(h, &GNUNET_FS_search_signal_suspend_, sc); |
3025 | GNUNET_free (ser); | 3053 | GNUNET_free(ser); |
3026 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 3054 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
3027 | { | 3055 | { |
3028 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3056 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3029 | _ ("Failure while resuming search operation `%s': %s\n"), | 3057 | _("Failure while resuming search operation `%s': %s\n"), |
3030 | filename, | 3058 | filename, |
3031 | emsg); | 3059 | emsg); |
3032 | GNUNET_free (emsg); | 3060 | GNUNET_free(emsg); |
3033 | } | 3061 | } |
3034 | return GNUNET_OK; | 3062 | return GNUNET_OK; |
3035 | } | 3063 | } |
3036 | 3064 | ||
@@ -3044,32 +3072,32 @@ deserialize_search_file (void *cls, const char *filename) | |||
3044 | * @return #GNUNET_OK (continue to iterate) | 3072 | * @return #GNUNET_OK (continue to iterate) |
3045 | */ | 3073 | */ |
3046 | static int | 3074 | static int |
3047 | deserialize_download_file (void *cls, const char *filename) | 3075 | deserialize_download_file(void *cls, const char *filename) |
3048 | { | 3076 | { |
3049 | struct GNUNET_FS_Handle *h = cls; | 3077 | struct GNUNET_FS_Handle *h = cls; |
3050 | char *ser; | 3078 | char *ser; |
3051 | char *emsg; | 3079 | char *emsg; |
3052 | struct GNUNET_BIO_ReadHandle *rh; | 3080 | struct GNUNET_BIO_ReadHandle *rh; |
3053 | 3081 | ||
3054 | ser = get_serialization_short_name (filename); | 3082 | ser = get_serialization_short_name(filename); |
3055 | rh = GNUNET_BIO_read_open (filename); | 3083 | rh = GNUNET_BIO_read_open(filename); |
3056 | if (NULL == rh) | 3084 | if (NULL == rh) |
3057 | { | 3085 | { |
3058 | if (0 != unlink (filename)) | 3086 | if (0 != unlink(filename)) |
3059 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 3087 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
3060 | GNUNET_free (ser); | 3088 | GNUNET_free(ser); |
3061 | return GNUNET_OK; | 3089 | return GNUNET_OK; |
3062 | } | 3090 | } |
3063 | deserialize_download (h, rh, NULL, NULL, ser); | 3091 | deserialize_download(h, rh, NULL, NULL, ser); |
3064 | GNUNET_free (ser); | 3092 | GNUNET_free(ser); |
3065 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 3093 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
3066 | { | 3094 | { |
3067 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3095 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3068 | _ ("Failure while resuming download operation `%s': %s\n"), | 3096 | _("Failure while resuming download operation `%s': %s\n"), |
3069 | filename, | 3097 | filename, |
3070 | emsg); | 3098 | emsg); |
3071 | GNUNET_free (emsg); | 3099 | GNUNET_free(emsg); |
3072 | } | 3100 | } |
3073 | return GNUNET_OK; | 3101 | return GNUNET_OK; |
3074 | } | 3102 | } |
3075 | 3103 | ||
@@ -3082,18 +3110,18 @@ deserialize_download_file (void *cls, const char *filename) | |||
3082 | * @param h the `struct GNUNET_FS_Handle *` | 3110 | * @param h the `struct GNUNET_FS_Handle *` |
3083 | */ | 3111 | */ |
3084 | static void | 3112 | static void |
3085 | deserialization_master (const char *master_path, | 3113 | deserialization_master(const char *master_path, |
3086 | GNUNET_FileNameCallback proc, | 3114 | GNUNET_FileNameCallback proc, |
3087 | struct GNUNET_FS_Handle *h) | 3115 | struct GNUNET_FS_Handle *h) |
3088 | { | 3116 | { |
3089 | char *dn; | 3117 | char *dn; |
3090 | 3118 | ||
3091 | dn = get_serialization_file_name (h, master_path, ""); | 3119 | dn = get_serialization_file_name(h, master_path, ""); |
3092 | if (NULL == dn) | 3120 | if (NULL == dn) |
3093 | return; | 3121 | return; |
3094 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) | 3122 | if (GNUNET_YES == GNUNET_DISK_directory_test(dn, GNUNET_YES)) |
3095 | GNUNET_DISK_directory_scan (dn, proc, h); | 3123 | GNUNET_DISK_directory_scan(dn, proc, h); |
3096 | GNUNET_free (dn); | 3124 | GNUNET_free(dn); |
3097 | } | 3125 | } |
3098 | 3126 | ||
3099 | 3127 | ||
@@ -3109,20 +3137,20 @@ deserialization_master (const char *master_path, | |||
3109 | * @return NULL on error | 3137 | * @return NULL on error |
3110 | */ | 3138 | */ |
3111 | struct GNUNET_FS_Handle * | 3139 | struct GNUNET_FS_Handle * |
3112 | GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 3140 | GNUNET_FS_start(const struct GNUNET_CONFIGURATION_Handle *cfg, |
3113 | const char *client_name, | 3141 | const char *client_name, |
3114 | GNUNET_FS_ProgressCallback upcb, | 3142 | GNUNET_FS_ProgressCallback upcb, |
3115 | void *upcb_cls, | 3143 | void *upcb_cls, |
3116 | enum GNUNET_FS_Flags flags, | 3144 | enum GNUNET_FS_Flags flags, |
3117 | ...) | 3145 | ...) |
3118 | { | 3146 | { |
3119 | struct GNUNET_FS_Handle *ret; | 3147 | struct GNUNET_FS_Handle *ret; |
3120 | enum GNUNET_FS_OPTIONS opt; | 3148 | enum GNUNET_FS_OPTIONS opt; |
3121 | va_list ap; | 3149 | va_list ap; |
3122 | 3150 | ||
3123 | ret = GNUNET_new (struct GNUNET_FS_Handle); | 3151 | ret = GNUNET_new(struct GNUNET_FS_Handle); |
3124 | ret->cfg = cfg; | 3152 | ret->cfg = cfg; |
3125 | ret->client_name = GNUNET_strdup (client_name); | 3153 | ret->client_name = GNUNET_strdup(client_name); |
3126 | ret->upcb = upcb; | 3154 | ret->upcb = upcb; |
3127 | ret->upcb_cls = upcb_cls; | 3155 | ret->upcb_cls = upcb_cls; |
3128 | ret->flags = flags; | 3156 | ret->flags = flags; |
@@ -3130,44 +3158,46 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3130 | ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; | 3158 | ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; |
3131 | ret->avg_block_latency = | 3159 | ret->avg_block_latency = |
3132 | GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ | 3160 | GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ |
3133 | va_start (ap, flags); | 3161 | va_start(ap, flags); |
3134 | while (GNUNET_FS_OPTIONS_END != | 3162 | while (GNUNET_FS_OPTIONS_END != |
3135 | (opt = GNUNET_VA_ARG_ENUM (ap, GNUNET_FS_OPTIONS))) | 3163 | (opt = GNUNET_VA_ARG_ENUM(ap, GNUNET_FS_OPTIONS))) |
3136 | { | ||
3137 | switch (opt) | ||
3138 | { | 3164 | { |
3139 | case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM: | 3165 | switch (opt) |
3140 | ret->max_parallel_downloads = va_arg (ap, unsigned int); | 3166 | { |
3167 | case GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM: | ||
3168 | ret->max_parallel_downloads = va_arg(ap, unsigned int); | ||
3141 | 3169 | ||
3142 | break; | 3170 | break; |
3143 | case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM: | ||
3144 | ret->max_parallel_requests = va_arg (ap, unsigned int); | ||
3145 | 3171 | ||
3146 | break; | 3172 | case GNUNET_FS_OPTIONS_REQUEST_PARALLELISM: |
3147 | default: | 3173 | ret->max_parallel_requests = va_arg(ap, unsigned int); |
3148 | GNUNET_break (0); | 3174 | |
3149 | GNUNET_free (ret->client_name); | 3175 | break; |
3150 | GNUNET_free (ret); | 3176 | |
3151 | va_end (ap); | 3177 | default: |
3152 | return NULL; | 3178 | GNUNET_break(0); |
3179 | GNUNET_free(ret->client_name); | ||
3180 | GNUNET_free(ret); | ||
3181 | va_end(ap); | ||
3182 | return NULL; | ||
3183 | } | ||
3153 | } | 3184 | } |
3154 | } | 3185 | va_end(ap); |
3155 | va_end (ap); | ||
3156 | if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) | 3186 | if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) |
3157 | { | 3187 | { |
3158 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 3188 | deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
3159 | &deserialize_publish_file, | 3189 | &deserialize_publish_file, |
3160 | ret); | 3190 | ret); |
3161 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | 3191 | deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_SEARCH, |
3162 | &deserialize_search_file, | 3192 | &deserialize_search_file, |
3163 | ret); | 3193 | ret); |
3164 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 3194 | deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
3165 | &deserialize_download_file, | 3195 | &deserialize_download_file, |
3166 | ret); | 3196 | ret); |
3167 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 3197 | deserialization_master(GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
3168 | &deserialize_unindex_file, | 3198 | &deserialize_unindex_file, |
3169 | ret); | 3199 | ret); |
3170 | } | 3200 | } |
3171 | return ret; | 3201 | return ret; |
3172 | } | 3202 | } |
3173 | 3203 | ||
@@ -3182,14 +3212,14 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3182 | * @param h handle that was returned from #GNUNET_FS_start() | 3212 | * @param h handle that was returned from #GNUNET_FS_start() |
3183 | */ | 3213 | */ |
3184 | void | 3214 | void |
3185 | GNUNET_FS_stop (struct GNUNET_FS_Handle *h) | 3215 | GNUNET_FS_stop(struct GNUNET_FS_Handle *h) |
3186 | { | 3216 | { |
3187 | while (NULL != h->top_head) | 3217 | while (NULL != h->top_head) |
3188 | h->top_head->ssf (h->top_head->ssf_cls); | 3218 | h->top_head->ssf(h->top_head->ssf_cls); |
3189 | if (NULL != h->queue_job) | 3219 | if (NULL != h->queue_job) |
3190 | GNUNET_SCHEDULER_cancel (h->queue_job); | 3220 | GNUNET_SCHEDULER_cancel(h->queue_job); |
3191 | GNUNET_free (h->client_name); | 3221 | GNUNET_free(h->client_name); |
3192 | GNUNET_free (h); | 3222 | GNUNET_free(h); |
3193 | } | 3223 | } |
3194 | 3224 | ||
3195 | 3225 | ||