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