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 | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/fs')
76 files changed, 16812 insertions, 16591 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h index 294a433fc..4c433e774 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h | |||
@@ -50,7 +50,8 @@ | |||
50 | /** | 50 | /** |
51 | * @brief content hash key | 51 | * @brief content hash key |
52 | */ | 52 | */ |
53 | struct ContentHashKey { | 53 | struct ContentHashKey |
54 | { | ||
54 | /** | 55 | /** |
55 | * Hash of the original content, used for encryption. | 56 | * Hash of the original content, used for encryption. |
56 | */ | 57 | */ |
@@ -70,7 +71,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
70 | * Message sent from a GNUnet (fs) publishing activity to sign | 71 | * Message sent from a GNUnet (fs) publishing activity to sign |
71 | * a LOC URI. | 72 | * a LOC URI. |
72 | */ | 73 | */ |
73 | struct RequestLocSignatureMessage { | 74 | struct RequestLocSignatureMessage |
75 | { | ||
74 | /** | 76 | /** |
75 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN. | 77 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN. |
76 | */ | 78 | */ |
@@ -102,7 +104,8 @@ struct RequestLocSignatureMessage { | |||
102 | /** | 104 | /** |
103 | * Message sent from the service with the signed LOC URI. | 105 | * Message sent from the service with the signed LOC URI. |
104 | */ | 106 | */ |
105 | struct ResponseLocSignatureMessage { | 107 | struct ResponseLocSignatureMessage |
108 | { | ||
106 | /** | 109 | /** |
107 | * Message type will be | 110 | * Message type will be |
108 | * #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE. | 111 | * #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE. |
@@ -145,7 +148,8 @@ struct ResponseLocSignatureMessage { | |||
145 | * computing it; this is an optimization that should be safe given | 148 | * computing it; this is an optimization that should be safe given |
146 | * that the client is not our adversary). | 149 | * that the client is not our adversary). |
147 | */ | 150 | */ |
148 | struct IndexStartMessage { | 151 | struct IndexStartMessage |
152 | { | ||
149 | /** | 153 | /** |
150 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_INDEX_START. | 154 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_INDEX_START. |
151 | */ | 155 | */ |
@@ -188,7 +192,8 @@ struct IndexStartMessage { | |||
188 | * Message send by FS service in response to a request | 192 | * Message send by FS service in response to a request |
189 | * asking for a list of all indexed files. | 193 | * asking for a list of all indexed files. |
190 | */ | 194 | */ |
191 | struct IndexInfoMessage { | 195 | struct IndexInfoMessage |
196 | { | ||
192 | /** | 197 | /** |
193 | * Message type will be | 198 | * Message type will be |
194 | * #GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY. | 199 | * #GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY. |
@@ -218,7 +223,8 @@ struct IndexInfoMessage { | |||
218 | * files and response with a confirmation message (even if the file | 223 | * files and response with a confirmation message (even if the file |
219 | * was already not on the list). | 224 | * was already not on the list). |
220 | */ | 225 | */ |
221 | struct UnindexMessage { | 226 | struct UnindexMessage |
227 | { | ||
222 | /** | 228 | /** |
223 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_UNINDEX. | 229 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_UNINDEX. |
224 | */ | 230 | */ |
@@ -259,7 +265,8 @@ struct UnindexMessage { | |||
259 | * Message sent from a GNUnet (fs) search activity to the | 265 | * Message sent from a GNUnet (fs) search activity to the |
260 | * gnunet-service-fs to start a search. | 266 | * gnunet-service-fs to start a search. |
261 | */ | 267 | */ |
262 | struct SearchMessage { | 268 | struct SearchMessage |
269 | { | ||
263 | /** | 270 | /** |
264 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_START_SEARCH. | 271 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_START_SEARCH. |
265 | */ | 272 | */ |
@@ -318,7 +325,8 @@ struct SearchMessage { | |||
318 | * single response are considered done. This message is transmitted | 325 | * single response are considered done. This message is transmitted |
319 | * between peers. | 326 | * between peers. |
320 | */ | 327 | */ |
321 | struct PutMessage { | 328 | struct PutMessage |
329 | { | ||
322 | /** | 330 | /** |
323 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT. | 331 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT. |
324 | */ | 332 | */ |
@@ -343,7 +351,8 @@ struct PutMessage { | |||
343 | * single response are considered done. This message is transmitted | 351 | * single response are considered done. This message is transmitted |
344 | * between the service and a client. | 352 | * between the service and a client. |
345 | */ | 353 | */ |
346 | struct ClientPutMessage { | 354 | struct ClientPutMessage |
355 | { | ||
347 | /** | 356 | /** |
348 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT. | 357 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT. |
349 | */ | 358 | */ |
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 | ||
diff --git a/src/fs/fs_api.h b/src/fs/fs_api.h index dcc487eb1..f7eb40b42 100644 --- a/src/fs/fs_api.h +++ b/src/fs/fs_api.h | |||
@@ -90,7 +90,8 @@ | |||
90 | * @brief complete information needed | 90 | * @brief complete information needed |
91 | * to download a file. | 91 | * to download a file. |
92 | */ | 92 | */ |
93 | struct FileIdentifier { | 93 | struct FileIdentifier |
94 | { | ||
94 | /** | 95 | /** |
95 | * Total size of the file in bytes. (network byte order (!)) | 96 | * Total size of the file in bytes. (network byte order (!)) |
96 | */ | 97 | */ |
@@ -107,7 +108,8 @@ struct FileIdentifier { | |||
107 | * Information about a file and its location | 108 | * Information about a file and its location |
108 | * (peer claiming to share the file). | 109 | * (peer claiming to share the file). |
109 | */ | 110 | */ |
110 | struct Location { | 111 | struct Location |
112 | { | ||
111 | /** | 113 | /** |
112 | * Information about the shared file. | 114 | * Information about the shared file. |
113 | */ | 115 | */ |
@@ -133,7 +135,8 @@ struct Location { | |||
133 | /** | 135 | /** |
134 | * Types of URIs. | 136 | * Types of URIs. |
135 | */ | 137 | */ |
136 | enum GNUNET_FS_UriType { | 138 | enum GNUNET_FS_UriType |
139 | { | ||
137 | /** | 140 | /** |
138 | * Content-hash-key (simple file). | 141 | * Content-hash-key (simple file). |
139 | */ | 142 | */ |
@@ -159,14 +162,17 @@ enum GNUNET_FS_UriType { | |||
159 | /** | 162 | /** |
160 | * A Universal Resource Identifier (URI), opaque. | 163 | * A Universal Resource Identifier (URI), opaque. |
161 | */ | 164 | */ |
162 | struct GNUNET_FS_Uri { | 165 | struct GNUNET_FS_Uri |
166 | { | ||
163 | /** | 167 | /** |
164 | * Type of the URI. | 168 | * Type of the URI. |
165 | */ | 169 | */ |
166 | enum GNUNET_FS_UriType type; | 170 | enum GNUNET_FS_UriType type; |
167 | 171 | ||
168 | union { | 172 | union |
169 | struct { | 173 | { |
174 | struct | ||
175 | { | ||
170 | /** | 176 | /** |
171 | * Keywords start with a '+' if they are mandatory (in which | 177 | * Keywords start with a '+' if they are mandatory (in which |
172 | * case the '+' is NOT part of the keyword) and with a simple | 178 | * case the '+' is NOT part of the keyword) and with a simple |
@@ -184,7 +190,8 @@ struct GNUNET_FS_Uri { | |||
184 | unsigned int keywordCount; | 190 | unsigned int keywordCount; |
185 | } ksk; | 191 | } ksk; |
186 | 192 | ||
187 | struct { | 193 | struct |
194 | { | ||
188 | /** | 195 | /** |
189 | * Identifier of the namespace. | 196 | * Identifier of the namespace. |
190 | */ | 197 | */ |
@@ -216,7 +223,8 @@ struct GNUNET_FS_Uri { | |||
216 | * Information for a file or directory that is | 223 | * Information for a file or directory that is |
217 | * about to be published. | 224 | * about to be published. |
218 | */ | 225 | */ |
219 | struct GNUNET_FS_FileInformation { | 226 | struct GNUNET_FS_FileInformation |
227 | { | ||
220 | /** | 228 | /** |
221 | * Files in a directory are kept as a linked list. | 229 | * Files in a directory are kept as a linked list. |
222 | */ | 230 | */ |
@@ -295,11 +303,13 @@ struct GNUNET_FS_FileInformation { | |||
295 | /** | 303 | /** |
296 | * Data describing either the file or the directory. | 304 | * Data describing either the file or the directory. |
297 | */ | 305 | */ |
298 | union { | 306 | union |
307 | { | ||
299 | /** | 308 | /** |
300 | * Data for a file. | 309 | * Data for a file. |
301 | */ | 310 | */ |
302 | struct { | 311 | struct |
312 | { | ||
303 | /** | 313 | /** |
304 | * Function that can be used to read the data for the file. | 314 | * Function that can be used to read the data for the file. |
305 | */ | 315 | */ |
@@ -343,7 +353,8 @@ struct GNUNET_FS_FileInformation { | |||
343 | /** | 353 | /** |
344 | * Data for a directory. | 354 | * Data for a directory. |
345 | */ | 355 | */ |
346 | struct { | 356 | struct |
357 | { | ||
347 | /** | 358 | /** |
348 | * Linked list of entries in the directory. | 359 | * Linked list of entries in the directory. |
349 | */ | 360 | */ |
@@ -388,7 +399,8 @@ struct GNUNET_FS_FileInformation { | |||
388 | /** | 399 | /** |
389 | * Priorities for the queue. | 400 | * Priorities for the queue. |
390 | */ | 401 | */ |
391 | enum GNUNET_FS_QueuePriority { | 402 | enum GNUNET_FS_QueuePriority |
403 | { | ||
392 | /** | 404 | /** |
393 | * This is a probe (low priority). | 405 | * This is a probe (low priority). |
394 | */ | 406 | */ |
@@ -404,7 +416,8 @@ enum GNUNET_FS_QueuePriority { | |||
404 | /** | 416 | /** |
405 | * Entry in the job queue. | 417 | * Entry in the job queue. |
406 | */ | 418 | */ |
407 | struct GNUNET_FS_QueueEntry { | 419 | struct GNUNET_FS_QueueEntry |
420 | { | ||
408 | /** | 421 | /** |
409 | * This is a linked list. | 422 | * This is a linked list. |
410 | */ | 423 | */ |
@@ -481,7 +494,8 @@ struct GNUNET_FS_QueueEntry { | |||
481 | /** | 494 | /** |
482 | * Information we store for each search result. | 495 | * Information we store for each search result. |
483 | */ | 496 | */ |
484 | struct GNUNET_FS_SearchResult { | 497 | struct GNUNET_FS_SearchResult |
498 | { | ||
485 | /** | 499 | /** |
486 | * File-sharing context this result belongs to. | 500 | * File-sharing context this result belongs to. |
487 | */ | 501 | */ |
@@ -556,7 +570,7 @@ struct GNUNET_FS_SearchResult { | |||
556 | * complete on time (and that will need to be cancelled if we clean | 570 | * complete on time (and that will need to be cancelled if we clean |
557 | * up the search result before then). | 571 | * up the search result before then). |
558 | */ | 572 | */ |
559 | struct GNUNET_SCHEDULER_Task * probe_cancel_task; | 573 | struct GNUNET_SCHEDULER_Task *probe_cancel_task; |
560 | 574 | ||
561 | /** | 575 | /** |
562 | * When did the current probe become active? | 576 | * When did the current probe become active? |
@@ -611,12 +625,12 @@ struct GNUNET_FS_SearchResult { | |||
611 | * @return queue handle | 625 | * @return queue handle |
612 | */ | 626 | */ |
613 | struct GNUNET_FS_QueueEntry * | 627 | struct GNUNET_FS_QueueEntry * |
614 | GNUNET_FS_queue_(struct GNUNET_FS_Handle *h, | 628 | GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, |
615 | GNUNET_SCHEDULER_TaskCallback start, | 629 | GNUNET_SCHEDULER_TaskCallback start, |
616 | GNUNET_SCHEDULER_TaskCallback stop, | 630 | GNUNET_SCHEDULER_TaskCallback stop, |
617 | void *cls, | 631 | void *cls, |
618 | unsigned int blocks, | 632 | unsigned int blocks, |
619 | enum GNUNET_FS_QueuePriority priority); | 633 | enum GNUNET_FS_QueuePriority priority); |
620 | 634 | ||
621 | 635 | ||
622 | /** | 636 | /** |
@@ -625,7 +639,7 @@ GNUNET_FS_queue_(struct GNUNET_FS_Handle *h, | |||
625 | * @param qe handle for the job | 639 | * @param qe handle for the job |
626 | */ | 640 | */ |
627 | void | 641 | void |
628 | GNUNET_FS_dequeue_(struct GNUNET_FS_QueueEntry *qe); | 642 | GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe); |
629 | 643 | ||
630 | 644 | ||
631 | /** | 645 | /** |
@@ -645,11 +659,11 @@ GNUNET_FS_dequeue_(struct GNUNET_FS_QueueEntry *qe); | |||
645 | * @return number of bytes written, usually "max", 0 on error | 659 | * @return number of bytes written, usually "max", 0 on error |
646 | */ | 660 | */ |
647 | size_t | 661 | size_t |
648 | GNUNET_FS_data_reader_file_(void *cls, | 662 | GNUNET_FS_data_reader_file_ (void *cls, |
649 | uint64_t offset, | 663 | uint64_t offset, |
650 | size_t max, | 664 | size_t max, |
651 | void *buf, | 665 | void *buf, |
652 | char **emsg); | 666 | char **emsg); |
653 | 667 | ||
654 | 668 | ||
655 | /** | 669 | /** |
@@ -659,7 +673,7 @@ GNUNET_FS_data_reader_file_(void *cls, | |||
659 | * @return closure to use | 673 | * @return closure to use |
660 | */ | 674 | */ |
661 | void * | 675 | void * |
662 | GNUNET_FS_make_file_reader_context_(const char *filename); | 676 | GNUNET_FS_make_file_reader_context_ (const char *filename); |
663 | 677 | ||
664 | 678 | ||
665 | 679 | ||
@@ -680,11 +694,11 @@ GNUNET_FS_make_file_reader_context_(const char *filename); | |||
680 | * @return number of bytes written, usually @a max, 0 on error | 694 | * @return number of bytes written, usually @a max, 0 on error |
681 | */ | 695 | */ |
682 | size_t | 696 | size_t |
683 | GNUNET_FS_data_reader_copy_(void *cls, | 697 | GNUNET_FS_data_reader_copy_ (void *cls, |
684 | uint64_t offset, | 698 | uint64_t offset, |
685 | size_t max, | 699 | size_t max, |
686 | void *buf, | 700 | void *buf, |
687 | char **emsg); | 701 | char **emsg); |
688 | 702 | ||
689 | 703 | ||
690 | /** | 704 | /** |
@@ -703,8 +717,8 @@ GNUNET_FS_data_reader_copy_(void *cls, | |||
703 | * field in the `struct GNUNET_FS_ProgressInfo`. | 717 | * field in the `struct GNUNET_FS_ProgressInfo`. |
704 | */ | 718 | */ |
705 | void * | 719 | void * |
706 | GNUNET_FS_search_probe_progress_(void *cls, | 720 | GNUNET_FS_search_probe_progress_ (void *cls, |
707 | const struct GNUNET_FS_ProgressInfo *info); | 721 | const struct GNUNET_FS_ProgressInfo *info); |
708 | 722 | ||
709 | 723 | ||
710 | /** | 724 | /** |
@@ -713,7 +727,7 @@ GNUNET_FS_search_probe_progress_(void *cls, | |||
713 | * @param cls `struct GNUNET_FS_PublishContext` identifies the upload | 727 | * @param cls `struct GNUNET_FS_PublishContext` identifies the upload |
714 | */ | 728 | */ |
715 | void | 729 | void |
716 | GNUNET_FS_publish_main_(void *cls); | 730 | GNUNET_FS_publish_main_ (void *cls); |
717 | 731 | ||
718 | 732 | ||
719 | /** | 733 | /** |
@@ -724,8 +738,8 @@ GNUNET_FS_publish_main_(void *cls); | |||
724 | * @param file_id computed hash, NULL on error | 738 | * @param file_id computed hash, NULL on error |
725 | */ | 739 | */ |
726 | void | 740 | void |
727 | GNUNET_FS_unindex_process_hash_(void *cls, | 741 | GNUNET_FS_unindex_process_hash_ (void *cls, |
728 | const struct GNUNET_HashCode *file_id); | 742 | const struct GNUNET_HashCode *file_id); |
729 | 743 | ||
730 | 744 | ||
731 | /** | 745 | /** |
@@ -734,7 +748,7 @@ GNUNET_FS_unindex_process_hash_(void *cls, | |||
734 | * @param uc context for the unindex operation. | 748 | * @param uc context for the unindex operation. |
735 | */ | 749 | */ |
736 | void | 750 | void |
737 | GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc); | 751 | GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc); |
738 | 752 | ||
739 | 753 | ||
740 | /** | 754 | /** |
@@ -743,7 +757,7 @@ GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc); | |||
743 | * @param uc context for the unindex operation. | 757 | * @param uc context for the unindex operation. |
744 | */ | 758 | */ |
745 | void | 759 | void |
746 | GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc); | 760 | GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc); |
747 | 761 | ||
748 | 762 | ||
749 | /** | 763 | /** |
@@ -757,10 +771,10 @@ GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc); | |||
757 | * @return value returned from callback | 771 | * @return value returned from callback |
758 | */ | 772 | */ |
759 | void * | 773 | void * |
760 | GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, | 774 | GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, |
761 | struct GNUNET_FS_PublishContext *pc, | 775 | struct GNUNET_FS_PublishContext *pc, |
762 | const struct GNUNET_FS_FileInformation *p, | 776 | const struct GNUNET_FS_FileInformation *p, |
763 | uint64_t offset); | 777 | uint64_t offset); |
764 | 778 | ||
765 | 779 | ||
766 | /** | 780 | /** |
@@ -771,8 +785,8 @@ GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, | |||
771 | * @param dc overall download context | 785 | * @param dc overall download context |
772 | */ | 786 | */ |
773 | void | 787 | void |
774 | GNUNET_FS_download_make_status_(struct GNUNET_FS_ProgressInfo *pi, | 788 | GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, |
775 | struct GNUNET_FS_DownloadContext *dc); | 789 | struct GNUNET_FS_DownloadContext *dc); |
776 | 790 | ||
777 | 791 | ||
778 | /** | 792 | /** |
@@ -782,7 +796,7 @@ GNUNET_FS_download_make_status_(struct GNUNET_FS_ProgressInfo *pi, | |||
782 | * @param cls the 'struct GNUNET_FS_DownloadContext' | 796 | * @param cls the 'struct GNUNET_FS_DownloadContext' |
783 | */ | 797 | */ |
784 | void | 798 | void |
785 | GNUNET_FS_download_start_task_(void *cls); | 799 | GNUNET_FS_download_start_task_ (void *cls); |
786 | 800 | ||
787 | 801 | ||
788 | 802 | ||
@@ -795,9 +809,9 @@ GNUNET_FS_download_start_task_(void *cls); | |||
795 | * @param offset where we are in the file (for progress) | 809 | * @param offset where we are in the file (for progress) |
796 | */ | 810 | */ |
797 | void | 811 | void |
798 | GNUNET_FS_unindex_make_status_(struct GNUNET_FS_ProgressInfo *pi, | 812 | GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, |
799 | struct GNUNET_FS_UnindexContext *uc, | 813 | struct GNUNET_FS_UnindexContext *uc, |
800 | uint64_t offset); | 814 | uint64_t offset); |
801 | 815 | ||
802 | /** | 816 | /** |
803 | * Fill in all of the generic fields for a search event and | 817 | * Fill in all of the generic fields for a search event and |
@@ -809,9 +823,9 @@ GNUNET_FS_unindex_make_status_(struct GNUNET_FS_ProgressInfo *pi, | |||
809 | * @return value returned by the callback | 823 | * @return value returned by the callback |
810 | */ | 824 | */ |
811 | void * | 825 | void * |
812 | GNUNET_FS_search_make_status_(struct GNUNET_FS_ProgressInfo *pi, | 826 | GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, |
813 | struct GNUNET_FS_Handle *h, | 827 | struct GNUNET_FS_Handle *h, |
814 | struct GNUNET_FS_SearchContext *sc); | 828 | struct GNUNET_FS_SearchContext *sc); |
815 | 829 | ||
816 | 830 | ||
817 | /** | 831 | /** |
@@ -820,7 +834,7 @@ GNUNET_FS_search_make_status_(struct GNUNET_FS_ProgressInfo *pi, | |||
820 | * @param uc context for the unindex operation. | 834 | * @param uc context for the unindex operation. |
821 | */ | 835 | */ |
822 | void | 836 | void |
823 | GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc); | 837 | GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc); |
824 | 838 | ||
825 | /** | 839 | /** |
826 | * Build the request and actually initiate the search using the | 840 | * Build the request and actually initiate the search using the |
@@ -830,7 +844,7 @@ GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc); | |||
830 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 844 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
831 | */ | 845 | */ |
832 | int | 846 | int |
833 | GNUNET_FS_search_start_searching_(struct GNUNET_FS_SearchContext *sc); | 847 | GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc); |
834 | 848 | ||
835 | /** | 849 | /** |
836 | * Start the downloading process (by entering the queue). | 850 | * Start the downloading process (by entering the queue). |
@@ -838,7 +852,7 @@ GNUNET_FS_search_start_searching_(struct GNUNET_FS_SearchContext *sc); | |||
838 | * @param dc our download context | 852 | * @param dc our download context |
839 | */ | 853 | */ |
840 | void | 854 | void |
841 | GNUNET_FS_download_start_downloading_(struct GNUNET_FS_DownloadContext *dc); | 855 | GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc); |
842 | 856 | ||
843 | 857 | ||
844 | /** | 858 | /** |
@@ -847,7 +861,7 @@ GNUNET_FS_download_start_downloading_(struct GNUNET_FS_DownloadContext *dc); | |||
847 | * @param sr the search result | 861 | * @param sr the search result |
848 | */ | 862 | */ |
849 | void | 863 | void |
850 | GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr); | 864 | GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr); |
851 | 865 | ||
852 | 866 | ||
853 | /** | 867 | /** |
@@ -858,9 +872,9 @@ GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr); | |||
858 | * @param ent entity identifier | 872 | * @param ent entity identifier |
859 | */ | 873 | */ |
860 | void | 874 | void |
861 | GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, | 875 | GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, |
862 | const char *ext, | 876 | const char *ext, |
863 | const char *ent); | 877 | const char *ent); |
864 | 878 | ||
865 | 879 | ||
866 | /** | 880 | /** |
@@ -871,9 +885,9 @@ GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, | |||
871 | * @param uni unique name of parent | 885 | * @param uni unique name of parent |
872 | */ | 886 | */ |
873 | void | 887 | void |
874 | GNUNET_FS_remove_sync_dir_(struct GNUNET_FS_Handle *h, | 888 | GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, |
875 | const char *ext, | 889 | const char *ext, |
876 | const char *uni); | 890 | const char *uni); |
877 | 891 | ||
878 | 892 | ||
879 | /** | 893 | /** |
@@ -885,7 +899,7 @@ GNUNET_FS_remove_sync_dir_(struct GNUNET_FS_Handle *h, | |||
885 | * @param fi the struct to sync | 899 | * @param fi the struct to sync |
886 | */ | 900 | */ |
887 | void | 901 | void |
888 | GNUNET_FS_file_information_sync_(struct GNUNET_FS_FileInformation *f); | 902 | GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f); |
889 | 903 | ||
890 | 904 | ||
891 | /** | 905 | /** |
@@ -897,7 +911,7 @@ GNUNET_FS_file_information_sync_(struct GNUNET_FS_FileInformation *f); | |||
897 | * @param pc the struct to sync | 911 | * @param pc the struct to sync |
898 | */ | 912 | */ |
899 | void | 913 | void |
900 | GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc); | 914 | GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc); |
901 | 915 | ||
902 | 916 | ||
903 | /** | 917 | /** |
@@ -909,7 +923,7 @@ GNUNET_FS_publish_sync_(struct GNUNET_FS_PublishContext *pc); | |||
909 | * @param uc the struct to sync | 923 | * @param uc the struct to sync |
910 | */ | 924 | */ |
911 | void | 925 | void |
912 | GNUNET_FS_unindex_sync_(struct GNUNET_FS_UnindexContext *uc); | 926 | GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc); |
913 | 927 | ||
914 | 928 | ||
915 | /** | 929 | /** |
@@ -921,7 +935,7 @@ GNUNET_FS_unindex_sync_(struct GNUNET_FS_UnindexContext *uc); | |||
921 | * @param sc the struct to sync | 935 | * @param sc the struct to sync |
922 | */ | 936 | */ |
923 | void | 937 | void |
924 | GNUNET_FS_search_sync_(struct GNUNET_FS_SearchContext *sc); | 938 | GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc); |
925 | 939 | ||
926 | 940 | ||
927 | /** | 941 | /** |
@@ -933,7 +947,7 @@ GNUNET_FS_search_sync_(struct GNUNET_FS_SearchContext *sc); | |||
933 | * @param sr the struct to sync | 947 | * @param sr the struct to sync |
934 | */ | 948 | */ |
935 | void | 949 | void |
936 | GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr); | 950 | GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr); |
937 | 951 | ||
938 | 952 | ||
939 | /** | 953 | /** |
@@ -945,7 +959,7 @@ GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr); | |||
945 | * @param dc the struct to sync | 959 | * @param dc the struct to sync |
946 | */ | 960 | */ |
947 | void | 961 | void |
948 | GNUNET_FS_download_sync_(struct GNUNET_FS_DownloadContext *dc); | 962 | GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc); |
949 | 963 | ||
950 | 964 | ||
951 | /** | 965 | /** |
@@ -955,7 +969,7 @@ GNUNET_FS_download_sync_(struct GNUNET_FS_DownloadContext *dc); | |||
955 | * @param cls the `struct GNUNET_FS_PublishContext` to signal for | 969 | * @param cls the `struct GNUNET_FS_PublishContext` to signal for |
956 | */ | 970 | */ |
957 | void | 971 | void |
958 | GNUNET_FS_publish_signal_suspend_(void *cls); | 972 | GNUNET_FS_publish_signal_suspend_ (void *cls); |
959 | 973 | ||
960 | 974 | ||
961 | /** | 975 | /** |
@@ -965,7 +979,7 @@ GNUNET_FS_publish_signal_suspend_(void *cls); | |||
965 | * @param cls the 'struct GNUNET_FS_SearchContext' to signal for | 979 | * @param cls the 'struct GNUNET_FS_SearchContext' to signal for |
966 | */ | 980 | */ |
967 | void | 981 | void |
968 | GNUNET_FS_search_signal_suspend_(void *cls); | 982 | GNUNET_FS_search_signal_suspend_ (void *cls); |
969 | 983 | ||
970 | 984 | ||
971 | /** | 985 | /** |
@@ -975,7 +989,7 @@ GNUNET_FS_search_signal_suspend_(void *cls); | |||
975 | * @param cls the `struct GNUNET_FS_DownloadContext` to signal for | 989 | * @param cls the `struct GNUNET_FS_DownloadContext` to signal for |
976 | */ | 990 | */ |
977 | void | 991 | void |
978 | GNUNET_FS_download_signal_suspend_(void *cls); | 992 | GNUNET_FS_download_signal_suspend_ (void *cls); |
979 | 993 | ||
980 | 994 | ||
981 | /** | 995 | /** |
@@ -985,7 +999,7 @@ GNUNET_FS_download_signal_suspend_(void *cls); | |||
985 | * @param cls the `struct GNUNET_FS_UnindexContext` to signal for | 999 | * @param cls the `struct GNUNET_FS_UnindexContext` to signal for |
986 | */ | 1000 | */ |
987 | void | 1001 | void |
988 | GNUNET_FS_unindex_signal_suspend_(void *cls); | 1002 | GNUNET_FS_unindex_signal_suspend_ (void *cls); |
989 | 1003 | ||
990 | 1004 | ||
991 | /** | 1005 | /** |
@@ -1001,7 +1015,8 @@ typedef void (*SuspendSignalFunction) (void *cls); | |||
1001 | * We track all of the top-level activities of FS | 1015 | * We track all of the top-level activities of FS |
1002 | * so that we can signal 'suspend' on shutdown. | 1016 | * so that we can signal 'suspend' on shutdown. |
1003 | */ | 1017 | */ |
1004 | struct TopLevelActivity { | 1018 | struct TopLevelActivity |
1019 | { | ||
1005 | /** | 1020 | /** |
1006 | * This is a doubly-linked list. | 1021 | * This is a doubly-linked list. |
1007 | */ | 1022 | */ |
@@ -1033,9 +1048,9 @@ struct TopLevelActivity { | |||
1033 | * @return fresh top-level activity handle | 1048 | * @return fresh top-level activity handle |
1034 | */ | 1049 | */ |
1035 | struct TopLevelActivity * | 1050 | struct TopLevelActivity * |
1036 | GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, | 1051 | GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, |
1037 | SuspendSignalFunction ssf, | 1052 | SuspendSignalFunction ssf, |
1038 | void *ssf_cls); | 1053 | void *ssf_cls); |
1039 | 1054 | ||
1040 | 1055 | ||
1041 | /** | 1056 | /** |
@@ -1045,15 +1060,16 @@ GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, | |||
1045 | * @param top top level activity entry | 1060 | * @param top top level activity entry |
1046 | */ | 1061 | */ |
1047 | void | 1062 | void |
1048 | GNUNET_FS_end_top(struct GNUNET_FS_Handle *h, | 1063 | GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, |
1049 | struct TopLevelActivity *top); | 1064 | struct TopLevelActivity *top); |
1050 | 1065 | ||
1051 | 1066 | ||
1052 | 1067 | ||
1053 | /** | 1068 | /** |
1054 | * Master context for most FS operations. | 1069 | * Master context for most FS operations. |
1055 | */ | 1070 | */ |
1056 | struct GNUNET_FS_Handle { | 1071 | struct GNUNET_FS_Handle |
1072 | { | ||
1057 | /** | 1073 | /** |
1058 | * Configuration to use. | 1074 | * Configuration to use. |
1059 | */ | 1075 | */ |
@@ -1118,13 +1134,13 @@ struct GNUNET_FS_Handle { | |||
1118 | * Task that processes the jobs in the running and pending queues | 1134 | * Task that processes the jobs in the running and pending queues |
1119 | * (and moves jobs around as needed). | 1135 | * (and moves jobs around as needed). |
1120 | */ | 1136 | */ |
1121 | struct GNUNET_SCHEDULER_Task * queue_job; | 1137 | struct GNUNET_SCHEDULER_Task *queue_job; |
1122 | 1138 | ||
1123 | /** | 1139 | /** |
1124 | * Task we use to report periodically to the application that | 1140 | * Task we use to report periodically to the application that |
1125 | * certain search probes (from @e probes_head) are still running. | 1141 | * certain search probes (from @e probes_head) are still running. |
1126 | */ | 1142 | */ |
1127 | struct GNUNET_SCHEDULER_Task * probe_ping_task; | 1143 | struct GNUNET_SCHEDULER_Task *probe_ping_task; |
1128 | 1144 | ||
1129 | /** | 1145 | /** |
1130 | * Average time we take for a single request to be satisfied. | 1146 | * Average time we take for a single request to be satisfied. |
@@ -1162,7 +1178,8 @@ struct GNUNET_FS_Handle { | |||
1162 | /** | 1178 | /** |
1163 | * Handle for controlling a publication process. | 1179 | * Handle for controlling a publication process. |
1164 | */ | 1180 | */ |
1165 | struct GNUNET_FS_PublishContext { | 1181 | struct GNUNET_FS_PublishContext |
1182 | { | ||
1166 | /** | 1183 | /** |
1167 | * Handle to the global fs context. | 1184 | * Handle to the global fs context. |
1168 | */ | 1185 | */ |
@@ -1241,7 +1258,7 @@ struct GNUNET_FS_PublishContext { | |||
1241 | * ID of the task performing the upload. NO_TASK if the upload has | 1258 | * ID of the task performing the upload. NO_TASK if the upload has |
1242 | * completed. | 1259 | * completed. |
1243 | */ | 1260 | */ |
1244 | struct GNUNET_SCHEDULER_Task * upload_task; | 1261 | struct GNUNET_SCHEDULER_Task *upload_task; |
1245 | 1262 | ||
1246 | /** | 1263 | /** |
1247 | * Storage space to reserve for the operation. | 1264 | * Storage space to reserve for the operation. |
@@ -1288,7 +1305,8 @@ struct GNUNET_FS_PublishContext { | |||
1288 | /** | 1305 | /** |
1289 | * Phases of unindex processing (state machine). | 1306 | * Phases of unindex processing (state machine). |
1290 | */ | 1307 | */ |
1291 | enum UnindexState { | 1308 | enum UnindexState |
1309 | { | ||
1292 | /** | 1310 | /** |
1293 | * We're currently hashing the file. | 1311 | * We're currently hashing the file. |
1294 | */ | 1312 | */ |
@@ -1331,7 +1349,8 @@ enum UnindexState { | |||
1331 | /** | 1349 | /** |
1332 | * Handle for controlling an unindexing operation. | 1350 | * Handle for controlling an unindexing operation. |
1333 | */ | 1351 | */ |
1334 | struct GNUNET_FS_UnindexContext { | 1352 | struct GNUNET_FS_UnindexContext |
1353 | { | ||
1335 | /** | 1354 | /** |
1336 | * The content hash key of the last block we processed, will in the | 1355 | * The content hash key of the last block we processed, will in the |
1337 | * end be set to the CHK from the URI. Used to remove the KBlocks. | 1356 | * end be set to the CHK from the URI. Used to remove the KBlocks. |
@@ -1451,7 +1470,8 @@ struct GNUNET_FS_UnindexContext { | |||
1451 | /** | 1470 | /** |
1452 | * Information we keep for each keyword in a keyword search. | 1471 | * Information we keep for each keyword in a keyword search. |
1453 | */ | 1472 | */ |
1454 | struct SearchRequestEntry { | 1473 | struct SearchRequestEntry |
1474 | { | ||
1455 | /** | 1475 | /** |
1456 | * Hash of the public key, also known as the query. | 1476 | * Hash of the public key, also known as the query. |
1457 | */ | 1477 | */ |
@@ -1489,7 +1509,8 @@ struct SearchRequestEntry { | |||
1489 | /** | 1509 | /** |
1490 | * Handle for controlling a search. | 1510 | * Handle for controlling a search. |
1491 | */ | 1511 | */ |
1492 | struct GNUNET_FS_SearchContext { | 1512 | struct GNUNET_FS_SearchContext |
1513 | { | ||
1493 | /** | 1514 | /** |
1494 | * Handle to the global FS context. | 1515 | * Handle to the global FS context. |
1495 | */ | 1516 | */ |
@@ -1585,7 +1606,8 @@ struct GNUNET_FS_SearchContext { | |||
1585 | * order of progression is linear through the states, alternatives | 1606 | * order of progression is linear through the states, alternatives |
1586 | * are documented in the comments. | 1607 | * are documented in the comments. |
1587 | */ | 1608 | */ |
1588 | enum BlockRequestState { | 1609 | enum BlockRequestState |
1610 | { | ||
1589 | /** | 1611 | /** |
1590 | * Initial state, block has only been allocated (since it is | 1612 | * Initial state, block has only been allocated (since it is |
1591 | * relevant to the overall download request). | 1613 | * relevant to the overall download request). |
@@ -1652,7 +1674,8 @@ enum BlockRequestState { | |||
1652 | /** | 1674 | /** |
1653 | * Information about an active download request. | 1675 | * Information about an active download request. |
1654 | */ | 1676 | */ |
1655 | struct DownloadRequest { | 1677 | struct DownloadRequest |
1678 | { | ||
1656 | /** | 1679 | /** |
1657 | * Parent in the CHK-tree. | 1680 | * Parent in the CHK-tree. |
1658 | */ | 1681 | */ |
@@ -1704,7 +1727,7 @@ struct DownloadRequest { | |||
1704 | * @param dr request to free | 1727 | * @param dr request to free |
1705 | */ | 1728 | */ |
1706 | void | 1729 | void |
1707 | GNUNET_FS_free_download_request_(struct DownloadRequest *dr); | 1730 | GNUNET_FS_free_download_request_ (struct DownloadRequest *dr); |
1708 | 1731 | ||
1709 | 1732 | ||
1710 | /** | 1733 | /** |
@@ -1713,13 +1736,14 @@ GNUNET_FS_free_download_request_(struct DownloadRequest *dr); | |||
1713 | * @param sr result to start pinging for. | 1736 | * @param sr result to start pinging for. |
1714 | */ | 1737 | */ |
1715 | void | 1738 | void |
1716 | GNUNET_FS_stop_probe_ping_task_(struct GNUNET_FS_SearchResult *sr); | 1739 | GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr); |
1717 | 1740 | ||
1718 | 1741 | ||
1719 | /** | 1742 | /** |
1720 | * Context for controlling a download. | 1743 | * Context for controlling a download. |
1721 | */ | 1744 | */ |
1722 | struct GNUNET_FS_DownloadContext { | 1745 | struct GNUNET_FS_DownloadContext |
1746 | { | ||
1723 | /** | 1747 | /** |
1724 | * Global FS context. | 1748 | * Global FS context. |
1725 | */ | 1749 | */ |
diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c index ae7727cf0..5e1e0af5e 100644 --- a/src/fs/fs_directory.c +++ b/src/fs/fs_directory.c | |||
@@ -51,18 +51,21 @@ | |||
51 | * we have no mime-type information (treat as #GNUNET_NO) | 51 | * we have no mime-type information (treat as #GNUNET_NO) |
52 | */ | 52 | */ |
53 | int | 53 | int |
54 | GNUNET_FS_meta_data_test_for_directory(const struct GNUNET_CONTAINER_MetaData *md) | 54 | GNUNET_FS_meta_data_test_for_directory (const struct |
55 | GNUNET_CONTAINER_MetaData *md) | ||
55 | { | 56 | { |
56 | char *mime; | 57 | char *mime; |
57 | int ret; | 58 | int ret; |
58 | 59 | ||
59 | if (NULL == md) | 60 | if (NULL == md) |
60 | return GNUNET_SYSERR; | 61 | return GNUNET_SYSERR; |
61 | mime = GNUNET_CONTAINER_meta_data_get_by_type(md, EXTRACTOR_METATYPE_MIMETYPE); | 62 | mime = GNUNET_CONTAINER_meta_data_get_by_type (md, |
63 | EXTRACTOR_METATYPE_MIMETYPE); | ||
62 | if (NULL == mime) | 64 | if (NULL == mime) |
63 | return GNUNET_SYSERR; | 65 | return GNUNET_SYSERR; |
64 | ret = (0 == strcasecmp(mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES : GNUNET_NO; | 66 | ret = (0 == strcasecmp (mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES : |
65 | GNUNET_free(mime); | 67 | GNUNET_NO; |
68 | GNUNET_free (mime); | ||
66 | return ret; | 69 | return ret; |
67 | } | 70 | } |
68 | 71 | ||
@@ -74,30 +77,31 @@ GNUNET_FS_meta_data_test_for_directory(const struct GNUNET_CONTAINER_MetaData *m | |||
74 | * @param md metadata to add mimetype to | 77 | * @param md metadata to add mimetype to |
75 | */ | 78 | */ |
76 | void | 79 | void |
77 | GNUNET_FS_meta_data_make_directory(struct GNUNET_CONTAINER_MetaData *md) | 80 | GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md) |
78 | { | 81 | { |
79 | char *mime; | 82 | char *mime; |
80 | 83 | ||
81 | mime = | 84 | mime = |
82 | GNUNET_CONTAINER_meta_data_get_by_type(md, EXTRACTOR_METATYPE_MIMETYPE); | 85 | GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE); |
83 | if (mime != NULL) | 86 | if (mime != NULL) |
84 | { | 87 | { |
85 | GNUNET_break(0 == strcmp(mime, GNUNET_FS_DIRECTORY_MIME)); | 88 | GNUNET_break (0 == strcmp (mime, GNUNET_FS_DIRECTORY_MIME)); |
86 | GNUNET_free(mime); | 89 | GNUNET_free (mime); |
87 | return; | 90 | return; |
88 | } | 91 | } |
89 | GNUNET_CONTAINER_meta_data_insert(md, "<gnunet>", | 92 | GNUNET_CONTAINER_meta_data_insert (md, "<gnunet>", |
90 | EXTRACTOR_METATYPE_MIMETYPE, | 93 | EXTRACTOR_METATYPE_MIMETYPE, |
91 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 94 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
92 | GNUNET_FS_DIRECTORY_MIME, | 95 | GNUNET_FS_DIRECTORY_MIME, |
93 | strlen(GNUNET_FS_DIRECTORY_MIME) + 1); | 96 | strlen (GNUNET_FS_DIRECTORY_MIME) + 1); |
94 | } | 97 | } |
95 | 98 | ||
96 | 99 | ||
97 | /** | 100 | /** |
98 | * Closure for 'find_full_data'. | 101 | * Closure for 'find_full_data'. |
99 | */ | 102 | */ |
100 | struct GetFullDataClosure { | 103 | struct GetFullDataClosure |
104 | { | ||
101 | /** | 105 | /** |
102 | * Extracted binary meta data. | 106 | * Extracted binary meta data. |
103 | */ | 107 | */ |
@@ -128,22 +132,22 @@ struct GetFullDataClosure { | |||
128 | * @return 0 to continue extracting, 1 to abort | 132 | * @return 0 to continue extracting, 1 to abort |
129 | */ | 133 | */ |
130 | static int | 134 | static int |
131 | find_full_data(void *cls, const char *plugin_name, | 135 | find_full_data (void *cls, const char *plugin_name, |
132 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, | 136 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, |
133 | const char *data_mime_type, const char *data, size_t data_len) | 137 | const char *data_mime_type, const char *data, size_t data_len) |
134 | { | 138 | { |
135 | struct GetFullDataClosure *gfdc = cls; | 139 | struct GetFullDataClosure *gfdc = cls; |
136 | 140 | ||
137 | if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) | 141 | if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) |
142 | { | ||
143 | gfdc->size = data_len; | ||
144 | if (data_len > 0) | ||
138 | { | 145 | { |
139 | gfdc->size = data_len; | 146 | gfdc->data = GNUNET_malloc (data_len); |
140 | if (data_len > 0) | 147 | GNUNET_memcpy (gfdc->data, data, data_len); |
141 | { | ||
142 | gfdc->data = GNUNET_malloc(data_len); | ||
143 | GNUNET_memcpy(gfdc->data, data, data_len); | ||
144 | } | ||
145 | return 1; | ||
146 | } | 148 | } |
149 | return 1; | ||
150 | } | ||
147 | return 0; | 151 | return 0; |
148 | } | 152 | } |
149 | 153 | ||
@@ -174,11 +178,11 @@ find_full_data(void *cls, const char *plugin_name, | |||
174 | * #GNUNET_SYSERR if @a data does not represent a directory | 178 | * #GNUNET_SYSERR if @a data does not represent a directory |
175 | */ | 179 | */ |
176 | int | 180 | int |
177 | GNUNET_FS_directory_list_contents(size_t size, | 181 | GNUNET_FS_directory_list_contents (size_t size, |
178 | const void *data, | 182 | const void *data, |
179 | uint64_t offset, | 183 | uint64_t offset, |
180 | GNUNET_FS_DirectoryEntryProcessor dep, | 184 | GNUNET_FS_DirectoryEntryProcessor dep, |
181 | void *dep_cls) | 185 | void *dep_cls) |
182 | { | 186 | { |
183 | struct GetFullDataClosure full_data; | 187 | struct GetFullDataClosure full_data; |
184 | const char *cdata = data; | 188 | const char *cdata = data; |
@@ -193,130 +197,131 @@ GNUNET_FS_directory_list_contents(size_t size, | |||
193 | 197 | ||
194 | if ((offset == 0) && | 198 | if ((offset == 0) && |
195 | ((size < 8 + sizeof(uint32_t)) || | 199 | ((size < 8 + sizeof(uint32_t)) || |
196 | (0 != memcmp(cdata, | 200 | (0 != memcmp (cdata, |
197 | GNUNET_FS_DIRECTORY_MAGIC, | 201 | GNUNET_FS_DIRECTORY_MAGIC, |
198 | 8)))) | 202 | 8)))) |
199 | return GNUNET_SYSERR; | 203 | return GNUNET_SYSERR; |
200 | pos = offset; | 204 | pos = offset; |
201 | if (offset == 0) | 205 | if (offset == 0) |
206 | { | ||
207 | GNUNET_memcpy (&mdSize, | ||
208 | &cdata[8], | ||
209 | sizeof(uint32_t)); | ||
210 | mdSize = ntohl (mdSize); | ||
211 | if (mdSize > size - 8 - sizeof(uint32_t)) | ||
202 | { | 212 | { |
203 | GNUNET_memcpy(&mdSize, | 213 | /* invalid size */ |
204 | &cdata[8], | 214 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
205 | sizeof(uint32_t)); | 215 | _ ("MAGIC mismatch. This is not a GNUnet directory.\n")); |
206 | mdSize = ntohl(mdSize); | 216 | return GNUNET_SYSERR; |
207 | if (mdSize > size - 8 - sizeof(uint32_t)) | 217 | } |
208 | { | 218 | md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 + sizeof(uint32_t)], |
209 | /* invalid size */ | 219 | mdSize); |
210 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 220 | if (md == NULL) |
211 | _("MAGIC mismatch. This is not a GNUnet directory.\n")); | 221 | { |
212 | return GNUNET_SYSERR; | 222 | GNUNET_break (0); |
213 | } | 223 | return GNUNET_SYSERR; /* malformed ! */ |
214 | md = GNUNET_CONTAINER_meta_data_deserialize(&cdata[8 + sizeof(uint32_t)], | ||
215 | mdSize); | ||
216 | if (md == NULL) | ||
217 | { | ||
218 | GNUNET_break(0); | ||
219 | return GNUNET_SYSERR; /* malformed ! */ | ||
220 | } | ||
221 | dep(dep_cls, | ||
222 | NULL, | ||
223 | NULL, | ||
224 | md, | ||
225 | 0, | ||
226 | NULL); | ||
227 | GNUNET_CONTAINER_meta_data_destroy(md); | ||
228 | pos = 8 + sizeof(uint32_t) + mdSize; | ||
229 | } | 224 | } |
225 | dep (dep_cls, | ||
226 | NULL, | ||
227 | NULL, | ||
228 | md, | ||
229 | 0, | ||
230 | NULL); | ||
231 | GNUNET_CONTAINER_meta_data_destroy (md); | ||
232 | pos = 8 + sizeof(uint32_t) + mdSize; | ||
233 | } | ||
230 | while (pos < size) | 234 | while (pos < size) |
235 | { | ||
236 | /* find end of URI */ | ||
237 | if (cdata[pos] == '\0') | ||
231 | { | 238 | { |
232 | /* find end of URI */ | 239 | /* URI is never empty, must be end of block, |
233 | if (cdata[pos] == '\0') | 240 | * skip to next alignment */ |
234 | { | 241 | align = ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE; |
235 | /* URI is never empty, must be end of block, | 242 | if (align == pos) |
236 | * skip to next alignment */ | 243 | { |
237 | align = ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE; | 244 | /* if we were already aligned, still skip a block! */ |
238 | if (align == pos) | 245 | align += DBLOCK_SIZE; |
239 | { | 246 | } |
240 | /* if we were already aligned, still skip a block! */ | 247 | pos = align; |
241 | align += DBLOCK_SIZE; | 248 | if (pos >= size) |
242 | } | 249 | { |
243 | pos = align; | 250 | /* malformed - or partial download... */ |
244 | if (pos >= size) | 251 | break; |
245 | { | 252 | } |
246 | /* malformed - or partial download... */ | 253 | } |
247 | break; | 254 | epos = pos; |
248 | } | 255 | while ((epos < size) && (cdata[epos] != '\0')) |
249 | } | 256 | epos++; |
250 | epos = pos; | 257 | if (epos >= size) |
251 | while ((epos < size) && (cdata[epos] != '\0')) | 258 | return GNUNET_NO; /* malformed - or partial download */ |
252 | epos++; | 259 | |
253 | if (epos >= size) | 260 | uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg); |
254 | return GNUNET_NO; /* malformed - or partial download */ | 261 | pos = epos + 1; |
255 | 262 | if (NULL == uri) | |
256 | uri = GNUNET_FS_uri_parse(&cdata[pos], &emsg); | 263 | { |
257 | pos = epos + 1; | 264 | GNUNET_free (emsg); |
258 | if (NULL == uri) | 265 | pos--; /* go back to '\0' to force going to next alignment */ |
259 | { | 266 | continue; |
260 | GNUNET_free(emsg); | 267 | } |
261 | pos--; /* go back to '\0' to force going to next alignment */ | 268 | if (GNUNET_FS_uri_test_ksk (uri)) |
262 | continue; | 269 | { |
263 | } | 270 | GNUNET_FS_uri_destroy (uri); |
264 | if (GNUNET_FS_uri_test_ksk(uri)) | 271 | GNUNET_break (0); |
265 | { | 272 | return GNUNET_NO; /* illegal in directory! */ |
266 | GNUNET_FS_uri_destroy(uri); | 273 | } |
267 | GNUNET_break(0); | ||
268 | return GNUNET_NO; /* illegal in directory! */ | ||
269 | } | ||
270 | 274 | ||
271 | GNUNET_memcpy(&mdSize, | 275 | GNUNET_memcpy (&mdSize, |
272 | &cdata[pos], | 276 | &cdata[pos], |
273 | sizeof(uint32_t)); | 277 | sizeof(uint32_t)); |
274 | mdSize = ntohl(mdSize); | 278 | mdSize = ntohl (mdSize); |
275 | pos += sizeof(uint32_t); | 279 | pos += sizeof(uint32_t); |
276 | if (pos + mdSize > size) | 280 | if (pos + mdSize > size) |
277 | { | 281 | { |
278 | GNUNET_FS_uri_destroy(uri); | 282 | GNUNET_FS_uri_destroy (uri); |
279 | return GNUNET_NO; /* malformed - or partial download */ | 283 | return GNUNET_NO; /* malformed - or partial download */ |
280 | } | 284 | } |
281 | 285 | ||
282 | md = GNUNET_CONTAINER_meta_data_deserialize(&cdata[pos], | 286 | md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], |
283 | mdSize); | 287 | mdSize); |
284 | if (NULL == md) | 288 | if (NULL == md) |
285 | { | 289 | { |
286 | GNUNET_FS_uri_destroy(uri); | 290 | GNUNET_FS_uri_destroy (uri); |
287 | GNUNET_break(0); | 291 | GNUNET_break (0); |
288 | return GNUNET_NO; /* malformed ! */ | 292 | return GNUNET_NO; /* malformed ! */ |
289 | } | 293 | } |
290 | pos += mdSize; | 294 | pos += mdSize; |
291 | filename = | 295 | filename = |
292 | GNUNET_CONTAINER_meta_data_get_by_type(md, | 296 | GNUNET_CONTAINER_meta_data_get_by_type (md, |
293 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 297 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
294 | full_data.size = 0; | 298 | full_data.size = 0; |
295 | full_data.data = NULL; | 299 | full_data.data = NULL; |
296 | GNUNET_CONTAINER_meta_data_iterate(md, | 300 | GNUNET_CONTAINER_meta_data_iterate (md, |
297 | &find_full_data, | 301 | &find_full_data, |
298 | &full_data); | 302 | &full_data); |
299 | if (NULL != dep) | 303 | if (NULL != dep) |
300 | { | 304 | { |
301 | dep(dep_cls, | 305 | dep (dep_cls, |
302 | filename, | 306 | filename, |
303 | uri, | 307 | uri, |
304 | md, | 308 | md, |
305 | full_data.size, | 309 | full_data.size, |
306 | full_data.data); | 310 | full_data.data); |
307 | } | ||
308 | GNUNET_free_non_null(full_data.data); | ||
309 | GNUNET_free_non_null(filename); | ||
310 | GNUNET_CONTAINER_meta_data_destroy(md); | ||
311 | GNUNET_FS_uri_destroy(uri); | ||
312 | } | 311 | } |
312 | GNUNET_free_non_null (full_data.data); | ||
313 | GNUNET_free_non_null (filename); | ||
314 | GNUNET_CONTAINER_meta_data_destroy (md); | ||
315 | GNUNET_FS_uri_destroy (uri); | ||
316 | } | ||
313 | return GNUNET_OK; | 317 | return GNUNET_OK; |
314 | } | 318 | } |
315 | 319 | ||
316 | /** | 320 | /** |
317 | * Entries in the directory (builder). | 321 | * Entries in the directory (builder). |
318 | */ | 322 | */ |
319 | struct BuilderEntry { | 323 | struct BuilderEntry |
324 | { | ||
320 | /** | 325 | /** |
321 | * This is a linked list. | 326 | * This is a linked list. |
322 | */ | 327 | */ |
@@ -331,7 +336,8 @@ struct BuilderEntry { | |||
331 | /** | 336 | /** |
332 | * Internal state of a directory builder. | 337 | * Internal state of a directory builder. |
333 | */ | 338 | */ |
334 | struct GNUNET_FS_DirectoryBuilder { | 339 | struct GNUNET_FS_DirectoryBuilder |
340 | { | ||
335 | /** | 341 | /** |
336 | * Meta-data for the directory itself. | 342 | * Meta-data for the directory itself. |
337 | */ | 343 | */ |
@@ -355,17 +361,17 @@ struct GNUNET_FS_DirectoryBuilder { | |||
355 | * @param mdir metadata for the directory | 361 | * @param mdir metadata for the directory |
356 | */ | 362 | */ |
357 | struct GNUNET_FS_DirectoryBuilder * | 363 | struct GNUNET_FS_DirectoryBuilder * |
358 | GNUNET_FS_directory_builder_create(const struct GNUNET_CONTAINER_MetaData | 364 | GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData |
359 | *mdir) | 365 | *mdir) |
360 | { | 366 | { |
361 | struct GNUNET_FS_DirectoryBuilder *ret; | 367 | struct GNUNET_FS_DirectoryBuilder *ret; |
362 | 368 | ||
363 | ret = GNUNET_new(struct GNUNET_FS_DirectoryBuilder); | 369 | ret = GNUNET_new (struct GNUNET_FS_DirectoryBuilder); |
364 | if (mdir != NULL) | 370 | if (mdir != NULL) |
365 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate(mdir); | 371 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate (mdir); |
366 | else | 372 | else |
367 | ret->meta = GNUNET_CONTAINER_meta_data_create(); | 373 | ret->meta = GNUNET_CONTAINER_meta_data_create (); |
368 | GNUNET_FS_meta_data_make_directory(ret->meta); | 374 | GNUNET_FS_meta_data_make_directory (ret->meta); |
369 | return ret; | 375 | return ret; |
370 | } | 376 | } |
371 | 377 | ||
@@ -381,10 +387,10 @@ GNUNET_FS_directory_builder_create(const struct GNUNET_CONTAINER_MetaData | |||
381 | * by the uri which must be of type LOC or CHK | 387 | * by the uri which must be of type LOC or CHK |
382 | */ | 388 | */ |
383 | void | 389 | void |
384 | GNUNET_FS_directory_builder_add(struct GNUNET_FS_DirectoryBuilder *bld, | 390 | GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, |
385 | const struct GNUNET_FS_Uri *uri, | 391 | const struct GNUNET_FS_Uri *uri, |
386 | const struct GNUNET_CONTAINER_MetaData *md, | 392 | const struct GNUNET_CONTAINER_MetaData *md, |
387 | const void *data) | 393 | const void *data) |
388 | { | 394 | { |
389 | struct GNUNET_FS_Uri *curi; | 395 | struct GNUNET_FS_Uri *curi; |
390 | struct BuilderEntry *e; | 396 | struct BuilderEntry *e; |
@@ -400,70 +406,70 @@ GNUNET_FS_directory_builder_add(struct GNUNET_FS_DirectoryBuilder *bld, | |||
400 | struct GNUNET_CONTAINER_MetaData *meta; | 406 | struct GNUNET_CONTAINER_MetaData *meta; |
401 | const struct GNUNET_CONTAINER_MetaData *meta_use; | 407 | const struct GNUNET_CONTAINER_MetaData *meta_use; |
402 | 408 | ||
403 | GNUNET_assert(!GNUNET_FS_uri_test_ksk(uri)); | 409 | GNUNET_assert (! GNUNET_FS_uri_test_ksk (uri)); |
404 | if (NULL != data) | 410 | if (NULL != data) |
411 | { | ||
412 | GNUNET_assert (! GNUNET_FS_uri_test_sks (uri)); | ||
413 | if (GNUNET_FS_uri_test_chk (uri)) | ||
405 | { | 414 | { |
406 | GNUNET_assert(!GNUNET_FS_uri_test_sks(uri)); | 415 | fsize = GNUNET_FS_uri_chk_get_file_size (uri); |
407 | if (GNUNET_FS_uri_test_chk(uri)) | ||
408 | { | ||
409 | fsize = GNUNET_FS_uri_chk_get_file_size(uri); | ||
410 | } | ||
411 | else | ||
412 | { | ||
413 | curi = GNUNET_FS_uri_loc_get_uri(uri); | ||
414 | GNUNET_assert(NULL != curi); | ||
415 | fsize = GNUNET_FS_uri_chk_get_file_size(curi); | ||
416 | GNUNET_FS_uri_destroy(curi); | ||
417 | } | ||
418 | } | 416 | } |
419 | else | 417 | else |
420 | { | 418 | { |
421 | fsize = 0; /* not given */ | 419 | curi = GNUNET_FS_uri_loc_get_uri (uri); |
420 | GNUNET_assert (NULL != curi); | ||
421 | fsize = GNUNET_FS_uri_chk_get_file_size (curi); | ||
422 | GNUNET_FS_uri_destroy (curi); | ||
422 | } | 423 | } |
424 | } | ||
425 | else | ||
426 | { | ||
427 | fsize = 0; /* not given */ | ||
428 | } | ||
423 | if (fsize > MAX_INLINE_SIZE) | 429 | if (fsize > MAX_INLINE_SIZE) |
424 | fsize = 0; /* too large */ | 430 | fsize = 0; /* too large */ |
425 | uris = GNUNET_FS_uri_to_string(uri); | 431 | uris = GNUNET_FS_uri_to_string (uri); |
426 | slen = strlen(uris) + 1; | 432 | slen = strlen (uris) + 1; |
427 | mds = GNUNET_CONTAINER_meta_data_get_serialized_size(md); | 433 | mds = GNUNET_CONTAINER_meta_data_get_serialized_size (md); |
428 | meta_use = md; | 434 | meta_use = md; |
429 | meta = NULL; | 435 | meta = NULL; |
430 | if (fsize > 0) | 436 | if (fsize > 0) |
437 | { | ||
438 | meta = GNUNET_CONTAINER_meta_data_duplicate (md); | ||
439 | GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", | ||
440 | EXTRACTOR_METATYPE_GNUNET_FULL_DATA, | ||
441 | EXTRACTOR_METAFORMAT_BINARY, NULL, data, | ||
442 | fsize); | ||
443 | mdxs = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); | ||
444 | if ((slen + sizeof(uint32_t) + mdxs - 1) / DBLOCK_SIZE == | ||
445 | (slen + sizeof(uint32_t) + mds - 1) / DBLOCK_SIZE) | ||
431 | { | 446 | { |
432 | meta = GNUNET_CONTAINER_meta_data_duplicate(md); | 447 | /* adding full data would not cause us to cross |
433 | GNUNET_CONTAINER_meta_data_insert(meta, "<gnunet>", | 448 | * additional blocks, so add it! */ |
434 | EXTRACTOR_METATYPE_GNUNET_FULL_DATA, | 449 | meta_use = meta; |
435 | EXTRACTOR_METAFORMAT_BINARY, NULL, data, | 450 | mds = mdxs; |
436 | fsize); | ||
437 | mdxs = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); | ||
438 | if ((slen + sizeof(uint32_t) + mdxs - 1) / DBLOCK_SIZE == | ||
439 | (slen + sizeof(uint32_t) + mds - 1) / DBLOCK_SIZE) | ||
440 | { | ||
441 | /* adding full data would not cause us to cross | ||
442 | * additional blocks, so add it! */ | ||
443 | meta_use = meta; | ||
444 | mds = mdxs; | ||
445 | } | ||
446 | } | 451 | } |
452 | } | ||
447 | 453 | ||
448 | if (mds > GNUNET_MAX_MALLOC_CHECKED / 2) | 454 | if (mds > GNUNET_MAX_MALLOC_CHECKED / 2) |
449 | mds = GNUNET_MAX_MALLOC_CHECKED / 2; | 455 | mds = GNUNET_MAX_MALLOC_CHECKED / 2; |
450 | e = GNUNET_malloc(sizeof(struct BuilderEntry) + slen + mds + | 456 | e = GNUNET_malloc (sizeof(struct BuilderEntry) + slen + mds |
451 | sizeof(uint32_t)); | 457 | + sizeof(uint32_t)); |
452 | ser = (char *)&e[1]; | 458 | ser = (char *) &e[1]; |
453 | GNUNET_memcpy(ser, uris, slen); | 459 | GNUNET_memcpy (ser, uris, slen); |
454 | GNUNET_free(uris); | 460 | GNUNET_free (uris); |
455 | sptr = &ser[slen + sizeof(uint32_t)]; | 461 | sptr = &ser[slen + sizeof(uint32_t)]; |
456 | ret = | 462 | ret = |
457 | GNUNET_CONTAINER_meta_data_serialize(meta_use, &sptr, mds, | 463 | GNUNET_CONTAINER_meta_data_serialize (meta_use, &sptr, mds, |
458 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 464 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
459 | if (NULL != meta) | 465 | if (NULL != meta) |
460 | GNUNET_CONTAINER_meta_data_destroy(meta); | 466 | GNUNET_CONTAINER_meta_data_destroy (meta); |
461 | if (ret == -1) | 467 | if (ret == -1) |
462 | mds = 0; | 468 | mds = 0; |
463 | else | 469 | else |
464 | mds = ret; | 470 | mds = ret; |
465 | big = htonl(mds); | 471 | big = htonl (mds); |
466 | GNUNET_memcpy(&ser[slen], &big, sizeof(uint32_t)); | 472 | GNUNET_memcpy (&ser[slen], &big, sizeof(uint32_t)); |
467 | e->len = slen + sizeof(uint32_t) + mds; | 473 | e->len = slen + sizeof(uint32_t) + mds; |
468 | e->next = bld->head; | 474 | e->next = bld->head; |
469 | bld->head = e; | 475 | bld->head = e; |
@@ -477,7 +483,7 @@ GNUNET_FS_directory_builder_add(struct GNUNET_FS_DirectoryBuilder *bld, | |||
477 | * after alignment to the DBLOCK_SIZE. | 483 | * after alignment to the DBLOCK_SIZE. |
478 | */ | 484 | */ |
479 | static size_t | 485 | static size_t |
480 | do_align(size_t start_position, size_t end_position) | 486 | do_align (size_t start_position, size_t end_position) |
481 | { | 487 | { |
482 | size_t align; | 488 | size_t align; |
483 | 489 | ||
@@ -498,8 +504,8 @@ do_align(size_t start_position, size_t end_position) | |||
498 | * @param perm the permutation of the blocks (updated) | 504 | * @param perm the permutation of the blocks (updated) |
499 | */ | 505 | */ |
500 | static void | 506 | static void |
501 | block_align(size_t start, unsigned int count, const size_t * sizes, | 507 | block_align (size_t start, unsigned int count, const size_t *sizes, |
502 | unsigned int *perm) | 508 | unsigned int *perm) |
503 | { | 509 | { |
504 | unsigned int i; | 510 | unsigned int i; |
505 | unsigned int j; | 511 | unsigned int j; |
@@ -513,46 +519,46 @@ block_align(size_t start, unsigned int count, const size_t * sizes, | |||
513 | 519 | ||
514 | cpos = start; | 520 | cpos = start; |
515 | for (i = 0; i < count; i++) | 521 | for (i = 0; i < count; i++) |
522 | { | ||
523 | start = cpos; | ||
524 | badness = 0x7FFFFFFF; | ||
525 | best = -1; | ||
526 | for (j = i; j < count; j++) | ||
516 | { | 527 | { |
517 | start = cpos; | 528 | cval = perm[j]; |
518 | badness = 0x7FFFFFFF; | 529 | cend = cpos + sizes[cval]; |
519 | best = -1; | 530 | if (cpos % DBLOCK_SIZE == 0) |
520 | for (j = i; j < count; j++) | 531 | { |
532 | /* prefer placing the largest blocks first */ | ||
533 | cbad = -(cend % DBLOCK_SIZE); | ||
534 | } | ||
535 | else | ||
536 | { | ||
537 | if (cpos / DBLOCK_SIZE == cend / DBLOCK_SIZE) | ||
538 | { | ||
539 | /* Data fits into the same block! Prefer small left-overs! */ | ||
540 | cbad = DBLOCK_SIZE - cend % DBLOCK_SIZE; | ||
541 | } | ||
542 | else | ||
521 | { | 543 | { |
522 | cval = perm[j]; | 544 | /* Would have to waste space to re-align, add big factor, this |
523 | cend = cpos + sizes[cval]; | 545 | * case is a real loss (proportional to space wasted)! */ |
524 | if (cpos % DBLOCK_SIZE == 0) | 546 | cbad = DBLOCK_SIZE * (DBLOCK_SIZE - cpos % DBLOCK_SIZE); |
525 | { | ||
526 | /* prefer placing the largest blocks first */ | ||
527 | cbad = -(cend % DBLOCK_SIZE); | ||
528 | } | ||
529 | else | ||
530 | { | ||
531 | if (cpos / DBLOCK_SIZE == cend / DBLOCK_SIZE) | ||
532 | { | ||
533 | /* Data fits into the same block! Prefer small left-overs! */ | ||
534 | cbad = DBLOCK_SIZE - cend % DBLOCK_SIZE; | ||
535 | } | ||
536 | else | ||
537 | { | ||
538 | /* Would have to waste space to re-align, add big factor, this | ||
539 | * case is a real loss (proportional to space wasted)! */ | ||
540 | cbad = DBLOCK_SIZE * (DBLOCK_SIZE - cpos % DBLOCK_SIZE); | ||
541 | } | ||
542 | } | ||
543 | if (cbad < badness) | ||
544 | { | ||
545 | best = j; | ||
546 | badness = cbad; | ||
547 | } | ||
548 | } | 547 | } |
549 | GNUNET_assert(best != -1); | 548 | } |
550 | tmp = perm[i]; | 549 | if (cbad < badness) |
551 | perm[i] = perm[best]; | 550 | { |
552 | perm[best] = tmp; | 551 | best = j; |
553 | cpos += sizes[perm[i]]; | 552 | badness = cbad; |
554 | cpos = do_align(start, cpos); | 553 | } |
555 | } | 554 | } |
555 | GNUNET_assert (best != -1); | ||
556 | tmp = perm[i]; | ||
557 | perm[i] = perm[best]; | ||
558 | perm[best] = tmp; | ||
559 | cpos += sizes[perm[i]]; | ||
560 | cpos = do_align (start, cpos); | ||
561 | } | ||
556 | } | 562 | } |
557 | 563 | ||
558 | 564 | ||
@@ -567,9 +573,9 @@ block_align(size_t start, unsigned int count, const size_t * sizes, | |||
567 | * @return #GNUNET_OK on success | 573 | * @return #GNUNET_OK on success |
568 | */ | 574 | */ |
569 | int | 575 | int |
570 | GNUNET_FS_directory_builder_finish(struct GNUNET_FS_DirectoryBuilder *bld, | 576 | GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld, |
571 | size_t * rsize, | 577 | size_t *rsize, |
572 | void **rdata) | 578 | void **rdata) |
573 | { | 579 | { |
574 | char *data; | 580 | char *data; |
575 | char *sptr; | 581 | char *sptr; |
@@ -585,82 +591,82 @@ GNUNET_FS_directory_builder_finish(struct GNUNET_FS_DirectoryBuilder *bld, | |||
585 | ssize_t ret; | 591 | ssize_t ret; |
586 | uint32_t big; | 592 | uint32_t big; |
587 | 593 | ||
588 | size = strlen(GNUNET_DIRECTORY_MAGIC) + sizeof(uint32_t); | 594 | size = strlen (GNUNET_DIRECTORY_MAGIC) + sizeof(uint32_t); |
589 | size += GNUNET_CONTAINER_meta_data_get_serialized_size(bld->meta); | 595 | size += GNUNET_CONTAINER_meta_data_get_serialized_size (bld->meta); |
590 | sizes = NULL; | 596 | sizes = NULL; |
591 | perm = NULL; | 597 | perm = NULL; |
592 | bes = NULL; | 598 | bes = NULL; |
593 | if (0 < bld->count) | 599 | if (0 < bld->count) |
600 | { | ||
601 | sizes = GNUNET_new_array (bld->count, | ||
602 | size_t); | ||
603 | perm = GNUNET_new_array (bld->count, | ||
604 | unsigned int); | ||
605 | bes = GNUNET_new_array (bld->count, | ||
606 | struct BuilderEntry *); | ||
607 | pos = bld->head; | ||
608 | for (i = 0; i < bld->count; i++) | ||
594 | { | 609 | { |
595 | sizes = GNUNET_new_array(bld->count, | 610 | perm[i] = i; |
596 | size_t); | 611 | bes[i] = pos; |
597 | perm = GNUNET_new_array(bld->count, | 612 | sizes[i] = pos->len; |
598 | unsigned int); | 613 | pos = pos->next; |
599 | bes = GNUNET_new_array(bld->count, | ||
600 | struct BuilderEntry *); | ||
601 | pos = bld->head; | ||
602 | for (i = 0; i < bld->count; i++) | ||
603 | { | ||
604 | perm[i] = i; | ||
605 | bes[i] = pos; | ||
606 | sizes[i] = pos->len; | ||
607 | pos = pos->next; | ||
608 | } | ||
609 | block_align(size, bld->count, sizes, perm); | ||
610 | /* compute final size with alignment */ | ||
611 | for (i = 0; i < bld->count; i++) | ||
612 | { | ||
613 | psize = size; | ||
614 | size += sizes[perm[i]]; | ||
615 | size = do_align(psize, size); | ||
616 | } | ||
617 | } | 614 | } |
618 | *rsize = size; | 615 | block_align (size, bld->count, sizes, perm); |
619 | data = GNUNET_malloc_large(size); | 616 | /* compute final size with alignment */ |
620 | if (data == NULL) | 617 | for (i = 0; i < bld->count; i++) |
621 | { | 618 | { |
622 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, | 619 | psize = size; |
623 | "malloc"); | 620 | size += sizes[perm[i]]; |
624 | *rsize = 0; | 621 | size = do_align (psize, size); |
625 | *rdata = NULL; | ||
626 | GNUNET_free_non_null(sizes); | ||
627 | GNUNET_free_non_null(perm); | ||
628 | GNUNET_free_non_null(bes); | ||
629 | return GNUNET_SYSERR; | ||
630 | } | 622 | } |
623 | } | ||
624 | *rsize = size; | ||
625 | data = GNUNET_malloc_large (size); | ||
626 | if (data == NULL) | ||
627 | { | ||
628 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
629 | "malloc"); | ||
630 | *rsize = 0; | ||
631 | *rdata = NULL; | ||
632 | GNUNET_free_non_null (sizes); | ||
633 | GNUNET_free_non_null (perm); | ||
634 | GNUNET_free_non_null (bes); | ||
635 | return GNUNET_SYSERR; | ||
636 | } | ||
631 | *rdata = data; | 637 | *rdata = data; |
632 | GNUNET_memcpy(data, | 638 | GNUNET_memcpy (data, |
633 | GNUNET_DIRECTORY_MAGIC, | 639 | GNUNET_DIRECTORY_MAGIC, |
634 | strlen(GNUNET_DIRECTORY_MAGIC)); | 640 | strlen (GNUNET_DIRECTORY_MAGIC)); |
635 | off = strlen(GNUNET_DIRECTORY_MAGIC); | 641 | off = strlen (GNUNET_DIRECTORY_MAGIC); |
636 | 642 | ||
637 | sptr = &data[off + sizeof(uint32_t)]; | 643 | sptr = &data[off + sizeof(uint32_t)]; |
638 | ret = | 644 | ret = |
639 | GNUNET_CONTAINER_meta_data_serialize(bld->meta, | 645 | GNUNET_CONTAINER_meta_data_serialize (bld->meta, |
640 | &sptr, | 646 | &sptr, |
641 | size - off - sizeof(uint32_t), | 647 | size - off - sizeof(uint32_t), |
642 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); | 648 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); |
643 | GNUNET_assert(ret != -1); | 649 | GNUNET_assert (ret != -1); |
644 | big = htonl(ret); | 650 | big = htonl (ret); |
645 | GNUNET_memcpy(&data[off], | 651 | GNUNET_memcpy (&data[off], |
646 | &big, | 652 | &big, |
647 | sizeof(uint32_t)); | 653 | sizeof(uint32_t)); |
648 | off += sizeof(uint32_t) + ret; | 654 | off += sizeof(uint32_t) + ret; |
649 | for (j = 0; j < bld->count; j++) | 655 | for (j = 0; j < bld->count; j++) |
650 | { | 656 | { |
651 | i = perm[j]; | 657 | i = perm[j]; |
652 | psize = off; | 658 | psize = off; |
653 | off += sizes[i]; | 659 | off += sizes[i]; |
654 | off = do_align(psize, off); | 660 | off = do_align (psize, off); |
655 | GNUNET_memcpy(&data[off - sizes[i]], &(bes[i])[1], sizes[i]); | 661 | GNUNET_memcpy (&data[off - sizes[i]], &(bes[i])[1], sizes[i]); |
656 | GNUNET_free(bes[i]); | 662 | GNUNET_free (bes[i]); |
657 | } | 663 | } |
658 | GNUNET_free_non_null(sizes); | 664 | GNUNET_free_non_null (sizes); |
659 | GNUNET_free_non_null(perm); | 665 | GNUNET_free_non_null (perm); |
660 | GNUNET_free_non_null(bes); | 666 | GNUNET_free_non_null (bes); |
661 | GNUNET_assert(off == size); | 667 | GNUNET_assert (off == size); |
662 | GNUNET_CONTAINER_meta_data_destroy(bld->meta); | 668 | GNUNET_CONTAINER_meta_data_destroy (bld->meta); |
663 | GNUNET_free(bld); | 669 | GNUNET_free (bld); |
664 | return GNUNET_OK; | 670 | return GNUNET_OK; |
665 | } | 671 | } |
666 | 672 | ||
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c index 9202de5ab..11efa053b 100644 --- a/src/fs/fs_dirmetascan.c +++ b/src/fs/fs_dirmetascan.c | |||
@@ -35,7 +35,8 @@ | |||
35 | * An opaque structure a pointer to which is returned to the | 35 | * An opaque structure a pointer to which is returned to the |
36 | * caller to be used to control the scanner. | 36 | * caller to be used to control the scanner. |
37 | */ | 37 | */ |
38 | struct GNUNET_FS_DirScanner { | 38 | struct GNUNET_FS_DirScanner |
39 | { | ||
39 | /** | 40 | /** |
40 | * Helper process. | 41 | * Helper process. |
41 | */ | 42 | */ |
@@ -94,20 +95,20 @@ struct GNUNET_FS_DirScanner { | |||
94 | * @param ds directory scanner structure | 95 | * @param ds directory scanner structure |
95 | */ | 96 | */ |
96 | void | 97 | void |
97 | GNUNET_FS_directory_scan_abort(struct GNUNET_FS_DirScanner *ds) | 98 | GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds) |
98 | { | 99 | { |
99 | /* terminate helper */ | 100 | /* terminate helper */ |
100 | if (NULL != ds->helper) | 101 | if (NULL != ds->helper) |
101 | GNUNET_HELPER_stop(ds->helper, GNUNET_NO); | 102 | GNUNET_HELPER_stop (ds->helper, GNUNET_NO); |
102 | 103 | ||
103 | /* free resources */ | 104 | /* free resources */ |
104 | if (NULL != ds->toplevel) | 105 | if (NULL != ds->toplevel) |
105 | GNUNET_FS_share_tree_free(ds->toplevel); | 106 | GNUNET_FS_share_tree_free (ds->toplevel); |
106 | if (NULL != ds->stop_task) | 107 | if (NULL != ds->stop_task) |
107 | GNUNET_SCHEDULER_cancel(ds->stop_task); | 108 | GNUNET_SCHEDULER_cancel (ds->stop_task); |
108 | GNUNET_free_non_null(ds->ex_arg); | 109 | GNUNET_free_non_null (ds->ex_arg); |
109 | GNUNET_free(ds->filename_expanded); | 110 | GNUNET_free (ds->filename_expanded); |
110 | GNUNET_free(ds); | 111 | GNUNET_free (ds); |
111 | } | 112 | } |
112 | 113 | ||
113 | 114 | ||
@@ -120,16 +121,16 @@ GNUNET_FS_directory_scan_abort(struct GNUNET_FS_DirScanner *ds) | |||
120 | * @return the results of the scan (a directory tree) | 121 | * @return the results of the scan (a directory tree) |
121 | */ | 122 | */ |
122 | struct GNUNET_FS_ShareTreeItem * | 123 | struct GNUNET_FS_ShareTreeItem * |
123 | GNUNET_FS_directory_scan_get_result(struct GNUNET_FS_DirScanner *ds) | 124 | GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds) |
124 | { | 125 | { |
125 | struct GNUNET_FS_ShareTreeItem *result; | 126 | struct GNUNET_FS_ShareTreeItem *result; |
126 | 127 | ||
127 | /* check that we're actually done */ | 128 | /* check that we're actually done */ |
128 | GNUNET_assert(NULL == ds->helper); | 129 | GNUNET_assert (NULL == ds->helper); |
129 | /* preserve result */ | 130 | /* preserve result */ |
130 | result = ds->toplevel; | 131 | result = ds->toplevel; |
131 | ds->toplevel = NULL; | 132 | ds->toplevel = NULL; |
132 | GNUNET_FS_directory_scan_abort(ds); | 133 | GNUNET_FS_directory_scan_abort (ds); |
133 | return result; | 134 | return result; |
134 | } | 135 | } |
135 | 136 | ||
@@ -142,35 +143,35 @@ GNUNET_FS_directory_scan_get_result(struct GNUNET_FS_DirScanner *ds) | |||
142 | * @return next file, NULL for none | 143 | * @return next file, NULL for none |
143 | */ | 144 | */ |
144 | static struct GNUNET_FS_ShareTreeItem * | 145 | static struct GNUNET_FS_ShareTreeItem * |
145 | advance(struct GNUNET_FS_ShareTreeItem *pos) | 146 | advance (struct GNUNET_FS_ShareTreeItem *pos) |
146 | { | 147 | { |
147 | int moved; | 148 | int moved; |
148 | 149 | ||
149 | GNUNET_assert(NULL != pos); | 150 | GNUNET_assert (NULL != pos); |
150 | moved = 0; /* must not terminate, even on file, otherwise "normal" */ | 151 | moved = 0; /* must not terminate, even on file, otherwise "normal" */ |
151 | while ((pos->is_directory == GNUNET_YES) || (0 == moved)) | 152 | while ((pos->is_directory == GNUNET_YES) || (0 == moved)) |
153 | { | ||
154 | if ((moved != -1) && (NULL != pos->children_head)) | ||
152 | { | 155 | { |
153 | if ((moved != -1) && (NULL != pos->children_head)) | 156 | pos = pos->children_head; |
154 | { | 157 | moved = 1; /* can terminate if file */ |
155 | pos = pos->children_head; | 158 | continue; |
156 | moved = 1; /* can terminate if file */ | 159 | } |
157 | continue; | 160 | if (NULL != pos->next) |
158 | } | 161 | { |
159 | if (NULL != pos->next) | 162 | pos = pos->next; |
160 | { | 163 | moved = 1; /* can terminate if file */ |
161 | pos = pos->next; | 164 | continue; |
162 | moved = 1; /* can terminate if file */ | 165 | } |
163 | continue; | 166 | if (NULL != pos->parent) |
164 | } | 167 | { |
165 | if (NULL != pos->parent) | 168 | pos = pos->parent; |
166 | { | 169 | moved = -1; /* force move to 'next' or 'parent' */ |
167 | pos = pos->parent; | 170 | continue; |
168 | moved = -1; /* force move to 'next' or 'parent' */ | ||
169 | continue; | ||
170 | } | ||
171 | /* no more options, end of traversal */ | ||
172 | return NULL; | ||
173 | } | 171 | } |
172 | /* no more options, end of traversal */ | ||
173 | return NULL; | ||
174 | } | ||
174 | return pos; | 175 | return pos; |
175 | } | 176 | } |
176 | 177 | ||
@@ -184,30 +185,30 @@ advance(struct GNUNET_FS_ShareTreeItem *pos) | |||
184 | * @return new entry that was just created | 185 | * @return new entry that was just created |
185 | */ | 186 | */ |
186 | static struct GNUNET_FS_ShareTreeItem * | 187 | static struct GNUNET_FS_ShareTreeItem * |
187 | expand_tree(struct GNUNET_FS_ShareTreeItem *parent, | 188 | expand_tree (struct GNUNET_FS_ShareTreeItem *parent, |
188 | const char *filename, | 189 | const char *filename, |
189 | int is_directory) | 190 | int is_directory) |
190 | { | 191 | { |
191 | struct GNUNET_FS_ShareTreeItem *chld; | 192 | struct GNUNET_FS_ShareTreeItem *chld; |
192 | size_t slen; | 193 | size_t slen; |
193 | 194 | ||
194 | chld = GNUNET_new(struct GNUNET_FS_ShareTreeItem); | 195 | chld = GNUNET_new (struct GNUNET_FS_ShareTreeItem); |
195 | chld->parent = parent; | 196 | chld->parent = parent; |
196 | chld->filename = GNUNET_strdup(filename); | 197 | chld->filename = GNUNET_strdup (filename); |
197 | GNUNET_asprintf(&chld->short_filename, | 198 | GNUNET_asprintf (&chld->short_filename, |
198 | "%s%s", | 199 | "%s%s", |
199 | GNUNET_STRINGS_get_short_name(filename), | 200 | GNUNET_STRINGS_get_short_name (filename), |
200 | is_directory == GNUNET_YES ? "/" : ""); | 201 | is_directory == GNUNET_YES ? "/" : ""); |
201 | /* make sure we do not end with '//' */ | 202 | /* make sure we do not end with '//' */ |
202 | slen = strlen(chld->short_filename); | 203 | slen = strlen (chld->short_filename); |
203 | if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') && | 204 | if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') && |
204 | (chld->short_filename[slen - 2] == '/')) | 205 | (chld->short_filename[slen - 2] == '/')) |
205 | chld->short_filename[slen - 1] = '\0'; | 206 | chld->short_filename[slen - 1] = '\0'; |
206 | chld->is_directory = is_directory; | 207 | chld->is_directory = is_directory; |
207 | if (NULL != parent) | 208 | if (NULL != parent) |
208 | GNUNET_CONTAINER_DLL_insert(parent->children_head, | 209 | GNUNET_CONTAINER_DLL_insert (parent->children_head, |
209 | parent->children_tail, | 210 | parent->children_tail, |
210 | chld); | 211 | chld); |
211 | return chld; | 212 | return chld; |
212 | } | 213 | } |
213 | 214 | ||
@@ -218,20 +219,20 @@ expand_tree(struct GNUNET_FS_ShareTreeItem *parent, | |||
218 | * @param cls the 'struct GNUNET_FS_DirScanner' | 219 | * @param cls the 'struct GNUNET_FS_DirScanner' |
219 | */ | 220 | */ |
220 | static void | 221 | static void |
221 | finish_scan(void *cls) | 222 | finish_scan (void *cls) |
222 | { | 223 | { |
223 | struct GNUNET_FS_DirScanner *ds = cls; | 224 | struct GNUNET_FS_DirScanner *ds = cls; |
224 | 225 | ||
225 | ds->stop_task = NULL; | 226 | ds->stop_task = NULL; |
226 | if (NULL != ds->helper) | 227 | if (NULL != ds->helper) |
227 | { | 228 | { |
228 | GNUNET_HELPER_stop(ds->helper, GNUNET_NO); | 229 | GNUNET_HELPER_stop (ds->helper, GNUNET_NO); |
229 | ds->helper = NULL; | 230 | ds->helper = NULL; |
230 | } | 231 | } |
231 | ds->progress_callback(ds->progress_callback_cls, | 232 | ds->progress_callback (ds->progress_callback_cls, |
232 | NULL, | 233 | NULL, |
233 | GNUNET_SYSERR, | 234 | GNUNET_SYSERR, |
234 | GNUNET_FS_DIRSCANNER_FINISHED); | 235 | GNUNET_FS_DIRSCANNER_FINISHED); |
235 | } | 236 | } |
236 | 237 | ||
237 | 238 | ||
@@ -246,175 +247,177 @@ finish_scan(void *cls) | |||
246 | * #GNUNET_SYSERR to stop further processing with error | 247 | * #GNUNET_SYSERR to stop further processing with error |
247 | */ | 248 | */ |
248 | static int | 249 | static int |
249 | process_helper_msgs(void *cls, const struct GNUNET_MessageHeader *msg) | 250 | process_helper_msgs (void *cls, const struct GNUNET_MessageHeader *msg) |
250 | { | 251 | { |
251 | struct GNUNET_FS_DirScanner *ds = cls; | 252 | struct GNUNET_FS_DirScanner *ds = cls; |
252 | const char *filename; | 253 | const char *filename; |
253 | size_t left; | 254 | size_t left; |
254 | 255 | ||
255 | #if 0 | 256 | #if 0 |
256 | fprintf(stderr, | 257 | fprintf (stderr, |
257 | "DMS parses %u-byte message of type %u\n", | 258 | "DMS parses %u-byte message of type %u\n", |
258 | (unsigned int)ntohs(msg->size), | 259 | (unsigned int) ntohs (msg->size), |
259 | (unsigned int)ntohs(msg->type)); | 260 | (unsigned int) ntohs (msg->type)); |
260 | #endif | 261 | #endif |
261 | left = ntohs(msg->size) - sizeof(struct GNUNET_MessageHeader); | 262 | left = ntohs (msg->size) - sizeof(struct GNUNET_MessageHeader); |
262 | filename = (const char *)&msg[1]; | 263 | filename = (const char *) &msg[1]; |
263 | switch (ntohs(msg->type)) | 264 | switch (ntohs (msg->type)) |
265 | { | ||
266 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: | ||
267 | if (filename[left - 1] != '\0') | ||
264 | { | 268 | { |
265 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: | 269 | GNUNET_break (0); |
266 | if (filename[left - 1] != '\0') | ||
267 | { | ||
268 | GNUNET_break(0); | ||
269 | break; | ||
270 | } | ||
271 | ds->progress_callback(ds->progress_callback_cls, | ||
272 | filename, | ||
273 | GNUNET_NO, | ||
274 | GNUNET_FS_DIRSCANNER_FILE_START); | ||
275 | if (NULL == ds->toplevel) | ||
276 | { | ||
277 | ds->toplevel = expand_tree(ds->pos, filename, GNUNET_NO); | ||
278 | } | ||
279 | else | ||
280 | { | ||
281 | GNUNET_assert(NULL != ds->pos); | ||
282 | (void)expand_tree(ds->pos, filename, GNUNET_NO); | ||
283 | } | ||
284 | return GNUNET_OK; | ||
285 | |||
286 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: | ||
287 | if (filename[left - 1] != '\0') | ||
288 | { | ||
289 | GNUNET_break(0); | ||
290 | break; | ||
291 | } | ||
292 | if (0 == strcmp("..", filename)) | ||
293 | { | ||
294 | if (NULL == ds->pos) | ||
295 | { | ||
296 | GNUNET_break(0); | ||
297 | break; | ||
298 | } | ||
299 | ds->pos = ds->pos->parent; | ||
300 | return GNUNET_OK; | ||
301 | } | ||
302 | ds->progress_callback(ds->progress_callback_cls, | ||
303 | filename, | ||
304 | GNUNET_YES, | ||
305 | GNUNET_FS_DIRSCANNER_FILE_START); | ||
306 | ds->pos = expand_tree(ds->pos, filename, GNUNET_YES); | ||
307 | if (NULL == ds->toplevel) | ||
308 | ds->toplevel = ds->pos; | ||
309 | return GNUNET_OK; | ||
310 | |||
311 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: | ||
312 | break; | 270 | break; |
271 | } | ||
272 | ds->progress_callback (ds->progress_callback_cls, | ||
273 | filename, | ||
274 | GNUNET_NO, | ||
275 | GNUNET_FS_DIRSCANNER_FILE_START); | ||
276 | if (NULL == ds->toplevel) | ||
277 | { | ||
278 | ds->toplevel = expand_tree (ds->pos, filename, GNUNET_NO); | ||
279 | } | ||
280 | else | ||
281 | { | ||
282 | GNUNET_assert (NULL != ds->pos); | ||
283 | (void) expand_tree (ds->pos, filename, GNUNET_NO); | ||
284 | } | ||
285 | return GNUNET_OK; | ||
313 | 286 | ||
314 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: | 287 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: |
315 | if ('\0' != filename[left - 1]) | 288 | if (filename[left - 1] != '\0') |
316 | break; | 289 | { |
317 | ds->progress_callback(ds->progress_callback_cls, | 290 | GNUNET_break (0); |
318 | filename, | 291 | break; |
319 | GNUNET_SYSERR, | 292 | } |
320 | GNUNET_FS_DIRSCANNER_FILE_IGNORED); | 293 | if (0 == strcmp ("..", filename)) |
321 | return GNUNET_OK; | 294 | { |
322 | 295 | if (NULL == ds->pos) | |
323 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: | 296 | { |
324 | if (0 != left) | 297 | GNUNET_break (0); |
325 | { | ||
326 | GNUNET_break(0); | ||
327 | break; | ||
328 | } | ||
329 | if (NULL == ds->toplevel) | ||
330 | break; | 298 | break; |
331 | ds->progress_callback(ds->progress_callback_cls, | 299 | } |
332 | NULL, | 300 | ds->pos = ds->pos->parent; |
333 | GNUNET_SYSERR, | ||
334 | GNUNET_FS_DIRSCANNER_ALL_COUNTED); | ||
335 | ds->pos = ds->toplevel; | ||
336 | if (GNUNET_YES == ds->pos->is_directory) | ||
337 | ds->pos = advance(ds->pos); | ||
338 | return GNUNET_OK; | 301 | return GNUNET_OK; |
339 | 302 | } | |
340 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { | 303 | ds->progress_callback (ds->progress_callback_cls, |
304 | filename, | ||
305 | GNUNET_YES, | ||
306 | GNUNET_FS_DIRSCANNER_FILE_START); | ||
307 | ds->pos = expand_tree (ds->pos, filename, GNUNET_YES); | ||
308 | if (NULL == ds->toplevel) | ||
309 | ds->toplevel = ds->pos; | ||
310 | return GNUNET_OK; | ||
311 | |||
312 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: | ||
313 | break; | ||
314 | |||
315 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: | ||
316 | if ('\0' != filename[left - 1]) | ||
317 | break; | ||
318 | ds->progress_callback (ds->progress_callback_cls, | ||
319 | filename, | ||
320 | GNUNET_SYSERR, | ||
321 | GNUNET_FS_DIRSCANNER_FILE_IGNORED); | ||
322 | return GNUNET_OK; | ||
323 | |||
324 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: | ||
325 | if (0 != left) | ||
326 | { | ||
327 | GNUNET_break (0); | ||
328 | break; | ||
329 | } | ||
330 | if (NULL == ds->toplevel) | ||
331 | break; | ||
332 | ds->progress_callback (ds->progress_callback_cls, | ||
333 | NULL, | ||
334 | GNUNET_SYSERR, | ||
335 | GNUNET_FS_DIRSCANNER_ALL_COUNTED); | ||
336 | ds->pos = ds->toplevel; | ||
337 | if (GNUNET_YES == ds->pos->is_directory) | ||
338 | ds->pos = advance (ds->pos); | ||
339 | return GNUNET_OK; | ||
340 | |||
341 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { | ||
341 | size_t nlen; | 342 | size_t nlen; |
342 | const char *end; | 343 | const char *end; |
343 | 344 | ||
344 | if (NULL == ds->pos) | 345 | if (NULL == ds->pos) |
345 | { | 346 | { |
346 | GNUNET_break(0); | 347 | GNUNET_break (0); |
347 | break; | 348 | break; |
348 | } | 349 | } |
349 | end = memchr(filename, 0, left); | 350 | end = memchr (filename, 0, left); |
350 | if (NULL == end) | 351 | if (NULL == end) |
351 | { | 352 | { |
352 | GNUNET_break(0); | 353 | GNUNET_break (0); |
353 | break; | 354 | break; |
354 | } | 355 | } |
355 | end++; | 356 | end++; |
356 | nlen = end - filename; | 357 | nlen = end - filename; |
357 | left -= nlen; | 358 | left -= nlen; |
358 | if (0 != strcmp(filename, ds->pos->filename)) | 359 | if (0 != strcmp (filename, ds->pos->filename)) |
359 | { | 360 | { |
360 | GNUNET_break(0); | 361 | GNUNET_break (0); |
361 | break; | 362 | break; |
362 | } | 363 | } |
363 | ds->progress_callback(ds->progress_callback_cls, | 364 | ds->progress_callback (ds->progress_callback_cls, |
364 | filename, | 365 | filename, |
365 | GNUNET_YES, | 366 | GNUNET_YES, |
366 | GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); | 367 | GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); |
367 | if (0 < left) | 368 | if (0 < left) |
369 | { | ||
370 | ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, left); | ||
371 | if (NULL == ds->pos->meta) | ||
368 | { | 372 | { |
369 | ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize(end, left); | 373 | GNUNET_break (0); |
370 | if (NULL == ds->pos->meta) | ||
371 | { | ||
372 | GNUNET_break(0); | ||
373 | break; | ||
374 | } | ||
375 | /* having full filenames is too dangerous; always make sure we clean them up */ | ||
376 | GNUNET_CONTAINER_meta_data_delete(ds->pos->meta, | ||
377 | EXTRACTOR_METATYPE_FILENAME, | ||
378 | NULL, | ||
379 | 0); | ||
380 | /* instead, put in our 'safer' original filename */ | ||
381 | GNUNET_CONTAINER_meta_data_insert(ds->pos->meta, | ||
382 | "<libgnunetfs>", | ||
383 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
384 | EXTRACTOR_METAFORMAT_UTF8, | ||
385 | "text/plain", | ||
386 | ds->pos->short_filename, | ||
387 | strlen(ds->pos->short_filename) + 1); | ||
388 | } | ||
389 | ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data(ds->pos->meta); | ||
390 | ds->pos = advance(ds->pos); | ||
391 | return GNUNET_OK; | ||
392 | } | ||
393 | |||
394 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: | ||
395 | if (NULL != ds->pos) | ||
396 | { | ||
397 | GNUNET_break(0); | ||
398 | break; | ||
399 | } | ||
400 | if (0 != left) | ||
401 | { | ||
402 | GNUNET_break(0); | ||
403 | break; | 374 | break; |
404 | } | 375 | } |
405 | if (NULL == ds->toplevel) | 376 | /* having full filenames is too dangerous; always make sure we clean them up */ |
406 | break; | 377 | GNUNET_CONTAINER_meta_data_delete (ds->pos->meta, |
407 | ds->stop_task = GNUNET_SCHEDULER_add_now(&finish_scan, ds); | 378 | EXTRACTOR_METATYPE_FILENAME, |
379 | NULL, | ||
380 | 0); | ||
381 | /* instead, put in our 'safer' original filename */ | ||
382 | GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, | ||
383 | "<libgnunetfs>", | ||
384 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
385 | EXTRACTOR_METAFORMAT_UTF8, | ||
386 | "text/plain", | ||
387 | ds->pos->short_filename, | ||
388 | strlen (ds->pos->short_filename) | ||
389 | + 1); | ||
390 | } | ||
391 | ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data ( | ||
392 | ds->pos->meta); | ||
393 | ds->pos = advance (ds->pos); | ||
408 | return GNUNET_OK; | 394 | return GNUNET_OK; |
395 | } | ||
409 | 396 | ||
410 | default: | 397 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: |
411 | GNUNET_break(0); | 398 | if (NULL != ds->pos) |
399 | { | ||
400 | GNUNET_break (0); | ||
401 | break; | ||
402 | } | ||
403 | if (0 != left) | ||
404 | { | ||
405 | GNUNET_break (0); | ||
412 | break; | 406 | break; |
413 | } | 407 | } |
414 | ds->progress_callback(ds->progress_callback_cls, | 408 | if (NULL == ds->toplevel) |
415 | NULL, | 409 | break; |
416 | GNUNET_SYSERR, | 410 | ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, ds); |
417 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | 411 | return GNUNET_OK; |
412 | |||
413 | default: | ||
414 | GNUNET_break (0); | ||
415 | break; | ||
416 | } | ||
417 | ds->progress_callback (ds->progress_callback_cls, | ||
418 | NULL, | ||
419 | GNUNET_SYSERR, | ||
420 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | ||
418 | return GNUNET_OK; | 421 | return GNUNET_OK; |
419 | } | 422 | } |
420 | 423 | ||
@@ -425,17 +428,17 @@ process_helper_msgs(void *cls, const struct GNUNET_MessageHeader *msg) | |||
425 | * @param cls the 'struct GNUNET_FS_DirScanner' callback. | 428 | * @param cls the 'struct GNUNET_FS_DirScanner' callback. |
426 | */ | 429 | */ |
427 | static void | 430 | static void |
428 | helper_died_cb(void *cls) | 431 | helper_died_cb (void *cls) |
429 | { | 432 | { |
430 | struct GNUNET_FS_DirScanner *ds = cls; | 433 | struct GNUNET_FS_DirScanner *ds = cls; |
431 | 434 | ||
432 | ds->helper = NULL; | 435 | ds->helper = NULL; |
433 | if (NULL != ds->stop_task) | 436 | if (NULL != ds->stop_task) |
434 | return; /* normal death, was finished */ | 437 | return; /* normal death, was finished */ |
435 | ds->progress_callback(ds->progress_callback_cls, | 438 | ds->progress_callback (ds->progress_callback_cls, |
436 | NULL, | 439 | NULL, |
437 | GNUNET_SYSERR, | 440 | GNUNET_SYSERR, |
438 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | 441 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); |
439 | } | 442 | } |
440 | 443 | ||
441 | 444 | ||
@@ -451,48 +454,48 @@ helper_died_cb(void *cls) | |||
451 | * @return directory scanner object to be used for controlling the scanner | 454 | * @return directory scanner object to be used for controlling the scanner |
452 | */ | 455 | */ |
453 | struct GNUNET_FS_DirScanner * | 456 | struct GNUNET_FS_DirScanner * |
454 | GNUNET_FS_directory_scan_start(const char *filename, | 457 | GNUNET_FS_directory_scan_start (const char *filename, |
455 | int disable_extractor, | 458 | int disable_extractor, |
456 | const char *ex, | 459 | const char *ex, |
457 | GNUNET_FS_DirScannerProgressCallback cb, | 460 | GNUNET_FS_DirScannerProgressCallback cb, |
458 | void *cb_cls) | 461 | void *cb_cls) |
459 | { | 462 | { |
460 | struct stat sbuf; | 463 | struct stat sbuf; |
461 | char *filename_expanded; | 464 | char *filename_expanded; |
462 | struct GNUNET_FS_DirScanner *ds; | 465 | struct GNUNET_FS_DirScanner *ds; |
463 | 466 | ||
464 | if (0 != stat(filename, &sbuf)) | 467 | if (0 != stat (filename, &sbuf)) |
465 | return NULL; | 468 | return NULL; |
466 | filename_expanded = GNUNET_STRINGS_filename_expand(filename); | 469 | filename_expanded = GNUNET_STRINGS_filename_expand (filename); |
467 | if (NULL == filename_expanded) | 470 | if (NULL == filename_expanded) |
468 | return NULL; | 471 | return NULL; |
469 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
470 | "Starting to scan directory `%s'\n", | 473 | "Starting to scan directory `%s'\n", |
471 | filename_expanded); | 474 | filename_expanded); |
472 | ds = GNUNET_new(struct GNUNET_FS_DirScanner); | 475 | ds = GNUNET_new (struct GNUNET_FS_DirScanner); |
473 | ds->progress_callback = cb; | 476 | ds->progress_callback = cb; |
474 | ds->progress_callback_cls = cb_cls; | 477 | ds->progress_callback_cls = cb_cls; |
475 | ds->filename_expanded = filename_expanded; | 478 | ds->filename_expanded = filename_expanded; |
476 | if (disable_extractor) | 479 | if (disable_extractor) |
477 | ds->ex_arg = GNUNET_strdup("-"); | 480 | ds->ex_arg = GNUNET_strdup ("-"); |
478 | else | 481 | else |
479 | ds->ex_arg = (NULL != ex) ? GNUNET_strdup(ex) : NULL; | 482 | ds->ex_arg = (NULL != ex) ? GNUNET_strdup (ex) : NULL; |
480 | ds->args[0] = "gnunet-helper-fs-publish"; | 483 | ds->args[0] = "gnunet-helper-fs-publish"; |
481 | ds->args[1] = ds->filename_expanded; | 484 | ds->args[1] = ds->filename_expanded; |
482 | ds->args[2] = ds->ex_arg; | 485 | ds->args[2] = ds->ex_arg; |
483 | ds->args[3] = NULL; | 486 | ds->args[3] = NULL; |
484 | ds->helper = GNUNET_HELPER_start(GNUNET_NO, | 487 | ds->helper = GNUNET_HELPER_start (GNUNET_NO, |
485 | "gnunet-helper-fs-publish", | 488 | "gnunet-helper-fs-publish", |
486 | ds->args, | 489 | ds->args, |
487 | &process_helper_msgs, | 490 | &process_helper_msgs, |
488 | &helper_died_cb, | 491 | &helper_died_cb, |
489 | ds); | 492 | ds); |
490 | if (NULL == ds->helper) | 493 | if (NULL == ds->helper) |
491 | { | 494 | { |
492 | GNUNET_free(filename_expanded); | 495 | GNUNET_free (filename_expanded); |
493 | GNUNET_free(ds); | 496 | GNUNET_free (ds); |
494 | return NULL; | 497 | return NULL; |
495 | } | 498 | } |
496 | return ds; | 499 | return ds; |
497 | } | 500 | } |
498 | 501 | ||
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index de70c53a8..e7ea87e50 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -34,16 +34,16 @@ | |||
34 | * use to try to do a recursive download. | 34 | * use to try to do a recursive download. |
35 | */ | 35 | */ |
36 | static int | 36 | static int |
37 | is_recursive_download(struct GNUNET_FS_DownloadContext *dc) | 37 | is_recursive_download (struct GNUNET_FS_DownloadContext *dc) |
38 | { | 38 | { |
39 | return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && | 39 | return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && |
40 | ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(dc->meta)) || | 40 | ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || |
41 | ((NULL == dc->meta) && | 41 | ((NULL == dc->meta) && |
42 | ((NULL == dc->filename) || | 42 | ((NULL == dc->filename) || |
43 | ((strlen(dc->filename) >= strlen(GNUNET_FS_DIRECTORY_EXT)) && | 43 | ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && |
44 | (NULL != strstr(dc->filename + strlen(dc->filename) - | 44 | (NULL != strstr (dc->filename + strlen (dc->filename) |
45 | strlen(GNUNET_FS_DIRECTORY_EXT), | 45 | - strlen (GNUNET_FS_DIRECTORY_EXT), |
46 | GNUNET_FS_DIRECTORY_EXT)))))); | 46 | GNUNET_FS_DIRECTORY_EXT)))))); |
47 | } | 47 | } |
48 | 48 | ||
49 | 49 | ||
@@ -64,7 +64,7 @@ is_recursive_download(struct GNUNET_FS_DownloadContext *dc) | |||
64 | * with the range for any other block | 64 | * with the range for any other block |
65 | */ | 65 | */ |
66 | static uint64_t | 66 | static uint64_t |
67 | compute_disk_offset(uint64_t fsize, uint64_t off, unsigned int depth) | 67 | compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) |
68 | { | 68 | { |
69 | unsigned int i; | 69 | unsigned int i; |
70 | uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */ | 70 | uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */ |
@@ -78,16 +78,16 @@ compute_disk_offset(uint64_t fsize, uint64_t off, unsigned int depth) | |||
78 | loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE; | 78 | loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE; |
79 | lsize = | 79 | lsize = |
80 | ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof(struct ContentHashKey); | 80 | ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof(struct ContentHashKey); |
81 | GNUNET_assert(0 == (off % DBLOCK_SIZE)); | 81 | GNUNET_assert (0 == (off % DBLOCK_SIZE)); |
82 | ioff = (off / DBLOCK_SIZE); | 82 | ioff = (off / DBLOCK_SIZE); |
83 | for (i = 1; i < depth; i++) | 83 | for (i = 1; i < depth; i++) |
84 | { | 84 | { |
85 | loff += lsize; | 85 | loff += lsize; |
86 | lsize = (lsize + CHK_PER_INODE - 1) / CHK_PER_INODE; | 86 | lsize = (lsize + CHK_PER_INODE - 1) / CHK_PER_INODE; |
87 | GNUNET_assert(lsize > 0); | 87 | GNUNET_assert (lsize > 0); |
88 | GNUNET_assert(0 == (ioff % CHK_PER_INODE)); | 88 | GNUNET_assert (0 == (ioff % CHK_PER_INODE)); |
89 | ioff /= CHK_PER_INODE; | 89 | ioff /= CHK_PER_INODE; |
90 | } | 90 | } |
91 | return loff + ioff * sizeof(struct ContentHashKey); | 91 | return loff + ioff * sizeof(struct ContentHashKey); |
92 | } | 92 | } |
93 | 93 | ||
@@ -100,8 +100,8 @@ compute_disk_offset(uint64_t fsize, uint64_t off, unsigned int depth) | |||
100 | * @param dc overall download context | 100 | * @param dc overall download context |
101 | */ | 101 | */ |
102 | void | 102 | void |
103 | GNUNET_FS_download_make_status_(struct GNUNET_FS_ProgressInfo *pi, | 103 | GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, |
104 | struct GNUNET_FS_DownloadContext *dc) | 104 | struct GNUNET_FS_DownloadContext *dc) |
105 | { | 105 | { |
106 | pi->value.download.dc = dc; | 106 | pi->value.download.dc = dc; |
107 | pi->value.download.cctx = dc->client_info; | 107 | pi->value.download.cctx = dc->client_info; |
@@ -114,24 +114,25 @@ GNUNET_FS_download_make_status_(struct GNUNET_FS_ProgressInfo *pi, | |||
114 | pi->value.download.size = dc->length; | 114 | pi->value.download.size = dc->length; |
115 | /* FIXME: Fix duration calculation to account for pauses */ | 115 | /* FIXME: Fix duration calculation to account for pauses */ |
116 | pi->value.download.duration = | 116 | pi->value.download.duration = |
117 | GNUNET_TIME_absolute_get_duration(dc->start_time); | 117 | GNUNET_TIME_absolute_get_duration (dc->start_time); |
118 | pi->value.download.completed = dc->completed; | 118 | pi->value.download.completed = dc->completed; |
119 | pi->value.download.anonymity = dc->anonymity; | 119 | pi->value.download.anonymity = dc->anonymity; |
120 | pi->value.download.eta = | 120 | pi->value.download.eta = |
121 | GNUNET_TIME_calculate_eta(dc->start_time, dc->completed, dc->length); | 121 | GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length); |
122 | pi->value.download.is_active = (NULL == dc->mq) ? GNUNET_NO : GNUNET_YES; | 122 | pi->value.download.is_active = (NULL == dc->mq) ? GNUNET_NO : GNUNET_YES; |
123 | pi->fsh = dc->h; | 123 | pi->fsh = dc->h; |
124 | if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 124 | if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) |
125 | dc->client_info = dc->h->upcb(dc->h->upcb_cls, pi); | 125 | dc->client_info = dc->h->upcb (dc->h->upcb_cls, pi); |
126 | else | 126 | else |
127 | dc->client_info = GNUNET_FS_search_probe_progress_(NULL, pi); | 127 | dc->client_info = GNUNET_FS_search_probe_progress_ (NULL, pi); |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | /** | 131 | /** |
132 | * Closure for iterator processing results. | 132 | * Closure for iterator processing results. |
133 | */ | 133 | */ |
134 | struct ProcessResultClosure { | 134 | struct ProcessResultClosure |
135 | { | ||
135 | /** | 136 | /** |
136 | * Hash of data. | 137 | * Hash of data. |
137 | */ | 138 | */ |
@@ -189,9 +190,9 @@ struct ProcessResultClosure { | |||
189 | * @return #GNUNET_YES (we should continue to iterate); unless serious error | 190 | * @return #GNUNET_YES (we should continue to iterate); unless serious error |
190 | */ | 191 | */ |
191 | static int | 192 | static int |
192 | process_result_with_request(void *cls, | 193 | process_result_with_request (void *cls, |
193 | const struct GNUNET_HashCode *key, | 194 | const struct GNUNET_HashCode *key, |
194 | void *value); | 195 | void *value); |
195 | 196 | ||
196 | 197 | ||
197 | /** | 198 | /** |
@@ -208,12 +209,12 @@ process_result_with_request(void *cls, | |||
208 | * @return GNUNET_OK on success | 209 | * @return GNUNET_OK on success |
209 | */ | 210 | */ |
210 | static int | 211 | static int |
211 | encrypt_existing_match(struct GNUNET_FS_DownloadContext *dc, | 212 | encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, |
212 | const struct ContentHashKey *chk, | 213 | const struct ContentHashKey *chk, |
213 | struct DownloadRequest *dr, | 214 | struct DownloadRequest *dr, |
214 | const char *block, | 215 | const char *block, |
215 | size_t len, | 216 | size_t len, |
216 | int do_store) | 217 | int do_store) |
217 | { | 218 | { |
218 | struct ProcessResultClosure prc; | 219 | struct ProcessResultClosure prc; |
219 | char enc[len]; | 220 | char enc[len]; |
@@ -221,24 +222,24 @@ encrypt_existing_match(struct GNUNET_FS_DownloadContext *dc, | |||
221 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 222 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
222 | struct GNUNET_HashCode query; | 223 | struct GNUNET_HashCode query; |
223 | 224 | ||
224 | GNUNET_CRYPTO_hash_to_aes_key(&chk->key, &sk, &iv); | 225 | GNUNET_CRYPTO_hash_to_aes_key (&chk->key, &sk, &iv); |
225 | if (-1 == GNUNET_CRYPTO_symmetric_encrypt(block, len, &sk, &iv, enc)) | 226 | if (-1 == GNUNET_CRYPTO_symmetric_encrypt (block, len, &sk, &iv, enc)) |
226 | { | 227 | { |
227 | GNUNET_break(0); | 228 | GNUNET_break (0); |
228 | return GNUNET_SYSERR; | 229 | return GNUNET_SYSERR; |
229 | } | 230 | } |
230 | GNUNET_CRYPTO_hash(enc, len, &query); | 231 | GNUNET_CRYPTO_hash (enc, len, &query); |
231 | if (0 != memcmp(&query, &chk->query, sizeof(struct GNUNET_HashCode))) | 232 | if (0 != memcmp (&query, &chk->query, sizeof(struct GNUNET_HashCode))) |
232 | { | 233 | { |
233 | GNUNET_break_op(0); | 234 | GNUNET_break_op (0); |
234 | return GNUNET_SYSERR; | 235 | return GNUNET_SYSERR; |
235 | } | 236 | } |
236 | GNUNET_log( | 237 | GNUNET_log ( |
237 | GNUNET_ERROR_TYPE_DEBUG, | 238 | GNUNET_ERROR_TYPE_DEBUG, |
238 | "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n", | 239 | "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n", |
239 | (unsigned int)len, | 240 | (unsigned int) len, |
240 | dc->filename, | 241 | dc->filename, |
241 | (unsigned long long)dr->offset); | 242 | (unsigned long long) dr->offset); |
242 | /* already got it! */ | 243 | /* already got it! */ |
243 | prc.dc = dc; | 244 | prc.dc = dc; |
244 | prc.data = enc; | 245 | prc.data = enc; |
@@ -248,7 +249,7 @@ encrypt_existing_match(struct GNUNET_FS_DownloadContext *dc, | |||
248 | prc.query = chk->query; | 249 | prc.query = chk->query; |
249 | prc.do_store = do_store; | 250 | prc.do_store = do_store; |
250 | prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; | 251 | prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; |
251 | process_result_with_request(&prc, &chk->key, dr); | 252 | process_result_with_request (&prc, &chk->key, dr); |
252 | return GNUNET_OK; | 253 | return GNUNET_OK; |
253 | } | 254 | } |
254 | 255 | ||
@@ -261,7 +262,7 @@ encrypt_existing_match(struct GNUNET_FS_DownloadContext *dc, | |||
261 | * @param dc download context that is having trouble | 262 | * @param dc download context that is having trouble |
262 | */ | 263 | */ |
263 | static void | 264 | static void |
264 | try_reconnect(struct GNUNET_FS_DownloadContext *dc); | 265 | try_reconnect (struct GNUNET_FS_DownloadContext *dc); |
265 | 266 | ||
266 | 267 | ||
267 | /** | 268 | /** |
@@ -276,12 +277,12 @@ try_reconnect(struct GNUNET_FS_DownloadContext *dc); | |||
276 | * @param data contents of the file (or NULL if they were not inlined) | 277 | * @param data contents of the file (or NULL if they were not inlined) |
277 | */ | 278 | */ |
278 | static void | 279 | static void |
279 | trigger_recursive_download(void *cls, | 280 | trigger_recursive_download (void *cls, |
280 | const char *filename, | 281 | const char *filename, |
281 | const struct GNUNET_FS_Uri *uri, | 282 | const struct GNUNET_FS_Uri *uri, |
282 | const struct GNUNET_CONTAINER_MetaData *meta, | 283 | const struct GNUNET_CONTAINER_MetaData *meta, |
283 | size_t length, | 284 | size_t length, |
284 | const void *data); | 285 | const void *data); |
285 | 286 | ||
286 | 287 | ||
287 | /** | 288 | /** |
@@ -291,7 +292,7 @@ trigger_recursive_download(void *cls, | |||
291 | * @param dc context of download that just completed | 292 | * @param dc context of download that just completed |
292 | */ | 293 | */ |
293 | static void | 294 | static void |
294 | full_recursive_download(struct GNUNET_FS_DownloadContext *dc) | 295 | full_recursive_download (struct GNUNET_FS_DownloadContext *dc) |
295 | { | 296 | { |
296 | size_t size; | 297 | size_t size; |
297 | uint64_t size64; | 298 | uint64_t size64; |
@@ -299,64 +300,64 @@ full_recursive_download(struct GNUNET_FS_DownloadContext *dc) | |||
299 | struct GNUNET_DISK_FileHandle *h; | 300 | struct GNUNET_DISK_FileHandle *h; |
300 | struct GNUNET_DISK_MapHandle *m; | 301 | struct GNUNET_DISK_MapHandle *m; |
301 | 302 | ||
302 | size64 = GNUNET_FS_uri_chk_get_file_size(dc->uri); | 303 | size64 = GNUNET_FS_uri_chk_get_file_size (dc->uri); |
303 | size = (size_t)size64; | 304 | size = (size_t) size64; |
304 | if (size64 != (uint64_t)size) | 305 | if (size64 != (uint64_t) size) |
305 | { | 306 | { |
306 | GNUNET_log( | 307 | GNUNET_log ( |
307 | GNUNET_ERROR_TYPE_ERROR, | 308 | GNUNET_ERROR_TYPE_ERROR, |
308 | _( | 309 | _ ( |
309 | "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); | 310 | "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); |
310 | return; | 311 | return; |
311 | } | 312 | } |
312 | if (NULL != dc->filename) | 313 | if (NULL != dc->filename) |
313 | { | 314 | { |
314 | h = GNUNET_DISK_file_open(dc->filename, | 315 | h = GNUNET_DISK_file_open (dc->filename, |
315 | GNUNET_DISK_OPEN_READ, | 316 | GNUNET_DISK_OPEN_READ, |
316 | GNUNET_DISK_PERM_NONE); | 317 | GNUNET_DISK_PERM_NONE); |
317 | } | 318 | } |
318 | else | 319 | else |
319 | { | 320 | { |
320 | GNUNET_assert(NULL != dc->temp_filename); | 321 | GNUNET_assert (NULL != dc->temp_filename); |
321 | h = GNUNET_DISK_file_open(dc->temp_filename, | 322 | h = GNUNET_DISK_file_open (dc->temp_filename, |
322 | GNUNET_DISK_OPEN_READ, | 323 | GNUNET_DISK_OPEN_READ, |
323 | GNUNET_DISK_PERM_NONE); | 324 | GNUNET_DISK_PERM_NONE); |
324 | } | 325 | } |
325 | if (NULL == h) | 326 | if (NULL == h) |
326 | return; /* oops */ | 327 | return; /* oops */ |
327 | data = GNUNET_DISK_file_map(h, &m, GNUNET_DISK_MAP_TYPE_READ, size); | 328 | data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size); |
328 | if (NULL == data) | 329 | if (NULL == data) |
329 | { | 330 | { |
330 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 331 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
331 | _("Directory too large for system address space\n")); | 332 | _ ("Directory too large for system address space\n")); |
332 | } | 333 | } |
333 | else | 334 | else |
334 | { | 335 | { |
335 | if (GNUNET_OK != | 336 | if (GNUNET_OK != |
336 | GNUNET_FS_directory_list_contents(size, | 337 | GNUNET_FS_directory_list_contents (size, |
337 | data, | 338 | data, |
338 | 0, | 339 | 0, |
339 | &trigger_recursive_download, | 340 | &trigger_recursive_download, |
340 | dc)) | 341 | dc)) |
341 | { | 342 | { |
342 | GNUNET_log( | 343 | GNUNET_log ( |
343 | GNUNET_ERROR_TYPE_WARNING, | 344 | GNUNET_ERROR_TYPE_WARNING, |
344 | _( | 345 | _ ( |
345 | "Failed to access full directroy contents of `%s' for recursive download\n"), | 346 | "Failed to access full directroy contents of `%s' for recursive download\n"), |
346 | dc->filename); | 347 | dc->filename); |
347 | } | 348 | } |
348 | GNUNET_DISK_file_unmap(m); | 349 | GNUNET_DISK_file_unmap (m); |
349 | } | 350 | } |
350 | GNUNET_DISK_file_close(h); | 351 | GNUNET_DISK_file_close (h); |
351 | if (NULL == dc->filename) | 352 | if (NULL == dc->filename) |
352 | { | 353 | { |
353 | if (0 != unlink(dc->temp_filename)) | 354 | if (0 != unlink (dc->temp_filename)) |
354 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, | 355 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
355 | "unlink", | 356 | "unlink", |
356 | dc->temp_filename); | 357 | dc->temp_filename); |
357 | GNUNET_free(dc->temp_filename); | 358 | GNUNET_free (dc->temp_filename); |
358 | dc->temp_filename = NULL; | 359 | dc->temp_filename = NULL; |
359 | } | 360 | } |
360 | } | 361 | } |
361 | 362 | ||
362 | 363 | ||
@@ -371,48 +372,48 @@ full_recursive_download(struct GNUNET_FS_DownloadContext *dc) | |||
371 | * @param dc download to check for completion of children | 372 | * @param dc download to check for completion of children |
372 | */ | 373 | */ |
373 | static void | 374 | static void |
374 | check_completed(struct GNUNET_FS_DownloadContext *dc) | 375 | check_completed (struct GNUNET_FS_DownloadContext *dc) |
375 | { | 376 | { |
376 | struct GNUNET_FS_ProgressInfo pi; | 377 | struct GNUNET_FS_ProgressInfo pi; |
377 | struct GNUNET_FS_DownloadContext *pos; | 378 | struct GNUNET_FS_DownloadContext *pos; |
378 | 379 | ||
379 | /* first, check if we need to download children */ | 380 | /* first, check if we need to download children */ |
380 | if (is_recursive_download(dc)) | 381 | if (is_recursive_download (dc)) |
381 | full_recursive_download(dc); | 382 | full_recursive_download (dc); |
382 | /* then, check if children are done already */ | 383 | /* then, check if children are done already */ |
383 | for (pos = dc->child_head; NULL != pos; pos = pos->next) | 384 | for (pos = dc->child_head; NULL != pos; pos = pos->next) |
384 | { | 385 | { |
385 | if ((NULL == pos->emsg) && (pos->completed < pos->length)) | 386 | if ((NULL == pos->emsg) && (pos->completed < pos->length)) |
386 | return; /* not done yet */ | 387 | return; /* not done yet */ |
387 | if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES)) | 388 | if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES)) |
388 | return; /* not transitively done yet */ | 389 | return; /* not transitively done yet */ |
389 | } | 390 | } |
390 | /* All of our children are done, so mark this download done */ | 391 | /* All of our children are done, so mark this download done */ |
391 | dc->has_finished = GNUNET_YES; | 392 | dc->has_finished = GNUNET_YES; |
392 | if (NULL != dc->job_queue) | 393 | if (NULL != dc->job_queue) |
393 | { | 394 | { |
394 | GNUNET_FS_dequeue_(dc->job_queue); | 395 | GNUNET_FS_dequeue_ (dc->job_queue); |
395 | dc->job_queue = NULL; | 396 | dc->job_queue = NULL; |
396 | } | 397 | } |
397 | if (NULL != dc->task) | 398 | if (NULL != dc->task) |
398 | { | 399 | { |
399 | GNUNET_SCHEDULER_cancel(dc->task); | 400 | GNUNET_SCHEDULER_cancel (dc->task); |
400 | dc->task = NULL; | 401 | dc->task = NULL; |
401 | } | 402 | } |
402 | if (NULL != dc->rfh) | 403 | if (NULL != dc->rfh) |
403 | { | 404 | { |
404 | GNUNET_break(GNUNET_OK == GNUNET_DISK_file_close(dc->rfh)); | 405 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); |
405 | dc->rfh = NULL; | 406 | dc->rfh = NULL; |
406 | } | 407 | } |
407 | GNUNET_FS_download_sync_(dc); | 408 | GNUNET_FS_download_sync_ (dc); |
408 | 409 | ||
409 | /* signal completion */ | 410 | /* signal completion */ |
410 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_COMPLETED; | 411 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_COMPLETED; |
411 | GNUNET_FS_download_make_status_(&pi, dc); | 412 | GNUNET_FS_download_make_status_ (&pi, dc); |
412 | 413 | ||
413 | /* let parent know */ | 414 | /* let parent know */ |
414 | if (NULL != dc->parent) | 415 | if (NULL != dc->parent) |
415 | check_completed(dc->parent); | 416 | check_completed (dc->parent); |
416 | } | 417 | } |
417 | 418 | ||
418 | 419 | ||
@@ -427,10 +428,10 @@ check_completed(struct GNUNET_FS_DownloadContext *dc) | |||
427 | * @param data_len number of bytes in data | 428 | * @param data_len number of bytes in data |
428 | */ | 429 | */ |
429 | static void | 430 | static void |
430 | try_match_block(struct GNUNET_FS_DownloadContext *dc, | 431 | try_match_block (struct GNUNET_FS_DownloadContext *dc, |
431 | struct DownloadRequest *dr, | 432 | struct DownloadRequest *dr, |
432 | const char *data, | 433 | const char *data, |
433 | size_t data_len) | 434 | size_t data_len) |
434 | { | 435 | { |
435 | struct GNUNET_FS_ProgressInfo pi; | 436 | struct GNUNET_FS_ProgressInfo pi; |
436 | unsigned int i; | 437 | unsigned int i; |
@@ -452,130 +453,130 @@ try_match_block(struct GNUNET_FS_DownloadContext *dc, | |||
452 | if (BRS_DOWNLOAD_UP == dr->state) | 453 | if (BRS_DOWNLOAD_UP == dr->state) |
453 | return; | 454 | return; |
454 | if (dr->depth > 0) | 455 | if (dr->depth > 0) |
455 | { | 456 | { |
456 | if ((dc->offset > 0) || | 457 | if ((dc->offset > 0) || |
457 | (dc->length < GNUNET_ntohll(dc->uri->data.chk.file_length))) | 458 | (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length))) |
458 | { | 459 | { |
459 | /* NOTE: this test is not tight, but should suffice; the issue | 460 | /* NOTE: this test is not tight, but should suffice; the issue |
460 | here is that 'dr->num_children' may inherently only specify a | 461 | here is that 'dr->num_children' may inherently only specify a |
461 | smaller range than what is in the original file; | 462 | smaller range than what is in the original file; |
462 | thus, reconstruction of (some) inner blocks will fail. | 463 | thus, reconstruction of (some) inner blocks will fail. |
463 | FIXME: we might eventually want to write a tighter test to | 464 | FIXME: we might eventually want to write a tighter test to |
464 | maximize the circumstances under which we do succeed with | 465 | maximize the circumstances under which we do succeed with |
465 | IBlock reconstruction. (need good tests though). */ | 466 | IBlock reconstruction. (need good tests though). */ |
466 | return; | 467 | return; |
467 | } | ||
468 | complete = GNUNET_YES; | ||
469 | for (i = 0; i < dr->num_children; i++) | ||
470 | { | ||
471 | drc = dr->children[i]; | ||
472 | try_match_block(dc, drc, data, data_len); | ||
473 | if (drc->state != BRS_RECONSTRUCT_META_UP) | ||
474 | complete = GNUNET_NO; | ||
475 | else | ||
476 | chks[i] = drc->chk; | ||
477 | } | ||
478 | if (GNUNET_YES != complete) | ||
479 | return; | ||
480 | data = (const char *)chks; | ||
481 | dlen = dr->num_children * sizeof(struct ContentHashKey); | ||
482 | } | 468 | } |
483 | else | 469 | complete = GNUNET_YES; |
470 | for (i = 0; i < dr->num_children; i++) | ||
484 | { | 471 | { |
485 | if (dr->offset > data_len) | 472 | drc = dr->children[i]; |
486 | return; /* oops */ | 473 | try_match_block (dc, drc, data, data_len); |
487 | dlen = GNUNET_MIN(data_len - dr->offset, DBLOCK_SIZE); | 474 | if (drc->state != BRS_RECONSTRUCT_META_UP) |
475 | complete = GNUNET_NO; | ||
476 | else | ||
477 | chks[i] = drc->chk; | ||
488 | } | 478 | } |
489 | GNUNET_CRYPTO_hash(&data[dr->offset], dlen, &in_chk.key); | 479 | if (GNUNET_YES != complete) |
490 | GNUNET_CRYPTO_hash_to_aes_key(&in_chk.key, &sk, &iv); | ||
491 | if (-1 == | ||
492 | GNUNET_CRYPTO_symmetric_encrypt(&data[dr->offset], dlen, &sk, &iv, enc)) | ||
493 | { | ||
494 | GNUNET_break(0); | ||
495 | return; | 480 | return; |
496 | } | 481 | data = (const char *) chks; |
497 | GNUNET_CRYPTO_hash(enc, dlen, &in_chk.query); | 482 | dlen = dr->num_children * sizeof(struct ContentHashKey); |
483 | } | ||
484 | else | ||
485 | { | ||
486 | if (dr->offset > data_len) | ||
487 | return; /* oops */ | ||
488 | dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE); | ||
489 | } | ||
490 | GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key); | ||
491 | GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); | ||
492 | if (-1 == | ||
493 | GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], dlen, &sk, &iv, enc)) | ||
494 | { | ||
495 | GNUNET_break (0); | ||
496 | return; | ||
497 | } | ||
498 | GNUNET_CRYPTO_hash (enc, dlen, &in_chk.query); | ||
498 | switch (dr->state) | 499 | switch (dr->state) |
499 | { | 500 | { |
500 | case BRS_INIT: | 501 | case BRS_INIT: |
501 | dr->chk = in_chk; | 502 | dr->chk = in_chk; |
502 | dr->state = BRS_RECONSTRUCT_META_UP; | 503 | dr->state = BRS_RECONSTRUCT_META_UP; |
503 | break; | 504 | break; |
504 | |||
505 | case BRS_CHK_SET: | ||
506 | if (0 != memcmp(&in_chk, &dr->chk, sizeof(struct ContentHashKey))) | ||
507 | { | ||
508 | /* other peer provided bogus meta data */ | ||
509 | GNUNET_break_op(0); | ||
510 | break; | ||
511 | } | ||
512 | /* write block to disk */ | ||
513 | fn = (NULL != dc->filename) ? dc->filename : dc->temp_filename; | ||
514 | if (NULL != fn) | ||
515 | { | ||
516 | fh = GNUNET_DISK_file_open(fn, | ||
517 | GNUNET_DISK_OPEN_READWRITE | | ||
518 | GNUNET_DISK_OPEN_CREATE | | ||
519 | GNUNET_DISK_OPEN_TRUNCATE, | ||
520 | GNUNET_DISK_PERM_USER_READ | | ||
521 | GNUNET_DISK_PERM_USER_WRITE | | ||
522 | GNUNET_DISK_PERM_GROUP_READ | | ||
523 | GNUNET_DISK_PERM_OTHER_READ); | ||
524 | if (NULL == fh) | ||
525 | { | ||
526 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", fn); | ||
527 | GNUNET_asprintf(&dc->emsg, | ||
528 | _("Failed to open file `%s' for writing"), | ||
529 | fn); | ||
530 | GNUNET_DISK_file_close(fh); | ||
531 | dr->state = BRS_ERROR; | ||
532 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | ||
533 | pi.value.download.specifics.error.message = dc->emsg; | ||
534 | GNUNET_FS_download_make_status_(&pi, dc); | ||
535 | return; | ||
536 | } | ||
537 | if (data_len != GNUNET_DISK_file_write(fh, odata, odata_len)) | ||
538 | { | ||
539 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", fn); | ||
540 | GNUNET_asprintf(&dc->emsg, | ||
541 | _("Failed to open file `%s' for writing"), | ||
542 | fn); | ||
543 | GNUNET_DISK_file_close(fh); | ||
544 | dr->state = BRS_ERROR; | ||
545 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | ||
546 | pi.value.download.specifics.error.message = dc->emsg; | ||
547 | GNUNET_FS_download_make_status_(&pi, dc); | ||
548 | return; | ||
549 | } | ||
550 | GNUNET_DISK_file_close(fh); | ||
551 | } | ||
552 | /* signal success */ | ||
553 | dr->state = BRS_DOWNLOAD_UP; | ||
554 | dc->completed = dc->length; | ||
555 | GNUNET_FS_download_sync_(dc); | ||
556 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; | ||
557 | pi.value.download.specifics.progress.data = data; | ||
558 | pi.value.download.specifics.progress.offset = 0; | ||
559 | pi.value.download.specifics.progress.data_len = dlen; | ||
560 | pi.value.download.specifics.progress.depth = 0; | ||
561 | pi.value.download.specifics.progress.respect_offered = 0; | ||
562 | pi.value.download.specifics.progress.block_download_duration = | ||
563 | GNUNET_TIME_UNIT_ZERO; | ||
564 | GNUNET_FS_download_make_status_(&pi, dc); | ||
565 | if ((NULL != dc->filename) && | ||
566 | (0 != truncate(dc->filename, | ||
567 | GNUNET_ntohll(dc->uri->data.chk.file_length)))) | ||
568 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, | ||
569 | "truncate", | ||
570 | dc->filename); | ||
571 | check_completed(dc); | ||
572 | break; | ||
573 | 505 | ||
574 | default: | 506 | case BRS_CHK_SET: |
575 | /* how did we get here? */ | 507 | if (0 != memcmp (&in_chk, &dr->chk, sizeof(struct ContentHashKey))) |
576 | GNUNET_break(0); | 508 | { |
509 | /* other peer provided bogus meta data */ | ||
510 | GNUNET_break_op (0); | ||
577 | break; | 511 | break; |
578 | } | 512 | } |
513 | /* write block to disk */ | ||
514 | fn = (NULL != dc->filename) ? dc->filename : dc->temp_filename; | ||
515 | if (NULL != fn) | ||
516 | { | ||
517 | fh = GNUNET_DISK_file_open (fn, | ||
518 | GNUNET_DISK_OPEN_READWRITE | ||
519 | | GNUNET_DISK_OPEN_CREATE | ||
520 | | GNUNET_DISK_OPEN_TRUNCATE, | ||
521 | GNUNET_DISK_PERM_USER_READ | ||
522 | | GNUNET_DISK_PERM_USER_WRITE | ||
523 | | GNUNET_DISK_PERM_GROUP_READ | ||
524 | | GNUNET_DISK_PERM_OTHER_READ); | ||
525 | if (NULL == fh) | ||
526 | { | ||
527 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); | ||
528 | GNUNET_asprintf (&dc->emsg, | ||
529 | _ ("Failed to open file `%s' for writing"), | ||
530 | fn); | ||
531 | GNUNET_DISK_file_close (fh); | ||
532 | dr->state = BRS_ERROR; | ||
533 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | ||
534 | pi.value.download.specifics.error.message = dc->emsg; | ||
535 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
536 | return; | ||
537 | } | ||
538 | if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len)) | ||
539 | { | ||
540 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); | ||
541 | GNUNET_asprintf (&dc->emsg, | ||
542 | _ ("Failed to open file `%s' for writing"), | ||
543 | fn); | ||
544 | GNUNET_DISK_file_close (fh); | ||
545 | dr->state = BRS_ERROR; | ||
546 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | ||
547 | pi.value.download.specifics.error.message = dc->emsg; | ||
548 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
549 | return; | ||
550 | } | ||
551 | GNUNET_DISK_file_close (fh); | ||
552 | } | ||
553 | /* signal success */ | ||
554 | dr->state = BRS_DOWNLOAD_UP; | ||
555 | dc->completed = dc->length; | ||
556 | GNUNET_FS_download_sync_ (dc); | ||
557 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; | ||
558 | pi.value.download.specifics.progress.data = data; | ||
559 | pi.value.download.specifics.progress.offset = 0; | ||
560 | pi.value.download.specifics.progress.data_len = dlen; | ||
561 | pi.value.download.specifics.progress.depth = 0; | ||
562 | pi.value.download.specifics.progress.respect_offered = 0; | ||
563 | pi.value.download.specifics.progress.block_download_duration = | ||
564 | GNUNET_TIME_UNIT_ZERO; | ||
565 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
566 | if ((NULL != dc->filename) && | ||
567 | (0 != truncate (dc->filename, | ||
568 | GNUNET_ntohll (dc->uri->data.chk.file_length)))) | ||
569 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
570 | "truncate", | ||
571 | dc->filename); | ||
572 | check_completed (dc); | ||
573 | break; | ||
574 | |||
575 | default: | ||
576 | /* how did we get here? */ | ||
577 | GNUNET_break (0); | ||
578 | break; | ||
579 | } | ||
579 | } | 580 | } |
580 | 581 | ||
581 | 582 | ||
@@ -598,27 +599,27 @@ try_match_block(struct GNUNET_FS_DownloadContext *dc, | |||
598 | * @return 0 to continue extracting, 1 to abort | 599 | * @return 0 to continue extracting, 1 to abort |
599 | */ | 600 | */ |
600 | static int | 601 | static int |
601 | match_full_data(void *cls, | 602 | match_full_data (void *cls, |
602 | const char *plugin_name, | 603 | const char *plugin_name, |
603 | enum EXTRACTOR_MetaType type, | 604 | enum EXTRACTOR_MetaType type, |
604 | enum EXTRACTOR_MetaFormat format, | 605 | enum EXTRACTOR_MetaFormat format, |
605 | const char *data_mime_type, | 606 | const char *data_mime_type, |
606 | const char *data, | 607 | const char *data, |
607 | size_t data_len) | 608 | size_t data_len) |
608 | { | 609 | { |
609 | struct GNUNET_FS_DownloadContext *dc = cls; | 610 | struct GNUNET_FS_DownloadContext *dc = cls; |
610 | 611 | ||
611 | if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type) | 612 | if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type) |
612 | return 0; | 613 | return 0; |
613 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
614 | "Found %u bytes of FD!\n", | 615 | "Found %u bytes of FD!\n", |
615 | (unsigned int)data_len); | 616 | (unsigned int) data_len); |
616 | if (GNUNET_FS_uri_chk_get_file_size(dc->uri) != data_len) | 617 | if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) |
617 | { | 618 | { |
618 | GNUNET_break_op(0); | 619 | GNUNET_break_op (0); |
619 | return 1; /* bogus meta data */ | 620 | return 1; /* bogus meta data */ |
620 | } | 621 | } |
621 | try_match_block(dc, dc->top_request, data, data_len); | 622 | try_match_block (dc, dc->top_request, data, data_len); |
622 | return 1; | 623 | return 1; |
623 | } | 624 | } |
624 | 625 | ||
@@ -630,20 +631,20 @@ match_full_data(void *cls, | |||
630 | * @param dr download request that is done | 631 | * @param dr download request that is done |
631 | */ | 632 | */ |
632 | static void | 633 | static void |
633 | propagate_up(struct DownloadRequest *dr) | 634 | propagate_up (struct DownloadRequest *dr) |
634 | { | 635 | { |
635 | unsigned int i; | 636 | unsigned int i; |
636 | 637 | ||
637 | do | 638 | do |
638 | { | 639 | { |
639 | dr->state = BRS_DOWNLOAD_UP; | 640 | dr->state = BRS_DOWNLOAD_UP; |
640 | dr = dr->parent; | 641 | dr = dr->parent; |
641 | if (NULL == dr) | 642 | if (NULL == dr) |
643 | break; | ||
644 | for (i = 0; i < dr->num_children; i++) | ||
645 | if (dr->children[i]->state != BRS_DOWNLOAD_UP) | ||
642 | break; | 646 | break; |
643 | for (i = 0; i < dr->num_children; i++) | 647 | } |
644 | if (dr->children[i]->state != BRS_DOWNLOAD_UP) | ||
645 | break; | ||
646 | } | ||
647 | while (i == dr->num_children); | 648 | while (i == dr->num_children); |
648 | } | 649 | } |
649 | 650 | ||
@@ -659,8 +660,8 @@ propagate_up(struct DownloadRequest *dr) | |||
659 | * @param dr block to reconstruct | 660 | * @param dr block to reconstruct |
660 | */ | 661 | */ |
661 | static void | 662 | static void |
662 | try_top_down_reconstruction(struct GNUNET_FS_DownloadContext *dc, | 663 | try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, |
663 | struct DownloadRequest *dr) | 664 | struct DownloadRequest *dr) |
664 | { | 665 | { |
665 | uint64_t off; | 666 | uint64_t off; |
666 | char block[DBLOCK_SIZE]; | 667 | char block[DBLOCK_SIZE]; |
@@ -673,64 +674,64 @@ try_top_down_reconstruction(struct GNUNET_FS_DownloadContext *dc, | |||
673 | const struct ContentHashKey *chks; | 674 | const struct ContentHashKey *chks; |
674 | int up_done; | 675 | int up_done; |
675 | 676 | ||
676 | GNUNET_assert(NULL != dc->rfh); | 677 | GNUNET_assert (NULL != dc->rfh); |
677 | GNUNET_assert(BRS_CHK_SET == dr->state); | 678 | GNUNET_assert (BRS_CHK_SET == dr->state); |
678 | total = GNUNET_FS_uri_chk_get_file_size(dc->uri); | 679 | total = GNUNET_FS_uri_chk_get_file_size (dc->uri); |
679 | GNUNET_assert(dr->depth < dc->treedepth); | 680 | GNUNET_assert (dr->depth < dc->treedepth); |
680 | len = GNUNET_FS_tree_calculate_block_size(total, dr->offset, dr->depth); | 681 | len = GNUNET_FS_tree_calculate_block_size (total, dr->offset, dr->depth); |
681 | GNUNET_assert(len <= DBLOCK_SIZE); | 682 | GNUNET_assert (len <= DBLOCK_SIZE); |
682 | off = compute_disk_offset(total, dr->offset, dr->depth); | 683 | off = compute_disk_offset (total, dr->offset, dr->depth); |
683 | if (dc->old_file_size < off + len) | 684 | if (dc->old_file_size < off + len) |
684 | return; /* failure */ | 685 | return; /* failure */ |
685 | if (off != GNUNET_DISK_file_seek(dc->rfh, off, GNUNET_DISK_SEEK_SET)) | 686 | if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET)) |
686 | { | 687 | { |
687 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename); | 688 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename); |
688 | return; /* failure */ | 689 | return; /* failure */ |
689 | } | 690 | } |
690 | if (len != GNUNET_DISK_file_read(dc->rfh, block, len)) | 691 | if (len != GNUNET_DISK_file_read (dc->rfh, block, len)) |
691 | { | 692 | { |
692 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "read", dc->filename); | 693 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename); |
693 | return; /* failure */ | 694 | return; /* failure */ |
694 | } | 695 | } |
695 | GNUNET_CRYPTO_hash(block, len, &key); | 696 | GNUNET_CRYPTO_hash (block, len, &key); |
696 | if (0 != memcmp(&key, &dr->chk.key, sizeof(struct GNUNET_HashCode))) | 697 | if (0 != memcmp (&key, &dr->chk.key, sizeof(struct GNUNET_HashCode))) |
697 | return; /* mismatch */ | 698 | return; /* mismatch */ |
698 | if (GNUNET_OK != | 699 | if (GNUNET_OK != |
699 | encrypt_existing_match(dc, &dr->chk, dr, block, len, GNUNET_NO)) | 700 | encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO)) |
701 | { | ||
702 | /* hash matches but encrypted block does not, really bad */ | ||
703 | dr->state = BRS_ERROR; | ||
704 | /* propagate up */ | ||
705 | while (NULL != dr->parent) | ||
700 | { | 706 | { |
701 | /* hash matches but encrypted block does not, really bad */ | 707 | dr = dr->parent; |
702 | dr->state = BRS_ERROR; | 708 | dr->state = BRS_ERROR; |
703 | /* propagate up */ | ||
704 | while (NULL != dr->parent) | ||
705 | { | ||
706 | dr = dr->parent; | ||
707 | dr->state = BRS_ERROR; | ||
708 | } | ||
709 | return; | ||
710 | } | 709 | } |
710 | return; | ||
711 | } | ||
711 | /* block matches */ | 712 | /* block matches */ |
712 | dr->state = BRS_DOWNLOAD_DOWN; | 713 | dr->state = BRS_DOWNLOAD_DOWN; |
713 | 714 | ||
714 | /* set CHKs for children */ | 715 | /* set CHKs for children */ |
715 | up_done = GNUNET_YES; | 716 | up_done = GNUNET_YES; |
716 | chks = (const struct ContentHashKey *)block; | 717 | chks = (const struct ContentHashKey *) block; |
717 | for (i = 0; i < dr->num_children; i++) | 718 | for (i = 0; i < dr->num_children; i++) |
718 | { | 719 | { |
719 | drc = dr->children[i]; | 720 | drc = dr->children[i]; |
720 | GNUNET_assert(drc->offset >= dr->offset); | 721 | GNUNET_assert (drc->offset >= dr->offset); |
721 | child_block_size = GNUNET_FS_tree_compute_tree_size(drc->depth); | 722 | child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth); |
722 | GNUNET_assert(0 == (drc->offset - dr->offset) % child_block_size); | 723 | GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size); |
723 | if (BRS_INIT == drc->state) | 724 | if (BRS_INIT == drc->state) |
724 | { | 725 | { |
725 | drc->state = BRS_CHK_SET; | 726 | drc->state = BRS_CHK_SET; |
726 | drc->chk = chks[drc->chk_idx]; | 727 | drc->chk = chks[drc->chk_idx]; |
727 | try_top_down_reconstruction(dc, drc); | 728 | try_top_down_reconstruction (dc, drc); |
728 | } | 729 | } |
729 | if (BRS_DOWNLOAD_UP != drc->state) | 730 | if (BRS_DOWNLOAD_UP != drc->state) |
730 | up_done = GNUNET_NO; /* children not all done */ | 731 | up_done = GNUNET_NO; /* children not all done */ |
731 | } | 732 | } |
732 | if (GNUNET_YES == up_done) | 733 | if (GNUNET_YES == up_done) |
733 | propagate_up(dr); /* children all done (or no children...) */ | 734 | propagate_up (dr); /* children all done (or no children...) */ |
734 | } | 735 | } |
735 | 736 | ||
736 | 737 | ||
@@ -743,26 +744,26 @@ try_top_down_reconstruction(struct GNUNET_FS_DownloadContext *dc, | |||
743 | * @return #GNUNET_OK | 744 | * @return #GNUNET_OK |
744 | */ | 745 | */ |
745 | static int | 746 | static int |
746 | retry_entry(void *cls, const struct GNUNET_HashCode *key, void *entry) | 747 | retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry) |
747 | { | 748 | { |
748 | struct GNUNET_FS_DownloadContext *dc = cls; | 749 | struct GNUNET_FS_DownloadContext *dc = cls; |
749 | struct DownloadRequest *dr = entry; | 750 | struct DownloadRequest *dr = entry; |
750 | struct SearchMessage *sm; | 751 | struct SearchMessage *sm; |
751 | struct GNUNET_MQ_Envelope *env; | 752 | struct GNUNET_MQ_Envelope *env; |
752 | 753 | ||
753 | env = GNUNET_MQ_msg(sm, GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | 754 | env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_FS_START_SEARCH); |
754 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) | 755 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) |
755 | sm->options = htonl(GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); | 756 | sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); |
756 | else | 757 | else |
757 | sm->options = htonl(GNUNET_FS_SEARCH_OPTION_NONE); | 758 | sm->options = htonl (GNUNET_FS_SEARCH_OPTION_NONE); |
758 | if (0 == dr->depth) | 759 | if (0 == dr->depth) |
759 | sm->type = htonl(GNUNET_BLOCK_TYPE_FS_DBLOCK); | 760 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK); |
760 | else | 761 | else |
761 | sm->type = htonl(GNUNET_BLOCK_TYPE_FS_IBLOCK); | 762 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK); |
762 | sm->anonymity_level = htonl(dc->anonymity); | 763 | sm->anonymity_level = htonl (dc->anonymity); |
763 | sm->target = dc->target; | 764 | sm->target = dc->target; |
764 | sm->query = dr->chk.query; | 765 | sm->query = dr->chk.query; |
765 | GNUNET_MQ_send(dc->mq, env); | 766 | GNUNET_MQ_send (dc->mq, env); |
766 | return GNUNET_OK; | 767 | return GNUNET_OK; |
767 | } | 768 | } |
768 | 769 | ||
@@ -774,62 +775,62 @@ retry_entry(void *cls, const struct GNUNET_HashCode *key, void *entry) | |||
774 | * @param dr request to schedule | 775 | * @param dr request to schedule |
775 | */ | 776 | */ |
776 | static void | 777 | static void |
777 | schedule_block_download(struct GNUNET_FS_DownloadContext *dc, | 778 | schedule_block_download (struct GNUNET_FS_DownloadContext *dc, |
778 | struct DownloadRequest *dr) | 779 | struct DownloadRequest *dr) |
779 | { | 780 | { |
780 | unsigned int i; | 781 | unsigned int i; |
781 | 782 | ||
782 | switch (dr->state) | 783 | switch (dr->state) |
783 | { | 784 | { |
784 | case BRS_INIT: | 785 | case BRS_INIT: |
785 | GNUNET_assert(0); | 786 | GNUNET_assert (0); |
786 | break; | 787 | break; |
787 | 788 | ||
788 | case BRS_RECONSTRUCT_DOWN: | 789 | case BRS_RECONSTRUCT_DOWN: |
789 | GNUNET_assert(0); | 790 | GNUNET_assert (0); |
790 | break; | 791 | break; |
791 | 792 | ||
792 | case BRS_RECONSTRUCT_META_UP: | 793 | case BRS_RECONSTRUCT_META_UP: |
793 | GNUNET_assert(0); | 794 | GNUNET_assert (0); |
794 | break; | 795 | break; |
795 | 796 | ||
796 | case BRS_RECONSTRUCT_UP: | 797 | case BRS_RECONSTRUCT_UP: |
797 | GNUNET_assert(0); | 798 | GNUNET_assert (0); |
798 | break; | 799 | break; |
799 | 800 | ||
800 | case BRS_CHK_SET: | 801 | case BRS_CHK_SET: |
801 | /* normal case, start download */ | 802 | /* normal case, start download */ |
802 | break; | 803 | break; |
803 | 804 | ||
804 | case BRS_DOWNLOAD_DOWN: | 805 | case BRS_DOWNLOAD_DOWN: |
805 | for (i = 0; i < dr->num_children; i++) | 806 | for (i = 0; i < dr->num_children; i++) |
806 | schedule_block_download(dc, dr->children[i]); | 807 | schedule_block_download (dc, dr->children[i]); |
807 | return; | 808 | return; |
808 | 809 | ||
809 | case BRS_DOWNLOAD_UP: | 810 | case BRS_DOWNLOAD_UP: |
810 | /* We're done! */ | 811 | /* We're done! */ |
811 | return; | 812 | return; |
812 | 813 | ||
813 | case BRS_ERROR: | 814 | case BRS_ERROR: |
814 | GNUNET_break(0); | 815 | GNUNET_break (0); |
815 | return; | 816 | return; |
816 | } | 817 | } |
817 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 818 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
818 | "Scheduling download at offset %llu and depth %u for `%s'\n", | 819 | "Scheduling download at offset %llu and depth %u for `%s'\n", |
819 | (unsigned long long)dr->offset, | 820 | (unsigned long long) dr->offset, |
820 | dr->depth, | 821 | dr->depth, |
821 | GNUNET_h2s(&dr->chk.query)); | 822 | GNUNET_h2s (&dr->chk.query)); |
822 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains_value(dc->active, | 823 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains_value (dc->active, |
823 | &dr->chk.query, | 824 | &dr->chk.query, |
824 | dr)) | 825 | dr)) |
825 | return; /* already active */ | 826 | return; /* already active */ |
826 | GNUNET_CONTAINER_multihashmap_put(dc->active, | 827 | GNUNET_CONTAINER_multihashmap_put (dc->active, |
827 | &dr->chk.query, | 828 | &dr->chk.query, |
828 | dr, | 829 | dr, |
829 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 830 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
830 | if (NULL == dc->mq) | 831 | if (NULL == dc->mq) |
831 | return; /* download not active */ | 832 | return; /* download not active */ |
832 | retry_entry(dc, &dr->chk.query, dr); | 833 | retry_entry (dc, &dr->chk.query, dr); |
833 | } | 834 | } |
834 | 835 | ||
835 | 836 | ||
@@ -847,12 +848,12 @@ schedule_block_download(struct GNUNET_FS_DownloadContext *dc, | |||
847 | * @param data contents of the file (or NULL if they were not inlined) | 848 | * @param data contents of the file (or NULL if they were not inlined) |
848 | */ | 849 | */ |
849 | static void | 850 | static void |
850 | trigger_recursive_download(void *cls, | 851 | trigger_recursive_download (void *cls, |
851 | const char *filename, | 852 | const char *filename, |
852 | const struct GNUNET_FS_Uri *uri, | 853 | const struct GNUNET_FS_Uri *uri, |
853 | const struct GNUNET_CONTAINER_MetaData *meta, | 854 | const struct GNUNET_CONTAINER_MetaData *meta, |
854 | size_t length, | 855 | size_t length, |
855 | const void *data) | 856 | const void *data) |
856 | { | 857 | { |
857 | struct GNUNET_FS_DownloadContext *dc = cls; | 858 | struct GNUNET_FS_DownloadContext *dc = cls; |
858 | struct GNUNET_FS_DownloadContext *cpos; | 859 | struct GNUNET_FS_DownloadContext *cpos; |
@@ -869,121 +870,121 @@ trigger_recursive_download(void *cls, | |||
869 | return; /* entry for the directory itself */ | 870 | return; /* entry for the directory itself */ |
870 | cpos = dc->child_head; | 871 | cpos = dc->child_head; |
871 | while (NULL != cpos) | 872 | while (NULL != cpos) |
872 | { | 873 | { |
873 | if ((GNUNET_FS_uri_test_equal(uri, cpos->uri)) || | 874 | if ((GNUNET_FS_uri_test_equal (uri, cpos->uri)) || |
874 | ((NULL != filename) && (0 == strcmp(cpos->filename, filename)))) | 875 | ((NULL != filename) && (0 == strcmp (cpos->filename, filename)))) |
875 | break; | 876 | break; |
876 | cpos = cpos->next; | 877 | cpos = cpos->next; |
877 | } | 878 | } |
878 | if (NULL != cpos) | 879 | if (NULL != cpos) |
879 | return; /* already exists */ | 880 | return; /* already exists */ |
880 | fn = NULL; | 881 | fn = NULL; |
881 | if (NULL == filename) | 882 | if (NULL == filename) |
882 | { | 883 | { |
883 | fn = GNUNET_FS_meta_data_suggest_filename(meta); | 884 | fn = GNUNET_FS_meta_data_suggest_filename (meta); |
884 | if (NULL == fn) | 885 | if (NULL == fn) |
885 | { | 886 | { |
886 | us = GNUNET_FS_uri_to_string(uri); | 887 | us = GNUNET_FS_uri_to_string (uri); |
887 | fn = GNUNET_strdup(&us[strlen(GNUNET_FS_URI_CHK_PREFIX)]); | 888 | fn = GNUNET_strdup (&us[strlen (GNUNET_FS_URI_CHK_PREFIX)]); |
888 | GNUNET_free(us); | 889 | GNUNET_free (us); |
889 | } | 890 | } |
890 | else if ('.' == fn[0]) | 891 | else if ('.' == fn[0]) |
891 | { | 892 | { |
892 | ext = fn; | 893 | ext = fn; |
893 | us = GNUNET_FS_uri_to_string(uri); | 894 | us = GNUNET_FS_uri_to_string (uri); |
894 | GNUNET_asprintf(&fn, | 895 | GNUNET_asprintf (&fn, |
895 | "%s%s", | 896 | "%s%s", |
896 | &us[strlen(GNUNET_FS_URI_CHK_PREFIX)], | 897 | &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], |
897 | ext); | 898 | ext); |
898 | GNUNET_free(ext); | 899 | GNUNET_free (ext); |
899 | GNUNET_free(us); | 900 | GNUNET_free (us); |
900 | } | 901 | } |
901 | /* change '\' to '/' (this should have happened | 902 | /* change '\' to '/' (this should have happened |
902 | * during insertion, but malicious peers may | 903 | * during insertion, but malicious peers may |
903 | * not have done this) */ | 904 | * not have done this) */ |
904 | while (NULL != (pos = strstr(fn, "\\"))) | 905 | while (NULL != (pos = strstr (fn, "\\"))) |
905 | *pos = '/'; | 906 | *pos = '/'; |
906 | /* remove '../' everywhere (again, well-behaved | 907 | /* remove '../' everywhere (again, well-behaved |
907 | * peers don't do this, but don't trust that | 908 | * peers don't do this, but don't trust that |
908 | * we did not get something nasty) */ | 909 | * we did not get something nasty) */ |
909 | while (NULL != (pos = strstr(fn, "../"))) | 910 | while (NULL != (pos = strstr (fn, "../"))) |
910 | { | 911 | { |
911 | pos[0] = '_'; | 912 | pos[0] = '_'; |
912 | pos[1] = '_'; | 913 | pos[1] = '_'; |
913 | pos[2] = '_'; | 914 | pos[2] = '_'; |
914 | } | 915 | } |
915 | filename = fn; | 916 | filename = fn; |
916 | } | 917 | } |
917 | if (NULL == dc->filename) | 918 | if (NULL == dc->filename) |
918 | { | 919 | { |
919 | full_name = NULL; | 920 | full_name = NULL; |
920 | } | 921 | } |
921 | else | 922 | else |
922 | { | 923 | { |
923 | dn = GNUNET_strdup(dc->filename); | 924 | dn = GNUNET_strdup (dc->filename); |
924 | GNUNET_break( | 925 | GNUNET_break ( |
925 | (strlen(dn) >= strlen(GNUNET_FS_DIRECTORY_EXT)) && | 926 | (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && |
926 | (NULL != strstr(dn + strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT), | 927 | (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), |
927 | GNUNET_FS_DIRECTORY_EXT))); | 928 | GNUNET_FS_DIRECTORY_EXT))); |
928 | sfn = GNUNET_strdup(filename); | 929 | sfn = GNUNET_strdup (filename); |
929 | while ((strlen(sfn) > 0) && ('/' == filename[strlen(sfn) - 1])) | 930 | while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1])) |
930 | sfn[strlen(sfn) - 1] = '\0'; | 931 | sfn[strlen (sfn) - 1] = '\0'; |
931 | if ((strlen(dn) >= strlen(GNUNET_FS_DIRECTORY_EXT)) && | 932 | if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && |
932 | (NULL != strstr(dn + strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT), | 933 | (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), |
933 | GNUNET_FS_DIRECTORY_EXT))) | 934 | GNUNET_FS_DIRECTORY_EXT))) |
934 | dn[strlen(dn) - strlen(GNUNET_FS_DIRECTORY_EXT)] = '\0'; | 935 | dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0'; |
935 | if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) && | 936 | if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) && |
936 | ((strlen(filename) < strlen(GNUNET_FS_DIRECTORY_EXT)) || | 937 | ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) || |
937 | (NULL == strstr(filename + strlen(filename) - | 938 | (NULL == strstr (filename + strlen (filename) |
938 | strlen(GNUNET_FS_DIRECTORY_EXT), | 939 | - strlen (GNUNET_FS_DIRECTORY_EXT), |
939 | GNUNET_FS_DIRECTORY_EXT)))) | 940 | GNUNET_FS_DIRECTORY_EXT)))) |
940 | { | 941 | { |
941 | GNUNET_asprintf(&full_name, | 942 | GNUNET_asprintf (&full_name, |
942 | "%s%s%s%s", | 943 | "%s%s%s%s", |
943 | dn, | 944 | dn, |
944 | DIR_SEPARATOR_STR, | 945 | DIR_SEPARATOR_STR, |
945 | sfn, | 946 | sfn, |
946 | GNUNET_FS_DIRECTORY_EXT); | 947 | GNUNET_FS_DIRECTORY_EXT); |
947 | } | 948 | } |
948 | else | 949 | else |
949 | { | 950 | { |
950 | GNUNET_asprintf(&full_name, "%s%s%s", dn, DIR_SEPARATOR_STR, sfn); | 951 | GNUNET_asprintf (&full_name, "%s%s%s", dn, DIR_SEPARATOR_STR, sfn); |
951 | } | 952 | } |
952 | GNUNET_free(sfn); | 953 | GNUNET_free (sfn); |
953 | GNUNET_free(dn); | 954 | GNUNET_free (dn); |
954 | } | 955 | } |
955 | if ((NULL != full_name) && | 956 | if ((NULL != full_name) && |
956 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file(full_name))) | 957 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name))) |
957 | { | 958 | { |
958 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 959 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
959 | _( | 960 | _ ( |
960 | "Failed to create directory for recursive download of `%s'\n"), | 961 | "Failed to create directory for recursive download of `%s'\n"), |
961 | full_name); | 962 | full_name); |
962 | GNUNET_free(full_name); | 963 | GNUNET_free (full_name); |
963 | GNUNET_free_non_null(fn); | 964 | GNUNET_free_non_null (fn); |
964 | return; | 965 | return; |
965 | } | 966 | } |
966 | 967 | ||
967 | temp_name = NULL; | 968 | temp_name = NULL; |
968 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 969 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
969 | "Triggering recursive download of size %llu with %u bytes MD\n", | 970 | "Triggering recursive download of size %llu with %u bytes MD\n", |
970 | (unsigned long long)GNUNET_FS_uri_chk_get_file_size(uri), | 971 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), |
971 | (unsigned int)GNUNET_CONTAINER_meta_data_get_serialized_size( | 972 | (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size ( |
972 | meta)); | 973 | meta)); |
973 | GNUNET_FS_download_start(dc->h, | 974 | GNUNET_FS_download_start (dc->h, |
974 | uri, | 975 | uri, |
975 | meta, | 976 | meta, |
976 | full_name, | 977 | full_name, |
977 | temp_name, | 978 | temp_name, |
978 | 0, | 979 | 0, |
979 | GNUNET_FS_uri_chk_get_file_size(uri), | 980 | GNUNET_FS_uri_chk_get_file_size (uri), |
980 | dc->anonymity, | 981 | dc->anonymity, |
981 | dc->options, | 982 | dc->options, |
982 | NULL, | 983 | NULL, |
983 | dc); | 984 | dc); |
984 | GNUNET_free_non_null(full_name); | 985 | GNUNET_free_non_null (full_name); |
985 | GNUNET_free_non_null(temp_name); | 986 | GNUNET_free_non_null (temp_name); |
986 | GNUNET_free_non_null(fn); | 987 | GNUNET_free_non_null (fn); |
987 | } | 988 | } |
988 | 989 | ||
989 | 990 | ||
@@ -993,14 +994,14 @@ trigger_recursive_download(void *cls, | |||
993 | * @param dr request to free | 994 | * @param dr request to free |
994 | */ | 995 | */ |
995 | void | 996 | void |
996 | GNUNET_FS_free_download_request_(struct DownloadRequest *dr) | 997 | GNUNET_FS_free_download_request_ (struct DownloadRequest *dr) |
997 | { | 998 | { |
998 | if (NULL == dr) | 999 | if (NULL == dr) |
999 | return; | 1000 | return; |
1000 | for (unsigned int i = 0; i < dr->num_children; i++) | 1001 | for (unsigned int i = 0; i < dr->num_children; i++) |
1001 | GNUNET_FS_free_download_request_(dr->children[i]); | 1002 | GNUNET_FS_free_download_request_ (dr->children[i]); |
1002 | GNUNET_free_non_null(dr->children); | 1003 | GNUNET_free_non_null (dr->children); |
1003 | GNUNET_free(dr); | 1004 | GNUNET_free (dr); |
1004 | } | 1005 | } |
1005 | 1006 | ||
1006 | 1007 | ||
@@ -1014,9 +1015,9 @@ GNUNET_FS_free_download_request_(struct DownloadRequest *dr) | |||
1014 | * @return #GNUNET_YES (we should continue to iterate); unless serious error | 1015 | * @return #GNUNET_YES (we should continue to iterate); unless serious error |
1015 | */ | 1016 | */ |
1016 | static int | 1017 | static int |
1017 | process_result_with_request(void *cls, | 1018 | process_result_with_request (void *cls, |
1018 | const struct GNUNET_HashCode *key, | 1019 | const struct GNUNET_HashCode *key, |
1019 | void *value) | 1020 | void *value) |
1020 | { | 1021 | { |
1021 | struct ProcessResultClosure *prc = cls; | 1022 | struct ProcessResultClosure *prc = cls; |
1022 | struct DownloadRequest *dr = value; | 1023 | struct DownloadRequest *dr = value; |
@@ -1033,132 +1034,132 @@ process_result_with_request(void *cls, | |||
1033 | int i; | 1034 | int i; |
1034 | struct ContentHashKey *chkarr; | 1035 | struct ContentHashKey *chkarr; |
1035 | 1036 | ||
1036 | GNUNET_log( | 1037 | GNUNET_log ( |
1037 | GNUNET_ERROR_TYPE_DEBUG, | 1038 | GNUNET_ERROR_TYPE_DEBUG, |
1038 | "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n", | 1039 | "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n", |
1039 | (unsigned int)prc->size, | 1040 | (unsigned int) prc->size, |
1040 | GNUNET_h2s(key), | 1041 | GNUNET_h2s (key), |
1041 | dr->depth, | 1042 | dr->depth, |
1042 | (unsigned long long)dr->offset, | 1043 | (unsigned long long) dr->offset, |
1043 | (unsigned long long)GNUNET_ntohll(dc->uri->data.chk.file_length)); | 1044 | (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length)); |
1044 | bs = GNUNET_FS_tree_calculate_block_size(GNUNET_ntohll( | 1045 | bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll ( |
1045 | dc->uri->data.chk.file_length), | 1046 | dc->uri->data.chk.file_length), |
1046 | dr->offset, | 1047 | dr->offset, |
1047 | dr->depth); | 1048 | dr->depth); |
1048 | if (prc->size != bs) | 1049 | if (prc->size != bs) |
1050 | { | ||
1051 | GNUNET_asprintf ( | ||
1052 | &dc->emsg, | ||
1053 | _ ( | ||
1054 | "Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), | ||
1055 | bs, | ||
1056 | dr->depth, | ||
1057 | (unsigned long long) dr->offset, | ||
1058 | (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length), | ||
1059 | prc->size); | ||
1060 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg); | ||
1061 | while (NULL != dr->parent) | ||
1049 | { | 1062 | { |
1050 | GNUNET_asprintf( | ||
1051 | &dc->emsg, | ||
1052 | _( | ||
1053 | "Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), | ||
1054 | bs, | ||
1055 | dr->depth, | ||
1056 | (unsigned long long)dr->offset, | ||
1057 | (unsigned long long)GNUNET_ntohll(dc->uri->data.chk.file_length), | ||
1058 | prc->size); | ||
1059 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg); | ||
1060 | while (NULL != dr->parent) | ||
1061 | { | ||
1062 | dr->state = BRS_ERROR; | ||
1063 | dr = dr->parent; | ||
1064 | } | ||
1065 | dr->state = BRS_ERROR; | 1063 | dr->state = BRS_ERROR; |
1066 | goto signal_error; | 1064 | dr = dr->parent; |
1067 | } | 1065 | } |
1066 | dr->state = BRS_ERROR; | ||
1067 | goto signal_error; | ||
1068 | } | ||
1068 | 1069 | ||
1069 | (void)GNUNET_CONTAINER_multihashmap_remove(dc->active, &prc->query, dr); | 1070 | (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, &prc->query, dr); |
1070 | GNUNET_CRYPTO_hash_to_aes_key(&dr->chk.key, &skey, &iv); | 1071 | GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv); |
1071 | if (-1 == | 1072 | if (-1 == |
1072 | GNUNET_CRYPTO_symmetric_decrypt(prc->data, prc->size, &skey, &iv, pt)) | 1073 | GNUNET_CRYPTO_symmetric_decrypt (prc->data, prc->size, &skey, &iv, pt)) |
1073 | { | 1074 | { |
1074 | GNUNET_break(0); | 1075 | GNUNET_break (0); |
1075 | dc->emsg = GNUNET_strdup(_("internal error decrypting content")); | 1076 | dc->emsg = GNUNET_strdup (_ ("internal error decrypting content")); |
1076 | goto signal_error; | 1077 | goto signal_error; |
1077 | } | 1078 | } |
1078 | off = compute_disk_offset(GNUNET_ntohll(dc->uri->data.chk.file_length), | 1079 | off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), |
1079 | dr->offset, | 1080 | dr->offset, |
1080 | dr->depth); | 1081 | dr->depth); |
1081 | /* save to disk */ | 1082 | /* save to disk */ |
1082 | if ((GNUNET_YES == prc->do_store) && | 1083 | if ((GNUNET_YES == prc->do_store) && |
1083 | ((NULL != dc->filename) || (is_recursive_download(dc))) && | 1084 | ((NULL != dc->filename) || (is_recursive_download (dc))) && |
1084 | ((dr->depth == dc->treedepth) || | 1085 | ((dr->depth == dc->treedepth) || |
1085 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) | 1086 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) |
1087 | { | ||
1088 | fh = GNUNET_DISK_file_open (NULL != dc->filename ? dc->filename | ||
1089 | : dc->temp_filename, | ||
1090 | GNUNET_DISK_OPEN_READWRITE | ||
1091 | | GNUNET_DISK_OPEN_CREATE, | ||
1092 | GNUNET_DISK_PERM_USER_READ | ||
1093 | | GNUNET_DISK_PERM_USER_WRITE | ||
1094 | | GNUNET_DISK_PERM_GROUP_READ | ||
1095 | | GNUNET_DISK_PERM_OTHER_READ); | ||
1096 | if (NULL == fh) | ||
1097 | { | ||
1098 | GNUNET_asprintf (&dc->emsg, | ||
1099 | _ ("Download failed: could not open file `%s': %s"), | ||
1100 | dc->filename, | ||
1101 | strerror (errno)); | ||
1102 | goto signal_error; | ||
1103 | } | ||
1104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1105 | "Saving decrypted block to disk at offset %llu\n", | ||
1106 | (unsigned long long) off); | ||
1107 | if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET))) | ||
1086 | { | 1108 | { |
1087 | fh = GNUNET_DISK_file_open(NULL != dc->filename ? dc->filename | 1109 | GNUNET_asprintf (&dc->emsg, |
1088 | : dc->temp_filename, | 1110 | _ ("Failed to seek to offset %llu in file `%s': %s"), |
1089 | GNUNET_DISK_OPEN_READWRITE | | 1111 | (unsigned long long) off, |
1090 | GNUNET_DISK_OPEN_CREATE, | 1112 | dc->filename, |
1091 | GNUNET_DISK_PERM_USER_READ | | 1113 | strerror (errno)); |
1092 | GNUNET_DISK_PERM_USER_WRITE | | 1114 | goto signal_error; |
1093 | GNUNET_DISK_PERM_GROUP_READ | | ||
1094 | GNUNET_DISK_PERM_OTHER_READ); | ||
1095 | if (NULL == fh) | ||
1096 | { | ||
1097 | GNUNET_asprintf(&dc->emsg, | ||
1098 | _("Download failed: could not open file `%s': %s"), | ||
1099 | dc->filename, | ||
1100 | strerror(errno)); | ||
1101 | goto signal_error; | ||
1102 | } | ||
1103 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1104 | "Saving decrypted block to disk at offset %llu\n", | ||
1105 | (unsigned long long)off); | ||
1106 | if ((off != GNUNET_DISK_file_seek(fh, off, GNUNET_DISK_SEEK_SET))) | ||
1107 | { | ||
1108 | GNUNET_asprintf(&dc->emsg, | ||
1109 | _("Failed to seek to offset %llu in file `%s': %s"), | ||
1110 | (unsigned long long)off, | ||
1111 | dc->filename, | ||
1112 | strerror(errno)); | ||
1113 | goto signal_error; | ||
1114 | } | ||
1115 | if (prc->size != GNUNET_DISK_file_write(fh, pt, prc->size)) | ||
1116 | { | ||
1117 | GNUNET_asprintf( | ||
1118 | &dc->emsg, | ||
1119 | _("Failed to write block of %u bytes at offset %llu in file `%s': %s"), | ||
1120 | (unsigned int)prc->size, | ||
1121 | (unsigned long long)off, | ||
1122 | dc->filename, | ||
1123 | strerror(errno)); | ||
1124 | goto signal_error; | ||
1125 | } | ||
1126 | GNUNET_break(GNUNET_OK == GNUNET_DISK_file_close(fh)); | ||
1127 | fh = NULL; | ||
1128 | } | 1115 | } |
1129 | 1116 | if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size)) | |
1130 | if (0 == dr->depth) | ||
1131 | { | 1117 | { |
1132 | /* DBLOCK, update progress and try recursion if applicable */ | 1118 | GNUNET_asprintf ( |
1133 | app = prc->size; | 1119 | &dc->emsg, |
1134 | if (dr->offset < dc->offset) | 1120 | _ ("Failed to write block of %u bytes at offset %llu in file `%s': %s"), |
1135 | { | 1121 | (unsigned int) prc->size, |
1136 | /* starting offset begins in the middle of pt, | 1122 | (unsigned long long) off, |
1137 | * do not count first bytes as progress */ | 1123 | dc->filename, |
1138 | GNUNET_assert(app > (dc->offset - dr->offset)); | 1124 | strerror (errno)); |
1139 | app -= (dc->offset - dr->offset); | 1125 | goto signal_error; |
1140 | } | ||
1141 | if (dr->offset + prc->size > dc->offset + dc->length) | ||
1142 | { | ||
1143 | /* end of block is after relevant range, | ||
1144 | * do not count last bytes as progress */ | ||
1145 | GNUNET_assert(app > | ||
1146 | (dr->offset + prc->size) - (dc->offset + dc->length)); | ||
1147 | app -= (dr->offset + prc->size) - (dc->offset + dc->length); | ||
1148 | } | ||
1149 | dc->completed += app; | ||
1150 | |||
1151 | /* do recursive download if option is set and either meta data | ||
1152 | * says it is a directory or if no meta data is given AND filename | ||
1153 | * ends in '.gnd' (top-level case) */ | ||
1154 | if (is_recursive_download(dc)) | ||
1155 | GNUNET_FS_directory_list_contents(prc->size, | ||
1156 | pt, | ||
1157 | off, | ||
1158 | &trigger_recursive_download, | ||
1159 | dc); | ||
1160 | } | 1126 | } |
1161 | GNUNET_assert(dc->completed <= dc->length); | 1127 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); |
1128 | fh = NULL; | ||
1129 | } | ||
1130 | |||
1131 | if (0 == dr->depth) | ||
1132 | { | ||
1133 | /* DBLOCK, update progress and try recursion if applicable */ | ||
1134 | app = prc->size; | ||
1135 | if (dr->offset < dc->offset) | ||
1136 | { | ||
1137 | /* starting offset begins in the middle of pt, | ||
1138 | * do not count first bytes as progress */ | ||
1139 | GNUNET_assert (app > (dc->offset - dr->offset)); | ||
1140 | app -= (dc->offset - dr->offset); | ||
1141 | } | ||
1142 | if (dr->offset + prc->size > dc->offset + dc->length) | ||
1143 | { | ||
1144 | /* end of block is after relevant range, | ||
1145 | * do not count last bytes as progress */ | ||
1146 | GNUNET_assert (app > | ||
1147 | (dr->offset + prc->size) - (dc->offset + dc->length)); | ||
1148 | app -= (dr->offset + prc->size) - (dc->offset + dc->length); | ||
1149 | } | ||
1150 | dc->completed += app; | ||
1151 | |||
1152 | /* do recursive download if option is set and either meta data | ||
1153 | * says it is a directory or if no meta data is given AND filename | ||
1154 | * ends in '.gnd' (top-level case) */ | ||
1155 | if (is_recursive_download (dc)) | ||
1156 | GNUNET_FS_directory_list_contents (prc->size, | ||
1157 | pt, | ||
1158 | off, | ||
1159 | &trigger_recursive_download, | ||
1160 | dc); | ||
1161 | } | ||
1162 | GNUNET_assert (dc->completed <= dc->length); | ||
1162 | dr->state = BRS_DOWNLOAD_DOWN; | 1163 | dr->state = BRS_DOWNLOAD_DOWN; |
1163 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; | 1164 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; |
1164 | pi.value.download.specifics.progress.data = pt; | 1165 | pi.value.download.specifics.progress.data = pt; |
@@ -1171,120 +1172,120 @@ process_result_with_request(void *cls, | |||
1171 | if (prc->last_transmission.abs_value_us != | 1172 | if (prc->last_transmission.abs_value_us != |
1172 | GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | 1173 | GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) |
1173 | pi.value.download.specifics.progress.block_download_duration = | 1174 | pi.value.download.specifics.progress.block_download_duration = |
1174 | GNUNET_TIME_absolute_get_duration(prc->last_transmission); | 1175 | GNUNET_TIME_absolute_get_duration (prc->last_transmission); |
1175 | else | 1176 | else |
1176 | pi.value.download.specifics.progress.block_download_duration = | 1177 | pi.value.download.specifics.progress.block_download_duration = |
1177 | GNUNET_TIME_UNIT_ZERO; /* found locally */ | 1178 | GNUNET_TIME_UNIT_ZERO; /* found locally */ |
1178 | GNUNET_FS_download_make_status_(&pi, dc); | 1179 | GNUNET_FS_download_make_status_ (&pi, dc); |
1179 | if (0 == dr->depth) | 1180 | if (0 == dr->depth) |
1180 | propagate_up(dr); | 1181 | propagate_up (dr); |
1181 | 1182 | ||
1182 | if (dc->completed == dc->length) | 1183 | if (dc->completed == dc->length) |
1183 | { | 1184 | { |
1184 | /* download completed, signal */ | 1185 | /* download completed, signal */ |
1185 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1186 | "Download completed, truncating file to desired length %llu\n", | 1187 | "Download completed, truncating file to desired length %llu\n", |
1187 | (unsigned long long)GNUNET_ntohll( | 1188 | (unsigned long long) GNUNET_ntohll ( |
1188 | dc->uri->data.chk.file_length)); | 1189 | dc->uri->data.chk.file_length)); |
1189 | /* truncate file to size (since we store IBlocks at the end) */ | 1190 | /* truncate file to size (since we store IBlocks at the end) */ |
1190 | if (NULL != dc->filename) | 1191 | if (NULL != dc->filename) |
1191 | { | 1192 | { |
1192 | if (0 != truncate(dc->filename, | 1193 | if (0 != truncate (dc->filename, |
1193 | GNUNET_ntohll(dc->uri->data.chk.file_length))) | 1194 | GNUNET_ntohll (dc->uri->data.chk.file_length))) |
1194 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, | 1195 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
1195 | "truncate", | 1196 | "truncate", |
1196 | dc->filename); | 1197 | dc->filename); |
1197 | } | 1198 | } |
1198 | GNUNET_assert(0 == dr->depth); | 1199 | GNUNET_assert (0 == dr->depth); |
1199 | check_completed(dc); | 1200 | check_completed (dc); |
1200 | } | 1201 | } |
1201 | if (0 == dr->depth) | 1202 | if (0 == dr->depth) |
1202 | { | 1203 | { |
1203 | /* bottom of the tree, no child downloads possible, just sync */ | 1204 | /* bottom of the tree, no child downloads possible, just sync */ |
1204 | GNUNET_FS_download_sync_(dc); | 1205 | GNUNET_FS_download_sync_ (dc); |
1205 | return GNUNET_YES; | 1206 | return GNUNET_YES; |
1206 | } | 1207 | } |
1207 | 1208 | ||
1208 | GNUNET_log( | 1209 | GNUNET_log ( |
1209 | GNUNET_ERROR_TYPE_DEBUG, | 1210 | GNUNET_ERROR_TYPE_DEBUG, |
1210 | "Triggering downloads of children (this block was at depth %u and offset %llu)\n", | 1211 | "Triggering downloads of children (this block was at depth %u and offset %llu)\n", |
1211 | dr->depth, | 1212 | dr->depth, |
1212 | (unsigned long long)dr->offset); | 1213 | (unsigned long long) dr->offset); |
1213 | GNUNET_assert(0 == (prc->size % sizeof(struct ContentHashKey))); | 1214 | GNUNET_assert (0 == (prc->size % sizeof(struct ContentHashKey))); |
1214 | chkarr = (struct ContentHashKey *)pt; | 1215 | chkarr = (struct ContentHashKey *) pt; |
1215 | for (i = dr->num_children - 1; i >= 0; i--) | 1216 | for (i = dr->num_children - 1; i >= 0; i--) |
1217 | { | ||
1218 | drc = dr->children[i]; | ||
1219 | switch (drc->state) | ||
1216 | { | 1220 | { |
1217 | drc = dr->children[i]; | 1221 | case BRS_INIT: |
1218 | switch (drc->state) | 1222 | if ((drc->chk_idx + 1) * sizeof(struct ContentHashKey) > prc->size) |
1219 | { | 1223 | { |
1220 | case BRS_INIT: | 1224 | /* 'chkarr' does not have enough space for this chk_idx; |
1221 | if ((drc->chk_idx + 1) * sizeof(struct ContentHashKey) > prc->size) | 1225 | internal error! */ |
1222 | { | 1226 | GNUNET_break (0); |
1223 | /* 'chkarr' does not have enough space for this chk_idx; | 1227 | GNUNET_assert (0); |
1224 | internal error! */ | 1228 | dc->emsg = GNUNET_strdup (_ ("internal error decoding tree")); |
1225 | GNUNET_break(0); | 1229 | goto signal_error; |
1226 | GNUNET_assert(0); | 1230 | } |
1227 | dc->emsg = GNUNET_strdup(_("internal error decoding tree")); | 1231 | drc->chk = chkarr[drc->chk_idx]; |
1228 | goto signal_error; | 1232 | drc->state = BRS_CHK_SET; |
1229 | } | 1233 | if (GNUNET_YES == dc->issue_requests) |
1230 | drc->chk = chkarr[drc->chk_idx]; | 1234 | schedule_block_download (dc, drc); |
1231 | drc->state = BRS_CHK_SET; | 1235 | break; |
1232 | if (GNUNET_YES == dc->issue_requests) | 1236 | |
1233 | schedule_block_download(dc, drc); | 1237 | case BRS_RECONSTRUCT_DOWN: |
1234 | break; | 1238 | GNUNET_assert (0); |
1235 | 1239 | break; | |
1236 | case BRS_RECONSTRUCT_DOWN: | 1240 | |
1237 | GNUNET_assert(0); | 1241 | case BRS_RECONSTRUCT_META_UP: |
1238 | break; | 1242 | GNUNET_assert (0); |
1239 | 1243 | break; | |
1240 | case BRS_RECONSTRUCT_META_UP: | 1244 | |
1241 | GNUNET_assert(0); | 1245 | case BRS_RECONSTRUCT_UP: |
1242 | break; | 1246 | GNUNET_assert (0); |
1243 | 1247 | break; | |
1244 | case BRS_RECONSTRUCT_UP: | 1248 | |
1245 | GNUNET_assert(0); | 1249 | case BRS_CHK_SET: |
1246 | break; | 1250 | GNUNET_assert (0); |
1247 | 1251 | break; | |
1248 | case BRS_CHK_SET: | 1252 | |
1249 | GNUNET_assert(0); | 1253 | case BRS_DOWNLOAD_DOWN: |
1250 | break; | 1254 | GNUNET_assert (0); |
1251 | 1255 | break; | |
1252 | case BRS_DOWNLOAD_DOWN: | 1256 | |
1253 | GNUNET_assert(0); | 1257 | case BRS_DOWNLOAD_UP: |
1254 | break; | 1258 | GNUNET_assert (0); |
1255 | 1259 | break; | |
1256 | case BRS_DOWNLOAD_UP: | 1260 | |
1257 | GNUNET_assert(0); | 1261 | case BRS_ERROR: |
1258 | break; | 1262 | GNUNET_assert (0); |
1259 | 1263 | break; | |
1260 | case BRS_ERROR: | 1264 | |
1261 | GNUNET_assert(0); | 1265 | default: |
1262 | break; | 1266 | GNUNET_assert (0); |
1263 | 1267 | break; | |
1264 | default: | ||
1265 | GNUNET_assert(0); | ||
1266 | break; | ||
1267 | } | ||
1268 | } | 1268 | } |
1269 | GNUNET_FS_download_sync_(dc); | 1269 | } |
1270 | GNUNET_FS_download_sync_ (dc); | ||
1270 | return GNUNET_YES; | 1271 | return GNUNET_YES; |
1271 | 1272 | ||
1272 | signal_error: | 1273 | signal_error: |
1273 | if (NULL != fh) | 1274 | if (NULL != fh) |
1274 | GNUNET_DISK_file_close(fh); | 1275 | GNUNET_DISK_file_close (fh); |
1275 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | 1276 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; |
1276 | pi.value.download.specifics.error.message = dc->emsg; | 1277 | pi.value.download.specifics.error.message = dc->emsg; |
1277 | GNUNET_FS_download_make_status_(&pi, dc); | 1278 | GNUNET_FS_download_make_status_ (&pi, dc); |
1278 | GNUNET_MQ_destroy(dc->mq); | 1279 | GNUNET_MQ_destroy (dc->mq); |
1279 | dc->mq = NULL; | 1280 | dc->mq = NULL; |
1280 | GNUNET_FS_free_download_request_(dc->top_request); | 1281 | GNUNET_FS_free_download_request_ (dc->top_request); |
1281 | dc->top_request = NULL; | 1282 | dc->top_request = NULL; |
1282 | if (NULL != dc->job_queue) | 1283 | if (NULL != dc->job_queue) |
1283 | { | 1284 | { |
1284 | GNUNET_FS_dequeue_(dc->job_queue); | 1285 | GNUNET_FS_dequeue_ (dc->job_queue); |
1285 | dc->job_queue = NULL; | 1286 | dc->job_queue = NULL; |
1286 | } | 1287 | } |
1287 | GNUNET_FS_download_sync_(dc); | 1288 | GNUNET_FS_download_sync_ (dc); |
1288 | return GNUNET_NO; | 1289 | return GNUNET_NO; |
1289 | } | 1290 | } |
1290 | 1291 | ||
@@ -1297,7 +1298,7 @@ signal_error: | |||
1297 | * @param msg message received | 1298 | * @param msg message received |
1298 | */ | 1299 | */ |
1299 | static int | 1300 | static int |
1300 | check_put(void *cls, const struct ClientPutMessage *cm) | 1301 | check_put (void *cls, const struct ClientPutMessage *cm) |
1301 | { | 1302 | { |
1302 | /* any varsize length is OK */ | 1303 | /* any varsize length is OK */ |
1303 | return GNUNET_OK; | 1304 | return GNUNET_OK; |
@@ -1312,28 +1313,28 @@ check_put(void *cls, const struct ClientPutMessage *cm) | |||
1312 | * @param msg message received | 1313 | * @param msg message received |
1313 | */ | 1314 | */ |
1314 | static void | 1315 | static void |
1315 | handle_put(void *cls, const struct ClientPutMessage *cm) | 1316 | handle_put (void *cls, const struct ClientPutMessage *cm) |
1316 | { | 1317 | { |
1317 | struct GNUNET_FS_DownloadContext *dc = cls; | 1318 | struct GNUNET_FS_DownloadContext *dc = cls; |
1318 | uint16_t msize = ntohs(cm->header.size) - sizeof(*cm); | 1319 | uint16_t msize = ntohs (cm->header.size) - sizeof(*cm); |
1319 | struct ProcessResultClosure prc; | 1320 | struct ProcessResultClosure prc; |
1320 | 1321 | ||
1321 | prc.dc = dc; | 1322 | prc.dc = dc; |
1322 | prc.data = &cm[1]; | 1323 | prc.data = &cm[1]; |
1323 | prc.last_transmission = GNUNET_TIME_absolute_ntoh(cm->last_transmission); | 1324 | prc.last_transmission = GNUNET_TIME_absolute_ntoh (cm->last_transmission); |
1324 | prc.size = msize; | 1325 | prc.size = msize; |
1325 | prc.type = ntohl(cm->type); | 1326 | prc.type = ntohl (cm->type); |
1326 | prc.do_store = GNUNET_YES; | 1327 | prc.do_store = GNUNET_YES; |
1327 | prc.respect_offered = ntohl(cm->respect_offered); | 1328 | prc.respect_offered = ntohl (cm->respect_offered); |
1328 | prc.num_transmissions = ntohl(cm->num_transmissions); | 1329 | prc.num_transmissions = ntohl (cm->num_transmissions); |
1329 | GNUNET_CRYPTO_hash(prc.data, msize, &prc.query); | 1330 | GNUNET_CRYPTO_hash (prc.data, msize, &prc.query); |
1330 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1331 | "Received result for query `%s' from FS service\n", | 1332 | "Received result for query `%s' from FS service\n", |
1332 | GNUNET_h2s(&prc.query)); | 1333 | GNUNET_h2s (&prc.query)); |
1333 | GNUNET_CONTAINER_multihashmap_get_multiple(dc->active, | 1334 | GNUNET_CONTAINER_multihashmap_get_multiple (dc->active, |
1334 | &prc.query, | 1335 | &prc.query, |
1335 | &process_result_with_request, | 1336 | &process_result_with_request, |
1336 | &prc); | 1337 | &prc); |
1337 | } | 1338 | } |
1338 | 1339 | ||
1339 | 1340 | ||
@@ -1346,18 +1347,18 @@ handle_put(void *cls, const struct ClientPutMessage *cm) | |||
1346 | * @param error error code | 1347 | * @param error error code |
1347 | */ | 1348 | */ |
1348 | static void | 1349 | static void |
1349 | download_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 1350 | download_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
1350 | { | 1351 | { |
1351 | struct GNUNET_FS_DownloadContext *dc = cls; | 1352 | struct GNUNET_FS_DownloadContext *dc = cls; |
1352 | 1353 | ||
1353 | if (NULL != dc->mq) | 1354 | if (NULL != dc->mq) |
1354 | { | 1355 | { |
1355 | GNUNET_MQ_destroy(dc->mq); | 1356 | GNUNET_MQ_destroy (dc->mq); |
1356 | dc->mq = NULL; | 1357 | dc->mq = NULL; |
1357 | } | 1358 | } |
1358 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1359 | "Transmitting download request failed, trying to reconnect\n"); | 1360 | "Transmitting download request failed, trying to reconnect\n"); |
1360 | try_reconnect(dc); | 1361 | try_reconnect (dc); |
1361 | } | 1362 | } |
1362 | 1363 | ||
1363 | 1364 | ||
@@ -1367,31 +1368,31 @@ download_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
1367 | * @param cls our download context | 1368 | * @param cls our download context |
1368 | */ | 1369 | */ |
1369 | static void | 1370 | static void |
1370 | do_reconnect(void *cls) | 1371 | do_reconnect (void *cls) |
1371 | { | 1372 | { |
1372 | struct GNUNET_FS_DownloadContext *dc = cls; | 1373 | struct GNUNET_FS_DownloadContext *dc = cls; |
1373 | struct GNUNET_MQ_MessageHandler handlers[] = | 1374 | struct GNUNET_MQ_MessageHandler handlers[] = |
1374 | { GNUNET_MQ_hd_var_size(put, | 1375 | { GNUNET_MQ_hd_var_size (put, |
1375 | GNUNET_MESSAGE_TYPE_FS_PUT, | 1376 | GNUNET_MESSAGE_TYPE_FS_PUT, |
1376 | struct ClientPutMessage, | 1377 | struct ClientPutMessage, |
1377 | dc), | 1378 | dc), |
1378 | GNUNET_MQ_handler_end() }; | 1379 | GNUNET_MQ_handler_end () }; |
1379 | 1380 | ||
1380 | dc->task = NULL; | 1381 | dc->task = NULL; |
1381 | dc->mq = GNUNET_CLIENT_connect(dc->h->cfg, | 1382 | dc->mq = GNUNET_CLIENT_connect (dc->h->cfg, |
1382 | "fs", | 1383 | "fs", |
1383 | handlers, | 1384 | handlers, |
1384 | &download_mq_error_handler, | 1385 | &download_mq_error_handler, |
1385 | dc); | 1386 | dc); |
1386 | if (NULL == dc->mq) | 1387 | if (NULL == dc->mq) |
1387 | { | 1388 | { |
1388 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1389 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1389 | "Connecting to `%s'-service failed, will try again.\n", | 1390 | "Connecting to `%s'-service failed, will try again.\n", |
1390 | "FS"); | 1391 | "FS"); |
1391 | try_reconnect(dc); | 1392 | try_reconnect (dc); |
1392 | return; | 1393 | return; |
1393 | } | 1394 | } |
1394 | GNUNET_CONTAINER_multihashmap_iterate(dc->active, &retry_entry, dc); | 1395 | GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc); |
1395 | } | 1396 | } |
1396 | 1397 | ||
1397 | 1398 | ||
@@ -1403,27 +1404,27 @@ do_reconnect(void *cls) | |||
1403 | * @param dc download context that is having trouble | 1404 | * @param dc download context that is having trouble |
1404 | */ | 1405 | */ |
1405 | static void | 1406 | static void |
1406 | try_reconnect(struct GNUNET_FS_DownloadContext *dc) | 1407 | try_reconnect (struct GNUNET_FS_DownloadContext *dc) |
1407 | { | 1408 | { |
1408 | if (NULL != dc->mq) | 1409 | if (NULL != dc->mq) |
1409 | { | 1410 | { |
1410 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1411 | "Moving all requests back to pending list\n"); | 1412 | "Moving all requests back to pending list\n"); |
1412 | GNUNET_MQ_destroy(dc->mq); | 1413 | GNUNET_MQ_destroy (dc->mq); |
1413 | dc->mq = NULL; | 1414 | dc->mq = NULL; |
1414 | } | 1415 | } |
1415 | if (0 == dc->reconnect_backoff.rel_value_us) | 1416 | if (0 == dc->reconnect_backoff.rel_value_us) |
1416 | dc->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 1417 | dc->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
1417 | else | 1418 | else |
1418 | dc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(dc->reconnect_backoff); | 1419 | dc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (dc->reconnect_backoff); |
1419 | 1420 | ||
1420 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1421 | "Will try to reconnect in %s\n", | 1422 | "Will try to reconnect in %s\n", |
1422 | GNUNET_STRINGS_relative_time_to_string(dc->reconnect_backoff, | 1423 | GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, |
1423 | GNUNET_YES)); | 1424 | GNUNET_YES)); |
1424 | GNUNET_break(NULL != dc->job_queue); | 1425 | GNUNET_break (NULL != dc->job_queue); |
1425 | dc->task = | 1426 | dc->task = |
1426 | GNUNET_SCHEDULER_add_delayed(dc->reconnect_backoff, &do_reconnect, dc); | 1427 | GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff, &do_reconnect, dc); |
1427 | } | 1428 | } |
1428 | 1429 | ||
1429 | 1430 | ||
@@ -1434,18 +1435,18 @@ try_reconnect(struct GNUNET_FS_DownloadContext *dc) | |||
1434 | * @param mq handle to use for communcation with FS (we must destroy it!) | 1435 | * @param mq handle to use for communcation with FS (we must destroy it!) |
1435 | */ | 1436 | */ |
1436 | static void | 1437 | static void |
1437 | activate_fs_download(void *cls) | 1438 | activate_fs_download (void *cls) |
1438 | { | 1439 | { |
1439 | struct GNUNET_FS_DownloadContext *dc = cls; | 1440 | struct GNUNET_FS_DownloadContext *dc = cls; |
1440 | struct GNUNET_FS_ProgressInfo pi; | 1441 | struct GNUNET_FS_ProgressInfo pi; |
1441 | 1442 | ||
1442 | GNUNET_assert(NULL == dc->mq); | 1443 | GNUNET_assert (NULL == dc->mq); |
1443 | GNUNET_assert(NULL != dc->active); | 1444 | GNUNET_assert (NULL != dc->active); |
1444 | do_reconnect(dc); | 1445 | do_reconnect (dc); |
1445 | if (NULL != dc->mq) | 1446 | if (NULL != dc->mq) |
1446 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download activated\n"); | 1447 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n"); |
1447 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; | 1448 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; |
1448 | GNUNET_FS_download_make_status_(&pi, dc); | 1449 | GNUNET_FS_download_make_status_ (&pi, dc); |
1449 | } | 1450 | } |
1450 | 1451 | ||
1451 | 1452 | ||
@@ -1455,19 +1456,19 @@ activate_fs_download(void *cls) | |||
1455 | * @param cls the `struct GNUNET_FS_DownloadContext` | 1456 | * @param cls the `struct GNUNET_FS_DownloadContext` |
1456 | */ | 1457 | */ |
1457 | static void | 1458 | static void |
1458 | deactivate_fs_download(void *cls) | 1459 | deactivate_fs_download (void *cls) |
1459 | { | 1460 | { |
1460 | struct GNUNET_FS_DownloadContext *dc = cls; | 1461 | struct GNUNET_FS_DownloadContext *dc = cls; |
1461 | struct GNUNET_FS_ProgressInfo pi; | 1462 | struct GNUNET_FS_ProgressInfo pi; |
1462 | 1463 | ||
1463 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n"); | 1464 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n"); |
1464 | if (NULL != dc->mq) | 1465 | if (NULL != dc->mq) |
1465 | { | 1466 | { |
1466 | GNUNET_MQ_destroy(dc->mq); | 1467 | GNUNET_MQ_destroy (dc->mq); |
1467 | dc->mq = NULL; | 1468 | dc->mq = NULL; |
1468 | } | 1469 | } |
1469 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE; | 1470 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE; |
1470 | GNUNET_FS_download_make_status_(&pi, dc); | 1471 | GNUNET_FS_download_make_status_ (&pi, dc); |
1471 | } | 1472 | } |
1472 | 1473 | ||
1473 | 1474 | ||
@@ -1491,38 +1492,38 @@ deactivate_fs_download(void *cls) | |||
1491 | * the specified depth | 1492 | * the specified depth |
1492 | */ | 1493 | */ |
1493 | static struct DownloadRequest * | 1494 | static struct DownloadRequest * |
1494 | create_download_request(struct DownloadRequest *parent, | 1495 | create_download_request (struct DownloadRequest *parent, |
1495 | unsigned int chk_idx, | 1496 | unsigned int chk_idx, |
1496 | unsigned int depth, | 1497 | unsigned int depth, |
1497 | uint64_t dr_offset, | 1498 | uint64_t dr_offset, |
1498 | uint64_t file_start_offset, | 1499 | uint64_t file_start_offset, |
1499 | uint64_t desired_length) | 1500 | uint64_t desired_length) |
1500 | { | 1501 | { |
1501 | struct DownloadRequest *dr; | 1502 | struct DownloadRequest *dr; |
1502 | unsigned int i; | 1503 | unsigned int i; |
1503 | unsigned int head_skip; | 1504 | unsigned int head_skip; |
1504 | uint64_t child_block_size; | 1505 | uint64_t child_block_size; |
1505 | 1506 | ||
1506 | dr = GNUNET_new(struct DownloadRequest); | 1507 | dr = GNUNET_new (struct DownloadRequest); |
1507 | dr->parent = parent; | 1508 | dr->parent = parent; |
1508 | dr->depth = depth; | 1509 | dr->depth = depth; |
1509 | dr->offset = dr_offset; | 1510 | dr->offset = dr_offset; |
1510 | dr->chk_idx = chk_idx; | 1511 | dr->chk_idx = chk_idx; |
1511 | if (0 == depth) | 1512 | if (0 == depth) |
1512 | return dr; | 1513 | return dr; |
1513 | child_block_size = GNUNET_FS_tree_compute_tree_size(depth - 1); | 1514 | child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1); |
1514 | 1515 | ||
1515 | /* calculate how many blocks at this level are not interesting | 1516 | /* calculate how many blocks at this level are not interesting |
1516 | * from the start (rounded down), either because of the requested | 1517 | * from the start (rounded down), either because of the requested |
1517 | * file offset or because this IBlock is further along */ | 1518 | * file offset or because this IBlock is further along */ |
1518 | if (dr_offset < file_start_offset) | 1519 | if (dr_offset < file_start_offset) |
1519 | { | 1520 | { |
1520 | head_skip = (file_start_offset - dr_offset) / child_block_size; | 1521 | head_skip = (file_start_offset - dr_offset) / child_block_size; |
1521 | } | 1522 | } |
1522 | else | 1523 | else |
1523 | { | 1524 | { |
1524 | head_skip = 0; | 1525 | head_skip = 0; |
1525 | } | 1526 | } |
1526 | 1527 | ||
1527 | /* calculate index of last block at this level that is interesting (rounded up) */ | 1528 | /* calculate index of last block at this level that is interesting (rounded up) */ |
1528 | dr->num_children = | 1529 | dr->num_children = |
@@ -1530,32 +1531,32 @@ create_download_request(struct DownloadRequest *parent, | |||
1530 | if (dr->num_children * child_block_size < | 1531 | if (dr->num_children * child_block_size < |
1531 | file_start_offset + desired_length - dr_offset) | 1532 | file_start_offset + desired_length - dr_offset) |
1532 | dr->num_children++; /* round up */ | 1533 | dr->num_children++; /* round up */ |
1533 | GNUNET_assert(dr->num_children > head_skip); | 1534 | GNUNET_assert (dr->num_children > head_skip); |
1534 | dr->num_children -= head_skip; | 1535 | dr->num_children -= head_skip; |
1535 | if (dr->num_children > CHK_PER_INODE) | 1536 | if (dr->num_children > CHK_PER_INODE) |
1536 | dr->num_children = CHK_PER_INODE; /* cap at max */ | 1537 | dr->num_children = CHK_PER_INODE; /* cap at max */ |
1537 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1538 | "Block at offset %llu and depth %u has %u children\n", | 1539 | "Block at offset %llu and depth %u has %u children\n", |
1539 | (unsigned long long)dr_offset, | 1540 | (unsigned long long) dr_offset, |
1540 | depth, | 1541 | depth, |
1541 | dr->num_children); | 1542 | dr->num_children); |
1542 | 1543 | ||
1543 | /* now we can get the total number of *interesting* children for this block */ | 1544 | /* now we can get the total number of *interesting* children for this block */ |
1544 | 1545 | ||
1545 | /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ | 1546 | /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ |
1546 | GNUNET_assert(dr->num_children > 0); | 1547 | GNUNET_assert (dr->num_children > 0); |
1547 | 1548 | ||
1548 | dr->children = GNUNET_new_array(dr->num_children, struct DownloadRequest *); | 1549 | dr->children = GNUNET_new_array (dr->num_children, struct DownloadRequest *); |
1549 | for (i = 0; i < dr->num_children; i++) | 1550 | for (i = 0; i < dr->num_children; i++) |
1550 | { | 1551 | { |
1551 | dr->children[i] = | 1552 | dr->children[i] = |
1552 | create_download_request(dr, | 1553 | create_download_request (dr, |
1553 | i + head_skip, | 1554 | i + head_skip, |
1554 | depth - 1, | 1555 | depth - 1, |
1555 | dr_offset + (i + head_skip) * child_block_size, | 1556 | dr_offset + (i + head_skip) * child_block_size, |
1556 | file_start_offset, | 1557 | file_start_offset, |
1557 | desired_length); | 1558 | desired_length); |
1558 | } | 1559 | } |
1559 | return dr; | 1560 | return dr; |
1560 | } | 1561 | } |
1561 | 1562 | ||
@@ -1567,25 +1568,25 @@ create_download_request(struct DownloadRequest *parent, | |||
1567 | * @param cls the 'struct ReconstructContext' | 1568 | * @param cls the 'struct ReconstructContext' |
1568 | */ | 1569 | */ |
1569 | static void | 1570 | static void |
1570 | reconstruct_cont(void *cls) | 1571 | reconstruct_cont (void *cls) |
1571 | { | 1572 | { |
1572 | struct GNUNET_FS_DownloadContext *dc = cls; | 1573 | struct GNUNET_FS_DownloadContext *dc = cls; |
1573 | 1574 | ||
1574 | /* clean up state from tree encoder */ | 1575 | /* clean up state from tree encoder */ |
1575 | if (NULL != dc->task) | 1576 | if (NULL != dc->task) |
1576 | { | 1577 | { |
1577 | GNUNET_SCHEDULER_cancel(dc->task); | 1578 | GNUNET_SCHEDULER_cancel (dc->task); |
1578 | dc->task = NULL; | 1579 | dc->task = NULL; |
1579 | } | 1580 | } |
1580 | if (NULL != dc->rfh) | 1581 | if (NULL != dc->rfh) |
1581 | { | 1582 | { |
1582 | GNUNET_break(GNUNET_OK == GNUNET_DISK_file_close(dc->rfh)); | 1583 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); |
1583 | dc->rfh = NULL; | 1584 | dc->rfh = NULL; |
1584 | } | 1585 | } |
1585 | /* start "normal" download */ | 1586 | /* start "normal" download */ |
1586 | dc->issue_requests = GNUNET_YES; | 1587 | dc->issue_requests = GNUNET_YES; |
1587 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n"); | 1588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n"); |
1588 | schedule_block_download(dc, dc->top_request); | 1589 | schedule_block_download (dc, dc->top_request); |
1589 | } | 1590 | } |
1590 | 1591 | ||
1591 | 1592 | ||
@@ -1595,12 +1596,12 @@ reconstruct_cont(void *cls) | |||
1595 | * @param cls the 'struct GNUJNET_FS_DownloadContext' we're processing | 1596 | * @param cls the 'struct GNUJNET_FS_DownloadContext' we're processing |
1596 | */ | 1597 | */ |
1597 | static void | 1598 | static void |
1598 | get_next_block(void *cls) | 1599 | get_next_block (void *cls) |
1599 | { | 1600 | { |
1600 | struct GNUNET_FS_DownloadContext *dc = cls; | 1601 | struct GNUNET_FS_DownloadContext *dc = cls; |
1601 | 1602 | ||
1602 | dc->task = NULL; | 1603 | dc->task = NULL; |
1603 | GNUNET_FS_tree_encoder_next(dc->te); | 1604 | GNUNET_FS_tree_encoder_next (dc->te); |
1604 | } | 1605 | } |
1605 | 1606 | ||
1606 | 1607 | ||
@@ -1622,13 +1623,13 @@ get_next_block(void *cls) | |||
1622 | * @param block_size size of block (in bytes) | 1623 | * @param block_size size of block (in bytes) |
1623 | */ | 1624 | */ |
1624 | static void | 1625 | static void |
1625 | reconstruct_cb(void *cls, | 1626 | reconstruct_cb (void *cls, |
1626 | const struct ContentHashKey *chk, | 1627 | const struct ContentHashKey *chk, |
1627 | uint64_t offset, | 1628 | uint64_t offset, |
1628 | unsigned int depth, | 1629 | unsigned int depth, |
1629 | enum GNUNET_BLOCK_Type type, | 1630 | enum GNUNET_BLOCK_Type type, |
1630 | const void *block, | 1631 | const void *block, |
1631 | uint16_t block_size) | 1632 | uint16_t block_size) |
1632 | { | 1633 | { |
1633 | struct GNUNET_FS_DownloadContext *dc = cls; | 1634 | struct GNUNET_FS_DownloadContext *dc = cls; |
1634 | struct GNUNET_FS_ProgressInfo pi; | 1635 | struct GNUNET_FS_ProgressInfo pi; |
@@ -1639,125 +1640,125 @@ reconstruct_cb(void *cls, | |||
1639 | /* find corresponding request entry */ | 1640 | /* find corresponding request entry */ |
1640 | dr = dc->top_request; | 1641 | dr = dc->top_request; |
1641 | while (dr->depth > depth) | 1642 | while (dr->depth > depth) |
1642 | { | 1643 | { |
1643 | GNUNET_assert(dr->num_children > 0); | 1644 | GNUNET_assert (dr->num_children > 0); |
1644 | blen = GNUNET_FS_tree_compute_tree_size(dr->depth - 1); | 1645 | blen = GNUNET_FS_tree_compute_tree_size (dr->depth - 1); |
1645 | chld = (offset - dr->offset) / blen; | 1646 | chld = (offset - dr->offset) / blen; |
1646 | if (chld < dr->children[0]->chk_idx) | 1647 | if (chld < dr->children[0]->chk_idx) |
1647 | { | 1648 | { |
1648 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1649 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1649 | "Block %u < %u irrelevant for our range\n", | 1650 | "Block %u < %u irrelevant for our range\n", |
1650 | chld, | 1651 | chld, |
1651 | dr->children[0]->chk_idx); | 1652 | dr->children[0]->chk_idx); |
1652 | dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); | 1653 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); |
1653 | return; /* irrelevant block */ | 1654 | return; /* irrelevant block */ |
1654 | } | 1655 | } |
1655 | if (chld > dr->children[dr->num_children - 1]->chk_idx) | 1656 | if (chld > dr->children[dr->num_children - 1]->chk_idx) |
1656 | { | 1657 | { |
1657 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1658 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1658 | "Block %u > %u irrelevant for our range\n", | 1659 | "Block %u > %u irrelevant for our range\n", |
1659 | chld, | 1660 | chld, |
1660 | dr->children[dr->num_children - 1]->chk_idx); | 1661 | dr->children[dr->num_children - 1]->chk_idx); |
1661 | dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); | 1662 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); |
1662 | return; /* irrelevant block */ | 1663 | return; /* irrelevant block */ |
1663 | } | 1664 | } |
1664 | dr = dr->children[chld - dr->children[0]->chk_idx]; | 1665 | dr = dr->children[chld - dr->children[0]->chk_idx]; |
1665 | } | 1666 | } |
1666 | GNUNET_log( | 1667 | GNUNET_log ( |
1667 | GNUNET_ERROR_TYPE_DEBUG, | 1668 | GNUNET_ERROR_TYPE_DEBUG, |
1668 | "Matched TE block with request at offset %llu and depth %u in state %d\n", | 1669 | "Matched TE block with request at offset %llu and depth %u in state %d\n", |
1669 | (unsigned long long)dr->offset, | 1670 | (unsigned long long) dr->offset, |
1670 | dr->depth, | 1671 | dr->depth, |
1671 | dr->state); | 1672 | dr->state); |
1672 | /* FIXME: this code needs more testing and might | 1673 | /* FIXME: this code needs more testing and might |
1673 | need to handle more states... */ | 1674 | need to handle more states... */ |
1674 | switch (dr->state) | 1675 | switch (dr->state) |
1675 | { | 1676 | { |
1676 | case BRS_INIT: | 1677 | case BRS_INIT: |
1677 | break; | 1678 | break; |
1678 | 1679 | ||
1679 | case BRS_RECONSTRUCT_DOWN: | 1680 | case BRS_RECONSTRUCT_DOWN: |
1680 | break; | 1681 | break; |
1681 | 1682 | ||
1682 | case BRS_RECONSTRUCT_META_UP: | 1683 | case BRS_RECONSTRUCT_META_UP: |
1683 | break; | 1684 | break; |
1684 | 1685 | ||
1685 | case BRS_RECONSTRUCT_UP: | 1686 | case BRS_RECONSTRUCT_UP: |
1686 | break; | 1687 | break; |
1687 | 1688 | ||
1688 | case BRS_CHK_SET: | 1689 | case BRS_CHK_SET: |
1689 | if (0 == memcmp(chk, &dr->chk, sizeof(struct ContentHashKey))) | 1690 | if (0 == memcmp (chk, &dr->chk, sizeof(struct ContentHashKey))) |
1691 | { | ||
1692 | GNUNET_log ( | ||
1693 | GNUNET_ERROR_TYPE_DEBUG, | ||
1694 | "Reconstruction succeeded, can use block at offset %llu, depth %u\n", | ||
1695 | (unsigned long long) offset, | ||
1696 | depth); | ||
1697 | /* block matches, hence tree below matches; | ||
1698 | * this request is done! */ | ||
1699 | dr->state = BRS_DOWNLOAD_UP; | ||
1700 | (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, | ||
1701 | &dr->chk.query, | ||
1702 | dr); | ||
1703 | /* calculate how many bytes of payload this block | ||
1704 | * corresponds to */ | ||
1705 | blen = GNUNET_FS_tree_compute_tree_size (dr->depth); | ||
1706 | /* how many of those bytes are in the requested range? */ | ||
1707 | blen = GNUNET_MIN (blen, dc->length + dc->offset - dr->offset); | ||
1708 | /* signal progress */ | ||
1709 | dc->completed += blen; | ||
1710 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; | ||
1711 | pi.value.download.specifics.progress.data = NULL; | ||
1712 | pi.value.download.specifics.progress.offset = offset; | ||
1713 | pi.value.download.specifics.progress.data_len = 0; | ||
1714 | pi.value.download.specifics.progress.depth = 0; | ||
1715 | pi.value.download.specifics.progress.respect_offered = 0; | ||
1716 | pi.value.download.specifics.progress.block_download_duration = | ||
1717 | GNUNET_TIME_UNIT_ZERO; | ||
1718 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
1719 | /* FIXME: duplicated code from 'process_result_with_request - refactor */ | ||
1720 | if (dc->completed == dc->length) | ||
1721 | { | ||
1722 | /* download completed, signal */ | ||
1723 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1724 | "Download completed, truncating file to desired length %llu\n", | ||
1725 | (unsigned long long) GNUNET_ntohll ( | ||
1726 | dc->uri->data.chk.file_length)); | ||
1727 | /* truncate file to size (since we store IBlocks at the end) */ | ||
1728 | if (NULL != dc->filename) | ||
1690 | { | 1729 | { |
1691 | GNUNET_log( | 1730 | if (0 != truncate (dc->filename, |
1692 | GNUNET_ERROR_TYPE_DEBUG, | 1731 | GNUNET_ntohll (dc->uri->data.chk.file_length))) |
1693 | "Reconstruction succeeded, can use block at offset %llu, depth %u\n", | 1732 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
1694 | (unsigned long long)offset, | 1733 | "truncate", |
1695 | depth); | 1734 | dc->filename); |
1696 | /* block matches, hence tree below matches; | ||
1697 | * this request is done! */ | ||
1698 | dr->state = BRS_DOWNLOAD_UP; | ||
1699 | (void)GNUNET_CONTAINER_multihashmap_remove(dc->active, | ||
1700 | &dr->chk.query, | ||
1701 | dr); | ||
1702 | /* calculate how many bytes of payload this block | ||
1703 | * corresponds to */ | ||
1704 | blen = GNUNET_FS_tree_compute_tree_size(dr->depth); | ||
1705 | /* how many of those bytes are in the requested range? */ | ||
1706 | blen = GNUNET_MIN(blen, dc->length + dc->offset - dr->offset); | ||
1707 | /* signal progress */ | ||
1708 | dc->completed += blen; | ||
1709 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; | ||
1710 | pi.value.download.specifics.progress.data = NULL; | ||
1711 | pi.value.download.specifics.progress.offset = offset; | ||
1712 | pi.value.download.specifics.progress.data_len = 0; | ||
1713 | pi.value.download.specifics.progress.depth = 0; | ||
1714 | pi.value.download.specifics.progress.respect_offered = 0; | ||
1715 | pi.value.download.specifics.progress.block_download_duration = | ||
1716 | GNUNET_TIME_UNIT_ZERO; | ||
1717 | GNUNET_FS_download_make_status_(&pi, dc); | ||
1718 | /* FIXME: duplicated code from 'process_result_with_request - refactor */ | ||
1719 | if (dc->completed == dc->length) | ||
1720 | { | ||
1721 | /* download completed, signal */ | ||
1722 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1723 | "Download completed, truncating file to desired length %llu\n", | ||
1724 | (unsigned long long)GNUNET_ntohll( | ||
1725 | dc->uri->data.chk.file_length)); | ||
1726 | /* truncate file to size (since we store IBlocks at the end) */ | ||
1727 | if (NULL != dc->filename) | ||
1728 | { | ||
1729 | if (0 != truncate(dc->filename, | ||
1730 | GNUNET_ntohll(dc->uri->data.chk.file_length))) | ||
1731 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, | ||
1732 | "truncate", | ||
1733 | dc->filename); | ||
1734 | } | ||
1735 | } | ||
1736 | } | 1735 | } |
1737 | else | 1736 | } |
1738 | GNUNET_log( | 1737 | } |
1739 | GNUNET_ERROR_TYPE_DEBUG, | 1738 | else |
1740 | "Reconstruction failed, need to download block at offset %llu, depth %u\n", | 1739 | GNUNET_log ( |
1741 | (unsigned long long)offset, | 1740 | GNUNET_ERROR_TYPE_DEBUG, |
1742 | depth); | 1741 | "Reconstruction failed, need to download block at offset %llu, depth %u\n", |
1743 | break; | 1742 | (unsigned long long) offset, |
1743 | depth); | ||
1744 | break; | ||
1744 | 1745 | ||
1745 | case BRS_DOWNLOAD_DOWN: | 1746 | case BRS_DOWNLOAD_DOWN: |
1746 | break; | 1747 | break; |
1747 | 1748 | ||
1748 | case BRS_DOWNLOAD_UP: | 1749 | case BRS_DOWNLOAD_UP: |
1749 | break; | 1750 | break; |
1750 | 1751 | ||
1751 | case BRS_ERROR: | 1752 | case BRS_ERROR: |
1752 | break; | 1753 | break; |
1753 | 1754 | ||
1754 | default: | 1755 | default: |
1755 | GNUNET_assert(0); | 1756 | GNUNET_assert (0); |
1756 | break; | 1757 | break; |
1757 | } | 1758 | } |
1758 | dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); | 1759 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); |
1759 | if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP)) | 1760 | if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP)) |
1760 | check_completed(dc); | 1761 | check_completed (dc); |
1761 | } | 1762 | } |
1762 | 1763 | ||
1763 | 1764 | ||
@@ -1774,7 +1775,7 @@ reconstruct_cb(void *cls, | |||
1774 | * @return number of bytes copied to buf, 0 on error | 1775 | * @return number of bytes copied to buf, 0 on error |
1775 | */ | 1776 | */ |
1776 | static size_t | 1777 | static size_t |
1777 | fh_reader(void *cls, uint64_t offset, size_t max, void *buf, char **emsg) | 1778 | fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) |
1778 | { | 1779 | { |
1779 | struct GNUNET_FS_DownloadContext *dc = cls; | 1780 | struct GNUNET_FS_DownloadContext *dc = cls; |
1780 | struct GNUNET_DISK_FileHandle *fh = dc->rfh; | 1781 | struct GNUNET_DISK_FileHandle *fh = dc->rfh; |
@@ -1782,19 +1783,19 @@ fh_reader(void *cls, uint64_t offset, size_t max, void *buf, char **emsg) | |||
1782 | 1783 | ||
1783 | if (NULL != emsg) | 1784 | if (NULL != emsg) |
1784 | *emsg = NULL; | 1785 | *emsg = NULL; |
1785 | if (offset != GNUNET_DISK_file_seek(fh, offset, GNUNET_DISK_SEEK_SET)) | 1786 | if (offset != GNUNET_DISK_file_seek (fh, offset, GNUNET_DISK_SEEK_SET)) |
1786 | { | 1787 | { |
1787 | if (NULL != emsg) | 1788 | if (NULL != emsg) |
1788 | *emsg = GNUNET_strdup(strerror(errno)); | 1789 | *emsg = GNUNET_strdup (strerror (errno)); |
1789 | return 0; | 1790 | return 0; |
1790 | } | 1791 | } |
1791 | ret = GNUNET_DISK_file_read(fh, buf, max); | 1792 | ret = GNUNET_DISK_file_read (fh, buf, max); |
1792 | if (ret < 0) | 1793 | if (ret < 0) |
1793 | { | 1794 | { |
1794 | if (NULL != emsg) | 1795 | if (NULL != emsg) |
1795 | *emsg = GNUNET_strdup(strerror(errno)); | 1796 | *emsg = GNUNET_strdup (strerror (errno)); |
1796 | return 0; | 1797 | return 0; |
1797 | } | 1798 | } |
1798 | return ret; | 1799 | return ret; |
1799 | } | 1800 | } |
1800 | 1801 | ||
@@ -1806,155 +1807,155 @@ fh_reader(void *cls, uint64_t offset, size_t max, void *buf, char **emsg) | |||
1806 | * @param cls the 'struct GNUNET_FS_DownloadContext' | 1807 | * @param cls the 'struct GNUNET_FS_DownloadContext' |
1807 | */ | 1808 | */ |
1808 | void | 1809 | void |
1809 | GNUNET_FS_download_start_task_(void *cls) | 1810 | GNUNET_FS_download_start_task_ (void *cls) |
1810 | { | 1811 | { |
1811 | struct GNUNET_FS_DownloadContext *dc = cls; | 1812 | struct GNUNET_FS_DownloadContext *dc = cls; |
1812 | struct GNUNET_FS_ProgressInfo pi; | 1813 | struct GNUNET_FS_ProgressInfo pi; |
1813 | struct GNUNET_DISK_FileHandle *fh; | 1814 | struct GNUNET_DISK_FileHandle *fh; |
1814 | 1815 | ||
1815 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n"); | 1816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n"); |
1816 | dc->task = NULL; | 1817 | dc->task = NULL; |
1817 | if (0 == dc->length) | 1818 | if (0 == dc->length) |
1818 | { | 1819 | { |
1819 | /* no bytes required! */ | 1820 | /* no bytes required! */ |
1820 | if (NULL != dc->filename) | 1821 | if (NULL != dc->filename) |
1821 | { | 1822 | { |
1822 | fh = GNUNET_DISK_file_open(dc->filename, | 1823 | fh = GNUNET_DISK_file_open (dc->filename, |
1823 | GNUNET_DISK_OPEN_READWRITE | | 1824 | GNUNET_DISK_OPEN_READWRITE |
1824 | GNUNET_DISK_OPEN_CREATE | | 1825 | | GNUNET_DISK_OPEN_CREATE |
1825 | ((0 == | 1826 | | ((0 == |
1826 | GNUNET_FS_uri_chk_get_file_size(dc->uri)) | 1827 | GNUNET_FS_uri_chk_get_file_size (dc->uri)) |
1827 | ? GNUNET_DISK_OPEN_TRUNCATE | 1828 | ? GNUNET_DISK_OPEN_TRUNCATE |
1828 | : 0), | 1829 | : 0), |
1829 | GNUNET_DISK_PERM_USER_READ | | 1830 | GNUNET_DISK_PERM_USER_READ |
1830 | GNUNET_DISK_PERM_USER_WRITE | | 1831 | | GNUNET_DISK_PERM_USER_WRITE |
1831 | GNUNET_DISK_PERM_GROUP_READ | | 1832 | | GNUNET_DISK_PERM_GROUP_READ |
1832 | GNUNET_DISK_PERM_OTHER_READ); | 1833 | | GNUNET_DISK_PERM_OTHER_READ); |
1833 | GNUNET_DISK_file_close(fh); | 1834 | GNUNET_DISK_file_close (fh); |
1834 | } | 1835 | } |
1835 | GNUNET_FS_download_sync_(dc); | 1836 | GNUNET_FS_download_sync_ (dc); |
1836 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; | 1837 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; |
1837 | pi.value.download.specifics.start.meta = dc->meta; | 1838 | pi.value.download.specifics.start.meta = dc->meta; |
1838 | GNUNET_FS_download_make_status_(&pi, dc); | 1839 | GNUNET_FS_download_make_status_ (&pi, dc); |
1839 | check_completed(dc); | 1840 | check_completed (dc); |
1840 | return; | 1841 | return; |
1841 | } | 1842 | } |
1842 | if (NULL != dc->emsg) | 1843 | if (NULL != dc->emsg) |
1843 | return; | 1844 | return; |
1844 | if (NULL == dc->top_request) | 1845 | if (NULL == dc->top_request) |
1845 | { | 1846 | { |
1846 | dc->top_request = create_download_request(NULL, | 1847 | dc->top_request = create_download_request (NULL, |
1847 | 0, | 1848 | 0, |
1848 | dc->treedepth - 1, | 1849 | dc->treedepth - 1, |
1849 | 0, | 1850 | 0, |
1850 | dc->offset, | 1851 | dc->offset, |
1851 | dc->length); | 1852 | dc->length); |
1852 | dc->top_request->state = BRS_CHK_SET; | 1853 | dc->top_request->state = BRS_CHK_SET; |
1853 | dc->top_request->chk = (dc->uri->type == GNUNET_FS_URI_CHK) | 1854 | dc->top_request->chk = (dc->uri->type == GNUNET_FS_URI_CHK) |
1854 | ? dc->uri->data.chk.chk | 1855 | ? dc->uri->data.chk.chk |
1855 | : dc->uri->data.loc.fi.chk; | 1856 | : dc->uri->data.loc.fi.chk; |
1856 | /* signal start */ | 1857 | /* signal start */ |
1857 | GNUNET_FS_download_sync_(dc); | 1858 | GNUNET_FS_download_sync_ (dc); |
1858 | if (NULL != dc->search) | 1859 | if (NULL != dc->search) |
1859 | GNUNET_FS_search_result_sync_(dc->search); | 1860 | GNUNET_FS_search_result_sync_ (dc->search); |
1860 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; | 1861 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; |
1861 | pi.value.download.specifics.start.meta = dc->meta; | 1862 | pi.value.download.specifics.start.meta = dc->meta; |
1862 | GNUNET_FS_download_make_status_(&pi, dc); | 1863 | GNUNET_FS_download_make_status_ (&pi, dc); |
1863 | } | 1864 | } |
1864 | GNUNET_FS_download_start_downloading_(dc); | 1865 | GNUNET_FS_download_start_downloading_ (dc); |
1865 | /* attempt reconstruction from disk */ | 1866 | /* attempt reconstruction from disk */ |
1866 | if (GNUNET_YES == GNUNET_DISK_file_test(dc->filename)) | 1867 | if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename)) |
1867 | dc->rfh = GNUNET_DISK_file_open(dc->filename, | 1868 | dc->rfh = GNUNET_DISK_file_open (dc->filename, |
1868 | GNUNET_DISK_OPEN_READ, | 1869 | GNUNET_DISK_OPEN_READ, |
1869 | GNUNET_DISK_PERM_NONE); | 1870 | GNUNET_DISK_PERM_NONE); |
1870 | if (dc->top_request->state == BRS_CHK_SET) | 1871 | if (dc->top_request->state == BRS_CHK_SET) |
1871 | { | 1872 | { |
1872 | if (NULL != dc->rfh) | 1873 | if (NULL != dc->rfh) |
1874 | { | ||
1875 | /* first, try top-down */ | ||
1876 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1877 | "Trying top-down reconstruction for `%s'\n", | ||
1878 | dc->filename); | ||
1879 | try_top_down_reconstruction (dc, dc->top_request); | ||
1880 | switch (dc->top_request->state) | ||
1881 | { | ||
1882 | case BRS_CHK_SET: | ||
1883 | break; /* normal */ | ||
1884 | |||
1885 | case BRS_DOWNLOAD_DOWN: | ||
1886 | break; /* normal, some blocks already down */ | ||
1887 | |||
1888 | case BRS_DOWNLOAD_UP: | ||
1889 | /* already done entirely, party! */ | ||
1890 | if (NULL != dc->rfh) | ||
1873 | { | 1891 | { |
1874 | /* first, try top-down */ | 1892 | /* avoid hanging on to file handle longer than |
1875 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1893 | * necessary */ |
1876 | "Trying top-down reconstruction for `%s'\n", | 1894 | GNUNET_DISK_file_close (dc->rfh); |
1877 | dc->filename); | 1895 | dc->rfh = NULL; |
1878 | try_top_down_reconstruction(dc, dc->top_request); | ||
1879 | switch (dc->top_request->state) | ||
1880 | { | ||
1881 | case BRS_CHK_SET: | ||
1882 | break; /* normal */ | ||
1883 | |||
1884 | case BRS_DOWNLOAD_DOWN: | ||
1885 | break; /* normal, some blocks already down */ | ||
1886 | |||
1887 | case BRS_DOWNLOAD_UP: | ||
1888 | /* already done entirely, party! */ | ||
1889 | if (NULL != dc->rfh) | ||
1890 | { | ||
1891 | /* avoid hanging on to file handle longer than | ||
1892 | * necessary */ | ||
1893 | GNUNET_DISK_file_close(dc->rfh); | ||
1894 | dc->rfh = NULL; | ||
1895 | } | ||
1896 | return; | ||
1897 | |||
1898 | case BRS_ERROR: | ||
1899 | GNUNET_asprintf(&dc->emsg, _("Invalid URI")); | ||
1900 | GNUNET_FS_download_sync_(dc); | ||
1901 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | ||
1902 | pi.value.download.specifics.error.message = dc->emsg; | ||
1903 | GNUNET_FS_download_make_status_(&pi, dc); | ||
1904 | return; | ||
1905 | |||
1906 | default: | ||
1907 | GNUNET_assert(0); | ||
1908 | break; | ||
1909 | } | ||
1910 | } | 1896 | } |
1897 | return; | ||
1898 | |||
1899 | case BRS_ERROR: | ||
1900 | GNUNET_asprintf (&dc->emsg, _ ("Invalid URI")); | ||
1901 | GNUNET_FS_download_sync_ (dc); | ||
1902 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | ||
1903 | pi.value.download.specifics.error.message = dc->emsg; | ||
1904 | GNUNET_FS_download_make_status_ (&pi, dc); | ||
1905 | return; | ||
1906 | |||
1907 | default: | ||
1908 | GNUNET_assert (0); | ||
1909 | break; | ||
1910 | } | ||
1911 | } | 1911 | } |
1912 | } | ||
1912 | /* attempt reconstruction from meta data */ | 1913 | /* attempt reconstruction from meta data */ |
1913 | if ((GNUNET_FS_uri_chk_get_file_size(dc->uri) <= MAX_INLINE_SIZE) && | 1914 | if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) && |
1914 | (NULL != dc->meta)) | 1915 | (NULL != dc->meta)) |
1916 | { | ||
1917 | GNUNET_log ( | ||
1918 | GNUNET_ERROR_TYPE_DEBUG, | ||
1919 | "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", | ||
1920 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri), | ||
1921 | (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); | ||
1922 | GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc); | ||
1923 | if (BRS_DOWNLOAD_UP == dc->top_request->state) | ||
1915 | { | 1924 | { |
1916 | GNUNET_log( | 1925 | if (NULL != dc->rfh) |
1917 | GNUNET_ERROR_TYPE_DEBUG, | 1926 | { |
1918 | "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", | 1927 | /* avoid hanging on to file handle longer than |
1919 | (unsigned long long)GNUNET_FS_uri_chk_get_file_size(dc->uri), | 1928 | * necessary */ |
1920 | (unsigned int)GNUNET_CONTAINER_meta_data_get_serialized_size(dc->meta)); | 1929 | GNUNET_DISK_file_close (dc->rfh); |
1921 | GNUNET_CONTAINER_meta_data_iterate(dc->meta, &match_full_data, dc); | 1930 | dc->rfh = NULL; |
1922 | if (BRS_DOWNLOAD_UP == dc->top_request->state) | 1931 | } |
1923 | { | 1932 | return; /* finished, status update was already done for us */ |
1924 | if (NULL != dc->rfh) | 1933 | } |
1925 | { | 1934 | } |
1926 | /* avoid hanging on to file handle longer than | ||
1927 | * necessary */ | ||
1928 | GNUNET_DISK_file_close(dc->rfh); | ||
1929 | dc->rfh = NULL; | ||
1930 | } | ||
1931 | return; /* finished, status update was already done for us */ | ||
1932 | } | ||
1933 | } | ||
1934 | if (NULL != dc->rfh) | 1935 | if (NULL != dc->rfh) |
1935 | { | 1936 | { |
1936 | /* finally, actually run bottom-up */ | 1937 | /* finally, actually run bottom-up */ |
1937 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1938 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1938 | "Trying bottom-up reconstruction of file `%s'\n", | 1939 | "Trying bottom-up reconstruction of file `%s'\n", |
1939 | dc->filename); | 1940 | dc->filename); |
1940 | dc->te = | 1941 | dc->te = |
1941 | GNUNET_FS_tree_encoder_create(dc->h, | 1942 | GNUNET_FS_tree_encoder_create (dc->h, |
1942 | GNUNET_FS_uri_chk_get_file_size(dc->uri), | 1943 | GNUNET_FS_uri_chk_get_file_size (dc->uri), |
1943 | dc, | 1944 | dc, |
1944 | &fh_reader, | 1945 | &fh_reader, |
1945 | &reconstruct_cb, | 1946 | &reconstruct_cb, |
1946 | NULL, | 1947 | NULL, |
1947 | &reconstruct_cont); | 1948 | &reconstruct_cont); |
1948 | dc->task = GNUNET_SCHEDULER_add_now(&get_next_block, dc); | 1949 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); |
1949 | } | 1950 | } |
1950 | else | 1951 | else |
1951 | { | 1952 | { |
1952 | /* simple, top-level download */ | 1953 | /* simple, top-level download */ |
1953 | dc->issue_requests = GNUNET_YES; | 1954 | dc->issue_requests = GNUNET_YES; |
1954 | schedule_block_download(dc, dc->top_request); | 1955 | schedule_block_download (dc, dc->top_request); |
1955 | } | 1956 | } |
1956 | if (BRS_DOWNLOAD_UP == dc->top_request->state) | 1957 | if (BRS_DOWNLOAD_UP == dc->top_request->state) |
1957 | check_completed(dc); | 1958 | check_completed (dc); |
1958 | } | 1959 | } |
1959 | 1960 | ||
1960 | 1961 | ||
@@ -1965,59 +1966,59 @@ GNUNET_FS_download_start_task_(void *cls) | |||
1965 | * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for | 1966 | * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for |
1966 | */ | 1967 | */ |
1967 | void | 1968 | void |
1968 | GNUNET_FS_download_signal_suspend_(void *cls) | 1969 | GNUNET_FS_download_signal_suspend_ (void *cls) |
1969 | { | 1970 | { |
1970 | struct GNUNET_FS_DownloadContext *dc = cls; | 1971 | struct GNUNET_FS_DownloadContext *dc = cls; |
1971 | struct GNUNET_FS_ProgressInfo pi; | 1972 | struct GNUNET_FS_ProgressInfo pi; |
1972 | 1973 | ||
1973 | if (NULL != dc->top) | 1974 | if (NULL != dc->top) |
1974 | GNUNET_FS_end_top(dc->h, dc->top); | 1975 | GNUNET_FS_end_top (dc->h, dc->top); |
1975 | while (NULL != dc->child_head) | 1976 | while (NULL != dc->child_head) |
1976 | GNUNET_FS_download_signal_suspend_(dc->child_head); | 1977 | GNUNET_FS_download_signal_suspend_ (dc->child_head); |
1977 | if (NULL != dc->search) | 1978 | if (NULL != dc->search) |
1978 | { | 1979 | { |
1979 | dc->search->download = NULL; | 1980 | dc->search->download = NULL; |
1980 | dc->search = NULL; | 1981 | dc->search = NULL; |
1981 | } | 1982 | } |
1982 | if (NULL != dc->job_queue) | 1983 | if (NULL != dc->job_queue) |
1983 | { | 1984 | { |
1984 | GNUNET_FS_dequeue_(dc->job_queue); | 1985 | GNUNET_FS_dequeue_ (dc->job_queue); |
1985 | dc->job_queue = NULL; | 1986 | dc->job_queue = NULL; |
1986 | } | 1987 | } |
1987 | if (NULL != dc->parent) | 1988 | if (NULL != dc->parent) |
1988 | GNUNET_CONTAINER_DLL_remove(dc->parent->child_head, | 1989 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, |
1989 | dc->parent->child_tail, | 1990 | dc->parent->child_tail, |
1990 | dc); | 1991 | dc); |
1991 | if (NULL != dc->task) | 1992 | if (NULL != dc->task) |
1992 | { | 1993 | { |
1993 | GNUNET_SCHEDULER_cancel(dc->task); | 1994 | GNUNET_SCHEDULER_cancel (dc->task); |
1994 | dc->task = NULL; | 1995 | dc->task = NULL; |
1995 | } | 1996 | } |
1996 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND; | 1997 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND; |
1997 | GNUNET_FS_download_make_status_(&pi, dc); | 1998 | GNUNET_FS_download_make_status_ (&pi, dc); |
1998 | if (NULL != dc->te) | 1999 | if (NULL != dc->te) |
1999 | { | 2000 | { |
2000 | GNUNET_FS_tree_encoder_finish(dc->te, NULL); | 2001 | GNUNET_FS_tree_encoder_finish (dc->te, NULL); |
2001 | dc->te = NULL; | 2002 | dc->te = NULL; |
2002 | } | 2003 | } |
2003 | if (NULL != dc->rfh) | 2004 | if (NULL != dc->rfh) |
2004 | { | 2005 | { |
2005 | GNUNET_DISK_file_close(dc->rfh); | 2006 | GNUNET_DISK_file_close (dc->rfh); |
2006 | dc->rfh = NULL; | 2007 | dc->rfh = NULL; |
2007 | } | 2008 | } |
2008 | GNUNET_FS_free_download_request_(dc->top_request); | 2009 | GNUNET_FS_free_download_request_ (dc->top_request); |
2009 | if (NULL != dc->active) | 2010 | if (NULL != dc->active) |
2010 | { | 2011 | { |
2011 | GNUNET_CONTAINER_multihashmap_destroy(dc->active); | 2012 | GNUNET_CONTAINER_multihashmap_destroy (dc->active); |
2012 | dc->active = NULL; | 2013 | dc->active = NULL; |
2013 | } | 2014 | } |
2014 | GNUNET_free_non_null(dc->filename); | 2015 | GNUNET_free_non_null (dc->filename); |
2015 | GNUNET_CONTAINER_meta_data_destroy(dc->meta); | 2016 | GNUNET_CONTAINER_meta_data_destroy (dc->meta); |
2016 | GNUNET_FS_uri_destroy(dc->uri); | 2017 | GNUNET_FS_uri_destroy (dc->uri); |
2017 | GNUNET_free_non_null(dc->temp_filename); | 2018 | GNUNET_free_non_null (dc->temp_filename); |
2018 | GNUNET_free_non_null(dc->serialization); | 2019 | GNUNET_free_non_null (dc->serialization); |
2019 | GNUNET_assert(NULL == dc->job_queue); | 2020 | GNUNET_assert (NULL == dc->job_queue); |
2020 | GNUNET_free(dc); | 2021 | GNUNET_free (dc); |
2021 | } | 2022 | } |
2022 | 2023 | ||
2023 | 2024 | ||
@@ -2041,72 +2042,72 @@ GNUNET_FS_download_signal_suspend_(void *cls) | |||
2041 | * @return context that can be used to control this download | 2042 | * @return context that can be used to control this download |
2042 | */ | 2043 | */ |
2043 | struct GNUNET_FS_DownloadContext * | 2044 | struct GNUNET_FS_DownloadContext * |
2044 | create_download_context(struct GNUNET_FS_Handle *h, | 2045 | create_download_context (struct GNUNET_FS_Handle *h, |
2045 | const struct GNUNET_FS_Uri *uri, | 2046 | const struct GNUNET_FS_Uri *uri, |
2046 | const struct GNUNET_CONTAINER_MetaData *meta, | 2047 | const struct GNUNET_CONTAINER_MetaData *meta, |
2047 | const char *filename, | 2048 | const char *filename, |
2048 | const char *tempname, | 2049 | const char *tempname, |
2049 | uint64_t offset, | 2050 | uint64_t offset, |
2050 | uint64_t length, | 2051 | uint64_t length, |
2051 | uint32_t anonymity, | 2052 | uint32_t anonymity, |
2052 | enum GNUNET_FS_DownloadOptions options, | 2053 | enum GNUNET_FS_DownloadOptions options, |
2053 | void *cctx) | 2054 | void *cctx) |
2054 | { | 2055 | { |
2055 | struct GNUNET_FS_DownloadContext *dc; | 2056 | struct GNUNET_FS_DownloadContext *dc; |
2056 | 2057 | ||
2057 | GNUNET_assert(GNUNET_FS_uri_test_chk(uri) || GNUNET_FS_uri_test_loc(uri)); | 2058 | GNUNET_assert (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)); |
2058 | if ((offset + length < offset) || | 2059 | if ((offset + length < offset) || |
2059 | (offset + length > GNUNET_FS_uri_chk_get_file_size(uri))) | 2060 | (offset + length > GNUNET_FS_uri_chk_get_file_size (uri))) |
2060 | { | 2061 | { |
2061 | GNUNET_break(0); | 2062 | GNUNET_break (0); |
2062 | return NULL; | 2063 | return NULL; |
2063 | } | 2064 | } |
2064 | dc = GNUNET_new(struct GNUNET_FS_DownloadContext); | 2065 | dc = GNUNET_new (struct GNUNET_FS_DownloadContext); |
2065 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2066 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2066 | "Starting download %p, %u bytes at offset %llu\n", | 2067 | "Starting download %p, %u bytes at offset %llu\n", |
2067 | dc, | 2068 | dc, |
2068 | (unsigned int)length, | 2069 | (unsigned int) length, |
2069 | (unsigned long long)offset); | 2070 | (unsigned long long) offset); |
2070 | dc->h = h; | 2071 | dc->h = h; |
2071 | dc->uri = GNUNET_FS_uri_dup(uri); | 2072 | dc->uri = GNUNET_FS_uri_dup (uri); |
2072 | dc->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); | 2073 | dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
2073 | dc->client_info = cctx; | 2074 | dc->client_info = cctx; |
2074 | dc->start_time = GNUNET_TIME_absolute_get(); | 2075 | dc->start_time = GNUNET_TIME_absolute_get (); |
2075 | if (NULL != filename) | 2076 | if (NULL != filename) |
2076 | { | 2077 | { |
2077 | dc->filename = GNUNET_strdup(filename); | 2078 | dc->filename = GNUNET_strdup (filename); |
2078 | if (GNUNET_YES == GNUNET_DISK_file_test(filename)) | 2079 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
2079 | GNUNET_break(GNUNET_OK == GNUNET_DISK_file_size(filename, | 2080 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename, |
2080 | &dc->old_file_size, | 2081 | &dc->old_file_size, |
2081 | GNUNET_YES, | 2082 | GNUNET_YES, |
2082 | GNUNET_YES)); | 2083 | GNUNET_YES)); |
2083 | } | 2084 | } |
2084 | if (GNUNET_FS_uri_test_loc(dc->uri)) | 2085 | if (GNUNET_FS_uri_test_loc (dc->uri)) |
2085 | GNUNET_assert(GNUNET_OK == | 2086 | GNUNET_assert (GNUNET_OK == |
2086 | GNUNET_FS_uri_loc_get_peer_identity(dc->uri, &dc->target)); | 2087 | GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target)); |
2087 | dc->offset = offset; | 2088 | dc->offset = offset; |
2088 | dc->length = length; | 2089 | dc->length = length; |
2089 | dc->anonymity = anonymity; | 2090 | dc->anonymity = anonymity; |
2090 | dc->options = options; | 2091 | dc->options = options; |
2091 | dc->active = | 2092 | dc->active = |
2092 | GNUNET_CONTAINER_multihashmap_create(1 + 2 * (length / DBLOCK_SIZE), | 2093 | GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE), |
2093 | GNUNET_NO); | 2094 | GNUNET_NO); |
2094 | dc->treedepth = | 2095 | dc->treedepth = |
2095 | GNUNET_FS_compute_depth(GNUNET_FS_uri_chk_get_file_size(dc->uri)); | 2096 | GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); |
2096 | if ((NULL == filename) && (is_recursive_download(dc))) | 2097 | if ((NULL == filename) && (is_recursive_download (dc))) |
2097 | { | 2098 | { |
2098 | if (NULL != tempname) | 2099 | if (NULL != tempname) |
2099 | dc->temp_filename = GNUNET_strdup(tempname); | 2100 | dc->temp_filename = GNUNET_strdup (tempname); |
2100 | else | 2101 | else |
2101 | dc->temp_filename = GNUNET_DISK_mktemp("gnunet-directory-download-tmp"); | 2102 | dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp"); |
2102 | } | 2103 | } |
2103 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2104 | "Starting download `%s' of %llu bytes with tree depth %u\n", | 2105 | "Starting download `%s' of %llu bytes with tree depth %u\n", |
2105 | filename, | 2106 | filename, |
2106 | (unsigned long long)length, | 2107 | (unsigned long long) length, |
2107 | dc->treedepth); | 2108 | dc->treedepth); |
2108 | GNUNET_assert(NULL == dc->job_queue); | 2109 | GNUNET_assert (NULL == dc->job_queue); |
2109 | dc->task = GNUNET_SCHEDULER_add_now(&GNUNET_FS_download_start_task_, dc); | 2110 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); |
2110 | return dc; | 2111 | return dc; |
2111 | } | 2112 | } |
2112 | 2113 | ||
@@ -2142,38 +2143,38 @@ create_download_context(struct GNUNET_FS_Handle *h, | |||
2142 | * @return context that can be used to control this download | 2143 | * @return context that can be used to control this download |
2143 | */ | 2144 | */ |
2144 | struct GNUNET_FS_DownloadContext * | 2145 | struct GNUNET_FS_DownloadContext * |
2145 | GNUNET_FS_download_start(struct GNUNET_FS_Handle *h, | 2146 | GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, |
2146 | const struct GNUNET_FS_Uri *uri, | 2147 | const struct GNUNET_FS_Uri *uri, |
2147 | const struct GNUNET_CONTAINER_MetaData *meta, | 2148 | const struct GNUNET_CONTAINER_MetaData *meta, |
2148 | const char *filename, | 2149 | const char *filename, |
2149 | const char *tempname, | 2150 | const char *tempname, |
2150 | uint64_t offset, | 2151 | uint64_t offset, |
2151 | uint64_t length, | 2152 | uint64_t length, |
2152 | uint32_t anonymity, | 2153 | uint32_t anonymity, |
2153 | enum GNUNET_FS_DownloadOptions options, | 2154 | enum GNUNET_FS_DownloadOptions options, |
2154 | void *cctx, | 2155 | void *cctx, |
2155 | struct GNUNET_FS_DownloadContext *parent) | 2156 | struct GNUNET_FS_DownloadContext *parent) |
2156 | { | 2157 | { |
2157 | struct GNUNET_FS_DownloadContext *dc; | 2158 | struct GNUNET_FS_DownloadContext *dc; |
2158 | 2159 | ||
2159 | dc = create_download_context(h, | 2160 | dc = create_download_context (h, |
2160 | uri, | 2161 | uri, |
2161 | meta, | 2162 | meta, |
2162 | filename, | 2163 | filename, |
2163 | tempname, | 2164 | tempname, |
2164 | offset, | 2165 | offset, |
2165 | length, | 2166 | length, |
2166 | anonymity, | 2167 | anonymity, |
2167 | options, | 2168 | options, |
2168 | cctx); | 2169 | cctx); |
2169 | if (NULL == dc) | 2170 | if (NULL == dc) |
2170 | return NULL; | 2171 | return NULL; |
2171 | dc->parent = parent; | 2172 | dc->parent = parent; |
2172 | if (NULL != parent) | 2173 | if (NULL != parent) |
2173 | GNUNET_CONTAINER_DLL_insert(parent->child_head, parent->child_tail, dc); | 2174 | GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); |
2174 | else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options)) | 2175 | else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options)) |
2175 | dc->top = | 2176 | dc->top = |
2176 | GNUNET_FS_make_top(dc->h, &GNUNET_FS_download_signal_suspend_, dc); | 2177 | GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); |
2177 | return dc; | 2178 | return dc; |
2178 | } | 2179 | } |
2179 | 2180 | ||
@@ -2213,43 +2214,43 @@ GNUNET_FS_download_start(struct GNUNET_FS_Handle *h, | |||
2213 | * @return context that can be used to control this download | 2214 | * @return context that can be used to control this download |
2214 | */ | 2215 | */ |
2215 | struct GNUNET_FS_DownloadContext * | 2216 | struct GNUNET_FS_DownloadContext * |
2216 | GNUNET_FS_download_start_from_search(struct GNUNET_FS_Handle *h, | 2217 | GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, |
2217 | struct GNUNET_FS_SearchResult *sr, | 2218 | struct GNUNET_FS_SearchResult *sr, |
2218 | const char *filename, | 2219 | const char *filename, |
2219 | const char *tempname, | 2220 | const char *tempname, |
2220 | uint64_t offset, | 2221 | uint64_t offset, |
2221 | uint64_t length, | 2222 | uint64_t length, |
2222 | uint32_t anonymity, | 2223 | uint32_t anonymity, |
2223 | enum GNUNET_FS_DownloadOptions options, | 2224 | enum GNUNET_FS_DownloadOptions options, |
2224 | void *cctx) | 2225 | void *cctx) |
2225 | { | 2226 | { |
2226 | struct GNUNET_FS_DownloadContext *dc; | 2227 | struct GNUNET_FS_DownloadContext *dc; |
2227 | 2228 | ||
2228 | if ((NULL == sr) || (NULL != sr->download)) | 2229 | if ((NULL == sr) || (NULL != sr->download)) |
2229 | { | 2230 | { |
2230 | GNUNET_break(0); | 2231 | GNUNET_break (0); |
2231 | return NULL; | 2232 | return NULL; |
2232 | } | 2233 | } |
2233 | dc = create_download_context(h, | 2234 | dc = create_download_context (h, |
2234 | sr->uri, | 2235 | sr->uri, |
2235 | sr->meta, | 2236 | sr->meta, |
2236 | filename, | 2237 | filename, |
2237 | tempname, | 2238 | tempname, |
2238 | offset, | 2239 | offset, |
2239 | length, | 2240 | length, |
2240 | anonymity, | 2241 | anonymity, |
2241 | options, | 2242 | options, |
2242 | cctx); | 2243 | cctx); |
2243 | if (NULL == dc) | 2244 | if (NULL == dc) |
2244 | return NULL; | 2245 | return NULL; |
2245 | dc->search = sr; | 2246 | dc->search = sr; |
2246 | sr->download = dc; | 2247 | sr->download = dc; |
2247 | if (NULL != sr->probe_ctx) | 2248 | if (NULL != sr->probe_ctx) |
2248 | { | 2249 | { |
2249 | GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); | 2250 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); |
2250 | sr->probe_ctx = NULL; | 2251 | sr->probe_ctx = NULL; |
2251 | GNUNET_FS_stop_probe_ping_task_(sr); | 2252 | GNUNET_FS_stop_probe_ping_task_ (sr); |
2252 | } | 2253 | } |
2253 | return dc; | 2254 | return dc; |
2254 | } | 2255 | } |
2255 | 2256 | ||
@@ -2260,28 +2261,28 @@ GNUNET_FS_download_start_from_search(struct GNUNET_FS_Handle *h, | |||
2260 | * @param dc our download context | 2261 | * @param dc our download context |
2261 | */ | 2262 | */ |
2262 | void | 2263 | void |
2263 | GNUNET_FS_download_start_downloading_(struct GNUNET_FS_DownloadContext *dc) | 2264 | GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) |
2264 | { | 2265 | { |
2265 | if (dc->completed == dc->length) | 2266 | if (dc->completed == dc->length) |
2266 | return; | 2267 | return; |
2267 | if (NULL != dc->mq) | 2268 | if (NULL != dc->mq) |
2268 | return; /* already running */ | 2269 | return; /* already running */ |
2269 | GNUNET_assert(NULL == dc->job_queue); | 2270 | GNUNET_assert (NULL == dc->job_queue); |
2270 | GNUNET_assert(NULL == dc->task); | 2271 | GNUNET_assert (NULL == dc->task); |
2271 | GNUNET_assert(NULL != dc->active); | 2272 | GNUNET_assert (NULL != dc->active); |
2272 | dc->job_queue = | 2273 | dc->job_queue = |
2273 | GNUNET_FS_queue_(dc->h, | 2274 | GNUNET_FS_queue_ (dc->h, |
2274 | &activate_fs_download, | 2275 | &activate_fs_download, |
2275 | &deactivate_fs_download, | 2276 | &deactivate_fs_download, |
2276 | dc, | 2277 | dc, |
2277 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, | 2278 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, |
2278 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 2279 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) |
2279 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL | 2280 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL |
2280 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); | 2281 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); |
2281 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2282 | "Download %p put into queue as job %p\n", | 2283 | "Download %p put into queue as job %p\n", |
2283 | dc, | 2284 | dc, |
2284 | dc->job_queue); | 2285 | dc->job_queue); |
2285 | } | 2286 | } |
2286 | 2287 | ||
2287 | /** | 2288 | /** |
@@ -2290,9 +2291,9 @@ GNUNET_FS_download_start_downloading_(struct GNUNET_FS_DownloadContext *dc) | |||
2290 | * @param dc handle for the download | 2291 | * @param dc handle for the download |
2291 | */ | 2292 | */ |
2292 | void | 2293 | void |
2293 | GNUNET_FS_download_suspend(struct GNUNET_FS_DownloadContext *dc) | 2294 | GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc) |
2294 | { | 2295 | { |
2295 | deactivate_fs_download(dc); | 2296 | deactivate_fs_download (dc); |
2296 | } | 2297 | } |
2297 | 2298 | ||
2298 | 2299 | ||
@@ -2302,23 +2303,23 @@ GNUNET_FS_download_suspend(struct GNUNET_FS_DownloadContext *dc) | |||
2302 | * @param dc handle for the download | 2303 | * @param dc handle for the download |
2303 | */ | 2304 | */ |
2304 | void | 2305 | void |
2305 | GNUNET_FS_download_resume(struct GNUNET_FS_DownloadContext *dc) | 2306 | GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc) |
2306 | { | 2307 | { |
2307 | struct GNUNET_FS_ProgressInfo pi; | 2308 | struct GNUNET_FS_ProgressInfo pi; |
2308 | 2309 | ||
2309 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; | 2310 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; |
2310 | GNUNET_FS_download_make_status_(&pi, dc); | 2311 | GNUNET_FS_download_make_status_ (&pi, dc); |
2311 | 2312 | ||
2312 | GNUNET_assert(NULL == dc->task); | 2313 | GNUNET_assert (NULL == dc->task); |
2313 | dc->job_queue = | 2314 | dc->job_queue = |
2314 | GNUNET_FS_queue_(dc->h, | 2315 | GNUNET_FS_queue_ (dc->h, |
2315 | &activate_fs_download, | 2316 | &activate_fs_download, |
2316 | &deactivate_fs_download, | 2317 | &deactivate_fs_download, |
2317 | dc, | 2318 | dc, |
2318 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, | 2319 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, |
2319 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 2320 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) |
2320 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL | 2321 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL |
2321 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); | 2322 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); |
2322 | } | 2323 | } |
2323 | 2324 | ||
2324 | 2325 | ||
@@ -2329,88 +2330,88 @@ GNUNET_FS_download_resume(struct GNUNET_FS_DownloadContext *dc) | |||
2329 | * @param do_delete delete files of incomplete downloads | 2330 | * @param do_delete delete files of incomplete downloads |
2330 | */ | 2331 | */ |
2331 | void | 2332 | void |
2332 | GNUNET_FS_download_stop(struct GNUNET_FS_DownloadContext *dc, int do_delete) | 2333 | GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete) |
2333 | { | 2334 | { |
2334 | struct GNUNET_FS_ProgressInfo pi; | 2335 | struct GNUNET_FS_ProgressInfo pi; |
2335 | int have_children; | 2336 | int have_children; |
2336 | int search_was_null; | 2337 | int search_was_null; |
2337 | 2338 | ||
2338 | if (NULL != dc->top) | 2339 | if (NULL != dc->top) |
2339 | GNUNET_FS_end_top(dc->h, dc->top); | 2340 | GNUNET_FS_end_top (dc->h, dc->top); |
2340 | if (NULL != dc->task) | 2341 | if (NULL != dc->task) |
2341 | { | 2342 | { |
2342 | GNUNET_SCHEDULER_cancel(dc->task); | 2343 | GNUNET_SCHEDULER_cancel (dc->task); |
2343 | dc->task = NULL; | 2344 | dc->task = NULL; |
2344 | } | 2345 | } |
2345 | search_was_null = (NULL == dc->search); | 2346 | search_was_null = (NULL == dc->search); |
2346 | if (NULL != dc->search) | 2347 | if (NULL != dc->search) |
2347 | { | 2348 | { |
2348 | dc->search->download = NULL; | 2349 | dc->search->download = NULL; |
2349 | GNUNET_FS_search_result_sync_(dc->search); | 2350 | GNUNET_FS_search_result_sync_ (dc->search); |
2350 | dc->search = NULL; | 2351 | dc->search = NULL; |
2351 | } | 2352 | } |
2352 | if (NULL != dc->job_queue) | 2353 | if (NULL != dc->job_queue) |
2353 | { | 2354 | { |
2354 | GNUNET_FS_dequeue_(dc->job_queue); | 2355 | GNUNET_FS_dequeue_ (dc->job_queue); |
2355 | dc->job_queue = NULL; | 2356 | dc->job_queue = NULL; |
2356 | } | 2357 | } |
2357 | if (NULL != dc->te) | 2358 | if (NULL != dc->te) |
2358 | { | 2359 | { |
2359 | GNUNET_FS_tree_encoder_finish(dc->te, NULL); | 2360 | GNUNET_FS_tree_encoder_finish (dc->te, NULL); |
2360 | dc->te = NULL; | 2361 | dc->te = NULL; |
2361 | } | 2362 | } |
2362 | have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO; | 2363 | have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO; |
2363 | while (NULL != dc->child_head) | 2364 | while (NULL != dc->child_head) |
2364 | GNUNET_FS_download_stop(dc->child_head, do_delete); | 2365 | GNUNET_FS_download_stop (dc->child_head, do_delete); |
2365 | if (NULL != dc->parent) | 2366 | if (NULL != dc->parent) |
2366 | GNUNET_CONTAINER_DLL_remove(dc->parent->child_head, | 2367 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, |
2367 | dc->parent->child_tail, | 2368 | dc->parent->child_tail, |
2368 | dc); | 2369 | dc); |
2369 | if (NULL != dc->serialization) | 2370 | if (NULL != dc->serialization) |
2370 | GNUNET_FS_remove_sync_file_(dc->h, | 2371 | GNUNET_FS_remove_sync_file_ (dc->h, |
2371 | ((NULL != dc->parent) || (!search_was_null)) | 2372 | ((NULL != dc->parent) || (! search_was_null)) |
2373 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD | ||
2374 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | ||
2375 | dc->serialization); | ||
2376 | if ((GNUNET_YES == have_children) && (NULL == dc->parent)) | ||
2377 | GNUNET_FS_remove_sync_dir_ (dc->h, | ||
2378 | (! search_was_null) | ||
2372 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD | 2379 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD |
2373 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 2380 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
2374 | dc->serialization); | 2381 | dc->serialization); |
2375 | if ((GNUNET_YES == have_children) && (NULL == dc->parent)) | ||
2376 | GNUNET_FS_remove_sync_dir_(dc->h, | ||
2377 | (!search_was_null) | ||
2378 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD | ||
2379 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | ||
2380 | dc->serialization); | ||
2381 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; | 2382 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; |
2382 | GNUNET_FS_download_make_status_(&pi, dc); | 2383 | GNUNET_FS_download_make_status_ (&pi, dc); |
2383 | GNUNET_FS_free_download_request_(dc->top_request); | 2384 | GNUNET_FS_free_download_request_ (dc->top_request); |
2384 | dc->top_request = NULL; | 2385 | dc->top_request = NULL; |
2385 | if (NULL != dc->active) | 2386 | if (NULL != dc->active) |
2386 | { | 2387 | { |
2387 | GNUNET_CONTAINER_multihashmap_destroy(dc->active); | 2388 | GNUNET_CONTAINER_multihashmap_destroy (dc->active); |
2388 | dc->active = NULL; | 2389 | dc->active = NULL; |
2389 | } | 2390 | } |
2390 | if (NULL != dc->filename) | 2391 | if (NULL != dc->filename) |
2391 | { | 2392 | { |
2392 | if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) | 2393 | if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) |
2393 | { | 2394 | { |
2394 | if ((0 != unlink(dc->filename)) && (ENOENT != errno)) | 2395 | if ((0 != unlink (dc->filename)) && (ENOENT != errno)) |
2395 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, | 2396 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
2396 | "unlink", | 2397 | "unlink", |
2397 | dc->filename); | 2398 | dc->filename); |
2398 | } | 2399 | } |
2399 | GNUNET_free(dc->filename); | 2400 | GNUNET_free (dc->filename); |
2400 | } | 2401 | } |
2401 | GNUNET_CONTAINER_meta_data_destroy(dc->meta); | 2402 | GNUNET_CONTAINER_meta_data_destroy (dc->meta); |
2402 | GNUNET_FS_uri_destroy(dc->uri); | 2403 | GNUNET_FS_uri_destroy (dc->uri); |
2403 | if (NULL != dc->temp_filename) | 2404 | if (NULL != dc->temp_filename) |
2404 | { | 2405 | { |
2405 | if (0 != unlink(dc->temp_filename)) | 2406 | if (0 != unlink (dc->temp_filename)) |
2406 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, | 2407 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
2407 | "unlink", | 2408 | "unlink", |
2408 | dc->temp_filename); | 2409 | dc->temp_filename); |
2409 | GNUNET_free(dc->temp_filename); | 2410 | GNUNET_free (dc->temp_filename); |
2410 | } | 2411 | } |
2411 | GNUNET_free_non_null(dc->serialization); | 2412 | GNUNET_free_non_null (dc->serialization); |
2412 | GNUNET_assert(NULL == dc->job_queue); | 2413 | GNUNET_assert (NULL == dc->job_queue); |
2413 | GNUNET_free(dc); | 2414 | GNUNET_free (dc); |
2414 | } | 2415 | } |
2415 | 2416 | ||
2416 | /* end of fs_download.c */ | 2417 | /* end of fs_download.c */ |
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c index dbcfd81c4..bbbc30a6e 100644 --- a/src/fs/fs_file_information.c +++ b/src/fs/fs_file_information.c | |||
@@ -42,7 +42,7 @@ | |||
42 | * can be used to read this fi-struct from disk. | 42 | * can be used to read this fi-struct from disk. |
43 | */ | 43 | */ |
44 | const char * | 44 | const char * |
45 | GNUNET_FS_file_information_get_id(struct GNUNET_FS_FileInformation *s) | 45 | GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s) |
46 | { | 46 | { |
47 | if (NULL != s->dir) | 47 | if (NULL != s->dir) |
48 | return NULL; | 48 | return NULL; |
@@ -56,7 +56,7 @@ GNUNET_FS_file_information_get_id(struct GNUNET_FS_FileInformation *s) | |||
56 | * @return "filename" field of the structure (can be NULL) | 56 | * @return "filename" field of the structure (can be NULL) |
57 | */ | 57 | */ |
58 | const char * | 58 | const char * |
59 | GNUNET_FS_file_information_get_filename(struct GNUNET_FS_FileInformation *s) | 59 | GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s) |
60 | { | 60 | { |
61 | return s->filename; | 61 | return s->filename; |
62 | } | 62 | } |
@@ -71,12 +71,12 @@ GNUNET_FS_file_information_get_filename(struct GNUNET_FS_FileInformation *s) | |||
71 | * @param filename filename to set | 71 | * @param filename filename to set |
72 | */ | 72 | */ |
73 | void | 73 | void |
74 | GNUNET_FS_file_information_set_filename(struct GNUNET_FS_FileInformation *s, | 74 | GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s, |
75 | const char *filename) | 75 | const char *filename) |
76 | { | 76 | { |
77 | GNUNET_free_non_null(s->filename); | 77 | GNUNET_free_non_null (s->filename); |
78 | if (filename) | 78 | if (filename) |
79 | s->filename = GNUNET_strdup(filename); | 79 | s->filename = GNUNET_strdup (filename); |
80 | else | 80 | else |
81 | s->filename = NULL; | 81 | s->filename = NULL; |
82 | } | 82 | } |
@@ -97,7 +97,7 @@ GNUNET_FS_file_information_set_filename(struct GNUNET_FS_FileInformation *s, | |||
97 | * @return publish structure entry for the file | 97 | * @return publish structure entry for the file |
98 | */ | 98 | */ |
99 | struct GNUNET_FS_FileInformation * | 99 | struct GNUNET_FS_FileInformation * |
100 | GNUNET_FS_file_information_create_from_file( | 100 | GNUNET_FS_file_information_create_from_file ( |
101 | struct GNUNET_FS_Handle *h, | 101 | struct GNUNET_FS_Handle *h, |
102 | void *client_info, | 102 | void *client_info, |
103 | const char *filename, | 103 | const char *filename, |
@@ -114,44 +114,44 @@ GNUNET_FS_file_information_create_from_file( | |||
114 | 114 | ||
115 | /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ | 115 | /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ |
116 | if (GNUNET_OK != | 116 | if (GNUNET_OK != |
117 | GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)) | 117 | GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)) |
118 | { | 118 | { |
119 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 119 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
120 | return NULL; | 120 | return NULL; |
121 | } | 121 | } |
122 | fi = GNUNET_FS_make_file_reader_context_(filename); | 122 | fi = GNUNET_FS_make_file_reader_context_ (filename); |
123 | if (NULL == fi) | 123 | if (NULL == fi) |
124 | { | 124 | { |
125 | GNUNET_break(0); | 125 | GNUNET_break (0); |
126 | return NULL; | 126 | return NULL; |
127 | } | 127 | } |
128 | ret = | 128 | ret = |
129 | GNUNET_FS_file_information_create_from_reader(h, | 129 | GNUNET_FS_file_information_create_from_reader (h, |
130 | client_info, | 130 | client_info, |
131 | fsize, | 131 | fsize, |
132 | &GNUNET_FS_data_reader_file_, | 132 | &GNUNET_FS_data_reader_file_, |
133 | fi, | 133 | fi, |
134 | keywords, | 134 | keywords, |
135 | meta, | 135 | meta, |
136 | do_index, | 136 | do_index, |
137 | bo); | 137 | bo); |
138 | if (ret == NULL) | 138 | if (ret == NULL) |
139 | return NULL; | 139 | return NULL; |
140 | ret->h = h; | 140 | ret->h = h; |
141 | ret->filename = GNUNET_strdup(filename); | 141 | ret->filename = GNUNET_strdup (filename); |
142 | fn = filename; | 142 | fn = filename; |
143 | while (NULL != (ss = strstr(fn, DIR_SEPARATOR_STR))) | 143 | while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) |
144 | fn = ss + 1; | 144 | fn = ss + 1; |
145 | /* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then | 145 | /* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then |
146 | * this should be changed to EXTRACTOR_METAFORMAT_UTF8 | 146 | * this should be changed to EXTRACTOR_METAFORMAT_UTF8 |
147 | */ | 147 | */ |
148 | GNUNET_CONTAINER_meta_data_insert(ret->meta, | 148 | GNUNET_CONTAINER_meta_data_insert (ret->meta, |
149 | "<gnunet>", | 149 | "<gnunet>", |
150 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | 150 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, |
151 | EXTRACTOR_METAFORMAT_C_STRING, | 151 | EXTRACTOR_METAFORMAT_C_STRING, |
152 | "text/plain", | 152 | "text/plain", |
153 | fn, | 153 | fn, |
154 | strlen(fn) + 1); | 154 | strlen (fn) + 1); |
155 | return ret; | 155 | return ret; |
156 | } | 156 | } |
157 | 157 | ||
@@ -173,7 +173,7 @@ GNUNET_FS_file_information_create_from_file( | |||
173 | * @return publish structure entry for the file | 173 | * @return publish structure entry for the file |
174 | */ | 174 | */ |
175 | struct GNUNET_FS_FileInformation * | 175 | struct GNUNET_FS_FileInformation * |
176 | GNUNET_FS_file_information_create_from_data( | 176 | GNUNET_FS_file_information_create_from_data ( |
177 | struct GNUNET_FS_Handle *h, | 177 | struct GNUNET_FS_Handle *h, |
178 | void *client_info, | 178 | void *client_info, |
179 | uint64_t length, | 179 | uint64_t length, |
@@ -184,19 +184,20 @@ GNUNET_FS_file_information_create_from_data( | |||
184 | const struct GNUNET_FS_BlockOptions *bo) | 184 | const struct GNUNET_FS_BlockOptions *bo) |
185 | { | 185 | { |
186 | if (GNUNET_YES == do_index) | 186 | if (GNUNET_YES == do_index) |
187 | { | 187 | { |
188 | GNUNET_break(0); | 188 | GNUNET_break (0); |
189 | return NULL; | 189 | return NULL; |
190 | } | 190 | } |
191 | return GNUNET_FS_file_information_create_from_reader(h, | 191 | return GNUNET_FS_file_information_create_from_reader (h, |
192 | client_info, | 192 | client_info, |
193 | length, | 193 | length, |
194 | &GNUNET_FS_data_reader_copy_, | 194 | & |
195 | data, | 195 | GNUNET_FS_data_reader_copy_, |
196 | keywords, | 196 | data, |
197 | meta, | 197 | keywords, |
198 | do_index, | 198 | meta, |
199 | bo); | 199 | do_index, |
200 | bo); | ||
200 | } | 201 | } |
201 | 202 | ||
202 | 203 | ||
@@ -217,7 +218,7 @@ GNUNET_FS_file_information_create_from_data( | |||
217 | * @return publish structure entry for the file | 218 | * @return publish structure entry for the file |
218 | */ | 219 | */ |
219 | struct GNUNET_FS_FileInformation * | 220 | struct GNUNET_FS_FileInformation * |
220 | GNUNET_FS_file_information_create_from_reader( | 221 | GNUNET_FS_file_information_create_from_reader ( |
221 | struct GNUNET_FS_Handle *h, | 222 | struct GNUNET_FS_Handle *h, |
222 | void *client_info, | 223 | void *client_info, |
223 | uint64_t length, | 224 | uint64_t length, |
@@ -231,17 +232,17 @@ GNUNET_FS_file_information_create_from_reader( | |||
231 | struct GNUNET_FS_FileInformation *ret; | 232 | struct GNUNET_FS_FileInformation *ret; |
232 | 233 | ||
233 | if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_)) | 234 | if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_)) |
234 | { | 235 | { |
235 | GNUNET_break(0); | 236 | GNUNET_break (0); |
236 | return NULL; | 237 | return NULL; |
237 | } | 238 | } |
238 | ret = GNUNET_new(struct GNUNET_FS_FileInformation); | 239 | ret = GNUNET_new (struct GNUNET_FS_FileInformation); |
239 | ret->h = h; | 240 | ret->h = h; |
240 | ret->client_info = client_info; | 241 | ret->client_info = client_info; |
241 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); | 242 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
242 | if (ret->meta == NULL) | 243 | if (ret->meta == NULL) |
243 | ret->meta = GNUNET_CONTAINER_meta_data_create(); | 244 | ret->meta = GNUNET_CONTAINER_meta_data_create (); |
244 | ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup(keywords); | 245 | ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords); |
245 | ret->data.file.reader = reader; | 246 | ret->data.file.reader = reader; |
246 | ret->data.file.reader_cls = reader_cls; | 247 | ret->data.file.reader_cls = reader_cls; |
247 | ret->data.file.do_index = do_index; | 248 | ret->data.file.do_index = do_index; |
@@ -258,7 +259,7 @@ GNUNET_FS_file_information_create_from_reader( | |||
258 | * @return #GNUNET_YES if so, #GNUNET_NO if not | 259 | * @return #GNUNET_YES if so, #GNUNET_NO if not |
259 | */ | 260 | */ |
260 | int | 261 | int |
261 | GNUNET_FS_file_information_is_directory( | 262 | GNUNET_FS_file_information_is_directory ( |
262 | const struct GNUNET_FS_FileInformation *ent) | 263 | const struct GNUNET_FS_FileInformation *ent) |
263 | { | 264 | { |
264 | return ent->is_directory; | 265 | return ent->is_directory; |
@@ -278,7 +279,7 @@ GNUNET_FS_file_information_is_directory( | |||
278 | * @return publish structure entry for the directory , NULL on error | 279 | * @return publish structure entry for the directory , NULL on error |
279 | */ | 280 | */ |
280 | struct GNUNET_FS_FileInformation * | 281 | struct GNUNET_FS_FileInformation * |
281 | GNUNET_FS_file_information_create_empty_directory( | 282 | GNUNET_FS_file_information_create_empty_directory ( |
282 | struct GNUNET_FS_Handle *h, | 283 | struct GNUNET_FS_Handle *h, |
283 | void *client_info, | 284 | void *client_info, |
284 | const struct GNUNET_FS_Uri *keywords, | 285 | const struct GNUNET_FS_Uri *keywords, |
@@ -288,15 +289,15 @@ GNUNET_FS_file_information_create_empty_directory( | |||
288 | { | 289 | { |
289 | struct GNUNET_FS_FileInformation *ret; | 290 | struct GNUNET_FS_FileInformation *ret; |
290 | 291 | ||
291 | ret = GNUNET_new(struct GNUNET_FS_FileInformation); | 292 | ret = GNUNET_new (struct GNUNET_FS_FileInformation); |
292 | ret->h = h; | 293 | ret->h = h; |
293 | ret->client_info = client_info; | 294 | ret->client_info = client_info; |
294 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); | 295 | ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
295 | ret->keywords = GNUNET_FS_uri_dup(keywords); | 296 | ret->keywords = GNUNET_FS_uri_dup (keywords); |
296 | ret->bo = *bo; | 297 | ret->bo = *bo; |
297 | ret->is_directory = GNUNET_YES; | 298 | ret->is_directory = GNUNET_YES; |
298 | if (filename != NULL) | 299 | if (filename != NULL) |
299 | ret->filename = GNUNET_strdup(filename); | 300 | ret->filename = GNUNET_strdup (filename); |
300 | return ret; | 301 | return ret; |
301 | } | 302 | } |
302 | 303 | ||
@@ -313,15 +314,15 @@ GNUNET_FS_file_information_create_empty_directory( | |||
313 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 314 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
314 | */ | 315 | */ |
315 | int | 316 | int |
316 | GNUNET_FS_file_information_add(struct GNUNET_FS_FileInformation *dir, | 317 | GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, |
317 | struct GNUNET_FS_FileInformation *ent) | 318 | struct GNUNET_FS_FileInformation *ent) |
318 | { | 319 | { |
319 | if ((ent->dir != NULL) || (ent->next != NULL) || | 320 | if ((ent->dir != NULL) || (ent->next != NULL) || |
320 | (dir->is_directory != GNUNET_YES)) | 321 | (dir->is_directory != GNUNET_YES)) |
321 | { | 322 | { |
322 | GNUNET_break(0); | 323 | GNUNET_break (0); |
323 | return GNUNET_SYSERR; | 324 | return GNUNET_SYSERR; |
324 | } | 325 | } |
325 | ent->dir = dir; | 326 | ent->dir = dir; |
326 | ent->next = dir->data.dir.entries; | 327 | ent->next = dir->data.dir.entries; |
327 | dir->data.dir.entries = ent; | 328 | dir->data.dir.entries = ent; |
@@ -345,45 +346,45 @@ GNUNET_FS_file_information_add(struct GNUNET_FS_FileInformation *dir, | |||
345 | * @param proc_cls closure for @a proc | 346 | * @param proc_cls closure for @a proc |
346 | */ | 347 | */ |
347 | void | 348 | void |
348 | GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir, | 349 | GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, |
349 | GNUNET_FS_FileInformationProcessor proc, | 350 | GNUNET_FS_FileInformationProcessor proc, |
350 | void *proc_cls) | 351 | void *proc_cls) |
351 | { | 352 | { |
352 | struct GNUNET_FS_FileInformation *pos; | 353 | struct GNUNET_FS_FileInformation *pos; |
353 | int no; | 354 | int no; |
354 | 355 | ||
355 | no = GNUNET_NO; | 356 | no = GNUNET_NO; |
356 | if (GNUNET_OK != | 357 | if (GNUNET_OK != |
357 | proc(proc_cls, | 358 | proc (proc_cls, |
358 | dir, | 359 | dir, |
359 | (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size | 360 | (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size |
360 | : dir->data.file.file_size, | 361 | : dir->data.file.file_size, |
361 | dir->meta, | 362 | dir->meta, |
362 | &dir->keywords, | 363 | &dir->keywords, |
363 | &dir->bo, | 364 | &dir->bo, |
364 | (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, | 365 | (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, |
365 | &dir->client_info)) | 366 | &dir->client_info)) |
366 | return; | 367 | return; |
367 | if (dir->is_directory != GNUNET_YES) | 368 | if (dir->is_directory != GNUNET_YES) |
368 | return; | 369 | return; |
369 | pos = dir->data.dir.entries; | 370 | pos = dir->data.dir.entries; |
370 | while (pos != NULL) | 371 | while (pos != NULL) |
371 | { | 372 | { |
372 | no = GNUNET_NO; | 373 | no = GNUNET_NO; |
373 | if (GNUNET_OK != | 374 | if (GNUNET_OK != |
374 | proc(proc_cls, | 375 | proc (proc_cls, |
375 | pos, | 376 | pos, |
376 | (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size | 377 | (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size |
377 | : pos->data.file.file_size, | 378 | : pos->data.file.file_size, |
378 | pos->meta, | 379 | pos->meta, |
379 | &pos->keywords, | 380 | &pos->keywords, |
380 | &pos->bo, | 381 | &pos->bo, |
381 | (pos->is_directory == GNUNET_YES) ? &no | 382 | (pos->is_directory == GNUNET_YES) ? &no |
382 | : &pos->data.file.do_index, | 383 | : &pos->data.file.do_index, |
383 | &pos->client_info)) | 384 | &pos->client_info)) |
384 | break; | 385 | break; |
385 | pos = pos->next; | 386 | pos = pos->next; |
386 | } | 387 | } |
387 | } | 388 | } |
388 | 389 | ||
389 | 390 | ||
@@ -398,75 +399,75 @@ GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir, | |||
398 | * @param cleaner_cls closure for @a cleaner | 399 | * @param cleaner_cls closure for @a cleaner |
399 | */ | 400 | */ |
400 | void | 401 | void |
401 | GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi, | 402 | GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, |
402 | GNUNET_FS_FileInformationProcessor cleaner, | 403 | GNUNET_FS_FileInformationProcessor cleaner, |
403 | void *cleaner_cls) | 404 | void *cleaner_cls) |
404 | { | 405 | { |
405 | struct GNUNET_FS_FileInformation *pos; | 406 | struct GNUNET_FS_FileInformation *pos; |
406 | int no; | 407 | int no; |
407 | 408 | ||
408 | no = GNUNET_NO; | 409 | no = GNUNET_NO; |
409 | if (GNUNET_YES == fi->is_directory) | 410 | if (GNUNET_YES == fi->is_directory) |
411 | { | ||
412 | /* clean up directory */ | ||
413 | while (NULL != (pos = fi->data.dir.entries)) | ||
410 | { | 414 | { |
411 | /* clean up directory */ | 415 | fi->data.dir.entries = pos->next; |
412 | while (NULL != (pos = fi->data.dir.entries)) | 416 | GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls); |
413 | { | ||
414 | fi->data.dir.entries = pos->next; | ||
415 | GNUNET_FS_file_information_destroy(pos, cleaner, cleaner_cls); | ||
416 | } | ||
417 | /* clean up client-info */ | ||
418 | if (NULL != cleaner) | ||
419 | cleaner(cleaner_cls, | ||
420 | fi, | ||
421 | fi->data.dir.dir_size, | ||
422 | fi->meta, | ||
423 | &fi->keywords, | ||
424 | &fi->bo, | ||
425 | &no, | ||
426 | &fi->client_info); | ||
427 | GNUNET_free_non_null(fi->data.dir.dir_data); | ||
428 | } | 417 | } |
418 | /* clean up client-info */ | ||
419 | if (NULL != cleaner) | ||
420 | cleaner (cleaner_cls, | ||
421 | fi, | ||
422 | fi->data.dir.dir_size, | ||
423 | fi->meta, | ||
424 | &fi->keywords, | ||
425 | &fi->bo, | ||
426 | &no, | ||
427 | &fi->client_info); | ||
428 | GNUNET_free_non_null (fi->data.dir.dir_data); | ||
429 | } | ||
429 | else | 430 | else |
431 | { | ||
432 | /* call clean-up function of the reader */ | ||
433 | if (NULL != fi->data.file.reader) | ||
430 | { | 434 | { |
431 | /* call clean-up function of the reader */ | 435 | (void) fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL); |
432 | if (NULL != fi->data.file.reader) | 436 | fi->data.file.reader = NULL; |
433 | { | ||
434 | (void)fi->data.file.reader(fi->data.file.reader_cls, 0, 0, NULL, NULL); | ||
435 | fi->data.file.reader = NULL; | ||
436 | } | ||
437 | /* clean up client-info */ | ||
438 | if (NULL != cleaner) | ||
439 | cleaner(cleaner_cls, | ||
440 | fi, | ||
441 | fi->data.file.file_size, | ||
442 | fi->meta, | ||
443 | &fi->keywords, | ||
444 | &fi->bo, | ||
445 | &fi->data.file.do_index, | ||
446 | &fi->client_info); | ||
447 | } | 437 | } |
448 | GNUNET_free_non_null(fi->filename); | 438 | /* clean up client-info */ |
449 | GNUNET_free_non_null(fi->emsg); | 439 | if (NULL != cleaner) |
440 | cleaner (cleaner_cls, | ||
441 | fi, | ||
442 | fi->data.file.file_size, | ||
443 | fi->meta, | ||
444 | &fi->keywords, | ||
445 | &fi->bo, | ||
446 | &fi->data.file.do_index, | ||
447 | &fi->client_info); | ||
448 | } | ||
449 | GNUNET_free_non_null (fi->filename); | ||
450 | GNUNET_free_non_null (fi->emsg); | ||
450 | if (NULL != fi->sks_uri) | 451 | if (NULL != fi->sks_uri) |
451 | GNUNET_FS_uri_destroy(fi->sks_uri); | 452 | GNUNET_FS_uri_destroy (fi->sks_uri); |
452 | if (NULL != fi->chk_uri) | 453 | if (NULL != fi->chk_uri) |
453 | GNUNET_FS_uri_destroy(fi->chk_uri); | 454 | GNUNET_FS_uri_destroy (fi->chk_uri); |
454 | /* clean up serialization */ | 455 | /* clean up serialization */ |
455 | if ((NULL != fi->serialization) && (0 != unlink(fi->serialization))) | 456 | if ((NULL != fi->serialization) && (0 != unlink (fi->serialization))) |
456 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, | 457 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
457 | "unlink", | 458 | "unlink", |
458 | fi->serialization); | 459 | fi->serialization); |
459 | if (NULL != fi->keywords) | 460 | if (NULL != fi->keywords) |
460 | GNUNET_FS_uri_destroy(fi->keywords); | 461 | GNUNET_FS_uri_destroy (fi->keywords); |
461 | if (NULL != fi->meta) | 462 | if (NULL != fi->meta) |
462 | GNUNET_CONTAINER_meta_data_destroy(fi->meta); | 463 | GNUNET_CONTAINER_meta_data_destroy (fi->meta); |
463 | GNUNET_free_non_null(fi->serialization); | 464 | GNUNET_free_non_null (fi->serialization); |
464 | if (NULL != fi->te) | 465 | if (NULL != fi->te) |
465 | { | 466 | { |
466 | GNUNET_FS_tree_encoder_finish(fi->te, NULL); | 467 | GNUNET_FS_tree_encoder_finish (fi->te, NULL); |
467 | fi->te = NULL; | 468 | fi->te = NULL; |
468 | } | 469 | } |
469 | GNUNET_free(fi); | 470 | GNUNET_free (fi); |
470 | } | 471 | } |
471 | 472 | ||
472 | 473 | ||
diff --git a/src/fs/fs_getopt.c b/src/fs/fs_getopt.c index 4f53f64a5..84c1f6123 100644 --- a/src/fs/fs_getopt.c +++ b/src/fs/fs_getopt.c | |||
@@ -43,10 +43,10 @@ | |||
43 | * @return #GNUNET_OK on success | 43 | * @return #GNUNET_OK on success |
44 | */ | 44 | */ |
45 | static int | 45 | static int |
46 | getopt_set_keywords(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 46 | getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
47 | void *scls, | 47 | void *scls, |
48 | const char *option, | 48 | const char *option, |
49 | const char *value) | 49 | const char *value) |
50 | { | 50 | { |
51 | struct GNUNET_FS_Uri **uri = scls; | 51 | struct GNUNET_FS_Uri **uri = scls; |
52 | struct GNUNET_FS_Uri *u = *uri; | 52 | struct GNUNET_FS_Uri *u = *uri; |
@@ -54,64 +54,64 @@ getopt_set_keywords(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
54 | size_t slen; | 54 | size_t slen; |
55 | 55 | ||
56 | if (NULL == u) | 56 | if (NULL == u) |
57 | { | 57 | { |
58 | u = GNUNET_new(struct GNUNET_FS_Uri); | 58 | u = GNUNET_new (struct GNUNET_FS_Uri); |
59 | *uri = u; | 59 | *uri = u; |
60 | u->type = GNUNET_FS_URI_KSK; | 60 | u->type = GNUNET_FS_URI_KSK; |
61 | u->data.ksk.keywordCount = 0; | 61 | u->data.ksk.keywordCount = 0; |
62 | u->data.ksk.keywords = NULL; | 62 | u->data.ksk.keywords = NULL; |
63 | } | 63 | } |
64 | else | 64 | else |
65 | { | 65 | { |
66 | GNUNET_assert(GNUNET_FS_URI_KSK == u->type); | 66 | GNUNET_assert (GNUNET_FS_URI_KSK == u->type); |
67 | } | 67 | } |
68 | slen = strlen(value); | 68 | slen = strlen (value); |
69 | if (0 == slen) | 69 | if (0 == slen) |
70 | return GNUNET_SYSERR; /* cannot be empty */ | 70 | return GNUNET_SYSERR; /* cannot be empty */ |
71 | if (value[0] == '+') | 71 | if (value[0] == '+') |
72 | { | ||
73 | /* simply preserve the "mandatory" flag */ | ||
74 | if (slen < 2) | ||
75 | return GNUNET_SYSERR; /* empty keywords not allowed */ | ||
76 | if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"')) | ||
72 | { | 77 | { |
73 | /* simply preserve the "mandatory" flag */ | 78 | /* remove the quotes, keep the '+' */ |
74 | if (slen < 2) | 79 | val = GNUNET_malloc (slen - 1); |
75 | return GNUNET_SYSERR; /* empty keywords not allowed */ | 80 | val[0] = '+'; |
76 | if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"')) | 81 | GNUNET_memcpy (&val[1], |
77 | { | 82 | &value[2], |
78 | /* remove the quotes, keep the '+' */ | 83 | slen - 3); |
79 | val = GNUNET_malloc(slen - 1); | 84 | val[slen - 2] = '\0'; |
80 | val[0] = '+'; | ||
81 | GNUNET_memcpy(&val[1], | ||
82 | &value[2], | ||
83 | slen - 3); | ||
84 | val[slen - 2] = '\0'; | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | /* no quotes, just keep the '+' */ | ||
89 | val = GNUNET_strdup(value); | ||
90 | } | ||
91 | } | 85 | } |
86 | else | ||
87 | { | ||
88 | /* no quotes, just keep the '+' */ | ||
89 | val = GNUNET_strdup (value); | ||
90 | } | ||
91 | } | ||
92 | else | 92 | else |
93 | { | ||
94 | if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"')) | ||
95 | { | ||
96 | /* remove the quotes, add a space */ | ||
97 | val = GNUNET_malloc (slen); | ||
98 | val[0] = ' '; | ||
99 | GNUNET_memcpy (&val[1], | ||
100 | &value[1], | ||
101 | slen - 2); | ||
102 | val[slen - 1] = '\0'; | ||
103 | } | ||
104 | else | ||
93 | { | 105 | { |
94 | if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"')) | 106 | /* add a space to indicate "not mandatory" */ |
95 | { | 107 | val = GNUNET_malloc (slen + 2); |
96 | /* remove the quotes, add a space */ | 108 | strcpy (val, " "); |
97 | val = GNUNET_malloc(slen); | 109 | strcat (val, value); |
98 | val[0] = ' '; | ||
99 | GNUNET_memcpy(&val[1], | ||
100 | &value[1], | ||
101 | slen - 2); | ||
102 | val[slen - 1] = '\0'; | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | /* add a space to indicate "not mandatory" */ | ||
107 | val = GNUNET_malloc(slen + 2); | ||
108 | strcpy(val, " "); | ||
109 | strcat(val, value); | ||
110 | } | ||
111 | } | 110 | } |
112 | GNUNET_array_append(u->data.ksk.keywords, | 111 | } |
113 | u->data.ksk.keywordCount, | 112 | GNUNET_array_append (u->data.ksk.keywords, |
114 | val); | 113 | u->data.ksk.keywordCount, |
114 | val); | ||
115 | return GNUNET_OK; | 115 | return GNUNET_OK; |
116 | } | 116 | } |
117 | 117 | ||
@@ -126,11 +126,11 @@ getopt_set_keywords(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
126 | * @param[out] topKeywords set to the desired value | 126 | * @param[out] topKeywords set to the desired value |
127 | */ | 127 | */ |
128 | struct GNUNET_GETOPT_CommandLineOption | 128 | struct GNUNET_GETOPT_CommandLineOption |
129 | GNUNET_FS_GETOPT_KEYWORDS(char shortName, | 129 | GNUNET_FS_GETOPT_KEYWORDS (char shortName, |
130 | const char *name, | 130 | const char *name, |
131 | const char *argumentHelp, | 131 | const char *argumentHelp, |
132 | const char *description, | 132 | const char *description, |
133 | struct GNUNET_FS_Uri **topKeywords) | 133 | struct GNUNET_FS_Uri **topKeywords) |
134 | { | 134 | { |
135 | struct GNUNET_GETOPT_CommandLineOption clo = { | 135 | struct GNUNET_GETOPT_CommandLineOption clo = { |
136 | .shortName = shortName, | 136 | .shortName = shortName, |
@@ -139,7 +139,7 @@ GNUNET_FS_GETOPT_KEYWORDS(char shortName, | |||
139 | .description = description, | 139 | .description = description, |
140 | .require_argument = 1, | 140 | .require_argument = 1, |
141 | .processor = &getopt_set_keywords, | 141 | .processor = &getopt_set_keywords, |
142 | .scls = (void *)topKeywords | 142 | .scls = (void *) topKeywords |
143 | }; | 143 | }; |
144 | 144 | ||
145 | return clo; | 145 | return clo; |
@@ -159,10 +159,10 @@ GNUNET_FS_GETOPT_KEYWORDS(char shortName, | |||
159 | * @return #GNUNET_OK on success | 159 | * @return #GNUNET_OK on success |
160 | */ | 160 | */ |
161 | static int | 161 | static int |
162 | getopt_set_metadata(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 162 | getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
163 | void *scls, | 163 | void *scls, |
164 | const char *option, | 164 | const char *option, |
165 | const char *value) | 165 | const char *value) |
166 | { | 166 | { |
167 | struct GNUNET_CONTAINER_MetaData **mm = scls; | 167 | struct GNUNET_CONTAINER_MetaData **mm = scls; |
168 | 168 | ||
@@ -176,66 +176,67 @@ getopt_set_metadata(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
176 | 176 | ||
177 | meta = *mm; | 177 | meta = *mm; |
178 | if (meta == NULL) | 178 | if (meta == NULL) |
179 | { | 179 | { |
180 | meta = GNUNET_CONTAINER_meta_data_create(); | 180 | meta = GNUNET_CONTAINER_meta_data_create (); |
181 | *mm = meta; | 181 | *mm = meta; |
182 | } | 182 | } |
183 | 183 | ||
184 | /* Use GNUNET_STRINGS_get_utf8_args() in main() to acquire utf-8-encoded | 184 | /* Use GNUNET_STRINGS_get_utf8_args() in main() to acquire utf-8-encoded |
185 | * commandline arguments, so that the following line is not needed. | 185 | * commandline arguments, so that the following line is not needed. |
186 | */ | 186 | */ |
187 | /*tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), locale_charset ());*/ | 187 | /*tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), locale_charset ());*/ |
188 | tmp = GNUNET_strdup(value); | 188 | tmp = GNUNET_strdup (value); |
189 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR | 189 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR |
190 | type = EXTRACTOR_metatype_get_max(); | 190 | type = EXTRACTOR_metatype_get_max (); |
191 | while (type > 0) | 191 | while (type > 0) |
192 | { | ||
193 | type--; | ||
194 | typename = EXTRACTOR_metatype_to_string (type); | ||
195 | typename_i18n = dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, typename); | ||
196 | if ((strlen (tmp) >= strlen (typename) + 1) && | ||
197 | (tmp[strlen (typename)] == ':') && | ||
198 | (0 == strncmp (typename, tmp, strlen (typename)))) | ||
192 | { | 199 | { |
193 | type--; | 200 | GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", type, |
194 | typename = EXTRACTOR_metatype_to_string(type); | 201 | EXTRACTOR_METAFORMAT_UTF8, |
195 | typename_i18n = dgettext(LIBEXTRACTOR_GETTEXT_DOMAIN, typename); | 202 | "text/plain", |
196 | if ((strlen(tmp) >= strlen(typename) + 1) && | 203 | &tmp[strlen (typename) + 1], |
197 | (tmp[strlen(typename)] == ':') && | 204 | strlen (&tmp[strlen (typename) + 1]) |
198 | (0 == strncmp(typename, tmp, strlen(typename)))) | 205 | + 1); |
199 | { | 206 | GNUNET_free (tmp); |
200 | GNUNET_CONTAINER_meta_data_insert(meta, "<gnunet>", type, | 207 | tmp = NULL; |
201 | EXTRACTOR_METAFORMAT_UTF8, | 208 | break; |
202 | "text/plain", | ||
203 | &tmp[strlen(typename) + 1], | ||
204 | strlen(&tmp[strlen(typename) + 1]) + | ||
205 | 1); | ||
206 | GNUNET_free(tmp); | ||
207 | tmp = NULL; | ||
208 | break; | ||
209 | } | ||
210 | if ((strlen(tmp) >= strlen(typename_i18n) + 1) && | ||
211 | (tmp[strlen(typename_i18n)] == ':') && | ||
212 | (0 == strncmp(typename_i18n, tmp, strlen(typename_i18n)))) | ||
213 | { | ||
214 | GNUNET_CONTAINER_meta_data_insert(meta, "<gnunet>", type, | ||
215 | EXTRACTOR_METAFORMAT_UTF8, | ||
216 | "text/plain", | ||
217 | &tmp[strlen(typename_i18n) + 1], | ||
218 | strlen(&tmp | ||
219 | [strlen(typename_i18n) + 1]) + | ||
220 | 1); | ||
221 | GNUNET_free(tmp); | ||
222 | tmp = NULL; | ||
223 | break; | ||
224 | } | ||
225 | } | 209 | } |
210 | if ((strlen (tmp) >= strlen (typename_i18n) + 1) && | ||
211 | (tmp[strlen (typename_i18n)] == ':') && | ||
212 | (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n)))) | ||
213 | { | ||
214 | GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", type, | ||
215 | EXTRACTOR_METAFORMAT_UTF8, | ||
216 | "text/plain", | ||
217 | &tmp[strlen (typename_i18n) + 1], | ||
218 | strlen (&tmp | ||
219 | [strlen (typename_i18n) + 1]) | ||
220 | + 1); | ||
221 | GNUNET_free (tmp); | ||
222 | tmp = NULL; | ||
223 | break; | ||
224 | } | ||
225 | } | ||
226 | #endif | 226 | #endif |
227 | 227 | ||
228 | if (NULL != tmp) | 228 | if (NULL != tmp) |
229 | { | 229 | { |
230 | GNUNET_CONTAINER_meta_data_insert(meta, "<gnunet>", | 230 | GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", |
231 | EXTRACTOR_METATYPE_UNKNOWN, | 231 | EXTRACTOR_METATYPE_UNKNOWN, |
232 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 232 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
233 | tmp, strlen(tmp) + 1); | 233 | tmp, strlen (tmp) + 1); |
234 | GNUNET_free(tmp); | 234 | GNUNET_free (tmp); |
235 | printf(_ | 235 | printf (_ |
236 | ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"), | 236 | ( |
237 | value); | 237 | "Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"), |
238 | } | 238 | value); |
239 | } | ||
239 | return GNUNET_OK; | 240 | return GNUNET_OK; |
240 | } | 241 | } |
241 | 242 | ||
@@ -249,11 +250,11 @@ getopt_set_metadata(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
249 | * @param[out] metadata set to the desired value | 250 | * @param[out] metadata set to the desired value |
250 | */ | 251 | */ |
251 | struct GNUNET_GETOPT_CommandLineOption | 252 | struct GNUNET_GETOPT_CommandLineOption |
252 | GNUNET_FS_GETOPT_METADATA(char shortName, | 253 | GNUNET_FS_GETOPT_METADATA (char shortName, |
253 | const char *name, | 254 | const char *name, |
254 | const char *argumentHelp, | 255 | const char *argumentHelp, |
255 | const char *description, | 256 | const char *description, |
256 | struct GNUNET_CONTAINER_MetaData **meta) | 257 | struct GNUNET_CONTAINER_MetaData **meta) |
257 | { | 258 | { |
258 | struct GNUNET_GETOPT_CommandLineOption clo = { | 259 | struct GNUNET_GETOPT_CommandLineOption clo = { |
259 | .shortName = shortName, | 260 | .shortName = shortName, |
@@ -262,7 +263,7 @@ GNUNET_FS_GETOPT_METADATA(char shortName, | |||
262 | .description = description, | 263 | .description = description, |
263 | .require_argument = 1, | 264 | .require_argument = 1, |
264 | .processor = &getopt_set_metadata, | 265 | .processor = &getopt_set_metadata, |
265 | .scls = (void *)meta | 266 | .scls = (void *) meta |
266 | }; | 267 | }; |
267 | 268 | ||
268 | return clo; | 269 | return clo; |
diff --git a/src/fs/fs_list_indexed.c b/src/fs/fs_list_indexed.c index c023d0ac6..0e16fb01b 100644 --- a/src/fs/fs_list_indexed.c +++ b/src/fs/fs_list_indexed.c | |||
@@ -34,7 +34,8 @@ | |||
34 | /** | 34 | /** |
35 | * Context for #GNUNET_FS_get_indexed_files(). | 35 | * Context for #GNUNET_FS_get_indexed_files(). |
36 | */ | 36 | */ |
37 | struct GNUNET_FS_GetIndexedContext { | 37 | struct GNUNET_FS_GetIndexedContext |
38 | { | ||
38 | /** | 39 | /** |
39 | * Connection to the FS service. | 40 | * Connection to the FS service. |
40 | */ | 41 | */ |
@@ -70,15 +71,15 @@ struct GNUNET_FS_GetIndexedContext { | |||
70 | * @param msg message with indexing information | 71 | * @param msg message with indexing information |
71 | */ | 72 | */ |
72 | static void | 73 | static void |
73 | handle_index_info_end(void *cls, | 74 | handle_index_info_end (void *cls, |
74 | const struct GNUNET_MessageHeader *msg) | 75 | const struct GNUNET_MessageHeader *msg) |
75 | { | 76 | { |
76 | struct GNUNET_FS_GetIndexedContext *gic = cls; | 77 | struct GNUNET_FS_GetIndexedContext *gic = cls; |
77 | 78 | ||
78 | (void)gic->iterator(gic->iterator_cls, | 79 | (void) gic->iterator (gic->iterator_cls, |
79 | NULL, | 80 | NULL, |
80 | NULL); | 81 | NULL); |
81 | GNUNET_FS_get_indexed_files_cancel(gic); | 82 | GNUNET_FS_get_indexed_files_cancel (gic); |
82 | } | 83 | } |
83 | 84 | ||
84 | 85 | ||
@@ -90,18 +91,18 @@ handle_index_info_end(void *cls, | |||
90 | * @param iim message with indexing information | 91 | * @param iim message with indexing information |
91 | */ | 92 | */ |
92 | static int | 93 | static int |
93 | check_index_info(void *cls, | 94 | check_index_info (void *cls, |
94 | const struct IndexInfoMessage *iim) | 95 | const struct IndexInfoMessage *iim) |
95 | { | 96 | { |
96 | uint16_t msize = ntohs(iim->header.size) - sizeof(*iim); | 97 | uint16_t msize = ntohs (iim->header.size) - sizeof(*iim); |
97 | const char *filename; | 98 | const char *filename; |
98 | 99 | ||
99 | filename = (const char *)&iim[1]; | 100 | filename = (const char *) &iim[1]; |
100 | if (filename[msize - 1] != '\0') | 101 | if (filename[msize - 1] != '\0') |
101 | { | 102 | { |
102 | GNUNET_break(0); | 103 | GNUNET_break (0); |
103 | return GNUNET_SYSERR; | 104 | return GNUNET_SYSERR; |
104 | } | 105 | } |
105 | return GNUNET_OK; | 106 | return GNUNET_OK; |
106 | } | 107 | } |
107 | 108 | ||
@@ -114,21 +115,21 @@ check_index_info(void *cls, | |||
114 | * @param iim message with indexing information | 115 | * @param iim message with indexing information |
115 | */ | 116 | */ |
116 | static void | 117 | static void |
117 | handle_index_info(void *cls, | 118 | handle_index_info (void *cls, |
118 | const struct IndexInfoMessage *iim) | 119 | const struct IndexInfoMessage *iim) |
119 | { | 120 | { |
120 | struct GNUNET_FS_GetIndexedContext *gic = cls; | 121 | struct GNUNET_FS_GetIndexedContext *gic = cls; |
121 | const char *filename; | 122 | const char *filename; |
122 | 123 | ||
123 | filename = (const char *)&iim[1]; | 124 | filename = (const char *) &iim[1]; |
124 | if (GNUNET_OK != | 125 | if (GNUNET_OK != |
125 | gic->iterator(gic->iterator_cls, | 126 | gic->iterator (gic->iterator_cls, |
126 | filename, | 127 | filename, |
127 | &iim->file_id)) | 128 | &iim->file_id)) |
128 | { | 129 | { |
129 | GNUNET_FS_get_indexed_files_cancel(gic); | 130 | GNUNET_FS_get_indexed_files_cancel (gic); |
130 | return; | 131 | return; |
131 | } | 132 | } |
132 | } | 133 | } |
133 | 134 | ||
134 | 135 | ||
@@ -141,16 +142,16 @@ handle_index_info(void *cls, | |||
141 | * @param error error code | 142 | * @param error error code |
142 | */ | 143 | */ |
143 | static void | 144 | static void |
144 | mq_error_handler(void *cls, | 145 | mq_error_handler (void *cls, |
145 | enum GNUNET_MQ_Error error) | 146 | enum GNUNET_MQ_Error error) |
146 | { | 147 | { |
147 | struct GNUNET_FS_GetIndexedContext *gic = cls; | 148 | struct GNUNET_FS_GetIndexedContext *gic = cls; |
148 | 149 | ||
149 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 150 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
150 | _("Failed to receive response from `%s' service.\n"), | 151 | _ ("Failed to receive response from `%s' service.\n"), |
151 | "fs"); | 152 | "fs"); |
152 | (void)gic->iterator(gic->iterator_cls, NULL, NULL); | 153 | (void) gic->iterator (gic->iterator_cls, NULL, NULL); |
153 | GNUNET_FS_get_indexed_files_cancel(gic); | 154 | GNUNET_FS_get_indexed_files_cancel (gic); |
154 | } | 155 | } |
155 | 156 | ||
156 | 157 | ||
@@ -163,45 +164,45 @@ mq_error_handler(void *cls, | |||
163 | * @return NULL on error ('iter' is not called) | 164 | * @return NULL on error ('iter' is not called) |
164 | */ | 165 | */ |
165 | struct GNUNET_FS_GetIndexedContext * | 166 | struct GNUNET_FS_GetIndexedContext * |
166 | GNUNET_FS_get_indexed_files(struct GNUNET_FS_Handle *h, | 167 | GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, |
167 | GNUNET_FS_IndexedFileProcessor iterator, | 168 | GNUNET_FS_IndexedFileProcessor iterator, |
168 | void *iterator_cls) | 169 | void *iterator_cls) |
169 | { | 170 | { |
170 | struct GNUNET_FS_GetIndexedContext *gic | 171 | struct GNUNET_FS_GetIndexedContext *gic |
171 | = GNUNET_new(struct GNUNET_FS_GetIndexedContext); | 172 | = GNUNET_new (struct GNUNET_FS_GetIndexedContext); |
172 | struct GNUNET_MQ_MessageHandler handlers[] = { | 173 | struct GNUNET_MQ_MessageHandler handlers[] = { |
173 | GNUNET_MQ_hd_fixed_size(index_info_end, | 174 | GNUNET_MQ_hd_fixed_size (index_info_end, |
174 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END, | 175 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END, |
175 | struct GNUNET_MessageHeader, | 176 | struct GNUNET_MessageHeader, |
176 | gic), | 177 | gic), |
177 | GNUNET_MQ_hd_var_size(index_info, | 178 | GNUNET_MQ_hd_var_size (index_info, |
178 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY, | 179 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY, |
179 | struct IndexInfoMessage, | 180 | struct IndexInfoMessage, |
180 | gic), | 181 | gic), |
181 | GNUNET_MQ_handler_end() | 182 | GNUNET_MQ_handler_end () |
182 | }; | 183 | }; |
183 | struct GNUNET_MQ_Envelope *env; | 184 | struct GNUNET_MQ_Envelope *env; |
184 | struct GNUNET_MessageHeader *msg; | 185 | struct GNUNET_MessageHeader *msg; |
185 | 186 | ||
186 | gic->mq = GNUNET_CLIENT_connect(h->cfg, | 187 | gic->mq = GNUNET_CLIENT_connect (h->cfg, |
187 | "fs", | 188 | "fs", |
188 | handlers, | 189 | handlers, |
189 | &mq_error_handler, | 190 | &mq_error_handler, |
190 | h); | 191 | h); |
191 | if (NULL == gic->mq) | 192 | if (NULL == gic->mq) |
192 | { | 193 | { |
193 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 194 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
194 | _("Failed to not connect to `%s' service.\n"), | 195 | _ ("Failed to not connect to `%s' service.\n"), |
195 | "fs"); | 196 | "fs"); |
196 | GNUNET_free(gic); | 197 | GNUNET_free (gic); |
197 | return NULL; | 198 | return NULL; |
198 | } | 199 | } |
199 | gic->iterator = iterator; | 200 | gic->iterator = iterator; |
200 | gic->iterator_cls = iterator_cls; | 201 | gic->iterator_cls = iterator_cls; |
201 | env = GNUNET_MQ_msg(msg, | 202 | env = GNUNET_MQ_msg (msg, |
202 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET); | 203 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET); |
203 | GNUNET_MQ_send(gic->mq, | 204 | GNUNET_MQ_send (gic->mq, |
204 | env); | 205 | env); |
205 | return gic; | 206 | return gic; |
206 | } | 207 | } |
207 | 208 | ||
@@ -212,10 +213,10 @@ GNUNET_FS_get_indexed_files(struct GNUNET_FS_Handle *h, | |||
212 | * @param gic operation to cancel | 213 | * @param gic operation to cancel |
213 | */ | 214 | */ |
214 | void | 215 | void |
215 | GNUNET_FS_get_indexed_files_cancel(struct GNUNET_FS_GetIndexedContext *gic) | 216 | GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic) |
216 | { | 217 | { |
217 | GNUNET_MQ_destroy(gic->mq); | 218 | GNUNET_MQ_destroy (gic->mq); |
218 | GNUNET_free(gic); | 219 | GNUNET_free (gic); |
219 | } | 220 | } |
220 | 221 | ||
221 | 222 | ||
diff --git a/src/fs/fs_misc.c b/src/fs/fs_misc.c index 79f082626..2e7816d65 100644 --- a/src/fs/fs_misc.c +++ b/src/fs/fs_misc.c | |||
@@ -35,8 +35,8 @@ | |||
35 | * @return NULL if meta data is useless for suggesting a filename | 35 | * @return NULL if meta data is useless for suggesting a filename |
36 | */ | 36 | */ |
37 | char * | 37 | char * |
38 | GNUNET_FS_meta_data_suggest_filename(const struct GNUNET_CONTAINER_MetaData | 38 | GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData |
39 | *md) | 39 | *md) |
40 | { | 40 | { |
41 | static const char *mimeMap[][2] = { | 41 | static const char *mimeMap[][2] = { |
42 | { "application/bz2", ".bz2" }, | 42 | { "application/bz2", ".bz2" }, |
@@ -111,52 +111,52 @@ GNUNET_FS_meta_data_suggest_filename(const struct GNUNET_CONTAINER_MetaData | |||
111 | const char *ext; | 111 | const char *ext; |
112 | 112 | ||
113 | ret = | 113 | ret = |
114 | GNUNET_CONTAINER_meta_data_get_by_type(md, | 114 | GNUNET_CONTAINER_meta_data_get_by_type (md, |
115 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 115 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
116 | if (ret != NULL) | 116 | if (ret != NULL) |
117 | return ret; | 117 | return ret; |
118 | ext = NULL; | 118 | ext = NULL; |
119 | mime = | 119 | mime = |
120 | GNUNET_CONTAINER_meta_data_get_by_type(md, EXTRACTOR_METATYPE_MIMETYPE); | 120 | GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE); |
121 | if (mime != NULL) | 121 | if (mime != NULL) |
122 | { | 122 | { |
123 | i = 0; | 123 | i = 0; |
124 | while ((mimeMap[i][0] != NULL) && (0 != strcmp(mime, mimeMap[i][0]))) | 124 | while ((mimeMap[i][0] != NULL) && (0 != strcmp (mime, mimeMap[i][0]))) |
125 | i++; | 125 | i++; |
126 | if (mimeMap[i][1] == NULL) | 126 | if (mimeMap[i][1] == NULL) |
127 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
128 | _("Did not find mime type `%s' in extension list.\n"), mime); | 128 | _ ("Did not find mime type `%s' in extension list.\n"), mime); |
129 | else | 129 | else |
130 | ext = mimeMap[i][1]; | 130 | ext = mimeMap[i][1]; |
131 | GNUNET_free(mime); | 131 | GNUNET_free (mime); |
132 | } | 132 | } |
133 | base = | 133 | base = |
134 | GNUNET_CONTAINER_meta_data_get_first_by_types(md, | 134 | GNUNET_CONTAINER_meta_data_get_first_by_types (md, |
135 | EXTRACTOR_METATYPE_TITLE, | 135 | EXTRACTOR_METATYPE_TITLE, |
136 | EXTRACTOR_METATYPE_BOOK_TITLE, | 136 | EXTRACTOR_METATYPE_BOOK_TITLE, |
137 | EXTRACTOR_METATYPE_ORIGINAL_TITLE, | 137 | EXTRACTOR_METATYPE_ORIGINAL_TITLE, |
138 | EXTRACTOR_METATYPE_PACKAGE_NAME, | 138 | EXTRACTOR_METATYPE_PACKAGE_NAME, |
139 | EXTRACTOR_METATYPE_URL, | 139 | EXTRACTOR_METATYPE_URL, |
140 | EXTRACTOR_METATYPE_URI, | 140 | EXTRACTOR_METATYPE_URI, |
141 | EXTRACTOR_METATYPE_DESCRIPTION, | 141 | EXTRACTOR_METATYPE_DESCRIPTION, |
142 | EXTRACTOR_METATYPE_ISRC, | 142 | EXTRACTOR_METATYPE_ISRC, |
143 | EXTRACTOR_METATYPE_JOURNAL_NAME, | 143 | EXTRACTOR_METATYPE_JOURNAL_NAME, |
144 | EXTRACTOR_METATYPE_AUTHOR_NAME, | 144 | EXTRACTOR_METATYPE_AUTHOR_NAME, |
145 | EXTRACTOR_METATYPE_SUBJECT, | 145 | EXTRACTOR_METATYPE_SUBJECT, |
146 | EXTRACTOR_METATYPE_ALBUM, | 146 | EXTRACTOR_METATYPE_ALBUM, |
147 | EXTRACTOR_METATYPE_ARTIST, | 147 | EXTRACTOR_METATYPE_ARTIST, |
148 | EXTRACTOR_METATYPE_KEYWORDS, | 148 | EXTRACTOR_METATYPE_KEYWORDS, |
149 | EXTRACTOR_METATYPE_COMMENT, | 149 | EXTRACTOR_METATYPE_COMMENT, |
150 | EXTRACTOR_METATYPE_UNKNOWN, | 150 | EXTRACTOR_METATYPE_UNKNOWN, |
151 | -1); | 151 | -1); |
152 | if ((base == NULL) && (ext == NULL)) | 152 | if ((base == NULL) && (ext == NULL)) |
153 | return NULL; | 153 | return NULL; |
154 | if (base == NULL) | 154 | if (base == NULL) |
155 | return GNUNET_strdup(ext); | 155 | return GNUNET_strdup (ext); |
156 | if (ext == NULL) | 156 | if (ext == NULL) |
157 | return base; | 157 | return base; |
158 | GNUNET_asprintf(&ret, "%s%s", base, ext); | 158 | GNUNET_asprintf (&ret, "%s%s", base, ext); |
159 | GNUNET_free(base); | 159 | GNUNET_free (base); |
160 | return ret; | 160 | return ret; |
161 | } | 161 | } |
162 | 162 | ||
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c index b740eb2ba..6ede02afd 100644 --- a/src/fs/fs_namespace.c +++ b/src/fs/fs_namespace.c | |||
@@ -37,7 +37,8 @@ | |||
37 | * Information about an (updateable) node in the | 37 | * Information about an (updateable) node in the |
38 | * namespace. | 38 | * namespace. |
39 | */ | 39 | */ |
40 | struct NamespaceUpdateNode { | 40 | struct NamespaceUpdateNode |
41 | { | ||
41 | /** | 42 | /** |
42 | * Identifier for this node. | 43 | * Identifier for this node. |
43 | */ | 44 | */ |
@@ -74,7 +75,8 @@ struct NamespaceUpdateNode { | |||
74 | /** | 75 | /** |
75 | * Handle to update information for a namespace. | 76 | * Handle to update information for a namespace. |
76 | */ | 77 | */ |
77 | struct GNUNET_FS_UpdateInformationGraph { | 78 | struct GNUNET_FS_UpdateInformationGraph |
79 | { | ||
78 | /** | 80 | /** |
79 | * Handle to the FS service context. | 81 | * Handle to the FS service context. |
80 | */ | 82 | */ |
@@ -122,7 +124,7 @@ struct GNUNET_FS_UpdateInformationGraph { | |||
122 | * @return NULL on error, otherwise the name of the directory | 124 | * @return NULL on error, otherwise the name of the directory |
123 | */ | 125 | */ |
124 | static char * | 126 | static char * |
125 | get_update_information_directory( | 127 | get_update_information_directory ( |
126 | struct GNUNET_FS_Handle *h, | 128 | struct GNUNET_FS_Handle *h, |
127 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) | 129 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) |
128 | { | 130 | { |
@@ -133,20 +135,20 @@ get_update_information_directory( | |||
133 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | 135 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; |
134 | 136 | ||
135 | if (GNUNET_OK != | 137 | if (GNUNET_OK != |
136 | GNUNET_CONFIGURATION_get_value_filename(h->cfg, "FS", "UPDATE_DIR", &dn)) | 138 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", &dn)) |
137 | { | 139 | { |
138 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR"); | 140 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR"); |
139 | return NULL; | 141 | return NULL; |
140 | } | 142 | } |
141 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, &pub); | 143 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &pub); |
142 | GNUNET_CRYPTO_hash(&pub, sizeof(pub), &hc); | 144 | GNUNET_CRYPTO_hash (&pub, sizeof(pub), &hc); |
143 | GNUNET_CRYPTO_hash_to_enc(&hc, &enc); | 145 | GNUNET_CRYPTO_hash_to_enc (&hc, &enc); |
144 | GNUNET_asprintf(&ret, | 146 | GNUNET_asprintf (&ret, |
145 | "%s%s%s", | 147 | "%s%s%s", |
146 | dn, | 148 | dn, |
147 | DIR_SEPARATOR_STR, | 149 | DIR_SEPARATOR_STR, |
148 | (const char *)enc.encoding); | 150 | (const char *) enc.encoding); |
149 | GNUNET_free(dn); | 151 | GNUNET_free (dn); |
150 | return ret; | 152 | return ret; |
151 | } | 153 | } |
152 | 154 | ||
@@ -157,24 +159,24 @@ get_update_information_directory( | |||
157 | * @param uig data structure to free | 159 | * @param uig data structure to free |
158 | */ | 160 | */ |
159 | static void | 161 | static void |
160 | free_update_information_graph(struct GNUNET_FS_UpdateInformationGraph *uig) | 162 | free_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) |
161 | { | 163 | { |
162 | unsigned int i; | 164 | unsigned int i; |
163 | struct NamespaceUpdateNode *nsn; | 165 | struct NamespaceUpdateNode *nsn; |
164 | 166 | ||
165 | for (i = 0; i < uig->update_node_count; i++) | 167 | for (i = 0; i < uig->update_node_count; i++) |
166 | { | 168 | { |
167 | nsn = uig->update_nodes[i]; | 169 | nsn = uig->update_nodes[i]; |
168 | GNUNET_CONTAINER_meta_data_destroy(nsn->md); | 170 | GNUNET_CONTAINER_meta_data_destroy (nsn->md); |
169 | GNUNET_FS_uri_destroy(nsn->uri); | 171 | GNUNET_FS_uri_destroy (nsn->uri); |
170 | GNUNET_free(nsn->id); | 172 | GNUNET_free (nsn->id); |
171 | GNUNET_free(nsn->update); | 173 | GNUNET_free (nsn->update); |
172 | GNUNET_free(nsn); | 174 | GNUNET_free (nsn); |
173 | } | 175 | } |
174 | GNUNET_array_grow(uig->update_nodes, uig->update_node_count, 0); | 176 | GNUNET_array_grow (uig->update_nodes, uig->update_node_count, 0); |
175 | if (NULL != uig->update_map) | 177 | if (NULL != uig->update_map) |
176 | GNUNET_CONTAINER_multihashmap_destroy(uig->update_map); | 178 | GNUNET_CONTAINER_multihashmap_destroy (uig->update_map); |
177 | GNUNET_free(uig); | 179 | GNUNET_free (uig); |
178 | } | 180 | } |
179 | 181 | ||
180 | 182 | ||
@@ -184,7 +186,7 @@ free_update_information_graph(struct GNUNET_FS_UpdateInformationGraph *uig) | |||
184 | * @param uig update information graph to dump | 186 | * @param uig update information graph to dump |
185 | */ | 187 | */ |
186 | static void | 188 | static void |
187 | write_update_information_graph(struct GNUNET_FS_UpdateInformationGraph *uig) | 189 | write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) |
188 | { | 190 | { |
189 | char *fn; | 191 | char *fn; |
190 | struct GNUNET_BIO_WriteHandle *wh; | 192 | struct GNUNET_BIO_WriteHandle *wh; |
@@ -192,40 +194,40 @@ write_update_information_graph(struct GNUNET_FS_UpdateInformationGraph *uig) | |||
192 | struct NamespaceUpdateNode *n; | 194 | struct NamespaceUpdateNode *n; |
193 | char *uris; | 195 | char *uris; |
194 | 196 | ||
195 | fn = get_update_information_directory(uig->h, &uig->ns); | 197 | fn = get_update_information_directory (uig->h, &uig->ns); |
196 | wh = GNUNET_BIO_write_open(fn); | 198 | wh = GNUNET_BIO_write_open (fn); |
197 | if (NULL == wh) | 199 | if (NULL == wh) |
198 | { | 200 | { |
199 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 201 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
200 | _("Failed to open `%s' for writing: %s\n"), | 202 | _ ("Failed to open `%s' for writing: %s\n"), |
201 | fn, | 203 | fn, |
202 | strerror(errno)); | 204 | strerror (errno)); |
203 | GNUNET_free(fn); | 205 | GNUNET_free (fn); |
204 | return; | 206 | return; |
205 | } | 207 | } |
206 | if (GNUNET_OK != GNUNET_BIO_write_int32(wh, uig->update_node_count)) | 208 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, uig->update_node_count)) |
207 | goto END; | 209 | goto END; |
208 | for (i = 0; i < uig->update_node_count; i++) | 210 | for (i = 0; i < uig->update_node_count; i++) |
211 | { | ||
212 | n = uig->update_nodes[i]; | ||
213 | uris = GNUNET_FS_uri_to_string (n->uri); | ||
214 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, n->id)) || | ||
215 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, n->md)) || | ||
216 | (GNUNET_OK != GNUNET_BIO_write_string (wh, n->update)) || | ||
217 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris))) | ||
209 | { | 218 | { |
210 | n = uig->update_nodes[i]; | 219 | GNUNET_free (uris); |
211 | uris = GNUNET_FS_uri_to_string(n->uri); | 220 | break; |
212 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, n->id)) || | ||
213 | (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, n->md)) || | ||
214 | (GNUNET_OK != GNUNET_BIO_write_string(wh, n->update)) || | ||
215 | (GNUNET_OK != GNUNET_BIO_write_string(wh, uris))) | ||
216 | { | ||
217 | GNUNET_free(uris); | ||
218 | break; | ||
219 | } | ||
220 | GNUNET_free(uris); | ||
221 | } | 221 | } |
222 | GNUNET_free (uris); | ||
223 | } | ||
222 | END: | 224 | END: |
223 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) | 225 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) |
224 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 226 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
225 | _("Failed to write `%s': %s\n"), | 227 | _ ("Failed to write `%s': %s\n"), |
226 | fn, | 228 | fn, |
227 | strerror(errno)); | 229 | strerror (errno)); |
228 | GNUNET_free(fn); | 230 | GNUNET_free (fn); |
229 | } | 231 | } |
230 | 232 | ||
231 | 233 | ||
@@ -237,8 +239,8 @@ END: | |||
237 | * @return update graph, never NULL | 239 | * @return update graph, never NULL |
238 | */ | 240 | */ |
239 | static struct GNUNET_FS_UpdateInformationGraph * | 241 | static struct GNUNET_FS_UpdateInformationGraph * |
240 | read_update_information_graph(struct GNUNET_FS_Handle *h, | 242 | read_update_information_graph (struct GNUNET_FS_Handle *h, |
241 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) | 243 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) |
242 | { | 244 | { |
243 | struct GNUNET_FS_UpdateInformationGraph *uig; | 245 | struct GNUNET_FS_UpdateInformationGraph *uig; |
244 | char *fn; | 246 | char *fn; |
@@ -249,79 +251,79 @@ read_update_information_graph(struct GNUNET_FS_Handle *h, | |||
249 | uint32_t count; | 251 | uint32_t count; |
250 | char *emsg; | 252 | char *emsg; |
251 | 253 | ||
252 | uig = GNUNET_new(struct GNUNET_FS_UpdateInformationGraph); | 254 | uig = GNUNET_new (struct GNUNET_FS_UpdateInformationGraph); |
253 | uig->h = h; | 255 | uig->h = h; |
254 | uig->ns = *ns; | 256 | uig->ns = *ns; |
255 | fn = get_update_information_directory(h, ns); | 257 | fn = get_update_information_directory (h, ns); |
256 | if (GNUNET_YES != GNUNET_DISK_file_test(fn)) | 258 | if (GNUNET_YES != GNUNET_DISK_file_test (fn)) |
257 | { | 259 | { |
258 | GNUNET_free(fn); | 260 | GNUNET_free (fn); |
259 | return uig; | 261 | return uig; |
260 | } | 262 | } |
261 | rh = GNUNET_BIO_read_open(fn); | 263 | rh = GNUNET_BIO_read_open (fn); |
262 | if (NULL == rh) | 264 | if (NULL == rh) |
263 | { | 265 | { |
264 | GNUNET_free(fn); | 266 | GNUNET_free (fn); |
265 | return uig; | 267 | return uig; |
266 | } | 268 | } |
267 | if (GNUNET_OK != GNUNET_BIO_read_int32(rh, &count)) | 269 | if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &count)) |
268 | { | 270 | { |
269 | GNUNET_break(0); | 271 | GNUNET_break (0); |
270 | goto END; | 272 | goto END; |
271 | } | 273 | } |
272 | if (count > 1024 * 1024) | 274 | if (count > 1024 * 1024) |
273 | { | 275 | { |
274 | GNUNET_break(0); | 276 | GNUNET_break (0); |
275 | goto END; | 277 | goto END; |
276 | } | 278 | } |
277 | if (0 == count) | 279 | if (0 == count) |
278 | goto END; | 280 | goto END; |
279 | uig->update_nodes = | 281 | uig->update_nodes = |
280 | GNUNET_malloc(count * sizeof(struct NamespaceUpdateNode *)); | 282 | GNUNET_malloc (count * sizeof(struct NamespaceUpdateNode *)); |
281 | 283 | ||
282 | for (i = 0; i < count; i++) | 284 | for (i = 0; i < count; i++) |
285 | { | ||
286 | n = GNUNET_new (struct NamespaceUpdateNode); | ||
287 | if ((GNUNET_OK != | ||
288 | GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) || | ||
289 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || | ||
290 | (GNUNET_OK != | ||
291 | GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || | ||
292 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2))) | ||
283 | { | 293 | { |
284 | n = GNUNET_new(struct NamespaceUpdateNode); | 294 | GNUNET_break (0); |
285 | if ((GNUNET_OK != | 295 | GNUNET_free_non_null (n->id); |
286 | GNUNET_BIO_read_string(rh, "identifier", &n->id, 1024)) || | 296 | GNUNET_free_non_null (n->update); |
287 | (GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "meta", &n->md)) || | 297 | if (n->md != NULL) |
288 | (GNUNET_OK != | 298 | GNUNET_CONTAINER_meta_data_destroy (n->md); |
289 | GNUNET_BIO_read_string(rh, "update-id", &n->update, 1024)) || | 299 | GNUNET_free (n); |
290 | (GNUNET_OK != GNUNET_BIO_read_string(rh, "uri", &uris, 1024 * 2))) | 300 | break; |
291 | { | ||
292 | GNUNET_break(0); | ||
293 | GNUNET_free_non_null(n->id); | ||
294 | GNUNET_free_non_null(n->update); | ||
295 | if (n->md != NULL) | ||
296 | GNUNET_CONTAINER_meta_data_destroy(n->md); | ||
297 | GNUNET_free(n); | ||
298 | break; | ||
299 | } | ||
300 | n->uri = GNUNET_FS_uri_parse(uris, &emsg); | ||
301 | GNUNET_free(uris); | ||
302 | if (n->uri == NULL) | ||
303 | { | ||
304 | GNUNET_break(0); | ||
305 | GNUNET_free(emsg); | ||
306 | GNUNET_free(n->id); | ||
307 | GNUNET_free_non_null(n->update); | ||
308 | GNUNET_CONTAINER_meta_data_destroy(n->md); | ||
309 | GNUNET_free(n); | ||
310 | break; | ||
311 | } | ||
312 | uig->update_nodes[i] = n; | ||
313 | } | 301 | } |
314 | uig->update_node_count = i; | 302 | n->uri = GNUNET_FS_uri_parse (uris, &emsg); |
315 | END: | 303 | GNUNET_free (uris); |
316 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) | 304 | if (n->uri == NULL) |
317 | { | 305 | { |
318 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 306 | GNUNET_break (0); |
319 | _("Failed to read `%s': %s\n"), | 307 | GNUNET_free (emsg); |
320 | fn, | 308 | GNUNET_free (n->id); |
321 | emsg); | 309 | GNUNET_free_non_null (n->update); |
322 | GNUNET_free(emsg); | 310 | GNUNET_CONTAINER_meta_data_destroy (n->md); |
311 | GNUNET_free (n); | ||
312 | break; | ||
323 | } | 313 | } |
324 | GNUNET_free(fn); | 314 | uig->update_nodes[i] = n; |
315 | } | ||
316 | uig->update_node_count = i; | ||
317 | END: | ||
318 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | ||
319 | { | ||
320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
321 | _ ("Failed to read `%s': %s\n"), | ||
322 | fn, | ||
323 | emsg); | ||
324 | GNUNET_free (emsg); | ||
325 | } | ||
326 | GNUNET_free (fn); | ||
325 | return uig; | 327 | return uig; |
326 | } | 328 | } |
327 | 329 | ||
@@ -329,7 +331,8 @@ END: | |||
329 | /** | 331 | /** |
330 | * Context for the SKS publication. | 332 | * Context for the SKS publication. |
331 | */ | 333 | */ |
332 | struct GNUNET_FS_PublishSksContext { | 334 | struct GNUNET_FS_PublishSksContext |
335 | { | ||
333 | /** | 336 | /** |
334 | * URI of the new entry in the namespace. | 337 | * URI of the new entry in the namespace. |
335 | */ | 338 | */ |
@@ -381,33 +384,33 @@ struct GNUNET_FS_PublishSksContext { | |||
381 | * @param msg error message (or NULL) | 384 | * @param msg error message (or NULL) |
382 | */ | 385 | */ |
383 | static void | 386 | static void |
384 | sks_publish_cont(void *cls, const char *msg) | 387 | sks_publish_cont (void *cls, const char *msg) |
385 | { | 388 | { |
386 | struct GNUNET_FS_PublishSksContext *psc = cls; | 389 | struct GNUNET_FS_PublishSksContext *psc = cls; |
387 | struct GNUNET_FS_UpdateInformationGraph *uig; | 390 | struct GNUNET_FS_UpdateInformationGraph *uig; |
388 | 391 | ||
389 | psc->uc = NULL; | 392 | psc->uc = NULL; |
390 | if (NULL != msg) | 393 | if (NULL != msg) |
391 | { | 394 | { |
392 | if (NULL != psc->cont) | 395 | if (NULL != psc->cont) |
393 | psc->cont(psc->cont_cls, NULL, msg); | 396 | psc->cont (psc->cont_cls, NULL, msg); |
394 | GNUNET_FS_publish_sks_cancel(psc); | 397 | GNUNET_FS_publish_sks_cancel (psc); |
395 | return; | 398 | return; |
396 | } | 399 | } |
397 | if (NULL != psc->nsn) | 400 | if (NULL != psc->nsn) |
398 | { | 401 | { |
399 | /* FIXME: this can be done much more | 402 | /* FIXME: this can be done much more |
400 | * efficiently by simply appending to the | 403 | * efficiently by simply appending to the |
401 | * file and overwriting the 4-byte header */ | 404 | * file and overwriting the 4-byte header */ |
402 | uig = read_update_information_graph(psc->h, &psc->ns); | 405 | uig = read_update_information_graph (psc->h, &psc->ns); |
403 | GNUNET_array_append(uig->update_nodes, uig->update_node_count, psc->nsn); | 406 | GNUNET_array_append (uig->update_nodes, uig->update_node_count, psc->nsn); |
404 | psc->nsn = NULL; | 407 | psc->nsn = NULL; |
405 | write_update_information_graph(uig); | 408 | write_update_information_graph (uig); |
406 | free_update_information_graph(uig); | 409 | free_update_information_graph (uig); |
407 | } | 410 | } |
408 | if (NULL != psc->cont) | 411 | if (NULL != psc->cont) |
409 | psc->cont(psc->cont_cls, psc->uri, NULL); | 412 | psc->cont (psc->cont_cls, psc->uri, NULL); |
410 | GNUNET_FS_publish_sks_cancel(psc); | 413 | GNUNET_FS_publish_sks_cancel (psc); |
411 | } | 414 | } |
412 | 415 | ||
413 | 416 | ||
@@ -427,59 +430,59 @@ sks_publish_cont(void *cls, const char *msg) | |||
427 | * @return NULL on error ('cont' will still be called) | 430 | * @return NULL on error ('cont' will still be called) |
428 | */ | 431 | */ |
429 | struct GNUNET_FS_PublishSksContext * | 432 | struct GNUNET_FS_PublishSksContext * |
430 | GNUNET_FS_publish_sks(struct GNUNET_FS_Handle *h, | 433 | GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, |
431 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 434 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
432 | const char *identifier, | 435 | const char *identifier, |
433 | const char *update, | 436 | const char *update, |
434 | const struct GNUNET_CONTAINER_MetaData *meta, | 437 | const struct GNUNET_CONTAINER_MetaData *meta, |
435 | const struct GNUNET_FS_Uri *uri, | 438 | const struct GNUNET_FS_Uri *uri, |
436 | const struct GNUNET_FS_BlockOptions *bo, | 439 | const struct GNUNET_FS_BlockOptions *bo, |
437 | enum GNUNET_FS_PublishOptions options, | 440 | enum GNUNET_FS_PublishOptions options, |
438 | GNUNET_FS_PublishContinuation cont, | 441 | GNUNET_FS_PublishContinuation cont, |
439 | void *cont_cls) | 442 | void *cont_cls) |
440 | { | 443 | { |
441 | struct GNUNET_FS_PublishSksContext *psc; | 444 | struct GNUNET_FS_PublishSksContext *psc; |
442 | struct GNUNET_FS_Uri *sks_uri; | 445 | struct GNUNET_FS_Uri *sks_uri; |
443 | 446 | ||
444 | sks_uri = GNUNET_new(struct GNUNET_FS_Uri); | 447 | sks_uri = GNUNET_new (struct GNUNET_FS_Uri); |
445 | sks_uri->type = GNUNET_FS_URI_SKS; | 448 | sks_uri->type = GNUNET_FS_URI_SKS; |
446 | sks_uri->data.sks.identifier = GNUNET_strdup(identifier); | 449 | sks_uri->data.sks.identifier = GNUNET_strdup (identifier); |
447 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, &sks_uri->data.sks.ns); | 450 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &sks_uri->data.sks.ns); |
448 | 451 | ||
449 | psc = GNUNET_new(struct GNUNET_FS_PublishSksContext); | 452 | psc = GNUNET_new (struct GNUNET_FS_PublishSksContext); |
450 | psc->h = h; | 453 | psc->h = h; |
451 | psc->uri = sks_uri; | 454 | psc->uri = sks_uri; |
452 | psc->cont = cont; | 455 | psc->cont = cont; |
453 | psc->cont_cls = cont_cls; | 456 | psc->cont_cls = cont_cls; |
454 | psc->ns = *ns; | 457 | psc->ns = *ns; |
455 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | 458 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) |
459 | { | ||
460 | psc->dsh = GNUNET_DATASTORE_connect (h->cfg); | ||
461 | if (NULL == psc->dsh) | ||
456 | { | 462 | { |
457 | psc->dsh = GNUNET_DATASTORE_connect(h->cfg); | 463 | sks_publish_cont (psc, _ ("Failed to connect to datastore.")); |
458 | if (NULL == psc->dsh) | 464 | return NULL; |
459 | { | ||
460 | sks_publish_cont(psc, _("Failed to connect to datastore.")); | ||
461 | return NULL; | ||
462 | } | ||
463 | } | 465 | } |
466 | } | ||
464 | if (NULL != update) | 467 | if (NULL != update) |
465 | { | 468 | { |
466 | psc->nsn = GNUNET_new(struct NamespaceUpdateNode); | 469 | psc->nsn = GNUNET_new (struct NamespaceUpdateNode); |
467 | psc->nsn->id = GNUNET_strdup(identifier); | 470 | psc->nsn->id = GNUNET_strdup (identifier); |
468 | psc->nsn->update = GNUNET_strdup(update); | 471 | psc->nsn->update = GNUNET_strdup (update); |
469 | psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate(meta); | 472 | psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta); |
470 | psc->nsn->uri = GNUNET_FS_uri_dup(uri); | 473 | psc->nsn->uri = GNUNET_FS_uri_dup (uri); |
471 | } | 474 | } |
472 | psc->uc = GNUNET_FS_publish_ublock_(h, | 475 | psc->uc = GNUNET_FS_publish_ublock_ (h, |
473 | psc->dsh, | 476 | psc->dsh, |
474 | identifier, | 477 | identifier, |
475 | update, | 478 | update, |
476 | ns, | 479 | ns, |
477 | meta, | 480 | meta, |
478 | uri, | 481 | uri, |
479 | bo, | 482 | bo, |
480 | options, | 483 | options, |
481 | &sks_publish_cont, | 484 | &sks_publish_cont, |
482 | psc); | 485 | psc); |
483 | return psc; | 486 | return psc; |
484 | } | 487 | } |
485 | 488 | ||
@@ -490,35 +493,36 @@ GNUNET_FS_publish_sks(struct GNUNET_FS_Handle *h, | |||
490 | * @param psc context of the operation to abort. | 493 | * @param psc context of the operation to abort. |
491 | */ | 494 | */ |
492 | void | 495 | void |
493 | GNUNET_FS_publish_sks_cancel(struct GNUNET_FS_PublishSksContext *psc) | 496 | GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc) |
494 | { | 497 | { |
495 | if (NULL != psc->uc) | 498 | if (NULL != psc->uc) |
496 | { | 499 | { |
497 | GNUNET_FS_publish_ublock_cancel_(psc->uc); | 500 | GNUNET_FS_publish_ublock_cancel_ (psc->uc); |
498 | psc->uc = NULL; | 501 | psc->uc = NULL; |
499 | } | 502 | } |
500 | if (NULL != psc->dsh) | 503 | if (NULL != psc->dsh) |
501 | { | 504 | { |
502 | GNUNET_DATASTORE_disconnect(psc->dsh, GNUNET_NO); | 505 | GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO); |
503 | psc->dsh = NULL; | 506 | psc->dsh = NULL; |
504 | } | 507 | } |
505 | GNUNET_FS_uri_destroy(psc->uri); | 508 | GNUNET_FS_uri_destroy (psc->uri); |
506 | if (NULL != psc->nsn) | 509 | if (NULL != psc->nsn) |
507 | { | 510 | { |
508 | GNUNET_CONTAINER_meta_data_destroy(psc->nsn->md); | 511 | GNUNET_CONTAINER_meta_data_destroy (psc->nsn->md); |
509 | GNUNET_FS_uri_destroy(psc->nsn->uri); | 512 | GNUNET_FS_uri_destroy (psc->nsn->uri); |
510 | GNUNET_free(psc->nsn->id); | 513 | GNUNET_free (psc->nsn->id); |
511 | GNUNET_free(psc->nsn->update); | 514 | GNUNET_free (psc->nsn->update); |
512 | GNUNET_free(psc->nsn); | 515 | GNUNET_free (psc->nsn); |
513 | } | 516 | } |
514 | GNUNET_free(psc); | 517 | GNUNET_free (psc); |
515 | } | 518 | } |
516 | 519 | ||
517 | 520 | ||
518 | /** | 521 | /** |
519 | * Closure for 'process_update_node'. | 522 | * Closure for 'process_update_node'. |
520 | */ | 523 | */ |
521 | struct ProcessUpdateClosure { | 524 | struct ProcessUpdateClosure |
525 | { | ||
522 | /** | 526 | /** |
523 | * Function to call for each node. | 527 | * Function to call for each node. |
524 | */ | 528 | */ |
@@ -542,12 +546,12 @@ struct ProcessUpdateClosure { | |||
542 | * GNUNET_NO if not. | 546 | * GNUNET_NO if not. |
543 | */ | 547 | */ |
544 | static int | 548 | static int |
545 | process_update_node(void *cls, const struct GNUNET_HashCode *key, void *value) | 549 | process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value) |
546 | { | 550 | { |
547 | struct ProcessUpdateClosure *pc = cls; | 551 | struct ProcessUpdateClosure *pc = cls; |
548 | struct NamespaceUpdateNode *nsn = value; | 552 | struct NamespaceUpdateNode *nsn = value; |
549 | 553 | ||
550 | pc->ip(pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); | 554 | pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); |
551 | return GNUNET_YES; | 555 | return GNUNET_YES; |
552 | } | 556 | } |
553 | 557 | ||
@@ -555,7 +559,8 @@ process_update_node(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
555 | /** | 559 | /** |
556 | * Closure for 'find_trees'. | 560 | * Closure for 'find_trees'. |
557 | */ | 561 | */ |
558 | struct FindTreeClosure { | 562 | struct FindTreeClosure |
563 | { | ||
559 | /** | 564 | /** |
560 | * UIG we are operating on. | 565 | * UIG we are operating on. |
561 | */ | 566 | */ |
@@ -604,38 +609,38 @@ struct FindTreeClosure { | |||
604 | * GNUNET_NO if not. | 609 | * GNUNET_NO if not. |
605 | */ | 610 | */ |
606 | static int | 611 | static int |
607 | find_trees(void *cls, const struct GNUNET_HashCode *key, void *value) | 612 | find_trees (void *cls, const struct GNUNET_HashCode *key, void *value) |
608 | { | 613 | { |
609 | struct FindTreeClosure *fc = cls; | 614 | struct FindTreeClosure *fc = cls; |
610 | struct NamespaceUpdateNode *nsn = value; | 615 | struct NamespaceUpdateNode *nsn = value; |
611 | struct GNUNET_HashCode hc; | 616 | struct GNUNET_HashCode hc; |
612 | 617 | ||
613 | if (nsn->nug == fc->nug) | 618 | if (nsn->nug == fc->nug) |
614 | { | 619 | { |
615 | if (UINT_MAX == nsn->tree_id) | 620 | if (UINT_MAX == nsn->tree_id) |
616 | return GNUNET_YES; /* circular */ | 621 | return GNUNET_YES; /* circular */ |
617 | GNUNET_assert(nsn->tree_id < fc->tree_array_size); | 622 | GNUNET_assert (nsn->tree_id < fc->tree_array_size); |
618 | if (fc->tree_array[nsn->tree_id] != nsn) | 623 | if (fc->tree_array[nsn->tree_id] != nsn) |
619 | return GNUNET_YES; /* part of "another" (directed) TREE, | 624 | return GNUNET_YES; /* part of "another" (directed) TREE, |
620 | * and not root of it, end trace */ | 625 | * and not root of it, end trace */ |
621 | if (nsn->tree_id == fc->id) | 626 | if (nsn->tree_id == fc->id) |
622 | return GNUNET_YES; /* that's our own root (can this be?) */ | 627 | return GNUNET_YES; /* that's our own root (can this be?) */ |
623 | /* merge existing TREE, we have a root for both */ | 628 | /* merge existing TREE, we have a root for both */ |
624 | fc->tree_array[nsn->tree_id] = NULL; | 629 | fc->tree_array[nsn->tree_id] = NULL; |
625 | if (UINT_MAX == fc->id) | 630 | if (UINT_MAX == fc->id) |
626 | fc->id = nsn->tree_id; /* take over ID */ | 631 | fc->id = nsn->tree_id; /* take over ID */ |
627 | } | 632 | } |
628 | else | 633 | else |
629 | { | 634 | { |
630 | nsn->nug = fc->nug; | 635 | nsn->nug = fc->nug; |
631 | nsn->tree_id = UINT_MAX; /* mark as undef */ | 636 | nsn->tree_id = UINT_MAX; /* mark as undef */ |
632 | /* trace */ | 637 | /* trace */ |
633 | GNUNET_CRYPTO_hash(nsn->update, strlen(nsn->update), &hc); | 638 | GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); |
634 | GNUNET_CONTAINER_multihashmap_get_multiple(fc->uig->update_map, | 639 | GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map, |
635 | &hc, | 640 | &hc, |
636 | &find_trees, | 641 | &find_trees, |
637 | fc); | 642 | fc); |
638 | } | 643 | } |
639 | return GNUNET_YES; | 644 | return GNUNET_YES; |
640 | } | 645 | } |
641 | 646 | ||
@@ -664,7 +669,7 @@ find_trees(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
664 | * @param ip_cls closure for ip | 669 | * @param ip_cls closure for ip |
665 | */ | 670 | */ |
666 | void | 671 | void |
667 | GNUNET_FS_namespace_list_updateable( | 672 | GNUNET_FS_namespace_list_updateable ( |
668 | struct GNUNET_FS_Handle *h, | 673 | struct GNUNET_FS_Handle *h, |
669 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 674 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
670 | const char *next_id, | 675 | const char *next_id, |
@@ -679,125 +684,125 @@ GNUNET_FS_namespace_list_updateable( | |||
679 | struct FindTreeClosure fc; | 684 | struct FindTreeClosure fc; |
680 | struct GNUNET_FS_UpdateInformationGraph *uig; | 685 | struct GNUNET_FS_UpdateInformationGraph *uig; |
681 | 686 | ||
682 | uig = read_update_information_graph(h, ns); | 687 | uig = read_update_information_graph (h, ns); |
683 | if (NULL == uig->update_nodes) | 688 | if (NULL == uig->update_nodes) |
684 | { | 689 | { |
685 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 690 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
686 | "No updateable nodes found for ID `%s'\n", | 691 | "No updateable nodes found for ID `%s'\n", |
687 | next_id); | 692 | next_id); |
688 | free_update_information_graph(uig); | 693 | free_update_information_graph (uig); |
689 | return; /* no nodes */ | 694 | return; /* no nodes */ |
690 | } | 695 | } |
691 | uig->update_map = | 696 | uig->update_map = |
692 | GNUNET_CONTAINER_multihashmap_create(2 + 3 * uig->update_node_count / 4, | 697 | GNUNET_CONTAINER_multihashmap_create (2 + 3 * uig->update_node_count / 4, |
693 | GNUNET_NO); | 698 | GNUNET_NO); |
694 | for (i = 0; i < uig->update_node_count; i++) | 699 | for (i = 0; i < uig->update_node_count; i++) |
695 | { | 700 | { |
696 | nsn = uig->update_nodes[i]; | 701 | nsn = uig->update_nodes[i]; |
697 | GNUNET_CRYPTO_hash(nsn->id, strlen(nsn->id), &hc); | 702 | GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); |
698 | GNUNET_CONTAINER_multihashmap_put( | 703 | GNUNET_CONTAINER_multihashmap_put ( |
699 | uig->update_map, | 704 | uig->update_map, |
700 | &hc, | 705 | &hc, |
701 | nsn, | 706 | nsn, |
702 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 707 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
703 | } | 708 | } |
704 | if (NULL != next_id) | 709 | if (NULL != next_id) |
705 | { | 710 | { |
706 | GNUNET_CRYPTO_hash(next_id, strlen(next_id), &hc); | 711 | GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc); |
707 | pc.ip = ip; | 712 | pc.ip = ip; |
708 | pc.ip_cls = ip_cls; | 713 | pc.ip_cls = ip_cls; |
709 | GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, | 714 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, |
710 | &hc, | 715 | &hc, |
711 | &process_update_node, | 716 | &process_update_node, |
712 | &pc); | 717 | &pc); |
713 | free_update_information_graph(uig); | 718 | free_update_information_graph (uig); |
714 | return; | 719 | return; |
715 | } | 720 | } |
716 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
717 | "Calculating TREEs to find roots of update trees\n"); | 722 | "Calculating TREEs to find roots of update trees\n"); |
718 | /* Find heads of TREEs in update graph */ | 723 | /* Find heads of TREEs in update graph */ |
719 | nug = ++uig->nug_gen; | 724 | nug = ++uig->nug_gen; |
720 | fc.tree_array = NULL; | 725 | fc.tree_array = NULL; |
721 | fc.tree_array_size = 0; | 726 | fc.tree_array_size = 0; |
722 | 727 | ||
723 | for (i = 0; i < uig->update_node_count; i++) | 728 | for (i = 0; i < uig->update_node_count; i++) |
729 | { | ||
730 | nsn = uig->update_nodes[i]; | ||
731 | if (nsn->nug == nug) | ||
724 | { | 732 | { |
725 | nsn = uig->update_nodes[i]; | 733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
726 | if (nsn->nug == nug) | 734 | "TREE of node `%s' is %u\n", |
727 | { | 735 | nsn->id, |
728 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 736 | nsn->nug); |
729 | "TREE of node `%s' is %u\n", | 737 | continue; /* already placed in TREE */ |
730 | nsn->id, | 738 | } |
731 | nsn->nug); | 739 | GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); |
732 | continue; /* already placed in TREE */ | 740 | nsn->nug = nug; |
733 | } | 741 | nsn->tree_id = UINT_MAX; |
734 | GNUNET_CRYPTO_hash(nsn->update, strlen(nsn->update), &hc); | 742 | fc.id = UINT_MAX; |
735 | nsn->nug = nug; | 743 | fc.nug = nug; |
736 | nsn->tree_id = UINT_MAX; | 744 | fc.uig = uig; |
737 | fc.id = UINT_MAX; | 745 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, |
738 | fc.nug = nug; | 746 | &hc, |
739 | fc.uig = uig; | 747 | &find_trees, |
740 | GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, | 748 | &fc); |
741 | &hc, | 749 | if (UINT_MAX == fc.id) |
742 | &find_trees, | 750 | { |
743 | &fc); | 751 | /* start new TREE */ |
744 | if (UINT_MAX == fc.id) | 752 | for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++) |
745 | { | 753 | { |
746 | /* start new TREE */ | 754 | if (NULL == fc.tree_array[fc.id]) |
747 | for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++) | ||
748 | { | ||
749 | if (NULL == fc.tree_array[fc.id]) | ||
750 | { | ||
751 | fc.tree_array[fc.id] = nsn; | ||
752 | nsn->tree_id = fc.id; | ||
753 | break; | ||
754 | } | ||
755 | } | ||
756 | if (fc.id == fc.tree_array_size) | ||
757 | { | ||
758 | GNUNET_array_append(fc.tree_array, fc.tree_array_size, nsn); | ||
759 | nsn->tree_id = fc.id; | ||
760 | } | ||
761 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
762 | "Starting new TREE %u with node `%s'\n", | ||
763 | nsn->tree_id, | ||
764 | nsn->id); | ||
765 | /* put all nodes with same identifier into this TREE */ | ||
766 | GNUNET_CRYPTO_hash(nsn->id, strlen(nsn->id), &hc); | ||
767 | fc.id = nsn->tree_id; | ||
768 | fc.nug = nug; | ||
769 | fc.uig = uig; | ||
770 | GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, | ||
771 | &hc, | ||
772 | &find_trees, | ||
773 | &fc); | ||
774 | } | ||
775 | else | ||
776 | { | 755 | { |
777 | /* make head of TREE "id" */ | ||
778 | fc.tree_array[fc.id] = nsn; | 756 | fc.tree_array[fc.id] = nsn; |
779 | nsn->tree_id = fc.id; | 757 | nsn->tree_id = fc.id; |
758 | break; | ||
780 | } | 759 | } |
781 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 760 | } |
782 | "TREE of node `%s' is %u\n", | 761 | if (fc.id == fc.tree_array_size) |
783 | nsn->id, | 762 | { |
784 | fc.id); | 763 | GNUNET_array_append (fc.tree_array, fc.tree_array_size, nsn); |
764 | nsn->tree_id = fc.id; | ||
765 | } | ||
766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
767 | "Starting new TREE %u with node `%s'\n", | ||
768 | nsn->tree_id, | ||
769 | nsn->id); | ||
770 | /* put all nodes with same identifier into this TREE */ | ||
771 | GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); | ||
772 | fc.id = nsn->tree_id; | ||
773 | fc.nug = nug; | ||
774 | fc.uig = uig; | ||
775 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, | ||
776 | &hc, | ||
777 | &find_trees, | ||
778 | &fc); | ||
785 | } | 779 | } |
780 | else | ||
781 | { | ||
782 | /* make head of TREE "id" */ | ||
783 | fc.tree_array[fc.id] = nsn; | ||
784 | nsn->tree_id = fc.id; | ||
785 | } | ||
786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
787 | "TREE of node `%s' is %u\n", | ||
788 | nsn->id, | ||
789 | fc.id); | ||
790 | } | ||
786 | for (i = 0; i < fc.tree_array_size; i++) | 791 | for (i = 0; i < fc.tree_array_size; i++) |
792 | { | ||
793 | nsn = fc.tree_array[i]; | ||
794 | if (NULL != nsn) | ||
787 | { | 795 | { |
788 | nsn = fc.tree_array[i]; | 796 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
789 | if (NULL != nsn) | 797 | "Root of TREE %u is node `%s'\n", |
790 | { | 798 | i, |
791 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 799 | nsn->id); |
792 | "Root of TREE %u is node `%s'\n", | 800 | ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); |
793 | i, | ||
794 | nsn->id); | ||
795 | ip(ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); | ||
796 | } | ||
797 | } | 801 | } |
798 | GNUNET_array_grow(fc.tree_array, fc.tree_array_size, 0); | 802 | } |
799 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n"); | 803 | GNUNET_array_grow (fc.tree_array, fc.tree_array_size, 0); |
800 | free_update_information_graph(uig); | 804 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n"); |
805 | free_update_information_graph (uig); | ||
801 | } | 806 | } |
802 | 807 | ||
803 | 808 | ||
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index b599bb06e..8bb57b1e2 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -44,10 +44,10 @@ | |||
44 | * @return value returned from callback | 44 | * @return value returned from callback |
45 | */ | 45 | */ |
46 | void * | 46 | void * |
47 | GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, | 47 | GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, |
48 | struct GNUNET_FS_PublishContext *pc, | 48 | struct GNUNET_FS_PublishContext *pc, |
49 | const struct GNUNET_FS_FileInformation *p, | 49 | const struct GNUNET_FS_FileInformation *p, |
50 | uint64_t offset) | 50 | uint64_t offset) |
51 | { | 51 | { |
52 | pi->value.publish.pc = pc; | 52 | pi->value.publish.pc = pc; |
53 | pi->value.publish.fi = p; | 53 | pi->value.publish.fi = p; |
@@ -55,16 +55,17 @@ GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, | |||
55 | pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info; | 55 | pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info; |
56 | pi->value.publish.filename = p->filename; | 56 | pi->value.publish.filename = p->filename; |
57 | pi->value.publish.size = | 57 | pi->value.publish.size = |
58 | (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; | 58 | (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : |
59 | p->data.file.file_size; | ||
59 | pi->value.publish.eta = | 60 | pi->value.publish.eta = |
60 | GNUNET_TIME_calculate_eta(p->start_time, offset, | 61 | GNUNET_TIME_calculate_eta (p->start_time, offset, |
61 | pi->value.publish.size); | 62 | pi->value.publish.size); |
62 | pi->value.publish.completed = offset; | 63 | pi->value.publish.completed = offset; |
63 | pi->value.publish.duration = | 64 | pi->value.publish.duration = |
64 | GNUNET_TIME_absolute_get_duration(p->start_time); | 65 | GNUNET_TIME_absolute_get_duration (p->start_time); |
65 | pi->value.publish.anonymity = p->bo.anonymity_level; | 66 | pi->value.publish.anonymity = p->bo.anonymity_level; |
66 | pi->fsh = pc->h; | 67 | pi->fsh = pc->h; |
67 | return pc->h->upcb(pc->h->upcb_cls, pi); | 68 | return pc->h->upcb (pc->h->upcb_cls, pi); |
68 | } | 69 | } |
69 | 70 | ||
70 | 71 | ||
@@ -74,31 +75,31 @@ GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, | |||
74 | * @param pc struct to clean up | 75 | * @param pc struct to clean up |
75 | */ | 76 | */ |
76 | static void | 77 | static void |
77 | publish_cleanup(struct GNUNET_FS_PublishContext *pc) | 78 | publish_cleanup (struct GNUNET_FS_PublishContext *pc) |
78 | { | 79 | { |
79 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
80 | "Cleaning up publish context (done!)\n"); | 81 | "Cleaning up publish context (done!)\n"); |
81 | if (NULL != pc->fhc) | 82 | if (NULL != pc->fhc) |
82 | { | 83 | { |
83 | GNUNET_CRYPTO_hash_file_cancel(pc->fhc); | 84 | GNUNET_CRYPTO_hash_file_cancel (pc->fhc); |
84 | pc->fhc = NULL; | 85 | pc->fhc = NULL; |
85 | } | 86 | } |
86 | GNUNET_FS_file_information_destroy(pc->fi, NULL, NULL); | 87 | GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); |
87 | GNUNET_free_non_null(pc->nid); | 88 | GNUNET_free_non_null (pc->nid); |
88 | GNUNET_free_non_null(pc->nuid); | 89 | GNUNET_free_non_null (pc->nuid); |
89 | GNUNET_free_non_null(pc->serialization); | 90 | GNUNET_free_non_null (pc->serialization); |
90 | if (NULL != pc->dsh) | 91 | if (NULL != pc->dsh) |
91 | { | 92 | { |
92 | GNUNET_DATASTORE_disconnect(pc->dsh, GNUNET_NO); | 93 | GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); |
93 | pc->dsh = NULL; | 94 | pc->dsh = NULL; |
94 | } | 95 | } |
95 | if (NULL != pc->mq) | 96 | if (NULL != pc->mq) |
96 | { | 97 | { |
97 | GNUNET_MQ_destroy(pc->mq); | 98 | GNUNET_MQ_destroy (pc->mq); |
98 | pc->mq = NULL; | 99 | pc->mq = NULL; |
99 | } | 100 | } |
100 | GNUNET_assert(NULL == pc->upload_task); | 101 | GNUNET_assert (NULL == pc->upload_task); |
101 | GNUNET_free(pc); | 102 | GNUNET_free (pc); |
102 | } | 103 | } |
103 | 104 | ||
104 | 105 | ||
@@ -112,42 +113,42 @@ publish_cleanup(struct GNUNET_FS_PublishContext *pc) | |||
112 | * @param msg error message (or NULL) | 113 | * @param msg error message (or NULL) |
113 | */ | 114 | */ |
114 | static void | 115 | static void |
115 | ds_put_cont(void *cls, | 116 | ds_put_cont (void *cls, |
116 | int success, | 117 | int success, |
117 | struct GNUNET_TIME_Absolute min_expiration, | 118 | struct GNUNET_TIME_Absolute min_expiration, |
118 | const char *msg) | 119 | const char *msg) |
119 | { | 120 | { |
120 | struct GNUNET_FS_PublishContext *pc = cls; | 121 | struct GNUNET_FS_PublishContext *pc = cls; |
121 | struct GNUNET_FS_ProgressInfo pi; | 122 | struct GNUNET_FS_ProgressInfo pi; |
122 | 123 | ||
123 | pc->qre = NULL; | 124 | pc->qre = NULL; |
124 | if (GNUNET_SYSERR == success) | 125 | if (GNUNET_SYSERR == success) |
126 | { | ||
127 | GNUNET_asprintf (&pc->fi_pos->emsg, | ||
128 | _ ("Publishing failed: %s"), | ||
129 | msg); | ||
130 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | ||
131 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | ||
132 | pi.value.publish.specifics.error.message = pc->fi_pos->emsg; | ||
133 | pc->fi_pos->client_info = | ||
134 | GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi_pos, 0); | ||
135 | if ((GNUNET_YES != pc->fi_pos->is_directory) && | ||
136 | (NULL != pc->fi_pos->filename) && | ||
137 | (GNUNET_YES == pc->any_done) && | ||
138 | (GNUNET_YES == pc->fi_pos->data.file.do_index)) | ||
125 | { | 139 | { |
126 | GNUNET_asprintf(&pc->fi_pos->emsg, | 140 | /* run unindex to clean up */ |
127 | _("Publishing failed: %s"), | 141 | GNUNET_FS_unindex_start (pc->h, |
128 | msg); | 142 | pc->fi_pos->filename, |
129 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 143 | NULL); |
130 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | ||
131 | pi.value.publish.specifics.error.message = pc->fi_pos->emsg; | ||
132 | pc->fi_pos->client_info = | ||
133 | GNUNET_FS_publish_make_status_(&pi, pc, pc->fi_pos, 0); | ||
134 | if ((GNUNET_YES != pc->fi_pos->is_directory) && | ||
135 | (NULL != pc->fi_pos->filename) && | ||
136 | (GNUNET_YES == pc->any_done) && | ||
137 | (GNUNET_YES == pc->fi_pos->data.file.do_index)) | ||
138 | { | ||
139 | /* run unindex to clean up */ | ||
140 | GNUNET_FS_unindex_start(pc->h, | ||
141 | pc->fi_pos->filename, | ||
142 | NULL); | ||
143 | } | ||
144 | return; | ||
145 | } | 144 | } |
145 | return; | ||
146 | } | ||
146 | pc->any_done = GNUNET_YES; | 147 | pc->any_done = GNUNET_YES; |
147 | GNUNET_assert(NULL == pc->upload_task); | 148 | GNUNET_assert (NULL == pc->upload_task); |
148 | pc->upload_task = | 149 | pc->upload_task = |
149 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 150 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
150 | &GNUNET_FS_publish_main_, pc); | 151 | &GNUNET_FS_publish_main_, pc); |
151 | } | 152 | } |
152 | 153 | ||
153 | 154 | ||
@@ -160,8 +161,8 @@ ds_put_cont(void *cls, | |||
160 | * @param pc context of the publication | 161 | * @param pc context of the publication |
161 | */ | 162 | */ |
162 | static void | 163 | static void |
163 | signal_publish_completion(struct GNUNET_FS_FileInformation *p, | 164 | signal_publish_completion (struct GNUNET_FS_FileInformation *p, |
164 | struct GNUNET_FS_PublishContext *pc) | 165 | struct GNUNET_FS_PublishContext *pc) |
165 | { | 166 | { |
166 | struct GNUNET_FS_ProgressInfo pi; | 167 | struct GNUNET_FS_ProgressInfo pi; |
167 | 168 | ||
@@ -170,8 +171,8 @@ signal_publish_completion(struct GNUNET_FS_FileInformation *p, | |||
170 | pi.value.publish.specifics.completed.chk_uri = p->chk_uri; | 171 | pi.value.publish.specifics.completed.chk_uri = p->chk_uri; |
171 | pi.value.publish.specifics.completed.sks_uri = p->sks_uri; | 172 | pi.value.publish.specifics.completed.sks_uri = p->sks_uri; |
172 | p->client_info = | 173 | p->client_info = |
173 | GNUNET_FS_publish_make_status_(&pi, pc, p, | 174 | GNUNET_FS_publish_make_status_ (&pi, pc, p, |
174 | p->data.file.file_size); | 175 | p->data.file.file_size); |
175 | } | 176 | } |
176 | 177 | ||
177 | 178 | ||
@@ -185,27 +186,27 @@ signal_publish_completion(struct GNUNET_FS_FileInformation *p, | |||
185 | * @param emsg error message | 186 | * @param emsg error message |
186 | */ | 187 | */ |
187 | static void | 188 | static void |
188 | signal_publish_error(struct GNUNET_FS_FileInformation *p, | 189 | signal_publish_error (struct GNUNET_FS_FileInformation *p, |
189 | struct GNUNET_FS_PublishContext *pc, | 190 | struct GNUNET_FS_PublishContext *pc, |
190 | const char *emsg) | 191 | const char *emsg) |
191 | { | 192 | { |
192 | struct GNUNET_FS_ProgressInfo pi; | 193 | struct GNUNET_FS_ProgressInfo pi; |
193 | 194 | ||
194 | p->emsg = GNUNET_strdup(emsg); | 195 | p->emsg = GNUNET_strdup (emsg); |
195 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 196 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
196 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 197 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
197 | pi.value.publish.specifics.error.message = emsg; | 198 | pi.value.publish.specifics.error.message = emsg; |
198 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); | 199 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); |
199 | if ((p->is_directory != GNUNET_YES) && | 200 | if ((p->is_directory != GNUNET_YES) && |
200 | (NULL != p->filename) && | 201 | (NULL != p->filename) && |
201 | (GNUNET_YES == pc->any_done) && | 202 | (GNUNET_YES == pc->any_done) && |
202 | (p->data.file.do_index == GNUNET_YES)) | 203 | (p->data.file.do_index == GNUNET_YES)) |
203 | { | 204 | { |
204 | /* run unindex to clean up */ | 205 | /* run unindex to clean up */ |
205 | GNUNET_FS_unindex_start(pc->h, | 206 | GNUNET_FS_unindex_start (pc->h, |
206 | p->filename, | 207 | p->filename, |
207 | NULL); | 208 | NULL); |
208 | } | 209 | } |
209 | } | 210 | } |
210 | 211 | ||
211 | 212 | ||
@@ -218,18 +219,18 @@ signal_publish_error(struct GNUNET_FS_FileInformation *p, | |||
218 | * @param msg error message (typically NULL, not used) | 219 | * @param msg error message (typically NULL, not used) |
219 | */ | 220 | */ |
220 | static void | 221 | static void |
221 | finish_release_reserve(void *cls, int success, | 222 | finish_release_reserve (void *cls, int success, |
222 | struct GNUNET_TIME_Absolute min_expiration, | 223 | struct GNUNET_TIME_Absolute min_expiration, |
223 | const char *msg) | 224 | const char *msg) |
224 | { | 225 | { |
225 | struct GNUNET_FS_PublishContext *pc = cls; | 226 | struct GNUNET_FS_PublishContext *pc = cls; |
226 | 227 | ||
227 | pc->qre = NULL; | 228 | pc->qre = NULL; |
228 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
229 | "Releasing reserve done!\n"); | 230 | "Releasing reserve done!\n"); |
230 | signal_publish_completion(pc->fi, pc); | 231 | signal_publish_completion (pc->fi, pc); |
231 | pc->all_done = GNUNET_YES; | 232 | pc->all_done = GNUNET_YES; |
232 | GNUNET_FS_publish_sync_(pc); | 233 | GNUNET_FS_publish_sync_ (pc); |
233 | } | 234 | } |
234 | 235 | ||
235 | 236 | ||
@@ -242,35 +243,35 @@ finish_release_reserve(void *cls, int success, | |||
242 | * @param emsg NULL on success, otherwise error message | 243 | * @param emsg NULL on success, otherwise error message |
243 | */ | 244 | */ |
244 | static void | 245 | static void |
245 | publish_sblocks_cont(void *cls, | 246 | publish_sblocks_cont (void *cls, |
246 | const struct GNUNET_FS_Uri *uri, | 247 | const struct GNUNET_FS_Uri *uri, |
247 | const char *emsg) | 248 | const char *emsg) |
248 | { | 249 | { |
249 | struct GNUNET_FS_PublishContext *pc = cls; | 250 | struct GNUNET_FS_PublishContext *pc = cls; |
250 | 251 | ||
251 | pc->sks_pc = NULL; | 252 | pc->sks_pc = NULL; |
252 | if (NULL != emsg) | 253 | if (NULL != emsg) |
253 | { | 254 | { |
254 | signal_publish_error(pc->fi, pc, emsg); | 255 | signal_publish_error (pc->fi, pc, emsg); |
255 | GNUNET_FS_publish_sync_(pc); | 256 | GNUNET_FS_publish_sync_ (pc); |
256 | return; | 257 | return; |
257 | } | 258 | } |
258 | if (NULL != uri) | 259 | if (NULL != uri) |
259 | { | 260 | { |
260 | /* sks publication, remember namespace URI */ | 261 | /* sks publication, remember namespace URI */ |
261 | pc->fi->sks_uri = GNUNET_FS_uri_dup(uri); | 262 | pc->fi->sks_uri = GNUNET_FS_uri_dup (uri); |
262 | } | 263 | } |
263 | GNUNET_assert(pc->qre == NULL); | 264 | GNUNET_assert (pc->qre == NULL); |
264 | if ((pc->dsh != NULL) && (pc->rid != 0)) | 265 | if ((pc->dsh != NULL) && (pc->rid != 0)) |
265 | { | 266 | { |
266 | pc->qre = | 267 | pc->qre = |
267 | GNUNET_DATASTORE_release_reserve(pc->dsh, pc->rid, UINT_MAX, UINT_MAX, | 268 | GNUNET_DATASTORE_release_reserve (pc->dsh, pc->rid, UINT_MAX, UINT_MAX, |
268 | &finish_release_reserve, pc); | 269 | &finish_release_reserve, pc); |
269 | } | 270 | } |
270 | else | 271 | else |
271 | { | 272 | { |
272 | finish_release_reserve(pc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL); | 273 | finish_release_reserve (pc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL); |
273 | } | 274 | } |
274 | } | 275 | } |
275 | 276 | ||
276 | 277 | ||
@@ -281,20 +282,20 @@ publish_sblocks_cont(void *cls, | |||
281 | * @param pc overall upload data | 282 | * @param pc overall upload data |
282 | */ | 283 | */ |
283 | static void | 284 | static void |
284 | publish_sblock(struct GNUNET_FS_PublishContext *pc) | 285 | publish_sblock (struct GNUNET_FS_PublishContext *pc) |
285 | { | 286 | { |
286 | if (NULL != pc->ns) | 287 | if (NULL != pc->ns) |
287 | pc->sks_pc = GNUNET_FS_publish_sks(pc->h, | 288 | pc->sks_pc = GNUNET_FS_publish_sks (pc->h, |
288 | pc->ns, | 289 | pc->ns, |
289 | pc->nid, | 290 | pc->nid, |
290 | pc->nuid, | 291 | pc->nuid, |
291 | pc->fi->meta, | 292 | pc->fi->meta, |
292 | pc->fi->chk_uri, | 293 | pc->fi->chk_uri, |
293 | &pc->fi->bo, | 294 | &pc->fi->bo, |
294 | pc->options, | 295 | pc->options, |
295 | &publish_sblocks_cont, pc); | 296 | &publish_sblocks_cont, pc); |
296 | else | 297 | else |
297 | publish_sblocks_cont(pc, NULL, NULL); | 298 | publish_sblocks_cont (pc, NULL, NULL); |
298 | } | 299 | } |
299 | 300 | ||
300 | 301 | ||
@@ -308,44 +309,44 @@ publish_sblock(struct GNUNET_FS_PublishContext *pc) | |||
308 | * @param emsg NULL on success, otherwise error message | 309 | * @param emsg NULL on success, otherwise error message |
309 | */ | 310 | */ |
310 | static void | 311 | static void |
311 | publish_kblocks_cont(void *cls, | 312 | publish_kblocks_cont (void *cls, |
312 | const struct GNUNET_FS_Uri *uri, | 313 | const struct GNUNET_FS_Uri *uri, |
313 | const char *emsg) | 314 | const char *emsg) |
314 | { | 315 | { |
315 | struct GNUNET_FS_PublishContext *pc = cls; | 316 | struct GNUNET_FS_PublishContext *pc = cls; |
316 | struct GNUNET_FS_FileInformation *p = pc->fi_pos; | 317 | struct GNUNET_FS_FileInformation *p = pc->fi_pos; |
317 | 318 | ||
318 | pc->ksk_pc = NULL; | 319 | pc->ksk_pc = NULL; |
319 | if (NULL != emsg) | 320 | if (NULL != emsg) |
320 | { | 321 | { |
321 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
322 | "Error uploading KSK blocks: %s\n", | 323 | "Error uploading KSK blocks: %s\n", |
323 | emsg); | 324 | emsg); |
324 | signal_publish_error(p, pc, emsg); | 325 | signal_publish_error (p, pc, emsg); |
325 | GNUNET_FS_file_information_sync_(p); | 326 | GNUNET_FS_file_information_sync_ (p); |
326 | GNUNET_FS_publish_sync_(pc); | 327 | GNUNET_FS_publish_sync_ (pc); |
327 | GNUNET_assert(NULL == pc->upload_task); | 328 | GNUNET_assert (NULL == pc->upload_task); |
328 | pc->upload_task = | 329 | pc->upload_task = |
329 | GNUNET_SCHEDULER_add_with_priority | 330 | GNUNET_SCHEDULER_add_with_priority |
330 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 331 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
331 | &GNUNET_FS_publish_main_, | 332 | &GNUNET_FS_publish_main_, |
332 | pc); | 333 | pc); |
333 | return; | 334 | return; |
334 | } | 335 | } |
335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
336 | "KSK blocks published, moving on to next file\n"); | 337 | "KSK blocks published, moving on to next file\n"); |
337 | if (NULL != p->dir) | 338 | if (NULL != p->dir) |
338 | signal_publish_completion(p, pc); | 339 | signal_publish_completion (p, pc); |
339 | /* move on to next file */ | 340 | /* move on to next file */ |
340 | if (NULL != p->next) | 341 | if (NULL != p->next) |
341 | pc->fi_pos = p->next; | 342 | pc->fi_pos = p->next; |
342 | else | 343 | else |
343 | pc->fi_pos = p->dir; | 344 | pc->fi_pos = p->dir; |
344 | GNUNET_FS_publish_sync_(pc); | 345 | GNUNET_FS_publish_sync_ (pc); |
345 | GNUNET_assert(NULL == pc->upload_task); | 346 | GNUNET_assert (NULL == pc->upload_task); |
346 | pc->upload_task = | 347 | pc->upload_task = |
347 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 348 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
348 | &GNUNET_FS_publish_main_, pc); | 349 | &GNUNET_FS_publish_main_, pc); |
349 | } | 350 | } |
350 | 351 | ||
351 | 352 | ||
@@ -363,11 +364,11 @@ publish_kblocks_cont(void *cls, | |||
363 | * @return number of bytes copied to buf, 0 on error | 364 | * @return number of bytes copied to buf, 0 on error |
364 | */ | 365 | */ |
365 | static size_t | 366 | static size_t |
366 | block_reader(void *cls, | 367 | block_reader (void *cls, |
367 | uint64_t offset, | 368 | uint64_t offset, |
368 | size_t max, | 369 | size_t max, |
369 | void *buf, | 370 | void *buf, |
370 | char **emsg) | 371 | char **emsg) |
371 | { | 372 | { |
372 | struct GNUNET_FS_PublishContext *pc = cls; | 373 | struct GNUNET_FS_PublishContext *pc = cls; |
373 | struct GNUNET_FS_FileInformation *p; | 374 | struct GNUNET_FS_FileInformation *p; |
@@ -376,31 +377,31 @@ block_reader(void *cls, | |||
376 | 377 | ||
377 | p = pc->fi_pos; | 378 | p = pc->fi_pos; |
378 | if (GNUNET_YES == p->is_directory) | 379 | if (GNUNET_YES == p->is_directory) |
379 | { | 380 | { |
380 | pt_size = GNUNET_MIN(max, p->data.dir.dir_size - offset); | 381 | pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset); |
381 | dd = p->data.dir.dir_data; | 382 | dd = p->data.dir.dir_data; |
382 | GNUNET_memcpy(buf, &dd[offset], pt_size); | 383 | GNUNET_memcpy (buf, &dd[offset], pt_size); |
383 | } | 384 | } |
384 | else | 385 | else |
385 | { | 386 | { |
386 | if (UINT64_MAX == offset) | 387 | if (UINT64_MAX == offset) |
387 | { | 388 | { |
388 | if (&GNUNET_FS_data_reader_file_ == p->data.file.reader) | 389 | if (&GNUNET_FS_data_reader_file_ == p->data.file.reader) |
389 | { | 390 | { |
390 | /* force closing the file to avoid keeping too many files open */ | 391 | /* force closing the file to avoid keeping too many files open */ |
391 | p->data.file.reader(p->data.file.reader_cls, offset, 0, NULL, NULL); | 392 | p->data.file.reader (p->data.file.reader_cls, offset, 0, NULL, NULL); |
392 | } | 393 | } |
393 | return 0; | 394 | return 0; |
394 | } | 395 | } |
395 | pt_size = GNUNET_MIN(max, p->data.file.file_size - offset); | 396 | pt_size = GNUNET_MIN (max, p->data.file.file_size - offset); |
396 | if (0 == pt_size) | 397 | if (0 == pt_size) |
397 | return 0; /* calling reader with pt_size==0 | 398 | return 0; /* calling reader with pt_size==0 |
398 | * might free buf, so don't! */ | 399 | * might free buf, so don't! */ |
399 | if (pt_size != | 400 | if (pt_size != |
400 | p->data.file.reader(p->data.file.reader_cls, offset, pt_size, buf, | 401 | p->data.file.reader (p->data.file.reader_cls, offset, pt_size, buf, |
401 | emsg)) | 402 | emsg)) |
402 | return 0; | 403 | return 0; |
403 | } | 404 | } |
404 | return pt_size; | 405 | return pt_size; |
405 | } | 406 | } |
406 | 407 | ||
@@ -413,7 +414,7 @@ block_reader(void *cls, | |||
413 | * @param cls our publishing context | 414 | * @param cls our publishing context |
414 | */ | 415 | */ |
415 | static void | 416 | static void |
416 | encode_cont(void *cls) | 417 | encode_cont (void *cls) |
417 | { | 418 | { |
418 | struct GNUNET_FS_PublishContext *pc = cls; | 419 | struct GNUNET_FS_PublishContext *pc = cls; |
419 | struct GNUNET_FS_FileInformation *p; | 420 | struct GNUNET_FS_FileInformation *p; |
@@ -421,44 +422,44 @@ encode_cont(void *cls) | |||
421 | char *emsg; | 422 | char *emsg; |
422 | uint64_t flen; | 423 | uint64_t flen; |
423 | 424 | ||
424 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
425 | "Finished with tree encoder\n"); | 426 | "Finished with tree encoder\n"); |
426 | p = pc->fi_pos; | 427 | p = pc->fi_pos; |
427 | p->chk_uri = GNUNET_FS_tree_encoder_get_uri(p->te); | 428 | p->chk_uri = GNUNET_FS_tree_encoder_get_uri (p->te); |
428 | GNUNET_FS_file_information_sync_(p); | 429 | GNUNET_FS_file_information_sync_ (p); |
429 | GNUNET_FS_tree_encoder_finish(p->te, &emsg); | 430 | GNUNET_FS_tree_encoder_finish (p->te, &emsg); |
430 | p->te = NULL; | 431 | p->te = NULL; |
431 | if (NULL != emsg) | 432 | if (NULL != emsg) |
432 | { | 433 | { |
433 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
434 | "Error during tree walk: %s\n", | 435 | "Error during tree walk: %s\n", |
435 | emsg); | 436 | emsg); |
436 | GNUNET_asprintf(&p->emsg, | 437 | GNUNET_asprintf (&p->emsg, |
437 | _("Publishing failed: %s"), | 438 | _ ("Publishing failed: %s"), |
438 | emsg); | 439 | emsg); |
439 | GNUNET_free(emsg); | 440 | GNUNET_free (emsg); |
440 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 441 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
441 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 442 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
442 | pi.value.publish.specifics.error.message = p->emsg; | 443 | pi.value.publish.specifics.error.message = p->emsg; |
443 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); | 444 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); |
444 | } | 445 | } |
445 | else | 446 | else |
446 | { | 447 | { |
447 | /* final progress event */ | 448 | /* final progress event */ |
448 | GNUNET_assert(NULL != p->chk_uri); | 449 | GNUNET_assert (NULL != p->chk_uri); |
449 | flen = GNUNET_FS_uri_chk_get_file_size(p->chk_uri); | 450 | flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri); |
450 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; | 451 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; |
451 | pi.value.publish.specifics.progress.data = NULL; | 452 | pi.value.publish.specifics.progress.data = NULL; |
452 | pi.value.publish.specifics.progress.offset = flen; | 453 | pi.value.publish.specifics.progress.offset = flen; |
453 | pi.value.publish.specifics.progress.data_len = 0; | 454 | pi.value.publish.specifics.progress.data_len = 0; |
454 | pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth(flen); | 455 | pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth (flen); |
455 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, flen); | 456 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, flen); |
456 | } | 457 | } |
457 | /* continue with main */ /* continue with main */ | 458 | /* continue with main */ /* continue with main */ |
458 | GNUNET_assert(NULL == pc->upload_task); | 459 | GNUNET_assert (NULL == pc->upload_task); |
459 | pc->upload_task = | 460 | pc->upload_task = |
460 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 461 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
461 | &GNUNET_FS_publish_main_, pc); | 462 | &GNUNET_FS_publish_main_, pc); |
462 | } | 463 | } |
463 | 464 | ||
464 | 465 | ||
@@ -477,13 +478,13 @@ encode_cont(void *cls) | |||
477 | * @param block_size size of @a block (in bytes) | 478 | * @param block_size size of @a block (in bytes) |
478 | */ | 479 | */ |
479 | static void | 480 | static void |
480 | block_proc(void *cls, | 481 | block_proc (void *cls, |
481 | const struct ContentHashKey *chk, | 482 | const struct ContentHashKey *chk, |
482 | uint64_t offset, | 483 | uint64_t offset, |
483 | unsigned int depth, | 484 | unsigned int depth, |
484 | enum GNUNET_BLOCK_Type type, | 485 | enum GNUNET_BLOCK_Type type, |
485 | const void *block, | 486 | const void *block, |
486 | uint16_t block_size) | 487 | uint16_t block_size) |
487 | { | 488 | { |
488 | struct GNUNET_FS_PublishContext *pc = cls; | 489 | struct GNUNET_FS_PublishContext *pc = cls; |
489 | struct GNUNET_FS_FileInformation *p; | 490 | struct GNUNET_FS_FileInformation *p; |
@@ -491,62 +492,63 @@ block_proc(void *cls, | |||
491 | 492 | ||
492 | p = pc->fi_pos; | 493 | p = pc->fi_pos; |
493 | if (NULL == pc->dsh) | 494 | if (NULL == pc->dsh) |
494 | { | 495 | { |
495 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
496 | "Waiting for datastore connection\n"); | 497 | "Waiting for datastore connection\n"); |
497 | GNUNET_assert(NULL == pc->upload_task); | 498 | GNUNET_assert (NULL == pc->upload_task); |
498 | pc->upload_task = | 499 | pc->upload_task = |
499 | GNUNET_SCHEDULER_add_with_priority | 500 | GNUNET_SCHEDULER_add_with_priority |
500 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); | 501 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); |
501 | return; | 502 | return; |
502 | } | 503 | } |
503 | 504 | ||
504 | if ((GNUNET_YES != p->is_directory) && | 505 | if ((GNUNET_YES != p->is_directory) && |
505 | (GNUNET_YES == p->data.file.do_index) && | 506 | (GNUNET_YES == p->data.file.do_index) && |
506 | (GNUNET_BLOCK_TYPE_FS_DBLOCK == type)) | 507 | (GNUNET_BLOCK_TYPE_FS_DBLOCK == type)) |
507 | { | 508 | { |
508 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
509 | "Indexing block `%s' for offset %llu with index size %u\n", | 510 | "Indexing block `%s' for offset %llu with index size %u\n", |
510 | GNUNET_h2s(&chk->query), | 511 | GNUNET_h2s (&chk->query), |
511 | (unsigned long long)offset, | 512 | (unsigned long long) offset, |
512 | (unsigned int)sizeof(struct OnDemandBlock)); | 513 | (unsigned int) sizeof(struct OnDemandBlock)); |
513 | odb.offset = GNUNET_htonll(offset); | 514 | odb.offset = GNUNET_htonll (offset); |
514 | odb.file_id = p->data.file.file_id; | 515 | odb.file_id = p->data.file.file_id; |
515 | GNUNET_assert(pc->qre == NULL); | 516 | GNUNET_assert (pc->qre == NULL); |
516 | pc->qre = | 517 | pc->qre = |
517 | GNUNET_DATASTORE_put(pc->dsh, | 518 | GNUNET_DATASTORE_put (pc->dsh, |
518 | (p->is_directory == GNUNET_YES) ? 0 : pc->rid, | 519 | (p->is_directory == GNUNET_YES) ? 0 : pc->rid, |
519 | &chk->query, | 520 | &chk->query, |
520 | sizeof(struct OnDemandBlock), | 521 | sizeof(struct OnDemandBlock), |
521 | &odb, | 522 | &odb, |
522 | GNUNET_BLOCK_TYPE_FS_ONDEMAND, | 523 | GNUNET_BLOCK_TYPE_FS_ONDEMAND, |
523 | p->bo.content_priority, | 524 | p->bo.content_priority, |
524 | p->bo.anonymity_level, | 525 | p->bo.anonymity_level, |
525 | p->bo.replication_level, | 526 | p->bo.replication_level, |
526 | p->bo.expiration_time, | 527 | p->bo.expiration_time, |
527 | -2, 1, | 528 | -2, 1, |
528 | &ds_put_cont, pc); | 529 | &ds_put_cont, pc); |
529 | return; | 530 | return; |
530 | } | 531 | } |
531 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
532 | "Publishing block `%s' for offset %llu with size %u\n", | 533 | "Publishing block `%s' for offset %llu with size %u\n", |
533 | GNUNET_h2s(&chk->query), | 534 | GNUNET_h2s (&chk->query), |
534 | (unsigned long long)offset, | 535 | (unsigned long long) offset, |
535 | (unsigned int)block_size); | 536 | (unsigned int) block_size); |
536 | GNUNET_assert(pc->qre == NULL); | 537 | GNUNET_assert (pc->qre == NULL); |
537 | pc->qre = | 538 | pc->qre = |
538 | GNUNET_DATASTORE_put(pc->dsh, (p->is_directory == GNUNET_YES) ? 0 : pc->rid, | 539 | GNUNET_DATASTORE_put (pc->dsh, (p->is_directory == GNUNET_YES) ? 0 : |
539 | &chk->query, | 540 | pc->rid, |
540 | block_size, | 541 | &chk->query, |
541 | block, | 542 | block_size, |
542 | type, | 543 | block, |
543 | p->bo.content_priority, | 544 | type, |
544 | p->bo.anonymity_level, | 545 | p->bo.content_priority, |
545 | p->bo.replication_level, | 546 | p->bo.anonymity_level, |
546 | p->bo.expiration_time, | 547 | p->bo.replication_level, |
547 | -2, 1, | 548 | p->bo.expiration_time, |
548 | &ds_put_cont, | 549 | -2, 1, |
549 | pc); | 550 | &ds_put_cont, |
551 | pc); | ||
550 | } | 552 | } |
551 | 553 | ||
552 | 554 | ||
@@ -561,10 +563,10 @@ block_proc(void *cls, | |||
561 | * @param depth depth of the block in the tree, 0 for DBLOCK | 563 | * @param depth depth of the block in the tree, 0 for DBLOCK |
562 | */ | 564 | */ |
563 | static void | 565 | static void |
564 | progress_proc(void *cls, uint64_t offset, | 566 | progress_proc (void *cls, uint64_t offset, |
565 | const void *pt_block, | 567 | const void *pt_block, |
566 | size_t pt_size, | 568 | size_t pt_size, |
567 | unsigned int depth) | 569 | unsigned int depth) |
568 | { | 570 | { |
569 | struct GNUNET_FS_PublishContext *pc = cls; | 571 | struct GNUNET_FS_PublishContext *pc = cls; |
570 | struct GNUNET_FS_FileInformation *p; | 572 | struct GNUNET_FS_FileInformation *p; |
@@ -577,23 +579,28 @@ progress_proc(void *cls, uint64_t offset, | |||
577 | pi.value.publish.specifics.progress.offset = offset; | 579 | pi.value.publish.specifics.progress.offset = offset; |
578 | pi.value.publish.specifics.progress.data_len = pt_size; | 580 | pi.value.publish.specifics.progress.data_len = pt_size; |
579 | pi.value.publish.specifics.progress.depth = depth; | 581 | pi.value.publish.specifics.progress.depth = depth; |
580 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, offset); | 582 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, offset); |
581 | if ((0 != depth) || | 583 | if ((0 != depth) || |
582 | (GNUNET_YES == p->is_directory)) | 584 | (GNUNET_YES == p->is_directory)) |
583 | return; | 585 | return; |
584 | while (NULL != (par = p->dir)) | 586 | while (NULL != (par = p->dir)) |
585 | { | 587 | { |
586 | p = par; | 588 | p = par; |
587 | GNUNET_assert(GNUNET_YES == par->is_directory); | 589 | GNUNET_assert (GNUNET_YES == par->is_directory); |
588 | p->data.dir.contents_completed += pt_size; | 590 | p->data.dir.contents_completed += pt_size; |
589 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY; | 591 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY; |
590 | pi.value.publish.specifics.progress_directory.completed = p->data.dir.contents_completed; | 592 | pi.value.publish.specifics.progress_directory.completed = |
591 | pi.value.publish.specifics.progress_directory.total = p->data.dir.contents_size; | 593 | p->data.dir.contents_completed; |
592 | pi.value.publish.specifics.progress_directory.eta = GNUNET_TIME_calculate_eta(p->start_time, | 594 | pi.value.publish.specifics.progress_directory.total = |
593 | p->data.dir.contents_completed, | 595 | p->data.dir.contents_size; |
594 | p->data.dir.contents_size); | 596 | pi.value.publish.specifics.progress_directory.eta = |
595 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); | 597 | GNUNET_TIME_calculate_eta (p->start_time, |
596 | } | 598 | p |
599 | ->data.dir.contents_completed, | ||
600 | p | ||
601 | ->data.dir.contents_size); | ||
602 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); | ||
603 | } | ||
597 | } | 604 | } |
598 | 605 | ||
599 | 606 | ||
@@ -605,7 +612,7 @@ progress_proc(void *cls, uint64_t offset, | |||
605 | * @param pc overall upload data | 612 | * @param pc overall upload data |
606 | */ | 613 | */ |
607 | static void | 614 | static void |
608 | publish_content(struct GNUNET_FS_PublishContext *pc) | 615 | publish_content (struct GNUNET_FS_PublishContext *pc) |
609 | { | 616 | { |
610 | struct GNUNET_FS_FileInformation *p; | 617 | struct GNUNET_FS_FileInformation *p; |
611 | char *emsg; | 618 | char *emsg; |
@@ -615,64 +622,66 @@ publish_content(struct GNUNET_FS_PublishContext *pc) | |||
615 | uint64_t size; | 622 | uint64_t size; |
616 | 623 | ||
617 | p = pc->fi_pos; | 624 | p = pc->fi_pos; |
618 | GNUNET_assert(NULL != p); | 625 | GNUNET_assert (NULL != p); |
619 | if (NULL == p->te) | 626 | if (NULL == p->te) |
620 | { | 627 | { |
621 | if (GNUNET_YES == p->is_directory) | 628 | if (GNUNET_YES == p->is_directory) |
629 | { | ||
630 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n"); | ||
631 | db = GNUNET_FS_directory_builder_create (p->meta); | ||
632 | dirpos = p->data.dir.entries; | ||
633 | while (NULL != dirpos) | ||
634 | { | ||
635 | if (GNUNET_YES == dirpos->is_directory) | ||
636 | { | ||
637 | raw_data = dirpos->data.dir.dir_data; | ||
638 | dirpos->data.dir.dir_data = NULL; | ||
639 | } | ||
640 | else | ||
622 | { | 641 | { |
623 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n"); | 642 | raw_data = NULL; |
624 | db = GNUNET_FS_directory_builder_create(p->meta); | 643 | if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) && |
625 | dirpos = p->data.dir.entries; | 644 | (dirpos->data.file.file_size > 0)) |
626 | while (NULL != dirpos) | 645 | { |
646 | raw_data = GNUNET_malloc (dirpos->data.file.file_size); | ||
647 | emsg = NULL; | ||
648 | if (dirpos->data.file.file_size != | ||
649 | dirpos->data.file.reader (dirpos->data.file.reader_cls, 0, | ||
650 | dirpos->data.file.file_size, raw_data, | ||
651 | &emsg)) | ||
627 | { | 652 | { |
628 | if (GNUNET_YES == dirpos->is_directory) | 653 | GNUNET_free_non_null (emsg); |
629 | { | 654 | GNUNET_free (raw_data); |
630 | raw_data = dirpos->data.dir.dir_data; | 655 | raw_data = NULL; |
631 | dirpos->data.dir.dir_data = NULL; | ||
632 | } | ||
633 | else | ||
634 | { | ||
635 | raw_data = NULL; | ||
636 | if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) && | ||
637 | (dirpos->data.file.file_size > 0)) | ||
638 | { | ||
639 | raw_data = GNUNET_malloc(dirpos->data.file.file_size); | ||
640 | emsg = NULL; | ||
641 | if (dirpos->data.file.file_size != | ||
642 | dirpos->data.file.reader(dirpos->data.file.reader_cls, 0, | ||
643 | dirpos->data.file.file_size, raw_data, | ||
644 | &emsg)) | ||
645 | { | ||
646 | GNUNET_free_non_null(emsg); | ||
647 | GNUNET_free(raw_data); | ||
648 | raw_data = NULL; | ||
649 | } | ||
650 | dirpos->data.file.reader(dirpos->data.file.reader_cls, UINT64_MAX, 0, 0, NULL); | ||
651 | } | ||
652 | } | ||
653 | GNUNET_FS_directory_builder_add(db, dirpos->chk_uri, dirpos->meta, | ||
654 | raw_data); | ||
655 | GNUNET_free_non_null(raw_data); | ||
656 | dirpos = dirpos->next; | ||
657 | } | 656 | } |
658 | GNUNET_free_non_null(p->data.dir.dir_data); | 657 | dirpos->data.file.reader (dirpos->data.file.reader_cls, UINT64_MAX, |
659 | p->data.dir.dir_data = NULL; | 658 | 0, 0, NULL); |
660 | p->data.dir.dir_size = 0; | 659 | } |
661 | GNUNET_FS_directory_builder_finish(db, &p->data.dir.dir_size, | ||
662 | &p->data.dir.dir_data); | ||
663 | GNUNET_FS_file_information_sync_(p); | ||
664 | } | 660 | } |
665 | size = (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; | 661 | GNUNET_FS_directory_builder_add (db, dirpos->chk_uri, dirpos->meta, |
666 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 662 | raw_data); |
667 | "Creating tree encoder\n"); | 663 | GNUNET_free_non_null (raw_data); |
668 | p->te = | 664 | dirpos = dirpos->next; |
669 | GNUNET_FS_tree_encoder_create(pc->h, size, pc, &block_reader, | 665 | } |
670 | &block_proc, &progress_proc, | 666 | GNUNET_free_non_null (p->data.dir.dir_data); |
671 | &encode_cont); | 667 | p->data.dir.dir_data = NULL; |
672 | } | 668 | p->data.dir.dir_size = 0; |
673 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 669 | GNUNET_FS_directory_builder_finish (db, &p->data.dir.dir_size, |
674 | "Processing next block from tree\n"); | 670 | &p->data.dir.dir_data); |
675 | GNUNET_FS_tree_encoder_next(p->te); | 671 | GNUNET_FS_file_information_sync_ (p); |
672 | } | ||
673 | size = (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : | ||
674 | p->data.file.file_size; | ||
675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
676 | "Creating tree encoder\n"); | ||
677 | p->te = | ||
678 | GNUNET_FS_tree_encoder_create (pc->h, size, pc, &block_reader, | ||
679 | &block_proc, &progress_proc, | ||
680 | &encode_cont); | ||
681 | } | ||
682 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
683 | "Processing next block from tree\n"); | ||
684 | GNUNET_FS_tree_encoder_next (p->te); | ||
676 | } | 685 | } |
677 | 686 | ||
678 | 687 | ||
@@ -684,17 +693,17 @@ publish_content(struct GNUNET_FS_PublishContext *pc) | |||
684 | * @param msg the response we got | 693 | * @param msg the response we got |
685 | */ | 694 | */ |
686 | static int | 695 | static int |
687 | check_index_start_failed(void *cls, | 696 | check_index_start_failed (void *cls, |
688 | const struct GNUNET_MessageHeader *msg) | 697 | const struct GNUNET_MessageHeader *msg) |
689 | { | 698 | { |
690 | size_t msize = ntohs(msg->size) - sizeof(*msg); | 699 | size_t msize = ntohs (msg->size) - sizeof(*msg); |
691 | const char *emsg = (const char *)&msg[1]; | 700 | const char *emsg = (const char *) &msg[1]; |
692 | 701 | ||
693 | if (emsg[msize - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') | 702 | if (emsg[msize - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') |
694 | { | 703 | { |
695 | GNUNET_break(0); | 704 | GNUNET_break (0); |
696 | return GNUNET_SYSERR; | 705 | return GNUNET_SYSERR; |
697 | } | 706 | } |
698 | return GNUNET_OK; | 707 | return GNUNET_OK; |
699 | } | 708 | } |
700 | 709 | ||
@@ -707,27 +716,27 @@ check_index_start_failed(void *cls, | |||
707 | * @param msg the response we got | 716 | * @param msg the response we got |
708 | */ | 717 | */ |
709 | static void | 718 | static void |
710 | handle_index_start_failed(void *cls, | 719 | handle_index_start_failed (void *cls, |
711 | const struct GNUNET_MessageHeader *msg) | 720 | const struct GNUNET_MessageHeader *msg) |
712 | { | 721 | { |
713 | struct GNUNET_FS_PublishContext *pc = cls; | 722 | struct GNUNET_FS_PublishContext *pc = cls; |
714 | struct GNUNET_FS_FileInformation *p; | 723 | struct GNUNET_FS_FileInformation *p; |
715 | const char *emsg = (const char *)&msg[1]; | 724 | const char *emsg = (const char *) &msg[1]; |
716 | char *msgtxt; | 725 | char *msgtxt; |
717 | 726 | ||
718 | GNUNET_MQ_destroy(pc->mq); | 727 | GNUNET_MQ_destroy (pc->mq); |
719 | pc->mq = NULL; | 728 | pc->mq = NULL; |
720 | p = pc->fi_pos; | 729 | p = pc->fi_pos; |
721 | GNUNET_asprintf(&msgtxt, | 730 | GNUNET_asprintf (&msgtxt, |
722 | _("Can not index file `%s': %s.\n"), | 731 | _ ("Can not index file `%s': %s.\n"), |
723 | p->filename, | 732 | p->filename, |
724 | gettext(emsg)); | 733 | gettext (emsg)); |
725 | signal_publish_error(p, | 734 | signal_publish_error (p, |
726 | pc, | 735 | pc, |
727 | msgtxt); | 736 | msgtxt); |
728 | GNUNET_free(msgtxt); | 737 | GNUNET_free (msgtxt); |
729 | GNUNET_FS_file_information_sync_(p); | 738 | GNUNET_FS_file_information_sync_ (p); |
730 | GNUNET_FS_publish_sync_(pc); | 739 | GNUNET_FS_publish_sync_ (pc); |
731 | } | 740 | } |
732 | 741 | ||
733 | 742 | ||
@@ -739,18 +748,18 @@ handle_index_start_failed(void *cls, | |||
739 | * @param msg the response we got | 748 | * @param msg the response we got |
740 | */ | 749 | */ |
741 | static void | 750 | static void |
742 | handle_index_start_ok(void *cls, | 751 | handle_index_start_ok (void *cls, |
743 | const struct GNUNET_MessageHeader *msg) | 752 | const struct GNUNET_MessageHeader *msg) |
744 | { | 753 | { |
745 | struct GNUNET_FS_PublishContext *pc = cls; | 754 | struct GNUNET_FS_PublishContext *pc = cls; |
746 | struct GNUNET_FS_FileInformation *p; | 755 | struct GNUNET_FS_FileInformation *p; |
747 | 756 | ||
748 | GNUNET_MQ_destroy(pc->mq); | 757 | GNUNET_MQ_destroy (pc->mq); |
749 | pc->mq = NULL; | 758 | pc->mq = NULL; |
750 | p = pc->fi_pos; | 759 | p = pc->fi_pos; |
751 | p->data.file.index_start_confirmed = GNUNET_YES; | 760 | p->data.file.index_start_confirmed = GNUNET_YES; |
752 | GNUNET_FS_file_information_sync_(p); | 761 | GNUNET_FS_file_information_sync_ (p); |
753 | publish_content(pc); | 762 | publish_content (pc); |
754 | } | 763 | } |
755 | 764 | ||
756 | 765 | ||
@@ -763,25 +772,25 @@ handle_index_start_ok(void *cls, | |||
763 | * @param error error code | 772 | * @param error error code |
764 | */ | 773 | */ |
765 | static void | 774 | static void |
766 | index_mq_error_handler(void *cls, | 775 | index_mq_error_handler (void *cls, |
767 | enum GNUNET_MQ_Error error) | 776 | enum GNUNET_MQ_Error error) |
768 | { | 777 | { |
769 | struct GNUNET_FS_PublishContext *pc = cls; | 778 | struct GNUNET_FS_PublishContext *pc = cls; |
770 | struct GNUNET_FS_FileInformation *p; | 779 | struct GNUNET_FS_FileInformation *p; |
771 | 780 | ||
772 | if (NULL != pc->mq) | 781 | if (NULL != pc->mq) |
773 | { | 782 | { |
774 | GNUNET_MQ_destroy(pc->mq); | 783 | GNUNET_MQ_destroy (pc->mq); |
775 | pc->mq = NULL; | 784 | pc->mq = NULL; |
776 | } | 785 | } |
777 | p = pc->fi_pos; | 786 | p = pc->fi_pos; |
778 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 787 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
779 | _("Can not index file `%s': %s. Will try to insert instead.\n"), | 788 | _ ("Can not index file `%s': %s. Will try to insert instead.\n"), |
780 | p->filename, | 789 | p->filename, |
781 | _("error on index-start request to `fs' service")); | 790 | _ ("error on index-start request to `fs' service")); |
782 | p->data.file.do_index = GNUNET_NO; | 791 | p->data.file.do_index = GNUNET_NO; |
783 | GNUNET_FS_file_information_sync_(p); | 792 | GNUNET_FS_file_information_sync_ (p); |
784 | publish_content(pc); | 793 | publish_content (pc); |
785 | } | 794 | } |
786 | 795 | ||
787 | 796 | ||
@@ -793,20 +802,20 @@ index_mq_error_handler(void *cls, | |||
793 | * @param res resulting hash, NULL on error | 802 | * @param res resulting hash, NULL on error |
794 | */ | 803 | */ |
795 | static void | 804 | static void |
796 | hash_for_index_cb(void *cls, | 805 | hash_for_index_cb (void *cls, |
797 | const struct GNUNET_HashCode *res) | 806 | const struct GNUNET_HashCode *res) |
798 | { | 807 | { |
799 | struct GNUNET_FS_PublishContext *pc = cls; | 808 | struct GNUNET_FS_PublishContext *pc = cls; |
800 | struct GNUNET_MQ_MessageHandler handlers[] = { | 809 | struct GNUNET_MQ_MessageHandler handlers[] = { |
801 | GNUNET_MQ_hd_fixed_size(index_start_ok, | 810 | GNUNET_MQ_hd_fixed_size (index_start_ok, |
802 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK, | 811 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK, |
803 | struct GNUNET_MessageHeader, | 812 | struct GNUNET_MessageHeader, |
804 | pc), | 813 | pc), |
805 | GNUNET_MQ_hd_var_size(index_start_failed, | 814 | GNUNET_MQ_hd_var_size (index_start_failed, |
806 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED, | 815 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED, |
807 | struct GNUNET_MessageHeader, | 816 | struct GNUNET_MessageHeader, |
808 | pc), | 817 | pc), |
809 | GNUNET_MQ_handler_end() | 818 | GNUNET_MQ_handler_end () |
810 | }; | 819 | }; |
811 | struct GNUNET_FS_FileInformation *p; | 820 | struct GNUNET_FS_FileInformation *p; |
812 | struct GNUNET_MQ_Envelope *env; | 821 | struct GNUNET_MQ_Envelope *env; |
@@ -819,97 +828,99 @@ hash_for_index_cb(void *cls, | |||
819 | pc->fhc = NULL; | 828 | pc->fhc = NULL; |
820 | p = pc->fi_pos; | 829 | p = pc->fi_pos; |
821 | if (NULL == res) | 830 | if (NULL == res) |
822 | { | 831 | { |
823 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 832 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
824 | _("Can not index file `%s': %s. Will try to insert instead.\n"), | 833 | _ ( |
825 | p->filename, | 834 | "Can not index file `%s': %s. Will try to insert instead.\n"), |
826 | _("failed to compute hash")); | 835 | p->filename, |
827 | p->data.file.do_index = GNUNET_NO; | 836 | _ ("failed to compute hash")); |
828 | GNUNET_FS_file_information_sync_(p); | 837 | p->data.file.do_index = GNUNET_NO; |
829 | publish_content(pc); | 838 | GNUNET_FS_file_information_sync_ (p); |
830 | return; | 839 | publish_content (pc); |
831 | } | 840 | return; |
841 | } | ||
832 | if (GNUNET_YES == p->data.file.index_start_confirmed) | 842 | if (GNUNET_YES == p->data.file.index_start_confirmed) |
833 | { | 843 | { |
834 | publish_content(pc); | 844 | publish_content (pc); |
835 | return; | 845 | return; |
836 | } | 846 | } |
837 | fn = GNUNET_STRINGS_filename_expand(p->filename); | 847 | fn = GNUNET_STRINGS_filename_expand (p->filename); |
838 | GNUNET_assert(fn != NULL); | 848 | GNUNET_assert (fn != NULL); |
839 | slen = strlen(fn) + 1; | 849 | slen = strlen (fn) + 1; |
840 | if (slen >= | 850 | if (slen >= |
841 | GNUNET_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) | 851 | GNUNET_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) |
842 | { | 852 | { |
843 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 853 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
844 | _ | 854 | _ |
845 | ("Can not index file `%s': %s. Will try to insert instead.\n"), | 855 | ("Can not index file `%s': %s. Will try to insert instead.\n"), |
846 | fn, _("filename too long")); | 856 | fn, _ ("filename too long")); |
847 | GNUNET_free(fn); | 857 | GNUNET_free (fn); |
848 | p->data.file.do_index = GNUNET_NO; | 858 | p->data.file.do_index = GNUNET_NO; |
849 | GNUNET_FS_file_information_sync_(p); | 859 | GNUNET_FS_file_information_sync_ (p); |
850 | publish_content(pc); | 860 | publish_content (pc); |
851 | return; | 861 | return; |
852 | } | 862 | } |
853 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
854 | "Hash of indexed file `%s' is `%s'\n", | 864 | "Hash of indexed file `%s' is `%s'\n", |
855 | p->filename, | 865 | p->filename, |
856 | GNUNET_h2s(res)); | 866 | GNUNET_h2s (res)); |
857 | if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | 867 | if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) |
858 | { | 868 | { |
859 | p->data.file.file_id = *res; | 869 | p->data.file.file_id = *res; |
860 | p->data.file.have_hash = GNUNET_YES; | 870 | p->data.file.have_hash = GNUNET_YES; |
861 | p->data.file.index_start_confirmed = GNUNET_YES; | 871 | p->data.file.index_start_confirmed = GNUNET_YES; |
862 | GNUNET_FS_file_information_sync_(p); | 872 | GNUNET_FS_file_information_sync_ (p); |
863 | publish_content(pc); | 873 | publish_content (pc); |
864 | GNUNET_free(fn); | 874 | GNUNET_free (fn); |
865 | return; | 875 | return; |
866 | } | 876 | } |
867 | pc->mq = GNUNET_CLIENT_connect(pc->h->cfg, | 877 | pc->mq = GNUNET_CLIENT_connect (pc->h->cfg, |
868 | "fs", | 878 | "fs", |
869 | handlers, | 879 | handlers, |
870 | &index_mq_error_handler, | 880 | &index_mq_error_handler, |
871 | pc); | 881 | pc); |
872 | if (NULL == pc->mq) | 882 | if (NULL == pc->mq) |
873 | { | 883 | { |
874 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 884 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
875 | _("Can not index file `%s': %s. Will try to insert instead.\n"), | 885 | _ ( |
876 | p->filename, | 886 | "Can not index file `%s': %s. Will try to insert instead.\n"), |
877 | _("could not connect to `fs' service")); | 887 | p->filename, |
878 | p->data.file.do_index = GNUNET_NO; | 888 | _ ("could not connect to `fs' service")); |
879 | publish_content(pc); | 889 | p->data.file.do_index = GNUNET_NO; |
880 | GNUNET_free(fn); | 890 | publish_content (pc); |
881 | return; | 891 | GNUNET_free (fn); |
882 | } | 892 | return; |
893 | } | ||
883 | if (p->data.file.have_hash != GNUNET_YES) | 894 | if (p->data.file.have_hash != GNUNET_YES) |
884 | { | 895 | { |
885 | p->data.file.file_id = *res; | 896 | p->data.file.file_id = *res; |
886 | p->data.file.have_hash = GNUNET_YES; | 897 | p->data.file.have_hash = GNUNET_YES; |
887 | GNUNET_FS_file_information_sync_(p); | 898 | GNUNET_FS_file_information_sync_ (p); |
888 | } | 899 | } |
889 | env = GNUNET_MQ_msg_extra(ism, | 900 | env = GNUNET_MQ_msg_extra (ism, |
890 | slen, | 901 | slen, |
891 | GNUNET_MESSAGE_TYPE_FS_INDEX_START); | 902 | GNUNET_MESSAGE_TYPE_FS_INDEX_START); |
892 | if (GNUNET_OK == | 903 | if (GNUNET_OK == |
893 | GNUNET_DISK_file_get_identifiers(p->filename, | 904 | GNUNET_DISK_file_get_identifiers (p->filename, |
894 | &dev, | 905 | &dev, |
895 | &ino)) | 906 | &ino)) |
896 | { | 907 | { |
897 | ism->device = GNUNET_htonll(dev); | 908 | ism->device = GNUNET_htonll (dev); |
898 | ism->inode = GNUNET_htonll(ino); | 909 | ism->inode = GNUNET_htonll (ino); |
899 | } | 910 | } |
900 | else | 911 | else |
901 | { | 912 | { |
902 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
903 | _("Failed to get file identifiers for `%s'\n"), | 914 | _ ("Failed to get file identifiers for `%s'\n"), |
904 | p->filename); | 915 | p->filename); |
905 | } | 916 | } |
906 | ism->file_id = *res; | 917 | ism->file_id = *res; |
907 | GNUNET_memcpy(&ism[1], | 918 | GNUNET_memcpy (&ism[1], |
908 | fn, | 919 | fn, |
909 | slen); | 920 | slen); |
910 | GNUNET_free(fn); | 921 | GNUNET_free (fn); |
911 | GNUNET_MQ_send(pc->mq, | 922 | GNUNET_MQ_send (pc->mq, |
912 | env); | 923 | env); |
913 | } | 924 | } |
914 | 925 | ||
915 | 926 | ||
@@ -919,27 +930,27 @@ hash_for_index_cb(void *cls, | |||
919 | * @param pc publishing context to do this for | 930 | * @param pc publishing context to do this for |
920 | */ | 931 | */ |
921 | static void | 932 | static void |
922 | publish_kblocks(struct GNUNET_FS_PublishContext *pc) | 933 | publish_kblocks (struct GNUNET_FS_PublishContext *pc) |
923 | { | 934 | { |
924 | struct GNUNET_FS_FileInformation *p; | 935 | struct GNUNET_FS_FileInformation *p; |
925 | 936 | ||
926 | p = pc->fi_pos; | 937 | p = pc->fi_pos; |
927 | /* upload of "p" complete, publish KBlocks! */ | 938 | /* upload of "p" complete, publish KBlocks! */ |
928 | if (NULL != p->keywords) | 939 | if (NULL != p->keywords) |
929 | { | 940 | { |
930 | pc->ksk_pc = GNUNET_FS_publish_ksk(pc->h, | 941 | pc->ksk_pc = GNUNET_FS_publish_ksk (pc->h, |
931 | p->keywords, | 942 | p->keywords, |
932 | p->meta, | 943 | p->meta, |
933 | p->chk_uri, | 944 | p->chk_uri, |
934 | &p->bo, | 945 | &p->bo, |
935 | pc->options, | 946 | pc->options, |
936 | &publish_kblocks_cont, | 947 | &publish_kblocks_cont, |
937 | pc); | 948 | pc); |
938 | } | 949 | } |
939 | else | 950 | else |
940 | { | 951 | { |
941 | publish_kblocks_cont(pc, p->chk_uri, NULL); | 952 | publish_kblocks_cont (pc, p->chk_uri, NULL); |
942 | } | 953 | } |
943 | } | 954 | } |
944 | 955 | ||
945 | 956 | ||
@@ -950,8 +961,8 @@ publish_kblocks(struct GNUNET_FS_PublishContext *pc) | |||
950 | * @param sig the response we got | 961 | * @param sig the response we got |
951 | */ | 962 | */ |
952 | static void | 963 | static void |
953 | handle_signature_response(void *cls, | 964 | handle_signature_response (void *cls, |
954 | const struct ResponseLocSignatureMessage *sig) | 965 | const struct ResponseLocSignatureMessage *sig) |
955 | { | 966 | { |
956 | struct GNUNET_FS_PublishContext *pc = cls; | 967 | struct GNUNET_FS_PublishContext *pc = cls; |
957 | struct GNUNET_FS_FileInformation *p; | 968 | struct GNUNET_FS_FileInformation *p; |
@@ -961,11 +972,11 @@ handle_signature_response(void *cls, | |||
961 | /* p->data.loc.fi kept from CHK before */ | 972 | /* p->data.loc.fi kept from CHK before */ |
962 | p->chk_uri->data.loc.peer = sig->peer; | 973 | p->chk_uri->data.loc.peer = sig->peer; |
963 | p->chk_uri->data.loc.expirationTime | 974 | p->chk_uri->data.loc.expirationTime |
964 | = GNUNET_TIME_absolute_ntoh(sig->expiration_time); | 975 | = GNUNET_TIME_absolute_ntoh (sig->expiration_time); |
965 | p->chk_uri->data.loc.contentSignature = sig->signature; | 976 | p->chk_uri->data.loc.contentSignature = sig->signature; |
966 | GNUNET_FS_file_information_sync_(p); | 977 | GNUNET_FS_file_information_sync_ (p); |
967 | GNUNET_FS_publish_sync_(pc); | 978 | GNUNET_FS_publish_sync_ (pc); |
968 | publish_kblocks(pc); | 979 | publish_kblocks (pc); |
969 | } | 980 | } |
970 | 981 | ||
971 | 982 | ||
@@ -978,19 +989,19 @@ handle_signature_response(void *cls, | |||
978 | * @param error error code | 989 | * @param error error code |
979 | */ | 990 | */ |
980 | static void | 991 | static void |
981 | loc_mq_error_handler(void *cls, | 992 | loc_mq_error_handler (void *cls, |
982 | enum GNUNET_MQ_Error error) | 993 | enum GNUNET_MQ_Error error) |
983 | { | 994 | { |
984 | struct GNUNET_FS_PublishContext *pc = cls; | 995 | struct GNUNET_FS_PublishContext *pc = cls; |
985 | 996 | ||
986 | if (NULL != pc->mq) | 997 | if (NULL != pc->mq) |
987 | { | 998 | { |
988 | GNUNET_MQ_destroy(pc->mq); | 999 | GNUNET_MQ_destroy (pc->mq); |
989 | pc->mq = NULL; | 1000 | pc->mq = NULL; |
990 | } | 1001 | } |
991 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1002 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
992 | _("Can not create LOC URI. Will continue with CHK instead.\n")); | 1003 | _ ("Can not create LOC URI. Will continue with CHK instead.\n")); |
993 | publish_kblocks(pc); | 1004 | publish_kblocks (pc); |
994 | } | 1005 | } |
995 | 1006 | ||
996 | 1007 | ||
@@ -1002,42 +1013,43 @@ loc_mq_error_handler(void *cls, | |||
1002 | * @param pc the publishing context do to this for | 1013 | * @param pc the publishing context do to this for |
1003 | */ | 1014 | */ |
1004 | static void | 1015 | static void |
1005 | create_loc_uri(struct GNUNET_FS_PublishContext *pc) | 1016 | create_loc_uri (struct GNUNET_FS_PublishContext *pc) |
1006 | { | 1017 | { |
1007 | struct GNUNET_MQ_MessageHandler handlers[] = { | 1018 | struct GNUNET_MQ_MessageHandler handlers[] = { |
1008 | GNUNET_MQ_hd_fixed_size(signature_response, | 1019 | GNUNET_MQ_hd_fixed_size (signature_response, |
1009 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE, | 1020 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE, |
1010 | struct ResponseLocSignatureMessage, | 1021 | struct ResponseLocSignatureMessage, |
1011 | pc), | 1022 | pc), |
1012 | GNUNET_MQ_handler_end() | 1023 | GNUNET_MQ_handler_end () |
1013 | }; | 1024 | }; |
1014 | struct GNUNET_MQ_Envelope *env; | 1025 | struct GNUNET_MQ_Envelope *env; |
1015 | struct RequestLocSignatureMessage *req; | 1026 | struct RequestLocSignatureMessage *req; |
1016 | struct GNUNET_FS_FileInformation *p; | 1027 | struct GNUNET_FS_FileInformation *p; |
1017 | 1028 | ||
1018 | if (NULL != pc->mq) | 1029 | if (NULL != pc->mq) |
1019 | GNUNET_MQ_destroy(pc->mq); | 1030 | GNUNET_MQ_destroy (pc->mq); |
1020 | pc->mq = GNUNET_CLIENT_connect(pc->h->cfg, | 1031 | pc->mq = GNUNET_CLIENT_connect (pc->h->cfg, |
1021 | "fs", | 1032 | "fs", |
1022 | handlers, | 1033 | handlers, |
1023 | &loc_mq_error_handler, | 1034 | &loc_mq_error_handler, |
1024 | pc); | 1035 | pc); |
1025 | if (NULL == pc->mq) | 1036 | if (NULL == pc->mq) |
1026 | { | 1037 | { |
1027 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1038 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1028 | _("Can not create LOC URI. Will continue with CHK instead.\n")); | 1039 | _ ( |
1029 | publish_kblocks(pc); | 1040 | "Can not create LOC URI. Will continue with CHK instead.\n")); |
1030 | return; | 1041 | publish_kblocks (pc); |
1031 | } | 1042 | return; |
1043 | } | ||
1032 | p = pc->fi_pos; | 1044 | p = pc->fi_pos; |
1033 | env = GNUNET_MQ_msg(req, | 1045 | env = GNUNET_MQ_msg (req, |
1034 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN); | 1046 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN); |
1035 | req->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 1047 | req->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
1036 | req->expiration_time = GNUNET_TIME_absolute_hton(p->bo.expiration_time); | 1048 | req->expiration_time = GNUNET_TIME_absolute_hton (p->bo.expiration_time); |
1037 | req->chk = p->chk_uri->data.chk.chk; | 1049 | req->chk = p->chk_uri->data.chk.chk; |
1038 | req->file_length = GNUNET_htonll(p->chk_uri->data.chk.file_length); | 1050 | req->file_length = GNUNET_htonll (p->chk_uri->data.chk.file_length); |
1039 | GNUNET_MQ_send(pc->mq, | 1051 | GNUNET_MQ_send (pc->mq, |
1040 | env); | 1052 | env); |
1041 | } | 1053 | } |
1042 | 1054 | ||
1043 | 1055 | ||
@@ -1047,7 +1059,7 @@ create_loc_uri(struct GNUNET_FS_PublishContext *pc) | |||
1047 | * @param cls `struct GNUNET_FS_PublishContext *` identifies the upload | 1059 | * @param cls `struct GNUNET_FS_PublishContext *` identifies the upload |
1048 | */ | 1060 | */ |
1049 | void | 1061 | void |
1050 | GNUNET_FS_publish_main_(void *cls) | 1062 | GNUNET_FS_publish_main_ (void *cls) |
1051 | { | 1063 | { |
1052 | struct GNUNET_FS_PublishContext *pc = cls; | 1064 | struct GNUNET_FS_PublishContext *pc = cls; |
1053 | struct GNUNET_FS_ProgressInfo pi; | 1065 | struct GNUNET_FS_ProgressInfo pi; |
@@ -1057,108 +1069,109 @@ GNUNET_FS_publish_main_(void *cls) | |||
1057 | pc->upload_task = NULL; | 1069 | pc->upload_task = NULL; |
1058 | p = pc->fi_pos; | 1070 | p = pc->fi_pos; |
1059 | if (NULL == p) | 1071 | if (NULL == p) |
1060 | { | 1072 | { |
1061 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1073 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1062 | "Publishing complete, now publishing SKS and KSK blocks.\n"); | 1074 | "Publishing complete, now publishing SKS and KSK blocks.\n"); |
1063 | /* upload of entire hierarchy complete, | 1075 | /* upload of entire hierarchy complete, |
1064 | * publish namespace entries */ | 1076 | * publish namespace entries */ |
1065 | GNUNET_FS_publish_sync_(pc); | 1077 | GNUNET_FS_publish_sync_ (pc); |
1066 | publish_sblock(pc); | 1078 | publish_sblock (pc); |
1067 | return; | 1079 | return; |
1068 | } | 1080 | } |
1069 | /* find starting position */ | 1081 | /* find starting position */ |
1070 | while ((GNUNET_YES == p->is_directory) && | 1082 | while ((GNUNET_YES == p->is_directory) && |
1071 | (NULL != p->data.dir.entries) && | 1083 | (NULL != p->data.dir.entries) && |
1072 | (NULL == p->emsg) && | 1084 | (NULL == p->emsg) && |
1073 | (NULL == p->data.dir.entries->chk_uri)) | 1085 | (NULL == p->data.dir.entries->chk_uri)) |
1074 | { | 1086 | { |
1075 | p = p->data.dir.entries; | 1087 | p = p->data.dir.entries; |
1076 | pc->fi_pos = p; | 1088 | pc->fi_pos = p; |
1077 | GNUNET_FS_publish_sync_(pc); | 1089 | GNUNET_FS_publish_sync_ (pc); |
1078 | } | 1090 | } |
1079 | /* abort on error */ | 1091 | /* abort on error */ |
1080 | if (NULL != p->emsg) | 1092 | if (NULL != p->emsg) |
1081 | { | 1093 | { |
1082 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1094 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1083 | "Error uploading: %s\n", | 1095 | "Error uploading: %s\n", |
1084 | p->emsg); | 1096 | p->emsg); |
1085 | /* error with current file, abort all | 1097 | /* error with current file, abort all |
1086 | * related files as well! */ | 1098 | * related files as well! */ |
1087 | while (NULL != p->dir) | 1099 | while (NULL != p->dir) |
1088 | { | 1100 | { |
1089 | fn = GNUNET_CONTAINER_meta_data_get_by_type(p->meta, | 1101 | fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta, |
1090 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 1102 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
1091 | p = p->dir; | 1103 | p = p->dir; |
1092 | if (fn != NULL) | 1104 | if (fn != NULL) |
1093 | { | 1105 | { |
1094 | GNUNET_asprintf(&p->emsg, | 1106 | GNUNET_asprintf (&p->emsg, |
1095 | _("Recursive upload failed at `%s': %s"), | 1107 | _ ("Recursive upload failed at `%s': %s"), |
1096 | fn, | 1108 | fn, |
1097 | p->emsg); | 1109 | p->emsg); |
1098 | GNUNET_free(fn); | 1110 | GNUNET_free (fn); |
1099 | } | 1111 | } |
1100 | else | 1112 | else |
1101 | { | 1113 | { |
1102 | GNUNET_asprintf(&p->emsg, | 1114 | GNUNET_asprintf (&p->emsg, |
1103 | _("Recursive upload failed: %s"), | 1115 | _ ("Recursive upload failed: %s"), |
1104 | p->emsg); | 1116 | p->emsg); |
1105 | } | 1117 | } |
1106 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 1118 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
1107 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 1119 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
1108 | pi.value.publish.specifics.error.message = p->emsg; | 1120 | pi.value.publish.specifics.error.message = p->emsg; |
1109 | p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); | 1121 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); |
1110 | } | ||
1111 | pc->all_done = GNUNET_YES; | ||
1112 | GNUNET_FS_publish_sync_(pc); | ||
1113 | return; | ||
1114 | } | 1122 | } |
1123 | pc->all_done = GNUNET_YES; | ||
1124 | GNUNET_FS_publish_sync_ (pc); | ||
1125 | return; | ||
1126 | } | ||
1115 | /* handle completion */ | 1127 | /* handle completion */ |
1116 | if (NULL != p->chk_uri) | 1128 | if (NULL != p->chk_uri) |
1117 | { | 1129 | { |
1118 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1119 | "File upload complete, now publishing KSK blocks.\n"); | 1131 | "File upload complete, now publishing KSK blocks.\n"); |
1120 | GNUNET_FS_publish_sync_(pc); | 1132 | GNUNET_FS_publish_sync_ (pc); |
1121 | 1133 | ||
1122 | if ((0 == p->bo.anonymity_level) && | 1134 | if ((0 == p->bo.anonymity_level) && |
1123 | (GNUNET_YES != | 1135 | (GNUNET_YES != |
1124 | GNUNET_FS_uri_test_loc(p->chk_uri))) | 1136 | GNUNET_FS_uri_test_loc (p->chk_uri))) |
1125 | { | 1137 | { |
1126 | /* zero anonymity, box CHK URI in LOC URI */ | 1138 | /* zero anonymity, box CHK URI in LOC URI */ |
1127 | create_loc_uri(pc); | 1139 | create_loc_uri (pc); |
1128 | } | 1140 | } |
1129 | else | 1141 | else |
1130 | { | 1142 | { |
1131 | publish_kblocks(pc); | 1143 | publish_kblocks (pc); |
1132 | } | ||
1133 | return; | ||
1134 | } | 1144 | } |
1145 | return; | ||
1146 | } | ||
1135 | if ((GNUNET_YES != p->is_directory) && (p->data.file.do_index)) | 1147 | if ((GNUNET_YES != p->is_directory) && (p->data.file.do_index)) |
1148 | { | ||
1149 | if (NULL == p->filename) | ||
1136 | { | 1150 | { |
1137 | if (NULL == p->filename) | 1151 | p->data.file.do_index = GNUNET_NO; |
1138 | { | 1152 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1139 | p->data.file.do_index = GNUNET_NO; | 1153 | _ ( |
1140 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1154 | "Can not index file `%s': %s. Will try to insert instead.\n"), |
1141 | _("Can not index file `%s': %s. Will try to insert instead.\n"), | 1155 | "<no-name>", |
1142 | "<no-name>", | 1156 | _ ("needs to be an actual file")); |
1143 | _("needs to be an actual file")); | 1157 | GNUNET_FS_file_information_sync_ (p); |
1144 | GNUNET_FS_file_information_sync_(p); | 1158 | publish_content (pc); |
1145 | publish_content(pc); | ||
1146 | return; | ||
1147 | } | ||
1148 | if (p->data.file.have_hash) | ||
1149 | { | ||
1150 | hash_for_index_cb(pc, &p->data.file.file_id); | ||
1151 | } | ||
1152 | else | ||
1153 | { | ||
1154 | p->start_time = GNUNET_TIME_absolute_get(); | ||
1155 | pc->fhc = | ||
1156 | GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, p->filename, | ||
1157 | HASHING_BLOCKSIZE, &hash_for_index_cb, pc); | ||
1158 | } | ||
1159 | return; | 1159 | return; |
1160 | } | 1160 | } |
1161 | publish_content(pc); | 1161 | if (p->data.file.have_hash) |
1162 | { | ||
1163 | hash_for_index_cb (pc, &p->data.file.file_id); | ||
1164 | } | ||
1165 | else | ||
1166 | { | ||
1167 | p->start_time = GNUNET_TIME_absolute_get (); | ||
1168 | pc->fhc = | ||
1169 | GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, p->filename, | ||
1170 | HASHING_BLOCKSIZE, &hash_for_index_cb, pc); | ||
1171 | } | ||
1172 | return; | ||
1173 | } | ||
1174 | publish_content (pc); | ||
1162 | } | 1175 | } |
1163 | 1176 | ||
1164 | 1177 | ||
@@ -1177,14 +1190,14 @@ GNUNET_FS_publish_main_(void *cls) | |||
1177 | * @return #GNUNET_OK to continue (always) | 1190 | * @return #GNUNET_OK to continue (always) |
1178 | */ | 1191 | */ |
1179 | static int | 1192 | static int |
1180 | fip_signal_start(void *cls, | 1193 | fip_signal_start (void *cls, |
1181 | struct GNUNET_FS_FileInformation *fi, | 1194 | struct GNUNET_FS_FileInformation *fi, |
1182 | uint64_t length, | 1195 | uint64_t length, |
1183 | struct GNUNET_CONTAINER_MetaData *meta, | 1196 | struct GNUNET_CONTAINER_MetaData *meta, |
1184 | struct GNUNET_FS_Uri **uri, | 1197 | struct GNUNET_FS_Uri **uri, |
1185 | struct GNUNET_FS_BlockOptions *bo, | 1198 | struct GNUNET_FS_BlockOptions *bo, |
1186 | int *do_index, | 1199 | int *do_index, |
1187 | void **client_info) | 1200 | void **client_info) |
1188 | { | 1201 | { |
1189 | struct GNUNET_FS_PublishContext *pc = cls; | 1202 | struct GNUNET_FS_PublishContext *pc = cls; |
1190 | struct GNUNET_FS_ProgressInfo pi; | 1203 | struct GNUNET_FS_ProgressInfo pi; |
@@ -1192,52 +1205,52 @@ fip_signal_start(void *cls, | |||
1192 | uint64_t left; | 1205 | uint64_t left; |
1193 | 1206 | ||
1194 | if (GNUNET_YES == pc->skip_next_fi_callback) | 1207 | if (GNUNET_YES == pc->skip_next_fi_callback) |
1195 | { | 1208 | { |
1196 | pc->skip_next_fi_callback = GNUNET_NO; | 1209 | pc->skip_next_fi_callback = GNUNET_NO; |
1197 | return GNUNET_OK; | 1210 | return GNUNET_OK; |
1198 | } | 1211 | } |
1199 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1200 | "Starting publish operation\n"); | 1213 | "Starting publish operation\n"); |
1201 | if (*do_index) | 1214 | if (*do_index) |
1202 | { | 1215 | { |
1203 | /* space for on-demand blocks */ | 1216 | /* space for on-demand blocks */ |
1204 | pc->reserve_space += | 1217 | pc->reserve_space += |
1205 | ((length + DBLOCK_SIZE - | 1218 | ((length + DBLOCK_SIZE |
1206 | 1) / DBLOCK_SIZE) * sizeof(struct OnDemandBlock); | 1219 | - 1) / DBLOCK_SIZE) * sizeof(struct OnDemandBlock); |
1207 | } | 1220 | } |
1208 | else | 1221 | else |
1209 | { | 1222 | { |
1210 | /* space for DBlocks */ | 1223 | /* space for DBlocks */ |
1211 | pc->reserve_space += length; | 1224 | pc->reserve_space += length; |
1212 | } | 1225 | } |
1213 | /* entries for IBlocks and DBlocks, space for IBlocks */ | 1226 | /* entries for IBlocks and DBlocks, space for IBlocks */ |
1214 | left = length; | 1227 | left = length; |
1215 | while (1) | 1228 | while (1) |
1216 | { | 1229 | { |
1217 | left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE; | 1230 | left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE; |
1218 | pc->reserve_entries += left; | 1231 | pc->reserve_entries += left; |
1219 | if (left <= 1) | 1232 | if (left <= 1) |
1220 | break; | 1233 | break; |
1221 | left = left * sizeof(struct ContentHashKey); | 1234 | left = left * sizeof(struct ContentHashKey); |
1222 | pc->reserve_space += left; | 1235 | pc->reserve_space += left; |
1223 | } | 1236 | } |
1224 | pc->reserve_entries++; | 1237 | pc->reserve_entries++; |
1225 | /* entries and space for keywords */ | 1238 | /* entries and space for keywords */ |
1226 | if (NULL != *uri) | 1239 | if (NULL != *uri) |
1227 | { | 1240 | { |
1228 | kc = GNUNET_FS_uri_ksk_get_keyword_count(*uri); | 1241 | kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri); |
1229 | pc->reserve_entries += kc; | 1242 | pc->reserve_entries += kc; |
1230 | pc->reserve_space += GNUNET_MAX_MESSAGE_SIZE * kc; | 1243 | pc->reserve_space += GNUNET_MAX_MESSAGE_SIZE * kc; |
1231 | } | 1244 | } |
1232 | pi.status = GNUNET_FS_STATUS_PUBLISH_START; | 1245 | pi.status = GNUNET_FS_STATUS_PUBLISH_START; |
1233 | *client_info = GNUNET_FS_publish_make_status_(&pi, pc, fi, 0); | 1246 | *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0); |
1234 | GNUNET_FS_file_information_sync_(fi); | 1247 | GNUNET_FS_file_information_sync_ (fi); |
1235 | if ((fi->is_directory) && (fi->dir != NULL)) | 1248 | if ((fi->is_directory) && (fi->dir != NULL)) |
1236 | { | 1249 | { |
1237 | /* We are a directory, and we are not top-level; process entries in directory */ | 1250 | /* We are a directory, and we are not top-level; process entries in directory */ |
1238 | pc->skip_next_fi_callback = GNUNET_YES; | 1251 | pc->skip_next_fi_callback = GNUNET_YES; |
1239 | GNUNET_FS_file_information_inspect(fi, &fip_signal_start, pc); | 1252 | GNUNET_FS_file_information_inspect (fi, &fip_signal_start, pc); |
1240 | } | 1253 | } |
1241 | return GNUNET_OK; | 1254 | return GNUNET_OK; |
1242 | } | 1255 | } |
1243 | 1256 | ||
@@ -1250,39 +1263,40 @@ fip_signal_start(void *cls, | |||
1250 | * @param pc the publish context of which a file is being suspended | 1263 | * @param pc the publish context of which a file is being suspended |
1251 | */ | 1264 | */ |
1252 | static void | 1265 | static void |
1253 | suspend_operation(struct GNUNET_FS_FileInformation *fi, | 1266 | suspend_operation (struct GNUNET_FS_FileInformation *fi, |
1254 | struct GNUNET_FS_PublishContext *pc) | 1267 | struct GNUNET_FS_PublishContext *pc) |
1255 | { | 1268 | { |
1256 | struct GNUNET_FS_ProgressInfo pi; | 1269 | struct GNUNET_FS_ProgressInfo pi; |
1257 | uint64_t off; | 1270 | uint64_t off; |
1258 | 1271 | ||
1259 | if (NULL != pc->ksk_pc) | 1272 | if (NULL != pc->ksk_pc) |
1260 | { | 1273 | { |
1261 | GNUNET_FS_publish_ksk_cancel(pc->ksk_pc); | 1274 | GNUNET_FS_publish_ksk_cancel (pc->ksk_pc); |
1262 | pc->ksk_pc = NULL; | 1275 | pc->ksk_pc = NULL; |
1263 | } | 1276 | } |
1264 | if (NULL != pc->sks_pc) | 1277 | if (NULL != pc->sks_pc) |
1265 | { | 1278 | { |
1266 | GNUNET_FS_publish_sks_cancel(pc->sks_pc); | 1279 | GNUNET_FS_publish_sks_cancel (pc->sks_pc); |
1267 | pc->sks_pc = NULL; | 1280 | pc->sks_pc = NULL; |
1268 | } | 1281 | } |
1269 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1270 | "Suspending publish operation\n"); | 1283 | "Suspending publish operation\n"); |
1271 | GNUNET_free_non_null(fi->serialization); | 1284 | GNUNET_free_non_null (fi->serialization); |
1272 | fi->serialization = NULL; | 1285 | fi->serialization = NULL; |
1273 | off = (NULL == fi->chk_uri) ? 0 : (GNUNET_YES == fi->is_directory) ? fi->data.dir.dir_size : fi->data.file.file_size; | 1286 | off = (NULL == fi->chk_uri) ? 0 : (GNUNET_YES == fi->is_directory) ? |
1287 | fi->data.dir.dir_size : fi->data.file.file_size; | ||
1274 | pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND; | 1288 | pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND; |
1275 | GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, fi, off)); | 1289 | GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off)); |
1276 | if (NULL != pc->qre) | 1290 | if (NULL != pc->qre) |
1277 | { | 1291 | { |
1278 | GNUNET_DATASTORE_cancel(pc->qre); | 1292 | GNUNET_DATASTORE_cancel (pc->qre); |
1279 | pc->qre = NULL; | 1293 | pc->qre = NULL; |
1280 | } | 1294 | } |
1281 | if (NULL != pc->dsh) | 1295 | if (NULL != pc->dsh) |
1282 | { | 1296 | { |
1283 | GNUNET_DATASTORE_disconnect(pc->dsh, GNUNET_NO); | 1297 | GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); |
1284 | pc->dsh = NULL; | 1298 | pc->dsh = NULL; |
1285 | } | 1299 | } |
1286 | pc->rid = 0; | 1300 | pc->rid = 0; |
1287 | } | 1301 | } |
1288 | 1302 | ||
@@ -1302,29 +1316,29 @@ suspend_operation(struct GNUNET_FS_FileInformation *fi, | |||
1302 | * @return #GNUNET_OK to continue (always) | 1316 | * @return #GNUNET_OK to continue (always) |
1303 | */ | 1317 | */ |
1304 | static int | 1318 | static int |
1305 | fip_signal_suspend(void *cls, | 1319 | fip_signal_suspend (void *cls, |
1306 | struct GNUNET_FS_FileInformation *fi, | 1320 | struct GNUNET_FS_FileInformation *fi, |
1307 | uint64_t length, | 1321 | uint64_t length, |
1308 | struct GNUNET_CONTAINER_MetaData *meta, | 1322 | struct GNUNET_CONTAINER_MetaData *meta, |
1309 | struct GNUNET_FS_Uri **uri, | 1323 | struct GNUNET_FS_Uri **uri, |
1310 | struct GNUNET_FS_BlockOptions *bo, | 1324 | struct GNUNET_FS_BlockOptions *bo, |
1311 | int *do_index, | 1325 | int *do_index, |
1312 | void **client_info) | 1326 | void **client_info) |
1313 | { | 1327 | { |
1314 | struct GNUNET_FS_PublishContext *pc = cls; | 1328 | struct GNUNET_FS_PublishContext *pc = cls; |
1315 | 1329 | ||
1316 | if (GNUNET_YES == pc->skip_next_fi_callback) | 1330 | if (GNUNET_YES == pc->skip_next_fi_callback) |
1317 | { | 1331 | { |
1318 | pc->skip_next_fi_callback = GNUNET_NO; | 1332 | pc->skip_next_fi_callback = GNUNET_NO; |
1319 | return GNUNET_OK; | 1333 | return GNUNET_OK; |
1320 | } | 1334 | } |
1321 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) | 1335 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) |
1322 | { | 1336 | { |
1323 | /* process entries in directory */ | 1337 | /* process entries in directory */ |
1324 | pc->skip_next_fi_callback = GNUNET_YES; | 1338 | pc->skip_next_fi_callback = GNUNET_YES; |
1325 | GNUNET_FS_file_information_inspect(fi, &fip_signal_suspend, pc); | 1339 | GNUNET_FS_file_information_inspect (fi, &fip_signal_suspend, pc); |
1326 | } | 1340 | } |
1327 | suspend_operation(fi, pc); | 1341 | suspend_operation (fi, pc); |
1328 | *client_info = NULL; | 1342 | *client_info = NULL; |
1329 | return GNUNET_OK; | 1343 | return GNUNET_OK; |
1330 | } | 1344 | } |
@@ -1337,21 +1351,21 @@ fip_signal_suspend(void *cls, | |||
1337 | * @param cls the `struct GNUNET_FS_PublishContext` to signal for | 1351 | * @param cls the `struct GNUNET_FS_PublishContext` to signal for |
1338 | */ | 1352 | */ |
1339 | void | 1353 | void |
1340 | GNUNET_FS_publish_signal_suspend_(void *cls) | 1354 | GNUNET_FS_publish_signal_suspend_ (void *cls) |
1341 | { | 1355 | { |
1342 | struct GNUNET_FS_PublishContext *pc = cls; | 1356 | struct GNUNET_FS_PublishContext *pc = cls; |
1343 | 1357 | ||
1344 | if (NULL != pc->upload_task) | 1358 | if (NULL != pc->upload_task) |
1345 | { | 1359 | { |
1346 | GNUNET_SCHEDULER_cancel(pc->upload_task); | 1360 | GNUNET_SCHEDULER_cancel (pc->upload_task); |
1347 | pc->upload_task = NULL; | 1361 | pc->upload_task = NULL; |
1348 | } | 1362 | } |
1349 | pc->skip_next_fi_callback = GNUNET_YES; | 1363 | pc->skip_next_fi_callback = GNUNET_YES; |
1350 | GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_suspend, pc); | 1364 | GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_suspend, pc); |
1351 | suspend_operation(pc->fi, pc); | 1365 | suspend_operation (pc->fi, pc); |
1352 | GNUNET_FS_end_top(pc->h, pc->top); | 1366 | GNUNET_FS_end_top (pc->h, pc->top); |
1353 | pc->top = NULL; | 1367 | pc->top = NULL; |
1354 | publish_cleanup(pc); | 1368 | publish_cleanup (pc); |
1355 | } | 1369 | } |
1356 | 1370 | ||
1357 | 1371 | ||
@@ -1365,30 +1379,30 @@ GNUNET_FS_publish_signal_suspend_(void *cls) | |||
1365 | * @param msg error message on error, otherwise NULL | 1379 | * @param msg error message on error, otherwise NULL |
1366 | */ | 1380 | */ |
1367 | static void | 1381 | static void |
1368 | finish_reserve(void *cls, | 1382 | finish_reserve (void *cls, |
1369 | int success, | 1383 | int success, |
1370 | struct GNUNET_TIME_Absolute min_expiration, | 1384 | struct GNUNET_TIME_Absolute min_expiration, |
1371 | const char *msg) | 1385 | const char *msg) |
1372 | { | 1386 | { |
1373 | struct GNUNET_FS_PublishContext *pc = cls; | 1387 | struct GNUNET_FS_PublishContext *pc = cls; |
1374 | 1388 | ||
1375 | pc->qre = NULL; | 1389 | pc->qre = NULL; |
1376 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1377 | "Reservation complete (%d)!\n", | 1391 | "Reservation complete (%d)!\n", |
1378 | success); | 1392 | success); |
1379 | if ((msg != NULL) || (success <= 0)) | 1393 | if ((msg != NULL) || (success <= 0)) |
1380 | { | 1394 | { |
1381 | GNUNET_asprintf(&pc->fi->emsg, | 1395 | GNUNET_asprintf (&pc->fi->emsg, |
1382 | _("Datastore failure: %s"), | 1396 | _ ("Datastore failure: %s"), |
1383 | msg); | 1397 | msg); |
1384 | signal_publish_error(pc->fi, pc, pc->fi->emsg); | 1398 | signal_publish_error (pc->fi, pc, pc->fi->emsg); |
1385 | return; | 1399 | return; |
1386 | } | 1400 | } |
1387 | pc->rid = success; | 1401 | pc->rid = success; |
1388 | GNUNET_assert(NULL == pc->upload_task); | 1402 | GNUNET_assert (NULL == pc->upload_task); |
1389 | pc->upload_task = | 1403 | pc->upload_task = |
1390 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 1404 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
1391 | &GNUNET_FS_publish_main_, pc); | 1405 | &GNUNET_FS_publish_main_, pc); |
1392 | } | 1406 | } |
1393 | 1407 | ||
1394 | 1408 | ||
@@ -1398,7 +1412,7 @@ finish_reserve(void *cls, | |||
1398 | * @param fi file structure to traverse | 1412 | * @param fi file structure to traverse |
1399 | */ | 1413 | */ |
1400 | static uint64_t | 1414 | static uint64_t |
1401 | compute_contents_size(struct GNUNET_FS_FileInformation *fi) | 1415 | compute_contents_size (struct GNUNET_FS_FileInformation *fi) |
1402 | { | 1416 | { |
1403 | struct GNUNET_FS_FileInformation *ent; | 1417 | struct GNUNET_FS_FileInformation *ent; |
1404 | 1418 | ||
@@ -1406,7 +1420,7 @@ compute_contents_size(struct GNUNET_FS_FileInformation *fi) | |||
1406 | return fi->data.file.file_size; | 1420 | return fi->data.file.file_size; |
1407 | fi->data.dir.contents_size = 0; | 1421 | fi->data.dir.contents_size = 0; |
1408 | for (ent = fi->data.dir.entries; NULL != ent; ent = ent->next) | 1422 | for (ent = fi->data.dir.entries; NULL != ent; ent = ent->next) |
1409 | fi->data.dir.contents_size += compute_contents_size(ent); | 1423 | fi->data.dir.contents_size += compute_contents_size (ent); |
1410 | return fi->data.dir.contents_size; | 1424 | return fi->data.dir.contents_size; |
1411 | } | 1425 | } |
1412 | 1426 | ||
@@ -1425,67 +1439,68 @@ compute_contents_size(struct GNUNET_FS_FileInformation *fi) | |||
1425 | * @return context that can be used to control the publish operation | 1439 | * @return context that can be used to control the publish operation |
1426 | */ | 1440 | */ |
1427 | struct GNUNET_FS_PublishContext * | 1441 | struct GNUNET_FS_PublishContext * |
1428 | GNUNET_FS_publish_start(struct GNUNET_FS_Handle *h, | 1442 | GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, |
1429 | struct GNUNET_FS_FileInformation *fi, | 1443 | struct GNUNET_FS_FileInformation *fi, |
1430 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 1444 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
1431 | const char *nid, | 1445 | const char *nid, |
1432 | const char *nuid, | 1446 | const char *nuid, |
1433 | enum GNUNET_FS_PublishOptions options) | 1447 | enum GNUNET_FS_PublishOptions options) |
1434 | { | 1448 | { |
1435 | struct GNUNET_FS_PublishContext *ret; | 1449 | struct GNUNET_FS_PublishContext *ret; |
1436 | struct GNUNET_DATASTORE_Handle *dsh; | 1450 | struct GNUNET_DATASTORE_Handle *dsh; |
1437 | 1451 | ||
1438 | GNUNET_assert(NULL != h); | 1452 | GNUNET_assert (NULL != h); |
1439 | compute_contents_size(fi); | 1453 | compute_contents_size (fi); |
1440 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | 1454 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) |
1441 | { | 1455 | { |
1442 | dsh = GNUNET_DATASTORE_connect(h->cfg); | 1456 | dsh = GNUNET_DATASTORE_connect (h->cfg); |
1443 | if (NULL == dsh) | 1457 | if (NULL == dsh) |
1444 | return NULL; | 1458 | return NULL; |
1445 | } | 1459 | } |
1446 | else | 1460 | else |
1447 | { | 1461 | { |
1448 | dsh = NULL; | 1462 | dsh = NULL; |
1449 | } | 1463 | } |
1450 | ret = GNUNET_new(struct GNUNET_FS_PublishContext); | 1464 | ret = GNUNET_new (struct GNUNET_FS_PublishContext); |
1451 | ret->dsh = dsh; | 1465 | ret->dsh = dsh; |
1452 | ret->h = h; | 1466 | ret->h = h; |
1453 | ret->fi = fi; | 1467 | ret->fi = fi; |
1454 | if (NULL != ns) | 1468 | if (NULL != ns) |
1455 | { | 1469 | { |
1456 | ret->ns = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); | 1470 | ret->ns = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); |
1457 | *ret->ns = *ns; | 1471 | *ret->ns = *ns; |
1458 | GNUNET_assert(NULL != nid); | 1472 | GNUNET_assert (NULL != nid); |
1459 | ret->nid = GNUNET_strdup(nid); | 1473 | ret->nid = GNUNET_strdup (nid); |
1460 | if (NULL != nuid) | 1474 | if (NULL != nuid) |
1461 | ret->nuid = GNUNET_strdup(nuid); | 1475 | ret->nuid = GNUNET_strdup (nuid); |
1462 | } | 1476 | } |
1463 | ret->options = options; | 1477 | ret->options = options; |
1464 | /* signal start */ | 1478 | /* signal start */ |
1465 | GNUNET_FS_file_information_inspect(ret->fi, &fip_signal_start, ret); | 1479 | GNUNET_FS_file_information_inspect (ret->fi, &fip_signal_start, ret); |
1466 | ret->fi_pos = ret->fi; | 1480 | ret->fi_pos = ret->fi; |
1467 | ret->top = GNUNET_FS_make_top(h, &GNUNET_FS_publish_signal_suspend_, ret); | 1481 | ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret); |
1468 | GNUNET_FS_publish_sync_(ret); | 1482 | GNUNET_FS_publish_sync_ (ret); |
1469 | if (NULL != ret->dsh) | 1483 | if (NULL != ret->dsh) |
1470 | { | 1484 | { |
1471 | GNUNET_assert(NULL == ret->qre); | 1485 | GNUNET_assert (NULL == ret->qre); |
1472 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1486 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1473 | _("Reserving space for %u entries and %llu bytes for publication\n"), | 1487 | _ ( |
1474 | (unsigned int)ret->reserve_entries, | 1488 | "Reserving space for %u entries and %llu bytes for publication\n"), |
1475 | (unsigned long long)ret->reserve_space); | 1489 | (unsigned int) ret->reserve_entries, |
1476 | ret->qre = | 1490 | (unsigned long long) ret->reserve_space); |
1477 | GNUNET_DATASTORE_reserve(ret->dsh, ret->reserve_space, | 1491 | ret->qre = |
1478 | ret->reserve_entries, | 1492 | GNUNET_DATASTORE_reserve (ret->dsh, ret->reserve_space, |
1479 | &finish_reserve, | 1493 | ret->reserve_entries, |
1480 | ret); | 1494 | &finish_reserve, |
1481 | } | 1495 | ret); |
1496 | } | ||
1482 | else | 1497 | else |
1483 | { | 1498 | { |
1484 | GNUNET_assert(NULL == ret->upload_task); | 1499 | GNUNET_assert (NULL == ret->upload_task); |
1485 | ret->upload_task = | 1500 | ret->upload_task = |
1486 | GNUNET_SCHEDULER_add_with_priority | 1501 | GNUNET_SCHEDULER_add_with_priority |
1487 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret); | 1502 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret); |
1488 | } | 1503 | } |
1489 | return ret; | 1504 | return ret; |
1490 | } | 1505 | } |
1491 | 1506 | ||
@@ -1505,39 +1520,39 @@ GNUNET_FS_publish_start(struct GNUNET_FS_Handle *h, | |||
1505 | * @return #GNUNET_OK to continue (always) | 1520 | * @return #GNUNET_OK to continue (always) |
1506 | */ | 1521 | */ |
1507 | static int | 1522 | static int |
1508 | fip_signal_stop(void *cls, | 1523 | fip_signal_stop (void *cls, |
1509 | struct GNUNET_FS_FileInformation *fi, | 1524 | struct GNUNET_FS_FileInformation *fi, |
1510 | uint64_t length, | 1525 | uint64_t length, |
1511 | struct GNUNET_CONTAINER_MetaData *meta, | 1526 | struct GNUNET_CONTAINER_MetaData *meta, |
1512 | struct GNUNET_FS_Uri **uri, | 1527 | struct GNUNET_FS_Uri **uri, |
1513 | struct GNUNET_FS_BlockOptions *bo, | 1528 | struct GNUNET_FS_BlockOptions *bo, |
1514 | int *do_index, void **client_info) | 1529 | int *do_index, void **client_info) |
1515 | { | 1530 | { |
1516 | struct GNUNET_FS_PublishContext *pc = cls; | 1531 | struct GNUNET_FS_PublishContext *pc = cls; |
1517 | struct GNUNET_FS_ProgressInfo pi; | 1532 | struct GNUNET_FS_ProgressInfo pi; |
1518 | uint64_t off; | 1533 | uint64_t off; |
1519 | 1534 | ||
1520 | if (GNUNET_YES == pc->skip_next_fi_callback) | 1535 | if (GNUNET_YES == pc->skip_next_fi_callback) |
1521 | { | 1536 | { |
1522 | pc->skip_next_fi_callback = GNUNET_NO; | 1537 | pc->skip_next_fi_callback = GNUNET_NO; |
1523 | return GNUNET_OK; | 1538 | return GNUNET_OK; |
1524 | } | 1539 | } |
1525 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) | 1540 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) |
1526 | { | 1541 | { |
1527 | /* process entries in directory first */ | 1542 | /* process entries in directory first */ |
1528 | pc->skip_next_fi_callback = GNUNET_YES; | 1543 | pc->skip_next_fi_callback = GNUNET_YES; |
1529 | GNUNET_FS_file_information_inspect(fi, &fip_signal_stop, pc); | 1544 | GNUNET_FS_file_information_inspect (fi, &fip_signal_stop, pc); |
1530 | } | 1545 | } |
1531 | if (NULL != fi->serialization) | 1546 | if (NULL != fi->serialization) |
1532 | { | 1547 | { |
1533 | GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, | 1548 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, |
1534 | fi->serialization); | 1549 | fi->serialization); |
1535 | GNUNET_free(fi->serialization); | 1550 | GNUNET_free (fi->serialization); |
1536 | fi->serialization = NULL; | 1551 | fi->serialization = NULL; |
1537 | } | 1552 | } |
1538 | off = (fi->chk_uri == NULL) ? 0 : length; | 1553 | off = (fi->chk_uri == NULL) ? 0 : length; |
1539 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; | 1554 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; |
1540 | GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, fi, off)); | 1555 | GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off)); |
1541 | *client_info = NULL; | 1556 | *client_info = NULL; |
1542 | return GNUNET_OK; | 1557 | return GNUNET_OK; |
1543 | } | 1558 | } |
@@ -1552,56 +1567,57 @@ fip_signal_stop(void *cls, | |||
1552 | * @param pc context for the upload to stop | 1567 | * @param pc context for the upload to stop |
1553 | */ | 1568 | */ |
1554 | void | 1569 | void |
1555 | GNUNET_FS_publish_stop(struct GNUNET_FS_PublishContext *pc) | 1570 | GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc) |
1556 | { | 1571 | { |
1557 | struct GNUNET_FS_ProgressInfo pi; | 1572 | struct GNUNET_FS_ProgressInfo pi; |
1558 | uint64_t off; | 1573 | uint64_t off; |
1559 | 1574 | ||
1560 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1561 | "Publish stop called\n"); | 1576 | "Publish stop called\n"); |
1562 | GNUNET_FS_end_top(pc->h, pc->top); | 1577 | GNUNET_FS_end_top (pc->h, pc->top); |
1563 | if (NULL != pc->ksk_pc) | 1578 | if (NULL != pc->ksk_pc) |
1564 | { | 1579 | { |
1565 | GNUNET_FS_publish_ksk_cancel(pc->ksk_pc); | 1580 | GNUNET_FS_publish_ksk_cancel (pc->ksk_pc); |
1566 | pc->ksk_pc = NULL; | 1581 | pc->ksk_pc = NULL; |
1567 | } | 1582 | } |
1568 | if (NULL != pc->sks_pc) | 1583 | if (NULL != pc->sks_pc) |
1569 | { | 1584 | { |
1570 | GNUNET_FS_publish_sks_cancel(pc->sks_pc); | 1585 | GNUNET_FS_publish_sks_cancel (pc->sks_pc); |
1571 | pc->sks_pc = NULL; | 1586 | pc->sks_pc = NULL; |
1572 | } | 1587 | } |
1573 | if (NULL != pc->upload_task) | 1588 | if (NULL != pc->upload_task) |
1574 | { | 1589 | { |
1575 | GNUNET_SCHEDULER_cancel(pc->upload_task); | 1590 | GNUNET_SCHEDULER_cancel (pc->upload_task); |
1576 | pc->upload_task = NULL; | 1591 | pc->upload_task = NULL; |
1577 | } | 1592 | } |
1578 | pc->skip_next_fi_callback = GNUNET_YES; | 1593 | pc->skip_next_fi_callback = GNUNET_YES; |
1579 | GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_stop, pc); | 1594 | GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_stop, pc); |
1580 | 1595 | ||
1581 | if (NULL != pc->fi->serialization) | 1596 | if (NULL != pc->fi->serialization) |
1582 | { | 1597 | { |
1583 | GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, | 1598 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, |
1584 | pc->fi->serialization); | 1599 | pc->fi->serialization); |
1585 | GNUNET_free(pc->fi->serialization); | 1600 | GNUNET_free (pc->fi->serialization); |
1586 | pc->fi->serialization = NULL; | 1601 | pc->fi->serialization = NULL; |
1587 | } | 1602 | } |
1588 | off = (NULL == pc->fi->chk_uri) ? 0 : GNUNET_ntohll(pc->fi->chk_uri->data.chk.file_length); | 1603 | off = (NULL == pc->fi->chk_uri) ? 0 : GNUNET_ntohll ( |
1604 | pc->fi->chk_uri->data.chk.file_length); | ||
1589 | 1605 | ||
1590 | if (NULL != pc->serialization) | 1606 | if (NULL != pc->serialization) |
1591 | { | 1607 | { |
1592 | GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1608 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
1593 | pc->serialization); | 1609 | pc->serialization); |
1594 | GNUNET_free(pc->serialization); | 1610 | GNUNET_free (pc->serialization); |
1595 | pc->serialization = NULL; | 1611 | pc->serialization = NULL; |
1596 | } | 1612 | } |
1597 | if (NULL != pc->qre) | 1613 | if (NULL != pc->qre) |
1598 | { | 1614 | { |
1599 | GNUNET_DATASTORE_cancel(pc->qre); | 1615 | GNUNET_DATASTORE_cancel (pc->qre); |
1600 | pc->qre = NULL; | 1616 | pc->qre = NULL; |
1601 | } | 1617 | } |
1602 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; | 1618 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; |
1603 | GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, pc->fi, off)); | 1619 | GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi, off)); |
1604 | publish_cleanup(pc); | 1620 | publish_cleanup (pc); |
1605 | } | 1621 | } |
1606 | 1622 | ||
1607 | 1623 | ||
diff --git a/src/fs/fs_publish_ksk.c b/src/fs/fs_publish_ksk.c index 151b8256c..372ac705d 100644 --- a/src/fs/fs_publish_ksk.c +++ b/src/fs/fs_publish_ksk.c | |||
@@ -38,7 +38,8 @@ | |||
38 | /** | 38 | /** |
39 | * Context for the KSK publication. | 39 | * Context for the KSK publication. |
40 | */ | 40 | */ |
41 | struct GNUNET_FS_PublishKskContext { | 41 | struct GNUNET_FS_PublishKskContext |
42 | { | ||
42 | /** | 43 | /** |
43 | * Keywords to use. | 44 | * Keywords to use. |
44 | */ | 45 | */ |
@@ -72,7 +73,7 @@ struct GNUNET_FS_PublishKskContext { | |||
72 | /** | 73 | /** |
73 | * Current task. | 74 | * Current task. |
74 | */ | 75 | */ |
75 | struct GNUNET_SCHEDULER_Task * ksk_task; | 76 | struct GNUNET_SCHEDULER_Task *ksk_task; |
76 | 77 | ||
77 | /** | 78 | /** |
78 | * Function to call once we're done. | 79 | * Function to call once we're done. |
@@ -109,7 +110,7 @@ struct GNUNET_FS_PublishKskContext { | |||
109 | * @param cls closure of type `struct PublishKskContext *` | 110 | * @param cls closure of type `struct PublishKskContext *` |
110 | */ | 111 | */ |
111 | static void | 112 | static void |
112 | publish_ksk_cont(void *cls); | 113 | publish_ksk_cont (void *cls); |
113 | 114 | ||
114 | 115 | ||
115 | /** | 116 | /** |
@@ -120,21 +121,21 @@ publish_ksk_cont(void *cls); | |||
120 | * @param msg error message (or NULL) | 121 | * @param msg error message (or NULL) |
121 | */ | 122 | */ |
122 | static void | 123 | static void |
123 | kb_put_cont(void *cls, | 124 | kb_put_cont (void *cls, |
124 | const char *msg) | 125 | const char *msg) |
125 | { | 126 | { |
126 | struct GNUNET_FS_PublishKskContext *pkc = cls; | 127 | struct GNUNET_FS_PublishKskContext *pkc = cls; |
127 | 128 | ||
128 | pkc->uc = NULL; | 129 | pkc->uc = NULL; |
129 | if (NULL != msg) | 130 | if (NULL != msg) |
130 | { | 131 | { |
131 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
132 | "KBlock PUT operation failed: %s\n", msg); | 133 | "KBlock PUT operation failed: %s\n", msg); |
133 | pkc->cont(pkc->cont_cls, NULL, msg); | 134 | pkc->cont (pkc->cont_cls, NULL, msg); |
134 | GNUNET_FS_publish_ksk_cancel(pkc); | 135 | GNUNET_FS_publish_ksk_cancel (pkc); |
135 | return; | 136 | return; |
136 | } | 137 | } |
137 | pkc->ksk_task = GNUNET_SCHEDULER_add_now(&publish_ksk_cont, pkc); | 138 | pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc); |
138 | } | 139 | } |
139 | 140 | ||
140 | 141 | ||
@@ -145,7 +146,7 @@ kb_put_cont(void *cls, | |||
145 | * @param cls closure of type `struct GNUNET_FS_PublishKskContext *` | 146 | * @param cls closure of type `struct GNUNET_FS_PublishKskContext *` |
146 | */ | 147 | */ |
147 | static void | 148 | static void |
148 | publish_ksk_cont(void *cls) | 149 | publish_ksk_cont (void *cls) |
149 | { | 150 | { |
150 | struct GNUNET_FS_PublishKskContext *pkc = cls; | 151 | struct GNUNET_FS_PublishKskContext *pkc = cls; |
151 | const char *keyword; | 152 | const char *keyword; |
@@ -153,25 +154,25 @@ publish_ksk_cont(void *cls) | |||
153 | pkc->ksk_task = NULL; | 154 | pkc->ksk_task = NULL; |
154 | if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || | 155 | if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || |
155 | (NULL == pkc->dsh)) | 156 | (NULL == pkc->dsh)) |
156 | { | 157 | { |
157 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
158 | "KSK PUT operation complete\n"); | 159 | "KSK PUT operation complete\n"); |
159 | pkc->cont(pkc->cont_cls, pkc->ksk_uri, | 160 | pkc->cont (pkc->cont_cls, pkc->ksk_uri, |
160 | NULL); | 161 | NULL); |
161 | GNUNET_FS_publish_ksk_cancel(pkc); | 162 | GNUNET_FS_publish_ksk_cancel (pkc); |
162 | return; | 163 | return; |
163 | } | 164 | } |
164 | keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; | 165 | keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; |
165 | pkc->uc = GNUNET_FS_publish_ublock_(pkc->h, | 166 | pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h, |
166 | pkc->dsh, | 167 | pkc->dsh, |
167 | keyword + 1 /* skip '+' */, | 168 | keyword + 1 /* skip '+' */, |
168 | NULL, | 169 | NULL, |
169 | GNUNET_CRYPTO_ecdsa_key_get_anonymous(), | 170 | GNUNET_CRYPTO_ecdsa_key_get_anonymous (), |
170 | pkc->meta, | 171 | pkc->meta, |
171 | pkc->uri, | 172 | pkc->uri, |
172 | &pkc->bo, | 173 | &pkc->bo, |
173 | pkc->options, | 174 | pkc->options, |
174 | &kb_put_cont, pkc); | 175 | &kb_put_cont, pkc); |
175 | } | 176 | } |
176 | 177 | ||
177 | 178 | ||
@@ -189,39 +190,39 @@ publish_ksk_cont(void *cls) | |||
189 | * @return NULL on error ('cont' will still be called) | 190 | * @return NULL on error ('cont' will still be called) |
190 | */ | 191 | */ |
191 | struct GNUNET_FS_PublishKskContext * | 192 | struct GNUNET_FS_PublishKskContext * |
192 | GNUNET_FS_publish_ksk(struct GNUNET_FS_Handle *h, | 193 | GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, |
193 | const struct GNUNET_FS_Uri *ksk_uri, | 194 | const struct GNUNET_FS_Uri *ksk_uri, |
194 | const struct GNUNET_CONTAINER_MetaData *meta, | 195 | const struct GNUNET_CONTAINER_MetaData *meta, |
195 | const struct GNUNET_FS_Uri *uri, | 196 | const struct GNUNET_FS_Uri *uri, |
196 | const struct GNUNET_FS_BlockOptions *bo, | 197 | const struct GNUNET_FS_BlockOptions *bo, |
197 | enum GNUNET_FS_PublishOptions options, | 198 | enum GNUNET_FS_PublishOptions options, |
198 | GNUNET_FS_PublishContinuation cont, void *cont_cls) | 199 | GNUNET_FS_PublishContinuation cont, void *cont_cls) |
199 | { | 200 | { |
200 | struct GNUNET_FS_PublishKskContext *pkc; | 201 | struct GNUNET_FS_PublishKskContext *pkc; |
201 | 202 | ||
202 | GNUNET_assert(NULL != uri); | 203 | GNUNET_assert (NULL != uri); |
203 | pkc = GNUNET_new(struct GNUNET_FS_PublishKskContext); | 204 | pkc = GNUNET_new (struct GNUNET_FS_PublishKskContext); |
204 | pkc->h = h; | 205 | pkc->h = h; |
205 | pkc->bo = *bo; | 206 | pkc->bo = *bo; |
206 | pkc->options = options; | 207 | pkc->options = options; |
207 | pkc->cont = cont; | 208 | pkc->cont = cont; |
208 | pkc->cont_cls = cont_cls; | 209 | pkc->cont_cls = cont_cls; |
209 | pkc->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); | 210 | pkc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
210 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | 211 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) |
212 | { | ||
213 | pkc->dsh = GNUNET_DATASTORE_connect (h->cfg); | ||
214 | if (NULL == pkc->dsh) | ||
211 | { | 215 | { |
212 | pkc->dsh = GNUNET_DATASTORE_connect(h->cfg); | 216 | cont (cont_cls, |
213 | if (NULL == pkc->dsh) | 217 | NULL, |
214 | { | 218 | _ ("Could not connect to datastore.")); |
215 | cont(cont_cls, | 219 | GNUNET_free (pkc); |
216 | NULL, | 220 | return NULL; |
217 | _("Could not connect to datastore.")); | ||
218 | GNUNET_free(pkc); | ||
219 | return NULL; | ||
220 | } | ||
221 | } | 221 | } |
222 | pkc->uri = GNUNET_FS_uri_dup(uri); | 222 | } |
223 | pkc->ksk_uri = GNUNET_FS_uri_dup(ksk_uri); | 223 | pkc->uri = GNUNET_FS_uri_dup (uri); |
224 | pkc->ksk_task = GNUNET_SCHEDULER_add_now(&publish_ksk_cont, pkc); | 224 | pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); |
225 | pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc); | ||
225 | return pkc; | 226 | return pkc; |
226 | } | 227 | } |
227 | 228 | ||
@@ -232,27 +233,27 @@ GNUNET_FS_publish_ksk(struct GNUNET_FS_Handle *h, | |||
232 | * @param pkc context of the operation to abort. | 233 | * @param pkc context of the operation to abort. |
233 | */ | 234 | */ |
234 | void | 235 | void |
235 | GNUNET_FS_publish_ksk_cancel(struct GNUNET_FS_PublishKskContext *pkc) | 236 | GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc) |
236 | { | 237 | { |
237 | if (NULL != pkc->ksk_task) | 238 | if (NULL != pkc->ksk_task) |
238 | { | 239 | { |
239 | GNUNET_SCHEDULER_cancel(pkc->ksk_task); | 240 | GNUNET_SCHEDULER_cancel (pkc->ksk_task); |
240 | pkc->ksk_task = NULL; | 241 | pkc->ksk_task = NULL; |
241 | } | 242 | } |
242 | if (NULL != pkc->uc) | 243 | if (NULL != pkc->uc) |
243 | { | 244 | { |
244 | GNUNET_FS_publish_ublock_cancel_(pkc->uc); | 245 | GNUNET_FS_publish_ublock_cancel_ (pkc->uc); |
245 | pkc->uc = NULL; | 246 | pkc->uc = NULL; |
246 | } | 247 | } |
247 | if (NULL != pkc->dsh) | 248 | if (NULL != pkc->dsh) |
248 | { | 249 | { |
249 | GNUNET_DATASTORE_disconnect(pkc->dsh, GNUNET_NO); | 250 | GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO); |
250 | pkc->dsh = NULL; | 251 | pkc->dsh = NULL; |
251 | } | 252 | } |
252 | GNUNET_CONTAINER_meta_data_destroy(pkc->meta); | 253 | GNUNET_CONTAINER_meta_data_destroy (pkc->meta); |
253 | GNUNET_FS_uri_destroy(pkc->ksk_uri); | 254 | GNUNET_FS_uri_destroy (pkc->ksk_uri); |
254 | GNUNET_FS_uri_destroy(pkc->uri); | 255 | GNUNET_FS_uri_destroy (pkc->uri); |
255 | GNUNET_free(pkc); | 256 | GNUNET_free (pkc); |
256 | } | 257 | } |
257 | 258 | ||
258 | 259 | ||
diff --git a/src/fs/fs_publish_ublock.c b/src/fs/fs_publish_ublock.c index 4dfb4a585..c50e71f0b 100644 --- a/src/fs/fs_publish_ublock.c +++ b/src/fs/fs_publish_ublock.c | |||
@@ -43,21 +43,22 @@ | |||
43 | * @param pub public key to use for key derivation | 43 | * @param pub public key to use for key derivation |
44 | */ | 44 | */ |
45 | static void | 45 | static void |
46 | derive_ublock_encryption_key(struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | 46 | derive_ublock_encryption_key (struct GNUNET_CRYPTO_SymmetricSessionKey *skey, |
47 | struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | 47 | struct GNUNET_CRYPTO_SymmetricInitializationVector |
48 | const char *label, | 48 | *iv, |
49 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) | 49 | const char *label, |
50 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) | ||
50 | { | 51 | { |
51 | struct GNUNET_HashCode key; | 52 | struct GNUNET_HashCode key; |
52 | 53 | ||
53 | /* derive key from 'label' and public key of the namespace */ | 54 | /* derive key from 'label' and public key of the namespace */ |
54 | GNUNET_assert(GNUNET_YES == | 55 | GNUNET_assert (GNUNET_YES == |
55 | GNUNET_CRYPTO_kdf(&key, sizeof(key), | 56 | GNUNET_CRYPTO_kdf (&key, sizeof(key), |
56 | "UBLOCK-ENC", strlen("UBLOCK-ENC"), | 57 | "UBLOCK-ENC", strlen ("UBLOCK-ENC"), |
57 | label, strlen(label), | 58 | label, strlen (label), |
58 | pub, sizeof(*pub), | 59 | pub, sizeof(*pub), |
59 | NULL, 0)); | 60 | NULL, 0)); |
60 | GNUNET_CRYPTO_hash_to_aes_key(&key, skey, iv); | 61 | GNUNET_CRYPTO_hash_to_aes_key (&key, skey, iv); |
61 | } | 62 | } |
62 | 63 | ||
63 | 64 | ||
@@ -71,27 +72,28 @@ derive_ublock_encryption_key(struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | |||
71 | * @param output where to write the result, has input_len bytes | 72 | * @param output where to write the result, has input_len bytes |
72 | */ | 73 | */ |
73 | void | 74 | void |
74 | GNUNET_FS_ublock_decrypt_(const void *input, | 75 | GNUNET_FS_ublock_decrypt_ (const void *input, |
75 | size_t input_len, | 76 | size_t input_len, |
76 | const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, | 77 | const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, |
77 | const char *label, | 78 | const char *label, |
78 | void *output) | 79 | void *output) |
79 | { | 80 | { |
80 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 81 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
81 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 82 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; |
82 | 83 | ||
83 | derive_ublock_encryption_key(&skey, &iv, | 84 | derive_ublock_encryption_key (&skey, &iv, |
84 | label, ns); | 85 | label, ns); |
85 | GNUNET_CRYPTO_symmetric_decrypt(input, input_len, | 86 | GNUNET_CRYPTO_symmetric_decrypt (input, input_len, |
86 | &skey, &iv, | 87 | &skey, &iv, |
87 | output); | 88 | output); |
88 | } | 89 | } |
89 | 90 | ||
90 | 91 | ||
91 | /** | 92 | /** |
92 | * Context for 'ublock_put_cont'. | 93 | * Context for 'ublock_put_cont'. |
93 | */ | 94 | */ |
94 | struct GNUNET_FS_PublishUblockContext { | 95 | struct GNUNET_FS_PublishUblockContext |
96 | { | ||
95 | /** | 97 | /** |
96 | * Function to call when done. | 98 | * Function to call when done. |
97 | */ | 99 | */ |
@@ -110,7 +112,7 @@ struct GNUNET_FS_PublishUblockContext { | |||
110 | /** | 112 | /** |
111 | * Task to run continuation asynchronously. | 113 | * Task to run continuation asynchronously. |
112 | */ | 114 | */ |
113 | struct GNUNET_SCHEDULER_Task * task; | 115 | struct GNUNET_SCHEDULER_Task *task; |
114 | }; | 116 | }; |
115 | 117 | ||
116 | 118 | ||
@@ -127,16 +129,16 @@ struct GNUNET_FS_PublishUblockContext { | |||
127 | * @param msg NULL on success, otherwise an error message | 129 | * @param msg NULL on success, otherwise an error message |
128 | */ | 130 | */ |
129 | static void | 131 | static void |
130 | ublock_put_cont(void *cls, | 132 | ublock_put_cont (void *cls, |
131 | int32_t success, | 133 | int32_t success, |
132 | struct GNUNET_TIME_Absolute min_expiration, | 134 | struct GNUNET_TIME_Absolute min_expiration, |
133 | const char *msg) | 135 | const char *msg) |
134 | { | 136 | { |
135 | struct GNUNET_FS_PublishUblockContext *uc = cls; | 137 | struct GNUNET_FS_PublishUblockContext *uc = cls; |
136 | 138 | ||
137 | uc->qre = NULL; | 139 | uc->qre = NULL; |
138 | uc->cont(uc->cont_cls, msg); | 140 | uc->cont (uc->cont_cls, msg); |
139 | GNUNET_free(uc); | 141 | GNUNET_free (uc); |
140 | } | 142 | } |
141 | 143 | ||
142 | 144 | ||
@@ -146,13 +148,13 @@ ublock_put_cont(void *cls, | |||
146 | * @param cls the `struct GNUNET_FS_PublishUblockContext *` | 148 | * @param cls the `struct GNUNET_FS_PublishUblockContext *` |
147 | */ | 149 | */ |
148 | static void | 150 | static void |
149 | run_cont(void *cls) | 151 | run_cont (void *cls) |
150 | { | 152 | { |
151 | struct GNUNET_FS_PublishUblockContext *uc = cls; | 153 | struct GNUNET_FS_PublishUblockContext *uc = cls; |
152 | 154 | ||
153 | uc->task = NULL; | 155 | uc->task = NULL; |
154 | uc->cont(uc->cont_cls, NULL); | 156 | uc->cont (uc->cont_cls, NULL); |
155 | GNUNET_free(uc); | 157 | GNUNET_free (uc); |
156 | } | 158 | } |
157 | 159 | ||
158 | 160 | ||
@@ -173,16 +175,16 @@ run_cont(void *cls) | |||
173 | * @return NULL on error (@a cont will still be called) | 175 | * @return NULL on error (@a cont will still be called) |
174 | */ | 176 | */ |
175 | struct GNUNET_FS_PublishUblockContext * | 177 | struct GNUNET_FS_PublishUblockContext * |
176 | GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, | 178 | GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, |
177 | struct GNUNET_DATASTORE_Handle *dsh, | 179 | struct GNUNET_DATASTORE_Handle *dsh, |
178 | const char *label, | 180 | const char *label, |
179 | const char *ulabel, | 181 | const char *ulabel, |
180 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 182 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
181 | const struct GNUNET_CONTAINER_MetaData *meta, | 183 | const struct GNUNET_CONTAINER_MetaData *meta, |
182 | const struct GNUNET_FS_Uri *uri, | 184 | const struct GNUNET_FS_Uri *uri, |
183 | const struct GNUNET_FS_BlockOptions *bo, | 185 | const struct GNUNET_FS_BlockOptions *bo, |
184 | enum GNUNET_FS_PublishOptions options, | 186 | enum GNUNET_FS_PublishOptions options, |
185 | GNUNET_FS_UBlockContinuation cont, void *cont_cls) | 187 | GNUNET_FS_UBlockContinuation cont, void *cont_cls) |
186 | { | 188 | { |
187 | struct GNUNET_FS_PublishUblockContext *uc; | 189 | struct GNUNET_FS_PublishUblockContext *uc; |
188 | struct GNUNET_HashCode query; | 190 | struct GNUNET_HashCode query; |
@@ -204,101 +206,101 @@ GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, | |||
204 | if (NULL == meta) | 206 | if (NULL == meta) |
205 | mdsize = 0; | 207 | mdsize = 0; |
206 | else | 208 | else |
207 | mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); | 209 | mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); |
208 | GNUNET_assert(mdsize >= 0); | 210 | GNUNET_assert (mdsize >= 0); |
209 | uris = GNUNET_FS_uri_to_string(uri); | 211 | uris = GNUNET_FS_uri_to_string (uri); |
210 | slen = strlen(uris) + 1; | 212 | slen = strlen (uris) + 1; |
211 | if (NULL == ulabel) | 213 | if (NULL == ulabel) |
212 | ulen = 1; | 214 | ulen = 1; |
213 | else | 215 | else |
214 | ulen = strlen(ulabel) + 1; | 216 | ulen = strlen (ulabel) + 1; |
215 | size = mdsize + sizeof(struct UBlock) + slen + ulen; | 217 | size = mdsize + sizeof(struct UBlock) + slen + ulen; |
216 | if (size > MAX_UBLOCK_SIZE) | 218 | if (size > MAX_UBLOCK_SIZE) |
217 | { | 219 | { |
218 | size = MAX_UBLOCK_SIZE; | 220 | size = MAX_UBLOCK_SIZE; |
219 | mdsize = size - sizeof(struct UBlock) - (slen + ulen); | 221 | mdsize = size - sizeof(struct UBlock) - (slen + ulen); |
220 | } | 222 | } |
221 | ub_plain = GNUNET_malloc(size); | 223 | ub_plain = GNUNET_malloc (size); |
222 | kbe = (char *)&ub_plain[1]; | 224 | kbe = (char *) &ub_plain[1]; |
223 | if (NULL != ulabel) | 225 | if (NULL != ulabel) |
224 | GNUNET_memcpy(kbe, ulabel, ulen); | 226 | GNUNET_memcpy (kbe, ulabel, ulen); |
225 | kbe += ulen; | 227 | kbe += ulen; |
226 | GNUNET_memcpy(kbe, uris, slen); | 228 | GNUNET_memcpy (kbe, uris, slen); |
227 | kbe += slen; | 229 | kbe += slen; |
228 | GNUNET_free(uris); | 230 | GNUNET_free (uris); |
229 | sptr = kbe; | 231 | sptr = kbe; |
230 | if (NULL != meta) | 232 | if (NULL != meta) |
231 | mdsize = | 233 | mdsize = |
232 | GNUNET_CONTAINER_meta_data_serialize(meta, &sptr, mdsize, | 234 | GNUNET_CONTAINER_meta_data_serialize (meta, &sptr, mdsize, |
233 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 235 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
234 | if (-1 == mdsize) | 236 | if (-1 == mdsize) |
235 | { | 237 | { |
236 | GNUNET_break(0); | 238 | GNUNET_break (0); |
237 | GNUNET_free(ub_plain); | 239 | GNUNET_free (ub_plain); |
238 | cont(cont_cls, _("Internal error.")); | 240 | cont (cont_cls, _ ("Internal error.")); |
239 | return NULL; | 241 | return NULL; |
240 | } | 242 | } |
241 | size = sizeof(struct UBlock) + slen + mdsize + ulen; | 243 | size = sizeof(struct UBlock) + slen + mdsize + ulen; |
242 | 244 | ||
243 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
244 | "Publishing under identifier `%s'\n", | 246 | "Publishing under identifier `%s'\n", |
245 | label); | 247 | label); |
246 | /* get public key of the namespace */ | 248 | /* get public key of the namespace */ |
247 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, | 249 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, |
248 | &pub); | 250 | &pub); |
249 | derive_ublock_encryption_key(&skey, &iv, | 251 | derive_ublock_encryption_key (&skey, &iv, |
250 | label, &pub); | 252 | label, &pub); |
251 | 253 | ||
252 | /* encrypt ublock */ | 254 | /* encrypt ublock */ |
253 | ub_enc = GNUNET_malloc(size); | 255 | ub_enc = GNUNET_malloc (size); |
254 | GNUNET_CRYPTO_symmetric_encrypt(&ub_plain[1], | 256 | GNUNET_CRYPTO_symmetric_encrypt (&ub_plain[1], |
255 | ulen + slen + mdsize, | 257 | ulen + slen + mdsize, |
256 | &skey, &iv, | 258 | &skey, &iv, |
257 | &ub_enc[1]); | 259 | &ub_enc[1]); |
258 | GNUNET_free(ub_plain); | 260 | GNUNET_free (ub_plain); |
259 | ub_enc->purpose.size = htonl(ulen + slen + mdsize + | 261 | ub_enc->purpose.size = htonl (ulen + slen + mdsize |
260 | sizeof(struct UBlock) | 262 | + sizeof(struct UBlock) |
261 | - sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); | 263 | - sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); |
262 | ub_enc->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK); | 264 | ub_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK); |
263 | 265 | ||
264 | /* derive signing-key from 'label' and public key of the namespace */ | 266 | /* derive signing-key from 'label' and public key of the namespace */ |
265 | nsd = GNUNET_CRYPTO_ecdsa_private_key_derive(ns, label, "fs-ublock"); | 267 | nsd = GNUNET_CRYPTO_ecdsa_private_key_derive (ns, label, "fs-ublock"); |
266 | GNUNET_CRYPTO_ecdsa_key_get_public(nsd, | 268 | GNUNET_CRYPTO_ecdsa_key_get_public (nsd, |
267 | &ub_enc->verification_key); | 269 | &ub_enc->verification_key); |
268 | GNUNET_assert(GNUNET_OK == | 270 | GNUNET_assert (GNUNET_OK == |
269 | GNUNET_CRYPTO_ecdsa_sign(nsd, | 271 | GNUNET_CRYPTO_ecdsa_sign (nsd, |
270 | &ub_enc->purpose, | 272 | &ub_enc->purpose, |
271 | &ub_enc->signature)); | 273 | &ub_enc->signature)); |
272 | GNUNET_CRYPTO_hash(&ub_enc->verification_key, | 274 | GNUNET_CRYPTO_hash (&ub_enc->verification_key, |
273 | sizeof(ub_enc->verification_key), | 275 | sizeof(ub_enc->verification_key), |
274 | &query); | 276 | &query); |
275 | GNUNET_free(nsd); | 277 | GNUNET_free (nsd); |
276 | 278 | ||
277 | uc = GNUNET_new(struct GNUNET_FS_PublishUblockContext); | 279 | uc = GNUNET_new (struct GNUNET_FS_PublishUblockContext); |
278 | uc->cont = cont; | 280 | uc->cont = cont; |
279 | uc->cont_cls = cont_cls; | 281 | uc->cont_cls = cont_cls; |
280 | if (NULL != dsh) | 282 | if (NULL != dsh) |
281 | { | 283 | { |
282 | uc->qre = | 284 | uc->qre = |
283 | GNUNET_DATASTORE_put(dsh, | 285 | GNUNET_DATASTORE_put (dsh, |
284 | 0, | 286 | 0, |
285 | &query, | 287 | &query, |
286 | ulen + slen + mdsize + sizeof(struct UBlock), | 288 | ulen + slen + mdsize + sizeof(struct UBlock), |
287 | ub_enc, | 289 | ub_enc, |
288 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | 290 | GNUNET_BLOCK_TYPE_FS_UBLOCK, |
289 | bo->content_priority, | 291 | bo->content_priority, |
290 | bo->anonymity_level, | 292 | bo->anonymity_level, |
291 | bo->replication_level, | 293 | bo->replication_level, |
292 | bo->expiration_time, | 294 | bo->expiration_time, |
293 | -2, 1, | 295 | -2, 1, |
294 | &ublock_put_cont, uc); | 296 | &ublock_put_cont, uc); |
295 | } | 297 | } |
296 | else | 298 | else |
297 | { | 299 | { |
298 | uc->task = GNUNET_SCHEDULER_add_now(&run_cont, | 300 | uc->task = GNUNET_SCHEDULER_add_now (&run_cont, |
299 | uc); | 301 | uc); |
300 | } | 302 | } |
301 | GNUNET_free(ub_enc); | 303 | GNUNET_free (ub_enc); |
302 | return uc; | 304 | return uc; |
303 | } | 305 | } |
304 | 306 | ||
@@ -309,13 +311,13 @@ GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, | |||
309 | * @param uc operation to abort. | 311 | * @param uc operation to abort. |
310 | */ | 312 | */ |
311 | void | 313 | void |
312 | GNUNET_FS_publish_ublock_cancel_(struct GNUNET_FS_PublishUblockContext *uc) | 314 | GNUNET_FS_publish_ublock_cancel_ (struct GNUNET_FS_PublishUblockContext *uc) |
313 | { | 315 | { |
314 | if (NULL != uc->qre) | 316 | if (NULL != uc->qre) |
315 | GNUNET_DATASTORE_cancel(uc->qre); | 317 | GNUNET_DATASTORE_cancel (uc->qre); |
316 | if (NULL != uc->task) | 318 | if (NULL != uc->task) |
317 | GNUNET_SCHEDULER_cancel(uc->task); | 319 | GNUNET_SCHEDULER_cancel (uc->task); |
318 | GNUNET_free(uc); | 320 | GNUNET_free (uc); |
319 | } | 321 | } |
320 | 322 | ||
321 | /* end of fs_publish_ublock.c */ | 323 | /* end of fs_publish_ublock.c */ |
diff --git a/src/fs/fs_publish_ublock.h b/src/fs/fs_publish_ublock.h index 9d0a518c6..83c6a50aa 100644 --- a/src/fs/fs_publish_ublock.h +++ b/src/fs/fs_publish_ublock.h | |||
@@ -44,11 +44,11 @@ | |||
44 | * @param output where to write the result, has input_len bytes | 44 | * @param output where to write the result, has input_len bytes |
45 | */ | 45 | */ |
46 | void | 46 | void |
47 | GNUNET_FS_ublock_decrypt_(const void *input, | 47 | GNUNET_FS_ublock_decrypt_ (const void *input, |
48 | size_t input_len, | 48 | size_t input_len, |
49 | const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, | 49 | const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, |
50 | const char *label, | 50 | const char *label, |
51 | void *output); | 51 | void *output); |
52 | 52 | ||
53 | 53 | ||
54 | /** | 54 | /** |
@@ -85,16 +85,16 @@ typedef void (*GNUNET_FS_UBlockContinuation) (void *cls, | |||
85 | * @return NULL on error ('cont' will still be called) | 85 | * @return NULL on error ('cont' will still be called) |
86 | */ | 86 | */ |
87 | struct GNUNET_FS_PublishUblockContext * | 87 | struct GNUNET_FS_PublishUblockContext * |
88 | GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, | 88 | GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, |
89 | struct GNUNET_DATASTORE_Handle *dsh, | 89 | struct GNUNET_DATASTORE_Handle *dsh, |
90 | const char *label, | 90 | const char *label, |
91 | const char *ulabel, | 91 | const char *ulabel, |
92 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 92 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
93 | const struct GNUNET_CONTAINER_MetaData *meta, | 93 | const struct GNUNET_CONTAINER_MetaData *meta, |
94 | const struct GNUNET_FS_Uri *uri, | 94 | const struct GNUNET_FS_Uri *uri, |
95 | const struct GNUNET_FS_BlockOptions *bo, | 95 | const struct GNUNET_FS_BlockOptions *bo, |
96 | enum GNUNET_FS_PublishOptions options, | 96 | enum GNUNET_FS_PublishOptions options, |
97 | GNUNET_FS_UBlockContinuation cont, void *cont_cls); | 97 | GNUNET_FS_UBlockContinuation cont, void *cont_cls); |
98 | 98 | ||
99 | 99 | ||
100 | /** | 100 | /** |
@@ -103,6 +103,6 @@ GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, | |||
103 | * @param uc operation to abort. | 103 | * @param uc operation to abort. |
104 | */ | 104 | */ |
105 | void | 105 | void |
106 | GNUNET_FS_publish_ublock_cancel_(struct GNUNET_FS_PublishUblockContext *uc); | 106 | GNUNET_FS_publish_ublock_cancel_ (struct GNUNET_FS_PublishUblockContext *uc); |
107 | 107 | ||
108 | #endif | 108 | #endif |
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 662bc1619..62ff4e90d 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c | |||
@@ -45,9 +45,9 @@ | |||
45 | * @return value returned by the callback | 45 | * @return value returned by the callback |
46 | */ | 46 | */ |
47 | void * | 47 | void * |
48 | GNUNET_FS_search_make_status_(struct GNUNET_FS_ProgressInfo *pi, | 48 | GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, |
49 | struct GNUNET_FS_Handle *h, | 49 | struct GNUNET_FS_Handle *h, |
50 | struct GNUNET_FS_SearchContext *sc) | 50 | struct GNUNET_FS_SearchContext *sc) |
51 | { | 51 | { |
52 | void *ret; | 52 | void *ret; |
53 | 53 | ||
@@ -59,11 +59,12 @@ GNUNET_FS_search_make_status_(struct GNUNET_FS_ProgressInfo *pi, | |||
59 | : sc->psearch_result->client_info; | 59 | : sc->psearch_result->client_info; |
60 | pi->value.search.query = (NULL != sc) ? sc->uri : NULL; | 60 | pi->value.search.query = (NULL != sc) ? sc->uri : NULL; |
61 | pi->value.search.duration = (NULL != sc) | 61 | pi->value.search.duration = (NULL != sc) |
62 | ? GNUNET_TIME_absolute_get_duration(sc->start_time) | 62 | ? GNUNET_TIME_absolute_get_duration ( |
63 | sc->start_time) | ||
63 | : GNUNET_TIME_UNIT_ZERO; | 64 | : GNUNET_TIME_UNIT_ZERO; |
64 | pi->value.search.anonymity = (NULL != sc) ? sc->anonymity : 0; | 65 | pi->value.search.anonymity = (NULL != sc) ? sc->anonymity : 0; |
65 | pi->fsh = h; | 66 | pi->fsh = h; |
66 | ret = h->upcb(h->upcb_cls, pi); | 67 | ret = h->upcb (h->upcb_cls, pi); |
67 | return ret; | 68 | return ret; |
68 | } | 69 | } |
69 | 70 | ||
@@ -79,14 +80,14 @@ GNUNET_FS_search_make_status_(struct GNUNET_FS_ProgressInfo *pi, | |||
79 | * #GNUNET_OK otherwise | 80 | * #GNUNET_OK otherwise |
80 | */ | 81 | */ |
81 | static int | 82 | static int |
82 | test_result_present(void *cls, | 83 | test_result_present (void *cls, |
83 | const struct GNUNET_HashCode * key, | 84 | const struct GNUNET_HashCode *key, |
84 | void *value) | 85 | void *value) |
85 | { | 86 | { |
86 | const struct GNUNET_FS_Uri *uri = cls; | 87 | const struct GNUNET_FS_Uri *uri = cls; |
87 | struct GNUNET_FS_SearchResult *sr = value; | 88 | struct GNUNET_FS_SearchResult *sr = value; |
88 | 89 | ||
89 | if (GNUNET_FS_uri_test_equal(uri, sr->uri)) | 90 | if (GNUNET_FS_uri_test_equal (uri, sr->uri)) |
90 | return GNUNET_SYSERR; | 91 | return GNUNET_SYSERR; |
91 | return GNUNET_OK; | 92 | return GNUNET_OK; |
92 | } | 93 | } |
@@ -100,8 +101,8 @@ test_result_present(void *cls, | |||
100 | * @param sr the specific result | 101 | * @param sr the specific result |
101 | */ | 102 | */ |
102 | static void | 103 | static void |
103 | notify_client_chk_result(struct GNUNET_FS_SearchContext *sc, | 104 | notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, |
104 | struct GNUNET_FS_SearchResult *sr) | 105 | struct GNUNET_FS_SearchResult *sr) |
105 | { | 106 | { |
106 | struct GNUNET_FS_ProgressInfo pi; | 107 | struct GNUNET_FS_ProgressInfo pi; |
107 | 108 | ||
@@ -110,7 +111,7 @@ notify_client_chk_result(struct GNUNET_FS_SearchContext *sc, | |||
110 | pi.value.search.specifics.result.uri = sr->uri; | 111 | pi.value.search.specifics.result.uri = sr->uri; |
111 | pi.value.search.specifics.result.result = sr; | 112 | pi.value.search.specifics.result.result = sr; |
112 | pi.value.search.specifics.result.applicability_rank = sr->optional_support; | 113 | pi.value.search.specifics.result.applicability_rank = sr->optional_support; |
113 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); | 114 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); |
114 | } | 115 | } |
115 | 116 | ||
116 | 117 | ||
@@ -122,8 +123,8 @@ notify_client_chk_result(struct GNUNET_FS_SearchContext *sc, | |||
122 | * @param sr the specific result | 123 | * @param sr the specific result |
123 | */ | 124 | */ |
124 | static void | 125 | static void |
125 | notify_client_chk_update(struct GNUNET_FS_SearchContext *sc, | 126 | notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, |
126 | struct GNUNET_FS_SearchResult *sr) | 127 | struct GNUNET_FS_SearchResult *sr) |
127 | { | 128 | { |
128 | struct GNUNET_FS_ProgressInfo pi; | 129 | struct GNUNET_FS_ProgressInfo pi; |
129 | 130 | ||
@@ -137,15 +138,16 @@ notify_client_chk_update(struct GNUNET_FS_SearchContext *sc, | |||
137 | sr->availability_trials; | 138 | sr->availability_trials; |
138 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; | 139 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; |
139 | pi.value.search.specifics.update.current_probe_time | 140 | pi.value.search.specifics.update.current_probe_time |
140 | = GNUNET_TIME_absolute_get_duration(sr->probe_active_time); | 141 | = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); |
141 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); | 142 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); |
142 | } | 143 | } |
143 | 144 | ||
144 | 145 | ||
145 | /** | 146 | /** |
146 | * Context for "get_result_present". | 147 | * Context for "get_result_present". |
147 | */ | 148 | */ |
148 | struct GetResultContext { | 149 | struct GetResultContext |
150 | { | ||
149 | /** | 151 | /** |
150 | * The URI we're looking for. | 152 | * The URI we're looking for. |
151 | */ | 153 | */ |
@@ -170,14 +172,14 @@ struct GetResultContext { | |||
170 | * @return #GNUNET_OK | 172 | * @return #GNUNET_OK |
171 | */ | 173 | */ |
172 | static int | 174 | static int |
173 | get_result_present(void *cls, | 175 | get_result_present (void *cls, |
174 | const struct GNUNET_HashCode *key, | 176 | const struct GNUNET_HashCode *key, |
175 | void *value) | 177 | void *value) |
176 | { | 178 | { |
177 | struct GetResultContext *grc = cls; | 179 | struct GetResultContext *grc = cls; |
178 | struct GNUNET_FS_SearchResult *sr = value; | 180 | struct GNUNET_FS_SearchResult *sr = value; |
179 | 181 | ||
180 | if (GNUNET_FS_uri_test_equal(grc->uri, sr->uri)) | 182 | if (GNUNET_FS_uri_test_equal (grc->uri, sr->uri)) |
181 | grc->sr = sr; | 183 | grc->sr = sr; |
182 | return GNUNET_OK; | 184 | return GNUNET_OK; |
183 | } | 185 | } |
@@ -190,7 +192,7 @@ get_result_present(void *cls, | |||
190 | * @param sr search result to signal for | 192 | * @param sr search result to signal for |
191 | */ | 193 | */ |
192 | static void | 194 | static void |
193 | signal_probe_result(struct GNUNET_FS_SearchResult *sr) | 195 | signal_probe_result (struct GNUNET_FS_SearchResult *sr) |
194 | { | 196 | { |
195 | struct GNUNET_FS_ProgressInfo pi; | 197 | struct GNUNET_FS_ProgressInfo pi; |
196 | 198 | ||
@@ -204,9 +206,9 @@ signal_probe_result(struct GNUNET_FS_SearchResult *sr) | |||
204 | = sr->availability_trials; | 206 | = sr->availability_trials; |
205 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; | 207 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; |
206 | pi.value.search.specifics.update.current_probe_time | 208 | pi.value.search.specifics.update.current_probe_time |
207 | = GNUNET_TIME_absolute_get_duration(sr->probe_active_time); | 209 | = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); |
208 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sr->h, sr->sc); | 210 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sr->h, sr->sc); |
209 | GNUNET_FS_search_start_probe_(sr); | 211 | GNUNET_FS_search_start_probe_ (sr); |
210 | } | 212 | } |
211 | 213 | ||
212 | 214 | ||
@@ -216,21 +218,21 @@ signal_probe_result(struct GNUNET_FS_SearchResult *sr) | |||
216 | * @param cls our `struct GNUNET_FS_SearchResult *` | 218 | * @param cls our `struct GNUNET_FS_SearchResult *` |
217 | */ | 219 | */ |
218 | static void | 220 | static void |
219 | probe_failure_handler(void *cls) | 221 | probe_failure_handler (void *cls) |
220 | { | 222 | { |
221 | struct GNUNET_FS_SearchResult *sr = cls; | 223 | struct GNUNET_FS_SearchResult *sr = cls; |
222 | 224 | ||
223 | sr->probe_cancel_task = NULL; | 225 | sr->probe_cancel_task = NULL; |
224 | sr->availability_trials++; | 226 | sr->availability_trials++; |
225 | GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); | 227 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); |
226 | sr->probe_ctx = NULL; | 228 | sr->probe_ctx = NULL; |
227 | GNUNET_FS_stop_probe_ping_task_(sr); | 229 | GNUNET_FS_stop_probe_ping_task_ (sr); |
228 | GNUNET_FS_search_result_sync_(sr); | 230 | GNUNET_FS_search_result_sync_ (sr); |
229 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
230 | "Probe #%u for search result %p failed\n", | 232 | "Probe #%u for search result %p failed\n", |
231 | sr->availability_trials, | 233 | sr->availability_trials, |
232 | sr); | 234 | sr); |
233 | signal_probe_result(sr); | 235 | signal_probe_result (sr); |
234 | } | 236 | } |
235 | 237 | ||
236 | 238 | ||
@@ -240,22 +242,22 @@ probe_failure_handler(void *cls) | |||
240 | * @param cls our `struct GNUNET_FS_SearchResult *` | 242 | * @param cls our `struct GNUNET_FS_SearchResult *` |
241 | */ | 243 | */ |
242 | static void | 244 | static void |
243 | probe_success_handler(void *cls) | 245 | probe_success_handler (void *cls) |
244 | { | 246 | { |
245 | struct GNUNET_FS_SearchResult *sr = cls; | 247 | struct GNUNET_FS_SearchResult *sr = cls; |
246 | 248 | ||
247 | sr->probe_cancel_task = NULL; | 249 | sr->probe_cancel_task = NULL; |
248 | sr->availability_trials++; | 250 | sr->availability_trials++; |
249 | sr->availability_success++; | 251 | sr->availability_success++; |
250 | GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); | 252 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); |
251 | sr->probe_ctx = NULL; | 253 | sr->probe_ctx = NULL; |
252 | GNUNET_FS_stop_probe_ping_task_(sr); | 254 | GNUNET_FS_stop_probe_ping_task_ (sr); |
253 | GNUNET_FS_search_result_sync_(sr); | 255 | GNUNET_FS_search_result_sync_ (sr); |
254 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
255 | "Probe #%u for search result %p succeeded\n", | 257 | "Probe #%u for search result %p succeeded\n", |
256 | sr->availability_trials, | 258 | sr->availability_trials, |
257 | sr); | 259 | sr); |
258 | signal_probe_result(sr); | 260 | signal_probe_result (sr); |
259 | } | 261 | } |
260 | 262 | ||
261 | 263 | ||
@@ -275,91 +277,83 @@ probe_success_handler(void *cls) | |||
275 | * field in the `struct GNUNET_FS_ProgressInfo`. | 277 | * field in the `struct GNUNET_FS_ProgressInfo`. |
276 | */ | 278 | */ |
277 | void * | 279 | void * |
278 | GNUNET_FS_search_probe_progress_(void *cls, | 280 | GNUNET_FS_search_probe_progress_ (void *cls, |
279 | const struct GNUNET_FS_ProgressInfo *info) | 281 | const struct GNUNET_FS_ProgressInfo *info) |
280 | { | 282 | { |
281 | struct GNUNET_FS_SearchResult *sr = info->value.download.cctx; | 283 | struct GNUNET_FS_SearchResult *sr = info->value.download.cctx; |
282 | struct GNUNET_TIME_Relative dur; | 284 | struct GNUNET_TIME_Relative dur; |
283 | 285 | ||
284 | switch (info->status) | 286 | switch (info->status) |
287 | { | ||
288 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
289 | /* ignore */ | ||
290 | break; | ||
291 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: | ||
292 | /* probes should never be resumed */ | ||
293 | GNUNET_assert (0); | ||
294 | break; | ||
295 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: | ||
296 | /* probes should never be suspended */ | ||
297 | GNUNET_break (0); | ||
298 | break; | ||
299 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
300 | /* ignore */ | ||
301 | break; | ||
302 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
303 | if (NULL != sr->probe_cancel_task) | ||
285 | { | 304 | { |
286 | case GNUNET_FS_STATUS_DOWNLOAD_START: | 305 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
287 | /* ignore */ | 306 | sr->probe_cancel_task = NULL; |
288 | break; | 307 | } |
289 | 308 | sr->probe_cancel_task = | |
290 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: | 309 | GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, |
291 | /* probes should never be resumed */ | 310 | &probe_failure_handler, sr); |
292 | GNUNET_assert(0); | 311 | break; |
293 | break; | 312 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
294 | 313 | if (NULL != sr->probe_cancel_task) | |
295 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: | 314 | { |
296 | /* probes should never be suspended */ | 315 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
297 | GNUNET_break(0); | 316 | sr->probe_cancel_task = NULL; |
298 | break; | 317 | } |
299 | 318 | sr->probe_cancel_task = | |
300 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 319 | GNUNET_SCHEDULER_add_now (&probe_success_handler, sr); |
301 | /* ignore */ | 320 | break; |
302 | break; | 321 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: |
303 | 322 | if (NULL != sr->probe_cancel_task) | |
304 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 323 | { |
305 | if (NULL != sr->probe_cancel_task) | 324 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
306 | { | 325 | sr->probe_cancel_task = NULL; |
307 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); | 326 | } |
308 | sr->probe_cancel_task = NULL; | 327 | sr = NULL; |
309 | } | 328 | break; |
329 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
330 | if (NULL == sr->probe_cancel_task) | ||
331 | { | ||
332 | sr->probe_active_time = GNUNET_TIME_absolute_get (); | ||
310 | sr->probe_cancel_task = | 333 | sr->probe_cancel_task = |
311 | GNUNET_SCHEDULER_add_delayed(sr->remaining_probe_time, | 334 | GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, |
312 | &probe_failure_handler, sr); | 335 | &probe_failure_handler, sr); |
313 | break; | 336 | } |
314 | 337 | break; | |
315 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 338 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: |
316 | if (NULL != sr->probe_cancel_task) | 339 | if (NULL != sr->probe_cancel_task) |
317 | { | 340 | { |
318 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); | 341 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
319 | sr->probe_cancel_task = NULL; | 342 | sr->probe_cancel_task = NULL; |
320 | } | 343 | } |
344 | dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); | ||
345 | sr->remaining_probe_time = | ||
346 | GNUNET_TIME_relative_subtract (sr->remaining_probe_time, dur); | ||
347 | if (0 == sr->remaining_probe_time.rel_value_us) | ||
321 | sr->probe_cancel_task = | 348 | sr->probe_cancel_task = |
322 | GNUNET_SCHEDULER_add_now(&probe_success_handler, sr); | 349 | GNUNET_SCHEDULER_add_now (&probe_failure_handler, sr); |
323 | break; | 350 | GNUNET_FS_search_result_sync_ (sr); |
324 | 351 | break; | |
325 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
326 | if (NULL != sr->probe_cancel_task) | ||
327 | { | ||
328 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); | ||
329 | sr->probe_cancel_task = NULL; | ||
330 | } | ||
331 | sr = NULL; | ||
332 | break; | ||
333 | 352 | ||
334 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | 353 | default: |
335 | if (NULL == sr->probe_cancel_task) | 354 | GNUNET_break (0); |
336 | { | 355 | return NULL; |
337 | sr->probe_active_time = GNUNET_TIME_absolute_get(); | 356 | } |
338 | sr->probe_cancel_task = | ||
339 | GNUNET_SCHEDULER_add_delayed(sr->remaining_probe_time, | ||
340 | &probe_failure_handler, sr); | ||
341 | } | ||
342 | break; | ||
343 | |||
344 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
345 | if (NULL != sr->probe_cancel_task) | ||
346 | { | ||
347 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); | ||
348 | sr->probe_cancel_task = NULL; | ||
349 | } | ||
350 | dur = GNUNET_TIME_absolute_get_duration(sr->probe_active_time); | ||
351 | sr->remaining_probe_time = | ||
352 | GNUNET_TIME_relative_subtract(sr->remaining_probe_time, dur); | ||
353 | if (0 == sr->remaining_probe_time.rel_value_us) | ||
354 | sr->probe_cancel_task = | ||
355 | GNUNET_SCHEDULER_add_now(&probe_failure_handler, sr); | ||
356 | GNUNET_FS_search_result_sync_(sr); | ||
357 | break; | ||
358 | |||
359 | default: | ||
360 | GNUNET_break(0); | ||
361 | return NULL; | ||
362 | } | ||
363 | return sr; | 357 | return sr; |
364 | } | 358 | } |
365 | 359 | ||
@@ -370,18 +364,19 @@ GNUNET_FS_search_probe_progress_(void *cls, | |||
370 | * @param cls the `struct GNUNET_FS_SearchResult` that we are probing for | 364 | * @param cls the `struct GNUNET_FS_SearchResult` that we are probing for |
371 | */ | 365 | */ |
372 | static void | 366 | static void |
373 | probe_ping_task_cb(void *cls) | 367 | probe_ping_task_cb (void *cls) |
374 | { | 368 | { |
375 | struct GNUNET_FS_Handle *h = cls; | 369 | struct GNUNET_FS_Handle *h = cls; |
376 | struct GNUNET_FS_SearchResult *sr; | ||
377 | 370 | ||
378 | for (sr = h->probes_head; NULL != sr; sr = sr->next) | 371 | for (struct GNUNET_FS_SearchResult *sr = h->probes_head; |
372 | NULL != sr; | ||
373 | sr = sr->next) | ||
379 | if (NULL != sr->probe_ctx->mq) | 374 | if (NULL != sr->probe_ctx->mq) |
380 | signal_probe_result(sr); | 375 | signal_probe_result (sr); |
381 | h->probe_ping_task | 376 | h->probe_ping_task |
382 | = GNUNET_SCHEDULER_add_delayed(GNUNET_FS_PROBE_UPDATE_FREQUENCY, | 377 | = GNUNET_SCHEDULER_add_delayed (GNUNET_FS_PROBE_UPDATE_FREQUENCY, |
383 | &probe_ping_task_cb, | 378 | &probe_ping_task_cb, |
384 | h); | 379 | h); |
385 | } | 380 | } |
386 | 381 | ||
387 | 382 | ||
@@ -391,17 +386,17 @@ probe_ping_task_cb(void *cls) | |||
391 | * @param sr result to start pinging for. | 386 | * @param sr result to start pinging for. |
392 | */ | 387 | */ |
393 | static void | 388 | static void |
394 | start_probe_ping_task(struct GNUNET_FS_SearchResult *sr) | 389 | start_probe_ping_task (struct GNUNET_FS_SearchResult *sr) |
395 | { | 390 | { |
396 | struct GNUNET_FS_Handle *h = sr->h; | 391 | struct GNUNET_FS_Handle *h = sr->h; |
397 | 392 | ||
398 | GNUNET_CONTAINER_DLL_insert(h->probes_head, | 393 | GNUNET_CONTAINER_DLL_insert (h->probes_head, |
399 | h->probes_tail, | 394 | h->probes_tail, |
400 | sr); | 395 | sr); |
401 | if (NULL == h->probe_ping_task) | 396 | if (NULL == h->probe_ping_task) |
402 | h->probe_ping_task | 397 | h->probe_ping_task |
403 | = GNUNET_SCHEDULER_add_now(&probe_ping_task_cb, | 398 | = GNUNET_SCHEDULER_add_now (&probe_ping_task_cb, |
404 | h); | 399 | h); |
405 | } | 400 | } |
406 | 401 | ||
407 | 402 | ||
@@ -411,18 +406,18 @@ start_probe_ping_task(struct GNUNET_FS_SearchResult *sr) | |||
411 | * @param sr result to start pinging for. | 406 | * @param sr result to start pinging for. |
412 | */ | 407 | */ |
413 | void | 408 | void |
414 | GNUNET_FS_stop_probe_ping_task_(struct GNUNET_FS_SearchResult *sr) | 409 | GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr) |
415 | { | 410 | { |
416 | struct GNUNET_FS_Handle *h = sr->h; | 411 | struct GNUNET_FS_Handle *h = sr->h; |
417 | 412 | ||
418 | GNUNET_CONTAINER_DLL_remove(h->probes_head, | 413 | GNUNET_CONTAINER_DLL_remove (h->probes_head, |
419 | h->probes_tail, | 414 | h->probes_tail, |
420 | sr); | 415 | sr); |
421 | if (NULL == h->probes_head) | 416 | if (NULL == h->probes_head) |
422 | { | 417 | { |
423 | GNUNET_SCHEDULER_cancel(h->probe_ping_task); | 418 | GNUNET_SCHEDULER_cancel (h->probe_ping_task); |
424 | h->probe_ping_task = NULL; | 419 | h->probe_ping_task = NULL; |
425 | } | 420 | } |
426 | } | 421 | } |
427 | 422 | ||
428 | 423 | ||
@@ -432,7 +427,7 @@ GNUNET_FS_stop_probe_ping_task_(struct GNUNET_FS_SearchResult *sr) | |||
432 | * @param sr the search result | 427 | * @param sr the search result |
433 | */ | 428 | */ |
434 | void | 429 | void |
435 | GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr) | 430 | GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) |
436 | { | 431 | { |
437 | uint64_t off; | 432 | uint64_t off; |
438 | uint64_t len; | 433 | uint64_t len; |
@@ -445,35 +440,37 @@ GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr) | |||
445 | return; | 440 | return; |
446 | if (sr->availability_trials > AVAILABILITY_TRIALS_MAX) | 441 | if (sr->availability_trials > AVAILABILITY_TRIALS_MAX) |
447 | return; | 442 | return; |
448 | if ((GNUNET_FS_URI_CHK != sr->uri->type) && (GNUNET_FS_URI_LOC != sr->uri->type)) | 443 | if ( (GNUNET_FS_URI_CHK != sr->uri->type) && |
444 | (GNUNET_FS_URI_LOC != sr->uri->type) ) | ||
449 | return; | 445 | return; |
450 | len = GNUNET_FS_uri_chk_get_file_size(sr->uri); | 446 | len = GNUNET_FS_uri_chk_get_file_size (sr->uri); |
451 | if (0 == len) | 447 | if (0 == len) |
452 | return; | 448 | return; |
453 | if ((len <= DBLOCK_SIZE) && (sr->availability_success > 0)) | 449 | if ((len <= DBLOCK_SIZE) && (sr->availability_success > 0)) |
454 | return; | 450 | return; |
455 | off = len / DBLOCK_SIZE; | 451 | off = len / DBLOCK_SIZE; |
456 | if (off > 0) | 452 | if (off > 0) |
457 | off = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, off); | 453 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, off); |
458 | off *= DBLOCK_SIZE; | 454 | off *= DBLOCK_SIZE; |
459 | if (len - off < DBLOCK_SIZE) | 455 | if (len - off < DBLOCK_SIZE) |
460 | len = len - off; | 456 | len = len - off; |
461 | else | 457 | else |
462 | len = DBLOCK_SIZE; | 458 | len = DBLOCK_SIZE; |
463 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 459 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
464 | "Starting probe #%u (at offset %llu) for search result %p\n", | 460 | "Starting probe #%u (at offset %llu) for search result %p\n", |
465 | sr->availability_trials + 1, | 461 | sr->availability_trials + 1, |
466 | (unsigned long long)off, | 462 | (unsigned long long) off, |
467 | sr); | 463 | sr); |
468 | sr->remaining_probe_time = | 464 | sr->remaining_probe_time = |
469 | GNUNET_TIME_relative_saturating_multiply(sr->h->avg_block_latency, | 465 | GNUNET_TIME_relative_saturating_multiply (sr->h->avg_block_latency, |
470 | 2 * (1 + sr->availability_trials)); | 466 | 2 * (1 |
467 | + sr->availability_trials)); | ||
471 | sr->probe_ctx = | 468 | sr->probe_ctx = |
472 | GNUNET_FS_download_start(sr->h, sr->uri, sr->meta, NULL, NULL, off, | 469 | GNUNET_FS_download_start (sr->h, sr->uri, sr->meta, NULL, NULL, off, |
473 | len, sr->anonymity, | 470 | len, sr->anonymity, |
474 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES | | 471 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES |
475 | GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL); | 472 | | GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL); |
476 | start_probe_ping_task(sr); | 473 | start_probe_ping_task (sr); |
477 | } | 474 | } |
478 | 475 | ||
479 | 476 | ||
@@ -488,23 +485,23 @@ GNUNET_FS_search_start_probe_(struct GNUNET_FS_SearchResult *sr) | |||
488 | * @return the search result handle to access the probe activity | 485 | * @return the search result handle to access the probe activity |
489 | */ | 486 | */ |
490 | struct GNUNET_FS_SearchResult * | 487 | struct GNUNET_FS_SearchResult * |
491 | GNUNET_FS_probe(struct GNUNET_FS_Handle *h, | 488 | GNUNET_FS_probe (struct GNUNET_FS_Handle *h, |
492 | const struct GNUNET_FS_Uri *uri, | 489 | const struct GNUNET_FS_Uri *uri, |
493 | const struct GNUNET_CONTAINER_MetaData *meta, | 490 | const struct GNUNET_CONTAINER_MetaData *meta, |
494 | void *client_info, | 491 | void *client_info, |
495 | uint32_t anonymity) | 492 | uint32_t anonymity) |
496 | { | 493 | { |
497 | struct GNUNET_FS_SearchResult *sr; | 494 | struct GNUNET_FS_SearchResult *sr; |
498 | 495 | ||
499 | GNUNET_assert(NULL != h); | 496 | GNUNET_assert (NULL != h); |
500 | GNUNET_assert(NULL != uri); | 497 | GNUNET_assert (NULL != uri); |
501 | sr = GNUNET_new(struct GNUNET_FS_SearchResult); | 498 | sr = GNUNET_new (struct GNUNET_FS_SearchResult); |
502 | sr->h = h; | 499 | sr->h = h; |
503 | sr->uri = GNUNET_FS_uri_dup(uri); | 500 | sr->uri = GNUNET_FS_uri_dup (uri); |
504 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); | 501 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
505 | sr->client_info = client_info; | 502 | sr->client_info = client_info; |
506 | sr->anonymity = anonymity; | 503 | sr->anonymity = anonymity; |
507 | GNUNET_FS_search_start_probe_(sr); | 504 | GNUNET_FS_search_start_probe_ (sr); |
508 | return sr; | 505 | return sr; |
509 | } | 506 | } |
510 | 507 | ||
@@ -515,19 +512,19 @@ GNUNET_FS_probe(struct GNUNET_FS_Handle *h, | |||
515 | * @param sr search result | 512 | * @param sr search result |
516 | */ | 513 | */ |
517 | static void | 514 | static void |
518 | GNUNET_FS_search_stop_probe_(struct GNUNET_FS_SearchResult *sr) | 515 | GNUNET_FS_search_stop_probe_ (struct GNUNET_FS_SearchResult *sr) |
519 | { | 516 | { |
520 | if (NULL != sr->probe_ctx) | 517 | if (NULL != sr->probe_ctx) |
521 | { | 518 | { |
522 | GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); | 519 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); |
523 | sr->probe_ctx = NULL; | 520 | sr->probe_ctx = NULL; |
524 | GNUNET_FS_stop_probe_ping_task_(sr); | 521 | GNUNET_FS_stop_probe_ping_task_ (sr); |
525 | } | 522 | } |
526 | if (NULL != sr->probe_cancel_task) | 523 | if (NULL != sr->probe_cancel_task) |
527 | { | 524 | { |
528 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); | 525 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
529 | sr->probe_cancel_task = NULL; | 526 | sr->probe_cancel_task = NULL; |
530 | } | 527 | } |
531 | } | 528 | } |
532 | 529 | ||
533 | 530 | ||
@@ -539,16 +536,16 @@ GNUNET_FS_search_stop_probe_(struct GNUNET_FS_SearchResult *sr) | |||
539 | * @return the value of the 'client_info' pointer | 536 | * @return the value of the 'client_info' pointer |
540 | */ | 537 | */ |
541 | void * | 538 | void * |
542 | GNUNET_FS_probe_stop(struct GNUNET_FS_SearchResult *sr) | 539 | GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr) |
543 | { | 540 | { |
544 | void *client_info; | 541 | void *client_info; |
545 | 542 | ||
546 | GNUNET_assert(NULL == sr->sc); | 543 | GNUNET_assert (NULL == sr->sc); |
547 | GNUNET_FS_search_stop_probe_(sr); | 544 | GNUNET_FS_search_stop_probe_ (sr); |
548 | GNUNET_FS_uri_destroy(sr->uri); | 545 | GNUNET_FS_uri_destroy (sr->uri); |
549 | GNUNET_CONTAINER_meta_data_destroy(sr->meta); | 546 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); |
550 | client_info = sr->client_info; | 547 | client_info = sr->client_info; |
551 | GNUNET_free(sr); | 548 | GNUNET_free (sr); |
552 | return client_info; | 549 | return client_info; |
553 | } | 550 | } |
554 | 551 | ||
@@ -564,10 +561,10 @@ GNUNET_FS_probe_stop(struct GNUNET_FS_SearchResult *sr) | |||
564 | * under the @a ent keyword | 561 | * under the @a ent keyword |
565 | */ | 562 | */ |
566 | static void | 563 | static void |
567 | process_ksk_result(struct GNUNET_FS_SearchContext *sc, | 564 | process_ksk_result (struct GNUNET_FS_SearchContext *sc, |
568 | struct SearchRequestEntry *ent, | 565 | struct SearchRequestEntry *ent, |
569 | const struct GNUNET_FS_Uri *uri, | 566 | const struct GNUNET_FS_Uri *uri, |
570 | const struct GNUNET_CONTAINER_MetaData *meta) | 567 | const struct GNUNET_CONTAINER_MetaData *meta) |
571 | { | 568 | { |
572 | struct GNUNET_HashCode key; | 569 | struct GNUNET_HashCode key; |
573 | struct GNUNET_FS_SearchResult *sr; | 570 | struct GNUNET_FS_SearchResult *sr; |
@@ -576,80 +573,81 @@ process_ksk_result(struct GNUNET_FS_SearchContext *sc, | |||
576 | unsigned int koff; | 573 | unsigned int koff; |
577 | 574 | ||
578 | /* check if new */ | 575 | /* check if new */ |
579 | GNUNET_assert(NULL != sc); | 576 | GNUNET_assert (NULL != sc); |
580 | if (GNUNET_OK != | 577 | if (GNUNET_OK != |
581 | GNUNET_FS_uri_to_key(uri, | 578 | GNUNET_FS_uri_to_key (uri, |
582 | &key)) | 579 | &key)) |
583 | { | 580 | { |
584 | GNUNET_break_op(0); | 581 | GNUNET_break_op (0); |
585 | return; | 582 | return; |
586 | } | 583 | } |
587 | if (GNUNET_SYSERR == | 584 | if (GNUNET_SYSERR == |
588 | GNUNET_CONTAINER_multihashmap_get_multiple(ent->results, | 585 | GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, |
589 | &key, | 586 | &key, |
590 | &test_result_present, | 587 | &test_result_present, |
591 | (void *)uri)) | 588 | (void *) uri)) |
592 | return; /* duplicate result */ | 589 | return; /* duplicate result */ |
593 | /* try to find search result in master map */ | 590 | /* try to find search result in master map */ |
594 | grc.sr = NULL; | 591 | grc.sr = NULL; |
595 | grc.uri = uri; | 592 | grc.uri = uri; |
596 | GNUNET_CONTAINER_multihashmap_get_multiple(sc->master_result_map, | 593 | GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, |
597 | &key, | 594 | &key, |
598 | &get_result_present, &grc); | 595 | &get_result_present, &grc); |
599 | sr = grc.sr; | 596 | sr = grc.sr; |
600 | is_new = (NULL == sr) || (sr->mandatory_missing > 0); | 597 | is_new = (NULL == sr) || (sr->mandatory_missing > 0); |
601 | if (NULL == sr) | 598 | if (NULL == sr) |
602 | { | 599 | { |
603 | sr = GNUNET_new(struct GNUNET_FS_SearchResult); | 600 | sr = GNUNET_new (struct GNUNET_FS_SearchResult); |
604 | sr->h = sc->h; | 601 | sr->h = sc->h; |
605 | sr->sc = sc; | 602 | sr->sc = sc; |
606 | sr->anonymity = sc->anonymity; | 603 | sr->anonymity = sc->anonymity; |
607 | sr->uri = GNUNET_FS_uri_dup(uri); | 604 | sr->uri = GNUNET_FS_uri_dup (uri); |
608 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); | 605 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
609 | sr->mandatory_missing = sc->mandatory_count; | 606 | sr->mandatory_missing = sc->mandatory_count; |
610 | sr->key = key; | 607 | sr->key = key; |
611 | sr->keyword_bitmap = GNUNET_malloc((sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ | 608 | sr->keyword_bitmap = GNUNET_malloc ((sc->uri->data.ksk.keywordCount + 7) |
612 | GNUNET_CONTAINER_multihashmap_put(sc->master_result_map, &key, sr, | 609 | / 8); /* round up, count bits */ |
613 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 610 | GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr, |
614 | } | 611 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
612 | } | ||
615 | else | 613 | else |
616 | { | 614 | { |
617 | GNUNET_CONTAINER_meta_data_merge(sr->meta, meta); | 615 | GNUNET_CONTAINER_meta_data_merge (sr->meta, meta); |
618 | } | 616 | } |
619 | GNUNET_break(GNUNET_OK == | 617 | GNUNET_break (GNUNET_OK == |
620 | GNUNET_CONTAINER_multihashmap_put(ent->results, | 618 | GNUNET_CONTAINER_multihashmap_put (ent->results, |
621 | &sr->key, | 619 | &sr->key, |
622 | sr, | 620 | sr, |
623 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 621 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
624 | 622 | ||
625 | koff = ent - sc->requests; | 623 | koff = ent - sc->requests; |
626 | GNUNET_assert((ent >= sc->requests) && | 624 | GNUNET_assert ((ent >= sc->requests) && |
627 | (koff < sc->uri->data.ksk.keywordCount)); | 625 | (koff < sc->uri->data.ksk.keywordCount)); |
628 | sr->keyword_bitmap[koff / 8] |= (1 << (koff % 8)); | 626 | sr->keyword_bitmap[koff / 8] |= (1 << (koff % 8)); |
629 | /* check if mandatory satisfied */ | 627 | /* check if mandatory satisfied */ |
630 | if (1 <= GNUNET_CONTAINER_multihashmap_size(ent->results)) | 628 | if (1 <= GNUNET_CONTAINER_multihashmap_size (ent->results)) |
629 | { | ||
630 | if (ent->mandatory) | ||
631 | { | 631 | { |
632 | if (ent->mandatory) | 632 | GNUNET_break (sr->mandatory_missing > 0); |
633 | { | 633 | sr->mandatory_missing--; |
634 | GNUNET_break(sr->mandatory_missing > 0); | ||
635 | sr->mandatory_missing--; | ||
636 | } | ||
637 | else | ||
638 | { | ||
639 | sr->optional_support++; | ||
640 | } | ||
641 | } | 634 | } |
642 | if (0 != sr->mandatory_missing) | 635 | else |
643 | { | 636 | { |
644 | GNUNET_break(NULL == sr->client_info); | 637 | sr->optional_support++; |
645 | return; | ||
646 | } | 638 | } |
639 | } | ||
640 | if (0 != sr->mandatory_missing) | ||
641 | { | ||
642 | GNUNET_break (NULL == sr->client_info); | ||
643 | return; | ||
644 | } | ||
647 | if (is_new) | 645 | if (is_new) |
648 | notify_client_chk_result(sc, sr); | 646 | notify_client_chk_result (sc, sr); |
649 | else | 647 | else |
650 | notify_client_chk_update(sc, sr); | 648 | notify_client_chk_update (sc, sr); |
651 | GNUNET_FS_search_result_sync_(sr); | 649 | GNUNET_FS_search_result_sync_ (sr); |
652 | GNUNET_FS_search_start_probe_(sr); | 650 | GNUNET_FS_search_start_probe_ (sr); |
653 | } | 651 | } |
654 | 652 | ||
655 | 653 | ||
@@ -666,12 +664,12 @@ process_ksk_result(struct GNUNET_FS_SearchContext *sc, | |||
666 | * @return context that can be used to control the search | 664 | * @return context that can be used to control the search |
667 | */ | 665 | */ |
668 | static struct GNUNET_FS_SearchContext * | 666 | static struct GNUNET_FS_SearchContext * |
669 | search_start(struct GNUNET_FS_Handle *h, | 667 | search_start (struct GNUNET_FS_Handle *h, |
670 | const struct GNUNET_FS_Uri *uri, | 668 | const struct GNUNET_FS_Uri *uri, |
671 | uint32_t anonymity, | 669 | uint32_t anonymity, |
672 | enum GNUNET_FS_SearchOptions options, | 670 | enum GNUNET_FS_SearchOptions options, |
673 | void *cctx, | 671 | void *cctx, |
674 | struct GNUNET_FS_SearchResult *psearch); | 672 | struct GNUNET_FS_SearchResult *psearch); |
675 | 673 | ||
676 | 674 | ||
677 | /** | 675 | /** |
@@ -684,56 +682,56 @@ search_start(struct GNUNET_FS_Handle *h, | |||
684 | * @param meta metadata associated with the URI | 682 | * @param meta metadata associated with the URI |
685 | */ | 683 | */ |
686 | static void | 684 | static void |
687 | process_sks_result(struct GNUNET_FS_SearchContext *sc, | 685 | process_sks_result (struct GNUNET_FS_SearchContext *sc, |
688 | const char *id_update, | 686 | const char *id_update, |
689 | const struct GNUNET_FS_Uri *uri, | 687 | const struct GNUNET_FS_Uri *uri, |
690 | const struct GNUNET_CONTAINER_MetaData *meta) | 688 | const struct GNUNET_CONTAINER_MetaData *meta) |
691 | { | 689 | { |
692 | struct GNUNET_FS_Uri uu; | 690 | struct GNUNET_FS_Uri uu; |
693 | struct GNUNET_HashCode key; | 691 | struct GNUNET_HashCode key; |
694 | struct GNUNET_FS_SearchResult *sr; | 692 | struct GNUNET_FS_SearchResult *sr; |
695 | 693 | ||
696 | /* check if new */ | 694 | /* check if new */ |
697 | GNUNET_assert(NULL != sc); | 695 | GNUNET_assert (NULL != sc); |
698 | if (GNUNET_OK != | 696 | if (GNUNET_OK != |
699 | GNUNET_FS_uri_to_key(uri, | 697 | GNUNET_FS_uri_to_key (uri, |
700 | &key)) | 698 | &key)) |
701 | { | 699 | { |
702 | GNUNET_break(0); | 700 | GNUNET_break (0); |
703 | return; | 701 | return; |
704 | } | 702 | } |
705 | GNUNET_CRYPTO_hash_xor(&uri->data.chk.chk.key, | 703 | GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, |
706 | &uri->data.chk.chk.query, | 704 | &uri->data.chk.chk.query, |
707 | &key); | 705 | &key); |
708 | if (GNUNET_SYSERR == | 706 | if (GNUNET_SYSERR == |
709 | GNUNET_CONTAINER_multihashmap_get_multiple(sc->master_result_map, &key, | 707 | GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key, |
710 | &test_result_present, | 708 | &test_result_present, |
711 | (void *)uri)) | 709 | (void *) uri)) |
712 | return; /* duplicate result */ | 710 | return; /* duplicate result */ |
713 | sr = GNUNET_new(struct GNUNET_FS_SearchResult); | 711 | sr = GNUNET_new (struct GNUNET_FS_SearchResult); |
714 | sr->h = sc->h; | 712 | sr->h = sc->h; |
715 | sr->sc = sc; | 713 | sr->sc = sc; |
716 | sr->anonymity = sc->anonymity; | 714 | sr->anonymity = sc->anonymity; |
717 | sr->uri = GNUNET_FS_uri_dup(uri); | 715 | sr->uri = GNUNET_FS_uri_dup (uri); |
718 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); | 716 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
719 | sr->key = key; | 717 | sr->key = key; |
720 | GNUNET_CONTAINER_multihashmap_put(sc->master_result_map, &key, sr, | 718 | GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr, |
721 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 719 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
722 | GNUNET_FS_search_result_sync_(sr); | 720 | GNUNET_FS_search_result_sync_ (sr); |
723 | GNUNET_FS_search_start_probe_(sr); | 721 | GNUNET_FS_search_start_probe_ (sr); |
724 | /* notify client */ | 722 | /* notify client */ |
725 | if (0 == sr->mandatory_missing) | 723 | if (0 == sr->mandatory_missing) |
726 | notify_client_chk_result(sc, sr); | 724 | notify_client_chk_result (sc, sr); |
727 | else | 725 | else |
728 | GNUNET_break(NULL == sr->client_info); | 726 | GNUNET_break (NULL == sr->client_info); |
729 | /* search for updates */ | 727 | /* search for updates */ |
730 | if (0 == strlen(id_update)) | 728 | if (0 == strlen (id_update)) |
731 | return; /* no updates */ | 729 | return; /* no updates */ |
732 | uu.type = GNUNET_FS_URI_SKS; | 730 | uu.type = GNUNET_FS_URI_SKS; |
733 | uu.data.sks.ns = sc->uri->data.sks.ns; | 731 | uu.data.sks.ns = sc->uri->data.sks.ns; |
734 | uu.data.sks.identifier = GNUNET_strdup(id_update); | 732 | uu.data.sks.identifier = GNUNET_strdup (id_update); |
735 | (void)search_start(sc->h, &uu, sc->anonymity, sc->options, NULL, sr); | 733 | (void) search_start (sc->h, &uu, sc->anonymity, sc->options, NULL, sr); |
736 | GNUNET_free(uu.data.sks.identifier); | 734 | GNUNET_free (uu.data.sks.identifier); |
737 | } | 735 | } |
738 | 736 | ||
739 | 737 | ||
@@ -752,11 +750,11 @@ process_sks_result(struct GNUNET_FS_SearchContext *sc, | |||
752 | * keyword, internal error) | 750 | * keyword, internal error) |
753 | */ | 751 | */ |
754 | static int | 752 | static int |
755 | decrypt_block_with_keyword(const struct GNUNET_FS_SearchContext *sc, | 753 | decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc, |
756 | const struct GNUNET_CRYPTO_EcdsaPublicKey *dpub, | 754 | const struct GNUNET_CRYPTO_EcdsaPublicKey *dpub, |
757 | const void *edata, | 755 | const void *edata, |
758 | size_t edata_size, | 756 | size_t edata_size, |
759 | char *data) | 757 | char *data) |
760 | { | 758 | { |
761 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; | 759 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; |
762 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; | 760 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; |
@@ -764,23 +762,23 @@ decrypt_block_with_keyword(const struct GNUNET_FS_SearchContext *sc, | |||
764 | 762 | ||
765 | /* find key */ | 763 | /* find key */ |
766 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | 764 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
767 | if (0 == memcmp(dpub, | 765 | if (0 == memcmp (dpub, |
768 | &sc->requests[i].dpub, | 766 | &sc->requests[i].dpub, |
769 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | 767 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) |
770 | break; | 768 | break; |
771 | if (i == sc->uri->data.ksk.keywordCount) | 769 | if (i == sc->uri->data.ksk.keywordCount) |
772 | { | 770 | { |
773 | /* oops, does not match any of our keywords!? */ | 771 | /* oops, does not match any of our keywords!? */ |
774 | GNUNET_break(0); | 772 | GNUNET_break (0); |
775 | return GNUNET_SYSERR; | 773 | return GNUNET_SYSERR; |
776 | } | 774 | } |
777 | /* decrypt */ | 775 | /* decrypt */ |
778 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous(); | 776 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); |
779 | GNUNET_CRYPTO_ecdsa_key_get_public(anon, &anon_pub); | 777 | GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub); |
780 | GNUNET_FS_ublock_decrypt_(edata, edata_size, | 778 | GNUNET_FS_ublock_decrypt_ (edata, edata_size, |
781 | &anon_pub, | 779 | &anon_pub, |
782 | sc->requests[i].keyword, | 780 | sc->requests[i].keyword, |
783 | data); | 781 | data); |
784 | return i; | 782 | return i; |
785 | } | 783 | } |
786 | 784 | ||
@@ -795,9 +793,9 @@ decrypt_block_with_keyword(const struct GNUNET_FS_SearchContext *sc, | |||
795 | * @param size size of @a ub | 793 | * @param size size of @a ub |
796 | */ | 794 | */ |
797 | static void | 795 | static void |
798 | process_kblock(struct GNUNET_FS_SearchContext *sc, | 796 | process_kblock (struct GNUNET_FS_SearchContext *sc, |
799 | const struct UBlock *ub, | 797 | const struct UBlock *ub, |
800 | size_t size) | 798 | size_t size) |
801 | { | 799 | { |
802 | size_t j; | 800 | size_t j; |
803 | char pt[size - sizeof(struct UBlock)]; | 801 | char pt[size - sizeof(struct UBlock)]; |
@@ -807,53 +805,53 @@ process_kblock(struct GNUNET_FS_SearchContext *sc, | |||
807 | char *emsg; | 805 | char *emsg; |
808 | int i; | 806 | int i; |
809 | 807 | ||
810 | if (-1 == (i = decrypt_block_with_keyword(sc, | 808 | if (-1 == (i = decrypt_block_with_keyword (sc, |
811 | &ub->verification_key, | 809 | &ub->verification_key, |
812 | &ub[1], | 810 | &ub[1], |
813 | size - sizeof(struct UBlock), | 811 | size - sizeof(struct UBlock), |
814 | pt))) | 812 | pt))) |
815 | return; | 813 | return; |
816 | /* parse; pt[0] is just '\0', so we skip over that */ | 814 | /* parse; pt[0] is just '\0', so we skip over that */ |
817 | eos = memchr(&pt[1], '\0', sizeof(pt) - 1); | 815 | eos = memchr (&pt[1], '\0', sizeof(pt) - 1); |
818 | if (NULL == eos) | 816 | if (NULL == eos) |
817 | { | ||
818 | GNUNET_break_op (0); | ||
819 | return; | ||
820 | } | ||
821 | if (NULL == (uri = GNUNET_FS_uri_parse (&pt[1], &emsg))) | ||
822 | { | ||
823 | if (GNUNET_FS_VERSION > 0x00090400) | ||
819 | { | 824 | { |
820 | GNUNET_break_op(0); | 825 | /* we broke this in 0x00090300, so don't bitch |
821 | return; | 826 | too loudly just one version up... */ |
822 | } | 827 | GNUNET_break_op (0); /* ublock malformed */ |
823 | if (NULL == (uri = GNUNET_FS_uri_parse(&pt[1], &emsg))) | 828 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
824 | { | 829 | _ ("Failed to parse URI `%s': %s\n"), |
825 | if (GNUNET_FS_VERSION > 0x00090400) | 830 | &pt[1], |
826 | { | 831 | emsg); |
827 | /* we broke this in 0x00090300, so don't bitch | ||
828 | too loudly just one version up... */ | ||
829 | GNUNET_break_op(0); /* ublock malformed */ | ||
830 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
831 | _("Failed to parse URI `%s': %s\n"), | ||
832 | &pt[1], | ||
833 | emsg); | ||
834 | } | ||
835 | GNUNET_free_non_null(emsg); | ||
836 | return; | ||
837 | } | 832 | } |
833 | GNUNET_free_non_null (emsg); | ||
834 | return; | ||
835 | } | ||
838 | j = eos - pt + 1; | 836 | j = eos - pt + 1; |
839 | if (sizeof(pt) == j) | 837 | if (sizeof(pt) == j) |
840 | meta = GNUNET_CONTAINER_meta_data_create(); | 838 | meta = GNUNET_CONTAINER_meta_data_create (); |
841 | else | 839 | else |
842 | meta = GNUNET_CONTAINER_meta_data_deserialize(&pt[j], sizeof(pt) - j); | 840 | meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof(pt) - j); |
843 | if (NULL == meta) | 841 | if (NULL == meta) |
844 | { | 842 | { |
845 | GNUNET_break_op(0); /* ublock malformed */ | 843 | GNUNET_break_op (0); /* ublock malformed */ |
846 | GNUNET_FS_uri_destroy(uri); | 844 | GNUNET_FS_uri_destroy (uri); |
847 | return; | 845 | return; |
848 | } | 846 | } |
849 | process_ksk_result(sc, | 847 | process_ksk_result (sc, |
850 | &sc->requests[i], | 848 | &sc->requests[i], |
851 | uri, | 849 | uri, |
852 | meta); | 850 | meta); |
853 | 851 | ||
854 | /* clean up */ | 852 | /* clean up */ |
855 | GNUNET_CONTAINER_meta_data_destroy(meta); | 853 | GNUNET_CONTAINER_meta_data_destroy (meta); |
856 | GNUNET_FS_uri_destroy(uri); | 854 | GNUNET_FS_uri_destroy (uri); |
857 | } | 855 | } |
858 | 856 | ||
859 | 857 | ||
@@ -867,9 +865,9 @@ process_kblock(struct GNUNET_FS_SearchContext *sc, | |||
867 | * @param size size of @a ub | 865 | * @param size size of @a ub |
868 | */ | 866 | */ |
869 | static void | 867 | static void |
870 | process_sblock(struct GNUNET_FS_SearchContext *sc, | 868 | process_sblock (struct GNUNET_FS_SearchContext *sc, |
871 | const struct UBlock *ub, | 869 | const struct UBlock *ub, |
872 | size_t size) | 870 | size_t size) |
873 | { | 871 | { |
874 | size_t len = size - sizeof(struct UBlock); | 872 | size_t len = size - sizeof(struct UBlock); |
875 | char pt[len]; | 873 | char pt[len]; |
@@ -880,36 +878,37 @@ process_sblock(struct GNUNET_FS_SearchContext *sc, | |||
880 | size_t off; | 878 | size_t off; |
881 | char *emsg; | 879 | char *emsg; |
882 | 880 | ||
883 | GNUNET_FS_ublock_decrypt_(&ub[1], len, | 881 | GNUNET_FS_ublock_decrypt_ (&ub[1], len, |
884 | &sc->uri->data.sks.ns, | 882 | &sc->uri->data.sks.ns, |
885 | sc->uri->data.sks.identifier, | 883 | sc->uri->data.sks.identifier, |
886 | pt); | 884 | pt); |
887 | /* parse */ | 885 | /* parse */ |
888 | if (0 == (off = GNUNET_STRINGS_buffer_tokenize(pt, len, 2, &id, &uris))) | 886 | if (0 == (off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris))) |
889 | { | 887 | { |
890 | GNUNET_break_op(0); /* ublock malformed */ | 888 | GNUNET_break_op (0); /* ublock malformed */ |
891 | return; | 889 | return; |
892 | } | 890 | } |
893 | if (NULL == (meta = GNUNET_CONTAINER_meta_data_deserialize(&pt[off], len - off))) | 891 | if (NULL == (meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], len |
894 | { | 892 | - off))) |
895 | GNUNET_break_op(0); /* ublock malformed */ | 893 | { |
896 | return; | 894 | GNUNET_break_op (0); /* ublock malformed */ |
897 | } | 895 | return; |
898 | if (NULL == (uri = GNUNET_FS_uri_parse(uris, &emsg))) | 896 | } |
899 | { | 897 | if (NULL == (uri = GNUNET_FS_uri_parse (uris, &emsg))) |
900 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 898 | { |
901 | _("Failed to parse URI `%s': %s\n"), | 899 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
902 | uris, emsg); | 900 | _ ("Failed to parse URI `%s': %s\n"), |
903 | GNUNET_break_op(0); /* ublock malformed */ | 901 | uris, emsg); |
904 | GNUNET_free_non_null(emsg); | 902 | GNUNET_break_op (0); /* ublock malformed */ |
905 | GNUNET_CONTAINER_meta_data_destroy(meta); | 903 | GNUNET_free_non_null (emsg); |
906 | return; | 904 | GNUNET_CONTAINER_meta_data_destroy (meta); |
907 | } | 905 | return; |
906 | } | ||
908 | /* process */ | 907 | /* process */ |
909 | process_sks_result(sc, id, uri, meta); | 908 | process_sks_result (sc, id, uri, meta); |
910 | /* clean up */ | 909 | /* clean up */ |
911 | GNUNET_FS_uri_destroy(uri); | 910 | GNUNET_FS_uri_destroy (uri); |
912 | GNUNET_CONTAINER_meta_data_destroy(meta); | 911 | GNUNET_CONTAINER_meta_data_destroy (meta); |
913 | } | 912 | } |
914 | 913 | ||
915 | 914 | ||
@@ -921,7 +920,7 @@ process_sblock(struct GNUNET_FS_SearchContext *sc, | |||
921 | * @param sc the search to reconnec | 920 | * @param sc the search to reconnec |
922 | */ | 921 | */ |
923 | static void | 922 | static void |
924 | try_reconnect(struct GNUNET_FS_SearchContext *sc); | 923 | try_reconnect (struct GNUNET_FS_SearchContext *sc); |
925 | 924 | ||
926 | 925 | ||
927 | /** | 926 | /** |
@@ -931,8 +930,8 @@ try_reconnect(struct GNUNET_FS_SearchContext *sc); | |||
931 | * @param msg result message received | 930 | * @param msg result message received |
932 | */ | 931 | */ |
933 | static int | 932 | static int |
934 | check_result(void *cls, | 933 | check_result (void *cls, |
935 | const struct ClientPutMessage *cm) | 934 | const struct ClientPutMessage *cm) |
936 | { | 935 | { |
937 | /* payload of any variable size is OK */ | 936 | /* payload of any variable size is OK */ |
938 | return GNUNET_OK; | 937 | return GNUNET_OK; |
@@ -946,54 +945,55 @@ check_result(void *cls, | |||
946 | * @param msg result message received | 945 | * @param msg result message received |
947 | */ | 946 | */ |
948 | static void | 947 | static void |
949 | handle_result(void *cls, | 948 | handle_result (void *cls, |
950 | const struct ClientPutMessage *cm) | 949 | const struct ClientPutMessage *cm) |
951 | { | 950 | { |
952 | struct GNUNET_FS_SearchContext *sc = cls; | 951 | struct GNUNET_FS_SearchContext *sc = cls; |
953 | uint16_t msize = ntohs(cm->header.size) - sizeof(*cm); | 952 | uint16_t msize = ntohs (cm->header.size) - sizeof(*cm); |
954 | enum GNUNET_BLOCK_Type type = ntohl(cm->type); | 953 | enum GNUNET_BLOCK_Type type = ntohl (cm->type); |
955 | 954 | ||
956 | if (GNUNET_TIME_absolute_get_duration(GNUNET_TIME_absolute_ntoh(cm->expiration)).rel_value_us > 0) | 955 | if (GNUNET_TIME_absolute_get_duration (GNUNET_TIME_absolute_ntoh ( |
957 | { | 956 | cm->expiration)).rel_value_us > 0) |
958 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 957 | { |
959 | "Result received has already expired.\n"); | 958 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
960 | return; /* result expired */ | 959 | "Result received has already expired.\n"); |
961 | } | 960 | return; /* result expired */ |
961 | } | ||
962 | switch (type) | 962 | switch (type) |
963 | { | 963 | { |
964 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | 964 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
965 | if (GNUNET_FS_URI_SKS == sc->uri->type) | 965 | if (GNUNET_FS_URI_SKS == sc->uri->type) |
966 | process_sblock(sc, | 966 | process_sblock (sc, |
967 | (const struct UBlock *)&cm[1], | 967 | (const struct UBlock *) &cm[1], |
968 | msize); | 968 | msize); |
969 | else | 969 | else |
970 | process_kblock(sc, | 970 | process_kblock (sc, |
971 | (const struct UBlock *)&cm[1], | 971 | (const struct UBlock *) &cm[1], |
972 | msize); | 972 | msize); |
973 | break; | 973 | break; |
974 | 974 | ||
975 | case GNUNET_BLOCK_TYPE_ANY: | 975 | case GNUNET_BLOCK_TYPE_ANY: |
976 | GNUNET_break(0); | 976 | GNUNET_break (0); |
977 | break; | 977 | break; |
978 | 978 | ||
979 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | 979 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
980 | GNUNET_break(0); | 980 | GNUNET_break (0); |
981 | break; | 981 | break; |
982 | 982 | ||
983 | case GNUNET_BLOCK_TYPE_FS_ONDEMAND: | 983 | case GNUNET_BLOCK_TYPE_FS_ONDEMAND: |
984 | GNUNET_break(0); | 984 | GNUNET_break (0); |
985 | break; | 985 | break; |
986 | 986 | ||
987 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | 987 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
988 | GNUNET_break(0); | 988 | GNUNET_break (0); |
989 | break; | 989 | break; |
990 | 990 | ||
991 | default: | 991 | default: |
992 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 992 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
993 | _("Got result with unknown block type `%d', ignoring"), | 993 | _ ("Got result with unknown block type `%d', ignoring"), |
994 | type); | 994 | type); |
995 | break; | 995 | break; |
996 | } | 996 | } |
997 | } | 997 | } |
998 | 998 | ||
999 | 999 | ||
@@ -1004,13 +1004,14 @@ handle_result(void *cls, | |||
1004 | * @param sc context for the search | 1004 | * @param sc context for the search |
1005 | */ | 1005 | */ |
1006 | static void | 1006 | static void |
1007 | schedule_transmit_search_request(struct GNUNET_FS_SearchContext *sc); | 1007 | schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc); |
1008 | 1008 | ||
1009 | 1009 | ||
1010 | /** | 1010 | /** |
1011 | * Closure for #build_result_set(). | 1011 | * Closure for #build_result_set(). |
1012 | */ | 1012 | */ |
1013 | struct MessageBuilderContext { | 1013 | struct MessageBuilderContext |
1014 | { | ||
1014 | /** | 1015 | /** |
1015 | * How many entries can we store to xoff. | 1016 | * How many entries can we store to xoff. |
1016 | */ | 1017 | */ |
@@ -1048,21 +1049,24 @@ struct MessageBuilderContext { | |||
1048 | * @return #GNUNET_OK to continue iterating | 1049 | * @return #GNUNET_OK to continue iterating |
1049 | */ | 1050 | */ |
1050 | static int | 1051 | static int |
1051 | build_result_set(void *cls, | 1052 | build_result_set (void *cls, |
1052 | const struct GNUNET_HashCode *key, | 1053 | const struct GNUNET_HashCode *key, |
1053 | void *value) | 1054 | void *value) |
1054 | { | 1055 | { |
1055 | struct MessageBuilderContext *mbc = cls; | 1056 | struct MessageBuilderContext *mbc = cls; |
1056 | struct GNUNET_FS_SearchResult *sr = value; | 1057 | struct GNUNET_FS_SearchResult *sr = value; |
1057 | 1058 | ||
1058 | if ((NULL != sr->keyword_bitmap) && | 1059 | if ((NULL != sr->keyword_bitmap) && |
1059 | (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8))))) | 1060 | (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 |
1061 | << (mbc-> | ||
1062 | keyword_offset | ||
1063 | % 8))))) | ||
1060 | return GNUNET_OK; /* have no match for this keyword yet */ | 1064 | return GNUNET_OK; /* have no match for this keyword yet */ |
1061 | if (mbc->skip_cnt > 0) | 1065 | if (mbc->skip_cnt > 0) |
1062 | { | 1066 | { |
1063 | mbc->skip_cnt--; | 1067 | mbc->skip_cnt--; |
1064 | return GNUNET_OK; | 1068 | return GNUNET_OK; |
1065 | } | 1069 | } |
1066 | if (0 == mbc->put_cnt) | 1070 | if (0 == mbc->put_cnt) |
1067 | return GNUNET_SYSERR; | 1071 | return GNUNET_SYSERR; |
1068 | mbc->xoff[--mbc->put_cnt] = *key; | 1072 | mbc->xoff[--mbc->put_cnt] = *key; |
@@ -1081,15 +1085,18 @@ build_result_set(void *cls, | |||
1081 | * @return #GNUNET_OK to continue iterating | 1085 | * @return #GNUNET_OK to continue iterating |
1082 | */ | 1086 | */ |
1083 | static int | 1087 | static int |
1084 | find_result_set(void *cls, | 1088 | find_result_set (void *cls, |
1085 | const struct GNUNET_HashCode *key, | 1089 | const struct GNUNET_HashCode *key, |
1086 | void *value) | 1090 | void *value) |
1087 | { | 1091 | { |
1088 | struct MessageBuilderContext *mbc = cls; | 1092 | struct MessageBuilderContext *mbc = cls; |
1089 | struct GNUNET_FS_SearchResult *sr = value; | 1093 | struct GNUNET_FS_SearchResult *sr = value; |
1090 | 1094 | ||
1091 | if ((NULL != sr->keyword_bitmap) && | 1095 | if ((NULL != sr->keyword_bitmap) && |
1092 | (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8))))) | 1096 | (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 |
1097 | << (mbc-> | ||
1098 | keyword_offset | ||
1099 | % 8))))) | ||
1093 | return GNUNET_OK; /* have no match for this keyword yet */ | 1100 | return GNUNET_OK; /* have no match for this keyword yet */ |
1094 | mbc->put_cnt++; | 1101 | mbc->put_cnt++; |
1095 | return GNUNET_OK; | 1102 | return GNUNET_OK; |
@@ -1103,7 +1110,7 @@ find_result_set(void *cls, | |||
1103 | * @param sc context for the search | 1110 | * @param sc context for the search |
1104 | */ | 1111 | */ |
1105 | static void | 1112 | static void |
1106 | schedule_transmit_search_request(struct GNUNET_FS_SearchContext *sc) | 1113 | schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) |
1107 | { | 1114 | { |
1108 | struct MessageBuilderContext mbc; | 1115 | struct MessageBuilderContext mbc; |
1109 | struct GNUNET_MQ_Envelope *env; | 1116 | struct GNUNET_MQ_Envelope *env; |
@@ -1118,115 +1125,116 @@ schedule_transmit_search_request(struct GNUNET_FS_SearchContext *sc) | |||
1118 | unsigned int keyword_offset; | 1125 | unsigned int keyword_offset; |
1119 | int first_call; | 1126 | int first_call; |
1120 | 1127 | ||
1121 | memset(&mbc, 0, sizeof(mbc)); | 1128 | memset (&mbc, 0, sizeof(mbc)); |
1122 | mbc.sc = sc; | 1129 | mbc.sc = sc; |
1123 | if (GNUNET_FS_uri_test_ksk(sc->uri)) | 1130 | if (GNUNET_FS_uri_test_ksk (sc->uri)) |
1124 | { | 1131 | { |
1125 | /* This will calculate the result set size ONLY for | 1132 | /* This will calculate the result set size ONLY for |
1126 | "keyword_offset == 0", so we will have to recalculate | 1133 | "keyword_offset == 0", so we will have to recalculate |
1127 | it for the other keywords later! */ | 1134 | it for the other keywords later! */ |
1128 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, | 1135 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1129 | &find_result_set, | 1136 | &find_result_set, |
1130 | &mbc); | 1137 | &mbc); |
1131 | total_seen_results = mbc.put_cnt; | 1138 | total_seen_results = mbc.put_cnt; |
1132 | } | 1139 | } |
1133 | else | 1140 | else |
1134 | { | 1141 | { |
1135 | total_seen_results | 1142 | total_seen_results |
1136 | = GNUNET_CONTAINER_multihashmap_size(sc->master_result_map); | 1143 | = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map); |
1137 | } | 1144 | } |
1138 | search_request_map_offset = 0; | 1145 | search_request_map_offset = 0; |
1139 | keyword_offset = 0; | 1146 | keyword_offset = 0; |
1140 | first_call = GNUNET_YES; | 1147 | first_call = GNUNET_YES; |
1141 | while ((0 != (left = | 1148 | while ((0 != (left = |
1142 | (total_seen_results - search_request_map_offset))) || | 1149 | (total_seen_results - search_request_map_offset))) || |
1143 | (GNUNET_YES == first_call)) | 1150 | (GNUNET_YES == first_call)) |
1151 | { | ||
1152 | first_call = GNUNET_NO; | ||
1153 | options = SEARCH_MESSAGE_OPTION_NONE; | ||
1154 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) | ||
1155 | options |= SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY; | ||
1156 | |||
1157 | fit = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*sm)) / sizeof(struct | ||
1158 | GNUNET_HashCode); | ||
1159 | todo = GNUNET_MIN (fit, | ||
1160 | left); | ||
1161 | env = GNUNET_MQ_msg_extra (sm, | ||
1162 | sizeof(struct GNUNET_HashCode) * todo, | ||
1163 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | ||
1164 | mbc.skip_cnt = search_request_map_offset; | ||
1165 | mbc.xoff = (struct GNUNET_HashCode *) &sm[1]; | ||
1166 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK); | ||
1167 | sm->anonymity_level = htonl (sc->anonymity); | ||
1168 | memset (&sm->target, | ||
1169 | 0, | ||
1170 | sizeof(struct GNUNET_PeerIdentity)); | ||
1171 | |||
1172 | if (GNUNET_FS_uri_test_ksk (sc->uri)) | ||
1144 | { | 1173 | { |
1145 | first_call = GNUNET_NO; | 1174 | mbc.keyword_offset = keyword_offset; |
1146 | options = SEARCH_MESSAGE_OPTION_NONE; | 1175 | /* calculate how many results we can send in this message */ |
1147 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) | 1176 | mbc.put_cnt = todo; |
1148 | options |= SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY; | 1177 | /* now build message */ |
1149 | 1178 | sm->query = sc->requests[keyword_offset].uquery; | |
1150 | fit = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*sm)) / sizeof(struct GNUNET_HashCode); | 1179 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1151 | todo = GNUNET_MIN(fit, | 1180 | &build_result_set, |
1152 | left); | 1181 | &mbc); |
1153 | env = GNUNET_MQ_msg_extra(sm, | 1182 | search_request_map_offset += todo; |
1154 | sizeof(struct GNUNET_HashCode) * todo, | 1183 | GNUNET_assert (0 == mbc.put_cnt); |
1155 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | 1184 | GNUNET_assert (total_seen_results >= search_request_map_offset); |
1156 | mbc.skip_cnt = search_request_map_offset; | 1185 | if (total_seen_results != search_request_map_offset) |
1157 | mbc.xoff = (struct GNUNET_HashCode *)&sm[1]; | 1186 | { |
1158 | sm->type = htonl(GNUNET_BLOCK_TYPE_FS_UBLOCK); | 1187 | /* more requesting to be done... */ |
1159 | sm->anonymity_level = htonl(sc->anonymity); | 1188 | sm->options = htonl (options | SEARCH_MESSAGE_OPTION_CONTINUED); |
1160 | memset(&sm->target, | 1189 | } |
1161 | 0, | 1190 | else |
1162 | sizeof(struct GNUNET_PeerIdentity)); | 1191 | { |
1163 | 1192 | sm->options = htonl (options); | |
1164 | if (GNUNET_FS_uri_test_ksk(sc->uri)) | 1193 | keyword_offset++; |
1194 | if (sc->uri->data.ksk.keywordCount != keyword_offset) | ||
1165 | { | 1195 | { |
1196 | /* more keywords => more requesting to be done... */ | ||
1197 | first_call = GNUNET_YES; | ||
1198 | search_request_map_offset = 0; | ||
1199 | mbc.put_cnt = 0; | ||
1166 | mbc.keyword_offset = keyword_offset; | 1200 | mbc.keyword_offset = keyword_offset; |
1167 | /* calculate how many results we can send in this message */ | 1201 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1168 | mbc.put_cnt = todo; | 1202 | &find_result_set, |
1169 | /* now build message */ | 1203 | &mbc); |
1170 | sm->query = sc->requests[keyword_offset].uquery; | 1204 | total_seen_results = mbc.put_cnt; |
1171 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, | ||
1172 | &build_result_set, | ||
1173 | &mbc); | ||
1174 | search_request_map_offset += todo; | ||
1175 | GNUNET_assert(0 == mbc.put_cnt); | ||
1176 | GNUNET_assert(total_seen_results >= search_request_map_offset); | ||
1177 | if (total_seen_results != search_request_map_offset) | ||
1178 | { | ||
1179 | /* more requesting to be done... */ | ||
1180 | sm->options = htonl(options | SEARCH_MESSAGE_OPTION_CONTINUED); | ||
1181 | } | ||
1182 | else | ||
1183 | { | ||
1184 | sm->options = htonl(options); | ||
1185 | keyword_offset++; | ||
1186 | if (sc->uri->data.ksk.keywordCount != keyword_offset) | ||
1187 | { | ||
1188 | /* more keywords => more requesting to be done... */ | ||
1189 | first_call = GNUNET_YES; | ||
1190 | search_request_map_offset = 0; | ||
1191 | mbc.put_cnt = 0; | ||
1192 | mbc.keyword_offset = keyword_offset; | ||
1193 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, | ||
1194 | &find_result_set, | ||
1195 | &mbc); | ||
1196 | total_seen_results = mbc.put_cnt; | ||
1197 | } | ||
1198 | } | ||
1199 | } | 1205 | } |
1206 | } | ||
1207 | } | ||
1208 | else | ||
1209 | { | ||
1210 | GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri)); | ||
1211 | |||
1212 | GNUNET_CRYPTO_ecdsa_public_key_derive (&sc->uri->data.sks.ns, | ||
1213 | sc->uri->data.sks.identifier, | ||
1214 | "fs-ublock", | ||
1215 | &dpub); | ||
1216 | GNUNET_CRYPTO_hash (&dpub, | ||
1217 | sizeof(dpub), | ||
1218 | &sm->query); | ||
1219 | mbc.put_cnt = todo; | ||
1220 | mbc.keyword_offset = 0; | ||
1221 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | ||
1222 | &build_result_set, | ||
1223 | &mbc); | ||
1224 | GNUNET_assert (total_seen_results >= search_request_map_offset); | ||
1225 | if (total_seen_results != search_request_map_offset) | ||
1226 | { | ||
1227 | /* more requesting to be done... */ | ||
1228 | sm->options = htonl (options | SEARCH_MESSAGE_OPTION_CONTINUED); | ||
1229 | } | ||
1200 | else | 1230 | else |
1201 | { | 1231 | { |
1202 | GNUNET_assert(GNUNET_FS_uri_test_sks(sc->uri)); | 1232 | sm->options = htonl (options); |
1203 | 1233 | } | |
1204 | GNUNET_CRYPTO_ecdsa_public_key_derive(&sc->uri->data.sks.ns, | ||
1205 | sc->uri->data.sks.identifier, | ||
1206 | "fs-ublock", | ||
1207 | &dpub); | ||
1208 | GNUNET_CRYPTO_hash(&dpub, | ||
1209 | sizeof(dpub), | ||
1210 | &sm->query); | ||
1211 | mbc.put_cnt = todo; | ||
1212 | mbc.keyword_offset = 0; | ||
1213 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, | ||
1214 | &build_result_set, | ||
1215 | &mbc); | ||
1216 | GNUNET_assert(total_seen_results >= search_request_map_offset); | ||
1217 | if (total_seen_results != search_request_map_offset) | ||
1218 | { | ||
1219 | /* more requesting to be done... */ | ||
1220 | sm->options = htonl(options | SEARCH_MESSAGE_OPTION_CONTINUED); | ||
1221 | } | ||
1222 | else | ||
1223 | { | ||
1224 | sm->options = htonl(options); | ||
1225 | } | ||
1226 | } | ||
1227 | GNUNET_MQ_send(sc->mq, | ||
1228 | env); | ||
1229 | } | 1234 | } |
1235 | GNUNET_MQ_send (sc->mq, | ||
1236 | env); | ||
1237 | } | ||
1230 | } | 1238 | } |
1231 | 1239 | ||
1232 | 1240 | ||
@@ -1239,17 +1247,17 @@ schedule_transmit_search_request(struct GNUNET_FS_SearchContext *sc) | |||
1239 | * @param error error code | 1247 | * @param error error code |
1240 | */ | 1248 | */ |
1241 | static void | 1249 | static void |
1242 | search_mq_error_handler(void *cls, | 1250 | search_mq_error_handler (void *cls, |
1243 | enum GNUNET_MQ_Error error) | 1251 | enum GNUNET_MQ_Error error) |
1244 | { | 1252 | { |
1245 | struct GNUNET_FS_SearchContext *sc = cls; | 1253 | struct GNUNET_FS_SearchContext *sc = cls; |
1246 | 1254 | ||
1247 | if (NULL != sc->mq) | 1255 | if (NULL != sc->mq) |
1248 | { | 1256 | { |
1249 | GNUNET_MQ_destroy(sc->mq); | 1257 | GNUNET_MQ_destroy (sc->mq); |
1250 | sc->mq = NULL; | 1258 | sc->mq = NULL; |
1251 | } | 1259 | } |
1252 | try_reconnect(sc); | 1260 | try_reconnect (sc); |
1253 | } | 1261 | } |
1254 | 1262 | ||
1255 | 1263 | ||
@@ -1260,29 +1268,29 @@ search_mq_error_handler(void *cls, | |||
1260 | * @param cls our search context | 1268 | * @param cls our search context |
1261 | */ | 1269 | */ |
1262 | static void | 1270 | static void |
1263 | do_reconnect(void *cls) | 1271 | do_reconnect (void *cls) |
1264 | { | 1272 | { |
1265 | struct GNUNET_FS_SearchContext *sc = cls; | 1273 | struct GNUNET_FS_SearchContext *sc = cls; |
1266 | struct GNUNET_MQ_MessageHandler handlers[] = { | 1274 | struct GNUNET_MQ_MessageHandler handlers[] = { |
1267 | GNUNET_MQ_hd_var_size(result, | 1275 | GNUNET_MQ_hd_var_size (result, |
1268 | GNUNET_MESSAGE_TYPE_FS_PUT, | 1276 | GNUNET_MESSAGE_TYPE_FS_PUT, |
1269 | struct ClientPutMessage, | 1277 | struct ClientPutMessage, |
1270 | sc), | 1278 | sc), |
1271 | GNUNET_MQ_handler_end() | 1279 | GNUNET_MQ_handler_end () |
1272 | }; | 1280 | }; |
1273 | 1281 | ||
1274 | sc->task = NULL; | 1282 | sc->task = NULL; |
1275 | sc->mq = GNUNET_CLIENT_connect(sc->h->cfg, | 1283 | sc->mq = GNUNET_CLIENT_connect (sc->h->cfg, |
1276 | "fs", | 1284 | "fs", |
1277 | handlers, | 1285 | handlers, |
1278 | &search_mq_error_handler, | 1286 | &search_mq_error_handler, |
1279 | sc); | 1287 | sc); |
1280 | if (NULL == sc->mq) | 1288 | if (NULL == sc->mq) |
1281 | { | 1289 | { |
1282 | try_reconnect(sc); | 1290 | try_reconnect (sc); |
1283 | return; | 1291 | return; |
1284 | } | 1292 | } |
1285 | schedule_transmit_search_request(sc); | 1293 | schedule_transmit_search_request (sc); |
1286 | } | 1294 | } |
1287 | 1295 | ||
1288 | 1296 | ||
@@ -1294,18 +1302,18 @@ do_reconnect(void *cls) | |||
1294 | * @param sc the search to reconnec | 1302 | * @param sc the search to reconnec |
1295 | */ | 1303 | */ |
1296 | static void | 1304 | static void |
1297 | try_reconnect(struct GNUNET_FS_SearchContext *sc) | 1305 | try_reconnect (struct GNUNET_FS_SearchContext *sc) |
1298 | { | 1306 | { |
1299 | if (NULL != sc->mq) | 1307 | if (NULL != sc->mq) |
1300 | { | 1308 | { |
1301 | GNUNET_MQ_destroy(sc->mq); | 1309 | GNUNET_MQ_destroy (sc->mq); |
1302 | sc->mq = NULL; | 1310 | sc->mq = NULL; |
1303 | } | 1311 | } |
1304 | sc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(sc->reconnect_backoff); | 1312 | sc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (sc->reconnect_backoff); |
1305 | sc->task = | 1313 | sc->task = |
1306 | GNUNET_SCHEDULER_add_delayed(sc->reconnect_backoff, | 1314 | GNUNET_SCHEDULER_add_delayed (sc->reconnect_backoff, |
1307 | &do_reconnect, | 1315 | &do_reconnect, |
1308 | sc); | 1316 | sc); |
1309 | } | 1317 | } |
1310 | 1318 | ||
1311 | 1319 | ||
@@ -1322,39 +1330,39 @@ try_reconnect(struct GNUNET_FS_SearchContext *sc) | |||
1322 | * @return context that can be used to control the search | 1330 | * @return context that can be used to control the search |
1323 | */ | 1331 | */ |
1324 | static struct GNUNET_FS_SearchContext * | 1332 | static struct GNUNET_FS_SearchContext * |
1325 | search_start(struct GNUNET_FS_Handle *h, | 1333 | search_start (struct GNUNET_FS_Handle *h, |
1326 | const struct GNUNET_FS_Uri *uri, | 1334 | const struct GNUNET_FS_Uri *uri, |
1327 | uint32_t anonymity, | 1335 | uint32_t anonymity, |
1328 | enum GNUNET_FS_SearchOptions options, | 1336 | enum GNUNET_FS_SearchOptions options, |
1329 | void *cctx, | 1337 | void *cctx, |
1330 | struct GNUNET_FS_SearchResult *psearch) | 1338 | struct GNUNET_FS_SearchResult *psearch) |
1331 | { | 1339 | { |
1332 | struct GNUNET_FS_SearchContext *sc; | 1340 | struct GNUNET_FS_SearchContext *sc; |
1333 | struct GNUNET_FS_ProgressInfo pi; | 1341 | struct GNUNET_FS_ProgressInfo pi; |
1334 | 1342 | ||
1335 | sc = GNUNET_new(struct GNUNET_FS_SearchContext); | 1343 | sc = GNUNET_new (struct GNUNET_FS_SearchContext); |
1336 | sc->h = h; | 1344 | sc->h = h; |
1337 | sc->options = options; | 1345 | sc->options = options; |
1338 | sc->uri = GNUNET_FS_uri_dup(uri); | 1346 | sc->uri = GNUNET_FS_uri_dup (uri); |
1339 | sc->anonymity = anonymity; | 1347 | sc->anonymity = anonymity; |
1340 | sc->start_time = GNUNET_TIME_absolute_get(); | 1348 | sc->start_time = GNUNET_TIME_absolute_get (); |
1341 | if (NULL != psearch) | 1349 | if (NULL != psearch) |
1342 | { | 1350 | { |
1343 | sc->psearch_result = psearch; | 1351 | sc->psearch_result = psearch; |
1344 | psearch->update_search = sc; | 1352 | psearch->update_search = sc; |
1345 | } | 1353 | } |
1346 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_NO); | 1354 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); |
1347 | sc->client_info = cctx; | 1355 | sc->client_info = cctx; |
1348 | if (GNUNET_OK != GNUNET_FS_search_start_searching_(sc)) | 1356 | if (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc)) |
1349 | { | 1357 | { |
1350 | GNUNET_FS_uri_destroy(sc->uri); | 1358 | GNUNET_FS_uri_destroy (sc->uri); |
1351 | GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); | 1359 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); |
1352 | GNUNET_free(sc); | 1360 | GNUNET_free (sc); |
1353 | return NULL; | 1361 | return NULL; |
1354 | } | 1362 | } |
1355 | GNUNET_FS_search_sync_(sc); | 1363 | GNUNET_FS_search_sync_ (sc); |
1356 | pi.status = GNUNET_FS_STATUS_SEARCH_START; | 1364 | pi.status = GNUNET_FS_STATUS_SEARCH_START; |
1357 | sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); | 1365 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); |
1358 | return sc; | 1366 | return sc; |
1359 | } | 1367 | } |
1360 | 1368 | ||
@@ -1369,22 +1377,22 @@ search_start(struct GNUNET_FS_Handle *h, | |||
1369 | * @return #GNUNET_YES (we should continue to iterate) | 1377 | * @return #GNUNET_YES (we should continue to iterate) |
1370 | */ | 1378 | */ |
1371 | static int | 1379 | static int |
1372 | update_sre_result_maps(void *cls, | 1380 | update_sre_result_maps (void *cls, |
1373 | const struct GNUNET_HashCode *key, | 1381 | const struct GNUNET_HashCode *key, |
1374 | void *value) | 1382 | void *value) |
1375 | { | 1383 | { |
1376 | struct GNUNET_FS_SearchContext *sc = cls; | 1384 | struct GNUNET_FS_SearchContext *sc = cls; |
1377 | struct GNUNET_FS_SearchResult *sr = value; | 1385 | struct GNUNET_FS_SearchResult *sr = value; |
1378 | unsigned int i; | ||
1379 | 1386 | ||
1380 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | 1387 | for (unsigned int i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
1388 | { | ||
1381 | if (0 != (sr->keyword_bitmap[i / 8] & (1 << (i % 8)))) | 1389 | if (0 != (sr->keyword_bitmap[i / 8] & (1 << (i % 8)))) |
1382 | GNUNET_break(GNUNET_OK == | 1390 | GNUNET_break (GNUNET_OK == |
1383 | GNUNET_CONTAINER_multihashmap_put(sc->requests[i].results, | 1391 | GNUNET_CONTAINER_multihashmap_put (sc->requests[i].results, |
1384 | &sr->key, | 1392 | &sr->key, |
1385 | sr, | 1393 | sr, |
1386 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1394 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1387 | 1395 | } | |
1388 | return GNUNET_YES; | 1396 | return GNUNET_YES; |
1389 | } | 1397 | } |
1390 | 1398 | ||
@@ -1397,7 +1405,7 @@ update_sre_result_maps(void *cls, | |||
1397 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1405 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1398 | */ | 1406 | */ |
1399 | int | 1407 | int |
1400 | GNUNET_FS_search_start_searching_(struct GNUNET_FS_SearchContext *sc) | 1408 | GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) |
1401 | { | 1409 | { |
1402 | unsigned int i; | 1410 | unsigned int i; |
1403 | const char *keyword; | 1411 | const char *keyword; |
@@ -1405,45 +1413,45 @@ GNUNET_FS_search_start_searching_(struct GNUNET_FS_SearchContext *sc) | |||
1405 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; | 1413 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; |
1406 | struct SearchRequestEntry *sre; | 1414 | struct SearchRequestEntry *sre; |
1407 | 1415 | ||
1408 | GNUNET_assert(NULL == sc->mq); | 1416 | GNUNET_assert (NULL == sc->mq); |
1409 | if (GNUNET_FS_uri_test_ksk(sc->uri)) | 1417 | if (GNUNET_FS_uri_test_ksk (sc->uri)) |
1418 | { | ||
1419 | GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); | ||
1420 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); | ||
1421 | GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub); | ||
1422 | sc->requests | ||
1423 | = GNUNET_new_array (sc->uri->data.ksk.keywordCount, | ||
1424 | struct SearchRequestEntry); | ||
1425 | |||
1426 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | ||
1410 | { | 1427 | { |
1411 | GNUNET_assert(0 != sc->uri->data.ksk.keywordCount); | 1428 | keyword = &sc->uri->data.ksk.keywords[i][1]; |
1412 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous(); | 1429 | sre = &sc->requests[i]; |
1413 | GNUNET_CRYPTO_ecdsa_key_get_public(anon, &anon_pub); | 1430 | sre->keyword = GNUNET_strdup (keyword); |
1414 | sc->requests | 1431 | GNUNET_CRYPTO_ecdsa_public_key_derive (&anon_pub, |
1415 | = GNUNET_new_array(sc->uri->data.ksk.keywordCount, | 1432 | keyword, |
1416 | struct SearchRequestEntry); | 1433 | "fs-ublock", |
1417 | 1434 | &sre->dpub); | |
1418 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | 1435 | GNUNET_CRYPTO_hash (&sre->dpub, |
1419 | { | 1436 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
1420 | keyword = &sc->uri->data.ksk.keywords[i][1]; | 1437 | &sre->uquery); |
1421 | sre = &sc->requests[i]; | 1438 | sre->mandatory = (sc->uri->data.ksk.keywords[i][0] == '+'); |
1422 | sre->keyword = GNUNET_strdup(keyword); | 1439 | if (sre->mandatory) |
1423 | GNUNET_CRYPTO_ecdsa_public_key_derive(&anon_pub, | 1440 | sc->mandatory_count++; |
1424 | keyword, | 1441 | sre->results = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); |
1425 | "fs-ublock", | ||
1426 | &sre->dpub); | ||
1427 | GNUNET_CRYPTO_hash(&sre->dpub, | ||
1428 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | ||
1429 | &sre->uquery); | ||
1430 | sre->mandatory = (sc->uri->data.ksk.keywords[i][0] == '+'); | ||
1431 | if (sre->mandatory) | ||
1432 | sc->mandatory_count++; | ||
1433 | sre->results = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); | ||
1434 | } | ||
1435 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, | ||
1436 | &update_sre_result_maps, | ||
1437 | sc); | ||
1438 | } | 1442 | } |
1439 | GNUNET_assert(NULL == sc->task); | 1443 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1440 | do_reconnect(sc); | 1444 | &update_sre_result_maps, |
1445 | sc); | ||
1446 | } | ||
1447 | GNUNET_assert (NULL == sc->task); | ||
1448 | do_reconnect (sc); | ||
1441 | if (NULL == sc->mq) | 1449 | if (NULL == sc->mq) |
1442 | { | 1450 | { |
1443 | GNUNET_SCHEDULER_cancel(sc->task); | 1451 | GNUNET_SCHEDULER_cancel (sc->task); |
1444 | sc->task = NULL; | 1452 | sc->task = NULL; |
1445 | return GNUNET_SYSERR; | 1453 | return GNUNET_SYSERR; |
1446 | } | 1454 | } |
1447 | return GNUNET_OK; | 1455 | return GNUNET_OK; |
1448 | } | 1456 | } |
1449 | 1457 | ||
@@ -1457,25 +1465,25 @@ GNUNET_FS_search_start_searching_(struct GNUNET_FS_SearchContext *sc) | |||
1457 | * @return #GNUNET_OK | 1465 | * @return #GNUNET_OK |
1458 | */ | 1466 | */ |
1459 | static int | 1467 | static int |
1460 | search_result_freeze_probes(void *cls, | 1468 | search_result_freeze_probes (void *cls, |
1461 | const struct GNUNET_HashCode *key, | 1469 | const struct GNUNET_HashCode *key, |
1462 | void *value) | 1470 | void *value) |
1463 | { | 1471 | { |
1464 | struct GNUNET_FS_SearchResult *sr = value; | 1472 | struct GNUNET_FS_SearchResult *sr = value; |
1465 | 1473 | ||
1466 | if (NULL != sr->probe_ctx) | 1474 | if (NULL != sr->probe_ctx) |
1467 | { | 1475 | { |
1468 | GNUNET_FS_download_stop(sr->probe_ctx, GNUNET_YES); | 1476 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); |
1469 | sr->probe_ctx = NULL; | 1477 | sr->probe_ctx = NULL; |
1470 | GNUNET_FS_stop_probe_ping_task_(sr); | 1478 | GNUNET_FS_stop_probe_ping_task_ (sr); |
1471 | } | 1479 | } |
1472 | if (NULL != sr->probe_cancel_task) | 1480 | if (NULL != sr->probe_cancel_task) |
1473 | { | 1481 | { |
1474 | GNUNET_SCHEDULER_cancel(sr->probe_cancel_task); | 1482 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
1475 | sr->probe_cancel_task = NULL; | 1483 | sr->probe_cancel_task = NULL; |
1476 | } | 1484 | } |
1477 | if (NULL != sr->update_search) | 1485 | if (NULL != sr->update_search) |
1478 | GNUNET_FS_search_pause(sr->update_search); | 1486 | GNUNET_FS_search_pause (sr->update_search); |
1479 | return GNUNET_OK; | 1487 | return GNUNET_OK; |
1480 | } | 1488 | } |
1481 | 1489 | ||
@@ -1489,15 +1497,15 @@ search_result_freeze_probes(void *cls, | |||
1489 | * @return #GNUNET_OK | 1497 | * @return #GNUNET_OK |
1490 | */ | 1498 | */ |
1491 | static int | 1499 | static int |
1492 | search_result_resume_probes(void *cls, | 1500 | search_result_resume_probes (void *cls, |
1493 | const struct GNUNET_HashCode * key, | 1501 | const struct GNUNET_HashCode *key, |
1494 | void *value) | 1502 | void *value) |
1495 | { | 1503 | { |
1496 | struct GNUNET_FS_SearchResult *sr = value; | 1504 | struct GNUNET_FS_SearchResult *sr = value; |
1497 | 1505 | ||
1498 | GNUNET_FS_search_start_probe_(sr); | 1506 | GNUNET_FS_search_start_probe_ (sr); |
1499 | if (NULL != sr->update_search) | 1507 | if (NULL != sr->update_search) |
1500 | GNUNET_FS_search_continue(sr->update_search); | 1508 | GNUNET_FS_search_continue (sr->update_search); |
1501 | return GNUNET_OK; | 1509 | return GNUNET_OK; |
1502 | } | 1510 | } |
1503 | 1511 | ||
@@ -1511,40 +1519,40 @@ search_result_resume_probes(void *cls, | |||
1511 | * @return #GNUNET_OK | 1519 | * @return #GNUNET_OK |
1512 | */ | 1520 | */ |
1513 | static int | 1521 | static int |
1514 | search_result_suspend(void *cls, | 1522 | search_result_suspend (void *cls, |
1515 | const struct GNUNET_HashCode *key, | 1523 | const struct GNUNET_HashCode *key, |
1516 | void *value) | 1524 | void *value) |
1517 | { | 1525 | { |
1518 | struct GNUNET_FS_SearchContext *sc = cls; | 1526 | struct GNUNET_FS_SearchContext *sc = cls; |
1519 | struct GNUNET_FS_SearchResult *sr = value; | 1527 | struct GNUNET_FS_SearchResult *sr = value; |
1520 | struct GNUNET_FS_ProgressInfo pi; | 1528 | struct GNUNET_FS_ProgressInfo pi; |
1521 | 1529 | ||
1522 | if (NULL != sr->download) | 1530 | if (NULL != sr->download) |
1523 | { | 1531 | { |
1524 | GNUNET_FS_download_signal_suspend_(sr->download); | 1532 | GNUNET_FS_download_signal_suspend_ (sr->download); |
1525 | sr->download = NULL; | 1533 | sr->download = NULL; |
1526 | } | 1534 | } |
1527 | if (NULL != sr->update_search) | 1535 | if (NULL != sr->update_search) |
1528 | { | 1536 | { |
1529 | GNUNET_FS_search_signal_suspend_(sr->update_search); | 1537 | GNUNET_FS_search_signal_suspend_ (sr->update_search); |
1530 | sr->update_search = NULL; | 1538 | sr->update_search = NULL; |
1531 | } | 1539 | } |
1532 | GNUNET_FS_search_stop_probe_(sr); | 1540 | GNUNET_FS_search_stop_probe_ (sr); |
1533 | if (0 == sr->mandatory_missing) | 1541 | if (0 == sr->mandatory_missing) |
1534 | { | 1542 | { |
1535 | /* client is aware of search result, notify about suspension event */ | 1543 | /* client is aware of search result, notify about suspension event */ |
1536 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND; | 1544 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND; |
1537 | pi.value.search.specifics.result_suspend.cctx = sr->client_info; | 1545 | pi.value.search.specifics.result_suspend.cctx = sr->client_info; |
1538 | pi.value.search.specifics.result_suspend.meta = sr->meta; | 1546 | pi.value.search.specifics.result_suspend.meta = sr->meta; |
1539 | pi.value.search.specifics.result_suspend.uri = sr->uri; | 1547 | pi.value.search.specifics.result_suspend.uri = sr->uri; |
1540 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); | 1548 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); |
1541 | } | 1549 | } |
1542 | GNUNET_break(NULL == sr->client_info); | 1550 | GNUNET_break (NULL == sr->client_info); |
1543 | GNUNET_free_non_null(sr->serialization); | 1551 | GNUNET_free_non_null (sr->serialization); |
1544 | GNUNET_FS_uri_destroy(sr->uri); | 1552 | GNUNET_FS_uri_destroy (sr->uri); |
1545 | GNUNET_CONTAINER_meta_data_destroy(sr->meta); | 1553 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); |
1546 | GNUNET_free_non_null(sr->keyword_bitmap); | 1554 | GNUNET_free_non_null (sr->keyword_bitmap); |
1547 | GNUNET_free(sr); | 1555 | GNUNET_free (sr); |
1548 | return GNUNET_OK; | 1556 | return GNUNET_OK; |
1549 | } | 1557 | } |
1550 | 1558 | ||
@@ -1556,43 +1564,43 @@ search_result_suspend(void *cls, | |||
1556 | * @param cls the `struct GNUNET_FS_SearchContext` to signal for | 1564 | * @param cls the `struct GNUNET_FS_SearchContext` to signal for |
1557 | */ | 1565 | */ |
1558 | void | 1566 | void |
1559 | GNUNET_FS_search_signal_suspend_(void *cls) | 1567 | GNUNET_FS_search_signal_suspend_ (void *cls) |
1560 | { | 1568 | { |
1561 | struct GNUNET_FS_SearchContext *sc = cls; | 1569 | struct GNUNET_FS_SearchContext *sc = cls; |
1562 | struct GNUNET_FS_ProgressInfo pi; | 1570 | struct GNUNET_FS_ProgressInfo pi; |
1563 | unsigned int i; | 1571 | unsigned int i; |
1564 | 1572 | ||
1565 | GNUNET_FS_end_top(sc->h, sc->top); | 1573 | GNUNET_FS_end_top (sc->h, sc->top); |
1566 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, | 1574 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1567 | &search_result_suspend, sc); | 1575 | &search_result_suspend, sc); |
1568 | pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND; | 1576 | pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND; |
1569 | sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); | 1577 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); |
1570 | GNUNET_break(NULL == sc->client_info); | 1578 | GNUNET_break (NULL == sc->client_info); |
1571 | if (sc->task != NULL) | 1579 | if (sc->task != NULL) |
1572 | { | 1580 | { |
1573 | GNUNET_SCHEDULER_cancel(sc->task); | 1581 | GNUNET_SCHEDULER_cancel (sc->task); |
1574 | sc->task = NULL; | 1582 | sc->task = NULL; |
1575 | } | 1583 | } |
1576 | if (NULL != sc->mq) | 1584 | if (NULL != sc->mq) |
1577 | { | 1585 | { |
1578 | GNUNET_MQ_destroy(sc->mq); | 1586 | GNUNET_MQ_destroy (sc->mq); |
1579 | sc->mq = NULL; | 1587 | sc->mq = NULL; |
1580 | } | 1588 | } |
1581 | GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); | 1589 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); |
1582 | if (NULL != sc->requests) | 1590 | if (NULL != sc->requests) |
1591 | { | ||
1592 | GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); | ||
1593 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | ||
1583 | { | 1594 | { |
1584 | GNUNET_assert(GNUNET_FS_uri_test_ksk(sc->uri)); | 1595 | GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); |
1585 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | 1596 | GNUNET_free (sc->requests[i].keyword); |
1586 | { | ||
1587 | GNUNET_CONTAINER_multihashmap_destroy(sc->requests[i].results); | ||
1588 | GNUNET_free(sc->requests[i].keyword); | ||
1589 | } | ||
1590 | } | 1597 | } |
1591 | GNUNET_free_non_null(sc->requests); | 1598 | } |
1592 | GNUNET_free_non_null(sc->emsg); | 1599 | GNUNET_free_non_null (sc->requests); |
1593 | GNUNET_FS_uri_destroy(sc->uri); | 1600 | GNUNET_free_non_null (sc->emsg); |
1594 | GNUNET_free_non_null(sc->serialization); | 1601 | GNUNET_FS_uri_destroy (sc->uri); |
1595 | GNUNET_free(sc); | 1602 | GNUNET_free_non_null (sc->serialization); |
1603 | GNUNET_free (sc); | ||
1596 | } | 1604 | } |
1597 | 1605 | ||
1598 | 1606 | ||
@@ -1608,16 +1616,16 @@ GNUNET_FS_search_signal_suspend_(void *cls) | |||
1608 | * @return context that can be used to control the search | 1616 | * @return context that can be used to control the search |
1609 | */ | 1617 | */ |
1610 | struct GNUNET_FS_SearchContext * | 1618 | struct GNUNET_FS_SearchContext * |
1611 | GNUNET_FS_search_start(struct GNUNET_FS_Handle *h, | 1619 | GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, |
1612 | const struct GNUNET_FS_Uri *uri, uint32_t anonymity, | 1620 | const struct GNUNET_FS_Uri *uri, uint32_t anonymity, |
1613 | enum GNUNET_FS_SearchOptions options, void *cctx) | 1621 | enum GNUNET_FS_SearchOptions options, void *cctx) |
1614 | { | 1622 | { |
1615 | struct GNUNET_FS_SearchContext *ret; | 1623 | struct GNUNET_FS_SearchContext *ret; |
1616 | 1624 | ||
1617 | ret = search_start(h, uri, anonymity, options, cctx, NULL); | 1625 | ret = search_start (h, uri, anonymity, options, cctx, NULL); |
1618 | if (NULL == ret) | 1626 | if (NULL == ret) |
1619 | return NULL; | 1627 | return NULL; |
1620 | ret->top = GNUNET_FS_make_top(h, &GNUNET_FS_search_signal_suspend_, ret); | 1628 | ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, ret); |
1621 | return ret; | 1629 | return ret; |
1622 | } | 1630 | } |
1623 | 1631 | ||
@@ -1628,28 +1636,28 @@ GNUNET_FS_search_start(struct GNUNET_FS_Handle *h, | |||
1628 | * @param sc context for the search that should be paused | 1636 | * @param sc context for the search that should be paused |
1629 | */ | 1637 | */ |
1630 | void | 1638 | void |
1631 | GNUNET_FS_search_pause(struct GNUNET_FS_SearchContext *sc) | 1639 | GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) |
1632 | { | 1640 | { |
1633 | struct GNUNET_FS_ProgressInfo pi; | 1641 | struct GNUNET_FS_ProgressInfo pi; |
1634 | 1642 | ||
1635 | if (NULL != sc->task) | 1643 | if (NULL != sc->task) |
1636 | { | 1644 | { |
1637 | GNUNET_SCHEDULER_cancel(sc->task); | 1645 | GNUNET_SCHEDULER_cancel (sc->task); |
1638 | sc->task = NULL; | 1646 | sc->task = NULL; |
1639 | } | 1647 | } |
1640 | if (NULL != sc->mq) | 1648 | if (NULL != sc->mq) |
1641 | { | 1649 | { |
1642 | GNUNET_MQ_destroy(sc->mq); | 1650 | GNUNET_MQ_destroy (sc->mq); |
1643 | sc->mq = NULL; | 1651 | sc->mq = NULL; |
1644 | } | 1652 | } |
1645 | GNUNET_FS_search_sync_(sc); | 1653 | GNUNET_FS_search_sync_ (sc); |
1646 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, | 1654 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1647 | &search_result_freeze_probes, | 1655 | &search_result_freeze_probes, |
1648 | sc); | 1656 | sc); |
1649 | pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED; | 1657 | pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED; |
1650 | sc->client_info = GNUNET_FS_search_make_status_(&pi, | 1658 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, |
1651 | sc->h, | 1659 | sc->h, |
1652 | sc); | 1660 | sc); |
1653 | } | 1661 | } |
1654 | 1662 | ||
1655 | 1663 | ||
@@ -1659,18 +1667,18 @@ GNUNET_FS_search_pause(struct GNUNET_FS_SearchContext *sc) | |||
1659 | * @param sc context for the search that should be resumed | 1667 | * @param sc context for the search that should be resumed |
1660 | */ | 1668 | */ |
1661 | void | 1669 | void |
1662 | GNUNET_FS_search_continue(struct GNUNET_FS_SearchContext *sc) | 1670 | GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) |
1663 | { | 1671 | { |
1664 | struct GNUNET_FS_ProgressInfo pi; | 1672 | struct GNUNET_FS_ProgressInfo pi; |
1665 | 1673 | ||
1666 | GNUNET_assert(NULL == sc->mq); | 1674 | GNUNET_assert (NULL == sc->mq); |
1667 | GNUNET_assert(NULL == sc->task); | 1675 | GNUNET_assert (NULL == sc->task); |
1668 | do_reconnect(sc); | 1676 | do_reconnect (sc); |
1669 | GNUNET_FS_search_sync_(sc); | 1677 | GNUNET_FS_search_sync_ (sc); |
1670 | pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED; | 1678 | pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED; |
1671 | sc->client_info = GNUNET_FS_search_make_status_(&pi, sc->h, sc); | 1679 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); |
1672 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, | 1680 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1673 | &search_result_resume_probes, sc); | 1681 | &search_result_resume_probes, sc); |
1674 | } | 1682 | } |
1675 | 1683 | ||
1676 | 1684 | ||
@@ -1683,48 +1691,48 @@ GNUNET_FS_search_continue(struct GNUNET_FS_SearchContext *sc) | |||
1683 | * @return #GNUNET_OK | 1691 | * @return #GNUNET_OK |
1684 | */ | 1692 | */ |
1685 | static int | 1693 | static int |
1686 | search_result_stop(void *cls, | 1694 | search_result_stop (void *cls, |
1687 | const struct GNUNET_HashCode *key, | 1695 | const struct GNUNET_HashCode *key, |
1688 | void *value) | 1696 | void *value) |
1689 | { | 1697 | { |
1690 | struct GNUNET_FS_SearchContext *sc = cls; | 1698 | struct GNUNET_FS_SearchContext *sc = cls; |
1691 | struct GNUNET_FS_SearchResult *sr = value; | 1699 | struct GNUNET_FS_SearchResult *sr = value; |
1692 | struct GNUNET_FS_ProgressInfo pi; | 1700 | struct GNUNET_FS_ProgressInfo pi; |
1693 | 1701 | ||
1694 | GNUNET_FS_search_stop_probe_(sr); | 1702 | GNUNET_FS_search_stop_probe_ (sr); |
1695 | if (NULL != sr->download) | 1703 | if (NULL != sr->download) |
1704 | { | ||
1705 | sr->download->search = NULL; | ||
1706 | sr->download->top | ||
1707 | = GNUNET_FS_make_top (sr->download->h, | ||
1708 | &GNUNET_FS_download_signal_suspend_, | ||
1709 | sr->download); | ||
1710 | if (NULL != sr->download->serialization) | ||
1696 | { | 1711 | { |
1697 | sr->download->search = NULL; | 1712 | GNUNET_FS_remove_sync_file_ (sc->h, |
1698 | sr->download->top | 1713 | GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, |
1699 | = GNUNET_FS_make_top(sr->download->h, | 1714 | sr->download->serialization); |
1700 | &GNUNET_FS_download_signal_suspend_, | 1715 | GNUNET_free (sr->download->serialization); |
1701 | sr->download); | 1716 | sr->download->serialization = NULL; |
1702 | if (NULL != sr->download->serialization) | ||
1703 | { | ||
1704 | GNUNET_FS_remove_sync_file_(sc->h, | ||
1705 | GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, | ||
1706 | sr->download->serialization); | ||
1707 | GNUNET_free(sr->download->serialization); | ||
1708 | sr->download->serialization = NULL; | ||
1709 | } | ||
1710 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; | ||
1711 | GNUNET_FS_download_make_status_(&pi, | ||
1712 | sr->download); | ||
1713 | GNUNET_FS_download_sync_(sr->download); | ||
1714 | sr->download = NULL; | ||
1715 | } | 1717 | } |
1718 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; | ||
1719 | GNUNET_FS_download_make_status_ (&pi, | ||
1720 | sr->download); | ||
1721 | GNUNET_FS_download_sync_ (sr->download); | ||
1722 | sr->download = NULL; | ||
1723 | } | ||
1716 | if (0 != sr->mandatory_missing) | 1724 | if (0 != sr->mandatory_missing) |
1717 | { | 1725 | { |
1718 | /* client is unaware of search result as | 1726 | /* client is unaware of search result as |
1719 | it does not match required keywords */ | 1727 | it does not match required keywords */ |
1720 | GNUNET_break(NULL == sr->client_info); | 1728 | GNUNET_break (NULL == sr->client_info); |
1721 | return GNUNET_OK; | 1729 | return GNUNET_OK; |
1722 | } | 1730 | } |
1723 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; | 1731 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; |
1724 | pi.value.search.specifics.result_stopped.cctx = sr->client_info; | 1732 | pi.value.search.specifics.result_stopped.cctx = sr->client_info; |
1725 | pi.value.search.specifics.result_stopped.meta = sr->meta; | 1733 | pi.value.search.specifics.result_stopped.meta = sr->meta; |
1726 | pi.value.search.specifics.result_stopped.uri = sr->uri; | 1734 | pi.value.search.specifics.result_stopped.uri = sr->uri; |
1727 | sr->client_info = GNUNET_FS_search_make_status_(&pi, sr->h, sc); | 1735 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sr->h, sc); |
1728 | return GNUNET_OK; | 1736 | return GNUNET_OK; |
1729 | } | 1737 | } |
1730 | 1738 | ||
@@ -1738,25 +1746,25 @@ search_result_stop(void *cls, | |||
1738 | * @return #GNUNET_OK | 1746 | * @return #GNUNET_OK |
1739 | */ | 1747 | */ |
1740 | static int | 1748 | static int |
1741 | search_result_free(void *cls, | 1749 | search_result_free (void *cls, |
1742 | const struct GNUNET_HashCode *key, | 1750 | const struct GNUNET_HashCode *key, |
1743 | void *value) | 1751 | void *value) |
1744 | { | 1752 | { |
1745 | struct GNUNET_FS_SearchResult *sr = value; | 1753 | struct GNUNET_FS_SearchResult *sr = value; |
1746 | 1754 | ||
1747 | if (NULL != sr->update_search) | 1755 | if (NULL != sr->update_search) |
1748 | { | 1756 | { |
1749 | GNUNET_FS_search_stop(sr->update_search); | 1757 | GNUNET_FS_search_stop (sr->update_search); |
1750 | GNUNET_assert(NULL == sr->update_search); | 1758 | GNUNET_assert (NULL == sr->update_search); |
1751 | } | 1759 | } |
1752 | GNUNET_break(NULL == sr->probe_ctx); | 1760 | GNUNET_break (NULL == sr->probe_ctx); |
1753 | GNUNET_break(NULL == sr->probe_cancel_task); | 1761 | GNUNET_break (NULL == sr->probe_cancel_task); |
1754 | GNUNET_break(NULL == sr->client_info); | 1762 | GNUNET_break (NULL == sr->client_info); |
1755 | GNUNET_free_non_null(sr->serialization); | 1763 | GNUNET_free_non_null (sr->serialization); |
1756 | GNUNET_FS_uri_destroy(sr->uri); | 1764 | GNUNET_FS_uri_destroy (sr->uri); |
1757 | GNUNET_CONTAINER_meta_data_destroy(sr->meta); | 1765 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); |
1758 | GNUNET_free_non_null(sr->keyword_bitmap); | 1766 | GNUNET_free_non_null (sr->keyword_bitmap); |
1759 | GNUNET_free(sr); | 1767 | GNUNET_free (sr); |
1760 | return GNUNET_OK; | 1768 | return GNUNET_OK; |
1761 | } | 1769 | } |
1762 | 1770 | ||
@@ -1767,60 +1775,60 @@ search_result_free(void *cls, | |||
1767 | * @param sc context for the search that should be stopped | 1775 | * @param sc context for the search that should be stopped |
1768 | */ | 1776 | */ |
1769 | void | 1777 | void |
1770 | GNUNET_FS_search_stop(struct GNUNET_FS_SearchContext *sc) | 1778 | GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) |
1771 | { | 1779 | { |
1772 | struct GNUNET_FS_ProgressInfo pi; | 1780 | struct GNUNET_FS_ProgressInfo pi; |
1773 | unsigned int i; | 1781 | unsigned int i; |
1774 | 1782 | ||
1775 | if (NULL != sc->top) | 1783 | if (NULL != sc->top) |
1776 | GNUNET_FS_end_top(sc->h, sc->top); | 1784 | GNUNET_FS_end_top (sc->h, sc->top); |
1777 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, | 1785 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1778 | &search_result_stop, | 1786 | &search_result_stop, |
1779 | sc); | 1787 | sc); |
1780 | if (NULL != sc->psearch_result) | 1788 | if (NULL != sc->psearch_result) |
1781 | sc->psearch_result->update_search = NULL; | 1789 | sc->psearch_result->update_search = NULL; |
1782 | if (NULL != sc->serialization) | 1790 | if (NULL != sc->serialization) |
1783 | { | 1791 | { |
1784 | GNUNET_FS_remove_sync_file_(sc->h, | 1792 | GNUNET_FS_remove_sync_file_ (sc->h, |
1785 | (NULL != sc->psearch_result) | ||
1786 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH | ||
1787 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | ||
1788 | sc->serialization); | ||
1789 | GNUNET_FS_remove_sync_dir_(sc->h, | ||
1790 | (NULL != sc->psearch_result) | 1793 | (NULL != sc->psearch_result) |
1791 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH | 1794 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH |
1792 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | 1795 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, |
1793 | sc->serialization); | 1796 | sc->serialization); |
1794 | GNUNET_free(sc->serialization); | 1797 | GNUNET_FS_remove_sync_dir_ (sc->h, |
1795 | } | 1798 | (NULL != sc->psearch_result) |
1799 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH | ||
1800 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | ||
1801 | sc->serialization); | ||
1802 | GNUNET_free (sc->serialization); | ||
1803 | } | ||
1796 | pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; | 1804 | pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; |
1797 | sc->client_info = GNUNET_FS_search_make_status_(&pi, | 1805 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, |
1798 | sc->h, | 1806 | sc->h, |
1799 | sc); | 1807 | sc); |
1800 | GNUNET_break(NULL == sc->client_info); | 1808 | GNUNET_break (NULL == sc->client_info); |
1801 | if (NULL != sc->task) | 1809 | if (NULL != sc->task) |
1802 | { | 1810 | { |
1803 | GNUNET_SCHEDULER_cancel(sc->task); | 1811 | GNUNET_SCHEDULER_cancel (sc->task); |
1804 | sc->task = NULL; | 1812 | sc->task = NULL; |
1805 | } | 1813 | } |
1806 | if (NULL != sc->mq) | 1814 | if (NULL != sc->mq) |
1807 | { | 1815 | { |
1808 | GNUNET_MQ_destroy(sc->mq); | 1816 | GNUNET_MQ_destroy (sc->mq); |
1809 | sc->mq = NULL; | 1817 | sc->mq = NULL; |
1810 | } | 1818 | } |
1811 | GNUNET_CONTAINER_multihashmap_iterate(sc->master_result_map, | 1819 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1812 | &search_result_free, sc); | 1820 | &search_result_free, sc); |
1813 | GNUNET_CONTAINER_multihashmap_destroy(sc->master_result_map); | 1821 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); |
1814 | if (NULL != sc->requests) | 1822 | if (NULL != sc->requests) |
1815 | { | 1823 | { |
1816 | GNUNET_assert(GNUNET_FS_uri_test_ksk(sc->uri)); | 1824 | GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); |
1817 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | 1825 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
1818 | GNUNET_CONTAINER_multihashmap_destroy(sc->requests[i].results); | 1826 | GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); |
1819 | } | 1827 | } |
1820 | GNUNET_free_non_null(sc->requests); | 1828 | GNUNET_free_non_null (sc->requests); |
1821 | GNUNET_free_non_null(sc->emsg); | 1829 | GNUNET_free_non_null (sc->emsg); |
1822 | GNUNET_FS_uri_destroy(sc->uri); | 1830 | GNUNET_FS_uri_destroy (sc->uri); |
1823 | GNUNET_free(sc); | 1831 | GNUNET_free (sc); |
1824 | } | 1832 | } |
1825 | 1833 | ||
1826 | /* end of fs_search.c */ | 1834 | /* end of fs_search.c */ |
diff --git a/src/fs/fs_sharetree.c b/src/fs/fs_sharetree.c index a2cc37170..dab5d00a0 100644 --- a/src/fs/fs_sharetree.c +++ b/src/fs/fs_sharetree.c | |||
@@ -34,7 +34,8 @@ | |||
34 | * Entry for each unique keyword to track how often | 34 | * Entry for each unique keyword to track how often |
35 | * it occured. Contains the keyword and the counter. | 35 | * it occured. Contains the keyword and the counter. |
36 | */ | 36 | */ |
37 | struct KeywordCounter { | 37 | struct KeywordCounter |
38 | { | ||
38 | /** | 39 | /** |
39 | * This is a doubly-linked list | 40 | * This is a doubly-linked list |
40 | */ | 41 | */ |
@@ -60,7 +61,8 @@ struct KeywordCounter { | |||
60 | /** | 61 | /** |
61 | * Aggregate information we keep for meta data in each directory. | 62 | * Aggregate information we keep for meta data in each directory. |
62 | */ | 63 | */ |
63 | struct MetaCounter { | 64 | struct MetaCounter |
65 | { | ||
64 | /** | 66 | /** |
65 | * This is a doubly-linked list | 67 | * This is a doubly-linked list |
66 | */ | 68 | */ |
@@ -113,7 +115,8 @@ struct MetaCounter { | |||
113 | * A structure that forms a singly-linked list that serves as a stack | 115 | * A structure that forms a singly-linked list that serves as a stack |
114 | * for metadata-processing function. | 116 | * for metadata-processing function. |
115 | */ | 117 | */ |
116 | struct TrimContext { | 118 | struct TrimContext |
119 | { | ||
117 | /** | 120 | /** |
118 | * Map from the hash over the keyword to an 'struct KeywordCounter *' | 121 | * Map from the hash over the keyword to an 'struct KeywordCounter *' |
119 | * counter that says how often this keyword was | 122 | * counter that says how often this keyword was |
@@ -149,26 +152,26 @@ struct TrimContext { | |||
149 | * @return always GNUNET_OK | 152 | * @return always GNUNET_OK |
150 | */ | 153 | */ |
151 | static int | 154 | static int |
152 | add_to_keyword_counter(void *cls, const char *keyword, int is_mandatory) | 155 | add_to_keyword_counter (void *cls, const char *keyword, int is_mandatory) |
153 | { | 156 | { |
154 | struct GNUNET_CONTAINER_MultiHashMap *mcm = cls; | 157 | struct GNUNET_CONTAINER_MultiHashMap *mcm = cls; |
155 | struct KeywordCounter *cnt; | 158 | struct KeywordCounter *cnt; |
156 | struct GNUNET_HashCode hc; | 159 | struct GNUNET_HashCode hc; |
157 | size_t klen; | 160 | size_t klen; |
158 | 161 | ||
159 | klen = strlen(keyword) + 1; | 162 | klen = strlen (keyword) + 1; |
160 | GNUNET_CRYPTO_hash(keyword, klen - 1, &hc); | 163 | GNUNET_CRYPTO_hash (keyword, klen - 1, &hc); |
161 | cnt = GNUNET_CONTAINER_multihashmap_get(mcm, &hc); | 164 | cnt = GNUNET_CONTAINER_multihashmap_get (mcm, &hc); |
162 | if (cnt == NULL) | 165 | if (cnt == NULL) |
163 | { | 166 | { |
164 | cnt = GNUNET_malloc(sizeof(struct KeywordCounter) + klen); | 167 | cnt = GNUNET_malloc (sizeof(struct KeywordCounter) + klen); |
165 | cnt->value = (const char *)&cnt[1]; | 168 | cnt->value = (const char *) &cnt[1]; |
166 | GNUNET_memcpy(&cnt[1], keyword, klen); | 169 | GNUNET_memcpy (&cnt[1], keyword, klen); |
167 | GNUNET_assert(GNUNET_OK == | 170 | GNUNET_assert (GNUNET_OK == |
168 | GNUNET_CONTAINER_multihashmap_put(mcm, | 171 | GNUNET_CONTAINER_multihashmap_put (mcm, |
169 | &hc, cnt, | 172 | &hc, cnt, |
170 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 173 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
171 | } | 174 | } |
172 | cnt->count++; | 175 | cnt->count++; |
173 | return GNUNET_OK; | 176 | return GNUNET_OK; |
174 | } | 177 | } |
@@ -192,30 +195,32 @@ add_to_keyword_counter(void *cls, const char *keyword, int is_mandatory) | |||
192 | * @return 0 to continue extracting / iterating | 195 | * @return 0 to continue extracting / iterating |
193 | */ | 196 | */ |
194 | static int | 197 | static int |
195 | add_to_meta_counter(void *cls, const char *plugin_name, | 198 | add_to_meta_counter (void *cls, const char *plugin_name, |
196 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, | 199 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat |
197 | const char *data_mime_type, const char *data, size_t data_len) | 200 | format, |
201 | const char *data_mime_type, const char *data, size_t | ||
202 | data_len) | ||
198 | { | 203 | { |
199 | struct GNUNET_CONTAINER_MultiHashMap *map = cls; | 204 | struct GNUNET_CONTAINER_MultiHashMap *map = cls; |
200 | struct GNUNET_HashCode key; | 205 | struct GNUNET_HashCode key; |
201 | struct MetaCounter *cnt; | 206 | struct MetaCounter *cnt; |
202 | 207 | ||
203 | GNUNET_CRYPTO_hash(data, data_len, &key); | 208 | GNUNET_CRYPTO_hash (data, data_len, &key); |
204 | cnt = GNUNET_CONTAINER_multihashmap_get(map, &key); | 209 | cnt = GNUNET_CONTAINER_multihashmap_get (map, &key); |
205 | if (NULL == cnt) | 210 | if (NULL == cnt) |
206 | { | 211 | { |
207 | cnt = GNUNET_new(struct MetaCounter); | 212 | cnt = GNUNET_new (struct MetaCounter); |
208 | cnt->data = data; | 213 | cnt->data = data; |
209 | cnt->data_size = data_len; | 214 | cnt->data_size = data_len; |
210 | cnt->plugin_name = plugin_name; | 215 | cnt->plugin_name = plugin_name; |
211 | cnt->type = type; | 216 | cnt->type = type; |
212 | cnt->format = format; | 217 | cnt->format = format; |
213 | cnt->data_mime_type = data_mime_type; | 218 | cnt->data_mime_type = data_mime_type; |
214 | GNUNET_assert(GNUNET_OK == | 219 | GNUNET_assert (GNUNET_OK == |
215 | GNUNET_CONTAINER_multihashmap_put(map, | 220 | GNUNET_CONTAINER_multihashmap_put (map, |
216 | &key, cnt, | 221 | &key, cnt, |
217 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 222 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
218 | } | 223 | } |
219 | cnt->count++; | 224 | cnt->count++; |
220 | return 0; | 225 | return 0; |
221 | } | 226 | } |
@@ -230,21 +235,22 @@ add_to_meta_counter(void *cls, const char *plugin_name, | |||
230 | * @return always GNUNET_OK | 235 | * @return always GNUNET_OK |
231 | */ | 236 | */ |
232 | static int | 237 | static int |
233 | remove_high_frequency_keywords(void *cls, const char *keyword, int is_mandatory) | 238 | remove_high_frequency_keywords (void *cls, const char *keyword, int |
239 | is_mandatory) | ||
234 | { | 240 | { |
235 | struct TrimContext *tc = cls; | 241 | struct TrimContext *tc = cls; |
236 | struct KeywordCounter *counter; | 242 | struct KeywordCounter *counter; |
237 | struct GNUNET_HashCode hc; | 243 | struct GNUNET_HashCode hc; |
238 | size_t klen; | 244 | size_t klen; |
239 | 245 | ||
240 | klen = strlen(keyword) + 1; | 246 | klen = strlen (keyword) + 1; |
241 | GNUNET_CRYPTO_hash(keyword, klen - 1, &hc); | 247 | GNUNET_CRYPTO_hash (keyword, klen - 1, &hc); |
242 | counter = GNUNET_CONTAINER_multihashmap_get(tc->keywordcounter, &hc); | 248 | counter = GNUNET_CONTAINER_multihashmap_get (tc->keywordcounter, &hc); |
243 | GNUNET_assert(NULL != counter); | 249 | GNUNET_assert (NULL != counter); |
244 | if (counter->count < tc->move_threshold) | 250 | if (counter->count < tc->move_threshold) |
245 | return GNUNET_OK; | 251 | return GNUNET_OK; |
246 | GNUNET_FS_uri_ksk_remove_keyword(tc->pos->ksk_uri, | 252 | GNUNET_FS_uri_ksk_remove_keyword (tc->pos->ksk_uri, |
247 | counter->value); | 253 | counter->value); |
248 | return GNUNET_OK; | 254 | return GNUNET_OK; |
249 | } | 255 | } |
250 | 256 | ||
@@ -259,23 +265,26 @@ remove_high_frequency_keywords(void *cls, const char *keyword, int is_mandatory) | |||
259 | * @return GNUNET_YES (always) | 265 | * @return GNUNET_YES (always) |
260 | */ | 266 | */ |
261 | static int | 267 | static int |
262 | migrate_and_drop_keywords(void *cls, const struct GNUNET_HashCode * key, void *value) | 268 | migrate_and_drop_keywords (void *cls, const struct GNUNET_HashCode *key, |
269 | void *value) | ||
263 | { | 270 | { |
264 | struct TrimContext *tc = cls; | 271 | struct TrimContext *tc = cls; |
265 | struct KeywordCounter *counter = value; | 272 | struct KeywordCounter *counter = value; |
266 | 273 | ||
267 | if (counter->count >= tc->move_threshold) | 274 | if (counter->count >= tc->move_threshold) |
268 | { | 275 | { |
269 | if (NULL == tc->pos->ksk_uri) | 276 | if (NULL == tc->pos->ksk_uri) |
270 | tc->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_args(1, &counter->value); | 277 | tc->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, |
271 | else | 278 | &counter->value); |
272 | GNUNET_FS_uri_ksk_add_keyword(tc->pos->ksk_uri, counter->value, GNUNET_NO); | 279 | else |
273 | } | 280 | GNUNET_FS_uri_ksk_add_keyword (tc->pos->ksk_uri, counter->value, |
274 | GNUNET_assert(GNUNET_YES == | 281 | GNUNET_NO); |
275 | GNUNET_CONTAINER_multihashmap_remove(tc->keywordcounter, | 282 | } |
276 | key, | 283 | GNUNET_assert (GNUNET_YES == |
277 | counter)); | 284 | GNUNET_CONTAINER_multihashmap_remove (tc->keywordcounter, |
278 | GNUNET_free(counter); | 285 | key, |
286 | counter)); | ||
287 | GNUNET_free (counter); | ||
279 | return GNUNET_YES; | 288 | return GNUNET_YES; |
280 | } | 289 | } |
281 | 290 | ||
@@ -290,27 +299,28 @@ migrate_and_drop_keywords(void *cls, const struct GNUNET_HashCode * key, void *v | |||
290 | * @return GNUNET_YES (always) | 299 | * @return GNUNET_YES (always) |
291 | */ | 300 | */ |
292 | static int | 301 | static int |
293 | migrate_and_drop_metadata(void *cls, const struct GNUNET_HashCode * key, void *value) | 302 | migrate_and_drop_metadata (void *cls, const struct GNUNET_HashCode *key, |
303 | void *value) | ||
294 | { | 304 | { |
295 | struct TrimContext *tc = cls; | 305 | struct TrimContext *tc = cls; |
296 | struct MetaCounter *counter = value; | 306 | struct MetaCounter *counter = value; |
297 | 307 | ||
298 | if (counter->count >= tc->move_threshold) | 308 | if (counter->count >= tc->move_threshold) |
299 | { | 309 | { |
300 | if (NULL == tc->pos->meta) | 310 | if (NULL == tc->pos->meta) |
301 | tc->pos->meta = GNUNET_CONTAINER_meta_data_create(); | 311 | tc->pos->meta = GNUNET_CONTAINER_meta_data_create (); |
302 | GNUNET_CONTAINER_meta_data_insert(tc->pos->meta, | 312 | GNUNET_CONTAINER_meta_data_insert (tc->pos->meta, |
303 | counter->plugin_name, | 313 | counter->plugin_name, |
304 | counter->type, | 314 | counter->type, |
305 | counter->format, | 315 | counter->format, |
306 | counter->data_mime_type, counter->data, | 316 | counter->data_mime_type, counter->data, |
307 | counter->data_size); | 317 | counter->data_size); |
308 | } | 318 | } |
309 | GNUNET_assert(GNUNET_YES == | 319 | GNUNET_assert (GNUNET_YES == |
310 | GNUNET_CONTAINER_multihashmap_remove(tc->metacounter, | 320 | GNUNET_CONTAINER_multihashmap_remove (tc->metacounter, |
311 | key, | 321 | key, |
312 | counter)); | 322 | counter)); |
313 | GNUNET_free(counter); | 323 | GNUNET_free (counter); |
314 | return GNUNET_YES; | 324 | return GNUNET_YES; |
315 | } | 325 | } |
316 | 326 | ||
@@ -323,8 +333,8 @@ migrate_and_drop_metadata(void *cls, const struct GNUNET_HashCode * key, void *v | |||
323 | * @param tree tree to trim | 333 | * @param tree tree to trim |
324 | */ | 334 | */ |
325 | static void | 335 | static void |
326 | share_tree_trim(struct TrimContext *tc, | 336 | share_tree_trim (struct TrimContext *tc, |
327 | struct GNUNET_FS_ShareTreeItem *tree) | 337 | struct GNUNET_FS_ShareTreeItem *tree) |
328 | { | 338 | { |
329 | struct GNUNET_FS_ShareTreeItem *pos; | 339 | struct GNUNET_FS_ShareTreeItem *pos; |
330 | unsigned int num_children; | 340 | unsigned int num_children; |
@@ -332,64 +342,67 @@ share_tree_trim(struct TrimContext *tc, | |||
332 | /* first, trim all children */ | 342 | /* first, trim all children */ |
333 | num_children = 0; | 343 | num_children = 0; |
334 | for (pos = tree->children_head; NULL != pos; pos = pos->next) | 344 | for (pos = tree->children_head; NULL != pos; pos = pos->next) |
335 | { | 345 | { |
336 | share_tree_trim(tc, pos); | 346 | share_tree_trim (tc, pos); |
337 | num_children++; | 347 | num_children++; |
338 | } | 348 | } |
339 | 349 | ||
340 | /* consider adding filename to directory meta data */ | 350 | /* consider adding filename to directory meta data */ |
341 | if (tree->is_directory == GNUNET_YES) | 351 | if (tree->is_directory == GNUNET_YES) |
352 | { | ||
353 | const char *user = getenv ("USER"); | ||
354 | if ((user == NULL) || | ||
355 | (0 != strncasecmp (user, tree->short_filename, strlen (user)))) | ||
342 | { | 356 | { |
343 | const char *user = getenv("USER"); | 357 | /* only use filename if it doesn't match $USER */ |
344 | if ((user == NULL) || | 358 | if (NULL == tree->meta) |
345 | (0 != strncasecmp(user, tree->short_filename, strlen(user)))) | 359 | tree->meta = GNUNET_CONTAINER_meta_data_create (); |
346 | { | 360 | GNUNET_CONTAINER_meta_data_insert (tree->meta, "<libgnunetfs>", |
347 | /* only use filename if it doesn't match $USER */ | 361 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, |
348 | if (NULL == tree->meta) | 362 | EXTRACTOR_METAFORMAT_UTF8, |
349 | tree->meta = GNUNET_CONTAINER_meta_data_create(); | 363 | "text/plain", tree->short_filename, |
350 | GNUNET_CONTAINER_meta_data_insert(tree->meta, "<libgnunetfs>", | 364 | strlen (tree->short_filename) + 1); |
351 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
352 | EXTRACTOR_METAFORMAT_UTF8, | ||
353 | "text/plain", tree->short_filename, | ||
354 | strlen(tree->short_filename) + 1); | ||
355 | } | ||
356 | } | 365 | } |
366 | } | ||
357 | 367 | ||
358 | if (1 >= num_children) | 368 | if (1 >= num_children) |
359 | return; /* nothing to trim */ | 369 | return; /* nothing to trim */ |
360 | 370 | ||
361 | /* now, count keywords and meta data in children */ | 371 | /* now, count keywords and meta data in children */ |
362 | for (pos = tree->children_head; NULL != pos; pos = pos->next) | 372 | for (pos = tree->children_head; NULL != pos; pos = pos->next) |
363 | { | 373 | { |
364 | if (NULL != pos->meta) | 374 | if (NULL != pos->meta) |
365 | GNUNET_CONTAINER_meta_data_iterate(pos->meta, &add_to_meta_counter, tc->metacounter); | 375 | GNUNET_CONTAINER_meta_data_iterate (pos->meta, &add_to_meta_counter, |
366 | if (NULL != pos->ksk_uri) | 376 | tc->metacounter); |
367 | GNUNET_FS_uri_ksk_get_keywords(pos->ksk_uri, &add_to_keyword_counter, tc->keywordcounter); | 377 | if (NULL != pos->ksk_uri) |
368 | } | 378 | GNUNET_FS_uri_ksk_get_keywords (pos->ksk_uri, &add_to_keyword_counter, |
379 | tc->keywordcounter); | ||
380 | } | ||
369 | 381 | ||
370 | /* calculate threshold for moving keywords / meta data */ | 382 | /* calculate threshold for moving keywords / meta data */ |
371 | tc->move_threshold = 1 + (num_children / 2); | 383 | tc->move_threshold = 1 + (num_children / 2); |
372 | 384 | ||
373 | /* remove high-frequency keywords from children */ | 385 | /* remove high-frequency keywords from children */ |
374 | for (pos = tree->children_head; NULL != pos; pos = pos->next) | 386 | for (pos = tree->children_head; NULL != pos; pos = pos->next) |
387 | { | ||
388 | tc->pos = pos; | ||
389 | if (NULL != pos->ksk_uri) | ||
375 | { | 390 | { |
376 | tc->pos = pos; | 391 | struct GNUNET_FS_Uri *ksk_uri_copy = GNUNET_FS_uri_dup (pos->ksk_uri); |
377 | if (NULL != pos->ksk_uri) | 392 | GNUNET_FS_uri_ksk_get_keywords (ksk_uri_copy, |
378 | { | 393 | &remove_high_frequency_keywords, tc); |
379 | struct GNUNET_FS_Uri *ksk_uri_copy = GNUNET_FS_uri_dup(pos->ksk_uri); | 394 | GNUNET_FS_uri_destroy (ksk_uri_copy); |
380 | GNUNET_FS_uri_ksk_get_keywords(ksk_uri_copy, &remove_high_frequency_keywords, tc); | ||
381 | GNUNET_FS_uri_destroy(ksk_uri_copy); | ||
382 | } | ||
383 | } | 395 | } |
396 | } | ||
384 | 397 | ||
385 | /* add high-frequency meta data and keywords to parent */ | 398 | /* add high-frequency meta data and keywords to parent */ |
386 | tc->pos = tree; | 399 | tc->pos = tree; |
387 | GNUNET_CONTAINER_multihashmap_iterate(tc->keywordcounter, | 400 | GNUNET_CONTAINER_multihashmap_iterate (tc->keywordcounter, |
388 | &migrate_and_drop_keywords, | 401 | &migrate_and_drop_keywords, |
389 | tc); | 402 | tc); |
390 | GNUNET_CONTAINER_multihashmap_iterate(tc->metacounter, | 403 | GNUNET_CONTAINER_multihashmap_iterate (tc->metacounter, |
391 | &migrate_and_drop_metadata, | 404 | &migrate_and_drop_metadata, |
392 | tc); | 405 | tc); |
393 | } | 406 | } |
394 | 407 | ||
395 | 408 | ||
@@ -400,17 +413,17 @@ share_tree_trim(struct TrimContext *tc, | |||
400 | * @param toplevel toplevel directory in the tree, returned by the scanner | 413 | * @param toplevel toplevel directory in the tree, returned by the scanner |
401 | */ | 414 | */ |
402 | void | 415 | void |
403 | GNUNET_FS_share_tree_trim(struct GNUNET_FS_ShareTreeItem *toplevel) | 416 | GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel) |
404 | { | 417 | { |
405 | struct TrimContext tc; | 418 | struct TrimContext tc; |
406 | 419 | ||
407 | if (toplevel == NULL) | 420 | if (toplevel == NULL) |
408 | return; | 421 | return; |
409 | tc.keywordcounter = GNUNET_CONTAINER_multihashmap_create(1024, GNUNET_NO); | 422 | tc.keywordcounter = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); |
410 | tc.metacounter = GNUNET_CONTAINER_multihashmap_create(1024, GNUNET_NO); | 423 | tc.metacounter = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); |
411 | share_tree_trim(&tc, toplevel); | 424 | share_tree_trim (&tc, toplevel); |
412 | GNUNET_CONTAINER_multihashmap_destroy(tc.keywordcounter); | 425 | GNUNET_CONTAINER_multihashmap_destroy (tc.keywordcounter); |
413 | GNUNET_CONTAINER_multihashmap_destroy(tc.metacounter); | 426 | GNUNET_CONTAINER_multihashmap_destroy (tc.metacounter); |
414 | } | 427 | } |
415 | 428 | ||
416 | 429 | ||
@@ -420,24 +433,23 @@ GNUNET_FS_share_tree_trim(struct GNUNET_FS_ShareTreeItem *toplevel) | |||
420 | * @param toplevel toplevel of the tree to be freed | 433 | * @param toplevel toplevel of the tree to be freed |
421 | */ | 434 | */ |
422 | void | 435 | void |
423 | GNUNET_FS_share_tree_free(struct GNUNET_FS_ShareTreeItem *toplevel) | 436 | GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel) |
424 | { | 437 | { |
425 | struct GNUNET_FS_ShareTreeItem *pos; | 438 | struct GNUNET_FS_ShareTreeItem *pos; |
426 | 439 | ||
427 | while (NULL != (pos = toplevel->children_head)) | 440 | while (NULL != (pos = toplevel->children_head)) |
428 | GNUNET_FS_share_tree_free(pos); | 441 | GNUNET_FS_share_tree_free (pos); |
429 | if (NULL != toplevel->parent) | 442 | if (NULL != toplevel->parent) |
430 | GNUNET_CONTAINER_DLL_remove(toplevel->parent->children_head, | 443 | GNUNET_CONTAINER_DLL_remove (toplevel->parent->children_head, |
431 | toplevel->parent->children_tail, | 444 | toplevel->parent->children_tail, |
432 | toplevel); | 445 | toplevel); |
433 | if (NULL != toplevel->meta) | 446 | if (NULL != toplevel->meta) |
434 | GNUNET_CONTAINER_meta_data_destroy(toplevel->meta); | 447 | GNUNET_CONTAINER_meta_data_destroy (toplevel->meta); |
435 | if (NULL != toplevel->ksk_uri) | 448 | if (NULL != toplevel->ksk_uri) |
436 | GNUNET_FS_uri_destroy(toplevel->ksk_uri); | 449 | GNUNET_FS_uri_destroy (toplevel->ksk_uri); |
437 | GNUNET_free_non_null(toplevel->filename); | 450 | GNUNET_free_non_null (toplevel->filename); |
438 | GNUNET_free_non_null(toplevel->short_filename); | 451 | GNUNET_free_non_null (toplevel->short_filename); |
439 | GNUNET_free(toplevel); | 452 | GNUNET_free (toplevel); |
440 | } | 453 | } |
441 | 454 | ||
442 | /* end fs_sharetree.c */ | 455 | /* end fs_sharetree.c */ |
443 | |||
diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c index e3ab0ec88..a0fe336df 100644 --- a/src/fs/fs_test_lib.c +++ b/src/fs/fs_test_lib.c | |||
@@ -37,7 +37,8 @@ | |||
37 | /** | 37 | /** |
38 | * Handle for a publishing operation started for testing FS. | 38 | * Handle for a publishing operation started for testing FS. |
39 | */ | 39 | */ |
40 | struct TestPublishOperation { | 40 | struct TestPublishOperation |
41 | { | ||
41 | /** | 42 | /** |
42 | * Handle for the operation to connect to the peer's 'fs' service. | 43 | * Handle for the operation to connect to the peer's 'fs' service. |
43 | */ | 44 | */ |
@@ -61,7 +62,7 @@ struct TestPublishOperation { | |||
61 | /** | 62 | /** |
62 | * Task to abort publishing (timeout). | 63 | * Task to abort publishing (timeout). |
63 | */ | 64 | */ |
64 | struct GNUNET_SCHEDULER_Task * publish_timeout_task; | 65 | struct GNUNET_SCHEDULER_Task *publish_timeout_task; |
65 | 66 | ||
66 | /** | 67 | /** |
67 | * Seed for file generation. | 68 | * Seed for file generation. |
@@ -108,7 +109,8 @@ struct TestPublishOperation { | |||
108 | /** | 109 | /** |
109 | * Handle for a download operation started for testing FS. | 110 | * Handle for a download operation started for testing FS. |
110 | */ | 111 | */ |
111 | struct TestDownloadOperation { | 112 | struct TestDownloadOperation |
113 | { | ||
112 | /** | 114 | /** |
113 | * Handle for the operation to connect to the peer's 'fs' service. | 115 | * Handle for the operation to connect to the peer's 'fs' service. |
114 | */ | 116 | */ |
@@ -142,7 +144,7 @@ struct TestDownloadOperation { | |||
142 | /** | 144 | /** |
143 | * Task to abort downloading (timeout). | 145 | * Task to abort downloading (timeout). |
144 | */ | 146 | */ |
145 | struct GNUNET_SCHEDULER_Task * download_timeout_task; | 147 | struct GNUNET_SCHEDULER_Task *download_timeout_task; |
146 | 148 | ||
147 | /** | 149 | /** |
148 | * Context for current download operation. | 150 | * Context for current download operation. |
@@ -178,23 +180,23 @@ struct TestDownloadOperation { | |||
178 | * @param tc scheduler context (unused) | 180 | * @param tc scheduler context (unused) |
179 | */ | 181 | */ |
180 | static void | 182 | static void |
181 | report_uri(void *cls) | 183 | report_uri (void *cls) |
182 | { | 184 | { |
183 | struct TestPublishOperation *po = cls; | 185 | struct TestPublishOperation *po = cls; |
184 | 186 | ||
185 | GNUNET_FS_publish_stop(po->publish_context); | 187 | GNUNET_FS_publish_stop (po->publish_context); |
186 | GNUNET_TESTBED_operation_done(po->fs_op); | 188 | GNUNET_TESTBED_operation_done (po->fs_op); |
187 | po->publish_cont(po->publish_cont_cls, | 189 | po->publish_cont (po->publish_cont_cls, |
188 | po->publish_uri, | 190 | po->publish_uri, |
189 | (GNUNET_YES == po->do_index) | 191 | (GNUNET_YES == po->do_index) |
190 | ? po->publish_tmp_file | 192 | ? po->publish_tmp_file |
191 | : NULL); | 193 | : NULL); |
192 | GNUNET_FS_uri_destroy(po->publish_uri); | 194 | GNUNET_FS_uri_destroy (po->publish_uri); |
193 | if ((GNUNET_YES != po->do_index) && | 195 | if ((GNUNET_YES != po->do_index) && |
194 | (NULL != po->publish_tmp_file)) | 196 | (NULL != po->publish_tmp_file)) |
195 | (void)GNUNET_DISK_directory_remove(po->publish_tmp_file); | 197 | (void) GNUNET_DISK_directory_remove (po->publish_tmp_file); |
196 | GNUNET_free_non_null(po->publish_tmp_file); | 198 | GNUNET_free_non_null (po->publish_tmp_file); |
197 | GNUNET_free(po); | 199 | GNUNET_free (po); |
198 | } | 200 | } |
199 | 201 | ||
200 | 202 | ||
@@ -204,19 +206,19 @@ report_uri(void *cls) | |||
204 | * @param cls the publish operation context | 206 | * @param cls the publish operation context |
205 | */ | 207 | */ |
206 | static void | 208 | static void |
207 | publish_timeout(void *cls) | 209 | publish_timeout (void *cls) |
208 | { | 210 | { |
209 | struct TestPublishOperation *po = cls; | 211 | struct TestPublishOperation *po = cls; |
210 | 212 | ||
211 | po->publish_timeout_task = NULL; | 213 | po->publish_timeout_task = NULL; |
212 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 214 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
213 | "Timeout while trying to publish data\n"); | 215 | "Timeout while trying to publish data\n"); |
214 | GNUNET_TESTBED_operation_done(po->fs_op); | 216 | GNUNET_TESTBED_operation_done (po->fs_op); |
215 | GNUNET_FS_publish_stop(po->publish_context); | 217 | GNUNET_FS_publish_stop (po->publish_context); |
216 | po->publish_cont(po->publish_cont_cls, NULL, NULL); | 218 | po->publish_cont (po->publish_cont_cls, NULL, NULL); |
217 | (void)GNUNET_DISK_directory_remove(po->publish_tmp_file); | 219 | (void) GNUNET_DISK_directory_remove (po->publish_tmp_file); |
218 | GNUNET_free_non_null(po->publish_tmp_file); | 220 | GNUNET_free_non_null (po->publish_tmp_file); |
219 | GNUNET_free(po); | 221 | GNUNET_free (po); |
220 | } | 222 | } |
221 | 223 | ||
222 | 224 | ||
@@ -227,41 +229,41 @@ publish_timeout(void *cls) | |||
227 | * @param info information about the event | 229 | * @param info information about the event |
228 | */ | 230 | */ |
229 | static void * | 231 | static void * |
230 | publish_progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) | 232 | publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
231 | { | 233 | { |
232 | struct TestPublishOperation *po = cls; | 234 | struct TestPublishOperation *po = cls; |
233 | 235 | ||
234 | switch (info->status) | 236 | switch (info->status) |
235 | { | 237 | { |
236 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 238 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
237 | GNUNET_SCHEDULER_cancel(po->publish_timeout_task); | 239 | GNUNET_SCHEDULER_cancel (po->publish_timeout_task); |
238 | po->publish_timeout_task = NULL; | 240 | po->publish_timeout_task = NULL; |
239 | po->publish_uri = | 241 | po->publish_uri = |
240 | GNUNET_FS_uri_dup(info->value.publish.specifics.completed.chk_uri); | 242 | GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri); |
241 | GNUNET_SCHEDULER_add_now(&report_uri, | 243 | GNUNET_SCHEDULER_add_now (&report_uri, |
242 | po); | 244 | po); |
243 | break; | 245 | break; |
244 | 246 | ||
245 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 247 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
246 | if (po->verbose) | 248 | if (po->verbose) |
247 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n", | 249 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n", |
248 | (unsigned long long)info->value.publish.completed, | 250 | (unsigned long long) info->value.publish.completed, |
249 | (unsigned long long)info->value.publish.size); | 251 | (unsigned long long) info->value.publish.size); |
250 | break; | 252 | break; |
251 | 253 | ||
252 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 254 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
253 | break; | 255 | break; |
254 | 256 | ||
255 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 257 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
256 | if (po->verbose) | 258 | if (po->verbose) |
257 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n", | 259 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n", |
258 | (unsigned long long)info->value.download.completed, | 260 | (unsigned long long) info->value.download.completed, |
259 | (unsigned long long)info->value.download.size); | 261 | (unsigned long long) info->value.download.size); |
260 | break; | 262 | break; |
261 | 263 | ||
262 | default: | 264 | default: |
263 | break; | 265 | break; |
264 | } | 266 | } |
265 | return NULL; | 267 | return NULL; |
266 | } | 268 | } |
267 | 269 | ||
@@ -277,11 +279,11 @@ publish_progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
277 | * @return number of bytes written to buf | 279 | * @return number of bytes written to buf |
278 | */ | 280 | */ |
279 | static size_t | 281 | static size_t |
280 | file_generator(void *cls, | 282 | file_generator (void *cls, |
281 | uint64_t offset, | 283 | uint64_t offset, |
282 | size_t max, | 284 | size_t max, |
283 | void *buf, | 285 | void *buf, |
284 | char **emsg) | 286 | char **emsg) |
285 | { | 287 | { |
286 | uint32_t *publish_seed = cls; | 288 | uint32_t *publish_seed = cls; |
287 | uint64_t pos; | 289 | uint64_t pos; |
@@ -293,14 +295,14 @@ file_generator(void *cls, | |||
293 | if (buf == NULL) | 295 | if (buf == NULL) |
294 | return 0; | 296 | return 0; |
295 | for (pos = 0; pos < 8; pos++) | 297 | for (pos = 0; pos < 8; pos++) |
296 | cbuf[pos] = (uint8_t)(offset >> pos * 8); | 298 | cbuf[pos] = (uint8_t) (offset >> pos * 8); |
297 | for (pos = 8; pos < max; pos++) | 299 | for (pos = 8; pos < max; pos++) |
298 | { | 300 | { |
299 | mod = (255 - (offset / 1024 / 32)); | 301 | mod = (255 - (offset / 1024 / 32)); |
300 | if (mod == 0) | 302 | if (mod == 0) |
301 | mod = 1; | 303 | mod = 1; |
302 | cbuf[pos] = (uint8_t)((offset * (*publish_seed)) % mod); | 304 | cbuf[pos] = (uint8_t) ((offset * (*publish_seed)) % mod); |
303 | } | 305 | } |
304 | return max; | 306 | return max; |
305 | } | 307 | } |
306 | 308 | ||
@@ -315,16 +317,16 @@ file_generator(void *cls, | |||
315 | * @return service handle to return in 'op_result', NULL on error | 317 | * @return service handle to return in 'op_result', NULL on error |
316 | */ | 318 | */ |
317 | static void * | 319 | static void * |
318 | publish_connect_adapter(void *cls, | 320 | publish_connect_adapter (void *cls, |
319 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 321 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
320 | { | 322 | { |
321 | struct TestPublishOperation *po = cls; | 323 | struct TestPublishOperation *po = cls; |
322 | 324 | ||
323 | return GNUNET_FS_start(cfg, | 325 | return GNUNET_FS_start (cfg, |
324 | "fs-test-publish", | 326 | "fs-test-publish", |
325 | &publish_progress_cb, po, | 327 | &publish_progress_cb, po, |
326 | GNUNET_FS_FLAGS_NONE, | 328 | GNUNET_FS_FLAGS_NONE, |
327 | GNUNET_FS_OPTIONS_END); | 329 | GNUNET_FS_OPTIONS_END); |
328 | } | 330 | } |
329 | 331 | ||
330 | 332 | ||
@@ -335,12 +337,12 @@ publish_connect_adapter(void *cls, | |||
335 | * @param op_result unused (different for publish/download!) | 337 | * @param op_result unused (different for publish/download!) |
336 | */ | 338 | */ |
337 | static void | 339 | static void |
338 | fs_disconnect_adapter(void *cls, | 340 | fs_disconnect_adapter (void *cls, |
339 | void *op_result) | 341 | void *op_result) |
340 | { | 342 | { |
341 | struct GNUNET_FS_Handle *fs = op_result; | 343 | struct GNUNET_FS_Handle *fs = op_result; |
342 | 344 | ||
343 | GNUNET_FS_stop(fs); | 345 | GNUNET_FS_stop (fs); |
344 | } | 346 | } |
345 | 347 | ||
346 | 348 | ||
@@ -354,10 +356,10 @@ fs_disconnect_adapter(void *cls, | |||
354 | * operation has executed successfully. | 356 | * operation has executed successfully. |
355 | */ | 357 | */ |
356 | static void | 358 | static void |
357 | publish_fs_connect_complete_cb(void *cls, | 359 | publish_fs_connect_complete_cb (void *cls, |
358 | struct GNUNET_TESTBED_Operation *op, | 360 | struct GNUNET_TESTBED_Operation *op, |
359 | void *ca_result, | 361 | void *ca_result, |
360 | const char *emsg) | 362 | const char *emsg) |
361 | { | 363 | { |
362 | struct TestPublishOperation *po = cls; | 364 | struct TestPublishOperation *po = cls; |
363 | struct GNUNET_FS_FileInformation *fi; | 365 | struct GNUNET_FS_FileInformation *fi; |
@@ -369,59 +371,62 @@ publish_fs_connect_complete_cb(void *cls, | |||
369 | struct GNUNET_FS_BlockOptions bo; | 371 | struct GNUNET_FS_BlockOptions bo; |
370 | 372 | ||
371 | if (NULL == ca_result) | 373 | if (NULL == ca_result) |
372 | { | 374 | { |
373 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to FS for publishing: %s\n", emsg); | 375 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
374 | po->publish_cont(po->publish_cont_cls, | 376 | "Failed to connect to FS for publishing: %s\n", emsg); |
375 | NULL, NULL); | 377 | po->publish_cont (po->publish_cont_cls, |
376 | GNUNET_TESTBED_operation_done(po->fs_op); | 378 | NULL, NULL); |
377 | GNUNET_free(po); | 379 | GNUNET_TESTBED_operation_done (po->fs_op); |
378 | return; | 380 | GNUNET_free (po); |
379 | } | 381 | return; |
382 | } | ||
380 | po->fs = ca_result; | 383 | po->fs = ca_result; |
381 | 384 | ||
382 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(CONTENT_LIFETIME); | 385 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (CONTENT_LIFETIME); |
383 | bo.anonymity_level = po->anonymity; | 386 | bo.anonymity_level = po->anonymity; |
384 | bo.content_priority = 42; | 387 | bo.content_priority = 42; |
385 | bo.replication_level = 1; | 388 | bo.replication_level = 1; |
386 | if (GNUNET_YES == po->do_index) | 389 | if (GNUNET_YES == po->do_index) |
390 | { | ||
391 | po->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index"); | ||
392 | GNUNET_assert (po->publish_tmp_file != NULL); | ||
393 | fh = GNUNET_DISK_file_open (po->publish_tmp_file, | ||
394 | GNUNET_DISK_OPEN_WRITE | ||
395 | | GNUNET_DISK_OPEN_CREATE, | ||
396 | GNUNET_DISK_PERM_USER_READ | ||
397 | | GNUNET_DISK_PERM_USER_WRITE); | ||
398 | GNUNET_assert (NULL != fh); | ||
399 | off = 0; | ||
400 | while (off < po->size) | ||
387 | { | 401 | { |
388 | po->publish_tmp_file = GNUNET_DISK_mktemp("fs-test-publish-index"); | 402 | bsize = GNUNET_MIN (sizeof(buf), po->size - off); |
389 | GNUNET_assert(po->publish_tmp_file != NULL); | 403 | emsg = NULL; |
390 | fh = GNUNET_DISK_file_open(po->publish_tmp_file, | 404 | GNUNET_assert (bsize == file_generator (&po->publish_seed, off, bsize, |
391 | GNUNET_DISK_OPEN_WRITE | | 405 | buf, &em)); |
392 | GNUNET_DISK_OPEN_CREATE, | 406 | GNUNET_assert (em == NULL); |
393 | GNUNET_DISK_PERM_USER_READ | | 407 | GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize)); |
394 | GNUNET_DISK_PERM_USER_WRITE); | 408 | off += bsize; |
395 | GNUNET_assert(NULL != fh); | ||
396 | off = 0; | ||
397 | while (off < po->size) | ||
398 | { | ||
399 | bsize = GNUNET_MIN(sizeof(buf), po->size - off); | ||
400 | emsg = NULL; | ||
401 | GNUNET_assert(bsize == file_generator(&po->publish_seed, off, bsize, buf, &em)); | ||
402 | GNUNET_assert(em == NULL); | ||
403 | GNUNET_assert(bsize == GNUNET_DISK_file_write(fh, buf, bsize)); | ||
404 | off += bsize; | ||
405 | } | ||
406 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); | ||
407 | fi = GNUNET_FS_file_information_create_from_file(po->fs, po, | ||
408 | po->publish_tmp_file, | ||
409 | NULL, NULL, po->do_index, | ||
410 | &bo); | ||
411 | GNUNET_assert(NULL != fi); | ||
412 | } | 409 | } |
410 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); | ||
411 | fi = GNUNET_FS_file_information_create_from_file (po->fs, po, | ||
412 | po->publish_tmp_file, | ||
413 | NULL, NULL, po->do_index, | ||
414 | &bo); | ||
415 | GNUNET_assert (NULL != fi); | ||
416 | } | ||
413 | else | 417 | else |
414 | { | 418 | { |
415 | fi = GNUNET_FS_file_information_create_from_reader(po->fs, po, | 419 | fi = GNUNET_FS_file_information_create_from_reader (po->fs, po, |
416 | po->size, | 420 | po->size, |
417 | &file_generator, &po->publish_seed, | 421 | &file_generator, |
418 | NULL, NULL, | 422 | &po->publish_seed, |
419 | po->do_index, &bo); | 423 | NULL, NULL, |
420 | GNUNET_assert(NULL != fi); | 424 | po->do_index, &bo); |
421 | } | 425 | GNUNET_assert (NULL != fi); |
426 | } | ||
422 | po->publish_context = | 427 | po->publish_context = |
423 | GNUNET_FS_publish_start(po->fs, fi, NULL, NULL, NULL, | 428 | GNUNET_FS_publish_start (po->fs, fi, NULL, NULL, NULL, |
424 | GNUNET_FS_PUBLISH_OPTION_NONE); | 429 | GNUNET_FS_PUBLISH_OPTION_NONE); |
425 | } | 430 | } |
426 | 431 | ||
427 | 432 | ||
@@ -441,15 +446,15 @@ publish_fs_connect_complete_cb(void *cls, | |||
441 | * @param cont_cls closure for cont | 446 | * @param cont_cls closure for cont |
442 | */ | 447 | */ |
443 | void | 448 | void |
444 | GNUNET_FS_TEST_publish(struct GNUNET_TESTBED_Peer *peer, | 449 | GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, |
445 | struct GNUNET_TIME_Relative timeout, uint32_t anonymity, | 450 | struct GNUNET_TIME_Relative timeout, uint32_t anonymity, |
446 | int do_index, uint64_t size, uint32_t seed, | 451 | int do_index, uint64_t size, uint32_t seed, |
447 | unsigned int verbose, | 452 | unsigned int verbose, |
448 | GNUNET_FS_TEST_UriContinuation cont, void *cont_cls) | 453 | GNUNET_FS_TEST_UriContinuation cont, void *cont_cls) |
449 | { | 454 | { |
450 | struct TestPublishOperation *po; | 455 | struct TestPublishOperation *po; |
451 | 456 | ||
452 | po = GNUNET_new(struct TestPublishOperation); | 457 | po = GNUNET_new (struct TestPublishOperation); |
453 | po->publish_cont = cont; | 458 | po->publish_cont = cont; |
454 | po->publish_cont_cls = cont_cls; | 459 | po->publish_cont_cls = cont_cls; |
455 | po->publish_seed = seed; | 460 | po->publish_seed = seed; |
@@ -457,16 +462,16 @@ GNUNET_FS_TEST_publish(struct GNUNET_TESTBED_Peer *peer, | |||
457 | po->size = size; | 462 | po->size = size; |
458 | po->verbose = verbose; | 463 | po->verbose = verbose; |
459 | po->do_index = do_index; | 464 | po->do_index = do_index; |
460 | po->fs_op = GNUNET_TESTBED_service_connect(po, | 465 | po->fs_op = GNUNET_TESTBED_service_connect (po, |
461 | peer, | 466 | peer, |
462 | "fs", | 467 | "fs", |
463 | &publish_fs_connect_complete_cb, | 468 | &publish_fs_connect_complete_cb, |
464 | po, | 469 | po, |
465 | &publish_connect_adapter, | 470 | &publish_connect_adapter, |
466 | &fs_disconnect_adapter, | 471 | &fs_disconnect_adapter, |
467 | po); | 472 | po); |
468 | po->publish_timeout_task = | 473 | po->publish_timeout_task = |
469 | GNUNET_SCHEDULER_add_delayed(timeout, &publish_timeout, po); | 474 | GNUNET_SCHEDULER_add_delayed (timeout, &publish_timeout, po); |
470 | } | 475 | } |
471 | 476 | ||
472 | 477 | ||
@@ -479,20 +484,20 @@ GNUNET_FS_TEST_publish(struct GNUNET_TESTBED_Peer *peer, | |||
479 | * @param cls the download operation context | 484 | * @param cls the download operation context |
480 | */ | 485 | */ |
481 | static void | 486 | static void |
482 | download_timeout(void *cls) | 487 | download_timeout (void *cls) |
483 | { | 488 | { |
484 | struct TestDownloadOperation *dop = cls; | 489 | struct TestDownloadOperation *dop = cls; |
485 | 490 | ||
486 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 491 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
487 | "Timeout while trying to download file\n"); | 492 | "Timeout while trying to download file\n"); |
488 | dop->download_timeout_task = NULL; | 493 | dop->download_timeout_task = NULL; |
489 | GNUNET_FS_download_stop(dop->download_context, | 494 | GNUNET_FS_download_stop (dop->download_context, |
490 | GNUNET_YES); | 495 | GNUNET_YES); |
491 | GNUNET_SCHEDULER_add_now(dop->download_cont, | 496 | GNUNET_SCHEDULER_add_now (dop->download_cont, |
492 | dop->download_cont_cls); | 497 | dop->download_cont_cls); |
493 | GNUNET_TESTBED_operation_done(dop->fs_op); | 498 | GNUNET_TESTBED_operation_done (dop->fs_op); |
494 | GNUNET_FS_uri_destroy(dop->uri); | 499 | GNUNET_FS_uri_destroy (dop->uri); |
495 | GNUNET_free(dop); | 500 | GNUNET_free (dop); |
496 | } | 501 | } |
497 | 502 | ||
498 | 503 | ||
@@ -502,17 +507,17 @@ download_timeout(void *cls) | |||
502 | * @param cls the download operation context | 507 | * @param cls the download operation context |
503 | */ | 508 | */ |
504 | static void | 509 | static void |
505 | report_success(void *cls) | 510 | report_success (void *cls) |
506 | { | 511 | { |
507 | struct TestDownloadOperation *dop = cls; | 512 | struct TestDownloadOperation *dop = cls; |
508 | 513 | ||
509 | GNUNET_FS_download_stop(dop->download_context, | 514 | GNUNET_FS_download_stop (dop->download_context, |
510 | GNUNET_YES); | 515 | GNUNET_YES); |
511 | GNUNET_SCHEDULER_add_now(dop->download_cont, | 516 | GNUNET_SCHEDULER_add_now (dop->download_cont, |
512 | dop->download_cont_cls); | 517 | dop->download_cont_cls); |
513 | GNUNET_TESTBED_operation_done(dop->fs_op); | 518 | GNUNET_TESTBED_operation_done (dop->fs_op); |
514 | GNUNET_FS_uri_destroy(dop->uri); | 519 | GNUNET_FS_uri_destroy (dop->uri); |
515 | GNUNET_free(dop); | 520 | GNUNET_free (dop); |
516 | } | 521 | } |
517 | 522 | ||
518 | 523 | ||
@@ -523,37 +528,37 @@ report_success(void *cls) | |||
523 | * @param info information about the event | 528 | * @param info information about the event |
524 | */ | 529 | */ |
525 | static void * | 530 | static void * |
526 | download_progress_cb(void *cls, | 531 | download_progress_cb (void *cls, |
527 | const struct GNUNET_FS_ProgressInfo *info) | 532 | const struct GNUNET_FS_ProgressInfo *info) |
528 | { | 533 | { |
529 | struct TestDownloadOperation *dop = cls; | 534 | struct TestDownloadOperation *dop = cls; |
530 | 535 | ||
531 | switch (info->status) | 536 | switch (info->status) |
532 | { | 537 | { |
533 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 538 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
534 | if (dop->verbose) | 539 | if (dop->verbose) |
535 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 540 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
536 | "Download at %llu/%llu bytes\n", | 541 | "Download at %llu/%llu bytes\n", |
537 | (unsigned long long)info->value.download.completed, | 542 | (unsigned long long) info->value.download.completed, |
538 | (unsigned long long)info->value.download.size); | 543 | (unsigned long long) info->value.download.size); |
539 | break; | 544 | break; |
540 | 545 | ||
541 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 546 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
542 | GNUNET_SCHEDULER_cancel(dop->download_timeout_task); | 547 | GNUNET_SCHEDULER_cancel (dop->download_timeout_task); |
543 | dop->download_timeout_task = NULL; | 548 | dop->download_timeout_task = NULL; |
544 | GNUNET_SCHEDULER_add_now(&report_success, dop); | 549 | GNUNET_SCHEDULER_add_now (&report_success, dop); |
545 | break; | 550 | break; |
546 | 551 | ||
547 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | 552 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: |
548 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 553 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: |
549 | break; | 554 | break; |
550 | 555 | ||
551 | /* FIXME: monitor data correctness during download progress */ | 556 | /* FIXME: monitor data correctness during download progress */ |
552 | /* FIXME: do performance reports given sufficient verbosity */ | 557 | /* FIXME: do performance reports given sufficient verbosity */ |
553 | /* FIXME: advance timeout task to "immediate" on error */ | 558 | /* FIXME: advance timeout task to "immediate" on error */ |
554 | default: | 559 | default: |
555 | break; | 560 | break; |
556 | } | 561 | } |
557 | return NULL; | 562 | return NULL; |
558 | } | 563 | } |
559 | 564 | ||
@@ -568,16 +573,16 @@ download_progress_cb(void *cls, | |||
568 | * @return service handle to return in 'op_result', NULL on error | 573 | * @return service handle to return in 'op_result', NULL on error |
569 | */ | 574 | */ |
570 | static void * | 575 | static void * |
571 | download_connect_adapter(void *cls, | 576 | download_connect_adapter (void *cls, |
572 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 577 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
573 | { | 578 | { |
574 | struct TestPublishOperation *po = cls; | 579 | struct TestPublishOperation *po = cls; |
575 | 580 | ||
576 | return GNUNET_FS_start(cfg, | 581 | return GNUNET_FS_start (cfg, |
577 | "fs-test-download", | 582 | "fs-test-download", |
578 | &download_progress_cb, po, | 583 | &download_progress_cb, po, |
579 | GNUNET_FS_FLAGS_NONE, | 584 | GNUNET_FS_FLAGS_NONE, |
580 | GNUNET_FS_OPTIONS_END); | 585 | GNUNET_FS_OPTIONS_END); |
581 | } | 586 | } |
582 | 587 | ||
583 | 588 | ||
@@ -591,19 +596,19 @@ download_connect_adapter(void *cls, | |||
591 | * operation has executed successfully. | 596 | * operation has executed successfully. |
592 | */ | 597 | */ |
593 | static void | 598 | static void |
594 | download_fs_connect_complete_cb(void *cls, | 599 | download_fs_connect_complete_cb (void *cls, |
595 | struct GNUNET_TESTBED_Operation *op, | 600 | struct GNUNET_TESTBED_Operation *op, |
596 | void *ca_result, | 601 | void *ca_result, |
597 | const char *emsg) | 602 | const char *emsg) |
598 | { | 603 | { |
599 | struct TestDownloadOperation *dop = cls; | 604 | struct TestDownloadOperation *dop = cls; |
600 | 605 | ||
601 | dop->fs = ca_result; | 606 | dop->fs = ca_result; |
602 | GNUNET_assert(NULL != dop->fs); | 607 | GNUNET_assert (NULL != dop->fs); |
603 | dop->download_context = | 608 | dop->download_context = |
604 | GNUNET_FS_download_start(dop->fs, dop->uri, NULL, NULL, NULL, 0, dop->size, | 609 | GNUNET_FS_download_start (dop->fs, dop->uri, NULL, NULL, NULL, 0, dop->size, |
605 | dop->anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, | 610 | dop->anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, |
606 | NULL, NULL); | 611 | NULL, NULL); |
607 | } | 612 | } |
608 | 613 | ||
609 | 614 | ||
@@ -621,33 +626,33 @@ download_fs_connect_complete_cb(void *cls, | |||
621 | * @param cont_cls closure for cont | 626 | * @param cont_cls closure for cont |
622 | */ | 627 | */ |
623 | void | 628 | void |
624 | GNUNET_FS_TEST_download(struct GNUNET_TESTBED_Peer *peer, | 629 | GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer, |
625 | struct GNUNET_TIME_Relative timeout, | 630 | struct GNUNET_TIME_Relative timeout, |
626 | uint32_t anonymity, uint32_t seed, | 631 | uint32_t anonymity, uint32_t seed, |
627 | const struct GNUNET_FS_Uri *uri, unsigned int verbose, | 632 | const struct GNUNET_FS_Uri *uri, unsigned int verbose, |
628 | GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) | 633 | GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) |
629 | { | 634 | { |
630 | struct TestDownloadOperation *dop; | 635 | struct TestDownloadOperation *dop; |
631 | 636 | ||
632 | dop = GNUNET_new(struct TestDownloadOperation); | 637 | dop = GNUNET_new (struct TestDownloadOperation); |
633 | dop->uri = GNUNET_FS_uri_dup(uri); | 638 | dop->uri = GNUNET_FS_uri_dup (uri); |
634 | dop->size = GNUNET_FS_uri_chk_get_file_size(uri); | 639 | dop->size = GNUNET_FS_uri_chk_get_file_size (uri); |
635 | dop->verbose = verbose; | 640 | dop->verbose = verbose; |
636 | dop->anonymity = anonymity; | 641 | dop->anonymity = anonymity; |
637 | dop->download_cont = cont; | 642 | dop->download_cont = cont; |
638 | dop->download_cont_cls = cont_cls; | 643 | dop->download_cont_cls = cont_cls; |
639 | dop->download_seed = seed; | 644 | dop->download_seed = seed; |
640 | 645 | ||
641 | dop->fs_op = GNUNET_TESTBED_service_connect(dop, | 646 | dop->fs_op = GNUNET_TESTBED_service_connect (dop, |
642 | peer, | 647 | peer, |
643 | "fs", | 648 | "fs", |
644 | &download_fs_connect_complete_cb, | 649 | &download_fs_connect_complete_cb, |
645 | dop, | 650 | dop, |
646 | &download_connect_adapter, | 651 | &download_connect_adapter, |
647 | &fs_disconnect_adapter, | 652 | &fs_disconnect_adapter, |
648 | dop); | 653 | dop); |
649 | dop->download_timeout_task = | 654 | dop->download_timeout_task = |
650 | GNUNET_SCHEDULER_add_delayed(timeout, &download_timeout, dop); | 655 | GNUNET_SCHEDULER_add_delayed (timeout, &download_timeout, dop); |
651 | } | 656 | } |
652 | 657 | ||
653 | 658 | ||
diff --git a/src/fs/fs_test_lib.h b/src/fs/fs_test_lib.h index e1c43bea7..87bc90bd6 100644 --- a/src/fs/fs_test_lib.h +++ b/src/fs/fs_test_lib.h | |||
@@ -64,15 +64,15 @@ typedef void | |||
64 | * @param cont_cls closure for @a cont | 64 | * @param cont_cls closure for @a cont |
65 | */ | 65 | */ |
66 | void | 66 | void |
67 | GNUNET_FS_TEST_publish(struct GNUNET_TESTBED_Peer *peer, | 67 | GNUNET_FS_TEST_publish (struct GNUNET_TESTBED_Peer *peer, |
68 | struct GNUNET_TIME_Relative timeout, | 68 | struct GNUNET_TIME_Relative timeout, |
69 | uint32_t anonymity, | 69 | uint32_t anonymity, |
70 | int do_index, | 70 | int do_index, |
71 | uint64_t size, | 71 | uint64_t size, |
72 | uint32_t seed, | 72 | uint32_t seed, |
73 | unsigned int verbose, | 73 | unsigned int verbose, |
74 | GNUNET_FS_TEST_UriContinuation cont, | 74 | GNUNET_FS_TEST_UriContinuation cont, |
75 | void *cont_cls); | 75 | void *cont_cls); |
76 | 76 | ||
77 | 77 | ||
78 | /** | 78 | /** |
@@ -89,14 +89,14 @@ GNUNET_FS_TEST_publish(struct GNUNET_TESTBED_Peer *peer, | |||
89 | * @param cont_cls closure for @a cont | 89 | * @param cont_cls closure for @a cont |
90 | */ | 90 | */ |
91 | void | 91 | void |
92 | GNUNET_FS_TEST_download(struct GNUNET_TESTBED_Peer *peer, | 92 | GNUNET_FS_TEST_download (struct GNUNET_TESTBED_Peer *peer, |
93 | struct GNUNET_TIME_Relative timeout, | 93 | struct GNUNET_TIME_Relative timeout, |
94 | uint32_t anonymity, | 94 | uint32_t anonymity, |
95 | uint32_t seed, | 95 | uint32_t seed, |
96 | const struct GNUNET_FS_Uri *uri, | 96 | const struct GNUNET_FS_Uri *uri, |
97 | unsigned int verbose, | 97 | unsigned int verbose, |
98 | GNUNET_SCHEDULER_TaskCallback cont, | 98 | GNUNET_SCHEDULER_TaskCallback cont, |
99 | void *cont_cls); | 99 | void *cont_cls); |
100 | 100 | ||
101 | 101 | ||
102 | 102 | ||
diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c index 5d486a8c9..177f151f2 100644 --- a/src/fs/fs_tree.c +++ b/src/fs/fs_tree.c | |||
@@ -32,7 +32,8 @@ | |||
32 | * Context for an ECRS-based file encoder that computes | 32 | * Context for an ECRS-based file encoder that computes |
33 | * the Merkle-ish-CHK tree. | 33 | * the Merkle-ish-CHK tree. |
34 | */ | 34 | */ |
35 | struct GNUNET_FS_TreeEncoder { | 35 | struct GNUNET_FS_TreeEncoder |
36 | { | ||
36 | /** | 37 | /** |
37 | * Global FS context. | 38 | * Global FS context. |
38 | */ | 39 | */ |
@@ -121,7 +122,7 @@ struct GNUNET_FS_TreeEncoder { | |||
121 | * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK. | 122 | * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK. |
122 | */ | 123 | */ |
123 | unsigned int | 124 | unsigned int |
124 | GNUNET_FS_compute_depth(uint64_t flen) | 125 | GNUNET_FS_compute_depth (uint64_t flen) |
125 | { | 126 | { |
126 | unsigned int treeDepth; | 127 | unsigned int treeDepth; |
127 | uint64_t fl; | 128 | uint64_t fl; |
@@ -129,15 +130,15 @@ GNUNET_FS_compute_depth(uint64_t flen) | |||
129 | treeDepth = 1; | 130 | treeDepth = 1; |
130 | fl = DBLOCK_SIZE; | 131 | fl = DBLOCK_SIZE; |
131 | while (fl < flen) | 132 | while (fl < flen) |
133 | { | ||
134 | treeDepth++; | ||
135 | if (fl * CHK_PER_INODE < fl) | ||
132 | { | 136 | { |
133 | treeDepth++; | 137 | /* integer overflow, this is a HUGE file... */ |
134 | if (fl * CHK_PER_INODE < fl) | 138 | return treeDepth; |
135 | { | ||
136 | /* integer overflow, this is a HUGE file... */ | ||
137 | return treeDepth; | ||
138 | } | ||
139 | fl = fl * CHK_PER_INODE; | ||
140 | } | 139 | } |
140 | fl = fl * CHK_PER_INODE; | ||
141 | } | ||
141 | return treeDepth; | 142 | return treeDepth; |
142 | } | 143 | } |
143 | 144 | ||
@@ -152,7 +153,7 @@ GNUNET_FS_compute_depth(uint64_t flen) | |||
152 | * @return number of bytes of payload a subtree of this depth may correspond to | 153 | * @return number of bytes of payload a subtree of this depth may correspond to |
153 | */ | 154 | */ |
154 | uint64_t | 155 | uint64_t |
155 | GNUNET_FS_tree_compute_tree_size(unsigned int depth) | 156 | GNUNET_FS_tree_compute_tree_size (unsigned int depth) |
156 | { | 157 | { |
157 | uint64_t rsize; | 158 | uint64_t rsize; |
158 | unsigned int i; | 159 | unsigned int i; |
@@ -179,30 +180,30 @@ GNUNET_FS_tree_compute_tree_size(unsigned int depth) | |||
179 | * @return size of the corresponding IBlock | 180 | * @return size of the corresponding IBlock |
180 | */ | 181 | */ |
181 | static uint16_t | 182 | static uint16_t |
182 | GNUNET_FS_tree_compute_iblock_size(unsigned int depth, uint64_t end_offset) | 183 | GNUNET_FS_tree_compute_iblock_size (unsigned int depth, uint64_t end_offset) |
183 | { | 184 | { |
184 | unsigned int ret; | 185 | unsigned int ret; |
185 | uint64_t mod; | 186 | uint64_t mod; |
186 | uint64_t bds; | 187 | uint64_t bds; |
187 | 188 | ||
188 | GNUNET_assert(depth > 0); | 189 | GNUNET_assert (depth > 0); |
189 | GNUNET_assert(end_offset > 0); | 190 | GNUNET_assert (end_offset > 0); |
190 | bds = GNUNET_FS_tree_compute_tree_size(depth); | 191 | bds = GNUNET_FS_tree_compute_tree_size (depth); |
191 | mod = end_offset % bds; | 192 | mod = end_offset % bds; |
192 | if (0 == mod) | 193 | if (0 == mod) |
193 | { | 194 | { |
194 | /* we were triggered at the end of a full block */ | 195 | /* we were triggered at the end of a full block */ |
195 | ret = CHK_PER_INODE; | 196 | ret = CHK_PER_INODE; |
196 | } | 197 | } |
197 | else | 198 | else |
198 | { | 199 | { |
199 | /* we were triggered at the end of the file */ | 200 | /* we were triggered at the end of the file */ |
200 | bds /= CHK_PER_INODE; | 201 | bds /= CHK_PER_INODE; |
201 | ret = mod / bds; | 202 | ret = mod / bds; |
202 | if (0 != mod % bds) | 203 | if (0 != mod % bds) |
203 | ret++; | 204 | ret++; |
204 | } | 205 | } |
205 | return (uint16_t)(ret * sizeof(struct ContentHashKey)); | 206 | return (uint16_t) (ret * sizeof(struct ContentHashKey)); |
206 | } | 207 | } |
207 | 208 | ||
208 | 209 | ||
@@ -218,31 +219,31 @@ GNUNET_FS_tree_compute_iblock_size(unsigned int depth, uint64_t end_offset) | |||
218 | * @return number of bytes stored in this node | 219 | * @return number of bytes stored in this node |
219 | */ | 220 | */ |
220 | size_t | 221 | size_t |
221 | GNUNET_FS_tree_calculate_block_size(uint64_t fsize, uint64_t offset, | 222 | GNUNET_FS_tree_calculate_block_size (uint64_t fsize, uint64_t offset, |
222 | unsigned int depth) | 223 | unsigned int depth) |
223 | { | 224 | { |
224 | size_t ret; | 225 | size_t ret; |
225 | uint64_t rsize; | 226 | uint64_t rsize; |
226 | uint64_t epos; | 227 | uint64_t epos; |
227 | unsigned int chks; | 228 | unsigned int chks; |
228 | 229 | ||
229 | GNUNET_assert(fsize > 0); | 230 | GNUNET_assert (fsize > 0); |
230 | GNUNET_assert(offset <= fsize); | 231 | GNUNET_assert (offset <= fsize); |
231 | if (depth == 0) | 232 | if (depth == 0) |
232 | { | 233 | { |
233 | ret = DBLOCK_SIZE; | 234 | ret = DBLOCK_SIZE; |
234 | if ((offset + ret > fsize) || (offset + ret < offset)) | 235 | if ((offset + ret > fsize) || (offset + ret < offset)) |
235 | ret = (size_t)(fsize - offset); | 236 | ret = (size_t) (fsize - offset); |
236 | return ret; | 237 | return ret; |
237 | } | 238 | } |
238 | 239 | ||
239 | rsize = GNUNET_FS_tree_compute_tree_size(depth - 1); | 240 | rsize = GNUNET_FS_tree_compute_tree_size (depth - 1); |
240 | epos = offset + rsize * CHK_PER_INODE; | 241 | epos = offset + rsize * CHK_PER_INODE; |
241 | if ((epos < offset) || (epos > fsize)) | 242 | if ((epos < offset) || (epos > fsize)) |
242 | epos = fsize; | 243 | epos = fsize; |
243 | /* round up when computing #CHKs in our IBlock */ | 244 | /* round up when computing #CHKs in our IBlock */ |
244 | chks = (epos - offset + rsize - 1) / rsize; | 245 | chks = (epos - offset + rsize - 1) / rsize; |
245 | GNUNET_assert(chks <= CHK_PER_INODE); | 246 | GNUNET_assert (chks <= CHK_PER_INODE); |
246 | return chks * sizeof(struct ContentHashKey); | 247 | return chks * sizeof(struct ContentHashKey); |
247 | } | 248 | } |
248 | 249 | ||
@@ -265,16 +266,16 @@ GNUNET_FS_tree_calculate_block_size(uint64_t fsize, uint64_t offset, | |||
265 | * @param cont function to call when done | 266 | * @param cont function to call when done |
266 | */ | 267 | */ |
267 | struct GNUNET_FS_TreeEncoder * | 268 | struct GNUNET_FS_TreeEncoder * |
268 | GNUNET_FS_tree_encoder_create(struct GNUNET_FS_Handle *h, uint64_t size, | 269 | GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, |
269 | void *cls, | 270 | void *cls, |
270 | GNUNET_FS_DataReader reader, | 271 | GNUNET_FS_DataReader reader, |
271 | GNUNET_FS_TreeBlockProcessor proc, | 272 | GNUNET_FS_TreeBlockProcessor proc, |
272 | GNUNET_FS_TreeProgressCallback progress, | 273 | GNUNET_FS_TreeProgressCallback progress, |
273 | GNUNET_SCHEDULER_TaskCallback cont) | 274 | GNUNET_SCHEDULER_TaskCallback cont) |
274 | { | 275 | { |
275 | struct GNUNET_FS_TreeEncoder *te; | 276 | struct GNUNET_FS_TreeEncoder *te; |
276 | 277 | ||
277 | te = GNUNET_new(struct GNUNET_FS_TreeEncoder); | 278 | te = GNUNET_new (struct GNUNET_FS_TreeEncoder); |
278 | te->h = h; | 279 | te->h = h; |
279 | te->size = size; | 280 | te->size = size; |
280 | te->cls = cls; | 281 | te->cls = cls; |
@@ -282,14 +283,14 @@ GNUNET_FS_tree_encoder_create(struct GNUNET_FS_Handle *h, uint64_t size, | |||
282 | te->proc = proc; | 283 | te->proc = proc; |
283 | te->progress = progress; | 284 | te->progress = progress; |
284 | te->cont = cont; | 285 | te->cont = cont; |
285 | te->chk_tree_depth = GNUNET_FS_compute_depth(size); | 286 | te->chk_tree_depth = GNUNET_FS_compute_depth (size); |
286 | te->chk_tree | 287 | te->chk_tree |
287 | = GNUNET_new_array(te->chk_tree_depth * CHK_PER_INODE, | 288 | = GNUNET_new_array (te->chk_tree_depth * CHK_PER_INODE, |
288 | struct ContentHashKey); | 289 | struct ContentHashKey); |
289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
290 | "Created tree encoder for file with %llu bytes and depth %u\n", | 291 | "Created tree encoder for file with %llu bytes and depth %u\n", |
291 | (unsigned long long)size, | 292 | (unsigned long long) size, |
292 | te->chk_tree_depth); | 293 | te->chk_tree_depth); |
293 | return te; | 294 | return te; |
294 | } | 295 | } |
295 | 296 | ||
@@ -306,12 +307,12 @@ GNUNET_FS_tree_encoder_create(struct GNUNET_FS_Handle *h, uint64_t size, | |||
306 | * @return (array of CHKs') offset in the above IBlock | 307 | * @return (array of CHKs') offset in the above IBlock |
307 | */ | 308 | */ |
308 | static unsigned int | 309 | static unsigned int |
309 | compute_chk_offset(unsigned int depth, uint64_t end_offset) | 310 | compute_chk_offset (unsigned int depth, uint64_t end_offset) |
310 | { | 311 | { |
311 | uint64_t bds; | 312 | uint64_t bds; |
312 | unsigned int ret; | 313 | unsigned int ret; |
313 | 314 | ||
314 | bds = GNUNET_FS_tree_compute_tree_size(depth); | 315 | bds = GNUNET_FS_tree_compute_tree_size (depth); |
315 | if (depth > 0) | 316 | if (depth > 0) |
316 | end_offset--; /* round down since for depth > 0 offset is at the END of the block */ | 317 | end_offset--; /* round down since for depth > 0 offset is at the END of the block */ |
317 | ret = end_offset / bds; | 318 | ret = end_offset / bds; |
@@ -327,7 +328,7 @@ compute_chk_offset(unsigned int depth, uint64_t end_offset) | |||
327 | * @param te tree encoder to use | 328 | * @param te tree encoder to use |
328 | */ | 329 | */ |
329 | void | 330 | void |
330 | GNUNET_FS_tree_encoder_next(struct GNUNET_FS_TreeEncoder *te) | 331 | GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) |
331 | { | 332 | { |
332 | struct ContentHashKey *mychk; | 333 | struct ContentHashKey *mychk; |
333 | const void *pt_block; | 334 | const void *pt_block; |
@@ -338,77 +339,77 @@ GNUNET_FS_tree_encoder_next(struct GNUNET_FS_TreeEncoder *te) | |||
338 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 339 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
339 | unsigned int off; | 340 | unsigned int off; |
340 | 341 | ||
341 | GNUNET_assert(GNUNET_NO == te->in_next); | 342 | GNUNET_assert (GNUNET_NO == te->in_next); |
342 | te->in_next = GNUNET_YES; | 343 | te->in_next = GNUNET_YES; |
343 | if (te->chk_tree_depth == te->current_depth) | 344 | if (te->chk_tree_depth == te->current_depth) |
345 | { | ||
346 | off = CHK_PER_INODE * (te->chk_tree_depth - 1); | ||
347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TE done, reading CHK `%s' from %u\n", | ||
348 | GNUNET_h2s (&te->chk_tree[off].query), off); | ||
349 | te->uri = GNUNET_new (struct GNUNET_FS_Uri); | ||
350 | te->uri->type = GNUNET_FS_URI_CHK; | ||
351 | te->uri->data.chk.chk = te->chk_tree[off]; | ||
352 | te->uri->data.chk.file_length = GNUNET_htonll (te->size); | ||
353 | te->in_next = GNUNET_NO; | ||
354 | te->cont (te->cls); | ||
355 | return; | ||
356 | } | ||
357 | if (0 == te->current_depth) | ||
358 | { | ||
359 | /* read DBLOCK */ | ||
360 | pt_size = GNUNET_MIN (DBLOCK_SIZE, te->size - te->publish_offset); | ||
361 | if (pt_size != | ||
362 | te->reader (te->cls, te->publish_offset, pt_size, iob, &te->emsg)) | ||
344 | { | 363 | { |
345 | off = CHK_PER_INODE * (te->chk_tree_depth - 1); | ||
346 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "TE done, reading CHK `%s' from %u\n", | ||
347 | GNUNET_h2s(&te->chk_tree[off].query), off); | ||
348 | te->uri = GNUNET_new(struct GNUNET_FS_Uri); | ||
349 | te->uri->type = GNUNET_FS_URI_CHK; | ||
350 | te->uri->data.chk.chk = te->chk_tree[off]; | ||
351 | te->uri->data.chk.file_length = GNUNET_htonll(te->size); | ||
352 | te->in_next = GNUNET_NO; | 364 | te->in_next = GNUNET_NO; |
353 | te->cont(te->cls); | 365 | te->cont (te->cls); |
354 | return; | 366 | return; |
355 | } | 367 | } |
356 | if (0 == te->current_depth) | 368 | pt_block = iob; |
357 | { | 369 | } |
358 | /* read DBLOCK */ | ||
359 | pt_size = GNUNET_MIN(DBLOCK_SIZE, te->size - te->publish_offset); | ||
360 | if (pt_size != | ||
361 | te->reader(te->cls, te->publish_offset, pt_size, iob, &te->emsg)) | ||
362 | { | ||
363 | te->in_next = GNUNET_NO; | ||
364 | te->cont(te->cls); | ||
365 | return; | ||
366 | } | ||
367 | pt_block = iob; | ||
368 | } | ||
369 | else | 370 | else |
370 | { | 371 | { |
371 | pt_size = | 372 | pt_size = |
372 | GNUNET_FS_tree_compute_iblock_size(te->current_depth, | 373 | GNUNET_FS_tree_compute_iblock_size (te->current_depth, |
373 | te->publish_offset); | 374 | te->publish_offset); |
374 | pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; | 375 | pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; |
375 | } | 376 | } |
376 | off = compute_chk_offset(te->current_depth, te->publish_offset); | 377 | off = compute_chk_offset (te->current_depth, te->publish_offset); |
377 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
378 | "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n", | 379 | "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n", |
379 | (unsigned long long)te->publish_offset, te->current_depth, | 380 | (unsigned long long) te->publish_offset, te->current_depth, |
380 | (unsigned int)pt_size, (unsigned int)off); | 381 | (unsigned int) pt_size, (unsigned int) off); |
381 | mychk = &te->chk_tree[te->current_depth * CHK_PER_INODE + off]; | 382 | mychk = &te->chk_tree[te->current_depth * CHK_PER_INODE + off]; |
382 | GNUNET_CRYPTO_hash(pt_block, pt_size, &mychk->key); | 383 | GNUNET_CRYPTO_hash (pt_block, pt_size, &mychk->key); |
383 | GNUNET_CRYPTO_hash_to_aes_key(&mychk->key, &sk, &iv); | 384 | GNUNET_CRYPTO_hash_to_aes_key (&mychk->key, &sk, &iv); |
384 | GNUNET_CRYPTO_symmetric_encrypt(pt_block, pt_size, &sk, &iv, enc); | 385 | GNUNET_CRYPTO_symmetric_encrypt (pt_block, pt_size, &sk, &iv, enc); |
385 | GNUNET_CRYPTO_hash(enc, pt_size, &mychk->query); | 386 | GNUNET_CRYPTO_hash (enc, pt_size, &mychk->query); |
386 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
387 | "TE calculates query to be `%s', stored at %u\n", | 388 | "TE calculates query to be `%s', stored at %u\n", |
388 | GNUNET_h2s(&mychk->query), | 389 | GNUNET_h2s (&mychk->query), |
389 | te->current_depth * CHK_PER_INODE + off); | 390 | te->current_depth * CHK_PER_INODE + off); |
390 | if (NULL != te->proc) | 391 | if (NULL != te->proc) |
391 | te->proc(te->cls, mychk, te->publish_offset, te->current_depth, | 392 | te->proc (te->cls, mychk, te->publish_offset, te->current_depth, |
392 | (0 == | 393 | (0 == |
393 | te->current_depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : | 394 | te->current_depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : |
394 | GNUNET_BLOCK_TYPE_FS_IBLOCK, enc, pt_size); | 395 | GNUNET_BLOCK_TYPE_FS_IBLOCK, enc, pt_size); |
395 | if (NULL != te->progress) | 396 | if (NULL != te->progress) |
396 | te->progress(te->cls, te->publish_offset, pt_block, pt_size, | 397 | te->progress (te->cls, te->publish_offset, pt_block, pt_size, |
397 | te->current_depth); | 398 | te->current_depth); |
398 | if (0 == te->current_depth) | 399 | if (0 == te->current_depth) |
399 | { | 400 | { |
400 | te->publish_offset += pt_size; | 401 | te->publish_offset += pt_size; |
401 | if ((te->publish_offset == te->size) || | 402 | if ((te->publish_offset == te->size) || |
402 | (0 == te->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE))) | 403 | (0 == te->publish_offset % (CHK_PER_INODE * DBLOCK_SIZE))) |
403 | te->current_depth++; | 404 | te->current_depth++; |
404 | } | 405 | } |
405 | else | 406 | else |
406 | { | 407 | { |
407 | if ((off == CHK_PER_INODE) || (te->publish_offset == te->size)) | 408 | if ((off == CHK_PER_INODE) || (te->publish_offset == te->size)) |
408 | te->current_depth++; | 409 | te->current_depth++; |
409 | else | 410 | else |
410 | te->current_depth = 0; | 411 | te->current_depth = 0; |
411 | } | 412 | } |
412 | te->in_next = GNUNET_NO; | 413 | te->in_next = GNUNET_NO; |
413 | } | 414 | } |
414 | 415 | ||
@@ -420,10 +421,10 @@ GNUNET_FS_tree_encoder_next(struct GNUNET_FS_TreeEncoder *te) | |||
420 | * @return uri set to the resulting URI (if encoding finished), NULL otherwise | 421 | * @return uri set to the resulting URI (if encoding finished), NULL otherwise |
421 | */ | 422 | */ |
422 | struct GNUNET_FS_Uri * | 423 | struct GNUNET_FS_Uri * |
423 | GNUNET_FS_tree_encoder_get_uri(struct GNUNET_FS_TreeEncoder *te) | 424 | GNUNET_FS_tree_encoder_get_uri (struct GNUNET_FS_TreeEncoder *te) |
424 | { | 425 | { |
425 | if (NULL != te->uri) | 426 | if (NULL != te->uri) |
426 | return GNUNET_FS_uri_dup(te->uri); | 427 | return GNUNET_FS_uri_dup (te->uri); |
427 | return NULL; | 428 | return NULL; |
428 | } | 429 | } |
429 | 430 | ||
@@ -439,23 +440,23 @@ GNUNET_FS_tree_encoder_get_uri(struct GNUNET_FS_TreeEncoder *te) | |||
439 | * both "*emsg" will be set to NULL). | 440 | * both "*emsg" will be set to NULL). |
440 | */ | 441 | */ |
441 | void | 442 | void |
442 | GNUNET_FS_tree_encoder_finish(struct GNUNET_FS_TreeEncoder *te, | 443 | GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, |
443 | char **emsg) | 444 | char **emsg) |
444 | { | 445 | { |
445 | if (NULL != te->reader) | 446 | if (NULL != te->reader) |
446 | { | 447 | { |
447 | (void)te->reader(te->cls, UINT64_MAX, 0, 0, NULL); | 448 | (void) te->reader (te->cls, UINT64_MAX, 0, 0, NULL); |
448 | te->reader = NULL; | 449 | te->reader = NULL; |
449 | } | 450 | } |
450 | GNUNET_assert(GNUNET_NO == te->in_next); | 451 | GNUNET_assert (GNUNET_NO == te->in_next); |
451 | if (NULL != te->uri) | 452 | if (NULL != te->uri) |
452 | GNUNET_FS_uri_destroy(te->uri); | 453 | GNUNET_FS_uri_destroy (te->uri); |
453 | if (emsg != NULL) | 454 | if (emsg != NULL) |
454 | *emsg = te->emsg; | 455 | *emsg = te->emsg; |
455 | else | 456 | else |
456 | GNUNET_free_non_null(te->emsg); | 457 | GNUNET_free_non_null (te->emsg); |
457 | GNUNET_free(te->chk_tree); | 458 | GNUNET_free (te->chk_tree); |
458 | GNUNET_free(te); | 459 | GNUNET_free (te); |
459 | } | 460 | } |
460 | 461 | ||
461 | /* end of fs_tree.c */ | 462 | /* end of fs_tree.c */ |
diff --git a/src/fs/fs_tree.h b/src/fs/fs_tree.h index 7ce7e461b..12b5b5d07 100644 --- a/src/fs/fs_tree.h +++ b/src/fs/fs_tree.h | |||
@@ -41,7 +41,7 @@ | |||
41 | * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK. | 41 | * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK. |
42 | */ | 42 | */ |
43 | unsigned int | 43 | unsigned int |
44 | GNUNET_FS_compute_depth(uint64_t flen); | 44 | GNUNET_FS_compute_depth (uint64_t flen); |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
@@ -54,7 +54,7 @@ GNUNET_FS_compute_depth(uint64_t flen); | |||
54 | * @return number of bytes of payload a subtree of this depth may correspond to | 54 | * @return number of bytes of payload a subtree of this depth may correspond to |
55 | */ | 55 | */ |
56 | uint64_t | 56 | uint64_t |
57 | GNUNET_FS_tree_compute_tree_size(unsigned int depth); | 57 | GNUNET_FS_tree_compute_tree_size (unsigned int depth); |
58 | 58 | ||
59 | 59 | ||
60 | /** | 60 | /** |
@@ -69,8 +69,8 @@ GNUNET_FS_tree_compute_tree_size(unsigned int depth); | |||
69 | * @return number of bytes stored in this node | 69 | * @return number of bytes stored in this node |
70 | */ | 70 | */ |
71 | size_t | 71 | size_t |
72 | GNUNET_FS_tree_calculate_block_size(uint64_t fsize, uint64_t offset, | 72 | GNUNET_FS_tree_calculate_block_size (uint64_t fsize, uint64_t offset, |
73 | unsigned int depth); | 73 | unsigned int depth); |
74 | 74 | ||
75 | 75 | ||
76 | /** | 76 | /** |
@@ -95,7 +95,7 @@ struct GNUNET_FS_TreeEncoder; | |||
95 | * @param block_size size of block (in bytes) | 95 | * @param block_size size of block (in bytes) |
96 | */ | 96 | */ |
97 | typedef void (*GNUNET_FS_TreeBlockProcessor) (void *cls, | 97 | typedef void (*GNUNET_FS_TreeBlockProcessor) (void *cls, |
98 | const struct ContentHashKey * chk, | 98 | const struct ContentHashKey *chk, |
99 | uint64_t offset, | 99 | uint64_t offset, |
100 | unsigned int depth, | 100 | unsigned int depth, |
101 | enum GNUNET_BLOCK_Type type, | 101 | enum GNUNET_BLOCK_Type type, |
@@ -138,11 +138,11 @@ typedef void (*GNUNET_FS_TreeProgressCallback) (void *cls, uint64_t offset, | |||
138 | * @return tree encoder context | 138 | * @return tree encoder context |
139 | */ | 139 | */ |
140 | struct GNUNET_FS_TreeEncoder * | 140 | struct GNUNET_FS_TreeEncoder * |
141 | GNUNET_FS_tree_encoder_create(struct GNUNET_FS_Handle *h, uint64_t size, | 141 | GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, |
142 | void *cls, GNUNET_FS_DataReader reader, | 142 | void *cls, GNUNET_FS_DataReader reader, |
143 | GNUNET_FS_TreeBlockProcessor proc, | 143 | GNUNET_FS_TreeBlockProcessor proc, |
144 | GNUNET_FS_TreeProgressCallback progress, | 144 | GNUNET_FS_TreeProgressCallback progress, |
145 | GNUNET_SCHEDULER_TaskCallback cont); | 145 | GNUNET_SCHEDULER_TaskCallback cont); |
146 | 146 | ||
147 | 147 | ||
148 | /** | 148 | /** |
@@ -154,7 +154,7 @@ GNUNET_FS_tree_encoder_create(struct GNUNET_FS_Handle *h, uint64_t size, | |||
154 | * @param te tree encoder to use | 154 | * @param te tree encoder to use |
155 | */ | 155 | */ |
156 | void | 156 | void |
157 | GNUNET_FS_tree_encoder_next(struct GNUNET_FS_TreeEncoder *te); | 157 | GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te); |
158 | 158 | ||
159 | 159 | ||
160 | /** | 160 | /** |
@@ -164,7 +164,7 @@ GNUNET_FS_tree_encoder_next(struct GNUNET_FS_TreeEncoder *te); | |||
164 | * @return uri set to the resulting URI (if encoding finished), NULL otherwise | 164 | * @return uri set to the resulting URI (if encoding finished), NULL otherwise |
165 | */ | 165 | */ |
166 | struct GNUNET_FS_Uri * | 166 | struct GNUNET_FS_Uri * |
167 | GNUNET_FS_tree_encoder_get_uri(struct GNUNET_FS_TreeEncoder *te); | 167 | GNUNET_FS_tree_encoder_get_uri (struct GNUNET_FS_TreeEncoder *te); |
168 | 168 | ||
169 | 169 | ||
170 | /** | 170 | /** |
@@ -178,8 +178,8 @@ GNUNET_FS_tree_encoder_get_uri(struct GNUNET_FS_TreeEncoder *te); | |||
178 | * both "*emsg" will be set to NULL). | 178 | * both "*emsg" will be set to NULL). |
179 | */ | 179 | */ |
180 | void | 180 | void |
181 | GNUNET_FS_tree_encoder_finish(struct GNUNET_FS_TreeEncoder *te, | 181 | GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, |
182 | char **emsg); | 182 | char **emsg); |
183 | 183 | ||
184 | 184 | ||
185 | #if 0 | 185 | #if 0 |
@@ -194,8 +194,8 @@ GNUNET_FS_tree_encoder_finish(struct GNUNET_FS_TreeEncoder *te, | |||
194 | * @param size set to the size of the resume data | 194 | * @param size set to the size of the resume data |
195 | */ | 195 | */ |
196 | void | 196 | void |
197 | GNUNET_FS_tree_encoder_resume_get_data(const struct GNUNET_FS_TreeEncoder *te, | 197 | GNUNET_FS_tree_encoder_resume_get_data (const struct GNUNET_FS_TreeEncoder *te, |
198 | void **data, size_t * size); | 198 | void **data, size_t *size); |
199 | 199 | ||
200 | 200 | ||
201 | /** | 201 | /** |
@@ -207,8 +207,8 @@ GNUNET_FS_tree_encoder_resume_get_data(const struct GNUNET_FS_TreeEncoder *te, | |||
207 | * @param size the size of the resume data | 207 | * @param size the size of the resume data |
208 | */ | 208 | */ |
209 | void | 209 | void |
210 | GNUNET_FS_tree_encoder_resume(struct GNUNET_FS_TreeEncoder *te, | 210 | GNUNET_FS_tree_encoder_resume (struct GNUNET_FS_TreeEncoder *te, |
211 | const void *data, size_t size); | 211 | const void *data, size_t size); |
212 | 212 | ||
213 | #endif | 213 | #endif |
214 | 214 | ||
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index be2dbbddd..c35d49312 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c | |||
@@ -48,26 +48,26 @@ | |||
48 | * @return number of bytes copied to buf, 0 on error | 48 | * @return number of bytes copied to buf, 0 on error |
49 | */ | 49 | */ |
50 | static size_t | 50 | static size_t |
51 | unindex_reader(void *cls, | 51 | unindex_reader (void *cls, |
52 | uint64_t offset, | 52 | uint64_t offset, |
53 | size_t max, | 53 | size_t max, |
54 | void *buf, | 54 | void *buf, |
55 | char **emsg) | 55 | char **emsg) |
56 | { | 56 | { |
57 | struct GNUNET_FS_UnindexContext *uc = cls; | 57 | struct GNUNET_FS_UnindexContext *uc = cls; |
58 | size_t pt_size; | 58 | size_t pt_size; |
59 | 59 | ||
60 | pt_size = GNUNET_MIN(max, uc->file_size - offset); | 60 | pt_size = GNUNET_MIN (max, uc->file_size - offset); |
61 | if (offset != GNUNET_DISK_file_seek(uc->fh, offset, GNUNET_DISK_SEEK_SET)) | 61 | if (offset != GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET)) |
62 | { | 62 | { |
63 | *emsg = GNUNET_strdup(_("Failed to find given position in file")); | 63 | *emsg = GNUNET_strdup (_ ("Failed to find given position in file")); |
64 | return 0; | 64 | return 0; |
65 | } | 65 | } |
66 | if (pt_size != GNUNET_DISK_file_read(uc->fh, buf, pt_size)) | 66 | if (pt_size != GNUNET_DISK_file_read (uc->fh, buf, pt_size)) |
67 | { | 67 | { |
68 | *emsg = GNUNET_strdup(_("Failed to read file")); | 68 | *emsg = GNUNET_strdup (_ ("Failed to read file")); |
69 | return 0; | 69 | return 0; |
70 | } | 70 | } |
71 | return pt_size; | 71 | return pt_size; |
72 | } | 72 | } |
73 | 73 | ||
@@ -81,21 +81,21 @@ unindex_reader(void *cls, | |||
81 | * @param offset where we are in the file (for progress) | 81 | * @param offset where we are in the file (for progress) |
82 | */ | 82 | */ |
83 | void | 83 | void |
84 | GNUNET_FS_unindex_make_status_(struct GNUNET_FS_ProgressInfo *pi, | 84 | GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi, |
85 | struct GNUNET_FS_UnindexContext *uc, | 85 | struct GNUNET_FS_UnindexContext *uc, |
86 | uint64_t offset) | 86 | uint64_t offset) |
87 | { | 87 | { |
88 | pi->value.unindex.uc = uc; | 88 | pi->value.unindex.uc = uc; |
89 | pi->value.unindex.cctx = uc->client_info; | 89 | pi->value.unindex.cctx = uc->client_info; |
90 | pi->value.unindex.filename = uc->filename; | 90 | pi->value.unindex.filename = uc->filename; |
91 | pi->value.unindex.size = uc->file_size; | 91 | pi->value.unindex.size = uc->file_size; |
92 | pi->value.unindex.eta = | 92 | pi->value.unindex.eta = |
93 | GNUNET_TIME_calculate_eta(uc->start_time, offset, uc->file_size); | 93 | GNUNET_TIME_calculate_eta (uc->start_time, offset, uc->file_size); |
94 | pi->value.unindex.duration = | 94 | pi->value.unindex.duration = |
95 | GNUNET_TIME_absolute_get_duration(uc->start_time); | 95 | GNUNET_TIME_absolute_get_duration (uc->start_time); |
96 | pi->value.unindex.completed = offset; | 96 | pi->value.unindex.completed = offset; |
97 | pi->fsh = uc->h; | 97 | pi->fsh = uc->h; |
98 | uc->client_info = uc->h->upcb(uc->h->upcb_cls, pi); | 98 | uc->client_info = uc->h->upcb (uc->h->upcb_cls, pi); |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
@@ -110,11 +110,11 @@ GNUNET_FS_unindex_make_status_(struct GNUNET_FS_ProgressInfo *pi, | |||
110 | * @param depth depth of the block in the tree, 0 for DBLOCK | 110 | * @param depth depth of the block in the tree, 0 for DBLOCK |
111 | */ | 111 | */ |
112 | static void | 112 | static void |
113 | unindex_progress(void *cls, | 113 | unindex_progress (void *cls, |
114 | uint64_t offset, | 114 | uint64_t offset, |
115 | const void *pt_block, | 115 | const void *pt_block, |
116 | size_t pt_size, | 116 | size_t pt_size, |
117 | unsigned int depth) | 117 | unsigned int depth) |
118 | { | 118 | { |
119 | struct GNUNET_FS_UnindexContext *uc = cls; | 119 | struct GNUNET_FS_UnindexContext *uc = cls; |
120 | struct GNUNET_FS_ProgressInfo pi; | 120 | struct GNUNET_FS_ProgressInfo pi; |
@@ -124,7 +124,7 @@ unindex_progress(void *cls, | |||
124 | pi.value.unindex.specifics.progress.offset = offset; | 124 | pi.value.unindex.specifics.progress.offset = offset; |
125 | pi.value.unindex.specifics.progress.data_len = pt_size; | 125 | pi.value.unindex.specifics.progress.data_len = pt_size; |
126 | pi.value.unindex.specifics.progress.depth = depth; | 126 | pi.value.unindex.specifics.progress.depth = depth; |
127 | GNUNET_FS_unindex_make_status_(&pi, uc, offset); | 127 | GNUNET_FS_unindex_make_status_ (&pi, uc, offset); |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
@@ -135,14 +135,14 @@ unindex_progress(void *cls, | |||
135 | * @param uc context for the failed unindexing operation | 135 | * @param uc context for the failed unindexing operation |
136 | */ | 136 | */ |
137 | static void | 137 | static void |
138 | signal_unindex_error(struct GNUNET_FS_UnindexContext *uc) | 138 | signal_unindex_error (struct GNUNET_FS_UnindexContext *uc) |
139 | { | 139 | { |
140 | struct GNUNET_FS_ProgressInfo pi; | 140 | struct GNUNET_FS_ProgressInfo pi; |
141 | 141 | ||
142 | pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR; | 142 | pi.status = GNUNET_FS_STATUS_UNINDEX_ERROR; |
143 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 143 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
144 | pi.value.unindex.specifics.error.message = uc->emsg; | 144 | pi.value.unindex.specifics.error.message = uc->emsg; |
145 | GNUNET_FS_unindex_make_status_(&pi, uc, 0); | 145 | GNUNET_FS_unindex_make_status_ (&pi, uc, 0); |
146 | } | 146 | } |
147 | 147 | ||
148 | 148 | ||
@@ -156,22 +156,22 @@ signal_unindex_error(struct GNUNET_FS_UnindexContext *uc) | |||
156 | * @param msg NULL on success, otherwise an error message | 156 | * @param msg NULL on success, otherwise an error message |
157 | */ | 157 | */ |
158 | static void | 158 | static void |
159 | process_cont(void *cls, | 159 | process_cont (void *cls, |
160 | int success, | 160 | int success, |
161 | struct GNUNET_TIME_Absolute min_expiration, | 161 | struct GNUNET_TIME_Absolute min_expiration, |
162 | const char *msg) | 162 | const char *msg) |
163 | { | 163 | { |
164 | struct GNUNET_FS_UnindexContext *uc = cls; | 164 | struct GNUNET_FS_UnindexContext *uc = cls; |
165 | 165 | ||
166 | if (success == GNUNET_SYSERR) | 166 | if (success == GNUNET_SYSERR) |
167 | { | 167 | { |
168 | uc->emsg = GNUNET_strdup(msg); | 168 | uc->emsg = GNUNET_strdup (msg); |
169 | signal_unindex_error(uc); | 169 | signal_unindex_error (uc); |
170 | return; | 170 | return; |
171 | } | 171 | } |
172 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
173 | "Datastore REMOVE operation succeeded\n"); | 173 | "Datastore REMOVE operation succeeded\n"); |
174 | GNUNET_FS_tree_encoder_next(uc->tc); | 174 | GNUNET_FS_tree_encoder_next (uc->tc); |
175 | } | 175 | } |
176 | 176 | ||
177 | 177 | ||
@@ -190,13 +190,13 @@ process_cont(void *cls, | |||
190 | * @param block_size size of block (in bytes) | 190 | * @param block_size size of block (in bytes) |
191 | */ | 191 | */ |
192 | static void | 192 | static void |
193 | unindex_process(void *cls, | 193 | unindex_process (void *cls, |
194 | const struct ContentHashKey *chk, | 194 | const struct ContentHashKey *chk, |
195 | uint64_t offset, | 195 | uint64_t offset, |
196 | unsigned int depth, | 196 | unsigned int depth, |
197 | enum GNUNET_BLOCK_Type type, | 197 | enum GNUNET_BLOCK_Type type, |
198 | const void *block, | 198 | const void *block, |
199 | uint16_t block_size) | 199 | uint16_t block_size) |
200 | { | 200 | { |
201 | struct GNUNET_FS_UnindexContext *uc = cls; | 201 | struct GNUNET_FS_UnindexContext *uc = cls; |
202 | uint32_t size; | 202 | uint32_t size; |
@@ -204,21 +204,21 @@ unindex_process(void *cls, | |||
204 | struct OnDemandBlock odb; | 204 | struct OnDemandBlock odb; |
205 | 205 | ||
206 | if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK) | 206 | if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK) |
207 | { | 207 | { |
208 | size = block_size; | 208 | size = block_size; |
209 | data = block; | 209 | data = block; |
210 | } | 210 | } |
211 | else /* on-demand encoded DBLOCK */ | 211 | else /* on-demand encoded DBLOCK */ |
212 | { | 212 | { |
213 | size = sizeof(struct OnDemandBlock); | 213 | size = sizeof(struct OnDemandBlock); |
214 | odb.offset = GNUNET_htonll(offset); | 214 | odb.offset = GNUNET_htonll (offset); |
215 | odb.file_id = uc->file_id; | 215 | odb.file_id = uc->file_id; |
216 | data = &odb; | 216 | data = &odb; |
217 | } | 217 | } |
218 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
219 | "Sending REMOVE request to DATASTORE service\n"); | 219 | "Sending REMOVE request to DATASTORE service\n"); |
220 | GNUNET_DATASTORE_remove(uc->dsh, &chk->query, size, data, -2, 1, | 220 | GNUNET_DATASTORE_remove (uc->dsh, &chk->query, size, data, -2, 1, |
221 | &process_cont, uc); | 221 | &process_cont, uc); |
222 | uc->chk = *chk; | 222 | uc->chk = *chk; |
223 | } | 223 | } |
224 | 224 | ||
@@ -231,24 +231,24 @@ unindex_process(void *cls, | |||
231 | * @param msg the response | 231 | * @param msg the response |
232 | */ | 232 | */ |
233 | static void | 233 | static void |
234 | handle_unindex_response(void *cls, | 234 | handle_unindex_response (void *cls, |
235 | const struct GNUNET_MessageHeader *msg) | 235 | const struct GNUNET_MessageHeader *msg) |
236 | { | 236 | { |
237 | struct GNUNET_FS_UnindexContext *uc = cls; | 237 | struct GNUNET_FS_UnindexContext *uc = cls; |
238 | struct GNUNET_FS_ProgressInfo pi; | 238 | struct GNUNET_FS_ProgressInfo pi; |
239 | 239 | ||
240 | if (NULL != uc->mq) | 240 | if (NULL != uc->mq) |
241 | { | 241 | { |
242 | GNUNET_MQ_destroy(uc->mq); | 242 | GNUNET_MQ_destroy (uc->mq); |
243 | uc->mq = NULL; | 243 | uc->mq = NULL; |
244 | } | 244 | } |
245 | uc->state = UNINDEX_STATE_COMPLETE; | 245 | uc->state = UNINDEX_STATE_COMPLETE; |
246 | pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED; | 246 | pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED; |
247 | pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; | 247 | pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; |
248 | GNUNET_FS_unindex_sync_(uc); | 248 | GNUNET_FS_unindex_sync_ (uc); |
249 | GNUNET_FS_unindex_make_status_(&pi, | 249 | GNUNET_FS_unindex_make_status_ (&pi, |
250 | uc, | 250 | uc, |
251 | uc->file_size); | 251 | uc->file_size); |
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
@@ -261,20 +261,20 @@ handle_unindex_response(void *cls, | |||
261 | * @param error error code | 261 | * @param error error code |
262 | */ | 262 | */ |
263 | static void | 263 | static void |
264 | unindex_mq_error_handler(void *cls, | 264 | unindex_mq_error_handler (void *cls, |
265 | enum GNUNET_MQ_Error error) | 265 | enum GNUNET_MQ_Error error) |
266 | { | 266 | { |
267 | struct GNUNET_FS_UnindexContext *uc = cls; | 267 | struct GNUNET_FS_UnindexContext *uc = cls; |
268 | 268 | ||
269 | if (NULL != uc->mq) | 269 | if (NULL != uc->mq) |
270 | { | 270 | { |
271 | GNUNET_MQ_destroy(uc->mq); | 271 | GNUNET_MQ_destroy (uc->mq); |
272 | uc->mq = NULL; | 272 | uc->mq = NULL; |
273 | } | 273 | } |
274 | uc->state = UNINDEX_STATE_ERROR; | 274 | uc->state = UNINDEX_STATE_ERROR; |
275 | uc->emsg = GNUNET_strdup(_("Error communicating with `fs' service.")); | 275 | uc->emsg = GNUNET_strdup (_ ("Error communicating with `fs' service.")); |
276 | GNUNET_FS_unindex_sync_(uc); | 276 | GNUNET_FS_unindex_sync_ (uc); |
277 | signal_unindex_error(uc); | 277 | signal_unindex_error (uc); |
278 | } | 278 | } |
279 | 279 | ||
280 | 280 | ||
@@ -286,56 +286,56 @@ unindex_mq_error_handler(void *cls, | |||
286 | * @param uc our unindexing context | 286 | * @param uc our unindexing context |
287 | */ | 287 | */ |
288 | static void | 288 | static void |
289 | unindex_finish(struct GNUNET_FS_UnindexContext *uc) | 289 | unindex_finish (struct GNUNET_FS_UnindexContext *uc) |
290 | { | 290 | { |
291 | struct GNUNET_MQ_MessageHandler handlers[] = { | 291 | struct GNUNET_MQ_MessageHandler handlers[] = { |
292 | GNUNET_MQ_hd_fixed_size(unindex_response, | 292 | GNUNET_MQ_hd_fixed_size (unindex_response, |
293 | GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK, | 293 | GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK, |
294 | struct GNUNET_MessageHeader, | 294 | struct GNUNET_MessageHeader, |
295 | uc), | 295 | uc), |
296 | GNUNET_MQ_handler_end() | 296 | GNUNET_MQ_handler_end () |
297 | }; | 297 | }; |
298 | char *emsg; | 298 | char *emsg; |
299 | struct GNUNET_MQ_Envelope *env; | 299 | struct GNUNET_MQ_Envelope *env; |
300 | struct UnindexMessage *req; | 300 | struct UnindexMessage *req; |
301 | 301 | ||
302 | /* generate final progress message */ | 302 | /* generate final progress message */ |
303 | unindex_progress(uc, | 303 | unindex_progress (uc, |
304 | uc->file_size, | 304 | uc->file_size, |
305 | NULL, | 305 | NULL, |
306 | 0, | 306 | 0, |
307 | 0); | 307 | 0); |
308 | GNUNET_FS_tree_encoder_finish(uc->tc, | 308 | GNUNET_FS_tree_encoder_finish (uc->tc, |
309 | &emsg); | 309 | &emsg); |
310 | uc->tc = NULL; | 310 | uc->tc = NULL; |
311 | GNUNET_DISK_file_close(uc->fh); | 311 | GNUNET_DISK_file_close (uc->fh); |
312 | uc->fh = NULL; | 312 | uc->fh = NULL; |
313 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); | 313 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); |
314 | uc->dsh = NULL; | 314 | uc->dsh = NULL; |
315 | uc->state = UNINDEX_STATE_FS_NOTIFY; | 315 | uc->state = UNINDEX_STATE_FS_NOTIFY; |
316 | GNUNET_FS_unindex_sync_(uc); | 316 | GNUNET_FS_unindex_sync_ (uc); |
317 | uc->mq = GNUNET_CLIENT_connect(uc->h->cfg, | 317 | uc->mq = GNUNET_CLIENT_connect (uc->h->cfg, |
318 | "fs", | 318 | "fs", |
319 | handlers, | 319 | handlers, |
320 | &unindex_mq_error_handler, | 320 | &unindex_mq_error_handler, |
321 | uc); | 321 | uc); |
322 | if (NULL == uc->mq) | 322 | if (NULL == uc->mq) |
323 | { | 323 | { |
324 | uc->state = UNINDEX_STATE_ERROR; | 324 | uc->state = UNINDEX_STATE_ERROR; |
325 | uc->emsg = | 325 | uc->emsg = |
326 | GNUNET_strdup(_("Failed to connect to FS service for unindexing.")); | 326 | GNUNET_strdup (_ ("Failed to connect to FS service for unindexing.")); |
327 | GNUNET_FS_unindex_sync_(uc); | 327 | GNUNET_FS_unindex_sync_ (uc); |
328 | signal_unindex_error(uc); | 328 | signal_unindex_error (uc); |
329 | return; | 329 | return; |
330 | } | 330 | } |
331 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
332 | "Sending UNINDEX message to FS service\n"); | 332 | "Sending UNINDEX message to FS service\n"); |
333 | env = GNUNET_MQ_msg(req, | 333 | env = GNUNET_MQ_msg (req, |
334 | GNUNET_MESSAGE_TYPE_FS_UNINDEX); | 334 | GNUNET_MESSAGE_TYPE_FS_UNINDEX); |
335 | req->reserved = 0; | 335 | req->reserved = 0; |
336 | req->file_id = uc->file_id; | 336 | req->file_id = uc->file_id; |
337 | GNUNET_MQ_send(uc->mq, | 337 | GNUNET_MQ_send (uc->mq, |
338 | env); | 338 | env); |
339 | } | 339 | } |
340 | 340 | ||
341 | 341 | ||
@@ -351,49 +351,49 @@ unindex_finish(struct GNUNET_FS_UnindexContext *uc) | |||
351 | * @param reason kind of progress we are making | 351 | * @param reason kind of progress we are making |
352 | */ | 352 | */ |
353 | static void | 353 | static void |
354 | unindex_directory_scan_cb(void *cls, | 354 | unindex_directory_scan_cb (void *cls, |
355 | const char *filename, | 355 | const char *filename, |
356 | int is_directory, | 356 | int is_directory, |
357 | enum GNUNET_FS_DirScannerProgressUpdateReason reason) | 357 | enum GNUNET_FS_DirScannerProgressUpdateReason reason) |
358 | { | 358 | { |
359 | struct GNUNET_FS_UnindexContext *uc = cls; | 359 | struct GNUNET_FS_UnindexContext *uc = cls; |
360 | static struct GNUNET_FS_ShareTreeItem * directory_scan_result; | 360 | static struct GNUNET_FS_ShareTreeItem *directory_scan_result; |
361 | 361 | ||
362 | switch (reason) | 362 | switch (reason) |
363 | { | 363 | { |
364 | case GNUNET_FS_DIRSCANNER_FINISHED: | 364 | case GNUNET_FS_DIRSCANNER_FINISHED: |
365 | directory_scan_result = GNUNET_FS_directory_scan_get_result(uc->dscan); | 365 | directory_scan_result = GNUNET_FS_directory_scan_get_result (uc->dscan); |
366 | uc->dscan = NULL; | 366 | uc->dscan = NULL; |
367 | if (NULL != directory_scan_result->ksk_uri) | 367 | if (NULL != directory_scan_result->ksk_uri) |
368 | { | 368 | { |
369 | uc->ksk_uri = GNUNET_FS_uri_dup(directory_scan_result->ksk_uri); | 369 | uc->ksk_uri = GNUNET_FS_uri_dup (directory_scan_result->ksk_uri); |
370 | uc->state = UNINDEX_STATE_DS_REMOVE_KBLOCKS; | 370 | uc->state = UNINDEX_STATE_DS_REMOVE_KBLOCKS; |
371 | GNUNET_FS_unindex_sync_(uc); | 371 | GNUNET_FS_unindex_sync_ (uc); |
372 | GNUNET_FS_unindex_do_remove_kblocks_(uc); | 372 | GNUNET_FS_unindex_do_remove_kblocks_ (uc); |
373 | } | 373 | } |
374 | else | 374 | else |
375 | { | 375 | { |
376 | uc->emsg = GNUNET_strdup(_("Failed to get KSKs from directory scan.")); | 376 | uc->emsg = GNUNET_strdup (_ ("Failed to get KSKs from directory scan.")); |
377 | GNUNET_FS_unindex_sync_(uc); | 377 | GNUNET_FS_unindex_sync_ (uc); |
378 | unindex_finish(uc); | 378 | unindex_finish (uc); |
379 | } | 379 | } |
380 | GNUNET_FS_share_tree_free(directory_scan_result); | 380 | GNUNET_FS_share_tree_free (directory_scan_result); |
381 | break; | 381 | break; |
382 | 382 | ||
383 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: | 383 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: |
384 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 384 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
385 | _("Internal error scanning `%s'.\n"), | 385 | _ ("Internal error scanning `%s'.\n"), |
386 | uc->filename); | 386 | uc->filename); |
387 | GNUNET_FS_directory_scan_abort(uc->dscan); | 387 | GNUNET_FS_directory_scan_abort (uc->dscan); |
388 | uc->dscan = NULL; | 388 | uc->dscan = NULL; |
389 | uc->emsg = GNUNET_strdup(_("Failed to get KSKs from directory scan.")); | 389 | uc->emsg = GNUNET_strdup (_ ("Failed to get KSKs from directory scan.")); |
390 | GNUNET_FS_unindex_sync_(uc); | 390 | GNUNET_FS_unindex_sync_ (uc); |
391 | unindex_finish(uc); | 391 | unindex_finish (uc); |
392 | break; | 392 | break; |
393 | 393 | ||
394 | default: | 394 | default: |
395 | break; | 395 | break; |
396 | } | 396 | } |
397 | } | 397 | } |
398 | 398 | ||
399 | 399 | ||
@@ -403,18 +403,19 @@ unindex_directory_scan_cb(void *cls, | |||
403 | * @param uc context for the unindex operation. | 403 | * @param uc context for the unindex operation. |
404 | */ | 404 | */ |
405 | void | 405 | void |
406 | GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc) | 406 | GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc) |
407 | { | 407 | { |
408 | char *ex; | 408 | char *ex; |
409 | 409 | ||
410 | if (GNUNET_OK != | 410 | if (GNUNET_OK != |
411 | GNUNET_CONFIGURATION_get_value_string(uc->h->cfg, "FS", "EXTRACTORS", &ex)) | 411 | GNUNET_CONFIGURATION_get_value_string (uc->h->cfg, "FS", "EXTRACTORS", |
412 | &ex)) | ||
412 | ex = NULL; | 413 | ex = NULL; |
413 | uc->dscan = GNUNET_FS_directory_scan_start(uc->filename, | 414 | uc->dscan = GNUNET_FS_directory_scan_start (uc->filename, |
414 | GNUNET_NO, ex, | 415 | GNUNET_NO, ex, |
415 | &unindex_directory_scan_cb, | 416 | &unindex_directory_scan_cb, |
416 | uc); | 417 | uc); |
417 | GNUNET_free_non_null(ex); | 418 | GNUNET_free_non_null (ex); |
418 | } | 419 | } |
419 | 420 | ||
420 | 421 | ||
@@ -432,20 +433,20 @@ GNUNET_FS_unindex_do_extract_keywords_(struct GNUNET_FS_UnindexContext *uc) | |||
432 | * @param msg NULL on success, otherwise an error message | 433 | * @param msg NULL on success, otherwise an error message |
433 | */ | 434 | */ |
434 | static void | 435 | static void |
435 | continue_after_remove(void *cls, | 436 | continue_after_remove (void *cls, |
436 | int32_t success, | 437 | int32_t success, |
437 | struct GNUNET_TIME_Absolute min_expiration, | 438 | struct GNUNET_TIME_Absolute min_expiration, |
438 | const char *msg) | 439 | const char *msg) |
439 | { | 440 | { |
440 | struct GNUNET_FS_UnindexContext *uc = cls; | 441 | struct GNUNET_FS_UnindexContext *uc = cls; |
441 | 442 | ||
442 | uc->dqe = NULL; | 443 | uc->dqe = NULL; |
443 | if (success != GNUNET_YES) | 444 | if (success != GNUNET_YES) |
444 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 445 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
445 | _("Failed to remove UBlock: %s\n"), | 446 | _ ("Failed to remove UBlock: %s\n"), |
446 | msg); | 447 | msg); |
447 | uc->ksk_offset++; | 448 | uc->ksk_offset++; |
448 | GNUNET_FS_unindex_do_remove_kblocks_(uc); | 449 | GNUNET_FS_unindex_do_remove_kblocks_ (uc); |
449 | } | 450 | } |
450 | 451 | ||
451 | 452 | ||
@@ -472,16 +473,16 @@ continue_after_remove(void *cls, | |||
472 | * maybe 0 if no unique identifier is available | 473 | * maybe 0 if no unique identifier is available |
473 | */ | 474 | */ |
474 | static void | 475 | static void |
475 | process_kblock_for_unindex(void *cls, | 476 | process_kblock_for_unindex (void *cls, |
476 | const struct GNUNET_HashCode *key, | 477 | const struct GNUNET_HashCode *key, |
477 | size_t size, | 478 | size_t size, |
478 | const void *data, | 479 | const void *data, |
479 | enum GNUNET_BLOCK_Type type, | 480 | enum GNUNET_BLOCK_Type type, |
480 | uint32_t priority, | 481 | uint32_t priority, |
481 | uint32_t anonymity, | 482 | uint32_t anonymity, |
482 | uint32_t replication, | 483 | uint32_t replication, |
483 | struct GNUNET_TIME_Absolute expiration, | 484 | struct GNUNET_TIME_Absolute expiration, |
484 | uint64_t uid) | 485 | uint64_t uid) |
485 | { | 486 | { |
486 | struct GNUNET_FS_UnindexContext *uc = cls; | 487 | struct GNUNET_FS_UnindexContext *uc = cls; |
487 | const struct UBlock *ub; | 488 | const struct UBlock *ub; |
@@ -490,82 +491,83 @@ process_kblock_for_unindex(void *cls, | |||
490 | 491 | ||
491 | uc->dqe = NULL; | 492 | uc->dqe = NULL; |
492 | if (NULL == data) | 493 | if (NULL == data) |
493 | { | 494 | { |
494 | /* no result */ | 495 | /* no result */ |
495 | uc->ksk_offset++; | 496 | uc->ksk_offset++; |
496 | GNUNET_FS_unindex_do_remove_kblocks_(uc); | 497 | GNUNET_FS_unindex_do_remove_kblocks_ (uc); |
497 | return; | 498 | return; |
498 | } | 499 | } |
499 | GNUNET_assert(GNUNET_BLOCK_TYPE_FS_UBLOCK == type); | 500 | GNUNET_assert (GNUNET_BLOCK_TYPE_FS_UBLOCK == type); |
500 | if (size < sizeof(struct UBlock)) | 501 | if (size < sizeof(struct UBlock)) |
501 | { | 502 | { |
502 | GNUNET_break(0); | 503 | GNUNET_break (0); |
503 | goto get_next; | 504 | goto get_next; |
504 | } | 505 | } |
505 | ub = data; | 506 | ub = data; |
506 | GNUNET_CRYPTO_hash(&ub->verification_key, | 507 | GNUNET_CRYPTO_hash (&ub->verification_key, |
507 | sizeof(ub->verification_key), | 508 | sizeof(ub->verification_key), |
508 | &query); | 509 | &query); |
509 | if (0 != memcmp(&query, | 510 | if (0 != memcmp (&query, |
510 | key, | 511 | key, |
511 | sizeof(struct GNUNET_HashCode))) | 512 | sizeof(struct GNUNET_HashCode))) |
512 | { | 513 | { |
513 | /* result does not match our keyword, skip */ | 514 | /* result does not match our keyword, skip */ |
514 | goto get_next; | 515 | goto get_next; |
515 | } | 516 | } |
516 | { | 517 | { |
517 | char pt[size - sizeof(struct UBlock)]; | 518 | char pt[size - sizeof(struct UBlock)]; |
518 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; | 519 | struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; |
519 | const char *keyword; | 520 | const char *keyword; |
520 | 521 | ||
521 | GNUNET_CRYPTO_ecdsa_key_get_public(GNUNET_CRYPTO_ecdsa_key_get_anonymous(), | 522 | GNUNET_CRYPTO_ecdsa_key_get_public ( |
522 | &anon_pub); | 523 | GNUNET_CRYPTO_ecdsa_key_get_anonymous (), |
524 | &anon_pub); | ||
523 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; | 525 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; |
524 | GNUNET_FS_ublock_decrypt_(&ub[1], size - sizeof(struct UBlock), | 526 | GNUNET_FS_ublock_decrypt_ (&ub[1], size - sizeof(struct UBlock), |
525 | &anon_pub, | 527 | &anon_pub, |
526 | keyword, | 528 | keyword, |
527 | pt); | 529 | pt); |
528 | if (NULL == memchr(&pt[1], 0, sizeof(pt) - 1)) | 530 | if (NULL == memchr (&pt[1], 0, sizeof(pt) - 1)) |
529 | { | 531 | { |
530 | GNUNET_break_op(0); /* malformed UBlock */ | 532 | GNUNET_break_op (0); /* malformed UBlock */ |
531 | goto get_next; | 533 | goto get_next; |
532 | } | 534 | } |
533 | chk_uri = GNUNET_FS_uri_parse(&pt[1], NULL); | 535 | chk_uri = GNUNET_FS_uri_parse (&pt[1], NULL); |
534 | if (NULL == chk_uri) | 536 | if (NULL == chk_uri) |
535 | { | ||
536 | GNUNET_break_op(0); /* malformed UBlock */ | ||
537 | goto get_next; | ||
538 | } | ||
539 | } | ||
540 | if (0 != memcmp(&uc->chk, | ||
541 | &chk_uri->data.chk.chk, | ||
542 | sizeof(struct ContentHashKey))) | ||
543 | { | 537 | { |
544 | /* different CHK, ignore */ | 538 | GNUNET_break_op (0); /* malformed UBlock */ |
545 | GNUNET_FS_uri_destroy(chk_uri); | ||
546 | goto get_next; | 539 | goto get_next; |
547 | } | 540 | } |
548 | GNUNET_FS_uri_destroy(chk_uri); | 541 | } |
542 | if (0 != memcmp (&uc->chk, | ||
543 | &chk_uri->data.chk.chk, | ||
544 | sizeof(struct ContentHashKey))) | ||
545 | { | ||
546 | /* different CHK, ignore */ | ||
547 | GNUNET_FS_uri_destroy (chk_uri); | ||
548 | goto get_next; | ||
549 | } | ||
550 | GNUNET_FS_uri_destroy (chk_uri); | ||
549 | /* matches! */ | 551 | /* matches! */ |
550 | uc->dqe = GNUNET_DATASTORE_remove(uc->dsh, | 552 | uc->dqe = GNUNET_DATASTORE_remove (uc->dsh, |
551 | key, | 553 | key, |
552 | size, | 554 | size, |
553 | data, | 555 | data, |
554 | 0 /* priority */, | ||
555 | 1 /* queue size */, | ||
556 | &continue_after_remove, | ||
557 | uc); | ||
558 | return; | ||
559 | get_next: | ||
560 | uc->dqe = GNUNET_DATASTORE_get_key(uc->dsh, | ||
561 | uid + 1 /* next_uid */, | ||
562 | false /* random */, | ||
563 | &uc->uquery, | ||
564 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | ||
565 | 0 /* priority */, | 556 | 0 /* priority */, |
566 | 1 /* queue size */, | 557 | 1 /* queue size */, |
567 | &process_kblock_for_unindex, | 558 | &continue_after_remove, |
568 | uc); | 559 | uc); |
560 | return; | ||
561 | get_next: | ||
562 | uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, | ||
563 | uid + 1 /* next_uid */, | ||
564 | false /* random */, | ||
565 | &uc->uquery, | ||
566 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | ||
567 | 0 /* priority */, | ||
568 | 1 /* queue size */, | ||
569 | &process_kblock_for_unindex, | ||
570 | uc); | ||
569 | } | 571 | } |
570 | 572 | ||
571 | 573 | ||
@@ -575,7 +577,7 @@ get_next: | |||
575 | * @param uc context for the unindex operation. | 577 | * @param uc context for the unindex operation. |
576 | */ | 578 | */ |
577 | void | 579 | void |
578 | GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc) | 580 | GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) |
579 | { | 581 | { |
580 | const char *keyword; | 582 | const char *keyword; |
581 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; | 583 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; |
@@ -583,41 +585,41 @@ GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc) | |||
583 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; | 585 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; |
584 | 586 | ||
585 | if (NULL == uc->dsh) | 587 | if (NULL == uc->dsh) |
586 | uc->dsh = GNUNET_DATASTORE_connect(uc->h->cfg); | 588 | uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); |
587 | if (NULL == uc->dsh) | 589 | if (NULL == uc->dsh) |
588 | { | 590 | { |
589 | uc->state = UNINDEX_STATE_ERROR; | 591 | uc->state = UNINDEX_STATE_ERROR; |
590 | uc->emsg = GNUNET_strdup(_("Failed to connect to `datastore' service.")); | 592 | uc->emsg = GNUNET_strdup (_ ("Failed to connect to `datastore' service.")); |
591 | GNUNET_FS_unindex_sync_(uc); | 593 | GNUNET_FS_unindex_sync_ (uc); |
592 | signal_unindex_error(uc); | 594 | signal_unindex_error (uc); |
593 | return; | 595 | return; |
594 | } | 596 | } |
595 | if ((NULL == uc->ksk_uri) || | 597 | if ((NULL == uc->ksk_uri) || |
596 | (uc->ksk_offset >= uc->ksk_uri->data.ksk.keywordCount)) | 598 | (uc->ksk_offset >= uc->ksk_uri->data.ksk.keywordCount)) |
597 | { | 599 | { |
598 | unindex_finish(uc); | 600 | unindex_finish (uc); |
599 | return; | 601 | return; |
600 | } | 602 | } |
601 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous(); | 603 | anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); |
602 | GNUNET_CRYPTO_ecdsa_key_get_public(anon, | 604 | GNUNET_CRYPTO_ecdsa_key_get_public (anon, |
603 | &anon_pub); | 605 | &anon_pub); |
604 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; | 606 | keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; |
605 | GNUNET_CRYPTO_ecdsa_public_key_derive(&anon_pub, | 607 | GNUNET_CRYPTO_ecdsa_public_key_derive (&anon_pub, |
606 | keyword, | 608 | keyword, |
607 | "fs-ublock", | 609 | "fs-ublock", |
608 | &dpub); | 610 | &dpub); |
609 | GNUNET_CRYPTO_hash(&dpub, | 611 | GNUNET_CRYPTO_hash (&dpub, |
610 | sizeof(dpub), | 612 | sizeof(dpub), |
611 | &uc->uquery); | 613 | &uc->uquery); |
612 | uc->dqe = GNUNET_DATASTORE_get_key(uc->dsh, | 614 | uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, |
613 | 0 /* next_uid */, | 615 | 0 /* next_uid */, |
614 | false /* random */, | 616 | false /* random */, |
615 | &uc->uquery, | 617 | &uc->uquery, |
616 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | 618 | GNUNET_BLOCK_TYPE_FS_UBLOCK, |
617 | 0 /* priority */, | 619 | 0 /* priority */, |
618 | 1 /* queue size */, | 620 | 1 /* queue size */, |
619 | &process_kblock_for_unindex, | 621 | &process_kblock_for_unindex, |
620 | uc); | 622 | uc); |
621 | } | 623 | } |
622 | 624 | ||
623 | 625 | ||
@@ -628,13 +630,13 @@ GNUNET_FS_unindex_do_remove_kblocks_(struct GNUNET_FS_UnindexContext *uc) | |||
628 | * @param cls our unindexing context | 630 | * @param cls our unindexing context |
629 | */ | 631 | */ |
630 | static void | 632 | static void |
631 | unindex_extract_keywords(void *cls) | 633 | unindex_extract_keywords (void *cls) |
632 | { | 634 | { |
633 | struct GNUNET_FS_UnindexContext *uc = cls; | 635 | struct GNUNET_FS_UnindexContext *uc = cls; |
634 | 636 | ||
635 | uc->state = UNINDEX_STATE_EXTRACT_KEYWORDS; | 637 | uc->state = UNINDEX_STATE_EXTRACT_KEYWORDS; |
636 | GNUNET_FS_unindex_sync_(uc); | 638 | GNUNET_FS_unindex_sync_ (uc); |
637 | GNUNET_FS_unindex_do_extract_keywords_(uc); | 639 | GNUNET_FS_unindex_do_extract_keywords_ (uc); |
638 | } | 640 | } |
639 | 641 | ||
640 | 642 | ||
@@ -644,40 +646,40 @@ unindex_extract_keywords(void *cls) | |||
644 | * @param uc context for the unindex operation. | 646 | * @param uc context for the unindex operation. |
645 | */ | 647 | */ |
646 | void | 648 | void |
647 | GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc) | 649 | GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc) |
648 | { | 650 | { |
649 | if (NULL == uc->dsh) | 651 | if (NULL == uc->dsh) |
650 | uc->dsh = GNUNET_DATASTORE_connect(uc->h->cfg); | 652 | uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); |
651 | if (NULL == uc->dsh) | 653 | if (NULL == uc->dsh) |
652 | { | 654 | { |
653 | uc->state = UNINDEX_STATE_ERROR; | 655 | uc->state = UNINDEX_STATE_ERROR; |
654 | uc->emsg = GNUNET_strdup(_("Failed to connect to `datastore' service.")); | 656 | uc->emsg = GNUNET_strdup (_ ("Failed to connect to `datastore' service.")); |
655 | GNUNET_FS_unindex_sync_(uc); | 657 | GNUNET_FS_unindex_sync_ (uc); |
656 | signal_unindex_error(uc); | 658 | signal_unindex_error (uc); |
657 | return; | 659 | return; |
658 | } | 660 | } |
659 | uc->fh = | 661 | uc->fh = |
660 | GNUNET_DISK_file_open(uc->filename, GNUNET_DISK_OPEN_READ, | 662 | GNUNET_DISK_file_open (uc->filename, GNUNET_DISK_OPEN_READ, |
661 | GNUNET_DISK_PERM_NONE); | 663 | GNUNET_DISK_PERM_NONE); |
662 | if (NULL == uc->fh) | 664 | if (NULL == uc->fh) |
663 | { | 665 | { |
664 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); | 666 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); |
665 | uc->dsh = NULL; | 667 | uc->dsh = NULL; |
666 | uc->state = UNINDEX_STATE_ERROR; | 668 | uc->state = UNINDEX_STATE_ERROR; |
667 | uc->emsg = GNUNET_strdup(_("Failed to open file for unindexing.")); | 669 | uc->emsg = GNUNET_strdup (_ ("Failed to open file for unindexing.")); |
668 | GNUNET_FS_unindex_sync_(uc); | 670 | GNUNET_FS_unindex_sync_ (uc); |
669 | signal_unindex_error(uc); | 671 | signal_unindex_error (uc); |
670 | return; | 672 | return; |
671 | } | 673 | } |
672 | uc->tc = | 674 | uc->tc = |
673 | GNUNET_FS_tree_encoder_create(uc->h, | 675 | GNUNET_FS_tree_encoder_create (uc->h, |
674 | uc->file_size, | 676 | uc->file_size, |
675 | uc, | 677 | uc, |
676 | &unindex_reader, | 678 | &unindex_reader, |
677 | &unindex_process, | 679 | &unindex_process, |
678 | &unindex_progress, | 680 | &unindex_progress, |
679 | &unindex_extract_keywords); | 681 | &unindex_extract_keywords); |
680 | GNUNET_FS_tree_encoder_next(uc->tc); | 682 | GNUNET_FS_tree_encoder_next (uc->tc); |
681 | } | 683 | } |
682 | 684 | ||
683 | 685 | ||
@@ -689,29 +691,29 @@ GNUNET_FS_unindex_do_remove_(struct GNUNET_FS_UnindexContext *uc) | |||
689 | * @param file_id computed hash, NULL on error | 691 | * @param file_id computed hash, NULL on error |
690 | */ | 692 | */ |
691 | void | 693 | void |
692 | GNUNET_FS_unindex_process_hash_(void *cls, | 694 | GNUNET_FS_unindex_process_hash_ (void *cls, |
693 | const struct GNUNET_HashCode *file_id) | 695 | const struct GNUNET_HashCode *file_id) |
694 | { | 696 | { |
695 | struct GNUNET_FS_UnindexContext *uc = cls; | 697 | struct GNUNET_FS_UnindexContext *uc = cls; |
696 | 698 | ||
697 | uc->fhc = NULL; | 699 | uc->fhc = NULL; |
698 | if (uc->state != UNINDEX_STATE_HASHING) | 700 | if (uc->state != UNINDEX_STATE_HASHING) |
699 | { | 701 | { |
700 | GNUNET_FS_unindex_stop(uc); | 702 | GNUNET_FS_unindex_stop (uc); |
701 | return; | 703 | return; |
702 | } | 704 | } |
703 | if (file_id == NULL) | 705 | if (file_id == NULL) |
704 | { | 706 | { |
705 | uc->state = UNINDEX_STATE_ERROR; | 707 | uc->state = UNINDEX_STATE_ERROR; |
706 | uc->emsg = GNUNET_strdup(_("Failed to compute hash of file.")); | 708 | uc->emsg = GNUNET_strdup (_ ("Failed to compute hash of file.")); |
707 | GNUNET_FS_unindex_sync_(uc); | 709 | GNUNET_FS_unindex_sync_ (uc); |
708 | signal_unindex_error(uc); | 710 | signal_unindex_error (uc); |
709 | return; | 711 | return; |
710 | } | 712 | } |
711 | uc->file_id = *file_id; | 713 | uc->file_id = *file_id; |
712 | uc->state = UNINDEX_STATE_DS_REMOVE; | 714 | uc->state = UNINDEX_STATE_DS_REMOVE; |
713 | GNUNET_FS_unindex_sync_(uc); | 715 | GNUNET_FS_unindex_sync_ (uc); |
714 | GNUNET_FS_unindex_do_remove_(uc); | 716 | GNUNET_FS_unindex_do_remove_ (uc); |
715 | } | 717 | } |
716 | 718 | ||
717 | 719 | ||
@@ -722,62 +724,62 @@ GNUNET_FS_unindex_process_hash_(void *cls, | |||
722 | * @param cls the `struct GNUNET_FS_UnindexContext` to signal for | 724 | * @param cls the `struct GNUNET_FS_UnindexContext` to signal for |
723 | */ | 725 | */ |
724 | void | 726 | void |
725 | GNUNET_FS_unindex_signal_suspend_(void *cls) | 727 | GNUNET_FS_unindex_signal_suspend_ (void *cls) |
726 | { | 728 | { |
727 | struct GNUNET_FS_UnindexContext *uc = cls; | 729 | struct GNUNET_FS_UnindexContext *uc = cls; |
728 | struct GNUNET_FS_ProgressInfo pi; | 730 | struct GNUNET_FS_ProgressInfo pi; |
729 | 731 | ||
730 | /* FIXME: lots of duplication with unindex_stop here! */ | 732 | /* FIXME: lots of duplication with unindex_stop here! */ |
731 | if (uc->dscan != NULL) | 733 | if (uc->dscan != NULL) |
732 | { | 734 | { |
733 | GNUNET_FS_directory_scan_abort(uc->dscan); | 735 | GNUNET_FS_directory_scan_abort (uc->dscan); |
734 | uc->dscan = NULL; | 736 | uc->dscan = NULL; |
735 | } | 737 | } |
736 | if (NULL != uc->dqe) | 738 | if (NULL != uc->dqe) |
737 | { | 739 | { |
738 | GNUNET_DATASTORE_cancel(uc->dqe); | 740 | GNUNET_DATASTORE_cancel (uc->dqe); |
739 | uc->dqe = NULL; | 741 | uc->dqe = NULL; |
740 | } | 742 | } |
741 | if (uc->fhc != NULL) | 743 | if (uc->fhc != NULL) |
742 | { | 744 | { |
743 | GNUNET_CRYPTO_hash_file_cancel(uc->fhc); | 745 | GNUNET_CRYPTO_hash_file_cancel (uc->fhc); |
744 | uc->fhc = NULL; | 746 | uc->fhc = NULL; |
745 | } | 747 | } |
746 | if (NULL != uc->ksk_uri) | 748 | if (NULL != uc->ksk_uri) |
747 | { | 749 | { |
748 | GNUNET_FS_uri_destroy(uc->ksk_uri); | 750 | GNUNET_FS_uri_destroy (uc->ksk_uri); |
749 | uc->ksk_uri = NULL; | 751 | uc->ksk_uri = NULL; |
750 | } | 752 | } |
751 | if (NULL != uc->mq) | 753 | if (NULL != uc->mq) |
752 | { | 754 | { |
753 | GNUNET_MQ_destroy(uc->mq); | 755 | GNUNET_MQ_destroy (uc->mq); |
754 | uc->mq = NULL; | 756 | uc->mq = NULL; |
755 | } | 757 | } |
756 | if (NULL != uc->dsh) | 758 | if (NULL != uc->dsh) |
757 | { | 759 | { |
758 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); | 760 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); |
759 | uc->dsh = NULL; | 761 | uc->dsh = NULL; |
760 | } | 762 | } |
761 | if (NULL != uc->tc) | 763 | if (NULL != uc->tc) |
762 | { | 764 | { |
763 | GNUNET_FS_tree_encoder_finish(uc->tc, NULL); | 765 | GNUNET_FS_tree_encoder_finish (uc->tc, NULL); |
764 | uc->tc = NULL; | 766 | uc->tc = NULL; |
765 | } | 767 | } |
766 | if (uc->fh != NULL) | 768 | if (uc->fh != NULL) |
767 | { | 769 | { |
768 | GNUNET_DISK_file_close(uc->fh); | 770 | GNUNET_DISK_file_close (uc->fh); |
769 | uc->fh = NULL; | 771 | uc->fh = NULL; |
770 | } | 772 | } |
771 | GNUNET_FS_end_top(uc->h, uc->top); | 773 | GNUNET_FS_end_top (uc->h, uc->top); |
772 | pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; | 774 | pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; |
773 | GNUNET_FS_unindex_make_status_(&pi, uc, | 775 | GNUNET_FS_unindex_make_status_ (&pi, uc, |
774 | (uc->state == | 776 | (uc->state == |
775 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); | 777 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); |
776 | GNUNET_break(NULL == uc->client_info); | 778 | GNUNET_break (NULL == uc->client_info); |
777 | GNUNET_free(uc->filename); | 779 | GNUNET_free (uc->filename); |
778 | GNUNET_free_non_null(uc->serialization); | 780 | GNUNET_free_non_null (uc->serialization); |
779 | GNUNET_free_non_null(uc->emsg); | 781 | GNUNET_free_non_null (uc->emsg); |
780 | GNUNET_free(uc); | 782 | GNUNET_free (uc); |
781 | } | 783 | } |
782 | 784 | ||
783 | 785 | ||
@@ -790,38 +792,38 @@ GNUNET_FS_unindex_signal_suspend_(void *cls) | |||
790 | * @return NULL on error, otherwise handle | 792 | * @return NULL on error, otherwise handle |
791 | */ | 793 | */ |
792 | struct GNUNET_FS_UnindexContext * | 794 | struct GNUNET_FS_UnindexContext * |
793 | GNUNET_FS_unindex_start(struct GNUNET_FS_Handle *h, | 795 | GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, |
794 | const char *filename, | 796 | const char *filename, |
795 | void *cctx) | 797 | void *cctx) |
796 | { | 798 | { |
797 | struct GNUNET_FS_UnindexContext *uc; | 799 | struct GNUNET_FS_UnindexContext *uc; |
798 | struct GNUNET_FS_ProgressInfo pi; | 800 | struct GNUNET_FS_ProgressInfo pi; |
799 | uint64_t size; | 801 | uint64_t size; |
800 | 802 | ||
801 | if (GNUNET_OK != | 803 | if (GNUNET_OK != |
802 | GNUNET_DISK_file_size(filename, | 804 | GNUNET_DISK_file_size (filename, |
803 | &size, | 805 | &size, |
804 | GNUNET_YES, | 806 | GNUNET_YES, |
805 | GNUNET_YES)) | 807 | GNUNET_YES)) |
806 | return NULL; | 808 | return NULL; |
807 | uc = GNUNET_new(struct GNUNET_FS_UnindexContext); | 809 | uc = GNUNET_new (struct GNUNET_FS_UnindexContext); |
808 | uc->h = h; | 810 | uc->h = h; |
809 | uc->filename = GNUNET_strdup(filename); | 811 | uc->filename = GNUNET_strdup (filename); |
810 | uc->start_time = GNUNET_TIME_absolute_get(); | 812 | uc->start_time = GNUNET_TIME_absolute_get (); |
811 | uc->file_size = size; | 813 | uc->file_size = size; |
812 | uc->client_info = cctx; | 814 | uc->client_info = cctx; |
813 | GNUNET_FS_unindex_sync_(uc); | 815 | GNUNET_FS_unindex_sync_ (uc); |
814 | pi.status = GNUNET_FS_STATUS_UNINDEX_START; | 816 | pi.status = GNUNET_FS_STATUS_UNINDEX_START; |
815 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 817 | pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
816 | GNUNET_FS_unindex_make_status_(&pi, uc, 0); | 818 | GNUNET_FS_unindex_make_status_ (&pi, uc, 0); |
817 | uc->fhc = | 819 | uc->fhc = |
818 | GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, | 820 | GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, |
819 | filename, | 821 | filename, |
820 | HASHING_BLOCKSIZE, | 822 | HASHING_BLOCKSIZE, |
821 | &GNUNET_FS_unindex_process_hash_, uc); | 823 | &GNUNET_FS_unindex_process_hash_, uc); |
822 | uc->top = GNUNET_FS_make_top(h, | 824 | uc->top = GNUNET_FS_make_top (h, |
823 | &GNUNET_FS_unindex_signal_suspend_, | 825 | &GNUNET_FS_unindex_signal_suspend_, |
824 | uc); | 826 | uc); |
825 | return uc; | 827 | return uc; |
826 | } | 828 | } |
827 | 829 | ||
@@ -832,67 +834,67 @@ GNUNET_FS_unindex_start(struct GNUNET_FS_Handle *h, | |||
832 | * @param uc handle | 834 | * @param uc handle |
833 | */ | 835 | */ |
834 | void | 836 | void |
835 | GNUNET_FS_unindex_stop(struct GNUNET_FS_UnindexContext *uc) | 837 | GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) |
836 | { | 838 | { |
837 | struct GNUNET_FS_ProgressInfo pi; | 839 | struct GNUNET_FS_ProgressInfo pi; |
838 | 840 | ||
839 | if (NULL != uc->dscan) | 841 | if (NULL != uc->dscan) |
840 | { | 842 | { |
841 | GNUNET_FS_directory_scan_abort(uc->dscan); | 843 | GNUNET_FS_directory_scan_abort (uc->dscan); |
842 | uc->dscan = NULL; | 844 | uc->dscan = NULL; |
843 | } | 845 | } |
844 | if (NULL != uc->dqe) | 846 | if (NULL != uc->dqe) |
845 | { | 847 | { |
846 | GNUNET_DATASTORE_cancel(uc->dqe); | 848 | GNUNET_DATASTORE_cancel (uc->dqe); |
847 | uc->dqe = NULL; | 849 | uc->dqe = NULL; |
848 | } | 850 | } |
849 | if (NULL != uc->fhc) | 851 | if (NULL != uc->fhc) |
850 | { | 852 | { |
851 | GNUNET_CRYPTO_hash_file_cancel(uc->fhc); | 853 | GNUNET_CRYPTO_hash_file_cancel (uc->fhc); |
852 | uc->fhc = NULL; | 854 | uc->fhc = NULL; |
853 | } | 855 | } |
854 | if (NULL != uc->mq) | 856 | if (NULL != uc->mq) |
855 | { | 857 | { |
856 | GNUNET_MQ_destroy(uc->mq); | 858 | GNUNET_MQ_destroy (uc->mq); |
857 | uc->mq = NULL; | 859 | uc->mq = NULL; |
858 | } | 860 | } |
859 | if (NULL != uc->dsh) | 861 | if (NULL != uc->dsh) |
860 | { | 862 | { |
861 | GNUNET_DATASTORE_disconnect(uc->dsh, GNUNET_NO); | 863 | GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); |
862 | uc->dsh = NULL; | 864 | uc->dsh = NULL; |
863 | } | 865 | } |
864 | if (NULL != uc->ksk_uri) | 866 | if (NULL != uc->ksk_uri) |
865 | { | 867 | { |
866 | GNUNET_FS_uri_destroy(uc->ksk_uri); | 868 | GNUNET_FS_uri_destroy (uc->ksk_uri); |
867 | uc->ksk_uri = NULL; | 869 | uc->ksk_uri = NULL; |
868 | } | 870 | } |
869 | if (NULL != uc->tc) | 871 | if (NULL != uc->tc) |
870 | { | 872 | { |
871 | GNUNET_FS_tree_encoder_finish(uc->tc, NULL); | 873 | GNUNET_FS_tree_encoder_finish (uc->tc, NULL); |
872 | uc->tc = NULL; | 874 | uc->tc = NULL; |
873 | } | 875 | } |
874 | if (uc->fh != NULL) | 876 | if (uc->fh != NULL) |
875 | { | 877 | { |
876 | GNUNET_DISK_file_close(uc->fh); | 878 | GNUNET_DISK_file_close (uc->fh); |
877 | uc->fh = NULL; | 879 | uc->fh = NULL; |
878 | } | 880 | } |
879 | GNUNET_FS_end_top(uc->h, uc->top); | 881 | GNUNET_FS_end_top (uc->h, uc->top); |
880 | if (uc->serialization != NULL) | 882 | if (uc->serialization != NULL) |
881 | { | 883 | { |
882 | GNUNET_FS_remove_sync_file_(uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 884 | GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
883 | uc->serialization); | 885 | uc->serialization); |
884 | GNUNET_free(uc->serialization); | 886 | GNUNET_free (uc->serialization); |
885 | uc->serialization = NULL; | 887 | uc->serialization = NULL; |
886 | } | 888 | } |
887 | pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; | 889 | pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; |
888 | pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; | 890 | pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; |
889 | GNUNET_FS_unindex_make_status_(&pi, uc, | 891 | GNUNET_FS_unindex_make_status_ (&pi, uc, |
890 | (uc->state == | 892 | (uc->state == |
891 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); | 893 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); |
892 | GNUNET_break(NULL == uc->client_info); | 894 | GNUNET_break (NULL == uc->client_info); |
893 | GNUNET_free_non_null(uc->emsg); | 895 | GNUNET_free_non_null (uc->emsg); |
894 | GNUNET_free(uc->filename); | 896 | GNUNET_free (uc->filename); |
895 | GNUNET_free(uc); | 897 | GNUNET_free (uc); |
896 | } | 898 | } |
897 | 899 | ||
898 | /* end of fs_unindex.c */ | 900 | /* end of fs_unindex.c */ |
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index c9ce19114..7eb9f86b0 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c | |||
@@ -100,47 +100,47 @@ | |||
100 | * @return #GNUNET_OK on success | 100 | * @return #GNUNET_OK on success |
101 | */ | 101 | */ |
102 | int | 102 | int |
103 | GNUNET_FS_uri_to_key(const struct GNUNET_FS_Uri *uri, | 103 | GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, |
104 | struct GNUNET_HashCode *key) | 104 | struct GNUNET_HashCode *key) |
105 | { | 105 | { |
106 | switch (uri->type) | 106 | switch (uri->type) |
107 | { | ||
108 | case GNUNET_FS_URI_CHK: | ||
109 | *key = uri->data.chk.chk.query; | ||
110 | return GNUNET_OK; | ||
111 | |||
112 | case GNUNET_FS_URI_SKS: | ||
113 | GNUNET_CRYPTO_hash (uri->data.sks.identifier, | ||
114 | strlen (uri->data.sks.identifier), | ||
115 | key); | ||
116 | return GNUNET_OK; | ||
117 | |||
118 | case GNUNET_FS_URI_KSK: | ||
119 | if (uri->data.ksk.keywordCount > 0) | ||
107 | { | 120 | { |
108 | case GNUNET_FS_URI_CHK: | 121 | GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], |
109 | *key = uri->data.chk.chk.query; | 122 | strlen (uri->data.ksk.keywords[0]), |
123 | key); | ||
110 | return GNUNET_OK; | 124 | return GNUNET_OK; |
111 | 125 | } | |
112 | case GNUNET_FS_URI_SKS: | 126 | else |
113 | GNUNET_CRYPTO_hash(uri->data.sks.identifier, | 127 | { |
114 | strlen(uri->data.sks.identifier), | 128 | memset (key, 0, sizeof(struct GNUNET_HashCode)); |
115 | key); | ||
116 | return GNUNET_OK; | ||
117 | |||
118 | case GNUNET_FS_URI_KSK: | ||
119 | if (uri->data.ksk.keywordCount > 0) | ||
120 | { | ||
121 | GNUNET_CRYPTO_hash(uri->data.ksk.keywords[0], | ||
122 | strlen(uri->data.ksk.keywords[0]), | ||
123 | key); | ||
124 | return GNUNET_OK; | ||
125 | } | ||
126 | else | ||
127 | { | ||
128 | memset(key, 0, sizeof(struct GNUNET_HashCode)); | ||
129 | return GNUNET_SYSERR; | ||
130 | } | ||
131 | break; | ||
132 | |||
133 | case GNUNET_FS_URI_LOC: | ||
134 | GNUNET_CRYPTO_hash(&uri->data.loc.fi, | ||
135 | sizeof(struct FileIdentifier) + | ||
136 | sizeof(struct GNUNET_PeerIdentity), | ||
137 | key); | ||
138 | return GNUNET_OK; | ||
139 | |||
140 | default: | ||
141 | memset(key, 0, sizeof(struct GNUNET_HashCode)); | ||
142 | return GNUNET_SYSERR; | 129 | return GNUNET_SYSERR; |
143 | } | 130 | } |
131 | break; | ||
132 | |||
133 | case GNUNET_FS_URI_LOC: | ||
134 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, | ||
135 | sizeof(struct FileIdentifier) | ||
136 | + sizeof(struct GNUNET_PeerIdentity), | ||
137 | key); | ||
138 | return GNUNET_OK; | ||
139 | |||
140 | default: | ||
141 | memset (key, 0, sizeof(struct GNUNET_HashCode)); | ||
142 | return GNUNET_SYSERR; | ||
143 | } | ||
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
@@ -152,7 +152,7 @@ GNUNET_FS_uri_to_key(const struct GNUNET_FS_Uri *uri, | |||
152 | * @return string with the keywords | 152 | * @return string with the keywords |
153 | */ | 153 | */ |
154 | char * | 154 | char * |
155 | GNUNET_FS_uri_ksk_to_string_fancy(const struct GNUNET_FS_Uri *uri) | 155 | GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) |
156 | { | 156 | { |
157 | size_t n; | 157 | size_t n; |
158 | char *ret; | 158 | char *ret; |
@@ -162,45 +162,45 @@ GNUNET_FS_uri_ksk_to_string_fancy(const struct GNUNET_FS_Uri *uri) | |||
162 | unsigned int keywordCount; | 162 | unsigned int keywordCount; |
163 | 163 | ||
164 | if ((NULL == uri) || (GNUNET_FS_URI_KSK != uri->type)) | 164 | if ((NULL == uri) || (GNUNET_FS_URI_KSK != uri->type)) |
165 | { | 165 | { |
166 | GNUNET_break(0); | 166 | GNUNET_break (0); |
167 | return NULL; | 167 | return NULL; |
168 | } | 168 | } |
169 | keywords = uri->data.ksk.keywords; | 169 | keywords = uri->data.ksk.keywords; |
170 | keywordCount = uri->data.ksk.keywordCount; | 170 | keywordCount = uri->data.ksk.keywordCount; |
171 | n = keywordCount + 1; | 171 | n = keywordCount + 1; |
172 | for (i = 0; i < keywordCount; i++) | 172 | for (i = 0; i < keywordCount; i++) |
173 | { | ||
174 | keyword = keywords[i]; | ||
175 | n += strlen (keyword) - 1; | ||
176 | if (NULL != strstr (&keyword[1], " ")) | ||
177 | n += 2; | ||
178 | if (keyword[0] == '+') | ||
179 | n++; | ||
180 | } | ||
181 | ret = GNUNET_malloc (n); | ||
182 | strcpy (ret, ""); | ||
183 | for (i = 0; i < keywordCount; i++) | ||
184 | { | ||
185 | keyword = keywords[i]; | ||
186 | if (NULL != strstr (&keyword[1], " ")) | ||
173 | { | 187 | { |
174 | keyword = keywords[i]; | 188 | strcat (ret, "\""); |
175 | n += strlen(keyword) - 1; | ||
176 | if (NULL != strstr(&keyword[1], " ")) | ||
177 | n += 2; | ||
178 | if (keyword[0] == '+') | 189 | if (keyword[0] == '+') |
179 | n++; | 190 | strcat (ret, keyword); |
191 | else | ||
192 | strcat (ret, &keyword[1]); | ||
193 | strcat (ret, "\""); | ||
180 | } | 194 | } |
181 | ret = GNUNET_malloc(n); | 195 | else |
182 | strcpy(ret, ""); | ||
183 | for (i = 0; i < keywordCount; i++) | ||
184 | { | 196 | { |
185 | keyword = keywords[i]; | 197 | if (keyword[0] == '+') |
186 | if (NULL != strstr(&keyword[1], " ")) | 198 | strcat (ret, keyword); |
187 | { | ||
188 | strcat(ret, "\""); | ||
189 | if (keyword[0] == '+') | ||
190 | strcat(ret, keyword); | ||
191 | else | ||
192 | strcat(ret, &keyword[1]); | ||
193 | strcat(ret, "\""); | ||
194 | } | ||
195 | else | 199 | else |
196 | { | 200 | strcat (ret, &keyword[1]); |
197 | if (keyword[0] == '+') | ||
198 | strcat(ret, keyword); | ||
199 | else | ||
200 | strcat(ret, &keyword[1]); | ||
201 | } | ||
202 | strcat(ret, " "); | ||
203 | } | 201 | } |
202 | strcat (ret, " "); | ||
203 | } | ||
204 | return ret; | 204 | return ret; |
205 | } | 205 | } |
206 | 206 | ||
@@ -216,7 +216,7 @@ GNUNET_FS_uri_ksk_to_string_fancy(const struct GNUNET_FS_Uri *uri) | |||
216 | * @return decodded string with leading space (or preserved plus) | 216 | * @return decodded string with leading space (or preserved plus) |
217 | */ | 217 | */ |
218 | static char * | 218 | static char * |
219 | percent_decode_keyword(const char *in, char **emsg) | 219 | percent_decode_keyword (const char *in, char **emsg) |
220 | { | 220 | { |
221 | char *out; | 221 | char *out; |
222 | char *ret; | 222 | char *ret; |
@@ -224,44 +224,44 @@ percent_decode_keyword(const char *in, char **emsg) | |||
224 | unsigned int wpos; | 224 | unsigned int wpos; |
225 | unsigned int hx; | 225 | unsigned int hx; |
226 | 226 | ||
227 | out = GNUNET_strdup(in); | 227 | out = GNUNET_strdup (in); |
228 | rpos = 0; | 228 | rpos = 0; |
229 | wpos = 0; | 229 | wpos = 0; |
230 | while (out[rpos] != '\0') | 230 | while (out[rpos] != '\0') |
231 | { | ||
232 | if (out[rpos] == '%') | ||
231 | { | 233 | { |
232 | if (out[rpos] == '%') | 234 | if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) |
233 | { | 235 | { |
234 | if (1 != sscanf(&out[rpos + 1], "%2X", &hx)) | 236 | GNUNET_free (out); |
235 | { | 237 | *emsg = GNUNET_strdup ( |
236 | GNUNET_free(out); | 238 | _ ( /* xgettext:no-c-format */ |
237 | *emsg = GNUNET_strdup( | 239 | "Malformed KSK URI (`%' must be followed by HEX number)")); |
238 | _(/* xgettext:no-c-format */ | 240 | return NULL; |
239 | "Malformed KSK URI (`%' must be followed by HEX number)")); | 241 | } |
240 | return NULL; | 242 | rpos += 3; |
241 | } | 243 | if (hx == '"') |
242 | rpos += 3; | 244 | continue; /* skip double quote */ |
243 | if (hx == '"') | 245 | out[wpos++] = (char) hx; |
244 | continue; /* skip double quote */ | ||
245 | out[wpos++] = (char)hx; | ||
246 | } | ||
247 | else | ||
248 | { | ||
249 | out[wpos++] = out[rpos++]; | ||
250 | } | ||
251 | } | 246 | } |
252 | out[wpos] = '\0'; | 247 | else |
253 | if (out[0] == '+') | ||
254 | { | 248 | { |
255 | ret = GNUNET_strdup(out); | 249 | out[wpos++] = out[rpos++]; |
256 | } | 250 | } |
251 | } | ||
252 | out[wpos] = '\0'; | ||
253 | if (out[0] == '+') | ||
254 | { | ||
255 | ret = GNUNET_strdup (out); | ||
256 | } | ||
257 | else | 257 | else |
258 | { | 258 | { |
259 | /* need to prefix with space */ | 259 | /* need to prefix with space */ |
260 | ret = GNUNET_malloc(strlen(out) + 2); | 260 | ret = GNUNET_malloc (strlen (out) + 2); |
261 | strcpy(ret, " "); | 261 | strcpy (ret, " "); |
262 | strcat(ret, out); | 262 | strcat (ret, out); |
263 | } | 263 | } |
264 | GNUNET_free(out); | 264 | GNUNET_free (out); |
265 | return ret; | 265 | return ret; |
266 | } | 266 | } |
267 | 267 | ||
@@ -275,7 +275,7 @@ percent_decode_keyword(const char *in, char **emsg) | |||
275 | * @return NULL on error, otherwise the KSK URI | 275 | * @return NULL on error, otherwise the KSK URI |
276 | */ | 276 | */ |
277 | static struct GNUNET_FS_Uri * | 277 | static struct GNUNET_FS_Uri * |
278 | uri_ksk_parse(const char *s, char **emsg) | 278 | uri_ksk_parse (const char *s, char **emsg) |
279 | { | 279 | { |
280 | struct GNUNET_FS_Uri *ret; | 280 | struct GNUNET_FS_Uri *ret; |
281 | char **keywords; | 281 | char **keywords; |
@@ -287,74 +287,74 @@ uri_ksk_parse(const char *s, char **emsg) | |||
287 | char *dup; | 287 | char *dup; |
288 | int saw_quote; | 288 | int saw_quote; |
289 | 289 | ||
290 | slen = strlen(s); | 290 | slen = strlen (s); |
291 | pos = strlen(GNUNET_FS_URI_KSK_PREFIX); | 291 | pos = strlen (GNUNET_FS_URI_KSK_PREFIX); |
292 | if ((slen <= pos) || (0 != strncmp(s, GNUNET_FS_URI_KSK_PREFIX, pos))) | 292 | if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos))) |
293 | return NULL; /* not KSK URI */ | 293 | return NULL; /* not KSK URI */ |
294 | if ((s[slen - 1] == '+') || (s[pos] == '+')) | 294 | if ((s[slen - 1] == '+') || (s[pos] == '+')) |
295 | { | 295 | { |
296 | *emsg = | 296 | *emsg = |
297 | GNUNET_strdup(_("Malformed KSK URI (must not begin or end with `+')")); | 297 | GNUNET_strdup (_ ("Malformed KSK URI (must not begin or end with `+')")); |
298 | return NULL; | 298 | return NULL; |
299 | } | 299 | } |
300 | max = 1; | 300 | max = 1; |
301 | saw_quote = 0; | 301 | saw_quote = 0; |
302 | for (i = pos; i < slen; i++) | 302 | for (i = pos; i < slen; i++) |
303 | { | ||
304 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | ||
303 | { | 305 | { |
304 | if ((s[i] == '%') && (&s[i] == strstr(&s[i], "%22"))) | 306 | saw_quote = (saw_quote + 1) % 2; |
305 | { | 307 | i += 3; |
306 | saw_quote = (saw_quote + 1) % 2; | 308 | continue; |
307 | i += 3; | ||
308 | continue; | ||
309 | } | ||
310 | if ((s[i] == '+') && (saw_quote == 0)) | ||
311 | { | ||
312 | max++; | ||
313 | if (s[i - 1] == '+') | ||
314 | { | ||
315 | *emsg = GNUNET_strdup(_("Malformed KSK URI (`++' not allowed)")); | ||
316 | return NULL; | ||
317 | } | ||
318 | } | ||
319 | } | 309 | } |
320 | if (saw_quote == 1) | 310 | if ((s[i] == '+') && (saw_quote == 0)) |
321 | { | 311 | { |
322 | *emsg = GNUNET_strdup(_("Malformed KSK URI (quotes not balanced)")); | 312 | max++; |
323 | return NULL; | 313 | if (s[i - 1] == '+') |
314 | { | ||
315 | *emsg = GNUNET_strdup (_ ("Malformed KSK URI (`++' not allowed)")); | ||
316 | return NULL; | ||
317 | } | ||
324 | } | 318 | } |
319 | } | ||
320 | if (saw_quote == 1) | ||
321 | { | ||
322 | *emsg = GNUNET_strdup (_ ("Malformed KSK URI (quotes not balanced)")); | ||
323 | return NULL; | ||
324 | } | ||
325 | iret = max; | 325 | iret = max; |
326 | dup = GNUNET_strdup(s); | 326 | dup = GNUNET_strdup (s); |
327 | keywords = GNUNET_new_array(max, char *); | 327 | keywords = GNUNET_new_array (max, char *); |
328 | for (i = slen - 1; i >= (int)pos; i--) | 328 | for (i = slen - 1; i >= (int) pos; i--) |
329 | { | ||
330 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | ||
329 | { | 331 | { |
330 | if ((s[i] == '%') && (&s[i] == strstr(&s[i], "%22"))) | 332 | saw_quote = (saw_quote + 1) % 2; |
331 | { | 333 | continue; |
332 | saw_quote = (saw_quote + 1) % 2; | ||
333 | continue; | ||
334 | } | ||
335 | if ((dup[i] == '+') && (saw_quote == 0)) | ||
336 | { | ||
337 | keywords[--max] = percent_decode_keyword(&dup[i + 1], emsg); | ||
338 | if (NULL == keywords[max]) | ||
339 | goto CLEANUP; | ||
340 | dup[i] = '\0'; | ||
341 | } | ||
342 | } | 334 | } |
343 | keywords[--max] = percent_decode_keyword(&dup[pos], emsg); | 335 | if ((dup[i] == '+') && (saw_quote == 0)) |
336 | { | ||
337 | keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg); | ||
338 | if (NULL == keywords[max]) | ||
339 | goto CLEANUP; | ||
340 | dup[i] = '\0'; | ||
341 | } | ||
342 | } | ||
343 | keywords[--max] = percent_decode_keyword (&dup[pos], emsg); | ||
344 | if (NULL == keywords[max]) | 344 | if (NULL == keywords[max]) |
345 | goto CLEANUP; | 345 | goto CLEANUP; |
346 | GNUNET_assert(0 == max); | 346 | GNUNET_assert (0 == max); |
347 | GNUNET_free(dup); | 347 | GNUNET_free (dup); |
348 | ret = GNUNET_new(struct GNUNET_FS_Uri); | 348 | ret = GNUNET_new (struct GNUNET_FS_Uri); |
349 | ret->type = GNUNET_FS_URI_KSK; | 349 | ret->type = GNUNET_FS_URI_KSK; |
350 | ret->data.ksk.keywordCount = iret; | 350 | ret->data.ksk.keywordCount = iret; |
351 | ret->data.ksk.keywords = keywords; | 351 | ret->data.ksk.keywords = keywords; |
352 | return ret; | 352 | return ret; |
353 | CLEANUP: | 353 | CLEANUP: |
354 | for (i = 0; i < max; i++) | 354 | for (i = 0; i < max; i++) |
355 | GNUNET_free_non_null(keywords[i]); | 355 | GNUNET_free_non_null (keywords[i]); |
356 | GNUNET_free(keywords); | 356 | GNUNET_free (keywords); |
357 | GNUNET_free(dup); | 357 | GNUNET_free (dup); |
358 | return NULL; | 358 | return NULL; |
359 | } | 359 | } |
360 | 360 | ||
@@ -369,31 +369,31 @@ CLEANUP: | |||
369 | * @return NULL on error, SKS URI otherwise | 369 | * @return NULL on error, SKS URI otherwise |
370 | */ | 370 | */ |
371 | static struct GNUNET_FS_Uri * | 371 | static struct GNUNET_FS_Uri * |
372 | uri_sks_parse(const char *s, char **emsg) | 372 | uri_sks_parse (const char *s, char **emsg) |
373 | { | 373 | { |
374 | struct GNUNET_FS_Uri *ret; | 374 | struct GNUNET_FS_Uri *ret; |
375 | struct GNUNET_CRYPTO_EcdsaPublicKey ns; | 375 | struct GNUNET_CRYPTO_EcdsaPublicKey ns; |
376 | size_t pos; | 376 | size_t pos; |
377 | char *end; | 377 | char *end; |
378 | 378 | ||
379 | pos = strlen(GNUNET_FS_URI_SKS_PREFIX); | 379 | pos = strlen (GNUNET_FS_URI_SKS_PREFIX); |
380 | if ((strlen(s) <= pos) || (0 != strncmp(s, GNUNET_FS_URI_SKS_PREFIX, pos))) | 380 | if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) |
381 | return NULL; /* not an SKS URI */ | 381 | return NULL; /* not an SKS URI */ |
382 | end = strchr(&s[pos], '/'); | 382 | end = strchr (&s[pos], '/'); |
383 | if ((NULL == end) || | 383 | if ((NULL == end) || |
384 | (GNUNET_OK != GNUNET_STRINGS_string_to_data(&s[pos], | 384 | (GNUNET_OK != GNUNET_STRINGS_string_to_data (&s[pos], |
385 | end - &s[pos], | 385 | end - &s[pos], |
386 | &ns, | 386 | &ns, |
387 | sizeof(ns)))) | 387 | sizeof(ns)))) |
388 | { | 388 | { |
389 | *emsg = GNUNET_strdup(_("Malformed SKS URI (wrong syntax)")); | 389 | *emsg = GNUNET_strdup (_ ("Malformed SKS URI (wrong syntax)")); |
390 | return NULL; /* malformed */ | 390 | return NULL; /* malformed */ |
391 | } | 391 | } |
392 | end++; /* skip over '/' */ | 392 | end++; /* skip over '/' */ |
393 | ret = GNUNET_new(struct GNUNET_FS_Uri); | 393 | ret = GNUNET_new (struct GNUNET_FS_Uri); |
394 | ret->type = GNUNET_FS_URI_SKS; | 394 | ret->type = GNUNET_FS_URI_SKS; |
395 | ret->data.sks.ns = ns; | 395 | ret->data.sks.ns = ns; |
396 | ret->data.sks.identifier = GNUNET_strdup(end); | 396 | ret->data.sks.identifier = GNUNET_strdup (end); |
397 | return ret; | 397 | return ret; |
398 | } | 398 | } |
399 | 399 | ||
@@ -408,7 +408,7 @@ uri_sks_parse(const char *s, char **emsg) | |||
408 | * @return NULL on error, CHK URI otherwise | 408 | * @return NULL on error, CHK URI otherwise |
409 | */ | 409 | */ |
410 | static struct GNUNET_FS_Uri * | 410 | static struct GNUNET_FS_Uri * |
411 | uri_chk_parse(const char *s, char **emsg) | 411 | uri_chk_parse (const char *s, char **emsg) |
412 | { | 412 | { |
413 | struct GNUNET_FS_Uri *ret; | 413 | struct GNUNET_FS_Uri *ret; |
414 | struct FileIdentifier fi; | 414 | struct FileIdentifier fi; |
@@ -418,36 +418,36 @@ uri_chk_parse(const char *s, char **emsg) | |||
418 | char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 418 | char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
419 | char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 419 | char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
420 | 420 | ||
421 | slen = strlen(s); | 421 | slen = strlen (s); |
422 | pos = strlen(GNUNET_FS_URI_CHK_PREFIX); | 422 | pos = strlen (GNUNET_FS_URI_CHK_PREFIX); |
423 | if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 423 | if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
424 | (0 != strncmp(s, GNUNET_FS_URI_CHK_PREFIX, pos))) | 424 | (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos))) |
425 | return NULL; /* not a CHK URI */ | 425 | return NULL; /* not a CHK URI */ |
426 | if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | 426 | if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || |
427 | (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) | 427 | (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) |
428 | { | 428 | { |
429 | *emsg = GNUNET_strdup(_("Malformed CHK URI (wrong syntax)")); | 429 | *emsg = GNUNET_strdup (_ ("Malformed CHK URI (wrong syntax)")); |
430 | return NULL; | 430 | return NULL; |
431 | } | 431 | } |
432 | GNUNET_memcpy(h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | 432 | GNUNET_memcpy (h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); |
433 | h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 433 | h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
434 | GNUNET_memcpy(h2, | 434 | GNUNET_memcpy (h2, |
435 | &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], | 435 | &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], |
436 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | 436 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); |
437 | h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 437 | h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
438 | 438 | ||
439 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h1, &fi.chk.key)) || | 439 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) || |
440 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h2, &fi.chk.query)) || | 440 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) || |
441 | (1 != | 441 | (1 != |
442 | sscanf(&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 442 | sscanf (&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
443 | "%llu", | 443 | "%llu", |
444 | &flen))) | 444 | &flen))) |
445 | { | 445 | { |
446 | *emsg = GNUNET_strdup(_("Malformed CHK URI (failed to decode CHK)")); | 446 | *emsg = GNUNET_strdup (_ ("Malformed CHK URI (failed to decode CHK)")); |
447 | return NULL; | 447 | return NULL; |
448 | } | 448 | } |
449 | fi.file_length = GNUNET_htonll(flen); | 449 | fi.file_length = GNUNET_htonll (flen); |
450 | ret = GNUNET_new(struct GNUNET_FS_Uri); | 450 | ret = GNUNET_new (struct GNUNET_FS_Uri); |
451 | ret->type = GNUNET_FS_URI_CHK; | 451 | ret->type = GNUNET_FS_URI_CHK; |
452 | ret->data.chk = fi; | 452 | ret->data.chk = fi; |
453 | return ret; | 453 | return ret; |
@@ -460,7 +460,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
460 | * assembled in memory to create or verify the signature of a location | 460 | * assembled in memory to create or verify the signature of a location |
461 | * URI. | 461 | * URI. |
462 | */ | 462 | */ |
463 | struct LocUriAssembly { | 463 | struct LocUriAssembly |
464 | { | ||
464 | /** | 465 | /** |
465 | * What is being signed (rest of this struct). | 466 | * What is being signed (rest of this struct). |
466 | */ | 467 | */ |
@@ -497,7 +498,7 @@ GNUNET_NETWORK_STRUCT_END | |||
497 | * @return NULL on error, valid LOC URI otherwise | 498 | * @return NULL on error, valid LOC URI otherwise |
498 | */ | 499 | */ |
499 | static struct GNUNET_FS_Uri * | 500 | static struct GNUNET_FS_Uri * |
500 | uri_loc_parse(const char *s, char **emsg) | 501 | uri_loc_parse (const char *s, char **emsg) |
501 | { | 502 | { |
502 | struct GNUNET_FS_Uri *uri; | 503 | struct GNUNET_FS_Uri *uri; |
503 | char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 504 | char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
@@ -511,113 +512,113 @@ uri_loc_parse(const char *s, char **emsg) | |||
511 | struct LocUriAssembly ass; | 512 | struct LocUriAssembly ass; |
512 | size_t slen; | 513 | size_t slen; |
513 | 514 | ||
514 | slen = strlen(s); | 515 | slen = strlen (s); |
515 | pos = strlen(GNUNET_FS_URI_LOC_PREFIX); | 516 | pos = strlen (GNUNET_FS_URI_LOC_PREFIX); |
516 | if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 517 | if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
517 | (0 != strncmp(s, GNUNET_FS_URI_LOC_PREFIX, pos))) | 518 | (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos))) |
518 | return NULL; /* not a LOC URI */ | 519 | return NULL; /* not a LOC URI */ |
519 | if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | 520 | if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || |
520 | (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) | 521 | (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) |
521 | { | 522 | { |
522 | *emsg = GNUNET_strdup(_("LOC URI malformed (wrong syntax)")); | 523 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (wrong syntax)")); |
523 | return NULL; | 524 | return NULL; |
524 | } | 525 | } |
525 | GNUNET_memcpy(h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | 526 | GNUNET_memcpy (h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); |
526 | h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 527 | h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
527 | GNUNET_memcpy(h2, | 528 | GNUNET_memcpy (h2, |
528 | &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], | 529 | &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], |
529 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | 530 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); |
530 | h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 531 | h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
531 | 532 | ||
532 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h1, &ass.fi.chk.key)) || | 533 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) || |
533 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h2, &ass.fi.chk.query)) || | 534 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) || |
534 | (1 != | 535 | (1 != |
535 | sscanf(&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 536 | sscanf (&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
536 | "%llu", | 537 | "%llu", |
537 | &flen))) | 538 | &flen))) |
538 | { | 539 | { |
539 | *emsg = GNUNET_strdup(_("LOC URI malformed (no CHK)")); | 540 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (no CHK)")); |
540 | return NULL; | 541 | return NULL; |
541 | } | 542 | } |
542 | ass.fi.file_length = GNUNET_htonll(flen); | 543 | ass.fi.file_length = GNUNET_htonll (flen); |
543 | 544 | ||
544 | npos = pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; | 545 | npos = pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; |
545 | while ((s[npos] != '\0') && (s[npos] != '.')) | 546 | while ((s[npos] != '\0') && (s[npos] != '.')) |
546 | npos++; | 547 | npos++; |
547 | if (s[npos] == '\0') | 548 | if (s[npos] == '\0') |
548 | { | 549 | { |
549 | *emsg = GNUNET_strdup(_("LOC URI malformed (missing LOC)")); | 550 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (missing LOC)")); |
550 | goto ERR; | 551 | goto ERR; |
551 | } | 552 | } |
552 | npos++; | 553 | npos++; |
553 | if ((strlen(&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || | 554 | if ((strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || |
554 | ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH])) | 555 | ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH])) |
555 | { | 556 | { |
556 | *emsg = | 557 | *emsg = |
557 | GNUNET_strdup(_("LOC URI malformed (wrong syntax for public key)")); | 558 | GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for public key)")); |
558 | } | 559 | } |
559 | if ( | 560 | if ( |
560 | GNUNET_OK != | 561 | GNUNET_OK != |
561 | GNUNET_CRYPTO_eddsa_public_key_from_string(&s[npos], | 562 | GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], |
562 | GNUNET_CRYPTO_PKEY_ASCII_LENGTH, | 563 | GNUNET_CRYPTO_PKEY_ASCII_LENGTH, |
563 | &ass.peer.public_key)) | 564 | &ass.peer.public_key)) |
564 | { | 565 | { |
565 | *emsg = | 566 | *emsg = |
566 | GNUNET_strdup(_("LOC URI malformed (could not decode public key)")); | 567 | GNUNET_strdup (_ ("LOC URI malformed (could not decode public key)")); |
567 | goto ERR; | 568 | goto ERR; |
568 | } | 569 | } |
569 | npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; | 570 | npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; |
570 | if (s[npos++] != '.') | 571 | if (s[npos++] != '.') |
571 | { | 572 | { |
572 | *emsg = GNUNET_strdup(_("LOC URI malformed (could not find signature)")); | 573 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (could not find signature)")); |
573 | goto ERR; | 574 | goto ERR; |
574 | } | 575 | } |
575 | if ((strlen(&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || | 576 | if ((strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || |
576 | ('.' != s[npos + SIGNATURE_ASCII_LENGTH])) | 577 | ('.' != s[npos + SIGNATURE_ASCII_LENGTH])) |
577 | { | 578 | { |
578 | *emsg = | 579 | *emsg = |
579 | GNUNET_strdup(_("LOC URI malformed (wrong syntax for signature)")); | 580 | GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for signature)")); |
580 | goto ERR; | 581 | goto ERR; |
581 | } | 582 | } |
582 | if (GNUNET_OK != | 583 | if (GNUNET_OK != |
583 | GNUNET_STRINGS_string_to_data(&s[npos], | 584 | GNUNET_STRINGS_string_to_data (&s[npos], |
584 | SIGNATURE_ASCII_LENGTH, | 585 | SIGNATURE_ASCII_LENGTH, |
585 | &sig, | 586 | &sig, |
586 | sizeof( | 587 | sizeof( |
587 | struct GNUNET_CRYPTO_EddsaSignature))) | 588 | struct GNUNET_CRYPTO_EddsaSignature))) |
588 | { | 589 | { |
589 | *emsg = | 590 | *emsg = |
590 | GNUNET_strdup(_("LOC URI malformed (could not decode signature)")); | 591 | GNUNET_strdup (_ ("LOC URI malformed (could not decode signature)")); |
591 | goto ERR; | 592 | goto ERR; |
592 | } | 593 | } |
593 | npos += SIGNATURE_ASCII_LENGTH; | 594 | npos += SIGNATURE_ASCII_LENGTH; |
594 | if (s[npos++] != '.') | 595 | if (s[npos++] != '.') |
595 | { | 596 | { |
596 | *emsg = GNUNET_strdup( | 597 | *emsg = GNUNET_strdup ( |
597 | _("LOC URI malformed (wrong syntax for expiration time)")); | 598 | _ ("LOC URI malformed (wrong syntax for expiration time)")); |
598 | goto ERR; | 599 | goto ERR; |
599 | } | 600 | } |
600 | if (1 != sscanf(&s[npos], "%llu", &exptime)) | 601 | if (1 != sscanf (&s[npos], "%llu", &exptime)) |
601 | { | 602 | { |
602 | *emsg = | 603 | *emsg = |
603 | GNUNET_strdup(_("LOC URI malformed (could not parse expiration time)")); | 604 | GNUNET_strdup (_ ("LOC URI malformed (could not parse expiration time)")); |
604 | goto ERR; | 605 | goto ERR; |
605 | } | 606 | } |
606 | ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); | 607 | ass.purpose.size = htonl (sizeof(struct LocUriAssembly)); |
607 | ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 608 | ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
608 | et.abs_value_us = exptime * 1000LL * 1000LL; | 609 | et.abs_value_us = exptime * 1000LL * 1000LL; |
609 | ass.exptime = GNUNET_TIME_absolute_hton(et); | 610 | ass.exptime = GNUNET_TIME_absolute_hton (et); |
610 | if (GNUNET_OK != | 611 | if (GNUNET_OK != |
611 | GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, | 612 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, |
612 | &ass.purpose, | 613 | &ass.purpose, |
613 | &sig, | 614 | &sig, |
614 | &ass.peer.public_key)) | 615 | &ass.peer.public_key)) |
615 | { | 616 | { |
616 | *emsg = | 617 | *emsg = |
617 | GNUNET_strdup(_("LOC URI malformed (signature failed validation)")); | 618 | GNUNET_strdup (_ ("LOC URI malformed (signature failed validation)")); |
618 | goto ERR; | 619 | goto ERR; |
619 | } | 620 | } |
620 | uri = GNUNET_new(struct GNUNET_FS_Uri); | 621 | uri = GNUNET_new (struct GNUNET_FS_Uri); |
621 | uri->type = GNUNET_FS_URI_LOC; | 622 | uri->type = GNUNET_FS_URI_LOC; |
622 | uri->data.loc.fi = ass.fi; | 623 | uri->data.loc.fi = ass.fi; |
623 | uri->data.loc.peer = ass.peer; | 624 | uri->data.loc.peer = ass.peer; |
@@ -638,30 +639,30 @@ ERR: | |||
638 | * @return NULL on error | 639 | * @return NULL on error |
639 | */ | 640 | */ |
640 | struct GNUNET_FS_Uri * | 641 | struct GNUNET_FS_Uri * |
641 | GNUNET_FS_uri_parse(const char *uri, char **emsg) | 642 | GNUNET_FS_uri_parse (const char *uri, char **emsg) |
642 | { | 643 | { |
643 | struct GNUNET_FS_Uri *ret; | 644 | struct GNUNET_FS_Uri *ret; |
644 | char *msg; | 645 | char *msg; |
645 | 646 | ||
646 | if (NULL == uri) | 647 | if (NULL == uri) |
647 | { | 648 | { |
648 | GNUNET_break(0); | 649 | GNUNET_break (0); |
649 | if (NULL != emsg) | 650 | if (NULL != emsg) |
650 | *emsg = GNUNET_strdup(_("invalid argument")); | 651 | *emsg = GNUNET_strdup (_ ("invalid argument")); |
651 | return NULL; | 652 | return NULL; |
652 | } | 653 | } |
653 | if (NULL == emsg) | 654 | if (NULL == emsg) |
654 | emsg = &msg; | 655 | emsg = &msg; |
655 | *emsg = NULL; | 656 | *emsg = NULL; |
656 | if ((NULL != (ret = uri_chk_parse(uri, emsg))) || | 657 | if ((NULL != (ret = uri_chk_parse (uri, emsg))) || |
657 | (NULL != (ret = uri_ksk_parse(uri, emsg))) || | 658 | (NULL != (ret = uri_ksk_parse (uri, emsg))) || |
658 | (NULL != (ret = uri_sks_parse(uri, emsg))) || | 659 | (NULL != (ret = uri_sks_parse (uri, emsg))) || |
659 | (NULL != (ret = uri_loc_parse(uri, emsg)))) | 660 | (NULL != (ret = uri_loc_parse (uri, emsg)))) |
660 | return ret; | 661 | return ret; |
661 | if (NULL == *emsg) | 662 | if (NULL == *emsg) |
662 | *emsg = GNUNET_strdup(_("Unrecognized URI type")); | 663 | *emsg = GNUNET_strdup (_ ("Unrecognized URI type")); |
663 | if (emsg == &msg) | 664 | if (emsg == &msg) |
664 | GNUNET_free(msg); | 665 | GNUNET_free (msg); |
665 | return NULL; | 666 | return NULL; |
666 | } | 667 | } |
667 | 668 | ||
@@ -672,30 +673,30 @@ GNUNET_FS_uri_parse(const char *uri, char **emsg) | |||
672 | * @param uri uri to free | 673 | * @param uri uri to free |
673 | */ | 674 | */ |
674 | void | 675 | void |
675 | GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri) | 676 | GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) |
676 | { | 677 | { |
677 | unsigned int i; | 678 | unsigned int i; |
678 | 679 | ||
679 | switch (uri->type) | 680 | switch (uri->type) |
680 | { | 681 | { |
681 | case GNUNET_FS_URI_KSK: | 682 | case GNUNET_FS_URI_KSK: |
682 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 683 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
683 | GNUNET_free(uri->data.ksk.keywords[i]); | 684 | GNUNET_free (uri->data.ksk.keywords[i]); |
684 | GNUNET_array_grow(uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0); | 685 | GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0); |
685 | break; | 686 | break; |
686 | 687 | ||
687 | case GNUNET_FS_URI_SKS: | 688 | case GNUNET_FS_URI_SKS: |
688 | GNUNET_free(uri->data.sks.identifier); | 689 | GNUNET_free (uri->data.sks.identifier); |
689 | break; | 690 | break; |
690 | 691 | ||
691 | case GNUNET_FS_URI_LOC: | 692 | case GNUNET_FS_URI_LOC: |
692 | break; | 693 | break; |
693 | 694 | ||
694 | default: | 695 | default: |
695 | /* do nothing */ | 696 | /* do nothing */ |
696 | break; | 697 | break; |
697 | } | 698 | } |
698 | GNUNET_free(uri); | 699 | GNUNET_free (uri); |
699 | } | 700 | } |
700 | 701 | ||
701 | 702 | ||
@@ -706,7 +707,7 @@ GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri) | |||
706 | * @return 0 if this is not a keyword URI | 707 | * @return 0 if this is not a keyword URI |
707 | */ | 708 | */ |
708 | unsigned int | 709 | unsigned int |
709 | GNUNET_FS_uri_ksk_get_keyword_count(const struct GNUNET_FS_Uri *uri) | 710 | GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri) |
710 | { | 711 | { |
711 | if (uri->type != GNUNET_FS_URI_KSK) | 712 | if (uri->type != GNUNET_FS_URI_KSK) |
712 | return 0; | 713 | return 0; |
@@ -724,9 +725,9 @@ GNUNET_FS_uri_ksk_get_keyword_count(const struct GNUNET_FS_Uri *uri) | |||
724 | * keywords iterated over until iterator aborted | 725 | * keywords iterated over until iterator aborted |
725 | */ | 726 | */ |
726 | int | 727 | int |
727 | GNUNET_FS_uri_ksk_get_keywords(const struct GNUNET_FS_Uri *uri, | 728 | GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, |
728 | GNUNET_FS_KeywordIterator iterator, | 729 | GNUNET_FS_KeywordIterator iterator, |
729 | void *iterator_cls) | 730 | void *iterator_cls) |
730 | { | 731 | { |
731 | unsigned int i; | 732 | unsigned int i; |
732 | char *keyword; | 733 | char *keyword; |
@@ -736,13 +737,13 @@ GNUNET_FS_uri_ksk_get_keywords(const struct GNUNET_FS_Uri *uri, | |||
736 | if (NULL == iterator) | 737 | if (NULL == iterator) |
737 | return uri->data.ksk.keywordCount; | 738 | return uri->data.ksk.keywordCount; |
738 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 739 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
739 | { | 740 | { |
740 | keyword = uri->data.ksk.keywords[i]; | 741 | keyword = uri->data.ksk.keywords[i]; |
741 | /* first character of keyword indicates | 742 | /* first character of keyword indicates |
742 | * if it is mandatory or not */ | 743 | * if it is mandatory or not */ |
743 | if (GNUNET_OK != iterator(iterator_cls, &keyword[1], keyword[0] == '+')) | 744 | if (GNUNET_OK != iterator (iterator_cls, &keyword[1],(keyword[0] == '+') )) |
744 | return i; | 745 | return i; |
745 | } | 746 | } |
746 | return i; | 747 | return i; |
747 | } | 748 | } |
748 | 749 | ||
@@ -756,23 +757,23 @@ GNUNET_FS_uri_ksk_get_keywords(const struct GNUNET_FS_Uri *uri, | |||
756 | * @param is_mandatory is this keyword mandatory? | 757 | * @param is_mandatory is this keyword mandatory? |
757 | */ | 758 | */ |
758 | void | 759 | void |
759 | GNUNET_FS_uri_ksk_add_keyword(struct GNUNET_FS_Uri *uri, | 760 | GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, |
760 | const char *keyword, | 761 | const char *keyword, |
761 | int is_mandatory) | 762 | int is_mandatory) |
762 | { | 763 | { |
763 | unsigned int i; | 764 | unsigned int i; |
764 | const char *old; | 765 | const char *old; |
765 | char *n; | 766 | char *n; |
766 | 767 | ||
767 | GNUNET_assert(uri->type == GNUNET_FS_URI_KSK); | 768 | GNUNET_assert (uri->type == GNUNET_FS_URI_KSK); |
768 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 769 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
769 | { | 770 | { |
770 | old = uri->data.ksk.keywords[i]; | 771 | old = uri->data.ksk.keywords[i]; |
771 | if (0 == strcmp(&old[1], keyword)) | 772 | if (0 == strcmp (&old[1], keyword)) |
772 | return; | 773 | return; |
773 | } | 774 | } |
774 | GNUNET_asprintf(&n, is_mandatory ? "+%s" : " %s", keyword); | 775 | GNUNET_asprintf (&n, is_mandatory ? "+%s" : " %s", keyword); |
775 | GNUNET_array_append(uri->data.ksk.keywords, uri->data.ksk.keywordCount, n); | 776 | GNUNET_array_append (uri->data.ksk.keywords, uri->data.ksk.keywordCount, n); |
776 | } | 777 | } |
777 | 778 | ||
778 | 779 | ||
@@ -784,27 +785,27 @@ GNUNET_FS_uri_ksk_add_keyword(struct GNUNET_FS_Uri *uri, | |||
784 | * @param keyword keyword to add | 785 | * @param keyword keyword to add |
785 | */ | 786 | */ |
786 | void | 787 | void |
787 | GNUNET_FS_uri_ksk_remove_keyword(struct GNUNET_FS_Uri *uri, | 788 | GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, |
788 | const char *keyword) | 789 | const char *keyword) |
789 | { | 790 | { |
790 | unsigned int i; | 791 | unsigned int i; |
791 | char *old; | 792 | char *old; |
792 | 793 | ||
793 | GNUNET_assert(uri->type == GNUNET_FS_URI_KSK); | 794 | GNUNET_assert (uri->type == GNUNET_FS_URI_KSK); |
794 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 795 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
796 | { | ||
797 | old = uri->data.ksk.keywords[i]; | ||
798 | if (0 == strcmp (&old[1], keyword)) | ||
795 | { | 799 | { |
796 | old = uri->data.ksk.keywords[i]; | 800 | uri->data.ksk.keywords[i] = |
797 | if (0 == strcmp(&old[1], keyword)) | 801 | uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; |
798 | { | 802 | GNUNET_array_grow (uri->data.ksk.keywords, |
799 | uri->data.ksk.keywords[i] = | 803 | uri->data.ksk.keywordCount, |
800 | uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; | 804 | uri->data.ksk.keywordCount - 1); |
801 | GNUNET_array_grow(uri->data.ksk.keywords, | 805 | GNUNET_free (old); |
802 | uri->data.ksk.keywordCount, | 806 | return; |
803 | uri->data.ksk.keywordCount - 1); | ||
804 | GNUNET_free(old); | ||
805 | return; | ||
806 | } | ||
807 | } | 807 | } |
808 | } | ||
808 | } | 809 | } |
809 | 810 | ||
810 | 811 | ||
@@ -816,8 +817,8 @@ GNUNET_FS_uri_ksk_remove_keyword(struct GNUNET_FS_Uri *uri, | |||
816 | * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK | 817 | * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK |
817 | */ | 818 | */ |
818 | int | 819 | int |
819 | GNUNET_FS_uri_loc_get_peer_identity(const struct GNUNET_FS_Uri *uri, | 820 | GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, |
820 | struct GNUNET_PeerIdentity *peer) | 821 | struct GNUNET_PeerIdentity *peer) |
821 | { | 822 | { |
822 | if (uri->type != GNUNET_FS_URI_LOC) | 823 | if (uri->type != GNUNET_FS_URI_LOC) |
823 | return GNUNET_SYSERR; | 824 | return GNUNET_SYSERR; |
@@ -833,9 +834,9 @@ GNUNET_FS_uri_loc_get_peer_identity(const struct GNUNET_FS_Uri *uri, | |||
833 | * @return expiration time of the URI | 834 | * @return expiration time of the URI |
834 | */ | 835 | */ |
835 | struct GNUNET_TIME_Absolute | 836 | struct GNUNET_TIME_Absolute |
836 | GNUNET_FS_uri_loc_get_expiration(const struct GNUNET_FS_Uri *uri) | 837 | GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri) |
837 | { | 838 | { |
838 | GNUNET_assert(uri->type == GNUNET_FS_URI_LOC); | 839 | GNUNET_assert (uri->type == GNUNET_FS_URI_LOC); |
839 | return uri->data.loc.expirationTime; | 840 | return uri->data.loc.expirationTime; |
840 | } | 841 | } |
841 | 842 | ||
@@ -847,13 +848,13 @@ GNUNET_FS_uri_loc_get_expiration(const struct GNUNET_FS_Uri *uri) | |||
847 | * @return NULL if argument is not a location URI | 848 | * @return NULL if argument is not a location URI |
848 | */ | 849 | */ |
849 | struct GNUNET_FS_Uri * | 850 | struct GNUNET_FS_Uri * |
850 | GNUNET_FS_uri_loc_get_uri(const struct GNUNET_FS_Uri *uri) | 851 | GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri) |
851 | { | 852 | { |
852 | struct GNUNET_FS_Uri *ret; | 853 | struct GNUNET_FS_Uri *ret; |
853 | 854 | ||
854 | if (uri->type != GNUNET_FS_URI_LOC) | 855 | if (uri->type != GNUNET_FS_URI_LOC) |
855 | return NULL; | 856 | return NULL; |
856 | ret = GNUNET_new(struct GNUNET_FS_Uri); | 857 | ret = GNUNET_new (struct GNUNET_FS_Uri); |
857 | ret->type = GNUNET_FS_URI_CHK; | 858 | ret->type = GNUNET_FS_URI_CHK; |
858 | ret->data.chk = uri->data.loc.fi; | 859 | ret->data.chk = uri->data.loc.fi; |
859 | return ret; | 860 | return ret; |
@@ -873,9 +874,9 @@ GNUNET_FS_uri_loc_get_uri(const struct GNUNET_FS_Uri *uri) | |||
873 | * @return the location URI, NULL on error | 874 | * @return the location URI, NULL on error |
874 | */ | 875 | */ |
875 | struct GNUNET_FS_Uri * | 876 | struct GNUNET_FS_Uri * |
876 | GNUNET_FS_uri_loc_create(const struct GNUNET_FS_Uri *base_uri, | 877 | GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, |
877 | const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key, | 878 | const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key, |
878 | struct GNUNET_TIME_Absolute expiration_time) | 879 | struct GNUNET_TIME_Absolute expiration_time) |
879 | { | 880 | { |
880 | struct GNUNET_FS_Uri *uri; | 881 | struct GNUNET_FS_Uri *uri; |
881 | struct GNUNET_CRYPTO_EddsaPublicKey my_public_key; | 882 | struct GNUNET_CRYPTO_EddsaPublicKey my_public_key; |
@@ -886,21 +887,21 @@ GNUNET_FS_uri_loc_create(const struct GNUNET_FS_Uri *base_uri, | |||
886 | return NULL; | 887 | return NULL; |
887 | /* we round expiration time to full seconds for SKS URIs */ | 888 | /* we round expiration time to full seconds for SKS URIs */ |
888 | et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; | 889 | et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; |
889 | GNUNET_CRYPTO_eddsa_key_get_public(sign_key, &my_public_key); | 890 | GNUNET_CRYPTO_eddsa_key_get_public (sign_key, &my_public_key); |
890 | ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); | 891 | ass.purpose.size = htonl (sizeof(struct LocUriAssembly)); |
891 | ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 892 | ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
892 | ass.exptime = GNUNET_TIME_absolute_hton(et); | 893 | ass.exptime = GNUNET_TIME_absolute_hton (et); |
893 | ass.fi = base_uri->data.chk; | 894 | ass.fi = base_uri->data.chk; |
894 | ass.peer.public_key = my_public_key; | 895 | ass.peer.public_key = my_public_key; |
895 | uri = GNUNET_new(struct GNUNET_FS_Uri); | 896 | uri = GNUNET_new (struct GNUNET_FS_Uri); |
896 | uri->type = GNUNET_FS_URI_LOC; | 897 | uri->type = GNUNET_FS_URI_LOC; |
897 | uri->data.loc.fi = base_uri->data.chk; | 898 | uri->data.loc.fi = base_uri->data.chk; |
898 | uri->data.loc.expirationTime = et; | 899 | uri->data.loc.expirationTime = et; |
899 | uri->data.loc.peer.public_key = my_public_key; | 900 | uri->data.loc.peer.public_key = my_public_key; |
900 | GNUNET_assert(GNUNET_OK == | 901 | GNUNET_assert (GNUNET_OK == |
901 | GNUNET_CRYPTO_eddsa_sign(sign_key, | 902 | GNUNET_CRYPTO_eddsa_sign (sign_key, |
902 | &ass.purpose, | 903 | &ass.purpose, |
903 | &uri->data.loc.contentSignature)); | 904 | &uri->data.loc.contentSignature)); |
904 | return uri; | 905 | return uri; |
905 | } | 906 | } |
906 | 907 | ||
@@ -913,15 +914,15 @@ GNUNET_FS_uri_loc_create(const struct GNUNET_FS_Uri *base_uri, | |||
913 | * @return an FS URI for the given namespace and identifier | 914 | * @return an FS URI for the given namespace and identifier |
914 | */ | 915 | */ |
915 | struct GNUNET_FS_Uri * | 916 | struct GNUNET_FS_Uri * |
916 | GNUNET_FS_uri_sks_create(const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, | 917 | GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, |
917 | const char *id) | 918 | const char *id) |
918 | { | 919 | { |
919 | struct GNUNET_FS_Uri *ns_uri; | 920 | struct GNUNET_FS_Uri *ns_uri; |
920 | 921 | ||
921 | ns_uri = GNUNET_new(struct GNUNET_FS_Uri); | 922 | ns_uri = GNUNET_new (struct GNUNET_FS_Uri); |
922 | ns_uri->type = GNUNET_FS_URI_SKS; | 923 | ns_uri->type = GNUNET_FS_URI_SKS; |
923 | ns_uri->data.sks.ns = *ns; | 924 | ns_uri->data.sks.ns = *ns; |
924 | ns_uri->data.sks.identifier = GNUNET_strdup(id); | 925 | ns_uri->data.sks.identifier = GNUNET_strdup (id); |
925 | return ns_uri; | 926 | return ns_uri; |
926 | } | 927 | } |
927 | 928 | ||
@@ -936,8 +937,8 @@ GNUNET_FS_uri_sks_create(const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, | |||
936 | * @return merged URI, NULL on error | 937 | * @return merged URI, NULL on error |
937 | */ | 938 | */ |
938 | struct GNUNET_FS_Uri * | 939 | struct GNUNET_FS_Uri * |
939 | GNUNET_FS_uri_ksk_merge(const struct GNUNET_FS_Uri *u1, | 940 | GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, |
940 | const struct GNUNET_FS_Uri *u2) | 941 | const struct GNUNET_FS_Uri *u2) |
941 | { | 942 | { |
942 | struct GNUNET_FS_Uri *ret; | 943 | struct GNUNET_FS_Uri *ret; |
943 | unsigned int kc; | 944 | unsigned int kc; |
@@ -950,34 +951,34 @@ GNUNET_FS_uri_ksk_merge(const struct GNUNET_FS_Uri *u1, | |||
950 | if ((u1 == NULL) && (u2 == NULL)) | 951 | if ((u1 == NULL) && (u2 == NULL)) |
951 | return NULL; | 952 | return NULL; |
952 | if (u1 == NULL) | 953 | if (u1 == NULL) |
953 | return GNUNET_FS_uri_dup(u2); | 954 | return GNUNET_FS_uri_dup (u2); |
954 | if (u2 == NULL) | 955 | if (u2 == NULL) |
955 | return GNUNET_FS_uri_dup(u1); | 956 | return GNUNET_FS_uri_dup (u1); |
956 | if ((u1->type != GNUNET_FS_URI_KSK) || (u2->type != GNUNET_FS_URI_KSK)) | 957 | if ((u1->type != GNUNET_FS_URI_KSK) || (u2->type != GNUNET_FS_URI_KSK)) |
957 | { | 958 | { |
958 | GNUNET_break(0); | 959 | GNUNET_break (0); |
959 | return NULL; | 960 | return NULL; |
960 | } | 961 | } |
961 | kc = u1->data.ksk.keywordCount; | 962 | kc = u1->data.ksk.keywordCount; |
962 | kl = GNUNET_new_array(kc + u2->data.ksk.keywordCount, char *); | 963 | kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, char *); |
963 | for (i = 0; i < u1->data.ksk.keywordCount; i++) | 964 | for (i = 0; i < u1->data.ksk.keywordCount; i++) |
964 | kl[i] = GNUNET_strdup(u1->data.ksk.keywords[i]); | 965 | kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); |
965 | for (i = 0; i < u2->data.ksk.keywordCount; i++) | 966 | for (i = 0; i < u2->data.ksk.keywordCount; i++) |
966 | { | 967 | { |
967 | kp = u2->data.ksk.keywords[i]; | 968 | kp = u2->data.ksk.keywords[i]; |
968 | found = 0; | 969 | found = 0; |
969 | for (j = 0; j < u1->data.ksk.keywordCount; j++) | 970 | for (j = 0; j < u1->data.ksk.keywordCount; j++) |
970 | if (0 == strcmp(kp + 1, kl[j] + 1)) | 971 | if (0 == strcmp (kp + 1, kl[j] + 1)) |
971 | { | 972 | { |
972 | found = 1; | 973 | found = 1; |
973 | if (kp[0] == '+') | 974 | if (kp[0] == '+') |
974 | kl[j][0] = '+'; | 975 | kl[j][0] = '+'; |
975 | break; | 976 | break; |
976 | } | 977 | } |
977 | if (0 == found) | 978 | if (0 == found) |
978 | kl[kc++] = GNUNET_strdup(kp); | 979 | kl[kc++] = GNUNET_strdup (kp); |
979 | } | 980 | } |
980 | ret = GNUNET_new(struct GNUNET_FS_Uri); | 981 | ret = GNUNET_new (struct GNUNET_FS_Uri); |
981 | ret->type = GNUNET_FS_URI_KSK; | 982 | ret->type = GNUNET_FS_URI_KSK; |
982 | ret->data.ksk.keywordCount = kc; | 983 | ret->data.ksk.keywordCount = kc; |
983 | ret->data.ksk.keywords = kl; | 984 | ret->data.ksk.keywords = kl; |
@@ -992,46 +993,46 @@ GNUNET_FS_uri_ksk_merge(const struct GNUNET_FS_Uri *u1, | |||
992 | * @return copy of the URI | 993 | * @return copy of the URI |
993 | */ | 994 | */ |
994 | struct GNUNET_FS_Uri * | 995 | struct GNUNET_FS_Uri * |
995 | GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri) | 996 | GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) |
996 | { | 997 | { |
997 | struct GNUNET_FS_Uri *ret; | 998 | struct GNUNET_FS_Uri *ret; |
998 | unsigned int i; | 999 | unsigned int i; |
999 | 1000 | ||
1000 | if (uri == NULL) | 1001 | if (uri == NULL) |
1001 | return NULL; | 1002 | return NULL; |
1002 | ret = GNUNET_new(struct GNUNET_FS_Uri); | 1003 | ret = GNUNET_new (struct GNUNET_FS_Uri); |
1003 | GNUNET_memcpy(ret, uri, sizeof(struct GNUNET_FS_Uri)); | 1004 | GNUNET_memcpy (ret, uri, sizeof(struct GNUNET_FS_Uri)); |
1004 | switch (ret->type) | 1005 | switch (ret->type) |
1006 | { | ||
1007 | case GNUNET_FS_URI_KSK: | ||
1008 | if (ret->data.ksk.keywordCount >= | ||
1009 | GNUNET_MAX_MALLOC_CHECKED / sizeof(char *)) | ||
1005 | { | 1010 | { |
1006 | case GNUNET_FS_URI_KSK: | 1011 | GNUNET_break (0); |
1007 | if (ret->data.ksk.keywordCount >= | 1012 | GNUNET_free (ret); |
1008 | GNUNET_MAX_MALLOC_CHECKED / sizeof(char *)) | 1013 | return NULL; |
1009 | { | 1014 | } |
1010 | GNUNET_break(0); | 1015 | if (ret->data.ksk.keywordCount > 0) |
1011 | GNUNET_free(ret); | 1016 | { |
1012 | return NULL; | 1017 | ret->data.ksk.keywords = |
1013 | } | 1018 | GNUNET_new_array (ret->data.ksk.keywordCount, char *); |
1014 | if (ret->data.ksk.keywordCount > 0) | 1019 | for (i = 0; i < ret->data.ksk.keywordCount; i++) |
1015 | { | 1020 | ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); |
1016 | ret->data.ksk.keywords = | 1021 | } |
1017 | GNUNET_new_array(ret->data.ksk.keywordCount, char *); | 1022 | else |
1018 | for (i = 0; i < ret->data.ksk.keywordCount; i++) | 1023 | ret->data.ksk.keywords = NULL; /* just to be sure */ |
1019 | ret->data.ksk.keywords[i] = GNUNET_strdup(uri->data.ksk.keywords[i]); | 1024 | break; |
1020 | } | ||
1021 | else | ||
1022 | ret->data.ksk.keywords = NULL; /* just to be sure */ | ||
1023 | break; | ||
1024 | 1025 | ||
1025 | case GNUNET_FS_URI_SKS: | 1026 | case GNUNET_FS_URI_SKS: |
1026 | ret->data.sks.identifier = GNUNET_strdup(uri->data.sks.identifier); | 1027 | ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); |
1027 | break; | 1028 | break; |
1028 | 1029 | ||
1029 | case GNUNET_FS_URI_LOC: | 1030 | case GNUNET_FS_URI_LOC: |
1030 | break; | 1031 | break; |
1031 | 1032 | ||
1032 | default: | 1033 | default: |
1033 | break; | 1034 | break; |
1034 | } | 1035 | } |
1035 | return ret; | 1036 | return ret; |
1036 | } | 1037 | } |
1037 | 1038 | ||
@@ -1054,7 +1055,7 @@ GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri) | |||
1054 | * if keywords is not legal (i.e. empty). | 1055 | * if keywords is not legal (i.e. empty). |
1055 | */ | 1056 | */ |
1056 | struct GNUNET_FS_Uri * | 1057 | struct GNUNET_FS_Uri * |
1057 | GNUNET_FS_uri_ksk_create(const char *keywords, char **emsg) | 1058 | GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) |
1058 | { | 1059 | { |
1059 | char **keywordarr; | 1060 | char **keywordarr; |
1060 | unsigned int num_Words; | 1061 | unsigned int num_Words; |
@@ -1065,68 +1066,68 @@ GNUNET_FS_uri_ksk_create(const char *keywords, char **emsg) | |||
1065 | int saw_quote; | 1066 | int saw_quote; |
1066 | 1067 | ||
1067 | if (keywords == NULL) | 1068 | if (keywords == NULL) |
1068 | { | 1069 | { |
1069 | *emsg = GNUNET_strdup(_("No keywords specified!\n")); | 1070 | *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); |
1070 | GNUNET_break(0); | 1071 | GNUNET_break (0); |
1071 | return NULL; | 1072 | return NULL; |
1072 | } | 1073 | } |
1073 | searchString = GNUNET_strdup(keywords); | 1074 | searchString = GNUNET_strdup (keywords); |
1074 | num_Words = 0; | 1075 | num_Words = 0; |
1075 | inWord = 0; | 1076 | inWord = 0; |
1076 | saw_quote = 0; | 1077 | saw_quote = 0; |
1077 | pos = searchString; | 1078 | pos = searchString; |
1078 | while ('\0' != *pos) | 1079 | while ('\0' != *pos) |
1080 | { | ||
1081 | if ((saw_quote == 0) && (isspace ((unsigned char) *pos))) | ||
1079 | { | 1082 | { |
1080 | if ((saw_quote == 0) && (isspace((unsigned char)*pos))) | 1083 | inWord = 0; |
1081 | { | ||
1082 | inWord = 0; | ||
1083 | } | ||
1084 | else if (0 == inWord) | ||
1085 | { | ||
1086 | inWord = 1; | ||
1087 | ++num_Words; | ||
1088 | } | ||
1089 | if ('"' == *pos) | ||
1090 | saw_quote = (saw_quote + 1) % 2; | ||
1091 | pos++; | ||
1092 | } | 1084 | } |
1093 | if (num_Words == 0) | 1085 | else if (0 == inWord) |
1094 | { | 1086 | { |
1095 | GNUNET_free(searchString); | 1087 | inWord = 1; |
1096 | *emsg = GNUNET_strdup(_("No keywords specified!\n")); | 1088 | ++num_Words; |
1097 | return NULL; | ||
1098 | } | 1089 | } |
1090 | if ('"' == *pos) | ||
1091 | saw_quote = (saw_quote + 1) % 2; | ||
1092 | pos++; | ||
1093 | } | ||
1094 | if (num_Words == 0) | ||
1095 | { | ||
1096 | GNUNET_free (searchString); | ||
1097 | *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); | ||
1098 | return NULL; | ||
1099 | } | ||
1099 | if (saw_quote != 0) | 1100 | if (saw_quote != 0) |
1100 | { | 1101 | { |
1101 | GNUNET_free(searchString); | 1102 | GNUNET_free (searchString); |
1102 | *emsg = GNUNET_strdup(_("Number of double-quotes not balanced!\n")); | 1103 | *emsg = GNUNET_strdup (_ ("Number of double-quotes not balanced!\n")); |
1103 | return NULL; | 1104 | return NULL; |
1104 | } | 1105 | } |
1105 | keywordarr = GNUNET_new_array(num_Words, char *); | 1106 | keywordarr = GNUNET_new_array (num_Words, char *); |
1106 | num_Words = 0; | 1107 | num_Words = 0; |
1107 | inWord = 0; | 1108 | inWord = 0; |
1108 | pos = searchString; | 1109 | pos = searchString; |
1109 | while ('\0' != *pos) | 1110 | while ('\0' != *pos) |
1111 | { | ||
1112 | if ((saw_quote == 0) && (isspace ((unsigned char) *pos))) | ||
1110 | { | 1113 | { |
1111 | if ((saw_quote == 0) && (isspace((unsigned char)*pos))) | 1114 | inWord = 0; |
1112 | { | 1115 | *pos = '\0'; |
1113 | inWord = 0; | ||
1114 | *pos = '\0'; | ||
1115 | } | ||
1116 | else if (0 == inWord) | ||
1117 | { | ||
1118 | keywordarr[num_Words] = pos; | ||
1119 | inWord = 1; | ||
1120 | ++num_Words; | ||
1121 | } | ||
1122 | if ('"' == *pos) | ||
1123 | saw_quote = (saw_quote + 1) % 2; | ||
1124 | pos++; | ||
1125 | } | 1116 | } |
1117 | else if (0 == inWord) | ||
1118 | { | ||
1119 | keywordarr[num_Words] = pos; | ||
1120 | inWord = 1; | ||
1121 | ++num_Words; | ||
1122 | } | ||
1123 | if ('"' == *pos) | ||
1124 | saw_quote = (saw_quote + 1) % 2; | ||
1125 | pos++; | ||
1126 | } | ||
1126 | uri = | 1127 | uri = |
1127 | GNUNET_FS_uri_ksk_create_from_args(num_Words, (const char **)keywordarr); | 1128 | GNUNET_FS_uri_ksk_create_from_args (num_Words, (const char **) keywordarr); |
1128 | GNUNET_free(keywordarr); | 1129 | GNUNET_free (keywordarr); |
1129 | GNUNET_free(searchString); | 1130 | GNUNET_free (searchString); |
1130 | return uri; | 1131 | return uri; |
1131 | } | 1132 | } |
1132 | 1133 | ||
@@ -1149,7 +1150,7 @@ GNUNET_FS_uri_ksk_create(const char *keywords, char **emsg) | |||
1149 | * if keywords is not legal (i.e. empty). | 1150 | * if keywords is not legal (i.e. empty). |
1150 | */ | 1151 | */ |
1151 | struct GNUNET_FS_Uri * | 1152 | struct GNUNET_FS_Uri * |
1152 | GNUNET_FS_uri_ksk_create_from_args(unsigned int argc, const char **argv) | 1153 | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) |
1153 | { | 1154 | { |
1154 | unsigned int i; | 1155 | unsigned int i; |
1155 | struct GNUNET_FS_Uri *uri; | 1156 | struct GNUNET_FS_Uri *uri; |
@@ -1164,36 +1165,36 @@ GNUNET_FS_uri_ksk_create_from_args(unsigned int argc, const char **argv) | |||
1164 | /* allow URI to be given as one and only keyword and | 1165 | /* allow URI to be given as one and only keyword and |
1165 | * handle accordingly */ | 1166 | * handle accordingly */ |
1166 | emsg = NULL; | 1167 | emsg = NULL; |
1167 | if ((argc == 1) && (strlen(argv[0]) > strlen(GNUNET_FS_URI_PREFIX)) && | 1168 | if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && |
1168 | (0 == strncmp(argv[0], | 1169 | (0 == strncmp (argv[0], |
1169 | GNUNET_FS_URI_PREFIX, | 1170 | GNUNET_FS_URI_PREFIX, |
1170 | strlen(GNUNET_FS_URI_PREFIX))) && | 1171 | strlen (GNUNET_FS_URI_PREFIX))) && |
1171 | (NULL != (uri = GNUNET_FS_uri_parse(argv[0], &emsg)))) | 1172 | (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) |
1172 | return uri; | 1173 | return uri; |
1173 | GNUNET_free_non_null(emsg); | 1174 | GNUNET_free_non_null (emsg); |
1174 | uri = GNUNET_new(struct GNUNET_FS_Uri); | 1175 | uri = GNUNET_new (struct GNUNET_FS_Uri); |
1175 | uri->type = GNUNET_FS_URI_KSK; | 1176 | uri->type = GNUNET_FS_URI_KSK; |
1176 | uri->data.ksk.keywordCount = argc; | 1177 | uri->data.ksk.keywordCount = argc; |
1177 | uri->data.ksk.keywords = GNUNET_new_array(argc, char *); | 1178 | uri->data.ksk.keywords = GNUNET_new_array (argc, char *); |
1178 | for (i = 0; i < argc; i++) | 1179 | for (i = 0; i < argc; i++) |
1180 | { | ||
1181 | keyword = argv[i]; | ||
1182 | if (keyword[0] == '+') | ||
1183 | val = GNUNET_strdup (keyword); | ||
1184 | else | ||
1185 | GNUNET_asprintf (&val, " %s", keyword); | ||
1186 | r = val; | ||
1187 | w = val; | ||
1188 | while ('\0' != *r) | ||
1179 | { | 1189 | { |
1180 | keyword = argv[i]; | 1190 | if ('"' == *r) |
1181 | if (keyword[0] == '+') | 1191 | r++; |
1182 | val = GNUNET_strdup(keyword); | ||
1183 | else | 1192 | else |
1184 | GNUNET_asprintf(&val, " %s", keyword); | 1193 | *(w++) = *(r++); |
1185 | r = val; | ||
1186 | w = val; | ||
1187 | while ('\0' != *r) | ||
1188 | { | ||
1189 | if ('"' == *r) | ||
1190 | r++; | ||
1191 | else | ||
1192 | *(w++) = *(r++); | ||
1193 | } | ||
1194 | *w = '\0'; | ||
1195 | uri->data.ksk.keywords[i] = val; | ||
1196 | } | 1194 | } |
1195 | *w = '\0'; | ||
1196 | uri->data.ksk.keywords[i] = val; | ||
1197 | } | ||
1197 | return uri; | 1198 | return uri; |
1198 | } | 1199 | } |
1199 | 1200 | ||
@@ -1206,66 +1207,66 @@ GNUNET_FS_uri_ksk_create_from_args(unsigned int argc, const char **argv) | |||
1206 | * @return #GNUNET_YES if the URIs are equal | 1207 | * @return #GNUNET_YES if the URIs are equal |
1207 | */ | 1208 | */ |
1208 | int | 1209 | int |
1209 | GNUNET_FS_uri_test_equal(const struct GNUNET_FS_Uri *u1, | 1210 | GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, |
1210 | const struct GNUNET_FS_Uri *u2) | 1211 | const struct GNUNET_FS_Uri *u2) |
1211 | { | 1212 | { |
1212 | int ret; | 1213 | int ret; |
1213 | unsigned int i; | 1214 | unsigned int i; |
1214 | unsigned int j; | 1215 | unsigned int j; |
1215 | 1216 | ||
1216 | GNUNET_assert(u1 != NULL); | 1217 | GNUNET_assert (u1 != NULL); |
1217 | GNUNET_assert(u2 != NULL); | 1218 | GNUNET_assert (u2 != NULL); |
1218 | if (u1->type != u2->type) | 1219 | if (u1->type != u2->type) |
1219 | return GNUNET_NO; | 1220 | return GNUNET_NO; |
1220 | switch (u1->type) | 1221 | switch (u1->type) |
1221 | { | 1222 | { |
1222 | case GNUNET_FS_URI_CHK: | 1223 | case GNUNET_FS_URI_CHK: |
1223 | if (0 == | 1224 | if (0 == |
1224 | memcmp(&u1->data.chk, &u2->data.chk, sizeof(struct FileIdentifier))) | 1225 | memcmp (&u1->data.chk, &u2->data.chk, sizeof(struct FileIdentifier))) |
1225 | return GNUNET_YES; | 1226 | return GNUNET_YES; |
1226 | return GNUNET_NO; | 1227 | return GNUNET_NO; |
1227 | 1228 | ||
1228 | case GNUNET_FS_URI_SKS: | 1229 | case GNUNET_FS_URI_SKS: |
1229 | if ((0 == memcmp(&u1->data.sks.ns, | 1230 | if ((0 == memcmp (&u1->data.sks.ns, |
1230 | &u2->data.sks.ns, | 1231 | &u2->data.sks.ns, |
1231 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) && | 1232 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) && |
1232 | (0 == strcmp(u1->data.sks.identifier, u2->data.sks.identifier))) | 1233 | (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) |
1233 | 1234 | ||
1234 | return GNUNET_YES; | 1235 | return GNUNET_YES; |
1235 | return GNUNET_NO; | 1236 | return GNUNET_NO; |
1236 | 1237 | ||
1237 | case GNUNET_FS_URI_KSK: | 1238 | case GNUNET_FS_URI_KSK: |
1238 | if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) | 1239 | if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) |
1239 | return GNUNET_NO; | 1240 | return GNUNET_NO; |
1240 | for (i = 0; i < u1->data.ksk.keywordCount; i++) | 1241 | for (i = 0; i < u1->data.ksk.keywordCount; i++) |
1242 | { | ||
1243 | ret = GNUNET_NO; | ||
1244 | for (j = 0; j < u2->data.ksk.keywordCount; j++) | ||
1245 | { | ||
1246 | if (0 == strcmp (u1->data.ksk.keywords[i], u2->data.ksk.keywords[j])) | ||
1241 | { | 1247 | { |
1242 | ret = GNUNET_NO; | 1248 | ret = GNUNET_YES; |
1243 | for (j = 0; j < u2->data.ksk.keywordCount; j++) | 1249 | break; |
1244 | { | ||
1245 | if (0 == strcmp(u1->data.ksk.keywords[i], u2->data.ksk.keywords[j])) | ||
1246 | { | ||
1247 | ret = GNUNET_YES; | ||
1248 | break; | ||
1249 | } | ||
1250 | } | ||
1251 | if (ret == GNUNET_NO) | ||
1252 | return GNUNET_NO; | ||
1253 | } | 1250 | } |
1254 | return GNUNET_YES; | 1251 | } |
1255 | 1252 | if (ret == GNUNET_NO) | |
1256 | case GNUNET_FS_URI_LOC: | ||
1257 | if (memcmp(&u1->data.loc, | ||
1258 | &u2->data.loc, | ||
1259 | sizeof(struct FileIdentifier) + | ||
1260 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) + | ||
1261 | sizeof(struct GNUNET_TIME_Absolute) + | ||
1262 | sizeof(unsigned short) + sizeof(unsigned short)) != 0) | ||
1263 | return GNUNET_NO; | 1253 | return GNUNET_NO; |
1264 | return GNUNET_YES; | ||
1265 | |||
1266 | default: | ||
1267 | return GNUNET_NO; | ||
1268 | } | 1254 | } |
1255 | return GNUNET_YES; | ||
1256 | |||
1257 | case GNUNET_FS_URI_LOC: | ||
1258 | if (memcmp (&u1->data.loc, | ||
1259 | &u2->data.loc, | ||
1260 | sizeof(struct FileIdentifier) | ||
1261 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
1262 | + sizeof(struct GNUNET_TIME_Absolute) | ||
1263 | + sizeof(unsigned short) + sizeof(unsigned short)) != 0) | ||
1264 | return GNUNET_NO; | ||
1265 | return GNUNET_YES; | ||
1266 | |||
1267 | default: | ||
1268 | return GNUNET_NO; | ||
1269 | } | ||
1269 | } | 1270 | } |
1270 | 1271 | ||
1271 | 1272 | ||
@@ -1276,7 +1277,7 @@ GNUNET_FS_uri_test_equal(const struct GNUNET_FS_Uri *u1, | |||
1276 | * @return #GNUNET_YES if this is an SKS uri | 1277 | * @return #GNUNET_YES if this is an SKS uri |
1277 | */ | 1278 | */ |
1278 | int | 1279 | int |
1279 | GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri) | 1280 | GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri) |
1280 | { | 1281 | { |
1281 | return uri->type == GNUNET_FS_URI_SKS; | 1282 | return uri->type == GNUNET_FS_URI_SKS; |
1282 | } | 1283 | } |
@@ -1291,14 +1292,14 @@ GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri) | |||
1291 | * @return #GNUNET_OK on success | 1292 | * @return #GNUNET_OK on success |
1292 | */ | 1293 | */ |
1293 | int | 1294 | int |
1294 | GNUNET_FS_uri_sks_get_namespace(const struct GNUNET_FS_Uri *uri, | 1295 | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, |
1295 | struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) | 1296 | struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) |
1296 | { | 1297 | { |
1297 | if (!GNUNET_FS_uri_test_sks(uri)) | 1298 | if (! GNUNET_FS_uri_test_sks (uri)) |
1298 | { | 1299 | { |
1299 | GNUNET_break(0); | 1300 | GNUNET_break (0); |
1300 | return GNUNET_SYSERR; | 1301 | return GNUNET_SYSERR; |
1301 | } | 1302 | } |
1302 | *pseudonym = uri->data.sks.ns; | 1303 | *pseudonym = uri->data.sks.ns; |
1303 | return GNUNET_OK; | 1304 | return GNUNET_OK; |
1304 | } | 1305 | } |
@@ -1311,14 +1312,14 @@ GNUNET_FS_uri_sks_get_namespace(const struct GNUNET_FS_Uri *uri, | |||
1311 | * @return NULL on error (not a valid SKS URI) | 1312 | * @return NULL on error (not a valid SKS URI) |
1312 | */ | 1313 | */ |
1313 | char * | 1314 | char * |
1314 | GNUNET_FS_uri_sks_get_content_id(const struct GNUNET_FS_Uri *uri) | 1315 | GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) |
1315 | { | 1316 | { |
1316 | if (!GNUNET_FS_uri_test_sks(uri)) | 1317 | if (! GNUNET_FS_uri_test_sks (uri)) |
1317 | { | 1318 | { |
1318 | GNUNET_break(0); | 1319 | GNUNET_break (0); |
1319 | return NULL; | 1320 | return NULL; |
1320 | } | 1321 | } |
1321 | return GNUNET_strdup(uri->data.sks.identifier); | 1322 | return GNUNET_strdup (uri->data.sks.identifier); |
1322 | } | 1323 | } |
1323 | 1324 | ||
1324 | 1325 | ||
@@ -1329,16 +1330,16 @@ GNUNET_FS_uri_sks_get_content_id(const struct GNUNET_FS_Uri *uri) | |||
1329 | * @return #GNUNET_YES if this is a KSK uri | 1330 | * @return #GNUNET_YES if this is a KSK uri |
1330 | */ | 1331 | */ |
1331 | int | 1332 | int |
1332 | GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri) | 1333 | GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) |
1333 | { | 1334 | { |
1334 | #if EXTRA_CHECKS | 1335 | #if EXTRA_CHECKS |
1335 | unsigned int i; | 1336 | unsigned int i; |
1336 | 1337 | ||
1337 | if (uri->type == GNUNET_FS_URI_KSK) | 1338 | if (uri->type == GNUNET_FS_URI_KSK) |
1338 | { | 1339 | { |
1339 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 1340 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
1340 | GNUNET_assert(uri->data.ksk.keywords[i] != NULL); | 1341 | GNUNET_assert (uri->data.ksk.keywords[i] != NULL); |
1341 | } | 1342 | } |
1342 | #endif | 1343 | #endif |
1343 | return uri->type == GNUNET_FS_URI_KSK; | 1344 | return uri->type == GNUNET_FS_URI_KSK; |
1344 | } | 1345 | } |
@@ -1351,7 +1352,7 @@ GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri) | |||
1351 | * @return #GNUNET_YES if this is a CHK uri | 1352 | * @return #GNUNET_YES if this is a CHK uri |
1352 | */ | 1353 | */ |
1353 | int | 1354 | int |
1354 | GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri) | 1355 | GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) |
1355 | { | 1356 | { |
1356 | return uri->type == GNUNET_FS_URI_CHK; | 1357 | return uri->type == GNUNET_FS_URI_CHK; |
1357 | } | 1358 | } |
@@ -1365,19 +1366,19 @@ GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri) | |||
1365 | * @return size of the file as specified in the CHK URI | 1366 | * @return size of the file as specified in the CHK URI |
1366 | */ | 1367 | */ |
1367 | uint64_t | 1368 | uint64_t |
1368 | GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri) | 1369 | GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) |
1369 | { | 1370 | { |
1370 | switch (uri->type) | 1371 | switch (uri->type) |
1371 | { | 1372 | { |
1372 | case GNUNET_FS_URI_CHK: | 1373 | case GNUNET_FS_URI_CHK: |
1373 | return GNUNET_ntohll(uri->data.chk.file_length); | 1374 | return GNUNET_ntohll (uri->data.chk.file_length); |
1374 | 1375 | ||
1375 | case GNUNET_FS_URI_LOC: | 1376 | case GNUNET_FS_URI_LOC: |
1376 | return GNUNET_ntohll(uri->data.loc.fi.file_length); | 1377 | return GNUNET_ntohll (uri->data.loc.fi.file_length); |
1377 | 1378 | ||
1378 | default: | 1379 | default: |
1379 | GNUNET_assert(0); | 1380 | GNUNET_assert (0); |
1380 | } | 1381 | } |
1381 | return 0; /* unreachable */ | 1382 | return 0; /* unreachable */ |
1382 | } | 1383 | } |
1383 | 1384 | ||
@@ -1389,7 +1390,7 @@ GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri) | |||
1389 | * @return #GNUNET_YES if this is a LOC uri | 1390 | * @return #GNUNET_YES if this is a LOC uri |
1390 | */ | 1391 | */ |
1391 | int | 1392 | int |
1392 | GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri) | 1393 | GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) |
1393 | { | 1394 | { |
1394 | return uri->type == GNUNET_FS_URI_LOC; | 1395 | return uri->type == GNUNET_FS_URI_LOC; |
1395 | } | 1396 | } |
@@ -1405,13 +1406,13 @@ GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri) | |||
1405 | * @param index offset where to add the keyword | 1406 | * @param index offset where to add the keyword |
1406 | */ | 1407 | */ |
1407 | static void | 1408 | static void |
1408 | insert_non_mandatory_keyword(const char *s, char **array, int index) | 1409 | insert_non_mandatory_keyword (const char *s, char **array, int index) |
1409 | { | 1410 | { |
1410 | char *nkword; | 1411 | char *nkword; |
1411 | 1412 | ||
1412 | GNUNET_asprintf(&nkword, | 1413 | GNUNET_asprintf (&nkword, |
1413 | " %s", /* space to mark as 'non mandatory' */ | 1414 | " %s", /* space to mark as 'non mandatory' */ |
1414 | s); | 1415 | s); |
1415 | array[index] = nkword; | 1416 | array[index] = nkword; |
1416 | } | 1417 | } |
1417 | 1418 | ||
@@ -1426,12 +1427,12 @@ insert_non_mandatory_keyword(const char *s, char **array, int index) | |||
1426 | * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not | 1427 | * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not |
1427 | */ | 1428 | */ |
1428 | static int | 1429 | static int |
1429 | find_duplicate(const char *s, const char **array, int array_length) | 1430 | find_duplicate (const char *s, const char **array, int array_length) |
1430 | { | 1431 | { |
1431 | int j; | 1432 | int j; |
1432 | 1433 | ||
1433 | for (j = array_length - 1; j >= 0; j--) | 1434 | for (j = array_length - 1; j >= 0; j--) |
1434 | if (0 == strcmp(&array[j][1], s)) | 1435 | if (0 == strcmp (&array[j][1], s)) |
1435 | return GNUNET_YES; | 1436 | return GNUNET_YES; |
1436 | return GNUNET_NO; | 1437 | return GNUNET_NO; |
1437 | } | 1438 | } |
@@ -1441,12 +1442,12 @@ find_duplicate(const char *s, const char **array, int array_length) | |||
1441 | * FIXME: comment | 1442 | * FIXME: comment |
1442 | */ | 1443 | */ |
1443 | static char * | 1444 | static char * |
1444 | normalize_metadata(enum EXTRACTOR_MetaFormat format, | 1445 | normalize_metadata (enum EXTRACTOR_MetaFormat format, |
1445 | const char *data, | 1446 | const char *data, |
1446 | size_t data_len) | 1447 | size_t data_len) |
1447 | { | 1448 | { |
1448 | uint8_t *free_str = NULL; | 1449 | uint8_t *free_str = NULL; |
1449 | uint8_t *str_to_normalize = (uint8_t *)data; | 1450 | uint8_t *str_to_normalize = (uint8_t *) data; |
1450 | uint8_t *normalized; | 1451 | uint8_t *normalized; |
1451 | size_t r_len; | 1452 | size_t r_len; |
1452 | 1453 | ||
@@ -1454,41 +1455,41 @@ normalize_metadata(enum EXTRACTOR_MetaFormat format, | |||
1454 | return NULL; | 1455 | return NULL; |
1455 | /* Don't trust libextractor */ | 1456 | /* Don't trust libextractor */ |
1456 | if (format == EXTRACTOR_METAFORMAT_UTF8) | 1457 | if (format == EXTRACTOR_METAFORMAT_UTF8) |
1457 | { | 1458 | { |
1458 | free_str = (uint8_t *)u8_check((const uint8_t *)data, data_len); | 1459 | free_str = (uint8_t *) u8_check ((const uint8_t *) data, data_len); |
1459 | if (free_str == NULL) | 1460 | if (free_str == NULL) |
1460 | free_str = NULL; | 1461 | free_str = NULL; |
1461 | else | 1462 | else |
1462 | format = EXTRACTOR_METAFORMAT_C_STRING; | 1463 | format = EXTRACTOR_METAFORMAT_C_STRING; |
1463 | } | 1464 | } |
1464 | if (format == EXTRACTOR_METAFORMAT_C_STRING) | 1465 | if (format == EXTRACTOR_METAFORMAT_C_STRING) |
1465 | { | 1466 | { |
1466 | free_str = u8_strconv_from_encoding(data, | 1467 | free_str = u8_strconv_from_encoding (data, |
1467 | locale_charset(), | 1468 | locale_charset (), |
1468 | iconveh_escape_sequence); | 1469 | iconveh_escape_sequence); |
1469 | if (free_str == NULL) | 1470 | if (free_str == NULL) |
1470 | return NULL; | 1471 | return NULL; |
1471 | } | 1472 | } |
1472 | 1473 | ||
1473 | normalized = u8_tolower(str_to_normalize, | 1474 | normalized = u8_tolower (str_to_normalize, |
1474 | strlen((char *)str_to_normalize), | 1475 | strlen ((char *) str_to_normalize), |
1475 | NULL, | 1476 | NULL, |
1476 | UNINORM_NFD, | 1477 | UNINORM_NFD, |
1477 | NULL, | 1478 | NULL, |
1478 | &r_len); | 1479 | &r_len); |
1479 | /* free_str is allocated by libunistring internally, use free() */ | 1480 | /* free_str is allocated by libunistring internally, use free() */ |
1480 | if (free_str != NULL) | 1481 | if (free_str != NULL) |
1481 | free(free_str); | 1482 | free (free_str); |
1482 | if (normalized != NULL) | 1483 | if (normalized != NULL) |
1483 | { | 1484 | { |
1484 | /* u8_tolower allocates a non-NULL-terminated string! */ | 1485 | /* u8_tolower allocates a non-NULL-terminated string! */ |
1485 | free_str = GNUNET_malloc(r_len + 1); | 1486 | free_str = GNUNET_malloc (r_len + 1); |
1486 | GNUNET_memcpy(free_str, normalized, r_len); | 1487 | GNUNET_memcpy (free_str, normalized, r_len); |
1487 | free_str[r_len] = '\0'; | 1488 | free_str[r_len] = '\0'; |
1488 | free(normalized); | 1489 | free (normalized); |
1489 | normalized = free_str; | 1490 | normalized = free_str; |
1490 | } | 1491 | } |
1491 | return (char *)normalized; | 1492 | return (char *) normalized; |
1492 | } | 1493 | } |
1493 | 1494 | ||
1494 | 1495 | ||
@@ -1497,16 +1498,16 @@ normalize_metadata(enum EXTRACTOR_MetaFormat format, | |||
1497 | * returns that count. | 1498 | * returns that count. |
1498 | */ | 1499 | */ |
1499 | static size_t | 1500 | static size_t |
1500 | u8_strcount(const uint8_t *s) | 1501 | u8_strcount (const uint8_t *s) |
1501 | { | 1502 | { |
1502 | size_t count; | 1503 | size_t count; |
1503 | ucs4_t c; | 1504 | ucs4_t c; |
1504 | 1505 | ||
1505 | GNUNET_assert(s != NULL); | 1506 | GNUNET_assert (s != NULL); |
1506 | if (s[0] == 0) | 1507 | if (s[0] == 0) |
1507 | return 0; | 1508 | return 0; |
1508 | for (count = 0; s != NULL; count++) | 1509 | for (count = 0; s != NULL; count++) |
1509 | s = u8_next(&c, s); | 1510 | s = u8_next (&c, s); |
1510 | return count - 1; | 1511 | return count - 1; |
1511 | } | 1512 | } |
1512 | 1513 | ||
@@ -1528,7 +1529,7 @@ u8_strcount(const uint8_t *s) | |||
1528 | * were duplicates (when extracting). | 1529 | * were duplicates (when extracting). |
1529 | */ | 1530 | */ |
1530 | static int | 1531 | static int |
1531 | get_keywords_from_parens(const char *s, char **array, int index) | 1532 | get_keywords_from_parens (const char *s, char **array, int index) |
1532 | { | 1533 | { |
1533 | int count = 0; | 1534 | int count = 0; |
1534 | char *open_paren; | 1535 | char *open_paren; |
@@ -1538,80 +1539,80 @@ get_keywords_from_parens(const char *s, char **array, int index) | |||
1538 | 1539 | ||
1539 | if (NULL == s) | 1540 | if (NULL == s) |
1540 | return 0; | 1541 | return 0; |
1541 | ss = GNUNET_strdup(s); | 1542 | ss = GNUNET_strdup (s); |
1542 | open_paren = ss - 1; | 1543 | open_paren = ss - 1; |
1543 | while (NULL != (open_paren = strpbrk(open_paren + 1, "[{("))) | 1544 | while (NULL != (open_paren = strpbrk (open_paren + 1, "[{("))) |
1545 | { | ||
1546 | int match = 0; | ||
1547 | |||
1548 | close_paren = strpbrk (open_paren + 1, "]})"); | ||
1549 | if (NULL == close_paren) | ||
1550 | continue; | ||
1551 | switch (open_paren[0]) | ||
1544 | { | 1552 | { |
1545 | int match = 0; | 1553 | case '[': |
1546 | 1554 | if (']' == close_paren[0]) | |
1547 | close_paren = strpbrk(open_paren + 1, "]})"); | 1555 | match = 1; |
1548 | if (NULL == close_paren) | 1556 | break; |
1549 | continue; | ||
1550 | switch (open_paren[0]) | ||
1551 | { | ||
1552 | case '[': | ||
1553 | if (']' == close_paren[0]) | ||
1554 | match = 1; | ||
1555 | break; | ||
1556 | 1557 | ||
1557 | case '{': | 1558 | case '{': |
1558 | if ('}' == close_paren[0]) | 1559 | if ('}' == close_paren[0]) |
1559 | match = 1; | 1560 | match = 1; |
1560 | break; | 1561 | break; |
1561 | 1562 | ||
1562 | case '(': | 1563 | case '(': |
1563 | if (')' == close_paren[0]) | 1564 | if (')' == close_paren[0]) |
1564 | match = 1; | 1565 | match = 1; |
1565 | break; | 1566 | break; |
1566 | 1567 | ||
1567 | default: | 1568 | default: |
1568 | break; | 1569 | break; |
1570 | } | ||
1571 | if (match && (close_paren - open_paren > 1)) | ||
1572 | { | ||
1573 | tmp = close_paren[0]; | ||
1574 | close_paren[0] = '\0'; | ||
1575 | /* Keywords must be at least 3 characters long */ | ||
1576 | if (u8_strcount ((const uint8_t *) &open_paren[1]) <= 2) | ||
1577 | { | ||
1578 | close_paren[0] = tmp; | ||
1579 | continue; | ||
1580 | } | ||
1581 | if (NULL != array) | ||
1582 | { | ||
1583 | char *normalized; | ||
1584 | if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1], | ||
1585 | (const char **) array, | ||
1586 | index + count)) | ||
1587 | { | ||
1588 | insert_non_mandatory_keyword ((const char *) &open_paren[1], | ||
1589 | array, | ||
1590 | index + count); | ||
1591 | count++; | ||
1569 | } | 1592 | } |
1570 | if (match && (close_paren - open_paren > 1)) | 1593 | normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, |
1594 | &open_paren[1], | ||
1595 | close_paren - &open_paren[1]); | ||
1596 | if (normalized != NULL) | ||
1571 | { | 1597 | { |
1572 | tmp = close_paren[0]; | 1598 | if (GNUNET_NO == find_duplicate ((const char *) normalized, |
1573 | close_paren[0] = '\0'; | 1599 | (const char **) array, |
1574 | /* Keywords must be at least 3 characters long */ | 1600 | index + count)) |
1575 | if (u8_strcount((const uint8_t *)&open_paren[1]) <= 2) | 1601 | { |
1576 | { | 1602 | insert_non_mandatory_keyword ((const char *) normalized, |
1577 | close_paren[0] = tmp; | 1603 | array, |
1578 | continue; | 1604 | index + count); |
1579 | } | ||
1580 | if (NULL != array) | ||
1581 | { | ||
1582 | char *normalized; | ||
1583 | if (GNUNET_NO == find_duplicate((const char *)&open_paren[1], | ||
1584 | (const char **)array, | ||
1585 | index + count)) | ||
1586 | { | ||
1587 | insert_non_mandatory_keyword((const char *)&open_paren[1], | ||
1588 | array, | ||
1589 | index + count); | ||
1590 | count++; | ||
1591 | } | ||
1592 | normalized = normalize_metadata(EXTRACTOR_METAFORMAT_UTF8, | ||
1593 | &open_paren[1], | ||
1594 | close_paren - &open_paren[1]); | ||
1595 | if (normalized != NULL) | ||
1596 | { | ||
1597 | if (GNUNET_NO == find_duplicate((const char *)normalized, | ||
1598 | (const char **)array, | ||
1599 | index + count)) | ||
1600 | { | ||
1601 | insert_non_mandatory_keyword((const char *)normalized, | ||
1602 | array, | ||
1603 | index + count); | ||
1604 | count++; | ||
1605 | } | ||
1606 | GNUNET_free(normalized); | ||
1607 | } | ||
1608 | } | ||
1609 | else | ||
1610 | count++; | 1605 | count++; |
1611 | close_paren[0] = tmp; | 1606 | } |
1607 | GNUNET_free (normalized); | ||
1612 | } | 1608 | } |
1609 | } | ||
1610 | else | ||
1611 | count++; | ||
1612 | close_paren[0] = tmp; | ||
1613 | } | 1613 | } |
1614 | GNUNET_free(ss); | 1614 | } |
1615 | GNUNET_free (ss); | ||
1615 | return count; | 1616 | return count; |
1616 | } | 1617 | } |
1617 | 1618 | ||
@@ -1636,46 +1637,46 @@ get_keywords_from_parens(const char *s, char **array, int index) | |||
1636 | * duplicates (when extracting). | 1637 | * duplicates (when extracting). |
1637 | */ | 1638 | */ |
1638 | static int | 1639 | static int |
1639 | get_keywords_from_tokens(const char *s, char **array, int index) | 1640 | get_keywords_from_tokens (const char *s, char **array, int index) |
1640 | { | 1641 | { |
1641 | char *p; | 1642 | char *p; |
1642 | char *ss; | 1643 | char *ss; |
1643 | int seps = 0; | 1644 | int seps = 0; |
1644 | 1645 | ||
1645 | ss = GNUNET_strdup(s); | 1646 | ss = GNUNET_strdup (s); |
1646 | for (p = strtok(ss, TOKENS); p != NULL; p = strtok(NULL, TOKENS)) | 1647 | for (p = strtok (ss, TOKENS); p != NULL; p = strtok (NULL, TOKENS)) |
1648 | { | ||
1649 | /* Keywords must be at least 3 characters long */ | ||
1650 | if (u8_strcount ((const uint8_t *) p) <= 2) | ||
1651 | continue; | ||
1652 | if (NULL != array) | ||
1647 | { | 1653 | { |
1648 | /* Keywords must be at least 3 characters long */ | 1654 | char *normalized; |
1649 | if (u8_strcount((const uint8_t *)p) <= 2) | 1655 | if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps)) |
1650 | continue; | 1656 | { |
1651 | if (NULL != array) | 1657 | insert_non_mandatory_keyword (p, array, index + seps); |
1658 | seps++; | ||
1659 | } | ||
1660 | normalized = | ||
1661 | normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, p, strlen (p)); | ||
1662 | if (normalized != NULL) | ||
1663 | { | ||
1664 | if (GNUNET_NO == find_duplicate ((const char *) normalized, | ||
1665 | (const char **) array, | ||
1666 | index + seps)) | ||
1652 | { | 1667 | { |
1653 | char *normalized; | 1668 | insert_non_mandatory_keyword ((const char *) normalized, |
1654 | if (GNUNET_NO == find_duplicate(p, (const char **)array, index + seps)) | 1669 | array, |
1655 | { | 1670 | index + seps); |
1656 | insert_non_mandatory_keyword(p, array, index + seps); | 1671 | seps++; |
1657 | seps++; | ||
1658 | } | ||
1659 | normalized = | ||
1660 | normalize_metadata(EXTRACTOR_METAFORMAT_UTF8, p, strlen(p)); | ||
1661 | if (normalized != NULL) | ||
1662 | { | ||
1663 | if (GNUNET_NO == find_duplicate((const char *)normalized, | ||
1664 | (const char **)array, | ||
1665 | index + seps)) | ||
1666 | { | ||
1667 | insert_non_mandatory_keyword((const char *)normalized, | ||
1668 | array, | ||
1669 | index + seps); | ||
1670 | seps++; | ||
1671 | } | ||
1672 | GNUNET_free(normalized); | ||
1673 | } | ||
1674 | } | 1672 | } |
1675 | else | 1673 | GNUNET_free (normalized); |
1676 | seps++; | 1674 | } |
1677 | } | 1675 | } |
1678 | GNUNET_free(ss); | 1676 | else |
1677 | seps++; | ||
1678 | } | ||
1679 | GNUNET_free (ss); | ||
1679 | return seps; | 1680 | return seps; |
1680 | } | 1681 | } |
1681 | #undef TOKENS | 1682 | #undef TOKENS |
@@ -1699,13 +1700,13 @@ get_keywords_from_tokens(const char *s, char **array, int index) | |||
1699 | * @return 0 (always) | 1700 | * @return 0 (always) |
1700 | */ | 1701 | */ |
1701 | static int | 1702 | static int |
1702 | gather_uri_data(void *cls, | 1703 | gather_uri_data (void *cls, |
1703 | const char *plugin_name, | 1704 | const char *plugin_name, |
1704 | enum EXTRACTOR_MetaType type, | 1705 | enum EXTRACTOR_MetaType type, |
1705 | enum EXTRACTOR_MetaFormat format, | 1706 | enum EXTRACTOR_MetaFormat format, |
1706 | const char *data_mime_type, | 1707 | const char *data_mime_type, |
1707 | const char *data, | 1708 | const char *data, |
1708 | size_t data_len) | 1709 | size_t data_len) |
1709 | { | 1710 | { |
1710 | struct GNUNET_FS_Uri *uri = cls; | 1711 | struct GNUNET_FS_Uri *uri = cls; |
1711 | char *normalized_data; | 1712 | char *normalized_data; |
@@ -1719,49 +1720,49 @@ gather_uri_data(void *cls, | |||
1719 | * and will return the length of its valid part, skipping the keyword. | 1720 | * and will return the length of its valid part, skipping the keyword. |
1720 | * If it does - fix the extractor, not this check! | 1721 | * If it does - fix the extractor, not this check! |
1721 | */ | 1722 | */ |
1722 | if (u8_strcount((const uint8_t *)data) <= 2) | 1723 | if (u8_strcount ((const uint8_t *) data) <= 2) |
1723 | return 0; | 1724 | return 0; |
1724 | if ((EXTRACTOR_METATYPE_MIMETYPE == type) && | 1725 | if ((EXTRACTOR_METATYPE_MIMETYPE == type) && |
1725 | (NULL != (sep = memchr(data, '/', data_len))) && (sep != data)) | 1726 | (NULL != (sep = memchr (data, '/', data_len))) && (sep != data)) |
1726 | { | 1727 | { |
1727 | char *xtra; | 1728 | char *xtra; |
1728 | 1729 | ||
1729 | GNUNET_asprintf(&xtra, "mimetype:%.*s", (int)(sep - data), data); | 1730 | GNUNET_asprintf (&xtra, "mimetype:%.*s", (int) (sep - data), data); |
1730 | if (!find_duplicate(xtra, | 1731 | if (! find_duplicate (xtra, |
1731 | (const char **)uri->data.ksk.keywords, | 1732 | (const char **) uri->data.ksk.keywords, |
1732 | uri->data.ksk.keywordCount)) | 1733 | uri->data.ksk.keywordCount)) |
1733 | { | ||
1734 | insert_non_mandatory_keyword(xtra, | ||
1735 | uri->data.ksk.keywords, | ||
1736 | uri->data.ksk.keywordCount); | ||
1737 | uri->data.ksk.keywordCount++; | ||
1738 | } | ||
1739 | GNUNET_free(xtra); | ||
1740 | } | ||
1741 | |||
1742 | normalized_data = normalize_metadata(format, data, data_len); | ||
1743 | if (!find_duplicate(data, | ||
1744 | (const char **)uri->data.ksk.keywords, | ||
1745 | uri->data.ksk.keywordCount)) | ||
1746 | { | 1734 | { |
1747 | insert_non_mandatory_keyword(data, | 1735 | insert_non_mandatory_keyword (xtra, |
1748 | uri->data.ksk.keywords, | 1736 | uri->data.ksk.keywords, |
1749 | uri->data.ksk.keywordCount); | 1737 | uri->data.ksk.keywordCount); |
1750 | uri->data.ksk.keywordCount++; | 1738 | uri->data.ksk.keywordCount++; |
1751 | } | 1739 | } |
1740 | GNUNET_free (xtra); | ||
1741 | } | ||
1742 | |||
1743 | normalized_data = normalize_metadata (format, data, data_len); | ||
1744 | if (! find_duplicate (data, | ||
1745 | (const char **) uri->data.ksk.keywords, | ||
1746 | uri->data.ksk.keywordCount)) | ||
1747 | { | ||
1748 | insert_non_mandatory_keyword (data, | ||
1749 | uri->data.ksk.keywords, | ||
1750 | uri->data.ksk.keywordCount); | ||
1751 | uri->data.ksk.keywordCount++; | ||
1752 | } | ||
1752 | if (NULL != normalized_data) | 1753 | if (NULL != normalized_data) |
1753 | { | 1754 | { |
1754 | if (!find_duplicate(normalized_data, | 1755 | if (! find_duplicate (normalized_data, |
1755 | (const char **)uri->data.ksk.keywords, | 1756 | (const char **) uri->data.ksk.keywords, |
1756 | uri->data.ksk.keywordCount)) | 1757 | uri->data.ksk.keywordCount)) |
1757 | { | 1758 | { |
1758 | insert_non_mandatory_keyword(normalized_data, | 1759 | insert_non_mandatory_keyword (normalized_data, |
1759 | uri->data.ksk.keywords, | 1760 | uri->data.ksk.keywords, |
1760 | uri->data.ksk.keywordCount); | 1761 | uri->data.ksk.keywordCount); |
1761 | uri->data.ksk.keywordCount++; | 1762 | uri->data.ksk.keywordCount++; |
1762 | } | ||
1763 | GNUNET_free(normalized_data); | ||
1764 | } | 1763 | } |
1764 | GNUNET_free (normalized_data); | ||
1765 | } | ||
1765 | return 0; | 1766 | return 0; |
1766 | } | 1767 | } |
1767 | 1768 | ||
@@ -1775,7 +1776,7 @@ gather_uri_data(void *cls, | |||
1775 | * @return NULL on error, otherwise a KSK URI | 1776 | * @return NULL on error, otherwise a KSK URI |
1776 | */ | 1777 | */ |
1777 | struct GNUNET_FS_Uri * | 1778 | struct GNUNET_FS_Uri * |
1778 | GNUNET_FS_uri_ksk_create_from_meta_data( | 1779 | GNUNET_FS_uri_ksk_create_from_meta_data ( |
1779 | const struct GNUNET_CONTAINER_MetaData *md) | 1780 | const struct GNUNET_CONTAINER_MetaData *md) |
1780 | { | 1781 | { |
1781 | struct GNUNET_FS_Uri *ret; | 1782 | struct GNUNET_FS_Uri *ret; |
@@ -1788,41 +1789,41 @@ GNUNET_FS_uri_ksk_create_from_meta_data( | |||
1788 | 1789 | ||
1789 | if (NULL == md) | 1790 | if (NULL == md) |
1790 | return NULL; | 1791 | return NULL; |
1791 | ret = GNUNET_new(struct GNUNET_FS_Uri); | 1792 | ret = GNUNET_new (struct GNUNET_FS_Uri); |
1792 | ret->type = GNUNET_FS_URI_KSK; | 1793 | ret->type = GNUNET_FS_URI_KSK; |
1793 | ent = GNUNET_CONTAINER_meta_data_iterate(md, NULL, NULL); | 1794 | ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); |
1794 | if (ent > 0) | 1795 | if (ent > 0) |
1796 | { | ||
1797 | full_name = GNUNET_CONTAINER_meta_data_get_first_by_types ( | ||
1798 | md, | ||
1799 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
1800 | -1); | ||
1801 | if (NULL != full_name) | ||
1795 | { | 1802 | { |
1796 | full_name = GNUNET_CONTAINER_meta_data_get_first_by_types( | 1803 | filename = full_name; |
1797 | md, | 1804 | while (NULL != (ss = strstr (filename, DIR_SEPARATOR_STR))) |
1798 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | 1805 | filename = ss + 1; |
1799 | -1); | 1806 | tok_keywords = get_keywords_from_tokens (filename, NULL, 0); |
1800 | if (NULL != full_name) | 1807 | paren_keywords = get_keywords_from_parens (filename, NULL, 0); |
1801 | { | ||
1802 | filename = full_name; | ||
1803 | while (NULL != (ss = strstr(filename, DIR_SEPARATOR_STR))) | ||
1804 | filename = ss + 1; | ||
1805 | tok_keywords = get_keywords_from_tokens(filename, NULL, 0); | ||
1806 | paren_keywords = get_keywords_from_parens(filename, NULL, 0); | ||
1807 | } | ||
1808 | /* x3 because there might be a normalized variant of every keyword, | ||
1809 | plus theoretically one more for mime... */ | ||
1810 | ret->data.ksk.keywords = | ||
1811 | GNUNET_new_array((ent + tok_keywords + paren_keywords) * 3, char *); | ||
1812 | GNUNET_CONTAINER_meta_data_iterate(md, &gather_uri_data, ret); | ||
1813 | } | 1808 | } |
1809 | /* x3 because there might be a normalized variant of every keyword, | ||
1810 | plus theoretically one more for mime... */ | ||
1811 | ret->data.ksk.keywords = | ||
1812 | GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, char *); | ||
1813 | GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); | ||
1814 | } | ||
1814 | if (tok_keywords > 0) | 1815 | if (tok_keywords > 0) |
1815 | ret->data.ksk.keywordCount += | 1816 | ret->data.ksk.keywordCount += |
1816 | get_keywords_from_tokens(filename, | 1817 | get_keywords_from_tokens (filename, |
1817 | ret->data.ksk.keywords, | 1818 | ret->data.ksk.keywords, |
1818 | ret->data.ksk.keywordCount); | 1819 | ret->data.ksk.keywordCount); |
1819 | if (paren_keywords > 0) | 1820 | if (paren_keywords > 0) |
1820 | ret->data.ksk.keywordCount += | 1821 | ret->data.ksk.keywordCount += |
1821 | get_keywords_from_parens(filename, | 1822 | get_keywords_from_parens (filename, |
1822 | ret->data.ksk.keywords, | 1823 | ret->data.ksk.keywords, |
1823 | ret->data.ksk.keywordCount); | 1824 | ret->data.ksk.keywordCount); |
1824 | if (ent > 0) | 1825 | if (ent > 0) |
1825 | GNUNET_free_non_null(full_name); | 1826 | GNUNET_free_non_null (full_name); |
1826 | return ret; | 1827 | return ret; |
1827 | } | 1828 | } |
1828 | 1829 | ||
@@ -1832,10 +1833,10 @@ GNUNET_FS_uri_ksk_create_from_meta_data( | |||
1832 | * need to be encoded using %-encoding? | 1833 | * need to be encoded using %-encoding? |
1833 | */ | 1834 | */ |
1834 | static int | 1835 | static int |
1835 | needs_percent(char c) | 1836 | needs_percent (char c) |
1836 | { | 1837 | { |
1837 | return(!((isalnum((unsigned char)c)) || (c == '-') || (c == '_') || | 1838 | return(! ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || |
1838 | (c == '.') || (c == '~'))); | 1839 | (c == '.') || (c == '~'))); |
1839 | } | 1840 | } |
1840 | 1841 | ||
1841 | 1842 | ||
@@ -1846,7 +1847,7 @@ needs_percent(char c) | |||
1846 | * @return NULL on error (i.e. keywordCount == 0) | 1847 | * @return NULL on error (i.e. keywordCount == 0) |
1847 | */ | 1848 | */ |
1848 | static char * | 1849 | static char * |
1849 | uri_ksk_to_string(const struct GNUNET_FS_Uri *uri) | 1850 | uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) |
1850 | { | 1851 | { |
1851 | char **keywords; | 1852 | char **keywords; |
1852 | unsigned int keywordCount; | 1853 | unsigned int keywordCount; |
@@ -1862,49 +1863,49 @@ uri_ksk_to_string(const struct GNUNET_FS_Uri *uri) | |||
1862 | return NULL; | 1863 | return NULL; |
1863 | keywords = uri->data.ksk.keywords; | 1864 | keywords = uri->data.ksk.keywords; |
1864 | keywordCount = uri->data.ksk.keywordCount; | 1865 | keywordCount = uri->data.ksk.keywordCount; |
1865 | n = keywordCount + strlen(GNUNET_FS_URI_PREFIX) + | 1866 | n = keywordCount + strlen (GNUNET_FS_URI_PREFIX) |
1866 | strlen(GNUNET_FS_URI_KSK_INFIX) + 1; | 1867 | + strlen (GNUNET_FS_URI_KSK_INFIX) + 1; |
1867 | for (i = 0; i < keywordCount; i++) | 1868 | for (i = 0; i < keywordCount; i++) |
1869 | { | ||
1870 | keyword = keywords[i]; | ||
1871 | slen = strlen (keyword); | ||
1872 | n += slen; | ||
1873 | for (j = 0; j < slen; j++) | ||
1868 | { | 1874 | { |
1869 | keyword = keywords[i]; | 1875 | if ((j == 0) && (keyword[j] == ' ')) |
1870 | slen = strlen(keyword); | 1876 | { |
1871 | n += slen; | 1877 | n--; |
1872 | for (j = 0; j < slen; j++) | 1878 | continue; /* skip leading space */ |
1873 | { | 1879 | } |
1874 | if ((j == 0) && (keyword[j] == ' ')) | 1880 | if (needs_percent (keyword[j])) |
1875 | { | 1881 | n += 2; /* will use %-encoding */ |
1876 | n--; | ||
1877 | continue; /* skip leading space */ | ||
1878 | } | ||
1879 | if (needs_percent(keyword[j])) | ||
1880 | n += 2; /* will use %-encoding */ | ||
1881 | } | ||
1882 | } | 1882 | } |
1883 | ret = GNUNET_malloc(n); | 1883 | } |
1884 | strcpy(ret, GNUNET_FS_URI_PREFIX); | 1884 | ret = GNUNET_malloc (n); |
1885 | strcat(ret, GNUNET_FS_URI_KSK_INFIX); | 1885 | strcpy (ret, GNUNET_FS_URI_PREFIX); |
1886 | wpos = strlen(ret); | 1886 | strcat (ret, GNUNET_FS_URI_KSK_INFIX); |
1887 | wpos = strlen (ret); | ||
1887 | for (i = 0; i < keywordCount; i++) | 1888 | for (i = 0; i < keywordCount; i++) |
1889 | { | ||
1890 | keyword = keywords[i]; | ||
1891 | slen = strlen (keyword); | ||
1892 | for (j = 0; j < slen; j++) | ||
1888 | { | 1893 | { |
1889 | keyword = keywords[i]; | 1894 | if ((j == 0) && (keyword[j] == ' ')) |
1890 | slen = strlen(keyword); | 1895 | continue; /* skip leading space */ |
1891 | for (j = 0; j < slen; j++) | 1896 | if (needs_percent (keyword[j])) |
1892 | { | 1897 | { |
1893 | if ((j == 0) && (keyword[j] == ' ')) | 1898 | sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]); |
1894 | continue; /* skip leading space */ | 1899 | wpos += 3; |
1895 | if (needs_percent(keyword[j])) | 1900 | } |
1896 | { | 1901 | else |
1897 | sprintf(&ret[wpos], "%%%02X", (unsigned char)keyword[j]); | 1902 | { |
1898 | wpos += 3; | 1903 | ret[wpos++] = keyword[j]; |
1899 | } | 1904 | } |
1900 | else | ||
1901 | { | ||
1902 | ret[wpos++] = keyword[j]; | ||
1903 | } | ||
1904 | } | ||
1905 | if (i != keywordCount - 1) | ||
1906 | ret[wpos++] = '+'; | ||
1907 | } | 1905 | } |
1906 | if (i != keywordCount - 1) | ||
1907 | ret[wpos++] = '+'; | ||
1908 | } | ||
1908 | return ret; | 1909 | return ret; |
1909 | } | 1910 | } |
1910 | 1911 | ||
@@ -1916,7 +1917,7 @@ uri_ksk_to_string(const struct GNUNET_FS_Uri *uri) | |||
1916 | * @return NULL on error | 1917 | * @return NULL on error |
1917 | */ | 1918 | */ |
1918 | static char * | 1919 | static char * |
1919 | uri_sks_to_string(const struct GNUNET_FS_Uri *uri) | 1920 | uri_sks_to_string (const struct GNUNET_FS_Uri *uri) |
1920 | { | 1921 | { |
1921 | char *ret; | 1922 | char *ret; |
1922 | char buf[1024]; | 1923 | char buf[1024]; |
@@ -1924,18 +1925,18 @@ uri_sks_to_string(const struct GNUNET_FS_Uri *uri) | |||
1924 | if (GNUNET_FS_URI_SKS != uri->type) | 1925 | if (GNUNET_FS_URI_SKS != uri->type) |
1925 | return NULL; | 1926 | return NULL; |
1926 | ret = | 1927 | ret = |
1927 | GNUNET_STRINGS_data_to_string(&uri->data.sks.ns, | 1928 | GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, |
1928 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 1929 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
1929 | buf, | 1930 | buf, |
1930 | sizeof(buf)); | 1931 | sizeof(buf)); |
1931 | GNUNET_assert(NULL != ret); | 1932 | GNUNET_assert (NULL != ret); |
1932 | ret[0] = '\0'; | 1933 | ret[0] = '\0'; |
1933 | GNUNET_asprintf(&ret, | 1934 | GNUNET_asprintf (&ret, |
1934 | "%s%s%s/%s", | 1935 | "%s%s%s/%s", |
1935 | GNUNET_FS_URI_PREFIX, | 1936 | GNUNET_FS_URI_PREFIX, |
1936 | GNUNET_FS_URI_SKS_INFIX, | 1937 | GNUNET_FS_URI_SKS_INFIX, |
1937 | buf, | 1938 | buf, |
1938 | uri->data.sks.identifier); | 1939 | uri->data.sks.identifier); |
1939 | return ret; | 1940 | return ret; |
1940 | } | 1941 | } |
1941 | 1942 | ||
@@ -1947,7 +1948,7 @@ uri_sks_to_string(const struct GNUNET_FS_Uri *uri) | |||
1947 | * @return NULL on error | 1948 | * @return NULL on error |
1948 | */ | 1949 | */ |
1949 | static char * | 1950 | static char * |
1950 | uri_chk_to_string(const struct GNUNET_FS_Uri *uri) | 1951 | uri_chk_to_string (const struct GNUNET_FS_Uri *uri) |
1951 | { | 1952 | { |
1952 | const struct FileIdentifier *fi; | 1953 | const struct FileIdentifier *fi; |
1953 | char *ret; | 1954 | char *ret; |
@@ -1957,16 +1958,16 @@ uri_chk_to_string(const struct GNUNET_FS_Uri *uri) | |||
1957 | if (uri->type != GNUNET_FS_URI_CHK) | 1958 | if (uri->type != GNUNET_FS_URI_CHK) |
1958 | return NULL; | 1959 | return NULL; |
1959 | fi = &uri->data.chk; | 1960 | fi = &uri->data.chk; |
1960 | GNUNET_CRYPTO_hash_to_enc(&fi->chk.key, &keyhash); | 1961 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); |
1961 | GNUNET_CRYPTO_hash_to_enc(&fi->chk.query, &queryhash); | 1962 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); |
1962 | 1963 | ||
1963 | GNUNET_asprintf(&ret, | 1964 | GNUNET_asprintf (&ret, |
1964 | "%s%s%s.%s.%llu", | 1965 | "%s%s%s.%s.%llu", |
1965 | GNUNET_FS_URI_PREFIX, | 1966 | GNUNET_FS_URI_PREFIX, |
1966 | GNUNET_FS_URI_CHK_INFIX, | 1967 | GNUNET_FS_URI_CHK_INFIX, |
1967 | (const char *)&keyhash, | 1968 | (const char *) &keyhash, |
1968 | (const char *)&queryhash, | 1969 | (const char *) &queryhash, |
1969 | GNUNET_ntohll(fi->file_length)); | 1970 | GNUNET_ntohll (fi->file_length)); |
1970 | return ret; | 1971 | return ret; |
1971 | } | 1972 | } |
1972 | 1973 | ||
@@ -1978,7 +1979,7 @@ uri_chk_to_string(const struct GNUNET_FS_Uri *uri) | |||
1978 | * @return NULL on error | 1979 | * @return NULL on error |
1979 | */ | 1980 | */ |
1980 | static char * | 1981 | static char * |
1981 | uri_loc_to_string(const struct GNUNET_FS_Uri *uri) | 1982 | uri_loc_to_string (const struct GNUNET_FS_Uri *uri) |
1982 | { | 1983 | { |
1983 | char *ret; | 1984 | char *ret; |
1984 | struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; | 1985 | struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; |
@@ -1986,30 +1987,30 @@ uri_loc_to_string(const struct GNUNET_FS_Uri *uri) | |||
1986 | char *peer_id; | 1987 | char *peer_id; |
1987 | char peer_sig[SIGNATURE_ASCII_LENGTH + 1]; | 1988 | char peer_sig[SIGNATURE_ASCII_LENGTH + 1]; |
1988 | 1989 | ||
1989 | GNUNET_CRYPTO_hash_to_enc(&uri->data.loc.fi.chk.key, &keyhash); | 1990 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); |
1990 | GNUNET_CRYPTO_hash_to_enc(&uri->data.loc.fi.chk.query, &queryhash); | 1991 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); |
1991 | peer_id = | 1992 | peer_id = |
1992 | GNUNET_CRYPTO_eddsa_public_key_to_string(&uri->data.loc.peer.public_key); | 1993 | GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key); |
1993 | GNUNET_assert( | 1994 | GNUNET_assert ( |
1994 | NULL != | 1995 | NULL != |
1995 | GNUNET_STRINGS_data_to_string(&uri->data.loc.contentSignature, | 1996 | GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, |
1996 | sizeof(struct GNUNET_CRYPTO_EddsaSignature), | 1997 | sizeof(struct GNUNET_CRYPTO_EddsaSignature), |
1997 | peer_sig, | 1998 | peer_sig, |
1998 | sizeof(peer_sig))); | 1999 | sizeof(peer_sig))); |
1999 | GNUNET_asprintf(&ret, | 2000 | GNUNET_asprintf (&ret, |
2000 | "%s%s%s.%s.%llu.%s.%s.%llu", | 2001 | "%s%s%s.%s.%llu.%s.%s.%llu", |
2001 | GNUNET_FS_URI_PREFIX, | 2002 | GNUNET_FS_URI_PREFIX, |
2002 | GNUNET_FS_URI_LOC_INFIX, | 2003 | GNUNET_FS_URI_LOC_INFIX, |
2003 | (const char *)&keyhash, | 2004 | (const char *) &keyhash, |
2004 | (const char *)&queryhash, | 2005 | (const char *) &queryhash, |
2005 | (unsigned long long)GNUNET_ntohll( | 2006 | (unsigned long long) GNUNET_ntohll ( |
2006 | uri->data.loc.fi.file_length), | 2007 | uri->data.loc.fi.file_length), |
2007 | peer_id, | 2008 | peer_id, |
2008 | peer_sig, | 2009 | peer_sig, |
2009 | (unsigned long long) | 2010 | (unsigned long long) |
2010 | uri->data.loc.expirationTime.abs_value_us / | 2011 | uri->data.loc.expirationTime.abs_value_us |
2011 | 1000000LL); | 2012 | / 1000000LL); |
2012 | GNUNET_free(peer_id); | 2013 | GNUNET_free (peer_id); |
2013 | return ret; | 2014 | return ret; |
2014 | } | 2015 | } |
2015 | 2016 | ||
@@ -2021,31 +2022,31 @@ uri_loc_to_string(const struct GNUNET_FS_Uri *uri) | |||
2021 | * @return the UTF-8 string | 2022 | * @return the UTF-8 string |
2022 | */ | 2023 | */ |
2023 | char * | 2024 | char * |
2024 | GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri) | 2025 | GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri) |
2025 | { | 2026 | { |
2026 | if (uri == NULL) | 2027 | if (uri == NULL) |
2027 | { | 2028 | { |
2028 | GNUNET_break(0); | 2029 | GNUNET_break (0); |
2029 | return NULL; | 2030 | return NULL; |
2030 | } | 2031 | } |
2031 | switch (uri->type) | 2032 | switch (uri->type) |
2032 | { | 2033 | { |
2033 | case GNUNET_FS_URI_KSK: | 2034 | case GNUNET_FS_URI_KSK: |
2034 | return uri_ksk_to_string(uri); | 2035 | return uri_ksk_to_string (uri); |
2035 | 2036 | ||
2036 | case GNUNET_FS_URI_SKS: | 2037 | case GNUNET_FS_URI_SKS: |
2037 | return uri_sks_to_string(uri); | 2038 | return uri_sks_to_string (uri); |
2038 | 2039 | ||
2039 | case GNUNET_FS_URI_CHK: | 2040 | case GNUNET_FS_URI_CHK: |
2040 | return uri_chk_to_string(uri); | 2041 | return uri_chk_to_string (uri); |
2041 | 2042 | ||
2042 | case GNUNET_FS_URI_LOC: | 2043 | case GNUNET_FS_URI_LOC: |
2043 | return uri_loc_to_string(uri); | 2044 | return uri_loc_to_string (uri); |
2044 | 2045 | ||
2045 | default: | 2046 | default: |
2046 | GNUNET_break(0); | 2047 | GNUNET_break (0); |
2047 | return NULL; | 2048 | return NULL; |
2048 | } | 2049 | } |
2049 | } | 2050 | } |
2050 | 2051 | ||
2051 | /* end of fs_uri.c */ | 2052 | /* end of fs_uri.c */ |
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index 6fc71ebe5..dc1912f09 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c | |||
@@ -29,7 +29,7 @@ | |||
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | 31 | ||
32 | #define MAX_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) | 32 | #define MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) |
33 | 33 | ||
34 | #define MIN_DELAY GNUNET_TIME_UNIT_MINUTES | 34 | #define MIN_DELAY GNUNET_TIME_UNIT_MINUTES |
35 | 35 | ||
@@ -38,7 +38,8 @@ | |||
38 | * Item in our work queue (or in the set of files/directories | 38 | * Item in our work queue (or in the set of files/directories |
39 | * we have successfully published). | 39 | * we have successfully published). |
40 | */ | 40 | */ |
41 | struct WorkItem { | 41 | struct WorkItem |
42 | { | ||
42 | /** | 43 | /** |
43 | * PENDING Work is kept in a linked list. | 44 | * PENDING Work is kept in a linked list. |
44 | */ | 45 | */ |
@@ -160,16 +161,16 @@ static struct GNUNET_OS_Process *publish_proc; | |||
160 | * Compute the name of the state database file we will use. | 161 | * Compute the name of the state database file we will use. |
161 | */ | 162 | */ |
162 | static char * | 163 | static char * |
163 | get_state_file() | 164 | get_state_file () |
164 | { | 165 | { |
165 | char *ret; | 166 | char *ret; |
166 | 167 | ||
167 | GNUNET_asprintf(&ret, | 168 | GNUNET_asprintf (&ret, |
168 | "%s%s.auto-share", | 169 | "%s%s.auto-share", |
169 | dir_name, | 170 | dir_name, |
170 | (DIR_SEPARATOR == dir_name[strlen(dir_name) - 1]) | 171 | (DIR_SEPARATOR == dir_name[strlen (dir_name) - 1]) |
171 | ? "" | 172 | ? "" |
172 | : DIR_SEPARATOR_STR); | 173 | : DIR_SEPARATOR_STR); |
173 | return ret; | 174 | return ret; |
174 | } | 175 | } |
175 | 176 | ||
@@ -178,7 +179,7 @@ get_state_file() | |||
178 | * Load the set of #work_finished items from disk. | 179 | * Load the set of #work_finished items from disk. |
179 | */ | 180 | */ |
180 | static void | 181 | static void |
181 | load_state() | 182 | load_state () |
182 | { | 183 | { |
183 | char *fn; | 184 | char *fn; |
184 | struct GNUNET_BIO_ReadHandle *rh; | 185 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -188,47 +189,47 @@ load_state() | |||
188 | char *emsg; | 189 | char *emsg; |
189 | 190 | ||
190 | emsg = NULL; | 191 | emsg = NULL; |
191 | fn = get_state_file(); | 192 | fn = get_state_file (); |
192 | rh = GNUNET_BIO_read_open(fn); | 193 | rh = GNUNET_BIO_read_open (fn); |
193 | GNUNET_free(fn); | 194 | GNUNET_free (fn); |
194 | if (NULL == rh) | 195 | if (NULL == rh) |
195 | return; | 196 | return; |
196 | fn = NULL; | 197 | fn = NULL; |
197 | if (GNUNET_OK != GNUNET_BIO_read_int32(rh, &n)) | 198 | if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &n)) |
198 | goto error; | 199 | goto error; |
199 | while (n-- > 0) | 200 | while (n-- > 0) |
200 | { | 201 | { |
201 | if ((GNUNET_OK != GNUNET_BIO_read_string(rh, "filename", &fn, 1024)) || | 202 | if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) || |
202 | (GNUNET_OK != | 203 | (GNUNET_OK != |
203 | GNUNET_BIO_read(rh, "id", &id, sizeof(struct GNUNET_HashCode)))) | 204 | GNUNET_BIO_read (rh, "id", &id, sizeof(struct GNUNET_HashCode)))) |
204 | goto error; | 205 | goto error; |
205 | wi = GNUNET_new(struct WorkItem); | 206 | wi = GNUNET_new (struct WorkItem); |
206 | wi->id = id; | 207 | wi->id = id; |
207 | wi->filename = fn; | 208 | wi->filename = fn; |
208 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
209 | "Loaded serialization ID for `%s' is `%s'\n", | 210 | "Loaded serialization ID for `%s' is `%s'\n", |
210 | wi->filename, | 211 | wi->filename, |
211 | GNUNET_h2s(&id)); | 212 | GNUNET_h2s (&id)); |
212 | fn = NULL; | 213 | fn = NULL; |
213 | GNUNET_CRYPTO_hash(wi->filename, strlen(wi->filename), &id); | 214 | GNUNET_CRYPTO_hash (wi->filename, strlen (wi->filename), &id); |
214 | GNUNET_break(GNUNET_OK == | 215 | GNUNET_break (GNUNET_OK == |
215 | GNUNET_CONTAINER_multihashmap_put( | 216 | GNUNET_CONTAINER_multihashmap_put ( |
216 | work_finished, | 217 | work_finished, |
217 | &id, | 218 | &id, |
218 | wi, | 219 | wi, |
219 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 220 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
220 | } | 221 | } |
221 | if (GNUNET_OK == GNUNET_BIO_read_close(rh, &emsg)) | 222 | if (GNUNET_OK == GNUNET_BIO_read_close (rh, &emsg)) |
222 | return; | 223 | return; |
223 | rh = NULL; | 224 | rh = NULL; |
224 | error: | 225 | error: |
225 | GNUNET_free_non_null(fn); | 226 | GNUNET_free_non_null (fn); |
226 | if (NULL != rh) | 227 | if (NULL != rh) |
227 | (void)GNUNET_BIO_read_close(rh, &emsg); | 228 | (void) GNUNET_BIO_read_close (rh, &emsg); |
228 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 229 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
229 | _("Failed to load state: %s\n"), | 230 | _ ("Failed to load state: %s\n"), |
230 | emsg); | 231 | emsg); |
231 | GNUNET_free_non_null(emsg); | 232 | GNUNET_free_non_null (emsg); |
232 | } | 233 | } |
233 | 234 | ||
234 | 235 | ||
@@ -241,18 +242,18 @@ error: | |||
241 | * @return #GNUNET_OK to continue to iterate (if write worked) | 242 | * @return #GNUNET_OK to continue to iterate (if write worked) |
242 | */ | 243 | */ |
243 | static int | 244 | static int |
244 | write_item(void *cls, const struct GNUNET_HashCode *key, void *value) | 245 | write_item (void *cls, const struct GNUNET_HashCode *key, void *value) |
245 | { | 246 | { |
246 | struct GNUNET_BIO_WriteHandle *wh = cls; | 247 | struct GNUNET_BIO_WriteHandle *wh = cls; |
247 | struct WorkItem *wi = value; | 248 | struct WorkItem *wi = value; |
248 | 249 | ||
249 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
250 | "Saving serialization ID of file `%s' with value `%s'\n", | 251 | "Saving serialization ID of file `%s' with value `%s'\n", |
251 | wi->filename, | 252 | wi->filename, |
252 | GNUNET_h2s(&wi->id)); | 253 | GNUNET_h2s (&wi->id)); |
253 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, wi->filename)) || | 254 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, wi->filename)) || |
254 | (GNUNET_OK != | 255 | (GNUNET_OK != |
255 | GNUNET_BIO_write(wh, &wi->id, sizeof(struct GNUNET_HashCode)))) | 256 | GNUNET_BIO_write (wh, &wi->id, sizeof(struct GNUNET_HashCode)))) |
256 | return GNUNET_SYSERR; /* write error, abort iteration */ | 257 | return GNUNET_SYSERR; /* write error, abort iteration */ |
257 | return GNUNET_OK; | 258 | return GNUNET_OK; |
258 | } | 259 | } |
@@ -262,38 +263,38 @@ write_item(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
262 | * Save the set of #work_finished items on disk. | 263 | * Save the set of #work_finished items on disk. |
263 | */ | 264 | */ |
264 | static void | 265 | static void |
265 | save_state() | 266 | save_state () |
266 | { | 267 | { |
267 | uint32_t n; | 268 | uint32_t n; |
268 | struct GNUNET_BIO_WriteHandle *wh; | 269 | struct GNUNET_BIO_WriteHandle *wh; |
269 | char *fn; | 270 | char *fn; |
270 | 271 | ||
271 | n = GNUNET_CONTAINER_multihashmap_size(work_finished); | 272 | n = GNUNET_CONTAINER_multihashmap_size (work_finished); |
272 | fn = get_state_file(); | 273 | fn = get_state_file (); |
273 | wh = GNUNET_BIO_write_open(fn); | 274 | wh = GNUNET_BIO_write_open (fn); |
274 | if (NULL == wh) | 275 | if (NULL == wh) |
275 | { | 276 | { |
276 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 277 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
277 | _("Failed to save state to file %s\n"), | 278 | _ ("Failed to save state to file %s\n"), |
278 | fn); | 279 | fn); |
279 | GNUNET_free(fn); | 280 | GNUNET_free (fn); |
280 | return; | 281 | return; |
281 | } | 282 | } |
282 | if (GNUNET_OK != GNUNET_BIO_write_int32(wh, n)) | 283 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, n)) |
283 | { | 284 | { |
284 | (void)GNUNET_BIO_write_close(wh); | 285 | (void) GNUNET_BIO_write_close (wh); |
285 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 286 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
286 | _("Failed to save state to file %s\n"), | 287 | _ ("Failed to save state to file %s\n"), |
287 | fn); | 288 | fn); |
288 | GNUNET_free(fn); | 289 | GNUNET_free (fn); |
289 | return; | 290 | return; |
290 | } | 291 | } |
291 | (void)GNUNET_CONTAINER_multihashmap_iterate(work_finished, &write_item, wh); | 292 | (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, &write_item, wh); |
292 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) | 293 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) |
293 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 294 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
294 | _("Failed to save state to file %s\n"), | 295 | _ ("Failed to save state to file %s\n"), |
295 | fn); | 296 | fn); |
296 | GNUNET_free(fn); | 297 | GNUNET_free (fn); |
297 | } | 298 | } |
298 | 299 | ||
299 | 300 | ||
@@ -303,19 +304,19 @@ save_state() | |||
303 | * @param cls closure, unused | 304 | * @param cls closure, unused |
304 | */ | 305 | */ |
305 | static void | 306 | static void |
306 | do_stop_task(void *cls) | 307 | do_stop_task (void *cls) |
307 | { | 308 | { |
308 | do_shutdown = GNUNET_YES; | 309 | do_shutdown = GNUNET_YES; |
309 | if (NULL != publish_proc) | 310 | if (NULL != publish_proc) |
310 | { | 311 | { |
311 | GNUNET_OS_process_kill(publish_proc, SIGKILL); | 312 | GNUNET_OS_process_kill (publish_proc, SIGKILL); |
312 | return; | 313 | return; |
313 | } | 314 | } |
314 | if (NULL != run_task) | 315 | if (NULL != run_task) |
315 | { | 316 | { |
316 | GNUNET_SCHEDULER_cancel(run_task); | 317 | GNUNET_SCHEDULER_cancel (run_task); |
317 | run_task = NULL; | 318 | run_task = NULL; |
318 | } | 319 | } |
319 | } | 320 | } |
320 | 321 | ||
321 | 322 | ||
@@ -323,7 +324,7 @@ do_stop_task(void *cls) | |||
323 | * Decide what the next task is (working or scanning) and schedule it. | 324 | * Decide what the next task is (working or scanning) and schedule it. |
324 | */ | 325 | */ |
325 | static void | 326 | static void |
326 | schedule_next_task(void); | 327 | schedule_next_task (void); |
327 | 328 | ||
328 | 329 | ||
329 | /** | 330 | /** |
@@ -333,7 +334,7 @@ schedule_next_task(void); | |||
333 | * @param cls the `struct WorkItem` we were working on | 334 | * @param cls the `struct WorkItem` we were working on |
334 | */ | 335 | */ |
335 | static void | 336 | static void |
336 | maint_child_death(void *cls) | 337 | maint_child_death (void *cls) |
337 | { | 338 | { |
338 | struct WorkItem *wi = cls; | 339 | struct WorkItem *wi = cls; |
339 | struct GNUNET_HashCode key; | 340 | struct GNUNET_HashCode key; |
@@ -345,65 +346,65 @@ maint_child_death(void *cls) | |||
345 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 346 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
346 | 347 | ||
347 | run_task = NULL; | 348 | run_task = NULL; |
348 | pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); | 349 | pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); |
349 | tc = GNUNET_SCHEDULER_get_task_context(); | 350 | tc = GNUNET_SCHEDULER_get_task_context (); |
350 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) | 351 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) |
351 | { | 352 | { |
352 | /* shutdown scheduled us, someone else will kill child, | 353 | /* shutdown scheduled us, someone else will kill child, |
353 | we should just try again */ | 354 | we should just try again */ |
354 | run_task = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, | 355 | run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
355 | pr, | 356 | pr, |
356 | &maint_child_death, | 357 | &maint_child_death, |
357 | wi); | 358 | wi); |
358 | return; | 359 | return; |
359 | } | 360 | } |
360 | /* consume the signal */ | 361 | /* consume the signal */ |
361 | GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); | 362 | GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c))); |
362 | 363 | ||
363 | ret = GNUNET_OS_process_status(publish_proc, &type, &code); | 364 | ret = GNUNET_OS_process_status (publish_proc, &type, &code); |
364 | GNUNET_assert(GNUNET_SYSERR != ret); | 365 | GNUNET_assert (GNUNET_SYSERR != ret); |
365 | if (GNUNET_NO == ret) | 366 | if (GNUNET_NO == ret) |
366 | { | 367 | { |
367 | /* process still running? Then where did the SIGCHLD come from? | 368 | /* process still running? Then where did the SIGCHLD come from? |
368 | Well, let's declare it spurious (kernel bug?) and keep rolling. | 369 | Well, let's declare it spurious (kernel bug?) and keep rolling. |
369 | */ | 370 | */ |
370 | GNUNET_break(0); | 371 | GNUNET_break (0); |
371 | run_task = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, | 372 | run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
372 | pr, | 373 | pr, |
373 | &maint_child_death, | 374 | &maint_child_death, |
374 | wi); | 375 | wi); |
375 | return; | 376 | return; |
376 | } | 377 | } |
377 | GNUNET_assert(GNUNET_OK == ret); | 378 | GNUNET_assert (GNUNET_OK == ret); |
378 | 379 | ||
379 | GNUNET_OS_process_destroy(publish_proc); | 380 | GNUNET_OS_process_destroy (publish_proc); |
380 | publish_proc = NULL; | 381 | publish_proc = NULL; |
381 | 382 | ||
382 | if (GNUNET_YES == do_shutdown) | 383 | if (GNUNET_YES == do_shutdown) |
383 | { | 384 | { |
384 | GNUNET_free(wi->filename); | 385 | GNUNET_free (wi->filename); |
385 | GNUNET_free(wi); | 386 | GNUNET_free (wi); |
386 | return; | 387 | return; |
387 | } | 388 | } |
388 | if ((GNUNET_OS_PROCESS_EXITED == type) && (0 == code)) | 389 | if ((GNUNET_OS_PROCESS_EXITED == type) && (0 == code)) |
389 | { | 390 | { |
390 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 391 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
391 | _("Publication of `%s' done\n"), | 392 | _ ("Publication of `%s' done\n"), |
392 | wi->filename); | 393 | wi->filename); |
393 | GNUNET_CRYPTO_hash(wi->filename, strlen(wi->filename), &key); | 394 | GNUNET_CRYPTO_hash (wi->filename, strlen (wi->filename), &key); |
394 | GNUNET_break(GNUNET_OK == | 395 | GNUNET_break (GNUNET_OK == |
395 | GNUNET_CONTAINER_multihashmap_put( | 396 | GNUNET_CONTAINER_multihashmap_put ( |
396 | work_finished, | 397 | work_finished, |
397 | &key, | 398 | &key, |
398 | wi, | 399 | wi, |
399 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 400 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
400 | } | 401 | } |
401 | else | 402 | else |
402 | { | 403 | { |
403 | GNUNET_CONTAINER_DLL_insert_tail(work_head, work_tail, wi); | 404 | GNUNET_CONTAINER_DLL_insert_tail (work_head, work_tail, wi); |
404 | } | 405 | } |
405 | save_state(); | 406 | save_state (); |
406 | schedule_next_task(); | 407 | schedule_next_task (); |
407 | } | 408 | } |
408 | 409 | ||
409 | 410 | ||
@@ -412,17 +413,17 @@ maint_child_death(void *cls) | |||
412 | * respective handler by writing to the trigger pipe. | 413 | * respective handler by writing to the trigger pipe. |
413 | */ | 414 | */ |
414 | static void | 415 | static void |
415 | sighandler_child_death() | 416 | sighandler_child_death () |
416 | { | 417 | { |
417 | static char c; | 418 | static char c; |
418 | int old_errno = errno; /* back-up errno */ | 419 | int old_errno = errno; /* back-up errno */ |
419 | 420 | ||
420 | GNUNET_break( | 421 | GNUNET_break ( |
421 | 1 == | 422 | 1 == |
422 | GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle(sigpipe, | 423 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, |
423 | GNUNET_DISK_PIPE_END_WRITE), | 424 | GNUNET_DISK_PIPE_END_WRITE), |
424 | &c, | 425 | &c, |
425 | sizeof(c))); | 426 | sizeof(c))); |
426 | errno = old_errno; /* restore errno */ | 427 | errno = old_errno; /* restore errno */ |
427 | } | 428 | } |
428 | 429 | ||
@@ -433,7 +434,7 @@ sighandler_child_death() | |||
433 | * @param cls closure, NULL | 434 | * @param cls closure, NULL |
434 | */ | 435 | */ |
435 | static void | 436 | static void |
436 | work(void *cls) | 437 | work (void *cls) |
437 | { | 438 | { |
438 | static char *argv[14]; | 439 | static char *argv[14]; |
439 | static char anon_level[20]; | 440 | static char anon_level[20]; |
@@ -445,7 +446,7 @@ work(void *cls) | |||
445 | 446 | ||
446 | run_task = NULL; | 447 | run_task = NULL; |
447 | wi = work_head; | 448 | wi = work_head; |
448 | GNUNET_CONTAINER_DLL_remove(work_head, work_tail, wi); | 449 | GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi); |
449 | argc = 0; | 450 | argc = 0; |
450 | argv[argc++] = "gnunet-publish"; | 451 | argv[argc++] = "gnunet-publish"; |
451 | if (verbose) | 452 | if (verbose) |
@@ -456,41 +457,41 @@ work(void *cls) | |||
456 | argv[argc++] = "-d"; | 457 | argv[argc++] = "-d"; |
457 | argv[argc++] = "-c"; | 458 | argv[argc++] = "-c"; |
458 | argv[argc++] = cfg_filename; | 459 | argv[argc++] = cfg_filename; |
459 | GNUNET_snprintf(anon_level, sizeof(anon_level), "%u", anonymity_level); | 460 | GNUNET_snprintf (anon_level, sizeof(anon_level), "%u", anonymity_level); |
460 | argv[argc++] = "-a"; | 461 | argv[argc++] = "-a"; |
461 | argv[argc++] = anon_level; | 462 | argv[argc++] = anon_level; |
462 | GNUNET_snprintf(content_prio, sizeof(content_prio), "%u", content_priority); | 463 | GNUNET_snprintf (content_prio, sizeof(content_prio), "%u", content_priority); |
463 | argv[argc++] = "-p"; | 464 | argv[argc++] = "-p"; |
464 | argv[argc++] = content_prio; | 465 | argv[argc++] = content_prio; |
465 | GNUNET_snprintf(repl_level, sizeof(repl_level), "%u", replication_level); | 466 | GNUNET_snprintf (repl_level, sizeof(repl_level), "%u", replication_level); |
466 | argv[argc++] = "-r"; | 467 | argv[argc++] = "-r"; |
467 | argv[argc++] = repl_level; | 468 | argv[argc++] = repl_level; |
468 | argv[argc++] = wi->filename; | 469 | argv[argc++] = wi->filename; |
469 | argv[argc] = NULL; | 470 | argv[argc] = NULL; |
470 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Publishing `%s'\n"), wi->filename); | 471 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Publishing `%s'\n"), wi->filename); |
471 | GNUNET_assert(NULL == publish_proc); | 472 | GNUNET_assert (NULL == publish_proc); |
472 | publish_proc = GNUNET_OS_start_process_vap(GNUNET_YES, | 473 | publish_proc = GNUNET_OS_start_process_vap (GNUNET_YES, |
473 | 0, | 474 | 0, |
474 | NULL, | 475 | NULL, |
475 | NULL, | 476 | NULL, |
476 | NULL, | 477 | NULL, |
477 | "gnunet-publish", | 478 | "gnunet-publish", |
478 | argv); | 479 | argv); |
479 | if (NULL == publish_proc) | 480 | if (NULL == publish_proc) |
480 | { | 481 | { |
481 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 482 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
482 | _("Failed to run `%s'\n"), | 483 | _ ("Failed to run `%s'\n"), |
483 | "gnunet-publish"); | 484 | "gnunet-publish"); |
484 | GNUNET_CONTAINER_DLL_insert(work_head, work_tail, wi); | 485 | GNUNET_CONTAINER_DLL_insert (work_head, work_tail, wi); |
485 | run_task = | 486 | run_task = |
486 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, &work, NULL); | 487 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &work, NULL); |
487 | return; | 488 | return; |
488 | } | 489 | } |
489 | pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); | 490 | pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); |
490 | run_task = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, | 491 | run_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
491 | pr, | 492 | pr, |
492 | &maint_child_death, | 493 | &maint_child_death, |
493 | wi); | 494 | wi); |
494 | } | 495 | } |
495 | 496 | ||
496 | 497 | ||
@@ -503,39 +504,39 @@ work(void *cls) | |||
503 | * @return #GNUNET_OK (always) | 504 | * @return #GNUNET_OK (always) |
504 | */ | 505 | */ |
505 | static int | 506 | static int |
506 | determine_id(void *cls, const char *filename) | 507 | determine_id (void *cls, const char *filename) |
507 | { | 508 | { |
508 | struct GNUNET_HashCode *id = cls; | 509 | struct GNUNET_HashCode *id = cls; |
509 | struct stat sbuf; | 510 | struct stat sbuf; |
510 | struct GNUNET_HashCode fx[2]; | 511 | struct GNUNET_HashCode fx[2]; |
511 | struct GNUNET_HashCode ft; | 512 | struct GNUNET_HashCode ft; |
512 | 513 | ||
513 | if (0 != stat(filename, &sbuf)) | 514 | if (0 != stat (filename, &sbuf)) |
514 | { | 515 | { |
515 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 516 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
516 | return GNUNET_OK; | 517 | return GNUNET_OK; |
517 | } | 518 | } |
518 | GNUNET_CRYPTO_hash(filename, strlen(filename), &fx[0]); | 519 | GNUNET_CRYPTO_hash (filename, strlen (filename), &fx[0]); |
519 | if (!S_ISDIR(sbuf.st_mode)) | 520 | if (! S_ISDIR (sbuf.st_mode)) |
520 | { | 521 | { |
521 | uint64_t fattr[2]; | 522 | uint64_t fattr[2]; |
522 | 523 | ||
523 | fattr[0] = GNUNET_htonll(sbuf.st_size); | 524 | fattr[0] = GNUNET_htonll (sbuf.st_size); |
524 | fattr[0] = GNUNET_htonll(sbuf.st_mtime); | 525 | fattr[0] = GNUNET_htonll (sbuf.st_mtime); |
525 | 526 | ||
526 | GNUNET_CRYPTO_hash(fattr, sizeof(fattr), &fx[1]); | 527 | GNUNET_CRYPTO_hash (fattr, sizeof(fattr), &fx[1]); |
527 | } | 528 | } |
528 | else | 529 | else |
529 | { | 530 | { |
530 | memset(&fx[1], 1, sizeof(struct GNUNET_HashCode)); | 531 | memset (&fx[1], 1, sizeof(struct GNUNET_HashCode)); |
531 | GNUNET_DISK_directory_scan(filename, &determine_id, &fx[1]); | 532 | GNUNET_DISK_directory_scan (filename, &determine_id, &fx[1]); |
532 | } | 533 | } |
533 | /* use hash here to make hierarchical structure distinct from | 534 | /* use hash here to make hierarchical structure distinct from |
534 | all files on the same level */ | 535 | all files on the same level */ |
535 | GNUNET_CRYPTO_hash(fx, sizeof(fx), &ft); | 536 | GNUNET_CRYPTO_hash (fx, sizeof(fx), &ft); |
536 | /* use XOR here so that order of the files in the directory | 537 | /* use XOR here so that order of the files in the directory |
537 | does not matter! */ | 538 | does not matter! */ |
538 | GNUNET_CRYPTO_hash_xor(&ft, id, id); | 539 | GNUNET_CRYPTO_hash_xor (&ft, id, id); |
539 | return GNUNET_OK; | 540 | return GNUNET_OK; |
540 | } | 541 | } |
541 | 542 | ||
@@ -550,7 +551,7 @@ determine_id(void *cls, const char *filename) | |||
550 | * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR during shutdown | 551 | * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR during shutdown |
551 | */ | 552 | */ |
552 | static int | 553 | static int |
553 | add_file(void *cls, const char *filename) | 554 | add_file (void *cls, const char *filename) |
554 | { | 555 | { |
555 | struct WorkItem *wi; | 556 | struct WorkItem *wi; |
556 | struct GNUNET_HashCode key; | 557 | struct GNUNET_HashCode key; |
@@ -558,29 +559,29 @@ add_file(void *cls, const char *filename) | |||
558 | 559 | ||
559 | if (GNUNET_YES == do_shutdown) | 560 | if (GNUNET_YES == do_shutdown) |
560 | return GNUNET_SYSERR; | 561 | return GNUNET_SYSERR; |
561 | if ((NULL != strstr(filename, "/.auto-share")) || | 562 | if ((NULL != strstr (filename, "/.auto-share")) || |
562 | (NULL != strstr(filename, "\\.auto-share"))) | 563 | (NULL != strstr (filename, "\\.auto-share"))) |
563 | return GNUNET_OK; /* skip internal file */ | 564 | return GNUNET_OK; /* skip internal file */ |
564 | GNUNET_CRYPTO_hash(filename, strlen(filename), &key); | 565 | GNUNET_CRYPTO_hash (filename, strlen (filename), &key); |
565 | wi = GNUNET_CONTAINER_multihashmap_get(work_finished, &key); | 566 | wi = GNUNET_CONTAINER_multihashmap_get (work_finished, &key); |
566 | memset(&id, 0, sizeof(struct GNUNET_HashCode)); | 567 | memset (&id, 0, sizeof(struct GNUNET_HashCode)); |
567 | determine_id(&id, filename); | 568 | determine_id (&id, filename); |
568 | if (NULL != wi) | 569 | if (NULL != wi) |
569 | { | 570 | { |
570 | if (0 == memcmp(&id, &wi->id, sizeof(struct GNUNET_HashCode))) | 571 | if (0 == memcmp (&id, &wi->id, sizeof(struct GNUNET_HashCode))) |
571 | return GNUNET_OK; /* skip: we did this one already */ | 572 | return GNUNET_OK; /* skip: we did this one already */ |
572 | /* contents changed, need to re-do the directory... */ | 573 | /* contents changed, need to re-do the directory... */ |
573 | GNUNET_assert( | 574 | GNUNET_assert ( |
574 | GNUNET_YES == | 575 | GNUNET_YES == |
575 | GNUNET_CONTAINER_multihashmap_remove(work_finished, &key, wi)); | 576 | GNUNET_CONTAINER_multihashmap_remove (work_finished, &key, wi)); |
576 | } | 577 | } |
577 | else | 578 | else |
578 | { | 579 | { |
579 | wi = GNUNET_new(struct WorkItem); | 580 | wi = GNUNET_new (struct WorkItem); |
580 | wi->filename = GNUNET_strdup(filename); | 581 | wi->filename = GNUNET_strdup (filename); |
581 | } | 582 | } |
582 | wi->id = id; | 583 | wi->id = id; |
583 | GNUNET_CONTAINER_DLL_insert(work_head, work_tail, wi); | 584 | GNUNET_CONTAINER_DLL_insert (work_head, work_tail, wi); |
584 | if (GNUNET_YES == do_shutdown) | 585 | if (GNUNET_YES == do_shutdown) |
585 | return GNUNET_SYSERR; | 586 | return GNUNET_SYSERR; |
586 | return GNUNET_OK; | 587 | return GNUNET_OK; |
@@ -593,12 +594,12 @@ add_file(void *cls, const char *filename) | |||
593 | * @param cls NULL | 594 | * @param cls NULL |
594 | */ | 595 | */ |
595 | static void | 596 | static void |
596 | scan(void *cls) | 597 | scan (void *cls) |
597 | { | 598 | { |
598 | run_task = NULL; | 599 | run_task = NULL; |
599 | start_time = GNUNET_TIME_absolute_get(); | 600 | start_time = GNUNET_TIME_absolute_get (); |
600 | (void)GNUNET_DISK_directory_scan(dir_name, &add_file, NULL); | 601 | (void) GNUNET_DISK_directory_scan (dir_name, &add_file, NULL); |
601 | schedule_next_task(); | 602 | schedule_next_task (); |
602 | } | 603 | } |
603 | 604 | ||
604 | 605 | ||
@@ -606,27 +607,27 @@ scan(void *cls) | |||
606 | * Decide what the next task is (working or scanning) and schedule it. | 607 | * Decide what the next task is (working or scanning) and schedule it. |
607 | */ | 608 | */ |
608 | static void | 609 | static void |
609 | schedule_next_task() | 610 | schedule_next_task () |
610 | { | 611 | { |
611 | struct GNUNET_TIME_Relative delay; | 612 | struct GNUNET_TIME_Relative delay; |
612 | 613 | ||
613 | if (GNUNET_YES == do_shutdown) | 614 | if (GNUNET_YES == do_shutdown) |
614 | return; | 615 | return; |
615 | GNUNET_assert(NULL == run_task); | 616 | GNUNET_assert (NULL == run_task); |
616 | if (NULL == work_head) | 617 | if (NULL == work_head) |
617 | { | 618 | { |
618 | /* delay by at most 4h, at least 1s, and otherwise in between depending | 619 | /* delay by at most 4h, at least 1s, and otherwise in between depending |
619 | on how long it took to scan */ | 620 | on how long it took to scan */ |
620 | delay = GNUNET_TIME_absolute_get_duration(start_time); | 621 | delay = GNUNET_TIME_absolute_get_duration (start_time); |
621 | delay = GNUNET_TIME_relative_saturating_multiply(delay, 100); | 622 | delay = GNUNET_TIME_relative_saturating_multiply (delay, 100); |
622 | delay = GNUNET_TIME_relative_min(delay, MAX_DELAY); | 623 | delay = GNUNET_TIME_relative_min (delay, MAX_DELAY); |
623 | delay = GNUNET_TIME_relative_max(delay, MIN_DELAY); | 624 | delay = GNUNET_TIME_relative_max (delay, MIN_DELAY); |
624 | run_task = GNUNET_SCHEDULER_add_delayed(delay, &scan, NULL); | 625 | run_task = GNUNET_SCHEDULER_add_delayed (delay, &scan, NULL); |
625 | } | 626 | } |
626 | else | 627 | else |
627 | { | 628 | { |
628 | run_task = GNUNET_SCHEDULER_add_now(&work, NULL); | 629 | run_task = GNUNET_SCHEDULER_add_now (&work, NULL); |
629 | } | 630 | } |
630 | } | 631 | } |
631 | 632 | ||
632 | 633 | ||
@@ -639,29 +640,29 @@ schedule_next_task() | |||
639 | * @param c configuration | 640 | * @param c configuration |
640 | */ | 641 | */ |
641 | static void | 642 | static void |
642 | run(void *cls, | 643 | run (void *cls, |
643 | char *const *args, | 644 | char *const *args, |
644 | const char *cfgfile, | 645 | const char *cfgfile, |
645 | const struct GNUNET_CONFIGURATION_Handle *c) | 646 | const struct GNUNET_CONFIGURATION_Handle *c) |
646 | { | 647 | { |
647 | /* check arguments */ | 648 | /* check arguments */ |
648 | if ((NULL == args[0]) || (NULL != args[1]) || | 649 | if ((NULL == args[0]) || (NULL != args[1]) || |
649 | (GNUNET_YES != GNUNET_DISK_directory_test(args[0], GNUNET_YES))) | 650 | (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES))) |
650 | { | 651 | { |
651 | printf(_( | 652 | printf (_ ( |
652 | "You must specify one and only one directory name for automatic publication.\n")); | 653 | "You must specify one and only one directory name for automatic publication.\n")); |
653 | ret = -1; | 654 | ret = -1; |
654 | return; | 655 | return; |
655 | } | 656 | } |
656 | cfg_filename = GNUNET_strdup(cfgfile); | 657 | cfg_filename = GNUNET_strdup (cfgfile); |
657 | cfg = c; | 658 | cfg = c; |
658 | dir_name = args[0]; | 659 | dir_name = args[0]; |
659 | work_finished = GNUNET_CONTAINER_multihashmap_create(1024, GNUNET_NO); | 660 | work_finished = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); |
660 | load_state(); | 661 | load_state (); |
661 | run_task = GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, | 662 | run_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
662 | &scan, | 663 | &scan, |
663 | NULL); | 664 | NULL); |
664 | GNUNET_SCHEDULER_add_shutdown(&do_stop_task, NULL); | 665 | GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL); |
665 | } | 666 | } |
666 | 667 | ||
667 | 668 | ||
@@ -674,12 +675,12 @@ run(void *cls, | |||
674 | * @return #GNUNET_OK to continue to iterate | 675 | * @return #GNUNET_OK to continue to iterate |
675 | */ | 676 | */ |
676 | static int | 677 | static int |
677 | free_item(void *cls, const struct GNUNET_HashCode *key, void *value) | 678 | free_item (void *cls, const struct GNUNET_HashCode *key, void *value) |
678 | { | 679 | { |
679 | struct WorkItem *wi = value; | 680 | struct WorkItem *wi = value; |
680 | 681 | ||
681 | GNUNET_free(wi->filename); | 682 | GNUNET_free (wi->filename); |
682 | GNUNET_free(wi); | 683 | GNUNET_free (wi); |
683 | return GNUNET_OK; | 684 | return GNUNET_OK; |
684 | } | 685 | } |
685 | 686 | ||
@@ -692,44 +693,44 @@ free_item(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
692 | * @return 0 ok, 1 on error | 693 | * @return 0 ok, 1 on error |
693 | */ | 694 | */ |
694 | int | 695 | int |
695 | main(int argc, char *const *argv) | 696 | main (int argc, char *const *argv) |
696 | { | 697 | { |
697 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 698 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
698 | GNUNET_GETOPT_option_uint('a', | 699 | GNUNET_GETOPT_option_uint ('a', |
699 | "anonymity", | 700 | "anonymity", |
700 | "LEVEL", | 701 | "LEVEL", |
701 | gettext_noop( | 702 | gettext_noop ( |
702 | "set the desired LEVEL of sender-anonymity"), | 703 | "set the desired LEVEL of sender-anonymity"), |
703 | &anonymity_level), | 704 | &anonymity_level), |
704 | 705 | ||
705 | GNUNET_GETOPT_option_flag( | 706 | GNUNET_GETOPT_option_flag ( |
706 | 'd', | 707 | 'd', |
707 | "disable-creation-time", | 708 | "disable-creation-time", |
708 | gettext_noop( | 709 | gettext_noop ( |
709 | "disable adding the creation time to the metadata of the uploaded file"), | 710 | "disable adding the creation time to the metadata of the uploaded file"), |
710 | &do_disable_creation_time), | 711 | &do_disable_creation_time), |
711 | 712 | ||
712 | GNUNET_GETOPT_option_flag( | 713 | GNUNET_GETOPT_option_flag ( |
713 | 'D', | 714 | 'D', |
714 | "disable-extractor", | 715 | "disable-extractor", |
715 | gettext_noop("do not use libextractor to add keywords or metadata"), | 716 | gettext_noop ("do not use libextractor to add keywords or metadata"), |
716 | &disable_extractor), | 717 | &disable_extractor), |
717 | 718 | ||
718 | GNUNET_GETOPT_option_uint('p', | 719 | GNUNET_GETOPT_option_uint ('p', |
719 | "priority", | 720 | "priority", |
720 | "PRIORITY", | 721 | "PRIORITY", |
721 | gettext_noop( | 722 | gettext_noop ( |
722 | "specify the priority of the content"), | 723 | "specify the priority of the content"), |
723 | &content_priority), | 724 | &content_priority), |
724 | 725 | ||
725 | GNUNET_GETOPT_option_uint('r', | 726 | GNUNET_GETOPT_option_uint ('r', |
726 | "replication", | 727 | "replication", |
727 | "LEVEL", | 728 | "LEVEL", |
728 | gettext_noop( | 729 | gettext_noop ( |
729 | "set the desired replication LEVEL"), | 730 | "set the desired replication LEVEL"), |
730 | &replication_level), | 731 | &replication_level), |
731 | 732 | ||
732 | GNUNET_GETOPT_option_verbose(&verbose), | 733 | GNUNET_GETOPT_option_verbose (&verbose), |
733 | 734 | ||
734 | GNUNET_GETOPT_OPTION_END | 735 | GNUNET_GETOPT_OPTION_END |
735 | }; | 736 | }; |
@@ -737,44 +738,44 @@ main(int argc, char *const *argv) | |||
737 | int ok; | 738 | int ok; |
738 | struct GNUNET_SIGNAL_Context *shc_chld; | 739 | struct GNUNET_SIGNAL_Context *shc_chld; |
739 | 740 | ||
740 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 741 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
741 | return 2; | 742 | return 2; |
742 | sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); | 743 | sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); |
743 | GNUNET_assert(NULL != sigpipe); | 744 | GNUNET_assert (NULL != sigpipe); |
744 | shc_chld = | 745 | shc_chld = |
745 | GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); | 746 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); |
746 | ok = | 747 | ok = |
747 | (GNUNET_OK == | 748 | (GNUNET_OK == |
748 | GNUNET_PROGRAM_run( | 749 | GNUNET_PROGRAM_run ( |
749 | argc, | 750 | argc, |
750 | argv, | 751 | argv, |
751 | "gnunet-auto-share [OPTIONS] FILENAME", | 752 | "gnunet-auto-share [OPTIONS] FILENAME", |
752 | gettext_noop("Automatically publish files from a directory on GNUnet"), | 753 | gettext_noop ("Automatically publish files from a directory on GNUnet"), |
753 | options, | 754 | options, |
754 | &run, | 755 | &run, |
755 | NULL)) | 756 | NULL)) |
756 | ? ret | 757 | ? ret |
757 | : 1; | 758 | : 1; |
758 | if (NULL != work_finished) | 759 | if (NULL != work_finished) |
759 | { | 760 | { |
760 | (void)GNUNET_CONTAINER_multihashmap_iterate(work_finished, | 761 | (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, |
761 | &free_item, | 762 | &free_item, |
762 | NULL); | 763 | NULL); |
763 | GNUNET_CONTAINER_multihashmap_destroy(work_finished); | 764 | GNUNET_CONTAINER_multihashmap_destroy (work_finished); |
764 | } | 765 | } |
765 | while (NULL != (wi = work_head)) | 766 | while (NULL != (wi = work_head)) |
766 | { | 767 | { |
767 | GNUNET_CONTAINER_DLL_remove(work_head, work_tail, wi); | 768 | GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi); |
768 | GNUNET_free(wi->filename); | 769 | GNUNET_free (wi->filename); |
769 | GNUNET_free(wi); | 770 | GNUNET_free (wi); |
770 | } | 771 | } |
771 | GNUNET_SIGNAL_handler_uninstall(shc_chld); | 772 | GNUNET_SIGNAL_handler_uninstall (shc_chld); |
772 | shc_chld = NULL; | 773 | shc_chld = NULL; |
773 | GNUNET_DISK_pipe_close(sigpipe); | 774 | GNUNET_DISK_pipe_close (sigpipe); |
774 | sigpipe = NULL; | 775 | sigpipe = NULL; |
775 | GNUNET_free_non_null(cfg_filename); | 776 | GNUNET_free_non_null (cfg_filename); |
776 | cfg_filename = NULL; | 777 | cfg_filename = NULL; |
777 | GNUNET_free((void *)argv); | 778 | GNUNET_free ((void *) argv); |
778 | return ok; | 779 | return ok; |
779 | } | 780 | } |
780 | 781 | ||
diff --git a/src/fs/gnunet-daemon-fsprofiler.c b/src/fs/gnunet-daemon-fsprofiler.c index 524475c40..0fe26fe8b 100644 --- a/src/fs/gnunet-daemon-fsprofiler.c +++ b/src/fs/gnunet-daemon-fsprofiler.c | |||
@@ -34,7 +34,8 @@ | |||
34 | * We use 'patterns' of the form (x,y,t) to specify desired download/publish | 34 | * We use 'patterns' of the form (x,y,t) to specify desired download/publish |
35 | * activities of a peer. They are stored in a DLL. | 35 | * activities of a peer. They are stored in a DLL. |
36 | */ | 36 | */ |
37 | struct Pattern { | 37 | struct Pattern |
38 | { | ||
38 | /** | 39 | /** |
39 | * Kept in a DLL. | 40 | * Kept in a DLL. |
40 | */ | 41 | */ |
@@ -68,12 +69,12 @@ struct Pattern { | |||
68 | /** | 69 | /** |
69 | * Task to run the operation. | 70 | * Task to run the operation. |
70 | */ | 71 | */ |
71 | struct GNUNET_SCHEDULER_Task * task; | 72 | struct GNUNET_SCHEDULER_Task *task; |
72 | 73 | ||
73 | /** | 74 | /** |
74 | * Secondary task to run the operation. | 75 | * Secondary task to run the operation. |
75 | */ | 76 | */ |
76 | struct GNUNET_SCHEDULER_Task * stask; | 77 | struct GNUNET_SCHEDULER_Task *stask; |
77 | 78 | ||
78 | /** | 79 | /** |
79 | * X-value. | 80 | * X-value. |
@@ -172,29 +173,29 @@ static struct Pattern *download_tail; | |||
172 | * @return GNUNET_OK on success | 173 | * @return GNUNET_OK on success |
173 | */ | 174 | */ |
174 | static int | 175 | static int |
175 | parse_pattern(struct Pattern **head, | 176 | parse_pattern (struct Pattern **head, |
176 | struct Pattern **tail, | 177 | struct Pattern **tail, |
177 | const char *pattern) | 178 | const char *pattern) |
178 | { | 179 | { |
179 | struct Pattern *p; | 180 | struct Pattern *p; |
180 | unsigned long long x; | 181 | unsigned long long x; |
181 | unsigned long long y; | 182 | unsigned long long y; |
182 | unsigned long long t; | 183 | unsigned long long t; |
183 | 184 | ||
184 | while (3 == sscanf(pattern, | 185 | while (3 == sscanf (pattern, |
185 | "(%llu,%llu,%llu)", | 186 | "(%llu,%llu,%llu)", |
186 | &x, &y, &t)) | 187 | &x, &y, &t)) |
187 | { | 188 | { |
188 | p = GNUNET_new(struct Pattern); | 189 | p = GNUNET_new (struct Pattern); |
189 | p->x = x; | 190 | p->x = x; |
190 | p->y = y; | 191 | p->y = y; |
191 | p->delay.rel_value_us = (uint64_t)t; | 192 | p->delay.rel_value_us = (uint64_t) t; |
192 | GNUNET_CONTAINER_DLL_insert(*head, *tail, p); | 193 | GNUNET_CONTAINER_DLL_insert (*head, *tail, p); |
193 | pattern = strstr(pattern, ")"); | 194 | pattern = strstr (pattern, ")"); |
194 | GNUNET_assert(NULL != pattern); | 195 | GNUNET_assert (NULL != pattern); |
195 | pattern++; | 196 | pattern++; |
196 | } | 197 | } |
197 | return (0 == strlen(pattern)) ? GNUNET_OK : GNUNET_SYSERR; | 198 | return (0 == strlen (pattern)) ? GNUNET_OK : GNUNET_SYSERR; |
198 | } | 199 | } |
199 | 200 | ||
200 | 201 | ||
@@ -205,13 +206,13 @@ parse_pattern(struct Pattern **head, | |||
205 | * @return corresponding KSK URI | 206 | * @return corresponding KSK URI |
206 | */ | 207 | */ |
207 | static struct GNUNET_FS_Uri * | 208 | static struct GNUNET_FS_Uri * |
208 | make_keywords(uint64_t kval) | 209 | make_keywords (uint64_t kval) |
209 | { | 210 | { |
210 | char kw[128]; | 211 | char kw[128]; |
211 | 212 | ||
212 | GNUNET_snprintf(kw, sizeof(kw), | 213 | GNUNET_snprintf (kw, sizeof(kw), |
213 | "%llu", (unsigned long long)kval); | 214 | "%llu", (unsigned long long) kval); |
214 | return GNUNET_FS_uri_ksk_create(kw, NULL); | 215 | return GNUNET_FS_uri_ksk_create (kw, NULL); |
215 | } | 216 | } |
216 | 217 | ||
217 | 218 | ||
@@ -225,9 +226,9 @@ make_keywords(uint64_t kval) | |||
225 | * @return file information handle for the file | 226 | * @return file information handle for the file |
226 | */ | 227 | */ |
227 | static struct GNUNET_FS_FileInformation * | 228 | static struct GNUNET_FS_FileInformation * |
228 | make_file(uint64_t length, | 229 | make_file (uint64_t length, |
229 | uint64_t kval, | 230 | uint64_t kval, |
230 | void *ctx) | 231 | void *ctx) |
231 | { | 232 | { |
232 | struct GNUNET_FS_FileInformation *fi; | 233 | struct GNUNET_FS_FileInformation *fi; |
233 | struct GNUNET_FS_BlockOptions bo; | 234 | struct GNUNET_FS_BlockOptions bo; |
@@ -238,26 +239,26 @@ make_file(uint64_t length, | |||
238 | 239 | ||
239 | data = NULL; /* to make compilers happy */ | 240 | data = NULL; /* to make compilers happy */ |
240 | if ((0 != length) && | 241 | if ((0 != length) && |
241 | (NULL == (data = GNUNET_malloc_large((size_t)length)))) | 242 | (NULL == (data = GNUNET_malloc_large ((size_t) length)))) |
242 | return NULL; | 243 | return NULL; |
243 | /* initialize data with 'unique' data only depending on 'kval' and 'size', | 244 | /* initialize data with 'unique' data only depending on 'kval' and 'size', |
244 | making sure that blocks do not repeat */ | 245 | making sure that blocks do not repeat */ |
245 | for (i = 0; i < length; i += 8) | 246 | for (i = 0; i < length; i += 8) |
246 | { | 247 | { |
247 | xor = length ^ kval ^ (uint64_t)(i / 32 / 1024); | 248 | xor = length ^ kval ^ (uint64_t) (i / 32 / 1024); |
248 | GNUNET_memcpy(&data[i], &xor, GNUNET_MIN(length - i, sizeof(uint64_t))); | 249 | GNUNET_memcpy (&data[i], &xor, GNUNET_MIN (length - i, sizeof(uint64_t))); |
249 | } | 250 | } |
250 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_DAYS); | 251 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); |
251 | bo.anonymity_level = (uint32_t)anonymity_level; | 252 | bo.anonymity_level = (uint32_t) anonymity_level; |
252 | bo.content_priority = 128; | 253 | bo.content_priority = 128; |
253 | bo.replication_level = (uint32_t)replication_level; | 254 | bo.replication_level = (uint32_t) replication_level; |
254 | keywords = make_keywords(kval); | 255 | keywords = make_keywords (kval); |
255 | fi = GNUNET_FS_file_information_create_from_data(fs_handle, | 256 | fi = GNUNET_FS_file_information_create_from_data (fs_handle, |
256 | ctx, | 257 | ctx, |
257 | length, | 258 | length, |
258 | data, keywords, | 259 | data, keywords, |
259 | NULL, GNUNET_NO, &bo); | 260 | NULL, GNUNET_NO, &bo); |
260 | GNUNET_FS_uri_destroy(keywords); | 261 | GNUNET_FS_uri_destroy (keywords); |
261 | return fi; | 262 | return fi; |
262 | } | 263 | } |
263 | 264 | ||
@@ -268,42 +269,42 @@ make_file(uint64_t length, | |||
268 | * @param cls unused | 269 | * @param cls unused |
269 | */ | 270 | */ |
270 | static void | 271 | static void |
271 | shutdown_task(void *cls) | 272 | shutdown_task (void *cls) |
272 | { | 273 | { |
273 | struct Pattern *p; | 274 | struct Pattern *p; |
274 | 275 | ||
275 | while (NULL != (p = publish_head)) | 276 | while (NULL != (p = publish_head)) |
276 | { | 277 | { |
277 | if (NULL != p->task) | 278 | if (NULL != p->task) |
278 | GNUNET_SCHEDULER_cancel(p->task); | 279 | GNUNET_SCHEDULER_cancel (p->task); |
279 | if (NULL != p->ctx) | 280 | if (NULL != p->ctx) |
280 | GNUNET_FS_publish_stop(p->ctx); | 281 | GNUNET_FS_publish_stop (p->ctx); |
281 | GNUNET_CONTAINER_DLL_remove(publish_head, publish_tail, p); | 282 | GNUNET_CONTAINER_DLL_remove (publish_head, publish_tail, p); |
282 | GNUNET_free(p); | 283 | GNUNET_free (p); |
283 | } | 284 | } |
284 | while (NULL != (p = download_head)) | 285 | while (NULL != (p = download_head)) |
285 | { | 286 | { |
286 | if (NULL != p->task) | 287 | if (NULL != p->task) |
287 | GNUNET_SCHEDULER_cancel(p->task); | 288 | GNUNET_SCHEDULER_cancel (p->task); |
288 | if (NULL != p->stask) | 289 | if (NULL != p->stask) |
289 | GNUNET_SCHEDULER_cancel(p->stask); | 290 | GNUNET_SCHEDULER_cancel (p->stask); |
290 | if (NULL != p->ctx) | 291 | if (NULL != p->ctx) |
291 | GNUNET_FS_download_stop(p->ctx, GNUNET_YES); | 292 | GNUNET_FS_download_stop (p->ctx, GNUNET_YES); |
292 | if (NULL != p->sctx) | 293 | if (NULL != p->sctx) |
293 | GNUNET_FS_search_stop(p->sctx); | 294 | GNUNET_FS_search_stop (p->sctx); |
294 | GNUNET_CONTAINER_DLL_remove(download_head, download_tail, p); | 295 | GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); |
295 | GNUNET_free(p); | 296 | GNUNET_free (p); |
296 | } | 297 | } |
297 | if (NULL != fs_handle) | 298 | if (NULL != fs_handle) |
298 | { | 299 | { |
299 | GNUNET_FS_stop(fs_handle); | 300 | GNUNET_FS_stop (fs_handle); |
300 | fs_handle = NULL; | 301 | fs_handle = NULL; |
301 | } | 302 | } |
302 | if (NULL != stats_handle) | 303 | if (NULL != stats_handle) |
303 | { | 304 | { |
304 | GNUNET_STATISTICS_destroy(stats_handle, GNUNET_YES); | 305 | GNUNET_STATISTICS_destroy (stats_handle, GNUNET_YES); |
305 | stats_handle = NULL; | 306 | stats_handle = NULL; |
306 | } | 307 | } |
307 | } | 308 | } |
308 | 309 | ||
309 | 310 | ||
@@ -313,12 +314,12 @@ shutdown_task(void *cls) | |||
313 | * @param cls the 'struct Pattern' of the publish operation to stop | 314 | * @param cls the 'struct Pattern' of the publish operation to stop |
314 | */ | 315 | */ |
315 | static void | 316 | static void |
316 | publish_stop_task(void *cls) | 317 | publish_stop_task (void *cls) |
317 | { | 318 | { |
318 | struct Pattern *p = cls; | 319 | struct Pattern *p = cls; |
319 | 320 | ||
320 | p->task = NULL; | 321 | p->task = NULL; |
321 | GNUNET_FS_publish_stop(p->ctx); | 322 | GNUNET_FS_publish_stop (p->ctx); |
322 | } | 323 | } |
323 | 324 | ||
324 | 325 | ||
@@ -328,12 +329,12 @@ publish_stop_task(void *cls) | |||
328 | * @param cls the 'struct Pattern' of the download operation to stop | 329 | * @param cls the 'struct Pattern' of the download operation to stop |
329 | */ | 330 | */ |
330 | static void | 331 | static void |
331 | download_stop_task(void *cls) | 332 | download_stop_task (void *cls) |
332 | { | 333 | { |
333 | struct Pattern *p = cls; | 334 | struct Pattern *p = cls; |
334 | 335 | ||
335 | p->task = NULL; | 336 | p->task = NULL; |
336 | GNUNET_FS_download_stop(p->ctx, GNUNET_YES); | 337 | GNUNET_FS_download_stop (p->ctx, GNUNET_YES); |
337 | } | 338 | } |
338 | 339 | ||
339 | 340 | ||
@@ -343,12 +344,12 @@ download_stop_task(void *cls) | |||
343 | * @param cls the 'struct Pattern' of the download operation to stop | 344 | * @param cls the 'struct Pattern' of the download operation to stop |
344 | */ | 345 | */ |
345 | static void | 346 | static void |
346 | search_stop_task(void *cls) | 347 | search_stop_task (void *cls) |
347 | { | 348 | { |
348 | struct Pattern *p = cls; | 349 | struct Pattern *p = cls; |
349 | 350 | ||
350 | p->stask = NULL; | 351 | p->stask = NULL; |
351 | GNUNET_FS_search_stop(p->sctx); | 352 | GNUNET_FS_search_stop (p->sctx); |
352 | } | 353 | } |
353 | 354 | ||
354 | 355 | ||
@@ -368,138 +369,141 @@ search_stop_task(void *cls) | |||
368 | * field in the GNUNET_FS_ProgressInfo struct. | 369 | * field in the GNUNET_FS_ProgressInfo struct. |
369 | */ | 370 | */ |
370 | static void * | 371 | static void * |
371 | progress_cb(void *cls, | 372 | progress_cb (void *cls, |
372 | const struct GNUNET_FS_ProgressInfo *info) | 373 | const struct GNUNET_FS_ProgressInfo *info) |
373 | { | 374 | { |
374 | struct Pattern *p; | 375 | struct Pattern *p; |
375 | const struct GNUNET_FS_Uri *uri; | 376 | const struct GNUNET_FS_Uri *uri; |
376 | 377 | ||
377 | switch (info->status) | 378 | switch (info->status) |
379 | { | ||
380 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
381 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
382 | p = info->value.publish.cctx; | ||
383 | return p; | ||
384 | |||
385 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
386 | p = info->value.publish.cctx; | ||
387 | return p; | ||
388 | |||
389 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
390 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
391 | "Publishing failed\n"); | ||
392 | GNUNET_STATISTICS_update (stats_handle, | ||
393 | "# failed publish operations", 1, GNUNET_NO); | ||
394 | p = info->value.publish.cctx; | ||
395 | p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p); | ||
396 | return p; | ||
397 | |||
398 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
399 | p = info->value.publish.cctx; | ||
400 | GNUNET_STATISTICS_update (stats_handle, | ||
401 | "# publishing time (ms)", | ||
402 | (long long) GNUNET_TIME_absolute_get_duration ( | ||
403 | p->start_time).rel_value_us / 1000LL, | ||
404 | GNUNET_NO); | ||
405 | p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p); | ||
406 | return p; | ||
407 | |||
408 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
409 | p = info->value.publish.cctx; | ||
410 | p->ctx = NULL; | ||
411 | GNUNET_CONTAINER_DLL_remove (publish_head, publish_tail, p); | ||
412 | GNUNET_free (p); | ||
413 | return NULL; | ||
414 | |||
415 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
416 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
417 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
418 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
419 | p = info->value.download.cctx; | ||
420 | return p; | ||
421 | |||
422 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
424 | "Download failed\n"); | ||
425 | GNUNET_STATISTICS_update (stats_handle, | ||
426 | "# failed downloads", 1, GNUNET_NO); | ||
427 | p = info->value.download.cctx; | ||
428 | p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p); | ||
429 | return p; | ||
430 | |||
431 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | ||
432 | p = info->value.download.cctx; | ||
433 | GNUNET_STATISTICS_update (stats_handle, | ||
434 | "# download time (ms)", | ||
435 | (long long) GNUNET_TIME_absolute_get_duration ( | ||
436 | p->start_time).rel_value_us / 1000LL, | ||
437 | GNUNET_NO); | ||
438 | p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p); | ||
439 | return p; | ||
440 | |||
441 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
442 | p = info->value.download.cctx; | ||
443 | p->ctx = NULL; | ||
444 | if (NULL == p->sctx) | ||
378 | { | 445 | { |
379 | case GNUNET_FS_STATUS_PUBLISH_START: | 446 | GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); |
380 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 447 | GNUNET_free (p); |
381 | p = info->value.publish.cctx; | ||
382 | return p; | ||
383 | |||
384 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
385 | p = info->value.publish.cctx; | ||
386 | return p; | ||
387 | |||
388 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
389 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
390 | "Publishing failed\n"); | ||
391 | GNUNET_STATISTICS_update(stats_handle, | ||
392 | "# failed publish operations", 1, GNUNET_NO); | ||
393 | p = info->value.publish.cctx; | ||
394 | p->task = GNUNET_SCHEDULER_add_now(&publish_stop_task, p); | ||
395 | return p; | ||
396 | |||
397 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
398 | p = info->value.publish.cctx; | ||
399 | GNUNET_STATISTICS_update(stats_handle, | ||
400 | "# publishing time (ms)", | ||
401 | (long long)GNUNET_TIME_absolute_get_duration(p->start_time).rel_value_us / 1000LL, | ||
402 | GNUNET_NO); | ||
403 | p->task = GNUNET_SCHEDULER_add_now(&publish_stop_task, p); | ||
404 | return p; | ||
405 | |||
406 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
407 | p = info->value.publish.cctx; | ||
408 | p->ctx = NULL; | ||
409 | GNUNET_CONTAINER_DLL_remove(publish_head, publish_tail, p); | ||
410 | GNUNET_free(p); | ||
411 | return NULL; | ||
412 | |||
413 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
414 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
415 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
416 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
417 | p = info->value.download.cctx; | ||
418 | return p; | ||
419 | |||
420 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
421 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
422 | "Download failed\n"); | ||
423 | GNUNET_STATISTICS_update(stats_handle, | ||
424 | "# failed downloads", 1, GNUNET_NO); | ||
425 | p = info->value.download.cctx; | ||
426 | p->task = GNUNET_SCHEDULER_add_now(&download_stop_task, p); | ||
427 | return p; | ||
428 | |||
429 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | ||
430 | p = info->value.download.cctx; | ||
431 | GNUNET_STATISTICS_update(stats_handle, | ||
432 | "# download time (ms)", | ||
433 | (long long)GNUNET_TIME_absolute_get_duration(p->start_time).rel_value_us / 1000LL, | ||
434 | GNUNET_NO); | ||
435 | p->task = GNUNET_SCHEDULER_add_now(&download_stop_task, p); | ||
436 | return p; | ||
437 | |||
438 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
439 | p = info->value.download.cctx; | ||
440 | p->ctx = NULL; | ||
441 | if (NULL == p->sctx) | ||
442 | { | ||
443 | GNUNET_CONTAINER_DLL_remove(download_head, download_tail, p); | ||
444 | GNUNET_free(p); | ||
445 | } | ||
446 | return NULL; | ||
447 | |||
448 | case GNUNET_FS_STATUS_SEARCH_START: | ||
449 | case GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE: | ||
450 | p = info->value.search.cctx; | ||
451 | return p; | ||
452 | |||
453 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
454 | p = info->value.search.cctx; | ||
455 | uri = info->value.search.specifics.result.uri; | ||
456 | if (GNUNET_YES != GNUNET_FS_uri_test_chk(uri)) | ||
457 | return NULL; /* not what we want */ | ||
458 | if (p->y != GNUNET_FS_uri_chk_get_file_size(uri)) | ||
459 | return NULL; /* not what we want */ | ||
460 | GNUNET_STATISTICS_update(stats_handle, | ||
461 | "# search time (ms)", | ||
462 | (long long)GNUNET_TIME_absolute_get_duration(p->start_time).rel_value_us / 1000LL, | ||
463 | GNUNET_NO); | ||
464 | p->start_time = GNUNET_TIME_absolute_get(); | ||
465 | p->ctx = GNUNET_FS_download_start(fs_handle, uri, | ||
466 | NULL, NULL, NULL, | ||
467 | 0, GNUNET_FS_uri_chk_get_file_size(uri), | ||
468 | anonymity_level, | ||
469 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES, | ||
470 | p, | ||
471 | NULL); | ||
472 | p->stask = GNUNET_SCHEDULER_add_now(&search_stop_task, p); | ||
473 | return NULL; | ||
474 | |||
475 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | ||
476 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
477 | return NULL; /* don't care */ | ||
478 | |||
479 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
480 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
481 | "Search failed\n"); | ||
482 | GNUNET_STATISTICS_update(stats_handle, | ||
483 | "# failed searches", 1, GNUNET_NO); | ||
484 | p = info->value.search.cctx; | ||
485 | p->stask = GNUNET_SCHEDULER_add_now(&search_stop_task, p); | ||
486 | return p; | ||
487 | |||
488 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
489 | p = info->value.search.cctx; | ||
490 | p->sctx = NULL; | ||
491 | if (NULL == p->ctx) | ||
492 | { | ||
493 | GNUNET_CONTAINER_DLL_remove(download_head, download_tail, p); | ||
494 | GNUNET_free(p); | ||
495 | } | ||
496 | return NULL; | ||
497 | |||
498 | default: | ||
499 | /* unexpected event during profiling */ | ||
500 | GNUNET_break(0); | ||
501 | return NULL; | ||
502 | } | 448 | } |
449 | return NULL; | ||
450 | |||
451 | case GNUNET_FS_STATUS_SEARCH_START: | ||
452 | case GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE: | ||
453 | p = info->value.search.cctx; | ||
454 | return p; | ||
455 | |||
456 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
457 | p = info->value.search.cctx; | ||
458 | uri = info->value.search.specifics.result.uri; | ||
459 | if (GNUNET_YES != GNUNET_FS_uri_test_chk (uri)) | ||
460 | return NULL; /* not what we want */ | ||
461 | if (p->y != GNUNET_FS_uri_chk_get_file_size (uri)) | ||
462 | return NULL; /* not what we want */ | ||
463 | GNUNET_STATISTICS_update (stats_handle, | ||
464 | "# search time (ms)", | ||
465 | (long long) GNUNET_TIME_absolute_get_duration ( | ||
466 | p->start_time).rel_value_us / 1000LL, | ||
467 | GNUNET_NO); | ||
468 | p->start_time = GNUNET_TIME_absolute_get (); | ||
469 | p->ctx = GNUNET_FS_download_start (fs_handle, uri, | ||
470 | NULL, NULL, NULL, | ||
471 | 0, GNUNET_FS_uri_chk_get_file_size (uri), | ||
472 | anonymity_level, | ||
473 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES, | ||
474 | p, | ||
475 | NULL); | ||
476 | p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p); | ||
477 | return NULL; | ||
478 | |||
479 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | ||
480 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
481 | return NULL; /* don't care */ | ||
482 | |||
483 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
484 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
485 | "Search failed\n"); | ||
486 | GNUNET_STATISTICS_update (stats_handle, | ||
487 | "# failed searches", 1, GNUNET_NO); | ||
488 | p = info->value.search.cctx; | ||
489 | p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p); | ||
490 | return p; | ||
491 | |||
492 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
493 | p = info->value.search.cctx; | ||
494 | p->sctx = NULL; | ||
495 | if (NULL == p->ctx) | ||
496 | { | ||
497 | GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); | ||
498 | GNUNET_free (p); | ||
499 | } | ||
500 | return NULL; | ||
501 | |||
502 | default: | ||
503 | /* unexpected event during profiling */ | ||
504 | GNUNET_break (0); | ||
505 | return NULL; | ||
506 | } | ||
503 | } | 507 | } |
504 | 508 | ||
505 | 509 | ||
@@ -509,18 +513,18 @@ progress_cb(void *cls, | |||
509 | * @param cls the 'struct Pattern' specifying the operation to perform | 513 | * @param cls the 'struct Pattern' specifying the operation to perform |
510 | */ | 514 | */ |
511 | static void | 515 | static void |
512 | start_publish(void *cls) | 516 | start_publish (void *cls) |
513 | { | 517 | { |
514 | struct Pattern *p = cls; | 518 | struct Pattern *p = cls; |
515 | struct GNUNET_FS_FileInformation *fi; | 519 | struct GNUNET_FS_FileInformation *fi; |
516 | 520 | ||
517 | p->task = NULL; | 521 | p->task = NULL; |
518 | fi = make_file(p->x, p->y, p); | 522 | fi = make_file (p->x, p->y, p); |
519 | p->start_time = GNUNET_TIME_absolute_get(); | 523 | p->start_time = GNUNET_TIME_absolute_get (); |
520 | p->ctx = GNUNET_FS_publish_start(fs_handle, | 524 | p->ctx = GNUNET_FS_publish_start (fs_handle, |
521 | fi, | 525 | fi, |
522 | NULL, NULL, NULL, | 526 | NULL, NULL, NULL, |
523 | GNUNET_FS_PUBLISH_OPTION_NONE); | 527 | GNUNET_FS_PUBLISH_OPTION_NONE); |
524 | } | 528 | } |
525 | 529 | ||
526 | 530 | ||
@@ -530,18 +534,18 @@ start_publish(void *cls) | |||
530 | * @param cls the 'struct Pattern' specifying the operation to perform | 534 | * @param cls the 'struct Pattern' specifying the operation to perform |
531 | */ | 535 | */ |
532 | static void | 536 | static void |
533 | start_download(void *cls) | 537 | start_download (void *cls) |
534 | { | 538 | { |
535 | struct Pattern *p = cls; | 539 | struct Pattern *p = cls; |
536 | struct GNUNET_FS_Uri *keywords; | 540 | struct GNUNET_FS_Uri *keywords; |
537 | 541 | ||
538 | p->task = NULL; | 542 | p->task = NULL; |
539 | keywords = make_keywords(p->x); | 543 | keywords = make_keywords (p->x); |
540 | p->start_time = GNUNET_TIME_absolute_get(); | 544 | p->start_time = GNUNET_TIME_absolute_get (); |
541 | p->sctx = GNUNET_FS_search_start(fs_handle, keywords, | 545 | p->sctx = GNUNET_FS_search_start (fs_handle, keywords, |
542 | anonymity_level, | 546 | anonymity_level, |
543 | GNUNET_FS_SEARCH_OPTION_NONE, | 547 | GNUNET_FS_SEARCH_OPTION_NONE, |
544 | p); | 548 | p); |
545 | } | 549 | } |
546 | 550 | ||
547 | 551 | ||
@@ -554,88 +558,89 @@ start_download(void *cls) | |||
554 | * @param cfg_ configuration | 558 | * @param cfg_ configuration |
555 | */ | 559 | */ |
556 | static void | 560 | static void |
557 | run(void *cls, char *const *args GNUNET_UNUSED, | 561 | run (void *cls, char *const *args GNUNET_UNUSED, |
558 | const char *cfgfile GNUNET_UNUSED, | 562 | const char *cfgfile GNUNET_UNUSED, |
559 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | 563 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
560 | { | 564 | { |
561 | char myoptname[128]; | 565 | char myoptname[128]; |
562 | struct Pattern *p; | 566 | struct Pattern *p; |
563 | 567 | ||
564 | cfg = cfg_; | 568 | cfg = cfg_; |
565 | /* Scheduled the task to clean up when shutdown is called */ | 569 | /* Scheduled the task to clean up when shutdown is called */ |
566 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, | 570 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
567 | NULL); | 571 | NULL); |
568 | 572 | ||
569 | if (GNUNET_OK != | 573 | if (GNUNET_OK != |
570 | GNUNET_CONFIGURATION_get_value_number(cfg, | 574 | GNUNET_CONFIGURATION_get_value_number (cfg, |
571 | "TESTBED", "PEERID", | 575 | "TESTBED", "PEERID", |
572 | &my_peerid)) | 576 | &my_peerid)) |
573 | { | 577 | { |
574 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 578 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
575 | "TESTBED", "PEERID"); | 579 | "TESTBED", "PEERID"); |
576 | global_ret = GNUNET_SYSERR; | 580 | global_ret = GNUNET_SYSERR; |
577 | GNUNET_SCHEDULER_shutdown(); | 581 | GNUNET_SCHEDULER_shutdown (); |
578 | return; | 582 | return; |
579 | } | 583 | } |
580 | if (GNUNET_OK != | 584 | if (GNUNET_OK != |
581 | GNUNET_CONFIGURATION_get_value_number(cfg, | 585 | GNUNET_CONFIGURATION_get_value_number (cfg, |
582 | "FSPROFILER", "ANONYMITY_LEVEL", | 586 | "FSPROFILER", "ANONYMITY_LEVEL", |
583 | &anonymity_level)) | 587 | &anonymity_level)) |
584 | anonymity_level = 1; | 588 | anonymity_level = 1; |
585 | if (GNUNET_OK != | 589 | if (GNUNET_OK != |
586 | GNUNET_CONFIGURATION_get_value_number(cfg, | 590 | GNUNET_CONFIGURATION_get_value_number (cfg, |
587 | "FSPROFILER", "REPLICATION_LEVEL", | 591 | "FSPROFILER", "REPLICATION_LEVEL", |
588 | &replication_level)) | 592 | &replication_level)) |
589 | replication_level = 1; | 593 | replication_level = 1; |
590 | GNUNET_snprintf(myoptname, sizeof(myoptname), | 594 | GNUNET_snprintf (myoptname, sizeof(myoptname), |
591 | "DOWNLOAD-PATTERN-%u", my_peerid); | 595 | "DOWNLOAD-PATTERN-%u", my_peerid); |
592 | if (GNUNET_OK != | 596 | if (GNUNET_OK != |
593 | GNUNET_CONFIGURATION_get_value_string(cfg, | 597 | GNUNET_CONFIGURATION_get_value_string (cfg, |
594 | "FSPROFILER", myoptname, | 598 | "FSPROFILER", myoptname, |
595 | &download_pattern)) | 599 | &download_pattern)) |
596 | download_pattern = GNUNET_strdup(""); | 600 | download_pattern = GNUNET_strdup (""); |
597 | GNUNET_snprintf(myoptname, sizeof(myoptname), | 601 | GNUNET_snprintf (myoptname, sizeof(myoptname), |
598 | "PUBLISH-PATTERN-%u", my_peerid); | 602 | "PUBLISH-PATTERN-%u", my_peerid); |
599 | if (GNUNET_OK != | 603 | if (GNUNET_OK != |
600 | GNUNET_CONFIGURATION_get_value_string(cfg, | 604 | GNUNET_CONFIGURATION_get_value_string (cfg, |
601 | "FSPROFILER", myoptname, | 605 | "FSPROFILER", myoptname, |
602 | &publish_pattern)) | 606 | &publish_pattern)) |
603 | publish_pattern = GNUNET_strdup(""); | 607 | publish_pattern = GNUNET_strdup (""); |
604 | if ((GNUNET_OK != | 608 | if ((GNUNET_OK != |
605 | parse_pattern(&download_head, | 609 | parse_pattern (&download_head, |
606 | &download_tail, | 610 | &download_tail, |
607 | download_pattern)) || | 611 | download_pattern)) || |
608 | (GNUNET_OK != | 612 | (GNUNET_OK != |
609 | parse_pattern(&publish_head, | 613 | parse_pattern (&publish_head, |
610 | &publish_tail, | 614 | &publish_tail, |
611 | publish_pattern))) | 615 | publish_pattern))) |
612 | { | 616 | { |
613 | GNUNET_SCHEDULER_shutdown(); | 617 | GNUNET_SCHEDULER_shutdown (); |
614 | return; | 618 | return; |
615 | } | 619 | } |
616 | 620 | ||
617 | stats_handle = GNUNET_STATISTICS_create("fsprofiler", cfg); | 621 | stats_handle = GNUNET_STATISTICS_create ("fsprofiler", cfg); |
618 | fs_handle = | 622 | fs_handle = |
619 | GNUNET_FS_start(cfg, | 623 | GNUNET_FS_start (cfg, |
620 | "fsprofiler", | 624 | "fsprofiler", |
621 | &progress_cb, NULL, | 625 | &progress_cb, NULL, |
622 | GNUNET_FS_FLAGS_NONE, | 626 | GNUNET_FS_FLAGS_NONE, |
623 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 1, | 627 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 1, |
624 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 1, | 628 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 1, |
625 | GNUNET_FS_OPTIONS_END); | 629 | GNUNET_FS_OPTIONS_END); |
626 | if (NULL == fs_handle) | 630 | if (NULL == fs_handle) |
627 | { | 631 | { |
628 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not acquire FS handle. Exiting.\n"); | 632 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
629 | global_ret = GNUNET_SYSERR; | 633 | "Could not acquire FS handle. Exiting.\n"); |
630 | GNUNET_SCHEDULER_shutdown(); | 634 | global_ret = GNUNET_SYSERR; |
631 | return; | 635 | GNUNET_SCHEDULER_shutdown (); |
632 | } | 636 | return; |
637 | } | ||
633 | for (p = publish_head; NULL != p; p = p->next) | 638 | for (p = publish_head; NULL != p; p = p->next) |
634 | p->task = GNUNET_SCHEDULER_add_delayed(p->delay, | 639 | p->task = GNUNET_SCHEDULER_add_delayed (p->delay, |
635 | &start_publish, p); | 640 | &start_publish, p); |
636 | for (p = download_head; NULL != p; p = p->next) | 641 | for (p = download_head; NULL != p; p = p->next) |
637 | p->task = GNUNET_SCHEDULER_add_delayed(p->delay, | 642 | p->task = GNUNET_SCHEDULER_add_delayed (p->delay, |
638 | &start_download, p); | 643 | &start_download, p); |
639 | } | 644 | } |
640 | 645 | ||
641 | 646 | ||
@@ -647,19 +652,20 @@ run(void *cls, char *const *args GNUNET_UNUSED, | |||
647 | * @return 0 ok, 1 on error | 652 | * @return 0 ok, 1 on error |
648 | */ | 653 | */ |
649 | int | 654 | int |
650 | main(int argc, char *const *argv) | 655 | main (int argc, char *const *argv) |
651 | { | 656 | { |
652 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 657 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
653 | GNUNET_GETOPT_OPTION_END | 658 | GNUNET_GETOPT_OPTION_END |
654 | }; | 659 | }; |
655 | 660 | ||
656 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 661 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
657 | return 2; | 662 | return 2; |
658 | return (GNUNET_OK == | 663 | return (GNUNET_OK == |
659 | GNUNET_PROGRAM_run(argc, argv, "gnunet-daemon-fsprofiler", | 664 | GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-fsprofiler", |
660 | gettext_noop | 665 | gettext_noop |
661 | ("Daemon to use file-sharing to measure its performance."), | 666 | ( |
662 | options, &run, NULL)) ? global_ret : 1; | 667 | "Daemon to use file-sharing to measure its performance."), |
668 | options, &run, NULL)) ? global_ret : 1; | ||
663 | } | 669 | } |
664 | 670 | ||
665 | /* end of gnunet-daemon-fsprofiler.c */ | 671 | /* end of gnunet-daemon-fsprofiler.c */ |
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c index f33db109f..8819d1777 100644 --- a/src/fs/gnunet-directory.c +++ b/src/fs/gnunet-directory.c | |||
@@ -40,32 +40,32 @@ static int ret; | |||
40 | * @return always 0 (to continue iterating) | 40 | * @return always 0 (to continue iterating) |
41 | */ | 41 | */ |
42 | static int | 42 | static int |
43 | item_printer(void *cls, | 43 | item_printer (void *cls, |
44 | const char *plugin_name, | 44 | const char *plugin_name, |
45 | enum EXTRACTOR_MetaType type, | 45 | enum EXTRACTOR_MetaType type, |
46 | enum EXTRACTOR_MetaFormat format, | 46 | enum EXTRACTOR_MetaFormat format, |
47 | const char *data_mime_type, | 47 | const char *data_mime_type, |
48 | const char *data, | 48 | const char *data, |
49 | size_t data_size) | 49 | size_t data_size) |
50 | { | 50 | { |
51 | if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) | 51 | if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) |
52 | { | 52 | { |
53 | printf(_("\t<original file embedded in %u bytes of meta data>\n"), | 53 | printf (_ ("\t<original file embedded in %u bytes of meta data>\n"), |
54 | (unsigned int)data_size); | 54 | (unsigned int) data_size); |
55 | return 0; | 55 | return 0; |
56 | } | 56 | } |
57 | if ((format != EXTRACTOR_METAFORMAT_UTF8) && | 57 | if ((format != EXTRACTOR_METAFORMAT_UTF8) && |
58 | (format != EXTRACTOR_METAFORMAT_C_STRING)) | 58 | (format != EXTRACTOR_METAFORMAT_C_STRING)) |
59 | return 0; | 59 | return 0; |
60 | if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) | 60 | if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) |
61 | return 0; | 61 | return 0; |
62 | #if HAVE_LIBEXTRACTOR | 62 | #if HAVE_LIBEXTRACTOR |
63 | printf("\t%20s: %s\n", | 63 | printf ("\t%20s: %s\n", |
64 | dgettext(LIBEXTRACTOR_GETTEXT_DOMAIN, | 64 | dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, |
65 | EXTRACTOR_metatype_to_string(type)), | 65 | EXTRACTOR_metatype_to_string (type)), |
66 | data); | 66 | data); |
67 | #else | 67 | #else |
68 | printf("\t%20d: %s\n", type, data); | 68 | printf ("\t%20d: %s\n", type, data); |
69 | #endif | 69 | #endif |
70 | return 0; | 70 | return 0; |
71 | } | 71 | } |
@@ -87,34 +87,34 @@ item_printer(void *cls, | |||
87 | * @param data data available for the file (length bytes) | 87 | * @param data data available for the file (length bytes) |
88 | */ | 88 | */ |
89 | static void | 89 | static void |
90 | print_entry(void *cls, | 90 | print_entry (void *cls, |
91 | const char *filename, | 91 | const char *filename, |
92 | const struct GNUNET_FS_Uri *uri, | 92 | const struct GNUNET_FS_Uri *uri, |
93 | const struct GNUNET_CONTAINER_MetaData *meta, | 93 | const struct GNUNET_CONTAINER_MetaData *meta, |
94 | size_t length, | 94 | size_t length, |
95 | const void *data) | 95 | const void *data) |
96 | { | 96 | { |
97 | char *string; | 97 | char *string; |
98 | char *name; | 98 | char *name; |
99 | 99 | ||
100 | name = GNUNET_CONTAINER_meta_data_get_by_type( | 100 | name = GNUNET_CONTAINER_meta_data_get_by_type ( |
101 | meta, | 101 | meta, |
102 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 102 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
103 | if (uri == NULL) | 103 | if (uri == NULL) |
104 | { | 104 | { |
105 | printf(_("Directory `%s' meta data:\n"), name ? name : ""); | 105 | printf (_ ("Directory `%s' meta data:\n"), name ? name : ""); |
106 | GNUNET_CONTAINER_meta_data_iterate(meta, &item_printer, NULL); | 106 | GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); |
107 | printf("\n"); | 107 | printf ("\n"); |
108 | printf(_("Directory `%s' contents:\n"), name ? name : ""); | 108 | printf (_ ("Directory `%s' contents:\n"), name ? name : ""); |
109 | GNUNET_free_non_null(name); | 109 | GNUNET_free_non_null (name); |
110 | return; | 110 | return; |
111 | } | 111 | } |
112 | string = GNUNET_FS_uri_to_string(uri); | 112 | string = GNUNET_FS_uri_to_string (uri); |
113 | printf("%s (%s):\n", name ? name : "", string); | 113 | printf ("%s (%s):\n", name ? name : "", string); |
114 | GNUNET_free(string); | 114 | GNUNET_free (string); |
115 | GNUNET_CONTAINER_meta_data_iterate(meta, &item_printer, NULL); | 115 | GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); |
116 | printf("\n"); | 116 | printf ("\n"); |
117 | GNUNET_free_non_null(name); | 117 | GNUNET_free_non_null (name); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
@@ -127,10 +127,10 @@ print_entry(void *cls, | |||
127 | * @param cfg configuration | 127 | * @param cfg configuration |
128 | */ | 128 | */ |
129 | static void | 129 | static void |
130 | run(void *cls, | 130 | run (void *cls, |
131 | char *const *args, | 131 | char *const *args, |
132 | const char *cfgfile, | 132 | const char *cfgfile, |
133 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 133 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
134 | { | 134 | { |
135 | struct GNUNET_DISK_MapHandle *map; | 135 | struct GNUNET_DISK_MapHandle *map; |
136 | struct GNUNET_DISK_FileHandle *h; | 136 | struct GNUNET_DISK_FileHandle *h; |
@@ -141,37 +141,37 @@ run(void *cls, | |||
141 | int i; | 141 | int i; |
142 | 142 | ||
143 | if (NULL == args[0]) | 143 | if (NULL == args[0]) |
144 | { | 144 | { |
145 | fprintf(stderr, "%s", _("You must specify a filename to inspect.\n")); | 145 | fprintf (stderr, "%s", _ ("You must specify a filename to inspect.\n")); |
146 | ret = 1; | 146 | ret = 1; |
147 | return; | 147 | return; |
148 | } | 148 | } |
149 | i = 0; | 149 | i = 0; |
150 | while (NULL != (filename = args[i++])) | 150 | while (NULL != (filename = args[i++])) |
151 | { | ||
152 | if ((GNUNET_OK != | ||
153 | GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) || | ||
154 | (NULL == (h = GNUNET_DISK_file_open (filename, | ||
155 | GNUNET_DISK_OPEN_READ, | ||
156 | GNUNET_DISK_PERM_NONE)))) | ||
151 | { | 157 | { |
152 | if ((GNUNET_OK != | 158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
153 | GNUNET_DISK_file_size(filename, &size, GNUNET_YES, GNUNET_YES)) || | 159 | _ ("Failed to read directory `%s'\n"), |
154 | (NULL == (h = GNUNET_DISK_file_open(filename, | 160 | filename); |
155 | GNUNET_DISK_OPEN_READ, | 161 | ret = 1; |
156 | GNUNET_DISK_PERM_NONE)))) | 162 | continue; |
157 | { | ||
158 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
159 | _("Failed to read directory `%s'\n"), | ||
160 | filename); | ||
161 | ret = 1; | ||
162 | continue; | ||
163 | } | ||
164 | len = (size_t)size; | ||
165 | data = GNUNET_DISK_file_map(h, &map, GNUNET_DISK_MAP_TYPE_READ, len); | ||
166 | GNUNET_assert(NULL != data); | ||
167 | if (GNUNET_OK != | ||
168 | GNUNET_FS_directory_list_contents(len, data, 0, &print_entry, NULL)) | ||
169 | fprintf(stdout, _("`%s' is not a GNUnet directory\n"), filename); | ||
170 | else | ||
171 | printf("\n"); | ||
172 | GNUNET_DISK_file_unmap(map); | ||
173 | GNUNET_DISK_file_close(h); | ||
174 | } | 163 | } |
164 | len = (size_t) size; | ||
165 | data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len); | ||
166 | GNUNET_assert (NULL != data); | ||
167 | if (GNUNET_OK != | ||
168 | GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL)) | ||
169 | fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename); | ||
170 | else | ||
171 | printf ("\n"); | ||
172 | GNUNET_DISK_file_unmap (map); | ||
173 | GNUNET_DISK_file_close (h); | ||
174 | } | ||
175 | } | 175 | } |
176 | 176 | ||
177 | /** | 177 | /** |
@@ -182,27 +182,27 @@ run(void *cls, | |||
182 | * @return 0 ok, 1 on error | 182 | * @return 0 ok, 1 on error |
183 | */ | 183 | */ |
184 | int | 184 | int |
185 | main(int argc, char *const *argv) | 185 | main (int argc, char *const *argv) |
186 | { | 186 | { |
187 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 187 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
188 | GNUNET_GETOPT_OPTION_END | 188 | GNUNET_GETOPT_OPTION_END |
189 | }; | 189 | }; |
190 | 190 | ||
191 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 191 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
192 | return 2; | 192 | return 2; |
193 | 193 | ||
194 | ret = (GNUNET_OK == | 194 | ret = (GNUNET_OK == |
195 | GNUNET_PROGRAM_run(argc, | 195 | GNUNET_PROGRAM_run (argc, |
196 | argv, | 196 | argv, |
197 | "gnunet-directory [OPTIONS] FILENAME", | 197 | "gnunet-directory [OPTIONS] FILENAME", |
198 | gettext_noop( | 198 | gettext_noop ( |
199 | "Display contents of a GNUnet directory"), | 199 | "Display contents of a GNUnet directory"), |
200 | options, | 200 | options, |
201 | &run, | 201 | &run, |
202 | NULL)) | 202 | NULL)) |
203 | ? ret | 203 | ? ret |
204 | : 1; | 204 | : 1; |
205 | GNUNET_free((void *)argv); | 205 | GNUNET_free ((void *) argv); |
206 | return ret; | 206 | return ret; |
207 | } | 207 | } |
208 | 208 | ||
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index 14a43e6ec..05e102eac 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c | |||
@@ -54,21 +54,21 @@ static int local_only; | |||
54 | 54 | ||
55 | 55 | ||
56 | static void | 56 | static void |
57 | cleanup_task(void *cls) | 57 | cleanup_task (void *cls) |
58 | { | 58 | { |
59 | GNUNET_FS_stop(ctx); | 59 | GNUNET_FS_stop (ctx); |
60 | ctx = NULL; | 60 | ctx = NULL; |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | static void | 64 | static void |
65 | shutdown_task(void *cls) | 65 | shutdown_task (void *cls) |
66 | { | 66 | { |
67 | if (NULL != dc) | 67 | if (NULL != dc) |
68 | { | 68 | { |
69 | GNUNET_FS_download_stop(dc, delete_incomplete); | 69 | GNUNET_FS_download_stop (dc, delete_incomplete); |
70 | dc = NULL; | 70 | dc = NULL; |
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
@@ -80,25 +80,25 @@ shutdown_task(void *cls) | |||
80 | * @param w desired number of steps in the progress bar | 80 | * @param w desired number of steps in the progress bar |
81 | */ | 81 | */ |
82 | static void | 82 | static void |
83 | display_bar(unsigned long long x, unsigned long long n, unsigned int w) | 83 | display_bar (unsigned long long x, unsigned long long n, unsigned int w) |
84 | { | 84 | { |
85 | char buf[w + 20]; | 85 | char buf[w + 20]; |
86 | unsigned int p; | 86 | unsigned int p; |
87 | unsigned int endeq; | 87 | unsigned int endeq; |
88 | float ratio_complete; | 88 | float ratio_complete; |
89 | 89 | ||
90 | if (0 == isatty(1)) | 90 | if (0 == isatty (1)) |
91 | return; | 91 | return; |
92 | ratio_complete = x / (float)n; | 92 | ratio_complete = x / (float) n; |
93 | endeq = ratio_complete * w; | 93 | endeq = ratio_complete * w; |
94 | GNUNET_snprintf(buf, sizeof(buf), "%3d%% [", (int)(ratio_complete * 100)); | 94 | GNUNET_snprintf (buf, sizeof(buf), "%3d%% [", (int) (ratio_complete * 100)); |
95 | for (p = 0; p < endeq; p++) | 95 | for (p = 0; p < endeq; p++) |
96 | strcat(buf, "="); | 96 | strcat (buf, "="); |
97 | for (p = endeq; p < w; p++) | 97 | for (p = endeq; p < w; p++) |
98 | strcat(buf, " "); | 98 | strcat (buf, " "); |
99 | strcat(buf, "]\r"); | 99 | strcat (buf, "]\r"); |
100 | printf("%s", buf); | 100 | printf ("%s", buf); |
101 | fflush(stdout); | 101 | fflush (stdout); |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
@@ -116,96 +116,96 @@ display_bar(unsigned long long x, unsigned long long n, unsigned int w) | |||
116 | * field in the `struct GNUNET_FS_ProgressInfo` | 116 | * field in the `struct GNUNET_FS_ProgressInfo` |
117 | */ | 117 | */ |
118 | static void * | 118 | static void * |
119 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) | 119 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
120 | { | 120 | { |
121 | char *s; | 121 | char *s; |
122 | const char *s2; | 122 | const char *s2; |
123 | char *t; | 123 | char *t; |
124 | 124 | ||
125 | switch (info->status) | 125 | switch (info->status) |
126 | { | ||
127 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
128 | if (verbose > 1) | ||
129 | fprintf (stderr, | ||
130 | _ ("Starting download `%s'.\n"), | ||
131 | info->value.download.filename); | ||
132 | break; | ||
133 | |||
134 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
135 | if (verbose) | ||
126 | { | 136 | { |
127 | case GNUNET_FS_STATUS_DOWNLOAD_START: | 137 | s = GNUNET_strdup ( |
128 | if (verbose > 1) | 138 | GNUNET_STRINGS_relative_time_to_string (info->value.download.eta, |
129 | fprintf(stderr, | 139 | GNUNET_YES)); |
130 | _("Starting download `%s'.\n"), | 140 | if (info->value.download.specifics.progress.block_download_duration |
131 | info->value.download.filename); | 141 | .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) |
132 | break; | 142 | s2 = _ ("<unknown time>"); |
133 | |||
134 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
135 | if (verbose) | ||
136 | { | ||
137 | s = GNUNET_strdup( | ||
138 | GNUNET_STRINGS_relative_time_to_string(info->value.download.eta, | ||
139 | GNUNET_YES)); | ||
140 | if (info->value.download.specifics.progress.block_download_duration | ||
141 | .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | ||
142 | s2 = _("<unknown time>"); | ||
143 | else | ||
144 | s2 = GNUNET_STRINGS_relative_time_to_string(info->value.download | ||
145 | .specifics.progress | ||
146 | .block_download_duration, | ||
147 | GNUNET_YES); | ||
148 | t = GNUNET_STRINGS_byte_size_fancy( | ||
149 | info->value.download.completed * 1000LL / | ||
150 | (info->value.download.duration.rel_value_us + 1)); | ||
151 | fprintf( | ||
152 | stdout, | ||
153 | _( | ||
154 | "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), | ||
155 | info->value.download.filename, | ||
156 | (unsigned long long)info->value.download.completed, | ||
157 | (unsigned long long)info->value.download.size, | ||
158 | s, | ||
159 | t, | ||
160 | s2); | ||
161 | GNUNET_free(s); | ||
162 | GNUNET_free(t); | ||
163 | } | ||
164 | else | 143 | else |
165 | { | 144 | s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download |
166 | display_bar(info->value.download.completed, | 145 | .specifics.progress |
167 | info->value.download.size, | 146 | .block_download_duration, |
168 | 60); | 147 | GNUNET_YES); |
169 | } | 148 | t = GNUNET_STRINGS_byte_size_fancy ( |
170 | break; | 149 | info->value.download.completed * 1000LL |
171 | 150 | / (info->value.download.duration.rel_value_us + 1)); | |
172 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 151 | fprintf ( |
173 | if (0 != isatty(1)) | 152 | stdout, |
174 | fprintf(stdout, "\n"); | 153 | _ ( |
175 | fprintf(stderr, | 154 | "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), |
176 | _("Error downloading: %s.\n"), | 155 | info->value.download.filename, |
177 | info->value.download.specifics.error.message); | 156 | (unsigned long long) info->value.download.completed, |
178 | GNUNET_SCHEDULER_shutdown(); | 157 | (unsigned long long) info->value.download.size, |
179 | break; | 158 | s, |
180 | 159 | t, | |
181 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 160 | s2); |
182 | s = GNUNET_STRINGS_byte_size_fancy( | 161 | GNUNET_free (s); |
183 | info->value.download.completed * 1000 / | 162 | GNUNET_free (t); |
184 | (info->value.download.duration.rel_value_us + 1)); | 163 | } |
185 | if (0 != isatty(1)) | 164 | else |
186 | fprintf(stdout, "\n"); | 165 | { |
187 | fprintf(stdout, | 166 | display_bar (info->value.download.completed, |
188 | _("Downloading `%s' done (%s/s).\n"), | 167 | info->value.download.size, |
189 | info->value.download.filename, | 168 | 60); |
190 | s); | ||
191 | GNUNET_free(s); | ||
192 | if (info->value.download.dc == dc) | ||
193 | GNUNET_SCHEDULER_shutdown(); | ||
194 | break; | ||
195 | |||
196 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
197 | if (info->value.download.dc == dc) | ||
198 | GNUNET_SCHEDULER_add_now(&cleanup_task, NULL); | ||
199 | break; | ||
200 | |||
201 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
202 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
203 | break; | ||
204 | |||
205 | default: | ||
206 | fprintf(stderr, _("Unexpected status: %d\n"), info->status); | ||
207 | break; | ||
208 | } | 169 | } |
170 | break; | ||
171 | |||
172 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
173 | if (0 != isatty (1)) | ||
174 | fprintf (stdout, "\n"); | ||
175 | fprintf (stderr, | ||
176 | _ ("Error downloading: %s.\n"), | ||
177 | info->value.download.specifics.error.message); | ||
178 | GNUNET_SCHEDULER_shutdown (); | ||
179 | break; | ||
180 | |||
181 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | ||
182 | s = GNUNET_STRINGS_byte_size_fancy ( | ||
183 | info->value.download.completed * 1000 | ||
184 | / (info->value.download.duration.rel_value_us + 1)); | ||
185 | if (0 != isatty (1)) | ||
186 | fprintf (stdout, "\n"); | ||
187 | fprintf (stdout, | ||
188 | _ ("Downloading `%s' done (%s/s).\n"), | ||
189 | info->value.download.filename, | ||
190 | s); | ||
191 | GNUNET_free (s); | ||
192 | if (info->value.download.dc == dc) | ||
193 | GNUNET_SCHEDULER_shutdown (); | ||
194 | break; | ||
195 | |||
196 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
197 | if (info->value.download.dc == dc) | ||
198 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | ||
199 | break; | ||
200 | |||
201 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
202 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
203 | break; | ||
204 | |||
205 | default: | ||
206 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); | ||
207 | break; | ||
208 | } | ||
209 | return NULL; | 209 | return NULL; |
210 | } | 210 | } |
211 | 211 | ||
@@ -219,84 +219,84 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
219 | * @param c configuration | 219 | * @param c configuration |
220 | */ | 220 | */ |
221 | static void | 221 | static void |
222 | run(void *cls, | 222 | run (void *cls, |
223 | char *const *args, | 223 | char *const *args, |
224 | const char *cfgfile, | 224 | const char *cfgfile, |
225 | const struct GNUNET_CONFIGURATION_Handle *c) | 225 | const struct GNUNET_CONFIGURATION_Handle *c) |
226 | { | 226 | { |
227 | struct GNUNET_FS_Uri *uri; | 227 | struct GNUNET_FS_Uri *uri; |
228 | char *emsg; | 228 | char *emsg; |
229 | enum GNUNET_FS_DownloadOptions options; | 229 | enum GNUNET_FS_DownloadOptions options; |
230 | 230 | ||
231 | if (NULL == args[0]) | 231 | if (NULL == args[0]) |
232 | { | 232 | { |
233 | fprintf(stderr, "%s", _("You need to specify a URI argument.\n")); | 233 | fprintf (stderr, "%s", _ ("You need to specify a URI argument.\n")); |
234 | return; | 234 | return; |
235 | } | 235 | } |
236 | uri = GNUNET_FS_uri_parse(args[0], &emsg); | 236 | uri = GNUNET_FS_uri_parse (args[0], &emsg); |
237 | if (NULL == uri) | 237 | if (NULL == uri) |
238 | { | 238 | { |
239 | fprintf(stderr, _("Failed to parse URI: %s\n"), emsg); | 239 | fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg); |
240 | GNUNET_free(emsg); | 240 | GNUNET_free (emsg); |
241 | ret = 1; | 241 | ret = 1; |
242 | return; | 242 | return; |
243 | } | 243 | } |
244 | if ((!GNUNET_FS_uri_test_chk(uri)) && (!GNUNET_FS_uri_test_loc(uri))) | 244 | if ((! GNUNET_FS_uri_test_chk (uri)) && (! GNUNET_FS_uri_test_loc (uri))) |
245 | { | 245 | { |
246 | fprintf(stderr, "%s", _("Only CHK or LOC URIs supported.\n")); | 246 | fprintf (stderr, "%s", _ ("Only CHK or LOC URIs supported.\n")); |
247 | ret = 1; | 247 | ret = 1; |
248 | GNUNET_FS_uri_destroy(uri); | 248 | GNUNET_FS_uri_destroy (uri); |
249 | return; | 249 | return; |
250 | } | 250 | } |
251 | if (NULL == filename) | 251 | if (NULL == filename) |
252 | { | 252 | { |
253 | fprintf(stderr, "%s", _("Target filename must be specified.\n")); | 253 | fprintf (stderr, "%s", _ ("Target filename must be specified.\n")); |
254 | ret = 1; | 254 | ret = 1; |
255 | GNUNET_FS_uri_destroy(uri); | 255 | GNUNET_FS_uri_destroy (uri); |
256 | return; | 256 | return; |
257 | } | 257 | } |
258 | cfg = c; | 258 | cfg = c; |
259 | ctx = GNUNET_FS_start(cfg, | 259 | ctx = GNUNET_FS_start (cfg, |
260 | "gnunet-download", | 260 | "gnunet-download", |
261 | &progress_cb, | 261 | &progress_cb, |
262 | NULL, | 262 | NULL, |
263 | GNUNET_FS_FLAGS_NONE, | 263 | GNUNET_FS_FLAGS_NONE, |
264 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, | 264 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, |
265 | parallelism, | 265 | parallelism, |
266 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, | 266 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, |
267 | request_parallelism, | 267 | request_parallelism, |
268 | GNUNET_FS_OPTIONS_END); | 268 | GNUNET_FS_OPTIONS_END); |
269 | if (NULL == ctx) | 269 | if (NULL == ctx) |
270 | { | 270 | { |
271 | fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); | 271 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); |
272 | GNUNET_FS_uri_destroy(uri); | 272 | GNUNET_FS_uri_destroy (uri); |
273 | ret = 1; | 273 | ret = 1; |
274 | return; | 274 | return; |
275 | } | 275 | } |
276 | options = GNUNET_FS_DOWNLOAD_OPTION_NONE; | 276 | options = GNUNET_FS_DOWNLOAD_OPTION_NONE; |
277 | if (do_recursive) | 277 | if (do_recursive) |
278 | options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; | 278 | options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; |
279 | if (local_only) | 279 | if (local_only) |
280 | options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; | 280 | options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; |
281 | dc = GNUNET_FS_download_start(ctx, | 281 | dc = GNUNET_FS_download_start (ctx, |
282 | uri, | 282 | uri, |
283 | NULL, | 283 | NULL, |
284 | filename, | 284 | filename, |
285 | NULL, | 285 | NULL, |
286 | 0, | 286 | 0, |
287 | GNUNET_FS_uri_chk_get_file_size(uri), | 287 | GNUNET_FS_uri_chk_get_file_size (uri), |
288 | anonymity, | 288 | anonymity, |
289 | options, | 289 | options, |
290 | NULL, | 290 | NULL, |
291 | NULL); | 291 | NULL); |
292 | GNUNET_FS_uri_destroy(uri); | 292 | GNUNET_FS_uri_destroy (uri); |
293 | if (dc == NULL) | 293 | if (dc == NULL) |
294 | { | 294 | { |
295 | GNUNET_FS_stop(ctx); | 295 | GNUNET_FS_stop (ctx); |
296 | ctx = NULL; | 296 | ctx = NULL; |
297 | return; | 297 | return; |
298 | } | 298 | } |
299 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 299 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
300 | } | 300 | } |
301 | 301 | ||
302 | 302 | ||
@@ -308,75 +308,75 @@ run(void *cls, | |||
308 | * @return 0 ok, 1 on error | 308 | * @return 0 ok, 1 on error |
309 | */ | 309 | */ |
310 | int | 310 | int |
311 | main(int argc, char *const *argv) | 311 | main (int argc, char *const *argv) |
312 | { | 312 | { |
313 | struct GNUNET_GETOPT_CommandLineOption options[] = | 313 | struct GNUNET_GETOPT_CommandLineOption options[] = |
314 | { GNUNET_GETOPT_option_uint('a', | 314 | { GNUNET_GETOPT_option_uint ('a', |
315 | "anonymity", | 315 | "anonymity", |
316 | "LEVEL", | 316 | "LEVEL", |
317 | gettext_noop( | 317 | gettext_noop ( |
318 | "set the desired LEVEL of receiver-anonymity"), | 318 | "set the desired LEVEL of receiver-anonymity"), |
319 | &anonymity), | 319 | &anonymity), |
320 | 320 | ||
321 | GNUNET_GETOPT_option_flag( | 321 | GNUNET_GETOPT_option_flag ( |
322 | 'D', | 322 | 'D', |
323 | "delete-incomplete", | 323 | "delete-incomplete", |
324 | gettext_noop("delete incomplete downloads (when aborted with CTRL-C)"), | 324 | gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), |
325 | &delete_incomplete), | 325 | &delete_incomplete), |
326 | 326 | ||
327 | GNUNET_GETOPT_option_flag( | 327 | GNUNET_GETOPT_option_flag ( |
328 | 'n', | 328 | 'n', |
329 | "no-network", | 329 | "no-network", |
330 | gettext_noop("only search the local peer (no P2P network search)"), | 330 | gettext_noop ("only search the local peer (no P2P network search)"), |
331 | &local_only), | 331 | &local_only), |
332 | GNUNET_GETOPT_option_string('o', | 332 | GNUNET_GETOPT_option_string ('o', |
333 | "output", | 333 | "output", |
334 | "FILENAME", | 334 | "FILENAME", |
335 | gettext_noop("write the file to FILENAME"), | 335 | gettext_noop ("write the file to FILENAME"), |
336 | &filename), | 336 | &filename), |
337 | GNUNET_GETOPT_option_uint( | 337 | GNUNET_GETOPT_option_uint ( |
338 | 'p', | 338 | 'p', |
339 | "parallelism", | 339 | "parallelism", |
340 | "DOWNLOADS", | 340 | "DOWNLOADS", |
341 | gettext_noop( | 341 | gettext_noop ( |
342 | "set the maximum number of parallel downloads that is allowed"), | 342 | "set the maximum number of parallel downloads that is allowed"), |
343 | ¶llelism), | 343 | ¶llelism), |
344 | GNUNET_GETOPT_option_uint( | 344 | GNUNET_GETOPT_option_uint ( |
345 | 'r', | 345 | 'r', |
346 | "request-parallelism", | 346 | "request-parallelism", |
347 | "REQUESTS", | 347 | "REQUESTS", |
348 | gettext_noop( | 348 | gettext_noop ( |
349 | "set the maximum number of parallel requests for blocks that is allowed"), | 349 | "set the maximum number of parallel requests for blocks that is allowed"), |
350 | &request_parallelism), | 350 | &request_parallelism), |
351 | GNUNET_GETOPT_option_flag('R', | 351 | GNUNET_GETOPT_option_flag ('R', |
352 | "recursive", | 352 | "recursive", |
353 | gettext_noop( | 353 | gettext_noop ( |
354 | "download a GNUnet directory recursively"), | 354 | "download a GNUnet directory recursively"), |
355 | &do_recursive), | 355 | &do_recursive), |
356 | GNUNET_GETOPT_option_increment_uint( | 356 | GNUNET_GETOPT_option_increment_uint ( |
357 | 'V', | 357 | 'V', |
358 | "verbose", | 358 | "verbose", |
359 | gettext_noop("be verbose (print progress information)"), | 359 | gettext_noop ("be verbose (print progress information)"), |
360 | &verbose), | 360 | &verbose), |
361 | GNUNET_GETOPT_OPTION_END }; | 361 | GNUNET_GETOPT_OPTION_END }; |
362 | 362 | ||
363 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 363 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
364 | return 2; | 364 | return 2; |
365 | 365 | ||
366 | ret = | 366 | ret = |
367 | (GNUNET_OK == | 367 | (GNUNET_OK == |
368 | GNUNET_PROGRAM_run( | 368 | GNUNET_PROGRAM_run ( |
369 | argc, | 369 | argc, |
370 | argv, | 370 | argv, |
371 | "gnunet-download [OPTIONS] URI", | 371 | "gnunet-download [OPTIONS] URI", |
372 | gettext_noop( | 372 | gettext_noop ( |
373 | "Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), | 373 | "Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), |
374 | options, | 374 | options, |
375 | &run, | 375 | &run, |
376 | NULL)) | 376 | NULL)) |
377 | ? ret | 377 | ? ret |
378 | : 1; | 378 | : 1; |
379 | GNUNET_free((void *)argv); | 379 | GNUNET_free ((void *) argv); |
380 | return ret; | 380 | return ret; |
381 | } | 381 | } |
382 | 382 | ||
diff --git a/src/fs/gnunet-fs-profiler.c b/src/fs/gnunet-fs-profiler.c index d47ca8b29..a6e248213 100644 --- a/src/fs/gnunet-fs-profiler.c +++ b/src/fs/gnunet-fs-profiler.c | |||
@@ -50,7 +50,7 @@ static struct GNUNET_TIME_Relative timeout; | |||
50 | /** | 50 | /** |
51 | * Handle to the task run during termination. | 51 | * Handle to the task run during termination. |
52 | */ | 52 | */ |
53 | static struct GNUNET_SCHEDULER_Task * terminate_taskid; | 53 | static struct GNUNET_SCHEDULER_Task *terminate_taskid; |
54 | 54 | ||
55 | 55 | ||
56 | /** | 56 | /** |
@@ -62,15 +62,15 @@ static struct GNUNET_SCHEDULER_Task * terminate_taskid; | |||
62 | * operation has executed successfully. | 62 | * operation has executed successfully. |
63 | */ | 63 | */ |
64 | static void | 64 | static void |
65 | shutdown_task(void *cls, | 65 | shutdown_task (void *cls, |
66 | struct GNUNET_TESTBED_Operation *op, | 66 | struct GNUNET_TESTBED_Operation *op, |
67 | const char *emsg) | 67 | const char *emsg) |
68 | { | 68 | { |
69 | if (NULL != emsg) | 69 | if (NULL != emsg) |
70 | fprintf(stderr, | 70 | fprintf (stderr, |
71 | "Error collecting statistics: %s\n", | 71 | "Error collecting statistics: %s\n", |
72 | emsg); | 72 | emsg); |
73 | GNUNET_SCHEDULER_shutdown(); | 73 | GNUNET_SCHEDULER_shutdown (); |
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
@@ -87,19 +87,19 @@ shutdown_task(void *cls, | |||
87 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 87 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
88 | */ | 88 | */ |
89 | static int | 89 | static int |
90 | process_stats(void *cls, | 90 | process_stats (void *cls, |
91 | const struct GNUNET_TESTBED_Peer *peer, | 91 | const struct GNUNET_TESTBED_Peer *peer, |
92 | const char *subsystem, | 92 | const char *subsystem, |
93 | const char *name, | 93 | const char *name, |
94 | uint64_t value, | 94 | uint64_t value, |
95 | int is_persistent) | 95 | int is_persistent) |
96 | { | 96 | { |
97 | fprintf(stdout, | 97 | fprintf (stdout, |
98 | "%p-%s: %s = %llu\n", | 98 | "%p-%s: %s = %llu\n", |
99 | peer, | 99 | peer, |
100 | subsystem, | 100 | subsystem, |
101 | name, | 101 | name, |
102 | (unsigned long long)value); | 102 | (unsigned long long) value); |
103 | return GNUNET_OK; | 103 | return GNUNET_OK; |
104 | } | 104 | } |
105 | 105 | ||
@@ -111,18 +111,18 @@ process_stats(void *cls, | |||
111 | * @param cls NULL | 111 | * @param cls NULL |
112 | */ | 112 | */ |
113 | static void | 113 | static void |
114 | terminate_task(void *cls) | 114 | terminate_task (void *cls) |
115 | { | 115 | { |
116 | if (NULL != terminate_taskid) | 116 | if (NULL != terminate_taskid) |
117 | { | 117 | { |
118 | GNUNET_SCHEDULER_cancel(terminate_taskid); | 118 | GNUNET_SCHEDULER_cancel (terminate_taskid); |
119 | terminate_taskid = NULL; | 119 | terminate_taskid = NULL; |
120 | } | 120 | } |
121 | GNUNET_TESTBED_get_statistics(0, NULL, | 121 | GNUNET_TESTBED_get_statistics (0, NULL, |
122 | NULL, NULL, | 122 | NULL, NULL, |
123 | &process_stats, | 123 | &process_stats, |
124 | &shutdown_task, | 124 | &shutdown_task, |
125 | NULL); | 125 | NULL); |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
@@ -133,10 +133,10 @@ terminate_task(void *cls) | |||
133 | * @param cls NULL | 133 | * @param cls NULL |
134 | */ | 134 | */ |
135 | static void | 135 | static void |
136 | timeout_task(void *cls) | 136 | timeout_task (void *cls) |
137 | { | 137 | { |
138 | terminate_taskid = NULL; | 138 | terminate_taskid = NULL; |
139 | GNUNET_SCHEDULER_shutdown(); | 139 | GNUNET_SCHEDULER_shutdown (); |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
@@ -153,23 +153,23 @@ timeout_task(void *cls) | |||
153 | * failed | 153 | * failed |
154 | */ | 154 | */ |
155 | static void | 155 | static void |
156 | test_master(void *cls, | 156 | test_master (void *cls, |
157 | struct GNUNET_TESTBED_RunHandle *h, | 157 | struct GNUNET_TESTBED_RunHandle *h, |
158 | unsigned int num_peers, | 158 | unsigned int num_peers, |
159 | struct GNUNET_TESTBED_Peer **peers, | 159 | struct GNUNET_TESTBED_Peer **peers, |
160 | unsigned int links_succeeded, | 160 | unsigned int links_succeeded, |
161 | unsigned int links_failed) | 161 | unsigned int links_failed) |
162 | { | 162 | { |
163 | // const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 163 | // const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
164 | // FIXME: enable clients to signal 'completion' before timeout; | 164 | // FIXME: enable clients to signal 'completion' before timeout; |
165 | // in that case, run the 'terminate_task' "immediately" | 165 | // in that case, run the 'terminate_task' "immediately" |
166 | 166 | ||
167 | if (0 != timeout.rel_value_us) | 167 | if (0 != timeout.rel_value_us) |
168 | terminate_taskid = GNUNET_SCHEDULER_add_delayed(timeout, | 168 | terminate_taskid = GNUNET_SCHEDULER_add_delayed (timeout, |
169 | &timeout_task, | 169 | &timeout_task, |
170 | NULL); | 170 | NULL); |
171 | GNUNET_SCHEDULER_add_shutdown(&terminate_task, | 171 | GNUNET_SCHEDULER_add_shutdown (&terminate_task, |
172 | NULL); | 172 | NULL); |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
@@ -182,14 +182,14 @@ test_master(void *cls, | |||
182 | * @param cfg configuration | 182 | * @param cfg configuration |
183 | */ | 183 | */ |
184 | static void | 184 | static void |
185 | run(void *cls, char *const *args, const char *cfgfile, | 185 | run (void *cls, char *const *args, const char *cfgfile, |
186 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 186 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
187 | { | 187 | { |
188 | GNUNET_TESTBED_run(host_filename, | 188 | GNUNET_TESTBED_run (host_filename, |
189 | cfg, | 189 | cfg, |
190 | num_peers, | 190 | num_peers, |
191 | 0, NULL, NULL, | 191 | 0, NULL, NULL, |
192 | &test_master, (void *)cfg); | 192 | &test_master, (void *) cfg); |
193 | } | 193 | } |
194 | 194 | ||
195 | 195 | ||
@@ -201,38 +201,43 @@ run(void *cls, char *const *args, const char *cfgfile, | |||
201 | * @return 0 ok, 1 on error | 201 | * @return 0 ok, 1 on error |
202 | */ | 202 | */ |
203 | int | 203 | int |
204 | main(int argc, char *const *argv) | 204 | main (int argc, char *const *argv) |
205 | { | 205 | { |
206 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 206 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
207 | GNUNET_GETOPT_option_uint('n', | 207 | GNUNET_GETOPT_option_uint ('n', |
208 | "num-peers", | 208 | "num-peers", |
209 | "COUNT", | 209 | "COUNT", |
210 | gettext_noop("run the experiment with COUNT peers"), | 210 | gettext_noop ( |
211 | &num_peers), | 211 | "run the experiment with COUNT peers"), |
212 | 212 | &num_peers), | |
213 | GNUNET_GETOPT_option_string('H', | 213 | |
214 | "hosts", | 214 | GNUNET_GETOPT_option_string ('H', |
215 | "HOSTFILE", | 215 | "hosts", |
216 | gettext_noop("specifies name of a file with the HOSTS the testbed should use"), | 216 | "HOSTFILE", |
217 | &host_filename), | 217 | gettext_noop ( |
218 | 218 | "specifies name of a file with the HOSTS the testbed should use"), | |
219 | GNUNET_GETOPT_option_relative_time('t', | 219 | &host_filename), |
220 | "timeout", | 220 | |
221 | "DELAY", | 221 | GNUNET_GETOPT_option_relative_time ('t', |
222 | gettext_noop("automatically terminate experiment after DELAY"), | 222 | "timeout", |
223 | &timeout), | 223 | "DELAY", |
224 | gettext_noop ( | ||
225 | "automatically terminate experiment after DELAY"), | ||
226 | &timeout), | ||
224 | 227 | ||
225 | GNUNET_GETOPT_OPTION_END | 228 | GNUNET_GETOPT_OPTION_END |
226 | }; | 229 | }; |
227 | 230 | ||
228 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 231 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
229 | return 2; | 232 | return 2; |
230 | 233 | ||
231 | ret = (GNUNET_OK == | 234 | ret = (GNUNET_OK == |
232 | GNUNET_PROGRAM_run(argc, argv, "gnunet-fs-profiler", | 235 | GNUNET_PROGRAM_run (argc, argv, "gnunet-fs-profiler", |
233 | gettext_noop("run a testbed to measure file-sharing performance"), options, &run, | 236 | gettext_noop ( |
234 | NULL)) ? ret : 1; | 237 | "run a testbed to measure file-sharing performance"), |
235 | GNUNET_free((void*)argv); | 238 | options, &run, |
239 | NULL)) ? ret : 1; | ||
240 | GNUNET_free ((void*) argv); | ||
236 | return ret; | 241 | return ret; |
237 | } | 242 | } |
238 | 243 | ||
diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c index 3fa65d6cb..a44fcdf7a 100644 --- a/src/fs/gnunet-fs.c +++ b/src/fs/gnunet-fs.c | |||
@@ -55,20 +55,20 @@ static unsigned int verbose; | |||
55 | * @return GNUNET_OK to continue iteration | 55 | * @return GNUNET_OK to continue iteration |
56 | */ | 56 | */ |
57 | static int | 57 | static int |
58 | print_indexed(void *cls, | 58 | print_indexed (void *cls, |
59 | const char *filename, | 59 | const char *filename, |
60 | const struct GNUNET_HashCode *file_id) | 60 | const struct GNUNET_HashCode *file_id) |
61 | { | 61 | { |
62 | if (NULL == filename) | 62 | if (NULL == filename) |
63 | { | 63 | { |
64 | GNUNET_FS_stop(fs); | 64 | GNUNET_FS_stop (fs); |
65 | fs = NULL; | 65 | fs = NULL; |
66 | return GNUNET_OK; | 66 | return GNUNET_OK; |
67 | } | 67 | } |
68 | if (verbose) | 68 | if (verbose) |
69 | fprintf(stdout, "%s: %s\n", GNUNET_h2s(file_id), filename); | 69 | fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename); |
70 | else | 70 | else |
71 | fprintf(stdout, "%s\n", filename); | 71 | fprintf (stdout, "%s\n", filename); |
72 | return GNUNET_OK; | 72 | return GNUNET_OK; |
73 | } | 73 | } |
74 | 74 | ||
@@ -82,32 +82,32 @@ print_indexed(void *cls, | |||
82 | * @param cfg configuration | 82 | * @param cfg configuration |
83 | */ | 83 | */ |
84 | static void | 84 | static void |
85 | run(void *cls, | 85 | run (void *cls, |
86 | char *const *args, | 86 | char *const *args, |
87 | const char *cfgfile, | 87 | const char *cfgfile, |
88 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 88 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
89 | { | 89 | { |
90 | if (list_indexed_files) | 90 | if (list_indexed_files) |
91 | { | ||
92 | fs = GNUNET_FS_start (cfg, | ||
93 | "gnunet-fs", | ||
94 | NULL, | ||
95 | NULL, | ||
96 | GNUNET_FS_FLAGS_NONE, | ||
97 | GNUNET_FS_OPTIONS_END); | ||
98 | if (NULL == fs) | ||
91 | { | 99 | { |
92 | fs = GNUNET_FS_start(cfg, | 100 | ret = 1; |
93 | "gnunet-fs", | 101 | return; |
94 | NULL, | 102 | } |
95 | NULL, | 103 | if (NULL == GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL)) |
96 | GNUNET_FS_FLAGS_NONE, | 104 | { |
97 | GNUNET_FS_OPTIONS_END); | 105 | ret = 2; |
98 | if (NULL == fs) | 106 | GNUNET_FS_stop (fs); |
99 | { | 107 | fs = NULL; |
100 | ret = 1; | 108 | return; |
101 | return; | ||
102 | } | ||
103 | if (NULL == GNUNET_FS_get_indexed_files(fs, &print_indexed, NULL)) | ||
104 | { | ||
105 | ret = 2; | ||
106 | GNUNET_FS_stop(fs); | ||
107 | fs = NULL; | ||
108 | return; | ||
109 | } | ||
110 | } | 109 | } |
110 | } | ||
111 | } | 111 | } |
112 | 112 | ||
113 | /** | 113 | /** |
@@ -118,32 +118,32 @@ run(void *cls, | |||
118 | * @return 0 ok, 1 on error | 118 | * @return 0 ok, 1 on error |
119 | */ | 119 | */ |
120 | int | 120 | int |
121 | main(int argc, char *const *argv) | 121 | main (int argc, char *const *argv) |
122 | { | 122 | { |
123 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 123 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
124 | GNUNET_GETOPT_option_flag('i', | 124 | GNUNET_GETOPT_option_flag ('i', |
125 | "list-indexed", | 125 | "list-indexed", |
126 | gettext_noop( | 126 | gettext_noop ( |
127 | "print a list of all indexed files"), | 127 | "print a list of all indexed files"), |
128 | &list_indexed_files), | 128 | &list_indexed_files), |
129 | 129 | ||
130 | GNUNET_GETOPT_option_verbose(&verbose), | 130 | GNUNET_GETOPT_option_verbose (&verbose), |
131 | GNUNET_GETOPT_OPTION_END | 131 | GNUNET_GETOPT_OPTION_END |
132 | }; | 132 | }; |
133 | 133 | ||
134 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 134 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
135 | return 2; | 135 | return 2; |
136 | ret = (GNUNET_OK == | 136 | ret = (GNUNET_OK == |
137 | GNUNET_PROGRAM_run(argc, | 137 | GNUNET_PROGRAM_run (argc, |
138 | argv, | 138 | argv, |
139 | "gnunet-fs [OPTIONS]", | 139 | "gnunet-fs [OPTIONS]", |
140 | gettext_noop("Special file-sharing operations"), | 140 | gettext_noop ("Special file-sharing operations"), |
141 | options, | 141 | options, |
142 | &run, | 142 | &run, |
143 | NULL)) | 143 | NULL)) |
144 | ? ret | 144 | ? ret |
145 | : 1; | 145 | : 1; |
146 | GNUNET_free((void *)argv); | 146 | GNUNET_free ((void *) argv); |
147 | return ret; | 147 | return ret; |
148 | } | 148 | } |
149 | 149 | ||
diff --git a/src/fs/gnunet-helper-fs-publish.c b/src/fs/gnunet-helper-fs-publish.c index a6776d84f..fb5f7497d 100644 --- a/src/fs/gnunet-helper-fs-publish.c +++ b/src/fs/gnunet-helper-fs-publish.c | |||
@@ -33,7 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * A node of a directory tree. | 34 | * A node of a directory tree. |
35 | */ | 35 | */ |
36 | struct ScanTreeNode { | 36 | struct ScanTreeNode |
37 | { | ||
37 | /** | 38 | /** |
38 | * This is a doubly-linked list | 39 | * This is a doubly-linked list |
39 | */ | 40 | */ |
@@ -111,41 +112,41 @@ static int output_stream; | |||
111 | * @return always 0 to continue extracting | 112 | * @return always 0 to continue extracting |
112 | */ | 113 | */ |
113 | static int | 114 | static int |
114 | add_to_md(void *cls, | 115 | add_to_md (void *cls, |
115 | const char *plugin_name, | 116 | const char *plugin_name, |
116 | enum EXTRACTOR_MetaType type, | 117 | enum EXTRACTOR_MetaType type, |
117 | enum EXTRACTOR_MetaFormat format, | 118 | enum EXTRACTOR_MetaFormat format, |
118 | const char *data_mime_type, | 119 | const char *data_mime_type, |
119 | const char *data, | 120 | const char *data, |
120 | size_t data_len) | 121 | size_t data_len) |
121 | { | 122 | { |
122 | struct GNUNET_CONTAINER_MetaData *md = cls; | 123 | struct GNUNET_CONTAINER_MetaData *md = cls; |
123 | 124 | ||
124 | if (((EXTRACTOR_METAFORMAT_UTF8 == format) || | 125 | if (((EXTRACTOR_METAFORMAT_UTF8 == format) || |
125 | (EXTRACTOR_METAFORMAT_C_STRING == format)) && | 126 | (EXTRACTOR_METAFORMAT_C_STRING == format)) && |
126 | ('\0' != data[data_len - 1])) | 127 | ('\0' != data[data_len - 1])) |
127 | { | 128 | { |
128 | char zdata[data_len + 1]; | 129 | char zdata[data_len + 1]; |
129 | GNUNET_memcpy(zdata, data, data_len); | 130 | GNUNET_memcpy (zdata, data, data_len); |
130 | zdata[data_len] = '\0'; | 131 | zdata[data_len] = '\0'; |
131 | (void)GNUNET_CONTAINER_meta_data_insert(md, | 132 | (void) GNUNET_CONTAINER_meta_data_insert (md, |
132 | plugin_name, | 133 | plugin_name, |
133 | type, | 134 | type, |
134 | format, | 135 | format, |
135 | data_mime_type, | 136 | data_mime_type, |
136 | zdata, | 137 | zdata, |
137 | data_len + 1); | 138 | data_len + 1); |
138 | } | 139 | } |
139 | else | 140 | else |
140 | { | 141 | { |
141 | (void)GNUNET_CONTAINER_meta_data_insert(md, | 142 | (void) GNUNET_CONTAINER_meta_data_insert (md, |
142 | plugin_name, | 143 | plugin_name, |
143 | type, | 144 | type, |
144 | format, | 145 | format, |
145 | data_mime_type, | 146 | data_mime_type, |
146 | data, | 147 | data, |
147 | data_len); | 148 | data_len); |
148 | } | 149 | } |
149 | return 0; | 150 | return 0; |
150 | } | 151 | } |
151 | #endif | 152 | #endif |
@@ -157,18 +158,18 @@ add_to_md(void *cls, | |||
157 | * @param tree tree to free | 158 | * @param tree tree to free |
158 | */ | 159 | */ |
159 | static void | 160 | static void |
160 | free_tree(struct ScanTreeNode *tree) | 161 | free_tree (struct ScanTreeNode *tree) |
161 | { | 162 | { |
162 | struct ScanTreeNode *pos; | 163 | struct ScanTreeNode *pos; |
163 | 164 | ||
164 | while (NULL != (pos = tree->children_head)) | 165 | while (NULL != (pos = tree->children_head)) |
165 | free_tree(pos); | 166 | free_tree (pos); |
166 | if (NULL != tree->parent) | 167 | if (NULL != tree->parent) |
167 | GNUNET_CONTAINER_DLL_remove(tree->parent->children_head, | 168 | GNUNET_CONTAINER_DLL_remove (tree->parent->children_head, |
168 | tree->parent->children_tail, | 169 | tree->parent->children_tail, |
169 | tree); | 170 | tree); |
170 | GNUNET_free(tree->filename); | 171 | GNUNET_free (tree->filename); |
171 | GNUNET_free(tree); | 172 | GNUNET_free (tree); |
172 | } | 173 | } |
173 | 174 | ||
174 | 175 | ||
@@ -180,7 +181,7 @@ free_tree(struct ScanTreeNode *tree) | |||
180 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 181 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
181 | */ | 182 | */ |
182 | static int | 183 | static int |
183 | write_all(const void *buf, size_t size) | 184 | write_all (const void *buf, size_t size) |
184 | { | 185 | { |
185 | const char *cbuf = buf; | 186 | const char *cbuf = buf; |
186 | size_t total; | 187 | size_t total; |
@@ -188,16 +189,16 @@ write_all(const void *buf, size_t size) | |||
188 | 189 | ||
189 | total = 0; | 190 | total = 0; |
190 | do | 191 | do |
191 | { | 192 | { |
192 | wr = write(output_stream, &cbuf[total], size - total); | 193 | wr = write (output_stream, &cbuf[total], size - total); |
193 | if (wr > 0) | 194 | if (wr > 0) |
194 | total += wr; | 195 | total += wr; |
195 | } | 196 | } |
196 | while ((wr > 0) && (total < size)); | 197 | while ((wr > 0) && (total < size)); |
197 | if (wr <= 0) | 198 | if (wr <= 0) |
198 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
199 | "Failed to write to stdout: %s\n", | 200 | "Failed to write to stdout: %s\n", |
200 | strerror(errno)); | 201 | strerror (errno)); |
201 | return (total == size) ? GNUNET_OK : GNUNET_SYSERR; | 202 | return (total == size) ? GNUNET_OK : GNUNET_SYSERR; |
202 | } | 203 | } |
203 | 204 | ||
@@ -211,20 +212,20 @@ write_all(const void *buf, size_t size) | |||
211 | * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) | 212 | * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) |
212 | */ | 213 | */ |
213 | static int | 214 | static int |
214 | write_message(uint16_t message_type, const char *data, size_t data_length) | 215 | write_message (uint16_t message_type, const char *data, size_t data_length) |
215 | { | 216 | { |
216 | struct GNUNET_MessageHeader hdr; | 217 | struct GNUNET_MessageHeader hdr; |
217 | 218 | ||
218 | #if 0 | 219 | #if 0 |
219 | fprintf(stderr, | 220 | fprintf (stderr, |
220 | "Helper sends %u-byte message of type %u\n", | 221 | "Helper sends %u-byte message of type %u\n", |
221 | (unsigned int)(sizeof(struct GNUNET_MessageHeader) + data_length), | 222 | (unsigned int) (sizeof(struct GNUNET_MessageHeader) + data_length), |
222 | (unsigned int)message_type); | 223 | (unsigned int) message_type); |
223 | #endif | 224 | #endif |
224 | hdr.type = htons(message_type); | 225 | hdr.type = htons (message_type); |
225 | hdr.size = htons(sizeof(struct GNUNET_MessageHeader) + data_length); | 226 | hdr.size = htons (sizeof(struct GNUNET_MessageHeader) + data_length); |
226 | if ((GNUNET_OK != write_all(&hdr, sizeof(hdr))) || | 227 | if ((GNUNET_OK != write_all (&hdr, sizeof(hdr))) || |
227 | (GNUNET_OK != write_all(data, data_length))) | 228 | (GNUNET_OK != write_all (data, data_length))) |
228 | return GNUNET_SYSERR; | 229 | return GNUNET_SYSERR; |
229 | return GNUNET_OK; | 230 | return GNUNET_OK; |
230 | } | 231 | } |
@@ -241,13 +242,14 @@ write_message(uint16_t message_type, const char *data, size_t data_length) | |||
241 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 242 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
242 | */ | 243 | */ |
243 | static int | 244 | static int |
244 | preprocess_file(const char *filename, struct ScanTreeNode **dst); | 245 | preprocess_file (const char *filename, struct ScanTreeNode **dst); |
245 | 246 | ||
246 | 247 | ||
247 | /** | 248 | /** |
248 | * Closure for the 'scan_callback' | 249 | * Closure for the 'scan_callback' |
249 | */ | 250 | */ |
250 | struct RecursionContext { | 251 | struct RecursionContext |
252 | { | ||
251 | /** | 253 | /** |
252 | * Parent to add the files to. | 254 | * Parent to add the files to. |
253 | */ | 255 | */ |
@@ -270,22 +272,22 @@ struct RecursionContext { | |||
270 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 272 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
271 | */ | 273 | */ |
272 | static int | 274 | static int |
273 | scan_callback(void *cls, const char *filename) | 275 | scan_callback (void *cls, const char *filename) |
274 | { | 276 | { |
275 | struct RecursionContext *rc = cls; | 277 | struct RecursionContext *rc = cls; |
276 | struct ScanTreeNode *chld; | 278 | struct ScanTreeNode *chld; |
277 | 279 | ||
278 | if (GNUNET_OK != preprocess_file(filename, &chld)) | 280 | if (GNUNET_OK != preprocess_file (filename, &chld)) |
279 | { | 281 | { |
280 | rc->stop = GNUNET_YES; | 282 | rc->stop = GNUNET_YES; |
281 | return GNUNET_SYSERR; | 283 | return GNUNET_SYSERR; |
282 | } | 284 | } |
283 | if (NULL == chld) | 285 | if (NULL == chld) |
284 | return GNUNET_OK; | 286 | return GNUNET_OK; |
285 | chld->parent = rc->parent; | 287 | chld->parent = rc->parent; |
286 | GNUNET_CONTAINER_DLL_insert(rc->parent->children_head, | 288 | GNUNET_CONTAINER_DLL_insert (rc->parent->children_head, |
287 | rc->parent->children_tail, | 289 | rc->parent->children_tail, |
288 | chld); | 290 | chld); |
289 | return GNUNET_OK; | 291 | return GNUNET_OK; |
290 | } | 292 | } |
291 | 293 | ||
@@ -301,60 +303,60 @@ scan_callback(void *cls, const char *filename) | |||
301 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 303 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
302 | */ | 304 | */ |
303 | static int | 305 | static int |
304 | preprocess_file(const char *filename, struct ScanTreeNode **dst) | 306 | preprocess_file (const char *filename, struct ScanTreeNode **dst) |
305 | { | 307 | { |
306 | struct ScanTreeNode *item; | 308 | struct ScanTreeNode *item; |
307 | struct stat sbuf; | 309 | struct stat sbuf; |
308 | uint64_t fsize = 0; | 310 | uint64_t fsize = 0; |
309 | 311 | ||
310 | if ((0 != stat(filename, &sbuf)) || | 312 | if ((0 != stat (filename, &sbuf)) || |
311 | ((!S_ISDIR(sbuf.st_mode)) && | 313 | ((! S_ISDIR (sbuf.st_mode)) && |
312 | (GNUNET_OK != | 314 | (GNUNET_OK != |
313 | GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)))) | 315 | GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)))) |
314 | { | 316 | { |
315 | /* If the file doesn't exist (or is not stat-able for any other reason) | 317 | /* If the file doesn't exist (or is not stat-able for any other reason) |
316 | skip it (but report it), but do continue. */ | 318 | skip it (but report it), but do continue. */ |
317 | if (GNUNET_OK != | 319 | if (GNUNET_OK != |
318 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, | 320 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, |
319 | filename, | 321 | filename, |
320 | strlen(filename) + 1)) | 322 | strlen (filename) + 1)) |
321 | return GNUNET_SYSERR; | 323 | return GNUNET_SYSERR; |
322 | /* recoverable error, store 'NULL' in *dst */ | 324 | /* recoverable error, store 'NULL' in *dst */ |
323 | *dst = NULL; | 325 | *dst = NULL; |
324 | return GNUNET_OK; | 326 | return GNUNET_OK; |
325 | } | 327 | } |
326 | 328 | ||
327 | /* Report the progress */ | 329 | /* Report the progress */ |
328 | if ( | 330 | if ( |
329 | GNUNET_OK != | 331 | GNUNET_OK != |
330 | write_message(S_ISDIR(sbuf.st_mode) | 332 | write_message (S_ISDIR (sbuf.st_mode) |
331 | ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY | 333 | ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY |
332 | : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, | 334 | : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, |
333 | filename, | 335 | filename, |
334 | strlen(filename) + 1)) | 336 | strlen (filename) + 1)) |
335 | return GNUNET_SYSERR; | 337 | return GNUNET_SYSERR; |
336 | item = GNUNET_new(struct ScanTreeNode); | 338 | item = GNUNET_new (struct ScanTreeNode); |
337 | item->filename = GNUNET_strdup(filename); | 339 | item->filename = GNUNET_strdup (filename); |
338 | item->is_directory = (S_ISDIR(sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO; | 340 | item->is_directory = (S_ISDIR (sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO; |
339 | item->file_size = fsize; | 341 | item->file_size = fsize; |
340 | if (GNUNET_YES == item->is_directory) | 342 | if (GNUNET_YES == item->is_directory) |
343 | { | ||
344 | struct RecursionContext rc; | ||
345 | |||
346 | rc.parent = item; | ||
347 | rc.stop = GNUNET_NO; | ||
348 | GNUNET_DISK_directory_scan (filename, &scan_callback, &rc); | ||
349 | if ( | ||
350 | (GNUNET_YES == rc.stop) || | ||
351 | (GNUNET_OK != | ||
352 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, | ||
353 | "..", | ||
354 | 3))) | ||
341 | { | 355 | { |
342 | struct RecursionContext rc; | 356 | free_tree (item); |
343 | 357 | return GNUNET_SYSERR; | |
344 | rc.parent = item; | ||
345 | rc.stop = GNUNET_NO; | ||
346 | GNUNET_DISK_directory_scan(filename, &scan_callback, &rc); | ||
347 | if ( | ||
348 | (GNUNET_YES == rc.stop) || | ||
349 | (GNUNET_OK != | ||
350 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, | ||
351 | "..", | ||
352 | 3))) | ||
353 | { | ||
354 | free_tree(item); | ||
355 | return GNUNET_SYSERR; | ||
356 | } | ||
357 | } | 358 | } |
359 | } | ||
358 | *dst = item; | 360 | *dst = item; |
359 | return GNUNET_OK; | 361 | return GNUNET_OK; |
360 | } | 362 | } |
@@ -367,67 +369,67 @@ preprocess_file(const char *filename, struct ScanTreeNode **dst) | |||
367 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors | 369 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors |
368 | */ | 370 | */ |
369 | static int | 371 | static int |
370 | extract_files(struct ScanTreeNode *item) | 372 | extract_files (struct ScanTreeNode *item) |
371 | { | 373 | { |
372 | struct GNUNET_CONTAINER_MetaData *meta; | 374 | struct GNUNET_CONTAINER_MetaData *meta; |
373 | ssize_t size; | 375 | ssize_t size; |
374 | size_t slen; | 376 | size_t slen; |
375 | 377 | ||
376 | if (GNUNET_YES == item->is_directory) | 378 | if (GNUNET_YES == item->is_directory) |
377 | { | 379 | { |
378 | /* for directories, we simply only descent, no extraction, no | 380 | /* for directories, we simply only descent, no extraction, no |
379 | progress reporting */ | 381 | progress reporting */ |
380 | struct ScanTreeNode *pos; | 382 | struct ScanTreeNode *pos; |
381 | 383 | ||
382 | for (pos = item->children_head; NULL != pos; pos = pos->next) | 384 | for (pos = item->children_head; NULL != pos; pos = pos->next) |
383 | if (GNUNET_OK != extract_files(pos)) | 385 | if (GNUNET_OK != extract_files (pos)) |
384 | return GNUNET_SYSERR; | 386 | return GNUNET_SYSERR; |
385 | return GNUNET_OK; | 387 | return GNUNET_OK; |
386 | } | 388 | } |
387 | 389 | ||
388 | /* this is the expensive operation, *afterwards* we'll check for aborts */ | 390 | /* this is the expensive operation, *afterwards* we'll check for aborts */ |
389 | meta = GNUNET_CONTAINER_meta_data_create(); | 391 | meta = GNUNET_CONTAINER_meta_data_create (); |
390 | #if HAVE_LIBEXTRACTOR | 392 | #if HAVE_LIBEXTRACTOR |
391 | EXTRACTOR_extract(plugins, item->filename, NULL, 0, &add_to_md, meta); | 393 | EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta); |
392 | #endif | 394 | #endif |
393 | slen = strlen(item->filename) + 1; | 395 | slen = strlen (item->filename) + 1; |
394 | size = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); | 396 | size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); |
395 | if (-1 == size) | 397 | if (-1 == size) |
396 | { | 398 | { |
397 | /* no meta data */ | 399 | /* no meta data */ |
398 | GNUNET_CONTAINER_meta_data_destroy(meta); | 400 | GNUNET_CONTAINER_meta_data_destroy (meta); |
399 | if (GNUNET_OK != | 401 | if (GNUNET_OK != |
400 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, | 402 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, |
401 | item->filename, | 403 | item->filename, |
402 | slen)) | 404 | slen)) |
403 | return GNUNET_SYSERR; | 405 | return GNUNET_SYSERR; |
404 | return GNUNET_OK; | 406 | return GNUNET_OK; |
405 | } | 407 | } |
406 | else if (size > (UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen)) | 408 | else if (size > (UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen)) |
407 | { | 409 | { |
408 | /* We can't transfer more than 64k bytes in one message. */ | 410 | /* We can't transfer more than 64k bytes in one message. */ |
409 | size = UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen; | 411 | size = UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen; |
410 | } | 412 | } |
411 | { | 413 | { |
412 | char buf[size + slen]; | 414 | char buf[size + slen]; |
413 | char *dst = &buf[slen]; | 415 | char *dst = &buf[slen]; |
414 | 416 | ||
415 | GNUNET_memcpy(buf, item->filename, slen); | 417 | GNUNET_memcpy (buf, item->filename, slen); |
416 | size = GNUNET_CONTAINER_meta_data_serialize( | 418 | size = GNUNET_CONTAINER_meta_data_serialize ( |
417 | meta, | 419 | meta, |
418 | &dst, | 420 | &dst, |
419 | size, | 421 | size, |
420 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 422 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
421 | if (size < 0) | 423 | if (size < 0) |
422 | { | 424 | { |
423 | GNUNET_break(0); | 425 | GNUNET_break (0); |
424 | size = 0; | 426 | size = 0; |
425 | } | 427 | } |
426 | GNUNET_CONTAINER_meta_data_destroy(meta); | 428 | GNUNET_CONTAINER_meta_data_destroy (meta); |
427 | if (GNUNET_OK != | 429 | if (GNUNET_OK != |
428 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, | 430 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, |
429 | buf, | 431 | buf, |
430 | slen + size)) | 432 | slen + size)) |
431 | return GNUNET_SYSERR; | 433 | return GNUNET_SYSERR; |
432 | } | 434 | } |
433 | return GNUNET_OK; | 435 | return GNUNET_OK; |
@@ -438,23 +440,23 @@ extract_files(struct ScanTreeNode *item) | |||
438 | * Install a signal handler to ignore SIGPIPE. | 440 | * Install a signal handler to ignore SIGPIPE. |
439 | */ | 441 | */ |
440 | static void | 442 | static void |
441 | ignore_sigpipe() | 443 | ignore_sigpipe () |
442 | { | 444 | { |
443 | struct sigaction oldsig; | 445 | struct sigaction oldsig; |
444 | struct sigaction sig; | 446 | struct sigaction sig; |
445 | 447 | ||
446 | memset(&sig, 0, sizeof(struct sigaction)); | 448 | memset (&sig, 0, sizeof(struct sigaction)); |
447 | sig.sa_handler = SIG_IGN; | 449 | sig.sa_handler = SIG_IGN; |
448 | sigemptyset(&sig.sa_mask); | 450 | sigemptyset (&sig.sa_mask); |
449 | #ifdef SA_INTERRUPT | 451 | #ifdef SA_INTERRUPT |
450 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ | 452 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ |
451 | #else | 453 | #else |
452 | sig.sa_flags = SA_RESTART; | 454 | sig.sa_flags = SA_RESTART; |
453 | #endif | 455 | #endif |
454 | if (0 != sigaction(SIGPIPE, &sig, &oldsig)) | 456 | if (0 != sigaction (SIGPIPE, &sig, &oldsig)) |
455 | fprintf(stderr, | 457 | fprintf (stderr, |
456 | "Failed to install SIGPIPE handler: %s\n", | 458 | "Failed to install SIGPIPE handler: %s\n", |
457 | strerror(errno)); | 459 | strerror (errno)); |
458 | } | 460 | } |
459 | 461 | ||
460 | 462 | ||
@@ -465,17 +467,17 @@ ignore_sigpipe() | |||
465 | * @param flags flags to use (O_RDONLY or O_WRONLY) | 467 | * @param flags flags to use (O_RDONLY or O_WRONLY) |
466 | */ | 468 | */ |
467 | static void | 469 | static void |
468 | make_dev_zero(int fd, int flags) | 470 | make_dev_zero (int fd, int flags) |
469 | { | 471 | { |
470 | int z; | 472 | int z; |
471 | 473 | ||
472 | GNUNET_assert(0 == close(fd)); | 474 | GNUNET_assert (0 == close (fd)); |
473 | z = open("/dev/null", flags); | 475 | z = open ("/dev/null", flags); |
474 | GNUNET_assert(-1 != z); | 476 | GNUNET_assert (-1 != z); |
475 | if (z == fd) | 477 | if (z == fd) |
476 | return; | 478 | return; |
477 | GNUNET_break(fd == dup2(z, fd)); | 479 | GNUNET_break (fd == dup2 (z, fd)); |
478 | GNUNET_assert(0 == close(z)); | 480 | GNUNET_assert (0 == close (z)); |
479 | } | 481 | } |
480 | 482 | ||
481 | 483 | ||
@@ -490,82 +492,82 @@ make_dev_zero(int fd, int flags) | |||
490 | * @return 0 on success | 492 | * @return 0 on success |
491 | */ | 493 | */ |
492 | int | 494 | int |
493 | main(int argc, char *const *argv) | 495 | main (int argc, char *const *argv) |
494 | { | 496 | { |
495 | const char *filename_expanded; | 497 | const char *filename_expanded; |
496 | const char *ex; | 498 | const char *ex; |
497 | struct ScanTreeNode *root; | 499 | struct ScanTreeNode *root; |
498 | 500 | ||
499 | ignore_sigpipe(); | 501 | ignore_sigpipe (); |
500 | /* move stdout to some other FD for IPC, bind | 502 | /* move stdout to some other FD for IPC, bind |
501 | stdout/stderr to /dev/null */ | 503 | stdout/stderr to /dev/null */ |
502 | output_stream = dup(1); | 504 | output_stream = dup (1); |
503 | make_dev_zero(1, O_WRONLY); | 505 | make_dev_zero (1, O_WRONLY); |
504 | make_dev_zero(2, O_WRONLY); | 506 | make_dev_zero (2, O_WRONLY); |
505 | 507 | ||
506 | /* parse command line */ | 508 | /* parse command line */ |
507 | if ((3 != argc) && (2 != argc)) | 509 | if ((3 != argc) && (2 != argc)) |
508 | { | 510 | { |
509 | fprintf(stderr, | 511 | fprintf (stderr, |
510 | "%s", | 512 | "%s", |
511 | "gnunet-helper-fs-publish needs exactly one or two arguments\n"); | 513 | "gnunet-helper-fs-publish needs exactly one or two arguments\n"); |
512 | return 1; | 514 | return 1; |
513 | } | 515 | } |
514 | filename_expanded = argv[1]; | 516 | filename_expanded = argv[1]; |
515 | ex = argv[2]; | 517 | ex = argv[2]; |
516 | if ((NULL == ex) || (0 != strcmp(ex, "-"))) | 518 | if ((NULL == ex) || (0 != strcmp (ex, "-"))) |
517 | { | 519 | { |
518 | #if HAVE_LIBEXTRACTOR | 520 | #if HAVE_LIBEXTRACTOR |
519 | plugins = EXTRACTOR_plugin_add_defaults(EXTRACTOR_OPTION_DEFAULT_POLICY); | 521 | plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); |
520 | if (NULL != ex) | 522 | if (NULL != ex) |
521 | plugins = EXTRACTOR_plugin_add_config(plugins, | 523 | plugins = EXTRACTOR_plugin_add_config (plugins, |
522 | ex, | 524 | ex, |
523 | EXTRACTOR_OPTION_DEFAULT_POLICY); | 525 | EXTRACTOR_OPTION_DEFAULT_POLICY); |
524 | #endif | 526 | #endif |
525 | } | 527 | } |
526 | 528 | ||
527 | /* scan tree to find out how much work there is to be done */ | 529 | /* scan tree to find out how much work there is to be done */ |
528 | if (GNUNET_OK != preprocess_file(filename_expanded, &root)) | 530 | if (GNUNET_OK != preprocess_file (filename_expanded, &root)) |
529 | { | 531 | { |
530 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); | 532 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); |
531 | #if HAVE_LIBEXTRACTOR | 533 | #if HAVE_LIBEXTRACTOR |
532 | EXTRACTOR_plugin_remove_all(plugins); | 534 | EXTRACTOR_plugin_remove_all (plugins); |
533 | #endif | 535 | #endif |
534 | return 2; | 536 | return 2; |
535 | } | 537 | } |
536 | /* signal that we're done counting files, so that a percentage of | 538 | /* signal that we're done counting files, so that a percentage of |
537 | progress can now be calculated */ | 539 | progress can now be calculated */ |
538 | if (GNUNET_OK != | 540 | if (GNUNET_OK != |
539 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, | 541 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, |
540 | NULL, | 542 | NULL, |
541 | 0)) | 543 | 0)) |
542 | { | 544 | { |
543 | #if HAVE_LIBEXTRACTOR | 545 | #if HAVE_LIBEXTRACTOR |
544 | EXTRACTOR_plugin_remove_all(plugins); | 546 | EXTRACTOR_plugin_remove_all (plugins); |
545 | #endif | 547 | #endif |
546 | return 3; | 548 | return 3; |
547 | } | 549 | } |
548 | if (NULL != root) | 550 | if (NULL != root) |
551 | { | ||
552 | if (GNUNET_OK != extract_files (root)) | ||
549 | { | 553 | { |
550 | if (GNUNET_OK != extract_files(root)) | 554 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, |
551 | { | 555 | NULL, |
552 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, | 556 | 0); |
553 | NULL, | 557 | free_tree (root); |
554 | 0); | ||
555 | free_tree(root); | ||
556 | #if HAVE_LIBEXTRACTOR | 558 | #if HAVE_LIBEXTRACTOR |
557 | EXTRACTOR_plugin_remove_all(plugins); | 559 | EXTRACTOR_plugin_remove_all (plugins); |
558 | #endif | 560 | #endif |
559 | return 4; | 561 | return 4; |
560 | } | ||
561 | free_tree(root); | ||
562 | } | 562 | } |
563 | free_tree (root); | ||
564 | } | ||
563 | /* enable "clean" shutdown by telling parent that we are done */ | 565 | /* enable "clean" shutdown by telling parent that we are done */ |
564 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, | 566 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, |
565 | NULL, | 567 | NULL, |
566 | 0); | 568 | 0); |
567 | #if HAVE_LIBEXTRACTOR | 569 | #if HAVE_LIBEXTRACTOR |
568 | EXTRACTOR_plugin_remove_all(plugins); | 570 | EXTRACTOR_plugin_remove_all (plugins); |
569 | #endif | 571 | #endif |
570 | return 0; | 572 | return 0; |
571 | } | 573 | } |
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index 24baa4d38..ff56dac8c 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c | |||
@@ -148,41 +148,41 @@ static struct GNUNET_IDENTITY_Handle *identity; | |||
148 | * @param cls NULL | 148 | * @param cls NULL |
149 | */ | 149 | */ |
150 | static void | 150 | static void |
151 | do_stop_task(void *cls) | 151 | do_stop_task (void *cls) |
152 | { | 152 | { |
153 | struct GNUNET_FS_PublishContext *p; | 153 | struct GNUNET_FS_PublishContext *p; |
154 | 154 | ||
155 | if (NULL != ds) | 155 | if (NULL != ds) |
156 | { | 156 | { |
157 | GNUNET_FS_directory_scan_abort(ds); | 157 | GNUNET_FS_directory_scan_abort (ds); |
158 | ds = NULL; | 158 | ds = NULL; |
159 | } | 159 | } |
160 | if (NULL != identity) | 160 | if (NULL != identity) |
161 | { | 161 | { |
162 | GNUNET_IDENTITY_disconnect(identity); | 162 | GNUNET_IDENTITY_disconnect (identity); |
163 | identity = NULL; | 163 | identity = NULL; |
164 | } | 164 | } |
165 | if (NULL != pc) | 165 | if (NULL != pc) |
166 | { | 166 | { |
167 | p = pc; | 167 | p = pc; |
168 | pc = NULL; | 168 | pc = NULL; |
169 | GNUNET_FS_publish_stop(p); | 169 | GNUNET_FS_publish_stop (p); |
170 | } | 170 | } |
171 | if (NULL != ctx) | 171 | if (NULL != ctx) |
172 | { | 172 | { |
173 | GNUNET_FS_stop(ctx); | 173 | GNUNET_FS_stop (ctx); |
174 | ctx = NULL; | 174 | ctx = NULL; |
175 | } | 175 | } |
176 | if (NULL != meta) | 176 | if (NULL != meta) |
177 | { | 177 | { |
178 | GNUNET_CONTAINER_meta_data_destroy(meta); | 178 | GNUNET_CONTAINER_meta_data_destroy (meta); |
179 | meta = NULL; | 179 | meta = NULL; |
180 | } | 180 | } |
181 | if (NULL != uri) | 181 | if (NULL != uri) |
182 | { | 182 | { |
183 | GNUNET_FS_uri_destroy(uri); | 183 | GNUNET_FS_uri_destroy (uri); |
184 | uri = NULL; | 184 | uri = NULL; |
185 | } | 185 | } |
186 | } | 186 | } |
187 | 187 | ||
188 | 188 | ||
@@ -200,105 +200,105 @@ do_stop_task(void *cls) | |||
200 | * field in the GNUNET_FS_ProgressInfo struct. | 200 | * field in the GNUNET_FS_ProgressInfo struct. |
201 | */ | 201 | */ |
202 | static void * | 202 | static void * |
203 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) | 203 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
204 | { | 204 | { |
205 | const char *s; | 205 | const char *s; |
206 | char *suri; | 206 | char *suri; |
207 | 207 | ||
208 | switch (info->status) | 208 | switch (info->status) |
209 | { | ||
210 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
211 | break; | ||
212 | |||
213 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
214 | if (verbose) | ||
209 | { | 215 | { |
210 | case GNUNET_FS_STATUS_PUBLISH_START: | 216 | s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta, |
211 | break; | 217 | GNUNET_YES); |
212 | 218 | fprintf (stdout, | |
213 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 219 | _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"), |
214 | if (verbose) | 220 | info->value.publish.filename, |
215 | { | 221 | (unsigned long long) info->value.publish.completed, |
216 | s = GNUNET_STRINGS_relative_time_to_string(info->value.publish.eta, | 222 | (unsigned long long) info->value.publish.size, |
217 | GNUNET_YES); | 223 | s); |
218 | fprintf(stdout, | ||
219 | _("Publishing `%s' at %llu/%llu (%s remaining)\n"), | ||
220 | info->value.publish.filename, | ||
221 | (unsigned long long)info->value.publish.completed, | ||
222 | (unsigned long long)info->value.publish.size, | ||
223 | s); | ||
224 | } | ||
225 | break; | ||
226 | |||
227 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
228 | if (verbose) | ||
229 | { | ||
230 | s = GNUNET_STRINGS_relative_time_to_string(info->value.publish.specifics | ||
231 | .progress_directory.eta, | ||
232 | GNUNET_YES); | ||
233 | fprintf(stdout, | ||
234 | _("Publishing `%s' at %llu/%llu (%s remaining)\n"), | ||
235 | info->value.publish.filename, | ||
236 | (unsigned long long) | ||
237 | info->value.publish.specifics.progress_directory.completed, | ||
238 | (unsigned long long) | ||
239 | info->value.publish.specifics.progress_directory.total, | ||
240 | s); | ||
241 | } | ||
242 | break; | ||
243 | |||
244 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
245 | fprintf(stderr, | ||
246 | _("Error publishing: %s.\n"), | ||
247 | info->value.publish.specifics.error.message); | ||
248 | ret = 1; | ||
249 | GNUNET_SCHEDULER_shutdown(); | ||
250 | break; | ||
251 | |||
252 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
253 | fprintf(stdout, | ||
254 | _("Publishing `%s' done.\n"), | ||
255 | info->value.publish.filename); | ||
256 | suri = | ||
257 | GNUNET_FS_uri_to_string(info->value.publish.specifics.completed.chk_uri); | ||
258 | fprintf(stdout, _("URI is `%s'.\n"), suri); | ||
259 | GNUNET_free(suri); | ||
260 | if (NULL != info->value.publish.specifics.completed.sks_uri) | ||
261 | { | ||
262 | suri = GNUNET_FS_uri_to_string( | ||
263 | info->value.publish.specifics.completed.sks_uri); | ||
264 | fprintf(stdout, _("Namespace URI is `%s'.\n"), suri); | ||
265 | GNUNET_free(suri); | ||
266 | } | ||
267 | if (NULL == info->value.publish.pctx) | ||
268 | { | ||
269 | ret = 0; | ||
270 | GNUNET_SCHEDULER_shutdown(); | ||
271 | } | ||
272 | break; | ||
273 | |||
274 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
275 | GNUNET_break(NULL == pc); | ||
276 | return NULL; | ||
277 | |||
278 | case GNUNET_FS_STATUS_UNINDEX_START: | ||
279 | fprintf(stderr, "%s", _("Starting cleanup after abort\n")); | ||
280 | return NULL; | ||
281 | |||
282 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | ||
283 | return NULL; | ||
284 | |||
285 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | ||
286 | fprintf(stderr, "%s", _("Cleanup after abort completed.\n")); | ||
287 | GNUNET_FS_unindex_stop(info->value.unindex.uc); | ||
288 | return NULL; | ||
289 | |||
290 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | ||
291 | fprintf(stderr, "%s", _("Cleanup after abort failed.\n")); | ||
292 | GNUNET_FS_unindex_stop(info->value.unindex.uc); | ||
293 | return NULL; | ||
294 | |||
295 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | ||
296 | return NULL; | ||
297 | |||
298 | default: | ||
299 | fprintf(stderr, _("Unexpected status: %d\n"), info->status); | ||
300 | return NULL; | ||
301 | } | 224 | } |
225 | break; | ||
226 | |||
227 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
228 | if (verbose) | ||
229 | { | ||
230 | s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics | ||
231 | .progress_directory.eta, | ||
232 | GNUNET_YES); | ||
233 | fprintf (stdout, | ||
234 | _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"), | ||
235 | info->value.publish.filename, | ||
236 | (unsigned long long) | ||
237 | info->value.publish.specifics.progress_directory.completed, | ||
238 | (unsigned long long) | ||
239 | info->value.publish.specifics.progress_directory.total, | ||
240 | s); | ||
241 | } | ||
242 | break; | ||
243 | |||
244 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
245 | fprintf (stderr, | ||
246 | _ ("Error publishing: %s.\n"), | ||
247 | info->value.publish.specifics.error.message); | ||
248 | ret = 1; | ||
249 | GNUNET_SCHEDULER_shutdown (); | ||
250 | break; | ||
251 | |||
252 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
253 | fprintf (stdout, | ||
254 | _ ("Publishing `%s' done.\n"), | ||
255 | info->value.publish.filename); | ||
256 | suri = | ||
257 | GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.chk_uri); | ||
258 | fprintf (stdout, _ ("URI is `%s'.\n"), suri); | ||
259 | GNUNET_free (suri); | ||
260 | if (NULL != info->value.publish.specifics.completed.sks_uri) | ||
261 | { | ||
262 | suri = GNUNET_FS_uri_to_string ( | ||
263 | info->value.publish.specifics.completed.sks_uri); | ||
264 | fprintf (stdout, _ ("Namespace URI is `%s'.\n"), suri); | ||
265 | GNUNET_free (suri); | ||
266 | } | ||
267 | if (NULL == info->value.publish.pctx) | ||
268 | { | ||
269 | ret = 0; | ||
270 | GNUNET_SCHEDULER_shutdown (); | ||
271 | } | ||
272 | break; | ||
273 | |||
274 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
275 | GNUNET_break (NULL == pc); | ||
276 | return NULL; | ||
277 | |||
278 | case GNUNET_FS_STATUS_UNINDEX_START: | ||
279 | fprintf (stderr, "%s", _ ("Starting cleanup after abort\n")); | ||
280 | return NULL; | ||
281 | |||
282 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | ||
283 | return NULL; | ||
284 | |||
285 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | ||
286 | fprintf (stderr, "%s", _ ("Cleanup after abort completed.\n")); | ||
287 | GNUNET_FS_unindex_stop (info->value.unindex.uc); | ||
288 | return NULL; | ||
289 | |||
290 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | ||
291 | fprintf (stderr, "%s", _ ("Cleanup after abort failed.\n")); | ||
292 | GNUNET_FS_unindex_stop (info->value.unindex.uc); | ||
293 | return NULL; | ||
294 | |||
295 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | ||
296 | return NULL; | ||
297 | |||
298 | default: | ||
299 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); | ||
300 | return NULL; | ||
301 | } | ||
302 | return ""; /* non-null */ | 302 | return ""; /* non-null */ |
303 | } | 303 | } |
304 | 304 | ||
@@ -317,13 +317,13 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
317 | * @return always 0 | 317 | * @return always 0 |
318 | */ | 318 | */ |
319 | static int | 319 | static int |
320 | meta_printer(void *cls, | 320 | meta_printer (void *cls, |
321 | const char *plugin_name, | 321 | const char *plugin_name, |
322 | enum EXTRACTOR_MetaType type, | 322 | enum EXTRACTOR_MetaType type, |
323 | enum EXTRACTOR_MetaFormat format, | 323 | enum EXTRACTOR_MetaFormat format, |
324 | const char *data_mime_type, | 324 | const char *data_mime_type, |
325 | const char *data, | 325 | const char *data, |
326 | size_t data_size) | 326 | size_t data_size) |
327 | { | 327 | { |
328 | if ((EXTRACTOR_METAFORMAT_UTF8 != format) && | 328 | if ((EXTRACTOR_METAFORMAT_UTF8 != format) && |
329 | (EXTRACTOR_METAFORMAT_C_STRING != format)) | 329 | (EXTRACTOR_METAFORMAT_C_STRING != format)) |
@@ -331,9 +331,9 @@ meta_printer(void *cls, | |||
331 | if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) | 331 | if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) |
332 | return 0; | 332 | return 0; |
333 | #if HAVE_LIBEXTRACTOR | 333 | #if HAVE_LIBEXTRACTOR |
334 | fprintf(stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string(type), data); | 334 | fprintf (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data); |
335 | #else | 335 | #else |
336 | fprintf(stdout, "\t%d - %s\n", type, data); | 336 | fprintf (stdout, "\t%d - %s\n", type, data); |
337 | #endif | 337 | #endif |
338 | return 0; | 338 | return 0; |
339 | } | 339 | } |
@@ -348,9 +348,9 @@ meta_printer(void *cls, | |||
348 | * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort | 348 | * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort |
349 | */ | 349 | */ |
350 | static int | 350 | static int |
351 | keyword_printer(void *cls, const char *keyword, int is_mandatory) | 351 | keyword_printer (void *cls, const char *keyword, int is_mandatory) |
352 | { | 352 | { |
353 | fprintf(stdout, "\t%s\n", keyword); | 353 | fprintf (stdout, "\t%s\n", keyword); |
354 | return GNUNET_OK; | 354 | return GNUNET_OK; |
355 | } | 355 | } |
356 | 356 | ||
@@ -373,14 +373,14 @@ keyword_printer(void *cls, const char *keyword, int is_mandatory) | |||
373 | * to abort the iteration | 373 | * to abort the iteration |
374 | */ | 374 | */ |
375 | static int | 375 | static int |
376 | publish_inspector(void *cls, | 376 | publish_inspector (void *cls, |
377 | struct GNUNET_FS_FileInformation *fi, | 377 | struct GNUNET_FS_FileInformation *fi, |
378 | uint64_t length, | 378 | uint64_t length, |
379 | struct GNUNET_CONTAINER_MetaData *m, | 379 | struct GNUNET_CONTAINER_MetaData *m, |
380 | struct GNUNET_FS_Uri **uri, | 380 | struct GNUNET_FS_Uri **uri, |
381 | struct GNUNET_FS_BlockOptions *bo, | 381 | struct GNUNET_FS_BlockOptions *bo, |
382 | int *do_index, | 382 | int *do_index, |
383 | void **client_info) | 383 | void **client_info) |
384 | { | 384 | { |
385 | char *fn; | 385 | char *fn; |
386 | char *fs; | 386 | char *fs; |
@@ -389,50 +389,50 @@ publish_inspector(void *cls, | |||
389 | if (cls == fi) | 389 | if (cls == fi) |
390 | return GNUNET_OK; | 390 | return GNUNET_OK; |
391 | if ((disable_extractor) && (NULL != *uri)) | 391 | if ((disable_extractor) && (NULL != *uri)) |
392 | { | 392 | { |
393 | GNUNET_FS_uri_destroy(*uri); | 393 | GNUNET_FS_uri_destroy (*uri); |
394 | *uri = NULL; | 394 | *uri = NULL; |
395 | } | 395 | } |
396 | if (NULL != topKeywords) | 396 | if (NULL != topKeywords) |
397 | { | ||
398 | if (NULL != *uri) | ||
397 | { | 399 | { |
398 | if (NULL != *uri) | 400 | new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, *uri); |
399 | { | 401 | GNUNET_FS_uri_destroy (*uri); |
400 | new_uri = GNUNET_FS_uri_ksk_merge(topKeywords, *uri); | 402 | *uri = new_uri; |
401 | GNUNET_FS_uri_destroy(*uri); | 403 | GNUNET_FS_uri_destroy (topKeywords); |
402 | *uri = new_uri; | ||
403 | GNUNET_FS_uri_destroy(topKeywords); | ||
404 | } | ||
405 | else | ||
406 | { | ||
407 | *uri = topKeywords; | ||
408 | } | ||
409 | topKeywords = NULL; | ||
410 | } | 404 | } |
411 | if (NULL != meta) | 405 | else |
412 | { | 406 | { |
413 | GNUNET_CONTAINER_meta_data_merge(m, meta); | 407 | *uri = topKeywords; |
414 | GNUNET_CONTAINER_meta_data_destroy(meta); | ||
415 | meta = NULL; | ||
416 | } | 408 | } |
409 | topKeywords = NULL; | ||
410 | } | ||
411 | if (NULL != meta) | ||
412 | { | ||
413 | GNUNET_CONTAINER_meta_data_merge (m, meta); | ||
414 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
415 | meta = NULL; | ||
416 | } | ||
417 | if (enable_creation_time) | 417 | if (enable_creation_time) |
418 | GNUNET_CONTAINER_meta_data_add_publication_date(m); | 418 | GNUNET_CONTAINER_meta_data_add_publication_date (m); |
419 | if (extract_only) | 419 | if (extract_only) |
420 | { | 420 | { |
421 | fn = GNUNET_CONTAINER_meta_data_get_by_type( | 421 | fn = GNUNET_CONTAINER_meta_data_get_by_type ( |
422 | m, | 422 | m, |
423 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 423 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
424 | fs = GNUNET_STRINGS_byte_size_fancy(length); | 424 | fs = GNUNET_STRINGS_byte_size_fancy (length); |
425 | fprintf(stdout, _("Meta data for file `%s' (%s)\n"), fn, fs); | 425 | fprintf (stdout, _ ("Meta data for file `%s' (%s)\n"), fn, fs); |
426 | GNUNET_CONTAINER_meta_data_iterate(m, &meta_printer, NULL); | 426 | GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL); |
427 | fprintf(stdout, _("Keywords for file `%s' (%s)\n"), fn, fs); | 427 | fprintf (stdout, _ ("Keywords for file `%s' (%s)\n"), fn, fs); |
428 | GNUNET_free(fn); | 428 | GNUNET_free (fn); |
429 | GNUNET_free(fs); | 429 | GNUNET_free (fs); |
430 | if (NULL != *uri) | 430 | if (NULL != *uri) |
431 | GNUNET_FS_uri_ksk_get_keywords(*uri, &keyword_printer, NULL); | 431 | GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL); |
432 | fprintf(stdout, "%s", "\n"); | 432 | fprintf (stdout, "%s", "\n"); |
433 | } | 433 | } |
434 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(m)) | 434 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) |
435 | GNUNET_FS_file_information_inspect(fi, &publish_inspector, fi); | 435 | GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi); |
436 | return GNUNET_OK; | 436 | return GNUNET_OK; |
437 | } | 437 | } |
438 | 438 | ||
@@ -447,16 +447,16 @@ publish_inspector(void *cls, | |||
447 | * @param emsg error message, NULL on success | 447 | * @param emsg error message, NULL on success |
448 | */ | 448 | */ |
449 | static void | 449 | static void |
450 | uri_sks_continuation(void *cls, | 450 | uri_sks_continuation (void *cls, |
451 | const struct GNUNET_FS_Uri *sks_uri, | 451 | const struct GNUNET_FS_Uri *sks_uri, |
452 | const char *emsg) | 452 | const char *emsg) |
453 | { | 453 | { |
454 | if (NULL != emsg) | 454 | if (NULL != emsg) |
455 | { | 455 | { |
456 | fprintf(stderr, "%s\n", emsg); | 456 | fprintf (stderr, "%s\n", emsg); |
457 | ret = 1; | 457 | ret = 1; |
458 | } | 458 | } |
459 | GNUNET_SCHEDULER_shutdown(); | 459 | GNUNET_SCHEDULER_shutdown (); |
460 | } | 460 | } |
461 | 461 | ||
462 | 462 | ||
@@ -470,33 +470,33 @@ uri_sks_continuation(void *cls, | |||
470 | * @param emsg error message, NULL on success | 470 | * @param emsg error message, NULL on success |
471 | */ | 471 | */ |
472 | static void | 472 | static void |
473 | uri_ksk_continuation(void *cls, | 473 | uri_ksk_continuation (void *cls, |
474 | const struct GNUNET_FS_Uri *ksk_uri, | 474 | const struct GNUNET_FS_Uri *ksk_uri, |
475 | const char *emsg) | 475 | const char *emsg) |
476 | { | 476 | { |
477 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; | 477 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; |
478 | 478 | ||
479 | if (NULL != emsg) | 479 | if (NULL != emsg) |
480 | { | 480 | { |
481 | fprintf(stderr, "%s\n", emsg); | 481 | fprintf (stderr, "%s\n", emsg); |
482 | ret = 1; | 482 | ret = 1; |
483 | } | 483 | } |
484 | if (NULL == namespace) | 484 | if (NULL == namespace) |
485 | { | 485 | { |
486 | GNUNET_SCHEDULER_shutdown(); | 486 | GNUNET_SCHEDULER_shutdown (); |
487 | return; | 487 | return; |
488 | } | 488 | } |
489 | priv = GNUNET_IDENTITY_ego_get_private_key(namespace); | 489 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); |
490 | GNUNET_FS_publish_sks(ctx, | 490 | GNUNET_FS_publish_sks (ctx, |
491 | priv, | 491 | priv, |
492 | this_id, | 492 | this_id, |
493 | next_id, | 493 | next_id, |
494 | meta, | 494 | meta, |
495 | uri, | 495 | uri, |
496 | &bo, | 496 | &bo, |
497 | GNUNET_FS_PUBLISH_OPTION_NONE, | 497 | GNUNET_FS_PUBLISH_OPTION_NONE, |
498 | &uri_sks_continuation, | 498 | &uri_sks_continuation, |
499 | NULL); | 499 | NULL); |
500 | } | 500 | } |
501 | 501 | ||
502 | 502 | ||
@@ -508,52 +508,52 @@ uri_ksk_continuation(void *cls, | |||
508 | * @return handle with the information for the publishing operation | 508 | * @return handle with the information for the publishing operation |
509 | */ | 509 | */ |
510 | static struct GNUNET_FS_FileInformation * | 510 | static struct GNUNET_FS_FileInformation * |
511 | get_file_information(struct GNUNET_FS_ShareTreeItem *item) | 511 | get_file_information (struct GNUNET_FS_ShareTreeItem *item) |
512 | { | 512 | { |
513 | struct GNUNET_FS_FileInformation *fi; | 513 | struct GNUNET_FS_FileInformation *fi; |
514 | struct GNUNET_FS_FileInformation *fic; | 514 | struct GNUNET_FS_FileInformation *fic; |
515 | struct GNUNET_FS_ShareTreeItem *child; | 515 | struct GNUNET_FS_ShareTreeItem *child; |
516 | 516 | ||
517 | if (GNUNET_YES == item->is_directory) | 517 | if (GNUNET_YES == item->is_directory) |
518 | { | ||
519 | if (NULL == item->meta) | ||
520 | item->meta = GNUNET_CONTAINER_meta_data_create (); | ||
521 | GNUNET_CONTAINER_meta_data_delete (item->meta, | ||
522 | EXTRACTOR_METATYPE_MIMETYPE, | ||
523 | NULL, | ||
524 | 0); | ||
525 | GNUNET_FS_meta_data_make_directory (item->meta); | ||
526 | if (NULL == item->ksk_uri) | ||
518 | { | 527 | { |
519 | if (NULL == item->meta) | 528 | const char *mime = GNUNET_FS_DIRECTORY_MIME; |
520 | item->meta = GNUNET_CONTAINER_meta_data_create(); | 529 | item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &mime); |
521 | GNUNET_CONTAINER_meta_data_delete(item->meta, | ||
522 | EXTRACTOR_METATYPE_MIMETYPE, | ||
523 | NULL, | ||
524 | 0); | ||
525 | GNUNET_FS_meta_data_make_directory(item->meta); | ||
526 | if (NULL == item->ksk_uri) | ||
527 | { | ||
528 | const char *mime = GNUNET_FS_DIRECTORY_MIME; | ||
529 | item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args(1, &mime); | ||
530 | } | ||
531 | else | ||
532 | GNUNET_FS_uri_ksk_add_keyword(item->ksk_uri, | ||
533 | GNUNET_FS_DIRECTORY_MIME, | ||
534 | GNUNET_NO); | ||
535 | fi = GNUNET_FS_file_information_create_empty_directory(ctx, | ||
536 | NULL, | ||
537 | item->ksk_uri, | ||
538 | item->meta, | ||
539 | &bo, | ||
540 | item->filename); | ||
541 | for (child = item->children_head; child; child = child->next) | ||
542 | { | ||
543 | fic = get_file_information(child); | ||
544 | GNUNET_break(GNUNET_OK == GNUNET_FS_file_information_add(fi, fic)); | ||
545 | } | ||
546 | } | 530 | } |
547 | else | 531 | else |
532 | GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, | ||
533 | GNUNET_FS_DIRECTORY_MIME, | ||
534 | GNUNET_NO); | ||
535 | fi = GNUNET_FS_file_information_create_empty_directory (ctx, | ||
536 | NULL, | ||
537 | item->ksk_uri, | ||
538 | item->meta, | ||
539 | &bo, | ||
540 | item->filename); | ||
541 | for (child = item->children_head; child; child = child->next) | ||
548 | { | 542 | { |
549 | fi = GNUNET_FS_file_information_create_from_file(ctx, | 543 | fic = get_file_information (child); |
550 | NULL, | 544 | GNUNET_break (GNUNET_OK == GNUNET_FS_file_information_add (fi, fic)); |
551 | item->filename, | ||
552 | item->ksk_uri, | ||
553 | item->meta, | ||
554 | !do_insert, | ||
555 | &bo); | ||
556 | } | 545 | } |
546 | } | ||
547 | else | ||
548 | { | ||
549 | fi = GNUNET_FS_file_information_create_from_file (ctx, | ||
550 | NULL, | ||
551 | item->filename, | ||
552 | item->ksk_uri, | ||
553 | item->meta, | ||
554 | ! do_insert, | ||
555 | &bo); | ||
556 | } | ||
557 | return fi; | 557 | return fi; |
558 | } | 558 | } |
559 | 559 | ||
@@ -565,46 +565,46 @@ get_file_information(struct GNUNET_FS_ShareTreeItem *item) | |||
565 | * @param directory_scan_result result from the directory scan, freed in this function | 565 | * @param directory_scan_result result from the directory scan, freed in this function |
566 | */ | 566 | */ |
567 | static void | 567 | static void |
568 | directory_trim_complete(struct GNUNET_FS_ShareTreeItem *directory_scan_result) | 568 | directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) |
569 | { | 569 | { |
570 | struct GNUNET_FS_FileInformation *fi; | 570 | struct GNUNET_FS_FileInformation *fi; |
571 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; | 571 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; |
572 | 572 | ||
573 | fi = get_file_information(directory_scan_result); | 573 | fi = get_file_information (directory_scan_result); |
574 | GNUNET_FS_share_tree_free(directory_scan_result); | 574 | GNUNET_FS_share_tree_free (directory_scan_result); |
575 | if (NULL == fi) | 575 | if (NULL == fi) |
576 | { | 576 | { |
577 | fprintf(stderr, "%s", _("Could not publish\n")); | 577 | fprintf (stderr, "%s", _ ("Could not publish\n")); |
578 | ret = 1; | 578 | ret = 1; |
579 | GNUNET_SCHEDULER_shutdown(); | 579 | GNUNET_SCHEDULER_shutdown (); |
580 | return; | 580 | return; |
581 | } | 581 | } |
582 | GNUNET_FS_file_information_inspect(fi, &publish_inspector, NULL); | 582 | GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL); |
583 | if (extract_only) | 583 | if (extract_only) |
584 | { | 584 | { |
585 | GNUNET_FS_file_information_destroy(fi, NULL, NULL); | 585 | GNUNET_FS_file_information_destroy (fi, NULL, NULL); |
586 | GNUNET_SCHEDULER_shutdown(); | 586 | GNUNET_SCHEDULER_shutdown (); |
587 | return; | 587 | return; |
588 | } | 588 | } |
589 | if (NULL == namespace) | 589 | if (NULL == namespace) |
590 | priv = NULL; | 590 | priv = NULL; |
591 | else | 591 | else |
592 | priv = GNUNET_IDENTITY_ego_get_private_key(namespace); | 592 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); |
593 | pc = GNUNET_FS_publish_start(ctx, | 593 | pc = GNUNET_FS_publish_start (ctx, |
594 | fi, | 594 | fi, |
595 | priv, | 595 | priv, |
596 | this_id, | 596 | this_id, |
597 | next_id, | 597 | next_id, |
598 | (do_simulate) | 598 | (do_simulate) |
599 | ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY | 599 | ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY |
600 | : GNUNET_FS_PUBLISH_OPTION_NONE); | 600 | : GNUNET_FS_PUBLISH_OPTION_NONE); |
601 | if (NULL == pc) | 601 | if (NULL == pc) |
602 | { | 602 | { |
603 | fprintf(stderr, "%s", _("Could not start publishing.\n")); | 603 | fprintf (stderr, "%s", _ ("Could not start publishing.\n")); |
604 | ret = 1; | 604 | ret = 1; |
605 | GNUNET_SCHEDULER_shutdown(); | 605 | GNUNET_SCHEDULER_shutdown (); |
606 | return; | 606 | return; |
607 | } | 607 | } |
608 | } | 608 | } |
609 | 609 | ||
610 | 610 | ||
@@ -620,63 +620,63 @@ directory_trim_complete(struct GNUNET_FS_ShareTreeItem *directory_scan_result) | |||
620 | * @param reason kind of progress we are making | 620 | * @param reason kind of progress we are making |
621 | */ | 621 | */ |
622 | static void | 622 | static void |
623 | directory_scan_cb(void *cls, | 623 | directory_scan_cb (void *cls, |
624 | const char *filename, | 624 | const char *filename, |
625 | int is_directory, | 625 | int is_directory, |
626 | enum GNUNET_FS_DirScannerProgressUpdateReason reason) | 626 | enum GNUNET_FS_DirScannerProgressUpdateReason reason) |
627 | { | 627 | { |
628 | struct GNUNET_FS_ShareTreeItem *directory_scan_result; | 628 | struct GNUNET_FS_ShareTreeItem *directory_scan_result; |
629 | 629 | ||
630 | switch (reason) | 630 | switch (reason) |
631 | { | ||
632 | case GNUNET_FS_DIRSCANNER_FILE_START: | ||
633 | if (verbose > 1) | ||
631 | { | 634 | { |
632 | case GNUNET_FS_DIRSCANNER_FILE_START: | 635 | if (is_directory == GNUNET_YES) |
633 | if (verbose > 1) | 636 | fprintf (stdout, _ ("Scanning directory `%s'.\n"), filename); |
634 | { | 637 | else |
635 | if (is_directory == GNUNET_YES) | 638 | fprintf (stdout, _ ("Scanning file `%s'.\n"), filename); |
636 | fprintf(stdout, _("Scanning directory `%s'.\n"), filename); | ||
637 | else | ||
638 | fprintf(stdout, _("Scanning file `%s'.\n"), filename); | ||
639 | } | ||
640 | break; | ||
641 | |||
642 | case GNUNET_FS_DIRSCANNER_FILE_IGNORED: | ||
643 | fprintf(stderr, | ||
644 | _("There was trouble processing file `%s', skipping it.\n"), | ||
645 | filename); | ||
646 | break; | ||
647 | |||
648 | case GNUNET_FS_DIRSCANNER_ALL_COUNTED: | ||
649 | if (verbose) | ||
650 | fprintf(stdout, "%s", _("Preprocessing complete.\n")); | ||
651 | break; | ||
652 | |||
653 | case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED: | ||
654 | if (verbose > 2) | ||
655 | fprintf(stdout, | ||
656 | _("Extracting meta data from file `%s' complete.\n"), | ||
657 | filename); | ||
658 | break; | ||
659 | |||
660 | case GNUNET_FS_DIRSCANNER_FINISHED: | ||
661 | if (verbose > 1) | ||
662 | fprintf(stdout, "%s", _("Meta data extraction has finished.\n")); | ||
663 | directory_scan_result = GNUNET_FS_directory_scan_get_result(ds); | ||
664 | ds = NULL; | ||
665 | GNUNET_FS_share_tree_trim(directory_scan_result); | ||
666 | directory_trim_complete(directory_scan_result); | ||
667 | break; | ||
668 | |||
669 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: | ||
670 | fprintf(stdout, "%s", _("Error scanning directory.\n")); | ||
671 | ret = 1; | ||
672 | GNUNET_SCHEDULER_shutdown(); | ||
673 | break; | ||
674 | |||
675 | default: | ||
676 | GNUNET_assert(0); | ||
677 | break; | ||
678 | } | 639 | } |
679 | fflush(stdout); | 640 | break; |
641 | |||
642 | case GNUNET_FS_DIRSCANNER_FILE_IGNORED: | ||
643 | fprintf (stderr, | ||
644 | _ ("There was trouble processing file `%s', skipping it.\n"), | ||
645 | filename); | ||
646 | break; | ||
647 | |||
648 | case GNUNET_FS_DIRSCANNER_ALL_COUNTED: | ||
649 | if (verbose) | ||
650 | fprintf (stdout, "%s", _ ("Preprocessing complete.\n")); | ||
651 | break; | ||
652 | |||
653 | case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED: | ||
654 | if (verbose > 2) | ||
655 | fprintf (stdout, | ||
656 | _ ("Extracting meta data from file `%s' complete.\n"), | ||
657 | filename); | ||
658 | break; | ||
659 | |||
660 | case GNUNET_FS_DIRSCANNER_FINISHED: | ||
661 | if (verbose > 1) | ||
662 | fprintf (stdout, "%s", _ ("Meta data extraction has finished.\n")); | ||
663 | directory_scan_result = GNUNET_FS_directory_scan_get_result (ds); | ||
664 | ds = NULL; | ||
665 | GNUNET_FS_share_tree_trim (directory_scan_result); | ||
666 | directory_trim_complete (directory_scan_result); | ||
667 | break; | ||
668 | |||
669 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: | ||
670 | fprintf (stdout, "%s", _ ("Error scanning directory.\n")); | ||
671 | ret = 1; | ||
672 | GNUNET_SCHEDULER_shutdown (); | ||
673 | break; | ||
674 | |||
675 | default: | ||
676 | GNUNET_assert (0); | ||
677 | break; | ||
678 | } | ||
679 | fflush (stdout); | ||
680 | } | 680 | } |
681 | 681 | ||
682 | 682 | ||
@@ -687,67 +687,67 @@ directory_scan_cb(void *cls, | |||
687 | * @param args0 filename to publish | 687 | * @param args0 filename to publish |
688 | */ | 688 | */ |
689 | static void | 689 | static void |
690 | identity_continuation(const char *args0) | 690 | identity_continuation (const char *args0) |
691 | { | 691 | { |
692 | char *ex; | 692 | char *ex; |
693 | char *emsg; | 693 | char *emsg; |
694 | 694 | ||
695 | if ((NULL != pseudonym) && (NULL == namespace)) | 695 | if ((NULL != pseudonym) && (NULL == namespace)) |
696 | { | 696 | { |
697 | fprintf(stderr, _("Selected pseudonym `%s' unknown\n"), pseudonym); | 697 | fprintf (stderr, _ ("Selected pseudonym `%s' unknown\n"), pseudonym); |
698 | ret = 1; | 698 | ret = 1; |
699 | GNUNET_SCHEDULER_shutdown(); | 699 | GNUNET_SCHEDULER_shutdown (); |
700 | return; | 700 | return; |
701 | } | 701 | } |
702 | if (NULL != uri_string) | 702 | if (NULL != uri_string) |
703 | { | ||
704 | emsg = NULL; | ||
705 | if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg))) | ||
703 | { | 706 | { |
704 | emsg = NULL; | 707 | fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg); |
705 | if (NULL == (uri = GNUNET_FS_uri_parse(uri_string, &emsg))) | 708 | GNUNET_free (emsg); |
706 | { | 709 | ret = 1; |
707 | fprintf(stderr, _("Failed to parse URI: %s\n"), emsg); | 710 | GNUNET_SCHEDULER_shutdown (); |
708 | GNUNET_free(emsg); | ||
709 | ret = 1; | ||
710 | GNUNET_SCHEDULER_shutdown(); | ||
711 | return; | ||
712 | } | ||
713 | GNUNET_FS_publish_ksk(ctx, | ||
714 | topKeywords, | ||
715 | meta, | ||
716 | uri, | ||
717 | &bo, | ||
718 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
719 | &uri_ksk_continuation, | ||
720 | NULL); | ||
721 | return; | 711 | return; |
722 | } | 712 | } |
713 | GNUNET_FS_publish_ksk (ctx, | ||
714 | topKeywords, | ||
715 | meta, | ||
716 | uri, | ||
717 | &bo, | ||
718 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
719 | &uri_ksk_continuation, | ||
720 | NULL); | ||
721 | return; | ||
722 | } | ||
723 | if (GNUNET_OK != | 723 | if (GNUNET_OK != |
724 | GNUNET_CONFIGURATION_get_value_string(cfg, "FS", "EXTRACTORS", &ex)) | 724 | GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex)) |
725 | ex = NULL; | 725 | ex = NULL; |
726 | if (0 != access(args0, R_OK)) | 726 | if (0 != access (args0, R_OK)) |
727 | { | 727 | { |
728 | fprintf(stderr, | 728 | fprintf (stderr, |
729 | _("Failed to access `%s': %s\n"), | 729 | _ ("Failed to access `%s': %s\n"), |
730 | args0, | 730 | args0, |
731 | strerror(errno)); | 731 | strerror (errno)); |
732 | GNUNET_free_non_null(ex); | 732 | GNUNET_free_non_null (ex); |
733 | return; | 733 | return; |
734 | } | 734 | } |
735 | ds = GNUNET_FS_directory_scan_start(args0, | 735 | ds = GNUNET_FS_directory_scan_start (args0, |
736 | disable_extractor, | 736 | disable_extractor, |
737 | ex, | 737 | ex, |
738 | &directory_scan_cb, | 738 | &directory_scan_cb, |
739 | NULL); | 739 | NULL); |
740 | if (NULL == ds) | 740 | if (NULL == ds) |
741 | { | 741 | { |
742 | fprintf( | 742 | fprintf ( |
743 | stderr, | 743 | stderr, |
744 | "%s", | 744 | "%s", |
745 | _( | 745 | _ ( |
746 | "Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n")); | 746 | "Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n")); |
747 | GNUNET_free_non_null(ex); | 747 | GNUNET_free_non_null (ex); |
748 | return; | 748 | return; |
749 | } | 749 | } |
750 | GNUNET_free_non_null(ex); | 750 | GNUNET_free_non_null (ex); |
751 | } | 751 | } |
752 | 752 | ||
753 | 753 | ||
@@ -763,21 +763,21 @@ identity_continuation(const char *args0) | |||
763 | * must thus no longer be used | 763 | * must thus no longer be used |
764 | */ | 764 | */ |
765 | static void | 765 | static void |
766 | identity_cb(void *cls, | 766 | identity_cb (void *cls, |
767 | struct GNUNET_IDENTITY_Ego *ego, | 767 | struct GNUNET_IDENTITY_Ego *ego, |
768 | void **ctx, | 768 | void **ctx, |
769 | const char *name) | 769 | const char *name) |
770 | { | 770 | { |
771 | const char *args0 = cls; | 771 | const char *args0 = cls; |
772 | 772 | ||
773 | if (NULL == ego) | 773 | if (NULL == ego) |
774 | { | 774 | { |
775 | identity_continuation(args0); | 775 | identity_continuation (args0); |
776 | return; | 776 | return; |
777 | } | 777 | } |
778 | if (NULL == name) | 778 | if (NULL == name) |
779 | return; | 779 | return; |
780 | if (0 == strcmp(name, pseudonym)) | 780 | if (0 == strcmp (name, pseudonym)) |
781 | namespace = ego; | 781 | namespace = ego; |
782 | } | 782 | } |
783 | 783 | ||
@@ -791,82 +791,82 @@ identity_cb(void *cls, | |||
791 | * @param c configuration | 791 | * @param c configuration |
792 | */ | 792 | */ |
793 | static void | 793 | static void |
794 | run(void *cls, | 794 | run (void *cls, |
795 | char *const *args, | 795 | char *const *args, |
796 | const char *cfgfile, | 796 | const char *cfgfile, |
797 | const struct GNUNET_CONFIGURATION_Handle *c) | 797 | const struct GNUNET_CONFIGURATION_Handle *c) |
798 | { | 798 | { |
799 | /* check arguments */ | 799 | /* check arguments */ |
800 | if ((NULL != uri_string) && (extract_only)) | 800 | if ((NULL != uri_string) && (extract_only)) |
801 | { | 801 | { |
802 | printf(_("Cannot extract metadata from a URI!\n")); | 802 | printf (_ ("Cannot extract metadata from a URI!\n")); |
803 | ret = -1; | 803 | ret = -1; |
804 | return; | 804 | return; |
805 | } | 805 | } |
806 | if (((NULL == uri_string) || (extract_only)) && | 806 | if (((NULL == uri_string) || (extract_only)) && |
807 | ((NULL == args[0]) || (NULL != args[1]))) | 807 | ((NULL == args[0]) || (NULL != args[1]))) |
808 | { | ||
809 | printf (_ ("You must specify one and only one filename for insertion.\n")); | ||
810 | ret = -1; | ||
811 | return; | ||
812 | } | ||
813 | if ((NULL != uri_string) && (NULL != args[0])) | ||
814 | { | ||
815 | printf (_ ("You must NOT specify an URI and a filename.\n")); | ||
816 | ret = -1; | ||
817 | return; | ||
818 | } | ||
819 | if (NULL != pseudonym) | ||
820 | { | ||
821 | if (NULL == this_id) | ||
808 | { | 822 | { |
809 | printf(_("You must specify one and only one filename for insertion.\n")); | 823 | fprintf (stderr, |
824 | _ ("Option `%s' is required when using option `%s'.\n"), | ||
825 | "-t", | ||
826 | "-P"); | ||
810 | ret = -1; | 827 | ret = -1; |
811 | return; | 828 | return; |
812 | } | 829 | } |
813 | if ((NULL != uri_string) && (NULL != args[0])) | 830 | } |
831 | else | ||
832 | { /* ordinary insertion checks */ | ||
833 | if (NULL != next_id) | ||
814 | { | 834 | { |
815 | printf(_("You must NOT specify an URI and a filename.\n")); | 835 | fprintf (stderr, |
836 | _ ("Option `%s' makes no sense without option `%s'.\n"), | ||
837 | "-N", | ||
838 | "-P"); | ||
816 | ret = -1; | 839 | ret = -1; |
817 | return; | 840 | return; |
818 | } | 841 | } |
819 | if (NULL != pseudonym) | 842 | if (NULL != this_id) |
820 | { | 843 | { |
821 | if (NULL == this_id) | 844 | fprintf (stderr, |
822 | { | 845 | _ ("Option `%s' makes no sense without option `%s'.\n"), |
823 | fprintf(stderr, | 846 | "-t", |
824 | _("Option `%s' is required when using option `%s'.\n"), | 847 | "-P"); |
825 | "-t", | 848 | ret = -1; |
826 | "-P"); | 849 | return; |
827 | ret = -1; | ||
828 | return; | ||
829 | } | ||
830 | } | ||
831 | else | ||
832 | { /* ordinary insertion checks */ | ||
833 | if (NULL != next_id) | ||
834 | { | ||
835 | fprintf(stderr, | ||
836 | _("Option `%s' makes no sense without option `%s'.\n"), | ||
837 | "-N", | ||
838 | "-P"); | ||
839 | ret = -1; | ||
840 | return; | ||
841 | } | ||
842 | if (NULL != this_id) | ||
843 | { | ||
844 | fprintf(stderr, | ||
845 | _("Option `%s' makes no sense without option `%s'.\n"), | ||
846 | "-t", | ||
847 | "-P"); | ||
848 | ret = -1; | ||
849 | return; | ||
850 | } | ||
851 | } | 850 | } |
851 | } | ||
852 | cfg = c; | 852 | cfg = c; |
853 | ctx = GNUNET_FS_start(cfg, | 853 | ctx = GNUNET_FS_start (cfg, |
854 | "gnunet-publish", | 854 | "gnunet-publish", |
855 | &progress_cb, | 855 | &progress_cb, |
856 | NULL, | 856 | NULL, |
857 | GNUNET_FS_FLAGS_NONE, | 857 | GNUNET_FS_FLAGS_NONE, |
858 | GNUNET_FS_OPTIONS_END); | 858 | GNUNET_FS_OPTIONS_END); |
859 | if (NULL == ctx) | 859 | if (NULL == ctx) |
860 | { | 860 | { |
861 | fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); | 861 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); |
862 | ret = 1; | 862 | ret = 1; |
863 | return; | 863 | return; |
864 | } | 864 | } |
865 | GNUNET_SCHEDULER_add_shutdown(&do_stop_task, NULL); | 865 | GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL); |
866 | if (NULL != pseudonym) | 866 | if (NULL != pseudonym) |
867 | identity = GNUNET_IDENTITY_connect(cfg, &identity_cb, args[0]); | 867 | identity = GNUNET_IDENTITY_connect (cfg, &identity_cb, args[0]); |
868 | else | 868 | else |
869 | identity_continuation(args[0]); | 869 | identity_continuation (args[0]); |
870 | } | 870 | } |
871 | 871 | ||
872 | 872 | ||
@@ -878,121 +878,121 @@ run(void *cls, | |||
878 | * @return 0 ok, 1 on error | 878 | * @return 0 ok, 1 on error |
879 | */ | 879 | */ |
880 | int | 880 | int |
881 | main(int argc, char *const *argv) | 881 | main (int argc, char *const *argv) |
882 | { | 882 | { |
883 | struct GNUNET_GETOPT_CommandLineOption options[] = | 883 | struct GNUNET_GETOPT_CommandLineOption options[] = |
884 | { GNUNET_GETOPT_option_uint('a', | 884 | { GNUNET_GETOPT_option_uint ('a', |
885 | "anonymity", | 885 | "anonymity", |
886 | "LEVEL", | 886 | "LEVEL", |
887 | gettext_noop( | 887 | gettext_noop ( |
888 | "set the desired LEVEL of sender-anonymity"), | 888 | "set the desired LEVEL of sender-anonymity"), |
889 | &bo.anonymity_level), | 889 | &bo.anonymity_level), |
890 | GNUNET_GETOPT_option_flag( | 890 | GNUNET_GETOPT_option_flag ( |
891 | 'D', | 891 | 'D', |
892 | "disable-extractor", | 892 | "disable-extractor", |
893 | gettext_noop("do not use libextractor to add keywords or metadata"), | 893 | gettext_noop ("do not use libextractor to add keywords or metadata"), |
894 | &disable_extractor), | 894 | &disable_extractor), |
895 | GNUNET_GETOPT_option_flag('E', | 895 | GNUNET_GETOPT_option_flag ('E', |
896 | "enable-creation-time", | 896 | "enable-creation-time", |
897 | gettext_noop( | 897 | gettext_noop ( |
898 | "enable adding the creation time to the " | 898 | "enable adding the creation time to the " |
899 | "metadata of the uploaded file"), | 899 | "metadata of the uploaded file"), |
900 | &enable_creation_time), | 900 | &enable_creation_time), |
901 | GNUNET_GETOPT_option_flag('e', | 901 | GNUNET_GETOPT_option_flag ('e', |
902 | "extract", | 902 | "extract", |
903 | gettext_noop( | 903 | gettext_noop ( |
904 | "print list of extracted keywords that would " | 904 | "print list of extracted keywords that would " |
905 | "be used, but do not perform upload"), | 905 | "be used, but do not perform upload"), |
906 | &extract_only), | 906 | &extract_only), |
907 | GNUNET_FS_GETOPT_KEYWORDS( | 907 | GNUNET_FS_GETOPT_KEYWORDS ( |
908 | 'k', | 908 | 'k', |
909 | "key", | 909 | "key", |
910 | "KEYWORD", | 910 | "KEYWORD", |
911 | gettext_noop( | 911 | gettext_noop ( |
912 | "add an additional keyword for the top-level " | 912 | "add an additional keyword for the top-level " |
913 | "file or directory (this option can be specified multiple times)"), | 913 | "file or directory (this option can be specified multiple times)"), |
914 | &topKeywords), | 914 | &topKeywords), |
915 | GNUNET_FS_GETOPT_METADATA( | 915 | GNUNET_FS_GETOPT_METADATA ( |
916 | 'm', | 916 | 'm', |
917 | "meta", | 917 | "meta", |
918 | "TYPE:VALUE", | 918 | "TYPE:VALUE", |
919 | gettext_noop("set the meta-data for the given TYPE to the given VALUE"), | 919 | gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), |
920 | &meta), | 920 | &meta), |
921 | GNUNET_GETOPT_option_flag( | 921 | GNUNET_GETOPT_option_flag ( |
922 | 'n', | 922 | 'n', |
923 | "noindex", | 923 | "noindex", |
924 | gettext_noop("do not index, perform full insertion (stores " | 924 | gettext_noop ("do not index, perform full insertion (stores " |
925 | "entire file in encrypted form in GNUnet database)"), | 925 | "entire file in encrypted form in GNUnet database)"), |
926 | &do_insert), | 926 | &do_insert), |
927 | GNUNET_GETOPT_option_string( | 927 | GNUNET_GETOPT_option_string ( |
928 | 'N', | 928 | 'N', |
929 | "next", | 929 | "next", |
930 | "ID", | 930 | "ID", |
931 | gettext_noop("specify ID of an updated version to be " | 931 | gettext_noop ("specify ID of an updated version to be " |
932 | "published in the future (for namespace insertions only)"), | 932 | "published in the future (for namespace insertions only)"), |
933 | &next_id), | 933 | &next_id), |
934 | GNUNET_GETOPT_option_uint('p', | 934 | GNUNET_GETOPT_option_uint ('p', |
935 | "priority", | 935 | "priority", |
936 | "PRIORITY", | 936 | "PRIORITY", |
937 | gettext_noop( | 937 | gettext_noop ( |
938 | "specify the priority of the content"), | 938 | "specify the priority of the content"), |
939 | &bo.content_priority), | 939 | &bo.content_priority), |
940 | GNUNET_GETOPT_option_string('P', | 940 | GNUNET_GETOPT_option_string ('P', |
941 | "pseudonym", | 941 | "pseudonym", |
942 | "NAME", | 942 | "NAME", |
943 | gettext_noop( | 943 | gettext_noop ( |
944 | "publish the files under the pseudonym " | 944 | "publish the files under the pseudonym " |
945 | "NAME (place file into namespace)"), | 945 | "NAME (place file into namespace)"), |
946 | &pseudonym), | 946 | &pseudonym), |
947 | GNUNET_GETOPT_option_uint('r', | 947 | GNUNET_GETOPT_option_uint ('r', |
948 | "replication", | 948 | "replication", |
949 | "LEVEL", | 949 | "LEVEL", |
950 | gettext_noop( | 950 | gettext_noop ( |
951 | "set the desired replication LEVEL"), | 951 | "set the desired replication LEVEL"), |
952 | &bo.replication_level), | 952 | &bo.replication_level), |
953 | GNUNET_GETOPT_option_flag('s', | 953 | GNUNET_GETOPT_option_flag ('s', |
954 | "simulate-only", | 954 | "simulate-only", |
955 | gettext_noop( | 955 | gettext_noop ( |
956 | "only simulate the process but do not do " | 956 | "only simulate the process but do not do " |
957 | "any actual publishing (useful to compute URIs)"), | 957 | "any actual publishing (useful to compute URIs)"), |
958 | &do_simulate), | 958 | &do_simulate), |
959 | GNUNET_GETOPT_option_string('t', | 959 | GNUNET_GETOPT_option_string ('t', |
960 | "this", | 960 | "this", |
961 | "ID", | 961 | "ID", |
962 | gettext_noop( | 962 | gettext_noop ( |
963 | "set the ID of this version of the publication " | 963 | "set the ID of this version of the publication " |
964 | "(for namespace insertions only)"), | 964 | "(for namespace insertions only)"), |
965 | &this_id), | 965 | &this_id), |
966 | GNUNET_GETOPT_option_string( | 966 | GNUNET_GETOPT_option_string ( |
967 | 'u', | 967 | 'u', |
968 | "uri", | 968 | "uri", |
969 | "URI", | 969 | "URI", |
970 | gettext_noop( | 970 | gettext_noop ( |
971 | "URI to be published (can be used instead of passing a " | 971 | "URI to be published (can be used instead of passing a " |
972 | "file to add keywords to the file with the respective URI)"), | 972 | "file to add keywords to the file with the respective URI)"), |
973 | &uri_string), | 973 | &uri_string), |
974 | 974 | ||
975 | GNUNET_GETOPT_option_verbose(&verbose), | 975 | GNUNET_GETOPT_option_verbose (&verbose), |
976 | 976 | ||
977 | GNUNET_GETOPT_OPTION_END }; | 977 | GNUNET_GETOPT_OPTION_END }; |
978 | 978 | ||
979 | bo.expiration_time = | 979 | bo.expiration_time = |
980 | GNUNET_TIME_year_to_time(GNUNET_TIME_get_current_year() + 2); | 980 | GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2); |
981 | 981 | ||
982 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 982 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
983 | return 2; | 983 | return 2; |
984 | ret = | 984 | ret = |
985 | (GNUNET_OK == | 985 | (GNUNET_OK == |
986 | GNUNET_PROGRAM_run(argc, | 986 | GNUNET_PROGRAM_run (argc, |
987 | argv, | 987 | argv, |
988 | "gnunet-publish [OPTIONS] FILENAME", | 988 | "gnunet-publish [OPTIONS] FILENAME", |
989 | gettext_noop("Publish a file or directory on GNUnet"), | 989 | gettext_noop ("Publish a file or directory on GNUnet"), |
990 | options, | 990 | options, |
991 | &run, | 991 | &run, |
992 | NULL)) | 992 | NULL)) |
993 | ? ret | 993 | ? ret |
994 | : 1; | 994 | : 1; |
995 | GNUNET_free((void *)argv); | 995 | GNUNET_free ((void *) argv); |
996 | return ret; | 996 | return ret; |
997 | } | 997 | } |
998 | 998 | ||
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index ac31387e2..f11335985 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c | |||
@@ -76,13 +76,13 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
76 | * @return 0 to continue extracting, 1 to abort | 76 | * @return 0 to continue extracting, 1 to abort |
77 | */ | 77 | */ |
78 | static int | 78 | static int |
79 | item_printer(void *cls, | 79 | item_printer (void *cls, |
80 | const char *plugin_name, | 80 | const char *plugin_name, |
81 | enum EXTRACTOR_MetaType type, | 81 | enum EXTRACTOR_MetaType type, |
82 | enum EXTRACTOR_MetaFormat format, | 82 | enum EXTRACTOR_MetaFormat format, |
83 | const char *data_mime_type, | 83 | const char *data_mime_type, |
84 | const char *data, | 84 | const char *data, |
85 | size_t data_size) | 85 | size_t data_size) |
86 | { | 86 | { |
87 | if ((format != EXTRACTOR_METAFORMAT_UTF8) && | 87 | if ((format != EXTRACTOR_METAFORMAT_UTF8) && |
88 | (format != EXTRACTOR_METAFORMAT_C_STRING)) | 88 | (format != EXTRACTOR_METAFORMAT_C_STRING)) |
@@ -90,45 +90,45 @@ item_printer(void *cls, | |||
90 | if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) | 90 | if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) |
91 | return 0; | 91 | return 0; |
92 | #if HAVE_LIBEXTRACTOR | 92 | #if HAVE_LIBEXTRACTOR |
93 | printf("\t%20s: %s\n", | 93 | printf ("\t%20s: %s\n", |
94 | dgettext(LIBEXTRACTOR_GETTEXT_DOMAIN, | 94 | dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, |
95 | EXTRACTOR_metatype_to_string(type)), | 95 | EXTRACTOR_metatype_to_string (type)), |
96 | data); | 96 | data); |
97 | #else | 97 | #else |
98 | printf("\t%20d: %s\n", type, data); | 98 | printf ("\t%20d: %s\n", type, data); |
99 | #endif | 99 | #endif |
100 | return 0; | 100 | return 0; |
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ||
104 | static void | 104 | static void |
105 | clean_task(void *cls) | 105 | clean_task (void *cls) |
106 | { | 106 | { |
107 | size_t dsize; | 107 | size_t dsize; |
108 | void *ddata; | 108 | void *ddata; |
109 | 109 | ||
110 | GNUNET_FS_stop(ctx); | 110 | GNUNET_FS_stop (ctx); |
111 | ctx = NULL; | 111 | ctx = NULL; |
112 | if (output_filename == NULL) | 112 | if (output_filename == NULL) |
113 | return; | 113 | return; |
114 | if (GNUNET_OK != GNUNET_FS_directory_builder_finish(db, &dsize, &ddata)) | 114 | if (GNUNET_OK != GNUNET_FS_directory_builder_finish (db, &dsize, &ddata)) |
115 | { | 115 | { |
116 | GNUNET_break(0); | 116 | GNUNET_break (0); |
117 | GNUNET_free(output_filename); | 117 | GNUNET_free (output_filename); |
118 | return; | 118 | return; |
119 | } | 119 | } |
120 | if (dsize != GNUNET_DISK_fn_write(output_filename, | 120 | if (dsize != GNUNET_DISK_fn_write (output_filename, |
121 | ddata, | 121 | ddata, |
122 | dsize, | 122 | dsize, |
123 | GNUNET_DISK_PERM_USER_READ | | 123 | GNUNET_DISK_PERM_USER_READ |
124 | GNUNET_DISK_PERM_USER_WRITE)) | 124 | | GNUNET_DISK_PERM_USER_WRITE)) |
125 | { | 125 | { |
126 | fprintf(stderr, | 126 | fprintf (stderr, |
127 | _("Failed to write directory with search results to `%s'\n"), | 127 | _ ("Failed to write directory with search results to `%s'\n"), |
128 | output_filename); | 128 | output_filename); |
129 | } | 129 | } |
130 | GNUNET_free_non_null(ddata); | 130 | GNUNET_free_non_null (ddata); |
131 | GNUNET_free(output_filename); | 131 | GNUNET_free (output_filename); |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
@@ -146,7 +146,7 @@ clean_task(void *cls) | |||
146 | * field in the GNUNET_FS_ProgressInfo struct. | 146 | * field in the GNUNET_FS_ProgressInfo struct. |
147 | */ | 147 | */ |
148 | static void * | 148 | static void * |
149 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) | 149 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
150 | { | 150 | { |
151 | static unsigned int cnt; | 151 | static unsigned int cnt; |
152 | int is_directory; | 152 | int is_directory; |
@@ -154,98 +154,98 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
154 | char *filename; | 154 | char *filename; |
155 | 155 | ||
156 | switch (info->status) | 156 | switch (info->status) |
157 | { | ||
158 | case GNUNET_FS_STATUS_SEARCH_START: | ||
159 | break; | ||
160 | |||
161 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
162 | if (db != NULL) | ||
163 | GNUNET_FS_directory_builder_add (db, | ||
164 | info->value.search.specifics.result.uri, | ||
165 | info->value.search.specifics.result.meta, | ||
166 | NULL); | ||
167 | uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); | ||
168 | printf ("#%u:\n", ++cnt); | ||
169 | filename = GNUNET_CONTAINER_meta_data_get_by_type ( | ||
170 | info->value.search.specifics.result.meta, | ||
171 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | ||
172 | is_directory = GNUNET_FS_meta_data_test_for_directory ( | ||
173 | info->value.search.specifics.result.meta); | ||
174 | if (NULL != filename) | ||
157 | { | 175 | { |
158 | case GNUNET_FS_STATUS_SEARCH_START: | 176 | while ((filename[0] != '\0') && ('/' == filename[strlen (filename) - 1])) |
159 | break; | 177 | filename[strlen (filename) - 1] = '\0'; |
160 | 178 | GNUNET_DISK_filename_canonicalize (filename); | |
161 | case GNUNET_FS_STATUS_SEARCH_RESULT: | 179 | if (GNUNET_YES == is_directory) |
162 | if (db != NULL) | 180 | printf ("gnunet-download -o \"%s%s\" -R %s\n", |
163 | GNUNET_FS_directory_builder_add(db, | 181 | filename, |
164 | info->value.search.specifics.result.uri, | 182 | GNUNET_FS_DIRECTORY_EXT, |
165 | info->value.search.specifics.result.meta, | 183 | uri); |
166 | NULL); | ||
167 | uri = GNUNET_FS_uri_to_string(info->value.search.specifics.result.uri); | ||
168 | printf("#%u:\n", ++cnt); | ||
169 | filename = GNUNET_CONTAINER_meta_data_get_by_type( | ||
170 | info->value.search.specifics.result.meta, | ||
171 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | ||
172 | is_directory = GNUNET_FS_meta_data_test_for_directory( | ||
173 | info->value.search.specifics.result.meta); | ||
174 | if (NULL != filename) | ||
175 | { | ||
176 | while ((filename[0] != '\0') && ('/' == filename[strlen(filename) - 1])) | ||
177 | filename[strlen(filename) - 1] = '\0'; | ||
178 | GNUNET_DISK_filename_canonicalize(filename); | ||
179 | if (GNUNET_YES == is_directory) | ||
180 | printf("gnunet-download -o \"%s%s\" -R %s\n", | ||
181 | filename, | ||
182 | GNUNET_FS_DIRECTORY_EXT, | ||
183 | uri); | ||
184 | else | ||
185 | printf("gnunet-download -o \"%s\" %s\n", filename, uri); | ||
186 | } | ||
187 | else if (GNUNET_YES == is_directory) | ||
188 | printf("gnunet-download -o \"collection%s\" -R %s\n", | ||
189 | GNUNET_FS_DIRECTORY_EXT, | ||
190 | uri); | ||
191 | else | 184 | else |
192 | printf("gnunet-download %s\n", uri); | 185 | printf ("gnunet-download -o \"%s\" %s\n", filename, uri); |
193 | if (verbose) | ||
194 | GNUNET_CONTAINER_meta_data_iterate(info->value.search.specifics.result | ||
195 | .meta, | ||
196 | &item_printer, | ||
197 | NULL); | ||
198 | printf("\n"); | ||
199 | fflush(stdout); | ||
200 | GNUNET_free_non_null(filename); | ||
201 | GNUNET_free(uri); | ||
202 | results++; | ||
203 | if ((results_limit > 0) && (results >= results_limit)) | ||
204 | GNUNET_SCHEDULER_shutdown(); | ||
205 | break; | ||
206 | |||
207 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | ||
208 | break; | ||
209 | |||
210 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
211 | /* ignore */ | ||
212 | break; | ||
213 | |||
214 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
215 | fprintf(stderr, | ||
216 | _("Error searching: %s.\n"), | ||
217 | info->value.search.specifics.error.message); | ||
218 | GNUNET_SCHEDULER_shutdown(); | ||
219 | break; | ||
220 | |||
221 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
222 | GNUNET_SCHEDULER_add_now(&clean_task, NULL); | ||
223 | break; | ||
224 | |||
225 | default: | ||
226 | fprintf(stderr, _("Unexpected status: %d\n"), info->status); | ||
227 | break; | ||
228 | } | 186 | } |
187 | else if (GNUNET_YES == is_directory) | ||
188 | printf ("gnunet-download -o \"collection%s\" -R %s\n", | ||
189 | GNUNET_FS_DIRECTORY_EXT, | ||
190 | uri); | ||
191 | else | ||
192 | printf ("gnunet-download %s\n", uri); | ||
193 | if (verbose) | ||
194 | GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.result | ||
195 | .meta, | ||
196 | &item_printer, | ||
197 | NULL); | ||
198 | printf ("\n"); | ||
199 | fflush (stdout); | ||
200 | GNUNET_free_non_null (filename); | ||
201 | GNUNET_free (uri); | ||
202 | results++; | ||
203 | if ((results_limit > 0) && (results >= results_limit)) | ||
204 | GNUNET_SCHEDULER_shutdown (); | ||
205 | break; | ||
206 | |||
207 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | ||
208 | break; | ||
209 | |||
210 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
211 | /* ignore */ | ||
212 | break; | ||
213 | |||
214 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
215 | fprintf (stderr, | ||
216 | _ ("Error searching: %s.\n"), | ||
217 | info->value.search.specifics.error.message); | ||
218 | GNUNET_SCHEDULER_shutdown (); | ||
219 | break; | ||
220 | |||
221 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
222 | GNUNET_SCHEDULER_add_now (&clean_task, NULL); | ||
223 | break; | ||
224 | |||
225 | default: | ||
226 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); | ||
227 | break; | ||
228 | } | ||
229 | return NULL; | 229 | return NULL; |
230 | } | 230 | } |
231 | 231 | ||
232 | 232 | ||
233 | static void | 233 | static void |
234 | shutdown_task(void *cls) | 234 | shutdown_task (void *cls) |
235 | { | 235 | { |
236 | if (sc != NULL) | 236 | if (sc != NULL) |
237 | { | 237 | { |
238 | GNUNET_FS_search_stop(sc); | 238 | GNUNET_FS_search_stop (sc); |
239 | sc = NULL; | 239 | sc = NULL; |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
243 | 243 | ||
244 | static void | 244 | static void |
245 | timeout_task(void *cls) | 245 | timeout_task (void *cls) |
246 | { | 246 | { |
247 | tt = NULL; | 247 | tt = NULL; |
248 | GNUNET_SCHEDULER_shutdown(); | 248 | GNUNET_SCHEDULER_shutdown (); |
249 | } | 249 | } |
250 | 250 | ||
251 | 251 | ||
@@ -258,10 +258,10 @@ timeout_task(void *cls) | |||
258 | * @param c configuration | 258 | * @param c configuration |
259 | */ | 259 | */ |
260 | static void | 260 | static void |
261 | run(void *cls, | 261 | run (void *cls, |
262 | char *const *args, | 262 | char *const *args, |
263 | const char *cfgfile, | 263 | const char *cfgfile, |
264 | const struct GNUNET_CONFIGURATION_Handle *c) | 264 | const struct GNUNET_CONFIGURATION_Handle *c) |
265 | { | 265 | { |
266 | struct GNUNET_FS_Uri *uri; | 266 | struct GNUNET_FS_Uri *uri; |
267 | unsigned int argc; | 267 | unsigned int argc; |
@@ -270,46 +270,46 @@ run(void *cls, | |||
270 | argc = 0; | 270 | argc = 0; |
271 | while (NULL != args[argc]) | 271 | while (NULL != args[argc]) |
272 | argc++; | 272 | argc++; |
273 | uri = GNUNET_FS_uri_ksk_create_from_args(argc, (const char **)args); | 273 | uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args); |
274 | if (NULL == uri) | 274 | if (NULL == uri) |
275 | { | 275 | { |
276 | fprintf(stderr, | 276 | fprintf (stderr, |
277 | "%s", | 277 | "%s", |
278 | _("Could not create keyword URI from arguments.\n")); | 278 | _ ("Could not create keyword URI from arguments.\n")); |
279 | ret = 1; | 279 | ret = 1; |
280 | return; | 280 | return; |
281 | } | 281 | } |
282 | cfg = c; | 282 | cfg = c; |
283 | ctx = GNUNET_FS_start(cfg, | 283 | ctx = GNUNET_FS_start (cfg, |
284 | "gnunet-search", | 284 | "gnunet-search", |
285 | &progress_cb, | 285 | &progress_cb, |
286 | NULL, | 286 | NULL, |
287 | GNUNET_FS_FLAGS_NONE, | 287 | GNUNET_FS_FLAGS_NONE, |
288 | GNUNET_FS_OPTIONS_END); | 288 | GNUNET_FS_OPTIONS_END); |
289 | if (NULL == ctx) | 289 | if (NULL == ctx) |
290 | { | 290 | { |
291 | fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); | 291 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); |
292 | GNUNET_FS_uri_destroy(uri); | 292 | GNUNET_FS_uri_destroy (uri); |
293 | ret = 1; | 293 | ret = 1; |
294 | return; | 294 | return; |
295 | } | 295 | } |
296 | if (output_filename != NULL) | 296 | if (output_filename != NULL) |
297 | db = GNUNET_FS_directory_builder_create(NULL); | 297 | db = GNUNET_FS_directory_builder_create (NULL); |
298 | options = GNUNET_FS_SEARCH_OPTION_NONE; | 298 | options = GNUNET_FS_SEARCH_OPTION_NONE; |
299 | if (local_only) | 299 | if (local_only) |
300 | options |= GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY; | 300 | options |= GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY; |
301 | sc = GNUNET_FS_search_start(ctx, uri, anonymity, options, NULL); | 301 | sc = GNUNET_FS_search_start (ctx, uri, anonymity, options, NULL); |
302 | GNUNET_FS_uri_destroy(uri); | 302 | GNUNET_FS_uri_destroy (uri); |
303 | if (NULL == sc) | 303 | if (NULL == sc) |
304 | { | 304 | { |
305 | fprintf(stderr, "%s", _("Could not start searching.\n")); | 305 | fprintf (stderr, "%s", _ ("Could not start searching.\n")); |
306 | GNUNET_FS_stop(ctx); | 306 | GNUNET_FS_stop (ctx); |
307 | ret = 1; | 307 | ret = 1; |
308 | return; | 308 | return; |
309 | } | 309 | } |
310 | if (0 != timeout.rel_value_us) | 310 | if (0 != timeout.rel_value_us) |
311 | tt = GNUNET_SCHEDULER_add_delayed(timeout, &timeout_task, NULL); | 311 | tt = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, NULL); |
312 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 312 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
@@ -321,57 +321,57 @@ run(void *cls, | |||
321 | * @return 0 ok, 1 on error | 321 | * @return 0 ok, 1 on error |
322 | */ | 322 | */ |
323 | int | 323 | int |
324 | main(int argc, char *const *argv) | 324 | main (int argc, char *const *argv) |
325 | { | 325 | { |
326 | struct GNUNET_GETOPT_CommandLineOption options[] = | 326 | struct GNUNET_GETOPT_CommandLineOption options[] = |
327 | { GNUNET_GETOPT_option_uint('a', | 327 | { GNUNET_GETOPT_option_uint ('a', |
328 | "anonymity", | 328 | "anonymity", |
329 | "LEVEL", | 329 | "LEVEL", |
330 | gettext_noop( | 330 | gettext_noop ( |
331 | "set the desired LEVEL of receiver-anonymity"), | 331 | "set the desired LEVEL of receiver-anonymity"), |
332 | &anonymity), | 332 | &anonymity), |
333 | GNUNET_GETOPT_option_flag( | 333 | GNUNET_GETOPT_option_flag ( |
334 | 'n', | 334 | 'n', |
335 | "no-network", | 335 | "no-network", |
336 | gettext_noop("only search the local peer (no P2P network search)"), | 336 | gettext_noop ("only search the local peer (no P2P network search)"), |
337 | &local_only), | 337 | &local_only), |
338 | GNUNET_GETOPT_option_string( | 338 | GNUNET_GETOPT_option_string ( |
339 | 'o', | 339 | 'o', |
340 | "output", | 340 | "output", |
341 | "PREFIX", | 341 | "PREFIX", |
342 | gettext_noop("write search results to file starting with PREFIX"), | 342 | gettext_noop ("write search results to file starting with PREFIX"), |
343 | &output_filename), | 343 | &output_filename), |
344 | GNUNET_GETOPT_option_relative_time( | 344 | GNUNET_GETOPT_option_relative_time ( |
345 | 't', | 345 | 't', |
346 | "timeout", | 346 | "timeout", |
347 | "DELAY", | 347 | "DELAY", |
348 | gettext_noop("automatically terminate search after DELAY"), | 348 | gettext_noop ("automatically terminate search after DELAY"), |
349 | &timeout), | 349 | &timeout), |
350 | GNUNET_GETOPT_option_verbose(&verbose), | 350 | GNUNET_GETOPT_option_verbose (&verbose), |
351 | GNUNET_GETOPT_option_uint('N', | 351 | GNUNET_GETOPT_option_uint ('N', |
352 | "results", | 352 | "results", |
353 | "VALUE", | 353 | "VALUE", |
354 | gettext_noop("automatically terminate search " | 354 | gettext_noop ("automatically terminate search " |
355 | "after VALUE results are found"), | 355 | "after VALUE results are found"), |
356 | &results_limit), | 356 | &results_limit), |
357 | GNUNET_GETOPT_OPTION_END }; | 357 | GNUNET_GETOPT_OPTION_END }; |
358 | 358 | ||
359 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 359 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
360 | return 2; | 360 | return 2; |
361 | 361 | ||
362 | ret = | 362 | ret = |
363 | (GNUNET_OK == | 363 | (GNUNET_OK == |
364 | GNUNET_PROGRAM_run(argc, | 364 | GNUNET_PROGRAM_run (argc, |
365 | argv, | 365 | argv, |
366 | "gnunet-search [OPTIONS] KEYWORD", | 366 | "gnunet-search [OPTIONS] KEYWORD", |
367 | gettext_noop( | 367 | gettext_noop ( |
368 | "Search GNUnet for files that were published on GNUnet"), | 368 | "Search GNUnet for files that were published on GNUnet"), |
369 | options, | 369 | options, |
370 | &run, | 370 | &run, |
371 | NULL)) | 371 | NULL)) |
372 | ? ret | 372 | ? ret |
373 | : 1; | 373 | : 1; |
374 | GNUNET_free((void *)argv); | 374 | GNUNET_free ((void *) argv); |
375 | return ret; | 375 | return ret; |
376 | } | 376 | } |
377 | 377 | ||
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 70aff8a75..40b3f6c1d 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c | |||
@@ -59,7 +59,8 @@ | |||
59 | * time interval, remaining cover traffic counters are | 59 | * time interval, remaining cover traffic counters are |
60 | * decremented by 1/16th. | 60 | * decremented by 1/16th. |
61 | */ | 61 | */ |
62 | #define COVER_AGE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 62 | #define COVER_AGE_FREQUENCY GNUNET_TIME_relative_multiply ( \ |
63 | GNUNET_TIME_UNIT_SECONDS, 5) | ||
63 | 64 | ||
64 | /** | 65 | /** |
65 | * Collect an instane number of statistics? May cause excessive IPC. | 66 | * Collect an instane number of statistics? May cause excessive IPC. |
@@ -72,7 +73,8 @@ | |||
72 | * Doubly-linked list of requests we are performing | 73 | * Doubly-linked list of requests we are performing |
73 | * on behalf of the same client. | 74 | * on behalf of the same client. |
74 | */ | 75 | */ |
75 | struct ClientRequest { | 76 | struct ClientRequest |
77 | { | ||
76 | /** | 78 | /** |
77 | * This is a doubly-linked list. | 79 | * This is a doubly-linked list. |
78 | */ | 80 | */ |
@@ -96,7 +98,7 @@ struct ClientRequest { | |||
96 | /** | 98 | /** |
97 | * Task scheduled to destroy the request. | 99 | * Task scheduled to destroy the request. |
98 | */ | 100 | */ |
99 | struct GNUNET_SCHEDULER_Task * kill_task; | 101 | struct GNUNET_SCHEDULER_Task *kill_task; |
100 | }; | 102 | }; |
101 | 103 | ||
102 | 104 | ||
@@ -104,7 +106,8 @@ struct ClientRequest { | |||
104 | * Replies to be transmitted to the client. The actual | 106 | * Replies to be transmitted to the client. The actual |
105 | * response message is allocated after this struct. | 107 | * response message is allocated after this struct. |
106 | */ | 108 | */ |
107 | struct ClientResponse { | 109 | struct ClientResponse |
110 | { | ||
108 | /** | 111 | /** |
109 | * This is a doubly-linked list. | 112 | * This is a doubly-linked list. |
110 | */ | 113 | */ |
@@ -131,7 +134,8 @@ struct ClientResponse { | |||
131 | * Information we track while handling an index | 134 | * Information we track while handling an index |
132 | * start request from a client. | 135 | * start request from a client. |
133 | */ | 136 | */ |
134 | struct IndexStartContext { | 137 | struct IndexStartContext |
138 | { | ||
135 | /** | 139 | /** |
136 | * This is a doubly linked list. | 140 | * This is a doubly linked list. |
137 | */ | 141 | */ |
@@ -167,7 +171,8 @@ struct IndexStartContext { | |||
167 | /** | 171 | /** |
168 | * A local client. | 172 | * A local client. |
169 | */ | 173 | */ |
170 | struct GSF_LocalClient { | 174 | struct GSF_LocalClient |
175 | { | ||
171 | /** | 176 | /** |
172 | * ID of the client. | 177 | * ID of the client. |
173 | */ | 178 | */ |
@@ -316,7 +321,7 @@ static struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | |||
316 | /** | 321 | /** |
317 | * ID of our task that we use to age the cover counters. | 322 | * ID of our task that we use to age the cover counters. |
318 | */ | 323 | */ |
319 | static struct GNUNET_SCHEDULER_Task * cover_age_task; | 324 | static struct GNUNET_SCHEDULER_Task *cover_age_task; |
320 | 325 | ||
321 | /** | 326 | /** |
322 | * Datastore 'GET' load tracking. | 327 | * Datastore 'GET' load tracking. |
@@ -333,13 +338,13 @@ static struct GNUNET_LOAD_Value *datastore_get_load; | |||
333 | * @return handle to local client entry | 338 | * @return handle to local client entry |
334 | */ | 339 | */ |
335 | static void * | 340 | static void * |
336 | client_connect_cb(void *cls, | 341 | client_connect_cb (void *cls, |
337 | struct GNUNET_SERVICE_Client *client, | 342 | struct GNUNET_SERVICE_Client *client, |
338 | struct GNUNET_MQ_Handle *mq) | 343 | struct GNUNET_MQ_Handle *mq) |
339 | { | 344 | { |
340 | struct GSF_LocalClient *pos; | 345 | struct GSF_LocalClient *pos; |
341 | 346 | ||
342 | pos = GNUNET_new(struct GSF_LocalClient); | 347 | pos = GNUNET_new (struct GSF_LocalClient); |
343 | pos->client = client; | 348 | pos->client = client; |
344 | pos->mq = mq; | 349 | pos->mq = mq; |
345 | return pos; | 350 | return pos; |
@@ -352,22 +357,22 @@ client_connect_cb(void *cls, | |||
352 | * @param cls the client request to free | 357 | * @param cls the client request to free |
353 | */ | 358 | */ |
354 | static void | 359 | static void |
355 | client_request_destroy(void *cls) | 360 | client_request_destroy (void *cls) |
356 | { | 361 | { |
357 | struct ClientRequest *cr = cls; | 362 | struct ClientRequest *cr = cls; |
358 | struct GSF_LocalClient *lc = cr->lc; | 363 | struct GSF_LocalClient *lc = cr->lc; |
359 | 364 | ||
360 | cr->kill_task = NULL; | 365 | cr->kill_task = NULL; |
361 | GNUNET_CONTAINER_DLL_remove(lc->cr_head, | 366 | GNUNET_CONTAINER_DLL_remove (lc->cr_head, |
362 | lc->cr_tail, | 367 | lc->cr_tail, |
363 | cr); | 368 | cr); |
364 | GSF_pending_request_cancel_(cr->pr, | 369 | GSF_pending_request_cancel_ (cr->pr, |
365 | GNUNET_YES); | 370 | GNUNET_YES); |
366 | GNUNET_STATISTICS_update(GSF_stats, | 371 | GNUNET_STATISTICS_update (GSF_stats, |
367 | gettext_noop("# client searches active"), | 372 | gettext_noop ("# client searches active"), |
368 | -1, | 373 | -1, |
369 | GNUNET_NO); | 374 | GNUNET_NO); |
370 | GNUNET_free(cr); | 375 | GNUNET_free (cr); |
371 | } | 376 | } |
372 | 377 | ||
373 | 378 | ||
@@ -390,15 +395,15 @@ client_request_destroy(void *cls) | |||
390 | * @param data_len number of bytes in @a data | 395 | * @param data_len number of bytes in @a data |
391 | */ | 396 | */ |
392 | static void | 397 | static void |
393 | client_response_handler(void *cls, | 398 | client_response_handler (void *cls, |
394 | enum GNUNET_BLOCK_EvaluationResult eval, | 399 | enum GNUNET_BLOCK_EvaluationResult eval, |
395 | struct GSF_PendingRequest *pr, | 400 | struct GSF_PendingRequest *pr, |
396 | uint32_t reply_anonymity_level, | 401 | uint32_t reply_anonymity_level, |
397 | struct GNUNET_TIME_Absolute expiration, | 402 | struct GNUNET_TIME_Absolute expiration, |
398 | struct GNUNET_TIME_Absolute last_transmission, | 403 | struct GNUNET_TIME_Absolute last_transmission, |
399 | enum GNUNET_BLOCK_Type type, | 404 | enum GNUNET_BLOCK_Type type, |
400 | const void *data, | 405 | const void *data, |
401 | size_t data_len) | 406 | size_t data_len) |
402 | { | 407 | { |
403 | struct ClientRequest *cr = cls; | 408 | struct ClientRequest *cr = cls; |
404 | struct GSF_LocalClient *lc; | 409 | struct GSF_LocalClient *lc; |
@@ -407,52 +412,52 @@ client_response_handler(void *cls, | |||
407 | const struct GSF_PendingRequestData *prd; | 412 | const struct GSF_PendingRequestData *prd; |
408 | 413 | ||
409 | if (NULL == data) | 414 | if (NULL == data) |
410 | { | 415 | { |
411 | /* local-only request, with no result, clean up. */ | 416 | /* local-only request, with no result, clean up. */ |
412 | if (NULL == cr->kill_task) | 417 | if (NULL == cr->kill_task) |
413 | cr->kill_task = GNUNET_SCHEDULER_add_now(&client_request_destroy, | 418 | cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, |
414 | cr); | 419 | cr); |
415 | return; | 420 | return; |
416 | } | 421 | } |
417 | prd = GSF_pending_request_get_data_(pr); | 422 | prd = GSF_pending_request_get_data_ (pr); |
418 | GNUNET_break(type != GNUNET_BLOCK_TYPE_ANY); | 423 | GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY); |
419 | if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY)) | 424 | if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY)) |
420 | { | 425 | { |
421 | GNUNET_break(0); | 426 | GNUNET_break (0); |
422 | return; | 427 | return; |
423 | } | 428 | } |
424 | GNUNET_STATISTICS_update(GSF_stats, | 429 | GNUNET_STATISTICS_update (GSF_stats, |
425 | gettext_noop | 430 | gettext_noop |
426 | ("# replies received for local clients"), 1, | 431 | ("# replies received for local clients"), 1, |
427 | GNUNET_NO); | 432 | GNUNET_NO); |
428 | GNUNET_assert(pr == cr->pr); | 433 | GNUNET_assert (pr == cr->pr); |
429 | lc = cr->lc; | 434 | lc = cr->lc; |
430 | env = GNUNET_MQ_msg_extra(pm, | 435 | env = GNUNET_MQ_msg_extra (pm, |
431 | data_len, | 436 | data_len, |
432 | GNUNET_MESSAGE_TYPE_FS_PUT); | 437 | GNUNET_MESSAGE_TYPE_FS_PUT); |
433 | pm->type = htonl(type); | 438 | pm->type = htonl (type); |
434 | pm->expiration = GNUNET_TIME_absolute_hton(expiration); | 439 | pm->expiration = GNUNET_TIME_absolute_hton (expiration); |
435 | pm->last_transmission = GNUNET_TIME_absolute_hton(last_transmission); | 440 | pm->last_transmission = GNUNET_TIME_absolute_hton (last_transmission); |
436 | pm->num_transmissions = htonl(prd->num_transmissions); | 441 | pm->num_transmissions = htonl (prd->num_transmissions); |
437 | pm->respect_offered = htonl(prd->respect_offered); | 442 | pm->respect_offered = htonl (prd->respect_offered); |
438 | GNUNET_memcpy(&pm[1], | 443 | GNUNET_memcpy (&pm[1], |
439 | data, | 444 | data, |
440 | data_len); | 445 | data_len); |
441 | GNUNET_MQ_send(lc->mq, | 446 | GNUNET_MQ_send (lc->mq, |
442 | env); | 447 | env); |
443 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
444 | "Queued reply to query `%s' for local client\n", | 449 | "Queued reply to query `%s' for local client\n", |
445 | GNUNET_h2s(&prd->query)); | 450 | GNUNET_h2s (&prd->query)); |
446 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) | 451 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) |
447 | { | 452 | { |
448 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
449 | "Evaluation %d - keeping query alive\n", | 454 | "Evaluation %d - keeping query alive\n", |
450 | (int)eval); | 455 | (int) eval); |
451 | return; | 456 | return; |
452 | } | 457 | } |
453 | if (NULL == cr->kill_task) | 458 | if (NULL == cr->kill_task) |
454 | cr->kill_task = GNUNET_SCHEDULER_add_now(&client_request_destroy, | 459 | cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, |
455 | cr); | 460 | cr); |
456 | } | 461 | } |
457 | 462 | ||
458 | 463 | ||
@@ -465,9 +470,9 @@ client_response_handler(void *cls, | |||
465 | * @param app_ctx the `struct GSF_LocalClient` | 470 | * @param app_ctx the `struct GSF_LocalClient` |
466 | */ | 471 | */ |
467 | static void | 472 | static void |
468 | client_disconnect_cb(void *cls, | 473 | client_disconnect_cb (void *cls, |
469 | struct GNUNET_SERVICE_Client *client, | 474 | struct GNUNET_SERVICE_Client *client, |
470 | void *app_ctx) | 475 | void *app_ctx) |
471 | { | 476 | { |
472 | struct GSF_LocalClient *lc = app_ctx; | 477 | struct GSF_LocalClient *lc = app_ctx; |
473 | struct IndexStartContext *isc; | 478 | struct IndexStartContext *isc; |
@@ -475,27 +480,27 @@ client_disconnect_cb(void *cls, | |||
475 | struct ClientResponse *res; | 480 | struct ClientResponse *res; |
476 | 481 | ||
477 | while (NULL != (cr = lc->cr_head)) | 482 | while (NULL != (cr = lc->cr_head)) |
478 | { | 483 | { |
479 | if (NULL != cr->kill_task) | 484 | if (NULL != cr->kill_task) |
480 | GNUNET_SCHEDULER_cancel(cr->kill_task); | 485 | GNUNET_SCHEDULER_cancel (cr->kill_task); |
481 | client_request_destroy(cr); | 486 | client_request_destroy (cr); |
482 | } | 487 | } |
483 | while (NULL != (res = lc->res_head)) | 488 | while (NULL != (res = lc->res_head)) |
484 | { | 489 | { |
485 | GNUNET_CONTAINER_DLL_remove(lc->res_head, | 490 | GNUNET_CONTAINER_DLL_remove (lc->res_head, |
486 | lc->res_tail, | 491 | lc->res_tail, |
487 | res); | 492 | res); |
488 | GNUNET_free(res); | 493 | GNUNET_free (res); |
489 | } | 494 | } |
490 | while (NULL != (isc = lc->isc_head)) | 495 | while (NULL != (isc = lc->isc_head)) |
491 | { | 496 | { |
492 | GNUNET_CONTAINER_DLL_remove(lc->isc_head, | 497 | GNUNET_CONTAINER_DLL_remove (lc->isc_head, |
493 | lc->isc_tail, | 498 | lc->isc_tail, |
494 | isc); | 499 | isc); |
495 | GNUNET_CRYPTO_hash_file_cancel(isc->fhc); | 500 | GNUNET_CRYPTO_hash_file_cancel (isc->fhc); |
496 | GNUNET_free(isc); | 501 | GNUNET_free (isc); |
497 | } | 502 | } |
498 | GNUNET_free(lc); | 503 | GNUNET_free (lc); |
499 | } | 504 | } |
500 | 505 | ||
501 | 506 | ||
@@ -508,14 +513,14 @@ client_disconnect_cb(void *cls, | |||
508 | * @param cls unused closure | 513 | * @param cls unused closure |
509 | */ | 514 | */ |
510 | static void | 515 | static void |
511 | age_cover_counters(void *cls) | 516 | age_cover_counters (void *cls) |
512 | { | 517 | { |
513 | GSF_cover_content_count = (GSF_cover_content_count * 15) / 16; | 518 | GSF_cover_content_count = (GSF_cover_content_count * 15) / 16; |
514 | GSF_cover_query_count = (GSF_cover_query_count * 15) / 16; | 519 | GSF_cover_query_count = (GSF_cover_query_count * 15) / 16; |
515 | cover_age_task = | 520 | cover_age_task = |
516 | GNUNET_SCHEDULER_add_delayed(COVER_AGE_FREQUENCY, | 521 | GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, |
517 | &age_cover_counters, | 522 | &age_cover_counters, |
518 | NULL); | 523 | NULL); |
519 | } | 524 | } |
520 | 525 | ||
521 | 526 | ||
@@ -526,12 +531,12 @@ age_cover_counters(void *cls) | |||
526 | * @param start time when the datastore request was issued | 531 | * @param start time when the datastore request was issued |
527 | */ | 532 | */ |
528 | void | 533 | void |
529 | GSF_update_datastore_delay_(struct GNUNET_TIME_Absolute start) | 534 | GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start) |
530 | { | 535 | { |
531 | struct GNUNET_TIME_Relative delay; | 536 | struct GNUNET_TIME_Relative delay; |
532 | 537 | ||
533 | delay = GNUNET_TIME_absolute_get_duration(start); | 538 | delay = GNUNET_TIME_absolute_get_duration (start); |
534 | GNUNET_LOAD_update(datastore_get_load, delay.rel_value_us); | 539 | GNUNET_LOAD_update (datastore_get_load, delay.rel_value_us); |
535 | } | 540 | } |
536 | 541 | ||
537 | 542 | ||
@@ -546,11 +551,11 @@ GSF_update_datastore_delay_(struct GNUNET_TIME_Absolute start) | |||
546 | * #GNUNET_SYSERR to process for free (load low) | 551 | * #GNUNET_SYSERR to process for free (load low) |
547 | */ | 552 | */ |
548 | int | 553 | int |
549 | GSF_test_get_load_too_high_(uint32_t priority) | 554 | GSF_test_get_load_too_high_ (uint32_t priority) |
550 | { | 555 | { |
551 | double ld; | 556 | double ld; |
552 | 557 | ||
553 | ld = GNUNET_LOAD_get_load(datastore_get_load); | 558 | ld = GNUNET_LOAD_get_load (datastore_get_load); |
554 | if (ld < 1) | 559 | if (ld < 1) |
555 | return GNUNET_SYSERR; | 560 | return GNUNET_SYSERR; |
556 | if (ld <= priority) | 561 | if (ld <= priority) |
@@ -571,30 +576,30 @@ GSF_test_get_load_too_high_(uint32_t priority) | |||
571 | * @param prop performance data for the address (as far as known) | 576 | * @param prop performance data for the address (as far as known) |
572 | */ | 577 | */ |
573 | static void | 578 | static void |
574 | update_latencies(void *cls, | 579 | update_latencies (void *cls, |
575 | const struct GNUNET_HELLO_Address *address, | 580 | const struct GNUNET_HELLO_Address *address, |
576 | int active, | 581 | int active, |
577 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 582 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
578 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 583 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
579 | const struct GNUNET_ATS_Properties *prop) | 584 | const struct GNUNET_ATS_Properties *prop) |
580 | { | 585 | { |
581 | if (NULL == address) | 586 | if (NULL == address) |
582 | { | 587 | { |
583 | /* ATS service temporarily disconnected */ | 588 | /* ATS service temporarily disconnected */ |
584 | return; | 589 | return; |
585 | } | 590 | } |
586 | 591 | ||
587 | if (GNUNET_YES != active) | 592 | if (GNUNET_YES != active) |
588 | return; | 593 | return; |
589 | GSF_update_peer_latency_(&address->peer, | 594 | GSF_update_peer_latency_ (&address->peer, |
590 | prop->delay); | 595 | prop->delay); |
591 | GSF_avg_latency.rel_value_us = | 596 | GSF_avg_latency.rel_value_us = |
592 | (GSF_avg_latency.rel_value_us * 31 + | 597 | (GSF_avg_latency.rel_value_us * 31 |
593 | GNUNET_MIN(5000, prop->delay.rel_value_us)) / 32; | 598 | + GNUNET_MIN (5000, prop->delay.rel_value_us)) / 32; |
594 | GNUNET_STATISTICS_set(GSF_stats, | 599 | GNUNET_STATISTICS_set (GSF_stats, |
595 | gettext_noop("# running average P2P latency (ms)"), | 600 | gettext_noop ("# running average P2P latency (ms)"), |
596 | GSF_avg_latency.rel_value_us / 1000LL, | 601 | GSF_avg_latency.rel_value_us / 1000LL, |
597 | GNUNET_NO); | 602 | GNUNET_NO); |
598 | } | 603 | } |
599 | 604 | ||
600 | 605 | ||
@@ -607,17 +612,17 @@ update_latencies(void *cls, | |||
607 | * #GNUNET_SYSERR to close it (signal serious error) | 612 | * #GNUNET_SYSERR to close it (signal serious error) |
608 | */ | 613 | */ |
609 | static int | 614 | static int |
610 | check_p2p_put(void *cls, | 615 | check_p2p_put (void *cls, |
611 | const struct PutMessage *put) | 616 | const struct PutMessage *put) |
612 | { | 617 | { |
613 | enum GNUNET_BLOCK_Type type; | 618 | enum GNUNET_BLOCK_Type type; |
614 | 619 | ||
615 | type = ntohl(put->type); | 620 | type = ntohl (put->type); |
616 | if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) | 621 | if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) |
617 | { | 622 | { |
618 | GNUNET_break_op(0); | 623 | GNUNET_break_op (0); |
619 | return GNUNET_SYSERR; | 624 | return GNUNET_SYSERR; |
620 | } | 625 | } |
621 | return GNUNET_OK; | 626 | return GNUNET_OK; |
622 | } | 627 | } |
623 | 628 | ||
@@ -632,25 +637,25 @@ check_p2p_put(void *cls, | |||
632 | * @param ppd peer performance data | 637 | * @param ppd peer performance data |
633 | */ | 638 | */ |
634 | static void | 639 | static void |
635 | consider_request_for_forwarding(void *cls, | 640 | consider_request_for_forwarding (void *cls, |
636 | const struct GNUNET_PeerIdentity *peer, | 641 | const struct GNUNET_PeerIdentity *peer, |
637 | struct GSF_ConnectedPeer *cp, | 642 | struct GSF_ConnectedPeer *cp, |
638 | const struct GSF_PeerPerformanceData *ppd) | 643 | const struct GSF_PeerPerformanceData *ppd) |
639 | { | 644 | { |
640 | struct GSF_PendingRequest *pr = cls; | 645 | struct GSF_PendingRequest *pr = cls; |
641 | 646 | ||
642 | if (GNUNET_YES != | 647 | if (GNUNET_YES != |
643 | GSF_pending_request_test_target_(pr, peer)) | 648 | GSF_pending_request_test_target_ (pr, peer)) |
644 | { | 649 | { |
645 | #if INSANE_STATISTICS | 650 | #if INSANE_STATISTICS |
646 | GNUNET_STATISTICS_update(GSF_stats, | 651 | GNUNET_STATISTICS_update (GSF_stats, |
647 | gettext_noop("# Loopback routes suppressed"), 1, | 652 | gettext_noop ("# Loopback routes suppressed"), 1, |
648 | GNUNET_NO); | 653 | GNUNET_NO); |
649 | #endif | 654 | #endif |
650 | return; | 655 | return; |
651 | } | 656 | } |
652 | GSF_plan_add_(cp, | 657 | GSF_plan_add_ (cp, |
653 | pr); | 658 | pr); |
654 | } | 659 | } |
655 | 660 | ||
656 | 661 | ||
@@ -665,17 +670,17 @@ consider_request_for_forwarding(void *cls, | |||
665 | * @param result final datastore lookup result | 670 | * @param result final datastore lookup result |
666 | */ | 671 | */ |
667 | void | 672 | void |
668 | GSF_consider_forwarding(void *cls, | 673 | GSF_consider_forwarding (void *cls, |
669 | struct GSF_PendingRequest *pr, | 674 | struct GSF_PendingRequest *pr, |
670 | enum GNUNET_BLOCK_EvaluationResult result) | 675 | enum GNUNET_BLOCK_EvaluationResult result) |
671 | { | 676 | { |
672 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) | 677 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) |
673 | return; /* we're done... */ | 678 | return; /* we're done... */ |
674 | if (GNUNET_YES != | 679 | if (GNUNET_YES != |
675 | GSF_pending_request_test_active_(pr)) | 680 | GSF_pending_request_test_active_ (pr)) |
676 | return; /* request is not actually active, skip! */ | 681 | return; /* request is not actually active, skip! */ |
677 | GSF_iterate_connected_peers_(&consider_request_for_forwarding, | 682 | GSF_iterate_connected_peers_ (&consider_request_for_forwarding, |
678 | pr); | 683 | pr); |
679 | } | 684 | } |
680 | 685 | ||
681 | 686 | ||
@@ -688,35 +693,37 @@ GSF_consider_forwarding(void *cls, | |||
688 | * #GNUNET_SYSERR to close it (signal serious error) | 693 | * #GNUNET_SYSERR to close it (signal serious error) |
689 | */ | 694 | */ |
690 | static int | 695 | static int |
691 | check_p2p_get(void *cls, | 696 | check_p2p_get (void *cls, |
692 | const struct GetMessage *gm) | 697 | const struct GetMessage *gm) |
693 | { | 698 | { |
694 | size_t msize; | 699 | size_t msize; |
695 | unsigned int bm; | 700 | unsigned int bm; |
696 | unsigned int bits; | 701 | unsigned int bits; |
697 | size_t bfsize; | 702 | size_t bfsize; |
698 | 703 | ||
699 | msize = ntohs(gm->header.size); | 704 | msize = ntohs (gm->header.size); |
700 | bm = ntohl(gm->hash_bitmap); | 705 | bm = ntohl (gm->hash_bitmap); |
701 | bits = 0; | 706 | bits = 0; |
702 | while (bm > 0) | 707 | while (bm > 0) |
703 | { | 708 | { |
704 | if (1 == (bm & 1)) | 709 | if (1 == (bm & 1)) |
705 | bits++; | 710 | bits++; |
706 | bm >>= 1; | 711 | bm >>= 1; |
707 | } | 712 | } |
708 | if (msize < sizeof(struct GetMessage) + bits * sizeof(struct GNUNET_PeerIdentity)) | 713 | if (msize < sizeof(struct GetMessage) + bits * sizeof(struct |
709 | { | 714 | GNUNET_PeerIdentity)) |
710 | GNUNET_break_op(0); | 715 | { |
711 | return GNUNET_SYSERR; | 716 | GNUNET_break_op (0); |
712 | } | 717 | return GNUNET_SYSERR; |
713 | bfsize = msize - sizeof(struct GetMessage) - bits * sizeof(struct GNUNET_PeerIdentity); | 718 | } |
719 | bfsize = msize - sizeof(struct GetMessage) - bits * sizeof(struct | ||
720 | GNUNET_PeerIdentity); | ||
714 | /* bfsize must be power of 2, check! */ | 721 | /* bfsize must be power of 2, check! */ |
715 | if (0 != ((bfsize - 1) & bfsize)) | 722 | if (0 != ((bfsize - 1) & bfsize)) |
716 | { | 723 | { |
717 | GNUNET_break_op(0); | 724 | GNUNET_break_op (0); |
718 | return GNUNET_SYSERR; | 725 | return GNUNET_SYSERR; |
719 | } | 726 | } |
720 | return GNUNET_OK; | 727 | return GNUNET_OK; |
721 | } | 728 | } |
722 | 729 | ||
@@ -732,48 +739,48 @@ check_p2p_get(void *cls, | |||
732 | * @param result final datastore lookup result | 739 | * @param result final datastore lookup result |
733 | */ | 740 | */ |
734 | static void | 741 | static void |
735 | start_p2p_processing(void *cls, | 742 | start_p2p_processing (void *cls, |
736 | struct GSF_PendingRequest *pr, | 743 | struct GSF_PendingRequest *pr, |
737 | enum GNUNET_BLOCK_EvaluationResult result) | 744 | enum GNUNET_BLOCK_EvaluationResult result) |
738 | { | 745 | { |
739 | struct GSF_LocalClient *lc = cls; | 746 | struct GSF_LocalClient *lc = cls; |
740 | struct GSF_PendingRequestData *prd; | 747 | struct GSF_PendingRequestData *prd; |
741 | 748 | ||
742 | GNUNET_SERVICE_client_continue(lc->client); | 749 | GNUNET_SERVICE_client_continue (lc->client); |
743 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) | 750 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) |
744 | return; /* we're done, 'pr' was already destroyed... */ | 751 | return; /* we're done, 'pr' was already destroyed... */ |
745 | prd = GSF_pending_request_get_data_(pr); | 752 | prd = GSF_pending_request_get_data_ (pr); |
746 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
747 | "Finished database lookup for local request `%s' with result %d\n", | 754 | "Finished database lookup for local request `%s' with result %d\n", |
748 | GNUNET_h2s(&prd->query), | 755 | GNUNET_h2s (&prd->query), |
749 | result); | 756 | result); |
750 | if (0 == prd->anonymity_level) | 757 | if (0 == prd->anonymity_level) |
758 | { | ||
759 | switch (prd->type) | ||
751 | { | 760 | { |
752 | switch (prd->type) | 761 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
753 | { | 762 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
754 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | 763 | /* the above block types MAY be available via 'cadet' */ |
755 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | 764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
756 | /* the above block types MAY be available via 'cadet' */ | 765 | "Considering cadet-based download for block\n"); |
757 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 766 | GSF_cadet_lookup_ (pr); |
758 | "Considering cadet-based download for block\n"); | 767 | break; |
759 | GSF_cadet_lookup_(pr); | 768 | |
760 | break; | 769 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
761 | 770 | /* the above block types are in the DHT */ | |
762 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | 771 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
763 | /* the above block types are in the DHT */ | 772 | "Considering DHT-based search for block\n"); |
764 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 773 | GSF_dht_lookup_ (pr); |
765 | "Considering DHT-based search for block\n"); | 774 | break; |
766 | GSF_dht_lookup_(pr); | 775 | |
767 | break; | 776 | default: |
768 | 777 | GNUNET_break (0); | |
769 | default: | 778 | break; |
770 | GNUNET_break(0); | ||
771 | break; | ||
772 | } | ||
773 | } | 779 | } |
774 | GSF_consider_forwarding(NULL, | 780 | } |
775 | pr, | 781 | GSF_consider_forwarding (NULL, |
776 | result); | 782 | pr, |
783 | result); | ||
777 | } | 784 | } |
778 | 785 | ||
779 | 786 | ||
@@ -786,17 +793,17 @@ start_p2p_processing(void *cls, | |||
786 | * @return #GNUNET_OK if @a sm is well-formed | 793 | * @return #GNUNET_OK if @a sm is well-formed |
787 | */ | 794 | */ |
788 | static int | 795 | static int |
789 | check_client_start_search(void *cls, | 796 | check_client_start_search (void *cls, |
790 | const struct SearchMessage *sm) | 797 | const struct SearchMessage *sm) |
791 | { | 798 | { |
792 | uint16_t msize; | 799 | uint16_t msize; |
793 | 800 | ||
794 | msize = ntohs(sm->header.size) - sizeof(struct SearchMessage); | 801 | msize = ntohs (sm->header.size) - sizeof(struct SearchMessage); |
795 | if (0 != msize % sizeof(struct GNUNET_HashCode)) | 802 | if (0 != msize % sizeof(struct GNUNET_HashCode)) |
796 | { | 803 | { |
797 | GNUNET_break(0); | 804 | GNUNET_break (0); |
798 | return GNUNET_SYSERR; | 805 | return GNUNET_SYSERR; |
799 | } | 806 | } |
800 | return GNUNET_OK; | 807 | return GNUNET_OK; |
801 | } | 808 | } |
802 | 809 | ||
@@ -812,8 +819,8 @@ check_client_start_search(void *cls, | |||
812 | * @param sm the actual message | 819 | * @param sm the actual message |
813 | */ | 820 | */ |
814 | static void | 821 | static void |
815 | handle_client_start_search(void *cls, | 822 | handle_client_start_search (void *cls, |
816 | const struct SearchMessage *sm) | 823 | const struct SearchMessage *sm) |
817 | { | 824 | { |
818 | static struct GNUNET_PeerIdentity all_zeros; | 825 | static struct GNUNET_PeerIdentity all_zeros; |
819 | struct GSF_LocalClient *lc = cls; | 826 | struct GSF_LocalClient *lc = cls; |
@@ -824,90 +831,93 @@ handle_client_start_search(void *cls, | |||
824 | enum GNUNET_BLOCK_Type type; | 831 | enum GNUNET_BLOCK_Type type; |
825 | enum GSF_PendingRequestOptions options; | 832 | enum GSF_PendingRequestOptions options; |
826 | 833 | ||
827 | GNUNET_STATISTICS_update(GSF_stats, | 834 | GNUNET_STATISTICS_update (GSF_stats, |
828 | gettext_noop("# client searches received"), | 835 | gettext_noop ("# client searches received"), |
829 | 1, | 836 | 1, |
830 | GNUNET_NO); | 837 | GNUNET_NO); |
831 | msize = ntohs(sm->header.size) - sizeof(struct SearchMessage); | 838 | msize = ntohs (sm->header.size) - sizeof(struct SearchMessage); |
832 | sc = msize / sizeof(struct GNUNET_HashCode); | 839 | sc = msize / sizeof(struct GNUNET_HashCode); |
833 | type = ntohl(sm->type); | 840 | type = ntohl (sm->type); |
834 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 841 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
835 | "Received request for `%s' of type %u from local client\n", | 842 | "Received request for `%s' of type %u from local client\n", |
836 | GNUNET_h2s(&sm->query), | 843 | GNUNET_h2s (&sm->query), |
837 | (unsigned int)type); | 844 | (unsigned int) type); |
838 | cr = NULL; | 845 | cr = NULL; |
839 | /* detect duplicate UBLOCK requests */ | 846 | /* detect duplicate UBLOCK requests */ |
840 | if ((type == GNUNET_BLOCK_TYPE_FS_UBLOCK) || | 847 | if ((type == GNUNET_BLOCK_TYPE_FS_UBLOCK) || |
841 | (type == GNUNET_BLOCK_TYPE_ANY)) | 848 | (type == GNUNET_BLOCK_TYPE_ANY)) |
849 | { | ||
850 | cr = lc->cr_head; | ||
851 | while (NULL != cr) | ||
842 | { | 852 | { |
843 | cr = lc->cr_head; | 853 | prd = GSF_pending_request_get_data_ (cr->pr); |
844 | while (NULL != cr) | 854 | /* only unify with queries that hae not yet started local processing |
845 | { | 855 | (SEARCH_MESSAGE_OPTION_CONTINUED was always set) and that have a |
846 | prd = GSF_pending_request_get_data_(cr->pr); | 856 | matching query and type */ |
847 | /* only unify with queries that hae not yet started local processing | 857 | if ((GNUNET_YES != prd->has_started) && |
848 | (SEARCH_MESSAGE_OPTION_CONTINUED was always set) and that have a | 858 | (0 != memcmp (&prd->query, |
849 | matching query and type */ | 859 | &sm->query, |
850 | if ((GNUNET_YES != prd->has_started) && | 860 | sizeof(struct GNUNET_HashCode))) && |
851 | (0 != memcmp(&prd->query, | 861 | (prd->type == type)) |
852 | &sm->query, | 862 | break; |
853 | sizeof(struct GNUNET_HashCode))) && | 863 | cr = cr->next; |
854 | (prd->type == type)) | ||
855 | break; | ||
856 | cr = cr->next; | ||
857 | } | ||
858 | } | 864 | } |
865 | } | ||
859 | if (NULL != cr) | 866 | if (NULL != cr) |
860 | { | 867 | { |
861 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 868 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
862 | "Have existing request, merging content-seen lists.\n"); | 869 | "Have existing request, merging content-seen lists.\n"); |
863 | GSF_pending_request_update_(cr->pr, | 870 | GSF_pending_request_update_ (cr->pr, |
864 | (const struct GNUNET_HashCode *)&sm[1], | 871 | (const struct GNUNET_HashCode *) &sm[1], |
865 | sc); | 872 | sc); |
866 | GNUNET_STATISTICS_update(GSF_stats, | 873 | GNUNET_STATISTICS_update (GSF_stats, |
867 | gettext_noop("# client searches updated (merged content seen list)"), | 874 | gettext_noop ( |
868 | 1, | 875 | "# client searches updated (merged content seen list)"), |
869 | GNUNET_NO); | 876 | 1, |
870 | } | 877 | GNUNET_NO); |
878 | } | ||
871 | else | 879 | else |
872 | { | 880 | { |
873 | GNUNET_STATISTICS_update(GSF_stats, | 881 | GNUNET_STATISTICS_update (GSF_stats, |
874 | gettext_noop("# client searches active"), | 882 | gettext_noop ("# client searches active"), |
875 | 1, | 883 | 1, |
876 | GNUNET_NO); | 884 | GNUNET_NO); |
877 | cr = GNUNET_new(struct ClientRequest); | 885 | cr = GNUNET_new (struct ClientRequest); |
878 | cr->lc = lc; | 886 | cr->lc = lc; |
879 | GNUNET_CONTAINER_DLL_insert(lc->cr_head, | 887 | GNUNET_CONTAINER_DLL_insert (lc->cr_head, |
880 | lc->cr_tail, | 888 | lc->cr_tail, |
881 | cr); | 889 | cr); |
882 | options = GSF_PRO_LOCAL_REQUEST; | 890 | options = GSF_PRO_LOCAL_REQUEST; |
883 | if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl(sm->options))) | 891 | if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl (sm->options))) |
884 | options |= GSF_PRO_LOCAL_ONLY; | 892 | options |= GSF_PRO_LOCAL_ONLY; |
885 | cr->pr = GSF_pending_request_create_(options, type, | 893 | cr->pr = GSF_pending_request_create_ (options, type, |
886 | &sm->query, | 894 | &sm->query, |
887 | (0 != | 895 | (0 != |
888 | memcmp(&sm->target, | 896 | memcmp (&sm->target, |
889 | &all_zeros, | 897 | &all_zeros, |
890 | sizeof(struct GNUNET_PeerIdentity))) | 898 | sizeof(struct |
891 | ? &sm->target : NULL, NULL, 0, | 899 | GNUNET_PeerIdentity))) |
892 | 0 /* bf */, | 900 | ? &sm->target : NULL, NULL, 0, |
893 | ntohl(sm->anonymity_level), | 901 | 0 /* bf */, |
894 | 0 /* priority */, | 902 | ntohl (sm->anonymity_level), |
895 | 0 /* ttl */, | 903 | 0 /* priority */, |
896 | 0 /* sender PID */, | 904 | 0 /* ttl */, |
897 | 0 /* origin PID */, | 905 | 0 /* sender PID */, |
898 | (const struct GNUNET_HashCode *)&sm[1], sc, | 906 | 0 /* origin PID */, |
899 | &client_response_handler, | 907 | (const struct |
900 | cr); | 908 | GNUNET_HashCode *) &sm[1], sc, |
901 | } | 909 | &client_response_handler, |
902 | if (0 != (SEARCH_MESSAGE_OPTION_CONTINUED & ntohl(sm->options))) | 910 | cr); |
903 | { | 911 | } |
904 | GNUNET_SERVICE_client_continue(lc->client); | 912 | if (0 != (SEARCH_MESSAGE_OPTION_CONTINUED & ntohl (sm->options))) |
905 | return; | 913 | { |
906 | } | 914 | GNUNET_SERVICE_client_continue (lc->client); |
907 | GSF_pending_request_get_data_(cr->pr)->has_started = GNUNET_YES; | 915 | return; |
908 | GSF_local_lookup_(cr->pr, | 916 | } |
909 | &start_p2p_processing, | 917 | GSF_pending_request_get_data_ (cr->pr)->has_started = GNUNET_YES; |
910 | lc); | 918 | GSF_local_lookup_ (cr->pr, |
919 | &start_p2p_processing, | ||
920 | lc); | ||
911 | } | 921 | } |
912 | 922 | ||
913 | 923 | ||
@@ -918,8 +928,8 @@ handle_client_start_search(void *cls, | |||
918 | * @param msg the actual message | 928 | * @param msg the actual message |
919 | */ | 929 | */ |
920 | static void | 930 | static void |
921 | handle_client_loc_sign(void *cls, | 931 | handle_client_loc_sign (void *cls, |
922 | const struct RequestLocSignatureMessage *msg) | 932 | const struct RequestLocSignatureMessage *msg) |
923 | { | 933 | { |
924 | struct GSF_LocalClient *lc = cls; | 934 | struct GSF_LocalClient *lc = cls; |
925 | struct GNUNET_FS_Uri base; | 935 | struct GNUNET_FS_Uri base; |
@@ -927,24 +937,26 @@ handle_client_loc_sign(void *cls, | |||
927 | struct GNUNET_MQ_Envelope *env; | 937 | struct GNUNET_MQ_Envelope *env; |
928 | struct ResponseLocSignatureMessage *resp; | 938 | struct ResponseLocSignatureMessage *resp; |
929 | 939 | ||
930 | GNUNET_break(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT == | 940 | GNUNET_break (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT == |
931 | ntohl(msg->purpose)); | 941 | ntohl (msg->purpose)); |
932 | base.type = GNUNET_FS_URI_CHK; | 942 | base.type = GNUNET_FS_URI_CHK; |
933 | base.data.chk.chk = msg->chk; | 943 | base.data.chk.chk = msg->chk; |
934 | base.data.chk.file_length = GNUNET_ntohll(msg->file_length); | 944 | base.data.chk.file_length = GNUNET_ntohll (msg->file_length); |
935 | loc = GNUNET_FS_uri_loc_create(&base, | 945 | loc = GNUNET_FS_uri_loc_create (&base, |
936 | pk, | 946 | pk, |
937 | GNUNET_TIME_absolute_ntoh(msg->expiration_time)); | 947 | GNUNET_TIME_absolute_ntoh ( |
938 | env = GNUNET_MQ_msg(resp, | 948 | msg->expiration_time)); |
939 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE); | 949 | env = GNUNET_MQ_msg (resp, |
940 | resp->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 950 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE); |
941 | resp->expiration_time = GNUNET_TIME_absolute_hton(loc->data.loc.expirationTime); | 951 | resp->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
952 | resp->expiration_time = GNUNET_TIME_absolute_hton ( | ||
953 | loc->data.loc.expirationTime); | ||
942 | resp->signature = loc->data.loc.contentSignature; | 954 | resp->signature = loc->data.loc.contentSignature; |
943 | resp->peer = loc->data.loc.peer; | 955 | resp->peer = loc->data.loc.peer; |
944 | GNUNET_FS_uri_destroy(loc); | 956 | GNUNET_FS_uri_destroy (loc); |
945 | GNUNET_MQ_send(lc->mq, | 957 | GNUNET_MQ_send (lc->mq, |
946 | env); | 958 | env); |
947 | GNUNET_SERVICE_client_continue(lc->client); | 959 | GNUNET_SERVICE_client_continue (lc->client); |
948 | } | 960 | } |
949 | 961 | ||
950 | 962 | ||
@@ -956,24 +968,24 @@ handle_client_loc_sign(void *cls, | |||
956 | * @return #GNUNET_OK if @a ism is well-formed | 968 | * @return #GNUNET_OK if @a ism is well-formed |
957 | */ | 969 | */ |
958 | static int | 970 | static int |
959 | check_client_index_start(void *cls, | 971 | check_client_index_start (void *cls, |
960 | const struct IndexStartMessage *ism) | 972 | const struct IndexStartMessage *ism) |
961 | { | 973 | { |
962 | char *fn; | 974 | char *fn; |
963 | 975 | ||
964 | GNUNET_MQ_check_zero_termination(ism); | 976 | GNUNET_MQ_check_zero_termination (ism); |
965 | if (0 != ism->reserved) | 977 | if (0 != ism->reserved) |
966 | { | 978 | { |
967 | GNUNET_break(0); | 979 | GNUNET_break (0); |
968 | return GNUNET_SYSERR; | 980 | return GNUNET_SYSERR; |
969 | } | 981 | } |
970 | fn = GNUNET_STRINGS_filename_expand((const char *)&ism[1]); | 982 | fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]); |
971 | if (NULL == fn) | 983 | if (NULL == fn) |
972 | { | 984 | { |
973 | GNUNET_break(0); | 985 | GNUNET_break (0); |
974 | return GNUNET_SYSERR; | 986 | return GNUNET_SYSERR; |
975 | } | 987 | } |
976 | GNUNET_free(fn); | 988 | GNUNET_free (fn); |
977 | return GNUNET_OK; | 989 | return GNUNET_OK; |
978 | } | 990 | } |
979 | 991 | ||
@@ -985,21 +997,21 @@ check_client_index_start(void *cls, | |||
985 | * @param isc the data about the index info entry for the request | 997 | * @param isc the data about the index info entry for the request |
986 | */ | 998 | */ |
987 | static void | 999 | static void |
988 | signal_index_ok(struct IndexStartContext *isc) | 1000 | signal_index_ok (struct IndexStartContext *isc) |
989 | { | 1001 | { |
990 | struct GSF_LocalClient *lc = isc->lc; | 1002 | struct GSF_LocalClient *lc = isc->lc; |
991 | struct GNUNET_MQ_Envelope *env; | 1003 | struct GNUNET_MQ_Envelope *env; |
992 | struct GNUNET_MessageHeader *msg; | 1004 | struct GNUNET_MessageHeader *msg; |
993 | 1005 | ||
994 | GNUNET_FS_add_to_index(isc->filename, | 1006 | GNUNET_FS_add_to_index (isc->filename, |
995 | &isc->file_id); | 1007 | &isc->file_id); |
996 | env = GNUNET_MQ_msg(msg, | 1008 | env = GNUNET_MQ_msg (msg, |
997 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); | 1009 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); |
998 | GNUNET_MQ_send(lc->mq, | 1010 | GNUNET_MQ_send (lc->mq, |
999 | env); | 1011 | env); |
1000 | GNUNET_free(isc->filename); | 1012 | GNUNET_free (isc->filename); |
1001 | GNUNET_free(isc); | 1013 | GNUNET_free (isc); |
1002 | GNUNET_SERVICE_client_continue(lc->client); | 1014 | GNUNET_SERVICE_client_continue (lc->client); |
1003 | } | 1015 | } |
1004 | 1016 | ||
1005 | 1017 | ||
@@ -1011,36 +1023,37 @@ signal_index_ok(struct IndexStartContext *isc) | |||
1011 | * @param res resulting hash, NULL on error | 1023 | * @param res resulting hash, NULL on error |
1012 | */ | 1024 | */ |
1013 | static void | 1025 | static void |
1014 | hash_for_index_val(void *cls, | 1026 | hash_for_index_val (void *cls, |
1015 | const struct GNUNET_HashCode *res) | 1027 | const struct GNUNET_HashCode *res) |
1016 | { | 1028 | { |
1017 | struct IndexStartContext *isc = cls; | 1029 | struct IndexStartContext *isc = cls; |
1018 | struct GSF_LocalClient *lc = isc->lc; | 1030 | struct GSF_LocalClient *lc = isc->lc; |
1019 | struct GNUNET_MQ_Envelope *env; | 1031 | struct GNUNET_MQ_Envelope *env; |
1020 | struct GNUNET_MessageHeader *msg; | 1032 | struct GNUNET_MessageHeader *msg; |
1021 | 1033 | ||
1022 | GNUNET_CONTAINER_DLL_remove(lc->isc_head, | 1034 | GNUNET_CONTAINER_DLL_remove (lc->isc_head, |
1023 | lc->isc_tail, | 1035 | lc->isc_tail, |
1024 | isc); | 1036 | isc); |
1025 | isc->fhc = NULL; | 1037 | isc->fhc = NULL; |
1026 | if ((NULL == res) || | 1038 | if ((NULL == res) || |
1027 | (0 != memcmp(res, | 1039 | (0 != memcmp (res, |
1028 | &isc->file_id, | 1040 | &isc->file_id, |
1029 | sizeof(struct GNUNET_HashCode)))) | 1041 | sizeof(struct GNUNET_HashCode)))) |
1030 | { | 1042 | { |
1031 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1043 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1032 | _("Hash mismatch trying to index file `%s' which does not have hash `%s'\n"), | 1044 | _ ( |
1033 | isc->filename, | 1045 | "Hash mismatch trying to index file `%s' which does not have hash `%s'\n"), |
1034 | GNUNET_h2s(&isc->file_id)); | 1046 | isc->filename, |
1035 | env = GNUNET_MQ_msg(msg, | 1047 | GNUNET_h2s (&isc->file_id)); |
1036 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); | 1048 | env = GNUNET_MQ_msg (msg, |
1037 | GNUNET_MQ_send(lc->mq, | 1049 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); |
1038 | env); | 1050 | GNUNET_MQ_send (lc->mq, |
1039 | GNUNET_SERVICE_client_continue(lc->client); | 1051 | env); |
1040 | GNUNET_free(isc); | 1052 | GNUNET_SERVICE_client_continue (lc->client); |
1041 | return; | 1053 | GNUNET_free (isc); |
1042 | } | 1054 | return; |
1043 | signal_index_ok(isc); | 1055 | } |
1056 | signal_index_ok (isc); | ||
1044 | } | 1057 | } |
1045 | 1058 | ||
1046 | 1059 | ||
@@ -1051,8 +1064,8 @@ hash_for_index_val(void *cls, | |||
1051 | * @param message the actual message | 1064 | * @param message the actual message |
1052 | */ | 1065 | */ |
1053 | static void | 1066 | static void |
1054 | handle_client_index_start(void *cls, | 1067 | handle_client_index_start (void *cls, |
1055 | const struct IndexStartMessage *ism) | 1068 | const struct IndexStartMessage *ism) |
1056 | { | 1069 | { |
1057 | struct GSF_LocalClient *lc = cls; | 1070 | struct GSF_LocalClient *lc = cls; |
1058 | struct IndexStartContext *isc; | 1071 | struct IndexStartContext *isc; |
@@ -1062,49 +1075,49 @@ handle_client_index_start(void *cls, | |||
1062 | uint64_t mydev; | 1075 | uint64_t mydev; |
1063 | uint64_t myino; | 1076 | uint64_t myino; |
1064 | 1077 | ||
1065 | fn = GNUNET_STRINGS_filename_expand((const char *)&ism[1]); | 1078 | fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]); |
1066 | GNUNET_assert(NULL != fn); | 1079 | GNUNET_assert (NULL != fn); |
1067 | dev = GNUNET_ntohll(ism->device); | 1080 | dev = GNUNET_ntohll (ism->device); |
1068 | ino = GNUNET_ntohll(ism->inode); | 1081 | ino = GNUNET_ntohll (ism->inode); |
1069 | isc = GNUNET_new(struct IndexStartContext); | 1082 | isc = GNUNET_new (struct IndexStartContext); |
1070 | isc->filename = fn; | 1083 | isc->filename = fn; |
1071 | isc->file_id = ism->file_id; | 1084 | isc->file_id = ism->file_id; |
1072 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1085 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1073 | "Received START_INDEX message for file `%s'\n", | 1086 | "Received START_INDEX message for file `%s'\n", |
1074 | isc->filename); | 1087 | isc->filename); |
1075 | isc->lc = lc; | 1088 | isc->lc = lc; |
1076 | mydev = 0; | 1089 | mydev = 0; |
1077 | myino = 0; | 1090 | myino = 0; |
1078 | if (((dev != 0) || | 1091 | if (((dev != 0) || |
1079 | (ino != 0)) && | 1092 | (ino != 0)) && |
1080 | (GNUNET_OK == GNUNET_DISK_file_get_identifiers(fn, | 1093 | (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn, |
1081 | &mydev, | 1094 | &mydev, |
1082 | &myino)) && | 1095 | &myino)) && |
1083 | (dev == mydev) && | 1096 | (dev == mydev) && |
1084 | (ino == myino)) | 1097 | (ino == myino)) |
1085 | { | 1098 | { |
1086 | /* fast validation OK! */ | 1099 | /* fast validation OK! */ |
1087 | signal_index_ok(isc); | 1100 | signal_index_ok (isc); |
1088 | return; | 1101 | return; |
1089 | } | 1102 | } |
1090 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1091 | "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", | 1104 | "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", |
1092 | (unsigned long long)ino, | 1105 | (unsigned long long) ino, |
1093 | (unsigned long long)myino, | 1106 | (unsigned long long) myino, |
1094 | (unsigned int)dev, | 1107 | (unsigned int) dev, |
1095 | (unsigned int)mydev); | 1108 | (unsigned int) mydev); |
1096 | /* slow validation, need to hash full file (again) */ | 1109 | /* slow validation, need to hash full file (again) */ |
1097 | GNUNET_CONTAINER_DLL_insert(lc->isc_head, | 1110 | GNUNET_CONTAINER_DLL_insert (lc->isc_head, |
1098 | lc->isc_tail, | 1111 | lc->isc_tail, |
1099 | isc); | 1112 | isc); |
1100 | isc->fhc = GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, | 1113 | isc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1101 | isc->filename, | 1114 | isc->filename, |
1102 | HASHING_BLOCKSIZE, | 1115 | HASHING_BLOCKSIZE, |
1103 | &hash_for_index_val, | 1116 | &hash_for_index_val, |
1104 | isc); | 1117 | isc); |
1105 | if (NULL == isc->fhc) | 1118 | if (NULL == isc->fhc) |
1106 | hash_for_index_val(isc, | 1119 | hash_for_index_val (isc, |
1107 | NULL); | 1120 | NULL); |
1108 | } | 1121 | } |
1109 | 1122 | ||
1110 | 1123 | ||
@@ -1115,13 +1128,13 @@ handle_client_index_start(void *cls, | |||
1115 | * @param message the actual message | 1128 | * @param message the actual message |
1116 | */ | 1129 | */ |
1117 | static void | 1130 | static void |
1118 | handle_client_index_list_get(void *cls, | 1131 | handle_client_index_list_get (void *cls, |
1119 | const struct GNUNET_MessageHeader *message) | 1132 | const struct GNUNET_MessageHeader *message) |
1120 | { | 1133 | { |
1121 | struct GSF_LocalClient *lc = cls; | 1134 | struct GSF_LocalClient *lc = cls; |
1122 | 1135 | ||
1123 | GNUNET_FS_indexing_send_list(lc->mq); | 1136 | GNUNET_FS_indexing_send_list (lc->mq); |
1124 | GNUNET_SERVICE_client_continue(lc->client); | 1137 | GNUNET_SERVICE_client_continue (lc->client); |
1125 | } | 1138 | } |
1126 | 1139 | ||
1127 | 1140 | ||
@@ -1132,25 +1145,25 @@ handle_client_index_list_get(void *cls, | |||
1132 | * @param message the actual message | 1145 | * @param message the actual message |
1133 | */ | 1146 | */ |
1134 | static void | 1147 | static void |
1135 | handle_client_unindex(void *cls, | 1148 | handle_client_unindex (void *cls, |
1136 | const struct UnindexMessage *um) | 1149 | const struct UnindexMessage *um) |
1137 | { | 1150 | { |
1138 | struct GSF_LocalClient *lc = cls; | 1151 | struct GSF_LocalClient *lc = cls; |
1139 | struct GNUNET_MQ_Envelope *env; | 1152 | struct GNUNET_MQ_Envelope *env; |
1140 | struct GNUNET_MessageHeader *msg; | 1153 | struct GNUNET_MessageHeader *msg; |
1141 | int found; | 1154 | int found; |
1142 | 1155 | ||
1143 | GNUNET_break(0 == um->reserved); | 1156 | GNUNET_break (0 == um->reserved); |
1144 | found = GNUNET_FS_indexing_do_unindex(&um->file_id); | 1157 | found = GNUNET_FS_indexing_do_unindex (&um->file_id); |
1145 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1146 | "Client requested unindexing of file `%s': %s\n", | 1159 | "Client requested unindexing of file `%s': %s\n", |
1147 | GNUNET_h2s(&um->file_id), | 1160 | GNUNET_h2s (&um->file_id), |
1148 | found ? "found" : "not found"); | 1161 | found ? "found" : "not found"); |
1149 | env = GNUNET_MQ_msg(msg, | 1162 | env = GNUNET_MQ_msg (msg, |
1150 | GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); | 1163 | GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); |
1151 | GNUNET_MQ_send(lc->mq, | 1164 | GNUNET_MQ_send (lc->mq, |
1152 | env); | 1165 | env); |
1153 | GNUNET_SERVICE_client_continue(lc->client); | 1166 | GNUNET_SERVICE_client_continue (lc->client); |
1154 | } | 1167 | } |
1155 | 1168 | ||
1156 | 1169 | ||
@@ -1160,44 +1173,44 @@ handle_client_unindex(void *cls, | |||
1160 | * @param cls unused | 1173 | * @param cls unused |
1161 | */ | 1174 | */ |
1162 | static void | 1175 | static void |
1163 | shutdown_task(void *cls) | 1176 | shutdown_task (void *cls) |
1164 | { | 1177 | { |
1165 | GSF_cadet_stop_server(); | 1178 | GSF_cadet_stop_server (); |
1166 | if (NULL != GSF_core) | 1179 | if (NULL != GSF_core) |
1167 | { | 1180 | { |
1168 | GNUNET_CORE_disconnect(GSF_core); | 1181 | GNUNET_CORE_disconnect (GSF_core); |
1169 | GSF_core = NULL; | 1182 | GSF_core = NULL; |
1170 | } | 1183 | } |
1171 | if (NULL != GSF_ats) | 1184 | if (NULL != GSF_ats) |
1172 | { | 1185 | { |
1173 | GNUNET_ATS_performance_done(GSF_ats); | 1186 | GNUNET_ATS_performance_done (GSF_ats); |
1174 | GSF_ats = NULL; | 1187 | GSF_ats = NULL; |
1175 | } | 1188 | } |
1176 | GSF_put_done_(); | 1189 | GSF_put_done_ (); |
1177 | GSF_push_done_(); | 1190 | GSF_push_done_ (); |
1178 | GSF_pending_request_done_(); | 1191 | GSF_pending_request_done_ (); |
1179 | GSF_plan_done(); | 1192 | GSF_plan_done (); |
1180 | GSF_connected_peer_done_(); | 1193 | GSF_connected_peer_done_ (); |
1181 | GNUNET_DATASTORE_disconnect(GSF_dsh, | 1194 | GNUNET_DATASTORE_disconnect (GSF_dsh, |
1182 | GNUNET_NO); | 1195 | GNUNET_NO); |
1183 | GSF_dsh = NULL; | 1196 | GSF_dsh = NULL; |
1184 | GNUNET_DHT_disconnect(GSF_dht); | 1197 | GNUNET_DHT_disconnect (GSF_dht); |
1185 | GSF_dht = NULL; | 1198 | GSF_dht = NULL; |
1186 | GNUNET_BLOCK_context_destroy(GSF_block_ctx); | 1199 | GNUNET_BLOCK_context_destroy (GSF_block_ctx); |
1187 | GSF_block_ctx = NULL; | 1200 | GSF_block_ctx = NULL; |
1188 | GNUNET_CONFIGURATION_destroy(block_cfg); | 1201 | GNUNET_CONFIGURATION_destroy (block_cfg); |
1189 | block_cfg = NULL; | 1202 | block_cfg = NULL; |
1190 | GNUNET_STATISTICS_destroy(GSF_stats, GNUNET_NO); | 1203 | GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO); |
1191 | GSF_stats = NULL; | 1204 | GSF_stats = NULL; |
1192 | if (NULL != cover_age_task) | 1205 | if (NULL != cover_age_task) |
1193 | { | 1206 | { |
1194 | GNUNET_SCHEDULER_cancel(cover_age_task); | 1207 | GNUNET_SCHEDULER_cancel (cover_age_task); |
1195 | cover_age_task = NULL; | 1208 | cover_age_task = NULL; |
1196 | } | 1209 | } |
1197 | GNUNET_FS_indexing_done(); | 1210 | GNUNET_FS_indexing_done (); |
1198 | GNUNET_LOAD_value_free(datastore_get_load); | 1211 | GNUNET_LOAD_value_free (datastore_get_load); |
1199 | datastore_get_load = NULL; | 1212 | datastore_get_load = NULL; |
1200 | GNUNET_LOAD_value_free(GSF_rt_entry_lifetime); | 1213 | GNUNET_LOAD_value_free (GSF_rt_entry_lifetime); |
1201 | GSF_rt_entry_lifetime = NULL; | 1214 | GSF_rt_entry_lifetime = NULL; |
1202 | } | 1215 | } |
1203 | 1216 | ||
@@ -1213,16 +1226,16 @@ shutdown_task(void *cls) | |||
1213 | * @param my_identity ID of this peer, NULL if we failed | 1226 | * @param my_identity ID of this peer, NULL if we failed |
1214 | */ | 1227 | */ |
1215 | static void | 1228 | static void |
1216 | peer_init_handler(void *cls, | 1229 | peer_init_handler (void *cls, |
1217 | const struct GNUNET_PeerIdentity *my_identity) | 1230 | const struct GNUNET_PeerIdentity *my_identity) |
1218 | { | 1231 | { |
1219 | if (0 != GNUNET_memcmp(&GSF_my_id, | 1232 | if (0 != GNUNET_memcmp (&GSF_my_id, |
1220 | my_identity)) | 1233 | my_identity)) |
1221 | { | 1234 | { |
1222 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1235 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1223 | "Peer identity mismatch, refusing to start!\n"); | 1236 | "Peer identity mismatch, refusing to start!\n"); |
1224 | GNUNET_SCHEDULER_shutdown(); | 1237 | GNUNET_SCHEDULER_shutdown (); |
1225 | } | 1238 | } |
1226 | } | 1239 | } |
1227 | 1240 | ||
1228 | 1241 | ||
@@ -1232,25 +1245,25 @@ peer_init_handler(void *cls, | |||
1232 | * @param c configuration to use | 1245 | * @param c configuration to use |
1233 | */ | 1246 | */ |
1234 | static int | 1247 | static int |
1235 | main_init(const struct GNUNET_CONFIGURATION_Handle *c) | 1248 | main_init (const struct GNUNET_CONFIGURATION_Handle *c) |
1236 | { | 1249 | { |
1237 | struct GNUNET_MQ_MessageHandler no_p2p_handlers[] = { | 1250 | struct GNUNET_MQ_MessageHandler no_p2p_handlers[] = { |
1238 | GNUNET_MQ_handler_end() | 1251 | GNUNET_MQ_handler_end () |
1239 | }; | 1252 | }; |
1240 | struct GNUNET_MQ_MessageHandler p2p_handlers[] = { | 1253 | struct GNUNET_MQ_MessageHandler p2p_handlers[] = { |
1241 | GNUNET_MQ_hd_var_size(p2p_get, | 1254 | GNUNET_MQ_hd_var_size (p2p_get, |
1242 | GNUNET_MESSAGE_TYPE_FS_GET, | 1255 | GNUNET_MESSAGE_TYPE_FS_GET, |
1243 | struct GetMessage, | 1256 | struct GetMessage, |
1244 | NULL), | 1257 | NULL), |
1245 | GNUNET_MQ_hd_var_size(p2p_put, | 1258 | GNUNET_MQ_hd_var_size (p2p_put, |
1246 | GNUNET_MESSAGE_TYPE_FS_PUT, | 1259 | GNUNET_MESSAGE_TYPE_FS_PUT, |
1247 | struct PutMessage, | 1260 | struct PutMessage, |
1248 | NULL), | 1261 | NULL), |
1249 | GNUNET_MQ_hd_fixed_size(p2p_migration_stop, | 1262 | GNUNET_MQ_hd_fixed_size (p2p_migration_stop, |
1250 | GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP, | 1263 | GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP, |
1251 | struct MigrationStopMessage, | 1264 | struct MigrationStopMessage, |
1252 | NULL), | 1265 | NULL), |
1253 | GNUNET_MQ_handler_end() | 1266 | GNUNET_MQ_handler_end () |
1254 | }; | 1267 | }; |
1255 | int anon_p2p_off; | 1268 | int anon_p2p_off; |
1256 | char *keyfile; | 1269 | char *keyfile; |
@@ -1258,54 +1271,55 @@ main_init(const struct GNUNET_CONFIGURATION_Handle *c) | |||
1258 | /* this option is really only for testcases that need to disable | 1271 | /* this option is really only for testcases that need to disable |
1259 | _anonymous_ file-sharing for some reason */ | 1272 | _anonymous_ file-sharing for some reason */ |
1260 | anon_p2p_off = (GNUNET_YES == | 1273 | anon_p2p_off = (GNUNET_YES == |
1261 | GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg, | 1274 | GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, |
1262 | "fs", | 1275 | "fs", |
1263 | "DISABLE_ANON_TRANSFER")); | 1276 | "DISABLE_ANON_TRANSFER")); |
1264 | 1277 | ||
1265 | if (GNUNET_OK != | 1278 | if (GNUNET_OK != |
1266 | GNUNET_CONFIGURATION_get_value_filename(GSF_cfg, | 1279 | GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, |
1267 | "PEER", | 1280 | "PEER", |
1268 | "PRIVATE_KEY", | 1281 | "PRIVATE_KEY", |
1269 | &keyfile)) | 1282 | &keyfile)) |
1270 | { | 1283 | { |
1271 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1284 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1272 | _("FS service is lacking HOSTKEY configuration setting. Exiting.\n")); | 1285 | _ ( |
1273 | GNUNET_SCHEDULER_shutdown(); | 1286 | "FS service is lacking HOSTKEY configuration setting. Exiting.\n")); |
1274 | return GNUNET_SYSERR; | 1287 | GNUNET_SCHEDULER_shutdown (); |
1275 | } | 1288 | return GNUNET_SYSERR; |
1276 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); | 1289 | } |
1277 | GNUNET_free(keyfile); | 1290 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); |
1278 | GNUNET_assert(NULL != pk); | 1291 | GNUNET_free (keyfile); |
1279 | GNUNET_CRYPTO_eddsa_key_get_public(pk, | 1292 | GNUNET_assert (NULL != pk); |
1280 | &GSF_my_id.public_key); | 1293 | GNUNET_CRYPTO_eddsa_key_get_public (pk, |
1281 | 1294 | &GSF_my_id.public_key); | |
1282 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1295 | |
1283 | "I am peer %s\n", | 1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1284 | GNUNET_i2s(&GSF_my_id)); | 1297 | "I am peer %s\n", |
1298 | GNUNET_i2s (&GSF_my_id)); | ||
1285 | GSF_core | 1299 | GSF_core |
1286 | = GNUNET_CORE_connect(GSF_cfg, | 1300 | = GNUNET_CORE_connect (GSF_cfg, |
1287 | NULL, | 1301 | NULL, |
1288 | &peer_init_handler, | 1302 | &peer_init_handler, |
1289 | &GSF_peer_connect_handler, | 1303 | &GSF_peer_connect_handler, |
1290 | &GSF_peer_disconnect_handler, | 1304 | &GSF_peer_disconnect_handler, |
1291 | (GNUNET_YES == anon_p2p_off) | 1305 | (GNUNET_YES == anon_p2p_off) |
1292 | ? no_p2p_handlers | 1306 | ? no_p2p_handlers |
1293 | : p2p_handlers); | 1307 | : p2p_handlers); |
1294 | if (NULL == GSF_core) | 1308 | if (NULL == GSF_core) |
1295 | { | 1309 | { |
1296 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1310 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1297 | _("Failed to connect to `%s' service.\n"), | 1311 | _ ("Failed to connect to `%s' service.\n"), |
1298 | "core"); | 1312 | "core"); |
1299 | return GNUNET_SYSERR; | 1313 | return GNUNET_SYSERR; |
1300 | } | 1314 | } |
1301 | cover_age_task = | 1315 | cover_age_task = |
1302 | GNUNET_SCHEDULER_add_delayed(COVER_AGE_FREQUENCY, | 1316 | GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, |
1303 | &age_cover_counters, | 1317 | &age_cover_counters, |
1318 | NULL); | ||
1319 | datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); | ||
1320 | GSF_cadet_start_server (); | ||
1321 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
1304 | NULL); | 1322 | NULL); |
1305 | datastore_get_load = GNUNET_LOAD_value_init(DATASTORE_LOAD_AUTODECLINE); | ||
1306 | GSF_cadet_start_server(); | ||
1307 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, | ||
1308 | NULL); | ||
1309 | return GNUNET_OK; | 1323 | return GNUNET_OK; |
1310 | } | 1324 | } |
1311 | 1325 | ||
@@ -1318,55 +1332,55 @@ main_init(const struct GNUNET_CONFIGURATION_Handle *c) | |||
1318 | * @param service the initialized service | 1332 | * @param service the initialized service |
1319 | */ | 1333 | */ |
1320 | static void | 1334 | static void |
1321 | run(void *cls, | 1335 | run (void *cls, |
1322 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1336 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1323 | struct GNUNET_SERVICE_Handle *service) | 1337 | struct GNUNET_SERVICE_Handle *service) |
1324 | { | 1338 | { |
1325 | unsigned long long dqs; | 1339 | unsigned long long dqs; |
1326 | 1340 | ||
1327 | GSF_cfg = cfg; | 1341 | GSF_cfg = cfg; |
1328 | if (GNUNET_OK != | 1342 | if (GNUNET_OK != |
1329 | GNUNET_CONFIGURATION_get_value_size(GSF_cfg, | 1343 | GNUNET_CONFIGURATION_get_value_size (GSF_cfg, |
1330 | "fs", | 1344 | "fs", |
1331 | "DATASTORE_QUEUE_SIZE", | 1345 | "DATASTORE_QUEUE_SIZE", |
1332 | &dqs)) | 1346 | &dqs)) |
1333 | { | 1347 | { |
1334 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_INFO, | 1348 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO, |
1335 | "fs", | 1349 | "fs", |
1336 | "DATASTORE_QUEUE_SIZE"); | 1350 | "DATASTORE_QUEUE_SIZE"); |
1337 | dqs = 32; | 1351 | dqs = 32; |
1338 | } | 1352 | } |
1339 | GSF_datastore_queue_size = (unsigned int)dqs; | 1353 | GSF_datastore_queue_size = (unsigned int) dqs; |
1340 | GSF_enable_randomized_delays = | 1354 | GSF_enable_randomized_delays = |
1341 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "fs", "DELAY"); | 1355 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY"); |
1342 | GSF_dsh = GNUNET_DATASTORE_connect(cfg); | 1356 | GSF_dsh = GNUNET_DATASTORE_connect (cfg); |
1343 | if (NULL == GSF_dsh) | 1357 | if (NULL == GSF_dsh) |
1344 | { | 1358 | { |
1345 | GNUNET_SCHEDULER_shutdown(); | 1359 | GNUNET_SCHEDULER_shutdown (); |
1346 | return; | 1360 | return; |
1347 | } | 1361 | } |
1348 | GSF_rt_entry_lifetime = GNUNET_LOAD_value_init(GNUNET_TIME_UNIT_FOREVER_REL); | 1362 | GSF_rt_entry_lifetime = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_FOREVER_REL); |
1349 | GSF_stats = GNUNET_STATISTICS_create("fs", cfg); | 1363 | GSF_stats = GNUNET_STATISTICS_create ("fs", cfg); |
1350 | block_cfg = GNUNET_CONFIGURATION_create(); | 1364 | block_cfg = GNUNET_CONFIGURATION_create (); |
1351 | GSF_block_ctx = GNUNET_BLOCK_context_create(block_cfg); | 1365 | GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg); |
1352 | GNUNET_assert(NULL != GSF_block_ctx); | 1366 | GNUNET_assert (NULL != GSF_block_ctx); |
1353 | GSF_dht = GNUNET_DHT_connect(cfg, FS_DHT_HT_SIZE); | 1367 | GSF_dht = GNUNET_DHT_connect (cfg, FS_DHT_HT_SIZE); |
1354 | GSF_plan_init(); | 1368 | GSF_plan_init (); |
1355 | GSF_pending_request_init_(); | 1369 | GSF_pending_request_init_ (); |
1356 | GSF_connected_peer_init_(); | 1370 | GSF_connected_peer_init_ (); |
1357 | GSF_ats = GNUNET_ATS_performance_init(GSF_cfg, | 1371 | GSF_ats = GNUNET_ATS_performance_init (GSF_cfg, |
1358 | &update_latencies, | 1372 | &update_latencies, |
1359 | NULL); | 1373 | NULL); |
1360 | GSF_push_init_(); | 1374 | GSF_push_init_ (); |
1361 | GSF_put_init_(); | 1375 | GSF_put_init_ (); |
1362 | if ((GNUNET_OK != GNUNET_FS_indexing_init(cfg, | 1376 | if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, |
1363 | GSF_dsh)) || | 1377 | GSF_dsh)) || |
1364 | (GNUNET_OK != main_init(cfg))) | 1378 | (GNUNET_OK != main_init (cfg))) |
1365 | { | 1379 | { |
1366 | GNUNET_SCHEDULER_shutdown(); | 1380 | GNUNET_SCHEDULER_shutdown (); |
1367 | shutdown_task(NULL); | 1381 | shutdown_task (NULL); |
1368 | return; | 1382 | return; |
1369 | } | 1383 | } |
1370 | } | 1384 | } |
1371 | 1385 | ||
1372 | 1386 | ||
@@ -1380,27 +1394,27 @@ GNUNET_SERVICE_MAIN | |||
1380 | &client_connect_cb, | 1394 | &client_connect_cb, |
1381 | &client_disconnect_cb, | 1395 | &client_disconnect_cb, |
1382 | NULL, | 1396 | NULL, |
1383 | GNUNET_MQ_hd_var_size(client_index_start, | 1397 | GNUNET_MQ_hd_var_size (client_index_start, |
1384 | GNUNET_MESSAGE_TYPE_FS_INDEX_START, | 1398 | GNUNET_MESSAGE_TYPE_FS_INDEX_START, |
1385 | struct IndexStartMessage, | 1399 | struct IndexStartMessage, |
1386 | NULL), | 1400 | NULL), |
1387 | GNUNET_MQ_hd_fixed_size(client_index_list_get, | 1401 | GNUNET_MQ_hd_fixed_size (client_index_list_get, |
1388 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, | 1402 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, |
1389 | struct GNUNET_MessageHeader, | 1403 | struct GNUNET_MessageHeader, |
1390 | NULL), | 1404 | NULL), |
1391 | GNUNET_MQ_hd_fixed_size(client_unindex, | 1405 | GNUNET_MQ_hd_fixed_size (client_unindex, |
1392 | GNUNET_MESSAGE_TYPE_FS_UNINDEX, | 1406 | GNUNET_MESSAGE_TYPE_FS_UNINDEX, |
1393 | struct UnindexMessage, | 1407 | struct UnindexMessage, |
1394 | NULL), | 1408 | NULL), |
1395 | GNUNET_MQ_hd_var_size(client_start_search, | 1409 | GNUNET_MQ_hd_var_size (client_start_search, |
1396 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH, | 1410 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH, |
1397 | struct SearchMessage, | 1411 | struct SearchMessage, |
1398 | NULL), | 1412 | NULL), |
1399 | GNUNET_MQ_hd_fixed_size(client_loc_sign, | 1413 | GNUNET_MQ_hd_fixed_size (client_loc_sign, |
1400 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN, | 1414 | GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN, |
1401 | struct RequestLocSignatureMessage, | 1415 | struct RequestLocSignatureMessage, |
1402 | NULL), | 1416 | NULL), |
1403 | GNUNET_MQ_handler_end()); | 1417 | GNUNET_MQ_handler_end ()); |
1404 | 1418 | ||
1405 | 1419 | ||
1406 | /* end of gnunet-service-fs.c */ | 1420 | /* end of gnunet-service-fs.c */ |
diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h index 21a822c6d..9c87115ed 100644 --- a/src/fs/gnunet-service-fs.h +++ b/src/fs/gnunet-service-fs.h | |||
@@ -48,7 +48,8 @@ | |||
48 | * automatically (since if we don't use it, clearly the | 48 | * automatically (since if we don't use it, clearly the |
49 | * load must be going down). | 49 | * load must be going down). |
50 | */ | 50 | */ |
51 | #define DATASTORE_LOAD_AUTODECLINE GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) | 51 | #define DATASTORE_LOAD_AUTODECLINE GNUNET_TIME_relative_multiply ( \ |
52 | GNUNET_TIME_UNIT_MILLISECONDS, 250) | ||
52 | 53 | ||
53 | /** | 54 | /** |
54 | * Only the (mandatory) query is included. | 55 | * Only the (mandatory) query is included. |
@@ -79,7 +80,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
79 | /** | 80 | /** |
80 | * Message sent between peers asking for FS-content. | 81 | * Message sent between peers asking for FS-content. |
81 | */ | 82 | */ |
82 | struct GetMessage { | 83 | struct GetMessage |
84 | { | ||
83 | /** | 85 | /** |
84 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_GET. | 86 | * Message type will be #GNUNET_MESSAGE_TYPE_FS_GET. |
85 | */ | 87 | */ |
@@ -134,7 +136,8 @@ struct GetMessage { | |||
134 | * Message send by a peer that wants to be excluded | 136 | * Message send by a peer that wants to be excluded |
135 | * from migration for a while. | 137 | * from migration for a while. |
136 | */ | 138 | */ |
137 | struct MigrationStopMessage { | 139 | struct MigrationStopMessage |
140 | { | ||
138 | /** | 141 | /** |
139 | * Message type will be | 142 | * Message type will be |
140 | * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP. | 143 | * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP. |
@@ -275,9 +278,9 @@ extern unsigned int GSF_datastore_queue_size; | |||
275 | * @param result final datastore lookup result | 278 | * @param result final datastore lookup result |
276 | */ | 279 | */ |
277 | void | 280 | void |
278 | GSF_consider_forwarding(void *cls, | 281 | GSF_consider_forwarding (void *cls, |
279 | struct GSF_PendingRequest *pr, | 282 | struct GSF_PendingRequest *pr, |
280 | enum GNUNET_BLOCK_EvaluationResult result); | 283 | enum GNUNET_BLOCK_EvaluationResult result); |
281 | 284 | ||
282 | 285 | ||
283 | /** | 286 | /** |
@@ -290,7 +293,7 @@ GSF_consider_forwarding(void *cls, | |||
290 | * #GNUNET_SYSERR to process for free (load low) | 293 | * #GNUNET_SYSERR to process for free (load low) |
291 | */ | 294 | */ |
292 | int | 295 | int |
293 | GSF_test_get_load_too_high_(uint32_t priority); | 296 | GSF_test_get_load_too_high_ (uint32_t priority); |
294 | 297 | ||
295 | 298 | ||
296 | /** | 299 | /** |
@@ -300,7 +303,7 @@ GSF_test_get_load_too_high_(uint32_t priority); | |||
300 | * @param start time when the datastore request was issued | 303 | * @param start time when the datastore request was issued |
301 | */ | 304 | */ |
302 | void | 305 | void |
303 | GSF_update_datastore_delay_(struct GNUNET_TIME_Absolute start); | 306 | GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start); |
304 | 307 | ||
305 | 308 | ||
306 | #endif | 309 | #endif |
diff --git a/src/fs/gnunet-service-fs_cadet.h b/src/fs/gnunet-service-fs_cadet.h index 61bd8b314..b8c255047 100644 --- a/src/fs/gnunet-service-fs_cadet.h +++ b/src/fs/gnunet-service-fs_cadet.h | |||
@@ -60,11 +60,11 @@ typedef void | |||
60 | * @return handle to cancel the operation | 60 | * @return handle to cancel the operation |
61 | */ | 61 | */ |
62 | struct GSF_CadetRequest * | 62 | struct GSF_CadetRequest * |
63 | GSF_cadet_query(const struct GNUNET_PeerIdentity *target, | 63 | GSF_cadet_query (const struct GNUNET_PeerIdentity *target, |
64 | const struct GNUNET_HashCode *query, | 64 | const struct GNUNET_HashCode *query, |
65 | enum GNUNET_BLOCK_Type type, | 65 | enum GNUNET_BLOCK_Type type, |
66 | GSF_CadetReplyProcessor proc, | 66 | GSF_CadetReplyProcessor proc, |
67 | void *proc_cls); | 67 | void *proc_cls); |
68 | 68 | ||
69 | /** | 69 | /** |
70 | * Function called on each active cadets to shut them down. | 70 | * Function called on each active cadets to shut them down. |
@@ -75,9 +75,9 @@ GSF_cadet_query(const struct GNUNET_PeerIdentity *target, | |||
75 | * @return #GNUNET_YES (continue to iterate) | 75 | * @return #GNUNET_YES (continue to iterate) |
76 | */ | 76 | */ |
77 | int | 77 | int |
78 | GSF_cadet_release_clients(void *cls, | 78 | GSF_cadet_release_clients (void *cls, |
79 | const struct GNUNET_PeerIdentity *key, | 79 | const struct GNUNET_PeerIdentity *key, |
80 | void *value); | 80 | void *value); |
81 | 81 | ||
82 | 82 | ||
83 | /** | 83 | /** |
@@ -87,21 +87,21 @@ GSF_cadet_release_clients(void *cls, | |||
87 | * @param sr request to cancel | 87 | * @param sr request to cancel |
88 | */ | 88 | */ |
89 | void | 89 | void |
90 | GSF_cadet_query_cancel(struct GSF_CadetRequest *sr); | 90 | GSF_cadet_query_cancel (struct GSF_CadetRequest *sr); |
91 | 91 | ||
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Initialize subsystem for non-anonymous file-sharing. | 94 | * Initialize subsystem for non-anonymous file-sharing. |
95 | */ | 95 | */ |
96 | void | 96 | void |
97 | GSF_cadet_start_server(void); | 97 | GSF_cadet_start_server (void); |
98 | 98 | ||
99 | 99 | ||
100 | /** | 100 | /** |
101 | * Shutdown subsystem for non-anonymous file-sharing. | 101 | * Shutdown subsystem for non-anonymous file-sharing. |
102 | */ | 102 | */ |
103 | void | 103 | void |
104 | GSF_cadet_stop_server(void); | 104 | GSF_cadet_stop_server (void); |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * Cadet channel for creating outbound channels. | 107 | * Cadet channel for creating outbound channels. |
@@ -120,7 +120,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
120 | /** | 120 | /** |
121 | * Query from one peer, asking the other for CHK-data. | 121 | * Query from one peer, asking the other for CHK-data. |
122 | */ | 122 | */ |
123 | struct CadetQueryMessage { | 123 | struct CadetQueryMessage |
124 | { | ||
124 | /** | 125 | /** |
125 | * Type is GNUNET_MESSAGE_TYPE_FS_CADET_QUERY. | 126 | * Type is GNUNET_MESSAGE_TYPE_FS_CADET_QUERY. |
126 | */ | 127 | */ |
@@ -141,7 +142,8 @@ struct CadetQueryMessage { | |||
141 | /** | 142 | /** |
142 | * Reply to a CadetQueryMessage. | 143 | * Reply to a CadetQueryMessage. |
143 | */ | 144 | */ |
144 | struct CadetReplyMessage { | 145 | struct CadetReplyMessage |
146 | { | ||
145 | /** | 147 | /** |
146 | * Type is GNUNET_MESSAGE_TYPE_FS_CADET_REPLY. | 148 | * Type is GNUNET_MESSAGE_TYPE_FS_CADET_REPLY. |
147 | */ | 149 | */ |
diff --git a/src/fs/gnunet-service-fs_cadet_client.c b/src/fs/gnunet-service-fs_cadet_client.c index a494ba751..96ccf8232 100644 --- a/src/fs/gnunet-service-fs_cadet_client.c +++ b/src/fs/gnunet-service-fs_cadet_client.c | |||
@@ -42,7 +42,7 @@ | |||
42 | * After how long do we reset connections without replies? | 42 | * After how long do we reset connections without replies? |
43 | */ | 43 | */ |
44 | #define CLIENT_RETRY_TIMEOUT \ | 44 | #define CLIENT_RETRY_TIMEOUT \ |
45 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) | 45 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
46 | 46 | ||
47 | 47 | ||
48 | /** | 48 | /** |
@@ -54,7 +54,8 @@ struct CadetHandle; | |||
54 | /** | 54 | /** |
55 | * Handle for a request that is going out via cadet API. | 55 | * Handle for a request that is going out via cadet API. |
56 | */ | 56 | */ |
57 | struct GSF_CadetRequest { | 57 | struct GSF_CadetRequest |
58 | { | ||
58 | /** | 59 | /** |
59 | * DLL. | 60 | * DLL. |
60 | */ | 61 | */ |
@@ -101,7 +102,8 @@ struct GSF_CadetRequest { | |||
101 | /** | 102 | /** |
102 | * Handle for a cadet to another peer. | 103 | * Handle for a cadet to another peer. |
103 | */ | 104 | */ |
104 | struct CadetHandle { | 105 | struct CadetHandle |
106 | { | ||
105 | /** | 107 | /** |
106 | * Head of DLL of pending requests on this cadet. | 108 | * Head of DLL of pending requests on this cadet. |
107 | */ | 109 | */ |
@@ -165,7 +167,7 @@ struct GNUNET_CONTAINER_MultiPeerMap *cadet_map; | |||
165 | * @param cls `struct CadetHandle` to process | 167 | * @param cls `struct CadetHandle` to process |
166 | */ | 168 | */ |
167 | static void | 169 | static void |
168 | transmit_pending(void *cls); | 170 | transmit_pending (void *cls); |
169 | 171 | ||
170 | 172 | ||
171 | /** | 173 | /** |
@@ -178,15 +180,15 @@ transmit_pending(void *cls); | |||
178 | * @return #GNUNET_YES (continue to iterate) | 180 | * @return #GNUNET_YES (continue to iterate) |
179 | */ | 181 | */ |
180 | static int | 182 | static int |
181 | move_to_pending(void *cls, const struct GNUNET_HashCode *key, void *value) | 183 | move_to_pending (void *cls, const struct GNUNET_HashCode *key, void *value) |
182 | { | 184 | { |
183 | struct CadetHandle *mh = cls; | 185 | struct CadetHandle *mh = cls; |
184 | struct GSF_CadetRequest *sr = value; | 186 | struct GSF_CadetRequest *sr = value; |
185 | 187 | ||
186 | GNUNET_assert( | 188 | GNUNET_assert ( |
187 | GNUNET_YES == | 189 | GNUNET_YES == |
188 | GNUNET_CONTAINER_multihashmap_remove(mh->waiting_map, key, value)); | 190 | GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, key, value)); |
189 | GNUNET_CONTAINER_DLL_insert(mh->pending_head, mh->pending_tail, sr); | 191 | GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr); |
190 | sr->was_transmitted = GNUNET_NO; | 192 | sr->was_transmitted = GNUNET_NO; |
191 | return GNUNET_YES; | 193 | return GNUNET_YES; |
192 | } | 194 | } |
@@ -201,7 +203,7 @@ move_to_pending(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
201 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | 203 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing |
202 | */ | 204 | */ |
203 | static int | 205 | static int |
204 | check_reply(void *cls, const struct CadetReplyMessage *srm) | 206 | check_reply (void *cls, const struct CadetReplyMessage *srm) |
205 | { | 207 | { |
206 | /* We check later... */ | 208 | /* We check later... */ |
207 | return GNUNET_OK; | 209 | return GNUNET_OK; |
@@ -214,7 +216,7 @@ check_reply(void *cls, const struct CadetReplyMessage *srm) | |||
214 | * @param cls the `struct CadetHandle` to tear down | 216 | * @param cls the `struct CadetHandle` to tear down |
215 | */ | 217 | */ |
216 | static void | 218 | static void |
217 | reset_cadet_task(void *cls); | 219 | reset_cadet_task (void *cls); |
218 | 220 | ||
219 | 221 | ||
220 | /** | 222 | /** |
@@ -224,18 +226,19 @@ reset_cadet_task(void *cls); | |||
224 | * @param mh cadet to reset | 226 | * @param mh cadet to reset |
225 | */ | 227 | */ |
226 | static void | 228 | static void |
227 | reset_cadet_async(struct CadetHandle *mh) | 229 | reset_cadet_async (struct CadetHandle *mh) |
228 | { | 230 | { |
229 | if (NULL != mh->reset_task) | 231 | if (NULL != mh->reset_task) |
230 | GNUNET_SCHEDULER_cancel(mh->reset_task); | 232 | GNUNET_SCHEDULER_cancel (mh->reset_task); |
231 | mh->reset_task = GNUNET_SCHEDULER_add_now(&reset_cadet_task, mh); | 233 | mh->reset_task = GNUNET_SCHEDULER_add_now (&reset_cadet_task, mh); |
232 | } | 234 | } |
233 | 235 | ||
234 | 236 | ||
235 | /** | 237 | /** |
236 | * Closure for handle_reply(). | 238 | * Closure for handle_reply(). |
237 | */ | 239 | */ |
238 | struct HandleReplyClosure { | 240 | struct HandleReplyClosure |
241 | { | ||
239 | /** | 242 | /** |
240 | * Reply payload. | 243 | * Reply payload. |
241 | */ | 244 | */ |
@@ -273,18 +276,18 @@ struct HandleReplyClosure { | |||
273 | * @return #GNUNET_YES (continue to iterate) | 276 | * @return #GNUNET_YES (continue to iterate) |
274 | */ | 277 | */ |
275 | static int | 278 | static int |
276 | process_reply(void *cls, const struct GNUNET_HashCode *key, void *value) | 279 | process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) |
277 | { | 280 | { |
278 | struct HandleReplyClosure *hrc = cls; | 281 | struct HandleReplyClosure *hrc = cls; |
279 | struct GSF_CadetRequest *sr = value; | 282 | struct GSF_CadetRequest *sr = value; |
280 | 283 | ||
281 | sr->proc(sr->proc_cls, | 284 | sr->proc (sr->proc_cls, |
282 | hrc->type, | 285 | hrc->type, |
283 | hrc->expiration, | 286 | hrc->expiration, |
284 | hrc->data_size, | 287 | hrc->data_size, |
285 | hrc->data); | 288 | hrc->data); |
286 | sr->proc = NULL; | 289 | sr->proc = NULL; |
287 | GSF_cadet_query_cancel(sr); | 290 | GSF_cadet_query_cancel (sr); |
288 | hrc->found = GNUNET_YES; | 291 | hrc->found = GNUNET_YES; |
289 | return GNUNET_YES; | 292 | return GNUNET_YES; |
290 | } | 293 | } |
@@ -301,11 +304,11 @@ process_reply(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
301 | * @return #GNUNET_YES (continue to iterate) | 304 | * @return #GNUNET_YES (continue to iterate) |
302 | */ | 305 | */ |
303 | static int | 306 | static int |
304 | free_waiting_entry(void *cls, const struct GNUNET_HashCode *key, void *value) | 307 | free_waiting_entry (void *cls, const struct GNUNET_HashCode *key, void *value) |
305 | { | 308 | { |
306 | struct GSF_CadetRequest *sr = value; | 309 | struct GSF_CadetRequest *sr = value; |
307 | 310 | ||
308 | GSF_cadet_query_cancel(sr); | 311 | GSF_cadet_query_cancel (sr); |
309 | return GNUNET_YES; | 312 | return GNUNET_YES; |
310 | } | 313 | } |
311 | 314 | ||
@@ -318,7 +321,7 @@ free_waiting_entry(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
318 | * @param srm the actual message | 321 | * @param srm the actual message |
319 | */ | 322 | */ |
320 | static void | 323 | static void |
321 | handle_reply(void *cls, const struct CadetReplyMessage *srm) | 324 | handle_reply (void *cls, const struct CadetReplyMessage *srm) |
322 | { | 325 | { |
323 | struct CadetHandle *mh = cls; | 326 | struct CadetHandle *mh = cls; |
324 | struct HandleReplyClosure hrc; | 327 | struct HandleReplyClosure hrc; |
@@ -326,47 +329,47 @@ handle_reply(void *cls, const struct CadetReplyMessage *srm) | |||
326 | enum GNUNET_BLOCK_Type type; | 329 | enum GNUNET_BLOCK_Type type; |
327 | struct GNUNET_HashCode query; | 330 | struct GNUNET_HashCode query; |
328 | 331 | ||
329 | msize = ntohs(srm->header.size) - sizeof(struct CadetReplyMessage); | 332 | msize = ntohs (srm->header.size) - sizeof(struct CadetReplyMessage); |
330 | type = (enum GNUNET_BLOCK_Type)ntohl(srm->type); | 333 | type = (enum GNUNET_BLOCK_Type) ntohl (srm->type); |
331 | if (GNUNET_YES != | 334 | if (GNUNET_YES != |
332 | GNUNET_BLOCK_get_key(GSF_block_ctx, type, &srm[1], msize, &query)) | 335 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, &srm[1], msize, &query)) |
333 | { | 336 | { |
334 | GNUNET_break_op(0); | 337 | GNUNET_break_op (0); |
335 | GNUNET_log( | 338 | GNUNET_log ( |
336 | GNUNET_ERROR_TYPE_WARNING, | 339 | GNUNET_ERROR_TYPE_WARNING, |
337 | "Received bogus reply of type %u with %u bytes via cadet from peer %s\n", | 340 | "Received bogus reply of type %u with %u bytes via cadet from peer %s\n", |
338 | type, | 341 | type, |
339 | msize, | 342 | msize, |
340 | GNUNET_i2s(&mh->target)); | 343 | GNUNET_i2s (&mh->target)); |
341 | reset_cadet_async(mh); | 344 | reset_cadet_async (mh); |
342 | return; | 345 | return; |
343 | } | 346 | } |
344 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
345 | "Received reply `%s' via cadet from peer %s\n", | 348 | "Received reply `%s' via cadet from peer %s\n", |
346 | GNUNET_h2s(&query), | 349 | GNUNET_h2s (&query), |
347 | GNUNET_i2s(&mh->target)); | 350 | GNUNET_i2s (&mh->target)); |
348 | GNUNET_CADET_receive_done(mh->channel); | 351 | GNUNET_CADET_receive_done (mh->channel); |
349 | GNUNET_STATISTICS_update(GSF_stats, | 352 | GNUNET_STATISTICS_update (GSF_stats, |
350 | gettext_noop("# replies received via cadet"), | 353 | gettext_noop ("# replies received via cadet"), |
351 | 1, | 354 | 1, |
352 | GNUNET_NO); | 355 | GNUNET_NO); |
353 | hrc.data = &srm[1]; | 356 | hrc.data = &srm[1]; |
354 | hrc.data_size = msize; | 357 | hrc.data_size = msize; |
355 | hrc.expiration = GNUNET_TIME_absolute_ntoh(srm->expiration); | 358 | hrc.expiration = GNUNET_TIME_absolute_ntoh (srm->expiration); |
356 | hrc.type = type; | 359 | hrc.type = type; |
357 | hrc.found = GNUNET_NO; | 360 | hrc.found = GNUNET_NO; |
358 | GNUNET_CONTAINER_multihashmap_get_multiple(mh->waiting_map, | 361 | GNUNET_CONTAINER_multihashmap_get_multiple (mh->waiting_map, |
359 | &query, | 362 | &query, |
360 | &process_reply, | 363 | &process_reply, |
361 | &hrc); | 364 | &hrc); |
362 | if (GNUNET_NO == hrc.found) | 365 | if (GNUNET_NO == hrc.found) |
363 | { | 366 | { |
364 | GNUNET_STATISTICS_update(GSF_stats, | 367 | GNUNET_STATISTICS_update (GSF_stats, |
365 | gettext_noop( | 368 | gettext_noop ( |
366 | "# replies received via cadet dropped"), | 369 | "# replies received via cadet dropped"), |
367 | 1, | 370 | 1, |
368 | GNUNET_NO); | 371 | GNUNET_NO); |
369 | } | 372 | } |
370 | } | 373 | } |
371 | 374 | ||
372 | 375 | ||
@@ -378,34 +381,34 @@ handle_reply(void *cls, const struct CadetReplyMessage *srm) | |||
378 | * @param channel channel of the disconnecting client | 381 | * @param channel channel of the disconnecting client |
379 | */ | 382 | */ |
380 | static void | 383 | static void |
381 | disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel) | 384 | disconnect_cb (void *cls, const struct GNUNET_CADET_Channel *channel) |
382 | { | 385 | { |
383 | struct CadetHandle *mh = cls; | 386 | struct CadetHandle *mh = cls; |
384 | struct GSF_CadetRequest *sr; | 387 | struct GSF_CadetRequest *sr; |
385 | 388 | ||
386 | if (NULL == mh->channel) | 389 | if (NULL == mh->channel) |
387 | return; /* being destroyed elsewhere */ | 390 | return; /* being destroyed elsewhere */ |
388 | GNUNET_assert(channel == mh->channel); | 391 | GNUNET_assert (channel == mh->channel); |
389 | mh->channel = NULL; | 392 | mh->channel = NULL; |
390 | while (NULL != (sr = mh->pending_head)) | 393 | while (NULL != (sr = mh->pending_head)) |
391 | GSF_cadet_query_cancel(sr); | 394 | GSF_cadet_query_cancel (sr); |
392 | /* first remove `mh` from the `cadet_map`, so that if the | 395 | /* first remove `mh` from the `cadet_map`, so that if the |
393 | callback from `free_waiting_entry()` happens to re-issue | 396 | callback from `free_waiting_entry()` happens to re-issue |
394 | the request, we don't immediately have it back in the | 397 | the request, we don't immediately have it back in the |
395 | `waiting_map`. */ | 398 | `waiting_map`. */ |
396 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove(cadet_map, | 399 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (cadet_map, |
397 | &mh->target, | 400 | &mh->target, |
398 | mh)); | 401 | mh)); |
399 | GNUNET_CONTAINER_multihashmap_iterate(mh->waiting_map, | 402 | GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, |
400 | &free_waiting_entry, | 403 | &free_waiting_entry, |
401 | mh); | 404 | mh); |
402 | if (NULL != mh->timeout_task) | 405 | if (NULL != mh->timeout_task) |
403 | GNUNET_SCHEDULER_cancel(mh->timeout_task); | 406 | GNUNET_SCHEDULER_cancel (mh->timeout_task); |
404 | if (NULL != mh->reset_task) | 407 | if (NULL != mh->reset_task) |
405 | GNUNET_SCHEDULER_cancel(mh->reset_task); | 408 | GNUNET_SCHEDULER_cancel (mh->reset_task); |
406 | GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(mh->waiting_map)); | 409 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)); |
407 | GNUNET_CONTAINER_multihashmap_destroy(mh->waiting_map); | 410 | GNUNET_CONTAINER_multihashmap_destroy (mh->waiting_map); |
408 | GNUNET_free(mh); | 411 | GNUNET_free (mh); |
409 | } | 412 | } |
410 | 413 | ||
411 | 414 | ||
@@ -424,16 +427,16 @@ disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel) | |||
424 | * this value will be negative.. | 427 | * this value will be negative.. |
425 | */ | 428 | */ |
426 | static void | 429 | static void |
427 | window_change_cb(void *cls, | 430 | window_change_cb (void *cls, |
428 | const struct GNUNET_CADET_Channel *channel, | 431 | const struct GNUNET_CADET_Channel *channel, |
429 | int window_size) | 432 | int window_size) |
430 | { | 433 | { |
431 | /* FIXME: for flow control, implement? */ | 434 | /* FIXME: for flow control, implement? */ |
432 | #if 0 | 435 | #if 0 |
433 | /* Something like this instead of the GNUNET_MQ_notify_sent() in | 436 | /* Something like this instead of the GNUNET_MQ_notify_sent() in |
434 | transmit_pending() might be good (once the window change CB works...) */ | 437 | transmit_pending() might be good (once the window change CB works...) */ |
435 | if (0 < window_size) /* test needed? */ | 438 | if (0 < window_size) /* test needed? */ |
436 | transmit_pending(mh); | 439 | transmit_pending (mh); |
437 | #endif | 440 | #endif |
438 | } | 441 | } |
439 | 442 | ||
@@ -444,38 +447,38 @@ window_change_cb(void *cls, | |||
444 | * @param mh cadet to reset | 447 | * @param mh cadet to reset |
445 | */ | 448 | */ |
446 | static void | 449 | static void |
447 | reset_cadet(struct CadetHandle *mh) | 450 | reset_cadet (struct CadetHandle *mh) |
448 | { | 451 | { |
449 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
450 | "Resetting cadet channel to %s\n", | 453 | "Resetting cadet channel to %s\n", |
451 | GNUNET_i2s(&mh->target)); | 454 | GNUNET_i2s (&mh->target)); |
452 | if (NULL != mh->channel) | 455 | if (NULL != mh->channel) |
453 | { | 456 | { |
454 | GNUNET_CADET_channel_destroy(mh->channel); | 457 | GNUNET_CADET_channel_destroy (mh->channel); |
455 | mh->channel = NULL; | 458 | mh->channel = NULL; |
456 | } | 459 | } |
457 | GNUNET_CONTAINER_multihashmap_iterate(mh->waiting_map, &move_to_pending, mh); | 460 | GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, &move_to_pending, mh); |
458 | { | 461 | { |
459 | struct GNUNET_MQ_MessageHandler handlers[] = | 462 | struct GNUNET_MQ_MessageHandler handlers[] = |
460 | { GNUNET_MQ_hd_var_size(reply, | 463 | { GNUNET_MQ_hd_var_size (reply, |
461 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, | 464 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, |
462 | struct CadetReplyMessage, | 465 | struct CadetReplyMessage, |
463 | mh), | 466 | mh), |
464 | GNUNET_MQ_handler_end() }; | 467 | GNUNET_MQ_handler_end () }; |
465 | struct GNUNET_HashCode port; | 468 | struct GNUNET_HashCode port; |
466 | 469 | ||
467 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, | 470 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, |
468 | strlen(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), | 471 | strlen (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), |
469 | &port); | 472 | &port); |
470 | mh->channel = GNUNET_CADET_channel_create(cadet_handle, | 473 | mh->channel = GNUNET_CADET_channel_create (cadet_handle, |
471 | mh, | 474 | mh, |
472 | &mh->target, | 475 | &mh->target, |
473 | &port, | 476 | &port, |
474 | &window_change_cb, | 477 | &window_change_cb, |
475 | &disconnect_cb, | 478 | &disconnect_cb, |
476 | handlers); | 479 | handlers); |
477 | } | 480 | } |
478 | transmit_pending(mh); | 481 | transmit_pending (mh); |
479 | } | 482 | } |
480 | 483 | ||
481 | 484 | ||
@@ -485,19 +488,19 @@ reset_cadet(struct CadetHandle *mh) | |||
485 | * @param cls the `struct CadetHandle` to tear down | 488 | * @param cls the `struct CadetHandle` to tear down |
486 | */ | 489 | */ |
487 | static void | 490 | static void |
488 | cadet_timeout(void *cls) | 491 | cadet_timeout (void *cls) |
489 | { | 492 | { |
490 | struct CadetHandle *mh = cls; | 493 | struct CadetHandle *mh = cls; |
491 | struct GNUNET_CADET_Channel *tun; | 494 | struct GNUNET_CADET_Channel *tun; |
492 | 495 | ||
493 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
494 | "Timeout on cadet channel to %s\n", | 497 | "Timeout on cadet channel to %s\n", |
495 | GNUNET_i2s(&mh->target)); | 498 | GNUNET_i2s (&mh->target)); |
496 | mh->timeout_task = NULL; | 499 | mh->timeout_task = NULL; |
497 | tun = mh->channel; | 500 | tun = mh->channel; |
498 | mh->channel = NULL; | 501 | mh->channel = NULL; |
499 | if (NULL != tun) | 502 | if (NULL != tun) |
500 | GNUNET_CADET_channel_destroy(tun); | 503 | GNUNET_CADET_channel_destroy (tun); |
501 | } | 504 | } |
502 | 505 | ||
503 | 506 | ||
@@ -507,12 +510,12 @@ cadet_timeout(void *cls) | |||
507 | * @param cls the `struct CadetHandle` to tear down | 510 | * @param cls the `struct CadetHandle` to tear down |
508 | */ | 511 | */ |
509 | static void | 512 | static void |
510 | reset_cadet_task(void *cls) | 513 | reset_cadet_task (void *cls) |
511 | { | 514 | { |
512 | struct CadetHandle *mh = cls; | 515 | struct CadetHandle *mh = cls; |
513 | 516 | ||
514 | mh->reset_task = NULL; | 517 | mh->reset_task = NULL; |
515 | reset_cadet(mh); | 518 | reset_cadet (mh); |
516 | } | 519 | } |
517 | 520 | ||
518 | 521 | ||
@@ -522,36 +525,36 @@ reset_cadet_task(void *cls) | |||
522 | * @param cls `struct CadetHandle` to process | 525 | * @param cls `struct CadetHandle` to process |
523 | */ | 526 | */ |
524 | static void | 527 | static void |
525 | transmit_pending(void *cls) | 528 | transmit_pending (void *cls) |
526 | { | 529 | { |
527 | struct CadetHandle *mh = cls; | 530 | struct CadetHandle *mh = cls; |
528 | struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq(mh->channel); | 531 | struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq (mh->channel); |
529 | struct GSF_CadetRequest *sr; | 532 | struct GSF_CadetRequest *sr; |
530 | struct GNUNET_MQ_Envelope *env; | 533 | struct GNUNET_MQ_Envelope *env; |
531 | struct CadetQueryMessage *sqm; | 534 | struct CadetQueryMessage *sqm; |
532 | 535 | ||
533 | if ((0 != GNUNET_MQ_get_length(mq)) || (NULL == (sr = mh->pending_head))) | 536 | if ((0 != GNUNET_MQ_get_length (mq)) || (NULL == (sr = mh->pending_head))) |
534 | return; | 537 | return; |
535 | GNUNET_CONTAINER_DLL_remove(mh->pending_head, mh->pending_tail, sr); | 538 | GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr); |
536 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( | 539 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( |
537 | mh->waiting_map, | 540 | mh->waiting_map, |
538 | &sr->query, | 541 | &sr->query, |
539 | sr, | 542 | sr, |
540 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 543 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
541 | sr->was_transmitted = GNUNET_YES; | 544 | sr->was_transmitted = GNUNET_YES; |
542 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
543 | "Sending query for %s via cadet to %s\n", | 546 | "Sending query for %s via cadet to %s\n", |
544 | GNUNET_h2s(&sr->query), | 547 | GNUNET_h2s (&sr->query), |
545 | GNUNET_i2s(&mh->target)); | 548 | GNUNET_i2s (&mh->target)); |
546 | env = GNUNET_MQ_msg(sqm, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY); | 549 | env = GNUNET_MQ_msg (sqm, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY); |
547 | GNUNET_MQ_env_set_options(env, | 550 | GNUNET_MQ_env_set_options (env, |
548 | GNUNET_MQ_PREF_GOODPUT | | 551 | GNUNET_MQ_PREF_GOODPUT |
549 | GNUNET_MQ_PREF_CORK_ALLOWED | | 552 | | GNUNET_MQ_PREF_CORK_ALLOWED |
550 | GNUNET_MQ_PREF_OUT_OF_ORDER); | 553 | | GNUNET_MQ_PREF_OUT_OF_ORDER); |
551 | sqm->type = htonl(sr->type); | 554 | sqm->type = htonl (sr->type); |
552 | sqm->query = sr->query; | 555 | sqm->query = sr->query; |
553 | GNUNET_MQ_notify_sent(env, &transmit_pending, mh); | 556 | GNUNET_MQ_notify_sent (env, &transmit_pending, mh); |
554 | GNUNET_MQ_send(mq, env); | 557 | GNUNET_MQ_send (mq, env); |
555 | } | 558 | } |
556 | 559 | ||
557 | 560 | ||
@@ -561,53 +564,53 @@ transmit_pending(void *cls) | |||
561 | * @param target peer we want to communicate with | 564 | * @param target peer we want to communicate with |
562 | */ | 565 | */ |
563 | static struct CadetHandle * | 566 | static struct CadetHandle * |
564 | get_cadet(const struct GNUNET_PeerIdentity *target) | 567 | get_cadet (const struct GNUNET_PeerIdentity *target) |
565 | { | 568 | { |
566 | struct CadetHandle *mh; | 569 | struct CadetHandle *mh; |
567 | 570 | ||
568 | mh = GNUNET_CONTAINER_multipeermap_get(cadet_map, target); | 571 | mh = GNUNET_CONTAINER_multipeermap_get (cadet_map, target); |
569 | if (NULL != mh) | 572 | if (NULL != mh) |
573 | { | ||
574 | if (NULL != mh->timeout_task) | ||
570 | { | 575 | { |
571 | if (NULL != mh->timeout_task) | 576 | GNUNET_SCHEDULER_cancel (mh->timeout_task); |
572 | { | 577 | mh->timeout_task = NULL; |
573 | GNUNET_SCHEDULER_cancel(mh->timeout_task); | ||
574 | mh->timeout_task = NULL; | ||
575 | } | ||
576 | return mh; | ||
577 | } | 578 | } |
578 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 579 | return mh; |
579 | "Creating cadet channel to %s\n", | 580 | } |
580 | GNUNET_i2s(target)); | 581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
581 | mh = GNUNET_new(struct CadetHandle); | 582 | "Creating cadet channel to %s\n", |
583 | GNUNET_i2s (target)); | ||
584 | mh = GNUNET_new (struct CadetHandle); | ||
582 | mh->reset_task = | 585 | mh->reset_task = |
583 | GNUNET_SCHEDULER_add_delayed(CLIENT_RETRY_TIMEOUT, &reset_cadet_task, mh); | 586 | GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT, &reset_cadet_task, mh); |
584 | mh->waiting_map = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_YES); | 587 | mh->waiting_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); |
585 | mh->target = *target; | 588 | mh->target = *target; |
586 | GNUNET_assert(GNUNET_OK == | 589 | GNUNET_assert (GNUNET_OK == |
587 | GNUNET_CONTAINER_multipeermap_put( | 590 | GNUNET_CONTAINER_multipeermap_put ( |
588 | cadet_map, | 591 | cadet_map, |
589 | &mh->target, | 592 | &mh->target, |
590 | mh, | 593 | mh, |
591 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 594 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
592 | { | 595 | { |
593 | struct GNUNET_MQ_MessageHandler handlers[] = | 596 | struct GNUNET_MQ_MessageHandler handlers[] = |
594 | { GNUNET_MQ_hd_var_size(reply, | 597 | { GNUNET_MQ_hd_var_size (reply, |
595 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, | 598 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, |
596 | struct CadetReplyMessage, | 599 | struct CadetReplyMessage, |
597 | mh), | 600 | mh), |
598 | GNUNET_MQ_handler_end() }; | 601 | GNUNET_MQ_handler_end () }; |
599 | struct GNUNET_HashCode port; | 602 | struct GNUNET_HashCode port; |
600 | 603 | ||
601 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, | 604 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, |
602 | strlen(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), | 605 | strlen (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), |
603 | &port); | 606 | &port); |
604 | mh->channel = GNUNET_CADET_channel_create(cadet_handle, | 607 | mh->channel = GNUNET_CADET_channel_create (cadet_handle, |
605 | mh, | 608 | mh, |
606 | &mh->target, | 609 | &mh->target, |
607 | &port, | 610 | &port, |
608 | &window_change_cb, | 611 | &window_change_cb, |
609 | &disconnect_cb, | 612 | &disconnect_cb, |
610 | handlers); | 613 | handlers); |
611 | } | 614 | } |
612 | return mh; | 615 | return mh; |
613 | } | 616 | } |
@@ -624,28 +627,28 @@ get_cadet(const struct GNUNET_PeerIdentity *target) | |||
624 | * @return handle to cancel the operation | 627 | * @return handle to cancel the operation |
625 | */ | 628 | */ |
626 | struct GSF_CadetRequest * | 629 | struct GSF_CadetRequest * |
627 | GSF_cadet_query(const struct GNUNET_PeerIdentity *target, | 630 | GSF_cadet_query (const struct GNUNET_PeerIdentity *target, |
628 | const struct GNUNET_HashCode *query, | 631 | const struct GNUNET_HashCode *query, |
629 | enum GNUNET_BLOCK_Type type, | 632 | enum GNUNET_BLOCK_Type type, |
630 | GSF_CadetReplyProcessor proc, | 633 | GSF_CadetReplyProcessor proc, |
631 | void *proc_cls) | 634 | void *proc_cls) |
632 | { | 635 | { |
633 | struct CadetHandle *mh; | 636 | struct CadetHandle *mh; |
634 | struct GSF_CadetRequest *sr; | 637 | struct GSF_CadetRequest *sr; |
635 | 638 | ||
636 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 639 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
637 | "Preparing to send query for %s via cadet to %s\n", | 640 | "Preparing to send query for %s via cadet to %s\n", |
638 | GNUNET_h2s(query), | 641 | GNUNET_h2s (query), |
639 | GNUNET_i2s(target)); | 642 | GNUNET_i2s (target)); |
640 | mh = get_cadet(target); | 643 | mh = get_cadet (target); |
641 | sr = GNUNET_new(struct GSF_CadetRequest); | 644 | sr = GNUNET_new (struct GSF_CadetRequest); |
642 | sr->mh = mh; | 645 | sr->mh = mh; |
643 | sr->proc = proc; | 646 | sr->proc = proc; |
644 | sr->proc_cls = proc_cls; | 647 | sr->proc_cls = proc_cls; |
645 | sr->type = type; | 648 | sr->type = type; |
646 | sr->query = *query; | 649 | sr->query = *query; |
647 | GNUNET_CONTAINER_DLL_insert(mh->pending_head, mh->pending_tail, sr); | 650 | GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr); |
648 | transmit_pending(mh); | 651 | transmit_pending (mh); |
649 | return sr; | 652 | return sr; |
650 | } | 653 | } |
651 | 654 | ||
@@ -657,7 +660,7 @@ GSF_cadet_query(const struct GNUNET_PeerIdentity *target, | |||
657 | * @param sr request to cancel | 660 | * @param sr request to cancel |
658 | */ | 661 | */ |
659 | void | 662 | void |
660 | GSF_cadet_query_cancel(struct GSF_CadetRequest *sr) | 663 | GSF_cadet_query_cancel (struct GSF_CadetRequest *sr) |
661 | { | 664 | { |
662 | struct CadetHandle *mh = sr->mh; | 665 | struct CadetHandle *mh = sr->mh; |
663 | GSF_CadetReplyProcessor p; | 666 | GSF_CadetReplyProcessor p; |
@@ -665,26 +668,26 @@ GSF_cadet_query_cancel(struct GSF_CadetRequest *sr) | |||
665 | p = sr->proc; | 668 | p = sr->proc; |
666 | sr->proc = NULL; | 669 | sr->proc = NULL; |
667 | if (NULL != p) | 670 | if (NULL != p) |
668 | { | 671 | { |
669 | /* signal failure / cancellation to callback */ | 672 | /* signal failure / cancellation to callback */ |
670 | p(sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, GNUNET_TIME_UNIT_ZERO_ABS, 0, NULL); | 673 | p (sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, GNUNET_TIME_UNIT_ZERO_ABS, 0, NULL); |
671 | } | 674 | } |
672 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
673 | "Cancelled query for %s via cadet to %s\n", | 676 | "Cancelled query for %s via cadet to %s\n", |
674 | GNUNET_h2s(&sr->query), | 677 | GNUNET_h2s (&sr->query), |
675 | GNUNET_i2s(&sr->mh->target)); | 678 | GNUNET_i2s (&sr->mh->target)); |
676 | if (GNUNET_YES == sr->was_transmitted) | 679 | if (GNUNET_YES == sr->was_transmitted) |
677 | GNUNET_assert( | 680 | GNUNET_assert ( |
678 | GNUNET_OK == | 681 | GNUNET_OK == |
679 | GNUNET_CONTAINER_multihashmap_remove(mh->waiting_map, &sr->query, sr)); | 682 | GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, &sr->query, sr)); |
680 | else | 683 | else |
681 | GNUNET_CONTAINER_DLL_remove(mh->pending_head, mh->pending_tail, sr); | 684 | GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr); |
682 | GNUNET_free(sr); | 685 | GNUNET_free (sr); |
683 | if ((0 == GNUNET_CONTAINER_multihashmap_size(mh->waiting_map)) && | 686 | if ((0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)) && |
684 | (NULL == mh->pending_head)) | 687 | (NULL == mh->pending_head)) |
685 | mh->timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | 688 | mh->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
686 | &cadet_timeout, | 689 | &cadet_timeout, |
687 | mh); | 690 | mh); |
688 | } | 691 | } |
689 | 692 | ||
690 | 693 | ||
@@ -697,27 +700,27 @@ GSF_cadet_query_cancel(struct GSF_CadetRequest *sr) | |||
697 | * @return #GNUNET_YES (continue to iterate) | 700 | * @return #GNUNET_YES (continue to iterate) |
698 | */ | 701 | */ |
699 | int | 702 | int |
700 | GSF_cadet_release_clients(void *cls, | 703 | GSF_cadet_release_clients (void *cls, |
701 | const struct GNUNET_PeerIdentity *key, | 704 | const struct GNUNET_PeerIdentity *key, |
702 | void *value) | 705 | void *value) |
703 | { | 706 | { |
704 | struct CadetHandle *mh = value; | 707 | struct CadetHandle *mh = value; |
705 | 708 | ||
706 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 709 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
707 | "Timeout on cadet channel to %s\n", | 710 | "Timeout on cadet channel to %s\n", |
708 | GNUNET_i2s(&mh->target)); | 711 | GNUNET_i2s (&mh->target)); |
709 | if (NULL != mh->channel) | 712 | if (NULL != mh->channel) |
710 | { | 713 | { |
711 | struct GNUNET_CADET_Channel *channel = mh->channel; | 714 | struct GNUNET_CADET_Channel *channel = mh->channel; |
712 | 715 | ||
713 | mh->channel = NULL; | 716 | mh->channel = NULL; |
714 | GNUNET_CADET_channel_destroy(channel); | 717 | GNUNET_CADET_channel_destroy (channel); |
715 | } | 718 | } |
716 | if (NULL != mh->reset_task) | 719 | if (NULL != mh->reset_task) |
717 | { | 720 | { |
718 | GNUNET_SCHEDULER_cancel(mh->reset_task); | 721 | GNUNET_SCHEDULER_cancel (mh->reset_task); |
719 | mh->reset_task = NULL; | 722 | mh->reset_task = NULL; |
720 | } | 723 | } |
721 | return GNUNET_YES; | 724 | return GNUNET_YES; |
722 | } | 725 | } |
723 | 726 | ||
diff --git a/src/fs/gnunet-service-fs_cadet_server.c b/src/fs/gnunet-service-fs_cadet_server.c index 68e87f092..34e4e6f58 100644 --- a/src/fs/gnunet-service-fs_cadet_server.c +++ b/src/fs/gnunet-service-fs_cadet_server.c | |||
@@ -40,13 +40,14 @@ | |||
40 | /** | 40 | /** |
41 | * After how long do we termiante idle connections? | 41 | * After how long do we termiante idle connections? |
42 | */ | 42 | */ |
43 | #define IDLE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) | 43 | #define IDLE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) |
44 | 44 | ||
45 | 45 | ||
46 | /** | 46 | /** |
47 | * A message in the queue to be written to the cadet. | 47 | * A message in the queue to be written to the cadet. |
48 | */ | 48 | */ |
49 | struct WriteQueueItem { | 49 | struct WriteQueueItem |
50 | { | ||
50 | /** | 51 | /** |
51 | * Kept in a DLL. | 52 | * Kept in a DLL. |
52 | */ | 53 | */ |
@@ -67,7 +68,8 @@ struct WriteQueueItem { | |||
67 | /** | 68 | /** |
68 | * Information we keep around for each active cadeting client. | 69 | * Information we keep around for each active cadeting client. |
69 | */ | 70 | */ |
70 | struct CadetClient { | 71 | struct CadetClient |
72 | { | ||
71 | /** | 73 | /** |
72 | * DLL | 74 | * DLL |
73 | */ | 75 | */ |
@@ -101,12 +103,12 @@ struct CadetClient { | |||
101 | /** | 103 | /** |
102 | * Task that is scheduled to asynchronously terminate the connection. | 104 | * Task that is scheduled to asynchronously terminate the connection. |
103 | */ | 105 | */ |
104 | struct GNUNET_SCHEDULER_Task * terminate_task; | 106 | struct GNUNET_SCHEDULER_Task *terminate_task; |
105 | 107 | ||
106 | /** | 108 | /** |
107 | * Task that is scheduled to terminate idle connections. | 109 | * Task that is scheduled to terminate idle connections. |
108 | */ | 110 | */ |
109 | struct GNUNET_SCHEDULER_Task * timeout_task; | 111 | struct GNUNET_SCHEDULER_Task *timeout_task; |
110 | 112 | ||
111 | /** | 113 | /** |
112 | * Size of the last write that was initiated. | 114 | * Size of the last write that was initiated. |
@@ -148,7 +150,7 @@ static unsigned long long sc_count_max; | |||
148 | * @param cls the 'struct CadetClient' | 150 | * @param cls the 'struct CadetClient' |
149 | */ | 151 | */ |
150 | static void | 152 | static void |
151 | timeout_cadet_task(void *cls) | 153 | timeout_cadet_task (void *cls) |
152 | { | 154 | { |
153 | struct CadetClient *sc = cls; | 155 | struct CadetClient *sc = cls; |
154 | struct GNUNET_CADET_Channel *tun; | 156 | struct GNUNET_CADET_Channel *tun; |
@@ -156,10 +158,10 @@ timeout_cadet_task(void *cls) | |||
156 | sc->timeout_task = NULL; | 158 | sc->timeout_task = NULL; |
157 | tun = sc->channel; | 159 | tun = sc->channel; |
158 | sc->channel = NULL; | 160 | sc->channel = NULL; |
159 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
160 | "Timeout for inactive cadet client %p\n", | 162 | "Timeout for inactive cadet client %p\n", |
161 | sc); | 163 | sc); |
162 | GNUNET_CADET_channel_destroy(tun); | 164 | GNUNET_CADET_channel_destroy (tun); |
163 | } | 165 | } |
164 | 166 | ||
165 | 167 | ||
@@ -169,13 +171,13 @@ timeout_cadet_task(void *cls) | |||
169 | * @param sc client handle to reset timeout for | 171 | * @param sc client handle to reset timeout for |
170 | */ | 172 | */ |
171 | static void | 173 | static void |
172 | refresh_timeout_task(struct CadetClient *sc) | 174 | refresh_timeout_task (struct CadetClient *sc) |
173 | { | 175 | { |
174 | if (NULL != sc->timeout_task) | 176 | if (NULL != sc->timeout_task) |
175 | GNUNET_SCHEDULER_cancel(sc->timeout_task); | 177 | GNUNET_SCHEDULER_cancel (sc->timeout_task); |
176 | sc->timeout_task = GNUNET_SCHEDULER_add_delayed(IDLE_TIMEOUT, | 178 | sc->timeout_task = GNUNET_SCHEDULER_add_delayed (IDLE_TIMEOUT, |
177 | &timeout_cadet_task, | 179 | &timeout_cadet_task, |
178 | sc); | 180 | sc); |
179 | } | 181 | } |
180 | 182 | ||
181 | 183 | ||
@@ -186,23 +188,23 @@ refresh_timeout_task(struct CadetClient *sc) | |||
186 | * @param cls where to process the write queue | 188 | * @param cls where to process the write queue |
187 | */ | 189 | */ |
188 | static void | 190 | static void |
189 | continue_writing(void *cls) | 191 | continue_writing (void *cls) |
190 | { | 192 | { |
191 | struct CadetClient *sc = cls; | 193 | struct CadetClient *sc = cls; |
192 | struct GNUNET_MQ_Handle *mq; | 194 | struct GNUNET_MQ_Handle *mq; |
193 | 195 | ||
194 | mq = GNUNET_CADET_get_mq(sc->channel); | 196 | mq = GNUNET_CADET_get_mq (sc->channel); |
195 | if (0 != GNUNET_MQ_get_length(mq)) | 197 | if (0 != GNUNET_MQ_get_length (mq)) |
196 | { | 198 | { |
197 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
198 | "Write pending, waiting for it to complete\n"); | 200 | "Write pending, waiting for it to complete\n"); |
199 | return; | 201 | return; |
200 | } | 202 | } |
201 | refresh_timeout_task(sc); | 203 | refresh_timeout_task (sc); |
202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
203 | "Finished processing cadet request from client %p, ready to receive the next one\n", | 205 | "Finished processing cadet request from client %p, ready to receive the next one\n", |
204 | sc); | 206 | sc); |
205 | GNUNET_CADET_receive_done(sc->channel); | 207 | GNUNET_CADET_receive_done (sc->channel); |
206 | } | 208 | } |
207 | 209 | ||
208 | 210 | ||
@@ -222,16 +224,16 @@ continue_writing(void *cls) | |||
222 | * maybe 0 if no unique identifier is available | 224 | * maybe 0 if no unique identifier is available |
223 | */ | 225 | */ |
224 | static void | 226 | static void |
225 | handle_datastore_reply(void *cls, | 227 | handle_datastore_reply (void *cls, |
226 | const struct GNUNET_HashCode *key, | 228 | const struct GNUNET_HashCode *key, |
227 | size_t size, | 229 | size_t size, |
228 | const void *data, | 230 | const void *data, |
229 | enum GNUNET_BLOCK_Type type, | 231 | enum GNUNET_BLOCK_Type type, |
230 | uint32_t priority, | 232 | uint32_t priority, |
231 | uint32_t anonymity, | 233 | uint32_t anonymity, |
232 | uint32_t replication, | 234 | uint32_t replication, |
233 | struct GNUNET_TIME_Absolute expiration, | 235 | struct GNUNET_TIME_Absolute expiration, |
234 | uint64_t uid) | 236 | uint64_t uid) |
235 | { | 237 | { |
236 | struct CadetClient *sc = cls; | 238 | struct CadetClient *sc = cls; |
237 | size_t msize = size + sizeof(struct CadetReplyMessage); | 239 | size_t msize = size + sizeof(struct CadetReplyMessage); |
@@ -240,85 +242,86 @@ handle_datastore_reply(void *cls, | |||
240 | 242 | ||
241 | sc->qe = NULL; | 243 | sc->qe = NULL; |
242 | if (NULL == data) | 244 | if (NULL == data) |
245 | { | ||
246 | /* no result, this should not really happen, as for | ||
247 | non-anonymous routing only peers that HAVE the | ||
248 | answers should be queried; OTOH, this is not a | ||
249 | hard error as we might have had the answer in the | ||
250 | past and the user might have unindexed it. Hence | ||
251 | we log at level "INFO" for now. */ | ||
252 | if (NULL == key) | ||
243 | { | 253 | { |
244 | /* no result, this should not really happen, as for | 254 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
245 | non-anonymous routing only peers that HAVE the | 255 | "Have no answer and the query was NULL\n"); |
246 | answers should be queried; OTOH, this is not a | ||
247 | hard error as we might have had the answer in the | ||
248 | past and the user might have unindexed it. Hence | ||
249 | we log at level "INFO" for now. */ | ||
250 | if (NULL == key) | ||
251 | { | ||
252 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
253 | "Have no answer and the query was NULL\n"); | ||
254 | } | ||
255 | else | ||
256 | { | ||
257 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
258 | "Have no answer for query `%s'\n", | ||
259 | GNUNET_h2s(key)); | ||
260 | } | ||
261 | GNUNET_STATISTICS_update(GSF_stats, | ||
262 | gettext_noop("# queries received via CADET not answered"), | ||
263 | 1, | ||
264 | GNUNET_NO); | ||
265 | continue_writing(sc); | ||
266 | return; | ||
267 | } | 256 | } |
268 | if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) | 257 | else |
269 | { | 258 | { |
270 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 259 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
271 | "Performing on-demand encoding for query %s\n", | 260 | "Have no answer for query `%s'\n", |
272 | GNUNET_h2s(key)); | 261 | GNUNET_h2s (key)); |
273 | if (GNUNET_OK != | ||
274 | GNUNET_FS_handle_on_demand_block(key, | ||
275 | size, | ||
276 | data, | ||
277 | type, | ||
278 | priority, | ||
279 | anonymity, | ||
280 | replication, | ||
281 | expiration, | ||
282 | uid, | ||
283 | &handle_datastore_reply, | ||
284 | sc)) | ||
285 | { | ||
286 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
287 | "On-demand encoding request failed\n"); | ||
288 | continue_writing(sc); | ||
289 | } | ||
290 | return; | ||
291 | } | 262 | } |
292 | if (msize > GNUNET_MAX_MESSAGE_SIZE) | 263 | GNUNET_STATISTICS_update (GSF_stats, |
264 | gettext_noop ( | ||
265 | "# queries received via CADET not answered"), | ||
266 | 1, | ||
267 | GNUNET_NO); | ||
268 | continue_writing (sc); | ||
269 | return; | ||
270 | } | ||
271 | if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) | ||
272 | { | ||
273 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
274 | "Performing on-demand encoding for query %s\n", | ||
275 | GNUNET_h2s (key)); | ||
276 | if (GNUNET_OK != | ||
277 | GNUNET_FS_handle_on_demand_block (key, | ||
278 | size, | ||
279 | data, | ||
280 | type, | ||
281 | priority, | ||
282 | anonymity, | ||
283 | replication, | ||
284 | expiration, | ||
285 | uid, | ||
286 | &handle_datastore_reply, | ||
287 | sc)) | ||
293 | { | 288 | { |
294 | GNUNET_break(0); | 289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
295 | continue_writing(sc); | 290 | "On-demand encoding request failed\n"); |
296 | return; | 291 | continue_writing (sc); |
297 | } | 292 | } |
298 | GNUNET_break(GNUNET_BLOCK_TYPE_ANY != type); | 293 | return; |
299 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 294 | } |
300 | "Starting transmission of %u byte reply of type %d for query `%s' via cadet to %p\n", | 295 | if (msize > GNUNET_MAX_MESSAGE_SIZE) |
301 | (unsigned int)size, | 296 | { |
302 | (unsigned int)type, | 297 | GNUNET_break (0); |
303 | GNUNET_h2s(key), | 298 | continue_writing (sc); |
304 | sc); | 299 | return; |
305 | env = GNUNET_MQ_msg_extra(srm, | 300 | } |
306 | size, | 301 | GNUNET_break (GNUNET_BLOCK_TYPE_ANY != type); |
307 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY); | 302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
308 | srm->type = htonl(type); | 303 | "Starting transmission of %u byte reply of type %d for query `%s' via cadet to %p\n", |
309 | srm->expiration = GNUNET_TIME_absolute_hton(expiration); | 304 | (unsigned int) size, |
310 | GNUNET_memcpy(&srm[1], | 305 | (unsigned int) type, |
311 | data, | 306 | GNUNET_h2s (key), |
312 | size); | 307 | sc); |
313 | GNUNET_MQ_notify_sent(env, | 308 | env = GNUNET_MQ_msg_extra (srm, |
314 | &continue_writing, | 309 | size, |
315 | sc); | 310 | GNUNET_MESSAGE_TYPE_FS_CADET_REPLY); |
316 | GNUNET_STATISTICS_update(GSF_stats, | 311 | srm->type = htonl (type); |
317 | gettext_noop("# Blocks transferred via cadet"), | 312 | srm->expiration = GNUNET_TIME_absolute_hton (expiration); |
318 | 1, | 313 | GNUNET_memcpy (&srm[1], |
319 | GNUNET_NO); | 314 | data, |
320 | GNUNET_MQ_send(GNUNET_CADET_get_mq(sc->channel), | 315 | size); |
321 | env); | 316 | GNUNET_MQ_notify_sent (env, |
317 | &continue_writing, | ||
318 | sc); | ||
319 | GNUNET_STATISTICS_update (GSF_stats, | ||
320 | gettext_noop ("# Blocks transferred via cadet"), | ||
321 | 1, | ||
322 | GNUNET_NO); | ||
323 | GNUNET_MQ_send (GNUNET_CADET_get_mq (sc->channel), | ||
324 | env); | ||
322 | } | 325 | } |
323 | 326 | ||
324 | 327 | ||
@@ -330,35 +333,35 @@ handle_datastore_reply(void *cls, | |||
330 | * @param sqm the actual message | 333 | * @param sqm the actual message |
331 | */ | 334 | */ |
332 | static void | 335 | static void |
333 | handle_request(void *cls, | 336 | handle_request (void *cls, |
334 | const struct CadetQueryMessage *sqm) | 337 | const struct CadetQueryMessage *sqm) |
335 | { | 338 | { |
336 | struct CadetClient *sc = cls; | 339 | struct CadetClient *sc = cls; |
337 | 340 | ||
338 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
339 | "Received query for `%s' via cadet from client %p\n", | 342 | "Received query for `%s' via cadet from client %p\n", |
340 | GNUNET_h2s(&sqm->query), | 343 | GNUNET_h2s (&sqm->query), |
341 | sc); | 344 | sc); |
342 | GNUNET_STATISTICS_update(GSF_stats, | 345 | GNUNET_STATISTICS_update (GSF_stats, |
343 | gettext_noop("# queries received via cadet"), | 346 | gettext_noop ("# queries received via cadet"), |
344 | 1, | 347 | 1, |
345 | GNUNET_NO); | 348 | GNUNET_NO); |
346 | refresh_timeout_task(sc); | 349 | refresh_timeout_task (sc); |
347 | sc->qe = GNUNET_DATASTORE_get_key(GSF_dsh, | 350 | sc->qe = GNUNET_DATASTORE_get_key (GSF_dsh, |
348 | 0 /* next_uid */, | 351 | 0 /* next_uid */, |
349 | false /* random */, | 352 | false /* random */, |
350 | &sqm->query, | 353 | &sqm->query, |
351 | ntohl(sqm->type), | 354 | ntohl (sqm->type), |
352 | 0 /* priority */, | 355 | 0 /* priority */, |
353 | GSF_datastore_queue_size, | 356 | GSF_datastore_queue_size, |
354 | &handle_datastore_reply, | 357 | &handle_datastore_reply, |
355 | sc); | 358 | sc); |
356 | if (NULL == sc->qe) | 359 | if (NULL == sc->qe) |
357 | { | 360 | { |
358 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
359 | "Queueing request with datastore failed (queue full?)\n"); | 362 | "Queueing request with datastore failed (queue full?)\n"); |
360 | continue_writing(sc); | 363 | continue_writing (sc); |
361 | } | 364 | } |
362 | } | 365 | } |
363 | 366 | ||
364 | 367 | ||
@@ -372,37 +375,38 @@ handle_request(void *cls, | |||
372 | * @return initial channel context (our `struct CadetClient`) | 375 | * @return initial channel context (our `struct CadetClient`) |
373 | */ | 376 | */ |
374 | static void * | 377 | static void * |
375 | connect_cb(void *cls, | 378 | connect_cb (void *cls, |
376 | struct GNUNET_CADET_Channel *channel, | 379 | struct GNUNET_CADET_Channel *channel, |
377 | const struct GNUNET_PeerIdentity *initiator) | 380 | const struct GNUNET_PeerIdentity *initiator) |
378 | { | 381 | { |
379 | struct CadetClient *sc; | 382 | struct CadetClient *sc; |
380 | 383 | ||
381 | GNUNET_assert(NULL != channel); | 384 | GNUNET_assert (NULL != channel); |
382 | if (sc_count >= sc_count_max) | 385 | if (sc_count >= sc_count_max) |
383 | { | 386 | { |
384 | GNUNET_STATISTICS_update(GSF_stats, | 387 | GNUNET_STATISTICS_update (GSF_stats, |
385 | gettext_noop("# cadet client connections rejected"), | 388 | gettext_noop ( |
386 | 1, | 389 | "# cadet client connections rejected"), |
387 | GNUNET_NO); | 390 | 1, |
388 | GNUNET_CADET_channel_destroy(channel); | 391 | GNUNET_NO); |
389 | return NULL; | 392 | GNUNET_CADET_channel_destroy (channel); |
390 | } | 393 | return NULL; |
391 | GNUNET_STATISTICS_update(GSF_stats, | 394 | } |
392 | gettext_noop("# cadet connections active"), | 395 | GNUNET_STATISTICS_update (GSF_stats, |
393 | 1, | 396 | gettext_noop ("# cadet connections active"), |
394 | GNUNET_NO); | 397 | 1, |
395 | sc = GNUNET_new(struct CadetClient); | 398 | GNUNET_NO); |
399 | sc = GNUNET_new (struct CadetClient); | ||
396 | sc->channel = channel; | 400 | sc->channel = channel; |
397 | GNUNET_CONTAINER_DLL_insert(sc_head, | 401 | GNUNET_CONTAINER_DLL_insert (sc_head, |
398 | sc_tail, | 402 | sc_tail, |
399 | sc); | 403 | sc); |
400 | sc_count++; | 404 | sc_count++; |
401 | refresh_timeout_task(sc); | 405 | refresh_timeout_task (sc); |
402 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
403 | "Accepting inbound cadet connection from `%s' as client %p\n", | 407 | "Accepting inbound cadet connection from `%s' as client %p\n", |
404 | GNUNET_i2s(initiator), | 408 | GNUNET_i2s (initiator), |
405 | sc); | 409 | sc); |
406 | return sc; | 410 | return sc; |
407 | } | 411 | } |
408 | 412 | ||
@@ -416,8 +420,8 @@ connect_cb(void *cls, | |||
416 | * @param channel_ctx | 420 | * @param channel_ctx |
417 | */ | 421 | */ |
418 | static void | 422 | static void |
419 | disconnect_cb(void *cls, | 423 | disconnect_cb (void *cls, |
420 | const struct GNUNET_CADET_Channel *channel) | 424 | const struct GNUNET_CADET_Channel *channel) |
421 | { | 425 | { |
422 | struct CadetClient *sc = cls; | 426 | struct CadetClient *sc = cls; |
423 | struct WriteQueueItem *wqi; | 427 | struct WriteQueueItem *wqi; |
@@ -425,30 +429,30 @@ disconnect_cb(void *cls, | |||
425 | if (NULL == sc) | 429 | if (NULL == sc) |
426 | return; | 430 | return; |
427 | sc->channel = NULL; | 431 | sc->channel = NULL; |
428 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 432 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
429 | "Terminating cadet connection with client %p\n", | 433 | "Terminating cadet connection with client %p\n", |
430 | sc); | 434 | sc); |
431 | GNUNET_STATISTICS_update(GSF_stats, | 435 | GNUNET_STATISTICS_update (GSF_stats, |
432 | gettext_noop("# cadet connections active"), -1, | 436 | gettext_noop ("# cadet connections active"), -1, |
433 | GNUNET_NO); | 437 | GNUNET_NO); |
434 | if (NULL != sc->terminate_task) | 438 | if (NULL != sc->terminate_task) |
435 | GNUNET_SCHEDULER_cancel(sc->terminate_task); | 439 | GNUNET_SCHEDULER_cancel (sc->terminate_task); |
436 | if (NULL != sc->timeout_task) | 440 | if (NULL != sc->timeout_task) |
437 | GNUNET_SCHEDULER_cancel(sc->timeout_task); | 441 | GNUNET_SCHEDULER_cancel (sc->timeout_task); |
438 | if (NULL != sc->qe) | 442 | if (NULL != sc->qe) |
439 | GNUNET_DATASTORE_cancel(sc->qe); | 443 | GNUNET_DATASTORE_cancel (sc->qe); |
440 | while (NULL != (wqi = sc->wqi_head)) | 444 | while (NULL != (wqi = sc->wqi_head)) |
441 | { | 445 | { |
442 | GNUNET_CONTAINER_DLL_remove(sc->wqi_head, | 446 | GNUNET_CONTAINER_DLL_remove (sc->wqi_head, |
443 | sc->wqi_tail, | 447 | sc->wqi_tail, |
444 | wqi); | 448 | wqi); |
445 | GNUNET_free(wqi); | 449 | GNUNET_free (wqi); |
446 | } | 450 | } |
447 | GNUNET_CONTAINER_DLL_remove(sc_head, | 451 | GNUNET_CONTAINER_DLL_remove (sc_head, |
448 | sc_tail, | 452 | sc_tail, |
449 | sc); | 453 | sc); |
450 | sc_count--; | 454 | sc_count--; |
451 | GNUNET_free(sc); | 455 | GNUNET_free (sc); |
452 | } | 456 | } |
453 | 457 | ||
454 | 458 | ||
@@ -467,9 +471,9 @@ disconnect_cb(void *cls, | |||
467 | * this value will be negative.. | 471 | * this value will be negative.. |
468 | */ | 472 | */ |
469 | static void | 473 | static void |
470 | window_change_cb(void *cls, | 474 | window_change_cb (void *cls, |
471 | const struct GNUNET_CADET_Channel *channel, | 475 | const struct GNUNET_CADET_Channel *channel, |
472 | int window_size) | 476 | int window_size) |
473 | { | 477 | { |
474 | /* FIXME: could do flow control here... */ | 478 | /* FIXME: could do flow control here... */ |
475 | } | 479 | } |
@@ -479,39 +483,39 @@ window_change_cb(void *cls, | |||
479 | * Initialize subsystem for non-anonymous file-sharing. | 483 | * Initialize subsystem for non-anonymous file-sharing. |
480 | */ | 484 | */ |
481 | void | 485 | void |
482 | GSF_cadet_start_server() | 486 | GSF_cadet_start_server () |
483 | { | 487 | { |
484 | struct GNUNET_MQ_MessageHandler handlers[] = { | 488 | struct GNUNET_MQ_MessageHandler handlers[] = { |
485 | GNUNET_MQ_hd_fixed_size(request, | 489 | GNUNET_MQ_hd_fixed_size (request, |
486 | GNUNET_MESSAGE_TYPE_FS_CADET_QUERY, | 490 | GNUNET_MESSAGE_TYPE_FS_CADET_QUERY, |
487 | struct CadetQueryMessage, | 491 | struct CadetQueryMessage, |
488 | NULL), | 492 | NULL), |
489 | GNUNET_MQ_handler_end() | 493 | GNUNET_MQ_handler_end () |
490 | }; | 494 | }; |
491 | struct GNUNET_HashCode port; | 495 | struct GNUNET_HashCode port; |
492 | 496 | ||
493 | if (GNUNET_YES != | 497 | if (GNUNET_YES != |
494 | GNUNET_CONFIGURATION_get_value_number(GSF_cfg, | 498 | GNUNET_CONFIGURATION_get_value_number (GSF_cfg, |
495 | "fs", | 499 | "fs", |
496 | "MAX_CADET_CLIENTS", | 500 | "MAX_CADET_CLIENTS", |
497 | &sc_count_max)) | 501 | &sc_count_max)) |
498 | return; | 502 | return; |
499 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 503 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
500 | "Initializing cadet FS server with a limit of %llu connections\n", | 504 | "Initializing cadet FS server with a limit of %llu connections\n", |
501 | sc_count_max); | 505 | sc_count_max); |
502 | cadet_map = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); | 506 | cadet_map = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); |
503 | cadet_handle = GNUNET_CADET_connect(GSF_cfg); | 507 | cadet_handle = GNUNET_CADET_connect (GSF_cfg); |
504 | GNUNET_assert(NULL != cadet_handle); | 508 | GNUNET_assert (NULL != cadet_handle); |
505 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, | 509 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, |
506 | strlen(GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), | 510 | strlen (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER), |
507 | &port); | 511 | &port); |
508 | cadet_port = GNUNET_CADET_open_port(cadet_handle, | 512 | cadet_port = GNUNET_CADET_open_port (cadet_handle, |
509 | &port, | 513 | &port, |
510 | &connect_cb, | 514 | &connect_cb, |
511 | NULL, | 515 | NULL, |
512 | &window_change_cb, | 516 | &window_change_cb, |
513 | &disconnect_cb, | 517 | &disconnect_cb, |
514 | handlers); | 518 | handlers); |
515 | } | 519 | } |
516 | 520 | ||
517 | 521 | ||
@@ -519,25 +523,25 @@ GSF_cadet_start_server() | |||
519 | * Shutdown subsystem for non-anonymous file-sharing. | 523 | * Shutdown subsystem for non-anonymous file-sharing. |
520 | */ | 524 | */ |
521 | void | 525 | void |
522 | GSF_cadet_stop_server() | 526 | GSF_cadet_stop_server () |
523 | { | 527 | { |
524 | GNUNET_CONTAINER_multipeermap_iterate(cadet_map, | 528 | GNUNET_CONTAINER_multipeermap_iterate (cadet_map, |
525 | &GSF_cadet_release_clients, | 529 | &GSF_cadet_release_clients, |
526 | NULL); | 530 | NULL); |
527 | GNUNET_CONTAINER_multipeermap_destroy(cadet_map); | 531 | GNUNET_CONTAINER_multipeermap_destroy (cadet_map); |
528 | cadet_map = NULL; | 532 | cadet_map = NULL; |
529 | if (NULL != cadet_port) | 533 | if (NULL != cadet_port) |
530 | { | 534 | { |
531 | GNUNET_CADET_close_port(cadet_port); | 535 | GNUNET_CADET_close_port (cadet_port); |
532 | cadet_port = NULL; | 536 | cadet_port = NULL; |
533 | } | 537 | } |
534 | if (NULL != cadet_handle) | 538 | if (NULL != cadet_handle) |
535 | { | 539 | { |
536 | GNUNET_CADET_disconnect(cadet_handle); | 540 | GNUNET_CADET_disconnect (cadet_handle); |
537 | cadet_handle = NULL; | 541 | cadet_handle = NULL; |
538 | } | 542 | } |
539 | GNUNET_assert(NULL == sc_head); | 543 | GNUNET_assert (NULL == sc_head); |
540 | GNUNET_assert(0 == sc_count); | 544 | GNUNET_assert (0 == sc_count); |
541 | } | 545 | } |
542 | 546 | ||
543 | /* end of gnunet-service-fs_cadet.c */ | 547 | /* end of gnunet-service-fs_cadet.c */ |
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index 6dab37869..dca8ae2a8 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c | |||
@@ -43,12 +43,14 @@ | |||
43 | /** | 43 | /** |
44 | * How often do we flush respect values to disk? | 44 | * How often do we flush respect values to disk? |
45 | */ | 45 | */ |
46 | #define RESPECT_FLUSH_FREQ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) | 46 | #define RESPECT_FLUSH_FREQ GNUNET_TIME_relative_multiply ( \ |
47 | GNUNET_TIME_UNIT_MINUTES, 5) | ||
47 | 48 | ||
48 | /** | 49 | /** |
49 | * After how long do we discard a reply? | 50 | * After how long do we discard a reply? |
50 | */ | 51 | */ |
51 | #define REPLY_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) | 52 | #define REPLY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, \ |
53 | 2) | ||
52 | 54 | ||
53 | /** | 55 | /** |
54 | * Collect an instane number of statistics? May cause excessive IPC. | 56 | * Collect an instane number of statistics? May cause excessive IPC. |
@@ -59,7 +61,8 @@ | |||
59 | /** | 61 | /** |
60 | * Handle to cancel a transmission request. | 62 | * Handle to cancel a transmission request. |
61 | */ | 63 | */ |
62 | struct GSF_PeerTransmitHandle { | 64 | struct GSF_PeerTransmitHandle |
65 | { | ||
63 | /** | 66 | /** |
64 | * Kept in a doubly-linked list. | 67 | * Kept in a doubly-linked list. |
65 | */ | 68 | */ |
@@ -105,7 +108,8 @@ struct GSF_PeerTransmitHandle { | |||
105 | /** | 108 | /** |
106 | * Handle for an entry in our delay list. | 109 | * Handle for an entry in our delay list. |
107 | */ | 110 | */ |
108 | struct GSF_DelayedHandle { | 111 | struct GSF_DelayedHandle |
112 | { | ||
109 | /** | 113 | /** |
110 | * Kept in a doubly-linked list. | 114 | * Kept in a doubly-linked list. |
111 | */ | 115 | */ |
@@ -141,7 +145,8 @@ struct GSF_DelayedHandle { | |||
141 | /** | 145 | /** |
142 | * Information per peer and request. | 146 | * Information per peer and request. |
143 | */ | 147 | */ |
144 | struct PeerRequest { | 148 | struct PeerRequest |
149 | { | ||
145 | /** | 150 | /** |
146 | * Handle to generic request (generic: from peer or local client). | 151 | * Handle to generic request (generic: from peer or local client). |
147 | */ | 152 | */ |
@@ -162,7 +167,8 @@ struct PeerRequest { | |||
162 | /** | 167 | /** |
163 | * A connected peer. | 168 | * A connected peer. |
164 | */ | 169 | */ |
165 | struct GSF_ConnectedPeer { | 170 | struct GSF_ConnectedPeer |
171 | { | ||
166 | /** | 172 | /** |
167 | * Performance data for this peer. | 173 | * Performance data for this peer. |
168 | */ | 174 | */ |
@@ -293,16 +299,16 @@ static struct GNUNET_SCHEDULER_Task *fr_task; | |||
293 | * @param latency current latency value | 299 | * @param latency current latency value |
294 | */ | 300 | */ |
295 | void | 301 | void |
296 | GSF_update_peer_latency_(const struct GNUNET_PeerIdentity *id, | 302 | GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, |
297 | struct GNUNET_TIME_Relative latency) | 303 | struct GNUNET_TIME_Relative latency) |
298 | { | 304 | { |
299 | struct GSF_ConnectedPeer *cp; | 305 | struct GSF_ConnectedPeer *cp; |
300 | 306 | ||
301 | cp = GSF_peer_get_(id); | 307 | cp = GSF_peer_get_ (id); |
302 | if (NULL == cp) | 308 | if (NULL == cp) |
303 | return; /* we're not yet connected at the core level, ignore */ | 309 | return; /* we're not yet connected at the core level, ignore */ |
304 | GNUNET_LOAD_value_set_decline(cp->ppd.transmission_delay, | 310 | GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, |
305 | latency); | 311 | latency); |
306 | } | 312 | } |
307 | 313 | ||
308 | 314 | ||
@@ -313,7 +319,7 @@ GSF_update_peer_latency_(const struct GNUNET_PeerIdentity *id, | |||
313 | * @return performance data record for the peer | 319 | * @return performance data record for the peer |
314 | */ | 320 | */ |
315 | struct GSF_PeerPerformanceData * | 321 | struct GSF_PeerPerformanceData * |
316 | GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp) | 322 | GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp) |
317 | { | 323 | { |
318 | return &cp->ppd; | 324 | return &cp->ppd; |
319 | } | 325 | } |
@@ -325,7 +331,7 @@ GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp) | |||
325 | * @param cp which peer to send a message to | 331 | * @param cp which peer to send a message to |
326 | */ | 332 | */ |
327 | static void | 333 | static void |
328 | peer_transmit(struct GSF_ConnectedPeer *cp); | 334 | peer_transmit (struct GSF_ConnectedPeer *cp); |
329 | 335 | ||
330 | 336 | ||
331 | /** | 337 | /** |
@@ -339,10 +345,10 @@ peer_transmit(struct GSF_ConnectedPeer *cp); | |||
339 | * long should the client wait until re-trying? | 345 | * long should the client wait until re-trying? |
340 | */ | 346 | */ |
341 | static void | 347 | static void |
342 | ats_reserve_callback(void *cls, | 348 | ats_reserve_callback (void *cls, |
343 | const struct GNUNET_PeerIdentity *peer, | 349 | const struct GNUNET_PeerIdentity *peer, |
344 | int32_t amount, | 350 | int32_t amount, |
345 | struct GNUNET_TIME_Relative res_delay); | 351 | struct GNUNET_TIME_Relative res_delay); |
346 | 352 | ||
347 | 353 | ||
348 | /** | 354 | /** |
@@ -352,42 +358,42 @@ ats_reserve_callback(void *cls, | |||
352 | * @param pth transmission handle to schedule | 358 | * @param pth transmission handle to schedule |
353 | */ | 359 | */ |
354 | static void | 360 | static void |
355 | schedule_transmission(struct GSF_PeerTransmitHandle *pth) | 361 | schedule_transmission (struct GSF_PeerTransmitHandle *pth) |
356 | { | 362 | { |
357 | struct GSF_ConnectedPeer *cp; | 363 | struct GSF_ConnectedPeer *cp; |
358 | struct GNUNET_PeerIdentity target; | 364 | struct GNUNET_PeerIdentity target; |
359 | 365 | ||
360 | cp = pth->cp; | 366 | cp = pth->cp; |
361 | GNUNET_assert(0 != cp->ppd.pid); | 367 | GNUNET_assert (0 != cp->ppd.pid); |
362 | GNUNET_PEER_resolve(cp->ppd.pid, &target); | 368 | GNUNET_PEER_resolve (cp->ppd.pid, &target); |
363 | 369 | ||
364 | if (0 != cp->inc_preference) | 370 | if (0 != cp->inc_preference) |
365 | { | 371 | { |
366 | GNUNET_ATS_performance_change_preference(GSF_ats, | 372 | GNUNET_ATS_performance_change_preference (GSF_ats, |
367 | &target, | 373 | &target, |
368 | GNUNET_ATS_PREFERENCE_BANDWIDTH, | 374 | GNUNET_ATS_PREFERENCE_BANDWIDTH, |
369 | (double)cp->inc_preference, | 375 | (double) cp->inc_preference, |
370 | GNUNET_ATS_PREFERENCE_END); | 376 | GNUNET_ATS_PREFERENCE_END); |
371 | cp->inc_preference = 0; | 377 | cp->inc_preference = 0; |
372 | } | 378 | } |
373 | 379 | ||
374 | if ((GNUNET_YES == pth->is_query) && | 380 | if ((GNUNET_YES == pth->is_query) && |
375 | (GNUNET_YES != pth->was_reserved)) | 381 | (GNUNET_YES != pth->was_reserved)) |
376 | { | 382 | { |
377 | /* query, need reservation */ | 383 | /* query, need reservation */ |
378 | if (GNUNET_YES != cp->did_reserve) | 384 | if (GNUNET_YES != cp->did_reserve) |
379 | return; /* not ready */ | 385 | return; /* not ready */ |
380 | cp->did_reserve = GNUNET_NO; | 386 | cp->did_reserve = GNUNET_NO; |
381 | /* reservation already done! */ | 387 | /* reservation already done! */ |
382 | pth->was_reserved = GNUNET_YES; | 388 | pth->was_reserved = GNUNET_YES; |
383 | cp->rc = GNUNET_ATS_reserve_bandwidth(GSF_ats, | 389 | cp->rc = GNUNET_ATS_reserve_bandwidth (GSF_ats, |
384 | &target, | 390 | &target, |
385 | DBLOCK_SIZE, | 391 | DBLOCK_SIZE, |
386 | &ats_reserve_callback, | 392 | &ats_reserve_callback, |
387 | cp); | 393 | cp); |
388 | return; | 394 | return; |
389 | } | 395 | } |
390 | peer_transmit(cp); | 396 | peer_transmit (cp); |
391 | } | 397 | } |
392 | 398 | ||
393 | 399 | ||
@@ -397,38 +403,38 @@ schedule_transmission(struct GSF_PeerTransmitHandle *pth) | |||
397 | * @param cp which peer to send a message to | 403 | * @param cp which peer to send a message to |
398 | */ | 404 | */ |
399 | static void | 405 | static void |
400 | peer_transmit(struct GSF_ConnectedPeer *cp) | 406 | peer_transmit (struct GSF_ConnectedPeer *cp) |
401 | { | 407 | { |
402 | struct GSF_PeerTransmitHandle *pth = cp->pth_head; | 408 | struct GSF_PeerTransmitHandle *pth = cp->pth_head; |
403 | struct GSF_PeerTransmitHandle *pos; | 409 | struct GSF_PeerTransmitHandle *pos; |
404 | 410 | ||
405 | if (NULL == pth) | 411 | if (NULL == pth) |
406 | return; | 412 | return; |
407 | GNUNET_CONTAINER_DLL_remove(cp->pth_head, | 413 | GNUNET_CONTAINER_DLL_remove (cp->pth_head, |
408 | cp->pth_tail, | 414 | cp->pth_tail, |
409 | pth); | 415 | pth); |
410 | if (GNUNET_YES == pth->is_query) | 416 | if (GNUNET_YES == pth->is_query) |
411 | { | 417 | { |
412 | cp->ppd.last_request_times[(cp->last_request_times_off++) % | 418 | cp->ppd.last_request_times[(cp->last_request_times_off++) |
413 | MAX_QUEUE_PER_PEER] = | 419 | % MAX_QUEUE_PER_PEER] = |
414 | GNUNET_TIME_absolute_get(); | 420 | GNUNET_TIME_absolute_get (); |
415 | GNUNET_assert(0 < cp->ppd.pending_queries--); | 421 | GNUNET_assert (0 < cp->ppd.pending_queries--); |
416 | } | 422 | } |
417 | else if (GNUNET_NO == pth->is_query) | 423 | else if (GNUNET_NO == pth->is_query) |
418 | { | 424 | { |
419 | GNUNET_assert(0 < cp->ppd.pending_replies--); | 425 | GNUNET_assert (0 < cp->ppd.pending_replies--); |
420 | } | 426 | } |
421 | GNUNET_LOAD_update(cp->ppd.transmission_delay, | 427 | GNUNET_LOAD_update (cp->ppd.transmission_delay, |
422 | GNUNET_TIME_absolute_get_duration | 428 | GNUNET_TIME_absolute_get_duration |
423 | (pth->transmission_request_start_time).rel_value_us); | 429 | (pth->transmission_request_start_time).rel_value_us); |
424 | GNUNET_MQ_send(cp->mq, | 430 | GNUNET_MQ_send (cp->mq, |
425 | pth->env); | 431 | pth->env); |
426 | GNUNET_free(pth); | 432 | GNUNET_free (pth); |
427 | if (NULL != (pos = cp->pth_head)) | 433 | if (NULL != (pos = cp->pth_head)) |
428 | { | 434 | { |
429 | GNUNET_assert(pos != pth); | 435 | GNUNET_assert (pos != pth); |
430 | schedule_transmission(pos); | 436 | schedule_transmission (pos); |
431 | } | 437 | } |
432 | } | 438 | } |
433 | 439 | ||
434 | 440 | ||
@@ -438,18 +444,18 @@ peer_transmit(struct GSF_ConnectedPeer *cp) | |||
438 | * @param cls the `struct GSF_ConnectedPeer` to reserve from | 444 | * @param cls the `struct GSF_ConnectedPeer` to reserve from |
439 | */ | 445 | */ |
440 | static void | 446 | static void |
441 | retry_reservation(void *cls) | 447 | retry_reservation (void *cls) |
442 | { | 448 | { |
443 | struct GSF_ConnectedPeer *cp = cls; | 449 | struct GSF_ConnectedPeer *cp = cls; |
444 | struct GNUNET_PeerIdentity target; | 450 | struct GNUNET_PeerIdentity target; |
445 | 451 | ||
446 | GNUNET_PEER_resolve(cp->ppd.pid, &target); | 452 | GNUNET_PEER_resolve (cp->ppd.pid, &target); |
447 | cp->rc_delay_task = NULL; | 453 | cp->rc_delay_task = NULL; |
448 | cp->rc = | 454 | cp->rc = |
449 | GNUNET_ATS_reserve_bandwidth(GSF_ats, | 455 | GNUNET_ATS_reserve_bandwidth (GSF_ats, |
450 | &target, | 456 | &target, |
451 | DBLOCK_SIZE, | 457 | DBLOCK_SIZE, |
452 | &ats_reserve_callback, cp); | 458 | &ats_reserve_callback, cp); |
453 | } | 459 | } |
454 | 460 | ||
455 | 461 | ||
@@ -464,34 +470,34 @@ retry_reservation(void *cls) | |||
464 | * long should the client wait until re-trying? | 470 | * long should the client wait until re-trying? |
465 | */ | 471 | */ |
466 | static void | 472 | static void |
467 | ats_reserve_callback(void *cls, | 473 | ats_reserve_callback (void *cls, |
468 | const struct GNUNET_PeerIdentity *peer, | 474 | const struct GNUNET_PeerIdentity *peer, |
469 | int32_t amount, | 475 | int32_t amount, |
470 | struct GNUNET_TIME_Relative res_delay) | 476 | struct GNUNET_TIME_Relative res_delay) |
471 | { | 477 | { |
472 | struct GSF_ConnectedPeer *cp = cls; | 478 | struct GSF_ConnectedPeer *cp = cls; |
473 | struct GSF_PeerTransmitHandle *pth; | 479 | struct GSF_PeerTransmitHandle *pth; |
474 | 480 | ||
475 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
476 | "Reserved %d bytes / need to wait %s for reservation\n", | 482 | "Reserved %d bytes / need to wait %s for reservation\n", |
477 | (int)amount, | 483 | (int) amount, |
478 | GNUNET_STRINGS_relative_time_to_string(res_delay, GNUNET_YES)); | 484 | GNUNET_STRINGS_relative_time_to_string (res_delay, GNUNET_YES)); |
479 | cp->rc = NULL; | 485 | cp->rc = NULL; |
480 | if (0 == amount) | 486 | if (0 == amount) |
481 | { | 487 | { |
482 | cp->rc_delay_task = | 488 | cp->rc_delay_task = |
483 | GNUNET_SCHEDULER_add_delayed(res_delay, | 489 | GNUNET_SCHEDULER_add_delayed (res_delay, |
484 | &retry_reservation, | 490 | &retry_reservation, |
485 | cp); | 491 | cp); |
486 | return; | 492 | return; |
487 | } | 493 | } |
488 | cp->did_reserve = GNUNET_YES; | 494 | cp->did_reserve = GNUNET_YES; |
489 | pth = cp->pth_head; | 495 | pth = cp->pth_head; |
490 | if (NULL != pth) | 496 | if (NULL != pth) |
491 | { | 497 | { |
492 | /* reservation success, try transmission now! */ | 498 | /* reservation success, try transmission now! */ |
493 | peer_transmit(cp); | 499 | peer_transmit (cp); |
494 | } | 500 | } |
495 | } | 501 | } |
496 | 502 | ||
497 | 503 | ||
@@ -503,22 +509,22 @@ ats_reserve_callback(void *cls, | |||
503 | * @param emsg error message, or NULL if no errors | 509 | * @param emsg error message, or NULL if no errors |
504 | */ | 510 | */ |
505 | static void | 511 | static void |
506 | peer_respect_cb(void *cls, | 512 | peer_respect_cb (void *cls, |
507 | const struct GNUNET_PEERSTORE_Record *record, | 513 | const struct GNUNET_PEERSTORE_Record *record, |
508 | const char *emsg) | 514 | const char *emsg) |
509 | { | 515 | { |
510 | struct GSF_ConnectedPeer *cp = cls; | 516 | struct GSF_ConnectedPeer *cp = cls; |
511 | 517 | ||
512 | GNUNET_assert(NULL != cp->respect_iterate_req); | 518 | GNUNET_assert (NULL != cp->respect_iterate_req); |
513 | if ((NULL != record) && | 519 | if ((NULL != record) && |
514 | (sizeof(cp->disk_respect) == record->value_size)) | 520 | (sizeof(cp->disk_respect) == record->value_size)) |
515 | { | 521 | { |
516 | cp->disk_respect = *((uint32_t *)record->value); | 522 | cp->disk_respect = *((uint32_t *) record->value); |
517 | cp->ppd.respect += *((uint32_t *)record->value); | 523 | cp->ppd.respect += *((uint32_t *) record->value); |
518 | } | 524 | } |
519 | GSF_push_start_(cp); | 525 | GSF_push_start_ (cp); |
520 | if (NULL != record) | 526 | if (NULL != record) |
521 | GNUNET_PEERSTORE_iterate_cancel(cp->respect_iterate_req); | 527 | GNUNET_PEERSTORE_iterate_cancel (cp->respect_iterate_req); |
522 | cp->respect_iterate_req = NULL; | 528 | cp->respect_iterate_req = NULL; |
523 | } | 529 | } |
524 | 530 | ||
@@ -534,27 +540,27 @@ peer_respect_cb(void *cls, | |||
534 | * @return #GNUNET_YES to continue to iterate | 540 | * @return #GNUNET_YES to continue to iterate |
535 | */ | 541 | */ |
536 | static int | 542 | static int |
537 | consider_peer_for_forwarding(void *cls, | 543 | consider_peer_for_forwarding (void *cls, |
538 | const struct GNUNET_HashCode *key, | 544 | const struct GNUNET_HashCode *key, |
539 | struct GSF_PendingRequest *pr) | 545 | struct GSF_PendingRequest *pr) |
540 | { | 546 | { |
541 | struct GSF_ConnectedPeer *cp = cls; | 547 | struct GSF_ConnectedPeer *cp = cls; |
542 | struct GNUNET_PeerIdentity pid; | 548 | struct GNUNET_PeerIdentity pid; |
543 | 549 | ||
544 | if (GNUNET_YES != | 550 | if (GNUNET_YES != |
545 | GSF_pending_request_test_active_(pr)) | 551 | GSF_pending_request_test_active_ (pr)) |
546 | return GNUNET_YES; /* request is not actually active, skip! */ | 552 | return GNUNET_YES; /* request is not actually active, skip! */ |
547 | GSF_connected_peer_get_identity_(cp, &pid); | 553 | GSF_connected_peer_get_identity_ (cp, &pid); |
548 | if (GNUNET_YES != | 554 | if (GNUNET_YES != |
549 | GSF_pending_request_test_target_(pr, &pid)) | 555 | GSF_pending_request_test_target_ (pr, &pid)) |
550 | { | 556 | { |
551 | GNUNET_STATISTICS_update(GSF_stats, | 557 | GNUNET_STATISTICS_update (GSF_stats, |
552 | gettext_noop("# Loopback routes suppressed"), | 558 | gettext_noop ("# Loopback routes suppressed"), |
553 | 1, | 559 | 1, |
554 | GNUNET_NO); | 560 | GNUNET_NO); |
555 | return GNUNET_YES; | 561 | return GNUNET_YES; |
556 | } | 562 | } |
557 | GSF_plan_add_(cp, pr); | 563 | GSF_plan_add_ (cp, pr); |
558 | return GNUNET_YES; | 564 | return GNUNET_YES; |
559 | } | 565 | } |
560 | 566 | ||
@@ -569,49 +575,50 @@ consider_peer_for_forwarding(void *cls, | |||
569 | * @return our internal handle for the peer | 575 | * @return our internal handle for the peer |
570 | */ | 576 | */ |
571 | void * | 577 | void * |
572 | GSF_peer_connect_handler(void *cls, | 578 | GSF_peer_connect_handler (void *cls, |
573 | const struct GNUNET_PeerIdentity *peer, | 579 | const struct GNUNET_PeerIdentity *peer, |
574 | struct GNUNET_MQ_Handle *mq) | 580 | struct GNUNET_MQ_Handle *mq) |
575 | { | 581 | { |
576 | struct GSF_ConnectedPeer *cp; | 582 | struct GSF_ConnectedPeer *cp; |
577 | 583 | ||
578 | if (0 == | 584 | if (0 == |
579 | GNUNET_memcmp(&GSF_my_id, | 585 | GNUNET_memcmp (&GSF_my_id, |
580 | peer)) | 586 | peer)) |
581 | return NULL; | 587 | return NULL; |
582 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
583 | "Connected to peer %s\n", | 589 | "Connected to peer %s\n", |
584 | GNUNET_i2s(peer)); | 590 | GNUNET_i2s (peer)); |
585 | cp = GNUNET_new(struct GSF_ConnectedPeer); | 591 | cp = GNUNET_new (struct GSF_ConnectedPeer); |
586 | cp->ppd.pid = GNUNET_PEER_intern(peer); | 592 | cp->ppd.pid = GNUNET_PEER_intern (peer); |
587 | cp->ppd.peer = peer; | 593 | cp->ppd.peer = peer; |
588 | cp->mq = mq; | 594 | cp->mq = mq; |
589 | cp->ppd.transmission_delay = GNUNET_LOAD_value_init(GNUNET_TIME_UNIT_ZERO); | 595 | cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); |
590 | cp->rc = | 596 | cp->rc = |
591 | GNUNET_ATS_reserve_bandwidth(GSF_ats, | 597 | GNUNET_ATS_reserve_bandwidth (GSF_ats, |
592 | peer, | 598 | peer, |
593 | DBLOCK_SIZE, | 599 | DBLOCK_SIZE, |
594 | &ats_reserve_callback, cp); | 600 | &ats_reserve_callback, cp); |
595 | cp->request_map = GNUNET_CONTAINER_multihashmap_create(128, | 601 | cp->request_map = GNUNET_CONTAINER_multihashmap_create (128, |
596 | GNUNET_YES); | 602 | GNUNET_YES); |
597 | GNUNET_break(GNUNET_OK == | 603 | GNUNET_break (GNUNET_OK == |
598 | GNUNET_CONTAINER_multipeermap_put(cp_map, | 604 | GNUNET_CONTAINER_multipeermap_put (cp_map, |
599 | GSF_connected_peer_get_identity2_(cp), | 605 | GSF_connected_peer_get_identity2_ ( |
600 | cp, | 606 | cp), |
601 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 607 | cp, |
602 | GNUNET_STATISTICS_set(GSF_stats, | 608 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
603 | gettext_noop("# peers connected"), | 609 | GNUNET_STATISTICS_set (GSF_stats, |
604 | GNUNET_CONTAINER_multipeermap_size(cp_map), | 610 | gettext_noop ("# peers connected"), |
605 | GNUNET_NO); | 611 | GNUNET_CONTAINER_multipeermap_size (cp_map), |
612 | GNUNET_NO); | ||
606 | cp->respect_iterate_req | 613 | cp->respect_iterate_req |
607 | = GNUNET_PEERSTORE_iterate(peerstore, | 614 | = GNUNET_PEERSTORE_iterate (peerstore, |
608 | "fs", | 615 | "fs", |
609 | peer, | 616 | peer, |
610 | "respect", | 617 | "respect", |
611 | &peer_respect_cb, | 618 | &peer_respect_cb, |
612 | cp); | ||
613 | GSF_iterate_pending_requests_(&consider_peer_for_forwarding, | ||
614 | cp); | 619 | cp); |
620 | GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, | ||
621 | cp); | ||
615 | return cp; | 622 | return cp; |
616 | } | 623 | } |
617 | 624 | ||
@@ -623,21 +630,21 @@ GSF_peer_connect_handler(void *cls, | |||
623 | * @param cls the `struct GSF_ConnectedPeer` | 630 | * @param cls the `struct GSF_ConnectedPeer` |
624 | */ | 631 | */ |
625 | static void | 632 | static void |
626 | revive_migration(void *cls) | 633 | revive_migration (void *cls) |
627 | { | 634 | { |
628 | struct GSF_ConnectedPeer *cp = cls; | 635 | struct GSF_ConnectedPeer *cp = cls; |
629 | struct GNUNET_TIME_Relative bt; | 636 | struct GNUNET_TIME_Relative bt; |
630 | 637 | ||
631 | cp->mig_revive_task = NULL; | 638 | cp->mig_revive_task = NULL; |
632 | bt = GNUNET_TIME_absolute_get_remaining(cp->ppd.migration_blocked_until); | 639 | bt = GNUNET_TIME_absolute_get_remaining (cp->ppd.migration_blocked_until); |
633 | if (0 != bt.rel_value_us) | 640 | if (0 != bt.rel_value_us) |
634 | { | 641 | { |
635 | /* still time left... */ | 642 | /* still time left... */ |
636 | cp->mig_revive_task = | 643 | cp->mig_revive_task = |
637 | GNUNET_SCHEDULER_add_delayed(bt, &revive_migration, cp); | 644 | GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp); |
638 | return; | 645 | return; |
639 | } | 646 | } |
640 | GSF_push_start_(cp); | 647 | GSF_push_start_ (cp); |
641 | } | 648 | } |
642 | 649 | ||
643 | 650 | ||
@@ -648,11 +655,11 @@ revive_migration(void *cls) | |||
648 | * @return NULL if the peer is not currently connected | 655 | * @return NULL if the peer is not currently connected |
649 | */ | 656 | */ |
650 | struct GSF_ConnectedPeer * | 657 | struct GSF_ConnectedPeer * |
651 | GSF_peer_get_(const struct GNUNET_PeerIdentity *peer) | 658 | GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer) |
652 | { | 659 | { |
653 | if (NULL == cp_map) | 660 | if (NULL == cp_map) |
654 | return NULL; | 661 | return NULL; |
655 | return GNUNET_CONTAINER_multipeermap_get(cp_map, peer); | 662 | return GNUNET_CONTAINER_multipeermap_get (cp_map, peer); |
656 | } | 663 | } |
657 | 664 | ||
658 | 665 | ||
@@ -663,29 +670,29 @@ GSF_peer_get_(const struct GNUNET_PeerIdentity *peer) | |||
663 | * @param msm the actual message | 670 | * @param msm the actual message |
664 | */ | 671 | */ |
665 | void | 672 | void |
666 | handle_p2p_migration_stop(void *cls, | 673 | handle_p2p_migration_stop (void *cls, |
667 | const struct MigrationStopMessage *msm) | 674 | const struct MigrationStopMessage *msm) |
668 | { | 675 | { |
669 | struct GSF_ConnectedPeer *cp = cls; | 676 | struct GSF_ConnectedPeer *cp = cls; |
670 | struct GNUNET_TIME_Relative bt; | 677 | struct GNUNET_TIME_Relative bt; |
671 | 678 | ||
672 | GNUNET_STATISTICS_update(GSF_stats, | 679 | GNUNET_STATISTICS_update (GSF_stats, |
673 | gettext_noop("# migration stop messages received"), | 680 | gettext_noop ("# migration stop messages received"), |
674 | 1, GNUNET_NO); | 681 | 1, GNUNET_NO); |
675 | bt = GNUNET_TIME_relative_ntoh(msm->duration); | 682 | bt = GNUNET_TIME_relative_ntoh (msm->duration); |
676 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 683 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
677 | _("Migration of content to peer `%s' blocked for %s\n"), | 684 | _ ("Migration of content to peer `%s' blocked for %s\n"), |
678 | GNUNET_i2s(cp->ppd.peer), | 685 | GNUNET_i2s (cp->ppd.peer), |
679 | GNUNET_STRINGS_relative_time_to_string(bt, GNUNET_YES)); | 686 | GNUNET_STRINGS_relative_time_to_string (bt, GNUNET_YES)); |
680 | cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute(bt); | 687 | cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (bt); |
681 | if ((NULL == cp->mig_revive_task) && | 688 | if ((NULL == cp->mig_revive_task) && |
682 | (NULL == cp->respect_iterate_req)) | 689 | (NULL == cp->respect_iterate_req)) |
683 | { | 690 | { |
684 | GSF_push_stop_(cp); | 691 | GSF_push_stop_ (cp); |
685 | cp->mig_revive_task = | 692 | cp->mig_revive_task = |
686 | GNUNET_SCHEDULER_add_delayed(bt, | 693 | GNUNET_SCHEDULER_add_delayed (bt, |
687 | &revive_migration, cp); | 694 | &revive_migration, cp); |
688 | } | 695 | } |
689 | } | 696 | } |
690 | 697 | ||
691 | 698 | ||
@@ -695,26 +702,26 @@ handle_p2p_migration_stop(void *cls, | |||
695 | * @param peerreq request to free | 702 | * @param peerreq request to free |
696 | */ | 703 | */ |
697 | static void | 704 | static void |
698 | free_pending_request(struct PeerRequest *peerreq) | 705 | free_pending_request (struct PeerRequest *peerreq) |
699 | { | 706 | { |
700 | struct GSF_ConnectedPeer *cp = peerreq->cp; | 707 | struct GSF_ConnectedPeer *cp = peerreq->cp; |
701 | struct GSF_PendingRequestData *prd; | 708 | struct GSF_PendingRequestData *prd; |
702 | 709 | ||
703 | prd = GSF_pending_request_get_data_(peerreq->pr); | 710 | prd = GSF_pending_request_get_data_ (peerreq->pr); |
704 | if (NULL != peerreq->kill_task) | 711 | if (NULL != peerreq->kill_task) |
705 | { | 712 | { |
706 | GNUNET_SCHEDULER_cancel(peerreq->kill_task); | 713 | GNUNET_SCHEDULER_cancel (peerreq->kill_task); |
707 | peerreq->kill_task = NULL; | 714 | peerreq->kill_task = NULL; |
708 | } | 715 | } |
709 | GNUNET_STATISTICS_update(GSF_stats, | 716 | GNUNET_STATISTICS_update (GSF_stats, |
710 | gettext_noop("# P2P searches active"), | 717 | gettext_noop ("# P2P searches active"), |
711 | -1, | 718 | -1, |
712 | GNUNET_NO); | 719 | GNUNET_NO); |
713 | GNUNET_break(GNUNET_YES == | 720 | GNUNET_break (GNUNET_YES == |
714 | GNUNET_CONTAINER_multihashmap_remove(cp->request_map, | 721 | GNUNET_CONTAINER_multihashmap_remove (cp->request_map, |
715 | &prd->query, | 722 | &prd->query, |
716 | peerreq)); | 723 | peerreq)); |
717 | GNUNET_free(peerreq); | 724 | GNUNET_free (peerreq); |
718 | } | 725 | } |
719 | 726 | ||
720 | 727 | ||
@@ -727,16 +734,16 @@ free_pending_request(struct PeerRequest *peerreq) | |||
727 | * @return #GNUNET_YES (continue to iterate) | 734 | * @return #GNUNET_YES (continue to iterate) |
728 | */ | 735 | */ |
729 | static int | 736 | static int |
730 | cancel_pending_request(void *cls, | 737 | cancel_pending_request (void *cls, |
731 | const struct GNUNET_HashCode *query, | 738 | const struct GNUNET_HashCode *query, |
732 | void *value) | 739 | void *value) |
733 | { | 740 | { |
734 | struct PeerRequest *peerreq = value; | 741 | struct PeerRequest *peerreq = value; |
735 | struct GSF_PendingRequest *pr = peerreq->pr; | 742 | struct GSF_PendingRequest *pr = peerreq->pr; |
736 | 743 | ||
737 | free_pending_request(peerreq); | 744 | free_pending_request (peerreq); |
738 | GSF_pending_request_cancel_(pr, | 745 | GSF_pending_request_cancel_ (pr, |
739 | GNUNET_NO); | 746 | GNUNET_NO); |
740 | return GNUNET_OK; | 747 | return GNUNET_OK; |
741 | } | 748 | } |
742 | 749 | ||
@@ -747,17 +754,17 @@ cancel_pending_request(void *cls, | |||
747 | * @param cls the request to free | 754 | * @param cls the request to free |
748 | */ | 755 | */ |
749 | static void | 756 | static void |
750 | peer_request_destroy(void *cls) | 757 | peer_request_destroy (void *cls) |
751 | { | 758 | { |
752 | struct PeerRequest *peerreq = cls; | 759 | struct PeerRequest *peerreq = cls; |
753 | struct GSF_PendingRequest *pr = peerreq->pr; | 760 | struct GSF_PendingRequest *pr = peerreq->pr; |
754 | struct GSF_PendingRequestData *prd; | 761 | struct GSF_PendingRequestData *prd; |
755 | 762 | ||
756 | peerreq->kill_task = NULL; | 763 | peerreq->kill_task = NULL; |
757 | prd = GSF_pending_request_get_data_(pr); | 764 | prd = GSF_pending_request_get_data_ (pr); |
758 | cancel_pending_request(NULL, | 765 | cancel_pending_request (NULL, |
759 | &prd->query, | 766 | &prd->query, |
760 | peerreq); | 767 | peerreq); |
761 | } | 768 | } |
762 | 769 | ||
763 | 770 | ||
@@ -767,20 +774,20 @@ peer_request_destroy(void *cls) | |||
767 | * @param cls the `struct GSF_DelayedHandle` with the message | 774 | * @param cls the `struct GSF_DelayedHandle` with the message |
768 | */ | 775 | */ |
769 | static void | 776 | static void |
770 | transmit_delayed_now(void *cls) | 777 | transmit_delayed_now (void *cls) |
771 | { | 778 | { |
772 | struct GSF_DelayedHandle *dh = cls; | 779 | struct GSF_DelayedHandle *dh = cls; |
773 | struct GSF_ConnectedPeer *cp = dh->cp; | 780 | struct GSF_ConnectedPeer *cp = dh->cp; |
774 | 781 | ||
775 | GNUNET_CONTAINER_DLL_remove(cp->delayed_head, | 782 | GNUNET_CONTAINER_DLL_remove (cp->delayed_head, |
776 | cp->delayed_tail, | 783 | cp->delayed_tail, |
777 | dh); | 784 | dh); |
778 | cp->delay_queue_size--; | 785 | cp->delay_queue_size--; |
779 | GSF_peer_transmit_(cp, | 786 | GSF_peer_transmit_ (cp, |
780 | GNUNET_NO, | 787 | GNUNET_NO, |
781 | UINT32_MAX, | 788 | UINT32_MAX, |
782 | dh->env); | 789 | dh->env); |
783 | GNUNET_free(dh); | 790 | GNUNET_free (dh); |
784 | } | 791 | } |
785 | 792 | ||
786 | 793 | ||
@@ -790,20 +797,20 @@ transmit_delayed_now(void *cls) | |||
790 | * @return desired delay | 797 | * @return desired delay |
791 | */ | 798 | */ |
792 | static struct GNUNET_TIME_Relative | 799 | static struct GNUNET_TIME_Relative |
793 | get_randomized_delay() | 800 | get_randomized_delay () |
794 | { | 801 | { |
795 | struct GNUNET_TIME_Relative ret; | 802 | struct GNUNET_TIME_Relative ret; |
796 | 803 | ||
797 | ret = | 804 | ret = |
798 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, | 805 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, |
799 | GNUNET_CRYPTO_random_u32 | 806 | GNUNET_CRYPTO_random_u32 |
800 | (GNUNET_CRYPTO_QUALITY_WEAK, | 807 | (GNUNET_CRYPTO_QUALITY_WEAK, |
801 | 2 * GSF_avg_latency.rel_value_us + 1)); | 808 | 2 * GSF_avg_latency.rel_value_us + 1)); |
802 | #if INSANE_STATISTICS | 809 | #if INSANE_STATISTICS |
803 | GNUNET_STATISTICS_update(GSF_stats, | 810 | GNUNET_STATISTICS_update (GSF_stats, |
804 | gettext_noop | 811 | gettext_noop |
805 | ("# artificial delays introduced (ms)"), | 812 | ("# artificial delays introduced (ms)"), |
806 | ret.rel_value_us / 1000LL, GNUNET_NO); | 813 | ret.rel_value_us / 1000LL, GNUNET_NO); |
807 | #endif | 814 | #endif |
808 | return ret; | 815 | return ret; |
809 | } | 816 | } |
@@ -828,15 +835,15 @@ get_randomized_delay() | |||
828 | * @param data_len number of bytes in @a data | 835 | * @param data_len number of bytes in @a data |
829 | */ | 836 | */ |
830 | static void | 837 | static void |
831 | handle_p2p_reply(void *cls, | 838 | handle_p2p_reply (void *cls, |
832 | enum GNUNET_BLOCK_EvaluationResult eval, | 839 | enum GNUNET_BLOCK_EvaluationResult eval, |
833 | struct GSF_PendingRequest *pr, | 840 | struct GSF_PendingRequest *pr, |
834 | uint32_t reply_anonymity_level, | 841 | uint32_t reply_anonymity_level, |
835 | struct GNUNET_TIME_Absolute expiration, | 842 | struct GNUNET_TIME_Absolute expiration, |
836 | struct GNUNET_TIME_Absolute last_transmission, | 843 | struct GNUNET_TIME_Absolute last_transmission, |
837 | enum GNUNET_BLOCK_Type type, | 844 | enum GNUNET_BLOCK_Type type, |
838 | const void *data, | 845 | const void *data, |
839 | size_t data_len) | 846 | size_t data_len) |
840 | { | 847 | { |
841 | struct PeerRequest *peerreq = cls; | 848 | struct PeerRequest *peerreq = cls; |
842 | struct GSF_ConnectedPeer *cp = peerreq->cp; | 849 | struct GSF_ConnectedPeer *cp = peerreq->cp; |
@@ -845,96 +852,98 @@ handle_p2p_reply(void *cls, | |||
845 | struct PutMessage *pm; | 852 | struct PutMessage *pm; |
846 | size_t msize; | 853 | size_t msize; |
847 | 854 | ||
848 | GNUNET_assert(data_len + sizeof(struct PutMessage) < | 855 | GNUNET_assert (data_len + sizeof(struct PutMessage) < |
849 | GNUNET_MAX_MESSAGE_SIZE); | 856 | GNUNET_MAX_MESSAGE_SIZE); |
850 | GNUNET_assert(peerreq->pr == pr); | 857 | GNUNET_assert (peerreq->pr == pr); |
851 | prd = GSF_pending_request_get_data_(pr); | 858 | prd = GSF_pending_request_get_data_ (pr); |
852 | if (NULL == data) | 859 | if (NULL == data) |
853 | { | 860 | { |
854 | free_pending_request(peerreq); | 861 | free_pending_request (peerreq); |
855 | return; | 862 | return; |
856 | } | 863 | } |
857 | GNUNET_break(GNUNET_BLOCK_TYPE_ANY != type); | 864 | GNUNET_break (GNUNET_BLOCK_TYPE_ANY != type); |
858 | if ((prd->type != type) && (GNUNET_BLOCK_TYPE_ANY != prd->type)) | 865 | if ((prd->type != type) && (GNUNET_BLOCK_TYPE_ANY != prd->type)) |
859 | { | 866 | { |
860 | GNUNET_STATISTICS_update(GSF_stats, | 867 | GNUNET_STATISTICS_update (GSF_stats, |
861 | gettext_noop | 868 | gettext_noop |
862 | ("# replies dropped due to type mismatch"), | 869 | ("# replies dropped due to type mismatch"), |
863 | 1, GNUNET_NO); | 870 | 1, GNUNET_NO); |
864 | return; | 871 | return; |
865 | } | 872 | } |
866 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 873 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
867 | "Transmitting result for query `%s' to peer\n", | 874 | "Transmitting result for query `%s' to peer\n", |
868 | GNUNET_h2s(&prd->query)); | 875 | GNUNET_h2s (&prd->query)); |
869 | GNUNET_STATISTICS_update(GSF_stats, | 876 | GNUNET_STATISTICS_update (GSF_stats, |
870 | gettext_noop("# replies received for other peers"), | 877 | gettext_noop ("# replies received for other peers"), |
871 | 1, GNUNET_NO); | 878 | 1, GNUNET_NO); |
872 | msize = sizeof(struct PutMessage) + data_len; | 879 | msize = sizeof(struct PutMessage) + data_len; |
873 | if (msize >= GNUNET_MAX_MESSAGE_SIZE) | 880 | if (msize >= GNUNET_MAX_MESSAGE_SIZE) |
874 | { | 881 | { |
875 | GNUNET_break(0); | 882 | GNUNET_break (0); |
876 | return; | 883 | return; |
877 | } | 884 | } |
878 | if ((UINT32_MAX != reply_anonymity_level) && (reply_anonymity_level > 1)) | 885 | if ((UINT32_MAX != reply_anonymity_level) && (reply_anonymity_level > 1)) |
886 | { | ||
887 | if (reply_anonymity_level - 1 > GSF_cover_content_count) | ||
879 | { | 888 | { |
880 | if (reply_anonymity_level - 1 > GSF_cover_content_count) | 889 | GNUNET_STATISTICS_update (GSF_stats, |
881 | { | 890 | gettext_noop |
882 | GNUNET_STATISTICS_update(GSF_stats, | 891 | ( |
883 | gettext_noop | 892 | "# replies dropped due to insufficient cover traffic"), |
884 | ("# replies dropped due to insufficient cover traffic"), | 893 | 1, GNUNET_NO); |
885 | 1, GNUNET_NO); | 894 | return; |
886 | return; | ||
887 | } | ||
888 | GSF_cover_content_count -= (reply_anonymity_level - 1); | ||
889 | } | 895 | } |
890 | 896 | GSF_cover_content_count -= (reply_anonymity_level - 1); | |
891 | env = GNUNET_MQ_msg_extra(pm, | 897 | } |
892 | data_len, | 898 | |
893 | GNUNET_MESSAGE_TYPE_FS_PUT); | 899 | env = GNUNET_MQ_msg_extra (pm, |
894 | pm->type = htonl(type); | 900 | data_len, |
895 | pm->expiration = GNUNET_TIME_absolute_hton(expiration); | 901 | GNUNET_MESSAGE_TYPE_FS_PUT); |
896 | GNUNET_memcpy(&pm[1], | 902 | pm->type = htonl (type); |
897 | data, | 903 | pm->expiration = GNUNET_TIME_absolute_hton (expiration); |
898 | data_len); | 904 | GNUNET_memcpy (&pm[1], |
905 | data, | ||
906 | data_len); | ||
899 | if ((UINT32_MAX != reply_anonymity_level) && | 907 | if ((UINT32_MAX != reply_anonymity_level) && |
900 | (0 != reply_anonymity_level) && | 908 | (0 != reply_anonymity_level) && |
901 | (GNUNET_YES == GSF_enable_randomized_delays)) | 909 | (GNUNET_YES == GSF_enable_randomized_delays)) |
902 | { | 910 | { |
903 | struct GSF_DelayedHandle *dh; | 911 | struct GSF_DelayedHandle *dh; |
904 | 912 | ||
905 | dh = GNUNET_new(struct GSF_DelayedHandle); | 913 | dh = GNUNET_new (struct GSF_DelayedHandle); |
906 | dh->cp = cp; | 914 | dh->cp = cp; |
907 | dh->env = env; | 915 | dh->env = env; |
908 | dh->msize = msize; | 916 | dh->msize = msize; |
909 | GNUNET_CONTAINER_DLL_insert(cp->delayed_head, | 917 | GNUNET_CONTAINER_DLL_insert (cp->delayed_head, |
910 | cp->delayed_tail, | 918 | cp->delayed_tail, |
911 | dh); | 919 | dh); |
912 | cp->delay_queue_size++; | 920 | cp->delay_queue_size++; |
913 | dh->delay_task = | 921 | dh->delay_task = |
914 | GNUNET_SCHEDULER_add_delayed(get_randomized_delay(), | 922 | GNUNET_SCHEDULER_add_delayed (get_randomized_delay (), |
915 | &transmit_delayed_now, | 923 | &transmit_delayed_now, |
916 | dh); | 924 | dh); |
917 | } | 925 | } |
918 | else | 926 | else |
919 | { | 927 | { |
920 | GSF_peer_transmit_(cp, | 928 | GSF_peer_transmit_ (cp, |
921 | GNUNET_NO, | 929 | GNUNET_NO, |
922 | UINT32_MAX, | 930 | UINT32_MAX, |
923 | env); | 931 | env); |
924 | } | 932 | } |
925 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) | 933 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) |
926 | return; | 934 | return; |
927 | if (NULL == peerreq->kill_task) | 935 | if (NULL == peerreq->kill_task) |
928 | { | 936 | { |
929 | GNUNET_STATISTICS_update(GSF_stats, | 937 | GNUNET_STATISTICS_update (GSF_stats, |
930 | gettext_noop | 938 | gettext_noop |
931 | ("# P2P searches destroyed due to ultimate reply"), | 939 | ( |
932 | 1, | 940 | "# P2P searches destroyed due to ultimate reply"), |
933 | GNUNET_NO); | 941 | 1, |
934 | peerreq->kill_task = | 942 | GNUNET_NO); |
935 | GNUNET_SCHEDULER_add_now(&peer_request_destroy, | 943 | peerreq->kill_task = |
936 | peerreq); | 944 | GNUNET_SCHEDULER_add_now (&peer_request_destroy, |
937 | } | 945 | peerreq); |
946 | } | ||
938 | } | 947 | } |
939 | 948 | ||
940 | 949 | ||
@@ -947,31 +956,31 @@ handle_p2p_reply(void *cls, | |||
947 | * @returns the actual change in respect (positive or negative) | 956 | * @returns the actual change in respect (positive or negative) |
948 | */ | 957 | */ |
949 | static int | 958 | static int |
950 | change_peer_respect(struct GSF_ConnectedPeer *cp, int value) | 959 | change_peer_respect (struct GSF_ConnectedPeer *cp, int value) |
951 | { | 960 | { |
952 | if (0 == value) | 961 | if (0 == value) |
953 | return 0; | 962 | return 0; |
954 | GNUNET_assert(NULL != cp); | 963 | GNUNET_assert (NULL != cp); |
955 | if (value > 0) | 964 | if (value > 0) |
965 | { | ||
966 | if (cp->ppd.respect + value < cp->ppd.respect) | ||
956 | { | 967 | { |
957 | if (cp->ppd.respect + value < cp->ppd.respect) | 968 | value = UINT32_MAX - cp->ppd.respect; |
958 | { | 969 | cp->ppd.respect = UINT32_MAX; |
959 | value = UINT32_MAX - cp->ppd.respect; | ||
960 | cp->ppd.respect = UINT32_MAX; | ||
961 | } | ||
962 | else | ||
963 | cp->ppd.respect += value; | ||
964 | } | 970 | } |
971 | else | ||
972 | cp->ppd.respect += value; | ||
973 | } | ||
965 | else | 974 | else |
975 | { | ||
976 | if (cp->ppd.respect < -value) | ||
966 | { | 977 | { |
967 | if (cp->ppd.respect < -value) | 978 | value = -cp->ppd.respect; |
968 | { | 979 | cp->ppd.respect = 0; |
969 | value = -cp->ppd.respect; | ||
970 | cp->ppd.respect = 0; | ||
971 | } | ||
972 | else | ||
973 | cp->ppd.respect += value; | ||
974 | } | 980 | } |
981 | else | ||
982 | cp->ppd.respect += value; | ||
983 | } | ||
975 | return value; | 984 | return value; |
976 | } | 985 | } |
977 | 986 | ||
@@ -985,58 +994,59 @@ change_peer_respect(struct GSF_ConnectedPeer *cp, int value) | |||
985 | * @return effective priority | 994 | * @return effective priority |
986 | */ | 995 | */ |
987 | static int32_t | 996 | static int32_t |
988 | bound_priority(uint32_t prio_in, | 997 | bound_priority (uint32_t prio_in, |
989 | struct GSF_ConnectedPeer *cp) | 998 | struct GSF_ConnectedPeer *cp) |
990 | { | 999 | { |
991 | #define N ((double)128.0) | 1000 | #define N ((double) 128.0) |
992 | uint32_t ret; | 1001 | uint32_t ret; |
993 | double rret; | 1002 | double rret; |
994 | int ld; | 1003 | int ld; |
995 | 1004 | ||
996 | ld = GSF_test_get_load_too_high_(0); | 1005 | ld = GSF_test_get_load_too_high_ (0); |
997 | if (GNUNET_SYSERR == ld) | 1006 | if (GNUNET_SYSERR == ld) |
998 | { | 1007 | { |
999 | #if INSANE_STATISTICS | 1008 | #if INSANE_STATISTICS |
1000 | GNUNET_STATISTICS_update(GSF_stats, | 1009 | GNUNET_STATISTICS_update (GSF_stats, |
1001 | gettext_noop | 1010 | gettext_noop |
1002 | ("# requests done for free (low load)"), 1, | 1011 | ("# requests done for free (low load)"), 1, |
1003 | GNUNET_NO); | 1012 | GNUNET_NO); |
1004 | #endif | 1013 | #endif |
1005 | return 0; /* excess resources */ | 1014 | return 0; /* excess resources */ |
1006 | } | 1015 | } |
1007 | if (prio_in > INT32_MAX) | 1016 | if (prio_in > INT32_MAX) |
1008 | prio_in = INT32_MAX; | 1017 | prio_in = INT32_MAX; |
1009 | ret = -change_peer_respect(cp, -(int)prio_in); | 1018 | ret = -change_peer_respect (cp, -(int) prio_in); |
1010 | if (ret > 0) | 1019 | if (ret > 0) |
1011 | { | 1020 | { |
1012 | if (ret > GSF_current_priorities + N) | 1021 | if (ret > GSF_current_priorities + N) |
1013 | rret = GSF_current_priorities + N; | 1022 | rret = GSF_current_priorities + N; |
1014 | else | 1023 | else |
1015 | rret = ret; | 1024 | rret = ret; |
1016 | GSF_current_priorities = (GSF_current_priorities * (N - 1) + rret) / N; | 1025 | GSF_current_priorities = (GSF_current_priorities * (N - 1) + rret) / N; |
1017 | } | 1026 | } |
1018 | if ((GNUNET_YES == ld) && (ret > 0)) | 1027 | if ((GNUNET_YES == ld) && (ret > 0)) |
1019 | { | 1028 | { |
1020 | /* try with charging */ | 1029 | /* try with charging */ |
1021 | ld = GSF_test_get_load_too_high_(ret); | 1030 | ld = GSF_test_get_load_too_high_ (ret); |
1022 | } | 1031 | } |
1023 | if (GNUNET_YES == ld) | 1032 | if (GNUNET_YES == ld) |
1024 | { | 1033 | { |
1025 | GNUNET_STATISTICS_update(GSF_stats, | 1034 | GNUNET_STATISTICS_update (GSF_stats, |
1026 | gettext_noop | 1035 | gettext_noop |
1027 | ("# request dropped, priority insufficient"), 1, | 1036 | ("# request dropped, priority insufficient"), 1, |
1028 | GNUNET_NO); | 1037 | GNUNET_NO); |
1029 | /* undo charge */ | 1038 | /* undo charge */ |
1030 | change_peer_respect(cp, (int)ret); | 1039 | change_peer_respect (cp, (int) ret); |
1031 | return -1; /* not enough resources */ | 1040 | return -1; /* not enough resources */ |
1032 | } | 1041 | } |
1033 | else | 1042 | else |
1034 | { | 1043 | { |
1035 | GNUNET_STATISTICS_update(GSF_stats, | 1044 | GNUNET_STATISTICS_update (GSF_stats, |
1036 | gettext_noop | 1045 | gettext_noop |
1037 | ("# requests done for a price (normal load)"), 1, | 1046 | ("# requests done for a price (normal load)"), |
1038 | GNUNET_NO); | 1047 | 1, |
1039 | } | 1048 | GNUNET_NO); |
1049 | } | ||
1040 | #undef N | 1050 | #undef N |
1041 | return ret; | 1051 | return ret; |
1042 | } | 1052 | } |
@@ -1052,20 +1062,20 @@ bound_priority(uint32_t prio_in, | |||
1052 | * otherwise the ttl-limit for the given @a prio | 1062 | * otherwise the ttl-limit for the given @a prio |
1053 | */ | 1063 | */ |
1054 | static int32_t | 1064 | static int32_t |
1055 | bound_ttl(int32_t ttl_in, | 1065 | bound_ttl (int32_t ttl_in, |
1056 | uint32_t prio) | 1066 | uint32_t prio) |
1057 | { | 1067 | { |
1058 | unsigned long long allowed; | 1068 | unsigned long long allowed; |
1059 | 1069 | ||
1060 | if (ttl_in <= 0) | 1070 | if (ttl_in <= 0) |
1061 | return ttl_in; | 1071 | return ttl_in; |
1062 | allowed = ((unsigned long long)prio) * TTL_DECREMENT / 1000; | 1072 | allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000; |
1063 | if (ttl_in > allowed) | 1073 | if (ttl_in > allowed) |
1064 | { | 1074 | { |
1065 | if (allowed >= (1 << 30)) | 1075 | if (allowed >= (1 << 30)) |
1066 | return 1 << 30; | 1076 | return 1 << 30; |
1067 | return allowed; | 1077 | return allowed; |
1068 | } | 1078 | } |
1069 | return ttl_in; | 1079 | return ttl_in; |
1070 | } | 1080 | } |
1071 | 1081 | ||
@@ -1073,7 +1083,8 @@ bound_ttl(int32_t ttl_in, | |||
1073 | /** | 1083 | /** |
1074 | * Closure for #test_exist_cb(). | 1084 | * Closure for #test_exist_cb(). |
1075 | */ | 1085 | */ |
1076 | struct TestExistClosure { | 1086 | struct TestExistClosure |
1087 | { | ||
1077 | /** | 1088 | /** |
1078 | * Priority of the incoming request. | 1089 | * Priority of the incoming request. |
1079 | */ | 1090 | */ |
@@ -1107,9 +1118,9 @@ struct TestExistClosure { | |||
1107 | * #GNUNET_NO if we successfully merged | 1118 | * #GNUNET_NO if we successfully merged |
1108 | */ | 1119 | */ |
1109 | static int | 1120 | static int |
1110 | test_exist_cb(void *cls, | 1121 | test_exist_cb (void *cls, |
1111 | const struct GNUNET_HashCode *hc, | 1122 | const struct GNUNET_HashCode *hc, |
1112 | void *value) | 1123 | void *value) |
1113 | { | 1124 | { |
1114 | struct TestExistClosure *tec = cls; | 1125 | struct TestExistClosure *tec = cls; |
1115 | struct PeerRequest *peerreq = value; | 1126 | struct PeerRequest *peerreq = value; |
@@ -1117,28 +1128,28 @@ test_exist_cb(void *cls, | |||
1117 | struct GSF_PendingRequestData *prd; | 1128 | struct GSF_PendingRequestData *prd; |
1118 | 1129 | ||
1119 | pr = peerreq->pr; | 1130 | pr = peerreq->pr; |
1120 | prd = GSF_pending_request_get_data_(pr); | 1131 | prd = GSF_pending_request_get_data_ (pr); |
1121 | if (prd->type != tec->type) | 1132 | if (prd->type != tec->type) |
1122 | return GNUNET_YES; | 1133 | return GNUNET_YES; |
1123 | if (prd->ttl.abs_value_us >= | 1134 | if (prd->ttl.abs_value_us >= |
1124 | GNUNET_TIME_absolute_get().abs_value_us + tec->ttl * 1000LL) | 1135 | GNUNET_TIME_absolute_get ().abs_value_us + tec->ttl * 1000LL) |
1125 | { | 1136 | { |
1126 | /* existing request has higher TTL, drop new one! */ | 1137 | /* existing request has higher TTL, drop new one! */ |
1127 | prd->priority += tec->priority; | 1138 | prd->priority += tec->priority; |
1128 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1129 | "Have existing request with higher TTL, dropping new request.\n"); | 1140 | "Have existing request with higher TTL, dropping new request.\n"); |
1130 | GNUNET_STATISTICS_update(GSF_stats, | 1141 | GNUNET_STATISTICS_update (GSF_stats, |
1131 | gettext_noop | 1142 | gettext_noop |
1132 | ("# requests dropped due to higher-TTL request"), | 1143 | ("# requests dropped due to higher-TTL request"), |
1133 | 1, GNUNET_NO); | 1144 | 1, GNUNET_NO); |
1134 | tec->finished = GNUNET_YES; | 1145 | tec->finished = GNUNET_YES; |
1135 | return GNUNET_NO; | 1146 | return GNUNET_NO; |
1136 | } | 1147 | } |
1137 | /* existing request has lower TTL, drop old one! */ | 1148 | /* existing request has lower TTL, drop old one! */ |
1138 | tec->priority += prd->priority; | 1149 | tec->priority += prd->priority; |
1139 | free_pending_request(peerreq); | 1150 | free_pending_request (peerreq); |
1140 | GSF_pending_request_cancel_(pr, | 1151 | GSF_pending_request_cancel_ (pr, |
1141 | GNUNET_YES); | 1152 | GNUNET_YES); |
1142 | return GNUNET_NO; | 1153 | return GNUNET_NO; |
1143 | } | 1154 | } |
1144 | 1155 | ||
@@ -1153,8 +1164,8 @@ test_exist_cb(void *cls, | |||
1153 | * @param gm the GET message | 1164 | * @param gm the GET message |
1154 | */ | 1165 | */ |
1155 | void | 1166 | void |
1156 | handle_p2p_get(void *cls, | 1167 | handle_p2p_get (void *cls, |
1157 | const struct GetMessage *gm) | 1168 | const struct GetMessage *gm) |
1158 | { | 1169 | { |
1159 | struct GSF_ConnectedPeer *cps = cls; | 1170 | struct GSF_ConnectedPeer *cps = cls; |
1160 | struct PeerRequest *peerreq; | 1171 | struct PeerRequest *peerreq; |
@@ -1172,167 +1183,172 @@ handle_p2p_get(void *cls, | |||
1172 | GNUNET_PEER_Id spid; | 1183 | GNUNET_PEER_Id spid; |
1173 | const struct GSF_PendingRequestData *prd; | 1184 | const struct GSF_PendingRequestData *prd; |
1174 | 1185 | ||
1175 | msize = ntohs(gm->header.size); | 1186 | msize = ntohs (gm->header.size); |
1176 | tec.type = ntohl(gm->type); | 1187 | tec.type = ntohl (gm->type); |
1177 | bm = ntohl(gm->hash_bitmap); | 1188 | bm = ntohl (gm->hash_bitmap); |
1178 | bits = 0; | 1189 | bits = 0; |
1179 | while (bm > 0) | 1190 | while (bm > 0) |
1180 | { | 1191 | { |
1181 | if (1 == (bm & 1)) | 1192 | if (1 == (bm & 1)) |
1182 | bits++; | 1193 | bits++; |
1183 | bm >>= 1; | 1194 | bm >>= 1; |
1184 | } | 1195 | } |
1185 | opt = (const struct GNUNET_PeerIdentity *)&gm[1]; | 1196 | opt = (const struct GNUNET_PeerIdentity *) &gm[1]; |
1186 | bfsize = msize - sizeof(struct GetMessage) - bits * sizeof(struct GNUNET_PeerIdentity); | 1197 | bfsize = msize - sizeof(struct GetMessage) - bits * sizeof(struct |
1187 | GNUNET_STATISTICS_update(GSF_stats, | 1198 | GNUNET_PeerIdentity); |
1188 | gettext_noop | 1199 | GNUNET_STATISTICS_update (GSF_stats, |
1189 | ("# GET requests received (from other peers)"), | 1200 | gettext_noop |
1190 | 1, | 1201 | ("# GET requests received (from other peers)"), |
1191 | GNUNET_NO); | 1202 | 1, |
1203 | GNUNET_NO); | ||
1192 | GSF_cover_query_count++; | 1204 | GSF_cover_query_count++; |
1193 | bm = ntohl(gm->hash_bitmap); | 1205 | bm = ntohl (gm->hash_bitmap); |
1194 | bits = 0; | 1206 | bits = 0; |
1195 | if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) | 1207 | if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) |
1196 | cp = GSF_peer_get_(&opt[bits++]); | 1208 | cp = GSF_peer_get_ (&opt[bits++]); |
1197 | else | 1209 | else |
1198 | cp = cps; | 1210 | cp = cps; |
1199 | if (NULL == cp) | 1211 | if (NULL == cp) |
1200 | { | 1212 | { |
1201 | if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) | 1213 | if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) |
1202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1203 | "Failed to find RETURN-TO peer `%s' in connection set. Dropping query.\n", | 1215 | "Failed to find RETURN-TO peer `%s' in connection set. Dropping query.\n", |
1204 | GNUNET_i2s(&opt[bits - 1])); | 1216 | GNUNET_i2s (&opt[bits - 1])); |
1205 | 1217 | ||
1206 | else | 1218 | else |
1207 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1208 | "Failed to find peer `%s' in connection set. Dropping query.\n", | 1220 | "Failed to find peer `%s' in connection set. Dropping query.\n", |
1209 | GNUNET_i2s(cps->ppd.peer)); | 1221 | GNUNET_i2s (cps->ppd.peer)); |
1210 | GNUNET_STATISTICS_update(GSF_stats, | 1222 | GNUNET_STATISTICS_update (GSF_stats, |
1211 | gettext_noop | 1223 | gettext_noop |
1212 | ("# requests dropped due to missing reverse route"), | 1224 | ( |
1213 | 1, | 1225 | "# requests dropped due to missing reverse route"), |
1214 | GNUNET_NO); | 1226 | 1, |
1215 | return; | 1227 | GNUNET_NO); |
1216 | } | 1228 | return; |
1217 | unsigned int queue_size = GNUNET_MQ_get_length(cp->mq); | 1229 | } |
1230 | unsigned int queue_size = GNUNET_MQ_get_length (cp->mq); | ||
1218 | queue_size += cp->ppd.pending_replies + cp->delay_queue_size; | 1231 | queue_size += cp->ppd.pending_replies + cp->delay_queue_size; |
1219 | if (queue_size > MAX_QUEUE_PER_PEER) | 1232 | if (queue_size > MAX_QUEUE_PER_PEER) |
1220 | { | 1233 | { |
1221 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1222 | "Peer `%s' has too many replies queued already. Dropping query.\n", | 1235 | "Peer `%s' has too many replies queued already. Dropping query.\n", |
1223 | GNUNET_i2s(cps->ppd.peer)); | 1236 | GNUNET_i2s (cps->ppd.peer)); |
1224 | GNUNET_STATISTICS_update(GSF_stats, | 1237 | GNUNET_STATISTICS_update (GSF_stats, |
1225 | gettext_noop("# requests dropped due to full reply queue"), | 1238 | gettext_noop ( |
1226 | 1, | 1239 | "# requests dropped due to full reply queue"), |
1227 | GNUNET_NO); | 1240 | 1, |
1228 | return; | 1241 | GNUNET_NO); |
1229 | } | 1242 | return; |
1243 | } | ||
1230 | /* note that we can really only check load here since otherwise | 1244 | /* note that we can really only check load here since otherwise |
1231 | * peers could find out that we are overloaded by not being | 1245 | * peers could find out that we are overloaded by not being |
1232 | * disconnected after sending us a malformed query... */ | 1246 | * disconnected after sending us a malformed query... */ |
1233 | tec.priority = bound_priority(ntohl(gm->priority), | 1247 | tec.priority = bound_priority (ntohl (gm->priority), |
1234 | cps); | 1248 | cps); |
1235 | if (tec.priority < 0) | 1249 | if (tec.priority < 0) |
1236 | { | 1250 | { |
1237 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1238 | "Dropping query from `%s', this peer is too busy.\n", | 1252 | "Dropping query from `%s', this peer is too busy.\n", |
1239 | GNUNET_i2s(cps->ppd.peer)); | 1253 | GNUNET_i2s (cps->ppd.peer)); |
1240 | return; | 1254 | return; |
1241 | } | 1255 | } |
1242 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1243 | "Received request for `%s' of type %u from peer `%s' with flags %u\n", | 1257 | "Received request for `%s' of type %u from peer `%s' with flags %u\n", |
1244 | GNUNET_h2s(&gm->query), | 1258 | GNUNET_h2s (&gm->query), |
1245 | (unsigned int)tec.type, | 1259 | (unsigned int) tec.type, |
1246 | GNUNET_i2s(cps->ppd.peer), | 1260 | GNUNET_i2s (cps->ppd.peer), |
1247 | (unsigned int)bm); | 1261 | (unsigned int) bm); |
1248 | target = | 1262 | target = |
1249 | (0 != | 1263 | (0 != |
1250 | (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? (&opt[bits++]) : NULL; | 1264 | (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? (&opt[bits++]) : NULL; |
1251 | options = GSF_PRO_DEFAULTS; | 1265 | options = GSF_PRO_DEFAULTS; |
1252 | spid = 0; | 1266 | spid = 0; |
1253 | if ((GNUNET_LOAD_get_load(cp->ppd.transmission_delay) > 3 * (1 + tec.priority)) | 1267 | if ((GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 |
1254 | || (GNUNET_LOAD_get_average(cp->ppd.transmission_delay) > | 1268 | + tec.priority)) |
1255 | GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value_us * 2 + | 1269 | || (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) > |
1256 | GNUNET_LOAD_get_average(GSF_rt_entry_lifetime))) | 1270 | GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value_us * 2 |
1257 | { | 1271 | + GNUNET_LOAD_get_average (GSF_rt_entry_lifetime))) |
1258 | /* don't have BW to send to peer, or would likely take longer than we have for it, | 1272 | { |
1259 | * so at best indirect the query */ | 1273 | /* don't have BW to send to peer, or would likely take longer than we have for it, |
1260 | tec.priority = 0; | 1274 | * so at best indirect the query */ |
1261 | options |= GSF_PRO_FORWARD_ONLY; | 1275 | tec.priority = 0; |
1262 | spid = GNUNET_PEER_intern(cps->ppd.peer); | 1276 | options |= GSF_PRO_FORWARD_ONLY; |
1263 | GNUNET_assert(0 != spid); | 1277 | spid = GNUNET_PEER_intern (cps->ppd.peer); |
1264 | } | 1278 | GNUNET_assert (0 != spid); |
1265 | tec.ttl = bound_ttl(ntohl(gm->ttl), | 1279 | } |
1266 | tec.priority); | 1280 | tec.ttl = bound_ttl (ntohl (gm->ttl), |
1281 | tec.priority); | ||
1267 | /* decrement ttl (always) */ | 1282 | /* decrement ttl (always) */ |
1268 | ttl_decrement = | 1283 | ttl_decrement = |
1269 | 2 * TTL_DECREMENT + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1284 | 2 * TTL_DECREMENT + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1270 | TTL_DECREMENT); | 1285 | TTL_DECREMENT); |
1271 | if ((tec.ttl < 0) && | 1286 | if ((tec.ttl < 0) && |
1272 | (((int32_t)(tec.ttl - ttl_decrement)) > 0)) | 1287 | (((int32_t) (tec.ttl - ttl_decrement)) > 0)) |
1273 | { | 1288 | { |
1274 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1275 | "Dropping query from `%s' due to TTL underflow (%d - %u).\n", | 1290 | "Dropping query from `%s' due to TTL underflow (%d - %u).\n", |
1276 | GNUNET_i2s(cps->ppd.peer), | 1291 | GNUNET_i2s (cps->ppd.peer), |
1277 | tec.ttl, | 1292 | tec.ttl, |
1278 | ttl_decrement); | 1293 | ttl_decrement); |
1279 | GNUNET_STATISTICS_update(GSF_stats, | 1294 | GNUNET_STATISTICS_update (GSF_stats, |
1280 | gettext_noop | 1295 | gettext_noop |
1281 | ("# requests dropped due TTL underflow"), 1, | 1296 | ("# requests dropped due TTL underflow"), 1, |
1282 | GNUNET_NO); | 1297 | GNUNET_NO); |
1283 | /* integer underflow => drop (should be very rare)! */ | 1298 | /* integer underflow => drop (should be very rare)! */ |
1284 | return; | 1299 | return; |
1285 | } | 1300 | } |
1286 | tec.ttl -= ttl_decrement; | 1301 | tec.ttl -= ttl_decrement; |
1287 | 1302 | ||
1288 | /* test if the request already exists */ | 1303 | /* test if the request already exists */ |
1289 | tec.finished = GNUNET_NO; | 1304 | tec.finished = GNUNET_NO; |
1290 | GNUNET_CONTAINER_multihashmap_get_multiple(cp->request_map, | 1305 | GNUNET_CONTAINER_multihashmap_get_multiple (cp->request_map, |
1291 | &gm->query, | 1306 | &gm->query, |
1292 | &test_exist_cb, | 1307 | &test_exist_cb, |
1293 | &tec); | 1308 | &tec); |
1294 | if (GNUNET_YES == tec.finished) | 1309 | if (GNUNET_YES == tec.finished) |
1295 | return; /* merged into existing request, we're done */ | 1310 | return; /* merged into existing request, we're done */ |
1296 | 1311 | ||
1297 | peerreq = GNUNET_new(struct PeerRequest); | 1312 | peerreq = GNUNET_new (struct PeerRequest); |
1298 | peerreq->cp = cp; | 1313 | peerreq->cp = cp; |
1299 | pr = GSF_pending_request_create_(options, | 1314 | pr = GSF_pending_request_create_ (options, |
1300 | tec.type, | 1315 | tec.type, |
1301 | &gm->query, | 1316 | &gm->query, |
1302 | target, | 1317 | target, |
1303 | (bfsize > 0) | 1318 | (bfsize > 0) |
1304 | ? (const char *)&opt[bits] | 1319 | ? (const char *) &opt[bits] |
1305 | : NULL, | 1320 | : NULL, |
1306 | bfsize, | 1321 | bfsize, |
1307 | ntohl(gm->filter_mutator), | 1322 | ntohl (gm->filter_mutator), |
1308 | 1 /* anonymity */, | 1323 | 1 /* anonymity */, |
1309 | (uint32_t)tec.priority, | 1324 | (uint32_t) tec.priority, |
1310 | tec.ttl, | 1325 | tec.ttl, |
1311 | spid, | 1326 | spid, |
1312 | GNUNET_PEER_intern(cps->ppd.peer), | 1327 | GNUNET_PEER_intern (cps->ppd.peer), |
1313 | NULL, 0, /* replies_seen */ | 1328 | NULL, 0, /* replies_seen */ |
1314 | &handle_p2p_reply, | 1329 | &handle_p2p_reply, |
1315 | peerreq); | 1330 | peerreq); |
1316 | GNUNET_assert(NULL != pr); | 1331 | GNUNET_assert (NULL != pr); |
1317 | prd = GSF_pending_request_get_data_(pr); | 1332 | prd = GSF_pending_request_get_data_ (pr); |
1318 | peerreq->pr = pr; | 1333 | peerreq->pr = pr; |
1319 | GNUNET_break(GNUNET_OK == | 1334 | GNUNET_break (GNUNET_OK == |
1320 | GNUNET_CONTAINER_multihashmap_put(cp->request_map, | 1335 | GNUNET_CONTAINER_multihashmap_put (cp->request_map, |
1321 | &prd->query, | 1336 | &prd->query, |
1322 | peerreq, | 1337 | peerreq, |
1323 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 1338 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
1324 | GNUNET_STATISTICS_update(GSF_stats, | 1339 | GNUNET_STATISTICS_update (GSF_stats, |
1325 | gettext_noop("# P2P query messages received and processed"), | 1340 | gettext_noop ( |
1326 | 1, | 1341 | "# P2P query messages received and processed"), |
1327 | GNUNET_NO); | 1342 | 1, |
1328 | GNUNET_STATISTICS_update(GSF_stats, | 1343 | GNUNET_NO); |
1329 | gettext_noop("# P2P searches active"), | 1344 | GNUNET_STATISTICS_update (GSF_stats, |
1330 | 1, | 1345 | gettext_noop ("# P2P searches active"), |
1331 | GNUNET_NO); | 1346 | 1, |
1332 | GSF_pending_request_get_data_(pr)->has_started = GNUNET_YES; | 1347 | GNUNET_NO); |
1333 | GSF_local_lookup_(pr, | 1348 | GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES; |
1334 | &GSF_consider_forwarding, | 1349 | GSF_local_lookup_ (pr, |
1335 | NULL); | 1350 | &GSF_consider_forwarding, |
1351 | NULL); | ||
1336 | } | 1352 | } |
1337 | 1353 | ||
1338 | 1354 | ||
@@ -1349,17 +1365,17 @@ handle_p2p_get(void *cls, | |||
1349 | * @param env message to send | 1365 | * @param env message to send |
1350 | */ | 1366 | */ |
1351 | void | 1367 | void |
1352 | GSF_peer_transmit_(struct GSF_ConnectedPeer *cp, | 1368 | GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, |
1353 | int is_query, | 1369 | int is_query, |
1354 | uint32_t priority, | 1370 | uint32_t priority, |
1355 | struct GNUNET_MQ_Envelope *env) | 1371 | struct GNUNET_MQ_Envelope *env) |
1356 | { | 1372 | { |
1357 | struct GSF_PeerTransmitHandle *pth; | 1373 | struct GSF_PeerTransmitHandle *pth; |
1358 | struct GSF_PeerTransmitHandle *pos; | 1374 | struct GSF_PeerTransmitHandle *pos; |
1359 | struct GSF_PeerTransmitHandle *prev; | 1375 | struct GSF_PeerTransmitHandle *prev; |
1360 | 1376 | ||
1361 | pth = GNUNET_new(struct GSF_PeerTransmitHandle); | 1377 | pth = GNUNET_new (struct GSF_PeerTransmitHandle); |
1362 | pth->transmission_request_start_time = GNUNET_TIME_absolute_get(); | 1378 | pth->transmission_request_start_time = GNUNET_TIME_absolute_get (); |
1363 | pth->env = env; | 1379 | pth->env = env; |
1364 | pth->is_query = is_query; | 1380 | pth->is_query = is_query; |
1365 | pth->priority = priority; | 1381 | pth->priority = priority; |
@@ -1368,19 +1384,19 @@ GSF_peer_transmit_(struct GSF_ConnectedPeer *cp, | |||
1368 | prev = NULL; | 1384 | prev = NULL; |
1369 | pos = cp->pth_head; | 1385 | pos = cp->pth_head; |
1370 | while ((NULL != pos) && (pos->priority > priority)) | 1386 | while ((NULL != pos) && (pos->priority > priority)) |
1371 | { | 1387 | { |
1372 | prev = pos; | 1388 | prev = pos; |
1373 | pos = pos->next; | 1389 | pos = pos->next; |
1374 | } | 1390 | } |
1375 | GNUNET_CONTAINER_DLL_insert_after(cp->pth_head, | 1391 | GNUNET_CONTAINER_DLL_insert_after (cp->pth_head, |
1376 | cp->pth_tail, | 1392 | cp->pth_tail, |
1377 | prev, | 1393 | prev, |
1378 | pth); | 1394 | pth); |
1379 | if (GNUNET_YES == is_query) | 1395 | if (GNUNET_YES == is_query) |
1380 | cp->ppd.pending_queries++; | 1396 | cp->ppd.pending_queries++; |
1381 | else if (GNUNET_NO == is_query) | 1397 | else if (GNUNET_NO == is_query) |
1382 | cp->ppd.pending_replies++; | 1398 | cp->ppd.pending_replies++; |
1383 | schedule_transmission(pth); | 1399 | schedule_transmission (pth); |
1384 | } | 1400 | } |
1385 | 1401 | ||
1386 | 1402 | ||
@@ -1392,19 +1408,19 @@ GSF_peer_transmit_(struct GSF_ConnectedPeer *cp, | |||
1392 | * @param request_priority priority of the original request | 1408 | * @param request_priority priority of the original request |
1393 | */ | 1409 | */ |
1394 | void | 1410 | void |
1395 | GSF_peer_update_performance_(struct GSF_ConnectedPeer *cp, | 1411 | GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, |
1396 | struct GNUNET_TIME_Absolute request_time, | 1412 | struct GNUNET_TIME_Absolute request_time, |
1397 | uint32_t request_priority) | 1413 | uint32_t request_priority) |
1398 | { | 1414 | { |
1399 | struct GNUNET_TIME_Relative delay; | 1415 | struct GNUNET_TIME_Relative delay; |
1400 | 1416 | ||
1401 | delay = GNUNET_TIME_absolute_get_duration(request_time); | 1417 | delay = GNUNET_TIME_absolute_get_duration (request_time); |
1402 | cp->ppd.avg_reply_delay.rel_value_us = | 1418 | cp->ppd.avg_reply_delay.rel_value_us = |
1403 | (cp->ppd.avg_reply_delay.rel_value_us * (RUNAVG_DELAY_N - 1) + | 1419 | (cp->ppd.avg_reply_delay.rel_value_us * (RUNAVG_DELAY_N - 1) |
1404 | delay.rel_value_us) / RUNAVG_DELAY_N; | 1420 | + delay.rel_value_us) / RUNAVG_DELAY_N; |
1405 | cp->ppd.avg_priority = | 1421 | cp->ppd.avg_priority = |
1406 | (cp->ppd.avg_priority * (RUNAVG_DELAY_N - 1) + | 1422 | (cp->ppd.avg_priority * (RUNAVG_DELAY_N - 1) |
1407 | request_priority) / RUNAVG_DELAY_N; | 1423 | + request_priority) / RUNAVG_DELAY_N; |
1408 | } | 1424 | } |
1409 | 1425 | ||
1410 | 1426 | ||
@@ -1416,11 +1432,11 @@ GSF_peer_update_performance_(struct GSF_ConnectedPeer *cp, | |||
1416 | * @param initiator_client local client on responsible for query | 1432 | * @param initiator_client local client on responsible for query |
1417 | */ | 1433 | */ |
1418 | void | 1434 | void |
1419 | GSF_peer_update_responder_client_(struct GSF_ConnectedPeer *cp, | 1435 | GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, |
1420 | struct GSF_LocalClient *initiator_client) | 1436 | struct GSF_LocalClient *initiator_client) |
1421 | { | 1437 | { |
1422 | cp->ppd.last_client_replies[cp->last_client_replies_woff++ % | 1438 | cp->ppd.last_client_replies[cp->last_client_replies_woff++ |
1423 | CS2P_SUCCESS_LIST_SIZE] = initiator_client; | 1439 | % CS2P_SUCCESS_LIST_SIZE] = initiator_client; |
1424 | } | 1440 | } |
1425 | 1441 | ||
1426 | 1442 | ||
@@ -1432,15 +1448,15 @@ GSF_peer_update_responder_client_(struct GSF_ConnectedPeer *cp, | |||
1432 | * @param initiator_peer other peer responsible for query | 1448 | * @param initiator_peer other peer responsible for query |
1433 | */ | 1449 | */ |
1434 | void | 1450 | void |
1435 | GSF_peer_update_responder_peer_(struct GSF_ConnectedPeer *cp, | 1451 | GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, |
1436 | const struct GSF_ConnectedPeer *initiator_peer) | 1452 | const struct GSF_ConnectedPeer *initiator_peer) |
1437 | { | 1453 | { |
1438 | unsigned int woff; | 1454 | unsigned int woff; |
1439 | 1455 | ||
1440 | woff = cp->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE; | 1456 | woff = cp->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE; |
1441 | GNUNET_PEER_change_rc(cp->ppd.last_p2p_replies[woff], -1); | 1457 | GNUNET_PEER_change_rc (cp->ppd.last_p2p_replies[woff], -1); |
1442 | cp->ppd.last_p2p_replies[woff] = initiator_peer->ppd.pid; | 1458 | cp->ppd.last_p2p_replies[woff] = initiator_peer->ppd.pid; |
1443 | GNUNET_PEER_change_rc(initiator_peer->ppd.pid, 1); | 1459 | GNUNET_PEER_change_rc (initiator_peer->ppd.pid, 1); |
1444 | cp->last_p2p_replies_woff = (woff + 1) % P2P_SUCCESS_LIST_SIZE; | 1460 | cp->last_p2p_replies_woff = (woff + 1) % P2P_SUCCESS_LIST_SIZE; |
1445 | } | 1461 | } |
1446 | 1462 | ||
@@ -1454,23 +1470,23 @@ GSF_peer_update_responder_peer_(struct GSF_ConnectedPeer *cp, | |||
1454 | * @return #GNUNET_OK to continue iteration | 1470 | * @return #GNUNET_OK to continue iteration |
1455 | */ | 1471 | */ |
1456 | static int | 1472 | static int |
1457 | flush_respect(void *cls, | 1473 | flush_respect (void *cls, |
1458 | const struct GNUNET_PeerIdentity *key, | 1474 | const struct GNUNET_PeerIdentity *key, |
1459 | void *value) | 1475 | void *value) |
1460 | { | 1476 | { |
1461 | struct GSF_ConnectedPeer *cp = value; | 1477 | struct GSF_ConnectedPeer *cp = value; |
1462 | struct GNUNET_PeerIdentity pid; | 1478 | struct GNUNET_PeerIdentity pid; |
1463 | 1479 | ||
1464 | if (cp->ppd.respect == cp->disk_respect) | 1480 | if (cp->ppd.respect == cp->disk_respect) |
1465 | return GNUNET_OK; /* unchanged */ | 1481 | return GNUNET_OK; /* unchanged */ |
1466 | GNUNET_assert(0 != cp->ppd.pid); | 1482 | GNUNET_assert (0 != cp->ppd.pid); |
1467 | GNUNET_PEER_resolve(cp->ppd.pid, &pid); | 1483 | GNUNET_PEER_resolve (cp->ppd.pid, &pid); |
1468 | GNUNET_PEERSTORE_store(peerstore, "fs", &pid, "respect", &cp->ppd.respect, | 1484 | GNUNET_PEERSTORE_store (peerstore, "fs", &pid, "respect", &cp->ppd.respect, |
1469 | sizeof(cp->ppd.respect), | 1485 | sizeof(cp->ppd.respect), |
1470 | GNUNET_TIME_UNIT_FOREVER_ABS, | 1486 | GNUNET_TIME_UNIT_FOREVER_ABS, |
1471 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 1487 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
1472 | NULL, | 1488 | NULL, |
1473 | NULL); | 1489 | NULL); |
1474 | return GNUNET_OK; | 1490 | return GNUNET_OK; |
1475 | } | 1491 | } |
1476 | 1492 | ||
@@ -1484,9 +1500,9 @@ flush_respect(void *cls, | |||
1484 | * @param internal_cls the corresponding `struct GSF_ConnectedPeer` | 1500 | * @param internal_cls the corresponding `struct GSF_ConnectedPeer` |
1485 | */ | 1501 | */ |
1486 | void | 1502 | void |
1487 | GSF_peer_disconnect_handler(void *cls, | 1503 | GSF_peer_disconnect_handler (void *cls, |
1488 | const struct GNUNET_PeerIdentity *peer, | 1504 | const struct GNUNET_PeerIdentity *peer, |
1489 | void *internal_cls) | 1505 | void *internal_cls) |
1490 | { | 1506 | { |
1491 | struct GSF_ConnectedPeer *cp = internal_cls; | 1507 | struct GSF_ConnectedPeer *cp = internal_cls; |
1492 | struct GSF_PeerTransmitHandle *pth; | 1508 | struct GSF_PeerTransmitHandle *pth; |
@@ -1495,82 +1511,83 @@ GSF_peer_disconnect_handler(void *cls, | |||
1495 | if (NULL == cp) | 1511 | if (NULL == cp) |
1496 | return; /* must have been disconnect from core with | 1512 | return; /* must have been disconnect from core with |
1497 | * 'peer' == my_id, ignore */ | 1513 | * 'peer' == my_id, ignore */ |
1498 | flush_respect(NULL, | 1514 | flush_respect (NULL, |
1499 | peer, | 1515 | peer, |
1500 | cp); | 1516 | cp); |
1501 | GNUNET_assert(GNUNET_YES == | 1517 | GNUNET_assert (GNUNET_YES == |
1502 | GNUNET_CONTAINER_multipeermap_remove(cp_map, | 1518 | GNUNET_CONTAINER_multipeermap_remove (cp_map, |
1503 | peer, | 1519 | peer, |
1504 | cp)); | 1520 | cp)); |
1505 | GNUNET_STATISTICS_set(GSF_stats, | 1521 | GNUNET_STATISTICS_set (GSF_stats, |
1506 | gettext_noop("# peers connected"), | 1522 | gettext_noop ("# peers connected"), |
1507 | GNUNET_CONTAINER_multipeermap_size(cp_map), | 1523 | GNUNET_CONTAINER_multipeermap_size (cp_map), |
1508 | GNUNET_NO); | 1524 | GNUNET_NO); |
1509 | if (NULL != cp->respect_iterate_req) | 1525 | if (NULL != cp->respect_iterate_req) |
1510 | { | 1526 | { |
1511 | GNUNET_PEERSTORE_iterate_cancel(cp->respect_iterate_req); | 1527 | GNUNET_PEERSTORE_iterate_cancel (cp->respect_iterate_req); |
1512 | cp->respect_iterate_req = NULL; | 1528 | cp->respect_iterate_req = NULL; |
1513 | } | 1529 | } |
1514 | if (NULL != cp->rc) | 1530 | if (NULL != cp->rc) |
1515 | { | 1531 | { |
1516 | GNUNET_ATS_reserve_bandwidth_cancel(cp->rc); | 1532 | GNUNET_ATS_reserve_bandwidth_cancel (cp->rc); |
1517 | cp->rc = NULL; | 1533 | cp->rc = NULL; |
1518 | } | 1534 | } |
1519 | if (NULL != cp->rc_delay_task) | 1535 | if (NULL != cp->rc_delay_task) |
1520 | { | 1536 | { |
1521 | GNUNET_SCHEDULER_cancel(cp->rc_delay_task); | 1537 | GNUNET_SCHEDULER_cancel (cp->rc_delay_task); |
1522 | cp->rc_delay_task = NULL; | 1538 | cp->rc_delay_task = NULL; |
1523 | } | 1539 | } |
1524 | GNUNET_CONTAINER_multihashmap_iterate(cp->request_map, | 1540 | GNUNET_CONTAINER_multihashmap_iterate (cp->request_map, |
1525 | &cancel_pending_request, | 1541 | &cancel_pending_request, |
1526 | cp); | 1542 | cp); |
1527 | GNUNET_CONTAINER_multihashmap_destroy(cp->request_map); | 1543 | GNUNET_CONTAINER_multihashmap_destroy (cp->request_map); |
1528 | cp->request_map = NULL; | 1544 | cp->request_map = NULL; |
1529 | GSF_plan_notify_peer_disconnect_(cp); | 1545 | GSF_plan_notify_peer_disconnect_ (cp); |
1530 | GNUNET_LOAD_value_free(cp->ppd.transmission_delay); | 1546 | GNUNET_LOAD_value_free (cp->ppd.transmission_delay); |
1531 | GNUNET_PEER_decrement_rcs(cp->ppd.last_p2p_replies, | 1547 | GNUNET_PEER_decrement_rcs (cp->ppd.last_p2p_replies, |
1532 | P2P_SUCCESS_LIST_SIZE); | 1548 | P2P_SUCCESS_LIST_SIZE); |
1533 | memset(cp->ppd.last_p2p_replies, | 1549 | memset (cp->ppd.last_p2p_replies, |
1534 | 0, | 1550 | 0, |
1535 | sizeof(cp->ppd.last_p2p_replies)); | 1551 | sizeof(cp->ppd.last_p2p_replies)); |
1536 | GSF_push_stop_(cp); | 1552 | GSF_push_stop_ (cp); |
1537 | while (NULL != (pth = cp->pth_head)) | 1553 | while (NULL != (pth = cp->pth_head)) |
1538 | { | 1554 | { |
1539 | GNUNET_CONTAINER_DLL_remove(cp->pth_head, | 1555 | GNUNET_CONTAINER_DLL_remove (cp->pth_head, |
1540 | cp->pth_tail, | 1556 | cp->pth_tail, |
1541 | pth); | 1557 | pth); |
1542 | if (GNUNET_YES == pth->is_query) | 1558 | if (GNUNET_YES == pth->is_query) |
1543 | GNUNET_assert(0 < cp->ppd.pending_queries--); | 1559 | GNUNET_assert (0 < cp->ppd.pending_queries--); |
1544 | else if (GNUNET_NO == pth->is_query) | 1560 | else if (GNUNET_NO == pth->is_query) |
1545 | GNUNET_assert(0 < cp->ppd.pending_replies--); | 1561 | GNUNET_assert (0 < cp->ppd.pending_replies--); |
1546 | GNUNET_free(pth); | 1562 | GNUNET_free (pth); |
1547 | } | 1563 | } |
1548 | while (NULL != (dh = cp->delayed_head)) | 1564 | while (NULL != (dh = cp->delayed_head)) |
1549 | { | 1565 | { |
1550 | GNUNET_CONTAINER_DLL_remove(cp->delayed_head, | 1566 | GNUNET_CONTAINER_DLL_remove (cp->delayed_head, |
1551 | cp->delayed_tail, | 1567 | cp->delayed_tail, |
1552 | dh); | 1568 | dh); |
1553 | GNUNET_MQ_discard(dh->env); | 1569 | GNUNET_MQ_discard (dh->env); |
1554 | cp->delay_queue_size--; | 1570 | cp->delay_queue_size--; |
1555 | GNUNET_SCHEDULER_cancel(dh->delay_task); | 1571 | GNUNET_SCHEDULER_cancel (dh->delay_task); |
1556 | GNUNET_free(dh); | 1572 | GNUNET_free (dh); |
1557 | } | 1573 | } |
1558 | GNUNET_PEER_change_rc(cp->ppd.pid, -1); | 1574 | GNUNET_PEER_change_rc (cp->ppd.pid, -1); |
1559 | if (NULL != cp->mig_revive_task) | 1575 | if (NULL != cp->mig_revive_task) |
1560 | { | 1576 | { |
1561 | GNUNET_SCHEDULER_cancel(cp->mig_revive_task); | 1577 | GNUNET_SCHEDULER_cancel (cp->mig_revive_task); |
1562 | cp->mig_revive_task = NULL; | 1578 | cp->mig_revive_task = NULL; |
1563 | } | 1579 | } |
1564 | GNUNET_break(0 == cp->ppd.pending_queries); | 1580 | GNUNET_break (0 == cp->ppd.pending_queries); |
1565 | GNUNET_break(0 == cp->ppd.pending_replies); | 1581 | GNUNET_break (0 == cp->ppd.pending_replies); |
1566 | GNUNET_free(cp); | 1582 | GNUNET_free (cp); |
1567 | } | 1583 | } |
1568 | 1584 | ||
1569 | 1585 | ||
1570 | /** | 1586 | /** |
1571 | * Closure for #call_iterator(). | 1587 | * Closure for #call_iterator(). |
1572 | */ | 1588 | */ |
1573 | struct IterationContext { | 1589 | struct IterationContext |
1590 | { | ||
1574 | /** | 1591 | /** |
1575 | * Function to call on each entry. | 1592 | * Function to call on each entry. |
1576 | */ | 1593 | */ |
@@ -1592,16 +1609,16 @@ struct IterationContext { | |||
1592 | * @return #GNUNET_YES to continue iteration | 1609 | * @return #GNUNET_YES to continue iteration |
1593 | */ | 1610 | */ |
1594 | static int | 1611 | static int |
1595 | call_iterator(void *cls, | 1612 | call_iterator (void *cls, |
1596 | const struct GNUNET_PeerIdentity *key, | 1613 | const struct GNUNET_PeerIdentity *key, |
1597 | void *value) | 1614 | void *value) |
1598 | { | 1615 | { |
1599 | struct IterationContext *ic = cls; | 1616 | struct IterationContext *ic = cls; |
1600 | struct GSF_ConnectedPeer *cp = value; | 1617 | struct GSF_ConnectedPeer *cp = value; |
1601 | 1618 | ||
1602 | ic->it(ic->it_cls, | 1619 | ic->it (ic->it_cls, |
1603 | key, cp, | 1620 | key, cp, |
1604 | &cp->ppd); | 1621 | &cp->ppd); |
1605 | return GNUNET_YES; | 1622 | return GNUNET_YES; |
1606 | } | 1623 | } |
1607 | 1624 | ||
@@ -1613,16 +1630,16 @@ call_iterator(void *cls, | |||
1613 | * @param it_cls closure for @a it | 1630 | * @param it_cls closure for @a it |
1614 | */ | 1631 | */ |
1615 | void | 1632 | void |
1616 | GSF_iterate_connected_peers_(GSF_ConnectedPeerIterator it, | 1633 | GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, |
1617 | void *it_cls) | 1634 | void *it_cls) |
1618 | { | 1635 | { |
1619 | struct IterationContext ic; | 1636 | struct IterationContext ic; |
1620 | 1637 | ||
1621 | ic.it = it; | 1638 | ic.it = it; |
1622 | ic.it_cls = it_cls; | 1639 | ic.it_cls = it_cls; |
1623 | GNUNET_CONTAINER_multipeermap_iterate(cp_map, | 1640 | GNUNET_CONTAINER_multipeermap_iterate (cp_map, |
1624 | &call_iterator, | 1641 | &call_iterator, |
1625 | &ic); | 1642 | &ic); |
1626 | } | 1643 | } |
1627 | 1644 | ||
1628 | 1645 | ||
@@ -1633,11 +1650,11 @@ GSF_iterate_connected_peers_(GSF_ConnectedPeerIterator it, | |||
1633 | * @param id identity to set (written to) | 1650 | * @param id identity to set (written to) |
1634 | */ | 1651 | */ |
1635 | void | 1652 | void |
1636 | GSF_connected_peer_get_identity_(const struct GSF_ConnectedPeer *cp, | 1653 | GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, |
1637 | struct GNUNET_PeerIdentity *id) | 1654 | struct GNUNET_PeerIdentity *id) |
1638 | { | 1655 | { |
1639 | GNUNET_assert(0 != cp->ppd.pid); | 1656 | GNUNET_assert (0 != cp->ppd.pid); |
1640 | GNUNET_PEER_resolve(cp->ppd.pid, id); | 1657 | GNUNET_PEER_resolve (cp->ppd.pid, id); |
1641 | } | 1658 | } |
1642 | 1659 | ||
1643 | 1660 | ||
@@ -1648,10 +1665,10 @@ GSF_connected_peer_get_identity_(const struct GSF_ConnectedPeer *cp, | |||
1648 | * @return reference to peer identity, valid until peer disconnects (!) | 1665 | * @return reference to peer identity, valid until peer disconnects (!) |
1649 | */ | 1666 | */ |
1650 | const struct GNUNET_PeerIdentity * | 1667 | const struct GNUNET_PeerIdentity * |
1651 | GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp) | 1668 | GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp) |
1652 | { | 1669 | { |
1653 | GNUNET_assert(0 != cp->ppd.pid); | 1670 | GNUNET_assert (0 != cp->ppd.pid); |
1654 | return GNUNET_PEER_resolve2(cp->ppd.pid); | 1671 | return GNUNET_PEER_resolve2 (cp->ppd.pid); |
1655 | } | 1672 | } |
1656 | 1673 | ||
1657 | 1674 | ||
@@ -1663,38 +1680,41 @@ GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp) | |||
1663 | * @param block_time until when to block | 1680 | * @param block_time until when to block |
1664 | */ | 1681 | */ |
1665 | void | 1682 | void |
1666 | GSF_block_peer_migration_(struct GSF_ConnectedPeer *cp, | 1683 | GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, |
1667 | struct GNUNET_TIME_Absolute block_time) | 1684 | struct GNUNET_TIME_Absolute block_time) |
1668 | { | 1685 | { |
1669 | struct GNUNET_MQ_Envelope *env; | 1686 | struct GNUNET_MQ_Envelope *env; |
1670 | struct MigrationStopMessage *msm; | 1687 | struct MigrationStopMessage *msm; |
1671 | 1688 | ||
1672 | if (cp->last_migration_block.abs_value_us > block_time.abs_value_us) | 1689 | if (cp->last_migration_block.abs_value_us > block_time.abs_value_us) |
1673 | { | 1690 | { |
1674 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1691 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1675 | "Migration already blocked for another %s\n", | 1692 | "Migration already blocked for another %s\n", |
1676 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining | 1693 | GNUNET_STRINGS_relative_time_to_string ( |
1677 | (cp->last_migration_block), GNUNET_YES)); | 1694 | GNUNET_TIME_absolute_get_remaining |
1678 | return; /* already blocked */ | 1695 | (cp-> |
1679 | } | 1696 | last_migration_block), GNUNET_YES)); |
1680 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking to stop migration for %s\n", | 1697 | return; /* already blocked */ |
1681 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(block_time), | 1698 | } |
1682 | GNUNET_YES)); | 1699 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking to stop migration for %s\n", |
1700 | GNUNET_STRINGS_relative_time_to_string ( | ||
1701 | GNUNET_TIME_absolute_get_remaining (block_time), | ||
1702 | GNUNET_YES)); | ||
1683 | cp->last_migration_block = block_time; | 1703 | cp->last_migration_block = block_time; |
1684 | env = GNUNET_MQ_msg(msm, | 1704 | env = GNUNET_MQ_msg (msm, |
1685 | GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP); | 1705 | GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP); |
1686 | msm->reserved = htonl(0); | 1706 | msm->reserved = htonl (0); |
1687 | msm->duration | 1707 | msm->duration |
1688 | = GNUNET_TIME_relative_hton(GNUNET_TIME_absolute_get_remaining | 1708 | = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining |
1689 | (cp->last_migration_block)); | 1709 | (cp->last_migration_block)); |
1690 | GNUNET_STATISTICS_update(GSF_stats, | 1710 | GNUNET_STATISTICS_update (GSF_stats, |
1691 | gettext_noop("# migration stop messages sent"), | 1711 | gettext_noop ("# migration stop messages sent"), |
1692 | 1, | 1712 | 1, |
1693 | GNUNET_NO); | 1713 | GNUNET_NO); |
1694 | GSF_peer_transmit_(cp, | 1714 | GSF_peer_transmit_ (cp, |
1695 | GNUNET_SYSERR, | 1715 | GNUNET_SYSERR, |
1696 | UINT32_MAX, | 1716 | UINT32_MAX, |
1697 | env); | 1717 | env); |
1698 | } | 1718 | } |
1699 | 1719 | ||
1700 | 1720 | ||
@@ -1708,8 +1728,8 @@ GSF_block_peer_migration_(struct GSF_ConnectedPeer *cp, | |||
1708 | * @param pref preference change | 1728 | * @param pref preference change |
1709 | */ | 1729 | */ |
1710 | void | 1730 | void |
1711 | GSF_connected_peer_change_preference_(struct GSF_ConnectedPeer *cp, | 1731 | GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, |
1712 | uint64_t pref) | 1732 | uint64_t pref) |
1713 | { | 1733 | { |
1714 | cp->inc_preference += pref; | 1734 | cp->inc_preference += pref; |
1715 | } | 1735 | } |
@@ -1721,15 +1741,16 @@ GSF_connected_peer_change_preference_(struct GSF_ConnectedPeer *cp, | |||
1721 | * @param cls closure, not used | 1741 | * @param cls closure, not used |
1722 | */ | 1742 | */ |
1723 | static void | 1743 | static void |
1724 | cron_flush_respect(void *cls) | 1744 | cron_flush_respect (void *cls) |
1725 | { | 1745 | { |
1726 | fr_task = NULL; | 1746 | fr_task = NULL; |
1727 | GNUNET_CONTAINER_multipeermap_iterate(cp_map, | 1747 | GNUNET_CONTAINER_multipeermap_iterate (cp_map, |
1728 | &flush_respect, | 1748 | &flush_respect, |
1729 | NULL); | 1749 | NULL); |
1730 | fr_task = GNUNET_SCHEDULER_add_delayed_with_priority(RESPECT_FLUSH_FREQ, | 1750 | fr_task = GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ, |
1731 | GNUNET_SCHEDULER_PRIORITY_HIGH, | 1751 | GNUNET_SCHEDULER_PRIORITY_HIGH, |
1732 | &cron_flush_respect, NULL); | 1752 | &cron_flush_respect, |
1753 | NULL); | ||
1733 | } | 1754 | } |
1734 | 1755 | ||
1735 | 1756 | ||
@@ -1737,12 +1758,12 @@ cron_flush_respect(void *cls) | |||
1737 | * Initialize peer management subsystem. | 1758 | * Initialize peer management subsystem. |
1738 | */ | 1759 | */ |
1739 | void | 1760 | void |
1740 | GSF_connected_peer_init_() | 1761 | GSF_connected_peer_init_ () |
1741 | { | 1762 | { |
1742 | cp_map = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); | 1763 | cp_map = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); |
1743 | peerstore = GNUNET_PEERSTORE_connect(GSF_cfg); | 1764 | peerstore = GNUNET_PEERSTORE_connect (GSF_cfg); |
1744 | fr_task = GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_HIGH, | 1765 | fr_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH, |
1745 | &cron_flush_respect, NULL); | 1766 | &cron_flush_respect, NULL); |
1746 | } | 1767 | } |
1747 | 1768 | ||
1748 | 1769 | ||
@@ -1750,17 +1771,17 @@ GSF_connected_peer_init_() | |||
1750 | * Shutdown peer management subsystem. | 1771 | * Shutdown peer management subsystem. |
1751 | */ | 1772 | */ |
1752 | void | 1773 | void |
1753 | GSF_connected_peer_done_() | 1774 | GSF_connected_peer_done_ () |
1754 | { | 1775 | { |
1755 | GNUNET_CONTAINER_multipeermap_iterate(cp_map, | 1776 | GNUNET_CONTAINER_multipeermap_iterate (cp_map, |
1756 | &flush_respect, | 1777 | &flush_respect, |
1757 | NULL); | 1778 | NULL); |
1758 | GNUNET_SCHEDULER_cancel(fr_task); | 1779 | GNUNET_SCHEDULER_cancel (fr_task); |
1759 | fr_task = NULL; | 1780 | fr_task = NULL; |
1760 | GNUNET_CONTAINER_multipeermap_destroy(cp_map); | 1781 | GNUNET_CONTAINER_multipeermap_destroy (cp_map); |
1761 | cp_map = NULL; | 1782 | cp_map = NULL; |
1762 | GNUNET_PEERSTORE_disconnect(peerstore, | 1783 | GNUNET_PEERSTORE_disconnect (peerstore, |
1763 | GNUNET_YES); | 1784 | GNUNET_YES); |
1764 | } | 1785 | } |
1765 | 1786 | ||
1766 | 1787 | ||
@@ -1773,9 +1794,9 @@ GSF_connected_peer_done_() | |||
1773 | * @return #GNUNET_YES (we should continue to iterate) | 1794 | * @return #GNUNET_YES (we should continue to iterate) |
1774 | */ | 1795 | */ |
1775 | static int | 1796 | static int |
1776 | clean_local_client(void *cls, | 1797 | clean_local_client (void *cls, |
1777 | const struct GNUNET_PeerIdentity *key, | 1798 | const struct GNUNET_PeerIdentity *key, |
1778 | void *value) | 1799 | void *value) |
1779 | { | 1800 | { |
1780 | const struct GSF_LocalClient *lc = cls; | 1801 | const struct GSF_LocalClient *lc = cls; |
1781 | struct GSF_ConnectedPeer *cp = value; | 1802 | struct GSF_ConnectedPeer *cp = value; |
@@ -1795,13 +1816,13 @@ clean_local_client(void *cls, | |||
1795 | * @param lc handle to the local client (henceforth invalid) | 1816 | * @param lc handle to the local client (henceforth invalid) |
1796 | */ | 1817 | */ |
1797 | void | 1818 | void |
1798 | GSF_handle_local_client_disconnect_(const struct GSF_LocalClient *lc) | 1819 | GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc) |
1799 | { | 1820 | { |
1800 | if (NULL == cp_map) | 1821 | if (NULL == cp_map) |
1801 | return; /* already cleaned up */ | 1822 | return; /* already cleaned up */ |
1802 | GNUNET_CONTAINER_multipeermap_iterate(cp_map, | 1823 | GNUNET_CONTAINER_multipeermap_iterate (cp_map, |
1803 | &clean_local_client, | 1824 | &clean_local_client, |
1804 | (void *)lc); | 1825 | (void *) lc); |
1805 | } | 1826 | } |
1806 | 1827 | ||
1807 | 1828 | ||
diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h index 9eab3d9de..c17b6a0a8 100644 --- a/src/fs/gnunet-service-fs_cp.h +++ b/src/fs/gnunet-service-fs_cp.h | |||
@@ -60,7 +60,8 @@ | |||
60 | /** | 60 | /** |
61 | * Performance data kept for a peer. | 61 | * Performance data kept for a peer. |
62 | */ | 62 | */ |
63 | struct GSF_PeerPerformanceData { | 63 | struct GSF_PeerPerformanceData |
64 | { | ||
64 | /** | 65 | /** |
65 | * List of the last clients for which this peer successfully | 66 | * List of the last clients for which this peer successfully |
66 | * answered a query. | 67 | * answered a query. |
@@ -202,9 +203,9 @@ struct GSF_PeerTransmitHandle; | |||
202 | * @return internal handle for the peer | 203 | * @return internal handle for the peer |
203 | */ | 204 | */ |
204 | void * | 205 | void * |
205 | GSF_peer_connect_handler(void *cls, | 206 | GSF_peer_connect_handler (void *cls, |
206 | const struct GNUNET_PeerIdentity *peer, | 207 | const struct GNUNET_PeerIdentity *peer, |
207 | struct GNUNET_MQ_Handle *mq); | 208 | struct GNUNET_MQ_Handle *mq); |
208 | 209 | ||
209 | 210 | ||
210 | /** | 211 | /** |
@@ -214,7 +215,7 @@ GSF_peer_connect_handler(void *cls, | |||
214 | * @return NULL if this peer is not currently connected | 215 | * @return NULL if this peer is not currently connected |
215 | */ | 216 | */ |
216 | struct GSF_ConnectedPeer * | 217 | struct GSF_ConnectedPeer * |
217 | GSF_peer_get_(const struct GNUNET_PeerIdentity *peer); | 218 | GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer); |
218 | 219 | ||
219 | 220 | ||
220 | /** | 221 | /** |
@@ -224,8 +225,8 @@ GSF_peer_get_(const struct GNUNET_PeerIdentity *peer); | |||
224 | * @param latency current latency value | 225 | * @param latency current latency value |
225 | */ | 226 | */ |
226 | void | 227 | void |
227 | GSF_update_peer_latency_(const struct GNUNET_PeerIdentity *id, | 228 | GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, |
228 | struct GNUNET_TIME_Relative latency); | 229 | struct GNUNET_TIME_Relative latency); |
229 | 230 | ||
230 | 231 | ||
231 | /** | 232 | /** |
@@ -239,10 +240,10 @@ GSF_update_peer_latency_(const struct GNUNET_PeerIdentity *id, | |||
239 | * @param env envelope of message to send | 240 | * @param env envelope of message to send |
240 | */ | 241 | */ |
241 | void | 242 | void |
242 | GSF_peer_transmit_(struct GSF_ConnectedPeer *cp, | 243 | GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, |
243 | int is_query, | 244 | int is_query, |
244 | uint32_t priority, | 245 | uint32_t priority, |
245 | struct GNUNET_MQ_Envelope *env); | 246 | struct GNUNET_MQ_Envelope *env); |
246 | 247 | ||
247 | 248 | ||
248 | /** | 249 | /** |
@@ -253,9 +254,9 @@ GSF_peer_transmit_(struct GSF_ConnectedPeer *cp, | |||
253 | * @param request_priority priority of the original request | 254 | * @param request_priority priority of the original request |
254 | */ | 255 | */ |
255 | void | 256 | void |
256 | GSF_peer_update_performance_(struct GSF_ConnectedPeer *cp, | 257 | GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, |
257 | struct GNUNET_TIME_Absolute request_time, | 258 | struct GNUNET_TIME_Absolute request_time, |
258 | uint32_t request_priority); | 259 | uint32_t request_priority); |
259 | 260 | ||
260 | 261 | ||
261 | /** | 262 | /** |
@@ -266,8 +267,8 @@ GSF_peer_update_performance_(struct GSF_ConnectedPeer *cp, | |||
266 | * @param initiator_client local client on responsible for query | 267 | * @param initiator_client local client on responsible for query |
267 | */ | 268 | */ |
268 | void | 269 | void |
269 | GSF_peer_update_responder_client_(struct GSF_ConnectedPeer *cp, | 270 | GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, |
270 | struct GSF_LocalClient *initiator_client); | 271 | struct GSF_LocalClient *initiator_client); |
271 | 272 | ||
272 | 273 | ||
273 | /** | 274 | /** |
@@ -278,9 +279,9 @@ GSF_peer_update_responder_client_(struct GSF_ConnectedPeer *cp, | |||
278 | * @param initiator_peer other peer responsible for query | 279 | * @param initiator_peer other peer responsible for query |
279 | */ | 280 | */ |
280 | void | 281 | void |
281 | GSF_peer_update_responder_peer_(struct GSF_ConnectedPeer *cp, | 282 | GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, |
282 | const struct GSF_ConnectedPeer | 283 | const struct GSF_ConnectedPeer |
283 | *initiator_peer); | 284 | *initiator_peer); |
284 | 285 | ||
285 | 286 | ||
286 | /** | 287 | /** |
@@ -290,8 +291,8 @@ GSF_peer_update_responder_peer_(struct GSF_ConnectedPeer *cp, | |||
290 | * @param msm the actual message | 291 | * @param msm the actual message |
291 | */ | 292 | */ |
292 | void | 293 | void |
293 | handle_p2p_migration_stop(void *cls, | 294 | handle_p2p_migration_stop (void *cls, |
294 | const struct MigrationStopMessage *message); | 295 | const struct MigrationStopMessage *message); |
295 | 296 | ||
296 | 297 | ||
297 | /** | 298 | /** |
@@ -301,8 +302,8 @@ handle_p2p_migration_stop(void *cls, | |||
301 | * @param gm the actual message | 302 | * @param gm the actual message |
302 | */ | 303 | */ |
303 | void | 304 | void |
304 | handle_p2p_get(void *cls, | 305 | handle_p2p_get (void *cls, |
305 | const struct GetMessage *gm); | 306 | const struct GetMessage *gm); |
306 | 307 | ||
307 | 308 | ||
308 | /** | 309 | /** |
@@ -312,7 +313,7 @@ handle_p2p_get(void *cls, | |||
312 | * @return performance data record for the peer | 313 | * @return performance data record for the peer |
313 | */ | 314 | */ |
314 | struct GSF_PeerPerformanceData * | 315 | struct GSF_PeerPerformanceData * |
315 | GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp); | 316 | GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp); |
316 | 317 | ||
317 | 318 | ||
318 | /** | 319 | /** |
@@ -323,8 +324,8 @@ GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp); | |||
323 | * @param block_time until when to block | 324 | * @param block_time until when to block |
324 | */ | 325 | */ |
325 | void | 326 | void |
326 | GSF_block_peer_migration_(struct GSF_ConnectedPeer *cp, | 327 | GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, |
327 | struct GNUNET_TIME_Absolute block_time); | 328 | struct GNUNET_TIME_Absolute block_time); |
328 | 329 | ||
329 | 330 | ||
330 | /** | 331 | /** |
@@ -336,9 +337,9 @@ GSF_block_peer_migration_(struct GSF_ConnectedPeer *cp, | |||
336 | * @param internal_cls our `struct GSF_ConnectedPeer` for @a peer | 337 | * @param internal_cls our `struct GSF_ConnectedPeer` for @a peer |
337 | */ | 338 | */ |
338 | void | 339 | void |
339 | GSF_peer_disconnect_handler(void *cls, | 340 | GSF_peer_disconnect_handler (void *cls, |
340 | const struct GNUNET_PeerIdentity *peer, | 341 | const struct GNUNET_PeerIdentity *peer, |
341 | void *internal_cls); | 342 | void *internal_cls); |
342 | 343 | ||
343 | 344 | ||
344 | /** | 345 | /** |
@@ -348,7 +349,7 @@ GSF_peer_disconnect_handler(void *cls, | |||
348 | * @param lc handle to the local client (henceforth invalid) | 349 | * @param lc handle to the local client (henceforth invalid) |
349 | */ | 350 | */ |
350 | void | 351 | void |
351 | GSF_handle_local_client_disconnect_(const struct GSF_LocalClient *lc); | 352 | GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc); |
352 | 353 | ||
353 | 354 | ||
354 | /** | 355 | /** |
@@ -361,8 +362,8 @@ GSF_handle_local_client_disconnect_(const struct GSF_LocalClient *lc); | |||
361 | * @param pref preference change | 362 | * @param pref preference change |
362 | */ | 363 | */ |
363 | void | 364 | void |
364 | GSF_connected_peer_change_preference_(struct GSF_ConnectedPeer *cp, | 365 | GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, |
365 | uint64_t pref); | 366 | uint64_t pref); |
366 | 367 | ||
367 | 368 | ||
368 | /** | 369 | /** |
@@ -372,8 +373,8 @@ GSF_connected_peer_change_preference_(struct GSF_ConnectedPeer *cp, | |||
372 | * @param id identity to set (written to) | 373 | * @param id identity to set (written to) |
373 | */ | 374 | */ |
374 | void | 375 | void |
375 | GSF_connected_peer_get_identity_(const struct GSF_ConnectedPeer *cp, | 376 | GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, |
376 | struct GNUNET_PeerIdentity *id); | 377 | struct GNUNET_PeerIdentity *id); |
377 | 378 | ||
378 | 379 | ||
379 | /** | 380 | /** |
@@ -383,7 +384,7 @@ GSF_connected_peer_get_identity_(const struct GSF_ConnectedPeer *cp, | |||
383 | * @return reference to peer identity, valid until peer disconnects (!) | 384 | * @return reference to peer identity, valid until peer disconnects (!) |
384 | */ | 385 | */ |
385 | const struct GNUNET_PeerIdentity * | 386 | const struct GNUNET_PeerIdentity * |
386 | GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp); | 387 | GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp); |
387 | 388 | ||
388 | 389 | ||
389 | 390 | ||
@@ -394,21 +395,21 @@ GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp); | |||
394 | * @param it_cls closure for it | 395 | * @param it_cls closure for it |
395 | */ | 396 | */ |
396 | void | 397 | void |
397 | GSF_iterate_connected_peers_(GSF_ConnectedPeerIterator it, void *it_cls); | 398 | GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, void *it_cls); |
398 | 399 | ||
399 | 400 | ||
400 | /** | 401 | /** |
401 | * Initialize peer management subsystem. | 402 | * Initialize peer management subsystem. |
402 | */ | 403 | */ |
403 | void | 404 | void |
404 | GSF_connected_peer_init_(void); | 405 | GSF_connected_peer_init_ (void); |
405 | 406 | ||
406 | 407 | ||
407 | /** | 408 | /** |
408 | * Shutdown peer management subsystem. | 409 | * Shutdown peer management subsystem. |
409 | */ | 410 | */ |
410 | void | 411 | void |
411 | GSF_connected_peer_done_(void); | 412 | GSF_connected_peer_done_ (void); |
412 | 413 | ||
413 | 414 | ||
414 | #endif | 415 | #endif |
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index e21b2ca57..4a7172c50 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c | |||
@@ -39,7 +39,8 @@ | |||
39 | * In-memory information about indexed files (also available | 39 | * In-memory information about indexed files (also available |
40 | * on-disk). | 40 | * on-disk). |
41 | */ | 41 | */ |
42 | struct IndexInfo { | 42 | struct IndexInfo |
43 | { | ||
43 | /** | 44 | /** |
44 | * This is a doubly linked list. | 45 | * This is a doubly linked list. |
45 | */ | 46 | */ |
@@ -108,44 +109,44 @@ static struct GNUNET_DATASTORE_Handle *dsh; | |||
108 | * Write the current index information list to disk. | 109 | * Write the current index information list to disk. |
109 | */ | 110 | */ |
110 | static void | 111 | static void |
111 | write_index_list() | 112 | write_index_list () |
112 | { | 113 | { |
113 | struct GNUNET_BIO_WriteHandle *wh; | 114 | struct GNUNET_BIO_WriteHandle *wh; |
114 | char *fn; | 115 | char *fn; |
115 | struct IndexInfo *pos; | 116 | struct IndexInfo *pos; |
116 | 117 | ||
117 | if (GNUNET_OK != | 118 | if (GNUNET_OK != |
118 | GNUNET_CONFIGURATION_get_value_filename(cfg, "FS", "INDEXDB", &fn)) | 119 | GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) |
119 | { | 120 | { |
120 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 121 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
121 | "fs", | 122 | "fs", |
122 | "INDEXDB"); | 123 | "INDEXDB"); |
123 | return; | 124 | return; |
124 | } | 125 | } |
125 | wh = GNUNET_BIO_write_open(fn); | 126 | wh = GNUNET_BIO_write_open (fn); |
126 | if (NULL == wh) | 127 | if (NULL == wh) |
127 | { | 128 | { |
128 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
129 | _("Could not open `%s'.\n"), | 130 | _ ("Could not open `%s'.\n"), |
130 | fn); | 131 | fn); |
131 | GNUNET_free(fn); | 132 | GNUNET_free (fn); |
132 | return; | 133 | return; |
133 | } | 134 | } |
134 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 135 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
135 | if ((GNUNET_OK != GNUNET_BIO_write(wh, | 136 | if ((GNUNET_OK != GNUNET_BIO_write (wh, |
136 | &pos->file_id, | 137 | &pos->file_id, |
137 | sizeof(struct GNUNET_HashCode))) || | 138 | sizeof(struct GNUNET_HashCode))) || |
138 | (GNUNET_OK != GNUNET_BIO_write_string(wh, pos->filename))) | 139 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename))) |
139 | break; | 140 | break; |
140 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) | 141 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) |
141 | { | 142 | { |
142 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 143 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
143 | _("Error writing `%s'.\n"), | 144 | _ ("Error writing `%s'.\n"), |
144 | fn); | 145 | fn); |
145 | GNUNET_free(fn); | 146 | GNUNET_free (fn); |
146 | return; | 147 | return; |
147 | } | 148 | } |
148 | GNUNET_free(fn); | 149 | GNUNET_free (fn); |
149 | } | 150 | } |
150 | 151 | ||
151 | 152 | ||
@@ -153,7 +154,7 @@ write_index_list() | |||
153 | * Read index information from disk. | 154 | * Read index information from disk. |
154 | */ | 155 | */ |
155 | static void | 156 | static void |
156 | read_index_list() | 157 | read_index_list () |
157 | { | 158 | { |
158 | struct GNUNET_BIO_ReadHandle *rh; | 159 | struct GNUNET_BIO_ReadHandle *rh; |
159 | char *fn; | 160 | char *fn; |
@@ -164,59 +165,59 @@ read_index_list() | |||
164 | char *emsg; | 165 | char *emsg; |
165 | 166 | ||
166 | if (GNUNET_OK != | 167 | if (GNUNET_OK != |
167 | GNUNET_CONFIGURATION_get_value_filename(cfg, "FS", "INDEXDB", &fn)) | 168 | GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) |
168 | { | 169 | { |
169 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 170 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
170 | "fs", | 171 | "fs", |
171 | "INDEXDB"); | 172 | "INDEXDB"); |
172 | return; | 173 | return; |
173 | } | 174 | } |
174 | if (GNUNET_NO == GNUNET_DISK_file_test(fn)) | 175 | if (GNUNET_NO == GNUNET_DISK_file_test (fn)) |
175 | { | 176 | { |
176 | /* no index info yet */ | 177 | /* no index info yet */ |
177 | GNUNET_free(fn); | 178 | GNUNET_free (fn); |
178 | return; | 179 | return; |
179 | } | 180 | } |
180 | rh = GNUNET_BIO_read_open(fn); | 181 | rh = GNUNET_BIO_read_open (fn); |
181 | if (NULL == rh) | 182 | if (NULL == rh) |
182 | { | 183 | { |
183 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
184 | _("Could not open `%s'.\n"), | 185 | _ ("Could not open `%s'.\n"), |
185 | fn); | 186 | fn); |
186 | GNUNET_free(fn); | 187 | GNUNET_free (fn); |
187 | return; | 188 | return; |
188 | } | 189 | } |
189 | while ( | 190 | while ( |
190 | (GNUNET_OK == GNUNET_BIO_read(rh, | 191 | (GNUNET_OK == GNUNET_BIO_read (rh, |
191 | "Hash of indexed file", | 192 | "Hash of indexed file", |
192 | &hc, | 193 | &hc, |
193 | sizeof(struct GNUNET_HashCode))) && | 194 | sizeof(struct GNUNET_HashCode))) && |
194 | (GNUNET_OK == | 195 | (GNUNET_OK == |
195 | GNUNET_BIO_read_string(rh, "Name of indexed file", &fname, 1024 * 16)) && | 196 | GNUNET_BIO_read_string (rh, "Name of indexed file", &fname, 1024 * 16)) && |
196 | (fname != NULL)) | 197 | (fname != NULL)) |
198 | { | ||
199 | slen = strlen (fname) + 1; | ||
200 | pos = GNUNET_malloc (sizeof(struct IndexInfo) + slen); | ||
201 | pos->file_id = hc; | ||
202 | pos->filename = (const char *) &pos[1]; | ||
203 | GNUNET_memcpy (&pos[1], fname, slen); | ||
204 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( | ||
205 | ifm, | ||
206 | &pos->file_id, | ||
207 | pos, | ||
208 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
209 | { | ||
210 | GNUNET_free (pos); | ||
211 | } | ||
212 | else | ||
197 | { | 213 | { |
198 | slen = strlen(fname) + 1; | 214 | GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, pos); |
199 | pos = GNUNET_malloc(sizeof(struct IndexInfo) + slen); | ||
200 | pos->file_id = hc; | ||
201 | pos->filename = (const char *)&pos[1]; | ||
202 | GNUNET_memcpy(&pos[1], fname, slen); | ||
203 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put( | ||
204 | ifm, | ||
205 | &pos->file_id, | ||
206 | pos, | ||
207 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
208 | { | ||
209 | GNUNET_free(pos); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | GNUNET_CONTAINER_DLL_insert(indexed_files_head, indexed_files_tail, pos); | ||
214 | } | ||
215 | GNUNET_free(fname); | ||
216 | } | 215 | } |
217 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) | 216 | GNUNET_free (fname); |
218 | GNUNET_free(emsg); | 217 | } |
219 | GNUNET_free(fn); | 218 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
219 | GNUNET_free (emsg); | ||
220 | GNUNET_free (fn); | ||
220 | } | 221 | } |
221 | 222 | ||
222 | 223 | ||
@@ -230,15 +231,15 @@ read_index_list() | |||
230 | * @param msg error message | 231 | * @param msg error message |
231 | */ | 232 | */ |
232 | static void | 233 | static void |
233 | remove_cont(void *cls, | 234 | remove_cont (void *cls, |
234 | int success, | 235 | int success, |
235 | struct GNUNET_TIME_Absolute min_expiration, | 236 | struct GNUNET_TIME_Absolute min_expiration, |
236 | const char *msg) | 237 | const char *msg) |
237 | { | 238 | { |
238 | if (GNUNET_OK != success) | 239 | if (GNUNET_OK != success) |
239 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
240 | _("Failed to delete bogus block: %s\n"), | 241 | _ ("Failed to delete bogus block: %s\n"), |
241 | msg); | 242 | msg); |
242 | } | 243 | } |
243 | 244 | ||
244 | 245 | ||
@@ -263,17 +264,17 @@ remove_cont(void *cls, | |||
263 | * @return GNUNET_OK on success | 264 | * @return GNUNET_OK on success |
264 | */ | 265 | */ |
265 | int | 266 | int |
266 | GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, | 267 | GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, |
267 | uint32_t size, | 268 | uint32_t size, |
268 | const void *data, | 269 | const void *data, |
269 | enum GNUNET_BLOCK_Type type, | 270 | enum GNUNET_BLOCK_Type type, |
270 | uint32_t priority, | 271 | uint32_t priority, |
271 | uint32_t anonymity, | 272 | uint32_t anonymity, |
272 | uint32_t replication, | 273 | uint32_t replication, |
273 | struct GNUNET_TIME_Absolute expiration, | 274 | struct GNUNET_TIME_Absolute expiration, |
274 | uint64_t uid, | 275 | uint64_t uid, |
275 | GNUNET_DATASTORE_DatumProcessor cont, | 276 | GNUNET_DATASTORE_DatumProcessor cont, |
276 | void *cont_cls) | 277 | void *cont_cls) |
277 | { | 278 | { |
278 | const struct OnDemandBlock *odb; | 279 | const struct OnDemandBlock *odb; |
279 | struct GNUNET_HashCode nkey; | 280 | struct GNUNET_HashCode nkey; |
@@ -289,78 +290,78 @@ GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, | |||
289 | struct IndexInfo *ii; | 290 | struct IndexInfo *ii; |
290 | 291 | ||
291 | if (size != sizeof(struct OnDemandBlock)) | 292 | if (size != sizeof(struct OnDemandBlock)) |
292 | { | 293 | { |
293 | GNUNET_break(0); | 294 | GNUNET_break (0); |
294 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); | 295 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
295 | return GNUNET_SYSERR; | 296 | return GNUNET_SYSERR; |
296 | } | 297 | } |
297 | odb = (const struct OnDemandBlock *)data; | 298 | odb = (const struct OnDemandBlock *) data; |
298 | off = GNUNET_ntohll(odb->offset); | 299 | off = GNUNET_ntohll (odb->offset); |
299 | ii = GNUNET_CONTAINER_multihashmap_get(ifm, &odb->file_id); | 300 | ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); |
300 | if (NULL == ii) | 301 | if (NULL == ii) |
301 | { | 302 | { |
302 | GNUNET_break(0); | 303 | GNUNET_break (0); |
303 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 304 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
304 | "Failed to find index %s\n", | 305 | "Failed to find index %s\n", |
305 | GNUNET_h2s(&odb->file_id)); | 306 | GNUNET_h2s (&odb->file_id)); |
306 | return GNUNET_SYSERR; | 307 | return GNUNET_SYSERR; |
307 | } | 308 | } |
308 | fn = ii->filename; | 309 | fn = ii->filename; |
309 | if ((NULL == fn) || (0 != access(fn, R_OK))) | 310 | if ((NULL == fn) || (0 != access (fn, R_OK))) |
310 | { | 311 | { |
311 | GNUNET_STATISTICS_update( | 312 | GNUNET_STATISTICS_update ( |
312 | GSF_stats, | 313 | GSF_stats, |
313 | gettext_noop("# index blocks removed: original file inaccessible"), | 314 | gettext_noop ("# index blocks removed: original file inaccessible"), |
314 | 1, | 315 | 1, |
315 | GNUNET_YES); | 316 | GNUNET_YES); |
316 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); | 317 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
317 | return GNUNET_SYSERR; | 318 | return GNUNET_SYSERR; |
318 | } | 319 | } |
319 | if ((NULL == (fh = GNUNET_DISK_file_open(fn, | 320 | if ((NULL == (fh = GNUNET_DISK_file_open (fn, |
320 | GNUNET_DISK_OPEN_READ, | 321 | GNUNET_DISK_OPEN_READ, |
321 | GNUNET_DISK_PERM_NONE))) || | 322 | GNUNET_DISK_PERM_NONE))) || |
322 | (off != GNUNET_DISK_file_seek(fh, off, GNUNET_DISK_SEEK_SET)) || | 323 | (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) || |
323 | (-1 == (nsize = GNUNET_DISK_file_read(fh, ndata, sizeof(ndata))))) | 324 | (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof(ndata))))) |
324 | { | 325 | { |
325 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 326 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
326 | _( | 327 | _ ( |
327 | "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), | 328 | "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), |
328 | GNUNET_h2s(&odb->file_id), | 329 | GNUNET_h2s (&odb->file_id), |
329 | fn, | 330 | fn, |
330 | (unsigned long long)off, | 331 | (unsigned long long) off, |
331 | (fn == NULL) ? _("not indexed") : strerror(errno)); | 332 | (fn == NULL) ? _ ("not indexed") : strerror (errno)); |
332 | if (fh != NULL) | 333 | if (fh != NULL) |
333 | GNUNET_DISK_file_close(fh); | 334 | GNUNET_DISK_file_close (fh); |
334 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); | 335 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
335 | return GNUNET_SYSERR; | 336 | return GNUNET_SYSERR; |
336 | } | 337 | } |
337 | GNUNET_DISK_file_close(fh); | 338 | GNUNET_DISK_file_close (fh); |
338 | GNUNET_CRYPTO_hash(ndata, nsize, &nkey); | 339 | GNUNET_CRYPTO_hash (ndata, nsize, &nkey); |
339 | GNUNET_CRYPTO_hash_to_aes_key(&nkey, &skey, &iv); | 340 | GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv); |
340 | GNUNET_CRYPTO_symmetric_encrypt(ndata, nsize, &skey, &iv, edata); | 341 | GNUNET_CRYPTO_symmetric_encrypt (ndata, nsize, &skey, &iv, edata); |
341 | GNUNET_CRYPTO_hash(edata, nsize, &query); | 342 | GNUNET_CRYPTO_hash (edata, nsize, &query); |
342 | if (0 != memcmp(&query, key, sizeof(struct GNUNET_HashCode))) | 343 | if (0 != memcmp (&query, key, sizeof(struct GNUNET_HashCode))) |
343 | { | 344 | { |
344 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 345 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
345 | _("Indexed file `%s' changed at offset %llu\n"), | 346 | _ ("Indexed file `%s' changed at offset %llu\n"), |
346 | fn, | 347 | fn, |
347 | (unsigned long long)off); | 348 | (unsigned long long) off); |
348 | GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL); | 349 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
349 | return GNUNET_SYSERR; | 350 | return GNUNET_SYSERR; |
350 | } | 351 | } |
351 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
352 | "On-demand encoded block for query `%s'\n", | 353 | "On-demand encoded block for query `%s'\n", |
353 | GNUNET_h2s(key)); | 354 | GNUNET_h2s (key)); |
354 | cont(cont_cls, | 355 | cont (cont_cls, |
355 | key, | 356 | key, |
356 | nsize, | 357 | nsize, |
357 | edata, | 358 | edata, |
358 | GNUNET_BLOCK_TYPE_FS_DBLOCK, | 359 | GNUNET_BLOCK_TYPE_FS_DBLOCK, |
359 | priority, | 360 | priority, |
360 | anonymity, | 361 | anonymity, |
361 | replication, | 362 | replication, |
362 | expiration, | 363 | expiration, |
363 | uid); | 364 | uid); |
364 | return GNUNET_OK; | 365 | return GNUNET_OK; |
365 | } | 366 | } |
366 | 367 | ||
@@ -371,7 +372,7 @@ GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, | |||
371 | * @param mq message queue to send information to | 372 | * @param mq message queue to send information to |
372 | */ | 373 | */ |
373 | void | 374 | void |
374 | GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq) | 375 | GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) |
375 | { | 376 | { |
376 | struct GNUNET_MQ_Envelope *env; | 377 | struct GNUNET_MQ_Envelope *env; |
377 | struct IndexInfoMessage *iim; | 378 | struct IndexInfoMessage *iim; |
@@ -381,23 +382,23 @@ GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq) | |||
381 | struct IndexInfo *pos; | 382 | struct IndexInfo *pos; |
382 | 383 | ||
383 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 384 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
385 | { | ||
386 | fn = pos->filename; | ||
387 | slen = strlen (fn) + 1; | ||
388 | if (slen + sizeof(struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE) | ||
384 | { | 389 | { |
385 | fn = pos->filename; | 390 | GNUNET_break (0); |
386 | slen = strlen(fn) + 1; | 391 | break; |
387 | if (slen + sizeof(struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE) | ||
388 | { | ||
389 | GNUNET_break(0); | ||
390 | break; | ||
391 | } | ||
392 | env = | ||
393 | GNUNET_MQ_msg_extra(iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); | ||
394 | iim->reserved = 0; | ||
395 | iim->file_id = pos->file_id; | ||
396 | GNUNET_memcpy(&iim[1], fn, slen); | ||
397 | GNUNET_MQ_send(mq, env); | ||
398 | } | 392 | } |
399 | env = GNUNET_MQ_msg(iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); | 393 | env = |
400 | GNUNET_MQ_send(mq, env); | 394 | GNUNET_MQ_msg_extra (iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); |
395 | iim->reserved = 0; | ||
396 | iim->file_id = pos->file_id; | ||
397 | GNUNET_memcpy (&iim[1], fn, slen); | ||
398 | GNUNET_MQ_send (mq, env); | ||
399 | } | ||
400 | env = GNUNET_MQ_msg (iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); | ||
401 | GNUNET_MQ_send (mq, env); | ||
401 | } | 402 | } |
402 | 403 | ||
403 | 404 | ||
@@ -408,23 +409,23 @@ GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq) | |||
408 | * @return #GNUNET_YES if the @a fid was found | 409 | * @return #GNUNET_YES if the @a fid was found |
409 | */ | 410 | */ |
410 | int | 411 | int |
411 | GNUNET_FS_indexing_do_unindex(const struct GNUNET_HashCode *fid) | 412 | GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid) |
412 | { | 413 | { |
413 | struct IndexInfo *pos; | 414 | struct IndexInfo *pos; |
414 | 415 | ||
415 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 416 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
417 | { | ||
418 | if (0 == memcmp (&pos->file_id, fid, sizeof(struct GNUNET_HashCode))) | ||
416 | { | 419 | { |
417 | if (0 == memcmp(&pos->file_id, fid, sizeof(struct GNUNET_HashCode))) | 420 | GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); |
418 | { | 421 | GNUNET_break ( |
419 | GNUNET_CONTAINER_DLL_remove(indexed_files_head, indexed_files_tail, pos); | 422 | GNUNET_OK == |
420 | GNUNET_break( | 423 | GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); |
421 | GNUNET_OK == | 424 | GNUNET_free (pos); |
422 | GNUNET_CONTAINER_multihashmap_remove(ifm, &pos->file_id, pos)); | 425 | write_index_list (); |
423 | GNUNET_free(pos); | 426 | return GNUNET_YES; |
424 | write_index_list(); | ||
425 | return GNUNET_YES; | ||
426 | } | ||
427 | } | 427 | } |
428 | } | ||
428 | return GNUNET_NO; | 429 | return GNUNET_NO; |
429 | } | 430 | } |
430 | 431 | ||
@@ -436,40 +437,40 @@ GNUNET_FS_indexing_do_unindex(const struct GNUNET_HashCode *fid) | |||
436 | * @param file_id hash identifier for @a filename | 437 | * @param file_id hash identifier for @a filename |
437 | */ | 438 | */ |
438 | void | 439 | void |
439 | GNUNET_FS_add_to_index(const char *filename, | 440 | GNUNET_FS_add_to_index (const char *filename, |
440 | const struct GNUNET_HashCode *file_id) | 441 | const struct GNUNET_HashCode *file_id) |
441 | { | 442 | { |
442 | struct IndexInfo *ii; | 443 | struct IndexInfo *ii; |
443 | size_t slen; | 444 | size_t slen; |
444 | 445 | ||
445 | ii = GNUNET_CONTAINER_multihashmap_get(ifm, file_id); | 446 | ii = GNUNET_CONTAINER_multihashmap_get (ifm, file_id); |
446 | if (NULL != ii) | 447 | if (NULL != ii) |
447 | { | 448 | { |
448 | GNUNET_log( | 449 | GNUNET_log ( |
449 | GNUNET_ERROR_TYPE_INFO, | 450 | GNUNET_ERROR_TYPE_INFO, |
450 | _( | 451 | _ ( |
451 | "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), | 452 | "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), |
452 | filename, | 453 | filename, |
453 | ii->filename); | 454 | ii->filename); |
454 | return; | 455 | return; |
455 | } | 456 | } |
456 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
457 | "Adding file %s to index as %s\n", | 458 | "Adding file %s to index as %s\n", |
458 | filename, | 459 | filename, |
459 | GNUNET_h2s(file_id)); | 460 | GNUNET_h2s (file_id)); |
460 | slen = strlen(filename) + 1; | 461 | slen = strlen (filename) + 1; |
461 | ii = GNUNET_malloc(sizeof(struct IndexInfo) + slen); | 462 | ii = GNUNET_malloc (sizeof(struct IndexInfo) + slen); |
462 | ii->file_id = *file_id; | 463 | ii->file_id = *file_id; |
463 | ii->filename = (const char *)&ii[1]; | 464 | ii->filename = (const char *) &ii[1]; |
464 | GNUNET_memcpy(&ii[1], filename, slen); | 465 | GNUNET_memcpy (&ii[1], filename, slen); |
465 | GNUNET_CONTAINER_DLL_insert(indexed_files_head, indexed_files_tail, ii); | 466 | GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, ii); |
466 | GNUNET_assert(GNUNET_OK == | 467 | GNUNET_assert (GNUNET_OK == |
467 | GNUNET_CONTAINER_multihashmap_put( | 468 | GNUNET_CONTAINER_multihashmap_put ( |
468 | ifm, | 469 | ifm, |
469 | &ii->file_id, | 470 | &ii->file_id, |
470 | ii, | 471 | ii, |
471 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 472 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
472 | write_index_list(); | 473 | write_index_list (); |
473 | } | 474 | } |
474 | 475 | ||
475 | 476 | ||
@@ -477,21 +478,21 @@ GNUNET_FS_add_to_index(const char *filename, | |||
477 | * Shutdown the module. | 478 | * Shutdown the module. |
478 | */ | 479 | */ |
479 | void | 480 | void |
480 | GNUNET_FS_indexing_done() | 481 | GNUNET_FS_indexing_done () |
481 | { | 482 | { |
482 | struct IndexInfo *pos; | 483 | struct IndexInfo *pos; |
483 | 484 | ||
484 | while (NULL != (pos = indexed_files_head)) | 485 | while (NULL != (pos = indexed_files_head)) |
485 | { | 486 | { |
486 | GNUNET_CONTAINER_DLL_remove(indexed_files_head, indexed_files_tail, pos); | 487 | GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); |
487 | if (pos->fhc != NULL) | 488 | if (pos->fhc != NULL) |
488 | GNUNET_CRYPTO_hash_file_cancel(pos->fhc); | 489 | GNUNET_CRYPTO_hash_file_cancel (pos->fhc); |
489 | GNUNET_break( | 490 | GNUNET_break ( |
490 | GNUNET_OK == | 491 | GNUNET_OK == |
491 | GNUNET_CONTAINER_multihashmap_remove(ifm, &pos->file_id, pos)); | 492 | GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); |
492 | GNUNET_free(pos); | 493 | GNUNET_free (pos); |
493 | } | 494 | } |
494 | GNUNET_CONTAINER_multihashmap_destroy(ifm); | 495 | GNUNET_CONTAINER_multihashmap_destroy (ifm); |
495 | ifm = NULL; | 496 | ifm = NULL; |
496 | cfg = NULL; | 497 | cfg = NULL; |
497 | } | 498 | } |
@@ -504,13 +505,13 @@ GNUNET_FS_indexing_done() | |||
504 | * @param d datastore to use | 505 | * @param d datastore to use |
505 | */ | 506 | */ |
506 | int | 507 | int |
507 | GNUNET_FS_indexing_init(const struct GNUNET_CONFIGURATION_Handle *c, | 508 | GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, |
508 | struct GNUNET_DATASTORE_Handle *d) | 509 | struct GNUNET_DATASTORE_Handle *d) |
509 | { | 510 | { |
510 | cfg = c; | 511 | cfg = c; |
511 | dsh = d; | 512 | dsh = d; |
512 | ifm = GNUNET_CONTAINER_multihashmap_create(128, GNUNET_YES); | 513 | ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES); |
513 | read_index_list(); | 514 | read_index_list (); |
514 | return GNUNET_OK; | 515 | return GNUNET_OK; |
515 | } | 516 | } |
516 | 517 | ||
diff --git a/src/fs/gnunet-service-fs_indexing.h b/src/fs/gnunet-service-fs_indexing.h index 4c137d7a6..546dbb172 100644 --- a/src/fs/gnunet-service-fs_indexing.h +++ b/src/fs/gnunet-service-fs_indexing.h | |||
@@ -56,17 +56,17 @@ | |||
56 | * @return #GNUNET_OK on success | 56 | * @return #GNUNET_OK on success |
57 | */ | 57 | */ |
58 | int | 58 | int |
59 | GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, | 59 | GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, |
60 | uint32_t size, | 60 | uint32_t size, |
61 | const void *data, | 61 | const void *data, |
62 | enum GNUNET_BLOCK_Type type, | 62 | enum GNUNET_BLOCK_Type type, |
63 | uint32_t priority, | 63 | uint32_t priority, |
64 | uint32_t anonymity, | 64 | uint32_t anonymity, |
65 | uint32_t replication, | 65 | uint32_t replication, |
66 | struct GNUNET_TIME_Absolute expiration, | 66 | struct GNUNET_TIME_Absolute expiration, |
67 | uint64_t uid, | 67 | uint64_t uid, |
68 | GNUNET_DATASTORE_DatumProcessor cont, | 68 | GNUNET_DATASTORE_DatumProcessor cont, |
69 | void *cont_cls); | 69 | void *cont_cls); |
70 | 70 | ||
71 | 71 | ||
72 | /** | 72 | /** |
@@ -75,7 +75,7 @@ GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, | |||
75 | * @param mq message queue to send information to | 75 | * @param mq message queue to send information to |
76 | */ | 76 | */ |
77 | void | 77 | void |
78 | GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq); | 78 | GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq); |
79 | 79 | ||
80 | 80 | ||
81 | /** | 81 | /** |
@@ -85,7 +85,7 @@ GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq); | |||
85 | * @return #GNUNET_YES if the @a fid was found | 85 | * @return #GNUNET_YES if the @a fid was found |
86 | */ | 86 | */ |
87 | int | 87 | int |
88 | GNUNET_FS_indexing_do_unindex(const struct GNUNET_HashCode *fid); | 88 | GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid); |
89 | 89 | ||
90 | 90 | ||
91 | /** | 91 | /** |
@@ -95,8 +95,8 @@ GNUNET_FS_indexing_do_unindex(const struct GNUNET_HashCode *fid); | |||
95 | * @param file_id hash identifier for @a filename | 95 | * @param file_id hash identifier for @a filename |
96 | */ | 96 | */ |
97 | void | 97 | void |
98 | GNUNET_FS_add_to_index(const char *filename, | 98 | GNUNET_FS_add_to_index (const char *filename, |
99 | const struct GNUNET_HashCode *file_id); | 99 | const struct GNUNET_HashCode *file_id); |
100 | 100 | ||
101 | 101 | ||
102 | /** | 102 | /** |
@@ -107,15 +107,15 @@ GNUNET_FS_add_to_index(const char *filename, | |||
107 | * @return GNUNET_OK on success | 107 | * @return GNUNET_OK on success |
108 | */ | 108 | */ |
109 | int | 109 | int |
110 | GNUNET_FS_indexing_init(const struct GNUNET_CONFIGURATION_Handle *c, | 110 | GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, |
111 | struct GNUNET_DATASTORE_Handle *d); | 111 | struct GNUNET_DATASTORE_Handle *d); |
112 | 112 | ||
113 | 113 | ||
114 | /** | 114 | /** |
115 | * Shutdown the module. | 115 | * Shutdown the module. |
116 | */ | 116 | */ |
117 | void | 117 | void |
118 | GNUNET_FS_indexing_done(void); | 118 | GNUNET_FS_indexing_done (void); |
119 | 119 | ||
120 | 120 | ||
121 | #endif | 121 | #endif |
diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c index 3c1112333..7933b2dee 100644 --- a/src/fs/gnunet-service-fs_pe.c +++ b/src/fs/gnunet-service-fs_pe.c | |||
@@ -63,7 +63,8 @@ struct PeerPlan; | |||
63 | * to be able to lookup all plan entries corresponding | 63 | * to be able to lookup all plan entries corresponding |
64 | * to a given pending request.) | 64 | * to a given pending request.) |
65 | */ | 65 | */ |
66 | struct GSF_PendingRequestPlanBijection { | 66 | struct GSF_PendingRequestPlanBijection |
67 | { | ||
67 | /** | 68 | /** |
68 | * This is a doubly-linked list. | 69 | * This is a doubly-linked list. |
69 | */ | 70 | */ |
@@ -104,7 +105,8 @@ struct GSF_PendingRequestPlanBijection { | |||
104 | * with one entry in each heap of each `struct PeerPlan`. Each | 105 | * with one entry in each heap of each `struct PeerPlan`. Each |
105 | * entry tracks information relevant for this request and this peer. | 106 | * entry tracks information relevant for this request and this peer. |
106 | */ | 107 | */ |
107 | struct GSF_RequestPlan { | 108 | struct GSF_RequestPlan |
109 | { | ||
108 | /** | 110 | /** |
109 | * This is a doubly-linked list. | 111 | * This is a doubly-linked list. |
110 | */ | 112 | */ |
@@ -162,7 +164,8 @@ struct GSF_RequestPlan { | |||
162 | /** | 164 | /** |
163 | * Transmission plan for a peer. | 165 | * Transmission plan for a peer. |
164 | */ | 166 | */ |
165 | struct PeerPlan { | 167 | struct PeerPlan |
168 | { | ||
166 | /** | 169 | /** |
167 | * Heap with pending queries (`struct GSF_RequestPlan`), higher weights mean higher priority. | 170 | * Heap with pending queries (`struct GSF_RequestPlan`), higher weights mean higher priority. |
168 | */ | 171 | */ |
@@ -227,9 +230,9 @@ static unsigned long long plan_count; | |||
227 | * @return the associated query | 230 | * @return the associated query |
228 | */ | 231 | */ |
229 | static const struct GNUNET_HashCode * | 232 | static const struct GNUNET_HashCode * |
230 | get_rp_key(struct GSF_RequestPlan *rp) | 233 | get_rp_key (struct GSF_RequestPlan *rp) |
231 | { | 234 | { |
232 | return &GSF_pending_request_get_data_(rp->pe_head->pr)->query; | 235 | return &GSF_pending_request_get_data_ (rp->pe_head->pr)->query; |
233 | } | 236 | } |
234 | 237 | ||
235 | 238 | ||
@@ -240,10 +243,10 @@ get_rp_key(struct GSF_RequestPlan *rp) | |||
240 | * @param rp request to plan | 243 | * @param rp request to plan |
241 | */ | 244 | */ |
242 | static void | 245 | static void |
243 | plan(struct PeerPlan *pp, | 246 | plan (struct PeerPlan *pp, |
244 | struct GSF_RequestPlan *rp) | 247 | struct GSF_RequestPlan *rp) |
245 | { | 248 | { |
246 | #define N ((double)128.0) | 249 | #define N ((double) 128.0) |
247 | /** | 250 | /** |
248 | * Running average delay we currently impose. | 251 | * Running average delay we currently impose. |
249 | */ | 252 | */ |
@@ -252,28 +255,28 @@ plan(struct PeerPlan *pp, | |||
252 | struct GSF_PendingRequestData *prd; | 255 | struct GSF_PendingRequestData *prd; |
253 | struct GNUNET_TIME_Relative delay; | 256 | struct GNUNET_TIME_Relative delay; |
254 | 257 | ||
255 | GNUNET_assert(rp->pp == pp); | 258 | GNUNET_assert (rp->pp == pp); |
256 | GNUNET_STATISTICS_set(GSF_stats, | 259 | GNUNET_STATISTICS_set (GSF_stats, |
257 | gettext_noop("# average retransmission delay (ms)"), | 260 | gettext_noop ("# average retransmission delay (ms)"), |
258 | total_delay * 1000LL / plan_count, GNUNET_NO); | 261 | total_delay * 1000LL / plan_count, GNUNET_NO); |
259 | prd = GSF_pending_request_get_data_(rp->pe_head->pr); | 262 | prd = GSF_pending_request_get_data_ (rp->pe_head->pr); |
260 | 263 | ||
261 | if (rp->transmission_counter < 8) | 264 | if (rp->transmission_counter < 8) |
262 | delay = | 265 | delay = |
263 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 266 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
264 | rp->transmission_counter); | 267 | rp->transmission_counter); |
265 | else if (rp->transmission_counter < 32) | 268 | else if (rp->transmission_counter < 32) |
266 | delay = | 269 | delay = |
267 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 270 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
268 | 8 + | 271 | 8 |
269 | (1LL << (rp->transmission_counter - 8))); | 272 | + (1LL << (rp->transmission_counter - 8))); |
270 | else | 273 | else |
271 | delay = | 274 | delay = |
272 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 275 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
273 | 8 + (1LL << 24)); | 276 | 8 + (1LL << 24)); |
274 | delay.rel_value_us = | 277 | delay.rel_value_us = |
275 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 278 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
276 | delay.rel_value_us + 1); | 279 | delay.rel_value_us + 1); |
277 | /* Add 0.01 to avg_delay to avoid division-by-zero later */ | 280 | /* Add 0.01 to avg_delay to avoid division-by-zero later */ |
278 | avg_delay = (((avg_delay * (N - 1.0)) + delay.rel_value_us) / N) + 0.01; | 281 | avg_delay = (((avg_delay * (N - 1.0)) + delay.rel_value_us) / N) + 0.01; |
279 | 282 | ||
@@ -299,36 +302,37 @@ plan(struct PeerPlan *pp, | |||
299 | * Note: M_PI_4 = PI/4 = arctan(1) | 302 | * Note: M_PI_4 = PI/4 = arctan(1) |
300 | */ | 303 | */ |
301 | rp->priority = | 304 | rp->priority = |
302 | round((GSF_current_priorities + | 305 | round ((GSF_current_priorities |
303 | 1.0) * atan(delay.rel_value_us / avg_delay)) / M_PI_4; | 306 | + 1.0) * atan (delay.rel_value_us / avg_delay)) / M_PI_4; |
304 | /* Note: usage of 'round' and 'atan' requires -lm */ | 307 | /* Note: usage of 'round' and 'atan' requires -lm */ |
305 | 308 | ||
306 | if (rp->transmission_counter != 0) | 309 | if (rp->transmission_counter != 0) |
307 | delay.rel_value_us += TTL_DECREMENT * 1000; | 310 | delay.rel_value_us += TTL_DECREMENT * 1000; |
308 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
309 | "Considering (re)transmission number %u in %s\n", | 312 | "Considering (re)transmission number %u in %s\n", |
310 | (unsigned int)rp->transmission_counter, | 313 | (unsigned int) rp->transmission_counter, |
311 | GNUNET_STRINGS_relative_time_to_string(delay, | 314 | GNUNET_STRINGS_relative_time_to_string (delay, |
312 | GNUNET_YES)); | 315 | GNUNET_YES)); |
313 | rp->earliest_transmission = GNUNET_TIME_relative_to_absolute(delay); | 316 | rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay); |
314 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
315 | "Earliest (re)transmission for `%s' in %us\n", | 318 | "Earliest (re)transmission for `%s' in %us\n", |
316 | GNUNET_h2s(&prd->query), | 319 | GNUNET_h2s (&prd->query), |
317 | rp->transmission_counter); | 320 | rp->transmission_counter); |
318 | GNUNET_assert(rp->hn == NULL); | 321 | GNUNET_assert (rp->hn == NULL); |
319 | if (0 == GNUNET_TIME_absolute_get_remaining(rp->earliest_transmission).rel_value_us) | 322 | if (0 == GNUNET_TIME_absolute_get_remaining ( |
320 | rp->hn = GNUNET_CONTAINER_heap_insert(pp->priority_heap, | 323 | rp->earliest_transmission).rel_value_us) |
321 | rp, | 324 | rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, |
322 | rp->priority); | 325 | rp, |
326 | rp->priority); | ||
323 | else | 327 | else |
324 | rp->hn = | 328 | rp->hn = |
325 | GNUNET_CONTAINER_heap_insert(pp->delay_heap, | 329 | GNUNET_CONTAINER_heap_insert (pp->delay_heap, |
326 | rp, | 330 | rp, |
327 | rp->earliest_transmission.abs_value_us); | 331 | rp->earliest_transmission.abs_value_us); |
328 | GNUNET_assert(GNUNET_YES == | 332 | GNUNET_assert (GNUNET_YES == |
329 | GNUNET_CONTAINER_multihashmap_contains_value(pp->plan_map, | 333 | GNUNET_CONTAINER_multihashmap_contains_value (pp->plan_map, |
330 | get_rp_key(rp), | 334 | get_rp_key (rp), |
331 | rp)); | 335 | rp)); |
332 | #undef N | 336 | #undef N |
333 | } | 337 | } |
334 | 338 | ||
@@ -340,7 +344,7 @@ plan(struct PeerPlan *pp, | |||
340 | * @return pending request with highest TTL | 344 | * @return pending request with highest TTL |
341 | */ | 345 | */ |
342 | struct GSF_PendingRequest * | 346 | struct GSF_PendingRequest * |
343 | get_latest(const struct GSF_RequestPlan *rp) | 347 | get_latest (const struct GSF_RequestPlan *rp) |
344 | { | 348 | { |
345 | struct GSF_PendingRequest *ret; | 349 | struct GSF_PendingRequest *ret; |
346 | struct GSF_PendingRequestPlanBijection *bi; | 350 | struct GSF_PendingRequestPlanBijection *bi; |
@@ -351,18 +355,18 @@ get_latest(const struct GSF_RequestPlan *rp) | |||
351 | if (NULL == bi) | 355 | if (NULL == bi) |
352 | return NULL; /* should never happen */ | 356 | return NULL; /* should never happen */ |
353 | ret = bi->pr; | 357 | ret = bi->pr; |
354 | rprd = GSF_pending_request_get_data_(ret); | 358 | rprd = GSF_pending_request_get_data_ (ret); |
355 | for (bi = bi->next_PE; NULL != bi; bi = bi->next_PE) | 359 | for (bi = bi->next_PE; NULL != bi; bi = bi->next_PE) |
360 | { | ||
361 | GNUNET_break (GNUNET_YES == | ||
362 | GSF_pending_request_test_active_ (bi->pr)); | ||
363 | prd = GSF_pending_request_get_data_ (bi->pr); | ||
364 | if (prd->ttl.abs_value_us > rprd->ttl.abs_value_us) | ||
356 | { | 365 | { |
357 | GNUNET_break(GNUNET_YES == | 366 | ret = bi->pr; |
358 | GSF_pending_request_test_active_(bi->pr)); | 367 | rprd = prd; |
359 | prd = GSF_pending_request_get_data_(bi->pr); | ||
360 | if (prd->ttl.abs_value_us > rprd->ttl.abs_value_us) | ||
361 | { | ||
362 | ret = bi->pr; | ||
363 | rprd = prd; | ||
364 | } | ||
365 | } | 368 | } |
369 | } | ||
366 | return ret; | 370 | return ret; |
367 | } | 371 | } |
368 | 372 | ||
@@ -373,100 +377,102 @@ get_latest(const struct GSF_RequestPlan *rp) | |||
373 | * @param cls the `struct PeerPlan` | 377 | * @param cls the `struct PeerPlan` |
374 | */ | 378 | */ |
375 | static void | 379 | static void |
376 | schedule_peer_transmission(void *cls) | 380 | schedule_peer_transmission (void *cls) |
377 | { | 381 | { |
378 | struct PeerPlan *pp = cls; | 382 | struct PeerPlan *pp = cls; |
379 | struct GSF_RequestPlan *rp; | 383 | struct GSF_RequestPlan *rp; |
380 | struct GNUNET_TIME_Relative delay; | 384 | struct GNUNET_TIME_Relative delay; |
381 | 385 | ||
382 | if (NULL != pp->task) | 386 | if (NULL != pp->task) |
383 | { | 387 | { |
384 | pp->task = NULL; | 388 | pp->task = NULL; |
385 | } | 389 | } |
386 | else | 390 | else |
387 | { | 391 | { |
388 | GNUNET_assert(NULL != pp->env); | 392 | GNUNET_assert (NULL != pp->env); |
389 | pp->env = NULL; | 393 | pp->env = NULL; |
390 | } | 394 | } |
391 | /* move ready requests to priority queue */ | 395 | /* move ready requests to priority queue */ |
392 | while ((NULL != (rp = GNUNET_CONTAINER_heap_peek(pp->delay_heap))) && | 396 | while ((NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) && |
393 | (0 == GNUNET_TIME_absolute_get_remaining | 397 | (0 == GNUNET_TIME_absolute_get_remaining |
394 | (rp->earliest_transmission).rel_value_us)) | 398 | (rp->earliest_transmission).rel_value_us)) |
399 | { | ||
400 | GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->delay_heap)); | ||
401 | rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, | ||
402 | rp, | ||
403 | rp->priority); | ||
404 | } | ||
405 | if (0 == GNUNET_CONTAINER_heap_get_size (pp->priority_heap)) | ||
406 | { | ||
407 | /* priority heap (still) empty, check for delay... */ | ||
408 | rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap); | ||
409 | if (NULL == rp) | ||
395 | { | 410 | { |
396 | GNUNET_assert(rp == GNUNET_CONTAINER_heap_remove_root(pp->delay_heap)); | 411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
397 | rp->hn = GNUNET_CONTAINER_heap_insert(pp->priority_heap, | 412 | "No active requests for plan %p.\n", |
398 | rp, | 413 | pp); |
399 | rp->priority); | 414 | return; /* both queues empty */ |
400 | } | 415 | } |
401 | if (0 == GNUNET_CONTAINER_heap_get_size(pp->priority_heap)) | 416 | delay = GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission); |
402 | { | 417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
403 | /* priority heap (still) empty, check for delay... */ | 418 | "Sleeping for %s before retrying requests on plan %p.\n", |
404 | rp = GNUNET_CONTAINER_heap_peek(pp->delay_heap); | 419 | GNUNET_STRINGS_relative_time_to_string (delay, |
405 | if (NULL == rp) | ||
406 | { | ||
407 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
408 | "No active requests for plan %p.\n", | ||
409 | pp); | ||
410 | return; /* both queues empty */ | ||
411 | } | ||
412 | delay = GNUNET_TIME_absolute_get_remaining(rp->earliest_transmission); | ||
413 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
414 | "Sleeping for %s before retrying requests on plan %p.\n", | ||
415 | GNUNET_STRINGS_relative_time_to_string(delay, | ||
416 | GNUNET_YES), | 420 | GNUNET_YES), |
417 | pp); | 421 | pp); |
418 | GNUNET_STATISTICS_set(GSF_stats, | 422 | GNUNET_STATISTICS_set (GSF_stats, |
419 | gettext_noop("# delay heap timeout (ms)"), | 423 | gettext_noop ("# delay heap timeout (ms)"), |
420 | delay.rel_value_us / 1000LL, GNUNET_NO); | 424 | delay.rel_value_us / 1000LL, GNUNET_NO); |
421 | 425 | ||
422 | pp->task | 426 | pp->task |
423 | = GNUNET_SCHEDULER_add_at(rp->earliest_transmission, | 427 | = GNUNET_SCHEDULER_add_at (rp->earliest_transmission, |
424 | &schedule_peer_transmission, | 428 | &schedule_peer_transmission, |
425 | pp); | 429 | pp); |
426 | return; | 430 | return; |
427 | } | 431 | } |
428 | #if INSANE_STATISTICS | 432 | #if INSANE_STATISTICS |
429 | GNUNET_STATISTICS_update(GSF_stats, | 433 | GNUNET_STATISTICS_update (GSF_stats, |
430 | gettext_noop("# query plans executed"), | 434 | gettext_noop ("# query plans executed"), |
431 | 1, | 435 | 1, |
432 | GNUNET_NO); | 436 | GNUNET_NO); |
433 | #endif | 437 | #endif |
434 | /* process from priority heap */ | 438 | /* process from priority heap */ |
435 | rp = GNUNET_CONTAINER_heap_remove_root(pp->priority_heap); | 439 | rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap); |
436 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
437 | "Executing query plan %p\n", | 441 | "Executing query plan %p\n", |
438 | rp); | 442 | rp); |
439 | GNUNET_assert(NULL != rp); | 443 | GNUNET_assert (NULL != rp); |
440 | rp->hn = NULL; | 444 | rp->hn = NULL; |
441 | rp->last_transmission = GNUNET_TIME_absolute_get(); | 445 | rp->last_transmission = GNUNET_TIME_absolute_get (); |
442 | rp->transmission_counter++; | 446 | rp->transmission_counter++; |
443 | total_delay++; | 447 | total_delay++; |
444 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
445 | "Executing plan %p executed %u times, planning retransmission\n", | 449 | "Executing plan %p executed %u times, planning retransmission\n", |
446 | rp, | 450 | rp, |
447 | rp->transmission_counter); | 451 | rp->transmission_counter); |
448 | GNUNET_assert(NULL == pp->env); | 452 | GNUNET_assert (NULL == pp->env); |
449 | pp->env = GSF_pending_request_get_message_(get_latest(rp)); | 453 | pp->env = GSF_pending_request_get_message_ (get_latest (rp)); |
450 | GNUNET_MQ_notify_sent(pp->env, | 454 | GNUNET_MQ_notify_sent (pp->env, |
451 | &schedule_peer_transmission, | 455 | &schedule_peer_transmission, |
452 | pp); | 456 | pp); |
453 | GSF_peer_transmit_(pp->cp, | 457 | GSF_peer_transmit_ (pp->cp, |
454 | GNUNET_YES, | 458 | GNUNET_YES, |
455 | rp->priority, | 459 | rp->priority, |
456 | pp->env); | 460 | pp->env); |
457 | GNUNET_STATISTICS_update(GSF_stats, | 461 | GNUNET_STATISTICS_update (GSF_stats, |
458 | gettext_noop("# query messages sent to other peers"), | 462 | gettext_noop ( |
459 | 1, | 463 | "# query messages sent to other peers"), |
460 | GNUNET_NO); | 464 | 1, |
461 | plan(pp, | 465 | GNUNET_NO); |
462 | rp); | 466 | plan (pp, |
467 | rp); | ||
463 | } | 468 | } |
464 | 469 | ||
465 | 470 | ||
466 | /** | 471 | /** |
467 | * Closure for merge_pr(). | 472 | * Closure for merge_pr(). |
468 | */ | 473 | */ |
469 | struct MergeContext { | 474 | struct MergeContext |
475 | { | ||
470 | /** | 476 | /** |
471 | * Request we are trying to merge. | 477 | * Request we are trying to merge. |
472 | */ | 478 | */ |
@@ -490,9 +496,9 @@ struct MergeContext { | |||
490 | * #GNUNET_NO if not (merge success) | 496 | * #GNUNET_NO if not (merge success) |
491 | */ | 497 | */ |
492 | static int | 498 | static int |
493 | merge_pr(void *cls, | 499 | merge_pr (void *cls, |
494 | const struct GNUNET_HashCode *query, | 500 | const struct GNUNET_HashCode *query, |
495 | void *element) | 501 | void *element) |
496 | { | 502 | { |
497 | struct MergeContext *mpr = cls; | 503 | struct MergeContext *mpr = cls; |
498 | struct GSF_RequestPlan *rp = element; | 504 | struct GSF_RequestPlan *rp = element; |
@@ -500,44 +506,44 @@ merge_pr(void *cls, | |||
500 | struct GSF_PendingRequestPlanBijection *bi; | 506 | struct GSF_PendingRequestPlanBijection *bi; |
501 | struct GSF_PendingRequest *latest; | 507 | struct GSF_PendingRequest *latest; |
502 | 508 | ||
503 | GNUNET_break(GNUNET_YES == | 509 | GNUNET_break (GNUNET_YES == |
504 | GSF_pending_request_test_active_(mpr->pr)); | 510 | GSF_pending_request_test_active_ (mpr->pr)); |
505 | if (GNUNET_OK != | 511 | if (GNUNET_OK != |
506 | GSF_pending_request_is_compatible_(mpr->pr, | 512 | GSF_pending_request_is_compatible_ (mpr->pr, |
507 | rp->pe_head->pr)) | 513 | rp->pe_head->pr)) |
508 | return GNUNET_YES; | 514 | return GNUNET_YES; |
509 | /* merge new request with existing request plan */ | 515 | /* merge new request with existing request plan */ |
510 | bi = GNUNET_new(struct GSF_PendingRequestPlanBijection); | 516 | bi = GNUNET_new (struct GSF_PendingRequestPlanBijection); |
511 | bi->rp = rp; | 517 | bi->rp = rp; |
512 | bi->pr = mpr->pr; | 518 | bi->pr = mpr->pr; |
513 | prd = GSF_pending_request_get_data_(mpr->pr); | 519 | prd = GSF_pending_request_get_data_ (mpr->pr); |
514 | GNUNET_CONTAINER_MDLL_insert(PR, | 520 | GNUNET_CONTAINER_MDLL_insert (PR, |
515 | prd->pr_head, | 521 | prd->pr_head, |
516 | prd->pr_tail, | 522 | prd->pr_tail, |
517 | bi); | 523 | bi); |
518 | GNUNET_CONTAINER_MDLL_insert(PE, | 524 | GNUNET_CONTAINER_MDLL_insert (PE, |
519 | rp->pe_head, | 525 | rp->pe_head, |
520 | rp->pe_tail, | 526 | rp->pe_tail, |
521 | bi); | 527 | bi); |
522 | mpr->merged = GNUNET_YES; | 528 | mpr->merged = GNUNET_YES; |
523 | #if INSANE_STATISTICS | 529 | #if INSANE_STATISTICS |
524 | GNUNET_STATISTICS_update(GSF_stats, | 530 | GNUNET_STATISTICS_update (GSF_stats, |
525 | gettext_noop("# requests merged"), | 531 | gettext_noop ("# requests merged"), |
526 | 1, | 532 | 1, |
527 | GNUNET_NO); | 533 | GNUNET_NO); |
528 | #endif | 534 | #endif |
529 | latest = get_latest(rp); | 535 | latest = get_latest (rp); |
530 | if (GSF_pending_request_get_data_(latest)->ttl.abs_value_us < | 536 | if (GSF_pending_request_get_data_ (latest)->ttl.abs_value_us < |
531 | prd->ttl.abs_value_us) | 537 | prd->ttl.abs_value_us) |
532 | { | 538 | { |
533 | #if INSANE_STATISTICS | 539 | #if INSANE_STATISTICS |
534 | GNUNET_STATISTICS_update(GSF_stats, | 540 | GNUNET_STATISTICS_update (GSF_stats, |
535 | gettext_noop("# requests refreshed"), | 541 | gettext_noop ("# requests refreshed"), |
536 | 1, | 542 | 1, |
537 | GNUNET_NO); | 543 | GNUNET_NO); |
538 | #endif | 544 | #endif |
539 | rp->transmission_counter = 0; /* reset */ | 545 | rp->transmission_counter = 0; /* reset */ |
540 | } | 546 | } |
541 | return GNUNET_NO; | 547 | return GNUNET_NO; |
542 | } | 548 | } |
543 | 549 | ||
@@ -549,8 +555,8 @@ merge_pr(void *cls, | |||
549 | * @param pr request with the entry | 555 | * @param pr request with the entry |
550 | */ | 556 | */ |
551 | void | 557 | void |
552 | GSF_plan_add_(struct GSF_ConnectedPeer *cp, | 558 | GSF_plan_add_ (struct GSF_ConnectedPeer *cp, |
553 | struct GSF_PendingRequest *pr) | 559 | struct GSF_PendingRequest *pr) |
554 | { | 560 | { |
555 | const struct GNUNET_PeerIdentity *id; | 561 | const struct GNUNET_PeerIdentity *id; |
556 | struct PeerPlan *pp; | 562 | struct PeerPlan *pp; |
@@ -559,66 +565,66 @@ GSF_plan_add_(struct GSF_ConnectedPeer *cp, | |||
559 | struct GSF_PendingRequestPlanBijection *bi; | 565 | struct GSF_PendingRequestPlanBijection *bi; |
560 | struct MergeContext mpc; | 566 | struct MergeContext mpc; |
561 | 567 | ||
562 | GNUNET_assert(GNUNET_YES == | 568 | GNUNET_assert (GNUNET_YES == |
563 | GSF_pending_request_test_active_(pr)); | 569 | GSF_pending_request_test_active_ (pr)); |
564 | GNUNET_assert(NULL != cp); | 570 | GNUNET_assert (NULL != cp); |
565 | id = GSF_connected_peer_get_identity2_(cp); | 571 | id = GSF_connected_peer_get_identity2_ (cp); |
566 | pp = GNUNET_CONTAINER_multipeermap_get(plans, id); | 572 | pp = GNUNET_CONTAINER_multipeermap_get (plans, id); |
567 | if (NULL == pp) | 573 | if (NULL == pp) |
568 | { | 574 | { |
569 | pp = GNUNET_new(struct PeerPlan); | 575 | pp = GNUNET_new (struct PeerPlan); |
570 | pp->plan_map = GNUNET_CONTAINER_multihashmap_create(128, GNUNET_NO); | 576 | pp->plan_map = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); |
571 | pp->priority_heap = | 577 | pp->priority_heap = |
572 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MAX); | 578 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); |
573 | pp->delay_heap = | 579 | pp->delay_heap = |
574 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 580 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
575 | pp->cp = cp; | 581 | pp->cp = cp; |
576 | GNUNET_assert(GNUNET_OK == | 582 | GNUNET_assert (GNUNET_OK == |
577 | GNUNET_CONTAINER_multipeermap_put(plans, | 583 | GNUNET_CONTAINER_multipeermap_put (plans, |
578 | id, | 584 | id, |
579 | pp, | 585 | pp, |
580 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 586 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
581 | pp->task = GNUNET_SCHEDULER_add_now(&schedule_peer_transmission, | 587 | pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, |
582 | pp); | 588 | pp); |
583 | } | 589 | } |
584 | mpc.merged = GNUNET_NO; | 590 | mpc.merged = GNUNET_NO; |
585 | mpc.pr = pr; | 591 | mpc.pr = pr; |
586 | prd = GSF_pending_request_get_data_(pr); | 592 | prd = GSF_pending_request_get_data_ (pr); |
587 | GNUNET_CONTAINER_multihashmap_get_multiple(pp->plan_map, | 593 | GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map, |
588 | &prd->query, | 594 | &prd->query, |
589 | &merge_pr, | 595 | &merge_pr, |
590 | &mpc); | 596 | &mpc); |
591 | if (GNUNET_NO != mpc.merged) | 597 | if (GNUNET_NO != mpc.merged) |
592 | return; | 598 | return; |
593 | plan_count++; | 599 | plan_count++; |
594 | GNUNET_STATISTICS_update(GSF_stats, | 600 | GNUNET_STATISTICS_update (GSF_stats, |
595 | gettext_noop("# query plan entries"), | 601 | gettext_noop ("# query plan entries"), |
596 | 1, | 602 | 1, |
597 | GNUNET_NO); | 603 | GNUNET_NO); |
598 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
599 | "Planning transmission of query `%s' to peer `%s'\n", | 605 | "Planning transmission of query `%s' to peer `%s'\n", |
600 | GNUNET_h2s(&prd->query), | 606 | GNUNET_h2s (&prd->query), |
601 | GNUNET_i2s(id)); | 607 | GNUNET_i2s (id)); |
602 | rp = GNUNET_new(struct GSF_RequestPlan); | 608 | rp = GNUNET_new (struct GSF_RequestPlan); |
603 | bi = GNUNET_new(struct GSF_PendingRequestPlanBijection); | 609 | bi = GNUNET_new (struct GSF_PendingRequestPlanBijection); |
604 | bi->rp = rp; | 610 | bi->rp = rp; |
605 | bi->pr = pr; | 611 | bi->pr = pr; |
606 | GNUNET_CONTAINER_MDLL_insert(PR, | 612 | GNUNET_CONTAINER_MDLL_insert (PR, |
607 | prd->pr_head, | 613 | prd->pr_head, |
608 | prd->pr_tail, | 614 | prd->pr_tail, |
609 | bi); | 615 | bi); |
610 | GNUNET_CONTAINER_MDLL_insert(PE, | 616 | GNUNET_CONTAINER_MDLL_insert (PE, |
611 | rp->pe_head, | 617 | rp->pe_head, |
612 | rp->pe_tail, | 618 | rp->pe_tail, |
613 | bi); | 619 | bi); |
614 | rp->pp = pp; | 620 | rp->pp = pp; |
615 | GNUNET_assert(GNUNET_YES == | 621 | GNUNET_assert (GNUNET_YES == |
616 | GNUNET_CONTAINER_multihashmap_put(pp->plan_map, | 622 | GNUNET_CONTAINER_multihashmap_put (pp->plan_map, |
617 | get_rp_key(rp), | 623 | get_rp_key (rp), |
618 | rp, | 624 | rp, |
619 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 625 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
620 | plan(pp, | 626 | plan (pp, |
621 | rp); | 627 | rp); |
622 | } | 628 | } |
623 | 629 | ||
624 | 630 | ||
@@ -629,7 +635,7 @@ GSF_plan_add_(struct GSF_ConnectedPeer *cp, | |||
629 | * @param cp connected peer | 635 | * @param cp connected peer |
630 | */ | 636 | */ |
631 | void | 637 | void |
632 | GSF_plan_notify_peer_disconnect_(const struct GSF_ConnectedPeer *cp) | 638 | GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp) |
633 | { | 639 | { |
634 | const struct GNUNET_PeerIdentity *id; | 640 | const struct GNUNET_PeerIdentity *id; |
635 | struct PeerPlan *pp; | 641 | struct PeerPlan *pp; |
@@ -637,70 +643,70 @@ GSF_plan_notify_peer_disconnect_(const struct GSF_ConnectedPeer *cp) | |||
637 | struct GSF_PendingRequestData *prd; | 643 | struct GSF_PendingRequestData *prd; |
638 | struct GSF_PendingRequestPlanBijection *bi; | 644 | struct GSF_PendingRequestPlanBijection *bi; |
639 | 645 | ||
640 | id = GSF_connected_peer_get_identity2_(cp); | 646 | id = GSF_connected_peer_get_identity2_ (cp); |
641 | pp = GNUNET_CONTAINER_multipeermap_get(plans, id); | 647 | pp = GNUNET_CONTAINER_multipeermap_get (plans, id); |
642 | if (NULL == pp) | 648 | if (NULL == pp) |
643 | return; /* nothing was ever planned for this peer */ | 649 | return; /* nothing was ever planned for this peer */ |
644 | GNUNET_assert(GNUNET_YES == | 650 | GNUNET_assert (GNUNET_YES == |
645 | GNUNET_CONTAINER_multipeermap_remove(plans, id, | 651 | GNUNET_CONTAINER_multipeermap_remove (plans, id, |
646 | pp)); | 652 | pp)); |
647 | if (NULL != pp->task) | 653 | if (NULL != pp->task) |
654 | { | ||
655 | GNUNET_SCHEDULER_cancel (pp->task); | ||
656 | pp->task = NULL; | ||
657 | } | ||
658 | while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap))) | ||
659 | { | ||
660 | GNUNET_break (GNUNET_YES == | ||
661 | GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, | ||
662 | get_rp_key (rp), | ||
663 | rp)); | ||
664 | while (NULL != (bi = rp->pe_head)) | ||
648 | { | 665 | { |
649 | GNUNET_SCHEDULER_cancel(pp->task); | 666 | GNUNET_CONTAINER_MDLL_remove (PE, |
650 | pp->task = NULL; | 667 | rp->pe_head, |
668 | rp->pe_tail, | ||
669 | bi); | ||
670 | prd = GSF_pending_request_get_data_ (bi->pr); | ||
671 | GNUNET_CONTAINER_MDLL_remove (PR, | ||
672 | prd->pr_head, | ||
673 | prd->pr_tail, | ||
674 | bi); | ||
675 | GNUNET_free (bi); | ||
651 | } | 676 | } |
652 | while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root(pp->priority_heap))) | 677 | plan_count--; |
653 | { | 678 | GNUNET_free (rp); |
654 | GNUNET_break(GNUNET_YES == | 679 | } |
655 | GNUNET_CONTAINER_multihashmap_remove(pp->plan_map, | 680 | GNUNET_CONTAINER_heap_destroy (pp->priority_heap); |
656 | get_rp_key(rp), | 681 | while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap))) |
682 | { | ||
683 | GNUNET_break (GNUNET_YES == | ||
684 | GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, | ||
685 | get_rp_key (rp), | ||
657 | rp)); | 686 | rp)); |
658 | while (NULL != (bi = rp->pe_head)) | 687 | while (NULL != (bi = rp->pe_head)) |
659 | { | ||
660 | GNUNET_CONTAINER_MDLL_remove(PE, | ||
661 | rp->pe_head, | ||
662 | rp->pe_tail, | ||
663 | bi); | ||
664 | prd = GSF_pending_request_get_data_(bi->pr); | ||
665 | GNUNET_CONTAINER_MDLL_remove(PR, | ||
666 | prd->pr_head, | ||
667 | prd->pr_tail, | ||
668 | bi); | ||
669 | GNUNET_free(bi); | ||
670 | } | ||
671 | plan_count--; | ||
672 | GNUNET_free(rp); | ||
673 | } | ||
674 | GNUNET_CONTAINER_heap_destroy(pp->priority_heap); | ||
675 | while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root(pp->delay_heap))) | ||
676 | { | 688 | { |
677 | GNUNET_break(GNUNET_YES == | 689 | prd = GSF_pending_request_get_data_ (bi->pr); |
678 | GNUNET_CONTAINER_multihashmap_remove(pp->plan_map, | 690 | GNUNET_CONTAINER_MDLL_remove (PE, |
679 | get_rp_key(rp), | 691 | rp->pe_head, |
680 | rp)); | 692 | rp->pe_tail, |
681 | while (NULL != (bi = rp->pe_head)) | 693 | bi); |
682 | { | 694 | GNUNET_CONTAINER_MDLL_remove (PR, |
683 | prd = GSF_pending_request_get_data_(bi->pr); | 695 | prd->pr_head, |
684 | GNUNET_CONTAINER_MDLL_remove(PE, | 696 | prd->pr_tail, |
685 | rp->pe_head, | 697 | bi); |
686 | rp->pe_tail, | 698 | GNUNET_free (bi); |
687 | bi); | ||
688 | GNUNET_CONTAINER_MDLL_remove(PR, | ||
689 | prd->pr_head, | ||
690 | prd->pr_tail, | ||
691 | bi); | ||
692 | GNUNET_free(bi); | ||
693 | } | ||
694 | plan_count--; | ||
695 | GNUNET_free(rp); | ||
696 | } | 699 | } |
697 | GNUNET_STATISTICS_set(GSF_stats, | 700 | plan_count--; |
698 | gettext_noop("# query plan entries"), | 701 | GNUNET_free (rp); |
699 | plan_count, | 702 | } |
700 | GNUNET_NO); | 703 | GNUNET_STATISTICS_set (GSF_stats, |
701 | GNUNET_CONTAINER_heap_destroy(pp->delay_heap); | 704 | gettext_noop ("# query plan entries"), |
702 | GNUNET_CONTAINER_multihashmap_destroy(pp->plan_map); | 705 | plan_count, |
703 | GNUNET_free(pp); | 706 | GNUNET_NO); |
707 | GNUNET_CONTAINER_heap_destroy (pp->delay_heap); | ||
708 | GNUNET_CONTAINER_multihashmap_destroy (pp->plan_map); | ||
709 | GNUNET_free (pp); | ||
704 | } | 710 | } |
705 | 711 | ||
706 | 712 | ||
@@ -714,23 +720,27 @@ GSF_plan_notify_peer_disconnect_(const struct GSF_ConnectedPeer *cp) | |||
714 | * @return #GNUNET_YES if @a result was changed, #GNUNET_NO otherwise. | 720 | * @return #GNUNET_YES if @a result was changed, #GNUNET_NO otherwise. |
715 | */ | 721 | */ |
716 | int | 722 | int |
717 | GSF_request_plan_reference_get_last_transmission_(struct GSF_PendingRequestPlanBijection *pr_head, | 723 | GSF_request_plan_reference_get_last_transmission_ (struct |
718 | struct GSF_ConnectedPeer *sender, | 724 | GSF_PendingRequestPlanBijection |
719 | struct GNUNET_TIME_Absolute *result) | 725 | *pr_head, |
726 | struct GSF_ConnectedPeer * | ||
727 | sender, | ||
728 | struct GNUNET_TIME_Absolute * | ||
729 | result) | ||
720 | { | 730 | { |
721 | struct GSF_PendingRequestPlanBijection *bi; | 731 | struct GSF_PendingRequestPlanBijection *bi; |
722 | 732 | ||
723 | for (bi = pr_head; NULL != bi; bi = bi->next_PR) | 733 | for (bi = pr_head; NULL != bi; bi = bi->next_PR) |
734 | { | ||
735 | if (bi->rp->pp->cp == sender) | ||
724 | { | 736 | { |
725 | if (bi->rp->pp->cp == sender) | 737 | if (0 == bi->rp->last_transmission.abs_value_us) |
726 | { | 738 | *result = GNUNET_TIME_UNIT_FOREVER_ABS; |
727 | if (0 == bi->rp->last_transmission.abs_value_us) | 739 | else |
728 | *result = GNUNET_TIME_UNIT_FOREVER_ABS; | 740 | *result = bi->rp->last_transmission; |
729 | else | 741 | return GNUNET_YES; |
730 | *result = bi->rp->last_transmission; | ||
731 | return GNUNET_YES; | ||
732 | } | ||
733 | } | 742 | } |
743 | } | ||
734 | return GNUNET_NO; | 744 | return GNUNET_NO; |
735 | } | 745 | } |
736 | 746 | ||
@@ -742,41 +752,41 @@ GSF_request_plan_reference_get_last_transmission_(struct GSF_PendingRequestPlanB | |||
742 | * @param pr request that is done | 752 | * @param pr request that is done |
743 | */ | 753 | */ |
744 | void | 754 | void |
745 | GSF_plan_notify_request_done_(struct GSF_PendingRequest *pr) | 755 | GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr) |
746 | { | 756 | { |
747 | struct GSF_RequestPlan *rp; | 757 | struct GSF_RequestPlan *rp; |
748 | struct GSF_PendingRequestData *prd; | 758 | struct GSF_PendingRequestData *prd; |
749 | struct GSF_PendingRequestPlanBijection *bi; | 759 | struct GSF_PendingRequestPlanBijection *bi; |
750 | 760 | ||
751 | prd = GSF_pending_request_get_data_(pr); | 761 | prd = GSF_pending_request_get_data_ (pr); |
752 | while (NULL != (bi = prd->pr_head)) | 762 | while (NULL != (bi = prd->pr_head)) |
763 | { | ||
764 | rp = bi->rp; | ||
765 | GNUNET_CONTAINER_MDLL_remove (PR, | ||
766 | prd->pr_head, | ||
767 | prd->pr_tail, | ||
768 | bi); | ||
769 | GNUNET_CONTAINER_MDLL_remove (PE, | ||
770 | rp->pe_head, | ||
771 | rp->pe_tail, | ||
772 | bi); | ||
773 | GNUNET_assert (bi->pr == pr); | ||
774 | if (NULL == rp->pe_head) | ||
753 | { | 775 | { |
754 | rp = bi->rp; | 776 | GNUNET_CONTAINER_heap_remove_node (rp->hn); |
755 | GNUNET_CONTAINER_MDLL_remove(PR, | 777 | plan_count--; |
756 | prd->pr_head, | 778 | GNUNET_break (GNUNET_YES == |
757 | prd->pr_tail, | 779 | GNUNET_CONTAINER_multihashmap_remove (rp->pp->plan_map, |
758 | bi); | 780 | &prd->query, |
759 | GNUNET_CONTAINER_MDLL_remove(PE, | 781 | rp)); |
760 | rp->pe_head, | 782 | GNUNET_free (rp); |
761 | rp->pe_tail, | ||
762 | bi); | ||
763 | GNUNET_assert(bi->pr == pr); | ||
764 | if (NULL == rp->pe_head) | ||
765 | { | ||
766 | GNUNET_CONTAINER_heap_remove_node(rp->hn); | ||
767 | plan_count--; | ||
768 | GNUNET_break(GNUNET_YES == | ||
769 | GNUNET_CONTAINER_multihashmap_remove(rp->pp->plan_map, | ||
770 | &prd->query, | ||
771 | rp)); | ||
772 | GNUNET_free(rp); | ||
773 | } | ||
774 | GNUNET_free(bi); | ||
775 | } | 783 | } |
776 | GNUNET_STATISTICS_set(GSF_stats, | 784 | GNUNET_free (bi); |
777 | gettext_noop("# query plan entries"), | 785 | } |
778 | plan_count, | 786 | GNUNET_STATISTICS_set (GSF_stats, |
779 | GNUNET_NO); | 787 | gettext_noop ("# query plan entries"), |
788 | plan_count, | ||
789 | GNUNET_NO); | ||
780 | } | 790 | } |
781 | 791 | ||
782 | 792 | ||
@@ -784,10 +794,10 @@ GSF_plan_notify_request_done_(struct GSF_PendingRequest *pr) | |||
784 | * Initialize plan subsystem. | 794 | * Initialize plan subsystem. |
785 | */ | 795 | */ |
786 | void | 796 | void |
787 | GSF_plan_init() | 797 | GSF_plan_init () |
788 | { | 798 | { |
789 | plans = GNUNET_CONTAINER_multipeermap_create(256, | 799 | plans = GNUNET_CONTAINER_multipeermap_create (256, |
790 | GNUNET_YES); | 800 | GNUNET_YES); |
791 | } | 801 | } |
792 | 802 | ||
793 | 803 | ||
@@ -795,10 +805,10 @@ GSF_plan_init() | |||
795 | * Shutdown plan subsystem. | 805 | * Shutdown plan subsystem. |
796 | */ | 806 | */ |
797 | void | 807 | void |
798 | GSF_plan_done() | 808 | GSF_plan_done () |
799 | { | 809 | { |
800 | GNUNET_assert(0 == GNUNET_CONTAINER_multipeermap_size(plans)); | 810 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (plans)); |
801 | GNUNET_CONTAINER_multipeermap_destroy(plans); | 811 | GNUNET_CONTAINER_multipeermap_destroy (plans); |
802 | } | 812 | } |
803 | 813 | ||
804 | 814 | ||
diff --git a/src/fs/gnunet-service-fs_pe.h b/src/fs/gnunet-service-fs_pe.h index dfad71be9..d532b6b71 100644 --- a/src/fs/gnunet-service-fs_pe.h +++ b/src/fs/gnunet-service-fs_pe.h | |||
@@ -36,8 +36,8 @@ | |||
36 | * @param pr request with the entry | 36 | * @param pr request with the entry |
37 | */ | 37 | */ |
38 | void | 38 | void |
39 | GSF_plan_add_(struct GSF_ConnectedPeer *cp, | 39 | GSF_plan_add_ (struct GSF_ConnectedPeer *cp, |
40 | struct GSF_PendingRequest *pr); | 40 | struct GSF_PendingRequest *pr); |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
@@ -47,7 +47,7 @@ GSF_plan_add_(struct GSF_ConnectedPeer *cp, | |||
47 | * @param cp connected peer | 47 | * @param cp connected peer |
48 | */ | 48 | */ |
49 | void | 49 | void |
50 | GSF_plan_notify_peer_disconnect_(const struct GSF_ConnectedPeer *cp); | 50 | GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp); |
51 | 51 | ||
52 | 52 | ||
53 | /** | 53 | /** |
@@ -57,7 +57,7 @@ GSF_plan_notify_peer_disconnect_(const struct GSF_ConnectedPeer *cp); | |||
57 | * @param pr request that is done | 57 | * @param pr request that is done |
58 | */ | 58 | */ |
59 | void | 59 | void |
60 | GSF_plan_notify_request_done_(struct GSF_PendingRequest *pr); | 60 | GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr); |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Get the last transmission attempt time for the request plan list | 63 | * Get the last transmission attempt time for the request plan list |
@@ -69,22 +69,26 @@ GSF_plan_notify_request_done_(struct GSF_PendingRequest *pr); | |||
69 | * @return GNUNET_YES if 'result' was changed, GNUNET_NO otherwise. | 69 | * @return GNUNET_YES if 'result' was changed, GNUNET_NO otherwise. |
70 | */ | 70 | */ |
71 | int | 71 | int |
72 | GSF_request_plan_reference_get_last_transmission_(struct GSF_PendingRequestPlanBijection *pr_head, | 72 | GSF_request_plan_reference_get_last_transmission_ (struct |
73 | struct GSF_ConnectedPeer *sender, | 73 | GSF_PendingRequestPlanBijection |
74 | struct GNUNET_TIME_Absolute *result); | 74 | *pr_head, |
75 | struct GSF_ConnectedPeer * | ||
76 | sender, | ||
77 | struct GNUNET_TIME_Absolute * | ||
78 | result); | ||
75 | 79 | ||
76 | /** | 80 | /** |
77 | * Initialize plan subsystem. | 81 | * Initialize plan subsystem. |
78 | */ | 82 | */ |
79 | void | 83 | void |
80 | GSF_plan_init(void); | 84 | GSF_plan_init (void); |
81 | 85 | ||
82 | 86 | ||
83 | /** | 87 | /** |
84 | * Shutdown plan subsystem. | 88 | * Shutdown plan subsystem. |
85 | */ | 89 | */ |
86 | void | 90 | void |
87 | GSF_plan_done(void); | 91 | GSF_plan_done (void); |
88 | 92 | ||
89 | 93 | ||
90 | #endif | 94 | #endif |
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index 90587cfa0..9c558674b 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c | |||
@@ -74,7 +74,8 @@ | |||
74 | /** | 74 | /** |
75 | * An active request. | 75 | * An active request. |
76 | */ | 76 | */ |
77 | struct GSF_PendingRequest { | 77 | struct GSF_PendingRequest |
78 | { | ||
78 | /** | 79 | /** |
79 | * Public data for the request. | 80 | * Public data for the request. |
80 | */ | 81 | */ |
@@ -246,31 +247,32 @@ static unsigned long long max_pending_requests = (32 * 1024); | |||
246 | * @param pr request for which the BF is to be recomputed | 247 | * @param pr request for which the BF is to be recomputed |
247 | */ | 248 | */ |
248 | static void | 249 | static void |
249 | refresh_bloomfilter(enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) | 250 | refresh_bloomfilter (enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) |
250 | { | 251 | { |
251 | if (NULL != pr->bg) | 252 | if (NULL != pr->bg) |
252 | { | 253 | { |
253 | GNUNET_BLOCK_group_destroy(pr->bg); | 254 | GNUNET_BLOCK_group_destroy (pr->bg); |
254 | pr->bg = NULL; | 255 | pr->bg = NULL; |
255 | } | 256 | } |
256 | if (GNUNET_BLOCK_TYPE_FS_UBLOCK != type) | 257 | if (GNUNET_BLOCK_TYPE_FS_UBLOCK != type) |
257 | return; /* no need */ | 258 | return; /* no need */ |
258 | pr->bg = | 259 | pr->bg = |
259 | GNUNET_BLOCK_group_create(GSF_block_ctx, | 260 | GNUNET_BLOCK_group_create (GSF_block_ctx, |
260 | type, | 261 | type, |
261 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 262 | GNUNET_CRYPTO_random_u32 ( |
262 | UINT32_MAX), | 263 | GNUNET_CRYPTO_QUALITY_WEAK, |
263 | NULL, | 264 | UINT32_MAX), |
264 | 0, | 265 | NULL, |
265 | "seen-set-size", | 266 | 0, |
266 | pr->replies_seen_count, | 267 | "seen-set-size", |
267 | NULL); | 268 | pr->replies_seen_count, |
269 | NULL); | ||
268 | if (NULL == pr->bg) | 270 | if (NULL == pr->bg) |
269 | return; | 271 | return; |
270 | GNUNET_break(GNUNET_OK == | 272 | GNUNET_break (GNUNET_OK == |
271 | GNUNET_BLOCK_group_set_seen(pr->bg, | 273 | GNUNET_BLOCK_group_set_seen (pr->bg, |
272 | pr->replies_seen, | 274 | pr->replies_seen, |
273 | pr->replies_seen_count)); | 275 | pr->replies_seen_count)); |
274 | } | 276 | } |
275 | 277 | ||
276 | 278 | ||
@@ -296,129 +298,129 @@ refresh_bloomfilter(enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) | |||
296 | * @return handle for the new pending request | 298 | * @return handle for the new pending request |
297 | */ | 299 | */ |
298 | struct GSF_PendingRequest * | 300 | struct GSF_PendingRequest * |
299 | GSF_pending_request_create_(enum GSF_PendingRequestOptions options, | 301 | GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, |
300 | enum GNUNET_BLOCK_Type type, | 302 | enum GNUNET_BLOCK_Type type, |
301 | const struct GNUNET_HashCode *query, | 303 | const struct GNUNET_HashCode *query, |
302 | const struct GNUNET_PeerIdentity *target, | 304 | const struct GNUNET_PeerIdentity *target, |
303 | const char *bf_data, | 305 | const char *bf_data, |
304 | size_t bf_size, | 306 | size_t bf_size, |
305 | uint32_t mingle, | 307 | uint32_t mingle, |
306 | uint32_t anonymity_level, | 308 | uint32_t anonymity_level, |
307 | uint32_t priority, | 309 | uint32_t priority, |
308 | int32_t ttl, | 310 | int32_t ttl, |
309 | GNUNET_PEER_Id sender_pid, | 311 | GNUNET_PEER_Id sender_pid, |
310 | GNUNET_PEER_Id origin_pid, | 312 | GNUNET_PEER_Id origin_pid, |
311 | const struct GNUNET_HashCode *replies_seen, | 313 | const struct GNUNET_HashCode *replies_seen, |
312 | unsigned int replies_seen_count, | 314 | unsigned int replies_seen_count, |
313 | GSF_PendingRequestReplyHandler rh, | 315 | GSF_PendingRequestReplyHandler rh, |
314 | void *rh_cls) | 316 | void *rh_cls) |
315 | { | 317 | { |
316 | struct GSF_PendingRequest *pr; | 318 | struct GSF_PendingRequest *pr; |
317 | struct GSF_PendingRequest *dpr; | 319 | struct GSF_PendingRequest *dpr; |
318 | size_t extra; | 320 | size_t extra; |
319 | struct GNUNET_HashCode *eptr; | 321 | struct GNUNET_HashCode *eptr; |
320 | 322 | ||
321 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
322 | "Creating request handle for `%s' of type %d\n", | 324 | "Creating request handle for `%s' of type %d\n", |
323 | GNUNET_h2s(query), | 325 | GNUNET_h2s (query), |
324 | type); | 326 | type); |
325 | #if INSANE_STATISTICS | 327 | #if INSANE_STATISTICS |
326 | GNUNET_STATISTICS_update(GSF_stats, | 328 | GNUNET_STATISTICS_update (GSF_stats, |
327 | gettext_noop("# Pending requests created"), | 329 | gettext_noop ("# Pending requests created"), |
328 | 1, | 330 | 1, |
329 | GNUNET_NO); | 331 | GNUNET_NO); |
330 | #endif | 332 | #endif |
331 | extra = 0; | 333 | extra = 0; |
332 | if (NULL != target) | 334 | if (NULL != target) |
333 | extra += sizeof(struct GNUNET_PeerIdentity); | 335 | extra += sizeof(struct GNUNET_PeerIdentity); |
334 | pr = GNUNET_malloc(sizeof(struct GSF_PendingRequest) + extra); | 336 | pr = GNUNET_malloc (sizeof(struct GSF_PendingRequest) + extra); |
335 | pr->public_data.query = *query; | 337 | pr->public_data.query = *query; |
336 | eptr = (struct GNUNET_HashCode *)&pr[1]; | 338 | eptr = (struct GNUNET_HashCode *) &pr[1]; |
337 | if (NULL != target) | 339 | if (NULL != target) |
338 | { | 340 | { |
339 | pr->public_data.target = (struct GNUNET_PeerIdentity *)eptr; | 341 | pr->public_data.target = (struct GNUNET_PeerIdentity *) eptr; |
340 | GNUNET_memcpy(eptr, target, sizeof(struct GNUNET_PeerIdentity)); | 342 | GNUNET_memcpy (eptr, target, sizeof(struct GNUNET_PeerIdentity)); |
341 | } | 343 | } |
342 | pr->public_data.anonymity_level = anonymity_level; | 344 | pr->public_data.anonymity_level = anonymity_level; |
343 | pr->public_data.priority = priority; | 345 | pr->public_data.priority = priority; |
344 | pr->public_data.original_priority = priority; | 346 | pr->public_data.original_priority = priority; |
345 | pr->public_data.options = options; | 347 | pr->public_data.options = options; |
346 | pr->public_data.type = type; | 348 | pr->public_data.type = type; |
347 | pr->public_data.start_time = GNUNET_TIME_absolute_get(); | 349 | pr->public_data.start_time = GNUNET_TIME_absolute_get (); |
348 | pr->sender_pid = sender_pid; | 350 | pr->sender_pid = sender_pid; |
349 | pr->origin_pid = origin_pid; | 351 | pr->origin_pid = origin_pid; |
350 | pr->rh = rh; | 352 | pr->rh = rh; |
351 | pr->rh_cls = rh_cls; | 353 | pr->rh_cls = rh_cls; |
352 | GNUNET_assert((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY))); | 354 | GNUNET_assert ((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY))); |
353 | if (ttl >= 0) | 355 | if (ttl >= 0) |
354 | pr->public_data.ttl = GNUNET_TIME_relative_to_absolute( | 356 | pr->public_data.ttl = GNUNET_TIME_relative_to_absolute ( |
355 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, (uint32_t)ttl)); | 357 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, (uint32_t) ttl)); |
356 | else | 358 | else |
357 | pr->public_data.ttl = GNUNET_TIME_absolute_subtract( | 359 | pr->public_data.ttl = GNUNET_TIME_absolute_subtract ( |
358 | pr->public_data.start_time, | 360 | pr->public_data.start_time, |
359 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 361 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
360 | (uint32_t)(-ttl))); | 362 | (uint32_t) (-ttl))); |
361 | if (replies_seen_count > 0) | 363 | if (replies_seen_count > 0) |
362 | { | 364 | { |
363 | pr->replies_seen_size = replies_seen_count; | 365 | pr->replies_seen_size = replies_seen_count; |
364 | pr->replies_seen = | 366 | pr->replies_seen = |
365 | GNUNET_new_array(pr->replies_seen_size, struct GNUNET_HashCode); | 367 | GNUNET_new_array (pr->replies_seen_size, struct GNUNET_HashCode); |
366 | GNUNET_memcpy(pr->replies_seen, | 368 | GNUNET_memcpy (pr->replies_seen, |
367 | replies_seen, | 369 | replies_seen, |
368 | replies_seen_count * sizeof(struct GNUNET_HashCode)); | 370 | replies_seen_count * sizeof(struct GNUNET_HashCode)); |
369 | pr->replies_seen_count = replies_seen_count; | 371 | pr->replies_seen_count = replies_seen_count; |
370 | } | 372 | } |
371 | if ((NULL != bf_data) && | 373 | if ((NULL != bf_data) && |
372 | (GNUNET_BLOCK_TYPE_FS_UBLOCK == pr->public_data.type)) | 374 | (GNUNET_BLOCK_TYPE_FS_UBLOCK == pr->public_data.type)) |
373 | { | 375 | { |
374 | pr->bg = GNUNET_BLOCK_group_create(GSF_block_ctx, | 376 | pr->bg = GNUNET_BLOCK_group_create (GSF_block_ctx, |
375 | pr->public_data.type, | 377 | pr->public_data.type, |
376 | mingle, | 378 | mingle, |
377 | bf_data, | 379 | bf_data, |
378 | bf_size, | 380 | bf_size, |
379 | "seen-set-size", | 381 | "seen-set-size", |
380 | 0, | 382 | 0, |
381 | NULL); | 383 | NULL); |
382 | } | 384 | } |
383 | else if ((replies_seen_count > 0) && | 385 | else if ((replies_seen_count > 0) && |
384 | (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))) | 386 | (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))) |
385 | { | 387 | { |
386 | refresh_bloomfilter(pr->public_data.type, pr); | 388 | refresh_bloomfilter (pr->public_data.type, pr); |
387 | } | 389 | } |
388 | GNUNET_CONTAINER_multihashmap_put(pr_map, | 390 | GNUNET_CONTAINER_multihashmap_put (pr_map, |
389 | &pr->public_data.query, | 391 | &pr->public_data.query, |
390 | pr, | 392 | pr, |
391 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 393 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
392 | if (0 == (options & GSF_PRO_REQUEST_NEVER_EXPIRES)) | 394 | if (0 == (options & GSF_PRO_REQUEST_NEVER_EXPIRES)) |
395 | { | ||
396 | pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, | ||
397 | pr, | ||
398 | pr->public_data.ttl.abs_value_us); | ||
399 | /* make sure we don't track too many requests */ | ||
400 | while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) > | ||
401 | max_pending_requests) | ||
393 | { | 402 | { |
394 | pr->hnode = GNUNET_CONTAINER_heap_insert(requests_by_expiration_heap, | 403 | dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap); |
395 | pr, | 404 | GNUNET_assert (NULL != dpr); |
396 | pr->public_data.ttl.abs_value_us); | 405 | if (pr == dpr) |
397 | /* make sure we don't track too many requests */ | 406 | break; /* let the request live briefly... */ |
398 | while (GNUNET_CONTAINER_heap_get_size(requests_by_expiration_heap) > | 407 | if (NULL != dpr->rh) |
399 | max_pending_requests) | 408 | dpr->rh (dpr->rh_cls, |
400 | { | 409 | GNUNET_BLOCK_EVALUATION_REQUEST_VALID, |
401 | dpr = GNUNET_CONTAINER_heap_peek(requests_by_expiration_heap); | 410 | dpr, |
402 | GNUNET_assert(NULL != dpr); | 411 | UINT32_MAX, |
403 | if (pr == dpr) | 412 | GNUNET_TIME_UNIT_FOREVER_ABS, |
404 | break; /* let the request live briefly... */ | 413 | GNUNET_TIME_UNIT_FOREVER_ABS, |
405 | if (NULL != dpr->rh) | 414 | GNUNET_BLOCK_TYPE_ANY, |
406 | dpr->rh(dpr->rh_cls, | 415 | NULL, |
407 | GNUNET_BLOCK_EVALUATION_REQUEST_VALID, | 416 | 0); |
408 | dpr, | 417 | GSF_pending_request_cancel_ (dpr, GNUNET_YES); |
409 | UINT32_MAX, | ||
410 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
411 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
412 | GNUNET_BLOCK_TYPE_ANY, | ||
413 | NULL, | ||
414 | 0); | ||
415 | GSF_pending_request_cancel_(dpr, GNUNET_YES); | ||
416 | } | ||
417 | } | 418 | } |
418 | GNUNET_STATISTICS_update(GSF_stats, | 419 | } |
419 | gettext_noop("# Pending requests active"), | 420 | GNUNET_STATISTICS_update (GSF_stats, |
420 | 1, | 421 | gettext_noop ("# Pending requests active"), |
421 | GNUNET_NO); | 422 | 1, |
423 | GNUNET_NO); | ||
422 | return pr; | 424 | return pr; |
423 | } | 425 | } |
424 | 426 | ||
@@ -429,7 +431,7 @@ GSF_pending_request_create_(enum GSF_PendingRequestOptions options, | |||
429 | * @return associated public data | 431 | * @return associated public data |
430 | */ | 432 | */ |
431 | struct GSF_PendingRequestData * | 433 | struct GSF_PendingRequestData * |
432 | GSF_pending_request_get_data_(struct GSF_PendingRequest *pr) | 434 | GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr) |
433 | { | 435 | { |
434 | return &pr->public_data; | 436 | return &pr->public_data; |
435 | } | 437 | } |
@@ -445,13 +447,13 @@ GSF_pending_request_get_data_(struct GSF_PendingRequest *pr) | |||
445 | * @return #GNUNET_OK if the requests are compatible | 447 | * @return #GNUNET_OK if the requests are compatible |
446 | */ | 448 | */ |
447 | int | 449 | int |
448 | GSF_pending_request_is_compatible_(struct GSF_PendingRequest *pra, | 450 | GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, |
449 | struct GSF_PendingRequest *prb) | 451 | struct GSF_PendingRequest *prb) |
450 | { | 452 | { |
451 | if ((pra->public_data.type != prb->public_data.type) || | 453 | if ((pra->public_data.type != prb->public_data.type) || |
452 | (0 != memcmp(&pra->public_data.query, | 454 | (0 != memcmp (&pra->public_data.query, |
453 | &prb->public_data.query, | 455 | &prb->public_data.query, |
454 | sizeof(struct GNUNET_HashCode)))) | 456 | sizeof(struct GNUNET_HashCode)))) |
455 | return GNUNET_NO; | 457 | return GNUNET_NO; |
456 | return GNUNET_OK; | 458 | return GNUNET_OK; |
457 | } | 459 | } |
@@ -466,45 +468,45 @@ GSF_pending_request_is_compatible_(struct GSF_PendingRequest *pra, | |||
466 | * @param replies_seen_count size of the replies_seen array | 468 | * @param replies_seen_count size of the replies_seen array |
467 | */ | 469 | */ |
468 | void | 470 | void |
469 | GSF_pending_request_update_(struct GSF_PendingRequest *pr, | 471 | GSF_pending_request_update_ (struct GSF_PendingRequest *pr, |
470 | const struct GNUNET_HashCode *replies_seen, | 472 | const struct GNUNET_HashCode *replies_seen, |
471 | unsigned int replies_seen_count) | 473 | unsigned int replies_seen_count) |
472 | { | 474 | { |
473 | if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count) | 475 | if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count) |
474 | return; /* integer overflow */ | 476 | return; /* integer overflow */ |
475 | if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)) | 477 | if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)) |
478 | { | ||
479 | /* we're responsible for the BF, full refresh */ | ||
480 | if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size) | ||
481 | GNUNET_array_grow (pr->replies_seen, | ||
482 | pr->replies_seen_size, | ||
483 | replies_seen_count + pr->replies_seen_count); | ||
484 | GNUNET_memcpy (&pr->replies_seen[pr->replies_seen_count], | ||
485 | replies_seen, | ||
486 | sizeof(struct GNUNET_HashCode) * replies_seen_count); | ||
487 | pr->replies_seen_count += replies_seen_count; | ||
488 | refresh_bloomfilter (pr->public_data.type, pr); | ||
489 | } | ||
490 | else | ||
491 | { | ||
492 | if (NULL == pr->bg) | ||
476 | { | 493 | { |
477 | /* we're responsible for the BF, full refresh */ | 494 | /* we're not the initiator, but the initiator did not give us |
478 | if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size) | 495 | * any bloom-filter, so we need to create one on-the-fly */ |
479 | GNUNET_array_grow(pr->replies_seen, | 496 | refresh_bloomfilter (pr->public_data.type, pr); |
480 | pr->replies_seen_size, | ||
481 | replies_seen_count + pr->replies_seen_count); | ||
482 | GNUNET_memcpy(&pr->replies_seen[pr->replies_seen_count], | ||
483 | replies_seen, | ||
484 | sizeof(struct GNUNET_HashCode) * replies_seen_count); | ||
485 | pr->replies_seen_count += replies_seen_count; | ||
486 | refresh_bloomfilter(pr->public_data.type, pr); | ||
487 | } | 497 | } |
488 | else | 498 | else |
489 | { | 499 | { |
490 | if (NULL == pr->bg) | 500 | GNUNET_break (GNUNET_OK == |
491 | { | 501 | GNUNET_BLOCK_group_set_seen (pr->bg, |
492 | /* we're not the initiator, but the initiator did not give us | 502 | replies_seen, |
493 | * any bloom-filter, so we need to create one on-the-fly */ | 503 | pr->replies_seen_count)); |
494 | refresh_bloomfilter(pr->public_data.type, pr); | ||
495 | } | ||
496 | else | ||
497 | { | ||
498 | GNUNET_break(GNUNET_OK == | ||
499 | GNUNET_BLOCK_group_set_seen(pr->bg, | ||
500 | replies_seen, | ||
501 | pr->replies_seen_count)); | ||
502 | } | ||
503 | } | 504 | } |
505 | } | ||
504 | if (NULL != pr->gh) | 506 | if (NULL != pr->gh) |
505 | GNUNET_DHT_get_filter_known_results(pr->gh, | 507 | GNUNET_DHT_get_filter_known_results (pr->gh, |
506 | replies_seen_count, | 508 | replies_seen_count, |
507 | replies_seen); | 509 | replies_seen); |
508 | } | 510 | } |
509 | 511 | ||
510 | 512 | ||
@@ -516,7 +518,7 @@ GSF_pending_request_update_(struct GSF_PendingRequest *pr, | |||
516 | * @return envelope with the request message | 518 | * @return envelope with the request message |
517 | */ | 519 | */ |
518 | struct GNUNET_MQ_Envelope * | 520 | struct GNUNET_MQ_Envelope * |
519 | GSF_pending_request_get_message_(struct GSF_PendingRequest *pr) | 521 | GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) |
520 | { | 522 | { |
521 | struct GNUNET_MQ_Envelope *env; | 523 | struct GNUNET_MQ_Envelope *env; |
522 | struct GetMessage *gm; | 524 | struct GetMessage *gm; |
@@ -531,61 +533,61 @@ GSF_pending_request_get_message_(struct GSF_PendingRequest *pr) | |||
531 | void *bf_data; | 533 | void *bf_data; |
532 | uint32_t bf_nonce; | 534 | uint32_t bf_nonce; |
533 | 535 | ||
534 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
535 | "Building request message for `%s' of type %d\n", | 537 | "Building request message for `%s' of type %d\n", |
536 | GNUNET_h2s(&pr->public_data.query), | 538 | GNUNET_h2s (&pr->public_data.query), |
537 | pr->public_data.type); | 539 | pr->public_data.type); |
538 | k = 0; | 540 | k = 0; |
539 | bm = 0; | 541 | bm = 0; |
540 | do_route = (0 == (pr->public_data.options & GSF_PRO_FORWARD_ONLY)); | 542 | do_route = (0 == (pr->public_data.options & GSF_PRO_FORWARD_ONLY)); |
541 | if ((!do_route) && (pr->sender_pid == 0)) | 543 | if ((! do_route) && (pr->sender_pid == 0)) |
542 | { | 544 | { |
543 | GNUNET_break(0); | 545 | GNUNET_break (0); |
544 | do_route = GNUNET_YES; | 546 | do_route = GNUNET_YES; |
545 | } | 547 | } |
546 | if (!do_route) | 548 | if (! do_route) |
547 | { | 549 | { |
548 | bm |= GET_MESSAGE_BIT_RETURN_TO; | 550 | bm |= GET_MESSAGE_BIT_RETURN_TO; |
549 | k++; | 551 | k++; |
550 | } | 552 | } |
551 | if (NULL != pr->public_data.target) | 553 | if (NULL != pr->public_data.target) |
552 | { | 554 | { |
553 | bm |= GET_MESSAGE_BIT_TRANSMIT_TO; | 555 | bm |= GET_MESSAGE_BIT_TRANSMIT_TO; |
554 | k++; | 556 | k++; |
555 | } | 557 | } |
556 | if (GNUNET_OK != | 558 | if (GNUNET_OK != |
557 | GNUNET_BLOCK_group_serialize(pr->bg, &bf_nonce, &bf_data, &bf_size)) | 559 | GNUNET_BLOCK_group_serialize (pr->bg, &bf_nonce, &bf_data, &bf_size)) |
558 | { | 560 | { |
559 | bf_size = 0; | 561 | bf_size = 0; |
560 | bf_data = NULL; | 562 | bf_data = NULL; |
561 | } | 563 | } |
562 | env = GNUNET_MQ_msg_extra(gm, | 564 | env = GNUNET_MQ_msg_extra (gm, |
563 | bf_size + k * sizeof(struct GNUNET_PeerIdentity), | 565 | bf_size + k * sizeof(struct GNUNET_PeerIdentity), |
564 | GNUNET_MESSAGE_TYPE_FS_GET); | 566 | GNUNET_MESSAGE_TYPE_FS_GET); |
565 | gm->type = htonl(pr->public_data.type); | 567 | gm->type = htonl (pr->public_data.type); |
566 | if (do_route) | 568 | if (do_route) |
567 | prio = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 569 | prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
568 | pr->public_data.priority + 1); | 570 | pr->public_data.priority + 1); |
569 | else | 571 | else |
570 | prio = 0; | 572 | prio = 0; |
571 | pr->public_data.priority -= prio; | 573 | pr->public_data.priority -= prio; |
572 | pr->public_data.num_transmissions++; | 574 | pr->public_data.num_transmissions++; |
573 | pr->public_data.respect_offered += prio; | 575 | pr->public_data.respect_offered += prio; |
574 | gm->priority = htonl(prio); | 576 | gm->priority = htonl (prio); |
575 | now = GNUNET_TIME_absolute_get(); | 577 | now = GNUNET_TIME_absolute_get (); |
576 | ttl = (int64_t)(pr->public_data.ttl.abs_value_us - now.abs_value_us); | 578 | ttl = (int64_t) (pr->public_data.ttl.abs_value_us - now.abs_value_us); |
577 | gm->ttl = htonl(ttl / 1000LL / 1000LL); | 579 | gm->ttl = htonl (ttl / 1000LL / 1000LL); |
578 | gm->filter_mutator = htonl(bf_nonce); | 580 | gm->filter_mutator = htonl (bf_nonce); |
579 | gm->hash_bitmap = htonl(bm); | 581 | gm->hash_bitmap = htonl (bm); |
580 | gm->query = pr->public_data.query; | 582 | gm->query = pr->public_data.query; |
581 | ext = (struct GNUNET_PeerIdentity *)&gm[1]; | 583 | ext = (struct GNUNET_PeerIdentity *) &gm[1]; |
582 | k = 0; | 584 | k = 0; |
583 | if (!do_route) | 585 | if (! do_route) |
584 | GNUNET_PEER_resolve(pr->sender_pid, &ext[k++]); | 586 | GNUNET_PEER_resolve (pr->sender_pid, &ext[k++]); |
585 | if (NULL != pr->public_data.target) | 587 | if (NULL != pr->public_data.target) |
586 | ext[k++] = *pr->public_data.target; | 588 | ext[k++] = *pr->public_data.target; |
587 | GNUNET_memcpy(&ext[k], bf_data, bf_size); | 589 | GNUNET_memcpy (&ext[k], bf_data, bf_size); |
588 | GNUNET_free_non_null(bf_data); | 590 | GNUNET_free_non_null (bf_data); |
589 | return env; | 591 | return env; |
590 | } | 592 | } |
591 | 593 | ||
@@ -599,61 +601,61 @@ GSF_pending_request_get_message_(struct GSF_PendingRequest *pr) | |||
599 | * @return #GNUNET_YES (we should continue to iterate) | 601 | * @return #GNUNET_YES (we should continue to iterate) |
600 | */ | 602 | */ |
601 | static int | 603 | static int |
602 | clean_request(void *cls, const struct GNUNET_HashCode *key, void *value) | 604 | clean_request (void *cls, const struct GNUNET_HashCode *key, void *value) |
603 | { | 605 | { |
604 | struct GSF_PendingRequest *pr = value; | 606 | struct GSF_PendingRequest *pr = value; |
605 | GSF_LocalLookupContinuation cont; | 607 | GSF_LocalLookupContinuation cont; |
606 | 608 | ||
607 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 609 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
608 | "Cleaning up pending request for `%s'.\n", | 610 | "Cleaning up pending request for `%s'.\n", |
609 | GNUNET_h2s(key)); | 611 | GNUNET_h2s (key)); |
610 | if (NULL != pr->cadet_request) | 612 | if (NULL != pr->cadet_request) |
611 | { | 613 | { |
612 | pr->cadet_retry_count = CADET_RETRY_MAX; | 614 | pr->cadet_retry_count = CADET_RETRY_MAX; |
613 | GSF_cadet_query_cancel(pr->cadet_request); | 615 | GSF_cadet_query_cancel (pr->cadet_request); |
614 | pr->cadet_request = NULL; | 616 | pr->cadet_request = NULL; |
615 | } | 617 | } |
616 | if (NULL != (cont = pr->llc_cont)) | 618 | if (NULL != (cont = pr->llc_cont)) |
617 | { | 619 | { |
618 | pr->llc_cont = NULL; | 620 | pr->llc_cont = NULL; |
619 | cont(pr->llc_cont_cls, pr, pr->local_result); | 621 | cont (pr->llc_cont_cls, pr, pr->local_result); |
620 | } | 622 | } |
621 | GSF_plan_notify_request_done_(pr); | 623 | GSF_plan_notify_request_done_ (pr); |
622 | GNUNET_free_non_null(pr->replies_seen); | 624 | GNUNET_free_non_null (pr->replies_seen); |
623 | GNUNET_BLOCK_group_destroy(pr->bg); | 625 | GNUNET_BLOCK_group_destroy (pr->bg); |
624 | pr->bg = NULL; | 626 | pr->bg = NULL; |
625 | GNUNET_PEER_change_rc(pr->sender_pid, -1); | 627 | GNUNET_PEER_change_rc (pr->sender_pid, -1); |
626 | pr->sender_pid = 0; | 628 | pr->sender_pid = 0; |
627 | GNUNET_PEER_change_rc(pr->origin_pid, -1); | 629 | GNUNET_PEER_change_rc (pr->origin_pid, -1); |
628 | pr->origin_pid = 0; | 630 | pr->origin_pid = 0; |
629 | if (NULL != pr->hnode) | 631 | if (NULL != pr->hnode) |
630 | { | 632 | { |
631 | GNUNET_CONTAINER_heap_remove_node(pr->hnode); | 633 | GNUNET_CONTAINER_heap_remove_node (pr->hnode); |
632 | pr->hnode = NULL; | 634 | pr->hnode = NULL; |
633 | } | 635 | } |
634 | if (NULL != pr->qe) | 636 | if (NULL != pr->qe) |
635 | { | 637 | { |
636 | GNUNET_DATASTORE_cancel(pr->qe); | 638 | GNUNET_DATASTORE_cancel (pr->qe); |
637 | pr->qe = NULL; | 639 | pr->qe = NULL; |
638 | } | 640 | } |
639 | if (NULL != pr->gh) | 641 | if (NULL != pr->gh) |
640 | { | 642 | { |
641 | GNUNET_DHT_get_stop(pr->gh); | 643 | GNUNET_DHT_get_stop (pr->gh); |
642 | pr->gh = NULL; | 644 | pr->gh = NULL; |
643 | } | 645 | } |
644 | if (NULL != pr->warn_task) | 646 | if (NULL != pr->warn_task) |
645 | { | 647 | { |
646 | GNUNET_SCHEDULER_cancel(pr->warn_task); | 648 | GNUNET_SCHEDULER_cancel (pr->warn_task); |
647 | pr->warn_task = NULL; | 649 | pr->warn_task = NULL; |
648 | } | 650 | } |
649 | GNUNET_assert( | 651 | GNUNET_assert ( |
650 | GNUNET_OK == | 652 | GNUNET_OK == |
651 | GNUNET_CONTAINER_multihashmap_remove(pr_map, &pr->public_data.query, pr)); | 653 | GNUNET_CONTAINER_multihashmap_remove (pr_map, &pr->public_data.query, pr)); |
652 | GNUNET_STATISTICS_update(GSF_stats, | 654 | GNUNET_STATISTICS_update (GSF_stats, |
653 | gettext_noop("# Pending requests active"), | 655 | gettext_noop ("# Pending requests active"), |
654 | -1, | 656 | -1, |
655 | GNUNET_NO); | 657 | GNUNET_NO); |
656 | GNUNET_free(pr); | 658 | GNUNET_free (pr); |
657 | return GNUNET_YES; | 659 | return GNUNET_YES; |
658 | } | 660 | } |
659 | 661 | ||
@@ -665,49 +667,49 @@ clean_request(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
665 | * @param full_cleanup fully purge the request | 667 | * @param full_cleanup fully purge the request |
666 | */ | 668 | */ |
667 | void | 669 | void |
668 | GSF_pending_request_cancel_(struct GSF_PendingRequest *pr, int full_cleanup) | 670 | GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup) |
669 | { | 671 | { |
670 | GSF_LocalLookupContinuation cont; | 672 | GSF_LocalLookupContinuation cont; |
671 | 673 | ||
672 | if (NULL == pr_map) | 674 | if (NULL == pr_map) |
673 | return; /* already cleaned up! */ | 675 | return; /* already cleaned up! */ |
674 | if (GNUNET_NO == full_cleanup) | 676 | if (GNUNET_NO == full_cleanup) |
677 | { | ||
678 | /* make request inactive (we're no longer interested in more results), | ||
679 | * but do NOT remove from our data-structures, we still need it there | ||
680 | * to prevent the request from looping */ | ||
681 | pr->rh = NULL; | ||
682 | if (NULL != pr->cadet_request) | ||
683 | { | ||
684 | pr->cadet_retry_count = CADET_RETRY_MAX; | ||
685 | GSF_cadet_query_cancel (pr->cadet_request); | ||
686 | pr->cadet_request = NULL; | ||
687 | } | ||
688 | if (NULL != (cont = pr->llc_cont)) | ||
689 | { | ||
690 | pr->llc_cont = NULL; | ||
691 | cont (pr->llc_cont_cls, pr, pr->local_result); | ||
692 | } | ||
693 | GSF_plan_notify_request_done_ (pr); | ||
694 | if (NULL != pr->qe) | ||
695 | { | ||
696 | GNUNET_DATASTORE_cancel (pr->qe); | ||
697 | pr->qe = NULL; | ||
698 | } | ||
699 | if (NULL != pr->gh) | ||
675 | { | 700 | { |
676 | /* make request inactive (we're no longer interested in more results), | 701 | GNUNET_DHT_get_stop (pr->gh); |
677 | * but do NOT remove from our data-structures, we still need it there | 702 | pr->gh = NULL; |
678 | * to prevent the request from looping */ | 703 | } |
679 | pr->rh = NULL; | 704 | if (NULL != pr->warn_task) |
680 | if (NULL != pr->cadet_request) | 705 | { |
681 | { | 706 | GNUNET_SCHEDULER_cancel (pr->warn_task); |
682 | pr->cadet_retry_count = CADET_RETRY_MAX; | 707 | pr->warn_task = NULL; |
683 | GSF_cadet_query_cancel(pr->cadet_request); | ||
684 | pr->cadet_request = NULL; | ||
685 | } | ||
686 | if (NULL != (cont = pr->llc_cont)) | ||
687 | { | ||
688 | pr->llc_cont = NULL; | ||
689 | cont(pr->llc_cont_cls, pr, pr->local_result); | ||
690 | } | ||
691 | GSF_plan_notify_request_done_(pr); | ||
692 | if (NULL != pr->qe) | ||
693 | { | ||
694 | GNUNET_DATASTORE_cancel(pr->qe); | ||
695 | pr->qe = NULL; | ||
696 | } | ||
697 | if (NULL != pr->gh) | ||
698 | { | ||
699 | GNUNET_DHT_get_stop(pr->gh); | ||
700 | pr->gh = NULL; | ||
701 | } | ||
702 | if (NULL != pr->warn_task) | ||
703 | { | ||
704 | GNUNET_SCHEDULER_cancel(pr->warn_task); | ||
705 | pr->warn_task = NULL; | ||
706 | } | ||
707 | return; | ||
708 | } | 708 | } |
709 | GNUNET_assert(GNUNET_YES == | 709 | return; |
710 | clean_request(NULL, &pr->public_data.query, pr)); | 710 | } |
711 | GNUNET_assert (GNUNET_YES == | ||
712 | clean_request (NULL, &pr->public_data.query, pr)); | ||
711 | } | 713 | } |
712 | 714 | ||
713 | 715 | ||
@@ -718,11 +720,11 @@ GSF_pending_request_cancel_(struct GSF_PendingRequest *pr, int full_cleanup) | |||
718 | * @param cls closure for @a it | 720 | * @param cls closure for @a it |
719 | */ | 721 | */ |
720 | void | 722 | void |
721 | GSF_iterate_pending_requests_(GSF_PendingRequestIterator it, void *cls) | 723 | GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls) |
722 | { | 724 | { |
723 | GNUNET_CONTAINER_multihashmap_iterate( | 725 | GNUNET_CONTAINER_multihashmap_iterate ( |
724 | pr_map, | 726 | pr_map, |
725 | (GNUNET_CONTAINER_MulitHashMapIteratorCallback)it, | 727 | (GNUNET_CONTAINER_MulitHashMapIteratorCallback) it, |
726 | cls); | 728 | cls); |
727 | } | 729 | } |
728 | 730 | ||
@@ -730,7 +732,8 @@ GSF_iterate_pending_requests_(GSF_PendingRequestIterator it, void *cls) | |||
730 | /** | 732 | /** |
731 | * Closure for process_reply() function. | 733 | * Closure for process_reply() function. |
732 | */ | 734 | */ |
733 | struct ProcessReplyClosure { | 735 | struct ProcessReplyClosure |
736 | { | ||
734 | /** | 737 | /** |
735 | * The data for the reply. | 738 | * The data for the reply. |
736 | */ | 739 | */ |
@@ -791,14 +794,14 @@ struct ProcessReplyClosure { | |||
791 | * @param pr request that was satisfied | 794 | * @param pr request that was satisfied |
792 | */ | 795 | */ |
793 | static void | 796 | static void |
794 | update_request_performance_data(struct ProcessReplyClosure *prq, | 797 | update_request_performance_data (struct ProcessReplyClosure *prq, |
795 | struct GSF_PendingRequest *pr) | 798 | struct GSF_PendingRequest *pr) |
796 | { | 799 | { |
797 | if (prq->sender == NULL) | 800 | if (prq->sender == NULL) |
798 | return; | 801 | return; |
799 | GSF_peer_update_performance_(prq->sender, | 802 | GSF_peer_update_performance_ (prq->sender, |
800 | pr->public_data.start_time, | 803 | pr->public_data.start_time, |
801 | prq->priority); | 804 | prq->priority); |
802 | } | 805 | } |
803 | 806 | ||
804 | 807 | ||
@@ -811,7 +814,7 @@ update_request_performance_data(struct ProcessReplyClosure *prq, | |||
811 | * @return #GNUNET_YES (we should continue to iterate) | 814 | * @return #GNUNET_YES (we should continue to iterate) |
812 | */ | 815 | */ |
813 | static int | 816 | static int |
814 | process_reply(void *cls, const struct GNUNET_HashCode *key, void *value) | 817 | process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) |
815 | { | 818 | { |
816 | struct ProcessReplyClosure *prq = cls; | 819 | struct ProcessReplyClosure *prq = cls; |
817 | struct GSF_PendingRequest *pr = value; | 820 | struct GSF_PendingRequest *pr = value; |
@@ -820,128 +823,128 @@ process_reply(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
820 | 823 | ||
821 | if (NULL == pr->rh) | 824 | if (NULL == pr->rh) |
822 | return GNUNET_YES; | 825 | return GNUNET_YES; |
823 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 826 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
824 | "Matched result (type %u) for query `%s' with pending request\n", | 827 | "Matched result (type %u) for query `%s' with pending request\n", |
825 | (unsigned int)prq->type, | 828 | (unsigned int) prq->type, |
826 | GNUNET_h2s(key)); | 829 | GNUNET_h2s (key)); |
827 | GNUNET_STATISTICS_update(GSF_stats, | 830 | GNUNET_STATISTICS_update (GSF_stats, |
828 | gettext_noop("# replies received and matched"), | 831 | gettext_noop ("# replies received and matched"), |
829 | 1, | 832 | 1, |
830 | GNUNET_NO); | 833 | GNUNET_NO); |
831 | prq->eval = GNUNET_BLOCK_evaluate(GSF_block_ctx, | 834 | prq->eval = GNUNET_BLOCK_evaluate (GSF_block_ctx, |
832 | prq->type, | 835 | prq->type, |
833 | pr->bg, | 836 | pr->bg, |
834 | prq->eo, | 837 | prq->eo, |
835 | key, | 838 | key, |
836 | NULL, | 839 | NULL, |
837 | 0, | 840 | 0, |
838 | prq->data, | 841 | prq->data, |
839 | prq->size); | 842 | prq->size); |
840 | switch (prq->eval) | 843 | switch (prq->eval) |
841 | { | 844 | { |
842 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 845 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
843 | update_request_performance_data(prq, pr); | 846 | update_request_performance_data (prq, pr); |
844 | break; | 847 | break; |
845 | 848 | ||
846 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 849 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
847 | /* short cut: stop processing early, no BF-update, etc. */ | 850 | /* short cut: stop processing early, no BF-update, etc. */ |
848 | update_request_performance_data(prq, pr); | 851 | update_request_performance_data (prq, pr); |
849 | GNUNET_LOAD_update(GSF_rt_entry_lifetime, | 852 | GNUNET_LOAD_update (GSF_rt_entry_lifetime, |
850 | GNUNET_TIME_absolute_get_duration( | 853 | GNUNET_TIME_absolute_get_duration ( |
851 | pr->public_data.start_time) | 854 | pr->public_data.start_time) |
852 | .rel_value_us); | 855 | .rel_value_us); |
853 | if (GNUNET_YES != | 856 | if (GNUNET_YES != |
854 | GSF_request_plan_reference_get_last_transmission_(pr->public_data | 857 | GSF_request_plan_reference_get_last_transmission_ (pr->public_data |
855 | .pr_head, | 858 | .pr_head, |
856 | prq->sender, | 859 | prq->sender, |
857 | &last_transmission)) | 860 | &last_transmission)) |
858 | last_transmission.abs_value_us = | 861 | last_transmission.abs_value_us = |
859 | GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 862 | GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
860 | /* pass on to other peers / local clients */ | 863 | /* pass on to other peers / local clients */ |
861 | pr->rh(pr->rh_cls, | 864 | pr->rh (pr->rh_cls, |
862 | prq->eval, | 865 | prq->eval, |
863 | pr, | 866 | pr, |
864 | prq->anonymity_level, | 867 | prq->anonymity_level, |
865 | prq->expiration, | 868 | prq->expiration, |
866 | last_transmission, | 869 | last_transmission, |
867 | prq->type, | 870 | prq->type, |
868 | prq->data, | 871 | prq->data, |
869 | prq->size); | 872 | prq->size); |
870 | return GNUNET_YES; | 873 | return GNUNET_YES; |
871 | 874 | ||
872 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 875 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
873 | #if INSANE_STATISTICS | 876 | #if INSANE_STATISTICS |
874 | GNUNET_STATISTICS_update(GSF_stats, | 877 | GNUNET_STATISTICS_update (GSF_stats, |
875 | gettext_noop( | 878 | gettext_noop ( |
876 | "# duplicate replies discarded (bloomfilter)"), | 879 | "# duplicate replies discarded (bloomfilter)"), |
877 | 1, | 880 | 1, |
878 | GNUNET_NO); | 881 | GNUNET_NO); |
879 | #endif | 882 | #endif |
880 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Duplicate response, discarding.\n"); | 883 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Duplicate response, discarding.\n"); |
881 | return GNUNET_YES; /* duplicate */ | 884 | return GNUNET_YES; /* duplicate */ |
882 | 885 | ||
883 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: | 886 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: |
884 | GNUNET_STATISTICS_update(GSF_stats, | 887 | GNUNET_STATISTICS_update (GSF_stats, |
885 | gettext_noop("# irrelevant replies discarded"), | 888 | gettext_noop ("# irrelevant replies discarded"), |
886 | 1, | 889 | 1, |
887 | GNUNET_NO); | 890 | GNUNET_NO); |
888 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Irrelevant response, ignoring.\n"); | 891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Irrelevant response, ignoring.\n"); |
889 | return GNUNET_YES; | 892 | return GNUNET_YES; |
890 | 893 | ||
891 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | 894 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
892 | return GNUNET_YES; /* wrong namespace */ | 895 | return GNUNET_YES; /* wrong namespace */ |
893 | 896 | ||
894 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | 897 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: |
895 | GNUNET_break(0); | 898 | GNUNET_break (0); |
896 | return GNUNET_YES; | 899 | return GNUNET_YES; |
897 | 900 | ||
898 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | 901 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: |
899 | GNUNET_break(0); | 902 | GNUNET_break (0); |
900 | return GNUNET_YES; | 903 | return GNUNET_YES; |
901 | 904 | ||
902 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 905 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
903 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 906 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
904 | _("Unsupported block type %u\n"), | 907 | _ ("Unsupported block type %u\n"), |
905 | prq->type); | 908 | prq->type); |
906 | return GNUNET_NO; | 909 | return GNUNET_NO; |
907 | } | 910 | } |
908 | /* update bloomfilter */ | 911 | /* update bloomfilter */ |
909 | GNUNET_CRYPTO_hash(prq->data, prq->size, &chash); | 912 | GNUNET_CRYPTO_hash (prq->data, prq->size, &chash); |
910 | GSF_pending_request_update_(pr, &chash, 1); | 913 | GSF_pending_request_update_ (pr, &chash, 1); |
911 | if (NULL == prq->sender) | 914 | if (NULL == prq->sender) |
912 | { | 915 | { |
913 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
914 | "Found result for query `%s' in local datastore\n", | 917 | "Found result for query `%s' in local datastore\n", |
915 | GNUNET_h2s(key)); | 918 | GNUNET_h2s (key)); |
916 | GNUNET_STATISTICS_update(GSF_stats, | 919 | GNUNET_STATISTICS_update (GSF_stats, |
917 | gettext_noop("# results found locally"), | 920 | gettext_noop ("# results found locally"), |
918 | 1, | 921 | 1, |
919 | GNUNET_NO); | 922 | GNUNET_NO); |
920 | } | 923 | } |
921 | else | 924 | else |
922 | { | 925 | { |
923 | GSF_dht_lookup_(pr); | 926 | GSF_dht_lookup_ (pr); |
924 | } | 927 | } |
925 | prq->priority += pr->public_data.original_priority; | 928 | prq->priority += pr->public_data.original_priority; |
926 | pr->public_data.priority = 0; | 929 | pr->public_data.priority = 0; |
927 | pr->public_data.original_priority = 0; | 930 | pr->public_data.original_priority = 0; |
928 | pr->public_data.results_found++; | 931 | pr->public_data.results_found++; |
929 | prq->request_found = GNUNET_YES; | 932 | prq->request_found = GNUNET_YES; |
930 | /* finally, pass on to other peer / local client */ | 933 | /* finally, pass on to other peer / local client */ |
931 | if (!GSF_request_plan_reference_get_last_transmission_(pr->public_data | 934 | if (! GSF_request_plan_reference_get_last_transmission_ (pr->public_data |
932 | .pr_head, | 935 | .pr_head, |
933 | prq->sender, | 936 | prq->sender, |
934 | &last_transmission)) | 937 | &last_transmission)) |
935 | last_transmission.abs_value_us = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 938 | last_transmission.abs_value_us = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
936 | pr->rh(pr->rh_cls, | 939 | pr->rh (pr->rh_cls, |
937 | prq->eval, | 940 | prq->eval, |
938 | pr, | 941 | pr, |
939 | prq->anonymity_level, | 942 | prq->anonymity_level, |
940 | prq->expiration, | 943 | prq->expiration, |
941 | last_transmission, | 944 | last_transmission, |
942 | prq->type, | 945 | prq->type, |
943 | prq->data, | 946 | prq->data, |
944 | prq->size); | 947 | prq->size); |
945 | return GNUNET_YES; | 948 | return GNUNET_YES; |
946 | } | 949 | } |
947 | 950 | ||
@@ -949,7 +952,8 @@ process_reply(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
949 | /** | 952 | /** |
950 | * Context for put_migration_continuation(). | 953 | * Context for put_migration_continuation(). |
951 | */ | 954 | */ |
952 | struct PutMigrationContext { | 955 | struct PutMigrationContext |
956 | { | ||
953 | /** | 957 | /** |
954 | * Start time for the operation. | 958 | * Start time for the operation. |
955 | */ | 959 | */ |
@@ -978,10 +982,10 @@ struct PutMigrationContext { | |||
978 | * @param msg NULL on success, otherwise an error message | 982 | * @param msg NULL on success, otherwise an error message |
979 | */ | 983 | */ |
980 | static void | 984 | static void |
981 | put_migration_continuation(void *cls, | 985 | put_migration_continuation (void *cls, |
982 | int success, | 986 | int success, |
983 | struct GNUNET_TIME_Absolute min_expiration, | 987 | struct GNUNET_TIME_Absolute min_expiration, |
984 | const char *msg) | 988 | const char *msg) |
985 | { | 989 | { |
986 | struct PutMigrationContext *pmc = cls; | 990 | struct PutMigrationContext *pmc = cls; |
987 | struct GSF_ConnectedPeer *cp; | 991 | struct GSF_ConnectedPeer *cp; |
@@ -989,67 +993,67 @@ put_migration_continuation(void *cls, | |||
989 | struct GSF_PeerPerformanceData *ppd; | 993 | struct GSF_PeerPerformanceData *ppd; |
990 | 994 | ||
991 | if (NULL != datastore_put_load) | 995 | if (NULL != datastore_put_load) |
996 | { | ||
997 | if (GNUNET_SYSERR != success) | ||
998 | { | ||
999 | GNUNET_LOAD_update (datastore_put_load, | ||
1000 | GNUNET_TIME_absolute_get_duration (pmc->start) | ||
1001 | .rel_value_us); | ||
1002 | } | ||
1003 | else | ||
992 | { | 1004 | { |
993 | if (GNUNET_SYSERR != success) | 1005 | /* on queue failure / timeout, increase the put load dramatically */ |
994 | { | 1006 | GNUNET_LOAD_update (datastore_put_load, |
995 | GNUNET_LOAD_update(datastore_put_load, | 1007 | GNUNET_TIME_UNIT_MINUTES.rel_value_us); |
996 | GNUNET_TIME_absolute_get_duration(pmc->start) | ||
997 | .rel_value_us); | ||
998 | } | ||
999 | else | ||
1000 | { | ||
1001 | /* on queue failure / timeout, increase the put load dramatically */ | ||
1002 | GNUNET_LOAD_update(datastore_put_load, | ||
1003 | GNUNET_TIME_UNIT_MINUTES.rel_value_us); | ||
1004 | } | ||
1005 | } | 1008 | } |
1006 | cp = GSF_peer_get_(&pmc->origin); | 1009 | } |
1010 | cp = GSF_peer_get_ (&pmc->origin); | ||
1007 | if (GNUNET_OK == success) | 1011 | if (GNUNET_OK == success) |
1012 | { | ||
1013 | if (NULL != cp) | ||
1008 | { | 1014 | { |
1009 | if (NULL != cp) | 1015 | ppd = GSF_get_peer_performance_data_ (cp); |
1010 | { | 1016 | ppd->migration_delay.rel_value_us /= 2; |
1011 | ppd = GSF_get_peer_performance_data_(cp); | ||
1012 | ppd->migration_delay.rel_value_us /= 2; | ||
1013 | } | ||
1014 | GNUNET_free(pmc); | ||
1015 | return; | ||
1016 | } | 1017 | } |
1018 | GNUNET_free (pmc); | ||
1019 | return; | ||
1020 | } | ||
1017 | if ((GNUNET_NO == success) && (GNUNET_NO == pmc->requested) && (NULL != cp)) | 1021 | if ((GNUNET_NO == success) && (GNUNET_NO == pmc->requested) && (NULL != cp)) |
1022 | { | ||
1023 | ppd = GSF_get_peer_performance_data_ (cp); | ||
1024 | if (min_expiration.abs_value_us > 0) | ||
1018 | { | 1025 | { |
1019 | ppd = GSF_get_peer_performance_data_(cp); | 1026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1020 | if (min_expiration.abs_value_us > 0) | 1027 | "Asking to stop migration for %s because datastore is full\n", |
1021 | { | 1028 | GNUNET_STRINGS_relative_time_to_string ( |
1022 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1029 | GNUNET_TIME_absolute_get_remaining (min_expiration), |
1023 | "Asking to stop migration for %s because datastore is full\n", | 1030 | GNUNET_YES)); |
1024 | GNUNET_STRINGS_relative_time_to_string( | 1031 | GSF_block_peer_migration_ (cp, min_expiration); |
1025 | GNUNET_TIME_absolute_get_remaining(min_expiration), | ||
1026 | GNUNET_YES)); | ||
1027 | GSF_block_peer_migration_(cp, min_expiration); | ||
1028 | } | ||
1029 | else | ||
1030 | { | ||
1031 | ppd->migration_delay = GNUNET_TIME_relative_max(GNUNET_TIME_UNIT_SECONDS, | ||
1032 | ppd->migration_delay); | ||
1033 | ppd->migration_delay = | ||
1034 | GNUNET_TIME_relative_min(GNUNET_TIME_UNIT_HOURS, ppd->migration_delay); | ||
1035 | mig_pause.rel_value_us = | ||
1036 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | ||
1037 | ppd->migration_delay.rel_value_us); | ||
1038 | ppd->migration_delay = | ||
1039 | GNUNET_TIME_relative_saturating_multiply(ppd->migration_delay, 2); | ||
1040 | GNUNET_log( | ||
1041 | GNUNET_ERROR_TYPE_DEBUG, | ||
1042 | "Replicated content already exists locally, asking to stop migration for %s\n", | ||
1043 | GNUNET_STRINGS_relative_time_to_string(mig_pause, GNUNET_YES)); | ||
1044 | GSF_block_peer_migration_(cp, | ||
1045 | GNUNET_TIME_relative_to_absolute(mig_pause)); | ||
1046 | } | ||
1047 | } | 1032 | } |
1048 | GNUNET_free(pmc); | 1033 | else |
1049 | GNUNET_STATISTICS_update(GSF_stats, | 1034 | { |
1050 | gettext_noop("# Datastore `PUT' failures"), | 1035 | ppd->migration_delay = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_SECONDS, |
1051 | 1, | 1036 | ppd->migration_delay); |
1052 | GNUNET_NO); | 1037 | ppd->migration_delay = |
1038 | GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, ppd->migration_delay); | ||
1039 | mig_pause.rel_value_us = | ||
1040 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1041 | ppd->migration_delay.rel_value_us); | ||
1042 | ppd->migration_delay = | ||
1043 | GNUNET_TIME_relative_saturating_multiply (ppd->migration_delay, 2); | ||
1044 | GNUNET_log ( | ||
1045 | GNUNET_ERROR_TYPE_DEBUG, | ||
1046 | "Replicated content already exists locally, asking to stop migration for %s\n", | ||
1047 | GNUNET_STRINGS_relative_time_to_string (mig_pause, GNUNET_YES)); | ||
1048 | GSF_block_peer_migration_ (cp, | ||
1049 | GNUNET_TIME_relative_to_absolute (mig_pause)); | ||
1050 | } | ||
1051 | } | ||
1052 | GNUNET_free (pmc); | ||
1053 | GNUNET_STATISTICS_update (GSF_stats, | ||
1054 | gettext_noop ("# Datastore `PUT' failures"), | ||
1055 | 1, | ||
1056 | GNUNET_NO); | ||
1053 | } | 1057 | } |
1054 | 1058 | ||
1055 | 1059 | ||
@@ -1063,22 +1067,22 @@ put_migration_continuation(void *cls, | |||
1063 | * #GNUNET_NO to process normally (load normal or low) | 1067 | * #GNUNET_NO to process normally (load normal or low) |
1064 | */ | 1068 | */ |
1065 | static int | 1069 | static int |
1066 | test_put_load_too_high(uint32_t priority) | 1070 | test_put_load_too_high (uint32_t priority) |
1067 | { | 1071 | { |
1068 | double ld; | 1072 | double ld; |
1069 | 1073 | ||
1070 | if (NULL == datastore_put_load) | 1074 | if (NULL == datastore_put_load) |
1071 | return GNUNET_NO; | 1075 | return GNUNET_NO; |
1072 | if (GNUNET_LOAD_get_average(datastore_put_load) < 50) | 1076 | if (GNUNET_LOAD_get_average (datastore_put_load) < 50) |
1073 | return GNUNET_NO; /* very fast */ | 1077 | return GNUNET_NO; /* very fast */ |
1074 | ld = GNUNET_LOAD_get_load(datastore_put_load); | 1078 | ld = GNUNET_LOAD_get_load (datastore_put_load); |
1075 | if (ld < 2.0 * (1 + priority)) | 1079 | if (ld < 2.0 * (1 + priority)) |
1076 | return GNUNET_NO; | 1080 | return GNUNET_NO; |
1077 | GNUNET_STATISTICS_update(GSF_stats, | 1081 | GNUNET_STATISTICS_update (GSF_stats, |
1078 | gettext_noop( | 1082 | gettext_noop ( |
1079 | "# storage requests dropped due to high load"), | 1083 | "# storage requests dropped due to high load"), |
1080 | 1, | 1084 | 1, |
1081 | GNUNET_NO); | 1085 | GNUNET_NO); |
1082 | return GNUNET_YES; | 1086 | return GNUNET_YES; |
1083 | } | 1087 | } |
1084 | 1088 | ||
@@ -1099,67 +1103,67 @@ test_put_load_too_high(uint32_t priority) | |||
1099 | * @param data pointer to the result data | 1103 | * @param data pointer to the result data |
1100 | */ | 1104 | */ |
1101 | static void | 1105 | static void |
1102 | handle_dht_reply(void *cls, | 1106 | handle_dht_reply (void *cls, |
1103 | struct GNUNET_TIME_Absolute exp, | 1107 | struct GNUNET_TIME_Absolute exp, |
1104 | const struct GNUNET_HashCode *key, | 1108 | const struct GNUNET_HashCode *key, |
1105 | const struct GNUNET_PeerIdentity *get_path, | 1109 | const struct GNUNET_PeerIdentity *get_path, |
1106 | unsigned int get_path_length, | 1110 | unsigned int get_path_length, |
1107 | const struct GNUNET_PeerIdentity *put_path, | 1111 | const struct GNUNET_PeerIdentity *put_path, |
1108 | unsigned int put_path_length, | 1112 | unsigned int put_path_length, |
1109 | enum GNUNET_BLOCK_Type type, | 1113 | enum GNUNET_BLOCK_Type type, |
1110 | size_t size, | 1114 | size_t size, |
1111 | const void *data) | 1115 | const void *data) |
1112 | { | 1116 | { |
1113 | struct GSF_PendingRequest *pr = cls; | 1117 | struct GSF_PendingRequest *pr = cls; |
1114 | struct ProcessReplyClosure prq; | 1118 | struct ProcessReplyClosure prq; |
1115 | struct PutMigrationContext *pmc; | 1119 | struct PutMigrationContext *pmc; |
1116 | 1120 | ||
1117 | GNUNET_STATISTICS_update(GSF_stats, | 1121 | GNUNET_STATISTICS_update (GSF_stats, |
1118 | gettext_noop("# Replies received from DHT"), | 1122 | gettext_noop ("# Replies received from DHT"), |
1119 | 1, | 1123 | 1, |
1120 | GNUNET_NO); | 1124 | GNUNET_NO); |
1121 | memset(&prq, 0, sizeof(prq)); | 1125 | memset (&prq, 0, sizeof(prq)); |
1122 | prq.data = data; | 1126 | prq.data = data; |
1123 | prq.expiration = exp; | 1127 | prq.expiration = exp; |
1124 | /* do not allow migrated content to live longer than 1 year */ | 1128 | /* do not allow migrated content to live longer than 1 year */ |
1125 | prq.expiration = GNUNET_TIME_absolute_min(GNUNET_TIME_relative_to_absolute( | 1129 | prq.expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute ( |
1126 | GNUNET_TIME_UNIT_YEARS), | 1130 | GNUNET_TIME_UNIT_YEARS), |
1127 | prq.expiration); | 1131 | prq.expiration); |
1128 | prq.size = size; | 1132 | prq.size = size; |
1129 | prq.type = type; | 1133 | prq.type = type; |
1130 | prq.eo = GNUNET_BLOCK_EO_NONE; | 1134 | prq.eo = GNUNET_BLOCK_EO_NONE; |
1131 | process_reply(&prq, key, pr); | 1135 | process_reply (&prq, key, pr); |
1132 | if ((GNUNET_YES == active_to_migration) && | 1136 | if ((GNUNET_YES == active_to_migration) && |
1133 | (GNUNET_NO == test_put_load_too_high(prq.priority))) | 1137 | (GNUNET_NO == test_put_load_too_high (prq.priority))) |
1138 | { | ||
1139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1140 | "Replicating result for query `%s' with priority %u\n", | ||
1141 | GNUNET_h2s (key), | ||
1142 | prq.priority); | ||
1143 | pmc = GNUNET_new (struct PutMigrationContext); | ||
1144 | pmc->start = GNUNET_TIME_absolute_get (); | ||
1145 | pmc->requested = GNUNET_YES; | ||
1146 | if (NULL == GNUNET_DATASTORE_put (GSF_dsh, | ||
1147 | 0, | ||
1148 | key, | ||
1149 | size, | ||
1150 | data, | ||
1151 | type, | ||
1152 | prq.priority, | ||
1153 | 1 /* anonymity */, | ||
1154 | 0 /* replication */, | ||
1155 | exp, | ||
1156 | 1 + prq.priority, | ||
1157 | MAX_DATASTORE_QUEUE, | ||
1158 | &put_migration_continuation, | ||
1159 | pmc)) | ||
1134 | { | 1160 | { |
1135 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1161 | put_migration_continuation (pmc, |
1136 | "Replicating result for query `%s' with priority %u\n", | 1162 | GNUNET_SYSERR, |
1137 | GNUNET_h2s(key), | 1163 | GNUNET_TIME_UNIT_ZERO_ABS, |
1138 | prq.priority); | 1164 | NULL); |
1139 | pmc = GNUNET_new(struct PutMigrationContext); | ||
1140 | pmc->start = GNUNET_TIME_absolute_get(); | ||
1141 | pmc->requested = GNUNET_YES; | ||
1142 | if (NULL == GNUNET_DATASTORE_put(GSF_dsh, | ||
1143 | 0, | ||
1144 | key, | ||
1145 | size, | ||
1146 | data, | ||
1147 | type, | ||
1148 | prq.priority, | ||
1149 | 1 /* anonymity */, | ||
1150 | 0 /* replication */, | ||
1151 | exp, | ||
1152 | 1 + prq.priority, | ||
1153 | MAX_DATASTORE_QUEUE, | ||
1154 | &put_migration_continuation, | ||
1155 | pmc)) | ||
1156 | { | ||
1157 | put_migration_continuation(pmc, | ||
1158 | GNUNET_SYSERR, | ||
1159 | GNUNET_TIME_UNIT_ZERO_ABS, | ||
1160 | NULL); | ||
1161 | } | ||
1162 | } | 1165 | } |
1166 | } | ||
1163 | } | 1167 | } |
1164 | 1168 | ||
1165 | 1169 | ||
@@ -1169,7 +1173,7 @@ handle_dht_reply(void *cls, | |||
1169 | * @param pr the pending request to process | 1173 | * @param pr the pending request to process |
1170 | */ | 1174 | */ |
1171 | void | 1175 | void |
1172 | GSF_dht_lookup_(struct GSF_PendingRequest *pr) | 1176 | GSF_dht_lookup_ (struct GSF_PendingRequest *pr) |
1173 | { | 1177 | { |
1174 | const void *xquery; | 1178 | const void *xquery; |
1175 | size_t xquery_size; | 1179 | size_t xquery_size; |
@@ -1179,32 +1183,32 @@ GSF_dht_lookup_(struct GSF_PendingRequest *pr) | |||
1179 | if (0 != pr->public_data.anonymity_level) | 1183 | if (0 != pr->public_data.anonymity_level) |
1180 | return; | 1184 | return; |
1181 | if (NULL != pr->gh) | 1185 | if (NULL != pr->gh) |
1182 | { | 1186 | { |
1183 | GNUNET_DHT_get_stop(pr->gh); | 1187 | GNUNET_DHT_get_stop (pr->gh); |
1184 | pr->gh = NULL; | 1188 | pr->gh = NULL; |
1185 | } | 1189 | } |
1186 | xquery = NULL; | 1190 | xquery = NULL; |
1187 | xquery_size = 0; | 1191 | xquery_size = 0; |
1188 | if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY)) | 1192 | if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY)) |
1189 | { | 1193 | { |
1190 | GNUNET_assert(0 != pr->sender_pid); | 1194 | GNUNET_assert (0 != pr->sender_pid); |
1191 | GNUNET_PEER_resolve(pr->sender_pid, &pi); | 1195 | GNUNET_PEER_resolve (pr->sender_pid, &pi); |
1192 | GNUNET_memcpy(&buf[xquery_size], &pi, sizeof(struct GNUNET_PeerIdentity)); | 1196 | GNUNET_memcpy (&buf[xquery_size], &pi, sizeof(struct GNUNET_PeerIdentity)); |
1193 | xquery_size += sizeof(struct GNUNET_PeerIdentity); | 1197 | xquery_size += sizeof(struct GNUNET_PeerIdentity); |
1194 | } | 1198 | } |
1195 | pr->gh = GNUNET_DHT_get_start(GSF_dht, | 1199 | pr->gh = GNUNET_DHT_get_start (GSF_dht, |
1196 | pr->public_data.type, | 1200 | pr->public_data.type, |
1197 | &pr->public_data.query, | 1201 | &pr->public_data.query, |
1198 | DHT_GET_REPLICATION, | 1202 | DHT_GET_REPLICATION, |
1199 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 1203 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
1200 | xquery, | 1204 | xquery, |
1201 | xquery_size, | 1205 | xquery_size, |
1202 | &handle_dht_reply, | 1206 | &handle_dht_reply, |
1203 | pr); | 1207 | pr); |
1204 | if ((NULL != pr->gh) && (0 != pr->replies_seen_count)) | 1208 | if ((NULL != pr->gh) && (0 != pr->replies_seen_count)) |
1205 | GNUNET_DHT_get_filter_known_results(pr->gh, | 1209 | GNUNET_DHT_get_filter_known_results (pr->gh, |
1206 | pr->replies_seen_count, | 1210 | pr->replies_seen_count, |
1207 | pr->replies_seen); | 1211 | pr->replies_seen); |
1208 | } | 1212 | } |
1209 | 1213 | ||
1210 | 1214 | ||
@@ -1218,11 +1222,11 @@ GSF_dht_lookup_(struct GSF_PendingRequest *pr) | |||
1218 | * @param data reply block data, NULL on error | 1222 | * @param data reply block data, NULL on error |
1219 | */ | 1223 | */ |
1220 | static void | 1224 | static void |
1221 | cadet_reply_proc(void *cls, | 1225 | cadet_reply_proc (void *cls, |
1222 | enum GNUNET_BLOCK_Type type, | 1226 | enum GNUNET_BLOCK_Type type, |
1223 | struct GNUNET_TIME_Absolute expiration, | 1227 | struct GNUNET_TIME_Absolute expiration, |
1224 | size_t data_size, | 1228 | size_t data_size, |
1225 | const void *data) | 1229 | const void *data) |
1226 | { | 1230 | { |
1227 | struct GSF_PendingRequest *pr = cls; | 1231 | struct GSF_PendingRequest *pr = cls; |
1228 | struct ProcessReplyClosure prq; | 1232 | struct ProcessReplyClosure prq; |
@@ -1230,46 +1234,46 @@ cadet_reply_proc(void *cls, | |||
1230 | 1234 | ||
1231 | pr->cadet_request = NULL; | 1235 | pr->cadet_request = NULL; |
1232 | if (GNUNET_BLOCK_TYPE_ANY == type) | 1236 | if (GNUNET_BLOCK_TYPE_ANY == type) |
1233 | { | 1237 | { |
1234 | GNUNET_break(NULL == data); | 1238 | GNUNET_break (NULL == data); |
1235 | GNUNET_break(0 == data_size); | 1239 | GNUNET_break (0 == data_size); |
1236 | pr->cadet_retry_count++; | 1240 | pr->cadet_retry_count++; |
1237 | if (pr->cadet_retry_count >= CADET_RETRY_MAX) | 1241 | if (pr->cadet_retry_count >= CADET_RETRY_MAX) |
1238 | return; /* give up on cadet */ | 1242 | return; /* give up on cadet */ |
1239 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Error retrieiving block via cadet\n"); | 1243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error retrieiving block via cadet\n"); |
1240 | /* retry -- without delay, as this is non-anonymous | 1244 | /* retry -- without delay, as this is non-anonymous |
1241 | and cadet/cadet connect will take some time anyway */ | 1245 | and cadet/cadet connect will take some time anyway */ |
1242 | pr->cadet_request = GSF_cadet_query(pr->public_data.target, | 1246 | pr->cadet_request = GSF_cadet_query (pr->public_data.target, |
1243 | &pr->public_data.query, | 1247 | &pr->public_data.query, |
1244 | pr->public_data.type, | 1248 | pr->public_data.type, |
1245 | &cadet_reply_proc, | 1249 | &cadet_reply_proc, |
1246 | pr); | 1250 | pr); |
1247 | return; | 1251 | return; |
1248 | } | 1252 | } |
1249 | if (GNUNET_YES != | 1253 | if (GNUNET_YES != |
1250 | GNUNET_BLOCK_get_key(GSF_block_ctx, type, data, data_size, &query)) | 1254 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, data_size, &query)) |
1251 | { | 1255 | { |
1252 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1253 | "Failed to derive key for block of type %d\n", | 1257 | "Failed to derive key for block of type %d\n", |
1254 | (int)type); | 1258 | (int) type); |
1255 | GNUNET_break_op(0); | 1259 | GNUNET_break_op (0); |
1256 | return; | 1260 | return; |
1257 | } | 1261 | } |
1258 | GNUNET_STATISTICS_update(GSF_stats, | 1262 | GNUNET_STATISTICS_update (GSF_stats, |
1259 | gettext_noop("# Replies received from CADET"), | 1263 | gettext_noop ("# Replies received from CADET"), |
1260 | 1, | 1264 | 1, |
1261 | GNUNET_NO); | 1265 | GNUNET_NO); |
1262 | memset(&prq, 0, sizeof(prq)); | 1266 | memset (&prq, 0, sizeof(prq)); |
1263 | prq.data = data; | 1267 | prq.data = data; |
1264 | prq.expiration = expiration; | 1268 | prq.expiration = expiration; |
1265 | /* do not allow migrated content to live longer than 1 year */ | 1269 | /* do not allow migrated content to live longer than 1 year */ |
1266 | prq.expiration = GNUNET_TIME_absolute_min(GNUNET_TIME_relative_to_absolute( | 1270 | prq.expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute ( |
1267 | GNUNET_TIME_UNIT_YEARS), | 1271 | GNUNET_TIME_UNIT_YEARS), |
1268 | prq.expiration); | 1272 | prq.expiration); |
1269 | prq.size = data_size; | 1273 | prq.size = data_size; |
1270 | prq.type = type; | 1274 | prq.type = type; |
1271 | prq.eo = GNUNET_BLOCK_EO_NONE; | 1275 | prq.eo = GNUNET_BLOCK_EO_NONE; |
1272 | process_reply(&prq, &query, pr); | 1276 | process_reply (&prq, &query, pr); |
1273 | } | 1277 | } |
1274 | 1278 | ||
1275 | 1279 | ||
@@ -1279,23 +1283,23 @@ cadet_reply_proc(void *cls, | |||
1279 | * @param pr the pending request to process | 1283 | * @param pr the pending request to process |
1280 | */ | 1284 | */ |
1281 | void | 1285 | void |
1282 | GSF_cadet_lookup_(struct GSF_PendingRequest *pr) | 1286 | GSF_cadet_lookup_ (struct GSF_PendingRequest *pr) |
1283 | { | 1287 | { |
1284 | if (0 != pr->public_data.anonymity_level) | 1288 | if (0 != pr->public_data.anonymity_level) |
1285 | return; | 1289 | return; |
1286 | if (0 == pr->public_data.target) | 1290 | if (0 == pr->public_data.target) |
1287 | { | 1291 | { |
1288 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1289 | "Cannot do cadet-based download, target peer not known\n"); | 1293 | "Cannot do cadet-based download, target peer not known\n"); |
1290 | return; | 1294 | return; |
1291 | } | 1295 | } |
1292 | if (NULL != pr->cadet_request) | 1296 | if (NULL != pr->cadet_request) |
1293 | return; | 1297 | return; |
1294 | pr->cadet_request = GSF_cadet_query(pr->public_data.target, | 1298 | pr->cadet_request = GSF_cadet_query (pr->public_data.target, |
1295 | &pr->public_data.query, | 1299 | &pr->public_data.query, |
1296 | pr->public_data.type, | 1300 | pr->public_data.type, |
1297 | &cadet_reply_proc, | 1301 | &cadet_reply_proc, |
1298 | pr); | 1302 | pr); |
1299 | } | 1303 | } |
1300 | 1304 | ||
1301 | 1305 | ||
@@ -1305,18 +1309,18 @@ GSF_cadet_lookup_(struct GSF_PendingRequest *pr) | |||
1305 | * @param cls the `struct GSF_PendingRequest` | 1309 | * @param cls the `struct GSF_PendingRequest` |
1306 | */ | 1310 | */ |
1307 | static void | 1311 | static void |
1308 | warn_delay_task(void *cls) | 1312 | warn_delay_task (void *cls) |
1309 | { | 1313 | { |
1310 | struct GSF_PendingRequest *pr = cls; | 1314 | struct GSF_PendingRequest *pr = cls; |
1311 | 1315 | ||
1312 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 1316 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
1313 | _("Datastore lookup already took %s!\n"), | 1317 | _ ("Datastore lookup already took %s!\n"), |
1314 | GNUNET_STRINGS_relative_time_to_string( | 1318 | GNUNET_STRINGS_relative_time_to_string ( |
1315 | GNUNET_TIME_absolute_get_duration(pr->qe_start), | 1319 | GNUNET_TIME_absolute_get_duration (pr->qe_start), |
1316 | GNUNET_YES)); | 1320 | GNUNET_YES)); |
1317 | pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, | 1321 | pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
1318 | &warn_delay_task, | 1322 | &warn_delay_task, |
1319 | pr); | 1323 | pr); |
1320 | } | 1324 | } |
1321 | 1325 | ||
1322 | 1326 | ||
@@ -1326,140 +1330,140 @@ warn_delay_task(void *cls) | |||
1326 | * @param cls the `struct GSF_PendingRequest` | 1330 | * @param cls the `struct GSF_PendingRequest` |
1327 | */ | 1331 | */ |
1328 | static void | 1332 | static void |
1329 | odc_warn_delay_task(void *cls) | 1333 | odc_warn_delay_task (void *cls) |
1330 | { | 1334 | { |
1331 | struct GSF_PendingRequest *pr = cls; | 1335 | struct GSF_PendingRequest *pr = cls; |
1332 | 1336 | ||
1333 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1337 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1334 | _("On-demand lookup already took %s!\n"), | 1338 | _ ("On-demand lookup already took %s!\n"), |
1335 | GNUNET_STRINGS_relative_time_to_string( | 1339 | GNUNET_STRINGS_relative_time_to_string ( |
1336 | GNUNET_TIME_absolute_get_duration(pr->qe_start), | 1340 | GNUNET_TIME_absolute_get_duration (pr->qe_start), |
1337 | GNUNET_YES)); | 1341 | GNUNET_YES)); |
1338 | pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, | 1342 | pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
1339 | &odc_warn_delay_task, | 1343 | &odc_warn_delay_task, |
1340 | pr); | 1344 | pr); |
1341 | } | 1345 | } |
1342 | 1346 | ||
1343 | 1347 | ||
1344 | /* Call our continuation (if we have any) */ | 1348 | /* Call our continuation (if we have any) */ |
1345 | static void | 1349 | static void |
1346 | call_continuation(struct GSF_PendingRequest *pr) | 1350 | call_continuation (struct GSF_PendingRequest *pr) |
1347 | { | 1351 | { |
1348 | GSF_LocalLookupContinuation cont = pr->llc_cont; | 1352 | GSF_LocalLookupContinuation cont = pr->llc_cont; |
1349 | 1353 | ||
1350 | GNUNET_assert(NULL == pr->qe); | 1354 | GNUNET_assert (NULL == pr->qe); |
1351 | if (NULL != pr->warn_task) | 1355 | if (NULL != pr->warn_task) |
1352 | { | 1356 | { |
1353 | GNUNET_SCHEDULER_cancel(pr->warn_task); | 1357 | GNUNET_SCHEDULER_cancel (pr->warn_task); |
1354 | pr->warn_task = NULL; | 1358 | pr->warn_task = NULL; |
1355 | } | 1359 | } |
1356 | if (NULL == cont) | 1360 | if (NULL == cont) |
1357 | return; /* no continuation */ | 1361 | return; /* no continuation */ |
1358 | pr->llc_cont = NULL; | 1362 | pr->llc_cont = NULL; |
1359 | if (0 != (GSF_PRO_LOCAL_ONLY & pr->public_data.options)) | 1363 | if (0 != (GSF_PRO_LOCAL_ONLY & pr->public_data.options)) |
1364 | { | ||
1365 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != pr->local_result) | ||
1360 | { | 1366 | { |
1361 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != pr->local_result) | 1367 | /* Signal that we are done and that there won't be any |
1362 | { | 1368 | additional results to allow client to clean up state. */ |
1363 | /* Signal that we are done and that there won't be any | 1369 | pr->rh (pr->rh_cls, |
1364 | additional results to allow client to clean up state. */ | 1370 | GNUNET_BLOCK_EVALUATION_OK_LAST, |
1365 | pr->rh(pr->rh_cls, | 1371 | pr, |
1366 | GNUNET_BLOCK_EVALUATION_OK_LAST, | 1372 | UINT32_MAX, |
1367 | pr, | 1373 | GNUNET_TIME_UNIT_ZERO_ABS, |
1368 | UINT32_MAX, | 1374 | GNUNET_TIME_UNIT_FOREVER_ABS, |
1369 | GNUNET_TIME_UNIT_ZERO_ABS, | 1375 | GNUNET_BLOCK_TYPE_ANY, |
1370 | GNUNET_TIME_UNIT_FOREVER_ABS, | 1376 | NULL, |
1371 | GNUNET_BLOCK_TYPE_ANY, | 1377 | 0); |
1372 | NULL, | ||
1373 | 0); | ||
1374 | } | ||
1375 | /* Finally, call our continuation to signal that we are | ||
1376 | done with local processing of this request; i.e. to | ||
1377 | start reading again from the client. */ | ||
1378 | cont(pr->llc_cont_cls, NULL, GNUNET_BLOCK_EVALUATION_OK_LAST); | ||
1379 | return; | ||
1380 | } | 1378 | } |
1379 | /* Finally, call our continuation to signal that we are | ||
1380 | done with local processing of this request; i.e. to | ||
1381 | start reading again from the client. */ | ||
1382 | cont (pr->llc_cont_cls, NULL, GNUNET_BLOCK_EVALUATION_OK_LAST); | ||
1383 | return; | ||
1384 | } | ||
1381 | 1385 | ||
1382 | cont(pr->llc_cont_cls, pr, pr->local_result); | 1386 | cont (pr->llc_cont_cls, pr, pr->local_result); |
1383 | } | 1387 | } |
1384 | 1388 | ||
1385 | 1389 | ||
1386 | /* Update stats and call continuation */ | 1390 | /* Update stats and call continuation */ |
1387 | static void | 1391 | static void |
1388 | no_more_local_results(struct GSF_PendingRequest *pr) | 1392 | no_more_local_results (struct GSF_PendingRequest *pr) |
1389 | { | 1393 | { |
1390 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1391 | "No further local responses available.\n"); | 1395 | "No further local responses available.\n"); |
1392 | #if INSANE_STATISTICS | 1396 | #if INSANE_STATISTICS |
1393 | if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == pr->public_data.type) || | 1397 | if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == pr->public_data.type) || |
1394 | (GNUNET_BLOCK_TYPE_FS_IBLOCK == pr->public_data.type)) | 1398 | (GNUNET_BLOCK_TYPE_FS_IBLOCK == pr->public_data.type)) |
1395 | GNUNET_STATISTICS_update(GSF_stats, | 1399 | GNUNET_STATISTICS_update (GSF_stats, |
1396 | gettext_noop( | 1400 | gettext_noop ( |
1397 | "# requested DBLOCK or IBLOCK not found"), | 1401 | "# requested DBLOCK or IBLOCK not found"), |
1398 | 1, | 1402 | 1, |
1399 | GNUNET_NO); | 1403 | GNUNET_NO); |
1400 | #endif | 1404 | #endif |
1401 | call_continuation(pr); | 1405 | call_continuation (pr); |
1402 | } | 1406 | } |
1403 | 1407 | ||
1404 | 1408 | ||
1405 | /* forward declaration */ | 1409 | /* forward declaration */ |
1406 | static void | 1410 | static void |
1407 | process_local_reply(void *cls, | 1411 | process_local_reply (void *cls, |
1408 | const struct GNUNET_HashCode *key, | 1412 | const struct GNUNET_HashCode *key, |
1409 | size_t size, | 1413 | size_t size, |
1410 | const void *data, | 1414 | const void *data, |
1411 | enum GNUNET_BLOCK_Type type, | 1415 | enum GNUNET_BLOCK_Type type, |
1412 | uint32_t priority, | 1416 | uint32_t priority, |
1413 | uint32_t anonymity, | 1417 | uint32_t anonymity, |
1414 | uint32_t replication, | 1418 | uint32_t replication, |
1415 | struct GNUNET_TIME_Absolute expiration, | 1419 | struct GNUNET_TIME_Absolute expiration, |
1416 | uint64_t uid); | 1420 | uint64_t uid); |
1417 | 1421 | ||
1418 | 1422 | ||
1419 | /* Start a local query */ | 1423 | /* Start a local query */ |
1420 | static void | 1424 | static void |
1421 | start_local_query(struct GSF_PendingRequest *pr, | 1425 | start_local_query (struct GSF_PendingRequest *pr, |
1422 | uint64_t next_uid, | 1426 | uint64_t next_uid, |
1423 | bool random) | 1427 | bool random) |
1424 | { | 1428 | { |
1425 | pr->qe_start = GNUNET_TIME_absolute_get(); | 1429 | pr->qe_start = GNUNET_TIME_absolute_get (); |
1426 | pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, | 1430 | pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
1427 | &warn_delay_task, | 1431 | &warn_delay_task, |
1428 | pr); | 1432 | pr); |
1429 | pr->qe = GNUNET_DATASTORE_get_key(GSF_dsh, | 1433 | pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh, |
1430 | next_uid, | 1434 | next_uid, |
1431 | random, | 1435 | random, |
1432 | &pr->public_data.query, | 1436 | &pr->public_data.query, |
1433 | pr->public_data.type == | 1437 | pr->public_data.type == |
1434 | GNUNET_BLOCK_TYPE_FS_DBLOCK | 1438 | GNUNET_BLOCK_TYPE_FS_DBLOCK |
1435 | ? GNUNET_BLOCK_TYPE_ANY | 1439 | ? GNUNET_BLOCK_TYPE_ANY |
1436 | : pr->public_data.type, | 1440 | : pr->public_data.type, |
1437 | (0 != (GSF_PRO_PRIORITY_UNLIMITED & | 1441 | (0 != (GSF_PRO_PRIORITY_UNLIMITED |
1438 | pr->public_data.options)) | 1442 | & pr->public_data.options)) |
1439 | ? UINT_MAX | 1443 | ? UINT_MAX |
1440 | : 1 | 1444 | : 1 |
1441 | /* queue priority */, | 1445 | /* queue priority */, |
1442 | (0 != (GSF_PRO_PRIORITY_UNLIMITED & | 1446 | (0 != (GSF_PRO_PRIORITY_UNLIMITED |
1443 | pr->public_data.options)) | 1447 | & pr->public_data.options)) |
1444 | ? UINT_MAX | 1448 | ? UINT_MAX |
1445 | : GSF_datastore_queue_size | 1449 | : GSF_datastore_queue_size |
1446 | /* max queue size */, | 1450 | /* max queue size */, |
1447 | &process_local_reply, | 1451 | &process_local_reply, |
1448 | pr); | 1452 | pr); |
1449 | if (NULL != pr->qe) | 1453 | if (NULL != pr->qe) |
1450 | return; | 1454 | return; |
1451 | GNUNET_log( | 1455 | GNUNET_log ( |
1452 | GNUNET_ERROR_TYPE_DEBUG, | 1456 | GNUNET_ERROR_TYPE_DEBUG, |
1453 | "ERROR Requesting `%s' of type %d with next_uid %llu from datastore.\n", | 1457 | "ERROR Requesting `%s' of type %d with next_uid %llu from datastore.\n", |
1454 | GNUNET_h2s(&pr->public_data.query), | 1458 | GNUNET_h2s (&pr->public_data.query), |
1455 | pr->public_data.type, | 1459 | pr->public_data.type, |
1456 | (unsigned long long)next_uid); | 1460 | (unsigned long long) next_uid); |
1457 | GNUNET_STATISTICS_update(GSF_stats, | 1461 | GNUNET_STATISTICS_update (GSF_stats, |
1458 | gettext_noop( | 1462 | gettext_noop ( |
1459 | "# Datastore lookups concluded (error queueing)"), | 1463 | "# Datastore lookups concluded (error queueing)"), |
1460 | 1, | 1464 | 1, |
1461 | GNUNET_NO); | 1465 | GNUNET_NO); |
1462 | call_continuation(pr); | 1466 | call_continuation (pr); |
1463 | } | 1467 | } |
1464 | 1468 | ||
1465 | 1469 | ||
@@ -1482,178 +1486,178 @@ start_local_query(struct GSF_PendingRequest *pr, | |||
1482 | * maybe 0 if no unique identifier is available | 1486 | * maybe 0 if no unique identifier is available |
1483 | */ | 1487 | */ |
1484 | static void | 1488 | static void |
1485 | process_local_reply(void *cls, | 1489 | process_local_reply (void *cls, |
1486 | const struct GNUNET_HashCode *key, | 1490 | const struct GNUNET_HashCode *key, |
1487 | size_t size, | 1491 | size_t size, |
1488 | const void *data, | 1492 | const void *data, |
1489 | enum GNUNET_BLOCK_Type type, | 1493 | enum GNUNET_BLOCK_Type type, |
1490 | uint32_t priority, | 1494 | uint32_t priority, |
1491 | uint32_t anonymity, | 1495 | uint32_t anonymity, |
1492 | uint32_t replication, | 1496 | uint32_t replication, |
1493 | struct GNUNET_TIME_Absolute expiration, | 1497 | struct GNUNET_TIME_Absolute expiration, |
1494 | uint64_t uid) | 1498 | uint64_t uid) |
1495 | { | 1499 | { |
1496 | struct GSF_PendingRequest *pr = cls; | 1500 | struct GSF_PendingRequest *pr = cls; |
1497 | struct ProcessReplyClosure prq; | 1501 | struct ProcessReplyClosure prq; |
1498 | struct GNUNET_HashCode query; | 1502 | struct GNUNET_HashCode query; |
1499 | unsigned int old_rf; | 1503 | unsigned int old_rf; |
1500 | 1504 | ||
1501 | GNUNET_SCHEDULER_cancel(pr->warn_task); | 1505 | GNUNET_SCHEDULER_cancel (pr->warn_task); |
1502 | pr->warn_task = NULL; | 1506 | pr->warn_task = NULL; |
1503 | if (NULL == pr->qe) | 1507 | if (NULL == pr->qe) |
1504 | goto called_from_on_demand; | 1508 | goto called_from_on_demand; |
1505 | pr->qe = NULL; | 1509 | pr->qe = NULL; |
1506 | if ( | 1510 | if ( |
1507 | (NULL == key) && pr->seen_null && | 1511 | (NULL == key) && pr->seen_null && |
1508 | !pr->have_first_uid) /* We have hit the end for the 2nd time with no results */ | 1512 | ! pr->have_first_uid) /* We have hit the end for the 2nd time with no results */ |
1509 | { | 1513 | { |
1510 | /* No results */ | 1514 | /* No results */ |
1511 | #if INSANE_STATISTICS | 1515 | #if INSANE_STATISTICS |
1512 | GNUNET_STATISTICS_update(GSF_stats, | 1516 | GNUNET_STATISTICS_update (GSF_stats, |
1513 | gettext_noop( | 1517 | gettext_noop ( |
1514 | "# Datastore lookups concluded (no results)"), | 1518 | "# Datastore lookups concluded (no results)"), |
1515 | 1, | 1519 | 1, |
1516 | GNUNET_NO); | 1520 | GNUNET_NO); |
1517 | #endif | 1521 | #endif |
1518 | no_more_local_results(pr); | 1522 | no_more_local_results (pr); |
1519 | return; | 1523 | return; |
1520 | } | 1524 | } |
1521 | if (((NULL == key) && | 1525 | if (((NULL == key) && |
1522 | pr->seen_null) || /* We have hit the end for the 2nd time OR */ | 1526 | pr->seen_null) || /* We have hit the end for the 2nd time OR */ |
1523 | (pr->seen_null && pr->have_first_uid && | 1527 | (pr->seen_null && pr->have_first_uid && |
1524 | (uid >= pr->first_uid))) /* We have hit the end and past first UID */ | 1528 | (uid >= pr->first_uid))) /* We have hit the end and past first UID */ |
1525 | { | 1529 | { |
1526 | /* Seen all results */ | 1530 | /* Seen all results */ |
1527 | GNUNET_STATISTICS_update(GSF_stats, | 1531 | GNUNET_STATISTICS_update (GSF_stats, |
1528 | gettext_noop( | 1532 | gettext_noop ( |
1529 | "# Datastore lookups concluded (seen all)"), | 1533 | "# Datastore lookups concluded (seen all)"), |
1530 | 1, | 1534 | 1, |
1531 | GNUNET_NO); | 1535 | GNUNET_NO); |
1532 | no_more_local_results(pr); | 1536 | no_more_local_results (pr); |
1533 | return; | 1537 | return; |
1534 | } | 1538 | } |
1535 | if (NULL == key) | 1539 | if (NULL == key) |
1536 | { | 1540 | { |
1537 | GNUNET_assert(!pr->seen_null); | 1541 | GNUNET_assert (! pr->seen_null); |
1538 | pr->seen_null = true; | 1542 | pr->seen_null = true; |
1539 | start_local_query(pr, 0 /* next_uid */, false /* random */); | 1543 | start_local_query (pr, 0 /* next_uid */, false /* random */); |
1540 | return; | 1544 | return; |
1541 | } | 1545 | } |
1542 | if (!pr->have_first_uid) | 1546 | if (! pr->have_first_uid) |
1543 | { | 1547 | { |
1544 | pr->first_uid = uid; | 1548 | pr->first_uid = uid; |
1545 | pr->have_first_uid = true; | 1549 | pr->have_first_uid = true; |
1546 | } | 1550 | } |
1547 | pr->result_count++; | 1551 | pr->result_count++; |
1548 | if (pr->result_count > MAX_RESULTS) | 1552 | if (pr->result_count > MAX_RESULTS) |
1549 | { | 1553 | { |
1550 | GNUNET_STATISTICS_update( | 1554 | GNUNET_STATISTICS_update ( |
1551 | GSF_stats, | 1555 | GSF_stats, |
1552 | gettext_noop("# Datastore lookups aborted (more than MAX_RESULTS)"), | 1556 | gettext_noop ("# Datastore lookups aborted (more than MAX_RESULTS)"), |
1553 | 1, | 1557 | 1, |
1554 | GNUNET_NO); | 1558 | GNUNET_NO); |
1555 | no_more_local_results(pr); | 1559 | no_more_local_results (pr); |
1556 | return; | 1560 | return; |
1557 | } | 1561 | } |
1558 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1562 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1559 | "Received reply for `%s' of type %d with UID %llu from datastore.\n", | 1563 | "Received reply for `%s' of type %d with UID %llu from datastore.\n", |
1560 | GNUNET_h2s(key), | 1564 | GNUNET_h2s (key), |
1561 | type, | 1565 | type, |
1562 | (unsigned long long)uid); | 1566 | (unsigned long long) uid); |
1563 | if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) | 1567 | if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) |
1568 | { | ||
1569 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1570 | "Found ONDEMAND block, performing on-demand encoding\n"); | ||
1571 | GNUNET_STATISTICS_update (GSF_stats, | ||
1572 | gettext_noop ( | ||
1573 | "# on-demand blocks matched requests"), | ||
1574 | 1, | ||
1575 | GNUNET_NO); | ||
1576 | pr->qe_start = GNUNET_TIME_absolute_get (); | ||
1577 | pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | ||
1578 | &odc_warn_delay_task, | ||
1579 | pr); | ||
1580 | if (GNUNET_OK == GNUNET_FS_handle_on_demand_block (key, | ||
1581 | size, | ||
1582 | data, | ||
1583 | type, | ||
1584 | priority, | ||
1585 | anonymity, | ||
1586 | replication, | ||
1587 | expiration, | ||
1588 | uid, | ||
1589 | &process_local_reply, | ||
1590 | pr)) | ||
1564 | { | 1591 | { |
1565 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1592 | GNUNET_STATISTICS_update (GSF_stats, |
1566 | "Found ONDEMAND block, performing on-demand encoding\n"); | 1593 | gettext_noop ( |
1567 | GNUNET_STATISTICS_update(GSF_stats, | 1594 | "# on-demand lookups performed successfully"), |
1568 | gettext_noop( | 1595 | 1, |
1569 | "# on-demand blocks matched requests"), | 1596 | GNUNET_NO); |
1570 | 1, | 1597 | return; /* we're done */ |
1571 | GNUNET_NO); | ||
1572 | pr->qe_start = GNUNET_TIME_absolute_get(); | ||
1573 | pr->warn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, | ||
1574 | &odc_warn_delay_task, | ||
1575 | pr); | ||
1576 | if (GNUNET_OK == GNUNET_FS_handle_on_demand_block(key, | ||
1577 | size, | ||
1578 | data, | ||
1579 | type, | ||
1580 | priority, | ||
1581 | anonymity, | ||
1582 | replication, | ||
1583 | expiration, | ||
1584 | uid, | ||
1585 | &process_local_reply, | ||
1586 | pr)) | ||
1587 | { | ||
1588 | GNUNET_STATISTICS_update(GSF_stats, | ||
1589 | gettext_noop( | ||
1590 | "# on-demand lookups performed successfully"), | ||
1591 | 1, | ||
1592 | GNUNET_NO); | ||
1593 | return; /* we're done */ | ||
1594 | } | ||
1595 | GNUNET_STATISTICS_update(GSF_stats, | ||
1596 | gettext_noop("# on-demand lookups failed"), | ||
1597 | 1, | ||
1598 | GNUNET_NO); | ||
1599 | GNUNET_SCHEDULER_cancel(pr->warn_task); | ||
1600 | start_local_query(pr, uid + 1 /* next_uid */, false /* random */); | ||
1601 | return; | ||
1602 | } | 1598 | } |
1599 | GNUNET_STATISTICS_update (GSF_stats, | ||
1600 | gettext_noop ("# on-demand lookups failed"), | ||
1601 | 1, | ||
1602 | GNUNET_NO); | ||
1603 | GNUNET_SCHEDULER_cancel (pr->warn_task); | ||
1604 | start_local_query (pr, uid + 1 /* next_uid */, false /* random */); | ||
1605 | return; | ||
1606 | } | ||
1603 | called_from_on_demand: | 1607 | called_from_on_demand: |
1604 | old_rf = pr->public_data.results_found; | 1608 | old_rf = pr->public_data.results_found; |
1605 | memset(&prq, 0, sizeof(prq)); | 1609 | memset (&prq, 0, sizeof(prq)); |
1606 | prq.data = data; | 1610 | prq.data = data; |
1607 | prq.expiration = expiration; | 1611 | prq.expiration = expiration; |
1608 | prq.size = size; | 1612 | prq.size = size; |
1609 | if (GNUNET_OK != | 1613 | if (GNUNET_OK != |
1610 | GNUNET_BLOCK_get_key(GSF_block_ctx, type, data, size, &query)) | 1614 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, size, &query)) |
1611 | { | 1615 | { |
1612 | GNUNET_break(0); | 1616 | GNUNET_break (0); |
1613 | GNUNET_DATASTORE_remove(GSF_dsh, | 1617 | GNUNET_DATASTORE_remove (GSF_dsh, |
1614 | key, | 1618 | key, |
1615 | size, | 1619 | size, |
1616 | data, | 1620 | data, |
1617 | UINT_MAX, | 1621 | UINT_MAX, |
1618 | UINT_MAX, | 1622 | UINT_MAX, |
1619 | NULL, | 1623 | NULL, |
1620 | NULL); | 1624 | NULL); |
1621 | start_local_query(pr, uid + 1 /* next_uid */, false /* random */); | 1625 | start_local_query (pr, uid + 1 /* next_uid */, false /* random */); |
1622 | return; | 1626 | return; |
1623 | } | 1627 | } |
1624 | prq.type = type; | 1628 | prq.type = type; |
1625 | prq.priority = priority; | 1629 | prq.priority = priority; |
1626 | prq.request_found = GNUNET_NO; | 1630 | prq.request_found = GNUNET_NO; |
1627 | prq.anonymity_level = anonymity; | 1631 | prq.anonymity_level = anonymity; |
1628 | if ((0 == old_rf) && (0 == pr->public_data.results_found)) | 1632 | if ((0 == old_rf) && (0 == pr->public_data.results_found)) |
1629 | GSF_update_datastore_delay_(pr->public_data.start_time); | 1633 | GSF_update_datastore_delay_ (pr->public_data.start_time); |
1630 | prq.eo = GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO; | 1634 | prq.eo = GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO; |
1631 | process_reply(&prq, key, pr); | 1635 | process_reply (&prq, key, pr); |
1632 | pr->local_result = prq.eval; | 1636 | pr->local_result = prq.eval; |
1633 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == prq.eval) | 1637 | if (GNUNET_BLOCK_EVALUATION_OK_LAST == prq.eval) |
1634 | { | 1638 | { |
1635 | GNUNET_STATISTICS_update( | 1639 | GNUNET_STATISTICS_update ( |
1636 | GSF_stats, | 1640 | GSF_stats, |
1637 | gettext_noop("# Datastore lookups concluded (found last result)"), | 1641 | gettext_noop ("# Datastore lookups concluded (found last result)"), |
1638 | 1, | 1642 | 1, |
1639 | GNUNET_NO); | 1643 | GNUNET_NO); |
1640 | call_continuation(pr); | 1644 | call_continuation (pr); |
1641 | return; | 1645 | return; |
1642 | } | 1646 | } |
1643 | if ((0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) && | 1647 | if ((0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) && |
1644 | ((GNUNET_YES == GSF_test_get_load_too_high_(0)) || | 1648 | ((GNUNET_YES == GSF_test_get_load_too_high_ (0)) || |
1645 | (pr->public_data.results_found > 5 + 2 * pr->public_data.priority))) | 1649 | (pr->public_data.results_found > 5 + 2 * pr->public_data.priority))) |
1646 | { | 1650 | { |
1647 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load too high, done with request\n"); | 1651 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load too high, done with request\n"); |
1648 | GNUNET_STATISTICS_update(GSF_stats, | 1652 | GNUNET_STATISTICS_update (GSF_stats, |
1649 | gettext_noop( | 1653 | gettext_noop ( |
1650 | "# Datastore lookups concluded (load too high)"), | 1654 | "# Datastore lookups concluded (load too high)"), |
1651 | 1, | 1655 | 1, |
1652 | GNUNET_NO); | 1656 | GNUNET_NO); |
1653 | call_continuation(pr); | 1657 | call_continuation (pr); |
1654 | return; | 1658 | return; |
1655 | } | 1659 | } |
1656 | start_local_query(pr, uid + 1 /* next_uid */, false /* random */); | 1660 | start_local_query (pr, uid + 1 /* next_uid */, false /* random */); |
1657 | } | 1661 | } |
1658 | 1662 | ||
1659 | 1663 | ||
@@ -1665,15 +1669,15 @@ called_from_on_demand: | |||
1665 | * @return #GNUNET_YES if this request could be forwarded to the given peer | 1669 | * @return #GNUNET_YES if this request could be forwarded to the given peer |
1666 | */ | 1670 | */ |
1667 | int | 1671 | int |
1668 | GSF_pending_request_test_target_(struct GSF_PendingRequest *pr, | 1672 | GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, |
1669 | const struct GNUNET_PeerIdentity *target) | 1673 | const struct GNUNET_PeerIdentity *target) |
1670 | { | 1674 | { |
1671 | struct GNUNET_PeerIdentity pi; | 1675 | struct GNUNET_PeerIdentity pi; |
1672 | 1676 | ||
1673 | if (0 == pr->origin_pid) | 1677 | if (0 == pr->origin_pid) |
1674 | return GNUNET_YES; | 1678 | return GNUNET_YES; |
1675 | GNUNET_PEER_resolve(pr->origin_pid, &pi); | 1679 | GNUNET_PEER_resolve (pr->origin_pid, &pi); |
1676 | return (0 == memcmp(&pi, target, sizeof(struct GNUNET_PeerIdentity))) | 1680 | return (0 == memcmp (&pi, target, sizeof(struct GNUNET_PeerIdentity))) |
1677 | ? GNUNET_NO | 1681 | ? GNUNET_NO |
1678 | : GNUNET_YES; | 1682 | : GNUNET_YES; |
1679 | } | 1683 | } |
@@ -1687,22 +1691,22 @@ GSF_pending_request_test_target_(struct GSF_PendingRequest *pr, | |||
1687 | * @param cont_cls closure for @a cont | 1691 | * @param cont_cls closure for @a cont |
1688 | */ | 1692 | */ |
1689 | void | 1693 | void |
1690 | GSF_local_lookup_(struct GSF_PendingRequest *pr, | 1694 | GSF_local_lookup_ (struct GSF_PendingRequest *pr, |
1691 | GSF_LocalLookupContinuation cont, | 1695 | GSF_LocalLookupContinuation cont, |
1692 | void *cont_cls) | 1696 | void *cont_cls) |
1693 | { | 1697 | { |
1694 | GNUNET_assert(NULL == pr->gh); | 1698 | GNUNET_assert (NULL == pr->gh); |
1695 | GNUNET_assert(NULL == pr->cadet_request); | 1699 | GNUNET_assert (NULL == pr->cadet_request); |
1696 | GNUNET_assert(NULL == pr->llc_cont); | 1700 | GNUNET_assert (NULL == pr->llc_cont); |
1697 | pr->llc_cont = cont; | 1701 | pr->llc_cont = cont; |
1698 | pr->llc_cont_cls = cont_cls; | 1702 | pr->llc_cont_cls = cont_cls; |
1699 | #if INSANE_STATISTICS | 1703 | #if INSANE_STATISTICS |
1700 | GNUNET_STATISTICS_update(GSF_stats, | 1704 | GNUNET_STATISTICS_update (GSF_stats, |
1701 | gettext_noop("# Datastore lookups initiated"), | 1705 | gettext_noop ("# Datastore lookups initiated"), |
1702 | 1, | 1706 | 1, |
1703 | GNUNET_NO); | 1707 | GNUNET_NO); |
1704 | #endif | 1708 | #endif |
1705 | start_local_query(pr, 0 /* next_uid */, true /* random */); | 1709 | start_local_query (pr, 0 /* next_uid */, true /* random */); |
1706 | } | 1710 | } |
1707 | 1711 | ||
1708 | 1712 | ||
@@ -1716,7 +1720,7 @@ GSF_local_lookup_(struct GSF_PendingRequest *pr, | |||
1716 | * @param put the actual message | 1720 | * @param put the actual message |
1717 | */ | 1721 | */ |
1718 | void | 1722 | void |
1719 | handle_p2p_put(void *cls, const struct PutMessage *put) | 1723 | handle_p2p_put (void *cls, const struct PutMessage *put) |
1720 | { | 1724 | { |
1721 | struct GSF_ConnectedPeer *cp = cls; | 1725 | struct GSF_ConnectedPeer *cp = cls; |
1722 | uint16_t msize; | 1726 | uint16_t msize; |
@@ -1729,30 +1733,30 @@ handle_p2p_put(void *cls, const struct PutMessage *put) | |||
1729 | double putl; | 1733 | double putl; |
1730 | struct PutMigrationContext *pmc; | 1734 | struct PutMigrationContext *pmc; |
1731 | 1735 | ||
1732 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1733 | "Received P2P PUT from %s\n", | 1737 | "Received P2P PUT from %s\n", |
1734 | GNUNET_i2s(GSF_get_peer_performance_data_(cp)->peer)); | 1738 | GNUNET_i2s (GSF_get_peer_performance_data_ (cp)->peer)); |
1735 | GSF_cover_content_count++; | 1739 | GSF_cover_content_count++; |
1736 | msize = ntohs(put->header.size); | 1740 | msize = ntohs (put->header.size); |
1737 | dsize = msize - sizeof(struct PutMessage); | 1741 | dsize = msize - sizeof(struct PutMessage); |
1738 | type = ntohl(put->type); | 1742 | type = ntohl (put->type); |
1739 | expiration = GNUNET_TIME_absolute_ntoh(put->expiration); | 1743 | expiration = GNUNET_TIME_absolute_ntoh (put->expiration); |
1740 | /* do not allow migrated content to live longer than 1 year */ | 1744 | /* do not allow migrated content to live longer than 1 year */ |
1741 | expiration = GNUNET_TIME_absolute_min(GNUNET_TIME_relative_to_absolute( | 1745 | expiration = GNUNET_TIME_absolute_min (GNUNET_TIME_relative_to_absolute ( |
1742 | GNUNET_TIME_UNIT_YEARS), | 1746 | GNUNET_TIME_UNIT_YEARS), |
1743 | expiration); | 1747 | expiration); |
1744 | if (GNUNET_OK != | 1748 | if (GNUNET_OK != |
1745 | GNUNET_BLOCK_get_key(GSF_block_ctx, type, &put[1], dsize, &query)) | 1749 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, &put[1], dsize, &query)) |
1746 | { | 1750 | { |
1747 | GNUNET_break_op(0); | 1751 | GNUNET_break_op (0); |
1748 | return; | 1752 | return; |
1749 | } | 1753 | } |
1750 | GNUNET_STATISTICS_update(GSF_stats, | 1754 | GNUNET_STATISTICS_update (GSF_stats, |
1751 | gettext_noop("# GAP PUT messages received"), | 1755 | gettext_noop ("# GAP PUT messages received"), |
1752 | 1, | 1756 | 1, |
1753 | GNUNET_NO); | 1757 | GNUNET_NO); |
1754 | /* now, lookup 'query' */ | 1758 | /* now, lookup 'query' */ |
1755 | prq.data = (const void *)&put[1]; | 1759 | prq.data = (const void *) &put[1]; |
1756 | prq.sender = cp; | 1760 | prq.sender = cp; |
1757 | prq.size = dsize; | 1761 | prq.size = dsize; |
1758 | prq.type = type; | 1762 | prq.type = type; |
@@ -1761,80 +1765,80 @@ handle_p2p_put(void *cls, const struct PutMessage *put) | |||
1761 | prq.anonymity_level = UINT32_MAX; | 1765 | prq.anonymity_level = UINT32_MAX; |
1762 | prq.request_found = GNUNET_NO; | 1766 | prq.request_found = GNUNET_NO; |
1763 | prq.eo = GNUNET_BLOCK_EO_NONE; | 1767 | prq.eo = GNUNET_BLOCK_EO_NONE; |
1764 | GNUNET_CONTAINER_multihashmap_get_multiple(pr_map, | 1768 | GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, |
1765 | &query, | 1769 | &query, |
1766 | &process_reply, | 1770 | &process_reply, |
1767 | &prq); | 1771 | &prq); |
1768 | if (NULL != cp) | 1772 | if (NULL != cp) |
1769 | { | 1773 | { |
1770 | GSF_connected_peer_change_preference_(cp, | 1774 | GSF_connected_peer_change_preference_ (cp, |
1771 | CONTENT_BANDWIDTH_VALUE + | 1775 | CONTENT_BANDWIDTH_VALUE |
1772 | 1000 * prq.priority); | 1776 | + 1000 * prq.priority); |
1773 | GSF_get_peer_performance_data_(cp)->respect += prq.priority; | 1777 | GSF_get_peer_performance_data_ (cp)->respect += prq.priority; |
1774 | } | 1778 | } |
1775 | if ((GNUNET_YES == active_to_migration) && (NULL != cp) && | 1779 | if ((GNUNET_YES == active_to_migration) && (NULL != cp) && |
1776 | (GNUNET_NO == test_put_load_too_high(prq.priority))) | 1780 | (GNUNET_NO == test_put_load_too_high (prq.priority))) |
1781 | { | ||
1782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1783 | "Replicating result for query `%s' with priority %u\n", | ||
1784 | GNUNET_h2s (&query), | ||
1785 | prq.priority); | ||
1786 | pmc = GNUNET_new (struct PutMigrationContext); | ||
1787 | pmc->start = GNUNET_TIME_absolute_get (); | ||
1788 | pmc->requested = prq.request_found; | ||
1789 | GNUNET_assert (0 != GSF_get_peer_performance_data_ (cp)->pid); | ||
1790 | GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid, | ||
1791 | &pmc->origin); | ||
1792 | if (NULL == GNUNET_DATASTORE_put (GSF_dsh, | ||
1793 | 0, | ||
1794 | &query, | ||
1795 | dsize, | ||
1796 | &put[1], | ||
1797 | type, | ||
1798 | prq.priority, | ||
1799 | 1 /* anonymity */, | ||
1800 | 0 /* replication */, | ||
1801 | expiration, | ||
1802 | 1 + prq.priority, | ||
1803 | MAX_DATASTORE_QUEUE, | ||
1804 | &put_migration_continuation, | ||
1805 | pmc)) | ||
1777 | { | 1806 | { |
1778 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1807 | put_migration_continuation (pmc, |
1779 | "Replicating result for query `%s' with priority %u\n", | 1808 | GNUNET_SYSERR, |
1780 | GNUNET_h2s(&query), | 1809 | GNUNET_TIME_UNIT_ZERO_ABS, |
1781 | prq.priority); | 1810 | NULL); |
1782 | pmc = GNUNET_new(struct PutMigrationContext); | ||
1783 | pmc->start = GNUNET_TIME_absolute_get(); | ||
1784 | pmc->requested = prq.request_found; | ||
1785 | GNUNET_assert(0 != GSF_get_peer_performance_data_(cp)->pid); | ||
1786 | GNUNET_PEER_resolve(GSF_get_peer_performance_data_(cp)->pid, | ||
1787 | &pmc->origin); | ||
1788 | if (NULL == GNUNET_DATASTORE_put(GSF_dsh, | ||
1789 | 0, | ||
1790 | &query, | ||
1791 | dsize, | ||
1792 | &put[1], | ||
1793 | type, | ||
1794 | prq.priority, | ||
1795 | 1 /* anonymity */, | ||
1796 | 0 /* replication */, | ||
1797 | expiration, | ||
1798 | 1 + prq.priority, | ||
1799 | MAX_DATASTORE_QUEUE, | ||
1800 | &put_migration_continuation, | ||
1801 | pmc)) | ||
1802 | { | ||
1803 | put_migration_continuation(pmc, | ||
1804 | GNUNET_SYSERR, | ||
1805 | GNUNET_TIME_UNIT_ZERO_ABS, | ||
1806 | NULL); | ||
1807 | } | ||
1808 | } | 1811 | } |
1812 | } | ||
1809 | else if (NULL != cp) | 1813 | else if (NULL != cp) |
1810 | { | 1814 | { |
1811 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1812 | "Choosing not to keep content `%s' (%d/%d)\n", | 1816 | "Choosing not to keep content `%s' (%d/%d)\n", |
1813 | GNUNET_h2s(&query), | 1817 | GNUNET_h2s (&query), |
1814 | active_to_migration, | 1818 | active_to_migration, |
1815 | test_put_load_too_high(prq.priority)); | 1819 | test_put_load_too_high (prq.priority)); |
1816 | } | 1820 | } |
1817 | putl = GNUNET_LOAD_get_load(datastore_put_load); | 1821 | putl = GNUNET_LOAD_get_load (datastore_put_load); |
1818 | if ((NULL != cp) && (GNUNET_NO == prq.request_found) && | 1822 | if ((NULL != cp) && (GNUNET_NO == prq.request_found) && |
1819 | ((GNUNET_YES != active_to_migration) || | 1823 | ((GNUNET_YES != active_to_migration) || |
1820 | (putl > 2.5 * (1 + prq.priority)))) | 1824 | (putl > 2.5 * (1 + prq.priority)))) |
1821 | { | 1825 | { |
1822 | if (GNUNET_YES != active_to_migration) | 1826 | if (GNUNET_YES != active_to_migration) |
1823 | putl = 1.0 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 5); | 1827 | putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5); |
1824 | block_time = GNUNET_TIME_relative_multiply( | 1828 | block_time = GNUNET_TIME_relative_multiply ( |
1825 | GNUNET_TIME_UNIT_MILLISECONDS, | 1829 | GNUNET_TIME_UNIT_MILLISECONDS, |
1826 | 5000 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1830 | 5000 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1827 | (unsigned int)(60000 * putl * putl))); | 1831 | (unsigned int) (60000 * putl * putl))); |
1828 | GNUNET_log( | 1832 | GNUNET_log ( |
1829 | GNUNET_ERROR_TYPE_DEBUG, | 1833 | GNUNET_ERROR_TYPE_DEBUG, |
1830 | "Asking to stop migration for %s because of load %f and events %d/%d\n", | 1834 | "Asking to stop migration for %s because of load %f and events %d/%d\n", |
1831 | GNUNET_STRINGS_relative_time_to_string(block_time, GNUNET_YES), | 1835 | GNUNET_STRINGS_relative_time_to_string (block_time, GNUNET_YES), |
1832 | putl, | 1836 | putl, |
1833 | active_to_migration, | 1837 | active_to_migration, |
1834 | (GNUNET_NO == prq.request_found)); | 1838 | (GNUNET_NO == prq.request_found)); |
1835 | GSF_block_peer_migration_(cp, | 1839 | GSF_block_peer_migration_ (cp, |
1836 | GNUNET_TIME_relative_to_absolute(block_time)); | 1840 | GNUNET_TIME_relative_to_absolute (block_time)); |
1837 | } | 1841 | } |
1838 | } | 1842 | } |
1839 | 1843 | ||
1840 | 1844 | ||
@@ -1845,7 +1849,7 @@ handle_p2p_put(void *cls, const struct PutMessage *put) | |||
1845 | * @return #GNUNET_YES if the request is still active | 1849 | * @return #GNUNET_YES if the request is still active |
1846 | */ | 1850 | */ |
1847 | int | 1851 | int |
1848 | GSF_pending_request_test_active_(struct GSF_PendingRequest *pr) | 1852 | GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr) |
1849 | { | 1853 | { |
1850 | return (NULL != pr->rh) ? GNUNET_YES : GNUNET_NO; | 1854 | return (NULL != pr->rh) ? GNUNET_YES : GNUNET_NO; |
1851 | } | 1855 | } |
@@ -1855,24 +1859,24 @@ GSF_pending_request_test_active_(struct GSF_PendingRequest *pr) | |||
1855 | * Setup the subsystem. | 1859 | * Setup the subsystem. |
1856 | */ | 1860 | */ |
1857 | void | 1861 | void |
1858 | GSF_pending_request_init_() | 1862 | GSF_pending_request_init_ () |
1859 | { | 1863 | { |
1860 | if (GNUNET_OK != | 1864 | if (GNUNET_OK != |
1861 | GNUNET_CONFIGURATION_get_value_number(GSF_cfg, | 1865 | GNUNET_CONFIGURATION_get_value_number (GSF_cfg, |
1862 | "fs", | 1866 | "fs", |
1863 | "MAX_PENDING_REQUESTS", | 1867 | "MAX_PENDING_REQUESTS", |
1864 | &max_pending_requests)) | 1868 | &max_pending_requests)) |
1865 | { | 1869 | { |
1866 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_INFO, | 1870 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO, |
1867 | "fs", | 1871 | "fs", |
1868 | "MAX_PENDING_REQUESTS"); | 1872 | "MAX_PENDING_REQUESTS"); |
1869 | } | 1873 | } |
1870 | active_to_migration = | 1874 | active_to_migration = |
1871 | GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg, "FS", "CONTENT_CACHING"); | 1875 | GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING"); |
1872 | datastore_put_load = GNUNET_LOAD_value_init(DATASTORE_LOAD_AUTODECLINE); | 1876 | datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); |
1873 | pr_map = GNUNET_CONTAINER_multihashmap_create(32 * 1024, GNUNET_YES); | 1877 | pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024, GNUNET_YES); |
1874 | requests_by_expiration_heap = | 1878 | requests_by_expiration_heap = |
1875 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1879 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1876 | } | 1880 | } |
1877 | 1881 | ||
1878 | 1882 | ||
@@ -1880,14 +1884,14 @@ GSF_pending_request_init_() | |||
1880 | * Shutdown the subsystem. | 1884 | * Shutdown the subsystem. |
1881 | */ | 1885 | */ |
1882 | void | 1886 | void |
1883 | GSF_pending_request_done_() | 1887 | GSF_pending_request_done_ () |
1884 | { | 1888 | { |
1885 | GNUNET_CONTAINER_multihashmap_iterate(pr_map, &clean_request, NULL); | 1889 | GNUNET_CONTAINER_multihashmap_iterate (pr_map, &clean_request, NULL); |
1886 | GNUNET_CONTAINER_multihashmap_destroy(pr_map); | 1890 | GNUNET_CONTAINER_multihashmap_destroy (pr_map); |
1887 | pr_map = NULL; | 1891 | pr_map = NULL; |
1888 | GNUNET_CONTAINER_heap_destroy(requests_by_expiration_heap); | 1892 | GNUNET_CONTAINER_heap_destroy (requests_by_expiration_heap); |
1889 | requests_by_expiration_heap = NULL; | 1893 | requests_by_expiration_heap = NULL; |
1890 | GNUNET_LOAD_value_free(datastore_put_load); | 1894 | GNUNET_LOAD_value_free (datastore_put_load); |
1891 | datastore_put_load = NULL; | 1895 | datastore_put_load = NULL; |
1892 | } | 1896 | } |
1893 | 1897 | ||
diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h index 39e471c4d..f22f85ee0 100644 --- a/src/fs/gnunet-service-fs_pr.h +++ b/src/fs/gnunet-service-fs_pr.h | |||
@@ -32,7 +32,8 @@ | |||
32 | /** | 32 | /** |
33 | * Options for pending requests (bits to be ORed). | 33 | * Options for pending requests (bits to be ORed). |
34 | */ | 34 | */ |
35 | enum GSF_PendingRequestOptions { | 35 | enum GSF_PendingRequestOptions |
36 | { | ||
36 | /** | 37 | /** |
37 | * No special options (P2P-default). | 38 | * No special options (P2P-default). |
38 | */ | 39 | */ |
@@ -67,7 +68,8 @@ enum GSF_PendingRequestOptions { | |||
67 | * Option mask for typical local requests. | 68 | * Option mask for typical local requests. |
68 | */ | 69 | */ |
69 | GSF_PRO_LOCAL_REQUEST = | 70 | GSF_PRO_LOCAL_REQUEST = |
70 | (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED | GSF_PRO_REQUEST_NEVER_EXPIRES) | 71 | (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED |
72 | | GSF_PRO_REQUEST_NEVER_EXPIRES) | ||
71 | }; | 73 | }; |
72 | 74 | ||
73 | 75 | ||
@@ -76,7 +78,8 @@ enum GSF_PendingRequestOptions { | |||
76 | * 'gnunet-service-fs_pr', not in the sense of network-wide | 78 | * 'gnunet-service-fs_pr', not in the sense of network-wide |
77 | * known) associated with each pending request. | 79 | * known) associated with each pending request. |
78 | */ | 80 | */ |
79 | struct GSF_PendingRequestData { | 81 | struct GSF_PendingRequestData |
82 | { | ||
80 | /** | 83 | /** |
81 | * Primary query hash for this request. | 84 | * Primary query hash for this request. |
82 | */ | 85 | */ |
@@ -186,7 +189,8 @@ typedef void | |||
186 | struct GSF_PendingRequest *pr, | 189 | struct GSF_PendingRequest *pr, |
187 | uint32_t reply_anonymity_level, | 190 | uint32_t reply_anonymity_level, |
188 | struct GNUNET_TIME_Absolute expiration, | 191 | struct GNUNET_TIME_Absolute expiration, |
189 | struct GNUNET_TIME_Absolute last_transmission, | 192 | struct GNUNET_TIME_Absolute |
193 | last_transmission, | ||
190 | enum GNUNET_BLOCK_Type type, | 194 | enum GNUNET_BLOCK_Type type, |
191 | const void *data, | 195 | const void *data, |
192 | size_t data_len); | 196 | size_t data_len); |
@@ -215,22 +219,22 @@ typedef void | |||
215 | * @return handle for the new pending request | 219 | * @return handle for the new pending request |
216 | */ | 220 | */ |
217 | struct GSF_PendingRequest * | 221 | struct GSF_PendingRequest * |
218 | GSF_pending_request_create_(enum GSF_PendingRequestOptions options, | 222 | GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, |
219 | enum GNUNET_BLOCK_Type type, | 223 | enum GNUNET_BLOCK_Type type, |
220 | const struct GNUNET_HashCode *query, | 224 | const struct GNUNET_HashCode *query, |
221 | const struct GNUNET_PeerIdentity *target, | 225 | const struct GNUNET_PeerIdentity *target, |
222 | const char *bf_data, | 226 | const char *bf_data, |
223 | size_t bf_size, | 227 | size_t bf_size, |
224 | uint32_t mingle, | 228 | uint32_t mingle, |
225 | uint32_t anonymity_level, | 229 | uint32_t anonymity_level, |
226 | uint32_t priority, | 230 | uint32_t priority, |
227 | int32_t ttl, | 231 | int32_t ttl, |
228 | GNUNET_PEER_Id sender_pid, | 232 | GNUNET_PEER_Id sender_pid, |
229 | GNUNET_PEER_Id origin_pid, | 233 | GNUNET_PEER_Id origin_pid, |
230 | const struct GNUNET_HashCode *replies_seen, | 234 | const struct GNUNET_HashCode *replies_seen, |
231 | unsigned int replies_seen_count, | 235 | unsigned int replies_seen_count, |
232 | GSF_PendingRequestReplyHandler rh, | 236 | GSF_PendingRequestReplyHandler rh, |
233 | void *rh_cls); | 237 | void *rh_cls); |
234 | 238 | ||
235 | 239 | ||
236 | /** | 240 | /** |
@@ -242,9 +246,9 @@ GSF_pending_request_create_(enum GSF_PendingRequestOptions options, | |||
242 | * @param replies_seen_count size of the @a replies_seen array | 246 | * @param replies_seen_count size of the @a replies_seen array |
243 | */ | 247 | */ |
244 | void | 248 | void |
245 | GSF_pending_request_update_(struct GSF_PendingRequest *pr, | 249 | GSF_pending_request_update_ (struct GSF_PendingRequest *pr, |
246 | const struct GNUNET_HashCode *replies_seen, | 250 | const struct GNUNET_HashCode *replies_seen, |
247 | unsigned int replies_seen_count); | 251 | unsigned int replies_seen_count); |
248 | 252 | ||
249 | 253 | ||
250 | /** | 254 | /** |
@@ -254,7 +258,7 @@ GSF_pending_request_update_(struct GSF_PendingRequest *pr, | |||
254 | * @return associated public data | 258 | * @return associated public data |
255 | */ | 259 | */ |
256 | struct GSF_PendingRequestData * | 260 | struct GSF_PendingRequestData * |
257 | GSF_pending_request_get_data_(struct GSF_PendingRequest *pr); | 261 | GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr); |
258 | 262 | ||
259 | 263 | ||
260 | /** | 264 | /** |
@@ -264,7 +268,7 @@ GSF_pending_request_get_data_(struct GSF_PendingRequest *pr); | |||
264 | * @return #GNUNET_YES if the request is still active | 268 | * @return #GNUNET_YES if the request is still active |
265 | */ | 269 | */ |
266 | int | 270 | int |
267 | GSF_pending_request_test_active_(struct GSF_PendingRequest *pr); | 271 | GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr); |
268 | 272 | ||
269 | 273 | ||
270 | /** | 274 | /** |
@@ -277,8 +281,8 @@ GSF_pending_request_test_active_(struct GSF_PendingRequest *pr); | |||
277 | * @return #GNUNET_OK if the requests are compatible | 281 | * @return #GNUNET_OK if the requests are compatible |
278 | */ | 282 | */ |
279 | int | 283 | int |
280 | GSF_pending_request_is_compatible_(struct GSF_PendingRequest *pra, | 284 | GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, |
281 | struct GSF_PendingRequest *prb); | 285 | struct GSF_PendingRequest *prb); |
282 | 286 | ||
283 | 287 | ||
284 | /** | 288 | /** |
@@ -289,7 +293,7 @@ GSF_pending_request_is_compatible_(struct GSF_PendingRequest *pra, | |||
289 | * @return envelope with the request message | 293 | * @return envelope with the request message |
290 | */ | 294 | */ |
291 | struct GNUNET_MQ_Envelope * | 295 | struct GNUNET_MQ_Envelope * |
292 | GSF_pending_request_get_message_(struct GSF_PendingRequest *pr); | 296 | GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr); |
293 | 297 | ||
294 | 298 | ||
295 | /** | 299 | /** |
@@ -299,8 +303,8 @@ GSF_pending_request_get_message_(struct GSF_PendingRequest *pr); | |||
299 | * @param full_cleanup fully purge the request | 303 | * @param full_cleanup fully purge the request |
300 | */ | 304 | */ |
301 | void | 305 | void |
302 | GSF_pending_request_cancel_(struct GSF_PendingRequest *pr, | 306 | GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, |
303 | int full_cleanup); | 307 | int full_cleanup); |
304 | 308 | ||
305 | 309 | ||
306 | /** | 310 | /** |
@@ -325,8 +329,8 @@ typedef int | |||
325 | * @param cls closure for it | 329 | * @param cls closure for it |
326 | */ | 330 | */ |
327 | void | 331 | void |
328 | GSF_iterate_pending_requests_(GSF_PendingRequestIterator it, | 332 | GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, |
329 | void *cls); | 333 | void *cls); |
330 | 334 | ||
331 | 335 | ||
332 | /** | 336 | /** |
@@ -339,8 +343,8 @@ GSF_iterate_pending_requests_(GSF_PendingRequestIterator it, | |||
339 | * @param put the actual message | 343 | * @param put the actual message |
340 | */ | 344 | */ |
341 | void | 345 | void |
342 | handle_p2p_put(void *cls, | 346 | handle_p2p_put (void *cls, |
343 | const struct PutMessage *put); | 347 | const struct PutMessage *put); |
344 | 348 | ||
345 | 349 | ||
346 | /** | 350 | /** |
@@ -349,7 +353,7 @@ handle_p2p_put(void *cls, | |||
349 | * @param pr the pending request to process | 353 | * @param pr the pending request to process |
350 | */ | 354 | */ |
351 | void | 355 | void |
352 | GSF_dht_lookup_(struct GSF_PendingRequest *pr); | 356 | GSF_dht_lookup_ (struct GSF_PendingRequest *pr); |
353 | 357 | ||
354 | 358 | ||
355 | /** | 359 | /** |
@@ -358,7 +362,7 @@ GSF_dht_lookup_(struct GSF_PendingRequest *pr); | |||
358 | * @param pr the pending request to process | 362 | * @param pr the pending request to process |
359 | */ | 363 | */ |
360 | void | 364 | void |
361 | GSF_cadet_lookup_(struct GSF_PendingRequest *pr); | 365 | GSF_cadet_lookup_ (struct GSF_PendingRequest *pr); |
362 | 366 | ||
363 | 367 | ||
364 | /** | 368 | /** |
@@ -383,9 +387,9 @@ typedef void | |||
383 | * @param cont_cls closure for @a cont | 387 | * @param cont_cls closure for @a cont |
384 | */ | 388 | */ |
385 | void | 389 | void |
386 | GSF_local_lookup_(struct GSF_PendingRequest *pr, | 390 | GSF_local_lookup_ (struct GSF_PendingRequest *pr, |
387 | GSF_LocalLookupContinuation cont, | 391 | GSF_LocalLookupContinuation cont, |
388 | void *cont_cls); | 392 | void *cont_cls); |
389 | 393 | ||
390 | 394 | ||
391 | /** | 395 | /** |
@@ -396,8 +400,8 @@ GSF_local_lookup_(struct GSF_PendingRequest *pr, | |||
396 | * @return #GNUNET_YES if this request could be forwarded to the given peer | 400 | * @return #GNUNET_YES if this request could be forwarded to the given peer |
397 | */ | 401 | */ |
398 | int | 402 | int |
399 | GSF_pending_request_test_target_(struct GSF_PendingRequest *pr, | 403 | GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, |
400 | const struct GNUNET_PeerIdentity *target); | 404 | const struct GNUNET_PeerIdentity *target); |
401 | 405 | ||
402 | 406 | ||
403 | 407 | ||
@@ -405,14 +409,14 @@ GSF_pending_request_test_target_(struct GSF_PendingRequest *pr, | |||
405 | * Setup the subsystem. | 409 | * Setup the subsystem. |
406 | */ | 410 | */ |
407 | void | 411 | void |
408 | GSF_pending_request_init_(void); | 412 | GSF_pending_request_init_ (void); |
409 | 413 | ||
410 | 414 | ||
411 | /** | 415 | /** |
412 | * Shutdown the subsystem. | 416 | * Shutdown the subsystem. |
413 | */ | 417 | */ |
414 | void | 418 | void |
415 | GSF_pending_request_done_(void); | 419 | GSF_pending_request_done_ (void); |
416 | 420 | ||
417 | 421 | ||
418 | #endif | 422 | #endif |
diff --git a/src/fs/gnunet-service-fs_push.c b/src/fs/gnunet-service-fs_push.c index 162dcc0b5..02990a637 100644 --- a/src/fs/gnunet-service-fs_push.c +++ b/src/fs/gnunet-service-fs_push.c | |||
@@ -49,13 +49,15 @@ | |||
49 | * that if this value is increased, the migration testcase may need to be | 49 | * that if this value is increased, the migration testcase may need to be |
50 | * adjusted as well (especially the CONTENT_LIFETIME in fs_test_lib.c). | 50 | * adjusted as well (especially the CONTENT_LIFETIME in fs_test_lib.c). |
51 | */ | 51 | */ |
52 | #define MIN_MIGRATION_CONTENT_LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) | 52 | #define MIN_MIGRATION_CONTENT_LIFETIME GNUNET_TIME_relative_multiply ( \ |
53 | GNUNET_TIME_UNIT_MINUTES, 30) | ||
53 | 54 | ||
54 | 55 | ||
55 | /** | 56 | /** |
56 | * Block that is ready for migration to other peers. Actual data is at the end of the block. | 57 | * Block that is ready for migration to other peers. Actual data is at the end of the block. |
57 | */ | 58 | */ |
58 | struct MigrationReadyBlock { | 59 | struct MigrationReadyBlock |
60 | { | ||
59 | /** | 61 | /** |
60 | * This is a doubly-linked list. | 62 | * This is a doubly-linked list. |
61 | */ | 63 | */ |
@@ -102,7 +104,8 @@ struct MigrationReadyBlock { | |||
102 | /** | 104 | /** |
103 | * Information about a peer waiting for migratable data. | 105 | * Information about a peer waiting for migratable data. |
104 | */ | 106 | */ |
105 | struct MigrationReadyPeer { | 107 | struct MigrationReadyPeer |
108 | { | ||
106 | /** | 109 | /** |
107 | * This is a doubly-linked list. | 110 | * This is a doubly-linked list. |
108 | */ | 111 | */ |
@@ -183,15 +186,15 @@ static int value_found; | |||
183 | * @param mb block to delete | 186 | * @param mb block to delete |
184 | */ | 187 | */ |
185 | static void | 188 | static void |
186 | delete_migration_block(struct MigrationReadyBlock *mb) | 189 | delete_migration_block (struct MigrationReadyBlock *mb) |
187 | { | 190 | { |
188 | GNUNET_CONTAINER_DLL_remove(mig_head, | 191 | GNUNET_CONTAINER_DLL_remove (mig_head, |
189 | mig_tail, | 192 | mig_tail, |
190 | mb); | 193 | mb); |
191 | GNUNET_PEER_decrement_rcs(mb->target_list, | 194 | GNUNET_PEER_decrement_rcs (mb->target_list, |
192 | MIGRATION_LIST_SIZE); | 195 | MIGRATION_LIST_SIZE); |
193 | mig_size--; | 196 | mig_size--; |
194 | GNUNET_free(mb); | 197 | GNUNET_free (mb); |
195 | } | 198 | } |
196 | 199 | ||
197 | 200 | ||
@@ -201,7 +204,7 @@ delete_migration_block(struct MigrationReadyBlock *mb) | |||
201 | * @param cls a `struct MigrationReadyPeer *` | 204 | * @param cls a `struct MigrationReadyPeer *` |
202 | */ | 205 | */ |
203 | static void | 206 | static void |
204 | find_content(void *cls); | 207 | find_content (void *cls); |
205 | 208 | ||
206 | 209 | ||
207 | /** | 210 | /** |
@@ -212,50 +215,50 @@ find_content(void *cls); | |||
212 | * @return #GNUNET_YES if the block was deleted (!) | 215 | * @return #GNUNET_YES if the block was deleted (!) |
213 | */ | 216 | */ |
214 | static int | 217 | static int |
215 | transmit_content(struct MigrationReadyPeer *mrp, | 218 | transmit_content (struct MigrationReadyPeer *mrp, |
216 | struct MigrationReadyBlock *block) | 219 | struct MigrationReadyBlock *block) |
217 | { | 220 | { |
218 | struct PutMessage *msg; | 221 | struct PutMessage *msg; |
219 | unsigned int i; | 222 | unsigned int i; |
220 | struct GSF_PeerPerformanceData *ppd; | 223 | struct GSF_PeerPerformanceData *ppd; |
221 | int ret; | 224 | int ret; |
222 | 225 | ||
223 | ppd = GSF_get_peer_performance_data_(mrp->peer); | 226 | ppd = GSF_get_peer_performance_data_ (mrp->peer); |
224 | GNUNET_assert(NULL == mrp->env); | 227 | GNUNET_assert (NULL == mrp->env); |
225 | mrp->env = GNUNET_MQ_msg_extra(msg, | 228 | mrp->env = GNUNET_MQ_msg_extra (msg, |
226 | block->size, | 229 | block->size, |
227 | GNUNET_MESSAGE_TYPE_FS_PUT); | 230 | GNUNET_MESSAGE_TYPE_FS_PUT); |
228 | msg->type = htonl(block->type); | 231 | msg->type = htonl (block->type); |
229 | msg->expiration = GNUNET_TIME_absolute_hton(block->expiration); | 232 | msg->expiration = GNUNET_TIME_absolute_hton (block->expiration); |
230 | GNUNET_memcpy(&msg[1], | 233 | GNUNET_memcpy (&msg[1], |
231 | &block[1], | 234 | &block[1], |
232 | block->size); | 235 | block->size); |
233 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) | 236 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) |
237 | { | ||
238 | if (block->target_list[i] == 0) | ||
234 | { | 239 | { |
235 | if (block->target_list[i] == 0) | 240 | block->target_list[i] = ppd->pid; |
236 | { | 241 | GNUNET_PEER_change_rc (block->target_list[i], |
237 | block->target_list[i] = ppd->pid; | 242 | 1); |
238 | GNUNET_PEER_change_rc(block->target_list[i], | 243 | break; |
239 | 1); | ||
240 | break; | ||
241 | } | ||
242 | } | 244 | } |
245 | } | ||
243 | if (MIGRATION_LIST_SIZE == i) | 246 | if (MIGRATION_LIST_SIZE == i) |
244 | { | 247 | { |
245 | delete_migration_block(block); | 248 | delete_migration_block (block); |
246 | ret = GNUNET_YES; | 249 | ret = GNUNET_YES; |
247 | } | 250 | } |
248 | else | 251 | else |
249 | { | 252 | { |
250 | ret = GNUNET_NO; | 253 | ret = GNUNET_NO; |
251 | } | 254 | } |
252 | GNUNET_MQ_notify_sent(mrp->env, | 255 | GNUNET_MQ_notify_sent (mrp->env, |
253 | &find_content, | 256 | &find_content, |
254 | mrp); | 257 | mrp); |
255 | GSF_peer_transmit_(mrp->peer, | 258 | GSF_peer_transmit_ (mrp->peer, |
256 | GNUNET_NO, | 259 | GNUNET_NO, |
257 | 0 /* priority */, | 260 | 0 /* priority */, |
258 | mrp->env); | 261 | mrp->env); |
259 | return ret; | 262 | return ret; |
260 | } | 263 | } |
261 | 264 | ||
@@ -268,7 +271,7 @@ transmit_content(struct MigrationReadyPeer *mrp, | |||
268 | * @return number of times block was forwarded | 271 | * @return number of times block was forwarded |
269 | */ | 272 | */ |
270 | static unsigned int | 273 | static unsigned int |
271 | count_targets(struct MigrationReadyBlock *block) | 274 | count_targets (struct MigrationReadyBlock *block) |
272 | { | 275 | { |
273 | unsigned int i; | 276 | unsigned int i; |
274 | 277 | ||
@@ -288,8 +291,8 @@ count_targets(struct MigrationReadyBlock *block) | |||
288 | * @return score (>= 0: feasible, negative: infeasible) | 291 | * @return score (>= 0: feasible, negative: infeasible) |
289 | */ | 292 | */ |
290 | static long | 293 | static long |
291 | score_content(struct MigrationReadyPeer *mrp, | 294 | score_content (struct MigrationReadyPeer *mrp, |
292 | struct MigrationReadyBlock *block) | 295 | struct MigrationReadyBlock *block) |
293 | { | 296 | { |
294 | unsigned int i; | 297 | unsigned int i; |
295 | struct GSF_PeerPerformanceData *ppd; | 298 | struct GSF_PeerPerformanceData *ppd; |
@@ -297,18 +300,18 @@ score_content(struct MigrationReadyPeer *mrp, | |||
297 | struct GNUNET_HashCode hc; | 300 | struct GNUNET_HashCode hc; |
298 | uint32_t dist; | 301 | uint32_t dist; |
299 | 302 | ||
300 | ppd = GSF_get_peer_performance_data_(mrp->peer); | 303 | ppd = GSF_get_peer_performance_data_ (mrp->peer); |
301 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) | 304 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) |
302 | if (block->target_list[i] == ppd->pid) | 305 | if (block->target_list[i] == ppd->pid) |
303 | return -1; | 306 | return -1; |
304 | GNUNET_assert(0 != ppd->pid); | 307 | GNUNET_assert (0 != ppd->pid); |
305 | GNUNET_PEER_resolve(ppd->pid, | 308 | GNUNET_PEER_resolve (ppd->pid, |
306 | &id); | 309 | &id); |
307 | GNUNET_CRYPTO_hash(&id, | 310 | GNUNET_CRYPTO_hash (&id, |
308 | sizeof(struct GNUNET_PeerIdentity), | 311 | sizeof(struct GNUNET_PeerIdentity), |
309 | &hc); | 312 | &hc); |
310 | dist = GNUNET_CRYPTO_hash_distance_u32(&block->query, | 313 | dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query, |
311 | &hc); | 314 | &hc); |
312 | /* closer distance, higher score: */ | 315 | /* closer distance, higher score: */ |
313 | return UINT32_MAX - dist; | 316 | return UINT32_MAX - dist; |
314 | } | 317 | } |
@@ -319,7 +322,7 @@ score_content(struct MigrationReadyPeer *mrp, | |||
319 | * (re)scheduling it with the appropriate delay. | 322 | * (re)scheduling it with the appropriate delay. |
320 | */ | 323 | */ |
321 | static void | 324 | static void |
322 | consider_gathering(void); | 325 | consider_gathering (void); |
323 | 326 | ||
324 | 327 | ||
325 | /** | 328 | /** |
@@ -328,7 +331,7 @@ consider_gathering(void); | |||
328 | * @param cls peer to find content for | 331 | * @param cls peer to find content for |
329 | */ | 332 | */ |
330 | static void | 333 | static void |
331 | find_content(void *cls) | 334 | find_content (void *cls) |
332 | { | 335 | { |
333 | struct MigrationReadyPeer *mrp = cls; | 336 | struct MigrationReadyPeer *mrp = cls; |
334 | struct MigrationReadyBlock *pos; | 337 | struct MigrationReadyBlock *pos; |
@@ -341,48 +344,48 @@ find_content(void *cls) | |||
341 | best_score = -1; | 344 | best_score = -1; |
342 | pos = mig_head; | 345 | pos = mig_head; |
343 | while (NULL != pos) | 346 | while (NULL != pos) |
347 | { | ||
348 | score = score_content (mrp, pos); | ||
349 | if (score > best_score) | ||
344 | { | 350 | { |
345 | score = score_content(mrp, pos); | 351 | best_score = score; |
346 | if (score > best_score) | 352 | best = pos; |
347 | { | ||
348 | best_score = score; | ||
349 | best = pos; | ||
350 | } | ||
351 | pos = pos->next; | ||
352 | } | 353 | } |
354 | pos = pos->next; | ||
355 | } | ||
353 | if (NULL == best) | 356 | if (NULL == best) |
357 | { | ||
358 | if (mig_size < MAX_MIGRATION_QUEUE) | ||
354 | { | 359 | { |
355 | if (mig_size < MAX_MIGRATION_QUEUE) | 360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
356 | { | 361 | "No content found for pushing, waiting for queue to fill\n"); |
357 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 362 | return; /* will fill up eventually... */ |
358 | "No content found for pushing, waiting for queue to fill\n"); | ||
359 | return; /* will fill up eventually... */ | ||
360 | } | ||
361 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
362 | "No suitable content found, purging content from full queue\n"); | ||
363 | /* failed to find migration target AND | ||
364 | * queue is full, purge most-forwarded | ||
365 | * block from queue to make room for more */ | ||
366 | pos = mig_head; | ||
367 | while (NULL != pos) | ||
368 | { | ||
369 | score = count_targets(pos); | ||
370 | if (score >= best_score) | ||
371 | { | ||
372 | best_score = score; | ||
373 | best = pos; | ||
374 | } | ||
375 | pos = pos->next; | ||
376 | } | ||
377 | GNUNET_assert(NULL != best); | ||
378 | delete_migration_block(best); | ||
379 | consider_gathering(); | ||
380 | return; | ||
381 | } | 363 | } |
382 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 364 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
383 | "Preparing to push best content to peer\n"); | 365 | "No suitable content found, purging content from full queue\n"); |
384 | transmit_content(mrp, | 366 | /* failed to find migration target AND |
385 | best); | 367 | * queue is full, purge most-forwarded |
368 | * block from queue to make room for more */ | ||
369 | pos = mig_head; | ||
370 | while (NULL != pos) | ||
371 | { | ||
372 | score = count_targets (pos); | ||
373 | if (score >= best_score) | ||
374 | { | ||
375 | best_score = score; | ||
376 | best = pos; | ||
377 | } | ||
378 | pos = pos->next; | ||
379 | } | ||
380 | GNUNET_assert (NULL != best); | ||
381 | delete_migration_block (best); | ||
382 | consider_gathering (); | ||
383 | return; | ||
384 | } | ||
385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
386 | "Preparing to push best content to peer\n"); | ||
387 | transmit_content (mrp, | ||
388 | best); | ||
386 | } | 389 | } |
387 | 390 | ||
388 | 391 | ||
@@ -393,7 +396,7 @@ find_content(void *cls) | |||
393 | * @param cls unused | 396 | * @param cls unused |
394 | */ | 397 | */ |
395 | static void | 398 | static void |
396 | gather_migration_blocks(void *cls); | 399 | gather_migration_blocks (void *cls); |
397 | 400 | ||
398 | 401 | ||
399 | /** | 402 | /** |
@@ -401,7 +404,7 @@ gather_migration_blocks(void *cls); | |||
401 | * (re)scheduling it with the appropriate delay. | 404 | * (re)scheduling it with the appropriate delay. |
402 | */ | 405 | */ |
403 | static void | 406 | static void |
404 | consider_gathering() | 407 | consider_gathering () |
405 | { | 408 | { |
406 | struct GNUNET_TIME_Relative delay; | 409 | struct GNUNET_TIME_Relative delay; |
407 | 410 | ||
@@ -413,25 +416,26 @@ consider_gathering() | |||
413 | return; | 416 | return; |
414 | if (mig_size >= MAX_MIGRATION_QUEUE) | 417 | if (mig_size >= MAX_MIGRATION_QUEUE) |
415 | return; | 418 | return; |
416 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 419 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
417 | mig_size); | 420 | mig_size); |
418 | delay = GNUNET_TIME_relative_divide(delay, | 421 | delay = GNUNET_TIME_relative_divide (delay, |
419 | MAX_MIGRATION_QUEUE); | 422 | MAX_MIGRATION_QUEUE); |
420 | delay = GNUNET_TIME_relative_max(delay, | 423 | delay = GNUNET_TIME_relative_max (delay, |
421 | min_migration_delay); | 424 | min_migration_delay); |
422 | if (GNUNET_NO == value_found) | 425 | if (GNUNET_NO == value_found) |
423 | { | 426 | { |
424 | /* wait at least 5s if the datastore is empty */ | 427 | /* wait at least 5s if the datastore is empty */ |
425 | delay = GNUNET_TIME_relative_max(delay, | 428 | delay = GNUNET_TIME_relative_max (delay, |
426 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 429 | GNUNET_TIME_relative_multiply ( |
427 | 5)); | 430 | GNUNET_TIME_UNIT_SECONDS, |
428 | } | 431 | 5)); |
429 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 432 | } |
430 | "Scheduling gathering task (queue size: %u)\n", | 433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
431 | mig_size); | 434 | "Scheduling gathering task (queue size: %u)\n", |
432 | mig_task = GNUNET_SCHEDULER_add_delayed(delay, | 435 | mig_size); |
433 | &gather_migration_blocks, | 436 | mig_task = GNUNET_SCHEDULER_add_delayed (delay, |
434 | NULL); | 437 | &gather_migration_blocks, |
438 | NULL); | ||
435 | } | 439 | } |
436 | 440 | ||
437 | 441 | ||
@@ -451,82 +455,82 @@ consider_gathering() | |||
451 | * maybe 0 if no unique identifier is available | 455 | * maybe 0 if no unique identifier is available |
452 | */ | 456 | */ |
453 | static void | 457 | static void |
454 | process_migration_content(void *cls, | 458 | process_migration_content (void *cls, |
455 | const struct GNUNET_HashCode *key, | 459 | const struct GNUNET_HashCode *key, |
456 | size_t size, | 460 | size_t size, |
457 | const void *data, | 461 | const void *data, |
458 | enum GNUNET_BLOCK_Type type, | 462 | enum GNUNET_BLOCK_Type type, |
459 | uint32_t priority, | 463 | uint32_t priority, |
460 | uint32_t anonymity, | 464 | uint32_t anonymity, |
461 | uint32_t replication, | 465 | uint32_t replication, |
462 | struct GNUNET_TIME_Absolute expiration, | 466 | struct GNUNET_TIME_Absolute expiration, |
463 | uint64_t uid) | 467 | uint64_t uid) |
464 | { | 468 | { |
465 | struct MigrationReadyBlock *mb; | 469 | struct MigrationReadyBlock *mb; |
466 | struct MigrationReadyPeer *pos; | 470 | struct MigrationReadyPeer *pos; |
467 | 471 | ||
468 | mig_qe = NULL; | 472 | mig_qe = NULL; |
469 | if (NULL == key) | 473 | if (NULL == key) |
470 | { | 474 | { |
471 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
472 | "No content found for migration...\n"); | 476 | "No content found for migration...\n"); |
473 | consider_gathering(); | 477 | consider_gathering (); |
474 | return; | 478 | return; |
475 | } | 479 | } |
476 | value_found = GNUNET_YES; | 480 | value_found = GNUNET_YES; |
477 | if (GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us < | 481 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us < |
478 | MIN_MIGRATION_CONTENT_LIFETIME.rel_value_us) | 482 | MIN_MIGRATION_CONTENT_LIFETIME.rel_value_us) |
479 | { | 483 | { |
480 | /* content will expire soon, don't bother */ | 484 | /* content will expire soon, don't bother */ |
481 | consider_gathering(); | 485 | consider_gathering (); |
482 | return; | 486 | return; |
483 | } | 487 | } |
484 | if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) | 488 | if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) |
485 | { | 489 | { |
486 | if (GNUNET_OK != | 490 | if (GNUNET_OK != |
487 | GNUNET_FS_handle_on_demand_block(key, | 491 | GNUNET_FS_handle_on_demand_block (key, |
488 | size, | 492 | size, |
489 | data, | 493 | data, |
490 | type, | 494 | type, |
491 | priority, | 495 | priority, |
492 | anonymity, | 496 | anonymity, |
493 | replication, | 497 | replication, |
494 | expiration, | 498 | expiration, |
495 | uid, | 499 | uid, |
496 | &process_migration_content, | 500 | &process_migration_content, |
497 | NULL)) | 501 | NULL)) |
498 | consider_gathering(); | 502 | consider_gathering (); |
499 | return; | 503 | return; |
500 | } | 504 | } |
501 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 505 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
502 | "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", | 506 | "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", |
503 | GNUNET_h2s(key), | 507 | GNUNET_h2s (key), |
504 | type, mig_size + 1, | 508 | type, mig_size + 1, |
505 | MAX_MIGRATION_QUEUE); | 509 | MAX_MIGRATION_QUEUE); |
506 | mb = GNUNET_malloc(sizeof(struct MigrationReadyBlock) + size); | 510 | mb = GNUNET_malloc (sizeof(struct MigrationReadyBlock) + size); |
507 | mb->query = *key; | 511 | mb->query = *key; |
508 | mb->expiration = expiration; | 512 | mb->expiration = expiration; |
509 | mb->size = size; | 513 | mb->size = size; |
510 | mb->type = type; | 514 | mb->type = type; |
511 | GNUNET_memcpy(&mb[1], data, size); | 515 | GNUNET_memcpy (&mb[1], data, size); |
512 | GNUNET_CONTAINER_DLL_insert_after(mig_head, | 516 | GNUNET_CONTAINER_DLL_insert_after (mig_head, |
513 | mig_tail, | 517 | mig_tail, |
514 | mig_tail, | 518 | mig_tail, |
515 | mb); | 519 | mb); |
516 | mig_size++; | 520 | mig_size++; |
517 | for (pos = peer_head; NULL != pos; pos = pos->next) | 521 | for (pos = peer_head; NULL != pos; pos = pos->next) |
522 | { | ||
523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
524 | "Preparing to push best content to peer %s\n", | ||
525 | GNUNET_i2s (GSF_connected_peer_get_identity2_ (pos->peer))); | ||
526 | if ((NULL == pos->env) && | ||
527 | (GNUNET_YES == transmit_content (pos, | ||
528 | mb))) | ||
518 | { | 529 | { |
519 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 530 | break; /* 'mb' was freed! */ |
520 | "Preparing to push best content to peer %s\n", | ||
521 | GNUNET_i2s(GSF_connected_peer_get_identity2_(pos->peer))); | ||
522 | if ((NULL == pos->env) && | ||
523 | (GNUNET_YES == transmit_content(pos, | ||
524 | mb))) | ||
525 | { | ||
526 | break; /* 'mb' was freed! */ | ||
527 | } | ||
528 | } | 531 | } |
529 | consider_gathering(); | 532 | } |
533 | consider_gathering (); | ||
530 | } | 534 | } |
531 | 535 | ||
532 | 536 | ||
@@ -537,24 +541,24 @@ process_migration_content(void *cls, | |||
537 | * @param cls unused | 541 | * @param cls unused |
538 | */ | 542 | */ |
539 | static void | 543 | static void |
540 | gather_migration_blocks(void *cls) | 544 | gather_migration_blocks (void *cls) |
541 | { | 545 | { |
542 | mig_task = NULL; | 546 | mig_task = NULL; |
543 | if (mig_size >= MAX_MIGRATION_QUEUE) | 547 | if (mig_size >= MAX_MIGRATION_QUEUE) |
544 | return; | 548 | return; |
545 | if (NULL == GSF_dsh) | 549 | if (NULL == GSF_dsh) |
546 | return; | 550 | return; |
547 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
548 | "Asking datastore for content for replication (queue size: %u)\n", | 552 | "Asking datastore for content for replication (queue size: %u)\n", |
549 | mig_size); | 553 | mig_size); |
550 | value_found = GNUNET_NO; | 554 | value_found = GNUNET_NO; |
551 | mig_qe = GNUNET_DATASTORE_get_for_replication(GSF_dsh, | 555 | mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh, |
552 | 0, | 556 | 0, |
553 | UINT_MAX, | 557 | UINT_MAX, |
554 | &process_migration_content, | 558 | &process_migration_content, |
555 | NULL); | 559 | NULL); |
556 | if (NULL == mig_qe) | 560 | if (NULL == mig_qe) |
557 | consider_gathering(); | 561 | consider_gathering (); |
558 | } | 562 | } |
559 | 563 | ||
560 | 564 | ||
@@ -565,7 +569,7 @@ gather_migration_blocks(void *cls) | |||
565 | * @param peer handle for the peer that connected | 569 | * @param peer handle for the peer that connected |
566 | */ | 570 | */ |
567 | void | 571 | void |
568 | GSF_push_start_(struct GSF_ConnectedPeer *peer) | 572 | GSF_push_start_ (struct GSF_ConnectedPeer *peer) |
569 | { | 573 | { |
570 | struct MigrationReadyPeer *mrp; | 574 | struct MigrationReadyPeer *mrp; |
571 | 575 | ||
@@ -575,22 +579,22 @@ GSF_push_start_(struct GSF_ConnectedPeer *peer) | |||
575 | if (mrp->peer == peer) | 579 | if (mrp->peer == peer) |
576 | break; | 580 | break; |
577 | if (NULL != mrp) | 581 | if (NULL != mrp) |
578 | { | 582 | { |
579 | /* same peer added twice, must not happen */ | 583 | /* same peer added twice, must not happen */ |
580 | GNUNET_break(0); | 584 | GNUNET_break (0); |
581 | return; | 585 | return; |
582 | } | 586 | } |
583 | 587 | ||
584 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
585 | "Adding peer %s to list for pushing\n", | 589 | "Adding peer %s to list for pushing\n", |
586 | GNUNET_i2s(GSF_connected_peer_get_identity2_(peer))); | 590 | GNUNET_i2s (GSF_connected_peer_get_identity2_ (peer))); |
587 | 591 | ||
588 | mrp = GNUNET_new(struct MigrationReadyPeer); | 592 | mrp = GNUNET_new (struct MigrationReadyPeer); |
589 | mrp->peer = peer; | 593 | mrp->peer = peer; |
590 | find_content(mrp); | 594 | find_content (mrp); |
591 | GNUNET_CONTAINER_DLL_insert(peer_head, | 595 | GNUNET_CONTAINER_DLL_insert (peer_head, |
592 | peer_tail, | 596 | peer_tail, |
593 | mrp); | 597 | mrp); |
594 | } | 598 | } |
595 | 599 | ||
596 | 600 | ||
@@ -601,7 +605,7 @@ GSF_push_start_(struct GSF_ConnectedPeer *peer) | |||
601 | * @param peer handle for the peer that disconnected | 605 | * @param peer handle for the peer that disconnected |
602 | */ | 606 | */ |
603 | void | 607 | void |
604 | GSF_push_stop_(struct GSF_ConnectedPeer *peer) | 608 | GSF_push_stop_ (struct GSF_ConnectedPeer *peer) |
605 | { | 609 | { |
606 | struct MigrationReadyPeer *pos; | 610 | struct MigrationReadyPeer *pos; |
607 | 611 | ||
@@ -611,11 +615,11 @@ GSF_push_stop_(struct GSF_ConnectedPeer *peer) | |||
611 | if (NULL == pos) | 615 | if (NULL == pos) |
612 | return; | 616 | return; |
613 | if (NULL != pos->env) | 617 | if (NULL != pos->env) |
614 | GNUNET_MQ_send_cancel(pos->env); | 618 | GNUNET_MQ_send_cancel (pos->env); |
615 | GNUNET_CONTAINER_DLL_remove(peer_head, | 619 | GNUNET_CONTAINER_DLL_remove (peer_head, |
616 | peer_tail, | 620 | peer_tail, |
617 | pos); | 621 | pos); |
618 | GNUNET_free(pos); | 622 | GNUNET_free (pos); |
619 | } | 623 | } |
620 | 624 | ||
621 | 625 | ||
@@ -623,28 +627,28 @@ GSF_push_stop_(struct GSF_ConnectedPeer *peer) | |||
623 | * Setup the module. | 627 | * Setup the module. |
624 | */ | 628 | */ |
625 | void | 629 | void |
626 | GSF_push_init_() | 630 | GSF_push_init_ () |
627 | { | 631 | { |
628 | enabled = | 632 | enabled = |
629 | GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg, | 633 | GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, |
630 | "FS", | 634 | "FS", |
631 | "CONTENT_PUSHING"); | 635 | "CONTENT_PUSHING"); |
632 | if (GNUNET_YES != enabled) | 636 | if (GNUNET_YES != enabled) |
633 | return; | 637 | return; |
634 | 638 | ||
635 | if (GNUNET_OK != | 639 | if (GNUNET_OK != |
636 | GNUNET_CONFIGURATION_get_value_time(GSF_cfg, | 640 | GNUNET_CONFIGURATION_get_value_time (GSF_cfg, |
637 | "fs", | 641 | "fs", |
638 | "MIN_MIGRATION_DELAY", | 642 | "MIN_MIGRATION_DELAY", |
639 | &min_migration_delay)) | 643 | &min_migration_delay)) |
640 | { | 644 | { |
641 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, | 645 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, |
642 | "fs", | 646 | "fs", |
643 | "MIN_MIGRATION_DELAY", | 647 | "MIN_MIGRATION_DELAY", |
644 | _("time required, content pushing disabled")); | 648 | _ ("time required, content pushing disabled")); |
645 | return; | 649 | return; |
646 | } | 650 | } |
647 | consider_gathering(); | 651 | consider_gathering (); |
648 | } | 652 | } |
649 | 653 | ||
650 | 654 | ||
@@ -652,21 +656,21 @@ GSF_push_init_() | |||
652 | * Shutdown the module. | 656 | * Shutdown the module. |
653 | */ | 657 | */ |
654 | void | 658 | void |
655 | GSF_push_done_() | 659 | GSF_push_done_ () |
656 | { | 660 | { |
657 | if (NULL != mig_task) | 661 | if (NULL != mig_task) |
658 | { | 662 | { |
659 | GNUNET_SCHEDULER_cancel(mig_task); | 663 | GNUNET_SCHEDULER_cancel (mig_task); |
660 | mig_task = NULL; | 664 | mig_task = NULL; |
661 | } | 665 | } |
662 | if (NULL != mig_qe) | 666 | if (NULL != mig_qe) |
663 | { | 667 | { |
664 | GNUNET_DATASTORE_cancel(mig_qe); | 668 | GNUNET_DATASTORE_cancel (mig_qe); |
665 | mig_qe = NULL; | 669 | mig_qe = NULL; |
666 | } | 670 | } |
667 | while (NULL != mig_head) | 671 | while (NULL != mig_head) |
668 | delete_migration_block(mig_head); | 672 | delete_migration_block (mig_head); |
669 | GNUNET_assert(0 == mig_size); | 673 | GNUNET_assert (0 == mig_size); |
670 | } | 674 | } |
671 | 675 | ||
672 | /* end of gnunet-service-fs_push.c */ | 676 | /* end of gnunet-service-fs_push.c */ |
diff --git a/src/fs/gnunet-service-fs_push.h b/src/fs/gnunet-service-fs_push.h index 0917364e2..2cd621bbb 100644 --- a/src/fs/gnunet-service-fs_push.h +++ b/src/fs/gnunet-service-fs_push.h | |||
@@ -33,14 +33,14 @@ | |||
33 | * Setup the module. | 33 | * Setup the module. |
34 | */ | 34 | */ |
35 | void | 35 | void |
36 | GSF_push_init_(void); | 36 | GSF_push_init_ (void); |
37 | 37 | ||
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Shutdown the module. | 40 | * Shutdown the module. |
41 | */ | 41 | */ |
42 | void | 42 | void |
43 | GSF_push_done_(void); | 43 | GSF_push_done_ (void); |
44 | 44 | ||
45 | 45 | ||
46 | /** | 46 | /** |
@@ -50,7 +50,7 @@ GSF_push_done_(void); | |||
50 | * @param peer handle for the peer that connected | 50 | * @param peer handle for the peer that connected |
51 | */ | 51 | */ |
52 | void | 52 | void |
53 | GSF_push_start_(struct GSF_ConnectedPeer *peer); | 53 | GSF_push_start_ (struct GSF_ConnectedPeer *peer); |
54 | 54 | ||
55 | 55 | ||
56 | /** | 56 | /** |
@@ -60,7 +60,7 @@ GSF_push_start_(struct GSF_ConnectedPeer *peer); | |||
60 | * @param peer handle for the peer that disconnected | 60 | * @param peer handle for the peer that disconnected |
61 | */ | 61 | */ |
62 | void | 62 | void |
63 | GSF_push_stop_(struct GSF_ConnectedPeer *peer); | 63 | GSF_push_stop_ (struct GSF_ConnectedPeer *peer); |
64 | 64 | ||
65 | 65 | ||
66 | #endif | 66 | #endif |
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c index deba91a0c..335496119 100644 --- a/src/fs/gnunet-service-fs_put.c +++ b/src/fs/gnunet-service-fs_put.c | |||
@@ -31,7 +31,8 @@ | |||
31 | /** | 31 | /** |
32 | * How often do we at most PUT content into the DHT? | 32 | * How often do we at most PUT content into the DHT? |
33 | */ | 33 | */ |
34 | #define MAX_DHT_PUT_FREQ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 34 | #define MAX_DHT_PUT_FREQ GNUNET_TIME_relative_multiply ( \ |
35 | GNUNET_TIME_UNIT_SECONDS, 5) | ||
35 | 36 | ||
36 | /** | 37 | /** |
37 | * How many replicas do we try to create per PUT? | 38 | * How many replicas do we try to create per PUT? |
@@ -42,7 +43,8 @@ | |||
42 | /** | 43 | /** |
43 | * Context for each zero-anonymity iterator. | 44 | * Context for each zero-anonymity iterator. |
44 | */ | 45 | */ |
45 | struct PutOperator { | 46 | struct PutOperator |
47 | { | ||
46 | /** | 48 | /** |
47 | * Request to datastore for DHT PUTs (or NULL). | 49 | * Request to datastore for DHT PUTs (or NULL). |
48 | */ | 50 | */ |
@@ -61,7 +63,7 @@ struct PutOperator { | |||
61 | /** | 63 | /** |
62 | * ID of task that collects blocks for DHT PUTs. | 64 | * ID of task that collects blocks for DHT PUTs. |
63 | */ | 65 | */ |
64 | struct GNUNET_SCHEDULER_Task * dht_task; | 66 | struct GNUNET_SCHEDULER_Task *dht_task; |
65 | 67 | ||
66 | /** | 68 | /** |
67 | * How many entires with zero anonymity of our type do we currently | 69 | * How many entires with zero anonymity of our type do we currently |
@@ -98,7 +100,7 @@ static struct PutOperator operators[] = { | |||
98 | * @param tc scheduler context (unused) | 100 | * @param tc scheduler context (unused) |
99 | */ | 101 | */ |
100 | static void | 102 | static void |
101 | gather_dht_put_blocks(void *cls); | 103 | gather_dht_put_blocks (void *cls); |
102 | 104 | ||
103 | 105 | ||
104 | /** | 106 | /** |
@@ -107,25 +109,25 @@ gather_dht_put_blocks(void *cls); | |||
107 | * @param po put operator to schedule | 109 | * @param po put operator to schedule |
108 | */ | 110 | */ |
109 | static void | 111 | static void |
110 | schedule_next_put(struct PutOperator *po) | 112 | schedule_next_put (struct PutOperator *po) |
111 | { | 113 | { |
112 | struct GNUNET_TIME_Relative delay; | 114 | struct GNUNET_TIME_Relative delay; |
113 | 115 | ||
114 | if (po->zero_anonymity_count_estimate > 0) | 116 | if (po->zero_anonymity_count_estimate > 0) |
115 | { | 117 | { |
116 | delay = | 118 | delay = |
117 | GNUNET_TIME_relative_divide(GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, | 119 | GNUNET_TIME_relative_divide (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, |
118 | po->zero_anonymity_count_estimate); | 120 | po->zero_anonymity_count_estimate); |
119 | delay = GNUNET_TIME_relative_min(delay, MAX_DHT_PUT_FREQ); | 121 | delay = GNUNET_TIME_relative_min (delay, MAX_DHT_PUT_FREQ); |
120 | } | 122 | } |
121 | else | 123 | else |
122 | { | 124 | { |
123 | /* if we have NO zero-anonymity content yet, wait 5 minutes for some to | 125 | /* if we have NO zero-anonymity content yet, wait 5 minutes for some to |
124 | * (hopefully) appear */ | 126 | * (hopefully) appear */ |
125 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5); | 127 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5); |
126 | } | 128 | } |
127 | po->dht_task = | 129 | po->dht_task = |
128 | GNUNET_SCHEDULER_add_delayed(delay, &gather_dht_put_blocks, po); | 130 | GNUNET_SCHEDULER_add_delayed (delay, &gather_dht_put_blocks, po); |
129 | } | 131 | } |
130 | 132 | ||
131 | 133 | ||
@@ -135,12 +137,12 @@ schedule_next_put(struct PutOperator *po) | |||
135 | * @param cls type of blocks to gather | 137 | * @param cls type of blocks to gather |
136 | */ | 138 | */ |
137 | static void | 139 | static void |
138 | delay_dht_put_blocks(void *cls) | 140 | delay_dht_put_blocks (void *cls) |
139 | { | 141 | { |
140 | struct PutOperator *po = cls; | 142 | struct PutOperator *po = cls; |
141 | 143 | ||
142 | po->dht_put = NULL; | 144 | po->dht_put = NULL; |
143 | schedule_next_put(po); | 145 | schedule_next_put (po); |
144 | } | 146 | } |
145 | 147 | ||
146 | 148 | ||
@@ -150,12 +152,12 @@ delay_dht_put_blocks(void *cls) | |||
150 | * @param cls type of blocks to gather | 152 | * @param cls type of blocks to gather |
151 | */ | 153 | */ |
152 | static void | 154 | static void |
153 | delay_dht_put_task(void *cls) | 155 | delay_dht_put_task (void *cls) |
154 | { | 156 | { |
155 | struct PutOperator *po = cls; | 157 | struct PutOperator *po = cls; |
156 | 158 | ||
157 | po->dht_task = NULL; | 159 | po->dht_task = NULL; |
158 | schedule_next_put(po); | 160 | schedule_next_put (po); |
159 | } | 161 | } |
160 | 162 | ||
161 | 163 | ||
@@ -175,45 +177,45 @@ delay_dht_put_task(void *cls) | |||
175 | * maybe 0 if no unique identifier is available | 177 | * maybe 0 if no unique identifier is available |
176 | */ | 178 | */ |
177 | static void | 179 | static void |
178 | process_dht_put_content(void *cls, | 180 | process_dht_put_content (void *cls, |
179 | const struct GNUNET_HashCode * key, | 181 | const struct GNUNET_HashCode *key, |
180 | size_t size, | 182 | size_t size, |
181 | const void *data, | 183 | const void *data, |
182 | enum GNUNET_BLOCK_Type type, | 184 | enum GNUNET_BLOCK_Type type, |
183 | uint32_t priority, | 185 | uint32_t priority, |
184 | uint32_t anonymity, | 186 | uint32_t anonymity, |
185 | uint32_t replication, | 187 | uint32_t replication, |
186 | struct GNUNET_TIME_Absolute expiration, | 188 | struct GNUNET_TIME_Absolute expiration, |
187 | uint64_t uid) | 189 | uint64_t uid) |
188 | { | 190 | { |
189 | struct PutOperator *po = cls; | 191 | struct PutOperator *po = cls; |
190 | 192 | ||
191 | po->dht_qe = NULL; | 193 | po->dht_qe = NULL; |
192 | if (key == NULL) | 194 | if (key == NULL) |
193 | { | 195 | { |
194 | po->zero_anonymity_count_estimate = po->result_count; | 196 | po->zero_anonymity_count_estimate = po->result_count; |
195 | po->result_count = 0; | 197 | po->result_count = 0; |
196 | po->next_uid = 0; | 198 | po->next_uid = 0; |
197 | po->dht_task = GNUNET_SCHEDULER_add_now(&delay_dht_put_task, po); | 199 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); |
198 | return; | 200 | return; |
199 | } | 201 | } |
200 | po->result_count++; | 202 | po->result_count++; |
201 | po->next_uid = uid + 1; | 203 | po->next_uid = uid + 1; |
202 | po->zero_anonymity_count_estimate = | 204 | po->zero_anonymity_count_estimate = |
203 | GNUNET_MAX(po->result_count, po->zero_anonymity_count_estimate); | 205 | GNUNET_MAX (po->result_count, po->zero_anonymity_count_estimate); |
204 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
205 | "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s(key), | 207 | "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key), |
206 | type); | 208 | type); |
207 | po->dht_put = GNUNET_DHT_put(GSF_dht, | 209 | po->dht_put = GNUNET_DHT_put (GSF_dht, |
208 | key, | 210 | key, |
209 | DEFAULT_PUT_REPLICATION, | 211 | DEFAULT_PUT_REPLICATION, |
210 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 212 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
211 | type, | 213 | type, |
212 | size, | 214 | size, |
213 | data, | 215 | data, |
214 | expiration, | 216 | expiration, |
215 | &delay_dht_put_blocks, | 217 | &delay_dht_put_blocks, |
216 | po); | 218 | po); |
217 | } | 219 | } |
218 | 220 | ||
219 | 221 | ||
@@ -223,21 +225,21 @@ process_dht_put_content(void *cls, | |||
223 | * @param cls type of blocks to gather | 225 | * @param cls type of blocks to gather |
224 | */ | 226 | */ |
225 | static void | 227 | static void |
226 | gather_dht_put_blocks(void *cls) | 228 | gather_dht_put_blocks (void *cls) |
227 | { | 229 | { |
228 | struct PutOperator *po = cls; | 230 | struct PutOperator *po = cls; |
229 | 231 | ||
230 | po->dht_task = NULL; | 232 | po->dht_task = NULL; |
231 | po->dht_qe = | 233 | po->dht_qe = |
232 | GNUNET_DATASTORE_get_zero_anonymity(GSF_dsh, | 234 | GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, |
233 | po->next_uid, | 235 | po->next_uid, |
234 | 0, | 236 | 0, |
235 | UINT_MAX, | 237 | UINT_MAX, |
236 | po->dht_put_type, | 238 | po->dht_put_type, |
237 | &process_dht_put_content, | 239 | &process_dht_put_content, |
238 | po); | 240 | po); |
239 | if (NULL == po->dht_qe) | 241 | if (NULL == po->dht_qe) |
240 | po->dht_task = GNUNET_SCHEDULER_add_now(&delay_dht_put_task, po); | 242 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); |
241 | } | 243 | } |
242 | 244 | ||
243 | 245 | ||
@@ -245,17 +247,17 @@ gather_dht_put_blocks(void *cls) | |||
245 | * Setup the module. | 247 | * Setup the module. |
246 | */ | 248 | */ |
247 | void | 249 | void |
248 | GSF_put_init_() | 250 | GSF_put_init_ () |
249 | { | 251 | { |
250 | unsigned int i; | 252 | unsigned int i; |
251 | 253 | ||
252 | i = 0; | 254 | i = 0; |
253 | while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY) | 255 | while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY) |
254 | { | 256 | { |
255 | operators[i].dht_task = | 257 | operators[i].dht_task = |
256 | GNUNET_SCHEDULER_add_now(&gather_dht_put_blocks, &operators[i]); | 258 | GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, &operators[i]); |
257 | i++; | 259 | i++; |
258 | } | 260 | } |
259 | } | 261 | } |
260 | 262 | ||
261 | 263 | ||
@@ -263,31 +265,31 @@ GSF_put_init_() | |||
263 | * Shutdown the module. | 265 | * Shutdown the module. |
264 | */ | 266 | */ |
265 | void | 267 | void |
266 | GSF_put_done_() | 268 | GSF_put_done_ () |
267 | { | 269 | { |
268 | struct PutOperator *po; | 270 | struct PutOperator *po; |
269 | unsigned int i; | 271 | unsigned int i; |
270 | 272 | ||
271 | i = 0; | 273 | i = 0; |
272 | while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY) | 274 | while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY) |
275 | { | ||
276 | if (NULL != po->dht_task) | ||
277 | { | ||
278 | GNUNET_SCHEDULER_cancel (po->dht_task); | ||
279 | po->dht_task = NULL; | ||
280 | } | ||
281 | if (NULL != po->dht_put) | ||
282 | { | ||
283 | GNUNET_DHT_put_cancel (po->dht_put); | ||
284 | po->dht_put = NULL; | ||
285 | } | ||
286 | if (NULL != po->dht_qe) | ||
273 | { | 287 | { |
274 | if (NULL != po->dht_task) | 288 | GNUNET_DATASTORE_cancel (po->dht_qe); |
275 | { | 289 | po->dht_qe = NULL; |
276 | GNUNET_SCHEDULER_cancel(po->dht_task); | ||
277 | po->dht_task = NULL; | ||
278 | } | ||
279 | if (NULL != po->dht_put) | ||
280 | { | ||
281 | GNUNET_DHT_put_cancel(po->dht_put); | ||
282 | po->dht_put = NULL; | ||
283 | } | ||
284 | if (NULL != po->dht_qe) | ||
285 | { | ||
286 | GNUNET_DATASTORE_cancel(po->dht_qe); | ||
287 | po->dht_qe = NULL; | ||
288 | } | ||
289 | i++; | ||
290 | } | 290 | } |
291 | i++; | ||
292 | } | ||
291 | } | 293 | } |
292 | 294 | ||
293 | /* end of gnunet-service-fs_put.c */ | 295 | /* end of gnunet-service-fs_put.c */ |
diff --git a/src/fs/gnunet-service-fs_put.h b/src/fs/gnunet-service-fs_put.h index 2d85d9831..b6c9ba86f 100644 --- a/src/fs/gnunet-service-fs_put.h +++ b/src/fs/gnunet-service-fs_put.h | |||
@@ -33,14 +33,14 @@ | |||
33 | * Setup the module. | 33 | * Setup the module. |
34 | */ | 34 | */ |
35 | void | 35 | void |
36 | GSF_put_init_(void); | 36 | GSF_put_init_ (void); |
37 | 37 | ||
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Shutdown the module. | 40 | * Shutdown the module. |
41 | */ | 41 | */ |
42 | void | 42 | void |
43 | GSF_put_done_(void); | 43 | GSF_put_done_ (void); |
44 | 44 | ||
45 | 45 | ||
46 | #endif | 46 | #endif |
diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c index 873dfa5eb..88825fa60 100644 --- a/src/fs/gnunet-unindex.c +++ b/src/fs/gnunet-unindex.c | |||
@@ -40,24 +40,24 @@ static struct GNUNET_FS_UnindexContext *uc; | |||
40 | 40 | ||
41 | 41 | ||
42 | static void | 42 | static void |
43 | cleanup_task(void *cls) | 43 | cleanup_task (void *cls) |
44 | { | 44 | { |
45 | GNUNET_FS_stop(ctx); | 45 | GNUNET_FS_stop (ctx); |
46 | ctx = NULL; | 46 | ctx = NULL; |
47 | } | 47 | } |
48 | 48 | ||
49 | 49 | ||
50 | static void | 50 | static void |
51 | shutdown_task(void *cls) | 51 | shutdown_task (void *cls) |
52 | { | 52 | { |
53 | struct GNUNET_FS_UnindexContext *u; | 53 | struct GNUNET_FS_UnindexContext *u; |
54 | 54 | ||
55 | if (uc != NULL) | 55 | if (uc != NULL) |
56 | { | 56 | { |
57 | u = uc; | 57 | u = uc; |
58 | uc = NULL; | 58 | uc = NULL; |
59 | GNUNET_FS_unindex_stop(u); | 59 | GNUNET_FS_unindex_stop (u); |
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
63 | /** | 63 | /** |
@@ -74,48 +74,48 @@ shutdown_task(void *cls) | |||
74 | * field in the GNUNET_FS_ProgressInfo struct. | 74 | * field in the GNUNET_FS_ProgressInfo struct. |
75 | */ | 75 | */ |
76 | static void * | 76 | static void * |
77 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) | 77 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
78 | { | 78 | { |
79 | const char *s; | 79 | const char *s; |
80 | 80 | ||
81 | switch (info->status) | 81 | switch (info->status) |
82 | { | ||
83 | case GNUNET_FS_STATUS_UNINDEX_START: | ||
84 | break; | ||
85 | |||
86 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | ||
87 | if (verbose) | ||
82 | { | 88 | { |
83 | case GNUNET_FS_STATUS_UNINDEX_START: | 89 | s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta, |
84 | break; | 90 | GNUNET_YES); |
85 | 91 | fprintf (stdout, | |
86 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | 92 | _ ("Unindexing at %llu/%llu (%s remaining)\n"), |
87 | if (verbose) | 93 | (unsigned long long) info->value.unindex.completed, |
88 | { | 94 | (unsigned long long) info->value.unindex.size, |
89 | s = GNUNET_STRINGS_relative_time_to_string(info->value.unindex.eta, | 95 | s); |
90 | GNUNET_YES); | ||
91 | fprintf(stdout, | ||
92 | _("Unindexing at %llu/%llu (%s remaining)\n"), | ||
93 | (unsigned long long)info->value.unindex.completed, | ||
94 | (unsigned long long)info->value.unindex.size, | ||
95 | s); | ||
96 | } | ||
97 | break; | ||
98 | |||
99 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | ||
100 | fprintf(stderr, | ||
101 | _("Error unindexing: %s.\n"), | ||
102 | info->value.unindex.specifics.error.message); | ||
103 | GNUNET_SCHEDULER_shutdown(); | ||
104 | break; | ||
105 | |||
106 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | ||
107 | fprintf(stdout, "%s", _("Unindexing done.\n")); | ||
108 | GNUNET_SCHEDULER_shutdown(); | ||
109 | break; | ||
110 | |||
111 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | ||
112 | GNUNET_SCHEDULER_add_now(&cleanup_task, NULL); | ||
113 | break; | ||
114 | |||
115 | default: | ||
116 | fprintf(stderr, _("Unexpected status: %d\n"), info->status); | ||
117 | break; | ||
118 | } | 96 | } |
97 | break; | ||
98 | |||
99 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | ||
100 | fprintf (stderr, | ||
101 | _ ("Error unindexing: %s.\n"), | ||
102 | info->value.unindex.specifics.error.message); | ||
103 | GNUNET_SCHEDULER_shutdown (); | ||
104 | break; | ||
105 | |||
106 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | ||
107 | fprintf (stdout, "%s", _ ("Unindexing done.\n")); | ||
108 | GNUNET_SCHEDULER_shutdown (); | ||
109 | break; | ||
110 | |||
111 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | ||
112 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | ||
113 | break; | ||
114 | |||
115 | default: | ||
116 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); | ||
117 | break; | ||
118 | } | ||
119 | return NULL; | 119 | return NULL; |
120 | } | 120 | } |
121 | 121 | ||
@@ -129,39 +129,39 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
129 | * @param c configuration | 129 | * @param c configuration |
130 | */ | 130 | */ |
131 | static void | 131 | static void |
132 | run(void *cls, | 132 | run (void *cls, |
133 | char *const *args, | 133 | char *const *args, |
134 | const char *cfgfile, | 134 | const char *cfgfile, |
135 | const struct GNUNET_CONFIGURATION_Handle *c) | 135 | const struct GNUNET_CONFIGURATION_Handle *c) |
136 | { | 136 | { |
137 | /* check arguments */ | 137 | /* check arguments */ |
138 | if ((args[0] == NULL) || (args[1] != NULL)) | 138 | if ((args[0] == NULL) || (args[1] != NULL)) |
139 | { | 139 | { |
140 | printf(_("You must specify one and only one filename for unindexing.\n")); | 140 | printf (_ ("You must specify one and only one filename for unindexing.\n")); |
141 | ret = -1; | 141 | ret = -1; |
142 | return; | 142 | return; |
143 | } | 143 | } |
144 | cfg = c; | 144 | cfg = c; |
145 | ctx = GNUNET_FS_start(cfg, | 145 | ctx = GNUNET_FS_start (cfg, |
146 | "gnunet-unindex", | 146 | "gnunet-unindex", |
147 | &progress_cb, | 147 | &progress_cb, |
148 | NULL, | 148 | NULL, |
149 | GNUNET_FS_FLAGS_NONE, | 149 | GNUNET_FS_FLAGS_NONE, |
150 | GNUNET_FS_OPTIONS_END); | 150 | GNUNET_FS_OPTIONS_END); |
151 | if (NULL == ctx) | 151 | if (NULL == ctx) |
152 | { | 152 | { |
153 | fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); | 153 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); |
154 | ret = 1; | 154 | ret = 1; |
155 | return; | 155 | return; |
156 | } | 156 | } |
157 | uc = GNUNET_FS_unindex_start(ctx, args[0], NULL); | 157 | uc = GNUNET_FS_unindex_start (ctx, args[0], NULL); |
158 | if (NULL == uc) | 158 | if (NULL == uc) |
159 | { | 159 | { |
160 | fprintf(stderr, "%s", _("Could not start unindex operation.\n")); | 160 | fprintf (stderr, "%s", _ ("Could not start unindex operation.\n")); |
161 | GNUNET_FS_stop(ctx); | 161 | GNUNET_FS_stop (ctx); |
162 | return; | 162 | return; |
163 | } | 163 | } |
164 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 164 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
@@ -173,30 +173,30 @@ run(void *cls, | |||
173 | * @return 0 ok, 1 on error | 173 | * @return 0 ok, 1 on error |
174 | */ | 174 | */ |
175 | int | 175 | int |
176 | main(int argc, char *const *argv) | 176 | main (int argc, char *const *argv) |
177 | { | 177 | { |
178 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 178 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
179 | GNUNET_GETOPT_option_verbose(&verbose), | 179 | GNUNET_GETOPT_option_verbose (&verbose), |
180 | 180 | ||
181 | GNUNET_GETOPT_OPTION_END | 181 | GNUNET_GETOPT_OPTION_END |
182 | }; | 182 | }; |
183 | 183 | ||
184 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 184 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
185 | return 2; | 185 | return 2; |
186 | 186 | ||
187 | ret = (GNUNET_OK == | 187 | ret = (GNUNET_OK == |
188 | GNUNET_PROGRAM_run( | 188 | GNUNET_PROGRAM_run ( |
189 | argc, | 189 | argc, |
190 | argv, | 190 | argv, |
191 | "gnunet-unindex [OPTIONS] FILENAME", | 191 | "gnunet-unindex [OPTIONS] FILENAME", |
192 | gettext_noop( | 192 | gettext_noop ( |
193 | "Unindex a file that was previously indexed with gnunet-publish."), | 193 | "Unindex a file that was previously indexed with gnunet-publish."), |
194 | options, | 194 | options, |
195 | &run, | 195 | &run, |
196 | NULL)) | 196 | NULL)) |
197 | ? ret | 197 | ? ret |
198 | : 1; | 198 | : 1; |
199 | GNUNET_free((void *)argv); | 199 | GNUNET_free ((void *) argv); |
200 | return ret; | 200 | return ret; |
201 | } | 201 | } |
202 | 202 | ||
diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c index 515144eb1..39563dfa4 100644 --- a/src/fs/perf_gnunet_service_fs_p2p.c +++ b/src/fs/perf_gnunet_service_fs_p2p.c | |||
@@ -37,7 +37,7 @@ | |||
37 | /** | 37 | /** |
38 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
39 | */ | 39 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) |
41 | 41 | ||
42 | #define NUM_DAEMONS 2 | 42 | #define NUM_DAEMONS 2 |
43 | 43 | ||
@@ -57,14 +57,16 @@ static struct GNUNET_TIME_Absolute start_time; | |||
57 | /** | 57 | /** |
58 | * Master context for 'stat_run'. | 58 | * Master context for 'stat_run'. |
59 | */ | 59 | */ |
60 | struct StatMaster { | 60 | struct StatMaster |
61 | { | ||
61 | struct GNUNET_STATISTICS_Handle *stat; | 62 | struct GNUNET_STATISTICS_Handle *stat; |
62 | struct GNUNET_TESTBED_Operation *op; | 63 | struct GNUNET_TESTBED_Operation *op; |
63 | unsigned int daemon; | 64 | unsigned int daemon; |
64 | unsigned int value; | 65 | unsigned int value; |
65 | }; | 66 | }; |
66 | 67 | ||
67 | struct StatValues { | 68 | struct StatValues |
69 | { | ||
68 | const char *subsystem; | 70 | const char *subsystem; |
69 | const char *name; | 71 | const char *name; |
70 | }; | 72 | }; |
@@ -109,17 +111,17 @@ static struct StatValues stats[] = { | |||
109 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 111 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
110 | */ | 112 | */ |
111 | static int | 113 | static int |
112 | print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, | 114 | print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, |
113 | int is_persistent) | 115 | int is_persistent) |
114 | { | 116 | { |
115 | struct StatMaster *sm = cls; | 117 | struct StatMaster *sm = cls; |
116 | 118 | ||
117 | fprintf(stderr, | 119 | fprintf (stderr, |
118 | "Peer %2u: %12s/%50s = %12llu\n", | 120 | "Peer %2u: %12s/%50s = %12llu\n", |
119 | sm->daemon, | 121 | sm->daemon, |
120 | subsystem, | 122 | subsystem, |
121 | name, | 123 | name, |
122 | (unsigned long long)value); | 124 | (unsigned long long) value); |
123 | return GNUNET_OK; | 125 | return GNUNET_OK; |
124 | } | 126 | } |
125 | 127 | ||
@@ -128,23 +130,23 @@ print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, | |||
128 | * Function that gathers stats from all daemons. | 130 | * Function that gathers stats from all daemons. |
129 | */ | 131 | */ |
130 | static void | 132 | static void |
131 | stat_run(void *cls, | 133 | stat_run (void *cls, |
132 | struct GNUNET_TESTBED_Operation *op, | 134 | struct GNUNET_TESTBED_Operation *op, |
133 | void *ca_result, | 135 | void *ca_result, |
134 | const char *emsg); | 136 | const char *emsg); |
135 | 137 | ||
136 | 138 | ||
137 | /** | 139 | /** |
138 | * Function called when GET operation on stats is done. | 140 | * Function called when GET operation on stats is done. |
139 | */ | 141 | */ |
140 | static void | 142 | static void |
141 | get_done(void *cls, int success) | 143 | get_done (void *cls, int success) |
142 | { | 144 | { |
143 | struct StatMaster *sm = cls; | 145 | struct StatMaster *sm = cls; |
144 | 146 | ||
145 | GNUNET_break(GNUNET_OK == success); | 147 | GNUNET_break (GNUNET_OK == success); |
146 | sm->value++; | 148 | sm->value++; |
147 | stat_run(sm, sm->op, sm->stat, NULL); | 149 | stat_run (sm, sm->op, sm->stat, NULL); |
148 | } | 150 | } |
149 | 151 | ||
150 | 152 | ||
@@ -159,11 +161,11 @@ get_done(void *cls, int success) | |||
159 | * @return service handle to return in 'op_result', NULL on error | 161 | * @return service handle to return in 'op_result', NULL on error |
160 | */ | 162 | */ |
161 | static void * | 163 | static void * |
162 | statistics_connect_adapter(void *cls, | 164 | statistics_connect_adapter (void *cls, |
163 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 165 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
164 | { | 166 | { |
165 | return GNUNET_STATISTICS_create("<driver>", | 167 | return GNUNET_STATISTICS_create ("<driver>", |
166 | cfg); | 168 | cfg); |
167 | } | 169 | } |
168 | 170 | ||
169 | 171 | ||
@@ -175,10 +177,10 @@ statistics_connect_adapter(void *cls, | |||
175 | * @param op_result service handle returned from the connect adapter | 177 | * @param op_result service handle returned from the connect adapter |
176 | */ | 178 | */ |
177 | static void | 179 | static void |
178 | statistics_disconnect_adapter(void *cls, | 180 | statistics_disconnect_adapter (void *cls, |
179 | void *op_result) | 181 | void *op_result) |
180 | { | 182 | { |
181 | GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); | 183 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); |
182 | } | 184 | } |
183 | 185 | ||
184 | 186 | ||
@@ -186,57 +188,57 @@ statistics_disconnect_adapter(void *cls, | |||
186 | * Function that gathers stats from all daemons. | 188 | * Function that gathers stats from all daemons. |
187 | */ | 189 | */ |
188 | static void | 190 | static void |
189 | stat_run(void *cls, | 191 | stat_run (void *cls, |
190 | struct GNUNET_TESTBED_Operation *op, | 192 | struct GNUNET_TESTBED_Operation *op, |
191 | void *ca_result, | 193 | void *ca_result, |
192 | const char *emsg) | 194 | const char *emsg) |
193 | { | 195 | { |
194 | struct StatMaster *sm = cls; | 196 | struct StatMaster *sm = cls; |
195 | 197 | ||
196 | if (NULL != emsg) | 198 | if (NULL != emsg) |
197 | { | 199 | { |
198 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
199 | "Failed to statistics service: %s\n", | 201 | "Failed to statistics service: %s\n", |
200 | emsg); | 202 | emsg); |
201 | GNUNET_SCHEDULER_shutdown(); | 203 | GNUNET_SCHEDULER_shutdown (); |
202 | return; | 204 | return; |
203 | } | 205 | } |
204 | sm->stat = ca_result; | 206 | sm->stat = ca_result; |
205 | 207 | ||
206 | if (stats[sm->value].name != NULL) | 208 | if (stats[sm->value].name != NULL) |
207 | { | 209 | { |
208 | GNUNET_STATISTICS_get(sm->stat, | 210 | GNUNET_STATISTICS_get (sm->stat, |
209 | #if 0 | 211 | #if 0 |
210 | NULL, NULL, | 212 | NULL, NULL, |
211 | #else | 213 | #else |
212 | stats[sm->value].subsystem, stats[sm->value].name, | 214 | stats[sm->value].subsystem, stats[sm->value].name, |
213 | #endif | 215 | #endif |
214 | &get_done, &print_stat, | 216 | &get_done, &print_stat, |
215 | sm); | 217 | sm); |
216 | return; | 218 | return; |
217 | } | 219 | } |
218 | GNUNET_TESTBED_operation_done(sm->op); | 220 | GNUNET_TESTBED_operation_done (sm->op); |
219 | sm->value = 0; | 221 | sm->value = 0; |
220 | sm->daemon++; | 222 | sm->daemon++; |
221 | if (NUM_DAEMONS == sm->daemon) | 223 | if (NUM_DAEMONS == sm->daemon) |
222 | { | 224 | { |
223 | GNUNET_free(sm); | 225 | GNUNET_free (sm); |
224 | GNUNET_SCHEDULER_shutdown(); | 226 | GNUNET_SCHEDULER_shutdown (); |
225 | return; | 227 | return; |
226 | } | 228 | } |
227 | sm->op = | 229 | sm->op = |
228 | GNUNET_TESTBED_service_connect(NULL, | 230 | GNUNET_TESTBED_service_connect (NULL, |
229 | daemons[sm->daemon], | 231 | daemons[sm->daemon], |
230 | "statistics", | 232 | "statistics", |
231 | &stat_run, sm, | 233 | &stat_run, sm, |
232 | &statistics_connect_adapter, | 234 | &statistics_connect_adapter, |
233 | &statistics_disconnect_adapter, | 235 | &statistics_disconnect_adapter, |
234 | NULL); | 236 | NULL); |
235 | } | 237 | } |
236 | 238 | ||
237 | 239 | ||
238 | static void | 240 | static void |
239 | do_report(void *cls) | 241 | do_report (void *cls) |
240 | { | 242 | { |
241 | char *fn = cls; | 243 | char *fn = cls; |
242 | struct GNUNET_TIME_Relative del; | 244 | struct GNUNET_TIME_Relative del; |
@@ -244,120 +246,121 @@ do_report(void *cls) | |||
244 | struct StatMaster *sm; | 246 | struct StatMaster *sm; |
245 | 247 | ||
246 | if (NULL != fn) | 248 | if (NULL != fn) |
247 | { | 249 | { |
248 | GNUNET_DISK_directory_remove(fn); | 250 | GNUNET_DISK_directory_remove (fn); |
249 | GNUNET_free(fn); | 251 | GNUNET_free (fn); |
250 | } | 252 | } |
251 | if (0 == | 253 | if (0 == |
252 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, | 254 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, |
253 | TIMEOUT)).rel_value_us) | 255 | TIMEOUT)). |
254 | { | 256 | rel_value_us) |
255 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 257 | { |
256 | "Timeout during download, shutting down with error\n"); | 258 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
257 | ok = 1; | 259 | "Timeout during download, shutting down with error\n"); |
258 | GNUNET_SCHEDULER_shutdown(); | 260 | ok = 1; |
259 | return; | 261 | GNUNET_SCHEDULER_shutdown (); |
260 | } | 262 | return; |
261 | 263 | } | |
262 | del = GNUNET_TIME_absolute_get_duration(start_time); | 264 | |
265 | del = GNUNET_TIME_absolute_get_duration (start_time); | ||
263 | if (del.rel_value_us == 0) | 266 | if (del.rel_value_us == 0) |
264 | del.rel_value_us = 1; | 267 | del.rel_value_us = 1; |
265 | fancy = | 268 | fancy = |
266 | GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * | 269 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) |
267 | 1000000LL / del.rel_value_us); | 270 | * 1000000LL / del.rel_value_us); |
268 | fprintf(stdout, | 271 | fprintf (stdout, |
269 | "Download speed was %s/s\n", | 272 | "Download speed was %s/s\n", |
270 | fancy); | 273 | fancy); |
271 | GNUNET_free(fancy); | 274 | GNUNET_free (fancy); |
272 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
273 | "Finished download, shutting down\n"); | 276 | "Finished download, shutting down\n"); |
274 | sm = GNUNET_new(struct StatMaster); | 277 | sm = GNUNET_new (struct StatMaster); |
275 | sm->op = | 278 | sm->op = |
276 | GNUNET_TESTBED_service_connect(NULL, | 279 | GNUNET_TESTBED_service_connect (NULL, |
277 | daemons[sm->daemon], | 280 | daemons[sm->daemon], |
278 | "statistics", | 281 | "statistics", |
279 | &stat_run, sm, | 282 | &stat_run, sm, |
280 | &statistics_connect_adapter, | 283 | &statistics_connect_adapter, |
281 | &statistics_disconnect_adapter, | 284 | &statistics_disconnect_adapter, |
282 | NULL); | 285 | NULL); |
283 | } | 286 | } |
284 | 287 | ||
285 | 288 | ||
286 | static void | 289 | static void |
287 | do_download(void *cls, | 290 | do_download (void *cls, |
288 | const struct GNUNET_FS_Uri *uri, | 291 | const struct GNUNET_FS_Uri *uri, |
289 | const char *fn) | 292 | const char *fn) |
290 | { | 293 | { |
291 | int anonymity; | 294 | int anonymity; |
292 | 295 | ||
293 | if (NULL == uri) | 296 | if (NULL == uri) |
294 | { | 297 | { |
295 | GNUNET_SCHEDULER_shutdown(); | 298 | GNUNET_SCHEDULER_shutdown (); |
296 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 299 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
297 | "Timeout during upload attempt, shutting down with error\n"); | 300 | "Timeout during upload attempt, shutting down with error\n"); |
298 | ok = 1; | 301 | ok = 1; |
299 | return; | 302 | return; |
300 | } | 303 | } |
301 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", | 304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", |
302 | (unsigned long long)FILESIZE); | 305 | (unsigned long long) FILESIZE); |
303 | start_time = GNUNET_TIME_absolute_get(); | 306 | start_time = GNUNET_TIME_absolute_get (); |
304 | if (NULL != strstr(progname, "dht")) | 307 | if (NULL != strstr (progname, "dht")) |
305 | anonymity = 0; | 308 | anonymity = 0; |
306 | else | 309 | else |
307 | anonymity = 1; | 310 | anonymity = 1; |
308 | start_time = GNUNET_TIME_absolute_get(); | 311 | start_time = GNUNET_TIME_absolute_get (); |
309 | GNUNET_FS_TEST_download(daemons[0], | 312 | GNUNET_FS_TEST_download (daemons[0], |
310 | TIMEOUT, | 313 | TIMEOUT, |
311 | anonymity, | 314 | anonymity, |
312 | SEED, | 315 | SEED, |
313 | uri, | 316 | uri, |
314 | VERBOSE, | 317 | VERBOSE, |
315 | &do_report, | 318 | &do_report, |
316 | (NULL == fn) ? NULL : GNUNET_strdup(fn)); | 319 | (NULL == fn) ? NULL : GNUNET_strdup (fn)); |
317 | } | 320 | } |
318 | 321 | ||
319 | 322 | ||
320 | static void | 323 | static void |
321 | do_publish(void *cls, | 324 | do_publish (void *cls, |
322 | struct GNUNET_TESTBED_RunHandle *h, | 325 | struct GNUNET_TESTBED_RunHandle *h, |
323 | unsigned int num_peers, | 326 | unsigned int num_peers, |
324 | struct GNUNET_TESTBED_Peer **peers, | 327 | struct GNUNET_TESTBED_Peer **peers, |
325 | unsigned int links_succeeded, | 328 | unsigned int links_succeeded, |
326 | unsigned int links_failed) | 329 | unsigned int links_failed) |
327 | { | 330 | { |
328 | unsigned int i; | 331 | unsigned int i; |
329 | int do_index; | 332 | int do_index; |
330 | int anonymity; | 333 | int anonymity; |
331 | 334 | ||
332 | GNUNET_assert(NUM_DAEMONS == num_peers); | 335 | GNUNET_assert (NUM_DAEMONS == num_peers); |
333 | for (i = 0; i < num_peers; i++) | 336 | for (i = 0; i < num_peers; i++) |
334 | daemons[i] = peers[i]; | 337 | daemons[i] = peers[i]; |
335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
336 | (unsigned long long)FILESIZE); | 339 | (unsigned long long) FILESIZE); |
337 | if (NULL != strstr(progname, "index")) | 340 | if (NULL != strstr (progname, "index")) |
338 | do_index = GNUNET_YES; | 341 | do_index = GNUNET_YES; |
339 | else | 342 | else |
340 | do_index = GNUNET_NO; | 343 | do_index = GNUNET_NO; |
341 | if (NULL != strstr(progname, "dht")) | 344 | if (NULL != strstr (progname, "dht")) |
342 | anonymity = 0; | 345 | anonymity = 0; |
343 | else | 346 | else |
344 | anonymity = 1; | 347 | anonymity = 1; |
345 | GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, | 348 | GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, |
346 | do_index, FILESIZE, SEED, VERBOSE, &do_download, | 349 | do_index, FILESIZE, SEED, VERBOSE, &do_download, |
347 | NULL); | 350 | NULL); |
348 | } | 351 | } |
349 | 352 | ||
350 | 353 | ||
351 | int | 354 | int |
352 | main(int argc, char *argv[]) | 355 | main (int argc, char *argv[]) |
353 | { | 356 | { |
354 | progname = argv[0]; | 357 | progname = argv[0]; |
355 | (void)GNUNET_TESTBED_test_run("perf-gnunet-service-fs-p2p", | 358 | (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p", |
356 | "perf_gnunet_service_fs_p2p.conf", | 359 | "perf_gnunet_service_fs_p2p.conf", |
357 | NUM_DAEMONS, | 360 | NUM_DAEMONS, |
358 | 0, NULL, NULL, | 361 | 0, NULL, NULL, |
359 | &do_publish, NULL); | 362 | &do_publish, NULL); |
360 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); | 363 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
361 | return ok; | 364 | return ok; |
362 | } | 365 | } |
363 | 366 | ||
diff --git a/src/fs/perf_gnunet_service_fs_p2p_respect.c b/src/fs/perf_gnunet_service_fs_p2p_respect.c index 91ec9c66d..fc17235fa 100644 --- a/src/fs/perf_gnunet_service_fs_p2p_respect.c +++ b/src/fs/perf_gnunet_service_fs_p2p_respect.c | |||
@@ -57,7 +57,7 @@ | |||
57 | /** | 57 | /** |
58 | * How long until we give up on transmitting the message? | 58 | * How long until we give up on transmitting the message? |
59 | */ | 59 | */ |
60 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) | 60 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Number of daemons in clique, must be at least 3 (!). | 63 | * Number of daemons in clique, must be at least 3 (!). |
@@ -93,14 +93,16 @@ static char *fn2; | |||
93 | /** | 93 | /** |
94 | * Master context for 'stat_run'. | 94 | * Master context for 'stat_run'. |
95 | */ | 95 | */ |
96 | struct StatMaster { | 96 | struct StatMaster |
97 | { | ||
97 | struct GNUNET_STATISTICS_Handle *stat; | 98 | struct GNUNET_STATISTICS_Handle *stat; |
98 | struct GNUNET_TESTBED_Operation *op; | 99 | struct GNUNET_TESTBED_Operation *op; |
99 | unsigned int daemon; | 100 | unsigned int daemon; |
100 | unsigned int value; | 101 | unsigned int value; |
101 | }; | 102 | }; |
102 | 103 | ||
103 | struct StatValues { | 104 | struct StatValues |
105 | { | ||
104 | const char *subsystem; | 106 | const char *subsystem; |
105 | const char *name; | 107 | const char *name; |
106 | }; | 108 | }; |
@@ -134,19 +136,19 @@ static struct StatValues stats[] = { | |||
134 | 136 | ||
135 | 137 | ||
136 | static void | 138 | static void |
137 | cleanup() | 139 | cleanup () |
138 | { | 140 | { |
139 | GNUNET_SCHEDULER_shutdown(); | 141 | GNUNET_SCHEDULER_shutdown (); |
140 | if (NULL != fn1) | 142 | if (NULL != fn1) |
141 | { | 143 | { |
142 | GNUNET_DISK_directory_remove(fn1); | 144 | GNUNET_DISK_directory_remove (fn1); |
143 | GNUNET_free(fn1); | 145 | GNUNET_free (fn1); |
144 | } | 146 | } |
145 | if (NULL != fn2) | 147 | if (NULL != fn2) |
146 | { | 148 | { |
147 | GNUNET_DISK_directory_remove(fn2); | 149 | GNUNET_DISK_directory_remove (fn2); |
148 | GNUNET_free(fn2); | 150 | GNUNET_free (fn2); |
149 | } | 151 | } |
150 | } | 152 | } |
151 | 153 | ||
152 | 154 | ||
@@ -161,13 +163,13 @@ cleanup() | |||
161 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 163 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
162 | */ | 164 | */ |
163 | static int | 165 | static int |
164 | print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, | 166 | print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, |
165 | int is_persistent) | 167 | int is_persistent) |
166 | { | 168 | { |
167 | struct StatMaster *sm = cls; | 169 | struct StatMaster *sm = cls; |
168 | 170 | ||
169 | fprintf(stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, | 171 | fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, |
170 | name, (unsigned long long)value); | 172 | name, (unsigned long long) value); |
171 | return GNUNET_OK; | 173 | return GNUNET_OK; |
172 | } | 174 | } |
173 | 175 | ||
@@ -176,23 +178,23 @@ print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, | |||
176 | * Function that gathers stats from all daemons. | 178 | * Function that gathers stats from all daemons. |
177 | */ | 179 | */ |
178 | static void | 180 | static void |
179 | stat_run(void *cls, | 181 | stat_run (void *cls, |
180 | struct GNUNET_TESTBED_Operation *op, | 182 | struct GNUNET_TESTBED_Operation *op, |
181 | void *ca_result, | 183 | void *ca_result, |
182 | const char *emsg); | 184 | const char *emsg); |
183 | 185 | ||
184 | 186 | ||
185 | /** | 187 | /** |
186 | * Function called when GET operation on stats is done. | 188 | * Function called when GET operation on stats is done. |
187 | */ | 189 | */ |
188 | static void | 190 | static void |
189 | get_done(void *cls, int success) | 191 | get_done (void *cls, int success) |
190 | { | 192 | { |
191 | struct StatMaster *sm = cls; | 193 | struct StatMaster *sm = cls; |
192 | 194 | ||
193 | GNUNET_break(GNUNET_OK == success); | 195 | GNUNET_break (GNUNET_OK == success); |
194 | sm->value++; | 196 | sm->value++; |
195 | stat_run(sm, sm->op, sm->stat, NULL); | 197 | stat_run (sm, sm->op, sm->stat, NULL); |
196 | } | 198 | } |
197 | 199 | ||
198 | 200 | ||
@@ -208,11 +210,11 @@ get_done(void *cls, int success) | |||
208 | * @return service handle to return in 'op_result', NULL on error | 210 | * @return service handle to return in 'op_result', NULL on error |
209 | */ | 211 | */ |
210 | static void * | 212 | static void * |
211 | statistics_connect_adapter(void *cls, | 213 | statistics_connect_adapter (void *cls, |
212 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 214 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
213 | { | 215 | { |
214 | return GNUNET_STATISTICS_create("<driver>", | 216 | return GNUNET_STATISTICS_create ("<driver>", |
215 | cfg); | 217 | cfg); |
216 | } | 218 | } |
217 | 219 | ||
218 | 220 | ||
@@ -224,10 +226,10 @@ statistics_connect_adapter(void *cls, | |||
224 | * @param op_result service handle returned from the connect adapter | 226 | * @param op_result service handle returned from the connect adapter |
225 | */ | 227 | */ |
226 | static void | 228 | static void |
227 | statistics_disconnect_adapter(void *cls, | 229 | statistics_disconnect_adapter (void *cls, |
228 | void *op_result) | 230 | void *op_result) |
229 | { | 231 | { |
230 | GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); | 232 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); |
231 | } | 233 | } |
232 | 234 | ||
233 | 235 | ||
@@ -235,49 +237,49 @@ statistics_disconnect_adapter(void *cls, | |||
235 | * Function that gathers stats from all daemons. | 237 | * Function that gathers stats from all daemons. |
236 | */ | 238 | */ |
237 | static void | 239 | static void |
238 | stat_run(void *cls, | 240 | stat_run (void *cls, |
239 | struct GNUNET_TESTBED_Operation *op, | 241 | struct GNUNET_TESTBED_Operation *op, |
240 | void *ca_result, | 242 | void *ca_result, |
241 | const char *emsg) | 243 | const char *emsg) |
242 | { | 244 | { |
243 | struct StatMaster *sm = cls; | 245 | struct StatMaster *sm = cls; |
244 | 246 | ||
245 | sm->stat = ca_result; | 247 | sm->stat = ca_result; |
246 | GNUNET_assert(NULL != sm->stat); | 248 | GNUNET_assert (NULL != sm->stat); |
247 | if (NULL != stats[sm->value].name) | 249 | if (NULL != stats[sm->value].name) |
248 | { | 250 | { |
249 | GNUNET_STATISTICS_get(sm->stat, | 251 | GNUNET_STATISTICS_get (sm->stat, |
250 | #if 0 | 252 | #if 0 |
251 | NULL, NULL, | 253 | NULL, NULL, |
252 | #else | 254 | #else |
253 | stats[sm->value].subsystem, stats[sm->value].name, | 255 | stats[sm->value].subsystem, stats[sm->value].name, |
254 | #endif | 256 | #endif |
255 | &get_done, &print_stat, | 257 | &get_done, &print_stat, |
256 | sm); | 258 | sm); |
257 | return; | 259 | return; |
258 | } | 260 | } |
259 | GNUNET_TESTBED_operation_done(sm->op); | 261 | GNUNET_TESTBED_operation_done (sm->op); |
260 | sm->value = 0; | 262 | sm->value = 0; |
261 | sm->daemon++; | 263 | sm->daemon++; |
262 | if (NUM_DAEMONS == sm->daemon) | 264 | if (NUM_DAEMONS == sm->daemon) |
263 | { | 265 | { |
264 | GNUNET_free(sm); | 266 | GNUNET_free (sm); |
265 | cleanup(); | 267 | cleanup (); |
266 | return; | 268 | return; |
267 | } | 269 | } |
268 | sm->op = | 270 | sm->op = |
269 | GNUNET_TESTBED_service_connect(NULL, | 271 | GNUNET_TESTBED_service_connect (NULL, |
270 | daemons[sm->daemon], | 272 | daemons[sm->daemon], |
271 | "statistics", | 273 | "statistics", |
272 | &stat_run, sm, | 274 | &stat_run, sm, |
273 | &statistics_connect_adapter, | 275 | &statistics_connect_adapter, |
274 | &statistics_disconnect_adapter, | 276 | &statistics_disconnect_adapter, |
275 | NULL); | 277 | NULL); |
276 | } | 278 | } |
277 | 279 | ||
278 | 280 | ||
279 | static void | 281 | static void |
280 | do_report(void *cls) | 282 | do_report (void *cls) |
281 | { | 283 | { |
282 | static int download_counter; | 284 | static int download_counter; |
283 | const char *type = cls; | 285 | const char *type = cls; |
@@ -286,62 +288,63 @@ do_report(void *cls) | |||
286 | struct StatMaster *sm; | 288 | struct StatMaster *sm; |
287 | 289 | ||
288 | if (0 == | 290 | if (0 == |
289 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, | 291 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, |
290 | TIMEOUT)).rel_value_us) | 292 | TIMEOUT)). |
291 | { | 293 | rel_value_us) |
292 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 294 | { |
293 | "Timeout during download for type `%s', shutting down with error\n", | 295 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
294 | type); | 296 | "Timeout during download for type `%s', shutting down with error\n", |
295 | ok = 1; | 297 | type); |
296 | cleanup(); | 298 | ok = 1; |
297 | return; | 299 | cleanup (); |
298 | } | 300 | return; |
299 | del = GNUNET_TIME_absolute_get_duration(start_time); | 301 | } |
302 | del = GNUNET_TIME_absolute_get_duration (start_time); | ||
300 | if (del.rel_value_us == 0) | 303 | if (del.rel_value_us == 0) |
301 | del.rel_value_us = 1; | 304 | del.rel_value_us = 1; |
302 | fancy = | 305 | fancy = |
303 | GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * | 306 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) |
304 | 1000000LL / del.rel_value_us); | 307 | * 1000000LL / del.rel_value_us); |
305 | fprintf(stderr, "Download speed of type `%s' was %s/s\n", type, fancy); | 308 | fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy); |
306 | GNUNET_free(fancy); | 309 | GNUNET_free (fancy); |
307 | if (NUM_DAEMONS != ++download_counter) | 310 | if (NUM_DAEMONS != ++download_counter) |
308 | return; /* more downloads to come */ | 311 | return; /* more downloads to come */ |
309 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
310 | "Finished all downloads, getting statistics\n"); | 313 | "Finished all downloads, getting statistics\n"); |
311 | sm = GNUNET_new(struct StatMaster); | 314 | sm = GNUNET_new (struct StatMaster); |
312 | sm->op = | 315 | sm->op = |
313 | GNUNET_TESTBED_service_connect(NULL, | 316 | GNUNET_TESTBED_service_connect (NULL, |
314 | daemons[sm->daemon], | 317 | daemons[sm->daemon], |
315 | "statistics", | 318 | "statistics", |
316 | &stat_run, sm, | 319 | &stat_run, sm, |
317 | &statistics_connect_adapter, | 320 | &statistics_connect_adapter, |
318 | &statistics_disconnect_adapter, | 321 | &statistics_disconnect_adapter, |
319 | NULL); | 322 | NULL); |
320 | } | 323 | } |
321 | 324 | ||
322 | 325 | ||
323 | static void | 326 | static void |
324 | do_downloads(void *cls, const struct GNUNET_FS_Uri *u2, | 327 | do_downloads (void *cls, const struct GNUNET_FS_Uri *u2, |
325 | const char *fn) | 328 | const char *fn) |
326 | { | 329 | { |
327 | int anonymity; | 330 | int anonymity; |
328 | unsigned int i; | 331 | unsigned int i; |
329 | 332 | ||
330 | if (NULL == u2) | 333 | if (NULL == u2) |
331 | { | 334 | { |
332 | cleanup(); | 335 | cleanup (); |
333 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 336 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
334 | "Timeout during upload attempt, shutting down with error\n"); | 337 | "Timeout during upload attempt, shutting down with error\n"); |
335 | ok = 1; | 338 | ok = 1; |
336 | return; | 339 | return; |
337 | } | 340 | } |
338 | if (NULL != fn) | 341 | if (NULL != fn) |
339 | fn2 = GNUNET_strdup(fn); | 342 | fn2 = GNUNET_strdup (fn); |
340 | uri2 = GNUNET_FS_uri_dup(u2); | 343 | uri2 = GNUNET_FS_uri_dup (u2); |
341 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", | 344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", |
342 | (unsigned long long)FILESIZE); | 345 | (unsigned long long) FILESIZE); |
343 | start_time = GNUNET_TIME_absolute_get(); | 346 | start_time = GNUNET_TIME_absolute_get (); |
344 | if (NULL != strstr(progname, "dht")) | 347 | if (NULL != strstr (progname, "dht")) |
345 | anonymity = 0; | 348 | anonymity = 0; |
346 | else | 349 | else |
347 | anonymity = 1; | 350 | anonymity = 1; |
@@ -349,127 +352,127 @@ do_downloads(void *cls, const struct GNUNET_FS_Uri *u2, | |||
349 | * these peers do participate in sharing, they just | 352 | * these peers do participate in sharing, they just |
350 | * don't have to offer anything *initially*. */ | 353 | * don't have to offer anything *initially*. */ |
351 | for (i = 0; i < NUM_DAEMONS - 2; i++) | 354 | for (i = 0; i < NUM_DAEMONS - 2; i++) |
352 | GNUNET_FS_TEST_download(daemons[i], TIMEOUT, anonymity, | 355 | GNUNET_FS_TEST_download (daemons[i], TIMEOUT, anonymity, |
353 | 0 == (i % 2) ? SEED1 : SEED2, | 356 | 0 == (i % 2) ? SEED1 : SEED2, |
354 | 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report, | 357 | 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report, |
355 | "leach"); | 358 | "leach"); |
356 | /* mutual downloads of (primary) sharing peers */ | 359 | /* mutual downloads of (primary) sharing peers */ |
357 | GNUNET_FS_TEST_download(daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1, | 360 | GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1, |
358 | uri1, VERBOSE, &do_report, "seeder 2"); | 361 | uri1, VERBOSE, &do_report, "seeder 2"); |
359 | GNUNET_FS_TEST_download(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2, | 362 | GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2, |
360 | uri2, VERBOSE, &do_report, "seeder 1"); | 363 | uri2, VERBOSE, &do_report, "seeder 1"); |
361 | } | 364 | } |
362 | 365 | ||
363 | 366 | ||
364 | static void | 367 | static void |
365 | do_publish2(void *cls, | 368 | do_publish2 (void *cls, |
366 | const struct GNUNET_FS_Uri *u1, | 369 | const struct GNUNET_FS_Uri *u1, |
367 | const char *fn) | 370 | const char *fn) |
368 | { | 371 | { |
369 | int do_index; | 372 | int do_index; |
370 | int anonymity; | 373 | int anonymity; |
371 | 374 | ||
372 | if (NULL == u1) | 375 | if (NULL == u1) |
373 | { | 376 | { |
374 | cleanup(); | 377 | cleanup (); |
375 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 378 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
376 | "Timeout during upload attempt, shutting down with error\n"); | 379 | "Timeout during upload attempt, shutting down with error\n"); |
377 | ok = 1; | 380 | ok = 1; |
378 | return; | 381 | return; |
379 | } | 382 | } |
380 | if (NULL != fn) | 383 | if (NULL != fn) |
381 | fn1 = GNUNET_strdup(fn); | 384 | fn1 = GNUNET_strdup (fn); |
382 | uri1 = GNUNET_FS_uri_dup(u1); | 385 | uri1 = GNUNET_FS_uri_dup (u1); |
383 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
384 | (unsigned long long)FILESIZE); | 387 | (unsigned long long) FILESIZE); |
385 | if (NULL != strstr(progname, "index")) | 388 | if (NULL != strstr (progname, "index")) |
386 | do_index = GNUNET_YES; | 389 | do_index = GNUNET_YES; |
387 | else | 390 | else |
388 | do_index = GNUNET_NO; | 391 | do_index = GNUNET_NO; |
389 | if (NULL != strstr(progname, "dht")) | 392 | if (NULL != strstr (progname, "dht")) |
390 | anonymity = 0; | 393 | anonymity = 0; |
391 | else | 394 | else |
392 | anonymity = 1; | 395 | anonymity = 1; |
393 | 396 | ||
394 | GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, | 397 | GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, |
395 | do_index, FILESIZE, SEED2, VERBOSE, &do_downloads, | 398 | do_index, FILESIZE, SEED2, VERBOSE, &do_downloads, |
396 | NULL); | 399 | NULL); |
397 | } | 400 | } |
398 | 401 | ||
399 | 402 | ||
400 | static void | 403 | static void |
401 | do_publish1(void *cls, | 404 | do_publish1 (void *cls, |
402 | struct GNUNET_TESTBED_Operation *op, | 405 | struct GNUNET_TESTBED_Operation *op, |
403 | const char *emsg) | 406 | const char *emsg) |
404 | { | 407 | { |
405 | unsigned int *coco = cls; | 408 | unsigned int *coco = cls; |
406 | int do_index; | 409 | int do_index; |
407 | int anonymity; | 410 | int anonymity; |
408 | 411 | ||
409 | GNUNET_TESTBED_operation_done(op); | 412 | GNUNET_TESTBED_operation_done (op); |
410 | if (NULL != emsg) | 413 | if (NULL != emsg) |
411 | { | 414 | { |
412 | cleanup(); | 415 | cleanup (); |
413 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); | 416 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg); |
414 | ok = 1; | 417 | ok = 1; |
415 | return; | 418 | return; |
416 | } | 419 | } |
417 | if (0 != (--(*coco))) | 420 | if (0 != (--(*coco))) |
418 | return; /* more connections to be created */ | 421 | return; /* more connections to be created */ |
419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
420 | (unsigned long long)FILESIZE); | 423 | (unsigned long long) FILESIZE); |
421 | if (NULL != strstr(progname, "index")) | 424 | if (NULL != strstr (progname, "index")) |
422 | do_index = GNUNET_YES; | 425 | do_index = GNUNET_YES; |
423 | else | 426 | else |
424 | do_index = GNUNET_NO; | 427 | do_index = GNUNET_NO; |
425 | if (NULL != strstr(progname, "dht")) | 428 | if (NULL != strstr (progname, "dht")) |
426 | anonymity = 0; | 429 | anonymity = 0; |
427 | else | 430 | else |
428 | anonymity = 1; | 431 | anonymity = 1; |
429 | GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, | 432 | GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, |
430 | do_index, FILESIZE, SEED1, VERBOSE, &do_publish2, | 433 | do_index, FILESIZE, SEED1, VERBOSE, &do_publish2, |
431 | NULL); | 434 | NULL); |
432 | } | 435 | } |
433 | 436 | ||
434 | 437 | ||
435 | static void | 438 | static void |
436 | do_connect(void *cls, | 439 | do_connect (void *cls, |
437 | struct GNUNET_TESTBED_RunHandle *h, | 440 | struct GNUNET_TESTBED_RunHandle *h, |
438 | unsigned int num_peers, | 441 | unsigned int num_peers, |
439 | struct GNUNET_TESTBED_Peer **peers, | 442 | struct GNUNET_TESTBED_Peer **peers, |
440 | unsigned int links_succeeded, | 443 | unsigned int links_succeeded, |
441 | unsigned int links_failed) | 444 | unsigned int links_failed) |
442 | { | 445 | { |
443 | static unsigned int coco; | 446 | static unsigned int coco; |
444 | unsigned int i; | 447 | unsigned int i; |
445 | unsigned int j; | 448 | unsigned int j; |
446 | 449 | ||
447 | GNUNET_assert(NUM_DAEMONS == num_peers); | 450 | GNUNET_assert (NUM_DAEMONS == num_peers); |
448 | for (i = 0; i < num_peers; i++) | 451 | for (i = 0; i < num_peers; i++) |
449 | daemons[i] = peers[i]; | 452 | daemons[i] = peers[i]; |
450 | for (i = 0; i < NUM_DAEMONS; i++) | 453 | for (i = 0; i < NUM_DAEMONS; i++) |
451 | for (j = i + 1; j < NUM_DAEMONS; j++) | 454 | for (j = i + 1; j < NUM_DAEMONS; j++) |
452 | { | 455 | { |
453 | coco++; | 456 | coco++; |
454 | GNUNET_TESTBED_overlay_connect(NULL, | 457 | GNUNET_TESTBED_overlay_connect (NULL, |
455 | &do_publish1, | 458 | &do_publish1, |
456 | &coco, | 459 | &coco, |
457 | peers[i], | 460 | peers[i], |
458 | peers[j]); | 461 | peers[j]); |
459 | } | 462 | } |
460 | } | 463 | } |
461 | 464 | ||
462 | 465 | ||
463 | int | 466 | int |
464 | main(int argc, char *argv[]) | 467 | main (int argc, char *argv[]) |
465 | { | 468 | { |
466 | progname = argv[0]; | 469 | progname = argv[0]; |
467 | (void)GNUNET_TESTBED_test_run("perf-gnunet-service-fs-p2p-respect", | 470 | (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p-respect", |
468 | "perf_gnunet_service_fs_p2p.conf", | 471 | "perf_gnunet_service_fs_p2p.conf", |
469 | NUM_DAEMONS, | 472 | NUM_DAEMONS, |
470 | 0, NULL, NULL, | 473 | 0, NULL, NULL, |
471 | &do_connect, NULL); | 474 | &do_connect, NULL); |
472 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); | 475 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
473 | return ok; | 476 | return ok; |
474 | } | 477 | } |
475 | 478 | ||
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index 8003e3837..e5ea91c98 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c | |||
@@ -51,61 +51,62 @@ | |||
51 | * by this @a type of block (this is not an error) | 51 | * by this @a type of block (this is not an error) |
52 | */ | 52 | */ |
53 | static struct GNUNET_BLOCK_Group * | 53 | static struct GNUNET_BLOCK_Group * |
54 | block_plugin_fs_create_group(void *cls, | 54 | block_plugin_fs_create_group (void *cls, |
55 | enum GNUNET_BLOCK_Type type, | 55 | enum GNUNET_BLOCK_Type type, |
56 | uint32_t nonce, | 56 | uint32_t nonce, |
57 | const void *raw_data, | 57 | const void *raw_data, |
58 | size_t raw_data_size, | 58 | size_t raw_data_size, |
59 | va_list va) | 59 | va_list va) |
60 | { | 60 | { |
61 | unsigned int size; | 61 | unsigned int size; |
62 | const char *guard; | 62 | const char *guard; |
63 | 63 | ||
64 | switch (type) | 64 | switch (type) |
65 | { | 65 | { |
66 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | 66 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
67 | GNUNET_break(NULL == va_arg(va, const char *)); | 67 | GNUNET_break (NULL == va_arg (va, const char *)); |
68 | return NULL; | 68 | return NULL; |
69 | |||
70 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
71 | GNUNET_break(NULL == va_arg(va, const char *)); | ||
72 | return NULL; | ||
73 | 69 | ||
74 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | 70 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
75 | guard = va_arg(va, const char *); | 71 | GNUNET_break (NULL == va_arg (va, const char *)); |
76 | if (0 == strcmp(guard, | 72 | return NULL; |
77 | "seen-set-size")) | ||
78 | { | ||
79 | size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), | ||
80 | BLOOMFILTER_K); | ||
81 | } | ||
82 | else if (0 == strcmp(guard, | ||
83 | "filter-size")) | ||
84 | { | ||
85 | size = va_arg(va, unsigned int); | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | /* va-args invalid! bad bug, complain! */ | ||
90 | GNUNET_break(0); | ||
91 | size = 8; | ||
92 | } | ||
93 | if (0 == size) | ||
94 | size = raw_data_size; /* not for us to determine, use what we got! */ | ||
95 | GNUNET_break(NULL == va_arg(va, const char *)); | ||
96 | return GNUNET_BLOCK_GROUP_bf_create(cls, | ||
97 | size, | ||
98 | BLOOMFILTER_K, | ||
99 | type, | ||
100 | nonce, | ||
101 | raw_data, | ||
102 | raw_data_size); | ||
103 | 73 | ||
104 | default: | 74 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
105 | GNUNET_break(NULL == va_arg(va, const char *)); | 75 | guard = va_arg (va, const char *); |
106 | GNUNET_break(0); | 76 | if (0 == strcmp (guard, |
107 | return NULL; | 77 | "seen-set-size")) |
78 | { | ||
79 | size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned | ||
80 | int), | ||
81 | BLOOMFILTER_K); | ||
82 | } | ||
83 | else if (0 == strcmp (guard, | ||
84 | "filter-size")) | ||
85 | { | ||
86 | size = va_arg (va, unsigned int); | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | /* va-args invalid! bad bug, complain! */ | ||
91 | GNUNET_break (0); | ||
92 | size = 8; | ||
108 | } | 93 | } |
94 | if (0 == size) | ||
95 | size = raw_data_size; /* not for us to determine, use what we got! */ | ||
96 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
97 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
98 | size, | ||
99 | BLOOMFILTER_K, | ||
100 | type, | ||
101 | nonce, | ||
102 | raw_data, | ||
103 | raw_data_size); | ||
104 | |||
105 | default: | ||
106 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
107 | GNUNET_break (0); | ||
108 | return NULL; | ||
109 | } | ||
109 | } | 110 | } |
110 | 111 | ||
111 | 112 | ||
@@ -129,86 +130,87 @@ block_plugin_fs_create_group(void *cls, | |||
129 | * @return characterization of result | 130 | * @return characterization of result |
130 | */ | 131 | */ |
131 | static enum GNUNET_BLOCK_EvaluationResult | 132 | static enum GNUNET_BLOCK_EvaluationResult |
132 | block_plugin_fs_evaluate(void *cls, | 133 | block_plugin_fs_evaluate (void *cls, |
133 | struct GNUNET_BLOCK_Context *ctx, | 134 | struct GNUNET_BLOCK_Context *ctx, |
134 | enum GNUNET_BLOCK_Type type, | 135 | enum GNUNET_BLOCK_Type type, |
135 | struct GNUNET_BLOCK_Group *bg, | 136 | struct GNUNET_BLOCK_Group *bg, |
136 | enum GNUNET_BLOCK_EvaluationOptions eo, | 137 | enum GNUNET_BLOCK_EvaluationOptions eo, |
137 | const struct GNUNET_HashCode *query, | 138 | const struct GNUNET_HashCode *query, |
138 | const void *xquery, | 139 | const void *xquery, |
139 | size_t xquery_size, | 140 | size_t xquery_size, |
140 | const void *reply_block, | 141 | const void *reply_block, |
141 | size_t reply_block_size) | 142 | size_t reply_block_size) |
142 | { | 143 | { |
143 | const struct UBlock *ub; | 144 | const struct UBlock *ub; |
144 | struct GNUNET_HashCode hc; | 145 | struct GNUNET_HashCode hc; |
145 | struct GNUNET_HashCode chash; | 146 | struct GNUNET_HashCode chash; |
146 | 147 | ||
147 | switch (type) | 148 | switch (type) |
149 | { | ||
150 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
151 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
152 | if (0 != xquery_size) | ||
148 | { | 153 | { |
149 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | 154 | GNUNET_break_op (0); |
150 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | 155 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; |
151 | if (0 != xquery_size) | 156 | } |
152 | { | 157 | if (NULL == reply_block) |
153 | GNUNET_break_op(0); | 158 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
154 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 159 | return GNUNET_BLOCK_EVALUATION_OK_LAST; |
155 | } | ||
156 | if (NULL == reply_block) | ||
157 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
158 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
159 | |||
160 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
161 | if (0 != xquery_size) | ||
162 | { | ||
163 | GNUNET_break_op(0); | ||
164 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
165 | } | ||
166 | if (NULL == reply_block) | ||
167 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
168 | 160 | ||
169 | if (reply_block_size < sizeof(struct UBlock)) | 161 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
170 | { | 162 | if (0 != xquery_size) |
171 | GNUNET_break_op(0); | 163 | { |
172 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 164 | GNUNET_break_op (0); |
173 | } | 165 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; |
174 | ub = reply_block; | 166 | } |
175 | GNUNET_CRYPTO_hash(&ub->verification_key, | 167 | if (NULL == reply_block) |
176 | sizeof(ub->verification_key), | 168 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
177 | &hc); | ||
178 | if (0 != memcmp(&hc, | ||
179 | query, | ||
180 | sizeof(struct GNUNET_HashCode))) | ||
181 | { | ||
182 | GNUNET_break_op(0); | ||
183 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
184 | } | ||
185 | if (reply_block_size != ntohl(ub->purpose.size) + sizeof(struct GNUNET_CRYPTO_EcdsaSignature)) | ||
186 | { | ||
187 | GNUNET_break_op(0); | ||
188 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
189 | } | ||
190 | if ((0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) && | ||
191 | (GNUNET_OK != | ||
192 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, | ||
193 | &ub->purpose, | ||
194 | &ub->signature, | ||
195 | &ub->verification_key))) | ||
196 | { | ||
197 | GNUNET_break_op(0); | ||
198 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
199 | } | ||
200 | GNUNET_CRYPTO_hash(reply_block, | ||
201 | reply_block_size, | ||
202 | &chash); | ||
203 | if (GNUNET_YES == | ||
204 | GNUNET_BLOCK_GROUP_bf_test_and_set(bg, | ||
205 | &chash)) | ||
206 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
207 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
208 | 169 | ||
209 | default: | 170 | if (reply_block_size < sizeof(struct UBlock)) |
210 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 171 | { |
172 | GNUNET_break_op (0); | ||
173 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
174 | } | ||
175 | ub = reply_block; | ||
176 | GNUNET_CRYPTO_hash (&ub->verification_key, | ||
177 | sizeof(ub->verification_key), | ||
178 | &hc); | ||
179 | if (0 != memcmp (&hc, | ||
180 | query, | ||
181 | sizeof(struct GNUNET_HashCode))) | ||
182 | { | ||
183 | GNUNET_break_op (0); | ||
184 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
185 | } | ||
186 | if (reply_block_size != ntohl (ub->purpose.size) + sizeof(struct | ||
187 | GNUNET_CRYPTO_EcdsaSignature)) | ||
188 | { | ||
189 | GNUNET_break_op (0); | ||
190 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
191 | } | ||
192 | if ((0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) && | ||
193 | (GNUNET_OK != | ||
194 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, | ||
195 | &ub->purpose, | ||
196 | &ub->signature, | ||
197 | &ub->verification_key))) | ||
198 | { | ||
199 | GNUNET_break_op (0); | ||
200 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
211 | } | 201 | } |
202 | GNUNET_CRYPTO_hash (reply_block, | ||
203 | reply_block_size, | ||
204 | &chash); | ||
205 | if (GNUNET_YES == | ||
206 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
207 | &chash)) | ||
208 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
209 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
210 | |||
211 | default: | ||
212 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
213 | } | ||
212 | } | 214 | } |
213 | 215 | ||
214 | 216 | ||
@@ -224,37 +226,37 @@ block_plugin_fs_evaluate(void *cls, | |||
224 | * (or if extracting a key from a block of this type does not work) | 226 | * (or if extracting a key from a block of this type does not work) |
225 | */ | 227 | */ |
226 | static int | 228 | static int |
227 | block_plugin_fs_get_key(void *cls, | 229 | block_plugin_fs_get_key (void *cls, |
228 | enum GNUNET_BLOCK_Type type, | 230 | enum GNUNET_BLOCK_Type type, |
229 | const void *block, | 231 | const void *block, |
230 | size_t block_size, | 232 | size_t block_size, |
231 | struct GNUNET_HashCode *key) | 233 | struct GNUNET_HashCode *key) |
232 | { | 234 | { |
233 | const struct UBlock *ub; | 235 | const struct UBlock *ub; |
234 | 236 | ||
235 | switch (type) | 237 | switch (type) |
236 | { | 238 | { |
237 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | 239 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
238 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | 240 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
239 | GNUNET_CRYPTO_hash(block, block_size, key); | 241 | GNUNET_CRYPTO_hash (block, block_size, key); |
240 | return GNUNET_OK; | 242 | return GNUNET_OK; |
241 | |||
242 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
243 | if (block_size < sizeof(struct UBlock)) | ||
244 | { | ||
245 | GNUNET_break(0); | ||
246 | return GNUNET_SYSERR; | ||
247 | } | ||
248 | ub = block; | ||
249 | GNUNET_CRYPTO_hash(&ub->verification_key, | ||
250 | sizeof(ub->verification_key), | ||
251 | key); | ||
252 | return GNUNET_OK; | ||
253 | 243 | ||
254 | default: | 244 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
255 | GNUNET_break(0); | 245 | if (block_size < sizeof(struct UBlock)) |
246 | { | ||
247 | GNUNET_break (0); | ||
256 | return GNUNET_SYSERR; | 248 | return GNUNET_SYSERR; |
257 | } | 249 | } |
250 | ub = block; | ||
251 | GNUNET_CRYPTO_hash (&ub->verification_key, | ||
252 | sizeof(ub->verification_key), | ||
253 | key); | ||
254 | return GNUNET_OK; | ||
255 | |||
256 | default: | ||
257 | GNUNET_break (0); | ||
258 | return GNUNET_SYSERR; | ||
259 | } | ||
258 | } | 260 | } |
259 | 261 | ||
260 | 262 | ||
@@ -262,10 +264,9 @@ block_plugin_fs_get_key(void *cls, | |||
262 | * Entry point for the plugin. | 264 | * Entry point for the plugin. |
263 | */ | 265 | */ |
264 | void * | 266 | void * |
265 | libgnunet_plugin_block_fs_init(void *cls) | 267 | libgnunet_plugin_block_fs_init (void *cls) |
266 | { | 268 | { |
267 | static enum GNUNET_BLOCK_Type types[] = | 269 | static enum GNUNET_BLOCK_Type types[] = { |
268 | { | ||
269 | GNUNET_BLOCK_TYPE_FS_DBLOCK, | 270 | GNUNET_BLOCK_TYPE_FS_DBLOCK, |
270 | GNUNET_BLOCK_TYPE_FS_IBLOCK, | 271 | GNUNET_BLOCK_TYPE_FS_IBLOCK, |
271 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | 272 | GNUNET_BLOCK_TYPE_FS_UBLOCK, |
@@ -273,7 +274,7 @@ libgnunet_plugin_block_fs_init(void *cls) | |||
273 | }; | 274 | }; |
274 | struct GNUNET_BLOCK_PluginFunctions *api; | 275 | struct GNUNET_BLOCK_PluginFunctions *api; |
275 | 276 | ||
276 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); | 277 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
277 | api->evaluate = &block_plugin_fs_evaluate; | 278 | api->evaluate = &block_plugin_fs_evaluate; |
278 | api->get_key = &block_plugin_fs_get_key; | 279 | api->get_key = &block_plugin_fs_get_key; |
279 | api->create_group = &block_plugin_fs_create_group; | 280 | api->create_group = &block_plugin_fs_create_group; |
@@ -286,11 +287,11 @@ libgnunet_plugin_block_fs_init(void *cls) | |||
286 | * Exit point from the plugin. | 287 | * Exit point from the plugin. |
287 | */ | 288 | */ |
288 | void * | 289 | void * |
289 | libgnunet_plugin_block_fs_done(void *cls) | 290 | libgnunet_plugin_block_fs_done (void *cls) |
290 | { | 291 | { |
291 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 292 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
292 | 293 | ||
293 | GNUNET_free(api); | 294 | GNUNET_free (api); |
294 | return NULL; | 295 | return NULL; |
295 | } | 296 | } |
296 | 297 | ||
diff --git a/src/fs/test_fs.c b/src/fs/test_fs.c index e88bacf59..73de7b204 100644 --- a/src/fs/test_fs.c +++ b/src/fs/test_fs.c | |||
@@ -30,19 +30,20 @@ | |||
30 | 30 | ||
31 | #define DEBUG_VERBOSE GNUNET_NO | 31 | #define DEBUG_VERBOSE GNUNET_NO |
32 | 32 | ||
33 | #define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto FAILURE; } | 33 | #define CHECK(a) if (! (a)) { ok = GNUNET_NO; GNUNET_GE_BREAK (NULL, 0); \ |
34 | goto FAILURE; } | ||
34 | 35 | ||
35 | static char * | 36 | static char * |
36 | makeName(unsigned int i) | 37 | makeName (unsigned int i) |
37 | { | 38 | { |
38 | char *fn; | 39 | char *fn; |
39 | 40 | ||
40 | fn = GNUNET_malloc(strlen("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + | 41 | fn = GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") |
41 | 14); | 42 | + 14); |
42 | GNUNET_snprintf(fn, | 43 | GNUNET_snprintf (fn, |
43 | strlen("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 14, | 44 | strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 14, |
44 | "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i); | 45 | "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i); |
45 | GNUNET_disk_directory_create_for_file(NULL, fn); | 46 | GNUNET_disk_directory_create_for_file (NULL, fn); |
46 | return fn; | 47 | return fn; |
47 | } | 48 | } |
48 | 49 | ||
@@ -55,47 +56,47 @@ static struct GNUNET_ECRS_URI *search_uri; | |||
55 | static struct GNUNET_FSUI_Context *ctx; | 56 | static struct GNUNET_FSUI_Context *ctx; |
56 | 57 | ||
57 | static void * | 58 | static void * |
58 | eventCallback(void *cls, const GNUNET_FSUI_Event * event) | 59 | eventCallback (void *cls, const GNUNET_FSUI_Event *event) |
59 | { | 60 | { |
60 | static char unused; | 61 | static char unused; |
61 | 62 | ||
62 | switch (event->type) | 63 | switch (event->type) |
63 | { | 64 | { |
64 | case GNUNET_FSUI_search_resumed: | 65 | case GNUNET_FSUI_search_resumed: |
65 | case GNUNET_FSUI_download_resumed: | 66 | case GNUNET_FSUI_download_resumed: |
66 | case GNUNET_FSUI_upload_resumed: | 67 | case GNUNET_FSUI_upload_resumed: |
67 | case GNUNET_FSUI_unindex_resumed: | 68 | case GNUNET_FSUI_unindex_resumed: |
68 | return &unused; | 69 | return &unused; |
69 | 70 | ||
70 | case GNUNET_FSUI_search_result: | 71 | case GNUNET_FSUI_search_result: |
71 | #if DEBUG_VERBOSE | 72 | #if DEBUG_VERBOSE |
72 | printf("Received search result\n"); | 73 | printf ("Received search result\n"); |
73 | #endif | 74 | #endif |
74 | search_uri = GNUNET_ECRS_uri_duplicate(event->data.SearchResult.fi.uri); | 75 | search_uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri); |
75 | search_meta = GNUNET_meta_data_duplicate(event->data.SearchResult.fi.meta); | 76 | search_meta = GNUNET_meta_data_duplicate (event->data.SearchResult.fi.meta); |
76 | break; | 77 | break; |
77 | 78 | ||
78 | case GNUNET_FSUI_upload_completed: | 79 | case GNUNET_FSUI_upload_completed: |
79 | #if DEBUG_VERBOSE | 80 | #if DEBUG_VERBOSE |
80 | printf("Upload complete.\n"); | 81 | printf ("Upload complete.\n"); |
81 | #endif | 82 | #endif |
82 | break; | 83 | break; |
83 | 84 | ||
84 | case GNUNET_FSUI_download_completed: | 85 | case GNUNET_FSUI_download_completed: |
85 | #if DEBUG_VERBOSE | 86 | #if DEBUG_VERBOSE |
86 | printf("Download complete.\n"); | 87 | printf ("Download complete.\n"); |
87 | #endif | 88 | #endif |
88 | break; | 89 | break; |
89 | 90 | ||
90 | case GNUNET_FSUI_unindex_completed: | 91 | case GNUNET_FSUI_unindex_completed: |
91 | #if DEBUG_VERBOSE | 92 | #if DEBUG_VERBOSE |
92 | printf("Unindex complete.\n"); | 93 | printf ("Unindex complete.\n"); |
93 | #endif | 94 | #endif |
94 | break; | 95 | break; |
95 | 96 | ||
96 | default: | 97 | default: |
97 | break; | 98 | break; |
98 | } | 99 | } |
99 | lastEvent = event->type; | 100 | lastEvent = event->type; |
100 | return NULL; | 101 | return NULL; |
101 | } | 102 | } |
@@ -103,7 +104,7 @@ eventCallback(void *cls, const GNUNET_FSUI_Event * event) | |||
103 | #define START_DAEMON 1 | 104 | #define START_DAEMON 1 |
104 | 105 | ||
105 | int | 106 | int |
106 | main(int argc, char *argv[]) | 107 | main (int argc, char *argv[]) |
107 | { | 108 | { |
108 | #if START_DAEMON | 109 | #if START_DAEMON |
109 | struct GNUNET_OS_Process *daemon; | 110 | struct GNUNET_OS_Process *daemon; |
@@ -127,128 +128,130 @@ main(int argc, char *argv[]) | |||
127 | struct GNUNET_FSUI_UnindexList *unindex = NULL; | 128 | struct GNUNET_FSUI_UnindexList *unindex = NULL; |
128 | struct GNUNET_FSUI_DownloadList *download = NULL; | 129 | struct GNUNET_FSUI_DownloadList *download = NULL; |
129 | 130 | ||
130 | cfg = GNUNET_GC_create(); | 131 | cfg = GNUNET_GC_create (); |
131 | if (-1 == GNUNET_GC_parse_configuration(cfg, "check.conf")) | 132 | if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) |
132 | { | 133 | { |
133 | GNUNET_GC_free(cfg); | 134 | GNUNET_GC_free (cfg); |
134 | return -1; | 135 | return -1; |
135 | } | 136 | } |
136 | #if START_DAEMON | 137 | #if START_DAEMON |
137 | daemon = GNUNET_daemon_start(NULL, cfg, "peer.conf", GNUNET_NO); | 138 | daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); |
138 | GNUNET_GE_ASSERT(NULL, daemon != NULL); | 139 | GNUNET_GE_ASSERT (NULL, daemon != NULL); |
139 | CHECK(GNUNET_OK == | 140 | CHECK (GNUNET_OK == |
140 | GNUNET_wait_for_daemon_running(NULL, cfg, 60 * GNUNET_CRON_SECONDS)); | 141 | GNUNET_wait_for_daemon_running (NULL, cfg, 60 * GNUNET_CRON_SECONDS)); |
141 | #endif | 142 | #endif |
142 | GNUNET_thread_sleep(5 * GNUNET_CRON_SECONDS); /* give apps time to start */ | 143 | GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ |
143 | ok = GNUNET_YES; | 144 | ok = GNUNET_YES; |
144 | 145 | ||
145 | /* ACTUAL TEST CODE */ | 146 | /* ACTUAL TEST CODE */ |
146 | ctx = GNUNET_FSUI_start(NULL, cfg, "basic_fsui_test", 32, /* thread pool size */ | 147 | ctx = GNUNET_FSUI_start (NULL, cfg, "basic_fsui_test", 32, /* thread pool size */ |
147 | GNUNET_NO, /* no resume */ | 148 | GNUNET_NO, /* no resume */ |
148 | &eventCallback, NULL); | 149 | &eventCallback, NULL); |
149 | CHECK(ctx != NULL); | 150 | CHECK (ctx != NULL); |
150 | filename = makeName(42); | 151 | filename = makeName (42); |
151 | GNUNET_disk_file_write(NULL, filename, "foo bar test!", | 152 | GNUNET_disk_file_write (NULL, filename, "foo bar test!", |
152 | strlen("foo bar test!"), "600"); | 153 | strlen ("foo bar test!"), "600"); |
153 | meta = GNUNET_meta_data_create(); | 154 | meta = GNUNET_meta_data_create (); |
154 | kuri = | 155 | kuri = |
155 | GNUNET_ECRS_keyword_command_line_to_uri(NULL, 2, | 156 | GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2, |
156 | (const char **)keywords); | 157 | (const char **) keywords); |
157 | /* upload */ | 158 | /* upload */ |
158 | upload = GNUNET_FSUI_upload_start(ctx, filename, (GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */ | 159 | upload = GNUNET_FSUI_upload_start (ctx, filename, |
159 | 0, /* priority */ | 160 | (GNUNET_FSUI_DirectoryScanCallback) |
160 | GNUNET_YES, GNUNET_NO, GNUNET_NO, | 161 | & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */ |
161 | GNUNET_get_time() + 5 * GNUNET_CRON_HOURS, | 162 | 0, /* priority */ |
162 | meta, kuri, kuri); | 163 | GNUNET_YES, GNUNET_NO, GNUNET_NO, |
163 | CHECK(upload != NULL); | 164 | GNUNET_get_time () + 5 * GNUNET_CRON_HOURS, |
164 | GNUNET_ECRS_uri_destroy(kuri); | 165 | meta, kuri, kuri); |
165 | GNUNET_meta_data_destroy(meta); | 166 | CHECK (upload != NULL); |
167 | GNUNET_ECRS_uri_destroy (kuri); | ||
168 | GNUNET_meta_data_destroy (meta); | ||
166 | prog = 0; | 169 | prog = 0; |
167 | while (lastEvent != GNUNET_FSUI_upload_completed) | 170 | while (lastEvent != GNUNET_FSUI_upload_completed) |
168 | { | 171 | { |
169 | prog++; | 172 | prog++; |
170 | CHECK(prog < 10000) GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); | 173 | CHECK (prog < 10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); |
171 | if (GNUNET_shutdown_test() == GNUNET_YES) | 174 | if (GNUNET_shutdown_test () == GNUNET_YES) |
172 | break; | 175 | break; |
173 | } | 176 | } |
174 | 177 | ||
175 | /* search */ | 178 | /* search */ |
176 | GNUNET_snprintf(keyword, 40, "+%s +%s", keywords[0], keywords[1]); | 179 | GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]); |
177 | uri = GNUNET_ECRS_keyword_string_to_uri(NULL, keyword); | 180 | uri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword); |
178 | search = GNUNET_FSUI_search_start(ctx, 0, uri); | 181 | search = GNUNET_FSUI_search_start (ctx, 0, uri); |
179 | GNUNET_ECRS_uri_destroy(uri); | 182 | GNUNET_ECRS_uri_destroy (uri); |
180 | CHECK(search != NULL); | 183 | CHECK (search != NULL); |
181 | prog = 0; | 184 | prog = 0; |
182 | while (lastEvent != GNUNET_FSUI_search_result) | 185 | while (lastEvent != GNUNET_FSUI_search_result) |
183 | { | 186 | { |
184 | prog++; | 187 | prog++; |
185 | CHECK(prog < 10000); | 188 | CHECK (prog < 10000); |
186 | GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); | 189 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); |
187 | if (GNUNET_shutdown_test() == GNUNET_YES) | 190 | if (GNUNET_shutdown_test () == GNUNET_YES) |
188 | break; | 191 | break; |
189 | } | 192 | } |
190 | GNUNET_FSUI_search_abort(search); | 193 | GNUNET_FSUI_search_abort (search); |
191 | GNUNET_FSUI_search_stop(search); | 194 | GNUNET_FSUI_search_stop (search); |
192 | 195 | ||
193 | /* download */ | 196 | /* download */ |
194 | fn = makeName(43); | 197 | fn = makeName (43); |
195 | download = | 198 | download = |
196 | GNUNET_FSUI_download_start(ctx, 0, GNUNET_NO, search_uri, search_meta, | 199 | GNUNET_FSUI_download_start (ctx, 0, GNUNET_NO, search_uri, search_meta, |
197 | fn, NULL, NULL); | 200 | fn, NULL, NULL); |
198 | GNUNET_free(fn); | 201 | GNUNET_free (fn); |
199 | prog = 0; | 202 | prog = 0; |
200 | while (lastEvent != GNUNET_FSUI_download_completed) | 203 | while (lastEvent != GNUNET_FSUI_download_completed) |
201 | { | 204 | { |
202 | prog++; | 205 | prog++; |
203 | CHECK(prog < 10000); | 206 | CHECK (prog < 10000); |
204 | GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); | 207 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); |
205 | if (GNUNET_shutdown_test() == GNUNET_YES) | 208 | if (GNUNET_shutdown_test () == GNUNET_YES) |
206 | break; | 209 | break; |
207 | } | 210 | } |
208 | GNUNET_FSUI_download_stop(download); | 211 | GNUNET_FSUI_download_stop (download); |
209 | download = NULL; | 212 | download = NULL; |
210 | GNUNET_ECRS_uri_destroy(search_uri); | 213 | GNUNET_ECRS_uri_destroy (search_uri); |
211 | GNUNET_meta_data_destroy(search_meta); | 214 | GNUNET_meta_data_destroy (search_meta); |
212 | /* unindex */ | 215 | /* unindex */ |
213 | unindex = GNUNET_FSUI_unindex_start(ctx, filename); | 216 | unindex = GNUNET_FSUI_unindex_start (ctx, filename); |
214 | prog = 0; | 217 | prog = 0; |
215 | while (lastEvent != GNUNET_FSUI_unindex_completed) | 218 | while (lastEvent != GNUNET_FSUI_unindex_completed) |
216 | { | 219 | { |
217 | prog++; | 220 | prog++; |
218 | CHECK(prog < 10000); | 221 | CHECK (prog < 10000); |
219 | GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS); | 222 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); |
220 | if (GNUNET_shutdown_test() == GNUNET_YES) | 223 | if (GNUNET_shutdown_test () == GNUNET_YES) |
221 | break; | 224 | break; |
222 | } | 225 | } |
223 | if (lastEvent != GNUNET_FSUI_unindex_completed) | 226 | if (lastEvent != GNUNET_FSUI_unindex_completed) |
224 | GNUNET_FSUI_unindex_abort(unindex); | 227 | GNUNET_FSUI_unindex_abort (unindex); |
225 | GNUNET_FSUI_unindex_stop(unindex); | 228 | GNUNET_FSUI_unindex_stop (unindex); |
226 | 229 | ||
227 | 230 | ||
228 | /* END OF TEST CODE */ | 231 | /* END OF TEST CODE */ |
229 | FAILURE: | 232 | FAILURE: |
230 | if (ctx != NULL) | 233 | if (ctx != NULL) |
231 | GNUNET_FSUI_stop(ctx); | 234 | GNUNET_FSUI_stop (ctx); |
232 | if (filename != NULL) | 235 | if (filename != NULL) |
233 | { | 236 | { |
234 | unlink(filename); | 237 | unlink (filename); |
235 | GNUNET_free(filename); | 238 | GNUNET_free (filename); |
236 | } | 239 | } |
237 | if (download != NULL) | 240 | if (download != NULL) |
238 | { | 241 | { |
239 | GNUNET_FSUI_download_abort(download); | 242 | GNUNET_FSUI_download_abort (download); |
240 | GNUNET_FSUI_download_stop(download); | 243 | GNUNET_FSUI_download_stop (download); |
241 | } | 244 | } |
242 | filename = makeName(43); | 245 | filename = makeName (43); |
243 | /* TODO: verify file 'filename(42)' == file 'filename(43)' */ | 246 | /* TODO: verify file 'filename(42)' == file 'filename(43)' */ |
244 | unlink(filename); | 247 | unlink (filename); |
245 | GNUNET_free(filename); | 248 | GNUNET_free (filename); |
246 | 249 | ||
247 | #if START_DAEMON | 250 | #if START_DAEMON |
248 | GNUNET_GE_ASSERT(NULL, GNUNET_OK == GNUNET_daemon_stop(NULL, daemon)); | 251 | GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon)); |
249 | GNUNET_OS_process_destroy(daemon); | 252 | GNUNET_OS_process_destroy (daemon); |
250 | #endif | 253 | #endif |
251 | GNUNET_GC_free(cfg); | 254 | GNUNET_GC_free (cfg); |
252 | 255 | ||
253 | return (ok == GNUNET_YES) ? 0 : 1; | 256 | return (ok == GNUNET_YES) ? 0 : 1; |
254 | } | 257 | } |
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c index 936c3bed4..37d74613a 100644 --- a/src/fs/test_fs_directory.c +++ b/src/fs/test_fs_directory.c | |||
@@ -30,9 +30,11 @@ | |||
30 | #include "gnunet_fs_service.h" | 30 | #include "gnunet_fs_service.h" |
31 | #include "fs_api.h" | 31 | #include "fs_api.h" |
32 | 32 | ||
33 | #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; } | 33 | #define ABORT() { fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); \ |
34 | return 1; } | ||
34 | 35 | ||
35 | struct PCLS { | 36 | struct PCLS |
37 | { | ||
36 | struct GNUNET_FS_Uri **uri; | 38 | struct GNUNET_FS_Uri **uri; |
37 | struct GNUNET_CONTAINER_MetaData **md; | 39 | struct GNUNET_CONTAINER_MetaData **md; |
38 | unsigned int pos; | 40 | unsigned int pos; |
@@ -40,9 +42,9 @@ struct PCLS { | |||
40 | }; | 42 | }; |
41 | 43 | ||
42 | static void | 44 | static void |
43 | processor(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, | 45 | processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, |
44 | const struct GNUNET_CONTAINER_MetaData *md, size_t length, | 46 | const struct GNUNET_CONTAINER_MetaData *md, size_t length, |
45 | const void *data) | 47 | const void *data) |
46 | { | 48 | { |
47 | struct PCLS *p = cls; | 49 | struct PCLS *p = cls; |
48 | int i; | 50 | int i; |
@@ -50,19 +52,19 @@ processor(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, | |||
50 | if (NULL == uri) | 52 | if (NULL == uri) |
51 | return; /* ignore directory's meta data */ | 53 | return; /* ignore directory's meta data */ |
52 | for (i = 0; i < p->max; i++) | 54 | for (i = 0; i < p->max; i++) |
55 | { | ||
56 | if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], md) && | ||
57 | GNUNET_FS_uri_test_equal (p->uri[i], uri)) | ||
53 | { | 58 | { |
54 | if (GNUNET_CONTAINER_meta_data_test_equal(p->md[i], md) && | 59 | p->pos++; |
55 | GNUNET_FS_uri_test_equal(p->uri[i], uri)) | 60 | return; |
56 | { | ||
57 | p->pos++; | ||
58 | return; | ||
59 | } | ||
60 | } | 61 | } |
61 | fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); | 62 | } |
63 | fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); | ||
62 | } | 64 | } |
63 | 65 | ||
64 | static int | 66 | static int |
65 | testDirectory(unsigned int i) | 67 | testDirectory (unsigned int i) |
66 | { | 68 | { |
67 | struct GNUNET_FS_DirectoryBuilder *db; | 69 | struct GNUNET_FS_DirectoryBuilder *db; |
68 | char *data; | 70 | char *data; |
@@ -81,99 +83,99 @@ testDirectory(unsigned int i) | |||
81 | const char *s; | 83 | const char *s; |
82 | 84 | ||
83 | cls.max = i; | 85 | cls.max = i; |
84 | uris = GNUNET_malloc(sizeof(struct GNUNET_FS_Uri *) * i); | 86 | uris = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri *) * i); |
85 | mds = GNUNET_malloc(sizeof(struct GNUNET_CONTAINER_MetaData *) * i); | 87 | mds = GNUNET_malloc (sizeof(struct GNUNET_CONTAINER_MetaData *) * i); |
86 | meta = GNUNET_CONTAINER_meta_data_create(); | 88 | meta = GNUNET_CONTAINER_meta_data_create (); |
87 | GNUNET_CONTAINER_meta_data_insert(meta, "<test>", EXTRACTOR_METATYPE_TITLE, | 89 | GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, |
88 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 90 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
89 | "A title", strlen("A title") + 1); | 91 | "A title", strlen ("A title") + 1); |
90 | GNUNET_CONTAINER_meta_data_insert(meta, "<test>", | 92 | GNUNET_CONTAINER_meta_data_insert (meta, "<test>", |
91 | EXTRACTOR_METATYPE_AUTHOR_NAME, | 93 | EXTRACTOR_METATYPE_AUTHOR_NAME, |
92 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 94 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
93 | "An author", strlen("An author") + 1); | 95 | "An author", strlen ("An author") + 1); |
94 | for (p = 0; p < i; p++) | 96 | for (p = 0; p < i; p++) |
97 | { | ||
98 | mds[p] = GNUNET_CONTAINER_meta_data_create (); | ||
99 | for (q = 0; q <= p; q++) | ||
95 | { | 100 | { |
96 | mds[p] = GNUNET_CONTAINER_meta_data_create(); | 101 | GNUNET_snprintf (txt, sizeof(txt), "%u -- %u\n", p, q); |
97 | for (q = 0; q <= p; q++) | 102 | GNUNET_CONTAINER_meta_data_insert (mds[p], "<test>", |
98 | { | ||
99 | GNUNET_snprintf(txt, sizeof(txt), "%u -- %u\n", p, q); | ||
100 | GNUNET_CONTAINER_meta_data_insert(mds[p], "<test>", | ||
101 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR | 103 | #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR |
102 | q % EXTRACTOR_metatype_get_max(), | 104 | q % EXTRACTOR_metatype_get_max (), |
103 | #else | 105 | #else |
104 | q % 128, | 106 | q % 128, |
105 | #endif | 107 | #endif |
106 | EXTRACTOR_METAFORMAT_UTF8, | 108 | EXTRACTOR_METAFORMAT_UTF8, |
107 | "text/plain", txt, strlen(txt) + 1); | 109 | "text/plain", txt, strlen (txt) + 1); |
108 | } | ||
109 | GNUNET_snprintf(uri, sizeof(uri), | ||
110 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", | ||
111 | p); | ||
112 | emsg = NULL; | ||
113 | uris[p] = GNUNET_FS_uri_parse(uri, &emsg); | ||
114 | if (uris[p] == NULL) | ||
115 | { | ||
116 | GNUNET_CONTAINER_meta_data_destroy(mds[p]); | ||
117 | while (--p > 0) | ||
118 | { | ||
119 | GNUNET_CONTAINER_meta_data_destroy(mds[p]); | ||
120 | GNUNET_FS_uri_destroy(uris[p]); | ||
121 | } | ||
122 | GNUNET_free(mds); | ||
123 | GNUNET_free(uris); | ||
124 | GNUNET_free(emsg); | ||
125 | GNUNET_CONTAINER_meta_data_destroy(meta); | ||
126 | ABORT(); /* error in testcase */ | ||
127 | } | ||
128 | GNUNET_assert(emsg == NULL); | ||
129 | } | 110 | } |
130 | start = GNUNET_TIME_absolute_get(); | 111 | GNUNET_snprintf (uri, sizeof(uri), |
131 | db = GNUNET_FS_directory_builder_create(meta); | 112 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", |
132 | for (p = 0; p < i; p++) | 113 | p); |
133 | GNUNET_FS_directory_builder_add(db, uris[p], mds[p], NULL); | 114 | emsg = NULL; |
134 | GNUNET_FS_directory_builder_finish(db, &dlen, (void **)&data); | 115 | uris[p] = GNUNET_FS_uri_parse (uri, &emsg); |
135 | s = GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration | 116 | if (uris[p] == NULL) |
136 | (start), | ||
137 | GNUNET_YES); | ||
138 | fprintf(stdout, | ||
139 | "Creating directory with %u entires and total size %llu took %s\n", | ||
140 | i, (unsigned long long)dlen, s); | ||
141 | if (i < 100) | ||
142 | { | 117 | { |
143 | cls.pos = 0; | 118 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); |
144 | cls.uri = uris; | 119 | while (--p > 0) |
145 | cls.md = mds; | 120 | { |
146 | GNUNET_FS_directory_list_contents(dlen, data, 0, &processor, &cls); | 121 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); |
147 | GNUNET_assert(cls.pos == i); | 122 | GNUNET_FS_uri_destroy (uris[p]); |
123 | } | ||
124 | GNUNET_free (mds); | ||
125 | GNUNET_free (uris); | ||
126 | GNUNET_free (emsg); | ||
127 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
128 | ABORT (); /* error in testcase */ | ||
148 | } | 129 | } |
149 | GNUNET_free(data); | 130 | GNUNET_assert (emsg == NULL); |
150 | GNUNET_CONTAINER_meta_data_destroy(meta); | 131 | } |
132 | start = GNUNET_TIME_absolute_get (); | ||
133 | db = GNUNET_FS_directory_builder_create (meta); | ||
151 | for (p = 0; p < i; p++) | 134 | for (p = 0; p < i; p++) |
152 | { | 135 | GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL); |
153 | GNUNET_CONTAINER_meta_data_destroy(mds[p]); | 136 | GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data); |
154 | GNUNET_FS_uri_destroy(uris[p]); | 137 | s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration |
155 | } | 138 | (start), |
156 | GNUNET_free(uris); | 139 | GNUNET_YES); |
157 | GNUNET_free(mds); | 140 | fprintf (stdout, |
141 | "Creating directory with %u entires and total size %llu took %s\n", | ||
142 | i, (unsigned long long) dlen, s); | ||
143 | if (i < 100) | ||
144 | { | ||
145 | cls.pos = 0; | ||
146 | cls.uri = uris; | ||
147 | cls.md = mds; | ||
148 | GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls); | ||
149 | GNUNET_assert (cls.pos == i); | ||
150 | } | ||
151 | GNUNET_free (data); | ||
152 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
153 | for (p = 0; p < i; p++) | ||
154 | { | ||
155 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); | ||
156 | GNUNET_FS_uri_destroy (uris[p]); | ||
157 | } | ||
158 | GNUNET_free (uris); | ||
159 | GNUNET_free (mds); | ||
158 | return ret; | 160 | return ret; |
159 | } | 161 | } |
160 | 162 | ||
161 | 163 | ||
162 | int | 164 | int |
163 | main(int argc, char *argv[]) | 165 | main (int argc, char *argv[]) |
164 | { | 166 | { |
165 | int failureCount = 0; | 167 | int failureCount = 0; |
166 | int i; | 168 | int i; |
167 | 169 | ||
168 | GNUNET_log_setup("test_fs_directory", | 170 | GNUNET_log_setup ("test_fs_directory", |
169 | #if VERBOSE | 171 | #if VERBOSE |
170 | "DEBUG", | 172 | "DEBUG", |
171 | #else | 173 | #else |
172 | "WARNING", | 174 | "WARNING", |
173 | #endif | 175 | #endif |
174 | NULL); | 176 | NULL); |
175 | for (i = 17; i < 1000; i *= 2) | 177 | for (i = 17; i < 1000; i *= 2) |
176 | failureCount += testDirectory(i); | 178 | failureCount += testDirectory (i); |
177 | if (failureCount != 0) | 179 | if (failureCount != 0) |
178 | return 1; | 180 | return 1; |
179 | return 0; | 181 | return 0; |
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index f7c35a680..422c41523 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c | |||
@@ -38,12 +38,12 @@ | |||
38 | /** | 38 | /** |
39 | * How long until we give up on transmitting the message? | 39 | * How long until we give up on transmitting the message? |
40 | */ | 40 | */ |
41 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) | 41 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * How long should our test-content live? | 44 | * How long should our test-content live? |
45 | */ | 45 | */ |
46 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 46 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
47 | 47 | ||
48 | static unsigned int anonymity_level; | 48 | static unsigned int anonymity_level; |
49 | 49 | ||
@@ -57,7 +57,7 @@ static struct GNUNET_FS_DownloadContext *download; | |||
57 | 57 | ||
58 | static struct GNUNET_FS_PublishContext *publish; | 58 | static struct GNUNET_FS_PublishContext *publish; |
59 | 59 | ||
60 | static struct GNUNET_SCHEDULER_Task * timeout_kill; | 60 | static struct GNUNET_SCHEDULER_Task *timeout_kill; |
61 | 61 | ||
62 | static char *fn; | 62 | static char *fn; |
63 | 63 | ||
@@ -67,198 +67,199 @@ static int err; | |||
67 | 67 | ||
68 | 68 | ||
69 | static void | 69 | static void |
70 | timeout_kill_task(void *cls) | 70 | timeout_kill_task (void *cls) |
71 | { | 71 | { |
72 | if (NULL != download) | 72 | if (NULL != download) |
73 | { | 73 | { |
74 | GNUNET_FS_download_stop(download, GNUNET_YES); | 74 | GNUNET_FS_download_stop (download, GNUNET_YES); |
75 | download = NULL; | 75 | download = NULL; |
76 | } | 76 | } |
77 | else if (NULL != publish) | 77 | else if (NULL != publish) |
78 | { | 78 | { |
79 | GNUNET_FS_publish_stop(publish); | 79 | GNUNET_FS_publish_stop (publish); |
80 | publish = NULL; | 80 | publish = NULL; |
81 | } | 81 | } |
82 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n"); | 82 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n"); |
83 | timeout_kill = NULL; | 83 | timeout_kill = NULL; |
84 | err = 1; | 84 | err = 1; |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | static void | 88 | static void |
89 | abort_publish_task(void *cls) | 89 | abort_publish_task (void *cls) |
90 | { | 90 | { |
91 | if (NULL != publish) | 91 | if (NULL != publish) |
92 | { | 92 | { |
93 | GNUNET_FS_publish_stop(publish); | 93 | GNUNET_FS_publish_stop (publish); |
94 | publish = NULL; | 94 | publish = NULL; |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | static void | 99 | static void |
100 | stop_fs_task(void *cls) | 100 | stop_fs_task (void *cls) |
101 | { | 101 | { |
102 | GNUNET_FS_stop(fs); | 102 | GNUNET_FS_stop (fs); |
103 | fs = NULL; | 103 | fs = NULL; |
104 | } | 104 | } |
105 | 105 | ||
106 | 106 | ||
107 | static void | 107 | static void |
108 | abort_download_task(void *cls) | 108 | abort_download_task (void *cls) |
109 | { | 109 | { |
110 | uint64_t size; | 110 | uint64_t size; |
111 | 111 | ||
112 | if (NULL != download) | 112 | if (NULL != download) |
113 | { | 113 | { |
114 | GNUNET_FS_download_stop(download, GNUNET_YES); | 114 | GNUNET_FS_download_stop (download, GNUNET_YES); |
115 | download = NULL; | 115 | download = NULL; |
116 | } | 116 | } |
117 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_size(fn, &size, GNUNET_YES, GNUNET_NO)); | 117 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES, |
118 | GNUNET_assert(size == FILESIZE); | 118 | GNUNET_NO)); |
119 | GNUNET_DISK_directory_remove(fn); | 119 | GNUNET_assert (size == FILESIZE); |
120 | GNUNET_free(fn); | 120 | GNUNET_DISK_directory_remove (fn); |
121 | GNUNET_free (fn); | ||
121 | fn = NULL; | 122 | fn = NULL; |
122 | GNUNET_SCHEDULER_cancel(timeout_kill); | 123 | GNUNET_SCHEDULER_cancel (timeout_kill); |
123 | timeout_kill = NULL; | 124 | timeout_kill = NULL; |
124 | } | 125 | } |
125 | 126 | ||
126 | 127 | ||
127 | static void * | 128 | static void * |
128 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 129 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
129 | { | 130 | { |
130 | switch (event->status) | 131 | switch (event->status) |
131 | { | 132 | { |
132 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 133 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
133 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
134 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 135 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
135 | (unsigned long long)event->value.publish.completed, | 136 | (unsigned long long) event->value.publish.completed, |
136 | (unsigned long long)event->value.publish.size, | 137 | (unsigned long long) event->value.publish.size, |
137 | event->value.publish.specifics.progress.depth, | 138 | event->value.publish.specifics.progress.depth, |
138 | (unsigned long long)event->value.publish.specifics. | 139 | (unsigned long long) event->value.publish.specifics. |
139 | progress.offset); | 140 | progress.offset); |
140 | break; | 141 | break; |
141 | 142 | ||
142 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 143 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
143 | break; | 144 | break; |
144 | 145 | ||
145 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 146 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
146 | fprintf(stdout, | 147 | fprintf (stdout, |
147 | "Publishing complete, %llu kb/s.\n", | 148 | "Publishing complete, %llu kb/s.\n", |
148 | (unsigned long long)(FILESIZE * 1000000LL / | 149 | (unsigned long long) (FILESIZE * 1000000LL |
149 | (1 + | 150 | / (1 |
150 | GNUNET_TIME_absolute_get_duration | 151 | + GNUNET_TIME_absolute_get_duration |
151 | (start).rel_value_us) / 1024LL)); | 152 | (start).rel_value_us) / 1024LL)); |
152 | GAUGER("FS", | 153 | GAUGER ("FS", |
153 | (GNUNET_YES == indexed) | 154 | (GNUNET_YES == indexed) |
154 | ? "Publishing speed (indexing)" | 155 | ? "Publishing speed (indexing)" |
155 | : "Publishing speed (insertion)", | 156 | : "Publishing speed (insertion)", |
156 | (unsigned long long)(FILESIZE * 1000000LL / | 157 | (unsigned long long) (FILESIZE * 1000000LL |
157 | (1 + | 158 | / (1 |
158 | GNUNET_TIME_absolute_get_duration | 159 | + GNUNET_TIME_absolute_get_duration |
159 | (start).rel_value_us) / 1024LL), "kb/s"); | 160 | (start).rel_value_us) / 1024LL), "kb/s"); |
160 | fn = GNUNET_DISK_mktemp("gnunet-download-test-dst"); | 161 | fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); |
161 | start = GNUNET_TIME_absolute_get(); | 162 | start = GNUNET_TIME_absolute_get (); |
162 | download = | 163 | download = |
163 | GNUNET_FS_download_start(fs, | 164 | GNUNET_FS_download_start (fs, |
164 | event->value.publish.specifics. | 165 | event->value.publish.specifics. |
165 | completed.chk_uri, NULL, fn, NULL, 0, | 166 | completed.chk_uri, NULL, fn, NULL, 0, |
166 | FILESIZE, anonymity_level, | 167 | FILESIZE, anonymity_level, |
167 | GNUNET_FS_DOWNLOAD_OPTION_NONE, | 168 | GNUNET_FS_DOWNLOAD_OPTION_NONE, |
168 | "download", NULL); | 169 | "download", NULL); |
169 | GNUNET_assert(download != NULL); | 170 | GNUNET_assert (download != NULL); |
170 | break; | 171 | break; |
171 | 172 | ||
172 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 173 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
173 | fprintf(stdout, | 174 | fprintf (stdout, |
174 | "Download complete, %llu kb/s.\n", | 175 | "Download complete, %llu kb/s.\n", |
175 | (unsigned long long)(FILESIZE * 1000000LL / | 176 | (unsigned long long) (FILESIZE * 1000000LL |
176 | (1 + | 177 | / (1 |
177 | GNUNET_TIME_absolute_get_duration | 178 | + GNUNET_TIME_absolute_get_duration |
178 | (start).rel_value_us) / 1024LL)); | 179 | (start).rel_value_us) / 1024LL)); |
179 | GAUGER("FS", | 180 | GAUGER ("FS", |
180 | (GNUNET_YES == indexed) | 181 | (GNUNET_YES == indexed) |
181 | ? "Local download speed (indexed)" | 182 | ? "Local download speed (indexed)" |
182 | : "Local download speed (inserted)", | 183 | : "Local download speed (inserted)", |
183 | (unsigned long long)(FILESIZE * 1000000LL / | 184 | (unsigned long long) (FILESIZE * 1000000LL |
184 | (1 + | 185 | / (1 |
185 | GNUNET_TIME_absolute_get_duration | 186 | + GNUNET_TIME_absolute_get_duration |
186 | (start).rel_value_us) / 1024LL), "kb/s"); | 187 | (start).rel_value_us) / 1024LL), "kb/s"); |
187 | GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); | 188 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); |
188 | break; | 189 | break; |
189 | 190 | ||
190 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 191 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
191 | GNUNET_assert(download == event->value.download.dc); | 192 | GNUNET_assert (download == event->value.download.dc); |
192 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
193 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", | 194 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", |
194 | (unsigned long long)event->value.download.completed, | 195 | (unsigned long long) event->value.download.completed, |
195 | (unsigned long long)event->value.download.size, | 196 | (unsigned long long) event->value.download.size, |
196 | event->value.download.specifics.progress.depth, | 197 | event->value.download.specifics.progress.depth, |
197 | (unsigned long long)event->value.download.specifics. | 198 | (unsigned long long) event->value.download.specifics. |
198 | progress.offset); | 199 | progress.offset); |
199 | break; | 200 | break; |
200 | 201 | ||
201 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 202 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
202 | fprintf(stderr, "Error publishing file: %s\n", | 203 | fprintf (stderr, "Error publishing file: %s\n", |
203 | event->value.publish.specifics.error.message); | 204 | event->value.publish.specifics.error.message); |
204 | GNUNET_break(0); | 205 | GNUNET_break (0); |
205 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 206 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
206 | GNUNET_SCHEDULER_shutdown(); | 207 | GNUNET_SCHEDULER_shutdown (); |
207 | break; | 208 | break; |
208 | 209 | ||
209 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 210 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
210 | fprintf(stderr, "Error downloading file: %s\n", | 211 | fprintf (stderr, "Error downloading file: %s\n", |
211 | event->value.download.specifics.error.message); | 212 | event->value.download.specifics.error.message); |
212 | GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); | 213 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); |
213 | GNUNET_SCHEDULER_shutdown(); | 214 | GNUNET_SCHEDULER_shutdown (); |
214 | break; | 215 | break; |
215 | 216 | ||
216 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | 217 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: |
217 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 218 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: |
218 | break; | 219 | break; |
219 | 220 | ||
220 | case GNUNET_FS_STATUS_PUBLISH_START: | 221 | case GNUNET_FS_STATUS_PUBLISH_START: |
221 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); | 222 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); |
222 | GNUNET_assert(NULL == event->value.publish.pctx); | 223 | GNUNET_assert (NULL == event->value.publish.pctx); |
223 | GNUNET_assert(FILESIZE == event->value.publish.size); | 224 | GNUNET_assert (FILESIZE == event->value.publish.size); |
224 | GNUNET_assert(0 == event->value.publish.completed); | 225 | GNUNET_assert (0 == event->value.publish.completed); |
225 | GNUNET_assert(1 == event->value.publish.anonymity); | 226 | GNUNET_assert (1 == event->value.publish.anonymity); |
226 | break; | 227 | break; |
227 | 228 | ||
228 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 229 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
229 | GNUNET_assert(publish == event->value.publish.pc); | 230 | GNUNET_assert (publish == event->value.publish.pc); |
230 | GNUNET_assert(FILESIZE == event->value.publish.size); | 231 | GNUNET_assert (FILESIZE == event->value.publish.size); |
231 | GNUNET_assert(1 == event->value.publish.anonymity); | 232 | GNUNET_assert (1 == event->value.publish.anonymity); |
232 | GNUNET_SCHEDULER_add_now(&stop_fs_task, NULL); | 233 | GNUNET_SCHEDULER_add_now (&stop_fs_task, NULL); |
233 | break; | 234 | break; |
234 | 235 | ||
235 | case GNUNET_FS_STATUS_DOWNLOAD_START: | 236 | case GNUNET_FS_STATUS_DOWNLOAD_START: |
236 | GNUNET_assert(0 == strcmp("download", event->value.download.cctx)); | 237 | GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); |
237 | GNUNET_assert(NULL == event->value.download.pctx); | 238 | GNUNET_assert (NULL == event->value.download.pctx); |
238 | GNUNET_assert(NULL != event->value.download.uri); | 239 | GNUNET_assert (NULL != event->value.download.uri); |
239 | GNUNET_assert(0 == strcmp(fn, event->value.download.filename)); | 240 | GNUNET_assert (0 == strcmp (fn, event->value.download.filename)); |
240 | GNUNET_assert(FILESIZE == event->value.download.size); | 241 | GNUNET_assert (FILESIZE == event->value.download.size); |
241 | GNUNET_assert(0 == event->value.download.completed); | 242 | GNUNET_assert (0 == event->value.download.completed); |
242 | GNUNET_assert(1 == event->value.download.anonymity); | 243 | GNUNET_assert (1 == event->value.download.anonymity); |
243 | break; | 244 | break; |
244 | 245 | ||
245 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | 246 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: |
246 | GNUNET_assert(download == event->value.download.dc); | 247 | GNUNET_assert (download == event->value.download.dc); |
247 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 248 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
248 | break; | 249 | break; |
249 | 250 | ||
250 | default: | 251 | default: |
251 | printf("Unexpected event: %d\n", event->status); | 252 | printf ("Unexpected event: %d\n", event->status); |
252 | break; | 253 | break; |
253 | } | 254 | } |
254 | return NULL; | 255 | return NULL; |
255 | } | 256 | } |
256 | 257 | ||
257 | 258 | ||
258 | static void | 259 | static void |
259 | run(void *cls, | 260 | run (void *cls, |
260 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 261 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
261 | struct GNUNET_TESTING_Peer *peer) | 262 | struct GNUNET_TESTING_Peer *peer) |
262 | { | 263 | { |
263 | const char *binary_name = cls; | 264 | const char *binary_name = cls; |
264 | const char *keywords[] = { | 265 | const char *keywords[] = { |
@@ -273,89 +274,90 @@ run(void *cls, | |||
273 | struct GNUNET_FS_BlockOptions bo; | 274 | struct GNUNET_FS_BlockOptions bo; |
274 | 275 | ||
275 | if (GNUNET_YES == | 276 | if (GNUNET_YES == |
276 | GNUNET_CONFIGURATION_get_value_yesno(cfg, | 277 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
277 | "download-test", | 278 | "download-test", |
278 | "USE_STREAM")) | 279 | "USE_STREAM")) |
279 | anonymity_level = 0; | 280 | anonymity_level = 0; |
280 | else | 281 | else |
281 | anonymity_level = 1; | 282 | anonymity_level = 1; |
282 | fs = GNUNET_FS_start(cfg, binary_name, &progress_cb, NULL, | 283 | fs = GNUNET_FS_start (cfg, binary_name, &progress_cb, NULL, |
283 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 284 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
284 | GNUNET_assert(NULL != fs); | 285 | GNUNET_assert (NULL != fs); |
285 | buf = GNUNET_malloc(FILESIZE); | 286 | buf = GNUNET_malloc (FILESIZE); |
286 | for (i = 0; i < FILESIZE; i++) | 287 | for (i = 0; i < FILESIZE; i++) |
287 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 288 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
288 | meta = GNUNET_CONTAINER_meta_data_create(); | 289 | meta = GNUNET_CONTAINER_meta_data_create (); |
289 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 290 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
290 | bo.content_priority = 42; | 291 | bo.content_priority = 42; |
291 | bo.anonymity_level = anonymity_level; | 292 | bo.anonymity_level = anonymity_level; |
292 | bo.replication_level = 0; | 293 | bo.replication_level = 0; |
293 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 294 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
294 | 295 | ||
295 | if (GNUNET_YES == | 296 | if (GNUNET_YES == |
296 | GNUNET_CONFIGURATION_get_value_yesno(cfg, | 297 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
297 | "download-test", | 298 | "download-test", |
298 | "USE_INDEX")) | 299 | "USE_INDEX")) |
299 | { | 300 | { |
300 | fn1 = GNUNET_DISK_mktemp("gnunet-download-indexed-test"); | 301 | fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test"); |
301 | GNUNET_assert(FILESIZE == | 302 | GNUNET_assert (FILESIZE == |
302 | GNUNET_DISK_fn_write(fn1, buf, FILESIZE, | 303 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, |
303 | GNUNET_DISK_PERM_USER_READ | | 304 | GNUNET_DISK_PERM_USER_READ |
304 | GNUNET_DISK_PERM_USER_WRITE)); | 305 | | GNUNET_DISK_PERM_USER_WRITE)); |
305 | GNUNET_free(buf); | 306 | GNUNET_free (buf); |
306 | fi = GNUNET_FS_file_information_create_from_file(fs, "publish-context", fn1, | 307 | fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", |
307 | kuri, meta, GNUNET_YES, | 308 | fn1, |
308 | &bo); | 309 | kuri, meta, GNUNET_YES, |
309 | indexed = GNUNET_YES; | 310 | &bo); |
310 | } | 311 | indexed = GNUNET_YES; |
312 | } | ||
311 | else | 313 | else |
312 | { | 314 | { |
313 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", | 315 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", |
314 | FILESIZE, buf, kuri, meta, | 316 | FILESIZE, buf, kuri, meta, |
315 | GNUNET_NO, &bo); | 317 | GNUNET_NO, &bo); |
316 | /* note: buf will be free'd as part of 'fi' now */ | 318 | /* note: buf will be free'd as part of 'fi' now */ |
317 | indexed = GNUNET_NO; | 319 | indexed = GNUNET_NO; |
318 | } | 320 | } |
319 | GNUNET_FS_uri_destroy(kuri); | 321 | GNUNET_FS_uri_destroy (kuri); |
320 | GNUNET_CONTAINER_meta_data_destroy(meta); | 322 | GNUNET_CONTAINER_meta_data_destroy (meta); |
321 | GNUNET_assert(NULL != fi); | 323 | GNUNET_assert (NULL != fi); |
322 | timeout_kill = | 324 | timeout_kill = |
323 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_kill_task, NULL); | 325 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL); |
324 | start = GNUNET_TIME_absolute_get(); | 326 | start = GNUNET_TIME_absolute_get (); |
325 | publish = | 327 | publish = |
326 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, | 328 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, |
327 | GNUNET_FS_PUBLISH_OPTION_NONE); | 329 | GNUNET_FS_PUBLISH_OPTION_NONE); |
328 | GNUNET_assert(publish != NULL); | 330 | GNUNET_assert (publish != NULL); |
329 | } | 331 | } |
330 | 332 | ||
331 | 333 | ||
332 | int | 334 | int |
333 | main(int argc, char *argv[]) | 335 | main (int argc, char *argv[]) |
334 | { | 336 | { |
335 | const char *binary_name; | 337 | const char *binary_name; |
336 | const char *config_name; | 338 | const char *config_name; |
337 | 339 | ||
338 | binary_name = "test-fs-download"; | 340 | binary_name = "test-fs-download"; |
339 | config_name = "test_fs_download_data.conf"; | 341 | config_name = "test_fs_download_data.conf"; |
340 | if (NULL != strstr(argv[0], "indexed")) | 342 | if (NULL != strstr (argv[0], "indexed")) |
341 | { | 343 | { |
342 | binary_name = "test-fs-download-indexed"; | 344 | binary_name = "test-fs-download-indexed"; |
343 | config_name = "test_fs_download_indexed.conf"; | 345 | config_name = "test_fs_download_indexed.conf"; |
344 | } | 346 | } |
345 | if (NULL != strstr(argv[0], "cadet")) | 347 | if (NULL != strstr (argv[0], "cadet")) |
346 | { | 348 | { |
347 | binary_name = "test-fs-download-cadet"; | 349 | binary_name = "test-fs-download-cadet"; |
348 | config_name = "test_fs_download_cadet.conf"; | 350 | config_name = "test_fs_download_cadet.conf"; |
349 | } | 351 | } |
350 | if (0 != GNUNET_TESTING_peer_run(binary_name, | 352 | if (0 != GNUNET_TESTING_peer_run (binary_name, |
351 | config_name, | 353 | config_name, |
352 | &run, (void *)binary_name)) | 354 | &run, (void *) binary_name)) |
353 | return 1; | 355 | return 1; |
354 | if (NULL != fn1) | 356 | if (NULL != fn1) |
355 | { | 357 | { |
356 | unlink(fn1); | 358 | unlink (fn1); |
357 | GNUNET_free(fn1); | 359 | GNUNET_free (fn1); |
358 | } | 360 | } |
359 | return err; | 361 | return err; |
360 | } | 362 | } |
361 | 363 | ||
diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c index 78dbe821e..7b7a886eb 100644 --- a/src/fs/test_fs_download_persistence.c +++ b/src/fs/test_fs_download_persistence.c | |||
@@ -36,12 +36,12 @@ | |||
36 | /** | 36 | /** |
37 | * How long until we give up on transmitting the message? | 37 | * How long until we give up on transmitting the message? |
38 | */ | 38 | */ |
39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How long should our test-content live? | 42 | * How long should our test-content live? |
43 | */ | 43 | */ |
44 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 44 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
45 | 45 | ||
46 | 46 | ||
47 | static struct GNUNET_TIME_Absolute start; | 47 | static struct GNUNET_TIME_Absolute start; |
@@ -54,7 +54,7 @@ static struct GNUNET_FS_DownloadContext *download; | |||
54 | 54 | ||
55 | static struct GNUNET_FS_PublishContext *publish; | 55 | static struct GNUNET_FS_PublishContext *publish; |
56 | 56 | ||
57 | static struct GNUNET_SCHEDULER_Task * timeout_kill; | 57 | static struct GNUNET_SCHEDULER_Task *timeout_kill; |
58 | 58 | ||
59 | static char *fn; | 59 | static char *fn; |
60 | 60 | ||
@@ -62,66 +62,67 @@ static int err; | |||
62 | 62 | ||
63 | 63 | ||
64 | static void | 64 | static void |
65 | timeout_kill_task(void *cls) | 65 | timeout_kill_task (void *cls) |
66 | { | 66 | { |
67 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n"); | 67 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout downloading file\n"); |
68 | if (download != NULL) | 68 | if (download != NULL) |
69 | { | 69 | { |
70 | GNUNET_FS_download_stop(download, GNUNET_YES); | 70 | GNUNET_FS_download_stop (download, GNUNET_YES); |
71 | download = NULL; | 71 | download = NULL; |
72 | } | 72 | } |
73 | else if (publish != NULL) | 73 | else if (publish != NULL) |
74 | { | 74 | { |
75 | GNUNET_FS_publish_stop(publish); | 75 | GNUNET_FS_publish_stop (publish); |
76 | publish = NULL; | 76 | publish = NULL; |
77 | } | 77 | } |
78 | timeout_kill = NULL; | 78 | timeout_kill = NULL; |
79 | err = 1; | 79 | err = 1; |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | static void | 83 | static void |
84 | abort_publish_task(void *cls) | 84 | abort_publish_task (void *cls) |
85 | { | 85 | { |
86 | if (publish != NULL) | 86 | if (publish != NULL) |
87 | { | 87 | { |
88 | GNUNET_FS_publish_stop(publish); | 88 | GNUNET_FS_publish_stop (publish); |
89 | publish = NULL; | 89 | publish = NULL; |
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | static void | 94 | static void |
95 | abort_download_task(void *cls) | 95 | abort_download_task (void *cls) |
96 | { | 96 | { |
97 | uint64_t size; | 97 | uint64_t size; |
98 | 98 | ||
99 | if (download != NULL) | 99 | if (download != NULL) |
100 | { | 100 | { |
101 | GNUNET_FS_download_stop(download, GNUNET_YES); | 101 | GNUNET_FS_download_stop (download, GNUNET_YES); |
102 | download = NULL; | 102 | download = NULL; |
103 | } | 103 | } |
104 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_size(fn, &size, GNUNET_YES, GNUNET_NO)); | 104 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES, |
105 | GNUNET_assert(size == FILESIZE); | 105 | GNUNET_NO)); |
106 | GNUNET_DISK_directory_remove(fn); | 106 | GNUNET_assert (size == FILESIZE); |
107 | GNUNET_free(fn); | 107 | GNUNET_DISK_directory_remove (fn); |
108 | GNUNET_free (fn); | ||
108 | fn = NULL; | 109 | fn = NULL; |
109 | GNUNET_SCHEDULER_cancel(timeout_kill); | 110 | GNUNET_SCHEDULER_cancel (timeout_kill); |
110 | timeout_kill = NULL; | 111 | timeout_kill = NULL; |
111 | } | 112 | } |
112 | 113 | ||
113 | 114 | ||
114 | static void * | 115 | static void * |
115 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event); | 116 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); |
116 | 117 | ||
117 | 118 | ||
118 | static void | 119 | static void |
119 | restart_fs_task(void *cls) | 120 | restart_fs_task (void *cls) |
120 | { | 121 | { |
121 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n"); | 122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n"); |
122 | GNUNET_FS_stop(fs); | 123 | GNUNET_FS_stop (fs); |
123 | fs = GNUNET_FS_start(cfg, "test-fs-download-persistence", &progress_cb, NULL, | 124 | fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL, |
124 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 125 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
125 | } | 126 | } |
126 | 127 | ||
127 | 128 | ||
@@ -133,7 +134,7 @@ restart_fs_task(void *cls) | |||
133 | * @param ev type of the event to consider | 134 | * @param ev type of the event to consider |
134 | */ | 135 | */ |
135 | static void | 136 | static void |
136 | consider_restart(int ev) | 137 | consider_restart (int ev) |
137 | { | 138 | { |
138 | static int prev[32]; | 139 | static int prev[32]; |
139 | static int off; | 140 | static int off; |
@@ -143,158 +144,158 @@ consider_restart(int ev) | |||
143 | if (prev[i] == ev) | 144 | if (prev[i] == ev) |
144 | return; | 145 | return; |
145 | prev[off++] = ev; | 146 | prev[off++] = ev; |
146 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT, | 147 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, |
147 | &restart_fs_task, NULL); | 148 | &restart_fs_task, NULL); |
148 | } | 149 | } |
149 | 150 | ||
150 | 151 | ||
151 | static void * | 152 | static void * |
152 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 153 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
153 | { | 154 | { |
154 | switch (event->status) | 155 | switch (event->status) |
155 | { | 156 | { |
156 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 157 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
157 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
158 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 159 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
159 | (unsigned long long)event->value.publish.completed, | 160 | (unsigned long long) event->value.publish.completed, |
160 | (unsigned long long)event->value.publish.size, | 161 | (unsigned long long) event->value.publish.size, |
161 | event->value.publish.specifics.progress.depth, | 162 | event->value.publish.specifics.progress.depth, |
162 | (unsigned long long)event->value.publish.specifics. | 163 | (unsigned long long) event->value.publish.specifics. |
163 | progress.offset); | 164 | progress.offset); |
164 | break; | 165 | break; |
165 | 166 | ||
166 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 167 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
167 | break; | 168 | break; |
168 | 169 | ||
169 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 170 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
170 | printf("Publishing complete, %llu kbps.\n", | 171 | printf ("Publishing complete, %llu kbps.\n", |
171 | (unsigned long long)(FILESIZE * 1000000LL / | 172 | (unsigned long long) (FILESIZE * 1000000LL |
172 | (1 + | 173 | / (1 |
173 | GNUNET_TIME_absolute_get_duration | 174 | + GNUNET_TIME_absolute_get_duration |
174 | (start).rel_value_us) / 1024LL)); | 175 | (start).rel_value_us) / 1024LL)); |
175 | fn = GNUNET_DISK_mktemp("gnunet-download-test-dst"); | 176 | fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); |
176 | start = GNUNET_TIME_absolute_get(); | 177 | start = GNUNET_TIME_absolute_get (); |
177 | GNUNET_assert(download == NULL); | 178 | GNUNET_assert (download == NULL); |
178 | GNUNET_FS_download_start(fs, | 179 | GNUNET_FS_download_start (fs, |
179 | event->value.publish.specifics.completed.chk_uri, | 180 | event->value.publish.specifics.completed.chk_uri, |
180 | NULL, fn, NULL, 0, FILESIZE, 1, | 181 | NULL, fn, NULL, 0, FILESIZE, 1, |
181 | GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL); | 182 | GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL); |
182 | break; | 183 | break; |
183 | 184 | ||
184 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 185 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
185 | printf("Download complete, %llu kbps.\n", | 186 | printf ("Download complete, %llu kbps.\n", |
186 | (unsigned long long)(FILESIZE * 1000000LL / | 187 | (unsigned long long) (FILESIZE * 1000000LL |
187 | (1 + | 188 | / (1 |
188 | GNUNET_TIME_absolute_get_duration | 189 | + GNUNET_TIME_absolute_get_duration |
189 | (start).rel_value_us) / 1024LL)); | 190 | (start).rel_value_us) / 1024LL)); |
190 | GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); | 191 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); |
191 | break; | 192 | break; |
192 | 193 | ||
193 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 194 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
194 | consider_restart(event->status); | 195 | consider_restart (event->status); |
195 | GNUNET_assert(download == event->value.download.dc); | 196 | GNUNET_assert (download == event->value.download.dc); |
196 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
197 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", | 198 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", |
198 | (unsigned long long)event->value.download.completed, | 199 | (unsigned long long) event->value.download.completed, |
199 | (unsigned long long)event->value.download.size, | 200 | (unsigned long long) event->value.download.size, |
200 | event->value.download.specifics.progress.depth, | 201 | event->value.download.specifics.progress.depth, |
201 | (unsigned long long)event->value.download.specifics. | 202 | (unsigned long long) event->value.download.specifics. |
202 | progress.offset); | 203 | progress.offset); |
203 | break; | 204 | break; |
204 | 205 | ||
205 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 206 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
206 | fprintf(stderr, "Error publishing file: %s\n", | 207 | fprintf (stderr, "Error publishing file: %s\n", |
207 | event->value.publish.specifics.error.message); | 208 | event->value.publish.specifics.error.message); |
208 | GNUNET_break(0); | 209 | GNUNET_break (0); |
209 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 210 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
210 | break; | 211 | break; |
211 | 212 | ||
212 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 213 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
213 | fprintf(stderr, "Error downloading file: %s\n", | 214 | fprintf (stderr, "Error downloading file: %s\n", |
214 | event->value.download.specifics.error.message); | 215 | event->value.download.specifics.error.message); |
215 | GNUNET_SCHEDULER_add_now(&abort_download_task, NULL); | 216 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); |
216 | break; | 217 | break; |
217 | 218 | ||
218 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | 219 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: |
219 | GNUNET_assert(event->value.publish.pc == publish); | 220 | GNUNET_assert (event->value.publish.pc == publish); |
220 | publish = NULL; | 221 | publish = NULL; |
221 | break; | 222 | break; |
222 | 223 | ||
223 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | 224 | case GNUNET_FS_STATUS_PUBLISH_RESUME: |
224 | GNUNET_assert(NULL == publish); | 225 | GNUNET_assert (NULL == publish); |
225 | publish = event->value.publish.pc; | 226 | publish = event->value.publish.pc; |
226 | break; | 227 | break; |
227 | 228 | ||
228 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: | 229 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: |
229 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download suspended.\n"); | 230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download suspended.\n"); |
230 | GNUNET_assert(event->value.download.dc == download); | 231 | GNUNET_assert (event->value.download.dc == download); |
231 | download = NULL; | 232 | download = NULL; |
232 | break; | 233 | break; |
233 | 234 | ||
234 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: | 235 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: |
235 | GNUNET_assert(NULL == download); | 236 | GNUNET_assert (NULL == download); |
236 | download = event->value.download.dc; | 237 | download = event->value.download.dc; |
237 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download resumed.\n"); | 238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download resumed.\n"); |
238 | break; | 239 | break; |
239 | 240 | ||
240 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | 241 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: |
241 | consider_restart(event->status); | 242 | consider_restart (event->status); |
242 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download active.\n"); | 243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download active.\n"); |
243 | break; | 244 | break; |
244 | 245 | ||
245 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 246 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: |
246 | consider_restart(event->status); | 247 | consider_restart (event->status); |
247 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download inactive.\n"); | 248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download inactive.\n"); |
248 | break; | 249 | break; |
249 | 250 | ||
250 | case GNUNET_FS_STATUS_PUBLISH_START: | 251 | case GNUNET_FS_STATUS_PUBLISH_START: |
251 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); | 252 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); |
252 | GNUNET_assert(NULL == event->value.publish.pctx); | 253 | GNUNET_assert (NULL == event->value.publish.pctx); |
253 | GNUNET_assert(FILESIZE == event->value.publish.size); | 254 | GNUNET_assert (FILESIZE == event->value.publish.size); |
254 | GNUNET_assert(0 == event->value.publish.completed); | 255 | GNUNET_assert (0 == event->value.publish.completed); |
255 | GNUNET_assert(1 == event->value.publish.anonymity); | 256 | GNUNET_assert (1 == event->value.publish.anonymity); |
256 | break; | 257 | break; |
257 | 258 | ||
258 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 259 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
259 | GNUNET_assert(publish == event->value.publish.pc); | 260 | GNUNET_assert (publish == event->value.publish.pc); |
260 | GNUNET_assert(FILESIZE == event->value.publish.size); | 261 | GNUNET_assert (FILESIZE == event->value.publish.size); |
261 | GNUNET_assert(1 == event->value.publish.anonymity); | 262 | GNUNET_assert (1 == event->value.publish.anonymity); |
262 | GNUNET_FS_stop(fs); | 263 | GNUNET_FS_stop (fs); |
263 | fs = NULL; | 264 | fs = NULL; |
264 | break; | 265 | break; |
265 | 266 | ||
266 | case GNUNET_FS_STATUS_DOWNLOAD_START: | 267 | case GNUNET_FS_STATUS_DOWNLOAD_START: |
267 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download started.\n"); | 268 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download started.\n"); |
268 | consider_restart(event->status); | 269 | consider_restart (event->status); |
269 | GNUNET_assert(download == NULL); | 270 | GNUNET_assert (download == NULL); |
270 | download = event->value.download.dc; | 271 | download = event->value.download.dc; |
271 | GNUNET_assert(0 == strcmp("download", event->value.download.cctx)); | 272 | GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); |
272 | GNUNET_assert(NULL == event->value.download.pctx); | 273 | GNUNET_assert (NULL == event->value.download.pctx); |
273 | GNUNET_assert(NULL != event->value.download.uri); | 274 | GNUNET_assert (NULL != event->value.download.uri); |
274 | GNUNET_assert(0 == strcmp(fn, event->value.download.filename)); | 275 | GNUNET_assert (0 == strcmp (fn, event->value.download.filename)); |
275 | GNUNET_assert(FILESIZE == event->value.download.size); | 276 | GNUNET_assert (FILESIZE == event->value.download.size); |
276 | GNUNET_assert(0 == event->value.download.completed); | 277 | GNUNET_assert (0 == event->value.download.completed); |
277 | GNUNET_assert(1 == event->value.download.anonymity); | 278 | GNUNET_assert (1 == event->value.download.anonymity); |
278 | break; | 279 | break; |
279 | 280 | ||
280 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | 281 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: |
281 | GNUNET_assert(download == event->value.download.dc); | 282 | GNUNET_assert (download == event->value.download.dc); |
282 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 283 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
283 | download = NULL; | 284 | download = NULL; |
284 | break; | 285 | break; |
285 | 286 | ||
286 | default: | 287 | default: |
287 | printf("Unexpected event: %d\n", event->status); | 288 | printf ("Unexpected event: %d\n", event->status); |
288 | break; | 289 | break; |
289 | } | 290 | } |
290 | return NULL; | 291 | return NULL; |
291 | } | 292 | } |
292 | 293 | ||
293 | 294 | ||
294 | static void | 295 | static void |
295 | run(void *cls, | 296 | run (void *cls, |
296 | const struct GNUNET_CONFIGURATION_Handle *c, | 297 | const struct GNUNET_CONFIGURATION_Handle *c, |
297 | struct GNUNET_TESTING_Peer *peer) | 298 | struct GNUNET_TESTING_Peer *peer) |
298 | { | 299 | { |
299 | const char *keywords[] = { | 300 | const char *keywords[] = { |
300 | "down_foo", | 301 | "down_foo", |
@@ -308,40 +309,40 @@ run(void *cls, | |||
308 | struct GNUNET_FS_BlockOptions bo; | 309 | struct GNUNET_FS_BlockOptions bo; |
309 | 310 | ||
310 | cfg = c; | 311 | cfg = c; |
311 | fs = GNUNET_FS_start(cfg, "test-fs-download-persistence", &progress_cb, NULL, | 312 | fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL, |
312 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 313 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
313 | GNUNET_assert(NULL != fs); | 314 | GNUNET_assert (NULL != fs); |
314 | buf = GNUNET_malloc(FILESIZE); | 315 | buf = GNUNET_malloc (FILESIZE); |
315 | for (i = 0; i < FILESIZE; i++) | 316 | for (i = 0; i < FILESIZE; i++) |
316 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 317 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
317 | meta = GNUNET_CONTAINER_meta_data_create(); | 318 | meta = GNUNET_CONTAINER_meta_data_create (); |
318 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 319 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
319 | bo.content_priority = 42; | 320 | bo.content_priority = 42; |
320 | bo.anonymity_level = 1; | 321 | bo.anonymity_level = 1; |
321 | bo.replication_level = 0; | 322 | bo.replication_level = 0; |
322 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 323 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
323 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", | 324 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", |
324 | FILESIZE, buf, kuri, meta, | 325 | FILESIZE, buf, kuri, meta, |
325 | GNUNET_NO, &bo); | 326 | GNUNET_NO, &bo); |
326 | GNUNET_FS_uri_destroy(kuri); | 327 | GNUNET_FS_uri_destroy (kuri); |
327 | GNUNET_CONTAINER_meta_data_destroy(meta); | 328 | GNUNET_CONTAINER_meta_data_destroy (meta); |
328 | GNUNET_assert(NULL != fi); | 329 | GNUNET_assert (NULL != fi); |
329 | timeout_kill = | 330 | timeout_kill = |
330 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_kill_task, NULL); | 331 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL); |
331 | start = GNUNET_TIME_absolute_get(); | 332 | start = GNUNET_TIME_absolute_get (); |
332 | publish = | 333 | publish = |
333 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, | 334 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, |
334 | GNUNET_FS_PUBLISH_OPTION_NONE); | 335 | GNUNET_FS_PUBLISH_OPTION_NONE); |
335 | GNUNET_assert(publish != NULL); | 336 | GNUNET_assert (publish != NULL); |
336 | } | 337 | } |
337 | 338 | ||
338 | 339 | ||
339 | int | 340 | int |
340 | main(int argc, char *argv[]) | 341 | main (int argc, char *argv[]) |
341 | { | 342 | { |
342 | if (0 != GNUNET_TESTING_peer_run("test-fs-download-persistence", | 343 | if (0 != GNUNET_TESTING_peer_run ("test-fs-download-persistence", |
343 | "test_fs_download_data.conf", | 344 | "test_fs_download_data.conf", |
344 | &run, NULL)) | 345 | &run, NULL)) |
345 | return 1; | 346 | return 1; |
346 | return err; | 347 | return err; |
347 | } | 348 | } |
diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c index 1f008997f..3f6f2d5a8 100644 --- a/src/fs/test_fs_file_information.c +++ b/src/fs/test_fs_file_information.c | |||
@@ -44,21 +44,21 @@ | |||
44 | /** | 44 | /** |
45 | * How long should our test-content live? | 45 | * How long should our test-content live? |
46 | */ | 46 | */ |
47 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 47 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
48 | 48 | ||
49 | 49 | ||
50 | static int | 50 | static int |
51 | mycleaner(void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, | 51 | mycleaner (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, |
52 | struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, | 52 | struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, |
53 | struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info) | 53 | struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info) |
54 | { | 54 | { |
55 | return GNUNET_OK; | 55 | return GNUNET_OK; |
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | static void | 59 | static void |
60 | run(void *cls, char *const *args, const char *cfgfile, | 60 | run (void *cls, char *const *args, const char *cfgfile, |
61 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 61 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
62 | { | 62 | { |
63 | const char *keywords[] = { | 63 | const char *keywords[] = { |
64 | "down_foo", | 64 | "down_foo", |
@@ -76,67 +76,67 @@ run(void *cls, char *const *args, const char *cfgfile, | |||
76 | size_t i; | 76 | size_t i; |
77 | struct GNUNET_FS_BlockOptions bo; | 77 | struct GNUNET_FS_BlockOptions bo; |
78 | 78 | ||
79 | fs = GNUNET_FS_start(cfg, "test-fs-file-information", NULL, NULL, | 79 | fs = GNUNET_FS_start (cfg, "test-fs-file-information", NULL, NULL, |
80 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 80 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
81 | fn1 = GNUNET_DISK_mktemp("gnunet-file_information-test-dst"); | 81 | fn1 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst"); |
82 | buf = GNUNET_malloc(FILESIZE); | 82 | buf = GNUNET_malloc (FILESIZE); |
83 | for (i = 0; i < FILESIZE; i++) | 83 | for (i = 0; i < FILESIZE; i++) |
84 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 84 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
85 | GNUNET_assert(FILESIZE == | 85 | GNUNET_assert (FILESIZE == |
86 | GNUNET_DISK_fn_write(fn1, buf, FILESIZE, | 86 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, |
87 | GNUNET_DISK_PERM_USER_READ | | 87 | GNUNET_DISK_PERM_USER_READ |
88 | GNUNET_DISK_PERM_USER_WRITE)); | 88 | | GNUNET_DISK_PERM_USER_WRITE)); |
89 | GNUNET_free(buf); | 89 | GNUNET_free (buf); |
90 | 90 | ||
91 | fn2 = GNUNET_DISK_mktemp("gnunet-file_information-test-dst"); | 91 | fn2 = GNUNET_DISK_mktemp ("gnunet-file_information-test-dst"); |
92 | buf = GNUNET_malloc(FILESIZE); | 92 | buf = GNUNET_malloc (FILESIZE); |
93 | for (i = 0; i < FILESIZE; i++) | 93 | for (i = 0; i < FILESIZE; i++) |
94 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 94 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
95 | GNUNET_assert(FILESIZE == | 95 | GNUNET_assert (FILESIZE == |
96 | GNUNET_DISK_fn_write(fn2, buf, FILESIZE, | 96 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, |
97 | GNUNET_DISK_PERM_USER_READ | | 97 | GNUNET_DISK_PERM_USER_READ |
98 | GNUNET_DISK_PERM_USER_WRITE)); | 98 | | GNUNET_DISK_PERM_USER_WRITE)); |
99 | GNUNET_free(buf); | 99 | GNUNET_free (buf); |
100 | 100 | ||
101 | meta = GNUNET_CONTAINER_meta_data_create(); | 101 | meta = GNUNET_CONTAINER_meta_data_create (); |
102 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 102 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
103 | bo.content_priority = 42; | 103 | bo.content_priority = 42; |
104 | bo.anonymity_level = 1; | 104 | bo.anonymity_level = 1; |
105 | bo.replication_level = 0; | 105 | bo.replication_level = 0; |
106 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 106 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
107 | fi1 = | 107 | fi1 = |
108 | GNUNET_FS_file_information_create_from_file(fs, | 108 | GNUNET_FS_file_information_create_from_file (fs, |
109 | "file_information-context1", | 109 | "file_information-context1", |
110 | fn1, kuri, meta, GNUNET_YES, | 110 | fn1, kuri, meta, GNUNET_YES, |
111 | &bo); | 111 | &bo); |
112 | GNUNET_assert(fi1 != NULL); | 112 | GNUNET_assert (fi1 != NULL); |
113 | fi2 = | 113 | fi2 = |
114 | GNUNET_FS_file_information_create_from_file(fs, | 114 | GNUNET_FS_file_information_create_from_file (fs, |
115 | "file_information-context2", | 115 | "file_information-context2", |
116 | fn2, kuri, meta, GNUNET_YES, | 116 | fn2, kuri, meta, GNUNET_YES, |
117 | &bo); | 117 | &bo); |
118 | GNUNET_assert(fi2 != NULL); | 118 | GNUNET_assert (fi2 != NULL); |
119 | fidir = | 119 | fidir = |
120 | GNUNET_FS_file_information_create_empty_directory(fs, | 120 | GNUNET_FS_file_information_create_empty_directory (fs, |
121 | "file_information-context-dir", | 121 | "file_information-context-dir", |
122 | kuri, meta, &bo, NULL); | 122 | kuri, meta, &bo, NULL); |
123 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); | 123 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); |
124 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); | 124 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); |
125 | GNUNET_FS_uri_destroy(kuri); | 125 | GNUNET_FS_uri_destroy (kuri); |
126 | GNUNET_CONTAINER_meta_data_destroy(meta); | 126 | GNUNET_CONTAINER_meta_data_destroy (meta); |
127 | GNUNET_assert(NULL != fidir); | 127 | GNUNET_assert (NULL != fidir); |
128 | /* FIXME: test more of API! */ | 128 | /* FIXME: test more of API! */ |
129 | GNUNET_FS_file_information_destroy(fidir, &mycleaner, NULL); | 129 | GNUNET_FS_file_information_destroy (fidir, &mycleaner, NULL); |
130 | GNUNET_DISK_directory_remove(fn1); | 130 | GNUNET_DISK_directory_remove (fn1); |
131 | GNUNET_DISK_directory_remove(fn2); | 131 | GNUNET_DISK_directory_remove (fn2); |
132 | GNUNET_free_non_null(fn1); | 132 | GNUNET_free_non_null (fn1); |
133 | GNUNET_free_non_null(fn2); | 133 | GNUNET_free_non_null (fn2); |
134 | GNUNET_FS_stop(fs); | 134 | GNUNET_FS_stop (fs); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | int | 138 | int |
139 | main(int argc, char *argv[]) | 139 | main (int argc, char *argv[]) |
140 | { | 140 | { |
141 | char *const argvx[] = { | 141 | char *const argvx[] = { |
142 | "test-fs-file_information", | 142 | "test-fs-file_information", |
@@ -148,12 +148,12 @@ main(int argc, char *argv[]) | |||
148 | GNUNET_GETOPT_OPTION_END | 148 | GNUNET_GETOPT_OPTION_END |
149 | }; | 149 | }; |
150 | 150 | ||
151 | GNUNET_log_setup("test_fs_file_information", | 151 | GNUNET_log_setup ("test_fs_file_information", |
152 | "WARNING", | 152 | "WARNING", |
153 | NULL); | 153 | NULL); |
154 | GNUNET_PROGRAM_run((sizeof(argvx) / sizeof(char *)) - 1, argvx, | 154 | GNUNET_PROGRAM_run ((sizeof(argvx) / sizeof(char *)) - 1, argvx, |
155 | "test-fs-file_information", "nohelp", options, &run, | 155 | "test-fs-file_information", "nohelp", options, &run, |
156 | NULL); | 156 | NULL); |
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | 159 | ||
diff --git a/src/fs/test_fs_getopt.c b/src/fs/test_fs_getopt.c index 48777b0e0..3d0da752b 100644 --- a/src/fs/test_fs_getopt.c +++ b/src/fs/test_fs_getopt.c | |||
@@ -27,11 +27,11 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | int | 29 | int |
30 | main(int argc, char *argv[]) | 30 | main (int argc, char *argv[]) |
31 | { | 31 | { |
32 | GNUNET_log_setup("test_fs_getopt", | 32 | GNUNET_log_setup ("test_fs_getopt", |
33 | "WARNING", | 33 | "WARNING", |
34 | NULL); | 34 | NULL); |
35 | fprintf(stderr, "%s", "WARNING: testcase not yet written.\n"); | 35 | fprintf (stderr, "%s", "WARNING: testcase not yet written.\n"); |
36 | return 0; /* testcase passed */ | 36 | return 0; /* testcase passed */ |
37 | } | 37 | } |
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c index b5e5982d0..431d42b2e 100644 --- a/src/fs/test_fs_list_indexed.c +++ b/src/fs/test_fs_list_indexed.c | |||
@@ -40,12 +40,12 @@ | |||
40 | /** | 40 | /** |
41 | * How long until we give up on transmitting the message? | 41 | * How long until we give up on transmitting the message? |
42 | */ | 42 | */ |
43 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 43 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * How long should our test-content live? | 46 | * How long should our test-content live? |
47 | */ | 47 | */ |
48 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 48 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
49 | 49 | ||
50 | 50 | ||
51 | static struct GNUNET_TIME_Absolute start; | 51 | static struct GNUNET_TIME_Absolute start; |
@@ -62,121 +62,121 @@ static int err; | |||
62 | 62 | ||
63 | 63 | ||
64 | static void | 64 | static void |
65 | abort_publish_task(void *cls) | 65 | abort_publish_task (void *cls) |
66 | { | 66 | { |
67 | GNUNET_FS_publish_stop(publish); | 67 | GNUNET_FS_publish_stop (publish); |
68 | publish = NULL; | 68 | publish = NULL; |
69 | GNUNET_DISK_directory_remove(fn1); | 69 | GNUNET_DISK_directory_remove (fn1); |
70 | GNUNET_free(fn1); | 70 | GNUNET_free (fn1); |
71 | fn1 = NULL; | 71 | fn1 = NULL; |
72 | GNUNET_DISK_directory_remove(fn2); | 72 | GNUNET_DISK_directory_remove (fn2); |
73 | GNUNET_free(fn2); | 73 | GNUNET_free (fn2); |
74 | fn2 = NULL; | 74 | fn2 = NULL; |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | static void | 78 | static void |
79 | list_indexed_task(void *cls) | 79 | list_indexed_task (void *cls) |
80 | { | 80 | { |
81 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 81 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | static void * | 85 | static void * |
86 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 86 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
87 | { | 87 | { |
88 | void *ret; | 88 | void *ret; |
89 | 89 | ||
90 | ret = NULL; | 90 | ret = NULL; |
91 | switch (event->status) | 91 | switch (event->status) |
92 | { | ||
93 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
94 | ret = event->value.publish.cctx; | ||
95 | printf ("Publish complete, %llu kbps.\n", | ||
96 | (unsigned long long) (FILESIZE * 1000000LL | ||
97 | / (1 | ||
98 | + GNUNET_TIME_absolute_get_duration | ||
99 | (start).rel_value_us) / 1024)); | ||
100 | if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | ||
101 | GNUNET_SCHEDULER_add_now (&list_indexed_task, NULL); | ||
102 | |||
103 | break; | ||
104 | |||
105 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
106 | ret = event->value.publish.cctx; | ||
107 | GNUNET_assert (publish == event->value.publish.pc); | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
109 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | ||
110 | (unsigned long long) event->value.publish.completed, | ||
111 | (unsigned long long) event->value.publish.size, | ||
112 | event->value.publish.specifics.progress.depth, | ||
113 | (unsigned long long) event->value.publish.specifics. | ||
114 | progress.offset); | ||
115 | break; | ||
116 | |||
117 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
118 | ret = event->value.publish.cctx; | ||
119 | break; | ||
120 | |||
121 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
122 | ret = event->value.publish.cctx; | ||
123 | fprintf (stderr, "Error publishing file: %s\n", | ||
124 | event->value.publish.specifics.error.message); | ||
125 | err = 1; | ||
126 | if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | ||
127 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
128 | break; | ||
129 | |||
130 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
131 | ret = event->value.publish.cctx; | ||
132 | if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx)) | ||
92 | { | 133 | { |
93 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 134 | GNUNET_assert (0 == |
94 | ret = event->value.publish.cctx; | 135 | strcmp ("list_indexed-context-dir", |
95 | printf("Publish complete, %llu kbps.\n", | 136 | event->value.publish.pctx)); |
96 | (unsigned long long)(FILESIZE * 1000000LL / | 137 | GNUNET_assert (FILESIZE == event->value.publish.size); |
97 | (1 + | 138 | GNUNET_assert (0 == event->value.publish.completed); |
98 | GNUNET_TIME_absolute_get_duration | 139 | GNUNET_assert (1 == event->value.publish.anonymity); |
99 | (start).rel_value_us) / 1024)); | ||
100 | if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx)) | ||
101 | GNUNET_SCHEDULER_add_now(&list_indexed_task, NULL); | ||
102 | |||
103 | break; | ||
104 | |||
105 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
106 | ret = event->value.publish.cctx; | ||
107 | GNUNET_assert(publish == event->value.publish.pc); | ||
108 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
109 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | ||
110 | (unsigned long long)event->value.publish.completed, | ||
111 | (unsigned long long)event->value.publish.size, | ||
112 | event->value.publish.specifics.progress.depth, | ||
113 | (unsigned long long)event->value.publish.specifics. | ||
114 | progress.offset); | ||
115 | break; | ||
116 | |||
117 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
118 | ret = event->value.publish.cctx; | ||
119 | break; | ||
120 | |||
121 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
122 | ret = event->value.publish.cctx; | ||
123 | fprintf(stderr, "Error publishing file: %s\n", | ||
124 | event->value.publish.specifics.error.message); | ||
125 | err = 1; | ||
126 | if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx)) | ||
127 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
128 | break; | ||
129 | |||
130 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
131 | ret = event->value.publish.cctx; | ||
132 | if (0 == strcmp("list_indexed-context1", event->value.publish.cctx)) | ||
133 | { | ||
134 | GNUNET_assert(0 == | ||
135 | strcmp("list_indexed-context-dir", | ||
136 | event->value.publish.pctx)); | ||
137 | GNUNET_assert(FILESIZE == event->value.publish.size); | ||
138 | GNUNET_assert(0 == event->value.publish.completed); | ||
139 | GNUNET_assert(1 == event->value.publish.anonymity); | ||
140 | } | ||
141 | else if (0 == strcmp("list_indexed-context2", event->value.publish.cctx)) | ||
142 | { | ||
143 | GNUNET_assert(0 == | ||
144 | strcmp("list_indexed-context-dir", | ||
145 | event->value.publish.pctx)); | ||
146 | GNUNET_assert(FILESIZE == event->value.publish.size); | ||
147 | GNUNET_assert(0 == event->value.publish.completed); | ||
148 | GNUNET_assert(2 == event->value.publish.anonymity); | ||
149 | } | ||
150 | else if (0 == | ||
151 | strcmp("list_indexed-context-dir", event->value.publish.cctx)) | ||
152 | { | ||
153 | GNUNET_assert(0 == event->value.publish.completed); | ||
154 | GNUNET_assert(3 == event->value.publish.anonymity); | ||
155 | } | ||
156 | else | ||
157 | GNUNET_assert(0); | ||
158 | break; | ||
159 | |||
160 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
161 | if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx)) | ||
162 | { | ||
163 | GNUNET_assert(publish == event->value.publish.pc); | ||
164 | publish = NULL; | ||
165 | } | ||
166 | break; | ||
167 | |||
168 | default: | ||
169 | printf("Unexpected event: %d\n", event->status); | ||
170 | break; | ||
171 | } | 140 | } |
141 | else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx)) | ||
142 | { | ||
143 | GNUNET_assert (0 == | ||
144 | strcmp ("list_indexed-context-dir", | ||
145 | event->value.publish.pctx)); | ||
146 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
147 | GNUNET_assert (0 == event->value.publish.completed); | ||
148 | GNUNET_assert (2 == event->value.publish.anonymity); | ||
149 | } | ||
150 | else if (0 == | ||
151 | strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | ||
152 | { | ||
153 | GNUNET_assert (0 == event->value.publish.completed); | ||
154 | GNUNET_assert (3 == event->value.publish.anonymity); | ||
155 | } | ||
156 | else | ||
157 | GNUNET_assert (0); | ||
158 | break; | ||
159 | |||
160 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
161 | if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | ||
162 | { | ||
163 | GNUNET_assert (publish == event->value.publish.pc); | ||
164 | publish = NULL; | ||
165 | } | ||
166 | break; | ||
167 | |||
168 | default: | ||
169 | printf ("Unexpected event: %d\n", event->status); | ||
170 | break; | ||
171 | } | ||
172 | return ret; | 172 | return ret; |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | static void | 176 | static void |
177 | run(void *cls, | 177 | run (void *cls, |
178 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 178 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
179 | struct GNUNET_TESTING_Peer *peer) | 179 | struct GNUNET_TESTING_Peer *peer) |
180 | { | 180 | { |
181 | const char *keywords[] = { | 181 | const char *keywords[] = { |
182 | "down_foo", | 182 | "down_foo", |
@@ -191,70 +191,70 @@ run(void *cls, | |||
191 | size_t i; | 191 | size_t i; |
192 | struct GNUNET_FS_BlockOptions bo; | 192 | struct GNUNET_FS_BlockOptions bo; |
193 | 193 | ||
194 | fs = GNUNET_FS_start(cfg, "test-fs-list_indexed", &progress_cb, NULL, | 194 | fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL, |
195 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 195 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
196 | GNUNET_assert(NULL != fs); | 196 | GNUNET_assert (NULL != fs); |
197 | fn1 = GNUNET_DISK_mktemp("gnunet-list_indexed-test-dst"); | 197 | fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); |
198 | buf = GNUNET_malloc(FILESIZE); | 198 | buf = GNUNET_malloc (FILESIZE); |
199 | for (i = 0; i < FILESIZE; i++) | 199 | for (i = 0; i < FILESIZE; i++) |
200 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 200 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
201 | GNUNET_assert(FILESIZE == | 201 | GNUNET_assert (FILESIZE == |
202 | GNUNET_DISK_fn_write(fn1, buf, FILESIZE, | 202 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, |
203 | GNUNET_DISK_PERM_USER_READ | | 203 | GNUNET_DISK_PERM_USER_READ |
204 | GNUNET_DISK_PERM_USER_WRITE)); | 204 | | GNUNET_DISK_PERM_USER_WRITE)); |
205 | GNUNET_free(buf); | 205 | GNUNET_free (buf); |
206 | 206 | ||
207 | fn2 = GNUNET_DISK_mktemp("gnunet-list_indexed-test-dst"); | 207 | fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); |
208 | buf = GNUNET_malloc(FILESIZE); | 208 | buf = GNUNET_malloc (FILESIZE); |
209 | for (i = 0; i < FILESIZE; i++) | 209 | for (i = 0; i < FILESIZE; i++) |
210 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 210 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
211 | GNUNET_assert(FILESIZE == | 211 | GNUNET_assert (FILESIZE == |
212 | GNUNET_DISK_fn_write(fn2, buf, FILESIZE, | 212 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, |
213 | GNUNET_DISK_PERM_USER_READ | | 213 | GNUNET_DISK_PERM_USER_READ |
214 | GNUNET_DISK_PERM_USER_WRITE)); | 214 | | GNUNET_DISK_PERM_USER_WRITE)); |
215 | GNUNET_free(buf); | 215 | GNUNET_free (buf); |
216 | 216 | ||
217 | meta = GNUNET_CONTAINER_meta_data_create(); | 217 | meta = GNUNET_CONTAINER_meta_data_create (); |
218 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 218 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
219 | bo.content_priority = 42; | 219 | bo.content_priority = 42; |
220 | bo.anonymity_level = 1; | 220 | bo.anonymity_level = 1; |
221 | bo.replication_level = 0; | 221 | bo.replication_level = 0; |
222 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 222 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
223 | fi1 = | 223 | fi1 = |
224 | GNUNET_FS_file_information_create_from_file(fs, "list_indexed-context1", | 224 | GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context1", |
225 | fn1, kuri, meta, GNUNET_YES, | 225 | fn1, kuri, meta, GNUNET_YES, |
226 | &bo); | 226 | &bo); |
227 | GNUNET_assert(NULL != fi1); | 227 | GNUNET_assert (NULL != fi1); |
228 | bo.anonymity_level = 2; | 228 | bo.anonymity_level = 2; |
229 | fi2 = | 229 | fi2 = |
230 | GNUNET_FS_file_information_create_from_file(fs, "list_indexed-context2", | 230 | GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context2", |
231 | fn2, kuri, meta, GNUNET_YES, | 231 | fn2, kuri, meta, GNUNET_YES, |
232 | &bo); | 232 | &bo); |
233 | GNUNET_assert(NULL != fi2); | 233 | GNUNET_assert (NULL != fi2); |
234 | bo.anonymity_level = 3; | 234 | bo.anonymity_level = 3; |
235 | fidir = | 235 | fidir = |
236 | GNUNET_FS_file_information_create_empty_directory(fs, | 236 | GNUNET_FS_file_information_create_empty_directory (fs, |
237 | "list_indexed-context-dir", | 237 | "list_indexed-context-dir", |
238 | kuri, meta, &bo, NULL); | 238 | kuri, meta, &bo, NULL); |
239 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); | 239 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); |
240 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); | 240 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); |
241 | GNUNET_FS_uri_destroy(kuri); | 241 | GNUNET_FS_uri_destroy (kuri); |
242 | GNUNET_CONTAINER_meta_data_destroy(meta); | 242 | GNUNET_CONTAINER_meta_data_destroy (meta); |
243 | GNUNET_assert(NULL != fidir); | 243 | GNUNET_assert (NULL != fidir); |
244 | start = GNUNET_TIME_absolute_get(); | 244 | start = GNUNET_TIME_absolute_get (); |
245 | publish = | 245 | publish = |
246 | GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL, | 246 | GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, |
247 | GNUNET_FS_PUBLISH_OPTION_NONE); | 247 | GNUNET_FS_PUBLISH_OPTION_NONE); |
248 | GNUNET_assert(publish != NULL); | 248 | GNUNET_assert (publish != NULL); |
249 | } | 249 | } |
250 | 250 | ||
251 | 251 | ||
252 | int | 252 | int |
253 | main(int argc, char *argv[]) | 253 | main (int argc, char *argv[]) |
254 | { | 254 | { |
255 | if (0 != GNUNET_TESTING_peer_run("test-fs-list-indexed", | 255 | if (0 != GNUNET_TESTING_peer_run ("test-fs-list-indexed", |
256 | "test_fs_list_indexed_data.conf", | 256 | "test_fs_list_indexed_data.conf", |
257 | &run, NULL)) | 257 | &run, NULL)) |
258 | return 1; | 258 | return 1; |
259 | return 0; | 259 | return 0; |
260 | } | 260 | } |
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c index 3abbd5063..cdcb4d8fd 100644 --- a/src/fs/test_fs_namespace.c +++ b/src/fs/test_fs_namespace.c | |||
@@ -41,7 +41,7 @@ static struct GNUNET_FS_SearchContext *sks_search; | |||
41 | 41 | ||
42 | static struct GNUNET_FS_SearchContext *ksk_search; | 42 | static struct GNUNET_FS_SearchContext *ksk_search; |
43 | 43 | ||
44 | static struct GNUNET_SCHEDULER_Task * kill_task; | 44 | static struct GNUNET_SCHEDULER_Task *kill_task; |
45 | 45 | ||
46 | static int update_started; | 46 | static int update_started; |
47 | 47 | ||
@@ -49,123 +49,123 @@ static int err; | |||
49 | 49 | ||
50 | 50 | ||
51 | static void | 51 | static void |
52 | abort_ksk_search_task(void *cls) | 52 | abort_ksk_search_task (void *cls) |
53 | { | 53 | { |
54 | if (ksk_search != NULL) | 54 | if (ksk_search != NULL) |
55 | { | ||
56 | GNUNET_FS_search_stop (ksk_search); | ||
57 | ksk_search = NULL; | ||
58 | if (sks_search == NULL) | ||
55 | { | 59 | { |
56 | GNUNET_FS_search_stop(ksk_search); | 60 | GNUNET_FS_stop (fs); |
57 | ksk_search = NULL; | 61 | if (NULL != kill_task) |
58 | if (sks_search == NULL) | 62 | GNUNET_SCHEDULER_cancel (kill_task); |
59 | { | ||
60 | GNUNET_FS_stop(fs); | ||
61 | if (NULL != kill_task) | ||
62 | GNUNET_SCHEDULER_cancel(kill_task); | ||
63 | } | ||
64 | } | 63 | } |
64 | } | ||
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | static void | 68 | static void |
69 | abort_sks_search_task(void *cls) | 69 | abort_sks_search_task (void *cls) |
70 | { | 70 | { |
71 | if (sks_search == NULL) | 71 | if (sks_search == NULL) |
72 | return; | 72 | return; |
73 | GNUNET_FS_search_stop(sks_search); | 73 | GNUNET_FS_search_stop (sks_search); |
74 | sks_search = NULL; | 74 | sks_search = NULL; |
75 | if (ksk_search == NULL) | 75 | if (ksk_search == NULL) |
76 | { | 76 | { |
77 | GNUNET_FS_stop(fs); | 77 | GNUNET_FS_stop (fs); |
78 | if (NULL != kill_task) | 78 | if (NULL != kill_task) |
79 | GNUNET_SCHEDULER_cancel(kill_task); | 79 | GNUNET_SCHEDULER_cancel (kill_task); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | static void | 84 | static void |
85 | do_timeout(void *cls) | 85 | do_timeout (void *cls) |
86 | { | 86 | { |
87 | err = 1; | 87 | err = 1; |
88 | fprintf(stderr, "%s", "Operation timed out\n"); | 88 | fprintf (stderr, "%s", "Operation timed out\n"); |
89 | kill_task = NULL; | 89 | kill_task = NULL; |
90 | abort_sks_search_task(NULL); | 90 | abort_sks_search_task (NULL); |
91 | abort_ksk_search_task(NULL); | 91 | abort_ksk_search_task (NULL); |
92 | } | 92 | } |
93 | 93 | ||
94 | 94 | ||
95 | static void * | 95 | static void * |
96 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 96 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
97 | { | 97 | { |
98 | switch (event->status) | 98 | switch (event->status) |
99 | { | ||
100 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
101 | if (sks_search == event->value.search.sc) | ||
99 | { | 102 | { |
100 | case GNUNET_FS_STATUS_SEARCH_RESULT: | 103 | if (! GNUNET_FS_uri_test_equal |
101 | if (sks_search == event->value.search.sc) | 104 | (sks_expect_uri, event->value.search.specifics.result.uri)) |
102 | { | 105 | { |
103 | if (!GNUNET_FS_uri_test_equal | 106 | fprintf (stderr, "%s", "Wrong result for sks search!\n"); |
104 | (sks_expect_uri, event->value.search.specifics.result.uri)) | 107 | err = 1; |
105 | { | 108 | } |
106 | fprintf(stderr, "%s", "Wrong result for sks search!\n"); | 109 | /* give system 1ms to initiate update search! */ |
107 | err = 1; | 110 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, |
108 | } | 111 | &abort_sks_search_task, NULL); |
109 | /* give system 1ms to initiate update search! */ | ||
110 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MILLISECONDS, | ||
111 | &abort_sks_search_task, NULL); | ||
112 | } | ||
113 | else if (ksk_search == event->value.search.sc) | ||
114 | { | ||
115 | if (!GNUNET_FS_uri_test_equal | ||
116 | (ksk_expect_uri, event->value.search.specifics.result.uri)) | ||
117 | { | ||
118 | fprintf(stderr, "%s", "Wrong result for ksk search!\n"); | ||
119 | err = 1; | ||
120 | } | ||
121 | GNUNET_SCHEDULER_add_now(&abort_ksk_search_task, NULL); | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | fprintf(stderr, "%s", "Unexpected search result received!\n"); | ||
126 | GNUNET_break(0); | ||
127 | } | ||
128 | break; | ||
129 | |||
130 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
131 | fprintf(stderr, "Error searching file: %s\n", | ||
132 | event->value.search.specifics.error.message); | ||
133 | if (sks_search == event->value.search.sc) | ||
134 | GNUNET_SCHEDULER_add_now(&abort_sks_search_task, NULL); | ||
135 | else if (ksk_search == event->value.search.sc) | ||
136 | GNUNET_SCHEDULER_add_now(&abort_ksk_search_task, NULL); | ||
137 | else | ||
138 | GNUNET_break(0); | ||
139 | break; | ||
140 | |||
141 | case GNUNET_FS_STATUS_SEARCH_START: | ||
142 | GNUNET_assert((NULL == event->value.search.cctx) || | ||
143 | (0 == strcmp("sks_search", event->value.search.cctx)) || | ||
144 | (0 == strcmp("ksk_search", event->value.search.cctx))); | ||
145 | if (NULL == event->value.search.cctx) | ||
146 | { | ||
147 | GNUNET_assert(0 == strcmp("sks_search", event->value.search.pctx)); | ||
148 | update_started = GNUNET_YES; | ||
149 | } | ||
150 | GNUNET_assert(1 == event->value.search.anonymity); | ||
151 | break; | ||
152 | |||
153 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
154 | return NULL; | ||
155 | |||
156 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
157 | return NULL; | ||
158 | |||
159 | default: | ||
160 | fprintf(stderr, "Unexpected event: %d\n", event->status); | ||
161 | break; | ||
162 | } | 112 | } |
113 | else if (ksk_search == event->value.search.sc) | ||
114 | { | ||
115 | if (! GNUNET_FS_uri_test_equal | ||
116 | (ksk_expect_uri, event->value.search.specifics.result.uri)) | ||
117 | { | ||
118 | fprintf (stderr, "%s", "Wrong result for ksk search!\n"); | ||
119 | err = 1; | ||
120 | } | ||
121 | GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | fprintf (stderr, "%s", "Unexpected search result received!\n"); | ||
126 | GNUNET_break (0); | ||
127 | } | ||
128 | break; | ||
129 | |||
130 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
131 | fprintf (stderr, "Error searching file: %s\n", | ||
132 | event->value.search.specifics.error.message); | ||
133 | if (sks_search == event->value.search.sc) | ||
134 | GNUNET_SCHEDULER_add_now (&abort_sks_search_task, NULL); | ||
135 | else if (ksk_search == event->value.search.sc) | ||
136 | GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); | ||
137 | else | ||
138 | GNUNET_break (0); | ||
139 | break; | ||
140 | |||
141 | case GNUNET_FS_STATUS_SEARCH_START: | ||
142 | GNUNET_assert ((NULL == event->value.search.cctx) || | ||
143 | (0 == strcmp ("sks_search", event->value.search.cctx)) || | ||
144 | (0 == strcmp ("ksk_search", event->value.search.cctx))); | ||
145 | if (NULL == event->value.search.cctx) | ||
146 | { | ||
147 | GNUNET_assert (0 == strcmp ("sks_search", event->value.search.pctx)); | ||
148 | update_started = GNUNET_YES; | ||
149 | } | ||
150 | GNUNET_assert (1 == event->value.search.anonymity); | ||
151 | break; | ||
152 | |||
153 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
154 | return NULL; | ||
155 | |||
156 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
157 | return NULL; | ||
158 | |||
159 | default: | ||
160 | fprintf (stderr, "Unexpected event: %d\n", event->status); | ||
161 | break; | ||
162 | } | ||
163 | return event->value.search.cctx; | 163 | return event->value.search.cctx; |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | static void | 167 | static void |
168 | publish_cont(void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) | 168 | publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) |
169 | { | 169 | { |
170 | char *msg; | 170 | char *msg; |
171 | struct GNUNET_FS_Uri *sks_uri; | 171 | struct GNUNET_FS_Uri *sks_uri; |
@@ -174,37 +174,37 @@ publish_cont(void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) | |||
174 | char *ret; | 174 | char *ret; |
175 | 175 | ||
176 | if (NULL != emsg) | 176 | if (NULL != emsg) |
177 | { | 177 | { |
178 | fprintf(stderr, "Error publishing: %s\n", emsg); | 178 | fprintf (stderr, "Error publishing: %s\n", emsg); |
179 | err = 1; | 179 | err = 1; |
180 | GNUNET_FS_stop(fs); | 180 | GNUNET_FS_stop (fs); |
181 | return; | 181 | return; |
182 | } | 182 | } |
183 | ret = GNUNET_STRINGS_data_to_string(&nsid, sizeof(nsid), buf, sizeof(buf)); | 183 | ret = GNUNET_STRINGS_data_to_string (&nsid, sizeof(nsid), buf, sizeof(buf)); |
184 | GNUNET_assert(NULL != ret); | 184 | GNUNET_assert (NULL != ret); |
185 | ret[0] = '\0'; | 185 | ret[0] = '\0'; |
186 | GNUNET_snprintf(sbuf, sizeof(sbuf), "gnunet://fs/sks/%s/this", buf); | 186 | GNUNET_snprintf (sbuf, sizeof(sbuf), "gnunet://fs/sks/%s/this", buf); |
187 | sks_uri = GNUNET_FS_uri_parse(sbuf, &msg); | 187 | sks_uri = GNUNET_FS_uri_parse (sbuf, &msg); |
188 | if (NULL == sks_uri) | 188 | if (NULL == sks_uri) |
189 | { | 189 | { |
190 | fprintf(stderr, "failed to parse URI `%s': %s\n", sbuf, msg); | 190 | fprintf (stderr, "failed to parse URI `%s': %s\n", sbuf, msg); |
191 | err = 1; | 191 | err = 1; |
192 | GNUNET_FS_stop(fs); | 192 | GNUNET_FS_stop (fs); |
193 | GNUNET_free_non_null(msg); | 193 | GNUNET_free_non_null (msg); |
194 | return; | 194 | return; |
195 | } | 195 | } |
196 | ksk_search = | 196 | ksk_search = |
197 | GNUNET_FS_search_start(fs, ksk_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | 197 | GNUNET_FS_search_start (fs, ksk_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, |
198 | "ksk_search"); | 198 | "ksk_search"); |
199 | sks_search = | 199 | sks_search = |
200 | GNUNET_FS_search_start(fs, sks_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | 200 | GNUNET_FS_search_start (fs, sks_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, |
201 | "sks_search"); | 201 | "sks_search"); |
202 | GNUNET_FS_uri_destroy(sks_uri); | 202 | GNUNET_FS_uri_destroy (sks_uri); |
203 | } | 203 | } |
204 | 204 | ||
205 | 205 | ||
206 | static void | 206 | static void |
207 | sks_cont(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | 207 | sks_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) |
208 | { | 208 | { |
209 | struct GNUNET_CONTAINER_MetaData *meta; | 209 | struct GNUNET_CONTAINER_MetaData *meta; |
210 | struct GNUNET_FS_Uri *ksk_uri; | 210 | struct GNUNET_FS_Uri *ksk_uri; |
@@ -212,61 +212,61 @@ sks_cont(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | |||
212 | struct GNUNET_FS_BlockOptions bo; | 212 | struct GNUNET_FS_BlockOptions bo; |
213 | 213 | ||
214 | if (NULL == uri) | 214 | if (NULL == uri) |
215 | { | 215 | { |
216 | fprintf(stderr, "Error publishing: %s\n", emsg); | 216 | fprintf (stderr, "Error publishing: %s\n", emsg); |
217 | err = 1; | 217 | err = 1; |
218 | GNUNET_FS_stop(fs); | 218 | GNUNET_FS_stop (fs); |
219 | return; | 219 | return; |
220 | } | 220 | } |
221 | meta = GNUNET_CONTAINER_meta_data_create(); | 221 | meta = GNUNET_CONTAINER_meta_data_create (); |
222 | msg = NULL; | 222 | msg = NULL; |
223 | ksk_uri = GNUNET_FS_uri_parse("gnunet://fs/ksk/ns-search", &msg); | 223 | ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/ns-search", &msg); |
224 | GNUNET_assert(NULL == msg); | 224 | GNUNET_assert (NULL == msg); |
225 | ksk_expect_uri = GNUNET_FS_uri_dup(uri); | 225 | ksk_expect_uri = GNUNET_FS_uri_dup (uri); |
226 | bo.content_priority = 1; | 226 | bo.content_priority = 1; |
227 | bo.anonymity_level = 1; | 227 | bo.anonymity_level = 1; |
228 | bo.replication_level = 0; | 228 | bo.replication_level = 0; |
229 | bo.expiration_time = | 229 | bo.expiration_time = |
230 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); | 230 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); |
231 | GNUNET_FS_publish_ksk(fs, ksk_uri, meta, uri, &bo, | 231 | GNUNET_FS_publish_ksk (fs, ksk_uri, meta, uri, &bo, |
232 | GNUNET_FS_PUBLISH_OPTION_NONE, &publish_cont, NULL); | 232 | GNUNET_FS_PUBLISH_OPTION_NONE, &publish_cont, NULL); |
233 | GNUNET_FS_uri_destroy(ksk_uri); | 233 | GNUNET_FS_uri_destroy (ksk_uri); |
234 | GNUNET_CONTAINER_meta_data_destroy(meta); | 234 | GNUNET_CONTAINER_meta_data_destroy (meta); |
235 | } | 235 | } |
236 | 236 | ||
237 | 237 | ||
238 | static void | 238 | static void |
239 | adv_cont(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | 239 | adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) |
240 | { | 240 | { |
241 | struct GNUNET_CONTAINER_MetaData *meta; | 241 | struct GNUNET_CONTAINER_MetaData *meta; |
242 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; | 242 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; |
243 | struct GNUNET_FS_BlockOptions bo; | 243 | struct GNUNET_FS_BlockOptions bo; |
244 | 244 | ||
245 | if (NULL != emsg) | 245 | if (NULL != emsg) |
246 | { | 246 | { |
247 | fprintf(stderr, "Error publishing: %s\n", emsg); | 247 | fprintf (stderr, "Error publishing: %s\n", emsg); |
248 | err = 1; | 248 | err = 1; |
249 | GNUNET_FS_stop(fs); | 249 | GNUNET_FS_stop (fs); |
250 | return; | 250 | return; |
251 | } | 251 | } |
252 | ns = GNUNET_CRYPTO_ecdsa_key_create(); | 252 | ns = GNUNET_CRYPTO_ecdsa_key_create (); |
253 | meta = GNUNET_CONTAINER_meta_data_create(); | 253 | meta = GNUNET_CONTAINER_meta_data_create (); |
254 | sks_expect_uri = GNUNET_FS_uri_dup(uri); | 254 | sks_expect_uri = GNUNET_FS_uri_dup (uri); |
255 | bo.content_priority = 1; | 255 | bo.content_priority = 1; |
256 | bo.anonymity_level = 1; | 256 | bo.anonymity_level = 1; |
257 | bo.replication_level = 0; | 257 | bo.replication_level = 0; |
258 | bo.expiration_time = | 258 | bo.expiration_time = |
259 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); | 259 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); |
260 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, &nsid); | 260 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &nsid); |
261 | GNUNET_FS_publish_sks(fs, ns, "this", "next", meta, uri, | 261 | GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri, |
262 | &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL); | 262 | &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL); |
263 | GNUNET_CONTAINER_meta_data_destroy(meta); | 263 | GNUNET_CONTAINER_meta_data_destroy (meta); |
264 | GNUNET_free(ns); | 264 | GNUNET_free (ns); |
265 | } | 265 | } |
266 | 266 | ||
267 | 267 | ||
268 | static void | 268 | static void |
269 | testNamespace() | 269 | testNamespace () |
270 | { | 270 | { |
271 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; | 271 | struct GNUNET_CRYPTO_EcdsaPrivateKey *ns; |
272 | struct GNUNET_FS_BlockOptions bo; | 272 | struct GNUNET_FS_BlockOptions bo; |
@@ -274,46 +274,46 @@ testNamespace() | |||
274 | struct GNUNET_FS_Uri *ksk_uri; | 274 | struct GNUNET_FS_Uri *ksk_uri; |
275 | struct GNUNET_FS_Uri *sks_uri; | 275 | struct GNUNET_FS_Uri *sks_uri; |
276 | 276 | ||
277 | ns = GNUNET_CRYPTO_ecdsa_key_create(); | 277 | ns = GNUNET_CRYPTO_ecdsa_key_create (); |
278 | meta = GNUNET_CONTAINER_meta_data_create(); | 278 | meta = GNUNET_CONTAINER_meta_data_create (); |
279 | ksk_uri = GNUNET_FS_uri_parse("gnunet://fs/ksk/testnsa", NULL); | 279 | ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/testnsa", NULL); |
280 | bo.content_priority = 1; | 280 | bo.content_priority = 1; |
281 | bo.anonymity_level = 1; | 281 | bo.anonymity_level = 1; |
282 | bo.replication_level = 0; | 282 | bo.replication_level = 0; |
283 | bo.expiration_time = | 283 | bo.expiration_time = |
284 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); | 284 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); |
285 | sks_uri = GNUNET_FS_uri_sks_create(&nsid, "root"); | 285 | sks_uri = GNUNET_FS_uri_sks_create (&nsid, "root"); |
286 | GNUNET_FS_publish_ksk(fs, | 286 | GNUNET_FS_publish_ksk (fs, |
287 | ksk_uri, meta, sks_uri, | 287 | ksk_uri, meta, sks_uri, |
288 | &bo, GNUNET_FS_PUBLISH_OPTION_NONE, | 288 | &bo, GNUNET_FS_PUBLISH_OPTION_NONE, |
289 | &adv_cont, NULL); | 289 | &adv_cont, NULL); |
290 | GNUNET_FS_uri_destroy(sks_uri); | 290 | GNUNET_FS_uri_destroy (sks_uri); |
291 | kill_task = | 291 | kill_task = |
292 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, &do_timeout, | 292 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &do_timeout, |
293 | NULL); | 293 | NULL); |
294 | GNUNET_FS_uri_destroy(ksk_uri); | 294 | GNUNET_FS_uri_destroy (ksk_uri); |
295 | GNUNET_CONTAINER_meta_data_destroy(meta); | 295 | GNUNET_CONTAINER_meta_data_destroy (meta); |
296 | GNUNET_free(ns); | 296 | GNUNET_free (ns); |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | static void | 300 | static void |
301 | run(void *cls, | 301 | run (void *cls, |
302 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 302 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
303 | struct GNUNET_TESTING_Peer *peer) | 303 | struct GNUNET_TESTING_Peer *peer) |
304 | { | 304 | { |
305 | fs = GNUNET_FS_start(cfg, "test-fs-namespace", &progress_cb, NULL, | 305 | fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL, |
306 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 306 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
307 | testNamespace(); | 307 | testNamespace (); |
308 | } | 308 | } |
309 | 309 | ||
310 | 310 | ||
311 | int | 311 | int |
312 | main(int argc, char *argv[]) | 312 | main (int argc, char *argv[]) |
313 | { | 313 | { |
314 | if (0 != GNUNET_TESTING_peer_run("test-fs-namespace", | 314 | if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace", |
315 | "test_fs_namespace_data.conf", | 315 | "test_fs_namespace_data.conf", |
316 | &run, NULL)) | 316 | &run, NULL)) |
317 | return 1; | 317 | return 1; |
318 | return err; | 318 | return err; |
319 | } | 319 | } |
diff --git a/src/fs/test_fs_namespace_list_updateable.c b/src/fs/test_fs_namespace_list_updateable.c index 9a28fcb1b..4311f0110 100644 --- a/src/fs/test_fs_namespace_list_updateable.c +++ b/src/fs/test_fs_namespace_list_updateable.c | |||
@@ -45,128 +45,130 @@ static struct GNUNET_FS_BlockOptions bo; | |||
45 | 45 | ||
46 | 46 | ||
47 | static void * | 47 | static void * |
48 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 48 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
49 | { | 49 | { |
50 | return NULL; | 50 | return NULL; |
51 | } | 51 | } |
52 | 52 | ||
53 | 53 | ||
54 | static void | 54 | static void |
55 | do_shutdown() | 55 | do_shutdown () |
56 | { | 56 | { |
57 | if (uri_this != NULL) | 57 | if (uri_this != NULL) |
58 | GNUNET_FS_uri_destroy(uri_this); | 58 | GNUNET_FS_uri_destroy (uri_this); |
59 | if (uri_next != NULL) | 59 | if (uri_next != NULL) |
60 | GNUNET_FS_uri_destroy(uri_next); | 60 | GNUNET_FS_uri_destroy (uri_next); |
61 | if (ns != NULL) | 61 | if (ns != NULL) |
62 | GNUNET_free(ns); | 62 | GNUNET_free (ns); |
63 | if (meta != NULL) | 63 | if (meta != NULL) |
64 | GNUNET_CONTAINER_meta_data_destroy(meta); | 64 | GNUNET_CONTAINER_meta_data_destroy (meta); |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | static void | 68 | static void |
69 | check_next(void *cls, const char *last_id, | 69 | check_next (void *cls, const char *last_id, |
70 | const struct GNUNET_FS_Uri *last_uri, | 70 | const struct GNUNET_FS_Uri *last_uri, |
71 | const struct GNUNET_CONTAINER_MetaData *last_meta, | 71 | const struct GNUNET_CONTAINER_MetaData *last_meta, |
72 | const char *next_id) | 72 | const char *next_id) |
73 | { | 73 | { |
74 | GNUNET_break(0 == strcmp(last_id, "next")); | 74 | GNUNET_break (0 == strcmp (last_id, "next")); |
75 | GNUNET_break(0 == strcmp(next_id, "future")); | 75 | GNUNET_break (0 == strcmp (next_id, "future")); |
76 | err -= 4; | 76 | err -= 4; |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | static void | 80 | static void |
81 | check_this_next(void *cls, const char *last_id, | 81 | check_this_next (void *cls, const char *last_id, |
82 | const struct GNUNET_FS_Uri *last_uri, | 82 | const struct GNUNET_FS_Uri *last_uri, |
83 | const struct GNUNET_CONTAINER_MetaData *last_meta, | 83 | const struct GNUNET_CONTAINER_MetaData *last_meta, |
84 | const char *next_id) | 84 | const char *next_id) |
85 | { | 85 | { |
86 | GNUNET_break(0 == strcmp(last_id, "this")); | 86 | GNUNET_break (0 == strcmp (last_id, "this")); |
87 | GNUNET_break(0 == strcmp(next_id, "next")); | 87 | GNUNET_break (0 == strcmp (next_id, "next")); |
88 | err -= 2; | 88 | err -= 2; |
89 | err += 4; | 89 | err += 4; |
90 | GNUNET_FS_namespace_list_updateable(fs, ns, next_id, &check_next, NULL); | 90 | GNUNET_FS_namespace_list_updateable (fs, ns, next_id, &check_next, NULL); |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | static void | 94 | static void |
95 | sks_cont_next(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | 95 | sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) |
96 | { | 96 | { |
97 | GNUNET_assert(NULL == emsg); | 97 | GNUNET_assert (NULL == emsg); |
98 | err += 2; | 98 | err += 2; |
99 | GNUNET_FS_namespace_list_updateable(fs, ns, NULL, &check_this_next, NULL); | 99 | GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this_next, NULL); |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | static void | 103 | static void |
104 | check_this(void *cls, const char *last_id, | 104 | check_this (void *cls, const char *last_id, |
105 | const struct GNUNET_FS_Uri *last_uri, | 105 | const struct GNUNET_FS_Uri *last_uri, |
106 | const struct GNUNET_CONTAINER_MetaData *last_meta, | 106 | const struct GNUNET_CONTAINER_MetaData *last_meta, |
107 | const char *next_id) | 107 | const char *next_id) |
108 | { | 108 | { |
109 | GNUNET_break(0 == strcmp(last_id, "this")); | 109 | GNUNET_break (0 == strcmp (last_id, "this")); |
110 | GNUNET_break(0 == strcmp(next_id, "next")); | 110 | GNUNET_break (0 == strcmp (next_id, "next")); |
111 | err -= 1; | 111 | err -= 1; |
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
115 | static void | 115 | static void |
116 | sks_cont_this(void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | 116 | sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) |
117 | { | 117 | { |
118 | GNUNET_assert(NULL == emsg); | 118 | GNUNET_assert (NULL == emsg); |
119 | err = 1; | 119 | err = 1; |
120 | GNUNET_FS_namespace_list_updateable(fs, ns, NULL, &check_this, NULL); | 120 | GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this, NULL); |
121 | GNUNET_FS_publish_sks(fs, ns, "next", "future", meta, uri_next, &bo, | 121 | GNUNET_FS_publish_sks (fs, ns, "next", "future", meta, uri_next, &bo, |
122 | GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL); | 122 | GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL); |
123 | } | 123 | } |
124 | 124 | ||
125 | 125 | ||
126 | static void | 126 | static void |
127 | testNamespace() | 127 | testNamespace () |
128 | { | 128 | { |
129 | ns = GNUNET_CRYPTO_ecdsa_key_create(); | 129 | ns = GNUNET_CRYPTO_ecdsa_key_create (); |
130 | GNUNET_assert(NULL != ns); | 130 | GNUNET_assert (NULL != ns); |
131 | bo.content_priority = 1; | 131 | bo.content_priority = 1; |
132 | bo.anonymity_level = 1; | 132 | bo.anonymity_level = 1; |
133 | bo.replication_level = 0; | 133 | bo.replication_level = 0; |
134 | bo.expiration_time = | 134 | bo.expiration_time = |
135 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); | 135 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); |
136 | meta = GNUNET_CONTAINER_meta_data_create(); | 136 | meta = GNUNET_CONTAINER_meta_data_create (); |
137 | 137 | ||
138 | uri_this = | 138 | uri_this = |
139 | GNUNET_FS_uri_parse | 139 | GNUNET_FS_uri_parse |
140 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", | 140 | ( |
141 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", | ||
141 | NULL); | 142 | NULL); |
142 | uri_next = | 143 | uri_next = |
143 | GNUNET_FS_uri_parse | 144 | GNUNET_FS_uri_parse |
144 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43", | 145 | ( |
146 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43", | ||
145 | NULL); | 147 | NULL); |
146 | GNUNET_FS_publish_sks(fs, ns, "this", "next", meta, uri_this, &bo, | 148 | GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo, |
147 | GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL); | 149 | GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL); |
148 | } | 150 | } |
149 | 151 | ||
150 | 152 | ||
151 | static void | 153 | static void |
152 | run(void *cls, | 154 | run (void *cls, |
153 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 155 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
154 | struct GNUNET_TESTING_Peer *peer) | 156 | struct GNUNET_TESTING_Peer *peer) |
155 | { | 157 | { |
156 | fs = GNUNET_FS_start(cfg, "test-fs-namespace", &progress_cb, NULL, | 158 | fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL, |
157 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 159 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
158 | testNamespace(); | 160 | testNamespace (); |
159 | } | 161 | } |
160 | 162 | ||
161 | 163 | ||
162 | int | 164 | int |
163 | main(int argc, char *argv[]) | 165 | main (int argc, char *argv[]) |
164 | { | 166 | { |
165 | if (0 != GNUNET_TESTING_peer_run("test-fs-namespace-list-updateable", | 167 | if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace-list-updateable", |
166 | "test_fs_namespace_data.conf", | 168 | "test_fs_namespace_data.conf", |
167 | &run, NULL)) | 169 | &run, NULL)) |
168 | return 1; | 170 | return 1; |
169 | do_shutdown(); | 171 | do_shutdown (); |
170 | return err; | 172 | return err; |
171 | } | 173 | } |
172 | 174 | ||
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index 02c1587d2..40eaa09e3 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c | |||
@@ -36,12 +36,12 @@ | |||
36 | /** | 36 | /** |
37 | * How long until we give up on transmitting the message? | 37 | * How long until we give up on transmitting the message? |
38 | */ | 38 | */ |
39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How long should our test-content live? | 42 | * How long should our test-content live? |
43 | */ | 43 | */ |
44 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 44 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
45 | 45 | ||
46 | 46 | ||
47 | static struct GNUNET_TIME_Absolute start; | 47 | static struct GNUNET_TIME_Absolute start; |
@@ -58,111 +58,111 @@ static int err; | |||
58 | 58 | ||
59 | 59 | ||
60 | static void | 60 | static void |
61 | abort_publish_task(void *cls) | 61 | abort_publish_task (void *cls) |
62 | { | 62 | { |
63 | GNUNET_FS_publish_stop(publish); | 63 | GNUNET_FS_publish_stop (publish); |
64 | publish = NULL; | 64 | publish = NULL; |
65 | GNUNET_DISK_directory_remove(fn1); | 65 | GNUNET_DISK_directory_remove (fn1); |
66 | GNUNET_free(fn1); | 66 | GNUNET_free (fn1); |
67 | fn1 = NULL; | 67 | fn1 = NULL; |
68 | GNUNET_DISK_directory_remove(fn2); | 68 | GNUNET_DISK_directory_remove (fn2); |
69 | GNUNET_free(fn2); | 69 | GNUNET_free (fn2); |
70 | fn2 = NULL; | 70 | fn2 = NULL; |
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
74 | static void * | 74 | static void * |
75 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 75 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
76 | { | 76 | { |
77 | void *ret; | 77 | void *ret; |
78 | 78 | ||
79 | ret = NULL; | 79 | ret = NULL; |
80 | switch (event->status) | 80 | switch (event->status) |
81 | { | ||
82 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
83 | ret = event->value.publish.cctx; | ||
84 | printf ("Publish complete, %llu kbps.\n", | ||
85 | (unsigned long long) (FILESIZE * 1000000LL | ||
86 | / (1 | ||
87 | + GNUNET_TIME_absolute_get_duration | ||
88 | (start).rel_value_us) / 1024)); | ||
89 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | ||
90 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
91 | break; | ||
92 | |||
93 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
94 | ret = event->value.publish.cctx; | ||
95 | GNUNET_assert (publish == event->value.publish.pc); | ||
96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
97 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | ||
98 | (unsigned long long) event->value.publish.completed, | ||
99 | (unsigned long long) event->value.publish.size, | ||
100 | event->value.publish.specifics.progress.depth, | ||
101 | (unsigned long long) event->value.publish.specifics. | ||
102 | progress.offset); | ||
103 | break; | ||
104 | |||
105 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
106 | ret = event->value.publish.cctx; | ||
107 | break; | ||
108 | |||
109 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
110 | ret = event->value.publish.cctx; | ||
111 | fprintf (stderr, "Error publishing file: %s\n", | ||
112 | event->value.publish.specifics.error.message); | ||
113 | err = 1; | ||
114 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | ||
81 | { | 115 | { |
82 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 116 | fprintf (stderr, "Scheduling abort task for error on `%s'\n", |
83 | ret = event->value.publish.cctx; | 117 | (const char *) event->value.publish.cctx); |
84 | printf("Publish complete, %llu kbps.\n", | 118 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
85 | (unsigned long long)(FILESIZE * 1000000LL / | ||
86 | (1 + | ||
87 | GNUNET_TIME_absolute_get_duration | ||
88 | (start).rel_value_us) / 1024)); | ||
89 | if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) | ||
90 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
91 | break; | ||
92 | |||
93 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
94 | ret = event->value.publish.cctx; | ||
95 | GNUNET_assert(publish == event->value.publish.pc); | ||
96 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
97 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | ||
98 | (unsigned long long)event->value.publish.completed, | ||
99 | (unsigned long long)event->value.publish.size, | ||
100 | event->value.publish.specifics.progress.depth, | ||
101 | (unsigned long long)event->value.publish.specifics. | ||
102 | progress.offset); | ||
103 | break; | ||
104 | |||
105 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
106 | ret = event->value.publish.cctx; | ||
107 | break; | ||
108 | |||
109 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
110 | ret = event->value.publish.cctx; | ||
111 | fprintf(stderr, "Error publishing file: %s\n", | ||
112 | event->value.publish.specifics.error.message); | ||
113 | err = 1; | ||
114 | if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) | ||
115 | { | ||
116 | fprintf(stderr, "Scheduling abort task for error on `%s'\n", | ||
117 | (const char *)event->value.publish.cctx); | ||
118 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
119 | } | ||
120 | break; | ||
121 | |||
122 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
123 | ret = event->value.publish.cctx; | ||
124 | if (0 == strcmp("publish-context1", event->value.publish.cctx)) | ||
125 | { | ||
126 | GNUNET_assert(0 == | ||
127 | strcmp("publish-context-dir", event->value.publish.pctx)); | ||
128 | GNUNET_assert(FILESIZE == event->value.publish.size); | ||
129 | GNUNET_assert(0 == event->value.publish.completed); | ||
130 | GNUNET_assert(1 == event->value.publish.anonymity); | ||
131 | } | ||
132 | else if (0 == strcmp("publish-context2", event->value.publish.cctx)) | ||
133 | { | ||
134 | GNUNET_assert(0 == | ||
135 | strcmp("publish-context-dir", event->value.publish.pctx)); | ||
136 | GNUNET_assert(FILESIZE == event->value.publish.size); | ||
137 | GNUNET_assert(0 == event->value.publish.completed); | ||
138 | GNUNET_assert(2 == event->value.publish.anonymity); | ||
139 | } | ||
140 | else if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) | ||
141 | { | ||
142 | GNUNET_assert(0 == event->value.publish.completed); | ||
143 | GNUNET_assert(3 == event->value.publish.anonymity); | ||
144 | } | ||
145 | else | ||
146 | GNUNET_assert(0); | ||
147 | break; | ||
148 | |||
149 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
150 | if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) | ||
151 | GNUNET_assert(publish == event->value.publish.pc); | ||
152 | break; | ||
153 | |||
154 | default: | ||
155 | printf("Unexpected event: %d\n", event->status); | ||
156 | break; | ||
157 | } | 119 | } |
120 | break; | ||
121 | |||
122 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
123 | ret = event->value.publish.cctx; | ||
124 | if (0 == strcmp ("publish-context1", event->value.publish.cctx)) | ||
125 | { | ||
126 | GNUNET_assert (0 == | ||
127 | strcmp ("publish-context-dir", event->value.publish.pctx)); | ||
128 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
129 | GNUNET_assert (0 == event->value.publish.completed); | ||
130 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
131 | } | ||
132 | else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) | ||
133 | { | ||
134 | GNUNET_assert (0 == | ||
135 | strcmp ("publish-context-dir", event->value.publish.pctx)); | ||
136 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
137 | GNUNET_assert (0 == event->value.publish.completed); | ||
138 | GNUNET_assert (2 == event->value.publish.anonymity); | ||
139 | } | ||
140 | else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | ||
141 | { | ||
142 | GNUNET_assert (0 == event->value.publish.completed); | ||
143 | GNUNET_assert (3 == event->value.publish.anonymity); | ||
144 | } | ||
145 | else | ||
146 | GNUNET_assert (0); | ||
147 | break; | ||
148 | |||
149 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
150 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | ||
151 | GNUNET_assert (publish == event->value.publish.pc); | ||
152 | break; | ||
153 | |||
154 | default: | ||
155 | printf ("Unexpected event: %d\n", event->status); | ||
156 | break; | ||
157 | } | ||
158 | return ret; | 158 | return ret; |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
162 | static void | 162 | static void |
163 | run(void *cls, | 163 | run (void *cls, |
164 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 164 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
165 | struct GNUNET_TESTING_Peer *peer) | 165 | struct GNUNET_TESTING_Peer *peer) |
166 | { | 166 | { |
167 | const char *keywords[] = { | 167 | const char *keywords[] = { |
168 | "down_foo", | 168 | "down_foo", |
@@ -177,70 +177,70 @@ run(void *cls, | |||
177 | size_t i; | 177 | size_t i; |
178 | struct GNUNET_FS_BlockOptions bo; | 178 | struct GNUNET_FS_BlockOptions bo; |
179 | 179 | ||
180 | fs = GNUNET_FS_start(cfg, "test-fs-publish", &progress_cb, NULL, | 180 | fs = GNUNET_FS_start (cfg, "test-fs-publish", &progress_cb, NULL, |
181 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 181 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
182 | GNUNET_assert(NULL != fs); | 182 | GNUNET_assert (NULL != fs); |
183 | fn1 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); | 183 | fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); |
184 | buf = GNUNET_malloc(FILESIZE); | 184 | buf = GNUNET_malloc (FILESIZE); |
185 | for (i = 0; i < FILESIZE; i++) | 185 | for (i = 0; i < FILESIZE; i++) |
186 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 186 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
187 | GNUNET_assert(FILESIZE == | 187 | GNUNET_assert (FILESIZE == |
188 | GNUNET_DISK_fn_write(fn1, buf, FILESIZE, | 188 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, |
189 | GNUNET_DISK_PERM_USER_READ | | 189 | GNUNET_DISK_PERM_USER_READ |
190 | GNUNET_DISK_PERM_USER_WRITE)); | 190 | | GNUNET_DISK_PERM_USER_WRITE)); |
191 | GNUNET_free(buf); | 191 | GNUNET_free (buf); |
192 | 192 | ||
193 | fn2 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); | 193 | fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); |
194 | buf = GNUNET_malloc(FILESIZE); | 194 | buf = GNUNET_malloc (FILESIZE); |
195 | for (i = 0; i < FILESIZE; i++) | 195 | for (i = 0; i < FILESIZE; i++) |
196 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 196 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
197 | GNUNET_assert(FILESIZE == | 197 | GNUNET_assert (FILESIZE == |
198 | GNUNET_DISK_fn_write(fn2, buf, FILESIZE, | 198 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, |
199 | GNUNET_DISK_PERM_USER_READ | | 199 | GNUNET_DISK_PERM_USER_READ |
200 | GNUNET_DISK_PERM_USER_WRITE)); | 200 | | GNUNET_DISK_PERM_USER_WRITE)); |
201 | GNUNET_free(buf); | 201 | GNUNET_free (buf); |
202 | 202 | ||
203 | meta = GNUNET_CONTAINER_meta_data_create(); | 203 | meta = GNUNET_CONTAINER_meta_data_create (); |
204 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 204 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
205 | bo.content_priority = 42; | 205 | bo.content_priority = 42; |
206 | bo.anonymity_level = 1; | 206 | bo.anonymity_level = 1; |
207 | bo.replication_level = 0; | 207 | bo.replication_level = 0; |
208 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 208 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
209 | 209 | ||
210 | fi1 = | 210 | fi1 = |
211 | GNUNET_FS_file_information_create_from_file(fs, "publish-context1", fn1, | 211 | GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1, |
212 | kuri, meta, GNUNET_YES, &bo); | 212 | kuri, meta, GNUNET_YES, &bo); |
213 | 213 | ||
214 | GNUNET_assert(NULL != fi1); | 214 | GNUNET_assert (NULL != fi1); |
215 | bo.anonymity_level = 2; | 215 | bo.anonymity_level = 2; |
216 | fi2 = | 216 | fi2 = |
217 | GNUNET_FS_file_information_create_from_file(fs, "publish-context2", fn2, | 217 | GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2, |
218 | kuri, meta, GNUNET_YES, &bo); | 218 | kuri, meta, GNUNET_YES, &bo); |
219 | GNUNET_assert(NULL != fi2); | 219 | GNUNET_assert (NULL != fi2); |
220 | bo.anonymity_level = 3; | 220 | bo.anonymity_level = 3; |
221 | fidir = | 221 | fidir = |
222 | GNUNET_FS_file_information_create_empty_directory(fs, | 222 | GNUNET_FS_file_information_create_empty_directory (fs, |
223 | "publish-context-dir", | 223 | "publish-context-dir", |
224 | kuri, meta, &bo, NULL); | 224 | kuri, meta, &bo, NULL); |
225 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); | 225 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); |
226 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); | 226 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); |
227 | GNUNET_FS_uri_destroy(kuri); | 227 | GNUNET_FS_uri_destroy (kuri); |
228 | GNUNET_CONTAINER_meta_data_destroy(meta); | 228 | GNUNET_CONTAINER_meta_data_destroy (meta); |
229 | GNUNET_assert(NULL != fidir); | 229 | GNUNET_assert (NULL != fidir); |
230 | start = GNUNET_TIME_absolute_get(); | 230 | start = GNUNET_TIME_absolute_get (); |
231 | publish = | 231 | publish = |
232 | GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL, | 232 | GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, |
233 | GNUNET_FS_PUBLISH_OPTION_NONE); | 233 | GNUNET_FS_PUBLISH_OPTION_NONE); |
234 | GNUNET_assert(publish != NULL); | 234 | GNUNET_assert (publish != NULL); |
235 | } | 235 | } |
236 | 236 | ||
237 | 237 | ||
238 | int | 238 | int |
239 | main(int argc, char *argv[]) | 239 | main (int argc, char *argv[]) |
240 | { | 240 | { |
241 | if (0 != GNUNET_TESTING_peer_run("test-fs-publish", | 241 | if (0 != GNUNET_TESTING_peer_run ("test-fs-publish", |
242 | "test_fs_publish_data.conf", | 242 | "test_fs_publish_data.conf", |
243 | &run, NULL)) | 243 | &run, NULL)) |
244 | return 1; | 244 | return 1; |
245 | return err; | 245 | return err; |
246 | } | 246 | } |
diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index 7cba55179..4247f78dd 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c | |||
@@ -36,12 +36,12 @@ | |||
36 | /** | 36 | /** |
37 | * How long until we give up on transmitting the message? | 37 | * How long until we give up on transmitting the message? |
38 | */ | 38 | */ |
39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How long should our test-content live? | 42 | * How long should our test-content live? |
43 | */ | 43 | */ |
44 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 44 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
45 | 45 | ||
46 | 46 | ||
47 | static struct GNUNET_TIME_Absolute start; | 47 | static struct GNUNET_TIME_Absolute start; |
@@ -64,39 +64,39 @@ static struct GNUNET_SCHEDULER_Task *rtask; | |||
64 | 64 | ||
65 | 65 | ||
66 | static void | 66 | static void |
67 | abort_publish_task(void *cls) | 67 | abort_publish_task (void *cls) |
68 | { | 68 | { |
69 | GNUNET_FS_publish_stop(publish); | 69 | GNUNET_FS_publish_stop (publish); |
70 | publish = NULL; | 70 | publish = NULL; |
71 | GNUNET_DISK_directory_remove(fn1); | 71 | GNUNET_DISK_directory_remove (fn1); |
72 | GNUNET_free(fn1); | 72 | GNUNET_free (fn1); |
73 | fn1 = NULL; | 73 | fn1 = NULL; |
74 | GNUNET_DISK_directory_remove(fn2); | 74 | GNUNET_DISK_directory_remove (fn2); |
75 | GNUNET_free(fn2); | 75 | GNUNET_free (fn2); |
76 | fn2 = NULL; | 76 | fn2 = NULL; |
77 | GNUNET_FS_stop(fs); | 77 | GNUNET_FS_stop (fs); |
78 | fs = NULL; | 78 | fs = NULL; |
79 | if (NULL != rtask) | 79 | if (NULL != rtask) |
80 | { | 80 | { |
81 | GNUNET_SCHEDULER_cancel(rtask); | 81 | GNUNET_SCHEDULER_cancel (rtask); |
82 | rtask = NULL; | 82 | rtask = NULL; |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | static void * | 87 | static void * |
88 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event); | 88 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); |
89 | 89 | ||
90 | 90 | ||
91 | static void | 91 | static void |
92 | restart_fs_task(void *cls) | 92 | restart_fs_task (void *cls) |
93 | { | 93 | { |
94 | rtask = NULL; | 94 | rtask = NULL; |
95 | GNUNET_FS_stop(fs); | 95 | GNUNET_FS_stop (fs); |
96 | fs = GNUNET_FS_start(cfg, "test-fs-publish-persistence", | 96 | fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", |
97 | &progress_cb, NULL, | 97 | &progress_cb, NULL, |
98 | GNUNET_FS_FLAGS_PERSISTENCE, | 98 | GNUNET_FS_FLAGS_PERSISTENCE, |
99 | GNUNET_FS_OPTIONS_END); | 99 | GNUNET_FS_OPTIONS_END); |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
@@ -108,7 +108,7 @@ restart_fs_task(void *cls) | |||
108 | * @param ev type of the event to consider | 108 | * @param ev type of the event to consider |
109 | */ | 109 | */ |
110 | static void | 110 | static void |
111 | consider_restart(int ev) | 111 | consider_restart (int ev) |
112 | { | 112 | { |
113 | static int prev[32]; | 113 | static int prev[32]; |
114 | static int off; | 114 | static int off; |
@@ -119,123 +119,123 @@ consider_restart(int ev) | |||
119 | return; | 119 | return; |
120 | prev[off++] = ev; | 120 | prev[off++] = ev; |
121 | rtask = | 121 | rtask = |
122 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT, | 122 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, |
123 | &restart_fs_task, NULL); | 123 | &restart_fs_task, NULL); |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | static void * | 127 | static void * |
128 | progress_cb(void *cls, | 128 | progress_cb (void *cls, |
129 | const struct GNUNET_FS_ProgressInfo *event) | 129 | const struct GNUNET_FS_ProgressInfo *event) |
130 | { | 130 | { |
131 | void *ret; | 131 | void *ret; |
132 | 132 | ||
133 | ret = NULL; | 133 | ret = NULL; |
134 | switch (event->status) | 134 | switch (event->status) |
135 | { | 135 | { |
136 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 136 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
137 | ret = event->value.publish.cctx; | 137 | ret = event->value.publish.cctx; |
138 | printf("Publish complete, %llu kbps.\n", | 138 | printf ("Publish complete, %llu kbps.\n", |
139 | (unsigned long long)(FILESIZE * 1000000LL / | 139 | (unsigned long long) (FILESIZE * 1000000LL |
140 | (1 + | 140 | / (1 |
141 | GNUNET_TIME_absolute_get_duration | 141 | + GNUNET_TIME_absolute_get_duration |
142 | (start).rel_value_us) / 1024)); | 142 | (start).rel_value_us) / 1024)); |
143 | if ((NULL != event->value.publish.cctx) && | 143 | if ((NULL != event->value.publish.cctx) && |
144 | (0 == strcmp("publish-context-dir", event->value.publish.cctx))) | 144 | (0 == strcmp ("publish-context-dir", event->value.publish.cctx))) |
145 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 145 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
146 | break; | 146 | break; |
147 | 147 | ||
148 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 148 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
149 | ret = event->value.publish.cctx; | 149 | ret = event->value.publish.cctx; |
150 | return ret; | 150 | return ret; |
151 | 151 | ||
152 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 152 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
153 | consider_restart(event->status); | 153 | consider_restart (event->status); |
154 | ret = event->value.publish.cctx; | 154 | ret = event->value.publish.cctx; |
155 | GNUNET_assert(publish == event->value.publish.pc); | 155 | GNUNET_assert (publish == event->value.publish.pc); |
156 | #if VERBOSE | 156 | #if VERBOSE |
157 | printf("Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 157 | printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
158 | (unsigned long long)event->value.publish.completed, | 158 | (unsigned long long) event->value.publish.completed, |
159 | (unsigned long long)event->value.publish.size, | 159 | (unsigned long long) event->value.publish.size, |
160 | event->value.publish.specifics.progress.depth, | 160 | event->value.publish.specifics.progress.depth, |
161 | (unsigned long long)event->value.publish.specifics. | 161 | (unsigned long long) event->value.publish.specifics. |
162 | progress.offset); | 162 | progress.offset); |
163 | #endif | 163 | #endif |
164 | break; | 164 | break; |
165 | 165 | ||
166 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | 166 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: |
167 | if (event->value.publish.pc == publish) | 167 | if (event->value.publish.pc == publish) |
168 | publish = NULL; | 168 | publish = NULL; |
169 | break; | 169 | break; |
170 | 170 | ||
171 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | 171 | case GNUNET_FS_STATUS_PUBLISH_RESUME: |
172 | if (NULL == publish) | 172 | if (NULL == publish) |
173 | { | 173 | { |
174 | GNUNET_assert(GNUNET_YES == | 174 | GNUNET_assert (GNUNET_YES == |
175 | GNUNET_FS_file_information_is_directory(event-> | 175 | GNUNET_FS_file_information_is_directory (event-> |
176 | value.publish. | 176 | value.publish. |
177 | fi)); | 177 | fi)); |
178 | publish = event->value.publish.pc; | ||
179 | return "publish-context-dir"; | ||
180 | } | ||
181 | break; | ||
182 | |||
183 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
184 | ret = event->value.publish.cctx; | ||
185 | fprintf(stderr, "Error publishing file: %s\n", | ||
186 | event->value.publish.specifics.error.message); | ||
187 | err = 1; | ||
188 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
189 | break; | ||
190 | |||
191 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
192 | consider_restart(event->status); | ||
193 | publish = event->value.publish.pc; | 178 | publish = event->value.publish.pc; |
194 | ret = event->value.publish.cctx; | 179 | return "publish-context-dir"; |
195 | if (0 == strcmp("publish-context1", event->value.publish.cctx)) | 180 | } |
196 | { | 181 | break; |
197 | GNUNET_assert(0 == | 182 | |
198 | strcmp("publish-context-dir", event->value.publish.pctx)); | 183 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
199 | GNUNET_assert(FILESIZE == event->value.publish.size); | 184 | ret = event->value.publish.cctx; |
200 | GNUNET_assert(0 == event->value.publish.completed); | 185 | fprintf (stderr, "Error publishing file: %s\n", |
201 | GNUNET_assert(1 == event->value.publish.anonymity); | 186 | event->value.publish.specifics.error.message); |
202 | } | 187 | err = 1; |
203 | else if (0 == strcmp("publish-context2", event->value.publish.cctx)) | 188 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
204 | { | 189 | break; |
205 | GNUNET_assert(0 == | 190 | |
206 | strcmp("publish-context-dir", event->value.publish.pctx)); | 191 | case GNUNET_FS_STATUS_PUBLISH_START: |
207 | GNUNET_assert(FILESIZE == event->value.publish.size); | 192 | consider_restart (event->status); |
208 | GNUNET_assert(0 == event->value.publish.completed); | 193 | publish = event->value.publish.pc; |
209 | GNUNET_assert(2 == event->value.publish.anonymity); | 194 | ret = event->value.publish.cctx; |
210 | } | 195 | if (0 == strcmp ("publish-context1", event->value.publish.cctx)) |
211 | else if (0 == strcmp("publish-context-dir", event->value.publish.cctx)) | 196 | { |
212 | { | 197 | GNUNET_assert (0 == |
213 | GNUNET_assert(0 == event->value.publish.completed); | 198 | strcmp ("publish-context-dir", event->value.publish.pctx)); |
214 | GNUNET_assert(3 == event->value.publish.anonymity); | 199 | GNUNET_assert (FILESIZE == event->value.publish.size); |
215 | } | 200 | GNUNET_assert (0 == event->value.publish.completed); |
216 | else | 201 | GNUNET_assert (1 == event->value.publish.anonymity); |
217 | GNUNET_assert(0); | 202 | } |
218 | break; | 203 | else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) |
219 | 204 | { | |
220 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 205 | GNUNET_assert (0 == |
221 | consider_restart(event->status); | 206 | strcmp ("publish-context-dir", event->value.publish.pctx)); |
222 | if ((NULL != event->value.publish.cctx) && | 207 | GNUNET_assert (FILESIZE == event->value.publish.size); |
223 | (0 == strcmp("publish-context-dir", event->value.publish.cctx))) | 208 | GNUNET_assert (0 == event->value.publish.completed); |
224 | GNUNET_assert(publish == event->value.publish.pc); | 209 | GNUNET_assert (2 == event->value.publish.anonymity); |
225 | break; | 210 | } |
226 | 211 | else if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | |
227 | default: | 212 | { |
228 | printf("Unexpected event: %d\n", event->status); | 213 | GNUNET_assert (0 == event->value.publish.completed); |
229 | break; | 214 | GNUNET_assert (3 == event->value.publish.anonymity); |
230 | } | 215 | } |
216 | else | ||
217 | GNUNET_assert (0); | ||
218 | break; | ||
219 | |||
220 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
221 | consider_restart (event->status); | ||
222 | if ((NULL != event->value.publish.cctx) && | ||
223 | (0 == strcmp ("publish-context-dir", event->value.publish.cctx))) | ||
224 | GNUNET_assert (publish == event->value.publish.pc); | ||
225 | break; | ||
226 | |||
227 | default: | ||
228 | printf ("Unexpected event: %d\n", event->status); | ||
229 | break; | ||
230 | } | ||
231 | return ret; | 231 | return ret; |
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | static void | 235 | static void |
236 | run(void *cls, | 236 | run (void *cls, |
237 | const struct GNUNET_CONFIGURATION_Handle *c, | 237 | const struct GNUNET_CONFIGURATION_Handle *c, |
238 | struct GNUNET_TESTING_Peer *peer) | 238 | struct GNUNET_TESTING_Peer *peer) |
239 | { | 239 | { |
240 | const char *keywords[] = { | 240 | const char *keywords[] = { |
241 | "down_foo", | 241 | "down_foo", |
@@ -251,67 +251,67 @@ run(void *cls, | |||
251 | struct GNUNET_FS_BlockOptions bo; | 251 | struct GNUNET_FS_BlockOptions bo; |
252 | 252 | ||
253 | cfg = c; | 253 | cfg = c; |
254 | fs = GNUNET_FS_start(cfg, "test-fs-publish-persistence", &progress_cb, NULL, | 254 | fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL, |
255 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 255 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
256 | GNUNET_assert(NULL != fs); | 256 | GNUNET_assert (NULL != fs); |
257 | fn1 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); | 257 | fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); |
258 | buf = GNUNET_malloc(FILESIZE); | 258 | buf = GNUNET_malloc (FILESIZE); |
259 | for (i = 0; i < FILESIZE; i++) | 259 | for (i = 0; i < FILESIZE; i++) |
260 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 260 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
261 | GNUNET_assert(FILESIZE == | 261 | GNUNET_assert (FILESIZE == |
262 | GNUNET_DISK_fn_write(fn1, buf, FILESIZE, | 262 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, |
263 | GNUNET_DISK_PERM_USER_READ | | 263 | GNUNET_DISK_PERM_USER_READ |
264 | GNUNET_DISK_PERM_USER_WRITE)); | 264 | | GNUNET_DISK_PERM_USER_WRITE)); |
265 | GNUNET_free(buf); | 265 | GNUNET_free (buf); |
266 | 266 | ||
267 | fn2 = GNUNET_DISK_mktemp("gnunet-publish-test-dst"); | 267 | fn2 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); |
268 | buf = GNUNET_malloc(FILESIZE); | 268 | buf = GNUNET_malloc (FILESIZE); |
269 | for (i = 0; i < FILESIZE; i++) | 269 | for (i = 0; i < FILESIZE; i++) |
270 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 270 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
271 | GNUNET_assert(FILESIZE == | 271 | GNUNET_assert (FILESIZE == |
272 | GNUNET_DISK_fn_write(fn2, buf, FILESIZE, | 272 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, |
273 | GNUNET_DISK_PERM_USER_READ | | 273 | GNUNET_DISK_PERM_USER_READ |
274 | GNUNET_DISK_PERM_USER_WRITE)); | 274 | | GNUNET_DISK_PERM_USER_WRITE)); |
275 | GNUNET_free(buf); | 275 | GNUNET_free (buf); |
276 | 276 | ||
277 | meta = GNUNET_CONTAINER_meta_data_create(); | 277 | meta = GNUNET_CONTAINER_meta_data_create (); |
278 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 278 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
279 | bo.content_priority = 42; | 279 | bo.content_priority = 42; |
280 | bo.anonymity_level = 1; | 280 | bo.anonymity_level = 1; |
281 | bo.replication_level = 0; | 281 | bo.replication_level = 0; |
282 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 282 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
283 | fi1 = | 283 | fi1 = |
284 | GNUNET_FS_file_information_create_from_file(fs, "publish-context1", fn1, | 284 | GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1, |
285 | kuri, meta, GNUNET_YES, &bo); | 285 | kuri, meta, GNUNET_YES, &bo); |
286 | GNUNET_assert(NULL != fi1); | 286 | GNUNET_assert (NULL != fi1); |
287 | bo.anonymity_level = 2; | 287 | bo.anonymity_level = 2; |
288 | fi2 = | 288 | fi2 = |
289 | GNUNET_FS_file_information_create_from_file(fs, "publish-context2", fn2, | 289 | GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2, |
290 | kuri, meta, GNUNET_YES, &bo); | 290 | kuri, meta, GNUNET_YES, &bo); |
291 | GNUNET_assert(NULL != fi2); | 291 | GNUNET_assert (NULL != fi2); |
292 | bo.anonymity_level = 3; | 292 | bo.anonymity_level = 3; |
293 | fidir = | 293 | fidir = |
294 | GNUNET_FS_file_information_create_empty_directory(fs, | 294 | GNUNET_FS_file_information_create_empty_directory (fs, |
295 | "publish-context-dir", | 295 | "publish-context-dir", |
296 | kuri, meta, &bo, NULL); | 296 | kuri, meta, &bo, NULL); |
297 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1)); | 297 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); |
298 | GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2)); | 298 | GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); |
299 | GNUNET_FS_uri_destroy(kuri); | 299 | GNUNET_FS_uri_destroy (kuri); |
300 | GNUNET_CONTAINER_meta_data_destroy(meta); | 300 | GNUNET_CONTAINER_meta_data_destroy (meta); |
301 | GNUNET_assert(NULL != fidir); | 301 | GNUNET_assert (NULL != fidir); |
302 | start = GNUNET_TIME_absolute_get(); | 302 | start = GNUNET_TIME_absolute_get (); |
303 | GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL, | 303 | GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, |
304 | GNUNET_FS_PUBLISH_OPTION_NONE); | 304 | GNUNET_FS_PUBLISH_OPTION_NONE); |
305 | GNUNET_assert(publish != NULL); | 305 | GNUNET_assert (publish != NULL); |
306 | } | 306 | } |
307 | 307 | ||
308 | 308 | ||
309 | int | 309 | int |
310 | main(int argc, char *argv[]) | 310 | main (int argc, char *argv[]) |
311 | { | 311 | { |
312 | if (0 != GNUNET_TESTING_peer_run("test-fs-publish-persistence", | 312 | if (0 != GNUNET_TESTING_peer_run ("test-fs-publish-persistence", |
313 | "test_fs_publish_data.conf", | 313 | "test_fs_publish_data.conf", |
314 | &run, NULL)) | 314 | &run, NULL)) |
315 | return 1; | 315 | return 1; |
316 | return err; | 316 | return err; |
317 | } | 317 | } |
diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c index 7906a4163..16f8ecbda 100644 --- a/src/fs/test_fs_search.c +++ b/src/fs/test_fs_search.c | |||
@@ -36,12 +36,12 @@ | |||
36 | /** | 36 | /** |
37 | * How long until we give up on transmitting the message? | 37 | * How long until we give up on transmitting the message? |
38 | */ | 38 | */ |
39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How long should our test-content live? | 42 | * How long should our test-content live? |
43 | */ | 43 | */ |
44 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 44 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
45 | 45 | ||
46 | 46 | ||
47 | static struct GNUNET_TIME_Absolute start; | 47 | static struct GNUNET_TIME_Absolute start; |
@@ -52,60 +52,60 @@ static struct GNUNET_FS_SearchContext *search; | |||
52 | 52 | ||
53 | static struct GNUNET_FS_PublishContext *publish; | 53 | static struct GNUNET_FS_PublishContext *publish; |
54 | 54 | ||
55 | static struct GNUNET_SCHEDULER_Task * timeout_task; | 55 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
56 | 56 | ||
57 | static int err; | 57 | static int err; |
58 | 58 | ||
59 | 59 | ||
60 | static void | 60 | static void |
61 | abort_publish_task(void *cls) | 61 | abort_publish_task (void *cls) |
62 | { | 62 | { |
63 | if (NULL != publish) | 63 | if (NULL != publish) |
64 | { | 64 | { |
65 | GNUNET_FS_publish_stop(publish); | 65 | GNUNET_FS_publish_stop (publish); |
66 | publish = NULL; | 66 | publish = NULL; |
67 | } | 67 | } |
68 | if (NULL != timeout_task) | 68 | if (NULL != timeout_task) |
69 | { | 69 | { |
70 | GNUNET_SCHEDULER_cancel(timeout_task); | 70 | GNUNET_SCHEDULER_cancel (timeout_task); |
71 | timeout_task = NULL; | 71 | timeout_task = NULL; |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static void | 76 | static void |
77 | abort_error(void *cls) | 77 | abort_error (void *cls) |
78 | { | 78 | { |
79 | fprintf(stderr, | 79 | fprintf (stderr, |
80 | "Timeout\n"); | 80 | "Timeout\n"); |
81 | timeout_task = NULL; | 81 | timeout_task = NULL; |
82 | if (NULL != search) | 82 | if (NULL != search) |
83 | { | 83 | { |
84 | GNUNET_FS_search_stop(search); | 84 | GNUNET_FS_search_stop (search); |
85 | search = NULL; | 85 | search = NULL; |
86 | } | 86 | } |
87 | if (NULL != publish) | 87 | if (NULL != publish) |
88 | { | 88 | { |
89 | GNUNET_FS_publish_stop(publish); | 89 | GNUNET_FS_publish_stop (publish); |
90 | publish = NULL; | 90 | publish = NULL; |
91 | } | 91 | } |
92 | err = 1; | 92 | err = 1; |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | static void | 96 | static void |
97 | abort_search_task(void *cls) | 97 | abort_search_task (void *cls) |
98 | { | 98 | { |
99 | if (NULL != search) | 99 | if (NULL != search) |
100 | { | 100 | { |
101 | GNUNET_FS_search_stop(search); | 101 | GNUNET_FS_search_stop (search); |
102 | search = NULL; | 102 | search = NULL; |
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
106 | 106 | ||
107 | static void * | 107 | static void * |
108 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 108 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
109 | { | 109 | { |
110 | const char *keywords[] = { | 110 | const char *keywords[] = { |
111 | "down_foo" | 111 | "down_foo" |
@@ -113,91 +113,91 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
113 | struct GNUNET_FS_Uri *kuri; | 113 | struct GNUNET_FS_Uri *kuri; |
114 | 114 | ||
115 | switch (event->status) | 115 | switch (event->status) |
116 | { | 116 | { |
117 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 117 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
118 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
119 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 119 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
120 | (unsigned long long)event->value.publish.completed, | 120 | (unsigned long long) event->value.publish.completed, |
121 | (unsigned long long)event->value.publish.size, | 121 | (unsigned long long) event->value.publish.size, |
122 | event->value.publish.specifics.progress.depth, | 122 | event->value.publish.specifics.progress.depth, |
123 | (unsigned long long)event->value.publish.specifics. | 123 | (unsigned long long) event->value.publish.specifics. |
124 | progress.offset); | 124 | progress.offset); |
125 | break; | 125 | break; |
126 | 126 | ||
127 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 127 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
128 | break; | 128 | break; |
129 | 129 | ||
130 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 130 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
131 | kuri = GNUNET_FS_uri_ksk_create_from_args(1, keywords); | 131 | kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); |
132 | start = GNUNET_TIME_absolute_get(); | 132 | start = GNUNET_TIME_absolute_get (); |
133 | search = | 133 | search = |
134 | GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | 134 | GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, |
135 | "search"); | 135 | "search"); |
136 | GNUNET_FS_uri_destroy(kuri); | 136 | GNUNET_FS_uri_destroy (kuri); |
137 | GNUNET_assert(search != NULL); | 137 | GNUNET_assert (search != NULL); |
138 | break; | 138 | break; |
139 | 139 | ||
140 | case GNUNET_FS_STATUS_SEARCH_RESULT: | 140 | case GNUNET_FS_STATUS_SEARCH_RESULT: |
141 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
142 | "Search complete.\n"); | 142 | "Search complete.\n"); |
143 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); | 143 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
144 | break; | 144 | break; |
145 | 145 | ||
146 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 146 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
147 | fprintf(stderr, "Error publishing file: %s\n", | 147 | fprintf (stderr, "Error publishing file: %s\n", |
148 | event->value.publish.specifics.error.message); | 148 | event->value.publish.specifics.error.message); |
149 | GNUNET_break(0); | 149 | GNUNET_break (0); |
150 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 150 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
151 | break; | 151 | break; |
152 | 152 | ||
153 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 153 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
154 | fprintf(stderr, "Error searching file: %s\n", | 154 | fprintf (stderr, "Error searching file: %s\n", |
155 | event->value.search.specifics.error.message); | 155 | event->value.search.specifics.error.message); |
156 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); | 156 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
157 | break; | 157 | break; |
158 | 158 | ||
159 | case GNUNET_FS_STATUS_PUBLISH_START: | 159 | case GNUNET_FS_STATUS_PUBLISH_START: |
160 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); | 160 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); |
161 | GNUNET_assert(NULL == event->value.publish.pctx); | 161 | GNUNET_assert (NULL == event->value.publish.pctx); |
162 | GNUNET_assert(FILESIZE == event->value.publish.size); | 162 | GNUNET_assert (FILESIZE == event->value.publish.size); |
163 | GNUNET_assert(0 == event->value.publish.completed); | 163 | GNUNET_assert (0 == event->value.publish.completed); |
164 | GNUNET_assert(1 == event->value.publish.anonymity); | 164 | GNUNET_assert (1 == event->value.publish.anonymity); |
165 | break; | 165 | break; |
166 | 166 | ||
167 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 167 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
168 | GNUNET_assert(publish == event->value.publish.pc); | 168 | GNUNET_assert (publish == event->value.publish.pc); |
169 | GNUNET_assert(FILESIZE == event->value.publish.size); | 169 | GNUNET_assert (FILESIZE == event->value.publish.size); |
170 | GNUNET_assert(1 == event->value.publish.anonymity); | 170 | GNUNET_assert (1 == event->value.publish.anonymity); |
171 | GNUNET_FS_stop(fs); | 171 | GNUNET_FS_stop (fs); |
172 | fs = NULL; | 172 | fs = NULL; |
173 | break; | 173 | break; |
174 | 174 | ||
175 | case GNUNET_FS_STATUS_SEARCH_START: | 175 | case GNUNET_FS_STATUS_SEARCH_START: |
176 | GNUNET_assert(search == NULL); | 176 | GNUNET_assert (search == NULL); |
177 | GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); | 177 | GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); |
178 | GNUNET_assert(1 == event->value.search.anonymity); | 178 | GNUNET_assert (1 == event->value.search.anonymity); |
179 | break; | 179 | break; |
180 | 180 | ||
181 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | 181 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: |
182 | break; | 182 | break; |
183 | 183 | ||
184 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | 184 | case GNUNET_FS_STATUS_SEARCH_STOPPED: |
185 | GNUNET_assert(search == event->value.search.sc); | 185 | GNUNET_assert (search == event->value.search.sc); |
186 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 186 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
187 | break; | 187 | break; |
188 | 188 | ||
189 | default: | 189 | default: |
190 | fprintf(stderr, "Unexpected event: %d\n", event->status); | 190 | fprintf (stderr, "Unexpected event: %d\n", event->status); |
191 | break; | 191 | break; |
192 | } | 192 | } |
193 | return NULL; | 193 | return NULL; |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | static void | 197 | static void |
198 | run(void *cls, | 198 | run (void *cls, |
199 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 199 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
200 | struct GNUNET_TESTING_Peer *peer) | 200 | struct GNUNET_TESTING_Peer *peer) |
201 | { | 201 | { |
202 | const char *keywords[] = { | 202 | const char *keywords[] = { |
203 | "down_foo", | 203 | "down_foo", |
@@ -210,40 +210,40 @@ run(void *cls, | |||
210 | struct GNUNET_FS_FileInformation *fi; | 210 | struct GNUNET_FS_FileInformation *fi; |
211 | size_t i; | 211 | size_t i; |
212 | 212 | ||
213 | fs = GNUNET_FS_start(cfg, "test-fs-search", &progress_cb, NULL, | 213 | fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, |
214 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 214 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
215 | GNUNET_assert(NULL != fs); | 215 | GNUNET_assert (NULL != fs); |
216 | buf = GNUNET_malloc(FILESIZE); | 216 | buf = GNUNET_malloc (FILESIZE); |
217 | for (i = 0; i < FILESIZE; i++) | 217 | for (i = 0; i < FILESIZE; i++) |
218 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 218 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
219 | meta = GNUNET_CONTAINER_meta_data_create(); | 219 | meta = GNUNET_CONTAINER_meta_data_create (); |
220 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 220 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
221 | bo.content_priority = 42; | 221 | bo.content_priority = 42; |
222 | bo.anonymity_level = 1; | 222 | bo.anonymity_level = 1; |
223 | bo.replication_level = 0; | 223 | bo.replication_level = 0; |
224 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 224 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
225 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", | 225 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", |
226 | FILESIZE, buf, kuri, meta, | 226 | FILESIZE, buf, kuri, meta, |
227 | GNUNET_NO, &bo); | 227 | GNUNET_NO, &bo); |
228 | GNUNET_FS_uri_destroy(kuri); | 228 | GNUNET_FS_uri_destroy (kuri); |
229 | GNUNET_CONTAINER_meta_data_destroy(meta); | 229 | GNUNET_CONTAINER_meta_data_destroy (meta); |
230 | GNUNET_assert(NULL != fi); | 230 | GNUNET_assert (NULL != fi); |
231 | start = GNUNET_TIME_absolute_get(); | 231 | start = GNUNET_TIME_absolute_get (); |
232 | publish = | 232 | publish = |
233 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, | 233 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, |
234 | GNUNET_FS_PUBLISH_OPTION_NONE); | 234 | GNUNET_FS_PUBLISH_OPTION_NONE); |
235 | GNUNET_assert(publish != NULL); | 235 | GNUNET_assert (publish != NULL); |
236 | timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, | 236 | timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, |
237 | &abort_error, NULL); | 237 | &abort_error, NULL); |
238 | } | 238 | } |
239 | 239 | ||
240 | 240 | ||
241 | int | 241 | int |
242 | main(int argc, char *argv[]) | 242 | main (int argc, char *argv[]) |
243 | { | 243 | { |
244 | if (0 != GNUNET_TESTING_peer_run("test-fs-search", | 244 | if (0 != GNUNET_TESTING_peer_run ("test-fs-search", |
245 | "test_fs_search_data.conf", | 245 | "test_fs_search_data.conf", |
246 | &run, NULL)) | 246 | &run, NULL)) |
247 | return 1; | 247 | return 1; |
248 | return err; | 248 | return err; |
249 | } | 249 | } |
diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c index b01abe75f..40671823d 100644 --- a/src/fs/test_fs_search_persistence.c +++ b/src/fs/test_fs_search_persistence.c | |||
@@ -36,12 +36,12 @@ | |||
36 | /** | 36 | /** |
37 | * How long until we give up on transmitting the message? | 37 | * How long until we give up on transmitting the message? |
38 | */ | 38 | */ |
39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How long should our test-content live? | 42 | * How long should our test-content live? |
43 | */ | 43 | */ |
44 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 44 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
45 | 45 | ||
46 | 46 | ||
47 | static struct GNUNET_TIME_Absolute start; | 47 | static struct GNUNET_TIME_Absolute start; |
@@ -54,68 +54,68 @@ static struct GNUNET_FS_PublishContext *publish; | |||
54 | 54 | ||
55 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 55 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
56 | 56 | ||
57 | static struct GNUNET_SCHEDULER_Task * timeout_task; | 57 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
58 | 58 | ||
59 | static int err; | 59 | static int err; |
60 | 60 | ||
61 | 61 | ||
62 | static void | 62 | static void |
63 | abort_error(void *cls) | 63 | abort_error (void *cls) |
64 | { | 64 | { |
65 | timeout_task = NULL; | 65 | timeout_task = NULL; |
66 | fprintf(stderr, | 66 | fprintf (stderr, |
67 | "Timeout\n"); | 67 | "Timeout\n"); |
68 | if (NULL != search) | 68 | if (NULL != search) |
69 | { | 69 | { |
70 | GNUNET_FS_search_stop(search); | 70 | GNUNET_FS_search_stop (search); |
71 | search = NULL; | 71 | search = NULL; |
72 | } | 72 | } |
73 | if (NULL != publish) | 73 | if (NULL != publish) |
74 | { | 74 | { |
75 | GNUNET_FS_publish_stop(publish); | 75 | GNUNET_FS_publish_stop (publish); |
76 | publish = NULL; | 76 | publish = NULL; |
77 | } | 77 | } |
78 | err = 1; | 78 | err = 1; |
79 | } | 79 | } |
80 | 80 | ||
81 | 81 | ||
82 | static void | 82 | static void |
83 | abort_publish_task(void *cls) | 83 | abort_publish_task (void *cls) |
84 | { | 84 | { |
85 | if (NULL != publish) | 85 | if (NULL != publish) |
86 | { | 86 | { |
87 | GNUNET_FS_publish_stop(publish); | 87 | GNUNET_FS_publish_stop (publish); |
88 | publish = NULL; | 88 | publish = NULL; |
89 | } | 89 | } |
90 | if (NULL != timeout_task) | 90 | if (NULL != timeout_task) |
91 | { | 91 | { |
92 | GNUNET_SCHEDULER_cancel(timeout_task); | 92 | GNUNET_SCHEDULER_cancel (timeout_task); |
93 | timeout_task = NULL; | 93 | timeout_task = NULL; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | static void | 98 | static void |
99 | abort_search_task(void *cls) | 99 | abort_search_task (void *cls) |
100 | { | 100 | { |
101 | if (NULL != search) | 101 | if (NULL != search) |
102 | { | 102 | { |
103 | GNUNET_FS_search_stop(search); | 103 | GNUNET_FS_search_stop (search); |
104 | search = NULL; | 104 | search = NULL; |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
109 | static void * | 109 | static void * |
110 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event); | 110 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); |
111 | 111 | ||
112 | 112 | ||
113 | static void | 113 | static void |
114 | restart_fs_task(void *cls) | 114 | restart_fs_task (void *cls) |
115 | { | 115 | { |
116 | GNUNET_FS_stop(fs); | 116 | GNUNET_FS_stop (fs); |
117 | fs = GNUNET_FS_start(cfg, "test-fs-search-persistence", &progress_cb, NULL, | 117 | fs = GNUNET_FS_start (cfg, "test-fs-search-persistence", &progress_cb, NULL, |
118 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 118 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
@@ -127,7 +127,7 @@ restart_fs_task(void *cls) | |||
127 | * @param ev type of the event to consider | 127 | * @param ev type of the event to consider |
128 | */ | 128 | */ |
129 | static void | 129 | static void |
130 | consider_restart(int ev) | 130 | consider_restart (int ev) |
131 | { | 131 | { |
132 | static int prev[32]; | 132 | static int prev[32]; |
133 | static int off; | 133 | static int off; |
@@ -137,13 +137,13 @@ consider_restart(int ev) | |||
137 | if (prev[i] == ev) | 137 | if (prev[i] == ev) |
138 | return; | 138 | return; |
139 | prev[off++] = ev; | 139 | prev[off++] = ev; |
140 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT, | 140 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, |
141 | &restart_fs_task, NULL); | 141 | &restart_fs_task, NULL); |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | static void * | 145 | static void * |
146 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 146 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
147 | { | 147 | { |
148 | const char *keywords[] = { | 148 | const char *keywords[] = { |
149 | "down_foo" | 149 | "down_foo" |
@@ -151,118 +151,118 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
151 | struct GNUNET_FS_Uri *kuri; | 151 | struct GNUNET_FS_Uri *kuri; |
152 | 152 | ||
153 | switch (event->status) | 153 | switch (event->status) |
154 | { | 154 | { |
155 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 155 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
156 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
157 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 157 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
158 | (unsigned long long)event->value.publish.completed, | 158 | (unsigned long long) event->value.publish.completed, |
159 | (unsigned long long)event->value.publish.size, | 159 | (unsigned long long) event->value.publish.size, |
160 | event->value.publish.specifics.progress.depth, | 160 | event->value.publish.specifics.progress.depth, |
161 | (unsigned long long)event->value.publish.specifics. | 161 | (unsigned long long) event->value.publish.specifics. |
162 | progress.offset); | 162 | progress.offset); |
163 | break; | 163 | break; |
164 | 164 | ||
165 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 165 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
166 | break; | 166 | break; |
167 | 167 | ||
168 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 168 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
169 | kuri = GNUNET_FS_uri_ksk_create_from_args(1, keywords); | 169 | kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); |
170 | start = GNUNET_TIME_absolute_get(); | 170 | start = GNUNET_TIME_absolute_get (); |
171 | GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | 171 | GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, |
172 | "search"); | 172 | "search"); |
173 | GNUNET_FS_uri_destroy(kuri); | 173 | GNUNET_FS_uri_destroy (kuri); |
174 | GNUNET_assert(search != NULL); | 174 | GNUNET_assert (search != NULL); |
175 | break; | 175 | break; |
176 | 176 | ||
177 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | 177 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: |
178 | if (event->value.publish.pc == publish) | 178 | if (event->value.publish.pc == publish) |
179 | publish = NULL; | 179 | publish = NULL; |
180 | break; | 180 | break; |
181 | 181 | ||
182 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | 182 | case GNUNET_FS_STATUS_PUBLISH_RESUME: |
183 | if (NULL == publish) | 183 | if (NULL == publish) |
184 | publish = event->value.publish.pc; | 184 | publish = event->value.publish.pc; |
185 | break; | 185 | break; |
186 | 186 | ||
187 | case GNUNET_FS_STATUS_SEARCH_RESULT: | 187 | case GNUNET_FS_STATUS_SEARCH_RESULT: |
188 | /* FIXME: consider_restart (event->status); cannot be tested with | 188 | /* FIXME: consider_restart (event->status); cannot be tested with |
189 | * search result since we exit here after the first one... */ | 189 | * search result since we exit here after the first one... */ |
190 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
191 | "Search complete.\n"); | 191 | "Search complete.\n"); |
192 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); | 192 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
193 | break; | 193 | break; |
194 | 194 | ||
195 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 195 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
196 | fprintf(stderr, "Error publishing file: %s\n", | 196 | fprintf (stderr, "Error publishing file: %s\n", |
197 | event->value.publish.specifics.error.message); | 197 | event->value.publish.specifics.error.message); |
198 | GNUNET_break(0); | 198 | GNUNET_break (0); |
199 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 199 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
200 | break; | 200 | break; |
201 | 201 | ||
202 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 202 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
203 | fprintf(stderr, "Error searching file: %s\n", | 203 | fprintf (stderr, "Error searching file: %s\n", |
204 | event->value.search.specifics.error.message); | 204 | event->value.search.specifics.error.message); |
205 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); | 205 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
206 | break; | 206 | break; |
207 | 207 | ||
208 | case GNUNET_FS_STATUS_SEARCH_SUSPEND: | 208 | case GNUNET_FS_STATUS_SEARCH_SUSPEND: |
209 | if (event->value.search.sc == search) | 209 | if (event->value.search.sc == search) |
210 | search = NULL; | ||
211 | break; | ||
212 | |||
213 | case GNUNET_FS_STATUS_SEARCH_RESUME: | ||
214 | if (NULL == search) | ||
215 | { | ||
216 | search = event->value.search.sc; | ||
217 | return "search"; | ||
218 | } | ||
219 | break; | ||
220 | |||
221 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
222 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); | ||
223 | GNUNET_assert(NULL == event->value.publish.pctx); | ||
224 | GNUNET_assert(FILESIZE == event->value.publish.size); | ||
225 | GNUNET_assert(0 == event->value.publish.completed); | ||
226 | GNUNET_assert(1 == event->value.publish.anonymity); | ||
227 | break; | ||
228 | |||
229 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
230 | GNUNET_assert(publish == event->value.publish.pc); | ||
231 | GNUNET_assert(FILESIZE == event->value.publish.size); | ||
232 | GNUNET_assert(1 == event->value.publish.anonymity); | ||
233 | GNUNET_FS_stop(fs); | ||
234 | fs = NULL; | ||
235 | break; | ||
236 | |||
237 | case GNUNET_FS_STATUS_SEARCH_START: | ||
238 | consider_restart(event->status); | ||
239 | GNUNET_assert(search == NULL); | ||
240 | search = event->value.search.sc; | ||
241 | GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); | ||
242 | GNUNET_assert(1 == event->value.search.anonymity); | ||
243 | break; | ||
244 | |||
245 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
246 | break; | ||
247 | |||
248 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
249 | GNUNET_assert(search == event->value.search.sc); | ||
250 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
251 | search = NULL; | 210 | search = NULL; |
252 | break; | 211 | break; |
253 | 212 | ||
254 | default: | 213 | case GNUNET_FS_STATUS_SEARCH_RESUME: |
255 | fprintf(stderr, "Unexpected event: %d\n", event->status); | 214 | if (NULL == search) |
256 | break; | 215 | { |
216 | search = event->value.search.sc; | ||
217 | return "search"; | ||
257 | } | 218 | } |
219 | break; | ||
220 | |||
221 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
222 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | ||
223 | GNUNET_assert (NULL == event->value.publish.pctx); | ||
224 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
225 | GNUNET_assert (0 == event->value.publish.completed); | ||
226 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
227 | break; | ||
228 | |||
229 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
230 | GNUNET_assert (publish == event->value.publish.pc); | ||
231 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
232 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
233 | GNUNET_FS_stop (fs); | ||
234 | fs = NULL; | ||
235 | break; | ||
236 | |||
237 | case GNUNET_FS_STATUS_SEARCH_START: | ||
238 | consider_restart (event->status); | ||
239 | GNUNET_assert (search == NULL); | ||
240 | search = event->value.search.sc; | ||
241 | GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); | ||
242 | GNUNET_assert (1 == event->value.search.anonymity); | ||
243 | break; | ||
244 | |||
245 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
246 | break; | ||
247 | |||
248 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
249 | GNUNET_assert (search == event->value.search.sc); | ||
250 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
251 | search = NULL; | ||
252 | break; | ||
253 | |||
254 | default: | ||
255 | fprintf (stderr, "Unexpected event: %d\n", event->status); | ||
256 | break; | ||
257 | } | ||
258 | return NULL; | 258 | return NULL; |
259 | } | 259 | } |
260 | 260 | ||
261 | 261 | ||
262 | static void | 262 | static void |
263 | run(void *cls, | 263 | run (void *cls, |
264 | const struct GNUNET_CONFIGURATION_Handle *c, | 264 | const struct GNUNET_CONFIGURATION_Handle *c, |
265 | struct GNUNET_TESTING_Peer *peer) | 265 | struct GNUNET_TESTING_Peer *peer) |
266 | { | 266 | { |
267 | const char *keywords[] = { | 267 | const char *keywords[] = { |
268 | "down_foo", | 268 | "down_foo", |
@@ -276,40 +276,40 @@ run(void *cls, | |||
276 | struct GNUNET_FS_BlockOptions bo; | 276 | struct GNUNET_FS_BlockOptions bo; |
277 | 277 | ||
278 | cfg = c; | 278 | cfg = c; |
279 | fs = GNUNET_FS_start(cfg, "test-fs-search-persistence", &progress_cb, NULL, | 279 | fs = GNUNET_FS_start (cfg, "test-fs-search-persistence", &progress_cb, NULL, |
280 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 280 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
281 | GNUNET_assert(NULL != fs); | 281 | GNUNET_assert (NULL != fs); |
282 | buf = GNUNET_malloc(FILESIZE); | 282 | buf = GNUNET_malloc (FILESIZE); |
283 | for (i = 0; i < FILESIZE; i++) | 283 | for (i = 0; i < FILESIZE; i++) |
284 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 284 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
285 | meta = GNUNET_CONTAINER_meta_data_create(); | 285 | meta = GNUNET_CONTAINER_meta_data_create (); |
286 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 286 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
287 | bo.content_priority = 42; | 287 | bo.content_priority = 42; |
288 | bo.anonymity_level = 1; | 288 | bo.anonymity_level = 1; |
289 | bo.replication_level = 0; | 289 | bo.replication_level = 0; |
290 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 290 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
291 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", | 291 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", |
292 | FILESIZE, buf, kuri, meta, | 292 | FILESIZE, buf, kuri, meta, |
293 | GNUNET_NO, &bo); | 293 | GNUNET_NO, &bo); |
294 | GNUNET_FS_uri_destroy(kuri); | 294 | GNUNET_FS_uri_destroy (kuri); |
295 | GNUNET_CONTAINER_meta_data_destroy(meta); | 295 | GNUNET_CONTAINER_meta_data_destroy (meta); |
296 | GNUNET_assert(NULL != fi); | 296 | GNUNET_assert (NULL != fi); |
297 | start = GNUNET_TIME_absolute_get(); | 297 | start = GNUNET_TIME_absolute_get (); |
298 | publish = | 298 | publish = |
299 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, | 299 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, |
300 | GNUNET_FS_PUBLISH_OPTION_NONE); | 300 | GNUNET_FS_PUBLISH_OPTION_NONE); |
301 | GNUNET_assert(publish != NULL); | 301 | GNUNET_assert (publish != NULL); |
302 | timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, | 302 | timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, |
303 | &abort_error, NULL); | 303 | &abort_error, NULL); |
304 | } | 304 | } |
305 | 305 | ||
306 | 306 | ||
307 | int | 307 | int |
308 | main(int argc, char *argv[]) | 308 | main (int argc, char *argv[]) |
309 | { | 309 | { |
310 | if (0 != GNUNET_TESTING_peer_run("test-fs-search-persistence", | 310 | if (0 != GNUNET_TESTING_peer_run ("test-fs-search-persistence", |
311 | "test_fs_search_data.conf", | 311 | "test_fs_search_data.conf", |
312 | &run, NULL)) | 312 | &run, NULL)) |
313 | return 1; | 313 | return 1; |
314 | return err; | 314 | return err; |
315 | } | 315 | } |
diff --git a/src/fs/test_fs_search_probes.c b/src/fs/test_fs_search_probes.c index 5584efca7..2e2dc6005 100644 --- a/src/fs/test_fs_search_probes.c +++ b/src/fs/test_fs_search_probes.c | |||
@@ -37,12 +37,12 @@ | |||
37 | /** | 37 | /** |
38 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
39 | */ | 39 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * How long should our test-content live? | 43 | * How long should our test-content live? |
44 | */ | 44 | */ |
45 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 45 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
46 | 46 | ||
47 | 47 | ||
48 | static struct GNUNET_TIME_Absolute start; | 48 | static struct GNUNET_TIME_Absolute start; |
@@ -53,58 +53,58 @@ static struct GNUNET_FS_SearchContext *search; | |||
53 | 53 | ||
54 | static struct GNUNET_FS_PublishContext *publish; | 54 | static struct GNUNET_FS_PublishContext *publish; |
55 | 55 | ||
56 | static struct GNUNET_SCHEDULER_Task * timeout_task; | 56 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
57 | 57 | ||
58 | static int err; | 58 | static int err; |
59 | 59 | ||
60 | 60 | ||
61 | static void | 61 | static void |
62 | abort_error(void *cls) | 62 | abort_error (void *cls) |
63 | { | 63 | { |
64 | timeout_task = NULL; | 64 | timeout_task = NULL; |
65 | fprintf(stderr, | 65 | fprintf (stderr, |
66 | "Timeout\n"); | 66 | "Timeout\n"); |
67 | if (NULL != search) | 67 | if (NULL != search) |
68 | { | 68 | { |
69 | GNUNET_FS_search_stop(search); | 69 | GNUNET_FS_search_stop (search); |
70 | search = NULL; | 70 | search = NULL; |
71 | } | 71 | } |
72 | if (NULL != publish) | 72 | if (NULL != publish) |
73 | { | 73 | { |
74 | GNUNET_FS_publish_stop(publish); | 74 | GNUNET_FS_publish_stop (publish); |
75 | publish = NULL; | 75 | publish = NULL; |
76 | } | 76 | } |
77 | err = 1; | 77 | err = 1; |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
81 | static void | 81 | static void |
82 | abort_publish_task(void *cls) | 82 | abort_publish_task (void *cls) |
83 | { | 83 | { |
84 | if (NULL != publish) | 84 | if (NULL != publish) |
85 | { | 85 | { |
86 | GNUNET_FS_publish_stop(publish); | 86 | GNUNET_FS_publish_stop (publish); |
87 | publish = NULL; | 87 | publish = NULL; |
88 | } | 88 | } |
89 | if (NULL != timeout_task) | 89 | if (NULL != timeout_task) |
90 | { | 90 | { |
91 | GNUNET_SCHEDULER_cancel(timeout_task); | 91 | GNUNET_SCHEDULER_cancel (timeout_task); |
92 | timeout_task = NULL; | 92 | timeout_task = NULL; |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | static void | 97 | static void |
98 | abort_search_task(void *cls) | 98 | abort_search_task (void *cls) |
99 | { | 99 | { |
100 | if (search != NULL) | 100 | if (search != NULL) |
101 | GNUNET_FS_search_stop(search); | 101 | GNUNET_FS_search_stop (search); |
102 | search = NULL; | 102 | search = NULL; |
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
106 | static void * | 106 | static void * |
107 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 107 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
108 | { | 108 | { |
109 | const char *keywords[] = { | 109 | const char *keywords[] = { |
110 | "down_foo" | 110 | "down_foo" |
@@ -112,97 +112,97 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
112 | struct GNUNET_FS_Uri *kuri; | 112 | struct GNUNET_FS_Uri *kuri; |
113 | 113 | ||
114 | switch (event->status) | 114 | switch (event->status) |
115 | { | 115 | { |
116 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 116 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
117 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
118 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 118 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
119 | (unsigned long long)event->value.publish.completed, | 119 | (unsigned long long) event->value.publish.completed, |
120 | (unsigned long long)event->value.publish.size, | 120 | (unsigned long long) event->value.publish.size, |
121 | event->value.publish.specifics.progress.depth, | 121 | event->value.publish.specifics.progress.depth, |
122 | (unsigned long long)event->value.publish.specifics. | 122 | (unsigned long long) event->value.publish.specifics. |
123 | progress.offset); | 123 | progress.offset); |
124 | break; | 124 | break; |
125 | 125 | ||
126 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 126 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
127 | break; | 127 | break; |
128 | 128 | ||
129 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 129 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
130 | kuri = GNUNET_FS_uri_ksk_create_from_args(1, keywords); | 130 | kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); |
131 | start = GNUNET_TIME_absolute_get(); | 131 | start = GNUNET_TIME_absolute_get (); |
132 | search = | 132 | search = |
133 | GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | 133 | GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, |
134 | "search"); | 134 | "search"); |
135 | GNUNET_FS_uri_destroy(kuri); | 135 | GNUNET_FS_uri_destroy (kuri); |
136 | GNUNET_assert(search != NULL); | 136 | GNUNET_assert (search != NULL); |
137 | break; | 137 | break; |
138 | 138 | ||
139 | case GNUNET_FS_STATUS_SEARCH_RESULT: | 139 | case GNUNET_FS_STATUS_SEARCH_RESULT: |
140 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n"); | 140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n"); |
141 | break; | 141 | break; |
142 | 142 | ||
143 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 143 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
144 | fprintf(stderr, "Error publishing file: %s\n", | 144 | fprintf (stderr, "Error publishing file: %s\n", |
145 | event->value.publish.specifics.error.message); | 145 | event->value.publish.specifics.error.message); |
146 | GNUNET_break(0); | 146 | GNUNET_break (0); |
147 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 147 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
148 | break; | 148 | break; |
149 | 149 | ||
150 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 150 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
151 | fprintf(stderr, "Error searching file: %s\n", | 151 | fprintf (stderr, "Error searching file: %s\n", |
152 | event->value.search.specifics.error.message); | 152 | event->value.search.specifics.error.message); |
153 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); | 153 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
154 | break; | 154 | break; |
155 | 155 | ||
156 | case GNUNET_FS_STATUS_PUBLISH_START: | 156 | case GNUNET_FS_STATUS_PUBLISH_START: |
157 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); | 157 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); |
158 | GNUNET_assert(NULL == event->value.publish.pctx); | 158 | GNUNET_assert (NULL == event->value.publish.pctx); |
159 | GNUNET_assert(FILESIZE == event->value.publish.size); | 159 | GNUNET_assert (FILESIZE == event->value.publish.size); |
160 | GNUNET_assert(0 == event->value.publish.completed); | 160 | GNUNET_assert (0 == event->value.publish.completed); |
161 | GNUNET_assert(1 == event->value.publish.anonymity); | 161 | GNUNET_assert (1 == event->value.publish.anonymity); |
162 | break; | 162 | break; |
163 | 163 | ||
164 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 164 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
165 | GNUNET_assert(publish == event->value.publish.pc); | 165 | GNUNET_assert (publish == event->value.publish.pc); |
166 | GNUNET_assert(FILESIZE == event->value.publish.size); | 166 | GNUNET_assert (FILESIZE == event->value.publish.size); |
167 | GNUNET_assert(1 == event->value.publish.anonymity); | 167 | GNUNET_assert (1 == event->value.publish.anonymity); |
168 | GNUNET_FS_stop(fs); | 168 | GNUNET_FS_stop (fs); |
169 | fs = NULL; | 169 | fs = NULL; |
170 | break; | 170 | break; |
171 | 171 | ||
172 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | 172 | case GNUNET_FS_STATUS_SEARCH_UPDATE: |
173 | if ((0 < event->value.search.specifics.update.availability_rank) && | 173 | if ((0 < event->value.search.specifics.update.availability_rank) && |
174 | (0 < event->value.search.specifics.update.availability_certainty)) | 174 | (0 < event->value.search.specifics.update.availability_certainty)) |
175 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); | 175 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
176 | break; | 176 | break; |
177 | 177 | ||
178 | case GNUNET_FS_STATUS_SEARCH_START: | 178 | case GNUNET_FS_STATUS_SEARCH_START: |
179 | GNUNET_assert(search == NULL); | 179 | GNUNET_assert (search == NULL); |
180 | GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); | 180 | GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); |
181 | GNUNET_assert(1 == event->value.search.anonymity); | 181 | GNUNET_assert (1 == event->value.search.anonymity); |
182 | break; | 182 | break; |
183 | 183 | ||
184 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | 184 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: |
185 | break; | 185 | break; |
186 | 186 | ||
187 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | 187 | case GNUNET_FS_STATUS_SEARCH_STOPPED: |
188 | GNUNET_assert(search == event->value.search.sc); | 188 | GNUNET_assert (search == event->value.search.sc); |
189 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 189 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
190 | break; | 190 | break; |
191 | 191 | ||
192 | default: | 192 | default: |
193 | fprintf(stderr, | 193 | fprintf (stderr, |
194 | "Unexpected event: %d\n", | 194 | "Unexpected event: %d\n", |
195 | event->status); | 195 | event->status); |
196 | break; | 196 | break; |
197 | } | 197 | } |
198 | return NULL; | 198 | return NULL; |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | static void | 202 | static void |
203 | run(void *cls, | 203 | run (void *cls, |
204 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 204 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
205 | struct GNUNET_TESTING_Peer *peer) | 205 | struct GNUNET_TESTING_Peer *peer) |
206 | { | 206 | { |
207 | const char *keywords[] = { | 207 | const char *keywords[] = { |
208 | "down_foo", | 208 | "down_foo", |
@@ -215,41 +215,41 @@ run(void *cls, | |||
215 | struct GNUNET_FS_FileInformation *fi; | 215 | struct GNUNET_FS_FileInformation *fi; |
216 | size_t i; | 216 | size_t i; |
217 | 217 | ||
218 | fs = GNUNET_FS_start(cfg, "test-fs-search", &progress_cb, NULL, | 218 | fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, |
219 | GNUNET_FS_FLAGS_DO_PROBES, | 219 | GNUNET_FS_FLAGS_DO_PROBES, |
220 | GNUNET_FS_OPTIONS_END); | 220 | GNUNET_FS_OPTIONS_END); |
221 | GNUNET_assert(NULL != fs); | 221 | GNUNET_assert (NULL != fs); |
222 | buf = GNUNET_malloc(FILESIZE); | 222 | buf = GNUNET_malloc (FILESIZE); |
223 | for (i = 0; i < FILESIZE; i++) | 223 | for (i = 0; i < FILESIZE; i++) |
224 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 224 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
225 | meta = GNUNET_CONTAINER_meta_data_create(); | 225 | meta = GNUNET_CONTAINER_meta_data_create (); |
226 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 226 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
227 | bo.content_priority = 42; | 227 | bo.content_priority = 42; |
228 | bo.anonymity_level = 1; | 228 | bo.anonymity_level = 1; |
229 | bo.replication_level = 0; | 229 | bo.replication_level = 0; |
230 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 230 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
231 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", | 231 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", |
232 | FILESIZE, buf, kuri, meta, | 232 | FILESIZE, buf, kuri, meta, |
233 | GNUNET_NO, &bo); | 233 | GNUNET_NO, &bo); |
234 | GNUNET_FS_uri_destroy(kuri); | 234 | GNUNET_FS_uri_destroy (kuri); |
235 | GNUNET_CONTAINER_meta_data_destroy(meta); | 235 | GNUNET_CONTAINER_meta_data_destroy (meta); |
236 | GNUNET_assert(NULL != fi); | 236 | GNUNET_assert (NULL != fi); |
237 | start = GNUNET_TIME_absolute_get(); | 237 | start = GNUNET_TIME_absolute_get (); |
238 | publish = | 238 | publish = |
239 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, | 239 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, |
240 | GNUNET_FS_PUBLISH_OPTION_NONE); | 240 | GNUNET_FS_PUBLISH_OPTION_NONE); |
241 | GNUNET_assert(publish != NULL); | 241 | GNUNET_assert (publish != NULL); |
242 | timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, | 242 | timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, |
243 | &abort_error, NULL); | 243 | &abort_error, NULL); |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | int | 247 | int |
248 | main(int argc, char *argv[]) | 248 | main (int argc, char *argv[]) |
249 | { | 249 | { |
250 | if (0 != GNUNET_TESTING_peer_run("test-fs-search-probes", | 250 | if (0 != GNUNET_TESTING_peer_run ("test-fs-search-probes", |
251 | "test_fs_search_data.conf", | 251 | "test_fs_search_data.conf", |
252 | &run, NULL)) | 252 | &run, NULL)) |
253 | return 1; | 253 | return 1; |
254 | return err; | 254 | return err; |
255 | } | 255 | } |
diff --git a/src/fs/test_fs_search_with_and.c b/src/fs/test_fs_search_with_and.c index e43b8e25a..60ceb94ee 100644 --- a/src/fs/test_fs_search_with_and.c +++ b/src/fs/test_fs_search_with_and.c | |||
@@ -42,12 +42,12 @@ | |||
42 | /** | 42 | /** |
43 | * How long until we give up on transmitting the message? | 43 | * How long until we give up on transmitting the message? |
44 | */ | 44 | */ |
45 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 45 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * How long should our test-content live? | 48 | * How long should our test-content live? |
49 | */ | 49 | */ |
50 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 50 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
51 | 51 | ||
52 | 52 | ||
53 | static struct GNUNET_TIME_Absolute start; | 53 | static struct GNUNET_TIME_Absolute start; |
@@ -58,7 +58,7 @@ static struct GNUNET_FS_SearchContext *search; | |||
58 | 58 | ||
59 | static struct GNUNET_FS_PublishContext *publish; | 59 | static struct GNUNET_FS_PublishContext *publish; |
60 | 60 | ||
61 | static struct GNUNET_SCHEDULER_Task * timeout_task; | 61 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
62 | 62 | ||
63 | static int err; | 63 | static int err; |
64 | 64 | ||
@@ -66,150 +66,150 @@ static int processed_files; | |||
66 | 66 | ||
67 | 67 | ||
68 | static void | 68 | static void |
69 | abort_publish_task(void *cls) | 69 | abort_publish_task (void *cls) |
70 | { | 70 | { |
71 | if (NULL != publish) | 71 | if (NULL != publish) |
72 | { | 72 | { |
73 | GNUNET_FS_publish_stop(publish); | 73 | GNUNET_FS_publish_stop (publish); |
74 | publish = NULL; | 74 | publish = NULL; |
75 | } | 75 | } |
76 | if (NULL != timeout_task) | 76 | if (NULL != timeout_task) |
77 | { | 77 | { |
78 | GNUNET_SCHEDULER_cancel(timeout_task); | 78 | GNUNET_SCHEDULER_cancel (timeout_task); |
79 | timeout_task = NULL; | 79 | timeout_task = NULL; |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | static void | 84 | static void |
85 | abort_error(void *cls) | 85 | abort_error (void *cls) |
86 | { | 86 | { |
87 | fprintf(stderr, | 87 | fprintf (stderr, |
88 | "Timeout\n"); | 88 | "Timeout\n"); |
89 | timeout_task = NULL; | 89 | timeout_task = NULL; |
90 | if (NULL != search) | 90 | if (NULL != search) |
91 | { | 91 | { |
92 | GNUNET_FS_search_stop(search); | 92 | GNUNET_FS_search_stop (search); |
93 | search = NULL; | 93 | search = NULL; |
94 | } | 94 | } |
95 | if (NULL != publish) | 95 | if (NULL != publish) |
96 | { | 96 | { |
97 | GNUNET_FS_publish_stop(publish); | 97 | GNUNET_FS_publish_stop (publish); |
98 | publish = NULL; | 98 | publish = NULL; |
99 | } | 99 | } |
100 | err = 1; | 100 | err = 1; |
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ||
104 | static void | 104 | static void |
105 | abort_search_task(void *cls) | 105 | abort_search_task (void *cls) |
106 | { | 106 | { |
107 | if (NULL != search) | 107 | if (NULL != search) |
108 | { | 108 | { |
109 | GNUNET_FS_search_stop(search); | 109 | GNUNET_FS_search_stop (search); |
110 | search = NULL; | 110 | search = NULL; |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
115 | static void * | 115 | static void * |
116 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 116 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
117 | { | 117 | { |
118 | struct GNUNET_FS_Uri *kuri; | 118 | struct GNUNET_FS_Uri *kuri; |
119 | 119 | ||
120 | switch (event->status) | 120 | switch (event->status) |
121 | { | ||
122 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
124 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | ||
125 | (unsigned long long) event->value.publish.completed, | ||
126 | (unsigned long long) event->value.publish.size, | ||
127 | event->value.publish.specifics.progress.depth, | ||
128 | (unsigned long long) event->value.publish.specifics. | ||
129 | progress.offset); | ||
130 | break; | ||
131 | |||
132 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
133 | break; | ||
134 | |||
135 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
136 | processed_files++; | ||
137 | if (processed_files == NUM_FILES) | ||
121 | { | 138 | { |
122 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 139 | char *emsg = NULL; |
123 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 140 | kuri = GNUNET_FS_uri_ksk_create ("+down_foo +down_bar", &emsg); |
124 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 141 | GNUNET_assert (kuri != NULL); |
125 | (unsigned long long)event->value.publish.completed, | 142 | |
126 | (unsigned long long)event->value.publish.size, | 143 | start = GNUNET_TIME_absolute_get (); |
127 | event->value.publish.specifics.progress.depth, | 144 | search = |
128 | (unsigned long long)event->value.publish.specifics. | 145 | GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, |
129 | progress.offset); | 146 | "search"); |
130 | break; | 147 | GNUNET_FS_uri_destroy (kuri); |
131 | 148 | GNUNET_assert (search != NULL); | |
132 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
133 | break; | ||
134 | |||
135 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
136 | processed_files++; | ||
137 | if (processed_files == NUM_FILES) | ||
138 | { | ||
139 | char *emsg = NULL; | ||
140 | kuri = GNUNET_FS_uri_ksk_create("+down_foo +down_bar", &emsg); | ||
141 | GNUNET_assert(kuri != NULL); | ||
142 | |||
143 | start = GNUNET_TIME_absolute_get(); | ||
144 | search = | ||
145 | GNUNET_FS_search_start(fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, | ||
146 | "search"); | ||
147 | GNUNET_FS_uri_destroy(kuri); | ||
148 | GNUNET_assert(search != NULL); | ||
149 | } | ||
150 | break; | ||
151 | |||
152 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
153 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
154 | "Search complete.\n"); | ||
155 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); | ||
156 | break; | ||
157 | |||
158 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
159 | fprintf(stderr, "Error publishing file: %s\n", | ||
160 | event->value.publish.specifics.error.message); | ||
161 | GNUNET_break(0); | ||
162 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
163 | break; | ||
164 | |||
165 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
166 | fprintf(stderr, "Error searching file: %s\n", | ||
167 | event->value.search.specifics.error.message); | ||
168 | GNUNET_SCHEDULER_add_now(&abort_search_task, NULL); | ||
169 | break; | ||
170 | |||
171 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
172 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); | ||
173 | GNUNET_assert(NULL == event->value.publish.pctx); | ||
174 | GNUNET_assert(FILESIZE == event->value.publish.size); | ||
175 | GNUNET_assert(0 == event->value.publish.completed); | ||
176 | GNUNET_assert(1 == event->value.publish.anonymity); | ||
177 | break; | ||
178 | |||
179 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
180 | GNUNET_assert(publish == event->value.publish.pc); | ||
181 | GNUNET_assert(FILESIZE == event->value.publish.size); | ||
182 | GNUNET_assert(1 == event->value.publish.anonymity); | ||
183 | GNUNET_FS_stop(fs); | ||
184 | fs = NULL; | ||
185 | break; | ||
186 | |||
187 | case GNUNET_FS_STATUS_SEARCH_START: | ||
188 | GNUNET_assert(search == NULL); | ||
189 | GNUNET_assert(0 == strcmp("search", event->value.search.cctx)); | ||
190 | GNUNET_assert(1 == event->value.search.anonymity); | ||
191 | break; | ||
192 | |||
193 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
194 | break; | ||
195 | |||
196 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
197 | GNUNET_assert(search == event->value.search.sc); | ||
198 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
199 | break; | ||
200 | |||
201 | default: | ||
202 | fprintf(stderr, "Unexpected event: %d\n", event->status); | ||
203 | break; | ||
204 | } | 149 | } |
150 | break; | ||
151 | |||
152 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
154 | "Search complete.\n"); | ||
155 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | ||
156 | break; | ||
157 | |||
158 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
159 | fprintf (stderr, "Error publishing file: %s\n", | ||
160 | event->value.publish.specifics.error.message); | ||
161 | GNUNET_break (0); | ||
162 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
163 | break; | ||
164 | |||
165 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
166 | fprintf (stderr, "Error searching file: %s\n", | ||
167 | event->value.search.specifics.error.message); | ||
168 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | ||
169 | break; | ||
170 | |||
171 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
172 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | ||
173 | GNUNET_assert (NULL == event->value.publish.pctx); | ||
174 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
175 | GNUNET_assert (0 == event->value.publish.completed); | ||
176 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
177 | break; | ||
178 | |||
179 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
180 | GNUNET_assert (publish == event->value.publish.pc); | ||
181 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
182 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
183 | GNUNET_FS_stop (fs); | ||
184 | fs = NULL; | ||
185 | break; | ||
186 | |||
187 | case GNUNET_FS_STATUS_SEARCH_START: | ||
188 | GNUNET_assert (search == NULL); | ||
189 | GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); | ||
190 | GNUNET_assert (1 == event->value.search.anonymity); | ||
191 | break; | ||
192 | |||
193 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
194 | break; | ||
195 | |||
196 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
197 | GNUNET_assert (search == event->value.search.sc); | ||
198 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
199 | break; | ||
200 | |||
201 | default: | ||
202 | fprintf (stderr, "Unexpected event: %d\n", event->status); | ||
203 | break; | ||
204 | } | ||
205 | return NULL; | 205 | return NULL; |
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | static void | 209 | static void |
210 | run(void *cls, | 210 | run (void *cls, |
211 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 211 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
212 | struct GNUNET_TESTING_Peer *peer) | 212 | struct GNUNET_TESTING_Peer *peer) |
213 | { | 213 | { |
214 | const char *keywords[] = { | 214 | const char *keywords[] = { |
215 | "down_foo", | 215 | "down_foo", |
@@ -223,47 +223,47 @@ run(void *cls, | |||
223 | size_t i; | 223 | size_t i; |
224 | size_t j; | 224 | size_t j; |
225 | 225 | ||
226 | fs = GNUNET_FS_start(cfg, "test-fs-search", &progress_cb, NULL, | 226 | fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, |
227 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 227 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
228 | GNUNET_assert(NULL != fs); | 228 | GNUNET_assert (NULL != fs); |
229 | 229 | ||
230 | processed_files = 0; | 230 | processed_files = 0; |
231 | for (j = 0; j < NUM_FILES; j++) | 231 | for (j = 0; j < NUM_FILES; j++) |
232 | { | 232 | { |
233 | buf = GNUNET_malloc(FILESIZE); | 233 | buf = GNUNET_malloc (FILESIZE); |
234 | for (i = 0; i < FILESIZE; i++) | 234 | for (i = 0; i < FILESIZE; i++) |
235 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 235 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
236 | meta = GNUNET_CONTAINER_meta_data_create(); | 236 | meta = GNUNET_CONTAINER_meta_data_create (); |
237 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 237 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
238 | bo.content_priority = 42; | 238 | bo.content_priority = 42; |
239 | bo.anonymity_level = 1; | 239 | bo.anonymity_level = 1; |
240 | bo.replication_level = 0; | 240 | bo.replication_level = 0; |
241 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 241 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
242 | fi = GNUNET_FS_file_information_create_from_data(fs, "publish-context", | 242 | fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context", |
243 | FILESIZE, buf, kuri, meta, | 243 | FILESIZE, buf, kuri, meta, |
244 | GNUNET_NO, &bo); | 244 | GNUNET_NO, &bo); |
245 | GNUNET_FS_uri_destroy(kuri); | 245 | GNUNET_FS_uri_destroy (kuri); |
246 | GNUNET_CONTAINER_meta_data_destroy(meta); | 246 | GNUNET_CONTAINER_meta_data_destroy (meta); |
247 | GNUNET_assert(NULL != fi); | 247 | GNUNET_assert (NULL != fi); |
248 | start = GNUNET_TIME_absolute_get(); | 248 | start = GNUNET_TIME_absolute_get (); |
249 | publish = | 249 | publish = |
250 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, | 250 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, |
251 | GNUNET_FS_PUBLISH_OPTION_NONE); | 251 | GNUNET_FS_PUBLISH_OPTION_NONE); |
252 | GNUNET_assert(publish != NULL); | 252 | GNUNET_assert (publish != NULL); |
253 | } | 253 | } |
254 | 254 | ||
255 | 255 | ||
256 | timeout_task = GNUNET_SCHEDULER_add_delayed(LIFETIME, | 256 | timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME, |
257 | &abort_error, NULL); | 257 | &abort_error, NULL); |
258 | } | 258 | } |
259 | 259 | ||
260 | 260 | ||
261 | int | 261 | int |
262 | main(int argc, char *argv[]) | 262 | main (int argc, char *argv[]) |
263 | { | 263 | { |
264 | if (0 != GNUNET_TESTING_peer_run("test-fs-search-with-and", | 264 | if (0 != GNUNET_TESTING_peer_run ("test-fs-search-with-and", |
265 | "test_fs_search_data.conf", | 265 | "test_fs_search_data.conf", |
266 | &run, NULL)) | 266 | &run, NULL)) |
267 | return 1; | 267 | return 1; |
268 | return err; | 268 | return err; |
269 | } | 269 | } |
diff --git a/src/fs/test_fs_start_stop.c b/src/fs/test_fs_start_stop.c index 4e3c17db0..1d6e27d62 100644 --- a/src/fs/test_fs_start_stop.c +++ b/src/fs/test_fs_start_stop.c | |||
@@ -30,32 +30,32 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | static void * | 32 | static void * |
33 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 33 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
34 | { | 34 | { |
35 | return NULL; | 35 | return NULL; |
36 | } | 36 | } |
37 | 37 | ||
38 | 38 | ||
39 | static void | 39 | static void |
40 | run(void *cls, | 40 | run (void *cls, |
41 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 41 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
42 | struct GNUNET_TESTING_Peer *peer) | 42 | struct GNUNET_TESTING_Peer *peer) |
43 | { | 43 | { |
44 | struct GNUNET_FS_Handle *fs; | 44 | struct GNUNET_FS_Handle *fs; |
45 | 45 | ||
46 | fs = GNUNET_FS_start(cfg, "test-fs-start-stop", &progress_cb, NULL, | 46 | fs = GNUNET_FS_start (cfg, "test-fs-start-stop", &progress_cb, NULL, |
47 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 47 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
48 | GNUNET_assert(NULL != fs); | 48 | GNUNET_assert (NULL != fs); |
49 | GNUNET_FS_stop(fs); | 49 | GNUNET_FS_stop (fs); |
50 | } | 50 | } |
51 | 51 | ||
52 | 52 | ||
53 | int | 53 | int |
54 | main(int argc, char *argv[]) | 54 | main (int argc, char *argv[]) |
55 | { | 55 | { |
56 | if (0 != GNUNET_TESTING_peer_run("test-fs-start-stop", | 56 | if (0 != GNUNET_TESTING_peer_run ("test-fs-start-stop", |
57 | "test_fs_data.conf", | 57 | "test_fs_data.conf", |
58 | &run, NULL)) | 58 | &run, NULL)) |
59 | return 1; | 59 | return 1; |
60 | return 0; | 60 | return 0; |
61 | } | 61 | } |
diff --git a/src/fs/test_fs_test_lib.c b/src/fs/test_fs_test_lib.c index 7e27469cc..25b843e85 100644 --- a/src/fs/test_fs_test_lib.c +++ b/src/fs/test_fs_test_lib.c | |||
@@ -36,7 +36,7 @@ | |||
36 | /** | 36 | /** |
37 | * How long until we give up on transmitting the message? | 37 | * How long until we give up on transmitting the message? |
38 | */ | 38 | */ |
39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
40 | 40 | ||
41 | #define NUM_DAEMONS 2 | 41 | #define NUM_DAEMONS 2 |
42 | 42 | ||
@@ -50,74 +50,75 @@ static int ret; | |||
50 | 50 | ||
51 | 51 | ||
52 | static void | 52 | static void |
53 | do_stop(void *cls) | 53 | do_stop (void *cls) |
54 | { | 54 | { |
55 | char *fn = cls; | 55 | char *fn = cls; |
56 | 56 | ||
57 | if (0 == | 57 | if (0 == |
58 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, | 58 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, |
59 | TIMEOUT)).rel_value_us) | 59 | TIMEOUT)). |
60 | { | 60 | rel_value_us) |
61 | GNUNET_break(0); | 61 | { |
62 | ret = 1; | 62 | GNUNET_break (0); |
63 | } | 63 | ret = 1; |
64 | } | ||
64 | else | 65 | else |
65 | { | 66 | { |
66 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 67 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
67 | "Finished download, shutting down\n"); | 68 | "Finished download, shutting down\n"); |
68 | } | 69 | } |
69 | if (NULL != fn) | 70 | if (NULL != fn) |
70 | { | 71 | { |
71 | GNUNET_DISK_directory_remove(fn); | 72 | GNUNET_DISK_directory_remove (fn); |
72 | GNUNET_free(fn); | 73 | GNUNET_free (fn); |
73 | } | 74 | } |
74 | GNUNET_SCHEDULER_shutdown(); | 75 | GNUNET_SCHEDULER_shutdown (); |
75 | } | 76 | } |
76 | 77 | ||
77 | 78 | ||
78 | static void | 79 | static void |
79 | do_download(void *cls, | 80 | do_download (void *cls, |
80 | const struct GNUNET_FS_Uri *uri, | 81 | const struct GNUNET_FS_Uri *uri, |
81 | const char *fn) | 82 | const char *fn) |
82 | { | 83 | { |
83 | if (NULL == uri) | 84 | if (NULL == uri) |
84 | { | 85 | { |
85 | GNUNET_break(0); | 86 | GNUNET_break (0); |
86 | GNUNET_SCHEDULER_shutdown(); | 87 | GNUNET_SCHEDULER_shutdown (); |
87 | ret = 1; | 88 | ret = 1; |
88 | return; | 89 | return; |
89 | } | 90 | } |
90 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
91 | "Downloading %llu bytes\n", | 92 | "Downloading %llu bytes\n", |
92 | (unsigned long long)FILESIZE); | 93 | (unsigned long long) FILESIZE); |
93 | start_time = GNUNET_TIME_absolute_get(); | 94 | start_time = GNUNET_TIME_absolute_get (); |
94 | GNUNET_FS_TEST_download(the_peers[0], | 95 | GNUNET_FS_TEST_download (the_peers[0], |
95 | TIMEOUT, 1, SEED, | 96 | TIMEOUT, 1, SEED, |
96 | uri, | 97 | uri, |
97 | VERBOSE, | 98 | VERBOSE, |
98 | &do_stop, | 99 | &do_stop, |
99 | (NULL == fn) ? NULL : GNUNET_strdup(fn)); | 100 | (NULL == fn) ? NULL : GNUNET_strdup (fn)); |
100 | } | 101 | } |
101 | 102 | ||
102 | 103 | ||
103 | static void | 104 | static void |
104 | do_publish(void *cls, | 105 | do_publish (void *cls, |
105 | struct GNUNET_TESTBED_Operation *op, | 106 | struct GNUNET_TESTBED_Operation *op, |
106 | const char *emsg) | 107 | const char *emsg) |
107 | { | 108 | { |
108 | GNUNET_TESTBED_operation_done(op); | 109 | GNUNET_TESTBED_operation_done (op); |
109 | if (NULL != emsg) | 110 | if (NULL != emsg) |
110 | { | 111 | { |
111 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect peers: %s\n", emsg); | 112 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect peers: %s\n", emsg); |
112 | GNUNET_break(0); | 113 | GNUNET_break (0); |
113 | ret = 1; | 114 | ret = 1; |
114 | GNUNET_SCHEDULER_shutdown(); | 115 | GNUNET_SCHEDULER_shutdown (); |
115 | return; | 116 | return; |
116 | } | 117 | } |
117 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
118 | (unsigned long long)FILESIZE); | 119 | (unsigned long long) FILESIZE); |
119 | GNUNET_FS_TEST_publish(the_peers[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED, | 120 | GNUNET_FS_TEST_publish (the_peers[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED, |
120 | VERBOSE, &do_download, NULL); | 121 | VERBOSE, &do_download, NULL); |
121 | } | 122 | } |
122 | 123 | ||
123 | 124 | ||
@@ -134,23 +135,23 @@ do_publish(void *cls, | |||
134 | * failed | 135 | * failed |
135 | */ | 136 | */ |
136 | static void | 137 | static void |
137 | run(void *cls, | 138 | run (void *cls, |
138 | struct GNUNET_TESTBED_RunHandle *h, | 139 | struct GNUNET_TESTBED_RunHandle *h, |
139 | unsigned int num_peers, | 140 | unsigned int num_peers, |
140 | struct GNUNET_TESTBED_Peer **peers, | 141 | struct GNUNET_TESTBED_Peer **peers, |
141 | unsigned int links_succeeded, | 142 | unsigned int links_succeeded, |
142 | unsigned int links_failed) | 143 | unsigned int links_failed) |
143 | { | 144 | { |
144 | unsigned int i; | 145 | unsigned int i; |
145 | 146 | ||
146 | GNUNET_assert(NUM_DAEMONS == num_peers); | 147 | GNUNET_assert (NUM_DAEMONS == num_peers); |
147 | for (i = 0; i < num_peers; i++) | 148 | for (i = 0; i < num_peers; i++) |
148 | the_peers[i] = peers[i]; | 149 | the_peers[i] = peers[i]; |
149 | GNUNET_TESTBED_overlay_connect(NULL, | 150 | GNUNET_TESTBED_overlay_connect (NULL, |
150 | &do_publish, | 151 | &do_publish, |
151 | NULL, | 152 | NULL, |
152 | peers[0], | 153 | peers[0], |
153 | peers[1]); | 154 | peers[1]); |
154 | } | 155 | } |
155 | 156 | ||
156 | 157 | ||
@@ -162,15 +163,15 @@ run(void *cls, | |||
162 | * @return 0 on success | 163 | * @return 0 on success |
163 | */ | 164 | */ |
164 | int | 165 | int |
165 | main(int argc, char *argv[]) | 166 | main (int argc, char *argv[]) |
166 | { | 167 | { |
167 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); | 168 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
168 | (void)GNUNET_TESTBED_test_run("test_fs_test_lib", | 169 | (void) GNUNET_TESTBED_test_run ("test_fs_test_lib", |
169 | "fs_test_lib_data.conf", | 170 | "fs_test_lib_data.conf", |
170 | NUM_DAEMONS, | 171 | NUM_DAEMONS, |
171 | 0, NULL, NULL, | 172 | 0, NULL, NULL, |
172 | &run, NULL); | 173 | &run, NULL); |
173 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); | 174 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
174 | return ret; | 175 | return ret; |
175 | } | 176 | } |
176 | 177 | ||
diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c index 1c1cf6239..19b935dbf 100644 --- a/src/fs/test_fs_unindex.c +++ b/src/fs/test_fs_unindex.c | |||
@@ -37,12 +37,12 @@ | |||
37 | /** | 37 | /** |
38 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
39 | */ | 39 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * How long should our test-content live? | 43 | * How long should our test-content live? |
44 | */ | 44 | */ |
45 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 45 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
46 | 46 | ||
47 | 47 | ||
48 | static struct GNUNET_TIME_Absolute start; | 48 | static struct GNUNET_TIME_Absolute start; |
@@ -57,127 +57,127 @@ static char *fn; | |||
57 | 57 | ||
58 | 58 | ||
59 | static void | 59 | static void |
60 | abort_publish_task(void *cls) | 60 | abort_publish_task (void *cls) |
61 | { | 61 | { |
62 | GNUNET_FS_publish_stop(publish); | 62 | GNUNET_FS_publish_stop (publish); |
63 | publish = NULL; | 63 | publish = NULL; |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
67 | static void | 67 | static void |
68 | abort_unindex_task(void *cls) | 68 | abort_unindex_task (void *cls) |
69 | { | 69 | { |
70 | GNUNET_FS_unindex_stop(unindex); | 70 | GNUNET_FS_unindex_stop (unindex); |
71 | unindex = NULL; | 71 | unindex = NULL; |
72 | GNUNET_DISK_directory_remove(fn); | 72 | GNUNET_DISK_directory_remove (fn); |
73 | GNUNET_free(fn); | 73 | GNUNET_free (fn); |
74 | fn = NULL; | 74 | fn = NULL; |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | static void * | 78 | static void * |
79 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 79 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
80 | { | 80 | { |
81 | switch (event->status) | 81 | switch (event->status) |
82 | { | 82 | { |
83 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 83 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
84 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
85 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 85 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
86 | (unsigned long long)event->value.publish.completed, | 86 | (unsigned long long) event->value.publish.completed, |
87 | (unsigned long long)event->value.publish.size, | 87 | (unsigned long long) event->value.publish.size, |
88 | event->value.publish.specifics.progress.depth, | 88 | event->value.publish.specifics.progress.depth, |
89 | (unsigned long long)event->value.publish.specifics. | 89 | (unsigned long long) event->value.publish.specifics. |
90 | progress.offset); | 90 | progress.offset); |
91 | break; | 91 | break; |
92 | 92 | ||
93 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 93 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
94 | break; | 94 | break; |
95 | 95 | ||
96 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 96 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
97 | printf("Publishing complete, %llu kbps.\n", | 97 | printf ("Publishing complete, %llu kbps.\n", |
98 | (unsigned long long)(FILESIZE * 1000000LL / | 98 | (unsigned long long) (FILESIZE * 1000000LL |
99 | (1 + | 99 | / (1 |
100 | GNUNET_TIME_absolute_get_duration | 100 | + GNUNET_TIME_absolute_get_duration |
101 | (start).rel_value_us) / 1024)); | 101 | (start).rel_value_us) / 1024)); |
102 | start = GNUNET_TIME_absolute_get(); | 102 | start = GNUNET_TIME_absolute_get (); |
103 | unindex = GNUNET_FS_unindex_start(fs, fn, "unindex"); | 103 | unindex = GNUNET_FS_unindex_start (fs, fn, "unindex"); |
104 | GNUNET_assert(unindex != NULL); | 104 | GNUNET_assert (unindex != NULL); |
105 | break; | 105 | break; |
106 | 106 | ||
107 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | 107 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: |
108 | printf("Unindex complete, %llu kbps.\n", | 108 | printf ("Unindex complete, %llu kbps.\n", |
109 | (unsigned long long)(FILESIZE * 1000000LL / | 109 | (unsigned long long) (FILESIZE * 1000000LL |
110 | (1 + | 110 | / (1 |
111 | GNUNET_TIME_absolute_get_duration | 111 | + GNUNET_TIME_absolute_get_duration |
112 | (start).rel_value_us) / 1024)); | 112 | (start).rel_value_us) / 1024)); |
113 | GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); | 113 | GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); |
114 | break; | 114 | break; |
115 | 115 | ||
116 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | 116 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: |
117 | GNUNET_assert(unindex == event->value.unindex.uc); | 117 | GNUNET_assert (unindex == event->value.unindex.uc); |
118 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
119 | "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", | 119 | "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", |
120 | (unsigned long long)event->value.unindex.completed, | 120 | (unsigned long long) event->value.unindex.completed, |
121 | (unsigned long long)event->value.unindex.size, | 121 | (unsigned long long) event->value.unindex.size, |
122 | event->value.unindex.specifics.progress.depth, | 122 | event->value.unindex.specifics.progress.depth, |
123 | (unsigned long long)event->value.unindex.specifics. | 123 | (unsigned long long) event->value.unindex.specifics. |
124 | progress.offset); | 124 | progress.offset); |
125 | break; | 125 | break; |
126 | 126 | ||
127 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 127 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
128 | fprintf(stderr, "Error publishing file: %s\n", | 128 | fprintf (stderr, "Error publishing file: %s\n", |
129 | event->value.publish.specifics.error.message); | 129 | event->value.publish.specifics.error.message); |
130 | GNUNET_break(0); | 130 | GNUNET_break (0); |
131 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 131 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
132 | break; | 132 | break; |
133 | 133 | ||
134 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | 134 | case GNUNET_FS_STATUS_UNINDEX_ERROR: |
135 | fprintf(stderr, "Error unindexing file: %s\n", | 135 | fprintf (stderr, "Error unindexing file: %s\n", |
136 | event->value.unindex.specifics.error.message); | 136 | event->value.unindex.specifics.error.message); |
137 | GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); | 137 | GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); |
138 | break; | 138 | break; |
139 | 139 | ||
140 | case GNUNET_FS_STATUS_PUBLISH_START: | 140 | case GNUNET_FS_STATUS_PUBLISH_START: |
141 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); | 141 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); |
142 | GNUNET_assert(NULL == event->value.publish.pctx); | 142 | GNUNET_assert (NULL == event->value.publish.pctx); |
143 | GNUNET_assert(FILESIZE == event->value.publish.size); | 143 | GNUNET_assert (FILESIZE == event->value.publish.size); |
144 | GNUNET_assert(0 == event->value.publish.completed); | 144 | GNUNET_assert (0 == event->value.publish.completed); |
145 | GNUNET_assert(1 == event->value.publish.anonymity); | 145 | GNUNET_assert (1 == event->value.publish.anonymity); |
146 | break; | 146 | break; |
147 | 147 | ||
148 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 148 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
149 | GNUNET_assert(publish == event->value.publish.pc); | 149 | GNUNET_assert (publish == event->value.publish.pc); |
150 | GNUNET_assert(FILESIZE == event->value.publish.size); | 150 | GNUNET_assert (FILESIZE == event->value.publish.size); |
151 | GNUNET_assert(1 == event->value.publish.anonymity); | 151 | GNUNET_assert (1 == event->value.publish.anonymity); |
152 | GNUNET_FS_stop(fs); | 152 | GNUNET_FS_stop (fs); |
153 | fs = NULL; | 153 | fs = NULL; |
154 | break; | 154 | break; |
155 | 155 | ||
156 | case GNUNET_FS_STATUS_UNINDEX_START: | 156 | case GNUNET_FS_STATUS_UNINDEX_START: |
157 | GNUNET_assert(unindex == NULL); | 157 | GNUNET_assert (unindex == NULL); |
158 | GNUNET_assert(0 == strcmp("unindex", event->value.unindex.cctx)); | 158 | GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx)); |
159 | GNUNET_assert(0 == strcmp(fn, event->value.unindex.filename)); | 159 | GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename)); |
160 | GNUNET_assert(FILESIZE == event->value.unindex.size); | 160 | GNUNET_assert (FILESIZE == event->value.unindex.size); |
161 | GNUNET_assert(0 == event->value.unindex.completed); | 161 | GNUNET_assert (0 == event->value.unindex.completed); |
162 | break; | 162 | break; |
163 | 163 | ||
164 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | 164 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: |
165 | GNUNET_assert(unindex == event->value.unindex.uc); | 165 | GNUNET_assert (unindex == event->value.unindex.uc); |
166 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | 166 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
167 | break; | 167 | break; |
168 | 168 | ||
169 | default: | 169 | default: |
170 | printf("Unexpected event: %d\n", event->status); | 170 | printf ("Unexpected event: %d\n", event->status); |
171 | break; | 171 | break; |
172 | } | 172 | } |
173 | return NULL; | 173 | return NULL; |
174 | } | 174 | } |
175 | 175 | ||
176 | 176 | ||
177 | static void | 177 | static void |
178 | run(void *cls, | 178 | run (void *cls, |
179 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 179 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
180 | struct GNUNET_TESTING_Peer *peer) | 180 | struct GNUNET_TESTING_Peer *peer) |
181 | { | 181 | { |
182 | const char *keywords[] = { | 182 | const char *keywords[] = { |
183 | "down_foo", | 183 | "down_foo", |
@@ -190,44 +190,44 @@ run(void *cls, | |||
190 | size_t i; | 190 | size_t i; |
191 | struct GNUNET_FS_BlockOptions bo; | 191 | struct GNUNET_FS_BlockOptions bo; |
192 | 192 | ||
193 | fn = GNUNET_DISK_mktemp("gnunet-unindex-test-dst"); | 193 | fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); |
194 | fs = GNUNET_FS_start(cfg, "test-fs-unindex", &progress_cb, NULL, | 194 | fs = GNUNET_FS_start (cfg, "test-fs-unindex", &progress_cb, NULL, |
195 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 195 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
196 | GNUNET_assert(NULL != fs); | 196 | GNUNET_assert (NULL != fs); |
197 | buf = GNUNET_malloc(FILESIZE); | 197 | buf = GNUNET_malloc (FILESIZE); |
198 | for (i = 0; i < FILESIZE; i++) | 198 | for (i = 0; i < FILESIZE; i++) |
199 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 199 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
200 | GNUNET_assert(FILESIZE == | 200 | GNUNET_assert (FILESIZE == |
201 | GNUNET_DISK_fn_write(fn, buf, FILESIZE, | 201 | GNUNET_DISK_fn_write (fn, buf, FILESIZE, |
202 | GNUNET_DISK_PERM_USER_READ | | 202 | GNUNET_DISK_PERM_USER_READ |
203 | GNUNET_DISK_PERM_USER_WRITE)); | 203 | | GNUNET_DISK_PERM_USER_WRITE)); |
204 | GNUNET_free(buf); | 204 | GNUNET_free (buf); |
205 | meta = GNUNET_CONTAINER_meta_data_create(); | 205 | meta = GNUNET_CONTAINER_meta_data_create (); |
206 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 206 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
207 | bo.content_priority = 42; | 207 | bo.content_priority = 42; |
208 | bo.anonymity_level = 1; | 208 | bo.anonymity_level = 1; |
209 | bo.replication_level = 0; | 209 | bo.replication_level = 0; |
210 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 210 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
211 | fi = GNUNET_FS_file_information_create_from_file(fs, "publish-context", fn, | 211 | fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn, |
212 | kuri, meta, GNUNET_YES, | 212 | kuri, meta, GNUNET_YES, |
213 | &bo); | 213 | &bo); |
214 | GNUNET_FS_uri_destroy(kuri); | 214 | GNUNET_FS_uri_destroy (kuri); |
215 | GNUNET_CONTAINER_meta_data_destroy(meta); | 215 | GNUNET_CONTAINER_meta_data_destroy (meta); |
216 | GNUNET_assert(NULL != fi); | 216 | GNUNET_assert (NULL != fi); |
217 | start = GNUNET_TIME_absolute_get(); | 217 | start = GNUNET_TIME_absolute_get (); |
218 | publish = | 218 | publish = |
219 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, | 219 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, |
220 | GNUNET_FS_PUBLISH_OPTION_NONE); | 220 | GNUNET_FS_PUBLISH_OPTION_NONE); |
221 | GNUNET_assert(publish != NULL); | 221 | GNUNET_assert (publish != NULL); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | int | 225 | int |
226 | main(int argc, char *argv[]) | 226 | main (int argc, char *argv[]) |
227 | { | 227 | { |
228 | if (0 != GNUNET_TESTING_peer_run("test-fs-unindex", | 228 | if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex", |
229 | "test_fs_unindex_data.conf", | 229 | "test_fs_unindex_data.conf", |
230 | &run, NULL)) | 230 | &run, NULL)) |
231 | return 1; | 231 | return 1; |
232 | return 0; | 232 | return 0; |
233 | } | 233 | } |
diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c index 7deebb95b..28079b842 100644 --- a/src/fs/test_fs_unindex_persistence.c +++ b/src/fs/test_fs_unindex_persistence.c | |||
@@ -36,12 +36,12 @@ | |||
36 | /** | 36 | /** |
37 | * How long until we give up on transmitting the message? | 37 | * How long until we give up on transmitting the message? |
38 | */ | 38 | */ |
39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How long should our test-content live? | 42 | * How long should our test-content live? |
43 | */ | 43 | */ |
44 | #define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 44 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
45 | 45 | ||
46 | 46 | ||
47 | static struct GNUNET_TIME_Absolute start; | 47 | static struct GNUNET_TIME_Absolute start; |
@@ -58,40 +58,40 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
58 | 58 | ||
59 | 59 | ||
60 | static void | 60 | static void |
61 | abort_publish_task(void *cls) | 61 | abort_publish_task (void *cls) |
62 | { | 62 | { |
63 | GNUNET_FS_publish_stop(publish); | 63 | GNUNET_FS_publish_stop (publish); |
64 | publish = NULL; | 64 | publish = NULL; |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | static void | 68 | static void |
69 | abort_unindex_task(void *cls) | 69 | abort_unindex_task (void *cls) |
70 | { | 70 | { |
71 | if (unindex != NULL) | 71 | if (unindex != NULL) |
72 | { | 72 | { |
73 | GNUNET_FS_unindex_stop(unindex); | 73 | GNUNET_FS_unindex_stop (unindex); |
74 | unindex = NULL; | 74 | unindex = NULL; |
75 | } | 75 | } |
76 | if (fn != NULL) | 76 | if (fn != NULL) |
77 | { | 77 | { |
78 | GNUNET_DISK_directory_remove(fn); | 78 | GNUNET_DISK_directory_remove (fn); |
79 | GNUNET_free(fn); | 79 | GNUNET_free (fn); |
80 | fn = NULL; | 80 | fn = NULL; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | static void * | 85 | static void * |
86 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event); | 86 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event); |
87 | 87 | ||
88 | 88 | ||
89 | static void | 89 | static void |
90 | restart_fs_task(void *cls) | 90 | restart_fs_task (void *cls) |
91 | { | 91 | { |
92 | GNUNET_FS_stop(fs); | 92 | GNUNET_FS_stop (fs); |
93 | fs = GNUNET_FS_start(cfg, "test-fs-unindex-persistence", &progress_cb, NULL, | 93 | fs = GNUNET_FS_start (cfg, "test-fs-unindex-persistence", &progress_cb, NULL, |
94 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 94 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
@@ -103,7 +103,7 @@ restart_fs_task(void *cls) | |||
103 | * @param ev type of the event to consider | 103 | * @param ev type of the event to consider |
104 | */ | 104 | */ |
105 | static void | 105 | static void |
106 | consider_restart(int ev) | 106 | consider_restart (int ev) |
107 | { | 107 | { |
108 | static int prev[32]; | 108 | static int prev[32]; |
109 | static int off; | 109 | static int off; |
@@ -113,140 +113,140 @@ consider_restart(int ev) | |||
113 | if (prev[i] == ev) | 113 | if (prev[i] == ev) |
114 | return; | 114 | return; |
115 | prev[off++] = ev; | 115 | prev[off++] = ev; |
116 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_URGENT, | 116 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, |
117 | &restart_fs_task, NULL); | 117 | &restart_fs_task, NULL); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | static void * | 121 | static void * |
122 | progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event) | 122 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) |
123 | { | 123 | { |
124 | switch (event->status) | 124 | switch (event->status) |
125 | { | ||
126 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
128 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | ||
129 | (unsigned long long) event->value.publish.completed, | ||
130 | (unsigned long long) event->value.publish.size, | ||
131 | event->value.publish.specifics.progress.depth, | ||
132 | (unsigned long long) event->value.publish.specifics. | ||
133 | progress.offset); | ||
134 | break; | ||
135 | |||
136 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
137 | break; | ||
138 | |||
139 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
140 | printf ("Publishing complete, %llu kbps.\n", | ||
141 | (unsigned long long) (FILESIZE * 1000000LL | ||
142 | / (1 | ||
143 | + GNUNET_TIME_absolute_get_duration | ||
144 | (start).rel_value_us) / 1024)); | ||
145 | start = GNUNET_TIME_absolute_get (); | ||
146 | unindex = GNUNET_FS_unindex_start (fs, fn, "unindex"); | ||
147 | GNUNET_assert (unindex != NULL); | ||
148 | break; | ||
149 | |||
150 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | ||
151 | printf ("Unindex complete, %llu kbps.\n", | ||
152 | (unsigned long long) (FILESIZE * 1000000LL | ||
153 | / (1 | ||
154 | + GNUNET_TIME_absolute_get_duration | ||
155 | (start).rel_value_us) / 1024)); | ||
156 | GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); | ||
157 | break; | ||
158 | |||
159 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | ||
160 | consider_restart (event->status); | ||
161 | GNUNET_assert (unindex == event->value.unindex.uc); | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
163 | "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", | ||
164 | (unsigned long long) event->value.unindex.completed, | ||
165 | (unsigned long long) event->value.unindex.size, | ||
166 | event->value.unindex.specifics.progress.depth, | ||
167 | (unsigned long long) event->value.unindex.specifics. | ||
168 | progress.offset); | ||
169 | break; | ||
170 | |||
171 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | ||
172 | if (event->value.publish.pc == publish) | ||
173 | publish = NULL; | ||
174 | break; | ||
175 | |||
176 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | ||
177 | if (NULL == publish) | ||
125 | { | 178 | { |
126 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 179 | publish = event->value.publish.pc; |
127 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 180 | return "publish-context"; |
128 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", | ||
129 | (unsigned long long)event->value.publish.completed, | ||
130 | (unsigned long long)event->value.publish.size, | ||
131 | event->value.publish.specifics.progress.depth, | ||
132 | (unsigned long long)event->value.publish.specifics. | ||
133 | progress.offset); | ||
134 | break; | ||
135 | |||
136 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
137 | break; | ||
138 | |||
139 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
140 | printf("Publishing complete, %llu kbps.\n", | ||
141 | (unsigned long long)(FILESIZE * 1000000LL / | ||
142 | (1 + | ||
143 | GNUNET_TIME_absolute_get_duration | ||
144 | (start).rel_value_us) / 1024)); | ||
145 | start = GNUNET_TIME_absolute_get(); | ||
146 | unindex = GNUNET_FS_unindex_start(fs, fn, "unindex"); | ||
147 | GNUNET_assert(unindex != NULL); | ||
148 | break; | ||
149 | |||
150 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | ||
151 | printf("Unindex complete, %llu kbps.\n", | ||
152 | (unsigned long long)(FILESIZE * 1000000LL / | ||
153 | (1 + | ||
154 | GNUNET_TIME_absolute_get_duration | ||
155 | (start).rel_value_us) / 1024)); | ||
156 | GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); | ||
157 | break; | ||
158 | |||
159 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | ||
160 | consider_restart(event->status); | ||
161 | GNUNET_assert(unindex == event->value.unindex.uc); | ||
162 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
163 | "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", | ||
164 | (unsigned long long)event->value.unindex.completed, | ||
165 | (unsigned long long)event->value.unindex.size, | ||
166 | event->value.unindex.specifics.progress.depth, | ||
167 | (unsigned long long)event->value.unindex.specifics. | ||
168 | progress.offset); | ||
169 | break; | ||
170 | |||
171 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | ||
172 | if (event->value.publish.pc == publish) | ||
173 | publish = NULL; | ||
174 | break; | ||
175 | |||
176 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | ||
177 | if (NULL == publish) | ||
178 | { | ||
179 | publish = event->value.publish.pc; | ||
180 | return "publish-context"; | ||
181 | } | ||
182 | break; | ||
183 | |||
184 | case GNUNET_FS_STATUS_UNINDEX_SUSPEND: | ||
185 | GNUNET_assert(event->value.unindex.uc == unindex); | ||
186 | unindex = NULL; | ||
187 | break; | ||
188 | |||
189 | case GNUNET_FS_STATUS_UNINDEX_RESUME: | ||
190 | GNUNET_assert(NULL == unindex); | ||
191 | unindex = event->value.unindex.uc; | ||
192 | return "unindex"; | ||
193 | |||
194 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
195 | fprintf(stderr, "Error publishing file: %s\n", | ||
196 | event->value.publish.specifics.error.message); | ||
197 | GNUNET_break(0); | ||
198 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
199 | break; | ||
200 | |||
201 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | ||
202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
203 | "Error unindexing file: %s\n", | ||
204 | event->value.unindex.specifics.error.message); | ||
205 | GNUNET_SCHEDULER_add_now(&abort_unindex_task, NULL); | ||
206 | break; | ||
207 | |||
208 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
209 | GNUNET_assert(0 == strcmp("publish-context", event->value.publish.cctx)); | ||
210 | GNUNET_assert(NULL == event->value.publish.pctx); | ||
211 | GNUNET_assert(FILESIZE == event->value.publish.size); | ||
212 | GNUNET_assert(0 == event->value.publish.completed); | ||
213 | GNUNET_assert(1 == event->value.publish.anonymity); | ||
214 | break; | ||
215 | |||
216 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
217 | GNUNET_assert(publish == event->value.publish.pc); | ||
218 | GNUNET_assert(FILESIZE == event->value.publish.size); | ||
219 | GNUNET_assert(1 == event->value.publish.anonymity); | ||
220 | GNUNET_FS_stop(fs); | ||
221 | fs = NULL; | ||
222 | break; | ||
223 | |||
224 | case GNUNET_FS_STATUS_UNINDEX_START: | ||
225 | consider_restart(event->status); | ||
226 | GNUNET_assert(unindex == NULL); | ||
227 | GNUNET_assert(0 == strcmp("unindex", event->value.unindex.cctx)); | ||
228 | GNUNET_assert(0 == strcmp(fn, event->value.unindex.filename)); | ||
229 | GNUNET_assert(FILESIZE == event->value.unindex.size); | ||
230 | GNUNET_assert(0 == event->value.unindex.completed); | ||
231 | break; | ||
232 | |||
233 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | ||
234 | GNUNET_assert(unindex == event->value.unindex.uc); | ||
235 | GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL); | ||
236 | break; | ||
237 | |||
238 | default: | ||
239 | printf("Unexpected event: %d\n", event->status); | ||
240 | break; | ||
241 | } | 181 | } |
182 | break; | ||
183 | |||
184 | case GNUNET_FS_STATUS_UNINDEX_SUSPEND: | ||
185 | GNUNET_assert (event->value.unindex.uc == unindex); | ||
186 | unindex = NULL; | ||
187 | break; | ||
188 | |||
189 | case GNUNET_FS_STATUS_UNINDEX_RESUME: | ||
190 | GNUNET_assert (NULL == unindex); | ||
191 | unindex = event->value.unindex.uc; | ||
192 | return "unindex"; | ||
193 | |||
194 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
195 | fprintf (stderr, "Error publishing file: %s\n", | ||
196 | event->value.publish.specifics.error.message); | ||
197 | GNUNET_break (0); | ||
198 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
199 | break; | ||
200 | |||
201 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | ||
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
203 | "Error unindexing file: %s\n", | ||
204 | event->value.unindex.specifics.error.message); | ||
205 | GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); | ||
206 | break; | ||
207 | |||
208 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
209 | GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); | ||
210 | GNUNET_assert (NULL == event->value.publish.pctx); | ||
211 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
212 | GNUNET_assert (0 == event->value.publish.completed); | ||
213 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
214 | break; | ||
215 | |||
216 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
217 | GNUNET_assert (publish == event->value.publish.pc); | ||
218 | GNUNET_assert (FILESIZE == event->value.publish.size); | ||
219 | GNUNET_assert (1 == event->value.publish.anonymity); | ||
220 | GNUNET_FS_stop (fs); | ||
221 | fs = NULL; | ||
222 | break; | ||
223 | |||
224 | case GNUNET_FS_STATUS_UNINDEX_START: | ||
225 | consider_restart (event->status); | ||
226 | GNUNET_assert (unindex == NULL); | ||
227 | GNUNET_assert (0 == strcmp ("unindex", event->value.unindex.cctx)); | ||
228 | GNUNET_assert (0 == strcmp (fn, event->value.unindex.filename)); | ||
229 | GNUNET_assert (FILESIZE == event->value.unindex.size); | ||
230 | GNUNET_assert (0 == event->value.unindex.completed); | ||
231 | break; | ||
232 | |||
233 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | ||
234 | GNUNET_assert (unindex == event->value.unindex.uc); | ||
235 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | ||
236 | break; | ||
237 | |||
238 | default: | ||
239 | printf ("Unexpected event: %d\n", event->status); | ||
240 | break; | ||
241 | } | ||
242 | return NULL; | 242 | return NULL; |
243 | } | 243 | } |
244 | 244 | ||
245 | 245 | ||
246 | static void | 246 | static void |
247 | run(void *cls, | 247 | run (void *cls, |
248 | const struct GNUNET_CONFIGURATION_Handle *c, | 248 | const struct GNUNET_CONFIGURATION_Handle *c, |
249 | struct GNUNET_TESTING_Peer *peer) | 249 | struct GNUNET_TESTING_Peer *peer) |
250 | { | 250 | { |
251 | const char *keywords[] = { | 251 | const char *keywords[] = { |
252 | "down_foo", | 252 | "down_foo", |
@@ -260,44 +260,44 @@ run(void *cls, | |||
260 | struct GNUNET_FS_BlockOptions bo; | 260 | struct GNUNET_FS_BlockOptions bo; |
261 | 261 | ||
262 | cfg = c; | 262 | cfg = c; |
263 | fn = GNUNET_DISK_mktemp("gnunet-unindex-test-dst"); | 263 | fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); |
264 | fs = GNUNET_FS_start(cfg, "test-fs-unindex-persistence", &progress_cb, NULL, | 264 | fs = GNUNET_FS_start (cfg, "test-fs-unindex-persistence", &progress_cb, NULL, |
265 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 265 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
266 | GNUNET_assert(NULL != fs); | 266 | GNUNET_assert (NULL != fs); |
267 | buf = GNUNET_malloc(FILESIZE); | 267 | buf = GNUNET_malloc (FILESIZE); |
268 | for (i = 0; i < FILESIZE; i++) | 268 | for (i = 0; i < FILESIZE; i++) |
269 | buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); | 269 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
270 | GNUNET_assert(FILESIZE == | 270 | GNUNET_assert (FILESIZE == |
271 | GNUNET_DISK_fn_write(fn, buf, FILESIZE, | 271 | GNUNET_DISK_fn_write (fn, buf, FILESIZE, |
272 | GNUNET_DISK_PERM_USER_READ | | 272 | GNUNET_DISK_PERM_USER_READ |
273 | GNUNET_DISK_PERM_USER_WRITE)); | 273 | | GNUNET_DISK_PERM_USER_WRITE)); |
274 | GNUNET_free(buf); | 274 | GNUNET_free (buf); |
275 | meta = GNUNET_CONTAINER_meta_data_create(); | 275 | meta = GNUNET_CONTAINER_meta_data_create (); |
276 | kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords); | 276 | kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); |
277 | bo.content_priority = 42; | 277 | bo.content_priority = 42; |
278 | bo.anonymity_level = 1; | 278 | bo.anonymity_level = 1; |
279 | bo.replication_level = 0; | 279 | bo.replication_level = 0; |
280 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME); | 280 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); |
281 | fi = GNUNET_FS_file_information_create_from_file(fs, "publish-context", fn, | 281 | fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn, |
282 | kuri, meta, GNUNET_YES, | 282 | kuri, meta, GNUNET_YES, |
283 | &bo); | 283 | &bo); |
284 | GNUNET_FS_uri_destroy(kuri); | 284 | GNUNET_FS_uri_destroy (kuri); |
285 | GNUNET_CONTAINER_meta_data_destroy(meta); | 285 | GNUNET_CONTAINER_meta_data_destroy (meta); |
286 | GNUNET_assert(NULL != fi); | 286 | GNUNET_assert (NULL != fi); |
287 | start = GNUNET_TIME_absolute_get(); | 287 | start = GNUNET_TIME_absolute_get (); |
288 | publish = | 288 | publish = |
289 | GNUNET_FS_publish_start(fs, fi, NULL, NULL, NULL, | 289 | GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, |
290 | GNUNET_FS_PUBLISH_OPTION_NONE); | 290 | GNUNET_FS_PUBLISH_OPTION_NONE); |
291 | GNUNET_assert(publish != NULL); | 291 | GNUNET_assert (publish != NULL); |
292 | } | 292 | } |
293 | 293 | ||
294 | 294 | ||
295 | int | 295 | int |
296 | main(int argc, char *argv[]) | 296 | main (int argc, char *argv[]) |
297 | { | 297 | { |
298 | if (0 != GNUNET_TESTING_peer_run("test-fs-unindex-persistence", | 298 | if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex-persistence", |
299 | "test_fs_unindex_data.conf", | 299 | "test_fs_unindex_data.conf", |
300 | &run, NULL)) | 300 | &run, NULL)) |
301 | return 1; | 301 | return 1; |
302 | return 0; | 302 | return 0; |
303 | } | 303 | } |
diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c index 3cbbc27d3..0602d8318 100644 --- a/src/fs/test_fs_uri.c +++ b/src/fs/test_fs_uri.c | |||
@@ -29,52 +29,52 @@ | |||
29 | 29 | ||
30 | 30 | ||
31 | static int | 31 | static int |
32 | testKeyword() | 32 | testKeyword () |
33 | { | 33 | { |
34 | char *uri; | 34 | char *uri; |
35 | struct GNUNET_FS_Uri *ret; | 35 | struct GNUNET_FS_Uri *ret; |
36 | char *emsg; | 36 | char *emsg; |
37 | 37 | ||
38 | if (NULL != (ret = GNUNET_FS_uri_parse("gnunet://fs/ksk/++", &emsg))) | 38 | if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/++", &emsg))) |
39 | { | 39 | { |
40 | GNUNET_FS_uri_destroy(ret); | 40 | GNUNET_FS_uri_destroy (ret); |
41 | GNUNET_assert(0); | 41 | GNUNET_assert (0); |
42 | } | 42 | } |
43 | GNUNET_free(emsg); | 43 | GNUNET_free (emsg); |
44 | ret = GNUNET_FS_uri_parse("gnunet://fs/ksk/foo+bar", &emsg); | 44 | ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/foo+bar", &emsg); |
45 | if (NULL == ret) | 45 | if (NULL == ret) |
46 | { | 46 | { |
47 | GNUNET_free(emsg); | 47 | GNUNET_free (emsg); |
48 | GNUNET_assert(0); | 48 | GNUNET_assert (0); |
49 | } | 49 | } |
50 | if (!GNUNET_FS_uri_test_ksk(ret)) | 50 | if (! GNUNET_FS_uri_test_ksk (ret)) |
51 | { | 51 | { |
52 | GNUNET_FS_uri_destroy(ret); | 52 | GNUNET_FS_uri_destroy (ret); |
53 | GNUNET_assert(0); | 53 | GNUNET_assert (0); |
54 | } | 54 | } |
55 | if ((2 != ret->data.ksk.keywordCount) || | 55 | if ((2 != ret->data.ksk.keywordCount) || |
56 | (0 != strcmp(" foo", ret->data.ksk.keywords[0])) || | 56 | (0 != strcmp (" foo", ret->data.ksk.keywords[0])) || |
57 | (0 != strcmp(" bar", ret->data.ksk.keywords[1]))) | 57 | (0 != strcmp (" bar", ret->data.ksk.keywords[1]))) |
58 | { | 58 | { |
59 | GNUNET_FS_uri_destroy(ret); | 59 | GNUNET_FS_uri_destroy (ret); |
60 | GNUNET_assert(0); | 60 | GNUNET_assert (0); |
61 | } | 61 | } |
62 | 62 | ||
63 | uri = GNUNET_FS_uri_to_string(ret); | 63 | uri = GNUNET_FS_uri_to_string (ret); |
64 | if (0 != strcmp(uri, "gnunet://fs/ksk/foo+bar")) | 64 | if (0 != strcmp (uri, "gnunet://fs/ksk/foo+bar")) |
65 | { | 65 | { |
66 | GNUNET_free(uri); | 66 | GNUNET_free (uri); |
67 | GNUNET_FS_uri_destroy(ret); | 67 | GNUNET_FS_uri_destroy (ret); |
68 | GNUNET_assert(0); | 68 | GNUNET_assert (0); |
69 | } | 69 | } |
70 | GNUNET_free(uri); | 70 | GNUNET_free (uri); |
71 | GNUNET_FS_uri_destroy(ret); | 71 | GNUNET_FS_uri_destroy (ret); |
72 | return 0; | 72 | return 0; |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static int | 76 | static int |
77 | testLocation() | 77 | testLocation () |
78 | { | 78 | { |
79 | struct GNUNET_FS_Uri *uri; | 79 | struct GNUNET_FS_Uri *uri; |
80 | char *uric; | 80 | char *uric; |
@@ -85,70 +85,71 @@ testLocation() | |||
85 | 85 | ||
86 | baseURI = | 86 | baseURI = |
87 | GNUNET_FS_uri_parse | 87 | GNUNET_FS_uri_parse |
88 | ("gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.15999", | 88 | ( |
89 | "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.15999", | ||
89 | &emsg); | 90 | &emsg); |
90 | GNUNET_assert(baseURI != NULL); | 91 | GNUNET_assert (baseURI != NULL); |
91 | GNUNET_assert(emsg == NULL); | 92 | GNUNET_assert (emsg == NULL); |
92 | pk = GNUNET_CRYPTO_eddsa_key_create(); | 93 | pk = GNUNET_CRYPTO_eddsa_key_create (); |
93 | uri = GNUNET_FS_uri_loc_create(baseURI, | 94 | uri = GNUNET_FS_uri_loc_create (baseURI, |
94 | pk, | 95 | pk, |
95 | GNUNET_TIME_absolute_get()); | 96 | GNUNET_TIME_absolute_get ()); |
96 | GNUNET_free(pk); | 97 | GNUNET_free (pk); |
97 | if (NULL == uri) | 98 | if (NULL == uri) |
98 | { | 99 | { |
99 | GNUNET_break(0); | 100 | GNUNET_break (0); |
100 | GNUNET_FS_uri_destroy(baseURI); | 101 | GNUNET_FS_uri_destroy (baseURI); |
101 | return 1; | 102 | return 1; |
102 | } | 103 | } |
103 | if (!GNUNET_FS_uri_test_loc(uri)) | 104 | if (! GNUNET_FS_uri_test_loc (uri)) |
104 | { | 105 | { |
105 | GNUNET_break(0); | 106 | GNUNET_break (0); |
106 | GNUNET_FS_uri_destroy(uri); | 107 | GNUNET_FS_uri_destroy (uri); |
107 | GNUNET_FS_uri_destroy(baseURI); | 108 | GNUNET_FS_uri_destroy (baseURI); |
108 | return 1; | 109 | return 1; |
109 | } | 110 | } |
110 | uri2 = GNUNET_FS_uri_loc_get_uri(uri); | 111 | uri2 = GNUNET_FS_uri_loc_get_uri (uri); |
111 | if (!GNUNET_FS_uri_test_equal(baseURI, uri2)) | 112 | if (! GNUNET_FS_uri_test_equal (baseURI, uri2)) |
112 | { | 113 | { |
113 | GNUNET_break(0); | 114 | GNUNET_break (0); |
114 | GNUNET_FS_uri_destroy(uri); | 115 | GNUNET_FS_uri_destroy (uri); |
115 | GNUNET_FS_uri_destroy(uri2); | 116 | GNUNET_FS_uri_destroy (uri2); |
116 | GNUNET_FS_uri_destroy(baseURI); | 117 | GNUNET_FS_uri_destroy (baseURI); |
117 | return 1; | 118 | return 1; |
118 | } | 119 | } |
119 | GNUNET_FS_uri_destroy(uri2); | 120 | GNUNET_FS_uri_destroy (uri2); |
120 | GNUNET_FS_uri_destroy(baseURI); | 121 | GNUNET_FS_uri_destroy (baseURI); |
121 | uric = GNUNET_FS_uri_to_string(uri); | 122 | uric = GNUNET_FS_uri_to_string (uri); |
122 | #if 0 | 123 | #if 0 |
123 | /* not for the faint of heart: */ | 124 | /* not for the faint of heart: */ |
124 | printf("URI: `%s'\n", uric); | 125 | printf ("URI: `%s'\n", uric); |
125 | #endif | 126 | #endif |
126 | uri2 = GNUNET_FS_uri_parse(uric, &emsg); | 127 | uri2 = GNUNET_FS_uri_parse (uric, &emsg); |
127 | GNUNET_free(uric); | 128 | GNUNET_free (uric); |
128 | if (uri2 == NULL) | 129 | if (uri2 == NULL) |
129 | { | 130 | { |
130 | fprintf(stderr, "URI parsing failed: %s\n", emsg); | 131 | fprintf (stderr, "URI parsing failed: %s\n", emsg); |
131 | GNUNET_break(0); | 132 | GNUNET_break (0); |
132 | GNUNET_FS_uri_destroy(uri); | 133 | GNUNET_FS_uri_destroy (uri); |
133 | GNUNET_free(emsg); | 134 | GNUNET_free (emsg); |
134 | return 1; | 135 | return 1; |
135 | } | 136 | } |
136 | GNUNET_assert(NULL == emsg); | 137 | GNUNET_assert (NULL == emsg); |
137 | if (GNUNET_YES != GNUNET_FS_uri_test_equal(uri, uri2)) | 138 | if (GNUNET_YES != GNUNET_FS_uri_test_equal (uri, uri2)) |
138 | { | 139 | { |
139 | GNUNET_break(0); | 140 | GNUNET_break (0); |
140 | GNUNET_FS_uri_destroy(uri); | 141 | GNUNET_FS_uri_destroy (uri); |
141 | GNUNET_FS_uri_destroy(uri2); | 142 | GNUNET_FS_uri_destroy (uri2); |
142 | return 1; | 143 | return 1; |
143 | } | 144 | } |
144 | GNUNET_FS_uri_destroy(uri2); | 145 | GNUNET_FS_uri_destroy (uri2); |
145 | GNUNET_FS_uri_destroy(uri); | 146 | GNUNET_FS_uri_destroy (uri); |
146 | return 0; | 147 | return 0; |
147 | } | 148 | } |
148 | 149 | ||
149 | 150 | ||
150 | static int | 151 | static int |
151 | testNamespace(int i) | 152 | testNamespace (int i) |
152 | { | 153 | { |
153 | char *uri; | 154 | char *uri; |
154 | struct GNUNET_FS_Uri *ret; | 155 | struct GNUNET_FS_Uri *ret; |
@@ -161,71 +162,74 @@ testNamespace(int i) | |||
161 | 162 | ||
162 | if (NULL != | 163 | if (NULL != |
163 | (ret = | 164 | (ret = |
164 | GNUNET_FS_uri_parse("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK", | 165 | GNUNET_FS_uri_parse ( |
165 | &emsg))) | 166 | "gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK", |
166 | { | 167 | &emsg))) |
167 | GNUNET_FS_uri_destroy(ret); | 168 | { |
168 | GNUNET_assert(0); | 169 | GNUNET_FS_uri_destroy (ret); |
169 | } | 170 | GNUNET_assert (0); |
170 | GNUNET_free(emsg); | 171 | } |
172 | GNUNET_free (emsg); | ||
171 | if (NULL != | 173 | if (NULL != |
172 | (ret = | 174 | (ret = |
173 | GNUNET_FS_uri_parse | 175 | GNUNET_FS_uri_parse |
174 | ("gnunet://fs/sks/XQHH4R288W26EBV369F6RCE0PJVJTX2Y74Q2FJPMPGA31HJX2JG/this", &emsg))) | 176 | ( |
175 | { | 177 | "gnunet://fs/sks/XQHH4R288W26EBV369F6RCE0PJVJTX2Y74Q2FJPMPGA31HJX2JG/this", |
176 | GNUNET_FS_uri_destroy(ret); | 178 | &emsg))) |
177 | GNUNET_assert(0); | 179 | { |
178 | } | 180 | GNUNET_FS_uri_destroy (ret); |
179 | GNUNET_free(emsg); | 181 | GNUNET_assert (0); |
180 | if (NULL != (ret = GNUNET_FS_uri_parse("gnunet://fs/sks/test", &emsg))) | 182 | } |
181 | { | 183 | GNUNET_free (emsg); |
182 | GNUNET_FS_uri_destroy(ret); | 184 | if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/test", &emsg))) |
183 | GNUNET_assert(0); | 185 | { |
184 | } | 186 | GNUNET_FS_uri_destroy (ret); |
185 | GNUNET_free(emsg); | 187 | GNUNET_assert (0); |
186 | ph = GNUNET_CRYPTO_ecdsa_key_create(); | 188 | } |
187 | GNUNET_CRYPTO_ecdsa_key_get_public(ph, &id); | 189 | GNUNET_free (emsg); |
188 | sret = GNUNET_STRINGS_data_to_string(&id, sizeof(id), | 190 | ph = GNUNET_CRYPTO_ecdsa_key_create (); |
189 | ubuf, sizeof(ubuf) - 1); | 191 | GNUNET_CRYPTO_ecdsa_key_get_public (ph, &id); |
190 | GNUNET_assert(NULL != sret); | 192 | sret = GNUNET_STRINGS_data_to_string (&id, sizeof(id), |
193 | ubuf, sizeof(ubuf) - 1); | ||
194 | GNUNET_assert (NULL != sret); | ||
191 | sret[0] = '\0'; | 195 | sret[0] = '\0'; |
192 | GNUNET_snprintf(buf, sizeof(buf), | 196 | GNUNET_snprintf (buf, sizeof(buf), |
193 | "gnunet://fs/sks/%s/test", | 197 | "gnunet://fs/sks/%s/test", |
194 | ubuf); | 198 | ubuf); |
195 | ret = GNUNET_FS_uri_parse(buf, &emsg); | 199 | ret = GNUNET_FS_uri_parse (buf, &emsg); |
196 | if (NULL == ret) | 200 | if (NULL == ret) |
197 | { | 201 | { |
198 | GNUNET_free(emsg); | 202 | GNUNET_free (emsg); |
199 | GNUNET_assert(0); | 203 | GNUNET_assert (0); |
200 | } | 204 | } |
201 | if (GNUNET_FS_uri_test_ksk(ret)) | 205 | if (GNUNET_FS_uri_test_ksk (ret)) |
202 | { | 206 | { |
203 | GNUNET_FS_uri_destroy(ret); | 207 | GNUNET_FS_uri_destroy (ret); |
204 | GNUNET_assert(0); | 208 | GNUNET_assert (0); |
205 | } | 209 | } |
206 | if (!GNUNET_FS_uri_test_sks(ret)) | 210 | if (! GNUNET_FS_uri_test_sks (ret)) |
207 | { | 211 | { |
208 | GNUNET_FS_uri_destroy(ret); | 212 | GNUNET_FS_uri_destroy (ret); |
209 | GNUNET_assert(0); | 213 | GNUNET_assert (0); |
210 | } | 214 | } |
211 | 215 | ||
212 | uri = GNUNET_FS_uri_to_string(ret); | 216 | uri = GNUNET_FS_uri_to_string (ret); |
213 | if (0 != | 217 | if (0 != |
214 | strcmp(uri, | 218 | strcmp (uri, |
215 | buf)) | 219 | buf)) |
216 | { | 220 | { |
217 | GNUNET_FS_uri_destroy(ret); | 221 | GNUNET_FS_uri_destroy (ret); |
218 | GNUNET_free(uri); | 222 | GNUNET_free (uri); |
219 | GNUNET_assert(0); | 223 | GNUNET_assert (0); |
220 | } | 224 | } |
221 | GNUNET_free(uri); | 225 | GNUNET_free (uri); |
222 | GNUNET_FS_uri_destroy(ret); | 226 | GNUNET_FS_uri_destroy (ret); |
223 | return 0; | 227 | return 0; |
224 | } | 228 | } |
225 | 229 | ||
226 | 230 | ||
227 | static int | 231 | static int |
228 | testFile(int i) | 232 | testFile (int i) |
229 | { | 233 | { |
230 | char *uri; | 234 | char *uri; |
231 | struct GNUNET_FS_Uri *ret; | 235 | struct GNUNET_FS_Uri *ret; |
@@ -234,92 +238,96 @@ testFile(int i) | |||
234 | if (NULL != | 238 | if (NULL != |
235 | (ret = | 239 | (ret = |
236 | GNUNET_FS_uri_parse | 240 | GNUNET_FS_uri_parse |
237 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42", | 241 | ( |
242 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42", | ||
238 | &emsg))) | 243 | &emsg))) |
239 | { | 244 | { |
240 | GNUNET_FS_uri_destroy(ret); | 245 | GNUNET_FS_uri_destroy (ret); |
241 | GNUNET_assert(0); | 246 | GNUNET_assert (0); |
242 | } | 247 | } |
243 | GNUNET_free(emsg); | 248 | GNUNET_free (emsg); |
244 | if (NULL != | 249 | if (NULL != |
245 | (ret = | 250 | (ret = |
246 | GNUNET_FS_uri_parse | 251 | GNUNET_FS_uri_parse |
247 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000", | 252 | ( |
253 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000", | ||
248 | &emsg))) | 254 | &emsg))) |
249 | { | 255 | { |
250 | GNUNET_FS_uri_destroy(ret); | 256 | GNUNET_FS_uri_destroy (ret); |
251 | GNUNET_assert(0); | 257 | GNUNET_assert (0); |
252 | } | 258 | } |
253 | GNUNET_free(emsg); | 259 | GNUNET_free (emsg); |
254 | if (NULL != | 260 | if (NULL != |
255 | (ret = | 261 | (ret = |
256 | GNUNET_FS_uri_parse | 262 | GNUNET_FS_uri_parse |
257 | ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH", | 263 | ( |
264 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH", | ||
258 | &emsg))) | 265 | &emsg))) |
259 | { | 266 | { |
260 | GNUNET_FS_uri_destroy(ret); | 267 | GNUNET_FS_uri_destroy (ret); |
261 | GNUNET_assert(0); | 268 | GNUNET_assert (0); |
262 | } | 269 | } |
263 | GNUNET_free(emsg); | 270 | GNUNET_free (emsg); |
264 | ret = | 271 | ret = |
265 | GNUNET_FS_uri_parse | 272 | GNUNET_FS_uri_parse |
266 | ("gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42", | 273 | ( |
274 | "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42", | ||
267 | &emsg); | 275 | &emsg); |
268 | if (ret == NULL) | 276 | if (ret == NULL) |
269 | { | 277 | { |
270 | GNUNET_free(emsg); | 278 | GNUNET_free (emsg); |
271 | GNUNET_assert(0); | 279 | GNUNET_assert (0); |
272 | } | 280 | } |
273 | if (GNUNET_FS_uri_test_ksk(ret)) | 281 | if (GNUNET_FS_uri_test_ksk (ret)) |
274 | { | 282 | { |
275 | GNUNET_FS_uri_destroy(ret); | 283 | GNUNET_FS_uri_destroy (ret); |
276 | GNUNET_assert(0); | 284 | GNUNET_assert (0); |
277 | } | 285 | } |
278 | if (GNUNET_FS_uri_test_sks(ret)) | 286 | if (GNUNET_FS_uri_test_sks (ret)) |
279 | { | 287 | { |
280 | GNUNET_FS_uri_destroy(ret); | 288 | GNUNET_FS_uri_destroy (ret); |
281 | GNUNET_assert(0); | 289 | GNUNET_assert (0); |
282 | } | 290 | } |
283 | if (GNUNET_ntohll(ret->data.chk.file_length) != 42) | 291 | if (GNUNET_ntohll (ret->data.chk.file_length) != 42) |
284 | { | 292 | { |
285 | GNUNET_FS_uri_destroy(ret); | 293 | GNUNET_FS_uri_destroy (ret); |
286 | GNUNET_assert(0); | 294 | GNUNET_assert (0); |
287 | } | 295 | } |
288 | 296 | ||
289 | uri = GNUNET_FS_uri_to_string(ret); | 297 | uri = GNUNET_FS_uri_to_string (ret); |
290 | if (0 != | 298 | if (0 != |
291 | strcmp(uri, | 299 | strcmp (uri, |
292 | "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42")) | 300 | "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42")) |
293 | { | 301 | { |
294 | GNUNET_free(uri); | 302 | GNUNET_free (uri); |
295 | GNUNET_FS_uri_destroy(ret); | 303 | GNUNET_FS_uri_destroy (ret); |
296 | GNUNET_assert(0); | 304 | GNUNET_assert (0); |
297 | } | 305 | } |
298 | GNUNET_free(uri); | 306 | GNUNET_free (uri); |
299 | GNUNET_FS_uri_destroy(ret); | 307 | GNUNET_FS_uri_destroy (ret); |
300 | return 0; | 308 | return 0; |
301 | } | 309 | } |
302 | 310 | ||
303 | 311 | ||
304 | int | 312 | int |
305 | main(int argc, char *argv[]) | 313 | main (int argc, char *argv[]) |
306 | { | 314 | { |
307 | int failureCount = 0; | 315 | int failureCount = 0; |
308 | int i; | 316 | int i; |
309 | 317 | ||
310 | GNUNET_log_setup("test_fs_uri", | 318 | GNUNET_log_setup ("test_fs_uri", |
311 | "WARNING", | 319 | "WARNING", |
312 | NULL); | 320 | NULL); |
313 | failureCount += testKeyword(); | 321 | failureCount += testKeyword (); |
314 | failureCount += testLocation(); | 322 | failureCount += testLocation (); |
315 | for (i = 0; i < 255; i++) | 323 | for (i = 0; i < 255; i++) |
316 | { | 324 | { |
317 | /* fprintf (stderr, "%s", "."); */ | 325 | /* fprintf (stderr, "%s", "."); */ |
318 | failureCount += testNamespace(i); | 326 | failureCount += testNamespace (i); |
319 | failureCount += testFile(i); | 327 | failureCount += testFile (i); |
320 | } | 328 | } |
321 | /* fprintf (stderr, "%s", "\n"); */ | 329 | /* fprintf (stderr, "%s", "\n"); */ |
322 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-uri"); | 330 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri"); |
323 | if (failureCount != 0) | 331 | if (failureCount != 0) |
324 | return 1; | 332 | return 1; |
325 | return 0; | 333 | return 0; |
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c index c56e89e11..9842f8a83 100644 --- a/src/fs/test_gnunet_service_fs_migration.c +++ b/src/fs/test_gnunet_service_fs_migration.c | |||
@@ -37,12 +37,13 @@ | |||
37 | /** | 37 | /** |
38 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
39 | */ | 39 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * How long do we give the peers for content migration? | 43 | * How long do we give the peers for content migration? |
44 | */ | 44 | */ |
45 | #define MIGRATION_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) | 45 | #define MIGRATION_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ |
46 | 90) | ||
46 | 47 | ||
47 | #define SEED 42 | 48 | #define SEED 42 |
48 | 49 | ||
@@ -55,7 +56,8 @@ static struct GNUNET_TIME_Absolute start_time; | |||
55 | static struct GNUNET_TESTBED_Operation *op; | 56 | static struct GNUNET_TESTBED_Operation *op; |
56 | 57 | ||
57 | 58 | ||
58 | struct DownloadContext { | 59 | struct DownloadContext |
60 | { | ||
59 | char *fn; | 61 | char *fn; |
60 | 62 | ||
61 | struct GNUNET_FS_Uri *uri; | 63 | struct GNUNET_FS_Uri *uri; |
@@ -63,154 +65,155 @@ struct DownloadContext { | |||
63 | 65 | ||
64 | 66 | ||
65 | static void | 67 | static void |
66 | do_stop(void *cls) | 68 | do_stop (void *cls) |
67 | { | 69 | { |
68 | struct GNUNET_TIME_Relative del; | 70 | struct GNUNET_TIME_Relative del; |
69 | char *fancy; | 71 | char *fancy; |
70 | 72 | ||
71 | GNUNET_SCHEDULER_shutdown(); | 73 | GNUNET_SCHEDULER_shutdown (); |
72 | if (0 == | 74 | if (0 == |
73 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, | 75 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, |
74 | TIMEOUT)).rel_value_us) | 76 | TIMEOUT)). |
75 | { | 77 | rel_value_us) |
76 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 78 | { |
77 | "Timeout during download, shutting down with error\n"); | 79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
78 | ok = 1; | 80 | "Timeout during download, shutting down with error\n"); |
79 | } | 81 | ok = 1; |
82 | } | ||
80 | else | 83 | else |
81 | { | 84 | { |
82 | del = GNUNET_TIME_absolute_get_duration(start_time); | 85 | del = GNUNET_TIME_absolute_get_duration (start_time); |
83 | if (del.rel_value_us == 0) | 86 | if (del.rel_value_us == 0) |
84 | del.rel_value_us = 1; | 87 | del.rel_value_us = 1; |
85 | fancy = | 88 | fancy = |
86 | GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * | 89 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) |
87 | 1000000LL / del.rel_value_us); | 90 | * 1000000LL / del.rel_value_us); |
88 | fprintf(stdout, | 91 | fprintf (stdout, |
89 | "Download speed was %s/s\n", | 92 | "Download speed was %s/s\n", |
90 | fancy); | 93 | fancy); |
91 | GNUNET_free(fancy); | 94 | GNUNET_free (fancy); |
92 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
93 | "Finished download, shutting down\n"); | 96 | "Finished download, shutting down\n"); |
94 | } | 97 | } |
95 | } | 98 | } |
96 | 99 | ||
97 | 100 | ||
98 | static void | 101 | static void |
99 | do_download(void *cls, | 102 | do_download (void *cls, |
100 | const char *emsg) | 103 | const char *emsg) |
101 | { | 104 | { |
102 | struct DownloadContext *dc = cls; | 105 | struct DownloadContext *dc = cls; |
103 | struct GNUNET_FS_Uri *uri = dc->uri; | 106 | struct GNUNET_FS_Uri *uri = dc->uri; |
104 | 107 | ||
105 | GNUNET_TESTBED_operation_done(op); | 108 | GNUNET_TESTBED_operation_done (op); |
106 | op = NULL; | 109 | op = NULL; |
107 | if (NULL != dc->fn) | 110 | if (NULL != dc->fn) |
108 | { | 111 | { |
109 | GNUNET_DISK_directory_remove(dc->fn); | 112 | GNUNET_DISK_directory_remove (dc->fn); |
110 | GNUNET_free(dc->fn); | 113 | GNUNET_free (dc->fn); |
111 | } | 114 | } |
112 | GNUNET_free(dc); | 115 | GNUNET_free (dc); |
113 | if (NULL != emsg) | 116 | if (NULL != emsg) |
114 | { | 117 | { |
115 | GNUNET_SCHEDULER_shutdown(); | 118 | GNUNET_SCHEDULER_shutdown (); |
116 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
117 | "Failed to stop source daemon: %s\n", | 120 | "Failed to stop source daemon: %s\n", |
118 | emsg); | 121 | emsg); |
119 | GNUNET_FS_uri_destroy(uri); | 122 | GNUNET_FS_uri_destroy (uri); |
120 | ok = 1; | 123 | ok = 1; |
121 | return; | 124 | return; |
122 | } | 125 | } |
123 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
124 | "Downloading %llu bytes\n", | 127 | "Downloading %llu bytes\n", |
125 | (unsigned long long)FILESIZE); | 128 | (unsigned long long) FILESIZE); |
126 | start_time = GNUNET_TIME_absolute_get(); | 129 | start_time = GNUNET_TIME_absolute_get (); |
127 | GNUNET_FS_TEST_download(daemons[0], | 130 | GNUNET_FS_TEST_download (daemons[0], |
128 | TIMEOUT, | 131 | TIMEOUT, |
129 | 1, | 132 | 1, |
130 | SEED, | 133 | SEED, |
131 | uri, | 134 | uri, |
132 | VERBOSE, | 135 | VERBOSE, |
133 | &do_stop, | 136 | &do_stop, |
134 | NULL); | 137 | NULL); |
135 | GNUNET_FS_uri_destroy(uri); | 138 | GNUNET_FS_uri_destroy (uri); |
136 | } | 139 | } |
137 | 140 | ||
138 | 141 | ||
139 | static void | 142 | static void |
140 | stop_source_peer(void *cls) | 143 | stop_source_peer (void *cls) |
141 | { | 144 | { |
142 | struct DownloadContext *dc = cls; | 145 | struct DownloadContext *dc = cls; |
143 | 146 | ||
144 | /* FIXME: We should not interact with testbed when shutting down */ | 147 | /* FIXME: We should not interact with testbed when shutting down */ |
145 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
146 | "Stopping source peer\n"); | 149 | "Stopping source peer\n"); |
147 | op = GNUNET_TESTBED_peer_stop(NULL, | 150 | op = GNUNET_TESTBED_peer_stop (NULL, |
148 | daemons[1], | 151 | daemons[1], |
149 | &do_download, dc); | 152 | &do_download, dc); |
150 | GNUNET_assert(NULL != op); | 153 | GNUNET_assert (NULL != op); |
151 | } | 154 | } |
152 | 155 | ||
153 | 156 | ||
154 | static void | 157 | static void |
155 | do_wait(void *cls, | 158 | do_wait (void *cls, |
156 | const struct GNUNET_FS_Uri *uri, | 159 | const struct GNUNET_FS_Uri *uri, |
157 | const char *fn) | 160 | const char *fn) |
158 | { | 161 | { |
159 | struct DownloadContext *dc; | 162 | struct DownloadContext *dc; |
160 | 163 | ||
161 | if (NULL == uri) | 164 | if (NULL == uri) |
162 | { | 165 | { |
163 | GNUNET_SCHEDULER_shutdown(); | 166 | GNUNET_SCHEDULER_shutdown (); |
164 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 167 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
165 | "Timeout during upload attempt, shutting down with error\n"); | 168 | "Timeout during upload attempt, shutting down with error\n"); |
166 | ok = 1; | 169 | ok = 1; |
167 | return; | 170 | return; |
168 | } | 171 | } |
169 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
170 | "Waiting to allow content to migrate\n"); | 173 | "Waiting to allow content to migrate\n"); |
171 | dc = GNUNET_new(struct DownloadContext); | 174 | dc = GNUNET_new (struct DownloadContext); |
172 | dc->uri = GNUNET_FS_uri_dup(uri); | 175 | dc->uri = GNUNET_FS_uri_dup (uri); |
173 | if (NULL != fn) | 176 | if (NULL != fn) |
174 | dc->fn = GNUNET_strdup(fn); | 177 | dc->fn = GNUNET_strdup (fn); |
175 | (void)GNUNET_SCHEDULER_add_delayed(MIGRATION_DELAY, | 178 | (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, |
176 | &stop_source_peer, | 179 | &stop_source_peer, |
177 | dc); | 180 | dc); |
178 | } | 181 | } |
179 | 182 | ||
180 | 183 | ||
181 | static void | 184 | static void |
182 | do_publish(void *cls, | 185 | do_publish (void *cls, |
183 | struct GNUNET_TESTBED_RunHandle *h, | 186 | struct GNUNET_TESTBED_RunHandle *h, |
184 | unsigned int num_peers, | 187 | unsigned int num_peers, |
185 | struct GNUNET_TESTBED_Peer **peers, | 188 | struct GNUNET_TESTBED_Peer **peers, |
186 | unsigned int links_succeeded, | 189 | unsigned int links_succeeded, |
187 | unsigned int links_failed) | 190 | unsigned int links_failed) |
188 | { | 191 | { |
189 | unsigned int i; | 192 | unsigned int i; |
190 | 193 | ||
191 | GNUNET_assert(2 == num_peers); | 194 | GNUNET_assert (2 == num_peers); |
192 | for (i = 0; i < num_peers; i++) | 195 | for (i = 0; i < num_peers; i++) |
193 | daemons[i] = peers[i]; | 196 | daemons[i] = peers[i]; |
194 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
195 | "Publishing %llu bytes\n", | 198 | "Publishing %llu bytes\n", |
196 | (unsigned long long)FILESIZE); | 199 | (unsigned long long) FILESIZE); |
197 | GNUNET_FS_TEST_publish(daemons[1], TIMEOUT, 1, GNUNET_NO, | 200 | GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, |
198 | FILESIZE, SEED, | 201 | FILESIZE, SEED, |
199 | VERBOSE, &do_wait, NULL); | 202 | VERBOSE, &do_wait, NULL); |
200 | } | 203 | } |
201 | 204 | ||
202 | 205 | ||
203 | int | 206 | int |
204 | main(int argc, | 207 | main (int argc, |
205 | char *argv[]) | 208 | char *argv[]) |
206 | { | 209 | { |
207 | (void)GNUNET_TESTBED_test_run("test-gnunet-service-fs-migration", | 210 | (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration", |
208 | "fs_test_lib_data.conf", | 211 | "fs_test_lib_data.conf", |
209 | 2, | 212 | 2, |
210 | 0, NULL, NULL, | 213 | 0, NULL, NULL, |
211 | &do_publish, | 214 | &do_publish, |
212 | NULL); | 215 | NULL); |
213 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-service-fs-migration/"); | 216 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); |
214 | return ok; | 217 | return ok; |
215 | } | 218 | } |
216 | 219 | ||
diff --git a/src/fs/test_gnunet_service_fs_p2p.c b/src/fs/test_gnunet_service_fs_p2p.c index eba4e112d..8d2ed144f 100644 --- a/src/fs/test_gnunet_service_fs_p2p.c +++ b/src/fs/test_gnunet_service_fs_p2p.c | |||
@@ -36,7 +36,7 @@ | |||
36 | /** | 36 | /** |
37 | * How long until we give up on the download? | 37 | * How long until we give up on the download? |
38 | */ | 38 | */ |
39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
40 | 40 | ||
41 | #define NUM_DAEMONS 2 | 41 | #define NUM_DAEMONS 2 |
42 | 42 | ||
@@ -54,110 +54,111 @@ static struct GNUNET_TIME_Absolute start_time; | |||
54 | 54 | ||
55 | 55 | ||
56 | static void | 56 | static void |
57 | do_stop(void *cls) | 57 | do_stop (void *cls) |
58 | { | 58 | { |
59 | char *fn = cls; | 59 | char *fn = cls; |
60 | struct GNUNET_TIME_Relative del; | 60 | struct GNUNET_TIME_Relative del; |
61 | char *fancy; | 61 | char *fancy; |
62 | 62 | ||
63 | GNUNET_SCHEDULER_shutdown(); | 63 | GNUNET_SCHEDULER_shutdown (); |
64 | if (0 == | 64 | if (0 == |
65 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, | 65 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, |
66 | TIMEOUT)).rel_value_us) | 66 | TIMEOUT)). |
67 | { | 67 | rel_value_us) |
68 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 68 | { |
69 | "Timeout during download, shutting down with error\n"); | 69 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
70 | ok = 1; | 70 | "Timeout during download, shutting down with error\n"); |
71 | } | 71 | ok = 1; |
72 | } | ||
72 | else | 73 | else |
73 | { | 74 | { |
74 | del = GNUNET_TIME_absolute_get_duration(start_time); | 75 | del = GNUNET_TIME_absolute_get_duration (start_time); |
75 | if (0 == del.rel_value_us) | 76 | if (0 == del.rel_value_us) |
76 | del.rel_value_us = 1; | 77 | del.rel_value_us = 1; |
77 | fancy = | 78 | fancy = |
78 | GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * | 79 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) |
79 | 1000000LL / del.rel_value_us); | 80 | * 1000000LL / del.rel_value_us); |
80 | fprintf(stdout, | 81 | fprintf (stdout, |
81 | "Download speed was %s/s\n", | 82 | "Download speed was %s/s\n", |
82 | fancy); | 83 | fancy); |
83 | GNUNET_free(fancy); | 84 | GNUNET_free (fancy); |
84 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
85 | "Finished download, shutting down\n"); | 86 | "Finished download, shutting down\n"); |
86 | } | 87 | } |
87 | if (NULL != fn) | 88 | if (NULL != fn) |
88 | { | 89 | { |
89 | GNUNET_DISK_directory_remove(fn); | 90 | GNUNET_DISK_directory_remove (fn); |
90 | GNUNET_free(fn); | 91 | GNUNET_free (fn); |
91 | } | 92 | } |
92 | } | 93 | } |
93 | 94 | ||
94 | 95 | ||
95 | static void | 96 | static void |
96 | do_download(void *cls, const struct GNUNET_FS_Uri *uri, | 97 | do_download (void *cls, const struct GNUNET_FS_Uri *uri, |
97 | const char *fn) | 98 | const char *fn) |
98 | { | 99 | { |
99 | if (NULL == uri) | 100 | if (NULL == uri) |
100 | { | 101 | { |
101 | GNUNET_SCHEDULER_shutdown(); | 102 | GNUNET_SCHEDULER_shutdown (); |
102 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
103 | "Timeout during upload attempt, shutting down with error\n"); | 104 | "Timeout during upload attempt, shutting down with error\n"); |
104 | ok = 1; | 105 | ok = 1; |
105 | return; | 106 | return; |
106 | } | 107 | } |
107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", |
108 | (unsigned long long)FILESIZE); | 109 | (unsigned long long) FILESIZE); |
109 | start_time = GNUNET_TIME_absolute_get(); | 110 | start_time = GNUNET_TIME_absolute_get (); |
110 | GNUNET_FS_TEST_download(daemons[0], TIMEOUT, | 111 | GNUNET_FS_TEST_download (daemons[0], TIMEOUT, |
111 | anonymity_level, SEED, uri, | 112 | anonymity_level, SEED, uri, |
112 | VERBOSE, &do_stop, | 113 | VERBOSE, &do_stop, |
113 | (NULL == fn) | 114 | (NULL == fn) |
114 | ? NULL | 115 | ? NULL |
115 | : GNUNET_strdup(fn)); | 116 | : GNUNET_strdup (fn)); |
116 | } | 117 | } |
117 | 118 | ||
118 | 119 | ||
119 | static void | 120 | static void |
120 | do_publish(void *cls, | 121 | do_publish (void *cls, |
121 | struct GNUNET_TESTBED_RunHandle *h, | 122 | struct GNUNET_TESTBED_RunHandle *h, |
122 | unsigned int num_peers, | 123 | unsigned int num_peers, |
123 | struct GNUNET_TESTBED_Peer **peers, | 124 | struct GNUNET_TESTBED_Peer **peers, |
124 | unsigned int links_succeeded, | 125 | unsigned int links_succeeded, |
125 | unsigned int links_failed) | 126 | unsigned int links_failed) |
126 | { | 127 | { |
127 | unsigned int i; | 128 | unsigned int i; |
128 | 129 | ||
129 | if (NULL != strstr(progname, "cadet")) | 130 | if (NULL != strstr (progname, "cadet")) |
130 | anonymity_level = 0; | 131 | anonymity_level = 0; |
131 | else | 132 | else |
132 | anonymity_level = 1; | 133 | anonymity_level = 1; |
133 | GNUNET_assert(NUM_DAEMONS == num_peers); | 134 | GNUNET_assert (NUM_DAEMONS == num_peers); |
134 | for (i = 0; i < num_peers; i++) | 135 | for (i = 0; i < num_peers; i++) |
135 | daemons[i] = peers[i]; | 136 | daemons[i] = peers[i]; |
136 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
137 | (unsigned long long)FILESIZE); | 138 | (unsigned long long) FILESIZE); |
138 | GNUNET_FS_TEST_publish(daemons[1], TIMEOUT, | 139 | GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, |
139 | anonymity_level, GNUNET_NO, | 140 | anonymity_level, GNUNET_NO, |
140 | FILESIZE, SEED, | 141 | FILESIZE, SEED, |
141 | VERBOSE, &do_download, NULL); | 142 | VERBOSE, &do_download, NULL); |
142 | } | 143 | } |
143 | 144 | ||
144 | 145 | ||
145 | int | 146 | int |
146 | main(int argc, char *argv[]) | 147 | main (int argc, char *argv[]) |
147 | { | 148 | { |
148 | const char *config; | 149 | const char *config; |
149 | 150 | ||
150 | progname = argv[0]; | 151 | progname = argv[0]; |
151 | if (NULL != strstr(progname, "cadet")) | 152 | if (NULL != strstr (progname, "cadet")) |
152 | config = "test_gnunet_service_fs_p2p_cadet.conf"; | 153 | config = "test_gnunet_service_fs_p2p_cadet.conf"; |
153 | else | 154 | else |
154 | config = "fs_test_lib_data.conf"; | 155 | config = "fs_test_lib_data.conf"; |
155 | (void)GNUNET_TESTBED_test_run("test-gnunet-service-fs-p2p", | 156 | (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-p2p", |
156 | config, | 157 | config, |
157 | NUM_DAEMONS, | 158 | NUM_DAEMONS, |
158 | 0, NULL, NULL, | 159 | 0, NULL, NULL, |
159 | &do_publish, NULL); | 160 | &do_publish, NULL); |
160 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); | 161 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
161 | return ok; | 162 | return ok; |
162 | } | 163 | } |
163 | 164 | ||
diff --git a/src/fs/test_plugin_block_fs.c b/src/fs/test_plugin_block_fs.c index 53f7304dd..305da2f18 100644 --- a/src/fs/test_plugin_block_fs.c +++ b/src/fs/test_plugin_block_fs.c | |||
@@ -27,64 +27,64 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | static int | 29 | static int |
30 | test_fs(struct GNUNET_BLOCK_Context *ctx) | 30 | test_fs (struct GNUNET_BLOCK_Context *ctx) |
31 | { | 31 | { |
32 | struct GNUNET_HashCode key; | 32 | struct GNUNET_HashCode key; |
33 | char block[4]; | 33 | char block[4]; |
34 | 34 | ||
35 | memset(block, 1, sizeof(block)); | 35 | memset (block, 1, sizeof(block)); |
36 | if (GNUNET_OK != | 36 | if (GNUNET_OK != |
37 | GNUNET_BLOCK_get_key(ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, block, | 37 | GNUNET_BLOCK_get_key (ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, block, |
38 | sizeof(block), &key)) | 38 | sizeof(block), &key)) |
39 | return 1; | 39 | return 1; |
40 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != | 40 | if (GNUNET_BLOCK_EVALUATION_OK_LAST != |
41 | GNUNET_BLOCK_evaluate(ctx, | 41 | GNUNET_BLOCK_evaluate (ctx, |
42 | GNUNET_BLOCK_TYPE_FS_DBLOCK, | 42 | GNUNET_BLOCK_TYPE_FS_DBLOCK, |
43 | NULL, | 43 | NULL, |
44 | GNUNET_BLOCK_EO_NONE, | 44 | GNUNET_BLOCK_EO_NONE, |
45 | &key, | 45 | &key, |
46 | NULL, 0, | 46 | NULL, 0, |
47 | block, sizeof(block))) | 47 | block, sizeof(block))) |
48 | return 2; | 48 | return 2; |
49 | if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID != | 49 | if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID != |
50 | GNUNET_BLOCK_evaluate(ctx, | 50 | GNUNET_BLOCK_evaluate (ctx, |
51 | GNUNET_BLOCK_TYPE_FS_DBLOCK, | 51 | GNUNET_BLOCK_TYPE_FS_DBLOCK, |
52 | NULL, | 52 | NULL, |
53 | GNUNET_BLOCK_EO_NONE, | 53 | GNUNET_BLOCK_EO_NONE, |
54 | &key, | 54 | &key, |
55 | NULL, 0, | 55 | NULL, 0, |
56 | NULL, 0)) | 56 | NULL, 0)) |
57 | return 4; | 57 | return 4; |
58 | GNUNET_log_skip(1, GNUNET_NO); | 58 | GNUNET_log_skip (1, GNUNET_NO); |
59 | if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID != | 59 | if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID != |
60 | GNUNET_BLOCK_evaluate(ctx, | 60 | GNUNET_BLOCK_evaluate (ctx, |
61 | GNUNET_BLOCK_TYPE_FS_DBLOCK, | 61 | GNUNET_BLOCK_TYPE_FS_DBLOCK, |
62 | NULL, | 62 | NULL, |
63 | GNUNET_BLOCK_EO_NONE, | 63 | GNUNET_BLOCK_EO_NONE, |
64 | &key, | 64 | &key, |
65 | "bogus", 5, | 65 | "bogus", 5, |
66 | NULL, 0)) | 66 | NULL, 0)) |
67 | return 8; | 67 | return 8; |
68 | GNUNET_log_skip(0, GNUNET_YES); | 68 | GNUNET_log_skip (0, GNUNET_YES); |
69 | return 0; | 69 | return 0; |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | int | 73 | int |
74 | main(int argc, char *argv[]) | 74 | main (int argc, char *argv[]) |
75 | { | 75 | { |
76 | int ret; | 76 | int ret; |
77 | struct GNUNET_BLOCK_Context *ctx; | 77 | struct GNUNET_BLOCK_Context *ctx; |
78 | struct GNUNET_CONFIGURATION_Handle *cfg; | 78 | struct GNUNET_CONFIGURATION_Handle *cfg; |
79 | 79 | ||
80 | GNUNET_log_setup("test-block", "WARNING", NULL); | 80 | GNUNET_log_setup ("test-block", "WARNING", NULL); |
81 | cfg = GNUNET_CONFIGURATION_create(); | 81 | cfg = GNUNET_CONFIGURATION_create (); |
82 | ctx = GNUNET_BLOCK_context_create(cfg); | 82 | ctx = GNUNET_BLOCK_context_create (cfg); |
83 | ret = test_fs(ctx); | 83 | ret = test_fs (ctx); |
84 | GNUNET_BLOCK_context_destroy(ctx); | 84 | GNUNET_BLOCK_context_destroy (ctx); |
85 | GNUNET_CONFIGURATION_destroy(cfg); | 85 | GNUNET_CONFIGURATION_destroy (cfg); |
86 | if (ret != 0) | 86 | if (ret != 0) |
87 | fprintf(stderr, "Tests failed: %d\n", ret); | 87 | fprintf (stderr, "Tests failed: %d\n", ret); |
88 | return ret; | 88 | return ret; |
89 | } | 89 | } |
90 | 90 | ||